aegiscode 6.7.5 → 6.7.6
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/README.md +253 -5
- package/package.json +1 -1
- package/scripts/predist.mjs +6 -0
- package/src/app.js +139 -8
- package/src/chatflow.js +9 -1
- package/src/commands.js +255 -30
- package/src/config.js +8 -0
- package/src/deps.js +10 -1
- package/src/engine.js +93 -15
- package/src/overlays.js +22 -3
- package/src/panels.js +14 -2
- package/src/tokens.js +56 -18
- package/vendor/client/aegis.js +10 -2
- package/vendor/desktop/lib/local/engine.js +29 -4
- package/vendor/desktop/lib/settings.js +364 -0
- package/vendor/desktop/renderer/usage.js +42 -11
package/README.md
CHANGED
|
@@ -13,6 +13,42 @@ an editor — built on the same two shared pieces and no others:
|
|
|
13
13
|
|
|
14
14
|
Routing, model tiers, memory and billing all stay behind aegiscloud.org.
|
|
15
15
|
|
|
16
|
+
## Quick start
|
|
17
|
+
|
|
18
|
+
Four steps, in order. Everything past this section is the fuller reference for
|
|
19
|
+
each one.
|
|
20
|
+
|
|
21
|
+
**1. Install** — requires Node 18+.
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
npm install -g aegiscode
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
**2. Log in** — get a key at <https://aegiscloud.org> if you don't have one.
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
aegiscode login # prompts, no echo
|
|
31
|
+
aegiscode key status # verify: masked key + which source is in use
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
**3. (Optional) Bring your own key** — skip this if you're happy on the
|
|
35
|
+
pooled AEGIS Cloud route (the default). Use your own OpenAI/Anthropic/etc. key
|
|
36
|
+
instead, at a flat handling fee instead of the pooled margin — see [Bring your
|
|
37
|
+
own key](#bring-your-own-key).
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
/byok # list providers and which are already set
|
|
41
|
+
/byok-key openai # save a key on this machine, prompts, no echo
|
|
42
|
+
/class byok # switch the session to run on it
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
**4. Use it.**
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
aegiscode # interactive session
|
|
49
|
+
aegiscode "why is the sky blue" # one-shot, prints the answer and the tokens
|
|
50
|
+
```
|
|
51
|
+
|
|
16
52
|
## Names: one name, `aegiscode`
|
|
17
53
|
|
|
18
54
|
This host and the CLI used to be two names for two packages. They are one
|
|
@@ -30,7 +66,7 @@ Publishing this host as `aegiscode` moves the `latest` dist-tag for that name
|
|
|
30
66
|
onto it. The previous line (`aegiscode@5.x`, the `aegisinfo/aegiscode` agent) is
|
|
31
67
|
still installable and immutable on the registry — pin `aegiscode@5` for it.
|
|
32
68
|
|
|
33
|
-
##
|
|
69
|
+
## Installation
|
|
34
70
|
|
|
35
71
|
```bash
|
|
36
72
|
npm install -g aegiscode
|
|
@@ -58,7 +94,7 @@ That one file is shared: the MCP plugin and AEGIS Desktop read the same store, s
|
|
|
58
94
|
signing in here signs you in everywhere (see [One memory, shared with AEGIS
|
|
59
95
|
Desktop](#one-memory-shared-with-aegis-desktop)).
|
|
60
96
|
|
|
61
|
-
##
|
|
97
|
+
## Launch options
|
|
62
98
|
|
|
63
99
|
```bash
|
|
64
100
|
aegiscode # interactive session
|
|
@@ -149,7 +185,7 @@ folder you just refused to vouch for is not read, edited or executed in.
|
|
|
149
185
|
Preferences survive a restart: model, effort, theme and vim mode are restored on
|
|
150
186
|
launch, and an explicit flag (`-m`, `--light`) always outranks the stored value.
|
|
151
187
|
|
|
152
|
-
##
|
|
188
|
+
## Commands
|
|
153
189
|
|
|
154
190
|
In a session, plain text is a prompt. `/help` lists commands, grouped by
|
|
155
191
|
category, the way `aegiscodex-dev` does. The registry is that client's, ported
|
|
@@ -159,9 +195,9 @@ command for command — 75 entries across nine categories:
|
|
|
159
195
|
|---|---|
|
|
160
196
|
| Session & context | `/clear` `/compact` `/cost` `/exit` `/new` `/recap` `/resume` `/rewind` `/agents` `/status` `/teleport` `/version` `/clone` `/schedule` |
|
|
161
197
|
| Workspace | `/run` `/build` `/cd` `/copy` `/init` `/review` `/prs` |
|
|
162
|
-
| Model & behavior | `/model` `/effort` `/thinking` `/theme` `/vim` `/router` `/confirm` `/yolo` `/permissions` `/hooks` `/skills` `/mcp` |
|
|
198
|
+
| Model & behavior | `/model` `/models` `/class` `/effort` `/thinking` `/theme` `/vim` `/router` `/confirm` `/yolo` `/permissions` `/hooks` `/skills` `/mcp` |
|
|
163
199
|
| Data | `/context` `/export` `/tokens` `/sync` |
|
|
164
|
-
| Auth | `/key` `/login` `/logout` `/credentials` `/byok` `/byok-set` `/byok-rm` |
|
|
200
|
+
| Auth | `/key` `/login` `/logout` `/credentials` `/byok` `/byok-set` `/byok-rm` `/byok-key` `/byok-rm-key` |
|
|
165
201
|
| Support | `/help` `/doctor` `/troubleshooting` `/feedback` `/bug` `/issue` `/onboarding` `/benchmark` `/release-notes` `/billing` `/cloud` |
|
|
166
202
|
| Aegis plugin | `/aegis-ask` `/aegis-status` `/aegis-recall` `/aegis-remember` `/memory` `/aegis-council` `/aegis-multi` `/aegis-print` `/aegis-import` `/tool` |
|
|
167
203
|
| Fun | `/radio` `/waifu` |
|
|
@@ -178,6 +214,218 @@ the project and writes `AEGIS.md`, `/export` writes the transcript out,
|
|
|
178
214
|
`/resume` and `/rewind` read the session store, `/cd` moves the working
|
|
179
215
|
directory, `/doctor` runs diagnostics.
|
|
180
216
|
|
|
217
|
+
## Model selection
|
|
218
|
+
|
|
219
|
+
Three layers, from broadest to narrowest. You only need the first one.
|
|
220
|
+
|
|
221
|
+
**1. The class — which route the turn takes.**
|
|
222
|
+
|
|
223
|
+
```bash
|
|
224
|
+
/class # show the picker
|
|
225
|
+
/class aegis # pooled AEGIS Cloud (the default)
|
|
226
|
+
/class byok # your own provider key, relayed by AEGIS
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
A class is *whose credential pays and who talks to the vendor*, not a model.
|
|
230
|
+
Switching applies to your **next** turn and leaves the conversation intact. The
|
|
231
|
+
choice is written to `~/.aegiscode/config.json` (`modelClass`), so it survives a
|
|
232
|
+
restart.
|
|
233
|
+
|
|
234
|
+
| Class | Route | Who pays |
|
|
235
|
+
|---|---|---|
|
|
236
|
+
| `aegis` *(default)* | the AEGIS pool — one id, `nexus-brain` (alias `aegis-brain`), auto-routed server-side across whichever providers are live | your AEGIS account balance |
|
|
237
|
+
| `byok` | your provider key, relayed via `POST /api/v1/byok/chat/completions` | your provider direct, **plus** a small AEGIS handling fee on your account |
|
|
238
|
+
|
|
239
|
+
**2. The model id — what to pin.**
|
|
240
|
+
|
|
241
|
+
```bash
|
|
242
|
+
/models # what you can pin, for the class you are on
|
|
243
|
+
/model # open the picker
|
|
244
|
+
/model nexus-brain # pin it
|
|
245
|
+
/model - # clear the pin, back to the class default
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
`/models` is class-aware: it answers from the pool catalogue under `aegis`, and
|
|
249
|
+
from the models your saved keys actually unlock under `byok`. A pooled id is
|
|
250
|
+
**cleared with a reason** if you switch to `byok` while it is pinned, instead of
|
|
251
|
+
failing later at the relay.
|
|
252
|
+
|
|
253
|
+
Under `byok` every id is compound — `provider:model`:
|
|
254
|
+
|
|
255
|
+
```bash
|
|
256
|
+
/models # e.g. anthropic:claude-sonnet-4-5
|
|
257
|
+
/model anthropic:claude-sonnet-4-5
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
```bash
|
|
261
|
+
aegiscode -m nexus-brain -p "…" # pin at launch
|
|
262
|
+
aegiscode -m anthropic:claude-sonnet-4-5 -p "…" # a BYOK id at launch
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
**3. Effort — how hard it reasons.**
|
|
266
|
+
|
|
267
|
+
```bash
|
|
268
|
+
/effort # show
|
|
269
|
+
/effort low|medium|high
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
Effort scales the token budget the provider is given, so it is the dial that
|
|
273
|
+
actually changes reasoning depth on a reasoning model (see the root README for
|
|
274
|
+
the per-provider mechanics).
|
|
275
|
+
|
|
276
|
+
> **A BYOK turn is single-shot.** The relay takes no `tools` parameter, so the
|
|
277
|
+
> agentic tool loop is off by construction — no file edits, no shell, no
|
|
278
|
+
> subagents, no approval cards. `/class` says so rather than letting you discover
|
|
279
|
+
> it mid-task.
|
|
280
|
+
|
|
281
|
+
## Bring your own key
|
|
282
|
+
|
|
283
|
+
Two lanes. The one people mix up is which key goes where, so state it plainly:
|
|
284
|
+
**`/byok-set` stores on your AEGIS account; `/byok-key` stores on this machine.**
|
|
285
|
+
|
|
286
|
+
| | `/byok-set <provider>` | `/byok-key <provider>` |
|
|
287
|
+
|---|---|---|
|
|
288
|
+
| Key lives | on your AEGIS account, encrypted server-side | in `~/.aegiscode/settings.json` (mode `0600`) |
|
|
289
|
+
| Follows you to other machines | yes | no |
|
|
290
|
+
| Reaches the vendor via | AEGIS, server-side | AEGIS's BYOK relay |
|
|
291
|
+
| Needed for `/class byok`? | no | **yes** — this is the one the relay reads |
|
|
292
|
+
|
|
293
|
+
### Save a key on this machine
|
|
294
|
+
|
|
295
|
+
```bash
|
|
296
|
+
/byok # list every provider, and which are already set
|
|
297
|
+
/byok-key openai # prompts, no echo, never enters history
|
|
298
|
+
/byok-key openai sk-… # scriptable form
|
|
299
|
+
/byok-rm-key openai # forget it
|
|
300
|
+
```
|
|
301
|
+
|
|
302
|
+
The first command is the one to run when you don't know a provider id. The
|
|
303
|
+
catalogue is server-side and grows, so `/byok` is the authority — each row names
|
|
304
|
+
the provider, the models its key unlocks, where the vendor issues it, and the
|
|
305
|
+
prefix a valid key starts with. A typo'd or wrong-vendor key is caught before it
|
|
306
|
+
is stored.
|
|
307
|
+
|
|
308
|
+
### Save a key on your account
|
|
309
|
+
|
|
310
|
+
```bash
|
|
311
|
+
/byok-set anthropic # prompts, no echo
|
|
312
|
+
/byok-rm anthropic # remove it
|
|
313
|
+
```
|
|
314
|
+
|
|
315
|
+
### What a BYOK turn costs
|
|
316
|
+
|
|
317
|
+
Bringing your own key does not make the turn free, and it is not meant to. AEGIS
|
|
318
|
+
pays the vendor nothing on this lane, so there is no provider cost to take a
|
|
319
|
+
margin on — the account is charged a flat **handling fee** per 1k tokens
|
|
320
|
+
instead, for the routing, prompt assembly, caching, tool bridging and uptime
|
|
321
|
+
that still happen server-side. It is deliberately well under the pooled price
|
|
322
|
+
for the same traffic, so BYOK stays the cheaper lane; it just is not the free
|
|
323
|
+
one.
|
|
324
|
+
|
|
325
|
+
The figure is published by the server (`GET /api/v1/byok/providers` returns
|
|
326
|
+
`fee`) and never hardcoded in this client, so what you see is what is charged.
|
|
327
|
+
Two consequences worth knowing:
|
|
328
|
+
|
|
329
|
+
- A BYOK turn needs an **AEGIS account key** as well as your provider key — that
|
|
330
|
+
is where the fee is billed. Without one the relay refuses up front and says so,
|
|
331
|
+
rather than running the turn and dropping the charge.
|
|
332
|
+
- If a fee is ever configured to zero the lane is genuinely free, and nothing in
|
|
333
|
+
this client needs to change to reflect that.
|
|
334
|
+
|
|
335
|
+
Removing a key is the only thing that stops the key being sent; unsetting
|
|
336
|
+
`/class byok` switches the route but leaves the key on disk.
|
|
337
|
+
|
|
338
|
+
## Command manual
|
|
339
|
+
|
|
340
|
+
Copy-paste, in the order you actually need them.
|
|
341
|
+
|
|
342
|
+
### Install and sign in
|
|
343
|
+
|
|
344
|
+
```bash
|
|
345
|
+
npm install -g aegiscode # requires Node 18+
|
|
346
|
+
aegiscode login # prompts for your AEGIS key, no echo
|
|
347
|
+
aegiscode key status # verify: masked key + which source is in use
|
|
348
|
+
aegiscode # start a session
|
|
349
|
+
```
|
|
350
|
+
|
|
351
|
+
No AEGIS key yet? Get one at <https://aegiscloud.org>. To run entirely on your
|
|
352
|
+
own provider key instead, skip `login` and see
|
|
353
|
+
[Bring your own key](#bring-your-own-key) — note that lane still bills its fee to
|
|
354
|
+
an AEGIS account.
|
|
355
|
+
|
|
356
|
+
### Day one in a repo
|
|
357
|
+
|
|
358
|
+
```bash
|
|
359
|
+
cd ~/my-project
|
|
360
|
+
aegiscode # first run asks you to trust the folder
|
|
361
|
+
/init # sniff the project, write AEGIS.md
|
|
362
|
+
/status # key, class, model, effort, cwd — one panel
|
|
363
|
+
```
|
|
364
|
+
|
|
365
|
+
Then just type. Plain text is a prompt.
|
|
366
|
+
|
|
367
|
+
### Ask one question and leave
|
|
368
|
+
|
|
369
|
+
```bash
|
|
370
|
+
aegiscode "explain this stack trace"
|
|
371
|
+
aegiscode -p "summarise docs/design.md" --json
|
|
372
|
+
echo "why is the sky blue" | aegiscode -p -
|
|
373
|
+
```
|
|
374
|
+
|
|
375
|
+
`--json` emits the answer plus the usage object, token total and balance.
|
|
376
|
+
|
|
377
|
+
### Switch how you're paying
|
|
378
|
+
|
|
379
|
+
```bash
|
|
380
|
+
/class # see both routes and who pays
|
|
381
|
+
/class byok # use your own key
|
|
382
|
+
/byok-key openai # …save one first if it says you have none
|
|
383
|
+
/models # what that key unlocks
|
|
384
|
+
/model openai:gpt-4o # pin one
|
|
385
|
+
/class aegis # back to the pool
|
|
386
|
+
```
|
|
387
|
+
|
|
388
|
+
### Control the budget
|
|
389
|
+
|
|
390
|
+
```bash
|
|
391
|
+
/effort low # cheaper, shallower
|
|
392
|
+
/effort high # deeper reasoning
|
|
393
|
+
/cost # this session
|
|
394
|
+
/balance # tokens beside € on every ledger row
|
|
395
|
+
/billing # spend and plan
|
|
396
|
+
```
|
|
397
|
+
|
|
398
|
+
### Keep the work
|
|
399
|
+
|
|
400
|
+
```bash
|
|
401
|
+
/compact # shrink the context, keep the thread
|
|
402
|
+
/export markdown ~/notes/session.md
|
|
403
|
+
/resume # pick up a saved session
|
|
404
|
+
/rewind 3 # back up three turns
|
|
405
|
+
/sync # push pending, then pull
|
|
406
|
+
```
|
|
407
|
+
|
|
408
|
+
### When something is wrong
|
|
409
|
+
|
|
410
|
+
```bash
|
|
411
|
+
/doctor # diagnostics, in one panel
|
|
412
|
+
/status # key + class + model actually in effect
|
|
413
|
+
/byok # which provider keys are set
|
|
414
|
+
/troubleshooting
|
|
415
|
+
```
|
|
416
|
+
|
|
417
|
+
### Unattended work
|
|
418
|
+
|
|
419
|
+
```bash
|
|
420
|
+
aegiscode autonomous add "fix the flaky retry test" --cwd ~/repo
|
|
421
|
+
aegiscode autonomous list
|
|
422
|
+
aegiscode autonomous proceed --commit
|
|
423
|
+
```
|
|
424
|
+
|
|
425
|
+
Queued tasks always run on the pooled brain (`nexus-brain`); a task naming
|
|
426
|
+
another model is refused where you can still see it. `--commit` commits only the
|
|
427
|
+
paths that task's own tool layer wrote.
|
|
428
|
+
|
|
181
429
|
## Account key and cloud sync
|
|
182
430
|
|
|
183
431
|
Three ways in, one store: `aegiscode login <key>`, `/key <api_key>` (or a bare
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "aegiscode",
|
|
3
3
|
"productName": "AEGIS Code",
|
|
4
|
-
"version": "6.7.
|
|
4
|
+
"version": "6.7.6",
|
|
5
5
|
"description": "aegiscode — the command-line version of AEGIS Desktop. The shared tool surface in your shell, over the same thin transport and tool registry as the MCP plugin and the desktop app. Ships transport + UI only; no brain.",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "AEGIS Code",
|
package/scripts/predist.mjs
CHANGED
|
@@ -61,6 +61,12 @@ const FILES = [
|
|
|
61
61
|
'desktop/lib/local/shell.js',
|
|
62
62
|
'desktop/lib/local/agents.js',
|
|
63
63
|
'desktop/lib/local/prompt.js',
|
|
64
|
+
// The provider-config store: one row per provider (base URL + key), and the
|
|
65
|
+
// row the 'byok' class reads for a per-provider key. The CLI now selects that
|
|
66
|
+
// class (src/engine.js), so it needs the same store the desktop writes —
|
|
67
|
+
// created without a safeStorage argument, which the store already supports
|
|
68
|
+
// (base64 at rest, file mode 0600). Pure node builtins, so it stages cleanly.
|
|
69
|
+
'desktop/lib/settings.js',
|
|
64
70
|
// engine.js requires all three at load time (turn-guard -> git-scope, and
|
|
65
71
|
// worktree-lock), so leaving them out stages a vendor tree whose engine
|
|
66
72
|
// throws MODULE_NOT_FOUND before it can answer anything — which is what
|
package/src/app.js
CHANGED
|
@@ -22,7 +22,7 @@ const readline = require('node:readline');
|
|
|
22
22
|
const os = require('node:os');
|
|
23
23
|
const { randomUUID } = require('node:crypto');
|
|
24
24
|
const { createTools, createClient, usageTokens, buildSystemPrompt } = require('./deps.js');
|
|
25
|
-
const { createEngine } = require('./engine.js');
|
|
25
|
+
const { createEngine, HOST_CLASSES, DEFAULT_CLASS, byokNamespace } = require('./engine.js');
|
|
26
26
|
const { GLYPH, VERBS, themeOf, RESET, THEME_TABLE } = require('./theme.js');
|
|
27
27
|
const { LiveRegion, termWidth, w } = require('./screen.js');
|
|
28
28
|
const { editPreview } = require('./diff.js');
|
|
@@ -126,6 +126,10 @@ function createApp(options = {}) {
|
|
|
126
126
|
options.engine ||
|
|
127
127
|
createEngine({
|
|
128
128
|
client,
|
|
129
|
+
// The live class — read per turn rather than captured, for the same
|
|
130
|
+
// reason confirmMode is a callback: a captured value made `/class`
|
|
131
|
+
// cosmetic, changing the panel and not what the next turn ran on.
|
|
132
|
+
getClass: () => commandCtx.modelClass,
|
|
129
133
|
getConfirmMode: () => {
|
|
130
134
|
if (options.confirmMode !== undefined) return confirmMode;
|
|
131
135
|
try {
|
|
@@ -135,6 +139,14 @@ function createApp(options = {}) {
|
|
|
135
139
|
}
|
|
136
140
|
},
|
|
137
141
|
});
|
|
142
|
+
// How a class is named in every surface that shows one (the status line, the
|
|
143
|
+
// class panel, the model picker's title). One definition, because the engine
|
|
144
|
+
// owns the label table (CLASS_LABELS) and re-spelling it here would let the
|
|
145
|
+
// picker and /class disagree about what the user is about to run on. Guarded
|
|
146
|
+
// because an injected engine (tests, embedding) may predate the class surface.
|
|
147
|
+
const classLabelOf = (cls) =>
|
|
148
|
+
typeof engine.classLabel === 'function' ? engine.classLabel(cls) : String(cls || '');
|
|
149
|
+
|
|
138
150
|
// Set by runInteractive: a question/answer channel for the engine's
|
|
139
151
|
// tool-approval requests. Left null in one-shot (-p) runs, where there is
|
|
140
152
|
// no one to ask — see the approval branch in ask() below.
|
|
@@ -149,6 +161,10 @@ function createApp(options = {}) {
|
|
|
149
161
|
const commandCtx = {
|
|
150
162
|
light: opts.light,
|
|
151
163
|
model: opts.model,
|
|
164
|
+
// Which class the next turn runs on. 'aegis' is the default because it is
|
|
165
|
+
// the one class an account key alone can run — BYOK additionally needs a
|
|
166
|
+
// provider key, so defaulting to it would break a fresh install.
|
|
167
|
+
modelClass: DEFAULT_CLASS,
|
|
152
168
|
// `null` = "auto": send no effort, so the server sizes the turn from the
|
|
153
169
|
// ask. This is the *budget* control on the pooled class (aegis1 sizes the
|
|
154
170
|
// token ladder from it), which is why it is not defaulted to a rung here —
|
|
@@ -443,6 +459,82 @@ function createApp(options = {}) {
|
|
|
443
459
|
// providers without a client release.
|
|
444
460
|
const MODEL_CACHE_MS = 5 * 60_000;
|
|
445
461
|
const modelCache = { at: 0, models: [] };
|
|
462
|
+
// The BYOK half of the same question. A BYOK model id is `provider:model`
|
|
463
|
+
// (the engine's splitByokModel), built from the server's provider catalog
|
|
464
|
+
// plus the provider rows this machine actually holds a key for — so this list
|
|
465
|
+
// is per-machine, not per-account, and cannot be served by the pooled catalog.
|
|
466
|
+
const byokCache = { at: 0, models: [] };
|
|
467
|
+
|
|
468
|
+
async function loadByokModels({ force = false } = {}) {
|
|
469
|
+
const fresh = byokCache.models.length && Date.now() - byokCache.at < MODEL_CACHE_MS;
|
|
470
|
+
if (!force && fresh) return byokCache.models;
|
|
471
|
+
// An injected engine (tests, embedding) may predate the class surface; an
|
|
472
|
+
// empty list is the honest answer then, not a fabricated one.
|
|
473
|
+
if (typeof engine.listModels !== 'function') return [];
|
|
474
|
+
const res = await engine.listModels('byok');
|
|
475
|
+
// The engine's row is `{id: "provider:model", label, provider, configured}`.
|
|
476
|
+
// `note` is added here because it is the field both renderers actually paint
|
|
477
|
+
// (the picker draws `m.note || m.model`, /models draws `m.note || m.label`)
|
|
478
|
+
// and because "openai:gpt-4o" alone does not say whether this machine holds
|
|
479
|
+
// the key the relay would ask for — a row without one is a turn that 400s,
|
|
480
|
+
// so it names the command that fixes it.
|
|
481
|
+
byokCache.models = ((res && res.models) || []).map((m) => ({
|
|
482
|
+
...m,
|
|
483
|
+
note: m.configured ? 'key on this machine' : `no key — /byok-key ${m.provider}`,
|
|
484
|
+
}));
|
|
485
|
+
byokCache.at = Date.now();
|
|
486
|
+
return byokCache.models;
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
/**
|
|
490
|
+
* The ids pinnable on one class — the ONE function `/model`, alt+p and
|
|
491
|
+
* `/models` all read, so the picker cannot offer something the class the turn
|
|
492
|
+
* runs on would reject. Both branches swallow their failure into "nothing to
|
|
493
|
+
* offer": a catalog is a convenience, and an offline client must still be
|
|
494
|
+
* able to chat on the server's own default.
|
|
495
|
+
*/
|
|
496
|
+
async function listModelsFor(cls) {
|
|
497
|
+
const want = HOST_CLASSES.includes(cls) ? cls : commandCtx.modelClass;
|
|
498
|
+
try {
|
|
499
|
+
return want === 'byok' ? await loadByokModels() : await loadModels();
|
|
500
|
+
} catch {
|
|
501
|
+
return [];
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
/**
|
|
506
|
+
* Switch the live class. Refuses anything this host cannot run (engine.js's
|
|
507
|
+
* HOST_CLASSES is the authority — the local/custom classes stay stubs).
|
|
508
|
+
*
|
|
509
|
+
* A pin is cleared when it does not belong to the class being entered: a
|
|
510
|
+
* pooled id pinned under byok would be parsed as provider `<pooled id>` and
|
|
511
|
+
* fail at the relay with a confusing "no key saved for …" instead of here,
|
|
512
|
+
* with a reason. Symmetrically, `anthropic:claude-…` under aegis is an id the
|
|
513
|
+
* pooled catalog does not advertise, which is the silent-fallback case
|
|
514
|
+
* validatePinnedModel exists to prevent.
|
|
515
|
+
*/
|
|
516
|
+
function switchClass(next) {
|
|
517
|
+
const want = String(next == null ? '' : next).trim().toLowerCase();
|
|
518
|
+
if (!HOST_CLASSES.includes(want)) {
|
|
519
|
+
return { ok: false, error: `unknown class "${next}" — classes: ${HOST_CLASSES.join(', ')}` };
|
|
520
|
+
}
|
|
521
|
+
const prev = commandCtx.modelClass;
|
|
522
|
+
commandCtx.modelClass = want;
|
|
523
|
+
let cleared = null;
|
|
524
|
+
if (prev !== want && commandCtx.model) {
|
|
525
|
+
const isByokId = String(commandCtx.model).includes(':');
|
|
526
|
+
if (want === 'byok' ? !isByokId : isByokId) {
|
|
527
|
+
cleared = commandCtx.model;
|
|
528
|
+
commandCtx.model = null;
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
updateConfig({
|
|
532
|
+
modelClass: want,
|
|
533
|
+
model: commandCtx.model,
|
|
534
|
+
currentModelId: commandCtx.model,
|
|
535
|
+
});
|
|
536
|
+
return { ok: true, class: want, prev, cleared };
|
|
537
|
+
}
|
|
446
538
|
|
|
447
539
|
/**
|
|
448
540
|
* Fetch (or return the cached) model catalog. Rejects when the account cannot
|
|
@@ -474,6 +566,23 @@ function createApp(options = {}) {
|
|
|
474
566
|
async function validatePinnedModel() {
|
|
475
567
|
const pinned = commandCtx.model;
|
|
476
568
|
if (!pinned) return null;
|
|
569
|
+
// A BYOK pin is validated by shape, not by the pooled catalog: the catalog
|
|
570
|
+
// can never contain a `provider:model` id, so checking it here would clear
|
|
571
|
+
// every legitimate BYOK pin on every launch.
|
|
572
|
+
if (commandCtx.modelClass === 'byok') {
|
|
573
|
+
if (String(pinned).includes(':')) return null;
|
|
574
|
+
commandCtx.model = null;
|
|
575
|
+
updateConfig({ model: null, currentModelId: null });
|
|
576
|
+
emit(
|
|
577
|
+
render.renderNotice(
|
|
578
|
+
ctx(),
|
|
579
|
+
'warn',
|
|
580
|
+
`pinned model "${pinned}" belongs to the pooled class — on BYOK an id is ` +
|
|
581
|
+
'"<provider>:<model>"; pin cleared, /models lists what this machine can relay.'
|
|
582
|
+
)
|
|
583
|
+
);
|
|
584
|
+
return pinned;
|
|
585
|
+
}
|
|
477
586
|
let models;
|
|
478
587
|
try {
|
|
479
588
|
models = await loadModels();
|
|
@@ -895,6 +1004,7 @@ function createApp(options = {}) {
|
|
|
895
1004
|
return {
|
|
896
1005
|
version: VERSION,
|
|
897
1006
|
model: commandCtx.model || 'server default',
|
|
1007
|
+
class: commandCtx.modelClass,
|
|
898
1008
|
effort: commandCtx.effort,
|
|
899
1009
|
thinking: commandCtx.thinking,
|
|
900
1010
|
theme: commandCtx.light ? 'light' : 'dark',
|
|
@@ -918,13 +1028,15 @@ function createApp(options = {}) {
|
|
|
918
1028
|
permissions: { mode: rules.defaultMode, rules },
|
|
919
1029
|
// The selectable (pickable) catalog, not the raw payload: alias tiers are
|
|
920
1030
|
// dropped, live ids only (see models.js pickerEntries).
|
|
921
|
-
|
|
1031
|
+
// Whichever class is live decides what is pinnable — the pooled ids the
|
|
1032
|
+
// server advertises, or the `provider:model` ids this machine can relay.
|
|
1033
|
+
models: pickerEntries(commandCtx.modelClass === 'byok' ? byokCache.models : modelCache.models),
|
|
922
1034
|
commands: visibleCommands(),
|
|
923
1035
|
transcript: transcript.slice(),
|
|
924
1036
|
sessions: [],
|
|
925
1037
|
memory: {},
|
|
926
1038
|
lastRecap: commandCtx.lastRecap,
|
|
927
|
-
backend:
|
|
1039
|
+
backend: commandCtx.modelClass,
|
|
928
1040
|
url: client.apiBase,
|
|
929
1041
|
};
|
|
930
1042
|
}
|
|
@@ -977,7 +1089,7 @@ function createApp(options = {}) {
|
|
|
977
1089
|
let lines = null;
|
|
978
1090
|
if (o.type === 'panel') lines = o.lines;
|
|
979
1091
|
else if (o.type === 'palette') lines = overlays.renderPalette(visibleCommands(), { query: o.query || '', sel: o.sel || 0 }, W, rows);
|
|
980
|
-
else if (o.type === 'model') lines = overlays.renderModelPicker(o.items || [], o.sel || 0, W, rows, o.current != null ? o.current : commandCtx.model);
|
|
1092
|
+
else if (o.type === 'model') lines = overlays.renderModelPicker(o.items || [], o.sel || 0, W, rows, o.current != null ? o.current : commandCtx.model, o.cls || commandCtx.modelClass, classLabelOf);
|
|
981
1093
|
else if (o.type === 'effort') lines = overlays.renderEffortPicker(o.sel || 0, W, commandCtx.effort);
|
|
982
1094
|
else if (o.type === 'resume') lines = overlays.renderResumeList(o.items || [], o.sel || 0, W, rows);
|
|
983
1095
|
else if (o.type === 'confirm') lines = render.renderApproval(ctx(), o.info || {}, W).map((s) => [spanRow(s)]);
|
|
@@ -1042,10 +1154,26 @@ function createApp(options = {}) {
|
|
|
1042
1154
|
runPrompt: (text) => runPrompt(text),
|
|
1043
1155
|
ask: (text) => ask(text),
|
|
1044
1156
|
runTool: (name, args) => runTool(name, args),
|
|
1045
|
-
// The
|
|
1046
|
-
//
|
|
1047
|
-
//
|
|
1048
|
-
|
|
1157
|
+
// The catalog `/model` and alt+p expect. Routed through listModelsFor so
|
|
1158
|
+
// it follows the LIVE class: on the pooled class that is the server's
|
|
1159
|
+
// catalog (loadModels), on byok the `provider:model` ids this machine can
|
|
1160
|
+
// relay. Wired on the app's context so the chatflow's `Object.assign`
|
|
1161
|
+
// based context inherits it too — one definition, both hosts, and the
|
|
1162
|
+
// picker can never offer something the class would reject.
|
|
1163
|
+
loadModels: () => listModelsFor(commandCtx.modelClass),
|
|
1164
|
+
// The provider-key store (`byok:<provider>` rows) /byok-key writes. Read
|
|
1165
|
+
// through a function, not captured, because an injected engine may not
|
|
1166
|
+
// carry one.
|
|
1167
|
+
settings: () => engine.settings || null,
|
|
1168
|
+
// The one spelling of a provider's settings row, shared with the engine
|
|
1169
|
+
// that reads it (`byok:<provider>`) — see engine.js byokNamespace.
|
|
1170
|
+
byokNamespace: (p) => byokNamespace(p),
|
|
1171
|
+
// The class surface: /class switches, /models lists for whichever class
|
|
1172
|
+
// is live (the frozen state carries the current one as c.ctx.modelClass).
|
|
1173
|
+
listModelsFor: (cls) => listModelsFor(cls),
|
|
1174
|
+
switchClass: (cls) => switchClass(cls),
|
|
1175
|
+
classLabel: (cls) => classLabelOf(cls),
|
|
1176
|
+
classes: () => (typeof engine.listClasses === 'function' ? engine.listClasses() : []),
|
|
1049
1177
|
refreshSpend: () => refreshSpend(),
|
|
1050
1178
|
state: () => buildState(),
|
|
1051
1179
|
setInput: () => {},
|
|
@@ -1567,6 +1695,9 @@ function createApp(options = {}) {
|
|
|
1567
1695
|
} catch {
|
|
1568
1696
|
return;
|
|
1569
1697
|
}
|
|
1698
|
+
// The class first: a stored BYOK pin is only meaningful under byok, and the
|
|
1699
|
+
// pin check right after this reads whichever class won.
|
|
1700
|
+
if (HOST_CLASSES.includes(cfg.modelClass)) commandCtx.modelClass = cfg.modelClass;
|
|
1570
1701
|
if (!opts.model && cfg.model) commandCtx.model = cfg.model;
|
|
1571
1702
|
// `null` in the config is "auto" and is deliberately not assigned over the
|
|
1572
1703
|
// default — there is nothing to restore, because nothing is pinned.
|
package/src/chatflow.js
CHANGED
|
@@ -870,7 +870,15 @@ async function runSession(host) {
|
|
|
870
870
|
if (overlay.type === 'palette') {
|
|
871
871
|
ol = overlays.renderPalette(host.visibleCommands(), { query: paletteQuery(overlay.query), sel: overlay.sel }, cols, termRows);
|
|
872
872
|
} else if (overlay.type === 'model') {
|
|
873
|
-
|
|
873
|
+
// The class rides on the overlay (set where it was opened, commands.js
|
|
874
|
+
// /model) with the live ctx as the fallback, and the label comes from the
|
|
875
|
+
// engine's table via the host — so this path and app.js's renderOverlay
|
|
876
|
+
// paint the same title, subtitle and row semantics for the same overlay.
|
|
877
|
+
ol = overlays.renderModelPicker(
|
|
878
|
+
overlay.items || [], overlay.sel || 0, cols, termRows, overlay.current,
|
|
879
|
+
overlay.cls || ctx.modelClass,
|
|
880
|
+
typeof host.classLabel === 'function' ? host.classLabel : null
|
|
881
|
+
);
|
|
874
882
|
} else if (overlay.type === 'effort') {
|
|
875
883
|
ol = overlays.renderEffortPicker(overlay.sel || 0, cols, ctx.effort);
|
|
876
884
|
} else if (overlay.type === 'resume') {
|