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