aegiscode 6.7.7 → 6.8.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/README.md +35 -51
- package/bin/aegiscode.js +24 -0
- package/package.json +1 -1
- package/scripts/predist.mjs +11 -7
- package/src/app.js +7 -46
- package/src/commands.js +40 -159
- package/src/config.js +0 -10
- package/src/deps.js +5 -30
- package/src/engine.js +18 -83
- package/src/sharedpaths.js +50 -0
- package/vendor/client/env-file.js +182 -0
- package/vendor/desktop/lib/local/engine.js +225 -128
- package/vendor/desktop/lib/local/local.js +433 -0
- package/vendor/desktop/lib/local/tools.js +7 -56
- package/vendor/desktop/lib/settings.js +33 -0
- package/vendor/desktop/renderer/usage.js +4 -4
- package/src/custommodels.js +0 -198
- package/vendor/desktop/lib/local/providers.js +0 -679
package/src/custommodels.js
DELETED
|
@@ -1,198 +0,0 @@
|
|
|
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
|
-
};
|