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.
104 lines
3.1 KiB
JavaScript
104 lines
3.1 KiB
JavaScript
// A fake of the InkStone console and API for the tests: one local server
|
|
// standing in for the console, its credit APIs and the OpenAI-compatible
|
|
// catalogue, which the plugin's ENDPOINTS are pointed at. route(method, path)
|
|
// answers a request; seen lists what came.
|
|
import { _internal } from "./index.mjs"
|
|
|
|
export function fakeInkStone() {
|
|
const routes = new Map()
|
|
const seen = []
|
|
const server = Bun.serve({
|
|
port: 0,
|
|
hostname: "127.0.0.1",
|
|
async fetch(req) {
|
|
const url = new URL(req.url)
|
|
const text = await req.text()
|
|
const r = {
|
|
method: req.method,
|
|
path: url.pathname,
|
|
query: url.searchParams,
|
|
headers: req.headers,
|
|
text,
|
|
url: url.pathname + url.search,
|
|
}
|
|
if ((req.headers.get("content-type") ?? "").includes("x-www-form-urlencoded")) {
|
|
r.form = Object.fromEntries(new URLSearchParams(text))
|
|
} else if (text) {
|
|
try {
|
|
r.json = JSON.parse(text)
|
|
} catch {}
|
|
}
|
|
seen.push(r)
|
|
const h = routes.get(req.method + " " + url.pathname)
|
|
if (!h) return new Response("no route " + req.method + " " + url.pathname, { status: 404 })
|
|
return h(r)
|
|
},
|
|
})
|
|
const origin = `http://127.0.0.1:${server.port}`
|
|
const was = { ..._internal.ENDPOINTS }
|
|
Object.assign(_internal.ENDPOINTS, {
|
|
console: origin,
|
|
api: origin + "/v1",
|
|
})
|
|
return {
|
|
origin,
|
|
seen,
|
|
route: (key, h) => routes.set(key, h),
|
|
close() {
|
|
server.stop(true)
|
|
Object.assign(_internal.ENDPOINTS, was)
|
|
},
|
|
}
|
|
}
|
|
|
|
export const json = (v, status = 200) =>
|
|
new Response(JSON.stringify(v), { status, headers: { "content-type": "application/json" } })
|
|
|
|
/** A console success envelope. */
|
|
export const ok = (data) => json({ code: 0, msg: "success", data })
|
|
|
|
/** A console failure envelope: HTTP 200 with a negative code, as the site sends. */
|
|
export const fail = (code, msg) => json({ code, msg, data: null })
|
|
|
|
/** A JWT with the given claims (the console's uaa-token is treated as one). */
|
|
export const jwtOf = (claims) =>
|
|
["e30", Buffer.from(JSON.stringify(claims)).toString("base64url"), "sig"].join(".")
|
|
|
|
export function poolUsageFixture() {
|
|
return {
|
|
available_credits: 10,
|
|
active_package_count: 2,
|
|
rpm_limit: 50,
|
|
decision_rpm_limit: 200,
|
|
tpm_limit: 2_000_000,
|
|
usage_windows: {
|
|
"5h": { enabled: true, limit_credits: 10, remaining_credits: 6.5, next_recover_at: "2026-11-05T08:00:00Z" },
|
|
"7d": { enabled: true, limit_credits: 50, remaining_credits: 41.2, next_recover_at: "2026-11-10T08:00:00Z" },
|
|
},
|
|
}
|
|
}
|
|
|
|
export function packagesFixture() {
|
|
return {
|
|
total: 2,
|
|
packages: [
|
|
{
|
|
pkg_id: "pkg-1",
|
|
status: "available",
|
|
remaining_credits: 6.5,
|
|
total_credits: 10,
|
|
current_cycle: { start_at: "2026-11-01T00:00:00Z", end_at: "2026-11-28T12:00:00Z" },
|
|
remark: "每月免费基础包",
|
|
},
|
|
{
|
|
pkg_id: "pkg-2",
|
|
status: "unused",
|
|
remaining_credits: 50,
|
|
total_credits: 50,
|
|
current_cycle: { start_at: "2026-11-01T00:00:00Z", end_at: "2026-12-28T00:00:00Z" },
|
|
remark: "扩容包",
|
|
},
|
|
],
|
|
}
|
|
}
|