openkodo 0.2.3 → 0.3.0
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 +14 -0
- package/README.md +3 -1
- package/index.mjs +174 -60
- package/package.json +6 -5
- package/v2.mjs +7 -3
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,20 @@
|
|
|
3
3
|
All notable changes to this package. Versioned independently of the OpenKodo
|
|
4
4
|
gateway.
|
|
5
5
|
|
|
6
|
+
## 0.3.0
|
|
7
|
+
|
|
8
|
+
- Show the reasoning levels each model declares in `GET /v1/models`
|
|
9
|
+
(`low`/`medium`/`high`/`max`, and `none` where the model offers an off
|
|
10
|
+
switch) instead of dropping `reasoning.efforts`.
|
|
11
|
+
- Merge the authenticated descriptor with the public catalog so names, limits
|
|
12
|
+
and prices stay available.
|
|
13
|
+
- Move model limits into the `limit: { context, output }` shape Magpie reads,
|
|
14
|
+
while keeping the older top-level fields for OpenCode 1.x.
|
|
15
|
+
- Fix usage windows: `used` is now a percentage, `amount` is the used value,
|
|
16
|
+
`limit` is the cap, `unit` is `USD` or `requests`, and `span` is seconds.
|
|
17
|
+
- Rename the public repository to **OpenKodo Magpie Plugin**; the Magpie row
|
|
18
|
+
still displays **OpenKodo**.
|
|
19
|
+
|
|
6
20
|
## 0.2.3
|
|
7
21
|
|
|
8
22
|
- First public release on npm as `openkodo`.
|
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# OpenKodo
|
|
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.
|
|
@@ -10,6 +10,8 @@ Provider id: `openkodo`.
|
|
|
10
10
|
- Three rolling spend windows, shortest first: **5 hours**, **7 days**, and the
|
|
11
11
|
**monthly** pool — each with the amount used, the cap, and when it frees up
|
|
12
12
|
- The per-model 5-hour request guardrail
|
|
13
|
+
- Thinking levels for every model that declares them, taken from the
|
|
14
|
+
authenticated `GET /v1/models` descriptor
|
|
13
15
|
- The live catalog from [`/api/public/models`](https://api.openkodo.dev/api/public/models)
|
|
14
16
|
|
|
15
17
|
The 5-hour and 7-day windows are enforced by the gateway, not decoration:
|
package/index.mjs
CHANGED
|
@@ -15,28 +15,65 @@ const USAGE = "https://api.openkodo.dev/api/plugin/usage"
|
|
|
15
15
|
const FIVE_HOURS = 5 * 60 * 60_000
|
|
16
16
|
const SEVEN_DAYS = 7 * 24 * 60 * 60_000
|
|
17
17
|
|
|
18
|
-
// Offline fallback only. The live
|
|
18
|
+
// Offline fallback only. The live model catalogs are authoritative;
|
|
19
19
|
// these are the official standard (off-peak) USD list rates.
|
|
20
20
|
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 },
|
|
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, efforts: ["none", "low", "high", "max"] },
|
|
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, efforts: ["none", "low", "high", "max"] },
|
|
23
|
+
"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"] },
|
|
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, efforts: ["low", "medium", "high"] },
|
|
25
25
|
"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
26
|
"qwen3.8-max": { name: "Qwen3.8 Max", context: 1_000_000, output: 131_072, input: 2.0, outputPrice: 6.0, cache: 0.25 },
|
|
27
27
|
"MiniMax-M3": { name: "MiniMax M3", context: 1_000_000, output: 131_072, input: 0.6, outputPrice: 2.4, cache: 0.12 },
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
+
const effortsOf = (m) => {
|
|
31
|
+
const list = m?.reasoning?.efforts ?? m?.reasoning_efforts
|
|
32
|
+
return Array.isArray(list) ? list.map(String).filter(Boolean) : []
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// Magpie turns each variant into an OpenCode reasoning level. "none" is a
|
|
36
|
+
// real level for the DeepSeek models, so it stays in the list: selecting it
|
|
37
|
+
// is the off switch.
|
|
38
|
+
const variantsOf = (efforts) =>
|
|
39
|
+
Object.fromEntries(efforts.map((effort) => [effort, { reasoningEffort: effort }]))
|
|
40
|
+
|
|
41
|
+
const modalitiesOf = (m) => {
|
|
42
|
+
const input = m?.architecture?.input_modalities
|
|
43
|
+
return Array.isArray(input) && input.length ? input.map(String) : ["text"]
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const modelRecord = ({ name, context, output, input, outputPrice, cache, efforts, inputModalities, reasoning }) => {
|
|
47
|
+
const levels = efforts ?? []
|
|
48
|
+
const thinks = reasoning ?? levels.length > 0
|
|
49
|
+
return {
|
|
50
|
+
name,
|
|
51
|
+
limit: { context: context || 1_000_000, output: output || 131_072 },
|
|
52
|
+
cost: { input, output: outputPrice, cache: { read: cache } },
|
|
53
|
+
tool_call: true,
|
|
54
|
+
attachment: inputModalities.includes("image"),
|
|
55
|
+
modalities: { input: inputModalities.length ? inputModalities : ["text"], output: ["text"] },
|
|
56
|
+
// OpenCode reads `reasoning`/`variants`; magpie's internalOf folds them
|
|
57
|
+
// into capabilities.reasoning. Both hosts then see the same levels.
|
|
58
|
+
...(thinks ? { reasoning: true } : {}),
|
|
59
|
+
...(levels.length ? { variants: variantsOf(levels) } : {}),
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
30
63
|
const fallbackModels = () =>
|
|
31
64
|
Object.fromEntries(
|
|
32
65
|
Object.entries(FALLBACK).map(([id, m]) => [
|
|
33
66
|
id,
|
|
34
|
-
{
|
|
67
|
+
modelRecord({
|
|
35
68
|
name: m.name,
|
|
36
69
|
context: m.context,
|
|
37
70
|
output: m.output,
|
|
38
|
-
|
|
39
|
-
|
|
71
|
+
input: m.input,
|
|
72
|
+
outputPrice: m.outputPrice,
|
|
73
|
+
cache: m.cache,
|
|
74
|
+
efforts: m.efforts,
|
|
75
|
+
inputModalities: ["text"],
|
|
76
|
+
}),
|
|
40
77
|
]),
|
|
41
78
|
)
|
|
42
79
|
|
|
@@ -55,17 +92,60 @@ async function fetchUsage(key) {
|
|
|
55
92
|
return body
|
|
56
93
|
}
|
|
57
94
|
|
|
58
|
-
async function
|
|
59
|
-
const res = await fetch(
|
|
95
|
+
async function fetchModelList(url, headers, signal) {
|
|
96
|
+
const res = await fetch(url, { headers, signal })
|
|
60
97
|
if (!res.ok) throw new Error(`OpenKodo model list failed (${res.status})`)
|
|
61
98
|
const body = await res.json()
|
|
99
|
+
const models = body?.data ?? body?.models
|
|
100
|
+
if (!Array.isArray(models)) throw new Error("OpenKodo model list was not valid")
|
|
101
|
+
return models.filter(m => typeof (m?.code || m?.id) === "string" && (m.code || m.id).trim())
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
async function fetchModels(key, signal) {
|
|
105
|
+
// The account list supplies efforts and available IDs. The public catalog
|
|
106
|
+
// supplies prices and limits even when /v1/models only gives descriptors.
|
|
107
|
+
const [accountResult, publicResult] = await Promise.allSettled([
|
|
108
|
+
key
|
|
109
|
+
? fetchModelList(`${BASE}/models`, { Authorization: `Bearer ${key}`, Accept: "application/json" }, signal)
|
|
110
|
+
: Promise.resolve([]),
|
|
111
|
+
fetchModelList(PUBLIC_MODELS, { Accept: "application/json" }, signal),
|
|
112
|
+
])
|
|
113
|
+
const account = accountResult.status === "fulfilled" ? accountResult.value : []
|
|
114
|
+
const catalog = publicResult.status === "fulfilled" ? publicResult.value : []
|
|
115
|
+
const byID = new Map(catalog.map(m => [m.code || m.id, m]))
|
|
116
|
+
const models = account.length ? account : catalog
|
|
117
|
+
if (!models.length) throw new Error("OpenKodo model list was empty or unavailable")
|
|
62
118
|
const out = {}
|
|
63
|
-
for (const
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
119
|
+
for (const descriptor of models) {
|
|
120
|
+
const id = descriptor.code || descriptor.id
|
|
121
|
+
const m = { ...byID.get(id), ...descriptor }
|
|
122
|
+
const declared = m.reasoning?.efforts ?? m.reasoning_efforts
|
|
123
|
+
const efforts = Array.isArray(declared) ? [...new Set(declared.filter(e => typeof e === "string" && e.trim()))] : []
|
|
124
|
+
const reasoning = efforts.length > 0 || m.reasoning === true || m.reasoning?.supported === true
|
|
125
|
+
|| m.capabilities?.reasoning === true || (Array.isArray(m.capabilities) && m.capabilities.includes("reasoning"))
|
|
126
|
+
// `limit` is the shape OpenCode/Magpie read. Keep context/output at the
|
|
127
|
+
// top level too: older OpenCode hosts read those.
|
|
128
|
+
const context = m.context_length ?? m.limit?.context ?? m.context_window ?? 1_000_000
|
|
129
|
+
const output = m.max_completion_tokens ?? m.max_output_tokens ?? m.limit?.output ?? m.max_output ?? 131_072
|
|
130
|
+
const inputModalities = modalitiesOf(m)
|
|
131
|
+
out[id] = {
|
|
132
|
+
name: m.name || id,
|
|
133
|
+
context,
|
|
134
|
+
output,
|
|
135
|
+
limit: { context, output },
|
|
136
|
+
// Config readers use the top-level flag. Model hooks use capabilities.
|
|
137
|
+
reasoning,
|
|
138
|
+
capabilities: {
|
|
139
|
+
reasoning,
|
|
140
|
+
toolcall: true,
|
|
141
|
+
attachment: inputModalities.includes("image"),
|
|
142
|
+
input: Object.fromEntries(["text", "image", "audio", "video", "pdf"].map((k) => [k, inputModalities.includes(k)])),
|
|
143
|
+
output: { text: true, image: false, audio: false, video: false, pdf: false },
|
|
144
|
+
},
|
|
145
|
+
modalities: { input: inputModalities, output: ["text"] },
|
|
146
|
+
tool_call: true,
|
|
147
|
+
attachment: inputModalities.includes("image"),
|
|
148
|
+
...(efforts.length ? { variants: variantsOf(efforts) } : {}),
|
|
69
149
|
cost: {
|
|
70
150
|
// Show the standard (off-peak) rate the gateway charges most of the
|
|
71
151
|
// day, not the peak rate stored in the primary columns.
|
|
@@ -75,10 +155,18 @@ async function fetchModels() {
|
|
|
75
155
|
},
|
|
76
156
|
}
|
|
77
157
|
}
|
|
158
|
+
|
|
78
159
|
return Object.keys(out).length ? out : fallbackModels()
|
|
79
160
|
}
|
|
80
161
|
|
|
81
|
-
export const OpenKodoAuthPlugin = async () =>
|
|
162
|
+
export const OpenKodoAuthPlugin = async () => {
|
|
163
|
+
// The last key the host validated. provider.models() has no credential
|
|
164
|
+
// argument, so this is what lets it read the authenticated descriptor (the
|
|
165
|
+
// only source that carries reasoning.efforts) instead of the public
|
|
166
|
+
// catalog. Per plugin instance, so tests and hosts never share a key.
|
|
167
|
+
let sessionKey = ""
|
|
168
|
+
|
|
169
|
+
return {
|
|
82
170
|
config: async (cfg) => {
|
|
83
171
|
cfg.provider ??= {}
|
|
84
172
|
const p = (cfg.provider[ID] ??= {})
|
|
@@ -91,9 +179,9 @@ export const OpenKodoAuthPlugin = async () => ({
|
|
|
91
179
|
|
|
92
180
|
provider: {
|
|
93
181
|
id: ID,
|
|
94
|
-
async models(provider) {
|
|
182
|
+
async models(provider, { auth, signal } = {}) {
|
|
95
183
|
try {
|
|
96
|
-
return await fetchModels()
|
|
184
|
+
return await fetchModels(keyOf(auth) || sessionKey, signal)
|
|
97
185
|
} catch {
|
|
98
186
|
return provider?.models && Object.keys(provider.models).length ? provider.models : fallbackModels()
|
|
99
187
|
}
|
|
@@ -126,6 +214,7 @@ export const OpenKodoAuthPlugin = async () => ({
|
|
|
126
214
|
try {
|
|
127
215
|
const usage = await fetchUsage(key)
|
|
128
216
|
if (!usage?.plan) throw new Error("OpenKodo usage response was not valid")
|
|
217
|
+
sessionKey = key
|
|
129
218
|
return {
|
|
130
219
|
type: "success",
|
|
131
220
|
key,
|
|
@@ -142,6 +231,7 @@ export const OpenKodoAuthPlugin = async () => ({
|
|
|
142
231
|
const auth = await getAuth()
|
|
143
232
|
const key = keyOf(auth)
|
|
144
233
|
if (!key) return {}
|
|
234
|
+
sessionKey = key
|
|
145
235
|
return { baseURL: BASE, apiKey: key }
|
|
146
236
|
},
|
|
147
237
|
|
|
@@ -155,7 +245,7 @@ export const OpenKodoAuthPlugin = async () => ({
|
|
|
155
245
|
const usd = (micros) => Math.round(Number(micros || 0) / 10_000) / 100
|
|
156
246
|
const remaining = usd(d.credits_remaining_micros)
|
|
157
247
|
const included = usd(d.credits_included_micros)
|
|
158
|
-
const spent = Math.max(0, included - remaining)
|
|
248
|
+
const spent = Math.max(0, Math.round((included - remaining) * 100) / 100)
|
|
159
249
|
const used5h = usd(d.cost_5h_micros)
|
|
160
250
|
const cap5h = usd(d.credits_per_5h_micros)
|
|
161
251
|
const used7d = usd(d.cost_7d_micros)
|
|
@@ -165,55 +255,79 @@ export const OpenKodoAuthPlugin = async () => ({
|
|
|
165
255
|
// ages out. A window with no spend has nothing to expire.
|
|
166
256
|
const rollingReset = (oldest, span) =>
|
|
167
257
|
oldest ? new Date(new Date(oldest).getTime() + span).toISOString() : undefined
|
|
258
|
+
|
|
259
|
+
// Magpie's UsageWindow contract: `used` is a 0–100 percentage,
|
|
260
|
+
// `amount` is the used count in the window's unit, `limit` is the
|
|
261
|
+
// cap, and `span` is in seconds. Sending dollars as `used` made the
|
|
262
|
+
// card print "50 / 50" instead of "48.26 / 50".
|
|
263
|
+
const windowOf = (name, amount, limit, unit, extra = {}) => {
|
|
264
|
+
if (!(limit > 0)) return null
|
|
265
|
+
return {
|
|
266
|
+
name,
|
|
267
|
+
used: Math.round(Math.min(100, Math.max(0, (100 * amount) / limit)) * 100) / 100,
|
|
268
|
+
amount,
|
|
269
|
+
limit,
|
|
270
|
+
unit,
|
|
271
|
+
...extra,
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
const window5h = cap5h > 0
|
|
275
|
+
? windowOf("5 hours", used5h, cap5h, "USD", {
|
|
276
|
+
span: FIVE_HOURS / 1000,
|
|
277
|
+
display: `$${used5h.toFixed(2)} / $${cap5h.toFixed(2)}`,
|
|
278
|
+
...(rollingReset(d.oldest_5h, FIVE_HOURS) ? { resetsAt: rollingReset(d.oldest_5h, FIVE_HOURS) } : {}),
|
|
279
|
+
})
|
|
280
|
+
: null
|
|
281
|
+
const window7d = cap7d > 0
|
|
282
|
+
? windowOf("7 days", used7d, cap7d, "USD", {
|
|
283
|
+
span: SEVEN_DAYS / 1000,
|
|
284
|
+
display: `$${used7d.toFixed(2)} / $${cap7d.toFixed(2)}`,
|
|
285
|
+
...(rollingReset(d.oldest_7d, SEVEN_DAYS) ? { resetsAt: rollingReset(d.oldest_7d, SEVEN_DAYS) } : {}),
|
|
286
|
+
})
|
|
287
|
+
: null
|
|
288
|
+
const monthWindow = included > 0
|
|
289
|
+
? windowOf("Month", spent, included, "USD", {
|
|
290
|
+
display: `$${remaining.toFixed(2)} left of $${included.toFixed(2)}`,
|
|
291
|
+
...(periodEnd ? { resetsAt: periodEnd } : {}),
|
|
292
|
+
})
|
|
293
|
+
: {
|
|
294
|
+
// Welcome-credit accounts have no plan pool, so a percentage
|
|
295
|
+
// against $0 would be nonsense. Magpie's balance-shaped window
|
|
296
|
+
// says exactly what is left.
|
|
297
|
+
name: "Month",
|
|
298
|
+
balance: remaining,
|
|
299
|
+
unit: "USD",
|
|
300
|
+
display: `$${remaining.toFixed(2)} remaining`,
|
|
301
|
+
}
|
|
302
|
+
const requestUsed = Number(d.model_window?.used ?? d.requests_5h ?? 0)
|
|
303
|
+
const requestLimit = Number(d.model_window?.limit ?? d.requests_limit_5h ?? 0)
|
|
304
|
+
const requestWindow = windowOf(
|
|
305
|
+
d.model_window?.model ? `Requests / 5h · ${d.model_window.model}` : "Requests / 5h",
|
|
306
|
+
requestUsed,
|
|
307
|
+
requestLimit,
|
|
308
|
+
"requests",
|
|
309
|
+
{
|
|
310
|
+
span: FIVE_HOURS / 1000,
|
|
311
|
+
display: `${requestUsed.toLocaleString()} / ${requestLimit.toLocaleString()}`,
|
|
312
|
+
...(d.model_window?.model ? { models: [d.model_window.model] } : {}),
|
|
313
|
+
},
|
|
314
|
+
)
|
|
168
315
|
return {
|
|
169
316
|
plan: d.plan,
|
|
170
317
|
user: d.email,
|
|
171
318
|
windows: [
|
|
172
|
-
...(
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
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
|
-
],
|
|
319
|
+
...(window5h ? [window5h] : []),
|
|
320
|
+
...(window7d ? [window7d] : []),
|
|
321
|
+
monthWindow,
|
|
322
|
+
...(requestWindow ? [requestWindow] : []),
|
|
323
|
+
].filter(Boolean),
|
|
211
324
|
}
|
|
212
325
|
} catch (e) {
|
|
213
326
|
return { error: e?.message || "OpenKodo usage unavailable", signIn: e?.status === 401 ? "expired" : "kept" }
|
|
214
327
|
}
|
|
215
328
|
},
|
|
216
329
|
},
|
|
217
|
-
}
|
|
330
|
+
}
|
|
331
|
+
}
|
|
218
332
|
|
|
219
333
|
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.
|
|
11
|
-
"description": "OpenKodo plans, credits, usage windows, and models in
|
|
11
|
+
"version": "0.3.0",
|
|
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": {
|
|
@@ -41,10 +42,10 @@
|
|
|
41
42
|
"homepage": "https://openkodo.dev",
|
|
42
43
|
"repository": {
|
|
43
44
|
"type": "git",
|
|
44
|
-
"url": "git+https://github.com/OpenKodo/
|
|
45
|
+
"url": "git+https://github.com/OpenKodo/OpenKodo-magpie-plugin.git"
|
|
45
46
|
},
|
|
46
47
|
"bugs": {
|
|
47
|
-
"url": "https://github.com/OpenKodo/
|
|
48
|
+
"url": "https://github.com/OpenKodo/OpenKodo-magpie-plugin/issues"
|
|
48
49
|
},
|
|
49
50
|
"engines": {
|
|
50
51
|
"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
|
-
|
|
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
|
|