aegiscode 6.8.8 → 6.8.9

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.
@@ -105,9 +105,84 @@ function filterAegisCatalog(models) {
105
105
  return [{ ...rest, label: NEXUS_LABEL }];
106
106
  }
107
107
 
108
+ /**
109
+ * The Aegis-class catalog as a host must OFFER it: the FULL list the server
110
+ * advertises — the pooled brain first, under its one name, then every other
111
+ * model the account can pin.
112
+ *
113
+ * `filterAegisCatalog` above collapses the class to the single brain row, and
114
+ * that was shipped: the desktop's dropdown and the terminal's alt+p picker both
115
+ * showed one entry, "Nexus", because collapsing was implemented to end a real
116
+ * disagreement (seven rows in one host, one in the other). Ending the
117
+ * disagreement by removing the choice was the wrong fix, and a user with a
118
+ * funded account could see no way to pin the deepseek or anthropic models the
119
+ * same catalogue advertises — the model was chosen for them, with no lever.
120
+ *
121
+ * So this is the rule both hosts now share: offer everything, collapse only the
122
+ * *aliases*.
123
+ *
124
+ * - The brain tier stays ONE row, labelled `NEXUS_LABEL`, first. The server
125
+ * lists it under five spellings (`nexus-brain` canonical, `aegis-brain` and
126
+ * the `-smart`/`-neo` tiers as `hidden: true, alias_of: "nexus-brain"`);
127
+ * those name one route, so they are folded into that one row rather than
128
+ * painted as five models — which is what `filterAegisCatalog` was for, and
129
+ * that half of it is kept.
130
+ * - Every other entry is offered as the server advertises it, INCLUDING
131
+ * entries the payload marks `hidden`, because "hidden" in this payload means
132
+ * "not the canonical spelling", not "do not offer".
133
+ * - An entry that is an alias OF another entry in the same payload is dropped
134
+ * only when its target is present — a pure duplicate row that would pin the
135
+ * id it points at, which is the `models.js` defect the CLI already guarded
136
+ * against. When the payload is nothing but aliases, they are all offered:
137
+ * an empty list is not a better answer than a list of aliases.
138
+ *
139
+ * Pure, like the rest of this file, and shape-tolerant (raw relay payload or
140
+ * the CLI's normalised entries) so both hosts can call it with what they hold.
141
+ * Returns `[]` for an empty payload; never invents an entry.
142
+ *
143
+ * @param {Array<object>} models the server's catalog (any shape).
144
+ * @returns {Array<object>} the entries to show, brain first (a new array).
145
+ */
146
+ function offerableCatalog(models) {
147
+ const list = Array.isArray(models) ? models.filter(Boolean) : [];
148
+ if (!list.length) return [];
149
+
150
+ const brain = selectBrainEntry(list);
151
+ const out = [];
152
+ const seen = new Set();
153
+
154
+ if (brain) {
155
+ // Same de-aliasing as filterAegisCatalog: this row IS the selection, so no
156
+ // renderer may filter it back out as a hidden alias.
157
+ const { hidden, alias_of, aliasOf, ...rest } = brain;
158
+ out.push({ ...rest, label: NEXUS_LABEL });
159
+ for (const id of NEXUS_BRAIN_IDS) seen.add(id);
160
+ if (typeof brain.id === 'string') seen.add(brain.id);
161
+ }
162
+
163
+ const ids = new Set(
164
+ list.map((m) => (typeof m.id === 'string' ? m.id.trim() : '')).filter(Boolean)
165
+ );
166
+ const aliasTargets = new Set(
167
+ list.map((m) => aliasOfEntry(m)).filter((t) => t && ids.has(t))
168
+ );
169
+
170
+ for (const m of list) {
171
+ const id = typeof m.id === 'string' ? m.id.trim() : '';
172
+ if (!id || seen.has(id)) continue;
173
+ // A row whose target is present is a duplicate pin, not a second model.
174
+ // Dropped here rather than per host, so the two hosts cannot disagree.
175
+ if (aliasOfEntry(m) && aliasTargets.has(aliasOfEntry(m))) continue;
176
+ seen.add(id);
177
+ out.push(m);
178
+ }
179
+ return out;
180
+ }
181
+
108
182
  module.exports = {
109
183
  NEXUS_BRAIN_IDS,
110
184
  NEXUS_LABEL,
111
185
  selectBrainEntry,
112
186
  filterAegisCatalog,
187
+ offerableCatalog,
113
188
  };
