codexmate 0.0.20 → 0.0.21

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 (102) hide show
  1. package/README.en.md +349 -259
  2. package/README.md +284 -252
  3. package/cli/agents-files.js +162 -0
  4. package/cli/archive-helpers.js +446 -0
  5. package/cli/auth-profiles.js +359 -0
  6. package/cli/builtin-proxy.js +580 -0
  7. package/cli/claude-proxy.js +998 -0
  8. package/cli/config-bootstrap.js +384 -0
  9. package/cli/config-health.js +338 -338
  10. package/cli/openclaw-config.js +629 -0
  11. package/cli/skills.js +1141 -0
  12. package/cli/zip-commands.js +510 -0
  13. package/cli.js +13101 -13497
  14. package/lib/cli-file-utils.js +151 -151
  15. package/lib/cli-models-utils.js +419 -311
  16. package/lib/cli-network-utils.js +164 -164
  17. package/lib/cli-path-utils.js +69 -0
  18. package/lib/cli-session-utils.js +121 -121
  19. package/lib/cli-sessions.js +386 -0
  20. package/lib/cli-utils.js +155 -155
  21. package/lib/download-artifacts.js +77 -0
  22. package/lib/mcp-stdio.js +440 -440
  23. package/lib/task-orchestrator.js +869 -0
  24. package/lib/text-diff.js +303 -303
  25. package/lib/workflow-engine.js +340 -340
  26. package/package.json +74 -70
  27. package/res/json5.min.js +1 -1
  28. package/res/vue.global.prod.js +13 -0
  29. package/web-ui/app.js +530 -397
  30. package/web-ui/index.html +33 -30
  31. package/web-ui/logic.agents-diff.mjs +386 -386
  32. package/web-ui/logic.claude.mjs +168 -108
  33. package/web-ui/logic.mjs +5 -5
  34. package/web-ui/logic.runtime.mjs +124 -124
  35. package/web-ui/logic.sessions.mjs +581 -263
  36. package/web-ui/modules/api.mjs +90 -69
  37. package/web-ui/modules/app.computed.dashboard.mjs +113 -113
  38. package/web-ui/modules/app.computed.index.mjs +15 -13
  39. package/web-ui/modules/app.computed.main-tabs.mjs +195 -0
  40. package/web-ui/modules/app.computed.session.mjs +507 -141
  41. package/web-ui/modules/app.constants.mjs +15 -15
  42. package/web-ui/modules/app.methods.agents.mjs +493 -493
  43. package/web-ui/modules/app.methods.claude-config.mjs +174 -174
  44. package/web-ui/modules/app.methods.codex-config.mjs +640 -640
  45. package/web-ui/modules/app.methods.index.mjs +88 -86
  46. package/web-ui/modules/app.methods.install.mjs +149 -157
  47. package/web-ui/modules/app.methods.navigation.mjs +619 -478
  48. package/web-ui/modules/app.methods.openclaw-core.mjs +814 -514
  49. package/web-ui/modules/app.methods.openclaw-editing.mjs +372 -337
  50. package/web-ui/modules/app.methods.openclaw-persist.mjs +369 -251
  51. package/web-ui/modules/app.methods.providers.mjs +363 -265
  52. package/web-ui/modules/app.methods.runtime.mjs +323 -323
  53. package/web-ui/modules/app.methods.session-actions.mjs +520 -457
  54. package/web-ui/modules/app.methods.session-browser.mjs +626 -435
  55. package/web-ui/modules/app.methods.session-timeline.mjs +448 -441
  56. package/web-ui/modules/app.methods.session-trash.mjs +422 -419
  57. package/web-ui/modules/app.methods.startup-claude.mjs +412 -406
  58. package/web-ui/modules/app.methods.task-orchestration.mjs +471 -0
  59. package/web-ui/modules/config-mode.computed.mjs +126 -124
  60. package/web-ui/modules/skills.computed.mjs +107 -107
  61. package/web-ui/modules/skills.methods.mjs +481 -481
  62. package/web-ui/partials/index/layout-footer.html +13 -69
  63. package/web-ui/partials/index/layout-header.html +402 -337
  64. package/web-ui/partials/index/modal-config-template-agents.html +125 -125
  65. package/web-ui/partials/index/modal-confirm-toast.html +32 -32
  66. package/web-ui/partials/index/modal-health-check.html +72 -72
  67. package/web-ui/partials/index/modal-openclaw-config.html +280 -275
  68. package/web-ui/partials/index/modal-skills.html +184 -184
  69. package/web-ui/partials/index/modals-basic.html +156 -196
  70. package/web-ui/partials/index/panel-config-claude.html +126 -100
  71. package/web-ui/partials/index/panel-config-codex.html +237 -237
  72. package/web-ui/partials/index/panel-config-openclaw.html +78 -84
  73. package/web-ui/partials/index/panel-docs.html +130 -0
  74. package/web-ui/partials/index/panel-market.html +174 -174
  75. package/web-ui/partials/index/panel-orchestration.html +397 -0
  76. package/web-ui/partials/index/panel-sessions.html +292 -387
  77. package/web-ui/partials/index/panel-settings.html +190 -166
  78. package/web-ui/partials/index/panel-usage.html +213 -0
  79. package/web-ui/session-helpers.mjs +559 -362
  80. package/web-ui/source-bundle.cjs +233 -233
  81. package/web-ui/styles/base-theme.css +271 -373
  82. package/web-ui/styles/controls-forms.css +360 -354
  83. package/web-ui/styles/docs-panel.css +182 -0
  84. package/web-ui/styles/feedback.css +108 -108
  85. package/web-ui/styles/health-check-dialog.css +144 -144
  86. package/web-ui/styles/layout-shell.css +376 -330
  87. package/web-ui/styles/modals-core.css +464 -449
  88. package/web-ui/styles/navigation-panels.css +348 -381
  89. package/web-ui/styles/openclaw-structured.css +266 -266
  90. package/web-ui/styles/responsive.css +450 -416
  91. package/web-ui/styles/sessions-list.css +400 -414
  92. package/web-ui/styles/sessions-preview.css +411 -405
  93. package/web-ui/styles/sessions-toolbar-trash.css +243 -243
  94. package/web-ui/styles/sessions-usage.css +628 -276
  95. package/web-ui/styles/skills-list.css +296 -298
  96. package/web-ui/styles/skills-market.css +335 -335
  97. package/web-ui/styles/task-orchestration.css +776 -0
  98. package/web-ui/styles/titles-cards.css +408 -407
  99. package/web-ui/styles.css +18 -16
  100. package/web-ui.html +17 -17
  101. package/res/screenshot.png +0 -0
  102. package/res/vue.global.js +0 -18552
