codex-copilot-dx 1.2.18 → 1.2.20
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 +3 -3
- package/docs/ARCHITECTURE.md +47 -4
- package/docs/REFERENCE.md +59 -8
- package/package.json +1 -1
- package/src/access-settings.mjs +3 -1
- package/src/api-catalog-refresh.mjs +72 -0
- package/src/api-target.mjs +10 -0
- package/src/client-model-plan.mjs +14 -37
- package/src/clients/claude-models.mjs +20 -0
- package/src/clients/codex-models.mjs +22 -0
- package/src/connection-runtime.mjs +73 -35
- package/src/dashboard/connections.js +103 -40
- package/src/dashboard/console.js +2 -2
- package/src/dashboard/index.html +16 -16
- package/src/dashboard/language.js +16 -3
- package/src/dashboard/status.js +6 -4
- package/src/dashboard/tools.js +1 -1
- package/src/dashboard/ui.css +21 -1
- package/src/model-capabilities.mjs +21 -11
- package/src/provider-metadata.mjs +4 -4
- package/src/providers/api-model-metadata.mjs +36 -0
- package/src/providers/api-network.mjs +3 -2
- package/src/providers/api.mjs +26 -18
- package/src/windows-http-network.mjs +2 -1
- package/src/windows-prediction-network.cs +7 -1
package/src/dashboard/index.html
CHANGED
|
@@ -64,16 +64,17 @@
|
|
|
64
64
|
<section class="panel dashboard-section"><h2 data-i18n="this_run_usage">THIS RUN</h2><p id="runtime-usage" class="table-note"></p><p class="table-note"><span data-i18n="approx_cache_hit_rate">Approx. cache hit rate</span>: <strong id="runtime-cache-hit" data-i18n-title="runtime_cache_hit_basis" title="Reused input / input tokens. ~ Partial counts. — Unknown or invalid.">—</strong></p><p class="hint" data-i18n="updated_from_returned_usage_not_a_live_bill_pending_usage_is_not">Counts returned usage only. Pending usage is not included. This is not a live bill.</p></section>
|
|
65
65
|
</div>
|
|
66
66
|
<div data-view="codex" hidden>
|
|
67
|
-
<div id="codex-model-management"> <section class="
|
|
68
|
-
<
|
|
67
|
+
<div id="codex-model-management"> <section class="connection-access" id="connection-clients">
|
|
68
|
+
<div id="connection-client-list"></div>
|
|
69
69
|
<details id="connection-disabled-clients" class="connection-disabled" hidden><summary data-i18n="api_disabled_clients">Disabled clients</summary><div id="connection-disabled-client-list"></div></details>
|
|
70
70
|
</section>
|
|
71
71
|
<section class="panel dashboard-section" id="connection-client-editor" hidden aria-labelledby="connection-client-title">
|
|
72
|
-
<div class="panel-heading"><h2 id="connection-client-title"></h2><
|
|
72
|
+
<div class="panel-heading"><h2 id="connection-client-title"></h2><span id="connection-draft-state" class="hint"></span></div>
|
|
73
73
|
<form id="connection-client-form">
|
|
74
|
-
<
|
|
74
|
+
<p id="connection-default-note" class="hint" role="status" hidden></p>
|
|
75
|
+
<div class="table-wrap"><table class="binding-table"><thead><tr><th data-i18n="model">Model</th><th data-i18n="source">Source</th><th data-i18n="cap_context">Context</th><th data-i18n="cap_reasoning">Reasoning</th><th data-i18n="cap_default">Default</th></tr></thead><tbody id="connection-bindings"></tbody></table></div>
|
|
75
76
|
<div class="setting-row"><label for="connection-auto-sync" data-i18n="cap_auto_sync">Sync model settings</label><input id="connection-auto-sync" type="checkbox" role="switch" checked><span class="hint" data-i18n="cap_sync_scope">Preserves your manual settings.</span></div>
|
|
76
|
-
<div class="section-actions"><button type="submit" data-i18n="api_save">Save</button><button type="button" id="connection-sync-preview" data-i18n="cap_sync_preview">Review sync</button></div>
|
|
77
|
+
<div class="section-actions"><button type="submit" data-i18n="api_save">Save</button><button type="button" id="connection-client-cancel" data-i18n="cap_discard_changes">Discard changes</button><button type="button" id="connection-sync-preview" data-i18n="cap_sync_preview">Review sync</button></div>
|
|
77
78
|
<p id="connection-client-note" class="hint" role="status" aria-live="polite"></p>
|
|
78
79
|
<div id="connection-sync-result" hidden></div>
|
|
79
80
|
</form>
|
|
@@ -144,25 +145,26 @@
|
|
|
144
145
|
<div data-view="claude" hidden>
|
|
145
146
|
<div class="provider-tabs client-segments" role="group" aria-label="Claude app"><button type="button" data-claude-client="claude_app" aria-pressed="true">Claude App</button><button type="button" data-claude-client="claude_code" aria-pressed="false">Claude Code</button></div>
|
|
146
147
|
<div id="claude-model-management"></div>
|
|
147
|
-
<
|
|
148
|
-
<
|
|
148
|
+
<details class="panel dashboard-section" id="claude-connections">
|
|
149
|
+
<summary data-i18n="connection_details">Connection details</summary>
|
|
149
150
|
<div class="table-wrap"><table><thead><tr><th data-i18n="client">APP</th><th data-i18n="connection_setup" data-i18n-title="configured_not_successful">Setup</th><th data-i18n="local_bridge">Local service</th><th data-i18n="last_request">LAST REQUEST</th></tr></thead><tbody id="claude-clients"></tbody></table></div>
|
|
150
151
|
<p id="claude-client-state" class="hint"></p>
|
|
151
152
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
<
|
|
155
|
-
<
|
|
153
|
+
<p id="claude-route" class="table-note"></p><p>Anthropic Messages</p><a class="section-link" href="#models" data-i18n="model_services">Model sources</a>
|
|
154
|
+
</details>
|
|
155
|
+
<details class="panel dashboard-section" id="claude-performance">
|
|
156
|
+
<summary data-i18n="request_performance">REQUEST PERFORMANCE</summary>
|
|
156
157
|
<dl class="stats"><div><dt data-i18n="completed">Completed</dt><dd id="claude-completed">—</dd></div><div><dt data-i18n="incomplete">Incomplete</dt><dd id="claude-incomplete">—</dd></div><div><dt data-i18n="failed">Failed</dt><dd id="claude-failed">—</dd></div><div><dt data-i18n="cancelled">Cancelled</dt><dd id="claude-cancelled">—</dd></div><div><dt data-i18n="first_output">First output</dt><dd id="claude-ttft">—</dd></div><div><dt data-i18n="output_speed">Output speed</dt><dd id="claude-speed">—</dd></div></dl>
|
|
157
158
|
|
|
158
159
|
|
|
159
160
|
<dl class="stats timing-stats"><div><dt data-i18n="estimated_percentiles" data-i18n-title="percentile_basis">Approx. first-output P50 / P95</dt><dd id="claude-ttft-percentiles">—</dd></div></dl>
|
|
160
161
|
<a class="section-link" href="#requests" data-i18n="view_request_details">View request details</a>
|
|
161
|
-
</
|
|
162
|
+
</details>
|
|
162
163
|
</div>
|
|
163
164
|
<div data-view="models" hidden>
|
|
164
165
|
<section class="panel dashboard-section" id="connection-sources">
|
|
165
166
|
<div class="panel-heading"><h2 data-i18n="model_services">Model sources</h2><button id="connection-add" type="button" data-i18n="api_add">Add API</button></div>
|
|
167
|
+
<div id="model-providers" class="provider-tabs" role="tablist" aria-label="Model providers" data-i18n-label="model_providers"></div>
|
|
166
168
|
<div id="connection-source-list"></div>
|
|
167
169
|
<details id="connection-disabled-sources" class="connection-disabled" hidden><summary data-i18n="api_disabled_sources">Disabled sources</summary><div id="connection-disabled-source-list"></div></details>
|
|
168
170
|
</section>
|
|
@@ -181,7 +183,7 @@
|
|
|
181
183
|
<label><span data-i18n="api_key_env">Read key from environment</span><input name="key_env" type="text" autocomplete="off" spellcheck="false" placeholder="CCDX_COMPANY_API_KEY"><span class="hint" data-i18n="api_key_env_hint">Optional for servers without a credential service. Set before starting CCDX.</span></label>
|
|
182
184
|
</div></details>
|
|
183
185
|
<fieldset><legend data-i18n="api_allowed_clients">Allowed clients</legend><div class="connection-checks" id="connection-allowed-clients"></div></fieldset>
|
|
184
|
-
<fieldset><legend data-i18n="model_catalog">Model list</legend><div class="section-actions"><button type="button" id="connection-discover" data-i18n="api_read_models">Read models</button><span class="hint" data-i18n="api_discovery_save_first">Save the API first. No chat request is sent.</span></div>
|
|
186
|
+
<fieldset><legend data-i18n="model_catalog">Model list</legend><div class="section-actions"><button type="button" id="connection-discover" data-i18n="api_read_models">Read models</button><button type="button" id="connection-discover-cancel" data-i18n="cancel" hidden>Cancel</button><span class="hint" data-i18n="api_discovery_save_first">Save the API first. No chat request is sent.</span></div>
|
|
185
187
|
<details class="tool-details" id="connection-manual-model"><summary data-i18n="api_manual_model">Add a model manually</summary><div class="section-actions"><input type="text" id="connection-model-id" spellcheck="false" autocomplete="off" aria-label="Model ID" placeholder="Model ID"><button type="button" id="connection-model-add" data-i18n="api_add_model">Add model</button></div></details>
|
|
186
188
|
<p class="hint" data-i18n="api_model_protocol_hint">Choose the APIs each model supports.</p><div class="table-wrap"><table><thead><tr><th data-i18n="model">Model</th><th data-i18n="api_protocols">Available APIs</th><th data-i18n="cap_context">Context</th><th data-i18n="cap_reasoning">Reasoning</th><th data-i18n="cap_search">Search</th><th></th></tr></thead><tbody id="connection-models"></tbody></table></div>
|
|
187
189
|
</fieldset>
|
|
@@ -193,8 +195,6 @@
|
|
|
193
195
|
<p id="connection-note" class="hint" role="status" aria-live="polite"></p>
|
|
194
196
|
|
|
195
197
|
|
|
196
|
-
<div id="model-providers" class="provider-tabs" role="tablist" aria-label="Model providers" data-i18n-label="model_providers"></div>
|
|
197
|
-
|
|
198
198
|
<div id="source-account-panel" role="tabpanel">
|
|
199
199
|
<p id="source-status-note" class="hint" role="status"></p>
|
|
200
200
|
<section class="panel dashboard-section" id="github-account">
|
|
@@ -231,7 +231,7 @@
|
|
|
231
231
|
<p id="m365-account-note" class="hint" role="status" aria-live="polite"></p>
|
|
232
232
|
</section>
|
|
233
233
|
<details class="panel dashboard-section model-catalog" id="upstream-models" open>
|
|
234
|
-
<summary class="panel-heading"><h2 data-i18n="model_catalog">MODEL LIST</h2><span id="models-state" data-i18n="checking_live">CHECKING</span></summary>
|
|
234
|
+
<summary class="panel-heading"><h2 data-i18n="model_catalog">MODEL LIST</h2><span id="models-state" role="status" aria-live="polite" data-i18n="checking_live">CHECKING</span></summary>
|
|
235
235
|
<div class="section-actions"><button id="refresh-models" type="button" data-i18n="refresh">Refresh</button></div>
|
|
236
236
|
<p id="models-note" class="table-note" data-i18n="reading_provider_catalog">Loading model list…</p>
|
|
237
237
|
<details id="model-check-details" class="model-check-details" hidden><summary data-i18n="source_check_details">Check details</summary><dl id="model-check-fields" class="failure-detail"></dl></details>
|
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
(() => {
|
|
2
2
|
const translations = {
|
|
3
|
+
"api_saving": ["Saving…", "保存中…"],
|
|
4
|
+
"api_reading": ["Reading…", "读取中…"],
|
|
5
|
+
"api_read_cancelled": ["Read cancelled. Saved metadata is kept.", "已取消读取,保留已存资料。"],
|
|
6
|
+
"cap_unsaved": ["Unsaved changes", "尚未保存"],
|
|
7
|
+
"cap_saved": ["Saved", "已保存"],
|
|
8
|
+
"cap_default_unavailable": ["Default model unavailable. Choose a default before saving.", "默认模型暂不可用,请选择默认后保存。"],
|
|
9
|
+
"cap_limit_default_model_unavailable": ["Default model unavailable. Existing app settings were kept.", "默认模型暂不可用,保留应用设置。"],
|
|
3
10
|
"cap_discard_changes": ["Discard changes", "放弃修改"],
|
|
4
11
|
"cap_current_budget": ["Current budget", "当前预算"],
|
|
5
12
|
"cap_proposed_budget": ["After sync", "同步后预算"],
|
|
@@ -14,7 +21,7 @@
|
|
|
14
21
|
"cap_set_default": ["Set default", "设为默认"],
|
|
15
22
|
"cap_details": ["Details", "能力详情"],
|
|
16
23
|
"cap_app_access": ["App access", "应用接入"],
|
|
17
|
-
"cap_unknown": ["Not
|
|
24
|
+
"cap_unknown": ["Not provided", "未提供"],
|
|
18
25
|
"cap_supported": ["Supported", "支持"],
|
|
19
26
|
"cap_unsupported": ["Not supported", "不支持"],
|
|
20
27
|
"cap_auto_sync": ["Sync model settings", "同步模型设置"],
|
|
@@ -24,7 +31,12 @@
|
|
|
24
31
|
"cap_follow_catalog": ["Use catalog value", "跟随目录"],
|
|
25
32
|
"cap_manual": ["Manual override", "手动设置"],
|
|
26
33
|
"cap_catalog": ["Declared by this API", "此 API 目录声明"],
|
|
27
|
-
"cap_metadata_scope": ["
|
|
34
|
+
"cap_metadata_scope": ["Overrides apply to this model's configured APIs. Leave blank to use upstream values.", "手动值适用于此模型的已选接口;留空跟随上游。"],
|
|
35
|
+
"cap_api": ["API", "接口"],
|
|
36
|
+
"cap_input_types": ["Input types", "输入类型"],
|
|
37
|
+
"cap_catalog_reported": ["Read from upstream", "已从上游读取"],
|
|
38
|
+
"cap_catalog_missing": ["Upstream did not provide capabilities", "上游未提供能力资料"],
|
|
39
|
+
"cap_catalog_unrecognized": ["Upstream capability format not recognized", "暂未识别上游能力格式"],
|
|
28
40
|
"cap_apply_details": ["Apply to draft", "应用到草稿"],
|
|
29
41
|
"cap_details_draft": ["Details updated. Save the source to apply.", "能力已加入草稿,请保存来源。"],
|
|
30
42
|
"cap_preview_scope": ["Save to apply. Restart Claude after its settings change.", "保存后同步;Claude 配置更新后需重启。"],
|
|
@@ -51,6 +63,7 @@
|
|
|
51
63
|
"cap_field_reasoning_budget_max": ["Maximum reasoning budget", "最大推理预算"],
|
|
52
64
|
"cap_field_reasoning_efforts": ["Reasoning levels (comma separated)", "推理等级(逗号分隔)"],
|
|
53
65
|
"cap_field_reasoning_format": ["Reasoning API", "推理参数接口"],
|
|
66
|
+
"cap_field_thinking_modes": ["Thinking modes", "思考模式"],
|
|
54
67
|
"cap_field_input_modalities": ["Input types (text, image, …)", "输入类型(text、image 等)"],
|
|
55
68
|
"cap_field_tools": ["Tool calls", "工具调用"],
|
|
56
69
|
"cap_field_parallel_tools": ["Parallel tool calls", "并行工具调用"],
|
|
@@ -96,7 +109,7 @@
|
|
|
96
109
|
"api_client_disabled": ["CCDX access is off; the app stays open.", "接入已关闭,应用保持运行。"],
|
|
97
110
|
"api_close_client": ["Disable client access", "关闭客户端接入"],
|
|
98
111
|
"api_saved": ["Saved. Reopen the app for first-time setup; existing requests stay unchanged.", "已保存。首次接入请重新打开应用。"],
|
|
99
|
-
"api_config_saved": ["API saved.
|
|
112
|
+
"api_config_saved": ["API saved. Metadata refresh runs separately.", "API 已保存,模型资料另行刷新。"],
|
|
100
113
|
"api_provider_disabled": ["Source disabled. Its configuration was kept.", "来源已关闭,配置已保留。"],
|
|
101
114
|
"api_provider_enabled": ["Source enabled. Client selections are unchanged.", "来源已开启,客户端来源未改变。"],
|
|
102
115
|
"api_client_enabled": ["Client enabled. Choose a source to connect.", "客户端已开启,请选择来源。"],
|
package/src/dashboard/status.js
CHANGED
|
@@ -6,11 +6,12 @@
|
|
|
6
6
|
let contextSignature;
|
|
7
7
|
const sourceNames = new Map([["github", "GitHub Copilot"], ["m365", "Microsoft 365"]]);
|
|
8
8
|
|
|
9
|
+
const sourceLabel = id => globalThis.ccdxConnectionNames?.[id] || sourceNames.get(id) || id;
|
|
9
10
|
function renderProviders(data) {
|
|
10
11
|
const providers = data.providers || [];
|
|
11
12
|
const states = { saved: "saved_locally", authorized: "authorized", disabled: "disabled", unavailable: "unavailable_ca184",
|
|
12
13
|
unknown: "unknown", unconfigured: "not_configured", ready: "ready", checking: "checking", unsupported: "unsupported",
|
|
13
|
-
configured: "configured", preserved: "existing_settings_kept", partially_preserved: "existing_settings_kept",
|
|
14
|
+
configured: "configured", default_unavailable: "cap_default_unavailable", preserved: "existing_settings_kept", partially_preserved: "existing_settings_kept",
|
|
14
15
|
restored: "settings_restored", not_installed: "not_installed", configuration_unavailable: "setup_unavailable", not_configured: "unknown", standby: "standby" };
|
|
15
16
|
const auth = element("provider-auth"), clients = element("provider-clients"), requests = element("provider-requests"), claudeClients = element("claude-clients");
|
|
16
17
|
auth.replaceChildren();clients.replaceChildren();requests.replaceChildren();claudeClients?.replaceChildren();
|
|
@@ -129,7 +130,7 @@
|
|
|
129
130
|
const timeline = failure.timeline;
|
|
130
131
|
const provider = failure.provider || timeline?.provider;
|
|
131
132
|
if (provider) {
|
|
132
|
-
const source =
|
|
133
|
+
const source = sourceLabel(provider);
|
|
133
134
|
const original = phrase("detail_retry", summary);
|
|
134
135
|
localize(title, "source_failure_summary", { source, detail: original });
|
|
135
136
|
}
|
|
@@ -182,6 +183,7 @@
|
|
|
182
183
|
}
|
|
183
184
|
|
|
184
185
|
function render(data) {
|
|
186
|
+
for (const source of data.providers?.connections?.providers || []) sourceNames.set(source.id, source.name);
|
|
185
187
|
globalThis.ccdxDashboardActivity?.update(data.model_activity);
|
|
186
188
|
globalThis.ccdxDashboardFlow?.update(data);
|
|
187
189
|
text("version", `v${data.version || "?"}`);
|
|
@@ -233,7 +235,7 @@
|
|
|
233
235
|
const routes = { ...data.stream_performance?.by_route, ...claudeMetrics?.by_route };
|
|
234
236
|
for (const [protocol, route] of Object.entries(routes)) for (const [source, stats] of Object.entries(route.by_provider || {})) {
|
|
235
237
|
const totals = stats.terminal_outcomes.totals;
|
|
236
|
-
sourceBody.append(tableRow([
|
|
238
|
+
sourceBody.append(tableRow([sourceLabel(source), protocol, number(stats.active), ...["completed", "incomplete", "failed", "cancelled", "unknown"].map(outcome => number(totals[outcome]))]));
|
|
237
239
|
}
|
|
238
240
|
if (!sourceBody.children.length) emptyTable("source-requests-body", 8, "no_requests_observed");
|
|
239
241
|
}
|
|
@@ -300,7 +302,7 @@
|
|
|
300
302
|
? `${(100 * Number(context.input_tokens) / Number(context.context_window_tokens)).toFixed(1)}%` : "—";
|
|
301
303
|
const at = Date.parse(request.at);
|
|
302
304
|
const row = tableRow([Number.isFinite(at) ? time(at) : "—",
|
|
303
|
-
String(
|
|
305
|
+
String(sourceLabel(request.provider) || "—").slice(0, 80),
|
|
304
306
|
String(request.model || "unknown").slice(0, 80), outcome, number(context.input_tokens), ""], { labels: [3] });
|
|
305
307
|
const wireFailure = Number.isInteger(request.http_status) && request.http_status >= 400;
|
|
306
308
|
if (globalThis.ccdxIcons) globalThis.ccdxIcons.set(row.children[3], wireFailure ? "request_http_failure" : outcome.toLowerCase(),
|
package/src/dashboard/tools.js
CHANGED
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
function field(list, key, value, kind) {
|
|
17
17
|
const term = document.createElement("dt"), detail = document.createElement("dd");label(term, key);
|
|
18
18
|
if (kind) globalThis.ccdxIcons.set(detail, value, kind);else detail.textContent = value;
|
|
19
|
-
list.append(term, detail);
|
|
19
|
+
if (list.classList.contains("account-summary")) { const pair = document.createElement("div");pair.append(term, detail);list.append(pair); }else list.append(term, detail);
|
|
20
20
|
}
|
|
21
21
|
function syncSource() {
|
|
22
22
|
const github = selectedProvider === "github";
|
package/src/dashboard/ui.css
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
:root { color-scheme: dark; font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace; --page: #0b110d; --surface: #111a13; --text: #e0e9df; --strong: #f0f6ec; --muted: #9aada0; --badge: #a9b9aa; --subtle: #78917d; --quiet: #
|
|
1
|
+
:root { color-scheme: dark; font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace; --page: #0b110d; --surface: #111a13; --text: #e0e9df; --strong: #f0f6ec; --muted: #9aada0; --badge: #a9b9aa; --subtle: #78917d; --quiet: #819987; --footer: #7f9785; --border: #2b3b2f; --top-border: #2a3a2e; --accent: #a6f5a8; --accent-soft: #84e99e; --heading: #83b98b; --bad: #ff947e; --failed: #ff9f91; --incomplete: #e3c77c; --button-border: #45634b; --button-bg: #152219; --button-fg: #b2f1bd; --button-hover: #203526; --selected-bg: #192a1d; --option-hover: #1a2a1e; --table-text: #d8e2d8; --preview: #657d69; --ansi-white: #f5fff5; --ansi-159: #9af5e9; --ansi-123: #75e4d9; --ansi-87: #5ad0d4; --ansi-51: #42b9d8; --ansi-45: #3ca2d0; --ansi-39: #4389c2; --ansi-33: #4775b2; }
|
|
2
2
|
:root[data-theme="light"] { color-scheme: light; --page: #f5f8f3; --surface: #ffffff; --text: #1b2b20; --strong: #122219; --muted: #475d4e; --badge: #475d4e; --subtle: #4b6652; --quiet: #55715c; --footer: #59735f; --border: #c4d2c5; --top-border: #b8c9ba; --accent: #176b3a; --accent-soft: #176b3a; --heading: #235f37; --bad: #a33625; --failed: #a33625; --incomplete: #835600; --button-border: #79a085; --button-bg: #ebf4ec; --button-fg: #185b32; --button-hover: #dbeedd; --selected-bg: #e4f3e7; --option-hover: #edf6ee; --table-text: #233b2b; --preview: #596f60; --ansi-white: #234231; --ansi-159: #116b64; --ansi-123: #0d7771; --ansi-87: #116b75; --ansi-51: #14697e; --ansi-45: #1a6183; --ansi-39: #265f8d; --ansi-33: #365a8d; }
|
|
3
3
|
* { box-sizing: border-box; }
|
|
4
4
|
[hidden] { display: none !important; }
|
|
@@ -492,3 +492,23 @@ input[role="switch"]:disabled { opacity: .5; cursor: wait; }
|
|
|
492
492
|
.binding-table td:last-child button { min-width: 102px; white-space: nowrap; }
|
|
493
493
|
#connection-sync-result { margin-top: 20px; }
|
|
494
494
|
#connection-sync-result tr:last-child td { border-bottom: 0; }
|
|
495
|
+
|
|
496
|
+
.connection-access { margin: 0 0 12px; }
|
|
497
|
+
.connection-access .connection-row { padding: 0; min-height: 44px; }
|
|
498
|
+
#connection-sources .provider-tabs { margin: 18px 0 0; }
|
|
499
|
+
.binding-unavailable { display: block; margin-left: 22px; }
|
|
500
|
+
#connection-default-note { color: var(--incomplete); }
|
|
501
|
+
@media (max-width: 650px) {
|
|
502
|
+
.binding-table, .binding-table tbody { display: block; width: 100%; }
|
|
503
|
+
.binding-table thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
|
|
504
|
+
.binding-table tr { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 12px; padding: 12px 0; border-bottom: 1px solid var(--border); }
|
|
505
|
+
.binding-table tr:last-child { border-bottom: 0; }
|
|
506
|
+
.binding-table td { border: 0; padding: 0; min-width: 0; }
|
|
507
|
+
.binding-table td:first-child { grid-column: 1; min-width: 0; }
|
|
508
|
+
.binding-table td:first-child label { overflow-wrap: anywhere; }
|
|
509
|
+
.binding-table td[data-label] { grid-column: 1 / -1; color: var(--muted); }
|
|
510
|
+
.binding-table td[data-label]::before { content: attr(data-label) " · "; color: var(--subtle); }
|
|
511
|
+
.binding-table td:last-child { grid-column: 2; grid-row: 1; align-self: center; }
|
|
512
|
+
.binding-table td:last-child button { min-width: 88px; padding: 9px; }
|
|
513
|
+
.binding-table td[colspan] { grid-column: 1 / -1; }
|
|
514
|
+
}
|
|
@@ -4,14 +4,14 @@ export const MODEL_PROTOCOLS = Object.freeze(["messages", "responses", "chat"]);
|
|
|
4
4
|
export const REASONING_EFFORTS = Object.freeze(["none", "minimal", "low", "medium", "high", "xhigh", "max"]);
|
|
5
5
|
const limits = ["context_window", "max_input_tokens", "max_output_tokens", "reasoning_budget_min", "reasoning_budget_max"];
|
|
6
6
|
const flags = ["reasoning", "reasoning_required", "reasoning_adaptive", "tools", "parallel_tools", "streaming", "structured_output"];
|
|
7
|
-
export const CAPABILITY_FIELDS = Object.freeze([...limits, ...flags, "reasoning_efforts", "reasoning_format", "input_modalities", "web_search"]);
|
|
7
|
+
export const CAPABILITY_FIELDS = Object.freeze([...limits, ...flags, "reasoning_efforts", "reasoning_format", "thinking_modes", "input_modalities", "web_search"]);
|
|
8
8
|
const object = value => value && typeof value === "object" && !Array.isArray(value);
|
|
9
9
|
export function validCapabilities(value) {
|
|
10
10
|
return object(value) && Object.entries(value).every(([key, item]) => {
|
|
11
11
|
if (limits.includes(key)) return Number.isSafeInteger(item) && item > 0 && item <= 100000000;
|
|
12
12
|
if (flags.includes(key)) return typeof item === "boolean";
|
|
13
13
|
if (key === "reasoning_format") return MODEL_PROTOCOLS.includes(item);
|
|
14
|
-
const choices = key === "reasoning_efforts" ? REASONING_EFFORTS : key === "input_modalities" ? ["text", "image", "audio", "video", "file"] : key === "web_search" ? MODEL_PROTOCOLS : null;
|
|
14
|
+
const choices = key === "reasoning_efforts" ? REASONING_EFFORTS : key === "thinking_modes" ? ["disabled", "enabled", "adaptive", "between_tools"] : key === "input_modalities" ? ["text", "image", "audio", "video", "file"] : key === "web_search" ? MODEL_PROTOCOLS : null;
|
|
15
15
|
return choices && Array.isArray(item) && item.length <= choices.length && new Set(item).size === item.length && item.every(v => choices.includes(v));
|
|
16
16
|
}) && !(value.max_input_tokens && value.context_window && value.max_input_tokens > value.context_window)
|
|
17
17
|
&& !(value.reasoning_budget_min && value.reasoning_budget_max && value.reasoning_budget_min > value.reasoning_budget_max);
|
|
@@ -38,9 +38,9 @@ export function catalogCapabilities(model) {
|
|
|
38
38
|
max_output_tokens: first(model.max_output_tokens, window.max_output_tokens),
|
|
39
39
|
reasoning: first(typeof caps.reasoning === "boolean" ? caps.reasoning : undefined, supports.reasoning),
|
|
40
40
|
reasoning_efforts: first(model.reasoning_efforts, supports.reasoning_effort),
|
|
41
|
-
input_modalities: first(model.input_modalities, caps.input_modalities),
|
|
42
|
-
tools: supports.tools, parallel_tools: supports.parallel_tool_calls, streaming: supports.streaming,
|
|
43
|
-
structured_output: supports.structured_output, web_search: first(model.web_search, caps.web_search),
|
|
41
|
+
input_modalities: first(model.input_modalities, caps.input_modalities, supports.vision === true ? ["text", "image"] : undefined),
|
|
42
|
+
tools: first(supports.tools, supports.tool_calls), parallel_tools: supports.parallel_tool_calls, streaming: supports.streaming,
|
|
43
|
+
structured_output: first(supports.structured_output, supports.structured_outputs), web_search: first(model.web_search, caps.web_search), thinking_modes: first(model.thinking_modes, caps.thinking_modes),
|
|
44
44
|
...Object.fromEntries(["reasoning_required", "reasoning_adaptive", "reasoning_budget_min", "reasoning_budget_max", "reasoning_format"].map(key => [key, first(model[key], caps[key])])),
|
|
45
45
|
};
|
|
46
46
|
for (const [key, value] of Object.entries(candidate)) if (value !== undefined && validCapabilities({ [key]: value })) values[key] = value;
|
|
@@ -49,17 +49,24 @@ export function catalogCapabilities(model) {
|
|
|
49
49
|
return values;
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
export function resolveModelCapabilities(model, { revision, checkedAt = null, builtin = false } = {}) {
|
|
53
|
-
const
|
|
52
|
+
export function resolveModelCapabilities(model, { revision, checkedAt = null, builtin = false, protocol } = {}) {
|
|
53
|
+
const metadata = model.metadata?.deployment === revision ? model.metadata : null;
|
|
54
|
+
const fields = {}, declared = builtin ? catalogCapabilities(model) : { ...metadata?.values, ...metadata?.protocols?.[protocol] };
|
|
54
55
|
const put = (values, source, time) => { for (const [key, value] of Object.entries(values || {})) fields[key] = { value, source, checked_at: time }; };
|
|
55
56
|
put(declared, "catalog", builtin ? checkedAt : model.metadata?.checked_at || null);
|
|
56
|
-
|
|
57
|
-
...(model.
|
|
58
|
-
|
|
57
|
+
if (!builtin) {
|
|
58
|
+
put({ ...(model.context_window === undefined ? {} : { context_window: model.context_window }),
|
|
59
|
+
...(model.reasoning_efforts === undefined ? {} : { reasoning_efforts: model.reasoning_efforts }) }, "manual", null);
|
|
60
|
+
put(Object.fromEntries(Object.entries(model.capabilities || {}).filter(([key, value]) => validCapabilities({ [key]: value }))), "manual", null);
|
|
61
|
+
}
|
|
59
62
|
const values = Object.fromEntries(Object.entries(fields).map(([key, field]) => [key, field.value]));
|
|
63
|
+
if (protocol && values.reasoning_format && values.reasoning_format !== protocol) {
|
|
64
|
+
for (const key of ["reasoning", "reasoning_efforts", "reasoning_required", "reasoning_adaptive", "reasoning_budget_min", "reasoning_budget_max", "reasoning_format", "thinking_modes"]) delete values[key];
|
|
65
|
+
}
|
|
60
66
|
if (values.reasoning === false) { delete values.reasoning_efforts;delete values.reasoning_adaptive;delete values.reasoning_required; }
|
|
61
67
|
const revisionId = createHash("sha256").update(JSON.stringify([revision, values])).digest("hex").slice(0, 16);
|
|
62
|
-
return { values, fields, revision: revisionId, stale: Boolean(model.metadata && model.metadata.deployment !== revision)
|
|
68
|
+
return { values, fields, revision: revisionId, stale: Boolean(model.metadata && model.metadata.deployment !== revision),
|
|
69
|
+
...(metadata?.state ? { catalog_state: metadata.state } : {}) };
|
|
63
70
|
}
|
|
64
71
|
|
|
65
72
|
export function claudeEffortsExpressible(values = {}) {
|
|
@@ -81,6 +88,9 @@ export function constrainModelRequest(body, capability, protocol) {
|
|
|
81
88
|
if (values.reasoning === false && body.thinking && body.thinking.type !== "disabled") {
|
|
82
89
|
throw Object.assign(new Error("Reasoning is disabled for this model."), { code: "ccdx_api_reasoning_unavailable", statusCode: 400 });
|
|
83
90
|
}
|
|
91
|
+
if (protocol === "messages" && body.thinking?.type && values.thinking_modes && !values.thinking_modes.includes(body.thinking.type)) {
|
|
92
|
+
throw Object.assign(new Error("This model does not declare the selected thinking mode."), { code: "ccdx_api_thinking_unavailable", statusCode: 400 });
|
|
93
|
+
}
|
|
84
94
|
const budget = body.thinking?.budget_tokens;
|
|
85
95
|
if (Number.isFinite(budget) && (values.reasoning_budget_min && budget < values.reasoning_budget_min || values.reasoning_budget_max && budget > values.reasoning_budget_max
|
|
86
96
|
|| applied.includes("output_limit") && Number.isFinite(result.max_tokens) && budget >= result.max_tokens)) {
|
|
@@ -4,7 +4,7 @@ export const isProviderId = value => typeof value === "string" && /^[a-z][a-z0-9
|
|
|
4
4
|
&& !["constructor", "prototype"].includes(value);
|
|
5
5
|
|
|
6
6
|
export function modelReasoningEfforts(model) {
|
|
7
|
-
const values = model?.capabilities?.supports?.reasoning_effort;
|
|
7
|
+
const values = model?.capability ? model.capability.values.reasoning === false ? [] : model.capability.values.reasoning_efforts : model?.capabilities?.supports?.reasoning_effort;
|
|
8
8
|
return Array.isArray(values) ? [...new Set(values.filter(value => typeof value === "string" && /^[a-z][a-z0-9_-]{0,15}$/.test(value)))].slice(0, 16) : null;
|
|
9
9
|
}
|
|
10
10
|
|
|
@@ -14,9 +14,9 @@ export function publicModelCatalog(models, { clients = () => [], selectable = ()
|
|
|
14
14
|
endpoints: [["responses", ["/responses", "/v1/responses"]], ["chat", ["/chat/completions", "/v1/chat/completions"]],
|
|
15
15
|
["messages", ["/v1/messages"]]].filter(([, paths]) => paths.some(path => model.supported_endpoints?.includes(path))).map(([label]) => label),
|
|
16
16
|
preview: model.preview === true, selectable: selectable(model), clients: clients(model),
|
|
17
|
-
reasoning_efforts: modelReasoningEfforts(model), auto_review_efforts: autoReviewReasoningEfforts(model),
|
|
18
|
-
context_window: Number.isSafeInteger(model.capabilities?.limits?.max_context_window_tokens)
|
|
19
|
-
&& model.capabilities.limits.max_context_window_tokens > 0 ? model.capabilities.limits.max_context_window_tokens : null,
|
|
17
|
+
reasoning_efforts: modelReasoningEfforts(model), auto_review_efforts: model.capability ? modelReasoningEfforts(model) || [] : autoReviewReasoningEfforts(model),
|
|
18
|
+
context_window: model.capability?.values.context_window ?? (Number.isSafeInteger(model.capabilities?.limits?.max_context_window_tokens)
|
|
19
|
+
&& model.capabilities.limits.max_context_window_tokens > 0 ? model.capabilities.limits.max_context_window_tokens : null),
|
|
20
20
|
state: model.policy?.state && model.policy.state !== "enabled" ? "restricted" : model.model_picker_enabled === false ? "hidden" : "listed",
|
|
21
21
|
}));
|
|
22
22
|
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { catalogCapabilities, validCapabilities } from "../model-capabilities.mjs";
|
|
2
|
+
|
|
3
|
+
// Interpret the catalog's declared schema, never the model's name. Anthropic
|
|
4
|
+
// fields describe Messages; a gateway exposing other APIs must declare those
|
|
5
|
+
// separately. No inference request is used to fill missing information.
|
|
6
|
+
export function apiModelMetadata(model, { deployment, checked_at }) {
|
|
7
|
+
const values = catalogCapabilities(model), caps = model.capabilities || {}, messages = {};
|
|
8
|
+
const anthropic = model.type === "model" && Object.hasOwn(model, "max_tokens") || typeof caps.thinking?.supported === "boolean" || typeof caps.effort?.supported === "boolean";
|
|
9
|
+
if (anthropic) {
|
|
10
|
+
const put = (key, value) => { if (value !== undefined && validCapabilities({ [key]: value })) messages[key] = value; };
|
|
11
|
+
put("context_window", model.max_input_tokens);
|
|
12
|
+
put("max_input_tokens", model.max_input_tokens);
|
|
13
|
+
put("max_output_tokens", model.max_tokens);
|
|
14
|
+
put("reasoning", caps.effort?.supported === true ? true : caps.thinking?.supported);
|
|
15
|
+
if (caps.thinking?.supported === false) put("thinking_modes", ["disabled"]);
|
|
16
|
+
else if (caps.thinking?.supported === true && caps.thinking.types) put("thinking_modes", ["disabled", "enabled", "adaptive", "between_tools"].filter(mode => caps.thinking.types[mode]?.supported === true));
|
|
17
|
+
put("reasoning_adaptive", caps.thinking?.types?.adaptive?.supported);
|
|
18
|
+
if (caps.effort?.supported === false) put("reasoning_efforts", []);
|
|
19
|
+
else if (caps.effort?.supported === true) {
|
|
20
|
+
const efforts = ["low", "medium", "high", "xhigh", "max"].filter(level => caps.effort[level]?.supported === true);
|
|
21
|
+
if (efforts.length) put("reasoning_efforts", efforts);
|
|
22
|
+
}
|
|
23
|
+
if (messages.reasoning_efforts?.length || messages.reasoning !== undefined) put("reasoning_format", "messages");
|
|
24
|
+
put("structured_output", caps.structured_outputs?.supported);
|
|
25
|
+
if (typeof caps.server_tools?.web_search?.supported === "boolean") put("web_search", caps.server_tools.web_search.supported ? ["messages"] : []);
|
|
26
|
+
// Image/PDF flags do not establish support for arbitrary files or audio.
|
|
27
|
+
if (caps.image_input?.supported === true) put("input_modalities", ["text", "image"]);
|
|
28
|
+
// Native input/output limits must not leak to another gateway API.
|
|
29
|
+
delete values.max_input_tokens;
|
|
30
|
+
}
|
|
31
|
+
const protocols = Object.keys(messages).length ? { messages } : {};
|
|
32
|
+
const reported = Object.keys(values).length || Object.keys(protocols).length;
|
|
33
|
+
const described = Object.keys(caps).length || ["max_tokens", "max_input_tokens", "max_output_tokens", "context_window", "reasoning_efforts"].some(key => Object.hasOwn(model, key));
|
|
34
|
+
return { values, ...(Object.keys(protocols).length ? { protocols } : {}), deployment, checked_at,
|
|
35
|
+
state: reported ? "reported" : described ? "unrecognized" : "missing" };
|
|
36
|
+
}
|
|
@@ -7,6 +7,7 @@ import { createProxyAgent } from "../proxy-tunnel.mjs";
|
|
|
7
7
|
import { apiUrl, accessError } from "../access-settings.mjs";
|
|
8
8
|
import { privateHelperEnvironment } from "../private-helper-environment.mjs";
|
|
9
9
|
import { transportErrorDetails } from "../operation-error.mjs";
|
|
10
|
+
import { apiTargetAllowed } from "../api-target.mjs";
|
|
10
11
|
|
|
11
12
|
export async function createApiNetwork({ targets, env = process.env, platform = process.platform, signal,
|
|
12
13
|
requestImpl = https.request, exec = promisify(execFile), startWindowsNetwork } = {}) {
|
|
@@ -30,7 +31,7 @@ export async function createApiNetwork({ targets, env = process.env, platform =
|
|
|
30
31
|
fetch(raw, init = {}) {
|
|
31
32
|
return new Promise((resolve, reject) => {
|
|
32
33
|
let url;try { url = new URL(raw); } catch { reject(accessError("ccdx_api_url_invalid"));return; }
|
|
33
|
-
if (closed || retiring || !
|
|
34
|
+
if (closed || retiring || !apiTargetAllowed(url.href, [...urls], init.method || "GET") || !["GET", "POST"].includes(init.method || "GET")) { reject(accessError("ccdx_api_url_invalid"));return; }
|
|
34
35
|
if (init.signal?.aborted) { reject(init.signal.reason);return; }
|
|
35
36
|
active++;
|
|
36
37
|
let req, incoming, socket, phase = "request", handedOff = false, released = false;
|
|
@@ -52,7 +53,7 @@ export async function createApiNetwork({ targets, env = process.env, platform =
|
|
|
52
53
|
};
|
|
53
54
|
const abort = () => { req?.destroy(init.signal.reason || accessError("ccdx_api_cancelled"));incoming?.destroy(); };
|
|
54
55
|
try {
|
|
55
|
-
req = requestImpl({ hostname: worker ? url.hostname : url.hostname.replace(/^\[|\]$/g, ""), port: Number(url.port || 443), protocol: "https:", path: url.pathname,
|
|
56
|
+
req = requestImpl({ hostname: worker ? url.hostname : url.hostname.replace(/^\[|\]$/g, ""), port: Number(url.port || 443), protocol: "https:", path: url.pathname + url.search,
|
|
56
57
|
method: init.method || "GET", headers: { ...Object.fromEntries(new Headers(init.headers)), "accept-encoding": "identity" }, agent, rejectUnauthorized: true }, res => {
|
|
57
58
|
phase = "response";incoming = res;
|
|
58
59
|
const finished = () => { cleanup();release(); };
|
package/src/providers/api.mjs
CHANGED
|
@@ -10,16 +10,17 @@ import { markUpstreamHeaders } from "../stream-performance.mjs";
|
|
|
10
10
|
import { createApiNetwork } from "./api-network.mjs";
|
|
11
11
|
import { checkedApiKey } from "../api-secrets.mjs";
|
|
12
12
|
import { transportErrorDetails } from "../operation-error.mjs";
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
13
|
+
import { resolveModelCapabilities, deploymentRevision, constrainModelRequest } from "../model-capabilities.mjs";
|
|
14
|
+
import { apiModelMetadata } from "./api-model-metadata.mjs";
|
|
15
15
|
import { markRequestObservation } from "../stream-performance.mjs";
|
|
16
16
|
|
|
17
17
|
const paths = { messages: "/v1/messages", responses: "/v1/responses", chat: "/v1/chat/completions" };
|
|
18
18
|
export function apiCatalog(config, env = process.env) {
|
|
19
|
-
|
|
19
|
+
const revision = deploymentRevision(config, env);
|
|
20
|
+
return config.models.map(model => { const protocol_capabilities = Object.fromEntries(model.protocols.map(protocol => [protocol, resolveModelCapabilities(model, { revision, protocol })]));
|
|
21
|
+
const capability = protocol_capabilities[model.protocols.includes("messages") ? "messages" : model.protocols[0]];return ({ id: model.id, name: model.id, publisher: "Unknown",
|
|
20
22
|
supported_endpoints: model.protocols.map(api => paths[api]), model_picker_enabled: true, policy: { state: "enabled" },
|
|
21
|
-
capability,
|
|
22
|
-
supports: { reasoning_effort: capability.values.reasoning_efforts || [] } } }); });
|
|
23
|
+
capability, protocol_capabilities }); });
|
|
23
24
|
}
|
|
24
25
|
export function createApiProvider({ config, secrets, env = process.env, platform = process.platform, networkFactory = createApiNetwork } = {}) {
|
|
25
26
|
const catalog = apiCatalog(config, env);
|
|
@@ -60,7 +61,7 @@ export function createApiProvider({ config, secrets, env = process.env, platform
|
|
|
60
61
|
for (const name of ["anthropic-version", "anthropic-beta"]) { const value = options.headers?.[name];if (typeof value === "string" && value.length < 8192 && !/[\r\n]/.test(value)) headers[name] = value; }
|
|
61
62
|
}
|
|
62
63
|
if (body && !options.countTokens) {
|
|
63
|
-
const capability = catalog.find(model => model.id === body.model)?.
|
|
64
|
+
const capability = catalog.find(model => model.id === body.model)?.protocol_capabilities[api];
|
|
64
65
|
const constrained = constrainModelRequest(body, capability, api);
|
|
65
66
|
if (constrained.body !== body) { body = constrained.body;options = { ...options, bodyText: undefined }; }
|
|
66
67
|
markRequestObservation({ capability_revision: capability?.revision, capability_constraints: constrained.applied.join(",") || "none" });
|
|
@@ -107,26 +108,33 @@ export function createApiProvider({ config, secrets, env = process.env, platform
|
|
|
107
108
|
},
|
|
108
109
|
};
|
|
109
110
|
return {
|
|
110
|
-
id: config.id, client, registry, configuredModels: true, defaultReviewEffort: null, profileId: (protocol = "responses") => profiles[protocol] || profile,
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
},
|
|
111
|
+
id: config.id, name: config.name, client, registry, configuredModels: true, defaultReviewEffort: null, profileId: (protocol = "responses") => profiles[protocol] || profile,
|
|
112
|
+
models: family => catalog.filter(model => model.supported_endpoints.includes(family === "claude" ? paths.messages : paths.responses))
|
|
113
|
+
.map(model => ({ ...model, capability: model.protocol_capabilities[family === "claude" ? "messages" : "responses"] })),
|
|
114
114
|
catalog: () => catalog,
|
|
115
115
|
publicCatalog(allowed = []) { return { source: "configured", checkedAt: config.checked_at || null, upstreamHost: new URL(config.base_url).hostname,
|
|
116
116
|
advertised: catalog.length, models: publicModelCatalog(catalog, { selectable: model => allowed.some(id => model.supported_endpoints.includes(id === "codex" ? paths.responses : paths.messages)),
|
|
117
117
|
clients: model => allowed.filter(id => model.supported_endpoints.includes(id === "codex" ? paths.responses : paths.messages)) }).map(model => ({ ...model,
|
|
118
|
-
capability: catalog.find(entry => entry.id === model.id)?.capability, auto_review_efforts: [...(catalog.find(entry => entry.id === model.id)?.
|
|
118
|
+
capability: catalog.find(entry => entry.id === model.id)?.capability, auto_review_efforts: [...(catalog.find(entry => entry.id === model.id)?.protocol_capabilities.responses?.values.reasoning_efforts || [])] })) }; },
|
|
119
119
|
async discover({ signal } = {}) {
|
|
120
|
-
const
|
|
120
|
+
const models = [], ids = new Set(), checked_at = new Date().toISOString();let url = modelsUrl, bytes = 0;
|
|
121
|
+
for (let page = 0; page < 25; page++) {
|
|
122
|
+
const response = await request(url, undefined, { signal }, config.endpoints.responses ? "responses" : "messages");
|
|
121
123
|
if (!response.ok) { await response.body?.cancel();throw accessError(`ccdx_api_catalog_http_${response.status}`, response.status === 401 || response.status === 403 ? response.status : 502); }
|
|
122
|
-
const text = await readBoundedResponseText(response, { maxBytes: MAX_UPSTREAM_MODEL_CATALOG_BYTES, label: "API model catalog", signal });
|
|
124
|
+
const text = await readBoundedResponseText(response, { maxBytes: MAX_UPSTREAM_MODEL_CATALOG_BYTES - bytes, label: "API model catalog", signal });bytes += Buffer.byteLength(text);
|
|
123
125
|
let value;try { value = JSON.parse(text); } catch { throw accessError("ccdx_api_catalog_invalid", 502); }
|
|
124
|
-
if (!Array.isArray(value.data) || value.data.length > 500) throw accessError("ccdx_api_catalog_invalid", 502);
|
|
125
|
-
const ids
|
|
126
|
-
for (const model of value.data) { if (!model || typeof model.id !== "string" || !/^[\w][\w./:@+-]{0,159}$/.test(model.id) || ids.has(model.id)) throw accessError("ccdx_api_catalog_invalid", 502);ids.add(model.id); }
|
|
126
|
+
if (!Array.isArray(value.data) || models.length + value.data.length > 500) throw accessError("ccdx_api_catalog_invalid", 502);
|
|
127
|
+
for (const model of value.data) { if (!model || typeof model.id !== "string" || !/^[\w][\w./:@+-]{0,159}$/.test(model.id) || model.id.includes("..") || model.id.includes("//") || ids.has(model.id)) throw accessError("ccdx_api_catalog_invalid", 502);ids.add(model.id); }
|
|
127
128
|
// A catalog listing is not evidence that every model supports every API.
|
|
128
|
-
|
|
129
|
-
? Object.entries(paths).filter(([, endpoint]) => model.supported_endpoints.includes(endpoint) || model.supported_endpoints.includes(endpoint.slice(3))).map(([api]) => api).filter(api => config.endpoints[api]) : [] }));
|
|
129
|
+
models.push(...value.data.map(model => ({ id: model.id, metadata: apiModelMetadata(model, { checked_at, deployment: deploymentRevision(config, env) }), protocols: Array.isArray(model.supported_endpoints)
|
|
130
|
+
? Object.entries(paths).filter(([, endpoint]) => model.supported_endpoints.includes(endpoint) || model.supported_endpoints.includes(endpoint.slice(3))).map(([api]) => api).filter(api => config.endpoints[api]) : [] })));
|
|
131
|
+
if (value.has_more !== true) return models;
|
|
132
|
+
// Follow only the native cursor on the configured origin, never an
|
|
133
|
+
// upstream next-page URL that could disclose this source's credential.
|
|
134
|
+
if (!value.data.length || value.last_id !== value.data.at(-1).id || bytes >= MAX_UPSTREAM_MODEL_CATALOG_BYTES) throw accessError("ccdx_api_catalog_invalid", 502);
|
|
135
|
+
const next = new URL(modelsUrl);next.searchParams.set("after_id", value.last_id);url = next.href;
|
|
136
|
+
}
|
|
137
|
+
throw accessError("ccdx_api_catalog_limit", 502);
|
|
130
138
|
},
|
|
131
139
|
selectModel(_body, { upstreamModel }) { selected(upstreamModel, "responses");return { upstreamModel, forceResponses: true }; },
|
|
132
140
|
route(_body, { upstreamModel, surface }) { return createRoutePlan({ disposition: "relay", origin: config.id, profile, protocol: "openai-responses", model: upstreamModel, surface }); },
|
|
@@ -72,7 +72,7 @@ export async function startWindowsHttpNetwork({ settings = {}, target = "predict
|
|
|
72
72
|
if(!allowedHosts.includes(host)||!String(options.path).startsWith("/")||target !== "api" && String(options.path).startsWith("//"))throw failure("proxy_target_invalid");
|
|
73
73
|
if(target === "m365" && !String(options.path).startsWith("/api/v1/llmapi/")) throw failure("proxy_target_invalid");
|
|
74
74
|
const requestUrl = `https://${host}${options.port && Number(options.port) !== 443 ? `:${options.port}` : ""}${options.path}`;
|
|
75
|
-
if(target === "api" && !apiTargets.
|
|
75
|
+
if(target === "api" && !apiTargetAllowed(requestUrl, apiTargets, options.method || "GET")) throw failure("proxy_target_invalid");
|
|
76
76
|
const headers=[];
|
|
77
77
|
for(const [name,value]of Object.entries(options.headers||{})){
|
|
78
78
|
if(!/^[!#$%&'*+.^_`|~0-9a-z-]+$/i.test(name))throw failure("proxy_headers_invalid");
|
|
@@ -125,3 +125,4 @@ export async function startWindowsHttpNetwork({ settings = {}, target = "predict
|
|
|
125
125
|
};
|
|
126
126
|
return {script,requestImpl,healthy:()=>!stopped,close(){closing=true;stop(failure("proxy_worker_closed"));}};
|
|
127
127
|
}
|
|
128
|
+
import { apiTargetAllowed } from "./api-target.mjs";
|
|
@@ -74,11 +74,17 @@ public static class CCDXPredictionNetwork {
|
|
|
74
74
|
}
|
|
75
75
|
} finally { if(request!=IntPtr.Zero)WinHttpCloseHandle(request);if(connection!=IntPtr.Zero)WinHttpCloseHandle(connection); }
|
|
76
76
|
}
|
|
77
|
+
static bool ApiTargetAllowed(Uri uri, string method) {
|
|
78
|
+
if(apiTargets.Contains(uri.AbsoluteUri))return true;
|
|
79
|
+
if(method!="GET" || !uri.AbsolutePath.EndsWith("/models",StringComparison.Ordinal) || !uri.Query.StartsWith("?after_id=",StringComparison.Ordinal) || uri.Query.IndexOf('&')>=0)return false;
|
|
80
|
+
string cursor=Uri.UnescapeDataString(uri.Query.Substring(10));
|
|
81
|
+
return System.Text.RegularExpressions.Regex.IsMatch(cursor,"^[A-Za-z0-9_][A-Za-z0-9_./:@+\\-]{0,159}$") && !cursor.Contains("..") && !cursor.Contains("//") && apiTargets.Contains(uri.GetLeftPart(UriPartial.Path));
|
|
82
|
+
}
|
|
77
83
|
static void Request(Dictionary<string,object> data, int id, Work work) {
|
|
78
84
|
IntPtr connection=IntPtr.Zero;
|
|
79
85
|
try {
|
|
80
86
|
var uri=new Uri((string)data["url"]);
|
|
81
|
-
if(uri.Scheme!="https" || uri.UserInfo.Length!=0 || uri.Fragment.Length!=0 || (target=="api" ? !
|
|
87
|
+
if(uri.Scheme!="https" || uri.UserInfo.Length!=0 || uri.Fragment.Length!=0 || (target=="api" ? !ApiTargetAllowed(uri,(string)data["method"]) : (uri.Port!=443 || (target=="m365" ? (uri.Host!="df.loki.delve.office.com" || !uri.AbsolutePath.StartsWith("/api/v1/llmapi/",StringComparison.Ordinal)) : (uri.Host!="chatgpt.com"&&uri.Host!="ab.chatgpt.com"))))) throw new IOException("winhttp_target_invalid");
|
|
82
88
|
var method=(string)data["method"];
|
|
83
89
|
if(method!="GET"&&method!="POST"&&method!="HEAD"&&method!="PUT"&&method!="DELETE"&&method!="OPTIONS"&&method!="PATCH")throw new IOException("winhttp_method_invalid");
|
|
84
90
|
var headers=(string)data["headers"];
|