aegiscode 7.0.13 → 7.0.15

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 (109) hide show
  1. package/SOURCE-OFFER.txt +9 -0
  2. package/package.json +3 -2
  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 -2932
  10. package/src/art.js +1 -289
  11. package/src/chatflow.js +1 -3008
  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 -3987
  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/fingerprint.js +1 -592
  28. package/src/format.js +1 -259
  29. package/src/fuzzy.js +1 -119
  30. package/src/history.js +1 -401
  31. package/src/init.js +1 -175
  32. package/src/input.js +1 -139
  33. package/src/keys.js +1 -183
  34. package/src/markdown.js +1 -306
  35. package/src/models.js +1 -487
  36. package/src/naming.js +1 -229
  37. package/src/overlays.js +1 -461
  38. package/src/panels.js +1 -1418
  39. package/src/ping.js +1 -226
  40. package/src/presence.js +1 -238
  41. package/src/render.js +1 -515
  42. package/src/screen.js +1 -518
  43. package/src/screens.js +1 -896
  44. package/src/secret.js +1 -59
  45. package/src/securefs.js +1 -359
  46. package/src/settings.js +1 -155
  47. package/src/shared.js +1 -52
  48. package/src/sharedpaths.js +1 -53
  49. package/src/signup.js +1 -156
  50. package/src/summarize.js +1 -95
  51. package/src/sysdiag.js +1 -585
  52. package/src/system.js +1 -40
  53. package/src/theme.js +1 -570
  54. package/src/title.js +1 -220
  55. package/src/todos.js +1 -115
  56. package/src/tokens.js +1 -263
  57. package/src/topup.js +1 -210
  58. package/src/update.js +1 -181
  59. package/vendor/client/aegis.js +1 -2054
  60. package/vendor/client/attest.js +1 -442
  61. package/vendor/client/authorship-key.js +1 -410
  62. package/vendor/client/auto-provision.js +1 -134
  63. package/vendor/client/brain-catalog.js +1 -268
  64. package/vendor/client/byok-catalog.js +1 -230
  65. package/vendor/client/credentials.js +1 -494
  66. package/vendor/client/device-fingerprint.js +1 -141
  67. package/vendor/client/drive-connect.js +1 -85
  68. package/vendor/client/drive-upload.js +1 -174
  69. package/vendor/client/env-file.js +1 -1273
  70. package/vendor/client/fingerprint.js +1 -1064
  71. package/vendor/client/foreign-memory.js +1 -669
  72. package/vendor/client/google-signin.js +1 -125
  73. package/vendor/client/hooks.js +1 -430
  74. package/vendor/client/model-discovery.js +1 -330
  75. package/vendor/client/platform.js +1 -937
  76. package/vendor/client/prefs.js +1 -351
  77. package/vendor/client/presence-constants.js +1 -107
  78. package/vendor/client/presence.js +1 -438
  79. package/vendor/client/record-vault.js +3 -1055
  80. package/vendor/client/session-store.js +1 -548
  81. package/vendor/client/topup.js +1 -297
  82. package/vendor/client/touch.js +1 -458
  83. package/vendor/client/update.js +1 -704
  84. package/vendor/client/user-models.js +1 -381
  85. package/vendor/desktop/lib/local/agents.js +1 -105
  86. package/vendor/desktop/lib/local/autonomous.js +1 -1045
  87. package/vendor/desktop/lib/local/claude-pro.js +1 -993
  88. package/vendor/desktop/lib/local/context.js +1 -95
  89. package/vendor/desktop/lib/local/engine.js +1 -3228
  90. package/vendor/desktop/lib/local/entitlement.js +1 -654
  91. package/vendor/desktop/lib/local/git-scope.js +1 -228
  92. package/vendor/desktop/lib/local/local.js +1 -2135
  93. package/vendor/desktop/lib/local/prompt.js +1 -275
  94. package/vendor/desktop/lib/local/queue.js +1 -560
  95. package/vendor/desktop/lib/local/session-rounds.js +1 -208
  96. package/vendor/desktop/lib/local/shell.js +1 -680
  97. package/vendor/desktop/lib/local/tools.js +1 -1238
  98. package/vendor/desktop/lib/local/turn-guard.js +1 -300
  99. package/vendor/desktop/lib/local/worktree-lock.js +1 -235
  100. package/vendor/desktop/lib/settings.js +1 -890
  101. package/vendor/desktop/renderer/usage.js +1 -1239
  102. package/vendor/hosts/install.js +1 -638
  103. package/vendor/hosts/openai-shim.js +1 -515
  104. package/vendor/hosts/spec.js +1 -164
  105. package/vendor/hosts/targets.js +1 -346
  106. package/vendor/mcp/server.js +1 -221
  107. package/vendor/mcp/tools.js +1 -408
  108. package/vendor/one/src/child.js +1 -285
  109. package/vendor/one/src/permissions.js +1 -369
