aegiscode 7.0.26 → 7.0.27

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.
Files changed (118) hide show
  1. package/SOURCE-OFFER.txt +9 -0
  2. package/package.json +4 -7
  3. package/scripts/check.mjs +1 -52
  4. package/scripts/demo.mjs +1 -94
  5. package/scripts/predist.mjs +1 -75
  6. package/scripts/runtests.mjs +1 -56
  7. package/scripts/seal-gate.mjs +1 -74
  8. package/src/agents.js +1 -139
  9. package/src/app.js +1 -2957
  10. package/src/art.js +1 -289
  11. package/src/chatflow.js +1 -3023
  12. package/src/checkpoint.js +1 -90
  13. package/src/clipboard.js +1 -424
  14. package/src/cloudsync.js +1 -528
  15. package/src/commands.js +1 -4089
  16. package/src/config.js +1 -581
  17. package/src/connect.js +1 -349
  18. package/src/credentials.js +1 -33
  19. package/src/deps.js +1 -232
  20. package/src/devrun.js +1 -187
  21. package/src/diff.js +1 -333
  22. package/src/diffview.js +1 -296
  23. package/src/engine.js +1 -297
  24. package/src/entitlement.js +1 -355
  25. package/src/events.js +1 -707
  26. package/src/export.js +1 -67
  27. package/src/filepreview.js +1 -153
  28. package/src/fingerprint.js +1 -592
  29. package/src/format.js +1 -259
  30. package/src/fuzzy.js +1 -119
  31. package/src/history.js +1 -423
  32. package/src/init.js +1 -175
  33. package/src/input.js +1 -139
  34. package/src/keys.js +1 -183
  35. package/src/markdown.js +1 -306
  36. package/src/models.js +1 -507
  37. package/src/naming.js +1 -57
  38. package/src/overlays.js +1 -462
  39. package/src/panels.js +1 -1418
  40. package/src/ping.js +1 -226
  41. package/src/presence.js +1 -238
  42. package/src/render.js +1 -516
  43. package/src/screen.js +1 -518
  44. package/src/screens.js +1 -896
  45. package/src/secret.js +1 -59
  46. package/src/securefs.js +1 -359
  47. package/src/settings.js +1 -155
  48. package/src/shared.js +1 -52
  49. package/src/sharedpaths.js +1 -53
  50. package/src/signup.js +1 -156
  51. package/src/summarize.js +1 -95
  52. package/src/sysdiag.js +1 -585
  53. package/src/system.js +1 -40
  54. package/src/theme.js +1 -570
  55. package/src/title.js +1 -220
  56. package/src/todos.js +1 -115
  57. package/src/tokens.js +1 -263
  58. package/src/topup.js +1 -210
  59. package/src/update.js +1 -191
  60. package/vendor/client/aegis.js +1 -2441
  61. package/vendor/client/attest.js +1 -518
  62. package/vendor/client/authorship-key.js +1 -410
  63. package/vendor/client/auto-provision.js +1 -134
  64. package/vendor/client/brain-catalog.js +1 -268
  65. package/vendor/client/byok-catalog.js +1 -199
  66. package/vendor/client/catalog-client.js +1 -487
  67. package/vendor/client/conversation-export.js +1 -177
  68. package/vendor/client/credentials.js +1 -494
  69. package/vendor/client/device-fingerprint.js +1 -141
  70. package/vendor/client/drive-connect.js +1 -110
  71. package/vendor/client/drive-upload.js +1 -234
  72. package/vendor/client/env-file.js +1 -1273
  73. package/vendor/client/fingerprint.js +1 -1064
  74. package/vendor/client/foreign-memory.js +1 -669
  75. package/vendor/client/google-signin.js +1 -133
  76. package/vendor/client/hooks.js +1 -430
  77. package/vendor/client/model-discovery.js +1 -373
  78. package/vendor/client/naming.js +1 -283
  79. package/vendor/client/platform.js +1 -937
  80. package/vendor/client/prefs.js +1 -351
  81. package/vendor/client/presence-constants.js +1 -107
  82. package/vendor/client/presence.js +1 -438
  83. package/vendor/client/record-vault.js +3 -1055
  84. package/vendor/client/session-store.js +1 -575
  85. package/vendor/client/topup.js +1 -297
  86. package/vendor/client/touch.js +1 -458
  87. package/vendor/client/update.js +1 -763
  88. package/vendor/client/user-models.js +1 -381
  89. package/vendor/desktop/lib/local/agents.js +1 -105
  90. package/vendor/desktop/lib/local/attachments.js +1 -276
  91. package/vendor/desktop/lib/local/autonomous.js +1 -1045
  92. package/vendor/desktop/lib/local/claude-pro.js +1 -1028
  93. package/vendor/desktop/lib/local/context.js +1 -125
  94. package/vendor/desktop/lib/local/engine.js +1 -3666
  95. package/vendor/desktop/lib/local/entitlement.js +1 -660
  96. package/vendor/desktop/lib/local/exec-plan.js +1 -269
  97. package/vendor/desktop/lib/local/git-scope.js +1 -228
  98. package/vendor/desktop/lib/local/integrity.js +1 -163
  99. package/vendor/desktop/lib/local/local.js +1 -2145
  100. package/vendor/desktop/lib/local/prompt.js +1 -280
  101. package/vendor/desktop/lib/local/queue.js +1 -560
  102. package/vendor/desktop/lib/local/session-rounds.js +1 -238
  103. package/vendor/desktop/lib/local/shell.js +1 -712
  104. package/vendor/desktop/lib/local/spill.js +1 -75
  105. package/vendor/desktop/lib/local/tools.js +1 -1328
  106. package/vendor/desktop/lib/local/turn-guard.js +1 -300
  107. package/vendor/desktop/lib/local/worktree-lock.js +1 -235
  108. package/vendor/desktop/lib/settings.js +1 -890
  109. package/vendor/desktop/main.js +3 -4890
  110. package/vendor/desktop/renderer/usage.js +1 -1239
  111. package/vendor/hosts/install.js +1 -638
  112. package/vendor/hosts/openai-shim.js +1 -515
  113. package/vendor/hosts/spec.js +1 -164
  114. package/vendor/hosts/targets.js +1 -346
  115. package/vendor/mcp/server.js +1 -221
  116. package/vendor/mcp/tools.js +1 -408
  117. package/vendor/one/src/child.js +1 -285
  118. package/vendor/one/src/permissions.js +1 -383
