openkodo 0.2.3 → 0.3.1

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/CHANGELOG.md CHANGED
@@ -1,7 +1,29 @@
1
1
  # Changelog
2
2
 
3
- All notable changes to this package. Versioned independently of the OpenKodo
4
- gateway.
3
+ All notable changes to this package. Versioned independently of OpenKodo.
4
+
5
+ ## 0.3.1
6
+
7
+ - Render the 5-hour, 7-day and monthly windows as **plan credits**, not USD.
8
+ - Add an estimated "requests left" to the 5-hour window based on the account's
9
+ recent average credit per request, so large agent requests are legible.
10
+ - Set `limit.input` to 200k on long-context models so agent hosts compact
11
+ before a single prompt consumes a large share of the 5-hour credit cap.
12
+ - Document plan credits vs dollars and the early-compaction behavior.
13
+
14
+ ## 0.3.0
15
+
16
+ - Show the reasoning levels each model declares in `GET /v1/models`
17
+ (`low`/`medium`/`high`/`max`, and `none` where the model offers an off
18
+ switch) instead of dropping `reasoning.efforts`.
19
+ - Merge the authenticated descriptor with the public catalog so names, limits
20
+ and prices stay available.
21
+ - Move model limits into the `limit: { context, output }` shape Magpie reads,
22
+ while keeping the older top-level fields for OpenCode 1.x.
23
+ - Fix usage windows: `used` is now a percentage, `amount` is the used value,
24
+ `limit` is the cap, `unit` identifies the window's unit, and `span` is seconds.
25
+ - Rename the public repository to **OpenKodo Magpie Plugin**; the Magpie row
26
+ still displays **OpenKodo**.
5
27
 
6
28
  ## 0.2.3
7
29
 
package/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # OpenKodo plugin
1
+ # OpenKodo Magpie Plugin
2
2
 