@@ -1,311 +1,419 @@
1
- const crypto = require('crypto');
2
- const { joinApiUrl, normalizeBaseUrl } = require('./cli-utils');
3
-
4
- function extractModelNames(payload) {
5
- if (!payload || typeof payload !== 'object') return [];
6
- const data = Array.isArray(payload.data)
7
- ? payload.data
8
- : (Array.isArray(payload.models) ? payload.models : []);
9
- const names = [];
10
- for (const item of data) {
11
- if (typeof item === 'string') {
12
- if (item.trim()) names.push(item.trim());
13
- continue;
14
- }
15
- if (!item || typeof item !== 'object') continue;
16
- const name = item.id || item.name || item.model || '';
17
- if (typeof name === 'string' && name.trim()) {
18
- names.push(name.trim());
19
- }
20
- }
21
- return Array.from(new Set(names));
22
- }
23
-
24
- function hasModelsListPayload(payload) {
25
- if (!payload || typeof payload !== 'object') return false;
26
- return Array.isArray(payload.data) || Array.isArray(payload.models);
27
- }
28
-
29
- function extractModelIds(payload) {
30
- const ids = [];
31
- const pushValue = (value) => {
32
- if (typeof value === 'string' && value.trim()) {
33
- ids.push(value.trim());
34
- }
35
- };
36
-
37
- if (!payload) return ids;
38
-
39
- if (Array.isArray(payload)) {
40
- for (const item of payload) {
41
- if (item && typeof item === 'object') {
42
- pushValue(item.id);
43
- pushValue(item.model);
44
- pushValue(item.name);
45
- } else {
46
- pushValue(item);
47
- }
48
- }
49
- return ids;
50
- }
51
-
52
- if (Array.isArray(payload.data)) {
53
- for (const item of payload.data) {
54
- if (item && typeof item === 'object') {
55
- pushValue(item.id);
56
- pushValue(item.model);
57
- pushValue(item.name);
58
- } else {
59
- pushValue(item);
60
- }
61
- }
62
- }
63
-
64
- if (Array.isArray(payload.models)) {
65
- for (const item of payload.models) {
66
- if (item && typeof item === 'object') {
67
- pushValue(item.id);
68
- pushValue(item.model);
69
- pushValue(item.name);
70
- } else {
71
- pushValue(item);
72
- }
73
- }
74
- }
75
-
76
- return ids;
77
- }
78
-
79
- function normalizeWireApi(value) {
80
- const raw = typeof value === 'string' ? value.trim().toLowerCase() : '';
81
- if (!raw) return 'responses';
82
- return raw.replace(/[\s\-\/]/g, '_');
83
- }
84
-
85
- function buildApiProbeUrlCandidates(baseUrl, pathSuffix) {
86
- const normalized = normalizeBaseUrl(baseUrl);
87
- if (!normalized) return [];
88
-
89
- const safeSuffix = String(pathSuffix || '').replace(/^\/+/g, '');
90
- if (!safeSuffix) return [normalized];
91
-
92
- const candidates = [];
93
- const pushUnique = (value) => {
94
- if (value && !candidates.includes(value)) {
95
- candidates.push(value);
96
- }
97
- };
98
-
99
- let pathname = '';
100
- try {
101
- pathname = new URL(normalized).pathname.replace(/\/+$/g, '');
102
- } catch (e) {
103
- pathname = '';
104
- }
105
-
106
- const directUrl = `${normalized}/${safeSuffix}`;
107
- const versionedUrl = joinApiUrl(normalized, safeSuffix);
108
- if (/\/v\d+$/i.test(pathname)) {
109
- pushUnique(directUrl);
110
- return candidates;
111
- }
112
-
113
- if (!pathname || pathname === '/') {
114
- pushUnique(versionedUrl);
115
- pushUnique(directUrl);
116
- return candidates;
117
- }
118
-
119
- pushUnique(directUrl);
120
- pushUnique(versionedUrl);
121
- return candidates;
122
- }
123
-
124
- function buildModelsProbeUrl(baseUrl) {
125
- return buildApiProbeUrlCandidates(baseUrl, 'models')[0] || '';
126
- }
127
-
128
- function buildModelProbeSpecs(provider, modelName, baseUrl) {
129
- const model = typeof modelName === 'string' ? modelName.trim() : '';
130
- if (!model) return [];
131
-
132
- const wireApi = normalizeWireApi(provider && provider.wire_api);
133
- let pathSuffix = 'responses';
134
- let body = {
135
- model,
136
- input: 'ping',
137
- max_output_tokens: 1
138
- };
139
-
140
- if (wireApi === 'chat_completions' || wireApi === 'chat') {
141
- pathSuffix = 'chat/completions';
142
- body = {
143
- model,
144
- messages: [{ role: 'user', content: 'ping' }],
145
- max_tokens: 1,
146
- temperature: 0
147
- };
148
- } else if (wireApi === 'completions') {
149
- pathSuffix = 'completions';
150
- body = {
151
- model,
152
- prompt: 'ping',
153
- max_tokens: 1,
154
- temperature: 0
155
- };
156
- }
157
-
158
- return buildApiProbeUrlCandidates(baseUrl, pathSuffix).map((url) => ({
159
- url,
160
- body
161
- }));
162
- }
163
-
164
- function buildModelProbeSpec(provider, modelName, baseUrl) {
165
- return buildModelProbeSpecs(provider, modelName, baseUrl)[0] || null;
166
- }
167
-
168
- function buildModelConversationSpecs(provider, modelName, baseUrl, prompt, options = {}) {
169
- const model = typeof modelName === 'string' ? modelName.trim() : '';
170
- const userPrompt = typeof prompt === 'string' ? prompt.trim() : '';
171
- if (!model || !userPrompt) return [];
172
-
173
- const wireApi = normalizeWireApi(provider && provider.wire_api);
174
- const maxOutputTokens = Number.isFinite(options.maxOutputTokens)
175
- ? Math.max(1, Number(options.maxOutputTokens))
176
- : 256;
177
- let pathSuffix = 'responses';
178
- let body = {
179
- model,
180
- input: userPrompt,
181
- max_output_tokens: maxOutputTokens
182
- };
183
-
184
- if (wireApi === 'chat_completions' || wireApi === 'chat') {
185
- pathSuffix = 'chat/completions';
186
- body = {
187
- model,
188
- messages: [{ role: 'user', content: userPrompt }],
189
- max_tokens: maxOutputTokens
190
- };
191
- } else if (wireApi === 'completions') {
192
- pathSuffix = 'completions';
193
- body = {
194
- model,
195
- prompt: userPrompt,
196
- max_tokens: maxOutputTokens
197
- };
198
- }
199
-
200
- return buildApiProbeUrlCandidates(baseUrl, pathSuffix).map((url) => ({
201
- url,
202
- body,
203
- wireApi
204
- }));
205
- }
206
-
207
- function collectStructuredText(content, pieces) {
208
- if (typeof content === 'string') {
209
- const text = content.trim();
210
- if (text) pieces.push(text);
211
- return;
212
- }
213
- if (Array.isArray(content)) {
214
- for (const item of content) {
215
- collectStructuredText(item, pieces);
216
- }
217
- return;
218
- }
219
- if (!content || typeof content !== 'object') {
220
- return;
221
- }
222
-
223
- if (typeof content.output_text === 'string' && content.output_text.trim()) {
224
- pieces.push(content.output_text.trim());
225
- }
226
- if (typeof content.text === 'string' && content.text.trim()) {
227
- pieces.push(content.text.trim());
228
- }
229
- if (typeof content.content === 'string' && content.content.trim()) {
230
- pieces.push(content.content.trim());
231
- }
232
-
233
- if (Array.isArray(content.content)) {
234
- collectStructuredText(content.content, pieces);
235
- }
236
- if (content.message) {
237
- collectStructuredText(content.message, pieces);
238
- }
239
- }
240
-
241
- function extractModelResponseText(payload) {
242
- if (!payload || typeof payload !== 'object') {
243
- return '';
244
- }
245
-
246
- if (typeof payload.output_text === 'string' && payload.output_text.trim()) {
247
- return payload.output_text.trim();
248
- }
249
-
250
- const pieces = [];
251
-
252
- if (Array.isArray(payload.output)) {
253
- for (const item of payload.output) {
254
- collectStructuredText(item, pieces);
255
- }
256
- }
257
-
258
- if (Array.isArray(payload.choices)) {
259
- for (const choice of payload.choices) {
260
- if (!choice || typeof choice !== 'object') continue;
261
- if (typeof choice.text === 'string' && choice.text.trim()) {
262
- pieces.push(choice.text.trim());
263
- }
264
- if (choice.message) {
265
- collectStructuredText(choice.message, pieces);
266
- }
267
- }
268
- }
269
-
270
- if (payload.message) {
271
- collectStructuredText(payload.message, pieces);
272
- }
273
- if (payload.content) {
274
- collectStructuredText(payload.content, pieces);
275
- }
276
- if (typeof payload.text === 'string' && payload.text.trim()) {
277
- pieces.push(payload.text.trim());
278
- }
279
-
280
- return Array.from(new Set(pieces)).join('\n\n').trim();
281
- }
282
-
283
- function hashModelsCacheValue(value) {
284
- if (!value) return '';
285
- try {
286
- return crypto.createHash('sha256').update(String(value)).digest('hex');
287
- } catch (e) {
288
- return '';
289
- }
290
- }
291
-
292
- function buildModelsCacheKey(baseUrl, apiKey) {
293
- const normalizedUrl = normalizeBaseUrl(baseUrl);
294
- const apiKeyHash = hashModelsCacheValue(apiKey);
295
- return `${normalizedUrl}|${apiKeyHash}`;
296
- }
297
-
298
- module.exports = {
299
- extractModelNames,
300
- hasModelsListPayload,
301
- extractModelIds,
302
- normalizeWireApi,
303
- buildApiProbeUrlCandidates,
304
- buildModelsProbeUrl,
305
- buildModelProbeSpecs,
306
- buildModelProbeSpec,
307
- buildModelConversationSpecs,
308
- extractModelResponseText,
309
- hashModelsCacheValue,
310
- buildModelsCacheKey
311
- };
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 buildModelConversationSpecs(provider, modelName, baseUrl, prompt, options = {}) {
275
+ const model = typeof modelName === 'string' ? modelName.trim() : '';
276
+ const userPrompt = typeof prompt === 'string' ? prompt.trim() : '';
277
+ if (!model || !userPrompt) return [];
278
+
279
+ const wireApi = normalizeWireApi(provider && provider.wire_api);
280
+ const maxOutputTokens = Number.isFinite(options.maxOutputTokens)
281
+ ? Math.max(1, Number(options.maxOutputTokens))
282
+ : 256;
283
+ let pathSuffix = 'responses';
284
+ let body = {
285
+ model,
286
+ input: userPrompt,
287
+ max_output_tokens: maxOutputTokens
288
+ };
289
+
290
+ if (wireApi === 'chat_completions' || wireApi === 'chat') {
291
+ pathSuffix = 'chat/completions';
292
+ body = {
293
+ model,
294
+ messages: [{ role: 'user', content: userPrompt }],
295
+ max_tokens: maxOutputTokens
296
+ };
297
+ } else if (wireApi === 'completions') {
298
+ pathSuffix = 'completions';
299
+ body = {
300
+ model,
301
+ prompt: userPrompt,
302
+ max_tokens: maxOutputTokens
303
+ };
304
+ }
305
+
306
+ return buildApiProbeUrlCandidates(baseUrl, pathSuffix).map((url) => ({
307
+ url,
308
+ body,
309
+ wireApi
310
+ }));
311
+ }
312
+
313
+ function collectStructuredText(content, pieces) {
314
+ if (typeof content === 'string') {
315
+ const text = content.trim();
316
+ if (text) pieces.push(text);
317
+ return;
318
+ }
319
+ if (Array.isArray(content)) {
320
+ for (const item of content) {
321
+ collectStructuredText(item, pieces);
322
+ }
323
+ return;
324
+ }
325
+ if (!content || typeof content !== 'object') {
326
+ return;
327
+ }
328
+
329
+ if (typeof content.output_text === 'string' && content.output_text.trim()) {
330
+ pieces.push(content.output_text.trim());
331
+ }
332
+ if (typeof content.text === 'string' && content.text.trim()) {
333
+ pieces.push(content.text.trim());
334
+ }
335
+ if (typeof content.content === 'string' && content.content.trim()) {
336
+ pieces.push(content.content.trim());
337
+ }
338
+
339
+ if (Array.isArray(content.content)) {
340
+ collectStructuredText(content.content, pieces);
341
+ }
342
+ if (content.message) {
343
+ collectStructuredText(content.message, pieces);
344
+ }
345
+ }
346
+
347
+ function extractModelResponseText(payload) {
348
+ if (!payload || typeof payload !== 'object') {
349
+ return '';
350
+ }
351
+
352
+ if (typeof payload.output_text === 'string' && payload.output_text.trim()) {
353
+ return payload.output_text.trim();
354
+ }
355
+
356
+ const pieces = [];
357
+
358
+ if (Array.isArray(payload.output)) {
359
+ for (const item of payload.output) {
360
+ collectStructuredText(item, pieces);
361
+ }
362
+ }
363
+
364
+ if (Array.isArray(payload.choices)) {
365
+ for (const choice of payload.choices) {
366
+ if (!choice || typeof choice !== 'object') continue;
367
+ if (typeof choice.text === 'string' && choice.text.trim()) {
368
+ pieces.push(choice.text.trim());
369
+ }
370
+ if (choice.message) {
371
+ collectStructuredText(choice.message, pieces);
372
+ }
373
+ }
374
+ }
375
+
376
+ if (payload.message) {
377
+ collectStructuredText(payload.message, pieces);
378
+ }
379
+ if (payload.content) {
380
+ collectStructuredText(payload.content, pieces);
381
+ }
382
+ if (typeof payload.text === 'string' && payload.text.trim()) {
383
+ pieces.push(payload.text.trim());
384
+ }
385
+
386
+ return Array.from(new Set(pieces)).join('\n\n').trim();
387
+ }
388
+
389
+ function hashModelsCacheValue(value) {
390
+ if (!value) return '';
391
+ try {
392
+ return crypto.createHash('sha256').update(String(value)).digest('hex');
393
+ } catch (e) {
394
+ return '';
395
+ }
396
+ }
397
+
398
+ function buildModelsCacheKey(baseUrl, apiKey) {
399
+ const normalizedUrl = normalizeBaseUrl(baseUrl);
400
+ const apiKeyHash = hashModelsCacheValue(apiKey);
401
+ return `${normalizedUrl}|${apiKeyHash}`;
402
+ }
403
+
404
+ module.exports = {
405
+ extractModelNames,
406
+ hasModelsListPayload,
407
+ extractModelIds,
408
+ normalizeWireApi,
409
+ buildApiProbeUrlCandidates,
410
+ buildModelsProbeUrl,
411
+ buildModelProbeSpecs,
412
+ buildModelProbeSpec,
413
+ buildModelConversationSpecs,
414
+ extractModelResponseText,
415
+ hashModelsCacheValue,
416
+ buildModelsCacheKey,
417
+ getSupplementalModelsForBaseUrl,
418
+ mergeModelCatalog
419
+ };