Files
magpie/internal/plugin/testdata/options/index.js
T
yetone e84870f173 plugins: an option's words in the window's language, and a filtered model list says so (plugins#590)
anewuser6937 (Discord, plugins#590) saw one model in WorkBuddy's editor
and took the plugin for broken. They had turned on "Free models only"
themselves, but its label and description read in English in the Chinese
window, and nothing by the models said the list was filtered.

A plugin option (auth.options, magpie's own field; OpenCode's AuthHook is
provider/loader/methods and never reads it) may now give `labels`,
`descriptions` and `confirms`, each keyed by the window's language
("zh", "zh-TW", "ja", "de"), beside the plain strings, as a page's
`titles` do. The host keeps only non-empty strings under language names
of 16 or less, 16 languages at most, each capped as the plain one is
(60/300/300). The editor shows the exact language, then its first part
(zh-TW reads zh), else the plain words, in the row, the hint, and the
confirm dialog and its title. `filtersModels: true` says the plugin's
model list leaves models out while the switch is on; while one is on, as
saved, the Models field says under the chips "Only some models are
listed: the plugin option “…” is on." (zh 只列出部分模型:插件选项「…」已开启。,
zh-TW, ja, de too). An older plugin shows what it showed before, and an
older magpie shows a new plugin's plain words with no note.

WorkBuddy 0.2.10 gives "Free models only" in all four languages with
filtersModels (magpie-community/plugins aec58ae, on npm: `npm view
@magpie-community/opencode-workbuddy-auth@0.2.10 --prefer-online` on mote
says 0.2.10, latest), and the mover's min is raised to it so every moved
user gets it. The CLI's `magpie plugin options` stays English, as the CLI is.

The core scripts would have gone 608 bytes over their budget; three of the
provider editor's comments in app.js are cut down instead, no raise
(1,532,865 of 1,533,105).

Run, on mote (mote-run), at this tree:
- node --test plugin-option-words.test.cjs (new): Chromium and WebKit,
  1100 and 420 wide, en/zh/zh-TW/ja/de, switch on and off: each
  language's label and description, zh-TW falling back to zh and ja/de to
  the plain words for a zh-only option, the note exactly once under the
  chips in a .hint inside the editor with no sideways scroll, none while
  off, the confirm in the language. With app.js put back: 19 of 21 red
  in Chromium (only "en off" passes, both widths).
- With plugin-options.test.cjs and i18n-keys.test.cjs, both engines:
  68 pass, 0 fail.
- go test ./internal/plugin ./internal/provider ./internal/cli: ok.
  TestPluginOptions with host.js put back: red (empty maps, FiltersModels
  false). The real WorkBuddy 0.2.10 index.mjs loaded into this host
  (a temporary test, not kept): plugin.Providers lists free_only for
  workbuddy and workbuddy-ai with all four languages and filtersModels true.
- go test ./internal/gui: TestCoreScriptBudget ok after the cut. Red,
  and red the same at origin/main ed5872d18 (run there too):
  TestSettingsSaveKeepsWhatItDoesNotSend (#4514), TestMainWindowCorners
  /macOS_26_SDK on macOS 27 (#3949); TestColdTurnsTaken red once in the
  package run and passed at origin/main (#4510, the same 0.00s red).
- gofmt -l: clean. go vet ./..., GOOS=linux go vet -tags nogui ./...,
  GOOS=windows go vet ./...: ok.
- plugins: HOME=$(mktemp -d) bun test packages/workbuddy 303 pass 0
  fail; the new freeonly test red 2 of 2 with index.mjs put back.

Not run: the whole GUI suite. mote and the WSL box were each running
another session's full GUI suite (hours left on both), and one runs per
machine; it runs on mote once that one ends. Not tried: a real WorkBuddy
account in the real app window. go test ./... was not run.
2026-11-01 13:24:50 +08:00

44 lines
2.5 KiB
JavaScript

// A plugin declaring switches for its provider (auth.options, magpie's own
// field, #2038) and reading them as they stand: its key prompt's check
// answers with what input.magpie.options says, read when it is asked.
export const Optco = async (input) => ({
// its list goes by a switch, as WorkBuddy's "Free models only" does
// (plugins#430): beta-model is listed only while beta is on
config: async (cfg) => {
cfg.provider ??= {}
cfg.provider.optco ??= { name: "Optco", npm: "@ai-sdk/openai-compatible", api: "http://127.0.0.1:9/v1", models: { "base-model": { name: "Base" } } }
},
provider: {
id: "optco",
async models(provider) {
const out = { ...provider.models }
if (input.magpie?.option("optco", "beta")) out["beta-model"] = { ...out["base-model"], id: "beta-model", name: "Beta" }
return out
},
},
auth: {
provider: "optco",
options: [
{ key: "auto-claim", label: " Claim rewards ", description: "Claims the daily reward when usage is read.", default: true, descriptions: { zh: " 读取用量时领取每日奖励。 " }, filtersModels: true },
// the words in other languages (plugins#590): what isn't a string,
// an empty one and a language name over 16 are left out
{ key: "beta", label: "Beta models", confirm: "Beta models may be withdrawn.", labels: { zh: " 测试版模型 ", "zh-TW": "", ja: 5, "a-language-name-too-long": "x", de: "Beta-Modelle" }, confirms: { zh: "测试版模型可能会下线。" } },
{ key: "beta", label: "the same key again" }, // dropped
{ key: "Bad Key", label: "not a key" }, // dropped
{ key: "nolabel" }, // dropped
{ key: "long", label: "L".repeat(200), description: "D".repeat(1000), default: "yes", filtersModels: "yes", labels: "not an object", descriptions: { zh: "D".repeat(1000) }, confirms: Object.fromEntries(Array.from({ length: 20 }, (_, i) => ["l" + i, "c"])) }, // default and filtersModels are no boolean: off; the words capped, at most 16 languages
...Array.from({ length: 20 }, (_, i) => ({ key: "o" + i, label: "Option " + i })),
],
methods: [
{
type: "api",
label: "API key",
prompts: [{ type: "text", key: "probe", message: "probe", validate: () => JSON.stringify([input.magpie?.options("optco"), input.magpie?.option("optco", "beta"), input.magpie?.option("optco", "nope")]) }],
},
],
},
})
// a provider whose plugin declares none
export const Plain = async () => ({ auth: { provider: "plain", options: "not a list", methods: [{ type: "api", label: "API key" }] } })