@@ -1,332 +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
- });
105
-
106
- /** Other spellings a user types for a provider this module knows. */
107
- const ALIASES = Object.freeze({
108
- 'x.ai': 'grok',
109
- xai: 'grok',
110
- 'google': 'gemini',
111
- 'google-ai': 'gemini',
112
- 'googleai': 'gemini',
113
- 'open-ai': 'openai',
114
- 'deep-seek': 'deepseek',
115
- });
116
-
117
- /**
118
- * The families that are NOT chat models, so a picker is not 400 lines of
119
- * embedding rows. These are not dropped — they come back in `others`, because
120
- * "the vendor lists 60 ids and the picker showed 12" is a fact the user is
121
- * owed, not a silent filter.
122
- */
123
- const NON_CHAT_RE = /embed|whisper|\btts\b|dall-e|moderation|rerank|imagen|\bveo\b|\baqa\b|transcribe|audio|speech|synthia|guard-content/i;
124
-
125
- /** The frozen endpoint for a provider id (or `null` when unknown). */
126
- function endpointFor(provider) {
127
- const raw = String(provider == null ? '' : provider).trim().toLowerCase();
128
- if (!raw) return null;
129
- const id = ALIASES[raw] || raw;
130
- const entry = ENDPOINTS[id];
131
- return entry ? Object.freeze({ id, ...entry }) : null;
132
- }
133
-
134
- /** True when discovery knows how to ask this provider at all. */
135
- function canDiscover(provider) {
136
- return Boolean(endpointFor(provider));
137
- }
138
-
139
- /** Every provider id discovery can ask, sorted — for a hint line. */
140
- function discoverableProviders() {
141
- return Object.keys(ENDPOINTS).sort();
142
- }
143
-
144
- /** True when a vendor id names something other than a chat model. */
145
- function looksNonChat(id) {
146
- return NON_CHAT_RE.test(String(id));
147
- }
148
-
149
- /**
150
- * Pull candidate ids out of whatever shape the vendor answered with.
151
- *
152
- * Handled: `{ data: [ { id } ] }` (OpenAI, DeepSeek, xAI, Groq, Mistral,
153
- * OpenRouter, Together), Anthropic's identical `{ data: [ { id } ] }`, Gemini's
154
- * `{ models: [ { name: "models/<id>" } ] }`, and a bare array of strings or
155
- * objects — vendors that answer unversioned occasionally answer either.
156
- *
157
- * Returns `null` when the payload has no list at all, which the caller reports
158
- * as "the vendor answered in a shape this client does not know" rather than as
159
- * an empty catalog (an empty list is a real, and very different, answer).
160
- */
161
- function idsFromPayload(payload) {
162
- const rows = Array.isArray(payload)
163
- ? payload
164
- : Array.isArray(payload && payload.data)
165
- ? payload.data
166
- : Array.isArray(payload && payload.models)
167
- ? payload.models
168
- : null;
169
- if (!rows) return null;
170
- const ids = [];
171
- const others = [];
172
- for (const row of rows) {
173
- if (row == null) continue;
174
- const raw = typeof row === 'string' ? row : row.id || row.name || row.model;
175
- if (typeof raw !== 'string' || !raw.trim()) continue;
176
- // Gemini names rows "models/<id>"; the vendor id is the part after it.
177
- const candidate = raw.trim().replace(/^models\//, '');
178
- // A row that declares the methods it supports and does NOT list
179
- // generateContent is not a chat model (Imagen says "predict"). That is a
180
- // stronger signal than the name, so it is used before the name is.
181
- const methods = row && Array.isArray(row.supportedGenerationMethods)
182
- ? row.supportedGenerationMethods
183
- : row && Array.isArray(row.supported_actions)
184
- ? row.supported_actions
185
- : null;
186
- const chatty = methods ? methods.includes('generateContent') || methods.includes('generate') : null;
187
- let id;
188
- try {
189
- id = sanitizeModel(candidate);
190
- } catch {
191
- continue; // not a string the declaration store would accept either
192
- }
193
- if (chatty === false || (chatty === null && looksNonChat(id))) others.push(id);
194
- else ids.push(id);
195
- }
196
- const uniq = (list) => [...new Set(list)];
197
- return { ids: uniq(ids), others: uniq(others).filter((id) => !ids.includes(id)) };
198
- }
199
-
200
- /**
201
- * Ask a provider what it serves.
202
- *
203
- * `opts.key` is the user's own vendor key — required, and never read or logged
204
- * here. `opts.fetchImpl` defaults to the global fetch. `opts.timeoutMs` bounds
205
- * the request; the timer is always cleared, and the caller's `opts.signal` is
206
- * honoured so a cancelled turn cancels the request.
207
- *
208
- * Resolves — never rejects — with one of:
209
- * { ok: true, provider, endpoint, ids, others, count }
210
- * { ok: false, provider, supported, error }
211
- * `supported: false` means this module has no endpoint for that vendor, which
212
- * is a different thing from a vendor that refused the key.
213
- */
214
- async function discoverModels(provider, opts = {}) {
215
- const entry = endpointFor(provider);
216
- const asked = String(provider == null ? '' : provider).trim().toLowerCase();
217
- const key = String(opts.key == null ? '' : opts.key).trim();
218
- if (!entry) {
219
- return {
220
- ok: false,
221
- provider: asked,
222
- supported: false,
223
- error: `${asked || 'that provider'} has no model-list endpoint this client knows`,
224
- };
225
- }
226
- if (!key) {
227
- return { ok: false, provider: entry.id, supported: true, error: `no ${entry.id} key on this machine` };
228
- }
229
- const fetchImpl = opts.fetchImpl || (typeof fetch === 'function' ? fetch : null);
230
- if (!fetchImpl) {
231
- return { ok: false, provider: entry.id, supported: true, error: 'no fetch implementation available' };
232
- }
233
- const timeoutMs = Number.isFinite(opts.timeoutMs) ? opts.timeoutMs : DISCOVERY_TIMEOUT_MS;
234
- const controller = typeof AbortController === 'function' ? new AbortController() : null;
235
- const timer = controller ? setTimeout(() => controller.abort(), timeoutMs) : null;
236
- // Deliberately NOT unref'd: the timer is the thing that must fire when a
237
- // vendor goes quiet. An unref'd timer in a process whose only other pending
238
- // work is the await would be collected before it fired, and the hang this
239
- // timeout exists to prevent is exactly what that produces. It is cleared in
240
- // the `finally` below, so it never outlives the request either way.
241
- const onAbort = () => controller && controller.abort();
242
- if (controller && opts.signal) {
243
- if (opts.signal.aborted) onAbort();
244
- else if (typeof opts.signal.addEventListener === 'function') opts.signal.addEventListener('abort', onAbort, { once: true });
245
- }
246
- try {
247
- const url = new URL(entry.url);
248
- if (typeof entry.query === 'function') {
249
- for (const [k, v] of Object.entries(entry.query(key) || {})) url.searchParams.set(k, v);
250
- }
251
- const headers = { accept: 'application/json' };
252
- for (const [k, v] of Object.entries(entry.headers(key) || {})) {
253
- // Vendors that want the header spelled a particular way get it; the
254
- // table stores the canonical lowercase name.
255
- headers[k === 'authorization' ? 'Authorization' : k] = v;
256
- }
257
- const res = await fetchImpl(url.toString(), {
258
- method: 'GET',
259
- headers,
260
- signal: controller ? controller.signal : undefined,
261
- });
262
- const status = res && typeof res.status === 'number' ? res.status : 0;
263
- if (!res || (typeof res.ok === 'boolean' && !res.ok)) {
264
- // 401/403 is the common case and deserves its own sentence: the fix is
265
- // a different key, not a different provider.
266
- const why = status === 401 || status === 403
267
- ? `the vendor refused the key (HTTP ${status})`
268
- : status === 404
269
- ? `the vendor has no model list at ${url.pathname} (HTTP 404)`
270
- : `the vendor answered HTTP ${status || 'nothing'}`;
271
- return { ok: false, provider: entry.id, supported: true, status, error: why };
272
- }
273
- let payload;
274
- try {
275
- payload = await res.json();
276
- } catch (err) {
277
- return {
278
- ok: false,
279
- provider: entry.id,
280
- supported: true,
281
- status,
282
- error: `the vendor's reply was not JSON (${(err && err.message) || err})`,
283
- };
284
- }
285
- const parsed = idsFromPayload(payload);
286
- if (!parsed) {
287
- return {
288
- ok: false,
289
- provider: entry.id,
290
- supported: true,
291
- status,
292
- error: `the vendor answered in a shape this client does not know (no "data" or "models" list)`,
293
- };
294
- }
295
- return {
296
- ok: true,
297
- provider: entry.id,
298
- endpoint: entry.url,
299
- ids: parsed.ids,
300
- others: parsed.others,
301
- count: parsed.ids.length,
302
- };
303
- } catch (err) {
304
- const aborted = (err && (err.name === 'AbortError' || err.code === 'ABORT_ERR')) || (controller && controller.signal.aborted);
305
- return {
306
- ok: false,
307
- provider: entry.id,
308
- supported: true,
309
- error: aborted
310
- ? `the vendor did not answer within ${timeoutMs} ms`
311
- : `could not reach the vendor (${(err && err.message) || err})`,
312
- };
313
- } finally {
314
- if (timer) clearTimeout(timer);
315
- if (controller && opts.signal && typeof opts.signal.removeEventListener === 'function') {
316
- opts.signal.removeEventListener('abort', onAbort);
317
- }
318
- }
319
- }
320
-
321
- module.exports = {
322
- DISCOVERY_TIMEOUT_MS,
323
- ENDPOINTS,
324
- ALIASES,
325
- NON_CHAT_RE,
326
- endpointFor,
327
- canDiscover,
328
- discoverableProviders,
329
- looksNonChat,
330
- idsFromPayload,
331
- discoverModels,
332
- };
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};