loomy 0.1.10: a refusal in a 200, or a failed read, gives the given list marked fell back
A non-OK business code in a 200 answer (the host saw an OK fetch) returned the static table unmarked; so did a throw. fake.mjs can now answer the models read with a code.
Archivemylife on X (agy-cli): "配置后报存提示成功,再打开还是全部都启用".
The same class as agy-cli 0.1.61: a list that isn't the account's own,
handed back as if it were, makes magpie relist on it and drop the models
the user picked that aren't in it. Marked with
Symbol.for("magpie.fellBack"), magpie's plugin host keeps the last good
list (keepListed) and the picks.
Run (mote-run, HOME=mktemp -d): index.test.mjs 34 pass on this change: all pass.
Red on the old code with the new test: "a refusal in a 200 gives the static table marked" fails.
Not tried: a real account.
This commit is contained in:
@@ -33,6 +33,7 @@ export function fakeLoomy() {
|
||||
dailyBalance: 3000, // the day's first first-login refreshes it to 5000
|
||||
recordsReads: 0,
|
||||
modelsReads: 0,
|
||||
modelsCode: null, // set to a business code to answer the models read 200 with it
|
||||
// onboarding: done[key]=true once its complete call lands (idempotent)
|
||||
onboardingDone: {},
|
||||
onboardingQueries: 0,
|
||||
@@ -48,6 +49,7 @@ export function fakeLoomy() {
|
||||
state.dailyBalance = 3000
|
||||
state.recordsReads = 0
|
||||
state.modelsReads = 0
|
||||
state.modelsCode = null
|
||||
state.onboardingDone = {}
|
||||
state.onboardingQueries = 0
|
||||
state.onboardingCompletes = 0
|
||||
@@ -108,6 +110,7 @@ export function fakeLoomy() {
|
||||
|
||||
if (url.pathname === "/api/v1/models") {
|
||||
state.modelsReads++
|
||||
if (state.modelsCode) return json(200, { code: state.modelsCode, desc: "系统繁忙" })
|
||||
return json(200, {
|
||||
data: [
|
||||
{ id: "spark-x", name: "Spark X2.5 (x0.1)", capabilities: { reasoning: true, function_calling: true, vision: false }, context_window: 128000, max_tokens: 8192 },
|
||||
|
||||
@@ -669,7 +669,10 @@ export async function LoomyAuthPlugin({ client } = {}) {
|
||||
if (auth?.type !== "oauth" || !auth.access) return p.models
|
||||
try {
|
||||
const payload = await tokenRequest("GET", "/api/v1/models", auth.access)
|
||||
if (codeOf(payload) && codeOf(payload) !== OK) return p.models
|
||||
// a refusal in a 200 lists nothing: what was given (the static
|
||||
// table at first) isn't the account's list, so magpie keeps the
|
||||
// one it had and the models picked from it
|
||||
if (codeOf(payload) && codeOf(payload) !== OK) return fellBack(p.models)
|
||||
const entries = Array.isArray(payload?.data) ? payload.data : []
|
||||
for (const entry of entries) {
|
||||
const m = catalogModel(entry)
|
||||
@@ -678,13 +681,19 @@ export async function LoomyAuthPlugin({ client } = {}) {
|
||||
}
|
||||
return p.models
|
||||
} catch {
|
||||
return p.models
|
||||
return fellBack(p.models)
|
||||
}
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// fellBack marks a list that isn't the account's own (magpie's plugin
|
||||
// host reads Symbol.for("magpie.fellBack"))
|
||||
function fellBack(models) {
|
||||
return Object.defineProperty(models, Symbol.for("magpie.fellBack"), { value: true, configurable: true })
|
||||
}
|
||||
|
||||
// for tests
|
||||
export const _internal = {
|
||||
retryableRefusal,
|
||||
|
||||
@@ -298,6 +298,17 @@ describe("models", () => {
|
||||
expect(list["glm-5.3-flash"].modalities).toEqual({ input: ["text", "image"], output: ["text"] })
|
||||
expect(list["plain"].rate).toBeUndefined()
|
||||
expect(list["plain"].name).toBe("No Suffix At All")
|
||||
expect(list[Symbol.for("magpie.fellBack")]).toBeUndefined()
|
||||
})
|
||||
|
||||
// Archivemylife on X (agy-cli's sibling): a list that isn't the account's
|
||||
// own, handed back as if it were, dropped the models the user picked
|
||||
test("a refusal in a 200 gives the static table marked as not the account's", async () => {
|
||||
fake.state.modelsCode = "100500"
|
||||
const p = { models: { ..._internal.STATIC_MODELS } }
|
||||
const list = await plugin.provider.models(p, { auth: saved })
|
||||
expect(Object.keys(list)).toEqual(Object.keys(_internal.STATIC_MODELS))
|
||||
expect(list[Symbol.for("magpie.fellBack")]).toBe(true)
|
||||
})
|
||||
|
||||
// plugins#1141: the host reads a listed model by OpenCode's shape
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@magpie-community/opencode-loomy-auth",
|
||||
"version": "0.1.9",
|
||||
"version": "0.1.10",
|
||||
"description": "OpenCode & Magpie provider plugin for Loomy (讯飞, loomyad.xunfei.cn): SMS sign-in, chat, models, the two point wallets and the daily first-login grant",
|
||||
"type": "module",
|
||||
"main": "./opencode.mjs",
|
||||
|
||||
Reference in New Issue
Block a user