New package @magpie-community/agent-pig 0.1.0, a connect-only Agent:
it manages the whole providers.magpie object in ~/.pig/agent/models.json
(name, baseUrl, apiKey, api openai-completions, models) and nothing else.
settings.json and auth.json are not touched; disconnect restores a prior
same-name provider or removes the provider whole. Models keep their ids,
names, image input, positive limits (output capped at the window), and
map Pi's seven thinking levels onto the model's efforts (off -> none,
unsupported -> null).
Re-review of head 7134b1038: both points of the 10-21 review are fixed.
The package README no longer names e2e scripts that aren't shipped, and
installs with `magpie plugin add @magpie-community/agent-pig`. Code is
unchanged from the reviewed 43fb5d927.
Run at this tree (PR squashed onto origin/main 397a890), sandbox HOME:
- bun test: 2093 pass, 0 fail.
- bun scripts/check.mjs: ok.
- Broken by hand, pig.test.mjs red each time: unsupported level as
undefined (2 fail), no output cap (1), zero context written (1), off
not mapped to none (1), hardcoded apiKey (1), ids rewritten (3).
- Read every line: no imports, no file or network access, no install
hooks; the icon is a URL (pi-in-go.dev) as aider's is.
- npm has no @magpie-community/agent-pig yet, so 0.1.0 stays.
Not tried at this head: a real PiG binary or the magpie host. The 10-21
review ran both at 43fb5d927 (PiG v0.5.1 darwin-arm64 offline parse,
fake-upstream request, host connect/disconnect); the runtime file is
byte-identical since.
Co-authored-by: netube <61469467+netube99@users.noreply.github.com>
54 lines
2.0 KiB
JavaScript
54 lines
2.0 KiB
JavaScript
// PiG reads providers from models.json and startup preferences from a separate
|
|
// settings.json. This connect-only agent owns the provider catalog alone.
|
|
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",
|
|
notice: "Choose a Magpie model with /model in PiG. Startup settings are unchanged. 在 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),
|
|
},
|
|
}
|
|
}
|