openkodo 0.3.0 → 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 +11 -3
- package/README.md +21 -4
- package/index.mjs +37 -24
- package/package.json +4 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,7 +1,15 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
-
All notable changes to this package. Versioned independently of
|
|
4
|
-
|
|
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.
|
|
5
13
|
|
|
6
14
|
## 0.3.0
|
|
7
15
|
|
|
@@ -13,7 +21,7 @@ gateway.
|
|
|
13
21
|
- Move model limits into the `limit: { context, output }` shape Magpie reads,
|
|
14
22
|
while keeping the older top-level fields for OpenCode 1.x.
|
|
15
23
|
- Fix usage windows: `used` is now a percentage, `amount` is the used value,
|
|
16
|
-
`limit` is the cap, `unit`
|
|
24
|
+
`limit` is the cap, `unit` identifies the window's unit, and `span` is seconds.
|
|
17
25
|
- Rename the public repository to **OpenKodo Magpie Plugin**; the Magpie row
|
|
18
26
|
still displays **OpenKodo**.
|
|
19
27
|
|
package/README.md
CHANGED
|
@@ -8,17 +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
|
|
13
16
|
- Thinking levels for every model that declares them, taken from the
|
|
14
17
|
authenticated `GET /v1/models` descriptor
|
|
15
18
|
- The live catalog from [`/api/public/models`](https://api.openkodo.dev/api/public/models)
|
|
16
19
|
|
|
17
|
-
The 5-hour and 7-day windows are enforced by
|
|
20
|
+
The 5-hour and 7-day windows are enforced by OpenKodo, not decoration:
|
|
18
21
|
Go is $25 / 5h and $50 / 7d, Pro is $50 / 5h and $100 / 7d. Reset times are
|
|
19
22
|
rolling — the cap frees up when the oldest spend in the window ages out — so
|
|
20
23
|
they move as new requests arrive.
|
|
21
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
|
+
|
|
22
35
|
## Install
|
|
23
36
|
|
|
24
37
|
From the magpie plugin store, search for **OpenKodo**.
|
|
@@ -45,12 +58,16 @@ the key itself, and it never creates keys, changes plans, or spends credits.
|
|
|
45
58
|
## Development
|
|
46
59
|
|
|
47
60
|
```bash
|
|
48
|
-
npm test
|
|
49
|
-
npm run
|
|
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
|
|
50
64
|
```
|
|
51
65
|
|
|
52
66
|
The tests stub `fetch`, so they never use a real API key.
|
|
53
67
|
|
|
68
|
+
See [PUBLISHING.md](./PUBLISHING.md) for the private denylist and the release
|
|
69
|
+
checklist.
|
|
70
|
+
|
|
54
71
|
## License
|
|
55
72
|
|
|
56
73
|
[MIT](./LICENSE)
|
package/index.mjs
CHANGED
|
@@ -10,10 +10,14 @@ 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
|
-
//
|
|
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
22
|
// Offline fallback only. The live model catalogs are authoritative;
|
|
19
23
|
// these are the official standard (off-peak) USD list rates.
|
|
@@ -46,9 +50,10 @@ const modalitiesOf = (m) => {
|
|
|
46
50
|
const modelRecord = ({ name, context, output, input, outputPrice, cache, efforts, inputModalities, reasoning }) => {
|
|
47
51
|
const levels = efforts ?? []
|
|
48
52
|
const thinks = reasoning ?? levels.length > 0
|
|
53
|
+
const ctx = context || 1_000_000
|
|
49
54
|
return {
|
|
50
55
|
name,
|
|
51
|
-
limit: { context:
|
|
56
|
+
limit: { context: ctx, input: Math.min(ctx, COMPACT_AT), output: output || 131_072 },
|
|
52
57
|
cost: { input, output: outputPrice, cache: { read: cache } },
|
|
53
58
|
tool_call: true,
|
|
54
59
|
attachment: inputModalities.includes("image"),
|
|
@@ -128,11 +133,12 @@ async function fetchModels(key, signal) {
|
|
|
128
133
|
const context = m.context_length ?? m.limit?.context ?? m.context_window ?? 1_000_000
|
|
129
134
|
const output = m.max_completion_tokens ?? m.max_output_tokens ?? m.limit?.output ?? m.max_output ?? 131_072
|
|
130
135
|
const inputModalities = modalitiesOf(m)
|
|
136
|
+
const inputLimit = Math.min(context, COMPACT_AT)
|
|
131
137
|
out[id] = {
|
|
132
138
|
name: m.name || id,
|
|
133
139
|
context,
|
|
134
140
|
output,
|
|
135
|
-
limit: { context, output },
|
|
141
|
+
limit: { context, input: inputLimit, output },
|
|
136
142
|
// Config readers use the top-level flag. Model hooks use capabilities.
|
|
137
143
|
reasoning,
|
|
138
144
|
capabilities: {
|
|
@@ -147,8 +153,8 @@ async function fetchModels(key, signal) {
|
|
|
147
153
|
attachment: inputModalities.includes("image"),
|
|
148
154
|
...(efforts.length ? { variants: variantsOf(efforts) } : {}),
|
|
149
155
|
cost: {
|
|
150
|
-
// Show the standard (off-peak) rate
|
|
151
|
-
//
|
|
156
|
+
// Show the standard (off-peak) list rate for most of the day, not the
|
|
157
|
+
// peak rate.
|
|
152
158
|
input: Number(m.offpeak_input_price_micros_per_mtok || m.input_price_micros_per_mtok || 0) / 1_000_000,
|
|
153
159
|
output: Number(m.offpeak_output_price_micros_per_mtok || m.output_price_micros_per_mtok || 0) / 1_000_000,
|
|
154
160
|
cache: { read: Number(m.offpeak_cached_input_price_micros_per_mtok || m.cached_input_price_micros_per_mtok || 0) / 1_000_000 },
|
|
@@ -241,15 +247,20 @@ export const OpenKodoAuthPlugin = async () => {
|
|
|
241
247
|
if (!key) return { error: "not signed in", signIn: "expired" }
|
|
242
248
|
try {
|
|
243
249
|
const d = await fetchUsage(key)
|
|
244
|
-
//
|
|
245
|
-
const
|
|
246
|
-
const remaining =
|
|
247
|
-
const included =
|
|
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)
|
|
248
254
|
const spent = Math.max(0, Math.round((included - remaining) * 100) / 100)
|
|
249
|
-
const used5h =
|
|
250
|
-
const cap5h =
|
|
251
|
-
const used7d =
|
|
252
|
-
const cap7d =
|
|
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
|
|
253
264
|
const periodEnd = d.period_end ? new Date(d.period_end).toISOString() : undefined
|
|
254
265
|
// Each window is rolling: the cap frees up when the oldest spend in it
|
|
255
266
|
// ages out. A window with no spend has nothing to expire.
|
|
@@ -258,8 +269,7 @@ export const OpenKodoAuthPlugin = async () => {
|
|
|
258
269
|
|
|
259
270
|
// Magpie's UsageWindow contract: `used` is a 0–100 percentage,
|
|
260
271
|
// `amount` is the used count in the window's unit, `limit` is the
|
|
261
|
-
// cap, and `span` is in seconds.
|
|
262
|
-
// card print "50 / 50" instead of "48.26 / 50".
|
|
272
|
+
// cap, and `span` is in seconds. Credits are the plan's unit.
|
|
263
273
|
const windowOf = (name, amount, limit, unit, extra = {}) => {
|
|
264
274
|
if (!(limit > 0)) return null
|
|
265
275
|
return {
|
|
@@ -272,32 +282,35 @@ export const OpenKodoAuthPlugin = async () => {
|
|
|
272
282
|
}
|
|
273
283
|
}
|
|
274
284
|
const window5h = cap5h > 0
|
|
275
|
-
? windowOf("5 hours", used5h, cap5h, "
|
|
285
|
+
? windowOf("5 hours", used5h, cap5h, "credits", {
|
|
276
286
|
span: FIVE_HOURS / 1000,
|
|
277
|
-
display:
|
|
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
|
+
} : {}),
|
|
278
291
|
...(rollingReset(d.oldest_5h, FIVE_HOURS) ? { resetsAt: rollingReset(d.oldest_5h, FIVE_HOURS) } : {}),
|
|
279
292
|
})
|
|
280
293
|
: null
|
|
281
294
|
const window7d = cap7d > 0
|
|
282
|
-
? windowOf("7 days", used7d, cap7d, "
|
|
295
|
+
? windowOf("7 days", used7d, cap7d, "credits", {
|
|
283
296
|
span: SEVEN_DAYS / 1000,
|
|
284
|
-
display:
|
|
297
|
+
display: `${used7d.toFixed(2)} / ${cap7d.toFixed(2)} credits`,
|
|
285
298
|
...(rollingReset(d.oldest_7d, SEVEN_DAYS) ? { resetsAt: rollingReset(d.oldest_7d, SEVEN_DAYS) } : {}),
|
|
286
299
|
})
|
|
287
300
|
: null
|
|
288
301
|
const monthWindow = included > 0
|
|
289
|
-
? windowOf("Month", spent, included, "
|
|
290
|
-
display:
|
|
302
|
+
? windowOf("Month", spent, included, "credits", {
|
|
303
|
+
display: `${remaining.toFixed(2)} credits left of ${included.toFixed(2)}`,
|
|
291
304
|
...(periodEnd ? { resetsAt: periodEnd } : {}),
|
|
292
305
|
})
|
|
293
306
|
: {
|
|
294
|
-
// Welcome-credit accounts have no plan
|
|
307
|
+
// Welcome-credit accounts have no monthly plan credits, so a percentage
|
|
295
308
|
// against $0 would be nonsense. Magpie's balance-shaped window
|
|
296
309
|
// says exactly what is left.
|
|
297
310
|
name: "Month",
|
|
298
311
|
balance: remaining,
|
|
299
|
-
unit: "
|
|
300
|
-
display:
|
|
312
|
+
unit: "credits",
|
|
313
|
+
display: `${remaining.toFixed(2)} credits remaining`,
|
|
301
314
|
}
|
|
302
315
|
const requestUsed = Number(d.model_window?.used ?? d.requests_5h ?? 0)
|
|
303
316
|
const requestLimit = Number(d.model_window?.limit ?? d.requests_limit_5h ?? 0)
|
package/package.json
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
},
|
|
9
9
|
"icon": "https://openkodo.dev/openkodo-logo.svg"
|
|
10
10
|
},
|
|
11
|
-
"version": "0.3.
|
|
11
|
+
"version": "0.3.1",
|
|
12
12
|
"description": "OpenKodo Magpie plugin: plans, credits, usage windows, and models in Magpie and OpenCode",
|
|
13
13
|
"type": "module",
|
|
14
14
|
"main": "./v1.mjs",
|
|
@@ -26,7 +26,9 @@
|
|
|
26
26
|
],
|
|
27
27
|
"scripts": {
|
|
28
28
|
"test": "node --test test/*.test.mjs",
|
|
29
|
-
"
|
|
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"
|
|
30
32
|
},
|
|
31
33
|
"keywords": [
|
|
32
34
|
"openkodo",
|