openkodo 0.3.0 → 0.3.2

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,21 @@
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.2
6
+
7
+ - Fix the model card showing 200k/250k context for every model. `limit.input`
8
+ now mirrors the live catalog's real context window instead of being capped
9
+ at 200k for early compaction.
10
+
11
+ ## 0.3.1
12
+
13
+ - Render the 5-hour, 7-day and monthly windows as **plan credits**, not USD.
14
+ - Add an estimated "requests left" to the 5-hour window based on the account's
15
+ recent average credit per request, so large agent requests are legible.
16
+ - Set `limit.input` to 200k on long-context models so agent hosts compact
17
+ before a single prompt consumes a large share of the 5-hour credit cap.
18
+ - Document plan credits vs dollars and the early-compaction behavior.
5
19
 
6
20
  ## 0.3.0
7
21
 
@@ -13,7 +27,7 @@ gateway.
13
27
  - Move model limits into the `limit: { context, output }` shape Magpie reads,
14
28
  while keeping the older top-level fields for OpenCode 1.x.
15
29
  - 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.
30
+ `limit` is the cap, `unit` identifies the window's unit, and `span` is seconds.
17
31
  - Rename the public repository to **OpenKodo Magpie Plugin**; the Magpie row
18
32
  still displays **OpenKodo**.
19
33
 
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
+ - The real model context window is passed through in both `limit.context` and
15
+ `limit.input`; there is no artificial 200k 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 the gateway, not decoration:
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 # unit tests, no network
49
- 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
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,11 +10,10 @@ 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
-
18
17
  // Offline fallback only. The live model catalogs are authoritative;
19
18
  // these are the official standard (off-peak) USD list rates.
