From 8cd520662f993e437d4f46424ab0bf2a9dfa2f90 Mon Sep 17 00:00:00 2001 From: yetone Date: Thu, 1 Oct 2026 17:06:17 +0800 Subject: [PATCH] =?UTF-8?q?plugin:=20a=20plugin=20can=20say=20the=20list?= =?UTF-8?q?=20it=20hands=20back=20is=20a=20fallback,=20and=20magpie=20keep?= =?UTF-8?q?s=20the=20one=20told=20last,=20as=20a=20built-in=20does=20?= =?UTF-8?q?=E2=80=94=20Command=20Code's=20Go=20accounts=20and=20ZCode=20gi?= =?UTF-8?q?ve=20a=20table=20of=20their=20own=20when=20their=20vendor's=20l?= =?UTF-8?q?ist=20can't=20be=20had,=20not=20the=20defaults=20they=20were=20?= =?UTF-8?q?given,=20so=20magpie=20couldn't=20tell=20it=20from=20a=20list?= =?UTF-8?q?=20read=20and=20a=20hiccup=20swapped=20the=20models=20for=20the?= =?UTF-8?q?=20table.=20A=20models=20hook's=20list=20marked=20Symbol.for("m?= =?UTF-8?q?agpie.fellBack")=20(OpenCode=20never=20sees=20a=20symbol's=20ke?= =?UTF-8?q?y)=20now=20counts=20as=20fallen=20back;=20commandcode=200.1.7?= =?UTF-8?q?=20and=20zcode=200.1.6=20mark=20theirs.=20TestFallenBackListKee?= =?UTF-8?q?psTheLastOne/throws=3Down=20fails=20without=20the=20change.=20g?= =?UTF-8?q?o=20vet,=20go=20build=20-tags=20nogui=20(darwin,=20GOOS=3Dlinux?= =?UTF-8?q?),=20GOOS=3Dwindows=20go=20build,=20go=20test=20-tags=20nogui?= =?UTF-8?q?=20./internal/plugin=20./internal/provider=20pass;=20internal/p?= =?UTF-8?q?lugin=20passes=20on=20Windows=20and=20Linux.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/plugin/host.js | 6 ++++-- internal/plugin/plugin_listed_test.go | 5 +++-- internal/plugin/testdata/fake/index.js | 8 ++++++-- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/internal/plugin/host.js b/internal/plugin/host.js index 3c4664725..124d60fa9 100644 --- a/internal/plugin/host.js +++ b/internal/plugin/host.js @@ -555,8 +555,10 @@ async function info(id, key, strict) { const next = await listing.run(l, () => inScope(id, k, () => ph.models(given, { auth: all[k] }))) // a hook that asked its vendor, got no list and gave back the one it // was given fell back: magpie keeps the list it had, as a built-in - // whose fetch failed keeps the one it fetched last - out.fellBack = next === given.models && l.tried && !l.lastOk + // whose fetch failed keeps the one it fetched last; so does one that + // says so, handing back a list of its own (Symbol.for("magpie.fellBack") + // on it: Command Code's Go table, ZCode's models) + out.fellBack = (next === given.models && l.tried && !l.lastOk) || next?.[Symbol.for("magpie.fellBack")] === true out.models = Object.fromEntries(Object.entries(next ?? {}).map(([k, m]) => [k, { ...m, id: k, providerID: id }])) } catch (e) { // an error the models hook throws may say what it means for the diff --git a/internal/plugin/plugin_listed_test.go b/internal/plugin/plugin_listed_test.go index a3f89ad5b..4f4c9b437 100644 --- a/internal/plugin/plugin_listed_test.go +++ b/internal/plugin/plugin_listed_test.go @@ -16,9 +16,10 @@ import ( // defaults back keeps the list it told last, for the provider and each // account, as a built-in whose fetch fails keeps the one it fetched last; // the vendor back, its list is told again. So too for a hook that throws -// (Cursor's, Grok's, Devin's) rather than give its defaults back. +// (Cursor's, Grok's, Devin's) rather than give its defaults back, and for +// one handing back a table of its own that it says is a fallback. func TestFallenBackListKeepsTheLastOne(t *testing.T) { - for _, throws := range []string{"", "1"} { + for _, throws := range []string{"", "1", "own"} { t.Run("throws="+throws, func(t *testing.T) { fallenBack(t, throws) }) } } diff --git a/internal/plugin/testdata/fake/index.js b/internal/plugin/testdata/fake/index.js index cde0e43db..f144f997c 100644 --- a/internal/plugin/testdata/fake/index.js +++ b/internal/plugin/testdata/fake/index.js @@ -115,9 +115,13 @@ export const FakePlugin = async ({ client }) => ({ if (process.env.FAKE_MODELS && auth) { const r = await fetch(process.env.FAKE_MODELS).then((r) => r.text()).catch((e) => { // $FAKE_MODELS_THROW: the hook throws, as Cursor's, Grok's and Devin's do - if (process.env.FAKE_MODELS_THROW) throw e - return "" + if (process.env.FAKE_MODELS_THROW === "1") throw e + return null }) + // "own": it hands back a table of its own, saying it fell back, as + // Command Code's Go and ZCode do + if (r === null && process.env.FAKE_MODELS_THROW === "own") + return { "fake-1": { ...p.models["fake-1"] }, [Symbol.for("magpie.fellBack")]: true } if (r) p.models["fake-" + r] = { ...p.models["fake-1"], id: "fake-" + r, name: r } } return p.models