codexmate 0.0.40 → 0.0.41
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.
- package/README.md +168 -156
- package/README.zh.md +168 -156
- package/cli/agents-files.js +230 -230
- package/cli/analytics-export-args.js +68 -68
- package/cli/archive-helpers.js +453 -453
- package/cli/auth-profiles.js +375 -375
- package/cli/builtin-proxy.js +2144 -2144
- package/cli/claude-proxy.js +1022 -1022
- package/cli/config-bootstrap.js +407 -407
- package/cli/config-health.js +454 -454
- package/cli/doctor-core.js +903 -903
- package/cli/import-skills-url.js +356 -356
- package/cli/local-bridge.js +556 -556
- package/cli/openai-bridge.js +1984 -1984
- package/cli/openclaw-config.js +629 -629
- package/cli/session-convert-args.js +69 -69
- package/cli/session-convert-io.js +82 -82
- package/cli/session-convert.js +150 -150
- package/cli/session-usage.concurrent.js +28 -28
- package/cli/session-usage.js +304 -304
- package/cli/session-usage.models.js +176 -176
- package/cli/skills.js +1141 -1141
- package/cli/update.js +171 -171
- package/cli/zip-commands.js +510 -510
- package/cli.js +16458 -16341
- package/lib/automation.js +404 -404
- package/lib/cli-file-utils.js +151 -151
- package/lib/cli-models-utils.js +440 -440
- package/lib/cli-network-utils.js +190 -190
- package/lib/cli-path-utils.js +85 -85
- package/lib/cli-session-utils.js +121 -121
- package/lib/cli-sessions.js +427 -427
- package/lib/cli-utils.js +155 -155
- package/lib/cli-webhook.js +154 -154
- package/lib/download-artifacts.js +92 -92
- package/lib/mcp-stdio.js +453 -453
- package/lib/task-orchestrator.js +869 -869
- package/lib/text-diff.js +303 -303
- package/lib/win-tray.js +119 -119
- package/lib/workflow-engine.js +340 -340
- package/package.json +77 -77
- package/plugins/README.md +20 -20
- package/plugins/README.zh-CN.md +20 -20
- package/plugins/prompt-templates/comment-polish/index.mjs +25 -25
- package/plugins/prompt-templates/computed.mjs +311 -311
- package/plugins/prompt-templates/index.mjs +8 -8
- package/plugins/prompt-templates/manifest.mjs +18 -18
- package/plugins/prompt-templates/methods.mjs +553 -553
- package/plugins/prompt-templates/overview.mjs +91 -91
- package/plugins/prompt-templates/ownership.mjs +19 -19
- package/plugins/prompt-templates/rule-ack/index.mjs +21 -21
- package/plugins/prompt-templates/storage.mjs +64 -64
- package/plugins/registry.mjs +16 -16
- package/web-ui/app.js +695 -695
- package/web-ui/index.html +37 -37
- package/web-ui/logic.agents-diff.mjs +386 -386
- package/web-ui/logic.claude.mjs +172 -172
- package/web-ui/logic.codex.mjs +69 -69
- package/web-ui/logic.mjs +5 -5
- package/web-ui/logic.runtime.mjs +128 -128
- package/web-ui/logic.session-convert.mjs +70 -70
- package/web-ui/logic.sessions.mjs +782 -782
- package/web-ui/modules/api.mjs +90 -90
- package/web-ui/modules/app.computed.dashboard.mjs +252 -252
- package/web-ui/modules/app.computed.index.mjs +17 -17
- package/web-ui/modules/app.computed.main-tabs.mjs +214 -214
- package/web-ui/modules/app.computed.session.mjs +876 -876
- package/web-ui/modules/app.constants.mjs +15 -15
- package/web-ui/modules/app.methods.agents.mjs +651 -651
- package/web-ui/modules/app.methods.claude-config.mjs +412 -412
- package/web-ui/modules/app.methods.codex-config.mjs +869 -869
- package/web-ui/modules/app.methods.index.mjs +96 -96
- package/web-ui/modules/app.methods.install.mjs +205 -205
- package/web-ui/modules/app.methods.navigation.mjs +804 -804
- package/web-ui/modules/app.methods.openclaw-core.mjs +814 -814
- package/web-ui/modules/app.methods.openclaw-editing.mjs +420 -420
- package/web-ui/modules/app.methods.openclaw-persist.mjs +375 -375
- package/web-ui/modules/app.methods.providers.mjs +601 -601
- package/web-ui/modules/app.methods.runtime.mjs +420 -420
- package/web-ui/modules/app.methods.session-actions.mjs +591 -591
- package/web-ui/modules/app.methods.session-browser.mjs +1018 -1018
- package/web-ui/modules/app.methods.session-timeline.mjs +479 -479
- package/web-ui/modules/app.methods.session-trash.mjs +468 -468
- package/web-ui/modules/app.methods.startup-claude.mjs +554 -554
- package/web-ui/modules/app.methods.task-orchestration.mjs +556 -556
- package/web-ui/modules/app.methods.tool-config-permissions.mjs +87 -87
- package/web-ui/modules/app.methods.webhook.mjs +87 -87
- package/web-ui/modules/config-mode.computed.mjs +124 -124
- package/web-ui/modules/config-template-confirm-pref.mjs +33 -33
- package/web-ui/modules/i18n/locales/en.mjs +1140 -1140
- package/web-ui/modules/i18n/locales/ja.mjs +1130 -1130
- package/web-ui/modules/i18n/locales/vi.mjs +239 -239
- package/web-ui/modules/i18n/locales/zh.mjs +1143 -1143
- package/web-ui/modules/i18n.dict.mjs +14 -14
- package/web-ui/modules/i18n.mjs +111 -111
- package/web-ui/modules/plugins.computed.mjs +3 -3
- package/web-ui/modules/plugins.methods.mjs +3 -3
- package/web-ui/modules/plugins.storage.mjs +11 -11
- package/web-ui/modules/provider-url-display.mjs +17 -17
- package/web-ui/modules/sessions-filters-url.mjs +138 -138
- package/web-ui/modules/skills.computed.mjs +107 -107
- package/web-ui/modules/skills.methods.mjs +513 -513
- package/web-ui/partials/index/layout-footer.html +13 -13
- package/web-ui/partials/index/layout-header.html +478 -478
- package/web-ui/partials/index/modal-config-template-agents.html +185 -185
- package/web-ui/partials/index/modal-confirm-toast.html +32 -32
- package/web-ui/partials/index/modal-health-check.html +45 -45
- package/web-ui/partials/index/modal-openclaw-config.html +344 -344
- package/web-ui/partials/index/modal-skills.html +200 -200
- package/web-ui/partials/index/modal-webhook.html +42 -42
- package/web-ui/partials/index/modals-basic.html +263 -263
- package/web-ui/partials/index/panel-config-claude.html +187 -187
- package/web-ui/partials/index/panel-config-codex.html +205 -205
- package/web-ui/partials/index/panel-config-openclaw.html +89 -89
- package/web-ui/partials/index/panel-dashboard.html +171 -171
- package/web-ui/partials/index/panel-docs.html +114 -114
- package/web-ui/partials/index/panel-market.html +104 -104
- package/web-ui/partials/index/panel-orchestration.html +391 -391
- package/web-ui/partials/index/panel-plugins.html +253 -253
- package/web-ui/partials/index/panel-sessions.html +319 -319
- package/web-ui/partials/index/panel-settings.html +181 -181
- package/web-ui/partials/index/panel-trash.html +82 -82
- package/web-ui/partials/index/panel-usage.html +181 -181
- package/web-ui/res/json5.min.js +1 -1
- package/web-ui/res/vue.global.prod.js +13 -13
- package/web-ui/res/vue.runtime.global.prod.js +7 -7
- package/web-ui/res/web-ui-render.precompiled.js +7666 -7666
- package/web-ui/session-helpers.mjs +602 -602
- package/web-ui/source-bundle.cjs +305 -305
- package/web-ui/styles/base-theme.css +291 -291
- package/web-ui/styles/bridge-pool.css +266 -266
- package/web-ui/styles/controls-forms.css +532 -532
- package/web-ui/styles/dashboard.css +438 -438
- package/web-ui/styles/docs-panel.css +245 -245
- package/web-ui/styles/feedback.css +108 -108
- package/web-ui/styles/health-check-dialog.css +144 -144
- package/web-ui/styles/layout-shell.css +711 -711
- package/web-ui/styles/modals-core.css +499 -499
- package/web-ui/styles/navigation-panels.css +399 -399
- package/web-ui/styles/openclaw-structured.css +616 -616
- package/web-ui/styles/plugins-panel.css +564 -564
- package/web-ui/styles/responsive.css +501 -501
- package/web-ui/styles/sessions-list.css +683 -683
- package/web-ui/styles/sessions-preview.css +407 -407
- package/web-ui/styles/sessions-toolbar-trash.css +518 -518
- package/web-ui/styles/sessions-usage.css +849 -849
- package/web-ui/styles/settings-panel.css +419 -419
- package/web-ui/styles/skills-list.css +305 -305
- package/web-ui/styles/skills-market.css +723 -723
- package/web-ui/styles/task-orchestration.css +822 -822
- package/web-ui/styles/titles-cards.css +486 -486
- package/web-ui/styles/trash-panel.css +90 -90
- package/web-ui/styles/webhook.css +115 -115
- package/web-ui/styles.css +24 -24
- package/web-ui.html +17 -17
package/lib/cli-models-utils.js
CHANGED
|
@@ -1,440 +1,440 @@
|
|
|
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
|
-
const DEEPSEEK_CLAUDE_COMPAT_MODELS = Object.freeze([
|
|
52
|
-
'DeepSeek-V3.2',
|
|
53
|
-
'DeepSeek-V3',
|
|
54
|
-
'DeepSeek-R1',
|
|
55
|
-
'deepseek-chat'
|
|
56
|
-
]);
|
|
57
|
-
|
|
58
|
-
const QWEN_CLAUDE_COMPAT_MODELS = Object.freeze([
|
|
59
|
-
'qwen3-coder',
|
|
60
|
-
'qwen-max',
|
|
61
|
-
'qwen-plus',
|
|
62
|
-
'qwen-turbo'
|
|
63
|
-
]);
|
|
64
|
-
|
|
65
|
-
const MODELSCOPE_CLAUDE_COMPAT_MODELS = Object.freeze([
|
|
66
|
-
'ZhipuAI/GLM-5'
|
|
67
|
-
]);
|
|
68
|
-
|
|
69
|
-
function normalizeModelCatalogId(value) {
|
|
70
|
-
return typeof value === 'string' ? value.trim().toLowerCase() : '';
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
function hasPathSegment(baseUrl, segment) {
|
|
74
|
-
const normalized = normalizeBaseUrl(baseUrl);
|
|
75
|
-
if (!normalized) return false;
|
|
76
|
-
try {
|
|
77
|
-
const parsed = new URL(normalized);
|
|
78
|
-
const pathname = String(parsed.pathname || '').toLowerCase();
|
|
79
|
-
const escaped = String(segment || '').replace(/[.*+?^${}()|[\]\\]/g, '\\$&').toLowerCase();
|
|
80
|
-
return new RegExp(`(^|/)${escaped}(/|$)`).test(pathname);
|
|
81
|
-
} catch (_) {
|
|
82
|
-
return false;
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
function getBaseUrlHost(baseUrl) {
|
|
87
|
-
const normalized = normalizeBaseUrl(baseUrl);
|
|
88
|
-
if (!normalized) return '';
|
|
89
|
-
try {
|
|
90
|
-
const parsed = new URL(normalized);
|
|
91
|
-
return String(parsed.hostname || '').toLowerCase();
|
|
92
|
-
} catch (_) {
|
|
93
|
-
return '';
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
function isHostOrSubdomain(host, domain) {
|
|
98
|
-
return host === domain || host.endsWith(`.${domain}`);
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
function isBigModelClaudeCompatibleBaseUrl(baseUrl) {
|
|
102
|
-
const host = getBaseUrlHost(baseUrl);
|
|
103
|
-
return isHostOrSubdomain(host, 'bigmodel.cn') && hasPathSegment(baseUrl, 'anthropic');
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
function isAnthropicBaseUrl(baseUrl) {
|
|
107
|
-
const host = getBaseUrlHost(baseUrl);
|
|
108
|
-
return isHostOrSubdomain(host, 'anthropic.com');
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
function isDeepSeekClaudeCompatibleBaseUrl(baseUrl) {
|
|
112
|
-
const host = getBaseUrlHost(baseUrl);
|
|
113
|
-
return isHostOrSubdomain(host, 'deepseek.com') && hasPathSegment(baseUrl, 'anthropic');
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
function isQwenClaudeCompatibleBaseUrl(baseUrl) {
|
|
117
|
-
const host = getBaseUrlHost(baseUrl);
|
|
118
|
-
return isHostOrSubdomain(host, 'dashscope.aliyuncs.com') && hasPathSegment(baseUrl, 'anthropic');
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
function isZaiClaudeCompatibleBaseUrl(baseUrl) {
|
|
122
|
-
const host = getBaseUrlHost(baseUrl);
|
|
123
|
-
return isHostOrSubdomain(host, 'z.ai') && hasPathSegment(baseUrl, 'anthropic');
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
function isModelScopeBaseUrl(baseUrl) {
|
|
127
|
-
const host = getBaseUrlHost(baseUrl);
|
|
128
|
-
return isHostOrSubdomain(host, 'modelscope.cn');
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
function getSupplementalModelsForBaseUrl(baseUrl) {
|
|
132
|
-
if (isBigModelClaudeCompatibleBaseUrl(baseUrl)) {
|
|
133
|
-
return [...BIGMODEL_CLAUDE_COMPAT_MODELS];
|
|
134
|
-
}
|
|
135
|
-
if (isAnthropicBaseUrl(baseUrl)) {
|
|
136
|
-
return [...ANTHROPIC_CLAUDE_MODELS];
|
|
137
|
-
}
|
|
138
|
-
if (isDeepSeekClaudeCompatibleBaseUrl(baseUrl)) {
|
|
139
|
-
return [...DEEPSEEK_CLAUDE_COMPAT_MODELS];
|
|
140
|
-
}
|
|
141
|
-
if (isQwenClaudeCompatibleBaseUrl(baseUrl)) {
|
|
142
|
-
return [...QWEN_CLAUDE_COMPAT_MODELS];
|
|
143
|
-
}
|
|
144
|
-
if (isZaiClaudeCompatibleBaseUrl(baseUrl)) {
|
|
145
|
-
return [...BIGMODEL_CLAUDE_COMPAT_MODELS];
|
|
146
|
-
}
|
|
147
|
-
if (isModelScopeBaseUrl(baseUrl)) {
|
|
148
|
-
return [...MODELSCOPE_CLAUDE_COMPAT_MODELS];
|
|
149
|
-
}
|
|
150
|
-
return [];
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
function mergeModelCatalog(remoteModels = [], supplementalModels = []) {
|
|
154
|
-
const merged = [];
|
|
155
|
-
const seen = new Set();
|
|
156
|
-
const push = (value) => {
|
|
157
|
-
if (typeof value !== 'string') return;
|
|
158
|
-
const trimmed = value.trim();
|
|
159
|
-
if (!trimmed) return;
|
|
160
|
-
const normalized = normalizeModelCatalogId(trimmed);
|
|
161
|
-
if (!normalized || seen.has(normalized)) return;
|
|
162
|
-
seen.add(normalized);
|
|
163
|
-
merged.push(trimmed);
|
|
164
|
-
};
|
|
165
|
-
|
|
166
|
-
for (const item of remoteModels) push(item);
|
|
167
|
-
for (const item of supplementalModels) push(item);
|
|
168
|
-
return merged;
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
function extractModelNames(payload) {
|
|
172
|
-
if (!payload || typeof payload !== 'object') return [];
|
|
173
|
-
const data = Array.isArray(payload.data)
|
|
174
|
-
? payload.data
|
|
175
|
-
: (Array.isArray(payload.models) ? payload.models : []);
|
|
176
|
-
const names = [];
|
|
177
|
-
for (const item of data) {
|
|
178
|
-
if (typeof item === 'string') {
|
|
179
|
-
if (item.trim()) names.push(item.trim());
|
|
180
|
-
continue;
|
|
181
|
-
}
|
|
182
|
-
if (!item || typeof item !== 'object') continue;
|
|
183
|
-
const name = item.id || item.name || item.model || '';
|
|
184
|
-
if (typeof name === 'string' && name.trim()) {
|
|
185
|
-
names.push(name.trim());
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
return Array.from(new Set(names));
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
function hasModelsListPayload(payload) {
|
|
192
|
-
if (!payload || typeof payload !== 'object') return false;
|
|
193
|
-
return Array.isArray(payload.data) || Array.isArray(payload.models);
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
function extractModelIds(payload) {
|
|
197
|
-
const ids = [];
|
|
198
|
-
const pushValue = (value) => {
|
|
199
|
-
if (typeof value === 'string' && value.trim()) {
|
|
200
|
-
ids.push(value.trim());
|
|
201
|
-
}
|
|
202
|
-
};
|
|
203
|
-
|
|
204
|
-
if (!payload) return ids;
|
|
205
|
-
|
|
206
|
-
if (Array.isArray(payload)) {
|
|
207
|
-
for (const item of payload) {
|
|
208
|
-
if (item && typeof item === 'object') {
|
|
209
|
-
pushValue(item.id);
|
|
210
|
-
pushValue(item.model);
|
|
211
|
-
pushValue(item.name);
|
|
212
|
-
} else {
|
|
213
|
-
pushValue(item);
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
return ids;
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
if (Array.isArray(payload.data)) {
|
|
220
|
-
for (const item of payload.data) {
|
|
221
|
-
if (item && typeof item === 'object') {
|
|
222
|
-
pushValue(item.id);
|
|
223
|
-
pushValue(item.model);
|
|
224
|
-
pushValue(item.name);
|
|
225
|
-
} else {
|
|
226
|
-
pushValue(item);
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
if (Array.isArray(payload.models)) {
|
|
232
|
-
for (const item of payload.models) {
|
|
233
|
-
if (item && typeof item === 'object') {
|
|
234
|
-
pushValue(item.id);
|
|
235
|
-
pushValue(item.model);
|
|
236
|
-
pushValue(item.name);
|
|
237
|
-
} else {
|
|
238
|
-
pushValue(item);
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
return ids;
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
function normalizeWireApi(value) {
|
|
247
|
-
const raw = typeof value === 'string' ? value.trim().toLowerCase() : '';
|
|
248
|
-
if (!raw) return 'responses';
|
|
249
|
-
return raw.replace(/[\s\-\/]/g, '_');
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
function buildApiProbeUrlCandidates(baseUrl, pathSuffix) {
|
|
253
|
-
const normalized = normalizeBaseUrl(baseUrl);
|
|
254
|
-
if (!normalized) return [];
|
|
255
|
-
|
|
256
|
-
const safeSuffix = String(pathSuffix || '').replace(/^\/+/g, '');
|
|
257
|
-
if (!safeSuffix) return [normalized];
|
|
258
|
-
|
|
259
|
-
const candidates = [];
|
|
260
|
-
const pushUnique = (value) => {
|
|
261
|
-
if (value && !candidates.includes(value)) {
|
|
262
|
-
candidates.push(value);
|
|
263
|
-
}
|
|
264
|
-
};
|
|
265
|
-
|
|
266
|
-
let pathname = '';
|
|
267
|
-
try {
|
|
268
|
-
pathname = new URL(normalized).pathname.replace(/\/+$/g, '');
|
|
269
|
-
} catch (e) {
|
|
270
|
-
pathname = '';
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
const directUrl = `${normalized}/${safeSuffix}`;
|
|
274
|
-
const versionedUrl = joinApiUrl(normalized, safeSuffix);
|
|
275
|
-
if (/\/v\d+$/i.test(pathname)) {
|
|
276
|
-
pushUnique(directUrl);
|
|
277
|
-
return candidates;
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
if (!pathname || pathname === '/') {
|
|
281
|
-
pushUnique(versionedUrl);
|
|
282
|
-
pushUnique(directUrl);
|
|
283
|
-
return candidates;
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
pushUnique(directUrl);
|
|
287
|
-
pushUnique(versionedUrl);
|
|
288
|
-
return candidates;
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
function buildModelsProbeUrl(baseUrl) {
|
|
292
|
-
return buildApiProbeUrlCandidates(baseUrl, 'models')[0] || '';
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
function buildModelProbeSpecs(provider, modelName, baseUrl) {
|
|
296
|
-
const model = typeof modelName === 'string' ? modelName.trim() : '';
|
|
297
|
-
if (!model) return [];
|
|
298
|
-
|
|
299
|
-
const wireApi = normalizeWireApi(provider && provider.wire_api);
|
|
300
|
-
let pathSuffix = 'responses';
|
|
301
|
-
let body = {
|
|
302
|
-
model,
|
|
303
|
-
input: 'ping',
|
|
304
|
-
max_output_tokens: 1
|
|
305
|
-
};
|
|
306
|
-
|
|
307
|
-
if (wireApi === 'chat_completions' || wireApi === 'chat') {
|
|
308
|
-
pathSuffix = 'chat/completions';
|
|
309
|
-
body = {
|
|
310
|
-
model,
|
|
311
|
-
messages: [{ role: 'user', content: 'ping' }],
|
|
312
|
-
max_tokens: 1,
|
|
313
|
-
temperature: 0
|
|
314
|
-
};
|
|
315
|
-
} else if (wireApi === 'completions') {
|
|
316
|
-
pathSuffix = 'completions';
|
|
317
|
-
body = {
|
|
318
|
-
model,
|
|
319
|
-
prompt: 'ping',
|
|
320
|
-
max_tokens: 1,
|
|
321
|
-
temperature: 0
|
|
322
|
-
};
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
return buildApiProbeUrlCandidates(baseUrl, pathSuffix).map((url) => ({
|
|
326
|
-
url,
|
|
327
|
-
body
|
|
328
|
-
}));
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
function buildModelProbeSpec(provider, modelName, baseUrl) {
|
|
332
|
-
return buildModelProbeSpecs(provider, modelName, baseUrl)[0] || null;
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
function collectStructuredText(content, pieces) {
|
|
336
|
-
if (typeof content === 'string') {
|
|
337
|
-
const text = content.trim();
|
|
338
|
-
if (text) pieces.push(text);
|
|
339
|
-
return;
|
|
340
|
-
}
|
|
341
|
-
if (Array.isArray(content)) {
|
|
342
|
-
for (const item of content) {
|
|
343
|
-
collectStructuredText(item, pieces);
|
|
344
|
-
}
|
|
345
|
-
return;
|
|
346
|
-
}
|
|
347
|
-
if (!content || typeof content !== 'object') {
|
|
348
|
-
return;
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
if (typeof content.output_text === 'string' && content.output_text.trim()) {
|
|
352
|
-
pieces.push(content.output_text.trim());
|
|
353
|
-
}
|
|
354
|
-
if (typeof content.text === 'string' && content.text.trim()) {
|
|
355
|
-
pieces.push(content.text.trim());
|
|
356
|
-
}
|
|
357
|
-
if (typeof content.content === 'string' && content.content.trim()) {
|
|
358
|
-
pieces.push(content.content.trim());
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
if (Array.isArray(content.content)) {
|
|
362
|
-
collectStructuredText(content.content, pieces);
|
|
363
|
-
}
|
|
364
|
-
if (content.message) {
|
|
365
|
-
collectStructuredText(content.message, pieces);
|
|
366
|
-
}
|
|
367
|
-
}
|
|
368
|
-
|
|
369
|
-
function extractModelResponseText(payload) {
|
|
370
|
-
if (!payload || typeof payload !== 'object') {
|
|
371
|
-
return '';
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
if (typeof payload.output_text === 'string' && payload.output_text.trim()) {
|
|
375
|
-
return payload.output_text.trim();
|
|
376
|
-
}
|
|
377
|
-
|
|
378
|
-
const pieces = [];
|
|
379
|
-
|
|
380
|
-
if (Array.isArray(payload.output)) {
|
|
381
|
-
for (const item of payload.output) {
|
|
382
|
-
collectStructuredText(item, pieces);
|
|
383
|
-
}
|
|
384
|
-
}
|
|
385
|
-
|
|
386
|
-
if (Array.isArray(payload.choices)) {
|
|
387
|
-
for (const choice of payload.choices) {
|
|
388
|
-
if (!choice || typeof choice !== 'object') continue;
|
|
389
|
-
if (typeof choice.text === 'string' && choice.text.trim()) {
|
|
390
|
-
pieces.push(choice.text.trim());
|
|
391
|
-
}
|
|
392
|
-
if (choice.message) {
|
|
393
|
-
collectStructuredText(choice.message, pieces);
|
|
394
|
-
}
|
|
395
|
-
}
|
|
396
|
-
}
|
|
397
|
-
|
|
398
|
-
if (payload.message) {
|
|
399
|
-
collectStructuredText(payload.message, pieces);
|
|
400
|
-
}
|
|
401
|
-
if (payload.content) {
|
|
402
|
-
collectStructuredText(payload.content, pieces);
|
|
403
|
-
}
|
|
404
|
-
if (typeof payload.text === 'string' && payload.text.trim()) {
|
|
405
|
-
pieces.push(payload.text.trim());
|
|
406
|
-
}
|
|
407
|
-
|
|
408
|
-
return Array.from(new Set(pieces)).join('\n\n').trim();
|
|
409
|
-
}
|
|
410
|
-
|
|
411
|
-
function hashModelsCacheValue(value) {
|
|
412
|
-
if (!value) return '';
|
|
413
|
-
try {
|
|
414
|
-
return crypto.createHash('sha256').update(String(value)).digest('hex');
|
|
415
|
-
} catch (e) {
|
|
416
|
-
return '';
|
|
417
|
-
}
|
|
418
|
-
}
|
|
419
|
-
|
|
420
|
-
function buildModelsCacheKey(baseUrl, apiKey) {
|
|
421
|
-
const normalizedUrl = normalizeBaseUrl(baseUrl);
|
|
422
|
-
const apiKeyHash = hashModelsCacheValue(apiKey);
|
|
423
|
-
return `${normalizedUrl}|${apiKeyHash}`;
|
|
424
|
-
}
|
|
425
|
-
|
|
426
|
-
module.exports = {
|
|
427
|
-
extractModelNames,
|
|
428
|
-
hasModelsListPayload,
|
|
429
|
-
extractModelIds,
|
|
430
|
-
normalizeWireApi,
|
|
431
|
-
buildApiProbeUrlCandidates,
|
|
432
|
-
buildModelsProbeUrl,
|
|
433
|
-
buildModelProbeSpecs,
|
|
434
|
-
buildModelProbeSpec,
|
|
435
|
-
extractModelResponseText,
|
|
436
|
-
hashModelsCacheValue,
|
|
437
|
-
buildModelsCacheKey,
|
|
438
|
-
getSupplementalModelsForBaseUrl,
|
|
439
|
-
mergeModelCatalog
|
|
440
|
-
};
|
|
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
|
+
const DEEPSEEK_CLAUDE_COMPAT_MODELS = Object.freeze([
|
|
52
|
+
'DeepSeek-V3.2',
|
|
53
|
+
'DeepSeek-V3',
|
|
54
|
+
'DeepSeek-R1',
|
|
55
|
+
'deepseek-chat'
|
|
56
|
+
]);
|
|
57
|
+
|
|
58
|
+
const QWEN_CLAUDE_COMPAT_MODELS = Object.freeze([
|
|
59
|
+
'qwen3-coder',
|
|
60
|
+
'qwen-max',
|
|
61
|
+
'qwen-plus',
|
|
62
|
+
'qwen-turbo'
|
|
63
|
+
]);
|
|
64
|
+
|
|
65
|
+
const MODELSCOPE_CLAUDE_COMPAT_MODELS = Object.freeze([
|
|
66
|
+
'ZhipuAI/GLM-5'
|
|
67
|
+
]);
|
|
68
|
+
|
|
69
|
+
function normalizeModelCatalogId(value) {
|
|
70
|
+
return typeof value === 'string' ? value.trim().toLowerCase() : '';
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function hasPathSegment(baseUrl, segment) {
|
|
74
|
+
const normalized = normalizeBaseUrl(baseUrl);
|
|
75
|
+
if (!normalized) return false;
|
|
76
|
+
try {
|
|
77
|
+
const parsed = new URL(normalized);
|
|
78
|
+
const pathname = String(parsed.pathname || '').toLowerCase();
|
|
79
|
+
const escaped = String(segment || '').replace(/[.*+?^${}()|[\]\\]/g, '\\$&').toLowerCase();
|
|
80
|
+
return new RegExp(`(^|/)${escaped}(/|$)`).test(pathname);
|
|
81
|
+
} catch (_) {
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function getBaseUrlHost(baseUrl) {
|
|
87
|
+
const normalized = normalizeBaseUrl(baseUrl);
|
|
88
|
+
if (!normalized) return '';
|
|
89
|
+
try {
|
|
90
|
+
const parsed = new URL(normalized);
|
|
91
|
+
return String(parsed.hostname || '').toLowerCase();
|
|
92
|
+
} catch (_) {
|
|
93
|
+
return '';
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function isHostOrSubdomain(host, domain) {
|
|
98
|
+
return host === domain || host.endsWith(`.${domain}`);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function isBigModelClaudeCompatibleBaseUrl(baseUrl) {
|
|
102
|
+
const host = getBaseUrlHost(baseUrl);
|
|
103
|
+
return isHostOrSubdomain(host, 'bigmodel.cn') && hasPathSegment(baseUrl, 'anthropic');
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function isAnthropicBaseUrl(baseUrl) {
|
|
107
|
+
const host = getBaseUrlHost(baseUrl);
|
|
108
|
+
return isHostOrSubdomain(host, 'anthropic.com');
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function isDeepSeekClaudeCompatibleBaseUrl(baseUrl) {
|
|
112
|
+
const host = getBaseUrlHost(baseUrl);
|
|
113
|
+
return isHostOrSubdomain(host, 'deepseek.com') && hasPathSegment(baseUrl, 'anthropic');
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function isQwenClaudeCompatibleBaseUrl(baseUrl) {
|
|
117
|
+
const host = getBaseUrlHost(baseUrl);
|
|
118
|
+
return isHostOrSubdomain(host, 'dashscope.aliyuncs.com') && hasPathSegment(baseUrl, 'anthropic');
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function isZaiClaudeCompatibleBaseUrl(baseUrl) {
|
|
122
|
+
const host = getBaseUrlHost(baseUrl);
|
|
123
|
+
return isHostOrSubdomain(host, 'z.ai') && hasPathSegment(baseUrl, 'anthropic');
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function isModelScopeBaseUrl(baseUrl) {
|
|
127
|
+
const host = getBaseUrlHost(baseUrl);
|
|
128
|
+
return isHostOrSubdomain(host, 'modelscope.cn');
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function getSupplementalModelsForBaseUrl(baseUrl) {
|
|
132
|
+
if (isBigModelClaudeCompatibleBaseUrl(baseUrl)) {
|
|
133
|
+
return [...BIGMODEL_CLAUDE_COMPAT_MODELS];
|
|
134
|
+
}
|
|
135
|
+
if (isAnthropicBaseUrl(baseUrl)) {
|
|
136
|
+
return [...ANTHROPIC_CLAUDE_MODELS];
|
|
137
|
+
}
|
|
138
|
+
if (isDeepSeekClaudeCompatibleBaseUrl(baseUrl)) {
|
|
139
|
+
return [...DEEPSEEK_CLAUDE_COMPAT_MODELS];
|
|
140
|
+
}
|
|
141
|
+
if (isQwenClaudeCompatibleBaseUrl(baseUrl)) {
|
|
142
|
+
return [...QWEN_CLAUDE_COMPAT_MODELS];
|
|
143
|
+
}
|
|
144
|
+
if (isZaiClaudeCompatibleBaseUrl(baseUrl)) {
|
|
145
|
+
return [...BIGMODEL_CLAUDE_COMPAT_MODELS];
|
|
146
|
+
}
|
|
147
|
+
if (isModelScopeBaseUrl(baseUrl)) {
|
|
148
|
+
return [...MODELSCOPE_CLAUDE_COMPAT_MODELS];
|
|
149
|
+
}
|
|
150
|
+
return [];
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
function mergeModelCatalog(remoteModels = [], supplementalModels = []) {
|
|
154
|
+
const merged = [];
|
|
155
|
+
const seen = new Set();
|
|
156
|
+
const push = (value) => {
|
|
157
|
+
if (typeof value !== 'string') return;
|
|
158
|
+
const trimmed = value.trim();
|
|
159
|
+
if (!trimmed) return;
|
|
160
|
+
const normalized = normalizeModelCatalogId(trimmed);
|
|
161
|
+
if (!normalized || seen.has(normalized)) return;
|
|
162
|
+
seen.add(normalized);
|
|
163
|
+
merged.push(trimmed);
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
for (const item of remoteModels) push(item);
|
|
167
|
+
for (const item of supplementalModels) push(item);
|
|
168
|
+
return merged;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
function extractModelNames(payload) {
|
|
172
|
+
if (!payload || typeof payload !== 'object') return [];
|
|
173
|
+
const data = Array.isArray(payload.data)
|
|
174
|
+
? payload.data
|
|
175
|
+
: (Array.isArray(payload.models) ? payload.models : []);
|
|
176
|
+
const names = [];
|
|
177
|
+
for (const item of data) {
|
|
178
|
+
if (typeof item === 'string') {
|
|
179
|
+
if (item.trim()) names.push(item.trim());
|
|
180
|
+
continue;
|
|
181
|
+
}
|
|
182
|
+
if (!item || typeof item !== 'object') continue;
|
|
183
|
+
const name = item.id || item.name || item.model || '';
|
|
184
|
+
if (typeof name === 'string' && name.trim()) {
|
|
185
|
+
names.push(name.trim());
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
return Array.from(new Set(names));
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
function hasModelsListPayload(payload) {
|
|
192
|
+
if (!payload || typeof payload !== 'object') return false;
|
|
193
|
+
return Array.isArray(payload.data) || Array.isArray(payload.models);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
function extractModelIds(payload) {
|
|
197
|
+
const ids = [];
|
|
198
|
+
const pushValue = (value) => {
|
|
199
|
+
if (typeof value === 'string' && value.trim()) {
|
|
200
|
+
ids.push(value.trim());
|
|
201
|
+
}
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
if (!payload) return ids;
|
|
205
|
+
|
|
206
|
+
if (Array.isArray(payload)) {
|
|
207
|
+
for (const item of payload) {
|
|
208
|
+
if (item && typeof item === 'object') {
|
|
209
|
+
pushValue(item.id);
|
|
210
|
+
pushValue(item.model);
|
|
211
|
+
pushValue(item.name);
|
|
212
|
+
} else {
|
|
213
|
+
pushValue(item);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
return ids;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
if (Array.isArray(payload.data)) {
|
|
220
|
+
for (const item of payload.data) {
|
|
221
|
+
if (item && typeof item === 'object') {
|
|
222
|
+
pushValue(item.id);
|
|
223
|
+
pushValue(item.model);
|
|
224
|
+
pushValue(item.name);
|
|
225
|
+
} else {
|
|
226
|
+
pushValue(item);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
if (Array.isArray(payload.models)) {
|
|
232
|
+
for (const item of payload.models) {
|
|
233
|
+
if (item && typeof item === 'object') {
|
|
234
|
+
pushValue(item.id);
|
|
235
|
+
pushValue(item.model);
|
|
236
|
+
pushValue(item.name);
|
|
237
|
+
} else {
|
|
238
|
+
pushValue(item);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
return ids;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
function normalizeWireApi(value) {
|
|
247
|
+
const raw = typeof value === 'string' ? value.trim().toLowerCase() : '';
|
|
248
|
+
if (!raw) return 'responses';
|
|
249
|
+
return raw.replace(/[\s\-\/]/g, '_');
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
function buildApiProbeUrlCandidates(baseUrl, pathSuffix) {
|
|
253
|
+
const normalized = normalizeBaseUrl(baseUrl);
|
|
254
|
+
if (!normalized) return [];
|
|
255
|
+
|
|
256
|
+
const safeSuffix = String(pathSuffix || '').replace(/^\/+/g, '');
|
|
257
|
+
if (!safeSuffix) return [normalized];
|
|
258
|
+
|
|
259
|
+
const candidates = [];
|
|
260
|
+
const pushUnique = (value) => {
|
|
261
|
+
if (value && !candidates.includes(value)) {
|
|
262
|
+
candidates.push(value);
|
|
263
|
+
}
|
|
264
|
+
};
|
|
265
|
+
|
|
266
|
+
let pathname = '';
|
|
267
|
+
try {
|
|
268
|
+
pathname = new URL(normalized).pathname.replace(/\/+$/g, '');
|
|
269
|
+
} catch (e) {
|
|
270
|
+
pathname = '';
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
const directUrl = `${normalized}/${safeSuffix}`;
|
|
274
|
+
const versionedUrl = joinApiUrl(normalized, safeSuffix);
|
|
275
|
+
if (/\/v\d+$/i.test(pathname)) {
|
|
276
|
+
pushUnique(directUrl);
|
|
277
|
+
return candidates;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
if (!pathname || pathname === '/') {
|
|
281
|
+
pushUnique(versionedUrl);
|
|
282
|
+
pushUnique(directUrl);
|
|
283
|
+
return candidates;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
pushUnique(directUrl);
|
|
287
|
+
pushUnique(versionedUrl);
|
|
288
|
+
return candidates;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
function buildModelsProbeUrl(baseUrl) {
|
|
292
|
+
return buildApiProbeUrlCandidates(baseUrl, 'models')[0] || '';
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
function buildModelProbeSpecs(provider, modelName, baseUrl) {
|
|
296
|
+
const model = typeof modelName === 'string' ? modelName.trim() : '';
|
|
297
|
+
if (!model) return [];
|
|
298
|
+
|
|
299
|
+
const wireApi = normalizeWireApi(provider && provider.wire_api);
|
|
300
|
+
let pathSuffix = 'responses';
|
|
301
|
+
let body = {
|
|
302
|
+
model,
|
|
303
|
+
input: 'ping',
|
|
304
|
+
max_output_tokens: 1
|
|
305
|
+
};
|
|
306
|
+
|
|
307
|
+
if (wireApi === 'chat_completions' || wireApi === 'chat') {
|
|
308
|
+
pathSuffix = 'chat/completions';
|
|
309
|
+
body = {
|
|
310
|
+
model,
|
|
311
|
+
messages: [{ role: 'user', content: 'ping' }],
|
|
312
|
+
max_tokens: 1,
|
|
313
|
+
temperature: 0
|
|
314
|
+
};
|
|
315
|
+
} else if (wireApi === 'completions') {
|
|
316
|
+
pathSuffix = 'completions';
|
|
317
|
+
body = {
|
|
318
|
+
model,
|
|
319
|
+
prompt: 'ping',
|
|
320
|
+
max_tokens: 1,
|
|
321
|
+
temperature: 0
|
|
322
|
+
};
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
return buildApiProbeUrlCandidates(baseUrl, pathSuffix).map((url) => ({
|
|
326
|
+
url,
|
|
327
|
+
body
|
|
328
|
+
}));
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
function buildModelProbeSpec(provider, modelName, baseUrl) {
|
|
332
|
+
return buildModelProbeSpecs(provider, modelName, baseUrl)[0] || null;
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
function collectStructuredText(content, pieces) {
|
|
336
|
+
if (typeof content === 'string') {
|
|
337
|
+
const text = content.trim();
|
|
338
|
+
if (text) pieces.push(text);
|
|
339
|
+
return;
|
|
340
|
+
}
|
|
341
|
+
if (Array.isArray(content)) {
|
|
342
|
+
for (const item of content) {
|
|
343
|
+
collectStructuredText(item, pieces);
|
|
344
|
+
}
|
|
345
|
+
return;
|
|
346
|
+
}
|
|
347
|
+
if (!content || typeof content !== 'object') {
|
|
348
|
+
return;
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
if (typeof content.output_text === 'string' && content.output_text.trim()) {
|
|
352
|
+
pieces.push(content.output_text.trim());
|
|
353
|
+
}
|
|
354
|
+
if (typeof content.text === 'string' && content.text.trim()) {
|
|
355
|
+
pieces.push(content.text.trim());
|
|
356
|
+
}
|
|
357
|
+
if (typeof content.content === 'string' && content.content.trim()) {
|
|
358
|
+
pieces.push(content.content.trim());
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
if (Array.isArray(content.content)) {
|
|
362
|
+
collectStructuredText(content.content, pieces);
|
|
363
|
+
}
|
|
364
|
+
if (content.message) {
|
|
365
|
+
collectStructuredText(content.message, pieces);
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
function extractModelResponseText(payload) {
|
|
370
|
+
if (!payload || typeof payload !== 'object') {
|
|
371
|
+
return '';
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
if (typeof payload.output_text === 'string' && payload.output_text.trim()) {
|
|
375
|
+
return payload.output_text.trim();
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
const pieces = [];
|
|
379
|
+
|
|
380
|
+
if (Array.isArray(payload.output)) {
|
|
381
|
+
for (const item of payload.output) {
|
|
382
|
+
collectStructuredText(item, pieces);
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
if (Array.isArray(payload.choices)) {
|
|
387
|
+
for (const choice of payload.choices) {
|
|
388
|
+
if (!choice || typeof choice !== 'object') continue;
|
|
389
|
+
if (typeof choice.text === 'string' && choice.text.trim()) {
|
|
390
|
+
pieces.push(choice.text.trim());
|
|
391
|
+
}
|
|
392
|
+
if (choice.message) {
|
|
393
|
+
collectStructuredText(choice.message, pieces);
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
if (payload.message) {
|
|
399
|
+
collectStructuredText(payload.message, pieces);
|
|
400
|
+
}
|
|
401
|
+
if (payload.content) {
|
|
402
|
+
collectStructuredText(payload.content, pieces);
|
|
403
|
+
}
|
|
404
|
+
if (typeof payload.text === 'string' && payload.text.trim()) {
|
|
405
|
+
pieces.push(payload.text.trim());
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
return Array.from(new Set(pieces)).join('\n\n').trim();
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
function hashModelsCacheValue(value) {
|
|
412
|
+
if (!value) return '';
|
|
413
|
+
try {
|
|
414
|
+
return crypto.createHash('sha256').update(String(value)).digest('hex');
|
|
415
|
+
} catch (e) {
|
|
416
|
+
return '';
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
function buildModelsCacheKey(baseUrl, apiKey) {
|
|
421
|
+
const normalizedUrl = normalizeBaseUrl(baseUrl);
|
|
422
|
+
const apiKeyHash = hashModelsCacheValue(apiKey);
|
|
423
|
+
return `${normalizedUrl}|${apiKeyHash}`;
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
module.exports = {
|
|
427
|
+
extractModelNames,
|
|
428
|
+
hasModelsListPayload,
|
|
429
|
+
extractModelIds,
|
|
430
|
+
normalizeWireApi,
|
|
431
|
+
buildApiProbeUrlCandidates,
|
|
432
|
+
buildModelsProbeUrl,
|
|
433
|
+
buildModelProbeSpecs,
|
|
434
|
+
buildModelProbeSpec,
|
|
435
|
+
extractModelResponseText,
|
|
436
|
+
hashModelsCacheValue,
|
|
437
|
+
buildModelsCacheKey,
|
|
438
|
+
getSupplementalModelsForBaseUrl,
|
|
439
|
+
mergeModelCatalog
|
|
440
|
+
};
|