codexmate 0.0.24 → 0.0.26

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 (136) hide show
  1. package/README.md +416 -391
  2. package/README.zh.md +349 -324
  3. package/cli/agents-files.js +224 -224
  4. package/cli/archive-helpers.js +446 -446
  5. package/cli/auth-profiles.js +375 -375
  6. package/cli/builtin-proxy.js +1079 -1044
  7. package/cli/claude-proxy.js +1022 -998
  8. package/cli/config-bootstrap.js +384 -384
  9. package/cli/config-health.js +338 -338
  10. package/cli/doctor-core.js +903 -903
  11. package/cli/import-skills-url.js +356 -334
  12. package/cli/openai-bridge.js +997 -950
  13. package/cli/openclaw-config.js +629 -629
  14. package/cli/session-convert-args.js +65 -0
  15. package/cli/session-convert-io.js +82 -0
  16. package/cli/session-convert.js +43 -0
  17. package/cli/session-usage.concurrent.js +28 -28
  18. package/cli/session-usage.js +118 -112
  19. package/cli/session-usage.models.js +176 -176
  20. package/cli/skills.js +1141 -1141
  21. package/cli/zip-commands.js +510 -510
  22. package/cli.js +15218 -13310
  23. package/lib/automation.js +404 -0
  24. package/lib/cli-file-utils.js +151 -151
  25. package/lib/cli-models-utils.js +379 -379
  26. package/lib/cli-network-utils.js +190 -190
  27. package/lib/cli-path-utils.js +85 -69
  28. package/lib/cli-session-utils.js +121 -121
  29. package/lib/cli-sessions.js +417 -386
  30. package/lib/cli-utils.js +155 -155
  31. package/lib/download-artifacts.js +92 -77
  32. package/lib/mcp-stdio.js +453 -440
  33. package/lib/task-orchestrator.js +869 -869
  34. package/lib/text-diff.js +303 -303
  35. package/lib/workflow-engine.js +340 -340
  36. package/package.json +74 -77
  37. package/plugins/README.md +20 -20
  38. package/plugins/README.zh-CN.md +20 -20
  39. package/plugins/prompt-templates/comment-polish/index.mjs +25 -25
  40. package/plugins/prompt-templates/computed.mjs +253 -253
  41. package/plugins/prompt-templates/index.mjs +8 -8
  42. package/plugins/prompt-templates/manifest.mjs +15 -15
  43. package/plugins/prompt-templates/methods.mjs +619 -619
  44. package/plugins/prompt-templates/overview.mjs +90 -90
  45. package/plugins/prompt-templates/ownership.mjs +19 -19
  46. package/plugins/prompt-templates/rule-ack/index.mjs +21 -21
  47. package/plugins/prompt-templates/storage.mjs +64 -64
  48. package/plugins/registry.mjs +16 -16
  49. package/web-ui/app.js +625 -609
  50. package/web-ui/index.html +35 -35
  51. package/web-ui/logic.agents-diff.mjs +386 -386
  52. package/web-ui/logic.claude.mjs +168 -168
  53. package/web-ui/logic.mjs +5 -5
  54. package/web-ui/logic.runtime.mjs +128 -128
  55. package/web-ui/logic.session-convert.mjs +70 -0
  56. package/web-ui/logic.sessions.mjs +709 -614
  57. package/web-ui/modules/api.mjs +90 -90
  58. package/web-ui/modules/app.computed.dashboard.mjs +171 -126
  59. package/web-ui/modules/app.computed.index.mjs +17 -17
  60. package/web-ui/modules/app.computed.main-tabs.mjs +205 -205
  61. package/web-ui/modules/app.computed.session.mjs +946 -653
  62. package/web-ui/modules/app.constants.mjs +15 -15
  63. package/web-ui/modules/app.methods.agents.mjs +632 -632
  64. package/web-ui/modules/app.methods.claude-config.mjs +179 -174
  65. package/web-ui/modules/app.methods.codex-config.mjs +860 -784
  66. package/web-ui/modules/app.methods.index.mjs +92 -92
  67. package/web-ui/modules/app.methods.install.mjs +205 -177
  68. package/web-ui/modules/app.methods.navigation.mjs +743 -695
  69. package/web-ui/modules/app.methods.openclaw-core.mjs +814 -814
  70. package/web-ui/modules/app.methods.openclaw-editing.mjs +372 -372
  71. package/web-ui/modules/app.methods.openclaw-persist.mjs +369 -369
  72. package/web-ui/modules/app.methods.providers.mjs +404 -404
  73. package/web-ui/modules/app.methods.runtime.mjs +345 -345
  74. package/web-ui/modules/app.methods.session-actions.mjs +596 -537
  75. package/web-ui/modules/app.methods.session-browser.mjs +985 -698
  76. package/web-ui/modules/app.methods.session-timeline.mjs +479 -448
  77. package/web-ui/modules/app.methods.session-trash.mjs +424 -422
  78. package/web-ui/modules/app.methods.startup-claude.mjs +522 -417
  79. package/web-ui/modules/app.methods.task-orchestration.mjs +556 -556
  80. package/web-ui/modules/config-mode.computed.mjs +124 -124
  81. package/web-ui/modules/config-template-confirm-pref.mjs +33 -33
  82. package/web-ui/modules/i18n.dict.mjs +2113 -2039
  83. package/web-ui/modules/i18n.mjs +56 -56
  84. package/web-ui/modules/plugins.computed.mjs +3 -3
  85. package/web-ui/modules/plugins.methods.mjs +3 -3
  86. package/web-ui/modules/plugins.storage.mjs +11 -11
  87. package/web-ui/modules/sessions-filters-url.mjs +85 -85
  88. package/web-ui/modules/skills.computed.mjs +107 -107
  89. package/web-ui/modules/skills.methods.mjs +481 -481
  90. package/web-ui/partials/index/layout-footer.html +13 -13
  91. package/web-ui/partials/index/layout-header.html +475 -465
  92. package/web-ui/partials/index/modal-config-template-agents.html +174 -174
  93. package/web-ui/partials/index/modal-confirm-toast.html +32 -32
  94. package/web-ui/partials/index/modal-health-check.html +45 -45
  95. package/web-ui/partials/index/modal-openclaw-config.html +280 -280
  96. package/web-ui/partials/index/modal-skills.html +200 -200
  97. package/web-ui/partials/index/modals-basic.html +165 -165
  98. package/web-ui/partials/index/panel-config-claude.html +184 -179
  99. package/web-ui/partials/index/panel-config-codex.html +283 -283
  100. package/web-ui/partials/index/panel-config-openclaw.html +83 -83
  101. package/web-ui/partials/index/panel-dashboard.html +186 -186
  102. package/web-ui/partials/index/panel-docs.html +147 -147
  103. package/web-ui/partials/index/panel-market.html +177 -177
  104. package/web-ui/partials/index/panel-orchestration.html +391 -391
  105. package/web-ui/partials/index/panel-plugins.html +279 -279
  106. package/web-ui/partials/index/panel-sessions.html +326 -301
  107. package/web-ui/partials/index/panel-settings.html +258 -258
  108. package/web-ui/partials/index/panel-usage.html +342 -354
  109. package/{res → web-ui/res}/json5.min.js +1 -1
  110. package/{res → web-ui/res}/vue.global.prod.js +13 -13
  111. package/web-ui/session-helpers.mjs +576 -573
  112. package/web-ui/source-bundle.cjs +233 -233
  113. package/web-ui/styles/base-theme.css +268 -264
  114. package/web-ui/styles/controls-forms.css +423 -376
  115. package/web-ui/styles/dashboard.css +274 -274
  116. package/web-ui/styles/docs-panel.css +247 -247
  117. package/web-ui/styles/feedback.css +108 -108
  118. package/web-ui/styles/health-check-dialog.css +144 -144
  119. package/web-ui/styles/layout-shell.css +603 -602
  120. package/web-ui/styles/modals-core.css +464 -464
  121. package/web-ui/styles/navigation-panels.css +390 -390
  122. package/web-ui/styles/openclaw-structured.css +266 -266
  123. package/web-ui/styles/plugins-panel.css +523 -523
  124. package/web-ui/styles/responsive.css +454 -456
  125. package/web-ui/styles/sessions-list.css +415 -400
  126. package/web-ui/styles/sessions-preview.css +411 -411
  127. package/web-ui/styles/sessions-toolbar-trash.css +330 -268
  128. package/web-ui/styles/sessions-usage.css +945 -888
  129. package/web-ui/styles/settings-panel.css +166 -166
  130. package/web-ui/styles/skills-list.css +303 -303
  131. package/web-ui/styles/skills-market.css +406 -406
  132. package/web-ui/styles/task-orchestration.css +822 -822
  133. package/web-ui/styles/titles-cards.css +408 -408
  134. package/web-ui/styles.css +21 -21
  135. package/web-ui.html +17 -17
  136. /package/{res → web-ui/res}/logo-pack.webp +0 -0