@@ -0,0 +1,144 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * BYOK model additions — the models a host OFFERS for a provider that the
5
+ * server's own catalog does not list.
6
+ *
7
+ * ── why a client-side addition is legitimate here, and only here ────────────
8
+ *
9
+ * For the POOLED class it would not be. `client/brain-catalog.js` exists
10
+ * precisely because a host may not invent an id: the pool can only address what
11
+ * it advertises, so an id a client made up would pin, look accepted, and 404 on
12
+ * the first turn. `/api/v1/models` is the whole list, and the rule is "offer
13
+ * what the server sends".
14
+ *
15
+ * BYOK is the opposite shape, and the server says so itself
16
+ * (services/byok_service.py, `byok_provider_catalog`): "the pooled route cannot
17
+ * address it, but BYOK relays whatever model the caller names, so it stays
18
+ * usable and stays listed". The relay is a stateless pass-through — the
19
+ * caller's own vendor key authenticates upstream, and AEGIS forwards the model
20
+ * string it was given. So for a provider the account holds a key for, an id the
21
+ * *vendor* serves is callable whether or not AEGIS's catalog happens to name
22
+ * it. That is the whole reason this file is allowed to exist.
23
+ *
24
+ * ── what was actually missing ──────────────────────────────────────────────
25
+ *
26
+ * The server derives each provider's `models` from MODEL_CATALOG, and for
27
+ * `deepseek` that catalog holds one descriptor (`default_model
28
+ * "deepseek-v4-flash"`, services/nexus_provider/catalog.py). Verified live
29
+ * 2026-09-18: `GET https://aegiscloud.org/api/v1/byok/providers` answers
30
+ * `deepseek` with `models: ["deepseek-v4-flash"]` and nothing else.
31
+ *
32
+ * So a user who brought a DeepSeek key saw exactly one pinnable model, and the
33
+ * 4.1 Flash — `deepseek-flash`, the spelling whose rate row, reasoning-token
34
+ * budget and effort rung this repo ALREADY carries (desktop/renderer/
35
+ * budget.js, desktop/lib/local/engine.js DEEPSEEK_REASONING_MODEL_RE, and the
36
+ * rate table in desktop/renderer/usage.js: "deepseek-flash, i.e. Flash 4.1")
37
+ * — was unreachable from the picker, with no hint that the key they had just
38
+ * pasted could call it.
39
+ *
40
+ * ── the rules this module keeps ────────────────────────────────────────────
41
+ *
42
+ * - ONE spelling per route. `deepseek-v4.1-flash` is the legacy alias the
43
+ * same regexes accept; listing both would paint two rows that pin one
44
+ * model, which is the "five spellings of one brain" defect the sibling
45
+ * brain-catalog module exists to end. The canonical 4.1 id is
46
+ * `deepseek-flash`, so that is the one added.
47
+ * - NEVER invent a provider. Only a provider the payload already lists is
48
+ * augmented. A provider row is a slot that accepts a vendor key; a row a
49
+ * client fabricated would invite a key for a slug the relay may not accept,
50
+ * and the failure would land on the user's first turn.
51
+ * - Idempotent and non-mutating. A payload that already carries the id comes
52
+ * back with the same provider objects untouched, so this is safe to apply
53
+ * twice (a caller that adds at fetch time and again before rendering cannot
54
+ * double-list) and safe to apply to a shared payload.
55
+ * - The server's order is preserved and additions are APPENDED, so the
56
+ * server's `default_model` keeps its first position — the default is what a
57
+ * bare provider id runs, and a client that reordered it would silently
58
+ * change which model a user gets for typing nothing.
59
+ *
60
+ * Pure: no I/O, no node builtins, no dependencies — requireable from a
61
+ * renderer, the CLI start-up path, the desktop main process, or an MCP host.
62
+ * Shared by the CLI and the desktop through one file for the same reason
63
+ * brain-catalog.js is: two copies is how those two hosts came to show one
64
+ * account two different model lists.
65
+ */
66
+
67
+ /**
68
+ * provider id → extra models to offer, in the order to append them.
69
+ *
70
+ * Frozen, and deliberately tiny: every entry here is a claim that the vendor
71
+ * serves an id the AEGIS catalog does not advertise. The durable fix for any of
72
+ * them is the server's MODEL_CATALOG (aegis1 services/nexus_provider/
73
+ * catalog.py) — this map is what keeps the two clients useful until that
74
+ * lands, and an entry must be deleted once the server lists the id itself
75
+ * (`withByokAdditions` then no longer reports it as an addition).
76
+ */
77
+ const BYOK_MODEL_ADDITIONS = Object.freeze({
78
+ // DeepSeek's 4.1 Flash. `deepseek-flash` is the spelling DeepSeek's own
79
+ // current API uses and the one this repo's rate table, token-budget and
80
+ // reasoning-model regexes all already key off; `deepseek-v4.1-flash` is the
81
+ // retired alias for the same route and is NOT listed separately.
82
+ deepseek: Object.freeze(['deepseek-flash']),
83
+ });
84
+
85
+ /** The extras to offer for one provider id (an empty array when there are none). */
86
+ function addedModelsFor(providerId) {
87
+ const id = typeof providerId === 'string' ? providerId.trim() : '';
88
+ const extra = id ? BYOK_MODEL_ADDITIONS[id] : null;
89
+ return Array.isArray(extra) ? extra.slice() : [];
90
+ }
91
+
92
+ /** The model ids an entry names, tolerating the server's two shapes. */
93
+ function modelIdsOf(provider) {
94
+ return (Array.isArray(provider && provider.models) ? provider.models : [])
95
+ .map((m) => (typeof m === 'string' ? m : m && m.id))
96
+ .map((m) => (typeof m === 'string' ? m.trim() : ''))
97
+ .filter(Boolean);
98
+ }
99
+
100
+ /**
101
+ * The server's BYOK provider catalog with the additions above applied.
102
+ *
103
+ * @param {Array<object>|object} providers the `providers` array from
104
+ * `GET /api/v1/byok/providers`, or the whole `{providers: [...]}` payload.
105
+ * @returns {Array<object>} a new array; provider objects are shared unless the
106
+ * row actually gained a model, and an empty/absent payload returns `[]`
107
+ * rather than a fabricated catalog.
108
+ */
109
+ function withByokAdditions(providers) {
110
+ const raw = Array.isArray(providers)
111
+ ? providers
112
+ : Array.isArray(providers && providers.providers)
113
+ ? providers.providers
114
+ : null;
115
+ if (!raw) return [];
116
+
117
+ const out = [];
118
+ for (const p of raw) {
119
+ if (!p || typeof p !== 'object') continue;
120
+ const id = typeof p.id === 'string' ? p.id.trim() : '';
121
+ const extra = id ? BYOK_MODEL_ADDITIONS[id] : null;
122
+ if (!Array.isArray(extra) || !extra.length) {
123
+ out.push(p);
124
+ continue;
125
+ }
126
+ const have = new Set(modelIdsOf(p));
127
+ const missing = extra.filter((m) => !have.has(m));
128
+ // Nothing to add: hand back the SAME object, so an already-complete payload
129
+ // is byte-identical after this pass and callers cannot tell it ran.
130
+ if (!missing.length) {
131
+ out.push(p);
132
+ continue;
133
+ }
134
+ const models = Array.isArray(p.models) ? p.models : [];
135
+ out.push({ ...p, models: [...models, ...missing] });
136
+ }
137
+ return out;
138
+ }
139
+
140
+ module.exports = {
141
+ BYOK_MODEL_ADDITIONS,
142
+ addedModelsFor,
143
+ withByokAdditions,
144
+ };