aegiscode 6.7.6 → 6.7.8

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.
@@ -17,6 +17,12 @@
17
17
 
18
18
  const fs = require('node:fs');
19
19
  const path = require('node:path');
20
+ // The direct-dial policy (see that file): which rows may hold a remote base URL.
21
+ // Enforced HERE, at the storage seam, so the unusable configuration cannot be
22
+ // created by either host — the desktop's Settings pane or the CLI's `/model add`
23
+ // — rather than only being refused at send time. Pure node builtins, so this
24
+ // store stays loadable without Electron.
25
+ const { isLocalEndpoint, remoteRefusal, isDirectDialRow } = require('./local/endpoints.js');
20
26
 
21
27
  const SETTINGS_FILE = 'settings.json';
22
28
 
@@ -154,8 +160,38 @@ function createSettingsStore({ dir, safeStorage } = {}) {
154
160
  };
155
161
  }
156
162
 
163
+ /**
164
+ * Write a provider row.
165
+ *
166
+ * A direct-dial row ('openai-compat', 'anthropic', 'custom:*') may not hold a
167
+ * remote base URL: those classes talk to the URL themselves (providers.js),
168
+ * which bills nobody, so the only usage they may carry is an endpoint on this
169
+ * machine. Refusing at STORAGE — the earliest seam, shared by the desktop's
170
+ * Settings pane and the CLI — means a remote custom endpoint cannot be
171
+ * configured into existence in the first place; the engine's dispatch gate
172
+ * then covers the rows that predate this rule or were hand-edited into the
173
+ * file. Empty is allowed (that is how the row is cleared, and how a
174
+ * not-yet-configured row looks), and every other namespace is untouched:
175
+ * `byok:<provider>` rows are remote by definition and reach their provider
176
+ * through AEGIS's relay, which is what bills them.
177
+ */
157
178
  function set(provider, { baseURL, key } = {}) {
158
179
  assertNotReserved(provider);
180
+ if (baseURL !== undefined && isDirectDialRow(provider)) {
181
+ const next = String(baseURL == null ? '' : baseURL).trim();
182
+ if (next && !isLocalEndpoint(next)) {
183
+ const err = new Error(remoteRefusal(next, {
184
+ subject: `the ${provider} endpoint`,
185
+ hint:
186
+ 'This lane is for a model running on this machine. To use a remote provider, ' +
187
+ 'save it under Bring-your-own-key (the CLI\'s /class byok), where the AEGIS handling ' +
188
+ 'fee bills the turn.',
189
+ }));
190
+ err.status = 400;
191
+ err.code = 'CUSTOM_ENDPOINT_NOT_LOCAL';
192
+ throw err;
193
+ }
194
+ }
159
195
  const data = load();
160
196
  const cfg = data[provider] || {};
161
197
  if (baseURL !== undefined) cfg.baseURL = baseURL;