@magpie-community/opencode-opendesign-auth 0.1.10 → 0.1.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -28,7 +28,7 @@ Open Design's cloud is two planes:
28
28
  | Plane | Host | Key | Used for |
29
29
  | --- | --- | --- | --- |
30
30
  | Control | `amr-api.open-design.ai` | `vela_ctrl_…` | plan, wallet balance, the Design Plan's allowance windows, the workspace |
31
- | Model | `amr-link.open-design.ai/v1` | `sk-amr-…` | `/models`, `/responses` (the OpenAI Responses API) |
31
+ | Model | `amr-link.open-design.ai/v1` | `sk-amr-…` | `/models`, `/chat/completions`, `/responses`, `/messages` |
32
32
 
33
33
  A sign-in is the same device authorization the Open Design CLI
34
34
  (`vela login`) runs:
@@ -120,6 +120,13 @@ for `claude-haiku-5.5` and `deepseek-v4-pro`, and Anthropic's messages
120
120
  (`@ai-sdk/anthropic`) for `glm-5.3-flash`. Every model reasons at `low`,
121
121
  `high` and `max`.
122
122
 
123
+ That API is each model's default, not the only one: amr-link serves every
124
+ model on all three (keyblues, plugins#888). A request for a model on another
125
+ of them is signed as that API takes the key — `x-api-key` on `/messages`,
126
+ `Authorization: Bearer` on `/chat/completions` and `/responses` — whatever
127
+ the model is declared on, so a model set to another API in magpie's model
128
+ editor works there too.
129
+
123
130
  ## Where the sign-in is kept
124
131
 
125
132
  magpie's `plugin-auth.json` (mode 600), as an oauth account:
package/index.mjs CHANGED
@@ -3,7 +3,8 @@
3
3
  // (amr-api.open-design.ai), which answers with two keys — a control key
4
4
  // (vela_ctrl_…) for the account's plan and its Design Plan allowance, and a
5
5
  // runtime key (sk-amr-…) that the model plane (amr-link.open-design.ai)
6
- // takes. Model requests are the OpenAI Responses API at the runtime key;
6
+ // takes. Model requests go there at the runtime key, on each model's own API
7
+ // (WIRE below) or any other of the three amr-link serves it on;
7
8
  // the model list, the plan and the 5-hour and 7-day allowance windows all
8
9
  // come from the control plane.
9
10
  //
@@ -41,6 +42,37 @@ const MODEL_WIRE = {
41
42
  "glm-5.3-flash": "anthropic",
42
43
  }
43
44
  const wireOf = (id) => WIRE[MODEL_WIRE[id]] ?? WIRE.chat
45
+ // The API a model is declared on is only its default: amr-link serves
46
+ // every model on all three (keyblues, plugins#888: each of the fourteen
47
+ // answered on chat completions and Responses at /v1 and on Anthropic's
48
+ // messages at the bare host, which the AI SDK asks at /v1/messages). A
49
+ // request can reach the plugin on another API than the declared one — magpie
50
+ // sends it there when the model is set to be asked on it — and the key
51
+ // rides as that API takes it, not as the declared package sends it: the
52
+ // host signs with the declared package's header (x-api-key for
53
+ // @ai-sdk/anthropic, Bearer for the others), so a chat model asked on
54
+ // /messages went with a Bearer and glm-5.3-flash asked on /chat/completions
55
+ // with an x-api-key. signFor reads the API off the request's path.
56
+ const MESSAGES = /\/messages(\/count_tokens)?\/?$/
57
+ const signFor = (key) => async (input, init = {}) => {
58
+ const url = input instanceof Request ? input.url : String(input)
59
+ const h = new Headers(init.headers ?? (input instanceof Request ? input.headers : undefined))
60
+ let path = ""
61
+ try {
62
+ path = new URL(url).pathname
63
+ } catch {}
64
+ if (MESSAGES.test(path)) {
65
+ h.delete("authorization")
66
+ h.set("x-api-key", key)
67
+ if (!h.has("anthropic-version")) h.set("anthropic-version", "2023-06-01")
68
+ } else {
69
+ h.delete("x-api-key")
70
+ h.set("authorization", `Bearer ${key}`)
71
+ }
72
+ // the global fetch as it is when the request is sent: the host's own,
73
+ // with its proxy and redirect rules, never one captured at load
74
+ return globalThis.fetch(input, { ...init, headers: h })
75
+ }
44
76
  // the provider's own default: a model this plugin doesn't name is asked on
45
77
  // chat completions, where ten of the eleven thought
46
78
  const NPM = WIRE.chat
@@ -280,6 +312,18 @@ function levelsOf(m) {
280
312
  return Array.isArray(m?.efforts) ? m.efforts.filter((e) => typeof e === "string" && e) : []
281
313
  }
282
314
 
315
+ // CAP is the most output a model may be asked for where amr-link's catalog
316
+ // (metadata.context_budget) says more than its API takes. Asking for more is
317
+ // a 400 "Open Design: The request could not be completed." that names no
318
+ // field, so nothing can lower it and retry. A client that names no limit
319
+ // (Codex) is given the published one by magpie, so every turn would fail
320
+ // (#827, Gitleonan, measured 2026-11-09 on two accounts): glm-5.3-flash took
321
+ // 131072 and refused 132000 (one account took 232000), and gemini-3.8-flash
322
+ // took 65536 and refused 65537 on both. The cap is applied here, not in
323
+ // models.mjs: the live catalog's number overrides the seed's (withSeed), and
324
+ // refresh-models.mjs writes the vendor's number back into the seed.
325
+ const CAP = { "glm-5.3-flash": 131072, "gemini-3.8-flash": 65536 }
326
+
283
327
  // modelOf turns one model's facts — models.mjs's, or amr-link's catalog
284
328
  // read again — into the model magpie shows, as the provider's config has
285
329
  // it. A model reasons when it has levels, or else when the vendor calls it
@@ -305,7 +349,7 @@ function modelOf(id, m) {
305
349
  ...(rate && { rate }),
306
350
  limit: {
307
351
  context: Number.isFinite(context) && context > 0 ? context : 200_000,
308
- output: Number.isFinite(output) && output > 0 ? output : 32_000,
352
+ output: Math.min(Number.isFinite(output) && output > 0 ? output : 32_000, CAP[id] ?? Infinity),
309
353
  },
310
354
  modalities: { input: ["text", ...input], output: ["text"] },
311
355
  }
@@ -480,7 +524,11 @@ export const OpenDesignAuthPlugin = async () => {
480
524
  const models = { ...seed(), ...(was.models ?? {}) }
481
525
  for (const [id, m] of Object.entries(models)) {
482
526
  const rate = RATES[id] === undefined ? undefined : "x" + RATES[id]
483
- models[id] = { ...m, api: { ...(m.api ?? {}), npm: wireOf(id) }, provider: { ...(m.provider ?? {}), npm: wireOf(id) }, ...(rate && { rate }) }
527
+ // a kept copy's limit is capped too: an earlier version wrote the
528
+ // catalog's 232000 for glm-5.3-flash, which amr-link refuses (CAP)
529
+ const out = Number(m.limit?.output)
530
+ const limit = CAP[id] && !(out > 0 && out <= CAP[id]) ? { limit: { ...(m.limit ?? {}), output: CAP[id] } } : {}
531
+ models[id] = { ...m, ...limit, api: { ...(m.api ?? {}), npm: wireOf(id) }, provider: { ...(m.provider ?? {}), npm: wireOf(id) }, ...(rate && { rate }) }
484
532
  }
485
533
  cfg.provider[ID] = {
486
534
  name: "Open Design",
@@ -512,7 +560,7 @@ export const OpenDesignAuthPlugin = async () => {
512
560
  loader: async (getAuth) => {
513
561
  const key = runtimeKeyOf(await getAuth().catch(() => null))
514
562
  if (!key) return {}
515
- return { baseURL: LINK, apiKey: key }
563
+ return { baseURL: LINK, apiKey: key, fetch: signFor(key) }
516
564
  },
517
565
  methods: [
518
566
  {
@@ -550,4 +598,4 @@ export const OpenDesignAuthPlugin = async () => {
550
598
 
551
599
  // _internal is what the tests read through; magpie calls every exported
552
600
  // function as a plugin, so only the plugin itself is exported bare.
553
- export const _internal = { authOf, allowances, controlKeyOf, credits, modelsOf, money, rateOf, runtimeKeyOf, said, startDevice, thePlan, usedPercent, waitForDevice, windowName, when, workspaceOf }
601
+ export const _internal = { authOf, signFor, allowances, controlKeyOf, credits, modelsOf, money, rateOf, runtimeKeyOf, said, startDevice, thePlan, usedPercent, waitForDevice, windowName, when, workspaceOf }
package/opencode2.mjs CHANGED
@@ -85,7 +85,6 @@ export function fieldsOf(prompts) {
85
85
  if (p.placeholder) f.placeholder = String(p.placeholder)
86
86
  if (p.type === "select" && Array.isArray(p.options))
87
87
  f.options = p.options.map((o) => ({ value: String(o.value), label: String(o.label ?? o.value), ...(o.hint ? { description: String(o.hint) } : {}) }))
88
- // a prompt shown only when another answer says so can't be required
89
88
  // a prompt shown only when another answer says so can't be required, and
90
89
  // neither can one whose own validate() accepts an empty answer (the
91
90
  // browser sign-in's optional API key)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@magpie-community/opencode-opendesign-auth",
3
- "version": "0.1.10",
3
+ "version": "0.1.12",
4
4
  "description": "Open Design Cloud (Design Plan) in OpenCode and magpie: the account's device sign-in, its models, and the plan's 5-hour and 7-day allowance",
5
5
  "type": "module",
6
6
  "main": "./opencode.mjs",