@@ -1,379 +1,379 @@
1
- const crypto = require('crypto');
2
- const { joinApiUrl, normalizeBaseUrl } = require('./cli-utils');
3
-
4
- const BIGMODEL_CLAUDE_COMPAT_MODELS = Object.freeze([
5
- 'glm-3-turbo',
6
- 'glm-4',
7
- 'glm-4-0520',
8
- 'glm-4-plus',
9
- 'glm-4-air',
10
- 'glm-4-airx',
11
- 'glm-4-flash',
12
- 'glm-4-flashx',
13
- 'glm-4v',
14
- 'glm-4v-flash',
15
- 'glm-4v-plus',
16
- 'glm-4v-plus-0111',
17
- 'glm-4.5',
18
- 'glm-4.5-air',
19
- 'glm-4.5v',
20
- 'glm-4.6',
21
- 'glm-4.6v',
22
- 'glm-4.7',
23
- 'glm-4.7-flash',
24
- 'glm-4.7-flashx',
25
- 'glm-5',
26
- 'glm-5-turbo',
27
- 'glm-5.1',
28
- 'glm-5v',
29
- 'glm-5v-turbo',
30
- 'glm-z1',
31
- 'glm-z1-air',
32
- 'glm-coding'
33
- ]);
34
-
35
- const ANTHROPIC_CLAUDE_MODELS = Object.freeze([
36
- 'claude-opus-4-6',
37
- 'claude-opus-4-1',
38
- 'claude-opus-4',
39
- 'claude-sonnet-4-6',
40
- 'claude-sonnet-4-5',
41
- 'claude-sonnet-4',
42
- 'claude-haiku-4-5',
43
- 'claude-3-7-sonnet',
44
- 'claude-3-5-sonnet',
45
- 'claude-3-5-haiku',
46
- 'claude-3-opus',
47
- 'claude-3-sonnet',
48
- 'claude-3-haiku'
49
- ]);
50
-
51
- function normalizeModelCatalogId(value) {
52
- return typeof value === 'string' ? value.trim().toLowerCase() : '';
53
- }
54
-
55
- function isBigModelClaudeCompatibleBaseUrl(baseUrl) {
56
- const normalized = normalizeBaseUrl(baseUrl);
57
- if (!normalized) return false;
58
- try {
59
- const parsed = new URL(normalized);
60
- const host = String(parsed.hostname || '').toLowerCase();
61
- const pathname = String(parsed.pathname || '').toLowerCase();
62
- const isBigModelHost = host === 'bigmodel.cn' || host.endsWith('.bigmodel.cn');
63
- const hasAnthropicSegment = /(^|\/)anthropic(\/|$)/.test(pathname);
64
- return isBigModelHost && hasAnthropicSegment;
65
- } catch (_) {
66
- return false;
67
- }
68
- }
69
-
70
- function isAnthropicBaseUrl(baseUrl) {
71
- const normalized = normalizeBaseUrl(baseUrl);
72
- if (!normalized) return false;
73
- try {
74
- const parsed = new URL(normalized);
75
- const host = String(parsed.hostname || '').toLowerCase();
76
- return host === 'api.anthropic.com' || host.endsWith('.anthropic.com');
77
- } catch (_) {
78
- return false;
79
- }
80
- }
81
-
82
- function getSupplementalModelsForBaseUrl(baseUrl) {
83
- if (isBigModelClaudeCompatibleBaseUrl(baseUrl)) {
84
- return [...BIGMODEL_CLAUDE_COMPAT_MODELS];
85
- }
86
- if (isAnthropicBaseUrl(baseUrl)) {
87
- return [...ANTHROPIC_CLAUDE_MODELS];
88
- }
89
- return [];
90
- }
91
-
92
- function mergeModelCatalog(remoteModels = [], supplementalModels = []) {
93
- const merged = [];
94
- const seen = new Set();
95
- const push = (value) => {
96
- if (typeof value !== 'string') return;
97
- const trimmed = value.trim();
98
- if (!trimmed) return;
99
- const normalized = normalizeModelCatalogId(trimmed);
100
- if (!normalized || seen.has(normalized)) return;
101
- seen.add(normalized);
102
- merged.push(trimmed);
103
- };
104
-
105
- for (const item of remoteModels) push(item);
106
- for (const item of supplementalModels) push(item);
107
- return merged;
108
- }
109
-
110
- function extractModelNames(payload) {
111
- if (!payload || typeof payload !== 'object') return [];
112
- const data = Array.isArray(payload.data)
113
- ? payload.data
114
- : (Array.isArray(payload.models) ? payload.models : []);
115
- const names = [];
116
- for (const item of data) {
117
- if (typeof item === 'string') {
118
- if (item.trim()) names.push(item.trim());
119
- continue;
120
- }
121
- if (!item || typeof item !== 'object') continue;
122
- const name = item.id || item.name || item.model || '';
123
- if (typeof name === 'string' && name.trim()) {
124
- names.push(name.trim());
125
- }
126
- }
127
- return Array.from(new Set(names));
128
- }
129
-
130
- function hasModelsListPayload(payload) {
131
- if (!payload || typeof payload !== 'object') return false;
132
- return Array.isArray(payload.data) || Array.isArray(payload.models);
133
- }
134
-
135
- function extractModelIds(payload) {
136
- const ids = [];
137
- const pushValue = (value) => {
138
- if (typeof value === 'string' && value.trim()) {
139
- ids.push(value.trim());
140
- }
141
- };
142
-
143
- if (!payload) return ids;
144
-
145
- if (Array.isArray(payload)) {
146
- for (const item of payload) {
147
- if (item && typeof item === 'object') {
148
- pushValue(item.id);
149
- pushValue(item.model);
150
- pushValue(item.name);
151
- } else {
152
- pushValue(item);
153
- }
154
- }
155
- return ids;
156
- }
157
-
158
- if (Array.isArray(payload.data)) {
159
- for (const item of payload.data) {
160
- if (item && typeof item === 'object') {
161
- pushValue(item.id);
162
- pushValue(item.model);
163
- pushValue(item.name);
164
- } else {
165
- pushValue(item);
166
- }
167
- }
168
- }
169
-
170
- if (Array.isArray(payload.models)) {
171
- for (const item of payload.models) {
172
- if (item && typeof item === 'object') {
173
- pushValue(item.id);
174
- pushValue(item.model);
175
- pushValue(item.name);
176
- } else {
177
- pushValue(item);
178
- }
179
- }
180
- }
181
-
182
- return ids;
183
- }
184
-
185
- function normalizeWireApi(value) {
186
- const raw = typeof value === 'string' ? value.trim().toLowerCase() : '';
187
- if (!raw) return 'responses';
188
- return raw.replace(/[\s\-\/]/g, '_');
189
- }
190
-
191
- function buildApiProbeUrlCandidates(baseUrl, pathSuffix) {
192
- const normalized = normalizeBaseUrl(baseUrl);
193
- if (!normalized) return [];
194
-
195
- const safeSuffix = String(pathSuffix || '').replace(/^\/+/g, '');
196
- if (!safeSuffix) return [normalized];
197
-
198
- const candidates = [];
199
- const pushUnique = (value) => {
200
- if (value && !candidates.includes(value)) {
201
- candidates.push(value);
202
- }
203
- };
204
-
205
- let pathname = '';
206
- try {
207
- pathname = new URL(normalized).pathname.replace(/\/+$/g, '');
208
- } catch (e) {
209
- pathname = '';
210
- }
211
-
212
- const directUrl = `${normalized}/${safeSuffix}`;
213
- const versionedUrl = joinApiUrl(normalized, safeSuffix);
214
- if (/\/v\d+$/i.test(pathname)) {
215
- pushUnique(directUrl);
216
- return candidates;
217
- }
218
-
219
- if (!pathname || pathname === '/') {
220
- pushUnique(versionedUrl);
221
- pushUnique(directUrl);
222
- return candidates;
223
- }
224
-
225
- pushUnique(directUrl);
226
- pushUnique(versionedUrl);
227
- return candidates;
228
- }
229
-
230
- function buildModelsProbeUrl(baseUrl) {
231
- return buildApiProbeUrlCandidates(baseUrl, 'models')[0] || '';
232
- }
233
-
234
- function buildModelProbeSpecs(provider, modelName, baseUrl) {
235
- const model = typeof modelName === 'string' ? modelName.trim() : '';
236
- if (!model) return [];
237
-
238
- const wireApi = normalizeWireApi(provider && provider.wire_api);
239
- let pathSuffix = 'responses';
240
- let body = {
241
- model,
242
- input: 'ping',
243
- max_output_tokens: 1
244
- };
245
-
246
- if (wireApi === 'chat_completions' || wireApi === 'chat') {
247
- pathSuffix = 'chat/completions';
248
- body = {
249
- model,
250
- messages: [{ role: 'user', content: 'ping' }],
251
- max_tokens: 1,
252
- temperature: 0
253
- };
254
- } else if (wireApi === 'completions') {
255
- pathSuffix = 'completions';
256
- body = {
257
- model,
258
- prompt: 'ping',
259
- max_tokens: 1,
260
- temperature: 0
261
- };
262
- }
263
-
264
- return buildApiProbeUrlCandidates(baseUrl, pathSuffix).map((url) => ({
265
- url,
266
- body
267
- }));
268
- }
269
-
270
- function buildModelProbeSpec(provider, modelName, baseUrl) {
271
- return buildModelProbeSpecs(provider, modelName, baseUrl)[0] || null;
272
- }
273
-
274
- function collectStructuredText(content, pieces) {
275
- if (typeof content === 'string') {
276
- const text = content.trim();
277
- if (text) pieces.push(text);
278
- return;
279
- }
280
- if (Array.isArray(content)) {
281
- for (const item of content) {
282
- collectStructuredText(item, pieces);
283
- }
284
- return;
285
- }
286
- if (!content || typeof content !== 'object') {
287
- return;
288
- }
289
-
290
- if (typeof content.output_text === 'string' && content.output_text.trim()) {
291
- pieces.push(content.output_text.trim());
292
- }
293
- if (typeof content.text === 'string' && content.text.trim()) {
294
- pieces.push(content.text.trim());
295
- }
296
- if (typeof content.content === 'string' && content.content.trim()) {
297
- pieces.push(content.content.trim());
298
- }
299
-
300
- if (Array.isArray(content.content)) {
301
- collectStructuredText(content.content, pieces);
302
- }
303
- if (content.message) {
304
- collectStructuredText(content.message, pieces);
305
- }
306
- }
307
-
308
- function extractModelResponseText(payload) {
309
- if (!payload || typeof payload !== 'object') {
310
- return '';
311
- }
312
-
313
- if (typeof payload.output_text === 'string' && payload.output_text.trim()) {
314
- return payload.output_text.trim();
315
- }
316
-
317
- const pieces = [];
318
-
319
- if (Array.isArray(payload.output)) {
320
- for (const item of payload.output) {
321
- collectStructuredText(item, pieces);
322
- }
323
- }
324
-
325
- if (Array.isArray(payload.choices)) {
326
- for (const choice of payload.choices) {
327
- if (!choice || typeof choice !== 'object') continue;
328
- if (typeof choice.text === 'string' && choice.text.trim()) {
329
- pieces.push(choice.text.trim());
330
- }
331
- if (choice.message) {
332
- collectStructuredText(choice.message, pieces);
333
- }
334
- }
335
- }
336
-
337
- if (payload.message) {
338
- collectStructuredText(payload.message, pieces);
339
- }
340
- if (payload.content) {
341
- collectStructuredText(payload.content, pieces);
342
- }
343
- if (typeof payload.text === 'string' && payload.text.trim()) {
344
- pieces.push(payload.text.trim());
345
- }
346
-
347
- return Array.from(new Set(pieces)).join('\n\n').trim();
348
- }
349
-
350
- function hashModelsCacheValue(value) {
351
- if (!value) return '';
352
- try {
353
- return crypto.createHash('sha256').update(String(value)).digest('hex');
354
- } catch (e) {
355
- return '';
356
- }
357
- }
358
-
359
- function buildModelsCacheKey(baseUrl, apiKey) {
360
- const normalizedUrl = normalizeBaseUrl(baseUrl);
361
- const apiKeyHash = hashModelsCacheValue(apiKey);
362
- return `${normalizedUrl}|${apiKeyHash}`;
363
- }
364
-
365
- module.exports = {
366
- extractModelNames,
367
- hasModelsListPayload,
368
- extractModelIds,
369
- normalizeWireApi,
370
- buildApiProbeUrlCandidates,
371
- buildModelsProbeUrl,
372
- buildModelProbeSpecs,
373
- buildModelProbeSpec,
374
- extractModelResponseText,
375
- hashModelsCacheValue,
376
- buildModelsCacheKey,
377
- getSupplementalModelsForBaseUrl,
378
- mergeModelCatalog
379
- };
1
+ const crypto = require('crypto');
2
+ const { joinApiUrl, normalizeBaseUrl } = require('./cli-utils');
3
+
4
+ const BIGMODEL_CLAUDE_COMPAT_MODELS = Object.freeze([
5
+ 'glm-3-turbo',
6
+ 'glm-4',
7
+ 'glm-4-0520',
8
+ 'glm-4-plus',
9
+ 'glm-4-air',
10
+ 'glm-4-airx',
11
+ 'glm-4-flash',
12
+ 'glm-4-flashx',
13
+ 'glm-4v',
14
+ 'glm-4v-flash',
15
+ 'glm-4v-plus',
16
+ 'glm-4v-plus-0111',
17
+ 'glm-4.5',
18
+ 'glm-4.5-air',
19
+ 'glm-4.5v',
20
+ 'glm-4.6',
21
+ 'glm-4.6v',
22
+ 'glm-4.7',
23
+ 'glm-4.7-flash',
24
+ 'glm-4.7-flashx',
25
+ 'glm-5',
26
+ 'glm-5-turbo',
27
+ 'glm-5.1',
28
+ 'glm-5v',
29
+ 'glm-5v-turbo',
30
+ 'glm-z1',
31
+ 'glm-z1-air',
32
+ 'glm-coding'
33
+ ]);
34
+
35
+ const ANTHROPIC_CLAUDE_MODELS = Object.freeze([
36
+ 'claude-opus-4-6',
37
+ 'claude-opus-4-1',
38
+ 'claude-opus-4',
39
+ 'claude-sonnet-4-6',
40
+ 'claude-sonnet-4-5',
41
+ 'claude-sonnet-4',
42
+ 'claude-haiku-4-5',
43
+ 'claude-3-7-sonnet',
44
+ 'claude-3-5-sonnet',
45
+ 'claude-3-5-haiku',
46
+ 'claude-3-opus',
47
+ 'claude-3-sonnet',
48
+ 'claude-3-haiku'
49
+ ]);
50
+
51
+ function normalizeModelCatalogId(value) {
52
+ return typeof value === 'string' ? value.trim().toLowerCase() : '';
53
+ }
54
+
55
+ function isBigModelClaudeCompatibleBaseUrl(baseUrl) {
56
+ const normalized = normalizeBaseUrl(baseUrl);
57
+ if (!normalized) return false;
58
+ try {
59
+ const parsed = new URL(normalized);
60
+ const host = String(parsed.hostname || '').toLowerCase();
61
+ const pathname = String(parsed.pathname || '').toLowerCase();
62
+ const isBigModelHost = host === 'bigmodel.cn' || host.endsWith('.bigmodel.cn');
63
+ const hasAnthropicSegment = /(^|\/)anthropic(\/|$)/.test(pathname);
64
+ return isBigModelHost && hasAnthropicSegment;
65
+ } catch (_) {
66
+ return false;
67
+ }
68
+ }
69
+
70
+ function isAnthropicBaseUrl(baseUrl) {
71
+ const normalized = normalizeBaseUrl(baseUrl);
72
+ if (!normalized) return false;
73
+ try {
74
+ const parsed = new URL(normalized);
75
+ const host = String(parsed.hostname || '').toLowerCase();
76
+ return host === 'api.anthropic.com' || host.endsWith('.anthropic.com');
77
+ } catch (_) {
78
+ return false;
79
+ }
80
+ }
81
+
82
+ function getSupplementalModelsForBaseUrl(baseUrl) {
83
+ if (isBigModelClaudeCompatibleBaseUrl(baseUrl)) {
84
+ return [...BIGMODEL_CLAUDE_COMPAT_MODELS];
85
+ }
86
+ if (isAnthropicBaseUrl(baseUrl)) {
87
+ return [...ANTHROPIC_CLAUDE_MODELS];
88
+ }
89
+ return [];
90
+ }
91
+
92
+ function mergeModelCatalog(remoteModels = [], supplementalModels = []) {
93
+ const merged = [];
94
+ const seen = new Set();
95
+ const push = (value) => {
96
+ if (typeof value !== 'string') return;
97
+ const trimmed = value.trim();
98
+ if (!trimmed) return;
99
+ const normalized = normalizeModelCatalogId(trimmed);
100
+ if (!normalized || seen.has(normalized)) return;
101
+ seen.add(normalized);
102
+ merged.push(trimmed);
103
+ };
104
+
105
+ for (const item of remoteModels) push(item);
106
+ for (const item of supplementalModels) push(item);
107
+ return merged;
108
+ }
109
+
110
+ function extractModelNames(payload) {
111
+ if (!payload || typeof payload !== 'object') return [];
112
+ const data = Array.isArray(payload.data)
113
+ ? payload.data
114
+ : (Array.isArray(payload.models) ? payload.models : []);
115
+ const names = [];
116
+ for (const item of data) {
117
+ if (typeof item === 'string') {
118
+ if (item.trim()) names.push(item.trim());
119
+ continue;
120
+ }
121
+ if (!item || typeof item !== 'object') continue;
122
+ const name = item.id || item.name || item.model || '';
123
+ if (typeof name === 'string' && name.trim()) {
124
+ names.push(name.trim());
125
+ }
126
+ }
127
+ return Array.from(new Set(names));
128
+ }
129
+
130
+ function hasModelsListPayload(payload) {
131
+ if (!payload || typeof payload !== 'object') return false;
132
+ return Array.isArray(payload.data) || Array.isArray(payload.models);
133
+ }
134
+
135
+ function extractModelIds(payload) {
136
+ const ids = [];
137
+ const pushValue = (value) => {
138
+ if (typeof value === 'string' && value.trim()) {
139
+ ids.push(value.trim());
140
+ }
141
+ };
142
+
143
+ if (!payload) return ids;
144
+
145
+ if (Array.isArray(payload)) {
146
+ for (const item of payload) {
147
+ if (item && typeof item === 'object') {
148
+ pushValue(item.id);
149
+ pushValue(item.model);
150
+ pushValue(item.name);
151
+ } else {
152
+ pushValue(item);
153
+ }
154
+ }
155
+ return ids;
156
+ }
157
+
158
+ if (Array.isArray(payload.data)) {
159
+ for (const item of payload.data) {
160
+ if (item && typeof item === 'object') {
161
+ pushValue(item.id);
162
+ pushValue(item.model);
163
+ pushValue(item.name);
164
+ } else {
165
+ pushValue(item);
166
+ }
167
+ }
168
+ }
169
+
170
+ if (Array.isArray(payload.models)) {
171
+ for (const item of payload.models) {
172
+ if (item && typeof item === 'object') {
173
+ pushValue(item.id);
174
+ pushValue(item.model);
175
+ pushValue(item.name);
176
+ } else {
177
+ pushValue(item);
178
+ }
179
+ }
180
+ }
181
+
182
+ return ids;
183
+ }
184
+
185
+ function normalizeWireApi(value) {
186
+ const raw = typeof value === 'string' ? value.trim().toLowerCase() : '';
187
+ if (!raw) return 'responses';
188
+ return raw.replace(/[\s\-\/]/g, '_');
189
+ }
190
+
191
+ function buildApiProbeUrlCandidates(baseUrl, pathSuffix) {
192
+ const normalized = normalizeBaseUrl(baseUrl);
193
+ if (!normalized) return [];
194
+
195
+ const safeSuffix = String(pathSuffix || '').replace(/^\/+/g, '');
196
+ if (!safeSuffix) return [normalized];
197
+
198
+ const candidates = [];
199
+ const pushUnique = (value) => {
200
+ if (value && !candidates.includes(value)) {
201
+ candidates.push(value);
202
+ }
203
+ };
204
+
205
+ let pathname = '';
206
+ try {
207
+ pathname = new URL(normalized).pathname.replace(/\/+$/g, '');
208
+ } catch (e) {
209
+ pathname = '';
210
+ }
211
+
212
+ const directUrl = `${normalized}/${safeSuffix}`;
213
+ const versionedUrl = joinApiUrl(normalized, safeSuffix);
214
+ if (/\/v\d+$/i.test(pathname)) {
215
+ pushUnique(directUrl);
216
+ return candidates;
217
+ }
218
+
219
+ if (!pathname || pathname === '/') {
220
+ pushUnique(versionedUrl);
221
+ pushUnique(directUrl);
222
+ return candidates;
223
+ }
224
+
225
+ pushUnique(directUrl);
226
+ pushUnique(versionedUrl);
227
+ return candidates;
228
+ }
229
+
230
+ function buildModelsProbeUrl(baseUrl) {
231
+ return buildApiProbeUrlCandidates(baseUrl, 'models')[0] || '';
232
+ }
233
+
234
+ function buildModelProbeSpecs(provider, modelName, baseUrl) {
235
+ const model = typeof modelName === 'string' ? modelName.trim() : '';
236
+ if (!model) return [];
237
+
238
+ const wireApi = normalizeWireApi(provider && provider.wire_api);
239
+ let pathSuffix = 'responses';
240
+ let body = {
241
+ model,
242
+ input: 'ping',
243
+ max_output_tokens: 1
244
+ };
245
+
246
+ if (wireApi === 'chat_completions' || wireApi === 'chat') {
247
+ pathSuffix = 'chat/completions';
248
+ body = {
249
+ model,
250
+ messages: [{ role: 'user', content: 'ping' }],
251
+ max_tokens: 1,
252
+ temperature: 0
253
+ };
254
+ } else if (wireApi === 'completions') {
255
+ pathSuffix = 'completions';
256
+ body = {
257
+ model,
258
+ prompt: 'ping',
259
+ max_tokens: 1,
260
+ temperature: 0
261
+ };
262
+ }
263
+
264
+ return buildApiProbeUrlCandidates(baseUrl, pathSuffix).map((url) => ({
265
+ url,
266
+ body
267
+ }));
268
+ }
269
+
270
+ function buildModelProbeSpec(provider, modelName, baseUrl) {
271
+ return buildModelProbeSpecs(provider, modelName, baseUrl)[0] || null;
272
+ }
273
+
274
+ function collectStructuredText(content, pieces) {
275
+ if (typeof content === 'string') {
276
+ const text = content.trim();
277
+ if (text) pieces.push(text);
278
+ return;
279
+ }
280
+ if (Array.isArray(content)) {
281
+ for (const item of content) {
282
+ collectStructuredText(item, pieces);
283
+ }
284
+ return;
285
+ }
286
+ if (!content || typeof content !== 'object') {
287
+ return;
288
+ }
289
+
290
+ if (typeof content.output_text === 'string' && content.output_text.trim()) {
291
+ pieces.push(content.output_text.trim());
292
+ }
293
+ if (typeof content.text === 'string' && content.text.trim()) {
294
+ pieces.push(content.text.trim());
295
+ }
296
+ if (typeof content.content === 'string' && content.content.trim()) {
297
+ pieces.push(content.content.trim());
298
+ }
299
+
300
+ if (Array.isArray(content.content)) {
301
+ collectStructuredText(content.content, pieces);
302
+ }
303
+ if (content.message) {
304
+ collectStructuredText(content.message, pieces);
305
+ }
306
+ }
307
+
308
+ function extractModelResponseText(payload) {
309
+ if (!payload || typeof payload !== 'object') {
310
+ return '';
311
+ }
312
+
313
+ if (typeof payload.output_text === 'string' && payload.output_text.trim()) {
314
+ return payload.output_text.trim();
315
+ }
316
+
317
+ const pieces = [];
318
+
319
+ if (Array.isArray(payload.output)) {
320
+ for (const item of payload.output) {
321
+ collectStructuredText(item, pieces);
322
+ }
323
+ }
324
+
325
+ if (Array.isArray(payload.choices)) {
326
+ for (const choice of payload.choices) {
327
+ if (!choice || typeof choice !== 'object') continue;
328
+ if (typeof choice.text === 'string' && choice.text.trim()) {
329
+ pieces.push(choice.text.trim());
330
+ }
331
+ if (choice.message) {
332
+ collectStructuredText(choice.message, pieces);
333
+ }
334
+ }
335
+ }
336
+
337
+ if (payload.message) {
338
+ collectStructuredText(payload.message, pieces);
339
+ }
340
+ if (payload.content) {
341
+ collectStructuredText(payload.content, pieces);
342
+ }
343
+ if (typeof payload.text === 'string' && payload.text.trim()) {
344
+ pieces.push(payload.text.trim());
345
+ }
346
+
347
+ return Array.from(new Set(pieces)).join('\n\n').trim();
348
+ }
349
+
350
+ function hashModelsCacheValue(value) {
351
+ if (!value) return '';
352
+ try {
353
+ return crypto.createHash('sha256').update(String(value)).digest('hex');
354
+ } catch (e) {
355
+ return '';
356
+ }
357
+ }
358
+
359
+ function buildModelsCacheKey(baseUrl, apiKey) {
360
+ const normalizedUrl = normalizeBaseUrl(baseUrl);
361
+ const apiKeyHash = hashModelsCacheValue(apiKey);
362
+ return `${normalizedUrl}|${apiKeyHash}`;
363
+ }
364
+
365
+ module.exports = {
366
+ extractModelNames,
367
+ hasModelsListPayload,
368
+ extractModelIds,
369
+ normalizeWireApi,
370
+ buildApiProbeUrlCandidates,
371
+ buildModelsProbeUrl,
372
+ buildModelProbeSpecs,
373
+ buildModelProbeSpec,
374
+ extractModelResponseText,
375
+ hashModelsCacheValue,
376
+ buildModelsCacheKey,
377
+ getSupplementalModelsForBaseUrl,
378
+ mergeModelCatalog
379
+ };