aegiscode 6.7.6 → 6.7.7
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 +50 -7
- package/package.json +1 -1
- package/scripts/predist.mjs +7 -0
- package/src/app.js +56 -4
- package/src/commands.js +130 -6
- package/src/config.js +10 -0
- package/src/custommodels.js +198 -0
- package/src/deps.js +8 -1
- package/src/engine.js +77 -10
- package/vendor/client/aegis.js +21 -11
- package/vendor/desktop/lib/local/engine.js +54 -19
- package/vendor/desktop/lib/local/providers.js +679 -0
package/README.md
CHANGED
|
@@ -224,6 +224,7 @@ Three layers, from broadest to narrowest. You only need the first one.
|
|
|
224
224
|
/class # show the picker
|
|
225
225
|
/class aegis # pooled AEGIS Cloud (the default)
|
|
226
226
|
/class byok # your own provider key, relayed by AEGIS
|
|
227
|
+
/class custom # your own endpoint, called by aegiscode directly
|
|
227
228
|
```
|
|
228
229
|
|
|
229
230
|
A class is *whose credential pays and who talks to the vendor*, not a model.
|
|
@@ -235,6 +236,7 @@ restart.
|
|
|
235
236
|
|---|---|---|
|
|
236
237
|
| `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
238
|
| `byok` | your provider key, relayed via `POST /api/v1/byok/chat/completions` | your provider direct, **plus** a small AEGIS handling fee on your account |
|
|
239
|
+
| `custom` | your own base URL, called **directly** by aegiscode — nothing is relayed | your provider direct. No AEGIS fee, no margin, no account balance |
|
|
238
240
|
|
|
239
241
|
**2. The model id — what to pin.**
|
|
240
242
|
|
|
@@ -245,10 +247,10 @@ restart.
|
|
|
245
247
|
/model - # clear the pin, back to the class default
|
|
246
248
|
```
|
|
247
249
|
|
|
248
|
-
`/models` is class-aware: it answers from the pool catalogue under `aegis`,
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
failing later at the
|
|
250
|
+
`/models` is class-aware: it answers from the pool catalogue under `aegis`, from
|
|
251
|
+
the models your saved keys actually unlock under `byok`, and from the entries you
|
|
252
|
+
added with `/model add` under `custom`. A pin is **cleared with a reason** if you
|
|
253
|
+
switch to a class it does not belong to, instead of failing later at the route.
|
|
252
254
|
|
|
253
255
|
Under `byok` every id is compound — `provider:model`:
|
|
254
256
|
|
|
@@ -257,9 +259,17 @@ Under `byok` every id is compound — `provider:model`:
|
|
|
257
259
|
/model anthropic:claude-sonnet-4-5
|
|
258
260
|
```
|
|
259
261
|
|
|
262
|
+
Under `custom` the id is whatever you named the entry:
|
|
263
|
+
|
|
264
|
+
```bash
|
|
265
|
+
/models # e.g. local-llama, work-gateway
|
|
266
|
+
/model local-llama
|
|
267
|
+
```
|
|
268
|
+
|
|
260
269
|
```bash
|
|
261
270
|
aegiscode -m nexus-brain -p "…" # pin at launch
|
|
262
271
|
aegiscode -m anthropic:claude-sonnet-4-5 -p "…" # a BYOK id at launch
|
|
272
|
+
aegiscode -m local-llama -p "…" # a custom id at launch
|
|
263
273
|
```
|
|
264
274
|
|
|
265
275
|
**3. Effort — how hard it reasons.**
|
|
@@ -273,10 +283,40 @@ Effort scales the token budget the provider is given, so it is the dial that
|
|
|
273
283
|
actually changes reasoning depth on a reasoning model (see the root README for
|
|
274
284
|
the per-provider mechanics).
|
|
275
285
|
|
|
276
|
-
> **A
|
|
286
|
+
> **A `byok` turn is single-shot.** The relay takes no `tools` parameter, so the
|
|
277
287
|
> agentic tool loop is off by construction — no file edits, no shell, no
|
|
278
288
|
> subagents, no approval cards. `/class` says so rather than letting you discover
|
|
279
|
-
> it mid-task.
|
|
289
|
+
> it mid-task. **`custom` does not have this limit** — aegiscode calls your
|
|
290
|
+
> endpoint itself, so the full tool loop works normally.
|
|
291
|
+
|
|
292
|
+
## Custom models — your endpoint, called directly
|
|
293
|
+
|
|
294
|
+
`/model add` teaches aegiscode about an endpoint AEGIS never sees. There is no
|
|
295
|
+
relay, no handling fee and no margin: the request goes straight from your machine
|
|
296
|
+
to the base URL you gave, with the key you gave.
|
|
297
|
+
|
|
298
|
+
```bash
|
|
299
|
+
/model add local-llama "Local Llama" llama-3.3-70b http://localhost:11434/v1
|
|
300
|
+
/model add work-gw "Work gateway" gpt-4o https://gw.corp/v1 openai
|
|
301
|
+
/model key local-llama # set or replace the key later (prompted, masked)
|
|
302
|
+
/class custom # route turns through these
|
|
303
|
+
/model local-llama # pin one
|
|
304
|
+
/model remove local-llama # drop the entry and its key
|
|
305
|
+
```
|
|
306
|
+
|
|
307
|
+
The wire protocol is detected from the base URL — `anthropic.com` gets the
|
|
308
|
+
Messages API, everything else the OpenAI-compatible one — or you can pass
|
|
309
|
+
`openai` / `anthropic` explicitly to override it.
|
|
310
|
+
|
|
311
|
+
Where things are stored, and why it is split:
|
|
312
|
+
|
|
313
|
+
| What | Where | Why |
|
|
314
|
+
|---|---|---|
|
|
315
|
+
| name, model, base URL, wire | `~/.aegiscode/config.json` | it is configuration, and it is not secret |
|
|
316
|
+
| the API key | `~/.aegiscode/settings.json` (mode `0600`) | secrets belong in the file we chmod, keyed `custom:<id>` |
|
|
317
|
+
|
|
318
|
+
The key is never written into `config.json`. A local endpoint that needs no key
|
|
319
|
+
is fine — omit it and no `Authorization` header is sent.
|
|
280
320
|
|
|
281
321
|
## Bring your own key
|
|
282
322
|
|
|
@@ -377,12 +417,15 @@ echo "why is the sky blue" | aegiscode -p -
|
|
|
377
417
|
### Switch how you're paying
|
|
378
418
|
|
|
379
419
|
```bash
|
|
380
|
-
/class # see
|
|
420
|
+
/class # see every route and who pays
|
|
381
421
|
/class byok # use your own key
|
|
382
422
|
/byok-key openai # …save one first if it says you have none
|
|
383
423
|
/models # what that key unlocks
|
|
384
424
|
/model openai:gpt-4o # pin one
|
|
385
425
|
/class aegis # back to the pool
|
|
426
|
+
|
|
427
|
+
/model add local-llama "Local Llama" llama-3.3-70b http://localhost:11434/v1
|
|
428
|
+
/class custom # or call your own endpoint directly
|
|
386
429
|
```
|
|
387
430
|
|
|
388
431
|
### Control the budget
|
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.7",
|
|
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,13 @@ 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 direct-provider transport (openaiCompatible + anthropicMessages) the
|
|
65
|
+
// desktop injects into the engine for its custom-endpoint classes. The CLI's
|
|
66
|
+
// `custom` class (src/engine.js, the /model add catalog) now injects the same
|
|
67
|
+
// real transport instead of the throwing stub it used to, so a user's own
|
|
68
|
+
// base URL + key is called directly with the full tool loop — so this file
|
|
69
|
+
// must ship. Pure node builtins (fetch), stages cleanly.
|
|
70
|
+
'desktop/lib/local/providers.js',
|
|
64
71
|
// The provider-config store: one row per provider (base URL + key), and the
|
|
65
72
|
// row the 'byok' class reads for a per-provider key. The CLI now selects that
|
|
66
73
|
// class (src/engine.js), so it needs the same store the desktop writes —
|
package/src/app.js
CHANGED
|
@@ -40,6 +40,7 @@ const {
|
|
|
40
40
|
const credentials = require('./credentials.js');
|
|
41
41
|
const cloudsync = require('./cloudsync.js');
|
|
42
42
|
const { readSecret } = require('./secret.js');
|
|
43
|
+
const customModelsCatalog = require('./custommodels.js');
|
|
43
44
|
const { normalizeModelCatalog, pickerEntries, catalogIds } = require('./models.js');
|
|
44
45
|
const { appendHistory, readSessionTranscript, readOwnSessions } = require('./history.js');
|
|
45
46
|
const { snapshotCheckpoint } = require('./checkpoint.js');
|
|
@@ -493,15 +494,40 @@ function createApp(options = {}) {
|
|
|
493
494
|
* offer": a catalog is a convenience, and an offline client must still be
|
|
494
495
|
* able to chat on the server's own default.
|
|
495
496
|
*/
|
|
497
|
+
async function loadCustomModels() {
|
|
498
|
+
// The `custom` catalog is local (config.json + the 0600 key store), so this
|
|
499
|
+
// never touches the network and needs no cache. The engine already returns
|
|
500
|
+
// the picker/`/models` shape ({id, label, note, configured, wire}).
|
|
501
|
+
if (typeof engine.listModels !== 'function') return [];
|
|
502
|
+
const res = await engine.listModels('custom');
|
|
503
|
+
return (res && res.models) || [];
|
|
504
|
+
}
|
|
505
|
+
|
|
496
506
|
async function listModelsFor(cls) {
|
|
497
507
|
const want = HOST_CLASSES.includes(cls) ? cls : commandCtx.modelClass;
|
|
498
508
|
try {
|
|
499
|
-
|
|
509
|
+
if (want === 'byok') return await loadByokModels();
|
|
510
|
+
if (want === 'custom') return await loadCustomModels();
|
|
511
|
+
return await loadModels();
|
|
500
512
|
} catch {
|
|
501
513
|
return [];
|
|
502
514
|
}
|
|
503
515
|
}
|
|
504
516
|
|
|
517
|
+
/**
|
|
518
|
+
* Whether a pinned id can run on `cls`, decided synchronously (switchClass is
|
|
519
|
+
* not async). byok ids are `provider:model`; custom ids are the catalog's
|
|
520
|
+
* own (config.json, read sync); aegis takes anything that is neither — the
|
|
521
|
+
* pooled catalog is validated separately, at launch, by validatePinnedModel.
|
|
522
|
+
*/
|
|
523
|
+
function pinBelongsToClass(cls, id) {
|
|
524
|
+
const s = String(id == null ? '' : id);
|
|
525
|
+
if (cls === 'byok') return s.includes(':');
|
|
526
|
+
if (cls === 'custom') return Boolean(customModelsCatalog.getCustom(s));
|
|
527
|
+
// aegis: not a byok id and not a custom-catalog id.
|
|
528
|
+
return !s.includes(':') && !customModelsCatalog.getCustom(s);
|
|
529
|
+
}
|
|
530
|
+
|
|
505
531
|
/**
|
|
506
532
|
* Switch the live class. Refuses anything this host cannot run (engine.js's
|
|
507
533
|
* HOST_CLASSES is the authority — the local/custom classes stay stubs).
|
|
@@ -511,7 +537,9 @@ function createApp(options = {}) {
|
|
|
511
537
|
* fail at the relay with a confusing "no key saved for …" instead of here,
|
|
512
538
|
* with a reason. Symmetrically, `anthropic:claude-…` under aegis is an id the
|
|
513
539
|
* pooled catalog does not advertise, which is the silent-fallback case
|
|
514
|
-
* validatePinnedModel exists to prevent.
|
|
540
|
+
* validatePinnedModel exists to prevent. The `custom` class owns its own id
|
|
541
|
+
* space (the /model add catalog, resolvable synchronously from config.json),
|
|
542
|
+
* so a pin belongs to it exactly when it is one of those ids.
|
|
515
543
|
*/
|
|
516
544
|
function switchClass(next) {
|
|
517
545
|
const want = String(next == null ? '' : next).trim().toLowerCase();
|
|
@@ -522,8 +550,7 @@ function createApp(options = {}) {
|
|
|
522
550
|
commandCtx.modelClass = want;
|
|
523
551
|
let cleared = null;
|
|
524
552
|
if (prev !== want && commandCtx.model) {
|
|
525
|
-
|
|
526
|
-
if (want === 'byok' ? !isByokId : isByokId) {
|
|
553
|
+
if (!pinBelongsToClass(want, commandCtx.model)) {
|
|
527
554
|
cleared = commandCtx.model;
|
|
528
555
|
commandCtx.model = null;
|
|
529
556
|
}
|
|
@@ -583,6 +610,31 @@ function createApp(options = {}) {
|
|
|
583
610
|
);
|
|
584
611
|
return pinned;
|
|
585
612
|
}
|
|
613
|
+
// A custom pin is validated against the local catalog, never the pooled one:
|
|
614
|
+
// its ids are the user's own (from /model add) and the pool has never heard
|
|
615
|
+
// of them, so checking the pooled catalog would clear every custom pin on
|
|
616
|
+
// launch. An empty catalog clears nothing (offline-safe like the pooled path).
|
|
617
|
+
if (commandCtx.modelClass === 'custom') {
|
|
618
|
+
let customModels;
|
|
619
|
+
try {
|
|
620
|
+
customModels = await loadCustomModels();
|
|
621
|
+
} catch {
|
|
622
|
+
return null;
|
|
623
|
+
}
|
|
624
|
+
if (!customModels.length) return null;
|
|
625
|
+
if (customModels.some((m) => m.id === pinned)) return null;
|
|
626
|
+
commandCtx.model = null;
|
|
627
|
+
updateConfig({ model: null, currentModelId: null });
|
|
628
|
+
emit(
|
|
629
|
+
render.renderNotice(
|
|
630
|
+
ctx(),
|
|
631
|
+
'warn',
|
|
632
|
+
`pinned model "${pinned}" is not in your custom catalog — pin cleared; ` +
|
|
633
|
+
'/models lists your endpoints, /model add registers one.'
|
|
634
|
+
)
|
|
635
|
+
);
|
|
636
|
+
return pinned;
|
|
637
|
+
}
|
|
586
638
|
let models;
|
|
587
639
|
try {
|
|
588
640
|
models = await loadModels();
|
package/src/commands.js
CHANGED
|
@@ -73,6 +73,9 @@ const {
|
|
|
73
73
|
const {
|
|
74
74
|
aggregateSessionUsage, pruneSessionHistory, readResumeList,
|
|
75
75
|
} = require('./history.js');
|
|
76
|
+
// The custom-endpoint catalog behind the `custom` class and /model add|key|remove.
|
|
77
|
+
const customModelsCatalog = require('./custommodels.js');
|
|
78
|
+
const { VALID_WIRES } = customModelsCatalog;
|
|
76
79
|
|
|
77
80
|
// Guarded: a concurrent workstream owns ./markdown.js.
|
|
78
81
|
let markdownModule = null;
|
|
@@ -111,8 +114,46 @@ const EFFORT_LEVELS = overlays.EFFORT_VALUES;
|
|
|
111
114
|
|
|
112
115
|
// ── Small handler helpers ─────────────────────────────────────────────────────
|
|
113
116
|
|
|
114
|
-
|
|
115
|
-
|
|
117
|
+
/**
|
|
118
|
+
* Split a command's raw tail into tokens, honouring double quotes so a model
|
|
119
|
+
* name or id with a space stays one token
|
|
120
|
+
* (`/model add local "Llama 3 70B" http://…`). Backslash escapes a quote or a
|
|
121
|
+
* backslash inside a quoted run. Never throws — an unclosed quote simply ends
|
|
122
|
+
* at the end of the line.
|
|
123
|
+
*/
|
|
124
|
+
function splitArgs(raw) {
|
|
125
|
+
const text = String(raw == null ? '' : raw);
|
|
126
|
+
const out = [];
|
|
127
|
+
let cur = '';
|
|
128
|
+
let quoted = false;
|
|
129
|
+
let started = false;
|
|
130
|
+
for (let i = 0; i < text.length; i++) {
|
|
131
|
+
const ch = text[i];
|
|
132
|
+
if (ch === '\\' && quoted && i + 1 < text.length && (text[i + 1] === '"' || text[i + 1] === '\\')) {
|
|
133
|
+
cur += text[++i];
|
|
134
|
+
started = true;
|
|
135
|
+
continue;
|
|
136
|
+
}
|
|
137
|
+
if (ch === '"') {
|
|
138
|
+
quoted = !quoted;
|
|
139
|
+
// A quoted empty string ("") is a real, intentional token.
|
|
140
|
+
started = true;
|
|
141
|
+
continue;
|
|
142
|
+
}
|
|
143
|
+
if (!quoted && /\s/.test(ch)) {
|
|
144
|
+
if (started) out.push(cur);
|
|
145
|
+
cur = '';
|
|
146
|
+
started = false;
|
|
147
|
+
continue;
|
|
148
|
+
}
|
|
149
|
+
cur += ch;
|
|
150
|
+
started = true;
|
|
151
|
+
}
|
|
152
|
+
if (started) out.push(cur);
|
|
153
|
+
return out;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
const note = (c, text) => c.push({ role: 'note', text });const panel = (c, lines) => c.push({ role: 'panel', lines });
|
|
116
157
|
const tip = (c, text) => c.push({ role: 'tip', text });
|
|
117
158
|
const done = (c, text) => c.push({ role: 'done', text });
|
|
118
159
|
const shortCwd = () => process.cwd().split('/').filter(Boolean).pop() || '~';
|
|
@@ -807,6 +848,10 @@ const COMMANDS = [
|
|
|
807
848
|
// will actually take (app.js's buildState().models is class-scoped too).
|
|
808
849
|
const cls = (c.ctx && c.ctx.modelClass) || 'aegis';
|
|
809
850
|
const byok = cls === 'byok';
|
|
851
|
+
// The sub-command token, lower-cased: `add` / `key` / `remove` are the
|
|
852
|
+
// custom-endpoint catalog's verbs. A model id is never one of these in
|
|
853
|
+
// practice, and `list` already shadows a real id the same way.
|
|
854
|
+
const sub = id.toLowerCase();
|
|
810
855
|
if (!id) {
|
|
811
856
|
note(c, `model: ${c.ctx.model || 'server default'}`);
|
|
812
857
|
// Populate the picker from the server first — app.js's state().models
|
|
@@ -861,10 +906,89 @@ const COMMANDS = [
|
|
|
861
906
|
c.render();
|
|
862
907
|
return true;
|
|
863
908
|
}
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
909
|
+
// The /model add catalog — the aegiscodex-dev concept ported in. A user
|
|
910
|
+
// registers their own endpoint (own base URL, own model string, own key)
|
|
911
|
+
// and the CLI calls it DIRECTLY through the desktop transport, the full
|
|
912
|
+
// tool loop and all: no pooled route, no BYOK relay, no fee or margin.
|
|
913
|
+
// The classic entry form is the positional one
|
|
914
|
+
// /model add <id> <name> <model> <baseURL> [wire]
|
|
915
|
+
// with the key prompted for (masked) right after, or supplied inline
|
|
916
|
+
// /model add <id> <name> <model> <baseURL> [wire] <key>
|
|
917
|
+
// (the scriptable spelling, like /byok-key's second token).
|
|
918
|
+
if (sub === 'add') {
|
|
919
|
+
const parts = splitArgs(args._rest);
|
|
920
|
+
// `sub` itself is the first token of _rest, so drop its own copy.
|
|
921
|
+
const rest = parts[0] === 'add' ? parts.slice(1) : parts;
|
|
922
|
+
// The wire name is optional and only recognised when it is one of the
|
|
923
|
+
// two transports — otherwise that token is the key (so
|
|
924
|
+
// `/model add id name model url sk-…` needs no placeholder).
|
|
925
|
+
let at = 4;
|
|
926
|
+
let wire;
|
|
927
|
+
if (VALID_WIRES.includes(String(rest[at] || '').toLowerCase())) {
|
|
928
|
+
wire = String(rest[at]).toLowerCase();
|
|
929
|
+
at += 1;
|
|
930
|
+
}
|
|
931
|
+
const fields = { id: rest[0], name: rest[1], model: rest[2], baseURL: rest[3], wire };
|
|
932
|
+
if (!fields.id || !fields.model || !fields.baseURL) {
|
|
933
|
+
note(c, 'Usage: /model add <id> <name> <model> <baseURL> [openai|anthropic] [key]');
|
|
934
|
+
note(c, ' e.g. /model add local Llama-3 "meta-llama/Llama-3-70b" http://localhost:8080/v1');
|
|
935
|
+
note(c, ' the key is prompted for and stored 0600 on this machine — never in config.json.');
|
|
936
|
+
c.render();
|
|
937
|
+
return true;
|
|
938
|
+
}
|
|
939
|
+
const inlineKey = rest[at] || '';
|
|
940
|
+
const store = c.settings && c.settings();
|
|
941
|
+
const res = customModelsCatalog.addCustom({ ...fields, key: null }, store);
|
|
942
|
+
if (res.error) {
|
|
943
|
+
c.push({ role: 'error', text: `couldn't add "${fields.id}": ${res.error}` });
|
|
944
|
+
return true;
|
|
945
|
+
}
|
|
946
|
+
const entry = res.entry;
|
|
947
|
+
let key = inlineKey || '';
|
|
948
|
+
if (!key) {
|
|
949
|
+
note(c, `storing a key for "${entry.id}" — leave it blank to add it later with /model key ${entry.id}.`);
|
|
950
|
+
c.render();
|
|
951
|
+
key = String((await c.readSecret(`${entry.id} key: `)) || '').trim();
|
|
952
|
+
}
|
|
953
|
+
if (key) {
|
|
954
|
+
customModelsCatalog.setCustomKey(entry.id, key, store);
|
|
955
|
+
}
|
|
956
|
+
note(c, `added "${entry.id}" → ${entry.model} at ${entry.baseURL} (${entry.wire} wire)${key ? '' : ' — no key yet'}.`);
|
|
957
|
+
note(c, key
|
|
958
|
+
? `run it with /class custom (then /model ${entry.id}), or /model ${entry.id} while on the custom class.`
|
|
959
|
+
: `add its key with /model key ${entry.id}, then /class custom runs it.`);
|
|
960
|
+
c.render();
|
|
961
|
+
return true;
|
|
962
|
+
}
|
|
963
|
+
if (sub === 'key') {
|
|
964
|
+
const target = splitArgs(args._rest)[1];
|
|
965
|
+
if (!target) { note(c, 'Usage: /model key <id> — /models lists your custom endpoints.'); c.render(); return true; }
|
|
966
|
+
const entry = customModelsCatalog.getCustom(target);
|
|
967
|
+
if (!entry) { note(c, `no custom endpoint "${target}" — /model add registers one.`); c.render(); return true; }
|
|
968
|
+
const store = c.settings && c.settings();
|
|
969
|
+
note(c, `storing a key for "${entry.id}" — blank clears it.`);
|
|
970
|
+
c.render();
|
|
971
|
+
const key = String((await c.readSecret(`${entry.id} key: `)) || '').trim();
|
|
972
|
+
if (!key) { note(c, 'nothing saved.'); c.render(); return true; }
|
|
973
|
+
customModelsCatalog.setCustomKey(entry.id, key, store);
|
|
974
|
+
note(c, `saved a key for "${entry.id}" on this machine — /class custom runs it.`);
|
|
975
|
+
c.render();
|
|
976
|
+
return true;
|
|
977
|
+
}
|
|
978
|
+
if (sub === 'remove' || sub === 'rm') {
|
|
979
|
+
const target = splitArgs(args._rest)[1];
|
|
980
|
+
if (!target) { note(c, 'Usage: /model remove <id>'); c.render(); return true; }
|
|
981
|
+
const store = c.settings && c.settings();
|
|
982
|
+
const { removed } = customModelsCatalog.removeCustom(target, store);
|
|
983
|
+
if (!removed) { note(c, `no custom endpoint "${target}" — /models lists your endpoints.`); c.render(); return true; }
|
|
984
|
+
// A pin on the row we just deleted would otherwise outlive its entry and
|
|
985
|
+
// fail at the next send with "no model … in the catalog".
|
|
986
|
+
if (String(c.ctx.model || '') === String(target)) {
|
|
987
|
+
c.ctx.model = null;
|
|
988
|
+
c.saveConfig({ model: null, currentModelId: null });
|
|
989
|
+
note(c, `unpinned "${target}" (its catalog entry is gone).`);
|
|
990
|
+
}
|
|
991
|
+
note(c, `removed "${target}" and forgot its key.`);
|
|
868
992
|
c.render();
|
|
869
993
|
return true;
|
|
870
994
|
}
|
package/src/config.js
CHANGED
|
@@ -73,6 +73,16 @@ const DEFAULT_CONFIG = {
|
|
|
73
73
|
// aegiscode- name so /model add/remove/switch stay compatible both ways.
|
|
74
74
|
models: null,
|
|
75
75
|
currentModelId: null,
|
|
76
|
+
// The named custom-model catalog behind the `custom` class — the
|
|
77
|
+
// aegiscodex-dev `/model add` concept: each entry names an endpoint the user
|
|
78
|
+
// brings themselves (own base URL + own key), called DIRECTLY through the
|
|
79
|
+
// desktop transport (providers.openaiCompatible / anthropicMessages), tools
|
|
80
|
+
// and all, never through the pooled route or the BYOK relay. Only the
|
|
81
|
+
// non-secret metadata lives here; the key is in the 0600 settings store under
|
|
82
|
+
// `custom:<id>` (engine.js), never in this file (config.json is not 0600 and
|
|
83
|
+
// participates in cloud sync). Shape: [{ id, name, model, baseURL, wire }],
|
|
84
|
+
// wire ∈ {'openai','anthropic'}.
|
|
85
|
+
customModels: [],
|
|
76
86
|
// `null` = no effort pinned, i.e. "auto": each turn is sized by the server
|
|
77
87
|
// from the ask itself (aegis1 services/pool_brain.py estimate_effort). The
|
|
78
88
|
// old 'high' was a *pin* on the top rung of the budget ladder — the most the
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The named custom-model catalog behind the `custom` class.
|
|
5
|
+
*
|
|
6
|
+
* This is the aegiscodex-dev `/model add` concept ported into the CLI: a user
|
|
7
|
+
* registers an endpoint they bring themselves — their own base URL, their own
|
|
8
|
+
* model string, their own API key — and the turn is called DIRECTLY through the
|
|
9
|
+
* desktop transport (desktop/lib/local/providers.js openaiCompatible /
|
|
10
|
+
* anthropicMessages), the full agent loop and all, never through the pooled
|
|
11
|
+
* route and never through the BYOK relay. There is no AEGIS margin or handling
|
|
12
|
+
* fee on this lane at all: the request never touches aegiscloud.org.
|
|
13
|
+
*
|
|
14
|
+
* Split storage, on purpose:
|
|
15
|
+
* · metadata (id, name, model, baseURL, wire) → config.json `customModels`.
|
|
16
|
+
* None of it is secret, and config.json is where /model pins already live.
|
|
17
|
+
* · the API key → the settings store under `custom:<id>` (file mode 0600,
|
|
18
|
+
* the same store byok keys use). config.json is NOT 0600 and participates in
|
|
19
|
+
* cloud sync, so a provider key must never land there.
|
|
20
|
+
*
|
|
21
|
+
* `wire` selects the transport: 'anthropic' → anthropicMessages (x-api-key,
|
|
22
|
+
* the Messages API), 'openai' → openaiCompatible (Bearer, /chat/completions).
|
|
23
|
+
* It is auto-detected from the base URL host on add, and overridable.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
const { loadConfig, updateConfig } = require('./config.js');
|
|
27
|
+
|
|
28
|
+
/** The settings-store row a custom model's key lives in. */
|
|
29
|
+
function customNamespace(id) {
|
|
30
|
+
return `custom:${id}`;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** Host of a URL, lower-cased, or '' if it does not parse. */
|
|
34
|
+
function hostOf(url) {
|
|
35
|
+
try {
|
|
36
|
+
return new URL(String(url)).host.toLowerCase();
|
|
37
|
+
} catch {
|
|
38
|
+
return '';
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Which transport a base URL implies. Anthropic's Messages API is a different
|
|
44
|
+
* wire format (x-api-key, `/v1/messages`, a `system` top-level field) from the
|
|
45
|
+
* OpenAI-compatible majority, so it must be recognised rather than guessed at
|
|
46
|
+
* call time. Everything else — OpenAI, Groq, DeepSeek, together, openrouter,
|
|
47
|
+
* a local llama.cpp — speaks the OpenAI shape.
|
|
48
|
+
*/
|
|
49
|
+
function inferWire(baseURL) {
|
|
50
|
+
const host = hostOf(baseURL);
|
|
51
|
+
return host && /(^|\.)anthropic\.com$/.test(host) ? 'anthropic' : 'openai';
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const VALID_WIRES = Object.freeze(['openai', 'anthropic']);
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Validate and normalise a would-be catalog entry. Returns `{ entry }` on
|
|
58
|
+
* success or `{ error }` with a one-line reason — never throws, so the command
|
|
59
|
+
* layer can show the reason and keep the session alive.
|
|
60
|
+
*
|
|
61
|
+
* The id rules are load-bearing, not cosmetic: a `:` would collide with the
|
|
62
|
+
* `provider:model` shape byok parses, and a whitespace id cannot be typed back
|
|
63
|
+
* to `/model <id>`. A base URL is required and must be http(s) — the transport
|
|
64
|
+
* POSTs to `${baseURL}/…`, so a bare host or a typo becomes an unroutable call
|
|
65
|
+
* later instead of a clear refusal now.
|
|
66
|
+
*/
|
|
67
|
+
function normalizeEntry({ id, name, model, baseURL, wire } = {}) {
|
|
68
|
+
const cleanId = String(id == null ? '' : id).trim();
|
|
69
|
+
if (!cleanId) return { error: 'an id is required — /model add <id> <name> <model> <baseURL>' };
|
|
70
|
+
if (/[\s:]/.test(cleanId)) return { error: `invalid id "${cleanId}" — no spaces or ":" (":" is the byok separator)` };
|
|
71
|
+
|
|
72
|
+
const cleanModel = String(model == null ? '' : model).trim();
|
|
73
|
+
if (!cleanModel) return { error: 'a model string is required — the id the provider expects on the wire' };
|
|
74
|
+
|
|
75
|
+
const cleanBase = String(baseURL == null ? '' : baseURL).trim();
|
|
76
|
+
if (!/^https?:\/\//i.test(cleanBase)) return { error: `base URL must start with http(s):// — got ${JSON.stringify(cleanBase)}` };
|
|
77
|
+
if (!hostOf(cleanBase)) return { error: `base URL does not parse — got ${JSON.stringify(cleanBase)}` };
|
|
78
|
+
|
|
79
|
+
let cleanWire = String(wire == null ? '' : wire).trim().toLowerCase();
|
|
80
|
+
if (cleanWire && !VALID_WIRES.includes(cleanWire)) {
|
|
81
|
+
return { error: `wire must be one of ${VALID_WIRES.join(', ')} — got ${JSON.stringify(cleanWire)}` };
|
|
82
|
+
}
|
|
83
|
+
if (!cleanWire) cleanWire = inferWire(cleanBase);
|
|
84
|
+
|
|
85
|
+
const cleanName = String(name == null ? '' : name).trim() || cleanId;
|
|
86
|
+
return { entry: { id: cleanId, name: cleanName, model: cleanModel, baseURL: cleanBase, wire: cleanWire } };
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** The stored catalog (metadata only), always an array. */
|
|
90
|
+
function rawCatalog() {
|
|
91
|
+
const list = loadConfig().customModels;
|
|
92
|
+
return Array.isArray(list) ? list.filter((e) => e && typeof e.id === 'string') : [];
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/** One entry's metadata by id, or null. */
|
|
96
|
+
function getCustom(id) {
|
|
97
|
+
const want = String(id == null ? '' : id).trim();
|
|
98
|
+
return rawCatalog().find((e) => e.id === want) || null;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* The catalog as pickable model rows ({ id, label, note, configured }) — the
|
|
103
|
+
* shape /models and the alt+p picker consume. `configured` reflects whether a
|
|
104
|
+
* key is saved for the row, so the list can say which entries can actually run.
|
|
105
|
+
*/
|
|
106
|
+
function listCustomModels(settings) {
|
|
107
|
+
return rawCatalog().map((e) => ({
|
|
108
|
+
id: e.id,
|
|
109
|
+
label: e.name || e.id,
|
|
110
|
+
note: `${e.model} · ${hostOf(e.baseURL) || e.baseURL} · ${e.wire}`,
|
|
111
|
+
configured: hasKey(settings, e.id),
|
|
112
|
+
wire: e.wire,
|
|
113
|
+
}));
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/** Whether a key is stored for this custom id. */
|
|
117
|
+
function hasKey(settings, id) {
|
|
118
|
+
if (!settings || typeof settings.rawKey !== 'function') return false;
|
|
119
|
+
return Boolean(settings.rawKey(customNamespace(id)));
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Add or replace a catalog entry, and store its key (when supplied) in the
|
|
124
|
+
* 0600 settings row. Returns `{ entry }` or `{ error }`. Adding an id that
|
|
125
|
+
* already exists REPLACES its metadata (and its key when a new one is given),
|
|
126
|
+
* so `/model add` doubles as an edit — re-running it to fix a typo'd base URL
|
|
127
|
+
* does not leave a second, dead row.
|
|
128
|
+
*/
|
|
129
|
+
function addCustom(fields, settings) {
|
|
130
|
+
const res = normalizeEntry(fields);
|
|
131
|
+
if (res.error) return res;
|
|
132
|
+
const { entry } = res;
|
|
133
|
+
const next = rawCatalog().filter((e) => e.id !== entry.id);
|
|
134
|
+
next.push(entry);
|
|
135
|
+
updateConfig({ customModels: next });
|
|
136
|
+
if (settings && typeof settings.set === 'function' && fields && fields.key != null && String(fields.key).trim()) {
|
|
137
|
+
settings.set(customNamespace(entry.id), { key: String(fields.key).trim() });
|
|
138
|
+
}
|
|
139
|
+
return { entry };
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/** Store (or clear) just the key for an existing custom id. */
|
|
143
|
+
function setCustomKey(id, key, settings) {
|
|
144
|
+
if (!settings || typeof settings.set !== 'function') return { error: 'no key store available' };
|
|
145
|
+
settings.set(customNamespace(id), { key: key ? String(key).trim() : null });
|
|
146
|
+
return { ok: true };
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Remove a catalog entry and forget its key. Returns whether anything was
|
|
151
|
+
* removed, so the command can say "removed" vs "there was no such entry".
|
|
152
|
+
*/
|
|
153
|
+
function removeCustom(id, settings) {
|
|
154
|
+
const want = String(id == null ? '' : id).trim();
|
|
155
|
+
const before = rawCatalog();
|
|
156
|
+
const after = before.filter((e) => e.id !== want);
|
|
157
|
+
const removed = after.length !== before.length;
|
|
158
|
+
if (removed) updateConfig({ customModels: after });
|
|
159
|
+
if (settings && typeof settings.remove === 'function') {
|
|
160
|
+
try { settings.remove(customNamespace(want)); } catch { /* nothing stored */ }
|
|
161
|
+
}
|
|
162
|
+
return { removed };
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Resolve a pinned custom id to everything the dispatch needs: the transport
|
|
167
|
+
* class it maps to ('anthropic' | 'openai-compat'), its base URL, its wire
|
|
168
|
+
* model string, and its key. Null when the id is not in the catalog. The key
|
|
169
|
+
* is read live from the settings store, never cached, so a key saved after the
|
|
170
|
+
* engine was constructed is picked up on the very next turn.
|
|
171
|
+
*/
|
|
172
|
+
function resolveCustom(id, settings) {
|
|
173
|
+
const entry = getCustom(id);
|
|
174
|
+
if (!entry) return null;
|
|
175
|
+
const key = settings && typeof settings.rawKey === 'function' ? settings.rawKey(customNamespace(entry.id)) : null;
|
|
176
|
+
return {
|
|
177
|
+
wireClass: entry.wire === 'anthropic' ? 'anthropic' : 'openai-compat',
|
|
178
|
+
baseURL: entry.baseURL,
|
|
179
|
+
model: entry.model,
|
|
180
|
+
key: key || null,
|
|
181
|
+
wire: entry.wire,
|
|
182
|
+
id: entry.id,
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
module.exports = {
|
|
187
|
+
customNamespace,
|
|
188
|
+
inferWire,
|
|
189
|
+
normalizeEntry,
|
|
190
|
+
getCustom,
|
|
191
|
+
listCustomModels,
|
|
192
|
+
hasKey,
|
|
193
|
+
addCustom,
|
|
194
|
+
setCustomKey,
|
|
195
|
+
removeCustom,
|
|
196
|
+
resolveCustom,
|
|
197
|
+
VALID_WIRES,
|
|
198
|
+
};
|
package/src/deps.js
CHANGED
|
@@ -81,11 +81,17 @@ const updatePath = resolveShared(path.join('client', 'update.js'));
|
|
|
81
81
|
// must work the SAME queue with the SAME rules (scoped commits included).
|
|
82
82
|
const queuePath = resolveShared(path.join('desktop', 'lib', 'local', 'queue.js'));
|
|
83
83
|
const autonomousPath = resolveShared(path.join('desktop', 'lib', 'local', 'autonomous.js'));
|
|
84
|
+
// The direct-provider transport (openaiCompatible + anthropicMessages). The
|
|
85
|
+
// desktop injects it into createLocalEngine for its custom-endpoint classes;
|
|
86
|
+
// the CLI injects the same real module for its `custom` class (the /model add
|
|
87
|
+
// catalog) rather than the throwing stub it shipped before.
|
|
88
|
+
const providersPath = resolveShared(path.join('desktop', 'lib', 'local', 'providers.js'));
|
|
84
89
|
|
|
85
90
|
const { createClient } = require(clientPath);
|
|
86
91
|
const { createTools } = require(toolsPath);
|
|
87
92
|
const { usageTokens } = require(usagePath);
|
|
88
93
|
const { createLocalEngine } = require(enginePath);
|
|
94
|
+
const providers = require(providersPath);
|
|
89
95
|
const { createSettingsStore, isReservedNamespace } = require(settingsPath);
|
|
90
96
|
const { agentRoles, agentRoleLabel } = require(agentsPath);
|
|
91
97
|
const { buildSystemPrompt } = require(promptPath);
|
|
@@ -99,6 +105,7 @@ module.exports = {
|
|
|
99
105
|
createTools,
|
|
100
106
|
usageTokens,
|
|
101
107
|
createLocalEngine,
|
|
108
|
+
providers,
|
|
102
109
|
createSettingsStore,
|
|
103
110
|
isReservedNamespace,
|
|
104
111
|
agentRoles,
|
|
@@ -107,6 +114,6 @@ module.exports = {
|
|
|
107
114
|
updater,
|
|
108
115
|
queue,
|
|
109
116
|
autonomous,
|
|
110
|
-
paths: { client: clientPath, tools: toolsPath, usage: usagePath, engine: enginePath, settings: settingsPath, agents: agentsPath, prompt: promptPath, update: updatePath, queue: queuePath, autonomous: autonomousPath },
|
|
117
|
+
paths: { client: clientPath, tools: toolsPath, usage: usagePath, engine: enginePath, providers: providersPath, settings: settingsPath, agents: agentsPath, prompt: promptPath, update: updatePath, queue: queuePath, autonomous: autonomousPath },
|
|
111
118
|
roots,
|
|
112
119
|
};
|