New package @magpie-community/opencode-inkstone-auth 0.1.0 for Intern InkStone (书生·端砚, Shanghai AI Lab) Token Plan, provider id `intern-inkstone`. Community package by yunwang2442-creator. What it does: - Browser sign-in (Edge/Chrome, its own profile under $XDG_CONFIG_HOME or ~/.config/magpie/inkstone-browser, or %LOCALAPPDATA%\magpie\inkstone-browser). The login window has no debugging port. A headless CDP read takes the uaa-token cookie, and the same read renews it silently later. - Usage card: ink-credit balance, 5-hour and 7-day windows, credit packs. - Chat: a pasted ink-* API key, or one the sign-in creates, named ink-<host4>-<acct4>-<rand4> (18 of the console's 20 characters). An idempotency clash (-15109) retries with a fresh name, up to three times. Pruning is on by default. It only touches this machine's and account's prefix, keeps the newest two and the key this sign-in created, and never deletes manual keys or keys of unknown age. - Closing on Unix: SIGTERM, then SIGKILL only after a 15s grace. Leftover browsers are matched by --user-data-dir=<escaped profile>, and Windows uses .Contains(). - The login wait comes from an injected waitForLogin in tests. No env hook is left in production code. - Hosts: discovery.intern-ai.org.cn, discovery-api.intern-ai.org.cn, 127.0.0.1 (CDP). Outside the package: scripts/opencode2.mjs lets a prompt with `required: false` stay optional (`p.required !== false`). Every package's copy is synced byte for byte, so all 39 copies in the merged tree are blobafe074cb. No other package sets `required: false` on a prompt, so this changes nothing for them. Also a root README row and a registry entry. Review at 36412a15, on mote, HOME=$(mktemp -d), Bun 1.4.2: - bun test packages/inkstone: 68 pass, 0 fail in Asia/Shanghai, UTC, America/Los_Angeles and Pacific/Kiritimati. - bun scripts/check.mjs inkstone and bun scripts/check.mjs: ok. - bun test (repo), on 36412a15 merged with origin/maine7cb9dc5: 6743 pass, 20 skip, 0 fail. main has since moved by cline 0.1.14 and zcode 0.1.55 only, and none of the adapter copies changed. - Broken by hand, each red: no protectName protection; prune_keys default off; no post-sign-in prune; no SIGTERM on close; the -15109 retry keeping its name. Not tried: a real InkStone account sign-in on macOS, Linux or Windows (no account here); a live chat request; magpie end to end with the plugin.
189 lines
7.3 KiB
JavaScript
189 lines
7.3 KiB
JavaScript
// The model catalogue: the live /v1/models set intersected with the public
|
|
// metadata, without the decision model and without thinking tiers (the
|
|
// platform documents that thinking cannot be turned on or off by request).
|
|
import "./nonet.mjs"
|
|
import { readFileSync } from "node:fs"
|
|
import { expect, test } from "bun:test"
|
|
import {
|
|
BOOT_MODELS,
|
|
DEFAULT_CONTEXT,
|
|
DEFAULT_OUTPUT,
|
|
bootModelOf,
|
|
bootModels,
|
|
createCatalog,
|
|
isChatCandidate,
|
|
mergeModel,
|
|
normalizePublic,
|
|
publicRowsOf,
|
|
} from "./lib/models.mjs"
|
|
|
|
const load = (name) => JSON.parse(readFileSync(new URL("./testdata/" + name, import.meta.url), "utf8"))
|
|
const META = publicRowsOf(load("public-models.json"))
|
|
|
|
test("the real public metadata has ten models, one of them a decision model", () => {
|
|
expect(META.length).toBe(10)
|
|
expect(META.filter((m) => m.type === "decision").map((m) => m.id)).toEqual(["intern-decision-4b"])
|
|
// four of the ten are free at the captured prices
|
|
expect(META.filter((m) => m.free).map((m) => m.id).sort()).toEqual([
|
|
"Agents-A1",
|
|
"Atria-Dawn",
|
|
"Sage-A1.5",
|
|
"intern-s2",
|
|
])
|
|
})
|
|
|
|
test("paid models carry a rate derived from the input price (1000 credits/1M = x1); free ones carry none", () => {
|
|
const rates = Object.fromEntries(META.filter((m) => m.rate).map((m) => [m.id, m.rate]))
|
|
expect(rates).toEqual({
|
|
"deepseek-v4.1-flash-1017": 1,
|
|
"glm-5.3": 8,
|
|
"intern-decision-4b": 0.2,
|
|
"kimi-k2.6": 6.5,
|
|
"minimax-m3": 2.1,
|
|
"qwen3.8-27b": 0.8,
|
|
})
|
|
for (const m of META.filter((m) => m.free)) expect(m.rate).toBeUndefined()
|
|
})
|
|
|
|
test("free and rate reach the merged model", () => {
|
|
const glm = mergeModel({ id: "glm-5.3" }, META.find((m) => m.id === "glm-5.3"))
|
|
expect(glm.rate).toBe(8)
|
|
expect(glm.free).toBeUndefined()
|
|
|
|
const sage = mergeModel({ id: "Sage-A1.5" }, META.find((m) => m.id === "Sage-A1.5"))
|
|
expect(sage.free).toBe(true)
|
|
expect(sage.rate).toBeUndefined()
|
|
})
|
|
|
|
test("a model keeps the catalogue's context and capability flags", () => {
|
|
const glm = mergeModel({ id: "glm-5.3" }, META.find((m) => m.id === "glm-5.3"))
|
|
expect(glm.name).toBe("GLM-5.3")
|
|
expect(glm.limit).toEqual({ context: 1048576, output: DEFAULT_OUTPUT })
|
|
expect(glm.reasoning).toBe(true)
|
|
expect(glm.tool_call).toBe(true)
|
|
expect(glm.capabilities.input.image).toBe(false)
|
|
// no variants: the platform publishes no thinking tiers it accepts.
|
|
expect(glm.variants).toBeUndefined()
|
|
|
|
const agents = mergeModel({ id: "Agents-A1" }, META.find((m) => m.id === "Agents-A1"))
|
|
expect(agents.limit.context).toBe(262144)
|
|
expect(agents.reasoning).toBe(false)
|
|
expect(agents.tool_call).toBe(true)
|
|
expect(agents.capabilities.input.image).toBe(true)
|
|
expect(agents.modalities.input).toEqual(["text", "image"])
|
|
})
|
|
|
|
test("a model outside the metadata is kept from the live list with safe defaults", () => {
|
|
const m = mergeModel({ id: "brand-new-model", context: 131072, features: ["tools", "reasoning"] }, undefined)
|
|
expect(m.name).toBe("brand-new-model")
|
|
expect(m.limit.context).toBe(131072)
|
|
expect(m.limit.output).toBe(DEFAULT_OUTPUT)
|
|
expect(m.reasoning).toBe(true)
|
|
expect(m.tool_call).toBe(true)
|
|
})
|
|
|
|
test("the decision model is never a chat candidate", () => {
|
|
const decision = META.find((m) => m.id === "intern-decision-4b")
|
|
expect(isChatCandidate({ id: "intern-decision-4b" }, decision)).toBe(false)
|
|
// a model that only speaks Anthropic is not chat
|
|
const anth = { id: "x", type: "chat", protocols: new Set(["anthropic_messages"]) }
|
|
expect(isChatCandidate({ id: "x" }, anth)).toBe(false)
|
|
// no metadata: the live /v1/models data[] is generative by definition
|
|
expect(isChatCandidate({ id: "x" }, undefined)).toBe(true)
|
|
})
|
|
|
|
test("the catalogue intersects the key's list with the metadata and drops the decision model", async () => {
|
|
const live = [
|
|
{ id: "glm-5.3" },
|
|
{ id: "Agents-A1" },
|
|
{ id: "intern-decision-4b" },
|
|
{ id: "brand-new-model" },
|
|
]
|
|
const catalog = createCatalog({
|
|
fetchLive: async () => live,
|
|
fetchMeta: async () => META,
|
|
})
|
|
const rows = await catalog.forKey("sk-test")
|
|
expect(rows.map((r) => r.id)).toEqual(["glm-5.3", "Agents-A1", "brand-new-model"])
|
|
})
|
|
|
|
test("a live read that fails keeps the last successful list for that key", async () => {
|
|
let fail = false
|
|
const catalog = createCatalog({
|
|
fetchLive: async () => {
|
|
if (fail) throw new Error("HTTP 500")
|
|
return [{ id: "glm-5.3" }]
|
|
},
|
|
fetchMeta: async () => META,
|
|
})
|
|
expect((await catalog.forKey("k")).map((r) => r.id)).toEqual(["glm-5.3"])
|
|
fail = true
|
|
expect((await catalog.forKey("k")).map((r) => r.id)).toEqual(["glm-5.3"])
|
|
})
|
|
|
|
test("an empty answer is cached briefly and gives no models, not the bootstrap set", async () => {
|
|
const catalog = createCatalog({
|
|
fetchLive: async () => [],
|
|
fetchMeta: async () => META,
|
|
})
|
|
expect(await catalog.forKey("k")).toEqual([])
|
|
expect(await catalog.forKey("k")).toEqual([])
|
|
})
|
|
|
|
test("the bootstrap list is non-empty, every entry has a usable limit and its price tier", () => {
|
|
const boot = bootModels()
|
|
expect(Object.keys(boot).length).toBeGreaterThan(0)
|
|
expect(Object.keys(boot)).toEqual(Object.keys(BOOT_MODELS))
|
|
for (const [id, m] of Object.entries(boot)) {
|
|
expect(m.limit.context).toBeGreaterThan(0)
|
|
expect(m.limit.output).toBe(DEFAULT_OUTPUT)
|
|
expect(m.variants).toBeUndefined()
|
|
if (BOOT_MODELS[id].free) {
|
|
expect(m.free).toBe(true)
|
|
expect(m.rate).toBeUndefined()
|
|
} else {
|
|
expect(m.free).toBeUndefined()
|
|
expect(m.rate).toBeGreaterThan(0)
|
|
}
|
|
}
|
|
})
|
|
|
|
test("the bootstrap list agrees with the captured catalogue on every id it shares", () => {
|
|
const byId = new Map(META.map((m) => [m.id, m]))
|
|
for (const [id, boot] of Object.entries(BOOT_MODELS)) {
|
|
const meta = byId.get(id)
|
|
expect(meta).toBeDefined()
|
|
// free/rate must not contradict the live prices: a bootstrap entry claiming
|
|
// free for a priced model would show a "free" badge on a paid model.
|
|
expect(Boolean(boot.free)).toBe(Boolean(meta.free))
|
|
if (!boot.free) expect(boot.rate).toBe(meta.rate)
|
|
}
|
|
})
|
|
|
|
test("a metadata row without prices is not marked free", () => {
|
|
const bare = normalizePublic({ id: "no-prices", display_name: "No Prices" })
|
|
expect(bare.id).toBe("no-prices")
|
|
expect(bare.free).toBeUndefined()
|
|
expect(bare.rate).toBeUndefined()
|
|
// a zero price on both sides is free
|
|
const free = normalizePublic({ id: "zero", input_uncached_price: 0, output_price: 0 })
|
|
expect(free.free).toBe(true)
|
|
// a zero input but a priced output is not free
|
|
const outOnly = normalizePublic({ id: "out", input_uncached_price: 0, output_price: 5 })
|
|
expect(outOnly.free).toBe(false)
|
|
// an empty string, junk or a negative number is a missing price, not 0
|
|
expect(normalizePublic({ id: "dirty", input_uncached_price: "", output_price: "" }).free).toBeUndefined()
|
|
expect(normalizePublic({ id: "dirty2", input_uncached_price: -5, output_price: 0 }).free).toBeUndefined()
|
|
expect(normalizePublic({ id: "dirty3", input_uncached_price: "n/a", output_price: 0 }).free).toBeUndefined()
|
|
// junk rows do not throw
|
|
expect(normalizePublic(null)).toBeNull()
|
|
expect(normalizePublic({})).toBeNull()
|
|
expect(normalizePublic({ id: 42 })).toBeNull()
|
|
})
|
|
|
|
test("mergeModel survives two empty sides", () => {
|
|
expect(mergeModel(null, null)).toBeNull()
|
|
expect(mergeModel({}, {})).toBeNull()
|
|
expect(bootModelOf("no-such-model")).toBeNull()
|
|
})
|