@magpie-community/opencode-opendesign-auth 0.1.11 → 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.
Files changed (3) hide show
  1. package/README.md +8 -1
  2. package/index.mjs +35 -3
  3. package/package.json +1 -1
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
@@ -528,7 +560,7 @@ export const OpenDesignAuthPlugin = async () => {
528
560
  loader: async (getAuth) => {
529
561
  const key = runtimeKeyOf(await getAuth().catch(() => null))
530
562
  if (!key) return {}
531
- return { baseURL: LINK, apiKey: key }
563
+ return { baseURL: LINK, apiKey: key, fetch: signFor(key) }
532
564
  },
533
565
  methods: [
534
566
  {
@@ -566,4 +598,4 @@ export const OpenDesignAuthPlugin = async () => {
566
598
 
567
599
  // _internal is what the tests read through; magpie calls every exported
568
600
  // function as a plugin, so only the plugin itself is exported bare.
569
- 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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@magpie-community/opencode-opendesign-auth",
3
- "version": "0.1.11",
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",