plugin: a plugin can say the list it hands back is a fallback, and magpie keeps the one told last, as a built-in does — Command Code's Go accounts and ZCode give a table of their own when their vendor's list can't be had, not the defaults they were given, so magpie couldn't tell it from a list read and a hiccup swapped the models for the table. A models hook's list marked Symbol.for("magpie.fellBack") (OpenCode never sees a symbol's key) now counts as fallen back; commandcode 0.1.7 and zcode 0.1.6 mark theirs. TestFallenBackListKeepsTheLastOne/throws=own fails without the change. go vet, go build -tags nogui (darwin, GOOS=linux), GOOS=windows go build, go test -tags nogui ./internal/plugin ./internal/provider pass; internal/plugin passes on Windows and Linux.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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) })
|
||||
}
|
||||
}
|
||||
|
||||
+6
-2
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user