foldrun 20.3.0 → 20.4.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/bin/foldrun.mjs +2 -0
- package/docs/api.md +2 -1
- package/docs/claude-code.md +57 -1
- package/docs/cli.md +1 -0
- package/package.json +2 -2
- package/src/commands.mjs +50 -4
package/bin/foldrun.mjs
CHANGED
|
@@ -304,6 +304,7 @@ Signing in
|
|
|
304
304
|
foldrun use <name> act as one of them from here on
|
|
305
305
|
foldrun keys ls the account's API keys: created, last used, expires, scope, and which are a machine's CLI sign-in (they renew themselves) — also create <label> [--expires 90d], rotate <id> [--grace 1h], revoke <id>
|
|
306
306
|
foldrun keys create <label> --a2a --to <ws> --flows a,b a key for an OUTSIDE agent: it opens /a2a for those published flows and no /api route (--max-tasks N open at once, default 10; --expires); shown once
|
|
307
|
+
foldrun keys set <id> --sonnet openai/gpt-6 which model a gateway key runs each Claude Code tier on (--opus, --haiku; - clears one, --clear all)
|
|
307
308
|
foldrun keys create <label> --gateway --cap <usd> [--daily <usd>] a key for a CODING agent (Claude Code: ANTHROPIC_BASE_URL + this key) — it spends the account's credits on foldrun's models through the gateway, up to its own limits, and opens no /api route; an admin of every workspace; shown once
|
|
308
309
|
foldrun a2a ls --to <ws> what a workspace serves over A2A: each flow's a2a:, card and endpoint URLs, its A2A keys (admins), recent tasks and the key that asked (--json)
|
|
309
310
|
foldrun a2a publish <flow> set a2a: publish: true in the flow (--to <ws>: the deployed copy, an admin's) — --name, --description, --example "…" (repeatable), --public-card | --private-card; diff, checked, --dry-run
|
|
@@ -456,6 +457,7 @@ Options
|
|
|
456
457
|
--gateway keys create: a gateway key for Claude Code — with --cap <usd> (in all) and/or --daily <usd> (per UTC day)
|
|
457
458
|
--cap <usd>, --daily <usd> keys create --gateway: the key's own spending limits, $0.01–$100000
|
|
458
459
|
--login keys create --gateway: on the operator's Claude login instead (the operator's own accounts; not metered, no limits)
|
|
460
|
+
--opus, --sonnet, --haiku <model> keys set <id>: which model that Claude Code tier runs on with a gateway key (e.g. openai/gpt-6; - clears it)
|
|
459
461
|
--key-env <NAME> a2a call, a2a status, a2a cancel, a2a card: the environment variable holding the A2A key (default FOLDRUN_A2A_KEY) — a key is never taken on the command line
|
|
460
462
|
--card <url> a2a status, a2a cancel: the agent card of the agent that holds the task
|
|
461
463
|
|
package/docs/api.md
CHANGED
|
@@ -366,7 +366,8 @@ Reads return which secrets exist, never their values.
|
|
|
366
366
|
|
|
367
367
|
| Route | Methods | |
|
|
368
368
|
|---|---|---|
|
|
369
|
-
| `/api/keys` | GET, POST, DELETE | API keys — an admin's (`keys:manage`) to list, mint and revoke; any key may revoke itself (DELETE with its own `id`, audited as self — what `foldrun logout` does). POST `label`, `role` (viewer \| editor \| admin, never above your own, default editor), `workspaces` (names, or `null` for all — never wider than your own scope); `expires` (`30d`, `90d`, `365d`, any number of days up to 3650, or `never` — the default; anything else is a 400, never a key that lives forever); returns `{ ok, key, id, prefix, role, workspaces, expiresAt }`. POST `{ purpose: "a2a", workspace, flows, maxTasks?, label?, expires? }` mints an A2A key instead: for an outside agent, it opens `/a2a/<account>/<workspace>/…` for the named flows (each must say `a2a: { publish: true }` when the key is minted — a flow not published is refused, 400 — and still say it on every call) and every `/api` route refuses it (403); `maxTasks` (1–100, default 10) caps its tasks open at once; it answers `{ ok, key, id, prefix, purpose, workspace, flows, maxTasks, role, workspaces, expiresAt }`, and rotating one keeps the tasks it made, and the key is shown once. POST `{ purpose: "gateway", capUsd?, dailyUsd?, label?, expires? }` mints a gateway key: for a coding agent such as Claude Code (`ANTHROPIC_BASE_URL` + the key, [Claude Code](claude-code.md)), it spends the account's credits on foldrun's Anthropic models through the gateway and every `/api` route refuses it (403); it needs `capUsd` (USD in all) or `dailyUsd` (USD per UTC day), $0.01–$100,000 after rounding to cents, is minted only by an admin of every workspace (a scoped admin is 403) and only on the hosted platform (400 elsewhere), and answers `{ ok, key, id, prefix, purpose, capUsd, dailyUsd, expiresAt, gatewayUrl }`; rotating one keeps its limits. With `credential: "login"` it runs on the operator's own Claude login instead — only on an account the operator allows its model credential (403 otherwise), with no `capUsd`/`dailyUsd` (400), not metered or billed; it answers `credential: "login"` and lists with no spend. GET lists each key with `createdAt`, `createdBy`, `expiresAt`, `lastUsedAt`, `lastIp` and `replacedBy` (the id of the key a rotation replaced it with; `null` until then), a gateway key's `gateway: { capUsd, dailyUsd, spentUsd, todayUsd }` (spent in all and today, UTC, calls in flight at their hold), and at the top `gatewayUrl` (the gateway's address; `null` where the install has none) — the last-use pair written at most once a minute per key, the address cut to its /24 (IPv4) or /48 (IPv6). A key past its `expiresAt` is refused with 401 `API key expired on <date>`; the owner is emailed seven days before. Mint, revoke and rotate are written to the audit log. POST with `workspace` or `access` is refused (400): those minted deploy keys for the platform's own git, which went on 17 Oct 2026 — a deploy key minted before is refused everywhere (403). A key for one workspace is `workspaces: ["<ws>"]`. DELETE `id`. `?tenant=` / body `tenant` is read only on an install with no users yet (first-run bootstrap), and there, when the install has a setup token (`FOLDRUN_SETUP_TOKEN`, written by the self-hosting installer), only with that token in `X-Foldrun-Setup-Token` |
|
|
369
|
+
| `/api/keys` | GET, POST, DELETE | API keys — an admin's (`keys:manage`) to list, mint and revoke; any key may revoke itself (DELETE with its own `id`, audited as self — what `foldrun logout` does). POST `label`, `role` (viewer \| editor \| admin, never above your own, default editor), `workspaces` (names, or `null` for all — never wider than your own scope); `expires` (`30d`, `90d`, `365d`, any number of days up to 3650, or `never` — the default; anything else is a 400, never a key that lives forever); returns `{ ok, key, id, prefix, role, workspaces, expiresAt }`. POST `{ purpose: "a2a", workspace, flows, maxTasks?, label?, expires? }` mints an A2A key instead: for an outside agent, it opens `/a2a/<account>/<workspace>/…` for the named flows (each must say `a2a: { publish: true }` when the key is minted — a flow not published is refused, 400 — and still say it on every call) and every `/api` route refuses it (403); `maxTasks` (1–100, default 10) caps its tasks open at once; it answers `{ ok, key, id, prefix, purpose, workspace, flows, maxTasks, role, workspaces, expiresAt }`, and rotating one keeps the tasks it made, and the key is shown once. POST `{ purpose: "gateway", capUsd?, dailyUsd?, label?, expires? }` mints a gateway key: for a coding agent such as Claude Code (`ANTHROPIC_BASE_URL` + the key, [Claude Code](claude-code.md)), it spends the account's credits on foldrun's Anthropic models through the gateway and every `/api` route refuses it (403); it needs `capUsd` (USD in all) or `dailyUsd` (USD per UTC day), $0.01–$100,000 after rounding to cents, is minted only by an admin of every workspace (a scoped admin is 403) and only on the hosted platform (400 elsewhere), and answers `{ ok, key, id, prefix, purpose, capUsd, dailyUsd, expiresAt, gatewayUrl }`; rotating one keeps its limits. `models` maps Claude Code's tiers to other models (see `PATCH /api/keys/<id>`). With `credential: "login"` it runs on the operator's own Claude login instead — only on an account the operator allows its model credential (403 otherwise), with no `capUsd`/`dailyUsd` (400), not metered or billed; it answers `credential: "login"` and lists with no spend. GET lists each key with `createdAt`, `createdBy`, `expiresAt`, `lastUsedAt`, `lastIp` and `replacedBy` (the id of the key a rotation replaced it with; `null` until then), a gateway key's `gateway: { capUsd, dailyUsd, spentUsd, todayUsd }` (spent in all and today, UTC, calls in flight at their hold), and at the top `gatewayUrl` (the gateway's address; `null` where the install has none) — the last-use pair written at most once a minute per key, the address cut to its /24 (IPv4) or /48 (IPv6). A key past its `expiresAt` is refused with 401 `API key expired on <date>`; the owner is emailed seven days before. Mint, revoke and rotate are written to the audit log. POST with `workspace` or `access` is refused (400): those minted deploy keys for the platform's own git, which went on 17 Oct 2026 — a deploy key minted before is refused everywhere (403). A key for one workspace is `workspaces: ["<ws>"]`. DELETE `id`. `?tenant=` / body `tenant` is read only on an install with no users yet (first-run bootstrap), and there, when the install has a setup token (`FOLDRUN_SETUP_TOKEN`, written by the self-hosting installer), only with that token in `X-Foldrun-Setup-Token` |
|
|
370
|
+
| `/api/keys/<id>` | PATCH | a gateway key's model map: `{ models: { opus?, sonnet?, haiku? } }` — which model each Claude Code tier runs on with that key (`provider/model` such as `openai/gpt-6`, or a known prefix), each on foldrun's price list; a login gateway key maps to Claude models only; `{ models: null }` clears it. Answers `{ ok, id, models }`. `keys:manage` and an admin of every workspace; any other key is 400. The gateway reads the change within its 10 s key cache. Audited as `apikey.models`. The same `models` may be given when minting (`POST /api/keys { purpose: "gateway", models }`) |
|
|
370
371
|
| `/api/keys/<id>/rotate` | POST | a new key with the old one's label, role, workspaces and deploy scope — and, when it had an end, the same lifetime from today — returned once like a mint (`{ ok, key, id, prefix, role, workspaces, expiresAt, replaced: { id, endsAt } }`). `grace`: `0` (default — the old key is revoked at once), or a duration up to `7d` such as `1h` or `24h`, during which the old key still works and after which it is refused as expired. A key is rotated once: rotating a key already replaced is 409 `this key was already rotated to <prefix>…; rotate that one` — and someone who lost the new key's secret rotates the NEW key, which mints another and ends the lost one (rotating the old one again would leave the lost key working). Two rotations of one key at once mint one key. `keys:manage`; a key outside the caller's scope is 404 — except that a key `foldrun login` minted may rotate **itself**, whatever its role: same label, role, workspaces and 90-day lifetime from today, the old key ending 10 minutes later (`grace` is not read). A retry with the old key inside those 10 minutes — the CLI lost the answer, or could not store it — rotates that replacement instead, when nobody has used it and it is at least 30 seconds old (a younger one is a 409: another command may have just stored it). That is how the CLI renews its sign-in; any other key rotating itself still needs `keys:manage`. Audited as `apikey.rotated` (`self: true` for a self-rotation). A `foldrun login` key stays one only when it renews itself or its own person rotates it, signed in; rotated by any other caller the new key is an ordinary one |
|
|
371
372
|
| `/api/team` | GET, POST | members with their roles and workspace scope; mint an invite (a session, or the person's own `foldrun login` key, which invites no admin) — `role` (viewer \| editor \| admin, default editor), `workspaces` (names, or omit for all), `email` (only that address can accept it; sent through the account's `RESEND_API_KEY` unless `send: false`). An invite works **once**, for seven days, and a newer invite to the same address revokes the older ones still pending. Returns `id`, `path` (the invite's relative URL, shown only here), `expires`, `sent` and any `sendError` either way; the full link is in the mail. Links made before 29 Oct 2026 (`inv1`–`inv3`) are refused |
|
|
372
373
|
| `/api/team/invites?all=1` | GET | the account's invites, newest first — pending ones unless `all=1` (then accepted, revoked and expired too): `{ invites: [{ id, email, role, workspaces, invitedBy, createdAt, expiresAt, status }] }`, `email` `null` for a link anyone may use, `workspaces` `null` for all, `status` `pending` \| `accepted` \| `revoked` \| `expired`. Never the link. `team:manage` — an admin key included; a caller scoped to some workspaces sees only the invites inside its scope |
|
package/docs/claude-code.md
CHANGED
|
@@ -66,6 +66,60 @@ only on such an account). Such a key:
|
|
|
66
66
|
It is for the operator's own use. A subscription's terms are its owner's to
|
|
67
67
|
keep; foldrun's models (the rest of this page) are what to give anyone else.
|
|
68
68
|
|
|
69
|
+
## Other providers' models
|
|
70
|
+
|
|
71
|
+
The same key reaches DeepSeek's, Kimi's, OpenAI's and Gemini's models: name
|
|
72
|
+
one, and the gateway sends it to that provider on foldrun's models (billed at
|
|
73
|
+
its price, under the same limits).
|
|
74
|
+
|
|
75
|
+
```sh
|
|
76
|
+
claude --model deepseek/deepseek-v4 # or /model deepseek/deepseek-v4 in a session
|
|
77
|
+
claude --model kimi/kimi-k3
|
|
78
|
+
claude --model openai/gpt-6 # or gpt-6
|
|
79
|
+
claude --model gemini/gemini-3-pro # or gemini-3-pro
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
- **Choosing a provider.** `provider/model` always works (`anthropic/`,
|
|
83
|
+
`deepseek/`, `kimi/`, `openai/`, `gemini/`). A bare name with a known prefix
|
|
84
|
+
works too: `deepseek-…`, `kimi-…`, `gpt-…`, `gemini-…`, or `claude-…` for
|
|
85
|
+
Anthropic. Anything else goes to Anthropic.
|
|
86
|
+
- **How each is reached.** DeepSeek and Kimi speak Anthropic's format and are
|
|
87
|
+
sent as they are. OpenAI (Responses API) and Gemini (Chat Completions) are
|
|
88
|
+
translated both ways, by the same translator runs use.
|
|
89
|
+
- Tools work on all of them.
|
|
90
|
+
- Gemini's thought signatures are kept between your calls (in the
|
|
91
|
+
platform's cache, per account, for two hours), so a multi-turn tool loop
|
|
92
|
+
works on Gemini too.
|
|
93
|
+
- Translation drops prompt caching, thinking where the provider has none,
|
|
94
|
+
and Anthropic's server tools (web search, web fetch).
|
|
95
|
+
- **What Claude Code sends.** It sends the name you give it unchanged.
|
|
96
|
+
Claude Code's own `/model` list shows Claude models only, so type the name.
|
|
97
|
+
Each provider gets only the request fields its API takes; the rest are
|
|
98
|
+
dropped.
|
|
99
|
+
- **Token counts.** A provider with no token-count route gets an estimate
|
|
100
|
+
(marked `x-foldrun-estimate: 1`).
|
|
101
|
+
- **What Claude Code can't know.** For non-Claude models it shows the wrong
|
|
102
|
+
cost and context size. The charge is foldrun's.
|
|
103
|
+
- **What isn't offered.** A login gateway key stays Claude-only.
|
|
104
|
+
|
|
105
|
+
## Run Claude Code's own tiers on other models
|
|
106
|
+
|
|
107
|
+
Claude Code's `/model` list shows Claude's tiers alone. A gateway key can map
|
|
108
|
+
each tier to any model foldrun offers, so picking Sonnet in `/model` (or
|
|
109
|
+
`--model sonnet`) runs, say, GPT — with no setting in Claude Code at all:
|
|
110
|
+
|
|
111
|
+
```sh
|
|
112
|
+
foldrun keys set <id> --sonnet openai/gpt-6 --haiku deepseek/deepseek-v4
|
|
113
|
+
foldrun keys set <id> --haiku - # Haiku back to Claude
|
|
114
|
+
foldrun keys set <id> --clear # every tier as Claude Code names it
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
On Settings → API keys, a gateway key's **Models** button does the same, and
|
|
118
|
+
the row shows what each tier runs on. A mapped model must be on foldrun's
|
|
119
|
+
price list; a login gateway key maps to Claude models only. The gateway reads a
|
|
120
|
+
change within 10 seconds. API: `PATCH /api/keys/<id> { models }`, or `models`
|
|
121
|
+
when minting.
|
|
122
|
+
|
|
69
123
|
## What the gateway serves
|
|
70
124
|
|
|
71
125
|
| Route | |
|
|
@@ -109,8 +163,10 @@ the reason:
|
|
|
109
163
|
| `401` | no key, an unknown, revoked or expired key |
|
|
110
164
|
| `403` | not a gateway key; foldrun's models off for the account |
|
|
111
165
|
| `402` | out of credits; the key's limit or the account's daily limit has no room; a model with no price |
|
|
166
|
+
| `429` | the key's request rate (300 a minute) or its open calls (32 at once) — with `Retry-After`; waiting helps. Every route and every kind of key counts |
|
|
112
167
|
| `400` | a request field that is not offered (named in the message) |
|
|
113
168
|
|
|
114
|
-
A
|
|
169
|
+
A key that is revoked can still answer for up to 10 seconds: each gateway pod
|
|
170
|
+
caches a key for that long. A spent limit is a `402`, not a `429`: Claude Code retries a `429` for minutes,
|
|
115
171
|
and no retry makes room under a limit. A `429` from Anthropic itself comes
|
|
116
172
|
back as it was.
|
package/docs/cli.md
CHANGED
|
@@ -209,6 +209,7 @@ claude.ai or Claude Code there, nor any MCP configuration on disk.
|
|
|
209
209
|
| `foldrun keys rotate <id>` | a new key with the old one's label, role, workspaces and deploy scope, printed once; the old key is revoked at once (asks first; `--yes` on a pipe), or keeps working for `--grace 1h` / `24h` while you swap the new one in. A key already rotated is refused (409) and the command names the key that replaced it — rotate that one, also if its secret was lost; `keys ls` shows `rotated → <id>`. The owner is emailed a week before any key expires |
|
|
210
210
|
| `foldrun keys create <label> --a2a --to <ws> --flows a,b` | a key for an outside agent ([A2A](a2a.md)): it opens `/a2a/<account>/<ws>/…` — the agent card and JSON-RPC endpoint of those flows, each published with `a2a:` (a flow not published when the key is minted is refused: publish first) — and no `/api` route. `--max-tasks <n>` caps the tasks it may have open at once (1–100, default 10); `--expires` as for any key. Printed once; `keys ls` shows it as `A2A · <ws> · <flows>`. `POST /api/keys { purpose: "a2a", workspace, flows, maxTasks }`, an admin's |
|
|
211
211
|
| `foldrun keys create <label> --gateway --cap <usd>` | a gateway key for a coding agent ([Claude Code](claude-code.md)): `ANTHROPIC_BASE_URL` + this key run Claude Code on the account's credits, through foldrun's gateway, and it opens no `/api` route. `--cap` (USD in all) and/or `--daily` (USD per UTC day) — at least one, $0.01–$100,000; `--expires` as for any key. Printed once with the two `export` lines; `keys ls` shows it as `gateway · Claude Code · $spent of $cap · $today of $daily today`. `POST /api/keys { purpose: "gateway", capUsd, dailyUsd }`, an admin of every workspace |
|
|
212
|
+
| `foldrun keys set <id> --sonnet <model>` | a gateway key's model map: which model each Claude Code tier runs on with that key (`--opus`, `--sonnet`, `--haiku`, each `provider/model` such as `openai/gpt-6`; `-` clears one, `--clear` all). The tiers named change, the rest stay. `keys ls` shows the map. `PATCH /api/keys/<id> { models }`, an admin of every workspace |
|
|
212
213
|
| `foldrun a2a ls --to <ws>` | what a workspace serves over A2A (`GET /api/workspaces/<ws>/a2a`): every flow that says `a2a:`, published or not, with its public/private card and its card and endpoint URLs; the workspace's A2A keys (an admin's view; `null` otherwise); and the newest tasks — state, flow, run, and `A2A · <key label>`; then, under **Secret and code**, every agent that holds a secret and can run code, accepted or not, with the `--accept-risk` line that accepts it. `--json` prints the answer as it came |
|
|
213
214
|
| `foldrun a2a publish <flow>` | sets `a2a: { publish: true }` in the flow, keeping the rest of its block: `--name`, `--description`, `--example "…"` (repeatable — the card's examples), `--public-card` (the card is readable without a key; calling never is) or `--private-card`. Checked with core's `a2a:` rules before anything is written; shows the diff, `--dry-run` writes nothing. Without `--to` it edits this folder (`deploy` ships it); `--to <workspace>` sends the flow page's `PATCH …/flows/<flow> { a2a, expect }` — an admin's, the platform refuses an editor — and prints the card URL. A caller also needs an A2A key that names the flow |
|
|
214
215
|
| `foldrun a2a unpublish <flow>` | `a2a: publish: false` — no outside agent may call it, whatever keys name it; the rest of `a2a:` stays for the next publish. `--to`, `--dry-run` as for `publish` |
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "foldrun",
|
|
3
|
-
"version": "20.
|
|
3
|
+
"version": "20.4.0",
|
|
4
4
|
"description": "Agents are just folders. Write them, check them, run them — on your machine.",
|
|
5
5
|
"license": "FSL-1.1-ALv2",
|
|
6
6
|
"type": "module",
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"node": ">=22"
|
|
12
12
|
},
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"@foldrun/core": "^18.0.
|
|
14
|
+
"@foldrun/core": "^18.0.1"
|
|
15
15
|
},
|
|
16
16
|
"files": [
|
|
17
17
|
"bin",
|
package/src/commands.mjs
CHANGED
|
@@ -4697,6 +4697,7 @@ async function doctor(flags) {
|
|
|
4697
4697
|
* keys create <label> --a2a --to <ws> --flows a,b [--max-tasks N] a key for an outside agent: /a2a only
|
|
4698
4698
|
* keys create <label> --gateway --cap <usd> [--daily <usd>] a coding agent's key (Claude Code): the gateway only
|
|
4699
4699
|
* keys create <label> --gateway --login on the operator's Claude login (its own accounts): not metered
|
|
4700
|
+
* keys set <id> --opus|--sonnet|--haiku <provider/model> which model each Claude Code tier runs on (a gateway key; `-` clears one, --clear all)
|
|
4700
4701
|
* keys rotate <id> [--grace 1h] a new key, same label/role/scope; the old
|
|
4701
4702
|
* one ends now, or when the grace runs out.
|
|
4702
4703
|
* A key already rotated is refused (409):
|
|
@@ -4795,7 +4796,8 @@ async function keysCmd(positional, flags) {
|
|
|
4795
4796
|
console.log(` ${c.dim(`Shown once. The old key ${grace === "0" ? "is revoked" : `keeps working until ${String(ends).slice(0, 16).replace("T", " ")} UTC`}.`)}\n`);
|
|
4796
4797
|
return 0;
|
|
4797
4798
|
}
|
|
4798
|
-
|
|
4799
|
+
if (verb === "set") return keysSetModels(url, arg, flags);
|
|
4800
|
+
throw new Error(`keys: unknown verb "${verb}" — ls, create, set, rotate, revoke`);
|
|
4799
4801
|
}
|
|
4800
4802
|
|
|
4801
4803
|
/**
|
|
@@ -4827,15 +4829,55 @@ async function keysCreateA2a(url, label, flags) {
|
|
|
4827
4829
|
return 0;
|
|
4828
4830
|
}
|
|
4829
4831
|
|
|
4832
|
+
/**
|
|
4833
|
+
* `foldrun keys set <id> --sonnet openai/gpt-6 [--opus …] [--haiku …]` — a
|
|
4834
|
+
* gateway key's model map: which model each Claude Code tier runs on with
|
|
4835
|
+
* that key. The tiers named change; the rest stay. `-` clears one tier,
|
|
4836
|
+
* `--clear` every one. PATCH /api/keys/<id> { models }.
|
|
4837
|
+
*/
|
|
4838
|
+
async function keysSetModels(url, id, flags) {
|
|
4839
|
+
if (!id) throw new Error("which key? foldrun keys set <id> --sonnet openai/gpt-6 — ids are in `foldrun keys ls`");
|
|
4840
|
+
const tiers = ["opus", "sonnet", "haiku"];
|
|
4841
|
+
const named = tiers.filter((t) => flags[t] !== undefined);
|
|
4842
|
+
if (flags.clear !== true && !named.length) throw new Error("which tier? --opus, --sonnet or --haiku <provider/model> (`-` clears one), or --clear for all");
|
|
4843
|
+
for (const t of named) if (typeof flags[t] !== "string" || !flags[t]) throw new Error(`--${t} needs a model, e.g. --${t} openai/gpt-6 (or - to clear it)`);
|
|
4844
|
+
let models = null;
|
|
4845
|
+
if (flags.clear !== true) {
|
|
4846
|
+
const { keys = [] } = await remoteCall(url, flags, "/api/keys");
|
|
4847
|
+
const key = keys.find((k) => k.id === id);
|
|
4848
|
+
if (!key) throw new Error(`no key ${id} — \`foldrun keys ls\` lists them`);
|
|
4849
|
+
if (key.purpose !== "gateway") throw new Error(`${id} is not a gateway key — only a gateway key has a model map`);
|
|
4850
|
+
const next = { ...(key.gateway?.models ?? {}) };
|
|
4851
|
+
for (const t of named) {
|
|
4852
|
+
if (flags[t] === "-") delete next[t];
|
|
4853
|
+
else next[t] = flags[t];
|
|
4854
|
+
}
|
|
4855
|
+
models = Object.keys(next).length ? next : null;
|
|
4856
|
+
}
|
|
4857
|
+
const made = await remoteCall(url, flags, `/api/keys/${encodeURIComponent(id)}`, { method: "PATCH", body: JSON.stringify({ models }) });
|
|
4858
|
+
const line = modelsLine(made.models);
|
|
4859
|
+
console.log(`\n ${c.green("✓")} ${c.bold(id)} ${line ? c.dim(line) : c.dim("runs Claude Code's models as named")}\n`);
|
|
4860
|
+
return 0;
|
|
4861
|
+
}
|
|
4862
|
+
|
|
4863
|
+
/** A gateway key's model map in one line, or null when there is none. */
|
|
4864
|
+
function modelsLine(m) {
|
|
4865
|
+
const label = { opus: "Opus", sonnet: "Sonnet", haiku: "Haiku" };
|
|
4866
|
+
const parts = ["opus", "sonnet", "haiku"].filter((t) => m?.[t]).map((t) => `${label[t]} → ${m[t]}`);
|
|
4867
|
+
return parts.length ? parts.join(" · ") : null;
|
|
4868
|
+
}
|
|
4869
|
+
|
|
4830
4870
|
/** How `keys ls` describes a gateway key: its limits, and what it has spent. */
|
|
4831
4871
|
function gatewayLine(g) {
|
|
4832
|
-
|
|
4872
|
+
const map = modelsLine(g?.models);
|
|
4873
|
+
const tail = map ? ` · ${map}` : "";
|
|
4874
|
+
if (g?.credential === "login") return `gateway · Claude Code · the operator's Claude login · not metered${tail}`;
|
|
4833
4875
|
const usd = (n) => `$${Number(n ?? 0).toFixed(2)}`;
|
|
4834
4876
|
const parts = ["gateway · Claude Code"];
|
|
4835
4877
|
if (g?.capUsd != null) parts.push(`${usd(g.spentUsd)} of ${usd(g.capUsd)}`);
|
|
4836
4878
|
else if (g?.spentUsd != null) parts.push(`${usd(g.spentUsd)} spent`);
|
|
4837
4879
|
if (g?.dailyUsd != null) parts.push(`${usd(g.todayUsd)} of ${usd(g.dailyUsd)} today`);
|
|
4838
|
-
return parts.join(" · ");
|
|
4880
|
+
return parts.join(" · ") + tail;
|
|
4839
4881
|
}
|
|
4840
4882
|
|
|
4841
4883
|
/** A dollar limit from a flag: above 0, at most 100000 (what the platform takes). */
|
|
@@ -4879,7 +4921,11 @@ async function keysCreateGateway(url, label, flags) {
|
|
|
4879
4921
|
console.log(` ${c.dim("Shown once. Point Claude Code at it:")}\n`);
|
|
4880
4922
|
console.log(` export ANTHROPIC_BASE_URL=${base}`);
|
|
4881
4923
|
console.log(` export ANTHROPIC_API_KEY=<key>\n`);
|
|
4882
|
-
|
|
4924
|
+
// A login key is not metered: there is no spend for `keys ls` to show.
|
|
4925
|
+
const after = made.credential === "login"
|
|
4926
|
+
? `It opens the gateway only and runs on the operator's Claude login, not metered — it shares that subscription's weekly cap with the desks. \`foldrun keys revoke ${made.id}\` ends it.`
|
|
4927
|
+
: `It opens the gateway only. \`foldrun keys ls\` shows what it has spent; \`foldrun keys revoke ${made.id}\` ends it.`;
|
|
4928
|
+
console.log(` ${c.dim(after)}\n`);
|
|
4883
4929
|
return 0;
|
|
4884
4930
|
}
|
|
4885
4931
|
|