Files
plugins/packages/pig/pig.agent.js
T
yetone 74cdf0de97 pig 0.1.1: the Agents row picks the model PiG starts on (str_)
str_ on Discord: PiG's row only listed models, where Pi's picks the one it
starts on. PiG keeps that in ~/.pig/agent/settings.json as
defaultProvider and defaultModel (PiG's settings reference and
startup_model.go). The descriptor now says `startup: {config:
settings.json, model: "defaultModel", keys: {defaultProvider: "magpie"}}`,
which magpie v0.1.3008 (1fd02d33c) reads: the row gets a model picker,
both keys are kept aside and put back on disconnect. An older magpie
ignores startup and keeps 0.1.0's connect-only row. The READMEs say so,
and that an enabledModels scope leaving the model out starts PiG on the
scope's first model.

Run (mote): bun test pig.test.mjs (11 pass; the new startup test checks
connect writes the provider defaultProvider names), bun scripts/check.mjs
ok. Real PiG 0.5.3 (darwin-arm64 release, SHA256SUMS checked) in a
sandbox HOME with this connect's models.json and the startup keys,
against a fake OpenAI server: `pig -p` sent model deepseek/flash; with
enabledModels ["magpie/deepseek/pro"] it sent deepseek/pro.

Not tried: PiG on Windows or Linux, a real magpie gateway in front of it.
2026-11-05 10:47:30 +08:00

65 lines
2.5 KiB
JavaScript

// PiG reads providers from models.json and startup preferences from a separate
// settings.json (docs/site/docs/settings.md: defaultProvider, plus defaultModel
// "without a provider prefix"). connect owns the provider catalog in
// models.json; startup names the model a new session starts on in
// settings.json, so the Agents row picks it as it does for Pi. A Magpie
// without startup support reads this as connect-only, as 0.1.0 was.
export const agent = {
id: "pig",
name: "PiG",
// PiG's own pixel-pig favicon from its site (MIT), as the app shows it.
icon: "https://pi-in-go.dev/pig-favicon.svg",
bin: "pig",
dir: "~/.pig/agent",
config: "~/.pig/agent/models.json",
format: "json",
startup: {
config: "~/.pig/agent/settings.json",
format: "json",
model: "defaultModel",
// the provider ID connect writes below
keys: { defaultProvider: "magpie" },
},
notice: "New PiG sessions start on this model; /model in PiG still switches. 新开的 PiG 会话从这个模型开始;PiG 里的 /model 仍可切换。",
}
const thinkingLevels = ["off", "minimal", "low", "medium", "high", "xhigh", "max"]
function modelEntry(model) {
const efforts = model.efforts || []
const entry = {
id: model.id,
name: model.name || model.id,
input: model.images ? ["text", "image"] : ["text"],
reasoning: efforts.length > 0,
}
// Unknown limits are left to PiG's defaults; zero is invalid in its schema.
if (model.context > 0) entry.contextWindow = model.context
// Match Magpie's Pi adapter: a published output limit cannot exceed its window.
if (model.output > 0) entry.maxTokens = model.context > 0 ? Math.min(model.output, model.context) : model.output
if (efforts.length > 0) {
entry.thinkingLevelMap = {}
for (const level of thinkingLevels) {
const effort = level === "off" ? "none" : level
entry.thinkingLevelMap[level] = efforts.includes(effort) ? effort : null
}
}
return entry
}
export function connect({ gateway, models }) {
// Stash and restore the provider as one unit. Leaf-only writes leave an
// invalid empty provider after disconnect when no provider existed before.
// Other provider IDs remain outside this plugin's ownership.
return {
"providers.magpie": {
name: "Magpie",
baseUrl: gateway.v1,
apiKey: gateway.key,
// The public hook has no native-protocol field; Magpie translates Chat.
api: "openai-completions",
models: models.map(modelEntry),
},
}
}