20
19
  const FALLBACK = {
@@ -46,9 +45,10 @@ const modalitiesOf = (m) => {
46
45
  const modelRecord = ({ name, context, output, input, outputPrice, cache, efforts, inputModalities, reasoning }) => {
47
46
  const levels = efforts ?? []
48
47
  const thinks = reasoning ?? levels.length > 0
48
+ const ctx = context || 1_000_000
49
49
  return {
50
50
  name,
51
- limit: { context: context || 1_000_000, output: output || 131_072 },
51
+ limit: { context: ctx, input: ctx, output: output || 131_072 },
52
52
  cost: { input, output: outputPrice, cache: { read: cache } },
53
53
  tool_call: true,
54
54
  attachment: inputModalities.includes("image"),
@@ -132,7 +132,7 @@ async function fetchModels(key, signal) {
132
132
  name: m.name || id,
133
133
  context,
134
134
  output,
135
- limit: { context, output },
135
+ limit: { context, input: context, output },
136
136
  // Config readers use the top-level flag. Model hooks use capabilities.
137
137
  reasoning,
138
138
  capabilities: {
@@ -147,8 +147,8 @@ async function fetchModels(key, signal) {
147
147
  attachment: inputModalities.includes("image"),
148
148
  ...(efforts.length ? { variants: variantsOf(efforts) } : {}),
149
149
  cost: {
150
- // Show the standard (off-peak) rate the gateway charges most of the
151
- // day, not the peak rate stored in the primary columns.
150
+ // Show the standard (off-peak) list rate for most of the day, not the
151
+ // peak rate.
152
152
  input: Number(m.offpeak_input_price_micros_per_mtok || m.input_price_micros_per_mtok || 0) / 1_000_000,
153
153
  output: Number(m.offpeak_output_price_micros_per_mtok || m.output_price_micros_per_mtok || 0) / 1_000_000,
154
154
  cache: { read: Number(m.offpeak_cached_input_price_micros_per_mtok || m.cached_input_price_micros_per_mtok || 0) / 1_000_000 },
@@ -241,15 +241,20 @@ export const OpenKodoAuthPlugin = async () => {
241
241
  if (!key) return { error: "not signed in", signIn: "expired" }
242
242
  try {
243
243
  const d = await fetchUsage(key)
244
- // Cents, not raw division: $26.599999999999994 must render as $26.60.
245
- const usd = (micros) => Math.round(Number(micros || 0) / 10_000) / 100
246
- const remaining = usd(d.credits_remaining_micros)
247
- const included = usd(d.credits_included_micros)
244
+ // Plan credits are OpenKodo's usage unit, not dollars.
245
+ const credits = (micros) => Math.round(Number(micros || 0) / 10_000) / 100
246
+ const remaining = credits(d.credits_remaining_micros)
247
+ const included = credits(d.credits_included_micros)
248
248
  const spent = Math.max(0, Math.round((included - remaining) * 100) / 100)
249
- const used5h = usd(d.cost_5h_micros)
250
- const cap5h = usd(d.credits_per_5h_micros)
251
- const used7d = usd(d.cost_7d_micros)
252
- const cap7d = usd(d.credits_per_week_micros)
249
+ const used5h = credits(d.cost_5h_micros)
250
+ const cap5h = credits(d.credits_per_5h_micros)
251
+ const used7d = credits(d.cost_7d_micros)
252
+ const cap7d = credits(d.credits_per_week_micros)
253
+ // The card can estimate how many requests are left at the account's
254
+ // current burn rate. This makes a large agent request legible.
255
+ const requests5h = Number(d.requests_5h ?? d.model_window?.used ?? 0)
256
+ const avgCredit5h = requests5h > 0 ? used5h / requests5h : 0
257
+ const requestsLeft5h = avgCredit5h > 0 ? Math.max(0, Math.floor((cap5h - used5h) / avgCredit5h)) : null
253
258
  const periodEnd = d.period_end ? new Date(d.period_end).toISOString() : undefined
254
259
  // Each window is rolling: the cap frees up when the oldest spend in it
255
260
  // ages out. A window with no spend has nothing to expire.
@@ -258,8 +263,7 @@ export const OpenKodoAuthPlugin = async () => {
258
263
 
259
264
  // Magpie's UsageWindow contract: `used` is a 0–100 percentage,
260
265
  // `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".
266
+ // cap, and `span` is in seconds. Credits are the plan's unit.
263
267
  const windowOf = (name, amount, limit, unit, extra = {}) => {
264
268
  if (!(limit > 0)) return null
265
269
  return {
@@ -272,32 +276,35 @@ export const OpenKodoAuthPlugin = async () => {
272
276
  }
273
277
  }
274
278
  const window5h = cap5h > 0
275
- ? windowOf("5 hours", used5h, cap5h, "USD", {
279
+ ? windowOf("5 hours", used5h, cap5h, "credits", {
276
280
  span: FIVE_HOURS / 1000,
277
- display: `$${used5h.toFixed(2)} / $${cap5h.toFixed(2)}`,
281
+ display: `${used5h.toFixed(2)} / ${cap5h.toFixed(2)} credits${requestsLeft5h !== null ? ` · ~${requestsLeft5h.toLocaleString()} left` : ""}`,
282
+ ...(requestsLeft5h !== null ? {
283
+ note: `At your recent average of ${avgCredit5h.toFixed(2)} credits per request, about ${requestsLeft5h.toLocaleString()} requests remain in this window.`,
284
+ } : {}),
278
285
  ...(rollingReset(d.oldest_5h, FIVE_HOURS) ? { resetsAt: rollingReset(d.oldest_5h, FIVE_HOURS) } : {}),
279
286
  })
280
287
  : null
281
288
  const window7d = cap7d > 0
282
- ? windowOf("7 days", used7d, cap7d, "USD", {
289
+ ? windowOf("7 days", used7d, cap7d, "credits", {
283
290
  span: SEVEN_DAYS / 1000,
284
- display: `$${used7d.toFixed(2)} / $${cap7d.toFixed(2)}`,
291
+ display: `${used7d.toFixed(2)} / ${cap7d.toFixed(2)} credits`,
285
292
  ...(rollingReset(d.oldest_7d, SEVEN_DAYS) ? { resetsAt: rollingReset(d.oldest_7d, SEVEN_DAYS) } : {}),
286
293
  })
287
294
  : null
288
295
  const monthWindow = included > 0
289
- ? windowOf("Month", spent, included, "USD", {
290
- display: `$${remaining.toFixed(2)} left of $${included.toFixed(2)}`,
296
+ ? windowOf("Month", spent, included, "credits", {
297
+ display: `${remaining.toFixed(2)} credits left of ${included.toFixed(2)}`,
291
298
  ...(periodEnd ? { resetsAt: periodEnd } : {}),
292
299
  })
293
300
  : {
294
- // Welcome-credit accounts have no plan pool, so a percentage
301
+ // Welcome-credit accounts have no monthly plan credits, so a percentage
295
302
  // against $0 would be nonsense. Magpie's balance-shaped window
296
303
  // says exactly what is left.
297
304
  name: "Month",
298
305
  balance: remaining,
299
- unit: "USD",
300
- display: `$${remaining.toFixed(2)} remaining`,
306
+ unit: "credits",
307
+ display: `${remaining.toFixed(2)} credits remaining`,
301
308
  }
302
309
  const requestUsed = Number(d.model_window?.used ?? d.requests_5h ?? 0)
303
310
  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.0",
11
+ "version": "0.3.2",
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
- "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"
30
32
  },
31
33
  "keywords": [
32
34
  "openkodo",