aegisone 1.0.34 → 1.0.35

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 (226) hide show
  1. package/LICENSE +661 -0
  2. package/README.md +1 -1
  3. package/SOURCE-OFFER.txt +9 -0
  4. package/bin/aegis.js +1 -322
  5. package/package.json +4 -5
  6. package/scripts/bump.mjs +1 -211
  7. package/scripts/bundle.js +1 -129
  8. package/scripts/predist.mjs +1 -976
  9. package/src/child.js +1 -285
  10. package/src/dispatch.js +1 -269
  11. package/src/doctor.js +1 -639
  12. package/src/host.js +1 -111
  13. package/src/permissions.js +1 -383
  14. package/src/probes.js +1 -159
  15. package/src/release.js +1 -409
  16. package/vendor/cli/package.json +3 -7
  17. package/vendor/cli/scripts/check.mjs +1 -52
  18. package/vendor/cli/scripts/demo.mjs +1 -94
  19. package/vendor/cli/scripts/predist.mjs +1 -75
  20. package/vendor/cli/scripts/runtests.mjs +1 -56
  21. package/vendor/cli/scripts/seal-gate.mjs +1 -74
  22. package/vendor/cli/src/agents.js +1 -139
  23. package/vendor/cli/src/app.js +1 -2957
  24. package/vendor/cli/src/art.js +1 -289
  25. package/vendor/cli/src/chatflow.js +1 -3023
  26. package/vendor/cli/src/checkpoint.js +1 -90
  27. package/vendor/cli/src/clipboard.js +1 -424
  28. package/vendor/cli/src/cloudsync.js +1 -528
  29. package/vendor/cli/src/commands.js +1 -4089
  30. package/vendor/cli/src/config.js +1 -581
  31. package/vendor/cli/src/connect.js +1 -349
  32. package/vendor/cli/src/credentials.js +1 -33
  33. package/vendor/cli/src/deps.js +1 -232
  34. package/vendor/cli/src/devrun.js +1 -187
  35. package/vendor/cli/src/diff.js +1 -333
  36. package/vendor/cli/src/diffview.js +1 -296
  37. package/vendor/cli/src/engine.js +1 -297
  38. package/vendor/cli/src/entitlement.js +1 -355
  39. package/vendor/cli/src/events.js +1 -707
  40. package/vendor/cli/src/export.js +1 -67
  41. package/vendor/cli/src/filepreview.js +1 -153
  42. package/vendor/cli/src/fingerprint.js +1 -592
  43. package/vendor/cli/src/format.js +1 -259
  44. package/vendor/cli/src/fuzzy.js +1 -119
  45. package/vendor/cli/src/history.js +1 -423
  46. package/vendor/cli/src/init.js +1 -175
  47. package/vendor/cli/src/input.js +1 -139
  48. package/vendor/cli/src/keys.js +1 -183
  49. package/vendor/cli/src/markdown.js +1 -306
  50. package/vendor/cli/src/models.js +1 -507
  51. package/vendor/cli/src/naming.js +1 -57
  52. package/vendor/cli/src/overlays.js +1 -462
  53. package/vendor/cli/src/panels.js +1 -1418
  54. package/vendor/cli/src/ping.js +1 -226
  55. package/vendor/cli/src/presence.js +1 -238
  56. package/vendor/cli/src/render.js +1 -516
  57. package/vendor/cli/src/screen.js +1 -518
  58. package/vendor/cli/src/screens.js +1 -896
  59. package/vendor/cli/src/secret.js +1 -59
  60. package/vendor/cli/src/securefs.js +1 -359
  61. package/vendor/cli/src/settings.js +1 -155
  62. package/vendor/cli/src/shared.js +1 -52
  63. package/vendor/cli/src/sharedpaths.js +1 -53
  64. package/vendor/cli/src/signup.js +1 -156
  65. package/vendor/cli/src/summarize.js +1 -95
  66. package/vendor/cli/src/sysdiag.js +1 -585
  67. package/vendor/cli/src/system.js +1 -40
  68. package/vendor/cli/src/theme.js +1 -570
  69. package/vendor/cli/src/title.js +1 -220
  70. package/vendor/cli/src/todos.js +1 -115
  71. package/vendor/cli/src/tokens.js +1 -263
  72. package/vendor/cli/src/topup.js +1 -210
  73. package/vendor/cli/src/update.js +1 -191
  74. package/vendor/cli/vendor/client/aegis.js +1 -2441
  75. package/vendor/cli/vendor/client/attest.js +1 -518
  76. package/vendor/cli/vendor/client/authorship-key.js +1 -410
  77. package/vendor/cli/vendor/client/auto-provision.js +1 -134
  78. package/vendor/cli/vendor/client/brain-catalog.js +1 -268
  79. package/vendor/cli/vendor/client/byok-catalog.js +1 -199
  80. package/vendor/cli/vendor/client/catalog-client.js +1 -487
  81. package/vendor/cli/vendor/client/conversation-export.js +1 -177
  82. package/vendor/cli/vendor/client/credentials.js +1 -494
  83. package/vendor/cli/vendor/client/device-fingerprint.js +1 -141
  84. package/vendor/cli/vendor/client/drive-connect.js +1 -110
  85. package/vendor/cli/vendor/client/drive-upload.js +1 -234
  86. package/vendor/cli/vendor/client/env-file.js +1 -1273
  87. package/vendor/cli/vendor/client/fingerprint.js +1 -1064
  88. package/vendor/cli/vendor/client/foreign-memory.js +1 -669
  89. package/vendor/cli/vendor/client/google-signin.js +1 -133
  90. package/vendor/cli/vendor/client/hooks.js +1 -430
  91. package/vendor/cli/vendor/client/model-discovery.js +1 -373
  92. package/vendor/cli/vendor/client/naming.js +1 -283
  93. package/vendor/cli/vendor/client/platform.js +1 -937
  94. package/vendor/cli/vendor/client/prefs.js +1 -351
  95. package/vendor/cli/vendor/client/presence-constants.js +1 -107
  96. package/vendor/cli/vendor/client/presence.js +1 -438
  97. package/vendor/cli/vendor/client/record-vault.js +3 -1055
  98. package/vendor/cli/vendor/client/session-store.js +1 -575
  99. package/vendor/cli/vendor/client/topup.js +1 -297
  100. package/vendor/cli/vendor/client/touch.js +1 -458
  101. package/vendor/cli/vendor/client/update.js +1 -763
  102. package/vendor/cli/vendor/client/user-models.js +1 -381
  103. package/vendor/cli/vendor/desktop/lib/local/agents.js +1 -105
  104. package/vendor/cli/vendor/desktop/lib/local/attachments.js +1 -276
  105. package/vendor/cli/vendor/desktop/lib/local/autonomous.js +1 -1045
  106. package/vendor/cli/vendor/desktop/lib/local/claude-pro.js +1 -1028
  107. package/vendor/cli/vendor/desktop/lib/local/context.js +1 -125
  108. package/vendor/cli/vendor/desktop/lib/local/engine.js +1 -3666
  109. package/vendor/cli/vendor/desktop/lib/local/entitlement.js +1 -660
  110. package/vendor/cli/vendor/desktop/lib/local/git-scope.js +1 -228
  111. package/vendor/cli/vendor/desktop/lib/local/local.js +1 -2145
  112. package/vendor/cli/vendor/desktop/lib/local/prompt.js +1 -280
  113. package/vendor/cli/vendor/desktop/lib/local/queue.js +1 -560
  114. package/vendor/cli/vendor/desktop/lib/local/session-rounds.js +1 -238
  115. package/vendor/cli/vendor/desktop/lib/local/spill.js +1 -75
  116. package/vendor/cli/vendor/desktop/lib/local/turn-guard.js +1 -300
  117. package/vendor/cli/vendor/desktop/lib/local/worktree-lock.js +1 -235
  118. package/vendor/cli/vendor/desktop/lib/settings.js +1 -890
  119. package/vendor/cli/vendor/desktop/renderer/usage.js +1 -1239
  120. package/vendor/cli/vendor/hosts/install.js +1 -638
  121. package/vendor/cli/vendor/hosts/openai-shim.js +1 -515
  122. package/vendor/cli/vendor/hosts/spec.js +1 -164
  123. package/vendor/cli/vendor/hosts/targets.js +1 -346
  124. package/vendor/cli/vendor/mcp/server.js +1 -221
  125. package/vendor/cli/vendor/mcp/tools.js +1 -408
  126. package/vendor/cli/vendor/one/src/child.js +1 -285
  127. package/vendor/cli/vendor/one/src/permissions.js +1 -383
  128. package/vendor/desktop/bin/aegis.js +1 -32
  129. package/vendor/desktop/lib/account-key.js +1 -56
  130. package/vendor/desktop/lib/auto.js +1 -461
  131. package/vendor/desktop/lib/avatar/companion.js +1 -698
  132. package/vendor/desktop/lib/avatar/cosmetics.js +1 -532
  133. package/vendor/desktop/lib/avatar/events.js +1 -344
  134. package/vendor/desktop/lib/avatar/holder-turn.js +1 -350
  135. package/vendor/desktop/lib/avatar/holders.js +1 -612
  136. package/vendor/desktop/lib/avatar/identity.js +1 -641
  137. package/vendor/desktop/lib/avatar/level.js +1 -368
  138. package/vendor/desktop/lib/avatar/mirror.js +1 -524
  139. package/vendor/desktop/lib/avatar/persona.js +1 -388
  140. package/vendor/desktop/lib/avatar/profile.js +1 -977
  141. package/vendor/desktop/lib/avatar/register.js +1 -307
  142. package/vendor/desktop/lib/avatar/store.js +1 -472
  143. package/vendor/desktop/lib/avatar/tiers.js +1 -38
  144. package/vendor/desktop/lib/avatar/transfer.js +1 -415
  145. package/vendor/desktop/lib/avatar/turn.js +1 -216
  146. package/vendor/desktop/lib/avatar/voice.js +1 -328
  147. package/vendor/desktop/lib/avatar/xp.js +1 -404
  148. package/vendor/desktop/lib/deep-link.js +1 -120
  149. package/vendor/desktop/lib/fingerprint.js +2 -347
  150. package/vendor/desktop/lib/google-connect.js +1 -323
  151. package/vendor/desktop/lib/local/agents.js +1 -105
  152. package/vendor/desktop/lib/local/attachments.js +1 -276
  153. package/vendor/desktop/lib/local/autonomous.js +1 -1045
  154. package/vendor/desktop/lib/local/claude-pro.js +1 -1028
  155. package/vendor/desktop/lib/local/context.js +1 -125
  156. package/vendor/desktop/lib/local/engine.js +1 -3666
  157. package/vendor/desktop/lib/local/entitlement.js +1 -660
  158. package/vendor/desktop/lib/local/git-scope.js +1 -228
  159. package/vendor/desktop/lib/local/local.js +1 -2145
  160. package/vendor/desktop/lib/local/prompt.js +1 -280
  161. package/vendor/desktop/lib/local/queue.js +1 -560
  162. package/vendor/desktop/lib/local/session-rounds.js +1 -238
  163. package/vendor/desktop/lib/local/spill.js +1 -75
  164. package/vendor/desktop/lib/local/telemetry.js +1 -470
  165. package/vendor/desktop/lib/local/turn-guard.js +1 -300
  166. package/vendor/desktop/lib/local/worktree-lock.js +1 -235
  167. package/vendor/desktop/lib/provider-key-mirror.js +1 -252
  168. package/vendor/desktop/lib/quick-launcher.js +1 -84
  169. package/vendor/desktop/lib/settings.js +1 -890
  170. package/vendor/desktop/lib/sync/memory-queue.js +1 -60
  171. package/vendor/desktop/lib/sync/persist-gate.js +1 -148
  172. package/vendor/desktop/lib/sync/sessions.js +1 -106
  173. package/vendor/desktop/lib/window-state.js +1 -66
  174. package/vendor/desktop/package.json +2 -4
  175. package/vendor/desktop/preload.js +1 -679
  176. package/vendor/desktop/renderer/app.js +1 -7250
  177. package/vendor/desktop/renderer/avatar/assemble.js +1 -335
  178. package/vendor/desktop/renderer/avatar/avatar.js +1 -380
  179. package/vendor/desktop/renderer/avatar/cards.js +1 -141
  180. package/vendor/desktop/renderer/avatar/hud.js +1 -206
  181. package/vendor/desktop/renderer/avatar/machine.js +1 -213
  182. package/vendor/desktop/renderer/avatar/pane.js +1 -439
  183. package/vendor/desktop/renderer/avatar/parts.js +1 -437
  184. package/vendor/desktop/renderer/budget.js +1 -172
  185. package/vendor/desktop/renderer/companion.js +1 -223
  186. package/vendor/desktop/renderer/diff.js +1 -359
  187. package/vendor/desktop/renderer/diffview.js +1 -336
  188. package/vendor/desktop/renderer/filepreview.js +1 -211
  189. package/vendor/desktop/renderer/fingerprint.js +3 -789
  190. package/vendor/desktop/renderer/markdown.js +1 -168
  191. package/vendor/desktop/renderer/provider-mark.js +1 -311
  192. package/vendor/desktop/renderer/provider-toolbar.js +1 -134
  193. package/vendor/desktop/renderer/providers.js +1 -259
  194. package/vendor/desktop/renderer/quick.js +1 -285
  195. package/vendor/desktop/renderer/stream-policy.js +1 -387
  196. package/vendor/desktop/renderer/transcript-view.js +1 -323
  197. package/vendor/desktop/renderer/usage.js +1 -1239
  198. package/vendor/desktop/vendor/aegis.js +1 -2441
  199. package/vendor/desktop/vendor/attest.js +1 -518
  200. package/vendor/desktop/vendor/authorship-key.js +1 -410
  201. package/vendor/desktop/vendor/auto-provision.js +1 -134
  202. package/vendor/desktop/vendor/brain-catalog.js +1 -268
  203. package/vendor/desktop/vendor/byok-catalog.js +1 -199
  204. package/vendor/desktop/vendor/catalog-client.js +1 -487
  205. package/vendor/desktop/vendor/conversation-export.js +1 -177
  206. package/vendor/desktop/vendor/credentials.js +1 -494
  207. package/vendor/desktop/vendor/device-fingerprint.js +1 -141
  208. package/vendor/desktop/vendor/drive-connect.js +1 -110
  209. package/vendor/desktop/vendor/drive-upload.js +1 -234
  210. package/vendor/desktop/vendor/env-file.js +1 -1273
  211. package/vendor/desktop/vendor/fingerprint.js +1 -1064
  212. package/vendor/desktop/vendor/foreign-memory.js +1 -669
  213. package/vendor/desktop/vendor/google-signin.js +1 -133
  214. package/vendor/desktop/vendor/hooks.js +1 -430
  215. package/vendor/desktop/vendor/model-discovery.js +1 -373
  216. package/vendor/desktop/vendor/naming.js +1 -283
  217. package/vendor/desktop/vendor/platform.js +1 -937
  218. package/vendor/desktop/vendor/prefs.js +1 -351
  219. package/vendor/desktop/vendor/presence-constants.js +1 -107
  220. package/vendor/desktop/vendor/presence.js +1 -438
  221. package/vendor/desktop/vendor/record-vault.js +3 -1055
  222. package/vendor/desktop/vendor/session-store.js +1 -575
  223. package/vendor/desktop/vendor/topup.js +1 -297
  224. package/vendor/desktop/vendor/touch.js +1 -458
  225. package/vendor/desktop/vendor/update.js +1 -763
  226. package/vendor/desktop/vendor/user-models.js +1 -381
@@ -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 r=new URL(o.url);if("function"==typeof o.query)for(const[e,t]of Object.entries(o.query(n)||{}))r.searchParams.set(e,t);const t={accept:"application/json"};for(const[e,r]of Object.entries(o.headers(n)||{}))t["authorization"===e?"Authorization":e]=r;const s=await i(r.toString(),{method:"GET",headers:t,signal:a?a.signal:void 0}),d=s&&"number"==typeof s.status?s.status:0;if(!s||"boolean"==typeof s.ok&&!s.ok){const e=401===d||403===d?`the vendor refused the key (HTTP ${d})`:404===d?`the vendor has no model list at ${r.pathname} (HTTP 404)`:`the vendor answered HTTP ${d||"nothing"}`;return{ok:!1,provider:o.id,supported:!0,status:d,error:e}}let l;try{l=await s.json()}catch(e){return{ok:!1,provider:o.id,supported:!0,status:d,error:`the vendor's reply was not JSON (${e&&e.message||e})`}}const c=idsFromPayload(l);return c?{ok:!0,provider:o.id,endpoint:o.url,ids:c.ids,others:c.others,count:c.ids.length}:{ok:!1,provider:o.id,supported:!0,status:d,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};