3
3
  Provider plugin that puts [OpenKodo](https://openkodo.dev) into Magpie and
4
4
  OpenCode: plans, credits, usage windows, and the live model catalog.
@@ -8,15 +8,30 @@ Provider id: `openkodo`.
8
8
 
9
9
  - Plan name and the OpenKodo mark
10
10
  - Three rolling spend windows, shortest first: **5 hours**, **7 days**, and the
11
- **monthly** pool — each with the amount used, the cap, and when it frees up
11
+ **monthly** pool — each with the amount used, the cap, and when it frees up.
12
+ These are **plan credits**, not dollars.
12
13
  - The per-model 5-hour request guardrail
14
+ - Early compaction: `limit.input` is 200k even for 1M-context models, so an
15
+ agent compacts before a single prompt eats a large share of the 5h cap
16
+ - Thinking levels for every model that declares them, taken from the
17
+ authenticated `GET /v1/models` descriptor
13
18
  - The live catalog from [`/api/public/models`](https://api.openkodo.dev/api/public/models)
14
19
 
15
- The 5-hour and 7-day windows are enforced by the gateway, not decoration:
20
+ The 5-hour and 7-day windows are enforced by OpenKodo, not decoration:
16
21
  Go is $25 / 5h and $50 / 7d, Pro is $50 / 5h and $100 / 7d. Reset times are
17
22
  rolling — the cap frees up when the oldest spend in the window ages out — so
18
23
  they move as new requests arrive.
19
24
 
25
+ ## Plan credits
26
+
27
+ Plans give a credit pool: Go 100, Pro 250, Max 1,250. The 5-hour, 7-day and
28
+ monthly windows in the card are **plan credits**, not dollars.
29
+
30
+ The 5-hour window also estimates **how many requests are left** at your recent
31
+ average credit per request. If that number is small, compact the conversation
32
+ or switch to a lighter model rather than topping up. Large prompts consume
33
+ credits much faster than small ones.
34
+
20
35
  ## Install
21
36
 
22
37
  From the magpie plugin store, search for **OpenKodo**.
@@ -43,12 +58,16 @@ the key itself, and it never creates keys, changes plans, or spends credits.
43
58
  ## Development
44
59
 
45
60
  ```bash
46
- npm test # unit tests, no network
47
- npm run pack:check # what would be published
61
+ npm test # unit tests, no network
62
+ npm run check:public # release gate: no credentials, backend details or pricing internals
63
+ npm run pack:check # public-surface check + what would be published
48
64
  ```
49
65
 
50
66
  The tests stub `fetch`, so they never use a real API key.
51
67
 
68
+ See [PUBLISHING.md](./PUBLISHING.md) for the private denylist and the release
69
+ checklist.
70
+
52
71
  ## License
53
72
 
54
73
  [MIT](./LICENSE)
package/index.mjs CHANGED
@@ -10,33 +10,75 @@ const ICON = "https://openkodo.dev/favicon.svg"
10
10
  const PUBLIC_MODELS = "https://api.openkodo.dev/api/public/models"
11
11
  const USAGE = "https://api.openkodo.dev/api/plugin/usage"
12
12
 
13
- // The gateway's windows are rolling, not calendar-based, so the reset time is
13
+ // OpenKodo's windows are rolling, not calendar-based, so the reset time is
14
14
  // when the oldest spend in the window falls out — not a fixed midnight.
15
15
  const FIVE_HOURS = 5 * 60 * 60_000
16
16
  const SEVEN_DAYS = 7 * 24 * 60 * 60_000
17
+ // Agent hosts compact when the input reaches limit.input. A 1M-context model
18
+ // with no input limit lets an agent grow the prompt far beyond a typical turn.
19
+ // 200k keeps long-context capability but compacts early enough to stay economical.
20
+ const COMPACT_AT = 200_000
17
21
 
18
- // Offline fallback only. The live /api/public/models response is authoritative;
22
+ // Offline fallback only. The live model catalogs are authoritative;
19
23
  // these are the official standard (off-peak) USD list rates.
20
24
  const FALLBACK = {
21
- "deepseek-v4.1-flash": { name: "DeepSeek V4.1 Flash", context: 1_000_000, output: 65_536, input: 0.15, outputPrice: 0.6, cache: 0.003 },
22
- "deepseek-v4.1-pro": { name: "DeepSeek V4 Pro 0813", context: 1_000_000, output: 131_072, input: 0.66, outputPrice: 1.98, cache: 0.022 },
23
- "glm-5.3": { name: "GLM-5.3", context: 1_000_000, output: 131_072, input: 1.4, outputPrice: 4.4, cache: 0.26 },
24
- "glm-5.3-flash": { name: "GLM-5.3 Flash", context: 1_000_000, output: 131_072, input: 0.15, outputPrice: 0.5, cache: 0.03 },
25
+ "deepseek-v4.1-flash": { name: "DeepSeek V4.1 Flash", context: 1_000_000, output: 65_536, input: 0.15, outputPrice: 0.6, cache: 0.003, efforts: ["none", "low", "high", "max"] },
26
+ "deepseek-v4.1-pro": { name: "DeepSeek V4 Pro 0813", context: 1_000_000, output: 131_072, input: 0.66, outputPrice: 1.98, cache: 0.022, efforts: ["none", "low", "high", "max"] },
27
+ "glm-5.3": { name: "GLM-5.3", context: 1_000_000, output: 131_072, input: 1.4, outputPrice: 4.4, cache: 0.26, efforts: ["low", "medium", "high"] },
28
+ "glm-5.3-flash": { name: "GLM-5.3 Flash", context: 1_000_000, output: 131_072, input: 0.15, outputPrice: 0.5, cache: 0.03, efforts: ["low", "medium", "high"] },
25
29
  "kimi-k3.1-pro": { name: "Kimi K3.1 Pro", context: 1_000_000, output: 131_072, input: 2.0, outputPrice: 10.0, cache: 0.2 },
26
30
  "qwen3.8-max": { name: "Qwen3.8 Max", context: 1_000_000, output: 131_072, input: 2.0, outputPrice: 6.0, cache: 0.25 },
27
31
  "MiniMax-M3": { name: "MiniMax M3", context: 1_000_000, output: 131_072, input: 0.6, outputPrice: 2.4, cache: 0.12 },
28
32
  }
29
33
 
34
+ const effortsOf = (m) => {
35
+ const list = m?.reasoning?.efforts ?? m?.reasoning_efforts
36
+ return Array.isArray(list) ? list.map(String).filter(Boolean) : []
37
+ }
38
+
39
+ // Magpie turns each variant into an OpenCode reasoning level. "none" is a
40
+ // real level for the DeepSeek models, so it stays in the list: selecting it
41
+ // is the off switch.
42
+ const variantsOf = (efforts) =>
43
+ Object.fromEntries(efforts.map((effort) => [effort, { reasoningEffort: effort }]))
44
+
45
+ const modalitiesOf = (m) => {
46
+ const input = m?.architecture?.input_modalities
47
+ return Array.isArray(input) && input.length ? input.map(String) : ["text"]
48
+ }
49
+
50
+ const modelRecord = ({ name, context, output, input, outputPrice, cache, efforts, inputModalities, reasoning }) => {
51
+ const levels = efforts ?? []
52
+ const thinks = reasoning ?? levels.length > 0
53
+ const ctx = context || 1_000_000
54
+ return {
55
+ name,
56
+ limit: { context: ctx, input: Math.min(ctx, COMPACT_AT), output: output || 131_072 },
57
+ cost: { input, output: outputPrice, cache: { read: cache } },
58
+ tool_call: true,
59
+ attachment: inputModalities.includes("image"),
60
+ modalities: { input: inputModalities.length ? inputModalities : ["text"], output: ["text"] },
61
+ // OpenCode reads `reasoning`/`variants`; magpie's internalOf folds them
62
+ // into capabilities.reasoning. Both hosts then see the same levels.
63
+ ...(thinks ? { reasoning: true } : {}),
64
+ ...(levels.length ? { variants: variantsOf(levels) } : {}),
65
+ }
66
+ }
67
+
30
68
  const fallbackModels = () =>
31
69
  Object.fromEntries(
32
70
  Object.entries(FALLBACK).map(([id, m]) => [
33
71
  id,
34
- {
72
+ modelRecord({
35
73
  name: m.name,
36
74
  context: m.context,
37
75
  output: m.output,
38
- cost: { input: m.input, output: m.outputPrice, cache: { read: m.cache } },
39
- },
76
+ input: m.input,
77
+ outputPrice: m.outputPrice,
78
+ cache: m.cache,
79
+ efforts: m.efforts,
80
+ inputModalities: ["text"],
81
+ }),
40
82
  ]),
41
83
  )
42
84
 
@@ -55,30 +97,82 @@ async function fetchUsage(key) {
55
97
  return body
56
98
  }
57
99
 
58
- async function fetchModels() {
59
- const res = await fetch(PUBLIC_MODELS, { headers: { Accept: "application/json" } })
100
+ async function fetchModelList(url, headers, signal) {
101
+ const res = await fetch(url, { headers, signal })
60
102
  if (!res.ok) throw new Error(`OpenKodo model list failed (${res.status})`)
61
103
  const body = await res.json()
104
+ const models = body?.data ?? body?.models
105
+ if (!Array.isArray(models)) throw new Error("OpenKodo model list was not valid")
106
+ return models.filter(m => typeof (m?.code || m?.id) === "string" && (m.code || m.id).trim())
107
+ }
108
+
109
+ async function fetchModels(key, signal) {
110
+ // The account list supplies efforts and available IDs. The public catalog
111
+ // supplies prices and limits even when /v1/models only gives descriptors.
112
+ const [accountResult, publicResult] = await Promise.allSettled([
113
+ key
114
+ ? fetchModelList(`${BASE}/models`, { Authorization: `Bearer ${key}`, Accept: "application/json" }, signal)
115
+ : Promise.resolve([]),
116
+ fetchModelList(PUBLIC_MODELS, { Accept: "application/json" }, signal),
117
+ ])
118
+ const account = accountResult.status === "fulfilled" ? accountResult.value : []
119
+ const catalog = publicResult.status === "fulfilled" ? publicResult.value : []
120
+ const byID = new Map(catalog.map(m => [m.code || m.id, m]))
121
+ const models = account.length ? account : catalog
122
+ if (!models.length) throw new Error("OpenKodo model list was empty or unavailable")
62
123
  const out = {}
63
- for (const m of body.models || []) {
64
- if (!m?.code) continue
65
- out[m.code] = {
66
- name: m.name || m.code,
67
- context: m.context_window || 1_000_000,
68
- output: m.max_output || 131_072,
124
+ for (const descriptor of models) {
125
+ const id = descriptor.code || descriptor.id
126
+ const m = { ...byID.get(id), ...descriptor }
127
+ const declared = m.reasoning?.efforts ?? m.reasoning_efforts
128
+ const efforts = Array.isArray(declared) ? [...new Set(declared.filter(e => typeof e === "string" && e.trim()))] : []
129
+ const reasoning = efforts.length > 0 || m.reasoning === true || m.reasoning?.supported === true
130
+ || m.capabilities?.reasoning === true || (Array.isArray(m.capabilities) && m.capabilities.includes("reasoning"))
131
+ // `limit` is the shape OpenCode/Magpie read. Keep context/output at the
132
+ // top level too: older OpenCode hosts read those.
133
+ const context = m.context_length ?? m.limit?.context ?? m.context_window ?? 1_000_000
134
+ const output = m.max_completion_tokens ?? m.max_output_tokens ?? m.limit?.output ?? m.max_output ?? 131_072
135
+ const inputModalities = modalitiesOf(m)
136
+ const inputLimit = Math.min(context, COMPACT_AT)
137
+ out[id] = {
138
+ name: m.name || id,
139
+ context,
140
+ output,
141
+ limit: { context, input: inputLimit, output },
142
+ // Config readers use the top-level flag. Model hooks use capabilities.
143
+ reasoning,
144
+ capabilities: {
145
+ reasoning,
146
+ toolcall: true,
147
+ attachment: inputModalities.includes("image"),
148
+ input: Object.fromEntries(["text", "image", "audio", "video", "pdf"].map((k) => [k, inputModalities.includes(k)])),
149
+ output: { text: true, image: false, audio: false, video: false, pdf: false },
150
+ },
151
+ modalities: { input: inputModalities, output: ["text"] },
152
+ tool_call: true,
153
+ attachment: inputModalities.includes("image"),
154
+ ...(efforts.length ? { variants: variantsOf(efforts) } : {}),
69
155
  cost: {
70
- // Show the standard (off-peak) rate the gateway charges most of the
71
- // day, not the peak rate stored in the primary columns.
156
+ // Show the standard (off-peak) list rate for most of the day, not the
157
+ // peak rate.
72
158
  input: Number(m.offpeak_input_price_micros_per_mtok || m.input_price_micros_per_mtok || 0) / 1_000_000,
73
159
  output: Number(m.offpeak_output_price_micros_per_mtok || m.output_price_micros_per_mtok || 0) / 1_000_000,
74
160
  cache: { read: Number(m.offpeak_cached_input_price_micros_per_mtok || m.cached_input_price_micros_per_mtok || 0) / 1_000_000 },
75
161
  },
76
162
  }
77
163
  }
164
+
78
165
  return Object.keys(out).length ? out : fallbackModels()
79
166
  }
80
167
 
81
- export const OpenKodoAuthPlugin = async () => ({
168
+ export const OpenKodoAuthPlugin = async () => {
169
+ // The last key the host validated. provider.models() has no credential
170
+ // argument, so this is what lets it read the authenticated descriptor (the
171
+ // only source that carries reasoning.efforts) instead of the public
172
+ // catalog. Per plugin instance, so tests and hosts never share a key.
173
+ let sessionKey = ""
174
+
175
+ return {
82
176
  config: async (cfg) => {
83
177
  cfg.provider ??= {}
84
178
  const p = (cfg.provider[ID] ??= {})
@@ -91,9 +185,9 @@ export const OpenKodoAuthPlugin = async () => ({
91
185
 
92
186
  provider: {
93
187
  id: ID,
94
- async models(provider) {
188
+ async models(provider, { auth, signal } = {}) {
95
189
  try {
96
- return await fetchModels()
190
+ return await fetchModels(keyOf(auth) || sessionKey, signal)
97
191
  } catch {
98
192
  return provider?.models && Object.keys(provider.models).length ? provider.models : fallbackModels()
99
193
  }
@@ -126,6 +220,7 @@ export const OpenKodoAuthPlugin = async () => ({
126
220
  try {
127
221
  const usage = await fetchUsage(key)
128
222
  if (!usage?.plan) throw new Error("OpenKodo usage response was not valid")
223
+ sessionKey = key
129
224
  return {
130
225
  type: "success",
131
226
  key,
@@ -142,6 +237,7 @@ export const OpenKodoAuthPlugin = async () => ({
142
237
  const auth = await getAuth()
143
238
  const key = keyOf(auth)
144
239
  if (!key) return {}
240
+ sessionKey = key
145
241
  return { baseURL: BASE, apiKey: key }
146
242
  },
147
243
 
@@ -151,69 +247,100 @@ export const OpenKodoAuthPlugin = async () => ({
151
247
  if (!key) return { error: "not signed in", signIn: "expired" }
152
248
  try {
153
249
  const d = await fetchUsage(key)
154
- // Cents, not raw division: $26.599999999999994 must render as $26.60.
155
- const usd = (micros) => Math.round(Number(micros || 0) / 10_000) / 100
156
- const remaining = usd(d.credits_remaining_micros)
157
- const included = usd(d.credits_included_micros)
158
- const spent = Math.max(0, included - remaining)
159
- const used5h = usd(d.cost_5h_micros)
160
- const cap5h = usd(d.credits_per_5h_micros)
161
- const used7d = usd(d.cost_7d_micros)
162
- const cap7d = usd(d.credits_per_week_micros)
250
+ // Plan credits are OpenKodo's usage unit, not dollars.
251
+ const credits = (micros) => Math.round(Number(micros || 0) / 10_000) / 100
252
+ const remaining = credits(d.credits_remaining_micros)
253
+ const included = credits(d.credits_included_micros)
254
+ const spent = Math.max(0, Math.round((included - remaining) * 100) / 100)
255
+ const used5h = credits(d.cost_5h_micros)
256
+ const cap5h = credits(d.credits_per_5h_micros)
257
+ const used7d = credits(d.cost_7d_micros)
258
+ const cap7d = credits(d.credits_per_week_micros)
259
+ // The card can estimate how many requests are left at the account's
260
+ // current burn rate. This makes a large agent request legible.
261
+ const requests5h = Number(d.requests_5h ?? d.model_window?.used ?? 0)
262
+ const avgCredit5h = requests5h > 0 ? used5h / requests5h : 0
263
+ const requestsLeft5h = avgCredit5h > 0 ? Math.max(0, Math.floor((cap5h - used5h) / avgCredit5h)) : null
163
264
  const periodEnd = d.period_end ? new Date(d.period_end).toISOString() : undefined
164
265
  // Each window is rolling: the cap frees up when the oldest spend in it
165
266
  // ages out. A window with no spend has nothing to expire.
166
267
  const rollingReset = (oldest, span) =>
167
268
  oldest ? new Date(new Date(oldest).getTime() + span).toISOString() : undefined
269
+
270
+ // Magpie's UsageWindow contract: `used` is a 0–100 percentage,
271
+ // `amount` is the used count in the window's unit, `limit` is the
272
+ // cap, and `span` is in seconds. Credits are the plan's unit.
273
+ const windowOf = (name, amount, limit, unit, extra = {}) => {
274
+ if (!(limit > 0)) return null
275
+ return {
276
+ name,
277
+ used: Math.round(Math.min(100, Math.max(0, (100 * amount) / limit)) * 100) / 100,
278
+ amount,
279
+ limit,
280
+ unit,
281
+ ...extra,
282
+ }
283
+ }
284
+ const window5h = cap5h > 0
285
+ ? windowOf("5 hours", used5h, cap5h, "credits", {
286
+ span: FIVE_HOURS / 1000,
287
+ display: `${used5h.toFixed(2)} / ${cap5h.toFixed(2)} credits${requestsLeft5h !== null ? ` · ~${requestsLeft5h.toLocaleString()} left` : ""}`,
288
+ ...(requestsLeft5h !== null ? {
289
+ note: `At your recent average of ${avgCredit5h.toFixed(2)} credits per request, about ${requestsLeft5h.toLocaleString()} requests remain in this window.`,
290
+ } : {}),
291
+ ...(rollingReset(d.oldest_5h, FIVE_HOURS) ? { resetsAt: rollingReset(d.oldest_5h, FIVE_HOURS) } : {}),
292
+ })
293
+ : null
294
+ const window7d = cap7d > 0
295
+ ? windowOf("7 days", used7d, cap7d, "credits", {
296
+ span: SEVEN_DAYS / 1000,
297
+ display: `${used7d.toFixed(2)} / ${cap7d.toFixed(2)} credits`,
298
+ ...(rollingReset(d.oldest_7d, SEVEN_DAYS) ? { resetsAt: rollingReset(d.oldest_7d, SEVEN_DAYS) } : {}),
299
+ })
300
+ : null
301
+ const monthWindow = included > 0
302
+ ? windowOf("Month", spent, included, "credits", {
303
+ display: `${remaining.toFixed(2)} credits left of ${included.toFixed(2)}`,
304
+ ...(periodEnd ? { resetsAt: periodEnd } : {}),
305
+ })
306
+ : {
307
+ // Welcome-credit accounts have no monthly plan credits, so a percentage
308
+ // against $0 would be nonsense. Magpie's balance-shaped window
309
+ // says exactly what is left.
310
+ name: "Month",
311
+ balance: remaining,
312
+ unit: "credits",
313
+ display: `${remaining.toFixed(2)} credits remaining`,
314
+ }
315
+ const requestUsed = Number(d.model_window?.used ?? d.requests_5h ?? 0)
316
+ const requestLimit = Number(d.model_window?.limit ?? d.requests_limit_5h ?? 0)
317
+ const requestWindow = windowOf(
318
+ d.model_window?.model ? `Requests / 5h · ${d.model_window.model}` : "Requests / 5h",
319
+ requestUsed,
320
+ requestLimit,
321
+ "requests",
322
+ {
323
+ span: FIVE_HOURS / 1000,
324
+ display: `${requestUsed.toLocaleString()} / ${requestLimit.toLocaleString()}`,
325
+ ...(d.model_window?.model ? { models: [d.model_window.model] } : {}),
326
+ },
327
+ )
168
328
  return {
169
329
  plan: d.plan,
170
330
  user: d.email,
171
331
  windows: [
172
- ...(cap5h > 0
173
- ? [{
174
- name: "5 hours",
175
- used: used5h,
176
- limit: cap5h,
177
- span: FIVE_HOURS,
178
- display: `$${used5h.toFixed(2)} / $${cap5h.toFixed(2)}`,
179
- ...(rollingReset(d.oldest_5h, FIVE_HOURS) ? { resetsAt: rollingReset(d.oldest_5h, FIVE_HOURS) } : {}),
180
- }]
181
- : []),
182
- ...(cap7d > 0
183
- ? [{
184
- name: "7 days",
185
- used: used7d,
186
- limit: cap7d,
187
- span: SEVEN_DAYS,
188
- display: `$${used7d.toFixed(2)} / $${cap7d.toFixed(2)}`,
189
- ...(rollingReset(d.oldest_7d, SEVEN_DAYS) ? { resetsAt: rollingReset(d.oldest_7d, SEVEN_DAYS) } : {}),
190
- }]
191
- : []),
192
- {
193
- name: "Month",
194
- used: spent,
195
- limit: included,
196
- // Welcome-credit accounts have no plan pool, so "left of $0.00"
197
- // would be nonsense. Show what they actually have.
198
- display: included > 0
199
- ? `$${remaining.toFixed(2)} left of $${included.toFixed(2)}`
200
- : `$${remaining.toFixed(2)} remaining`,
201
- ...(periodEnd ? { resetsAt: periodEnd } : {}),
202
- },
203
- {
204
- name: d.model_window?.model ? `Requests / 5h · ${d.model_window.model}` : "Requests / 5h",
205
- used: Number(d.model_window?.used ?? d.requests_5h ?? 0),
206
- limit: Number(d.model_window?.limit ?? d.requests_limit_5h ?? 0),
207
- display: `${Number(d.model_window?.used ?? d.requests_5h ?? 0).toLocaleString()} / ${Number(d.model_window?.limit ?? d.requests_limit_5h ?? 0).toLocaleString()}`,
208
- span: FIVE_HOURS,
209
- },
210
- ],
332
+ ...(window5h ? [window5h] : []),
333
+ ...(window7d ? [window7d] : []),
334
+ monthWindow,
335
+ ...(requestWindow ? [requestWindow] : []),
336
+ ].filter(Boolean),
211
337
  }
212
338
  } catch (e) {
213
339
  return { error: e?.message || "OpenKodo usage unavailable", signIn: e?.status === 401 ? "expired" : "kept" }
214
340
  }
215
341
  },
216
342
  },
217
- })
343
+ }
344
+ }
218
345
 
219
346
  export default OpenKodoAuthPlugin
package/package.json CHANGED
@@ -5,10 +5,11 @@
5
5
  "summary": {
6
6
  "en": "OpenKodo: plans, credits and usage windows",
7
7
  "zh": "OpenKodo:套餐、额度与用量窗口"
8
- }
8
+ },
9
+ "icon": "https://openkodo.dev/openkodo-logo.svg"
9
10
  },
10
- "version": "0.2.3",
11
- "description": "OpenKodo plans, credits, usage windows, and models in OpenCode and magpie",
11
+ "version": "0.3.1",
12
+ "description": "OpenKodo Magpie plugin: plans, credits, usage windows, and models in Magpie and OpenCode",
12
13
  "type": "module",
13
14
  "main": "./v1.mjs",
14
15
  "exports": {
@@ -25,7 +26,9 @@
25
26
  ],
26
27
  "scripts": {
27
28
  "test": "node --test test/*.test.mjs",
28
- "pack:check": "npm pack --dry-run"
29
+ "check:public": "node scripts/check-public.mjs",
30
+ "prepublishOnly": "npm run check:public && npm test",
31
+ "pack:check": "npm run check:public && npm pack --dry-run"
29
32
  },
30
33
  "keywords": [
31
34
  "openkodo",
@@ -41,10 +44,10 @@
41
44
  "homepage": "https://openkodo.dev",
42
45
  "repository": {
43
46
  "type": "git",
44
- "url": "git+https://github.com/OpenKodo/openkodo.git"
47
+ "url": "git+https://github.com/OpenKodo/OpenKodo-magpie-plugin.git"
45
48
  },
46
49
  "bugs": {
47
- "url": "https://github.com/OpenKodo/openkodo/issues"
50
+ "url": "https://github.com/OpenKodo/OpenKodo-magpie-plugin/issues"
48
51
  },
49
52
  "engines": {
50
53
  "node": ">=18"
package/v2.mjs CHANGED
@@ -19,9 +19,13 @@ const readKey = (auth) => String(auth?.key ?? auth?.access ?? "").trim()
19
19
 
20
20
  const methodsOf = (plugin) => plugin?.auth?.methods ?? []
21
21
  const loaderOf = (plugin) => plugin?.auth?.loader
22
- const modelsOf = async (plugin, provider) => {
22
+ const modelsOf = async (plugin, provider, ctx) => {
23
+ let auth
23
24
  try {
24
- const models = await plugin?.provider?.models?.(provider)
25
+ auth = await ctx?.auth?.get?.()
26
+ } catch {}
27
+ try {
28
+ const models = await plugin?.provider?.models?.(provider, { auth })
25
29
  if (models && Object.keys(models).length) return models
26
30
  } catch {}
27
31
  return provider?.models ?? {}
@@ -39,7 +43,7 @@ export async function setup(ctx) {
39
43
  icon: "https://openkodo.dev/favicon.svg",
40
44
  npm: "@ai-sdk/openai-compatible",
41
45
  api: BASE,
42
- models: await modelsOf(plugin, provider),
46
+ models: await modelsOf(plugin, provider, ctx),
43
47
  auth: { type: "api" },
44
48
  }
45
49