@@ -1,375 +1,3 @@
1
1
  // SPDX-License-Identifier: AGPL-3.0-or-later
2
2
  // Copyright (C) 2026 Niklas Borneklint — AEGIS Code (aegiscode) / Aegiscloud.
3
- // AEGIS Code (aegiscode) — source: https://github.com/aegisinfo/aegiscode-plugin
4
- // Conveying a modified copy, or running one as a network service, owes the
5
- // corresponding source under this licence (§5/§13) — see LICENSING.md.
6
- 'use strict';
7
-
8
- /**
9
- * Ask the VENDOR what it serves, so declaring a model stops depending on the
10
- * user remembering an id.
11
- *
12
- * `client/user-models.js` is how a model the AEGIS catalog does not name
13
- * becomes a pickable row, and `/model-add` is how a host writes one — but a
14
- * path whose only input is "type the vendor's model id" moves the release-lag
15
- * problem onto the user's memory instead of removing it. The cost is visible
16
- * in this repo: `client/byok-catalog.js` carries a hand-copied, hand-verified
17
- * list of Anthropic's ids ("Verified live 2026-10-11 against `GET
18
- * https://api.anthropic.com/v1/models`") plus a paragraph on which id is
19
- * retired — a chore the list endpoint answers in one request, and which goes
20
- * stale the day the vendor ships.
21
- *
22
- * So this module asks. It is pure in the parts that matter:
23
- * - no filesystem and no key store: the caller resolves the key and passes
24
- * it in, exactly as the callers of `env-file.js` already do;
25
- * - no network at load time and no module-scope `process` read;
26
- * - `fetchImpl` is injectable, so every test runs against a stub;
27
- * - it NEVER throws. A wrong key, a blocked network or a vendor changing
28
- * its response shape returns `{ ok: false, error }` for the caller to
29
- * report. Discovery sits on top of a path that already works by typing
30
- * the id, so a failure here must not be able to take that path down.
31
- *
32
- * Only ids `client/user-models.js` would accept come back, because the store
33
- * that is about to be written is the one with the rule — a discovery list that
34
- * offered an id `/model-add` then refused would be worse than no list.
35
- */
36
-
37
- const { sanitizeModel } = require('./user-models.js');
38
-
39
- /** How long a vendor gets to answer before discovery stands down. */
40
- const DISCOVERY_TIMEOUT_MS = 8000;
41
-
42
- /** `Authorization: Bearer <key>` — what most OpenAI-compatible vendors take. */
43
- function bearer(key) {
44
- return { authorization: `Bearer ${key}` };
45
- }
46
-
47
- /**
48
- * The providers whose OWN list endpoint this module knows, by the id the BYOK
49
- * relay uses. A provider that is not here is not an error: it is a provider
50
- * whose list is either undocumented or has no stable endpoint, and the caller
51
- * falls back to asking the user to type the id.
52
- *
53
- * Keys are lowercase provider ids; `aliases` maps the other spellings a user
54
- * might type (`/model-discover xai` and `/model-discover grok` must hit the
55
- * same vendor).
56
- */
57
- const ENDPOINTS = Object.freeze({
58
- anthropic: Object.freeze({
59
- url: 'https://api.anthropic.com/v1/models',
60
- headers: (key) => ({ 'x-api-key': key, 'anthropic-version': '2023-06-01' }),
61
- note: 'the vendor requires anthropic-version; the console key is sent as x-api-key',
62
- }),
63
- openai: Object.freeze({
64
- url: 'https://api.openai.com/v1/models',
65
- headers: bearer,
66
- note: 'OpenAI-compatible: { data: [ { id } ] }',
67
- }),
68
- deepseek: Object.freeze({
69
- url: 'https://api.deepseek.com/models',
70
- headers: bearer,
71
- note: 'OpenAI-compatible; /v1/models answers the same list',
72
- }),
73
- grok: Object.freeze({
74
- url: 'https://api.x.ai/v1/models',
75
- headers: bearer,
76
- note: 'xAI answers on /v1/models under the vendor id grok',
77
- }),
78
- gemini: Object.freeze({
79
- url: 'https://generativelanguage.googleapis.com/v1beta/models',
80
- headers: () => ({}),
81
- query: (key) => ({ key }),
82
- note: 'the key travels in the query string; ids come back as "models/<id>"',
83
- }),
84
- groq: Object.freeze({
85
- url: 'https://api.groq.com/openai/v1/models',
86
- headers: bearer,
87
- note: 'OpenAI-compatible under /openai/v1',
88
- }),
89
- mistral: Object.freeze({
90
- url: 'https://api.mistral.ai/v1/models',
91
- headers: bearer,
92
- note: 'OpenAI-compatible',
93
- }),
94
- openrouter: Object.freeze({
95
- url: 'https://openrouter.ai/api/v1/models',
96
- headers: bearer,
97
- note: 'OpenAI-compatible; ids are prefixed "vendor/model"',
98
- }),
99
- together: Object.freeze({
100
- url: 'https://api.together.xyz/v1/models',
101
- headers: bearer,
102
- note: 'OpenAI-compatible',
103
- }),
104
- // The remaining providers in aegis1's catalog that speak `openai_chat` and
105
- // answer a standard OpenAI-shaped list on `<base_url>/models`.
106
- //
107
- // Probed live rather than assumed, because "OpenAI-compatible chat" does not
108
- // imply "has a list endpoint": cerebras, fireworks and sakana answer 401/403
109
- // without a key (the endpoint exists and is gated) and NVIDIA's list answers
110
- // 200 unauthenticated with 84 rows, which is why it is the one endpoint here
111
- // whose list is public. Ollama is deliberately absent: it is keyless and
112
- // local, so it has nothing to put in the API key this module requires, and
113
- // `canDiscover` would be reporting a capability the caller cannot use.
114
- cerebras: Object.freeze({
115
- url: 'https://api.cerebras.ai/v1/models',
116
- headers: bearer,
117
- note: 'OpenAI-compatible under /v1',
118
- }),
119
- fireworks: Object.freeze({
120
- url: 'https://api.fireworks.ai/inference/v1/models',
121
- headers: bearer,
122
- note: 'OpenAI-compatible under /inference/v1; ids are "accounts/fireworks/models/<id>"',
123
- }),
124
- nvidia_nim: Object.freeze({
125
- url: 'https://integrate.api.nvidia.com/v1/models',
126
- headers: bearer,
127
- note: 'OpenAI-compatible; ids are "<vendor>/<model>"',
128
- }),
129
- sakana: Object.freeze({
130
- url: 'https://api.sakana.ai/v1/models',
131
- headers: bearer,
132
- note: 'OpenAI-compatible under /v1',
133
- }),
134
- });
135
-
136
- /** Other spellings a user types for a provider this module knows. */
137
- const ALIASES = Object.freeze({
138
- 'x.ai': 'grok',
139
- xai: 'grok',
140
- 'google': 'gemini',
141
- 'google-ai': 'gemini',
142
- 'googleai': 'gemini',
143
- 'open-ai': 'openai',
144
- 'deep-seek': 'deepseek',
145
- // Two catalog rows that are the SAME VENDOR under a second provider id: both
146
- // `openai-gpt4o-mini` and `anthropic-haiku` share their sibling's credential
147
- // and base_url, and differ only in the default model they pin (see
148
- // `client/byok-catalog.js`, which notes the two OpenAI ids "share one
149
- // credential and one model"). Discovery asks a vendor, so both spellings must
150
- // reach the one list its key can already answer — otherwise a user holding a
151
- // key filed under the `-haiku` / `-gpt4o-mini` row is told this client has no
152
- // endpoint for their provider while the identical key under the sibling row
153
- // is accepted. `custom` and `ollama` are deliberately NOT aliased: the first
154
- // has no fixed base_url (it is supplied per request), and the second is
155
- // keyless, so neither has a vendor list this module could ask.
156
- 'openai-gpt4o-mini': 'openai',
157
- 'anthropic-haiku': 'anthropic',
158
- });
159
-
160
- /**
161
- * The families that are NOT chat models, so a picker is not 400 lines of
162
- * embedding rows. These are not dropped — they come back in `others`, because
163
- * "the vendor lists 60 ids and the picker showed 12" is a fact the user is
164
- * owed, not a silent filter.
165
- */
166
- const NON_CHAT_RE = /embed|whisper|\btts\b|dall-e|moderation|rerank|imagen|\bveo\b|\baqa\b|transcribe|audio|speech|synthia|guard-content/i;
167
-
168
- /** The frozen endpoint for a provider id (or `null` when unknown). */
169
- function endpointFor(provider) {
170
- const raw = String(provider == null ? '' : provider).trim().toLowerCase();
171
- if (!raw) return null;
172
- const id = ALIASES[raw] || raw;
173
- const entry = ENDPOINTS[id];
174
- return entry ? Object.freeze({ id, ...entry }) : null;
175
- }
176
-
177
- /** True when discovery knows how to ask this provider at all. */
178
- function canDiscover(provider) {
179
- return Boolean(endpointFor(provider));
180
- }
181
-
182
- /** Every provider id discovery can ask, sorted — for a hint line. */
183
- function discoverableProviders() {
184
- return Object.keys(ENDPOINTS).sort();
185
- }
186
-
187
- /** True when a vendor id names something other than a chat model. */
188
- function looksNonChat(id) {
189
- return NON_CHAT_RE.test(String(id));
190
- }
191
-
192
- /**
193
- * Pull candidate ids out of whatever shape the vendor answered with.
194
- *
195
- * Handled: `{ data: [ { id } ] }` (OpenAI, DeepSeek, xAI, Groq, Mistral,
196
- * OpenRouter, Together), Anthropic's identical `{ data: [ { id } ] }`, Gemini's
197
- * `{ models: [ { name: "models/<id>" } ] }`, and a bare array of strings or
198
- * objects — vendors that answer unversioned occasionally answer either.
199
- *
200
- * Returns `null` when the payload has no list at all, which the caller reports
201
- * as "the vendor answered in a shape this client does not know" rather than as
202
- * an empty catalog (an empty list is a real, and very different, answer).
203
- */
204
- function idsFromPayload(payload) {
205
- const rows = Array.isArray(payload)
206
- ? payload
207
- : Array.isArray(payload && payload.data)
208
- ? payload.data
209
- : Array.isArray(payload && payload.models)
210
- ? payload.models
211
- : null;
212
- if (!rows) return null;
213
- const ids = [];
214
- const others = [];
215
- for (const row of rows) {
216
- if (row == null) continue;
217
- const raw = typeof row === 'string' ? row : row.id || row.name || row.model;
218
- if (typeof raw !== 'string' || !raw.trim()) continue;
219
- // Gemini names rows "models/<id>"; the vendor id is the part after it.
220
- const candidate = raw.trim().replace(/^models\//, '');
221
- // A row that declares the methods it supports and does NOT list
222
- // generateContent is not a chat model (Imagen says "predict"). That is a
223
- // stronger signal than the name, so it is used before the name is.
224
- const methods = row && Array.isArray(row.supportedGenerationMethods)
225
- ? row.supportedGenerationMethods
226
- : row && Array.isArray(row.supported_actions)
227
- ? row.supported_actions
228
- : null;
229
- const chatty = methods ? methods.includes('generateContent') || methods.includes('generate') : null;
230
- let id;
231
- try {
232
- id = sanitizeModel(candidate);
233
- } catch {
234
- continue; // not a string the declaration store would accept either
235
- }
236
- if (chatty === false || (chatty === null && looksNonChat(id))) others.push(id);
237
- else ids.push(id);
238
- }
239
- const uniq = (list) => [...new Set(list)];
240
- return { ids: uniq(ids), others: uniq(others).filter((id) => !ids.includes(id)) };
241
- }
242
-
243
- /**
244
- * Ask a provider what it serves.
245
- *
246
- * `opts.key` is the user's own vendor key — required, and never read or logged
247
- * here. `opts.fetchImpl` defaults to the global fetch. `opts.timeoutMs` bounds
248
- * the request; the timer is always cleared, and the caller's `opts.signal` is
249
- * honoured so a cancelled turn cancels the request.
250
- *
251
- * Resolves — never rejects — with one of:
252
- * { ok: true, provider, endpoint, ids, others, count }
253
- * { ok: false, provider, supported, error }
254
- * `supported: false` means this module has no endpoint for that vendor, which
255
- * is a different thing from a vendor that refused the key.
256
- */
257
- async function discoverModels(provider, opts = {}) {
258
- const entry = endpointFor(provider);
259
- const asked = String(provider == null ? '' : provider).trim().toLowerCase();
260
- const key = String(opts.key == null ? '' : opts.key).trim();
261
- if (!entry) {
262
- return {
263
- ok: false,
264
- provider: asked,
265
- supported: false,
266
- error: `${asked || 'that provider'} has no model-list endpoint this client knows`,
267
- };
268
- }
269
- if (!key) {
270
- return { ok: false, provider: entry.id, supported: true, error: `no ${entry.id} key on this machine` };
271
- }
272
- const fetchImpl = opts.fetchImpl || (typeof fetch === 'function' ? fetch : null);
273
- if (!fetchImpl) {
274
- return { ok: false, provider: entry.id, supported: true, error: 'no fetch implementation available' };
275
- }
276
- const timeoutMs = Number.isFinite(opts.timeoutMs) ? opts.timeoutMs : DISCOVERY_TIMEOUT_MS;
277
- const controller = typeof AbortController === 'function' ? new AbortController() : null;
278
- const timer = controller ? setTimeout(() => controller.abort(), timeoutMs) : null;
279
- // Deliberately NOT unref'd: the timer is the thing that must fire when a
280
- // vendor goes quiet. An unref'd timer in a process whose only other pending
281
- // work is the await would be collected before it fired, and the hang this
282
- // timeout exists to prevent is exactly what that produces. It is cleared in
283
- // the `finally` below, so it never outlives the request either way.
284
- const onAbort = () => controller && controller.abort();
285
- if (controller && opts.signal) {
286
- if (opts.signal.aborted) onAbort();
287
- else if (typeof opts.signal.addEventListener === 'function') opts.signal.addEventListener('abort', onAbort, { once: true });
288
- }
289
- try {
290
- const url = new URL(entry.url);
291
- if (typeof entry.query === 'function') {
292
- for (const [k, v] of Object.entries(entry.query(key) || {})) url.searchParams.set(k, v);
293
- }
294
- const headers = { accept: 'application/json' };
295
- for (const [k, v] of Object.entries(entry.headers(key) || {})) {
296
- // Vendors that want the header spelled a particular way get it; the
297
- // table stores the canonical lowercase name.
298
- headers[k === 'authorization' ? 'Authorization' : k] = v;
299
- }
300
- const res = await fetchImpl(url.toString(), {
301
- method: 'GET',
302
- headers,
303
- signal: controller ? controller.signal : undefined,
304
- });
305
- const status = res && typeof res.status === 'number' ? res.status : 0;
306
- if (!res || (typeof res.ok === 'boolean' && !res.ok)) {
307
- // 401/403 is the common case and deserves its own sentence: the fix is
308
- // a different key, not a different provider.
309
- const why = status === 401 || status === 403
310
- ? `the vendor refused the key (HTTP ${status})`
311
- : status === 404
312
- ? `the vendor has no model list at ${url.pathname} (HTTP 404)`
313
- : `the vendor answered HTTP ${status || 'nothing'}`;
314
- return { ok: false, provider: entry.id, supported: true, status, error: why };
315
- }
316
- let payload;
317
- try {
318
- payload = await res.json();
319
- } catch (err) {
320
- return {
321
- ok: false,
322
- provider: entry.id,
323
- supported: true,
324
- status,
325
- error: `the vendor's reply was not JSON (${(err && err.message) || err})`,
326
- };
327
- }
328
- const parsed = idsFromPayload(payload);
329
- if (!parsed) {
330
- return {
331
- ok: false,
332
- provider: entry.id,
333
- supported: true,
334
- status,
335
- error: `the vendor answered in a shape this client does not know (no "data" or "models" list)`,
336
- };
337
- }
338
- return {
339
- ok: true,
340
- provider: entry.id,
341
- endpoint: entry.url,
342
- ids: parsed.ids,
343
- others: parsed.others,
344
- count: parsed.ids.length,
345
- };
346
- } catch (err) {
347
- const aborted = (err && (err.name === 'AbortError' || err.code === 'ABORT_ERR')) || (controller && controller.signal.aborted);
348
- return {
349
- ok: false,
350
- provider: entry.id,
351
- supported: true,
352
- error: aborted
353
- ? `the vendor did not answer within ${timeoutMs} ms`
354
- : `could not reach the vendor (${(err && err.message) || err})`,
355
- };
356
- } finally {
357
- if (timer) clearTimeout(timer);
358
- if (controller && opts.signal && typeof opts.signal.removeEventListener === 'function') {
359
- opts.signal.removeEventListener('abort', onAbort);
360
- }
361
- }
362
- }
363
-
364
- module.exports = {
365
- DISCOVERY_TIMEOUT_MS,
366
- ENDPOINTS,
367
- ALIASES,
368
- NON_CHAT_RE,
369
- endpointFor,
370
- canDiscover,
371
- discoverableProviders,
372
- looksNonChat,
373
- idsFromPayload,
374
- discoverModels,
375
- };
3
+ "use strict";const{sanitizeModel:sanitizeModel}=require("./user-models.js"),DISCOVERY_TIMEOUT_MS=8e3;function bearer(e){return{authorization:`Bearer ${e}`}}const ENDPOINTS=Object.freeze({anthropic:Object.freeze({url:"https://api.anthropic.com/v1/models",headers:e=>({"x-api-key":e,"anthropic-version":"2023-06-01"}),note:"the vendor requires anthropic-version; the console key is sent as x-api-key"}),openai:Object.freeze({url:"https://api.openai.com/v1/models",headers:bearer,note:"OpenAI-compatible: { data: [ { id } ] }"}),deepseek:Object.freeze({url:"https://api.deepseek.com/models",headers:bearer,note:"OpenAI-compatible; /v1/models answers the same list"}),grok:Object.freeze({url:"https://api.x.ai/v1/models",headers:bearer,note:"xAI answers on /v1/models under the vendor id grok"}),gemini:Object.freeze({url:"https://generativelanguage.googleapis.com/v1beta/models",headers:()=>({}),query:e=>({key:e}),note:'the key travels in the query string; ids come back as "models/<id>"'}),groq:Object.freeze({url:"https://api.groq.com/openai/v1/models",headers:bearer,note:"OpenAI-compatible under /openai/v1"}),mistral:Object.freeze({url:"https://api.mistral.ai/v1/models",headers:bearer,note:"OpenAI-compatible"}),openrouter:Object.freeze({url:"https://openrouter.ai/api/v1/models",headers:bearer,note:'OpenAI-compatible; ids are prefixed "vendor/model"'}),together:Object.freeze({url:"https://api.together.xyz/v1/models",headers:bearer,note:"OpenAI-compatible"}),cerebras:Object.freeze({url:"https://api.cerebras.ai/v1/models",headers:bearer,note:"OpenAI-compatible under /v1"}),fireworks:Object.freeze({url:"https://api.fireworks.ai/inference/v1/models",headers:bearer,note:'OpenAI-compatible under /inference/v1; ids are "accounts/fireworks/models/<id>"'}),nvidia_nim:Object.freeze({url:"https://integrate.api.nvidia.com/v1/models",headers:bearer,note:'OpenAI-compatible; ids are "<vendor>/<model>"'}),sakana:Object.freeze({url:"https://api.sakana.ai/v1/models",headers:bearer,note:"OpenAI-compatible under /v1"})}),ALIASES=Object.freeze({"x.ai":"grok",xai:"grok",google:"gemini","google-ai":"gemini",googleai:"gemini","open-ai":"openai","deep-seek":"deepseek","openai-gpt4o-mini":"openai","anthropic-haiku":"anthropic"}),NON_CHAT_RE=/embed|whisper|\btts\b|dall-e|moderation|rerank|imagen|\bveo\b|\baqa\b|transcribe|audio|speech|synthia|guard-content/i;function endpointFor(e){const r=String(null==e?"":e).trim().toLowerCase();if(!r)return null;const o=ALIASES[r]||r,t=ENDPOINTS[o];return t?Object.freeze({id:o,...t}):null}function canDiscover(e){return Boolean(endpointFor(e))}function discoverableProviders(){return Object.keys(ENDPOINTS).sort()}function looksNonChat(e){return NON_CHAT_RE.test(String(e))}function idsFromPayload(e){const r=Array.isArray(e)?e:Array.isArray(e&&e.data)?e.data:Array.isArray(e&&e.models)?e.models:null;if(!r)return null;const o=[],t=[];for(const e of r){if(null==e)continue;const r="string"==typeof e?e:e.id||e.name||e.model;if("string"!=typeof r||!r.trim())continue;const n=r.trim().replace(/^models\//,""),i=e&&Array.isArray(e.supportedGenerationMethods)?e.supportedGenerationMethods:e&&Array.isArray(e.supported_actions)?e.supported_actions:null,s=i?i.includes("generateContent")||i.includes("generate"):null;let a;try{a=sanitizeModel(n)}catch{continue}!1===s||null===s&&looksNonChat(a)?t.push(a):o.push(a)}const n=e=>[...new Set(e)];return{ids:n(o),others:n(t).filter((e=>!o.includes(e)))}}async function discoverModels(e,r={}){const o=endpointFor(e),t=String(null==e?"":e).trim().toLowerCase(),n=String(null==r.key?"":r.key).trim();if(!o)return{ok:!1,provider:t,supported:!1,error:`${t||"that provider"} has no model-list endpoint this client knows`};if(!n)return{ok:!1,provider:o.id,supported:!0,error:`no ${o.id} key on this machine`};const i=r.fetchImpl||("function"==typeof fetch?fetch:null);if(!i)return{ok:!1,provider:o.id,supported:!0,error:"no fetch implementation available"};const s=Number.isFinite(r.timeoutMs)?r.timeoutMs:8e3,a="function"==typeof AbortController?new AbortController:null,d=a?setTimeout((()=>a.abort()),s):null,l=()=>a&&a.abort();a&&r.signal&&(r.signal.aborted?l():"function"==typeof r.signal.addEventListener&&r.signal.addEventListener("abort",l,{once:!0}));try{const e=new URL(o.url);if("function"==typeof o.query)for(const[r,t]of Object.entries(o.query(n)||{}))e.searchParams.set(r,t);const r={accept:"application/json"};for(const[e,t]of Object.entries(o.headers(n)||{}))r["authorization"===e?"Authorization":e]=t;const t=await i(e.toString(),{method:"GET",headers:r,signal:a?a.signal:void 0}),s=t&&"number"==typeof t.status?t.status:0;if(!t||"boolean"==typeof t.ok&&!t.ok){const r=401===s||403===s?`the vendor refused the key (HTTP ${s})`:404===s?`the vendor has no model list at ${e.pathname} (HTTP 404)`:`the vendor answered HTTP ${s||"nothing"}`;return{ok:!1,provider:o.id,supported:!0,status:s,error:r}}let d;try{d=await t.json()}catch(e){return{ok:!1,provider:o.id,supported:!0,status:s,error:`the vendor's reply was not JSON (${e&&e.message||e})`}}const l=idsFromPayload(d);return l?{ok:!0,provider:o.id,endpoint:o.url,ids:l.ids,others:l.others,count:l.ids.length}:{ok:!1,provider:o.id,supported:!0,status:s,error:'the vendor answered in a shape this client does not know (no "data" or "models" list)'}}catch(e){const r=e&&("AbortError"===e.name||"ABORT_ERR"===e.code)||a&&a.signal.aborted;return{ok:!1,provider:o.id,supported:!0,error:r?`the vendor did not answer within ${s} ms`:`could not reach the vendor (${e&&e.message||e})`}}finally{d&&clearTimeout(d),a&&r.signal&&"function"==typeof r.signal.removeEventListener&&r.signal.removeEventListener("abort",l)}}module.exports={DISCOVERY_TIMEOUT_MS:8e3,ENDPOINTS:ENDPOINTS,ALIASES:ALIASES,NON_CHAT_RE:NON_CHAT_RE,endpointFor:endpointFor,canDiscover:canDiscover,discoverableProviders:discoverableProviders,looksNonChat:looksNonChat,idsFromPayload:idsFromPayload,discoverModels:discoverModels};