omnicell-router 0.7.0 → 0.8.2
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/backend/dist/cli/clients/activity.d.ts +35 -0
- package/backend/dist/cli/clients/activity.js +67 -0
- package/backend/dist/cli/clients/base.d.ts +13 -2
- package/backend/dist/cli/clients/claude.d.ts +2 -2
- package/backend/dist/cli/clients/codex.d.ts +2 -2
- package/backend/dist/cli/clients/core-adapters.d.ts +3 -4
- package/backend/dist/cli/clients/core-adapters.js +3 -4
- package/backend/dist/cli/clients/cursor-proxy.d.ts +88 -0
- package/backend/dist/cli/clients/cursor-proxy.js +421 -0
- package/backend/dist/cli/clients/dsh.d.ts +2 -2
- package/backend/dist/cli/clients/grok.d.ts +2 -2
- package/backend/dist/cli/clients/index.d.ts +8 -1
- package/backend/dist/cli/clients/index.js +55 -21
- package/backend/dist/cli/clients/kimi.d.ts +2 -2
- package/backend/dist/cli/clients/launcher.d.ts +8 -0
- package/backend/dist/cli/clients/model-meta.js +1 -1
- package/backend/dist/cli/clients/omp.d.ts +2 -2
- package/backend/dist/cli/clients/openclaw.d.ts +2 -2
- package/backend/dist/cli/clients/opencode-proxy.d.ts +11 -0
- package/backend/dist/cli/clients/opencode-proxy.js +351 -0
- package/backend/dist/cli/clients/opencode.d.ts +2 -2
- package/backend/dist/cli/clients/pi.d.ts +2 -2
- package/backend/dist/cli/clients/plugin-adapters.d.ts +3 -1
- package/backend/dist/cli/clients/plugin-adapters.js +6 -29
- package/backend/dist/cli/clients/qoder-proxy.d.ts +84 -0
- package/backend/dist/cli/clients/qoder-proxy.js +497 -0
- package/backend/dist/cli/clients/reserved.d.ts +2 -6
- package/backend/dist/cli/clients/reserved.js +2 -0
- package/backend/dist/cli/clients/workbuddy.d.ts +2 -2
- package/backend/dist/cli/index.js +60 -9
- package/backend/dist/cli/types.d.ts +29 -8
- package/backend/dist/compression/caveman-prompts.d.ts +1 -1
- package/backend/dist/config/comments-en.js +6 -12
- package/backend/dist/config/comments-zh.js +6 -12
- package/backend/dist/config/defaults.d.ts +56 -1
- package/backend/dist/config/defaults.js +68 -0
- package/backend/dist/config/index.d.ts +9 -2
- package/backend/dist/config/index.js +26 -3
- package/backend/dist/config/types.d.ts +55 -43
- package/backend/dist/forward-proxy/egress.d.ts +10 -2
- package/backend/dist/forward-proxy/egress.js +42 -4
- package/backend/dist/forward-proxy/ordered-relay.d.ts +29 -0
- package/backend/dist/forward-proxy/ordered-relay.js +46 -0
- package/backend/dist/forward-proxy/rules.d.ts +66 -19
- package/backend/dist/forward-proxy/rules.js +61 -14
- package/backend/dist/forward-proxy/server.js +226 -77
- package/backend/dist/forward-proxy/system-proxy.d.ts +42 -2
- package/backend/dist/forward-proxy/system-proxy.js +199 -22
- package/backend/dist/harness/common/market.d.ts +3 -3
- package/backend/dist/harness/host/adapters/amp.d.ts +1 -1
- package/backend/dist/harness/host/adapters/antigravity.d.ts +1 -1
- package/backend/dist/harness/host/adapters/claude.d.ts +1 -1
- package/backend/dist/harness/host/adapters/cline.d.ts +1 -1
- package/backend/dist/harness/host/adapters/codex.d.ts +1 -1
- package/backend/dist/harness/host/adapters/cursor.d.ts +1 -1
- package/backend/dist/harness/host/adapters/dsh.d.ts +2 -2
- package/backend/dist/harness/host/adapters/factory.d.ts +1 -1
- package/backend/dist/harness/host/adapters/gemini-cli.d.ts +1 -1
- package/backend/dist/harness/host/adapters/grok.d.ts +1 -1
- package/backend/dist/harness/host/adapters/kimi.d.ts +1 -1
- package/backend/dist/harness/host/adapters/omp.d.ts +1 -1
- package/backend/dist/harness/host/adapters/openclaw.d.ts +1 -1
- package/backend/dist/harness/host/adapters/opencode.d.ts +1 -1
- package/backend/dist/harness/host/adapters/pi.d.ts +1 -1
- package/backend/dist/harness/host/adapters/universal.d.ts +1 -1
- package/backend/dist/harness/host/adapters/windsurf.d.ts +1 -1
- package/backend/dist/harness/host/adapters/zed.d.ts +1 -1
- package/backend/dist/harness/skill/skills-sh.d.ts +1 -1
- package/backend/dist/harness/translation.js +64 -21
- package/backend/dist/harness/types.d.ts +1 -1
- package/backend/dist/harness/types.js +1 -1
- package/backend/dist/index.js +31 -18
- package/backend/dist/ir/adapters/anthropic-stream.d.ts +18 -0
- package/backend/dist/ir/adapters/anthropic-stream.js +247 -0
- package/backend/dist/ir/adapters/anthropic.d.ts +29 -0
- package/backend/dist/ir/adapters/anthropic.js +788 -0
- package/backend/dist/ir/adapters/chat.d.ts +15 -0
- package/backend/dist/ir/adapters/chat.js +602 -0
- package/backend/dist/ir/adapters/google-stream.d.ts +22 -0
- package/backend/dist/ir/adapters/google-stream.js +242 -0
- package/backend/dist/ir/adapters/google.d.ts +9 -0
- package/backend/dist/ir/adapters/google.js +317 -0
- package/backend/dist/ir/adapters/openai-responses-output.js +8 -5
- package/backend/dist/ir/adapters/openai-responses.d.ts +15 -0
- package/backend/dist/ir/adapters/openai-responses.js +26 -1
- package/backend/dist/ir/adapters/responses-output.d.ts +50 -0
- package/backend/dist/ir/adapters/responses-output.js +348 -0
- package/backend/dist/ir/adapters/responses-stream.d.ts +12 -0
- package/backend/dist/ir/adapters/responses-stream.js +178 -0
- package/backend/dist/ir/adapters/responses.d.ts +14 -0
- package/backend/dist/ir/adapters/responses.js +646 -0
- package/backend/dist/ir/errors.d.ts +2 -2
- package/backend/dist/ir/types.d.ts +2 -1
- package/backend/dist/metrics/request-cost.d.ts +11 -2
- package/backend/dist/metrics/request-cost.js +12 -3
- package/backend/dist/observability/request-identity.d.ts +1 -1
- package/backend/dist/observability/trace-id.d.ts +40 -0
- package/backend/dist/observability/trace-id.js +134 -0
- package/backend/dist/observability/upstream-events.d.ts +82 -60
- package/backend/dist/observability/upstream-events.js +142 -67
- package/backend/dist/opencode/catalog/types.d.ts +9 -0
- package/backend/dist/opencode/credentials/types.d.ts +2 -2
- package/backend/dist/opencode/probe.d.ts +24 -1
- package/backend/dist/opencode/probe.js +28 -4
- package/backend/dist/opencode/user-config.d.ts +5 -0
- package/backend/dist/pipeline/directives.d.ts +6 -2
- package/backend/dist/pipeline/directives.js +7 -3
- package/backend/dist/pipeline/orchestrator.d.ts +28 -27
- package/backend/dist/pipeline/orchestrator.js +220 -194
- package/backend/dist/pipeline/unresolved-model.d.ts +33 -0
- package/backend/dist/pipeline/unresolved-model.js +43 -0
- package/backend/dist/plugins/catalog-def.d.ts +143 -0
- package/backend/dist/plugins/catalog-def.js +177 -0
- package/backend/dist/plugins/gateways.d.ts +62 -3
- package/backend/dist/plugins/gateways.js +139 -2
- package/backend/dist/plugins/host.d.ts +42 -5
- package/backend/dist/plugins/host.js +454 -38
- package/backend/dist/plugins/manifest.d.ts +119 -10
- package/backend/dist/plugins/manifest.js +265 -14
- package/backend/dist/plugins/pack.js +26 -0
- package/backend/dist/plugins/types.d.ts +187 -21
- package/backend/dist/protocols/systemone/convert.d.ts +1 -0
- package/backend/dist/protocols/systemone/convert.js +6 -1
- package/backend/dist/protocols/systemone/decide.js +18 -8
- package/backend/dist/providers/anthropic-messages.d.ts +12 -0
- package/backend/dist/providers/anthropic-messages.js +53 -0
- package/backend/dist/providers/anthropic.d.ts +7 -8
- package/backend/dist/providers/anthropic.js +36 -324
- package/backend/dist/providers/base.d.ts +14 -2
- package/backend/dist/providers/boot-direct.js +68 -38
- package/backend/dist/providers/dispatch.d.ts +5 -19
- package/backend/dist/providers/dispatch.js +46 -58
- package/backend/dist/providers/executors/anthropic-messages.d.ts +1 -0
- package/backend/dist/providers/executors/anthropic-messages.js +3 -0
- package/backend/dist/providers/executors/dispatch.d.ts +16 -2
- package/backend/dist/providers/executors/dispatch.js +39 -9
- package/backend/dist/providers/executors/google-gemini.d.ts +1 -0
- package/backend/dist/providers/executors/google-gemini.js +3 -0
- package/backend/dist/providers/executors/http-stream.js +16 -3
- package/backend/dist/providers/executors/openai-chat.d.ts +1 -0
- package/backend/dist/providers/executors/openai-chat.js +3 -0
- package/backend/dist/providers/executors/openai-responses.d.ts +1 -0
- package/backend/dist/providers/executors/openai-responses.js +3 -0
- package/backend/dist/providers/executors/plugin-adapter.js +4 -4
- package/backend/dist/providers/google-gemini.d.ts +12 -0
- package/backend/dist/providers/google-gemini.js +50 -0
- package/backend/dist/providers/google.d.ts +7 -8
- package/backend/dist/providers/google.js +35 -308
- package/backend/dist/providers/http-json.d.ts +19 -0
- package/backend/dist/providers/http-json.js +104 -0
- package/backend/dist/providers/http-stream.d.ts +52 -0
- package/backend/dist/providers/http-stream.js +423 -0
- package/backend/dist/providers/member-match.d.ts +4 -5
- package/backend/dist/providers/member-match.js +4 -5
- package/backend/dist/providers/openai-chat.d.ts +13 -0
- package/backend/dist/providers/openai-chat.js +99 -0
- package/backend/dist/providers/openai-compatible.d.ts +7 -4
- package/backend/dist/providers/openai-compatible.js +71 -368
- package/backend/dist/providers/openai-responses.d.ts +12 -0
- package/backend/dist/providers/openai-responses.js +68 -0
- package/backend/dist/providers/opencode-proxy.d.ts +5 -5
- package/backend/dist/providers/opencode-proxy.js +49 -125
- package/backend/dist/providers/plugin-adapter.d.ts +9 -0
- package/backend/dist/providers/plugin-adapter.js +31 -0
- package/backend/dist/providers/registry.d.ts +49 -24
- package/backend/dist/providers/registry.js +97 -55
- package/backend/dist/providers/responses.d.ts +7 -28
- package/backend/dist/providers/responses.js +45 -253
- package/backend/dist/providers/tool-markup-leak.d.ts +41 -0
- package/backend/dist/providers/tool-markup-leak.js +57 -0
- package/backend/dist/providers/tool-markup-recovery.d.ts +27 -0
- package/backend/dist/providers/tool-markup-recovery.js +786 -0
- package/backend/dist/providers/virtual-meta.d.ts +21 -2
- package/backend/dist/providers/virtual-meta.js +49 -9
- package/backend/dist/proxy/asset-download.d.ts +54 -0
- package/backend/dist/proxy/asset-download.js +420 -0
- package/backend/dist/proxy/manual-node-spec.d.ts +16 -16
- package/backend/dist/proxy/mihomo-binary.d.ts +17 -2
- package/backend/dist/proxy/mihomo-binary.js +62 -51
- package/backend/dist/proxy/mihomo-client.js +15 -1
- package/backend/dist/proxy/mihomo-config.js +11 -2
- package/backend/dist/proxy/mihomo-geo.d.ts +87 -0
- package/backend/dist/proxy/mihomo-geo.js +213 -0
- package/backend/dist/proxy/mihomo-logs.d.ts +27 -0
- package/backend/dist/proxy/mihomo-logs.js +70 -0
- package/backend/dist/proxy/mihomo-pac.d.ts +11 -0
- package/backend/dist/proxy/mihomo-pac.js +15 -0
- package/backend/dist/proxy/mihomo-rules-import.d.ts +1 -1
- package/backend/dist/proxy/mihomo-rules-import.js +7 -7
- package/backend/dist/proxy/mihomo-sidecar.d.ts +17 -1
- package/backend/dist/proxy/mihomo-sidecar.js +148 -26
- package/backend/dist/quota/adapters/minimax.js +36 -13
- package/backend/dist/quota/cli-login.d.ts +8 -0
- package/backend/dist/quota/cli-login.js +18 -0
- package/backend/dist/quota/declarations.js +10 -0
- package/backend/dist/quota/dsl.js +18 -5
- package/backend/dist/quota/engine.d.ts +22 -1
- package/backend/dist/quota/engine.js +170 -29
- package/backend/dist/quota/prober.d.ts +5 -0
- package/backend/dist/quota/prober.js +11 -2
- package/backend/dist/quota/types.d.ts +87 -8
- package/backend/dist/quota/verdict.d.ts +35 -0
- package/backend/dist/quota/verdict.js +135 -0
- package/backend/dist/ratelimit/admission.d.ts +131 -0
- package/backend/dist/ratelimit/admission.js +233 -0
- package/backend/dist/ratelimit/rate-limiter.js +6 -0
- package/backend/dist/resilience/types.d.ts +2 -2
- package/backend/dist/router/layer2-decision.d.ts +1 -1
- package/backend/dist/router/layer2-decision.js +5 -8
- package/backend/dist/routes/console.js +248 -52
- package/backend/dist/routes/mihomo.d.ts +2 -0
- package/backend/dist/routes/mihomo.js +334 -29
- package/backend/dist/routes/responses.d.ts +87 -8
- package/backend/dist/routes/responses.js +314 -33
- package/backend/dist/server.js +34 -6
- package/backend/dist/session/session-manager.d.ts +6 -0
- package/backend/dist/session/session-manager.js +20 -9
- package/backend/dist/surfaces/chat-pipeline.d.ts +2 -2
- package/backend/dist/surfaces/chat-pipeline.js +17 -7
- package/backend/dist/surfaces/chat.js +15 -0
- package/backend/dist/surfaces/decision-pipeline.js +7 -10
- package/backend/dist/surfaces/direct-forward.d.ts +3 -0
- package/backend/dist/surfaces/direct-forward.js +206 -0
- package/backend/dist/surfaces/rate-limit-response.d.ts +17 -0
- package/backend/dist/surfaces/rate-limit-response.js +57 -0
- package/backend/dist/surfaces/types.d.ts +11 -0
- package/backend/dist/trace/tracker.d.ts +32 -1
- package/backend/dist/trace/tracker.js +29 -4
- package/backend/dist/types/router.d.ts +34 -12
- package/backend/dist/types/router.js +35 -6
- package/backend/dist/utils/chat-stream.d.ts +21 -8
- package/backend/dist/utils/chat-stream.js +46 -9
- package/backend/dist/utils/event-ring.d.ts +4 -0
- package/backend/dist/utils/event-ring.js +4 -0
- package/backend/dist/utils/popularity.js +29 -4
- package/backend/dist/utils/proxy.d.ts +7 -0
- package/backend/dist/utils/proxy.js +35 -10
- package/backend/dist/utils/retry-after.d.ts +21 -0
- package/backend/dist/utils/retry-after.js +36 -0
- package/bin/ocr.js +2 -2
- package/frontend/dist/assets/index-55VVwfFQ.js +1521 -0
- package/frontend/dist/assets/{index-CQSLGFTV.css → index-DxZ9MHKB.css} +1 -1
- package/frontend/dist/assets/workbuddy.color-DOMpQkxJ.svg +29 -0
- package/frontend/dist/index.html +2 -2
- package/package.json +1 -1
- package/frontend/dist/assets/index-CLvxJjp_.js +0 -1476
|
@@ -6,20 +6,33 @@ import { getOcrHomeDir } from '../cli/paths.js';
|
|
|
6
6
|
import { getRuntimeConfigRef } from '../config/index.js';
|
|
7
7
|
import { caCertPath } from './ca.js';
|
|
8
8
|
/**
|
|
9
|
-
* Cross-platform OS system-proxy ownership for
|
|
9
|
+
* Cross-platform OS system-proxy ownership for OCR's two local endpoints: the
|
|
10
|
+
* inbound forward proxy (`owner: 'forward'`) and the Clash core's mixed port
|
|
11
|
+
* (`owner: 'clash'`).
|
|
10
12
|
*
|
|
11
|
-
* Model — snapshot-and-restore, never blind-off:
|
|
13
|
+
* Model — ONE owner, snapshot-and-restore, never blind-off:
|
|
12
14
|
* - `enable` reads the CURRENT OS proxy settings (whatever they point at —
|
|
13
15
|
* including a user's clash/v2ray), snapshots them to
|
|
14
16
|
* `<ocrHome>/forward-proxy/system-proxy.json`, then points the OS proxy at
|
|
15
|
-
* 127.0.0.1:<port> with a bypass list
|
|
16
|
-
* -
|
|
17
|
-
*
|
|
18
|
-
*
|
|
17
|
+
* 127.0.0.1:<port> with a bypass list.
|
|
18
|
+
* - There is exactly ONE snapshot slot, and it always holds the PRE-OCR
|
|
19
|
+
* state. Re-enabling the same endpoint refreshes; enabling the OTHER
|
|
20
|
+
* endpoint REWRITES the OS pointer and updates the snapshot's `owner` —
|
|
21
|
+
* it never re-reads the OS, whose values at that moment are ours.
|
|
22
|
+
* - `disable` restores the snapshot verbatim and deletes it, whichever owner
|
|
23
|
+
* set it. Without a snapshot OCR owns nothing, so disable is a NO-OP — it
|
|
24
|
+
* never blind-offs a proxy it did not set (a user's clash/v2ray keeps
|
|
25
|
+
* working).
|
|
19
26
|
* - The snapshot file doubles as crash detection: if it exists while the OS
|
|
20
27
|
* no longer points at us (or after a hard kill), the state reads `stale`
|
|
21
28
|
* and the console offers one-click restore.
|
|
22
29
|
*
|
|
30
|
+
* The bypass list differs BY OWNER, because the endpoints route differently:
|
|
31
|
+
* the inbound proxy decides ingress per rule (unmatched traffic is tunneled
|
|
32
|
+
* through), so only loopback + literal `direct` hosts are bypassed; the Clash
|
|
33
|
+
* core's generated config ends in `MATCH,<group>`, so private/LAN ranges must
|
|
34
|
+
* also stay DIRECT or they would be dragged into the tunnel.
|
|
35
|
+
*
|
|
23
36
|
* Platforms: win32 (WinINET registry), darwin (networksetup, every enabled
|
|
24
37
|
* network service), linux with GNOME/gsettings. Anything else reports
|
|
25
38
|
* `unsupported` — the UI hides the controls instead of pretending.
|
|
@@ -29,7 +42,10 @@ const snapshotPath = () => path.join(getOcrHomeDir(), 'forward-proxy', 'system-p
|
|
|
29
42
|
function readSnapshot() {
|
|
30
43
|
try {
|
|
31
44
|
const raw = fs.readFileSync(snapshotPath(), 'utf8');
|
|
32
|
-
|
|
45
|
+
const parsed = JSON.parse(raw);
|
|
46
|
+
if (!parsed.owner)
|
|
47
|
+
parsed.owner = 'forward';
|
|
48
|
+
return parsed;
|
|
33
49
|
}
|
|
34
50
|
catch {
|
|
35
51
|
return undefined;
|
|
@@ -54,6 +70,37 @@ export function buildOverride(bypassList, platform) {
|
|
|
54
70
|
}
|
|
55
71
|
return platform === 'win32' ? hosts.join(';') : JSON.stringify(hosts);
|
|
56
72
|
}
|
|
73
|
+
export function planSystemProxyAction(snapshot, targetServer) {
|
|
74
|
+
if (!snapshot)
|
|
75
|
+
return 'snapshot';
|
|
76
|
+
return snapshot.targetServer === targetServer ? 'refresh' : 'switch';
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Private / link-local / CGNAT ranges that stay DIRECT when the OS proxy points
|
|
80
|
+
* at the Clash mixed port. Same set as the PAC's direct list
|
|
81
|
+
* (proxy/mihomo-pac.ts `PRIVATE_RANGES`), in each bypass syntax: WinINET takes
|
|
82
|
+
* `x.*` wildcards, the networksetup / gsettings lists take CIDR.
|
|
83
|
+
*/
|
|
84
|
+
const LAN_BYPASS_WILDCARDS = [
|
|
85
|
+
'10.*',
|
|
86
|
+
'172.16.*', '172.17.*', '172.18.*', '172.19.*',
|
|
87
|
+
'172.20.*', '172.21.*', '172.22.*', '172.23.*',
|
|
88
|
+
'172.24.*', '172.25.*', '172.26.*', '172.27.*',
|
|
89
|
+
'172.28.*', '172.29.*', '172.30.*', '172.31.*',
|
|
90
|
+
'192.168.*',
|
|
91
|
+
'169.254.*',
|
|
92
|
+
'100.64.*',
|
|
93
|
+
];
|
|
94
|
+
const LAN_BYPASS_CIDR = [
|
|
95
|
+
'10.0.0.0/8',
|
|
96
|
+
'172.16.0.0/12',
|
|
97
|
+
'192.168.0.0/16',
|
|
98
|
+
'169.254.0.0/16',
|
|
99
|
+
'100.64.0.0/10',
|
|
100
|
+
];
|
|
101
|
+
export function lanBypassHosts(platform) {
|
|
102
|
+
return [...(platform === 'win32' ? LAN_BYPASS_WILDCARDS : LAN_BYPASS_CIDR)];
|
|
103
|
+
}
|
|
57
104
|
/* ── win32 ─────────────────────────────────────────────────────────────── */
|
|
58
105
|
const WIN_KEY = 'HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings';
|
|
59
106
|
/**
|
|
@@ -226,6 +273,127 @@ async function readCurrentServer(platform) {
|
|
|
226
273
|
}
|
|
227
274
|
return undefined;
|
|
228
275
|
}
|
|
276
|
+
export async function readOsProxyEndpoint() {
|
|
277
|
+
const platform = process.platform;
|
|
278
|
+
try {
|
|
279
|
+
if (platform === 'win32') {
|
|
280
|
+
const s = await winRead();
|
|
281
|
+
if (!s.ProxyEnable || s.AutoConfigURL.trim())
|
|
282
|
+
return undefined;
|
|
283
|
+
const server = pickWinServer(s.ProxyServer);
|
|
284
|
+
if (!server)
|
|
285
|
+
return undefined;
|
|
286
|
+
return { server, bypass: s.ProxyOverride.split(';').map(v => v.trim()).filter(Boolean) };
|
|
287
|
+
}
|
|
288
|
+
if (platform === 'darwin') {
|
|
289
|
+
for (const svc of await macServices()) {
|
|
290
|
+
const s = await macRead(svc);
|
|
291
|
+
const pick = s.secure.enabled && s.secure.host ? s.secure : s.web.enabled && s.web.host ? s.web : undefined;
|
|
292
|
+
if (pick)
|
|
293
|
+
return { server: `${pick.host}:${pick.port}`, bypass: s.bypass };
|
|
294
|
+
}
|
|
295
|
+
return undefined;
|
|
296
|
+
}
|
|
297
|
+
if (platform === 'linux') {
|
|
298
|
+
const g = await gnomeRead();
|
|
299
|
+
if (g.mode !== 'manual')
|
|
300
|
+
return undefined;
|
|
301
|
+
const pick = g.https.host ? g.https : g.http.host ? g.http : undefined;
|
|
302
|
+
return pick ? { server: `${pick.host}:${pick.port}`, bypass: g.ignoreHosts } : undefined;
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
catch {
|
|
306
|
+
// A probe must never fail because the OS settings are unreadable; the
|
|
307
|
+
// caller treats "no endpoint" as "connect directly".
|
|
308
|
+
return undefined;
|
|
309
|
+
}
|
|
310
|
+
return undefined;
|
|
311
|
+
}
|
|
312
|
+
/** WinINET's per-scheme form (`http=host:port;https=host:port`) reduces to
|
|
313
|
+
* one endpoint; an `http://` prefix is stripped but `user:pass@` is kept.
|
|
314
|
+
* A SOCKS-only config (`socks=host:port`) yields nothing: the machine leg
|
|
315
|
+
* speaks the HTTP proxy protocol, and reporting a direct run is honester
|
|
316
|
+
* than dialing `socks=...` as a hostname. */
|
|
317
|
+
function pickWinServer(raw) {
|
|
318
|
+
const value = raw.trim();
|
|
319
|
+
if (!value)
|
|
320
|
+
return undefined;
|
|
321
|
+
const https = /(?:^|;)https=([^;]+)/i.exec(value)?.[1];
|
|
322
|
+
const http = /(?:^|;)http=([^;]+)/i.exec(value)?.[1];
|
|
323
|
+
const pick = (https || http || value.split(';')[0]).trim().replace(/^https?:\/\//i, '').replace(/\/+$/, '');
|
|
324
|
+
if (!pick || /^[a-z]+=/i.test(pick))
|
|
325
|
+
return undefined;
|
|
326
|
+
return pick;
|
|
327
|
+
}
|
|
328
|
+
function ipv4ToInt(addr) {
|
|
329
|
+
const m = /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/.exec(addr);
|
|
330
|
+
if (!m)
|
|
331
|
+
return undefined;
|
|
332
|
+
const parts = m.slice(1).map(Number);
|
|
333
|
+
if (parts.some(n => n > 255))
|
|
334
|
+
return undefined;
|
|
335
|
+
return ((parts[0] << 24) | (parts[1] << 16) | (parts[2] << 8) | parts[3]) >>> 0;
|
|
336
|
+
}
|
|
337
|
+
const isLoopbackHost = (host) => host === 'localhost' || host === '::1' || /^127\./.test(host);
|
|
338
|
+
/**
|
|
339
|
+
* Would the OS send `host` through its proxy, given the OS bypass list?
|
|
340
|
+
* Covers the syntaxes the three platforms actually store: WinINET wildcards
|
|
341
|
+
* (`192.168.*`, `<local>`), macOS/Linux CIDR entries and domain suffixes.
|
|
342
|
+
* Loopback is ALWAYS direct — a proxy in front of a loopback target would
|
|
343
|
+
* either loop back into this gateway or fail for no diagnosable reason.
|
|
344
|
+
*/
|
|
345
|
+
export function osProxyBypasses(host, bypass) {
|
|
346
|
+
const name = host.toLowerCase().replace(/^\[|\]$/g, '');
|
|
347
|
+
if (isLoopbackHost(name))
|
|
348
|
+
return true;
|
|
349
|
+
const ip = ipv4ToInt(name);
|
|
350
|
+
for (const entry of bypass) {
|
|
351
|
+
const e = entry.trim().toLowerCase();
|
|
352
|
+
if (!e)
|
|
353
|
+
continue;
|
|
354
|
+
if (e === '*')
|
|
355
|
+
return true;
|
|
356
|
+
if (e === '<local>') {
|
|
357
|
+
// WinINET: plain host names, no dot. An IP address is never "<local>".
|
|
358
|
+
if (!name.includes('.') && !ip)
|
|
359
|
+
return true;
|
|
360
|
+
continue;
|
|
361
|
+
}
|
|
362
|
+
if (e.includes('/') && ip !== undefined) {
|
|
363
|
+
const m = /^(\d{1,3}(?:\.\d{1,3}){3})\/(\d{1,2})$/.exec(e);
|
|
364
|
+
if (m) {
|
|
365
|
+
const base = ipv4ToInt(m[1]);
|
|
366
|
+
const bits = Number(m[2]);
|
|
367
|
+
if (base !== undefined && bits >= 0 && bits <= 32) {
|
|
368
|
+
const mask = bits === 0 ? 0 : (~0 << (32 - bits)) >>> 0;
|
|
369
|
+
if ((ip & mask) === (base & mask))
|
|
370
|
+
return true;
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
continue;
|
|
374
|
+
}
|
|
375
|
+
if (e.startsWith('*.')) {
|
|
376
|
+
const suffix = e.slice(1); // `.example.com`
|
|
377
|
+
if (name === e.slice(2) || name.endsWith(suffix))
|
|
378
|
+
return true;
|
|
379
|
+
continue;
|
|
380
|
+
}
|
|
381
|
+
if (e.startsWith('.')) {
|
|
382
|
+
if (name === e.slice(1) || name.endsWith(e))
|
|
383
|
+
return true;
|
|
384
|
+
continue;
|
|
385
|
+
}
|
|
386
|
+
if (e.includes('*')) {
|
|
387
|
+
const pattern = e.split('*').map(part => part.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')).join('.*');
|
|
388
|
+
if (new RegExp(`^${pattern}$`).test(name))
|
|
389
|
+
return true;
|
|
390
|
+
continue;
|
|
391
|
+
}
|
|
392
|
+
if (name === e)
|
|
393
|
+
return true;
|
|
394
|
+
}
|
|
395
|
+
return false;
|
|
396
|
+
}
|
|
229
397
|
export async function getSystemProxyStatus(targetPort, bypassList) {
|
|
230
398
|
const platform = process.platform;
|
|
231
399
|
const supported = platformSupported(platform);
|
|
@@ -244,38 +412,47 @@ export async function getSystemProxyStatus(targetPort, bypassList) {
|
|
|
244
412
|
const currentServer = await readCurrentServer(platform);
|
|
245
413
|
if (snapshot) {
|
|
246
414
|
const owned = currentServer === snapshot.targetServer;
|
|
247
|
-
return { ...base, state: owned ? 'on' : 'stale', currentServer, snapshot };
|
|
415
|
+
return { ...base, state: owned ? 'on' : 'stale', owner: snapshot.owner, currentServer, snapshot };
|
|
248
416
|
}
|
|
249
417
|
return { ...base, state: currentServer ? 'external' : 'off', currentServer };
|
|
250
418
|
}
|
|
251
|
-
/**
|
|
252
|
-
|
|
419
|
+
/**
|
|
420
|
+
* Point the OS proxy at one of OCR's local endpoints, snapshotting first.
|
|
421
|
+
* See `planSystemProxyAction` for how an existing snapshot is treated.
|
|
422
|
+
*/
|
|
423
|
+
export async function enableSystemProxy(targetPort, bypassList, owner = 'forward') {
|
|
253
424
|
const platform = process.platform;
|
|
254
425
|
if (!platformSupported(platform))
|
|
255
426
|
throw new Error(`system proxy not supported on ${platform}`);
|
|
256
|
-
// Idempotent ownership: a second enable MUST NOT re-read the OS settings
|
|
257
|
-
// through the snapshot slot — at that point they point at OUR server, so
|
|
258
|
-
// re-snapshotting would overwrite (and permanently lose) the user's
|
|
259
|
-
// original proxy configuration. Treat re-enable as a status refresh.
|
|
260
|
-
if (readSnapshot())
|
|
261
|
-
return getSystemProxyStatus(targetPort, bypassList);
|
|
262
427
|
const targetServer = `127.0.0.1:${targetPort}`;
|
|
428
|
+
const snapshot = readSnapshot();
|
|
429
|
+
const plan = planSystemProxyAction(snapshot, targetServer);
|
|
430
|
+
if (plan === 'refresh') {
|
|
431
|
+
// Same endpoint: never re-read the OS here — it points at OUR server, and
|
|
432
|
+
// re-snapshotting would overwrite (and permanently lose) the user's
|
|
433
|
+
// original proxy configuration. Only a relabelled owner is worth a write.
|
|
434
|
+
if (snapshot.owner !== owner)
|
|
435
|
+
writeSnapshot({ ...snapshot, owner });
|
|
436
|
+
return getSystemProxyStatus(targetPort, bypassList);
|
|
437
|
+
}
|
|
263
438
|
const overrideHosts = ['localhost', '127.0.0.1', '<local>', ...bypassList.filter(Boolean)];
|
|
439
|
+
/** `switch` keeps the snapshot's PRE-OCR payload; only `snapshot` reads the OS. */
|
|
440
|
+
const original = plan === 'snapshot' ? undefined : snapshot;
|
|
264
441
|
if (platform === 'win32') {
|
|
265
|
-
const snap = await winRead();
|
|
442
|
+
const snap = original ? original.win : await winRead();
|
|
266
443
|
await winSet(targetServer, buildOverride(bypassList, platform));
|
|
267
|
-
writeSnapshot({ platform, setAt: Date.now(), targetServer, win: snap });
|
|
444
|
+
writeSnapshot({ platform, setAt: Date.now(), targetServer, owner, win: snap });
|
|
268
445
|
}
|
|
269
446
|
else if (platform === 'darwin') {
|
|
270
447
|
const services = await macServices();
|
|
271
|
-
const snaps = await Promise.all(services.map(macRead));
|
|
448
|
+
const snaps = original ? original.mac : await Promise.all(services.map(macRead));
|
|
272
449
|
await Promise.all(services.map(svc => macSet(svc, targetServer, overrideHosts)));
|
|
273
|
-
writeSnapshot({ platform, setAt: Date.now(), targetServer, mac: snaps });
|
|
450
|
+
writeSnapshot({ platform, setAt: Date.now(), targetServer, owner, mac: snaps });
|
|
274
451
|
}
|
|
275
452
|
else {
|
|
276
|
-
const snap = await gnomeRead();
|
|
453
|
+
const snap = original ? original.gnome : await gnomeRead();
|
|
277
454
|
await gnomeSet(targetServer, overrideHosts);
|
|
278
|
-
writeSnapshot({ platform, setAt: Date.now(), targetServer, gnome: snap });
|
|
455
|
+
writeSnapshot({ platform, setAt: Date.now(), targetServer, owner, gnome: snap });
|
|
279
456
|
}
|
|
280
457
|
return getSystemProxyStatus(targetPort, bypassList);
|
|
281
458
|
}
|
|
@@ -379,9 +379,9 @@ export declare function resolveSlug(repo: string, extensionDir: string | null |
|
|
|
379
379
|
* distinct so the message names the occupying repository instead of echoing a slug. Shared by the
|
|
380
380
|
* plugin and skill registration paths — the collision logic is one store rule, not two. */
|
|
381
381
|
export declare const SLUG_FAILURE_REASON: {
|
|
382
|
-
readonly repo_taken:
|
|
383
|
-
readonly slug_taken:
|
|
384
|
-
readonly slug_unavailable:
|
|
382
|
+
readonly repo_taken: "already_configured";
|
|
383
|
+
readonly slug_taken: "slug_taken";
|
|
384
|
+
readonly slug_unavailable: "invalid_source";
|
|
385
385
|
};
|
|
386
386
|
/**
|
|
387
387
|
* The slug for a repository that ANOTHER harness already carries and this one wants its own copy
|
|
@@ -6,7 +6,7 @@ import type { PluginMarketplaceInstall, PluginSpec } from './types.js';
|
|
|
6
6
|
* Native install command: `agy plugin install https://github.com/<repo>`.
|
|
7
7
|
*/
|
|
8
8
|
export declare class AntigravityAdapter extends BaseHostAdapter {
|
|
9
|
-
readonly id:
|
|
9
|
+
readonly id: "antigravity";
|
|
10
10
|
readonly extensionDir = ".antigravity-plugin";
|
|
11
11
|
readonly presence: {
|
|
12
12
|
command: string;
|
|
@@ -15,7 +15,7 @@ import { BaseHostAdapter, type HostMcpSpec, type MarketplaceSyncResult, type Nat
|
|
|
15
15
|
* Claude expands `${VAR}` from its own environment at startup.
|
|
16
16
|
*/
|
|
17
17
|
export declare class ClaudeAdapter extends BaseHostAdapter {
|
|
18
|
-
readonly id:
|
|
18
|
+
readonly id: "claude";
|
|
19
19
|
readonly extensionDir = ".claude-plugin";
|
|
20
20
|
readonly presence: {
|
|
21
21
|
command: string;
|
|
@@ -7,7 +7,7 @@ import type { SkillsSpec } from './types.js';
|
|
|
7
7
|
* `.agents/skills`). No native MCP or plugin landing.
|
|
8
8
|
*/
|
|
9
9
|
export declare class ClineAdapter extends BaseHostAdapter {
|
|
10
|
-
readonly id:
|
|
10
|
+
readonly id: "cline";
|
|
11
11
|
readonly extensionDir = ".clinerules";
|
|
12
12
|
readonly presence: {
|
|
13
13
|
command: string;
|
|
@@ -21,7 +21,7 @@ import type { PluginSpec, SkillsSpec } from './types.js';
|
|
|
21
21
|
* custom headers — only `--bearer-token-env-var`.
|
|
22
22
|
*/
|
|
23
23
|
export declare class CodexAdapter extends BaseHostAdapter {
|
|
24
|
-
readonly id:
|
|
24
|
+
readonly id: "codex";
|
|
25
25
|
readonly extensionDir = ".codex-plugin";
|
|
26
26
|
readonly presence: {
|
|
27
27
|
command: string;
|
|
@@ -5,7 +5,7 @@ import type { PluginSpec, SkillsSpec } from './types.js';
|
|
|
5
5
|
* Native plugin command: `/add-plugin <name>` (session-interactive).
|
|
6
6
|
*/
|
|
7
7
|
export declare class CursorAdapter extends BaseHostAdapter {
|
|
8
|
-
readonly id:
|
|
8
|
+
readonly id: "cursor";
|
|
9
9
|
readonly extensionDir = ".cursor-plugin";
|
|
10
10
|
readonly presence: {
|
|
11
11
|
command: string;
|
|
@@ -31,7 +31,7 @@ export declare function dshInstallProfiles(): {
|
|
|
31
31
|
exists: boolean;
|
|
32
32
|
}[];
|
|
33
33
|
export declare class DshAdapter extends BaseHostAdapter {
|
|
34
|
-
readonly id:
|
|
34
|
+
readonly id: "dsh";
|
|
35
35
|
readonly configRootEnv = "DSH_HOME";
|
|
36
36
|
readonly presence: {
|
|
37
37
|
command: string;
|
|
@@ -60,11 +60,11 @@ export declare class DshAdapter extends BaseHostAdapter {
|
|
|
60
60
|
args?: undefined;
|
|
61
61
|
timeoutMs?: undefined;
|
|
62
62
|
} | {
|
|
63
|
-
reason?: undefined;
|
|
64
63
|
ok: true;
|
|
65
64
|
command: string;
|
|
66
65
|
args: string[];
|
|
67
66
|
timeoutMs: number;
|
|
67
|
+
reason?: undefined;
|
|
68
68
|
};
|
|
69
69
|
declarations(_ctx: AdapterContext, scope: HarnessScope): {
|
|
70
70
|
file: string;
|
|
@@ -7,7 +7,7 @@ import type { PluginSpec } from './types.js';
|
|
|
7
7
|
* - `droid plugin install <plugin>@<marketplace> --scope user`
|
|
8
8
|
*/
|
|
9
9
|
export declare class FactoryAdapter extends BaseHostAdapter {
|
|
10
|
-
readonly id:
|
|
10
|
+
readonly id: "factory";
|
|
11
11
|
readonly extensionDir = ".factory-plugin";
|
|
12
12
|
readonly presence: {
|
|
13
13
|
command: string;
|
|
@@ -7,7 +7,7 @@ import type { SkillsSpec } from './types.js';
|
|
|
7
7
|
* alias tier on both scopes) and geminicli.com/docs/cli/skills.
|
|
8
8
|
*/
|
|
9
9
|
export declare class GeminiCliAdapter extends BaseHostAdapter {
|
|
10
|
-
readonly id:
|
|
10
|
+
readonly id: "gemini-cli";
|
|
11
11
|
readonly presence: {
|
|
12
12
|
command: string;
|
|
13
13
|
dir: string;
|
|
@@ -28,7 +28,7 @@ import type { PluginSpec, SkillsSpec } from './types.js';
|
|
|
28
28
|
* TOML literals (no `${KEY}` expansion), so an unnamed secret is refused per target.
|
|
29
29
|
*/
|
|
30
30
|
export declare class GrokAdapter extends BaseHostAdapter {
|
|
31
|
-
readonly id:
|
|
31
|
+
readonly id: "grok";
|
|
32
32
|
readonly extensionDir = ".grok-plugin";
|
|
33
33
|
readonly presence: {
|
|
34
34
|
command: string;
|
|
@@ -9,7 +9,7 @@ import type { McpRuntimeHostReport, PluginSpec, SkillsSpec } from './types.js';
|
|
|
9
9
|
* writing a reference the runtime would never resolve (`literalEnv`).
|
|
10
10
|
*/
|
|
11
11
|
export declare class KimiAdapter extends BaseHostAdapter {
|
|
12
|
-
readonly id:
|
|
12
|
+
readonly id: "kimi";
|
|
13
13
|
readonly configRootEnv = "KIMI_CODE_HOME";
|
|
14
14
|
readonly extensionDir = ".kimi-plugin";
|
|
15
15
|
readonly presence: {
|
|
@@ -6,7 +6,7 @@ import type { PluginSpec, SkillsSpec } from './types.js';
|
|
|
6
6
|
* Relocated by `PI_CONFIG_DIR`.
|
|
7
7
|
*/
|
|
8
8
|
export declare class OmpAdapter extends BaseHostAdapter {
|
|
9
|
-
readonly id:
|
|
9
|
+
readonly id: "omp";
|
|
10
10
|
readonly configRootEnv = "PI_CONFIG_DIR";
|
|
11
11
|
readonly presence: {
|
|
12
12
|
command: string;
|
|
@@ -18,7 +18,7 @@ import type { AdapterContext, PluginSpec, SkillsSpec } from './types.js';
|
|
|
18
18
|
* `<key=value>`, which the prose examples' `--header "K: V"` form misstates).
|
|
19
19
|
*/
|
|
20
20
|
export declare class OpenClawAdapter extends BaseHostAdapter {
|
|
21
|
-
readonly id:
|
|
21
|
+
readonly id: "openclaw";
|
|
22
22
|
readonly configRootEnv = "OPENCLAW_STATE_DIR";
|
|
23
23
|
readonly extensionDir = ".openclaw";
|
|
24
24
|
readonly presence: {
|
|
@@ -7,7 +7,7 @@ import type { McpRuntimeHostReport, PluginSpec, SkillsSpec } from './types.js';
|
|
|
7
7
|
* - npm: `opencode.json` config array merge
|
|
8
8
|
*/
|
|
9
9
|
export declare class OpencodeAdapter extends BaseHostAdapter {
|
|
10
|
-
readonly id:
|
|
10
|
+
readonly id: "opencode";
|
|
11
11
|
readonly configRootEnv = "OPENCODE_CONFIG_DIR";
|
|
12
12
|
readonly extensionDir = ".opencode";
|
|
13
13
|
readonly presence: {
|
|
@@ -7,7 +7,7 @@ import type { PluginSpec, SkillsSpec } from './types.js';
|
|
|
7
7
|
* npm plugin installs (`pi install npm:<spec>`).
|
|
8
8
|
*/
|
|
9
9
|
export declare class PiAdapter extends BaseHostAdapter {
|
|
10
|
-
readonly id:
|
|
10
|
+
readonly id: "pi";
|
|
11
11
|
readonly extensionDir = "pi-extension";
|
|
12
12
|
readonly presence: {
|
|
13
13
|
command: string;
|
|
@@ -5,7 +5,7 @@ import type { SkillsSpec } from './types.js';
|
|
|
5
5
|
* Location-only entry representing the shared directory every readsUniversal host reads.
|
|
6
6
|
*/
|
|
7
7
|
export declare class UniversalAdapter extends BaseHostAdapter {
|
|
8
|
-
readonly id:
|
|
8
|
+
readonly id: "universal";
|
|
9
9
|
/** The shared AGENTS convention's plugin layer — `.agents/plugins/marketplace.json` is the
|
|
10
10
|
* published catalog, and the DIRECTORY is the form a repository is detected by. */
|
|
11
11
|
readonly extensionDir = ".agents/plugins";
|
|
@@ -9,7 +9,7 @@ import type { SkillsSpec } from './types.js';
|
|
|
9
9
|
* reads `.windsurf/skills/` as a legacy location. No MCP or plugin landing.
|
|
10
10
|
*/
|
|
11
11
|
export declare class WindsurfAdapter extends BaseHostAdapter {
|
|
12
|
-
readonly id:
|
|
12
|
+
readonly id: "windsurf";
|
|
13
13
|
readonly extensionDir = ".windsurf";
|
|
14
14
|
readonly presence: {
|
|
15
15
|
command: string;
|
|
@@ -2,7 +2,7 @@ import { BaseHostAdapter } from './base.js';
|
|
|
2
2
|
import type { SkillsSpec } from './types.js';
|
|
3
3
|
/** Zed — reads the shared cross-agent skills directory. */
|
|
4
4
|
export declare class ZedAdapter extends BaseHostAdapter {
|
|
5
|
-
readonly id:
|
|
5
|
+
readonly id: "zed";
|
|
6
6
|
readonly presence: {
|
|
7
7
|
command: string;
|
|
8
8
|
dir: string;
|
|
@@ -2,7 +2,7 @@ import type { BrowseResult } from '../common/market.js';
|
|
|
2
2
|
import type { HarnessSourceView } from '../types.js';
|
|
3
3
|
import { type FailureReason } from '../net.js';
|
|
4
4
|
/** The three boards the site publishes, in the site's own tab order. */
|
|
5
|
-
export declare const SKILLS_SH_BOARDS: readonly [
|
|
5
|
+
export declare const SKILLS_SH_BOARDS: readonly ["all-time", "trending", "hot"];
|
|
6
6
|
export type SkillsShBoard = (typeof SKILLS_SH_BOARDS)[number];
|
|
7
7
|
/** Rows one BOARD answer carries — the site's own page size, not a console choice. */
|
|
8
8
|
export declare const SKILLS_SH_PAGE_SIZE = 200;
|
|
@@ -368,29 +368,58 @@ export function translationChain() {
|
|
|
368
368
|
}
|
|
369
369
|
return chainFor(configured);
|
|
370
370
|
}
|
|
371
|
+
/**
|
|
372
|
+
* Model refs whose upstream refused the thinking pin. Keyed by the ref the
|
|
373
|
+
* operator configured (a physical id is exact; a tier alias is a safe
|
|
374
|
+
* over-approximation — one member rejecting it costs the pool a latency
|
|
375
|
+
* optimization, never a translation). The first call pays one 400 and
|
|
376
|
+
* learns; later calls never send the pin again.
|
|
377
|
+
*/
|
|
378
|
+
const effortPinRejectedModels = new Set();
|
|
379
|
+
/** Short, whitespace-collapsed body snippet — actionable, never a full dump. */
|
|
380
|
+
async function errorSnippet(response) {
|
|
381
|
+
try {
|
|
382
|
+
return (await response.text()).replace(/\s+/g, ' ').trim().slice(0, 200);
|
|
383
|
+
}
|
|
384
|
+
catch {
|
|
385
|
+
return ''; // body unreadable — the status code is the whole message
|
|
386
|
+
}
|
|
387
|
+
}
|
|
371
388
|
/** One gateway round-trip for a fixed model ref. Errors are values, so the caller can retry. */
|
|
372
389
|
async function callGateway(key, model, text, lang, systemPrompt = SYSTEM_PROMPT, sessionId,
|
|
373
390
|
/** Per-round-trip ceiling; the document deadline hands a shorter one to the last attempts. */
|
|
374
391
|
timeoutMs = MD_CALL_TIMEOUT_MS) {
|
|
392
|
+
// Thinking pin. Translation is a mechanical internal call — a thinking model
|
|
393
|
+
// must not burn reasoning tokens on a two-sentence answer, and this WAS the
|
|
394
|
+
// reported slowness: the configured translator (deepseek-v4-flash) thought by
|
|
395
|
+
// default because the request sent no effort at all, so the vendor's default
|
|
396
|
+
// (high-ish) ran before every answer. 'low' rather than 'none': the chain may
|
|
397
|
+
// name a model whose effort enum lacks 'none' (e.g. low|high|max) and an
|
|
398
|
+
// invalid level would 400 into the lite fallback — slower than thinking
|
|
399
|
+
// briefly. The gateway's own machinery (effortMap, capability clamp) still
|
|
400
|
+
// applies, and a vendor that refuses the field outright is handled below:
|
|
401
|
+
// the pin is an optimization, never a reason to lose the translation.
|
|
402
|
+
const post = (pinEffort) => fetch(`http://127.0.0.1:${defaultGatewayPort()}/v1/chat/completions`, {
|
|
403
|
+
method: 'POST',
|
|
404
|
+
headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${key}` },
|
|
405
|
+
body: JSON.stringify({
|
|
406
|
+
model,
|
|
407
|
+
temperature: 0,
|
|
408
|
+
...(pinEffort ? { reasoning_effort: 'low' } : {}),
|
|
409
|
+
messages: [
|
|
410
|
+
{ role: 'system', content: systemPrompt },
|
|
411
|
+
{ role: 'user', content: `Target language: ${LANG_LABEL[lang]}\n\n${text}` },
|
|
412
|
+
],
|
|
413
|
+
// Pin the reserved internal-session namespace (ADR-0015) so these
|
|
414
|
+
// loopback calls share one session instead of minting a fresh
|
|
415
|
+
// cold_start session per call — the id IS the internal marker.
|
|
416
|
+
...(sessionId ? { router_options: { session_id: sessionId } } : {}),
|
|
417
|
+
}),
|
|
418
|
+
signal: AbortSignal.timeout(Math.max(1, timeoutMs)),
|
|
419
|
+
});
|
|
375
420
|
let response;
|
|
376
421
|
try {
|
|
377
|
-
response = await
|
|
378
|
-
method: 'POST',
|
|
379
|
-
headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${key}` },
|
|
380
|
-
body: JSON.stringify({
|
|
381
|
-
model,
|
|
382
|
-
temperature: 0,
|
|
383
|
-
messages: [
|
|
384
|
-
{ role: 'system', content: systemPrompt },
|
|
385
|
-
{ role: 'user', content: `Target language: ${LANG_LABEL[lang]}\n\n${text}` },
|
|
386
|
-
],
|
|
387
|
-
// Pin the reserved internal-session namespace (ADR-0015) so these
|
|
388
|
-
// loopback calls share one session instead of minting a fresh
|
|
389
|
-
// cold_start session per call — the id IS the internal marker.
|
|
390
|
-
...(sessionId ? { router_options: { session_id: sessionId } } : {}),
|
|
391
|
-
}),
|
|
392
|
-
signal: AbortSignal.timeout(Math.max(1, timeoutMs)),
|
|
393
|
-
});
|
|
422
|
+
response = await post(!effortPinRejectedModels.has(model));
|
|
394
423
|
}
|
|
395
424
|
catch (e) {
|
|
396
425
|
return { error: `${model}: ${e instanceof Error ? e.message : String(e)}` };
|
|
@@ -398,12 +427,26 @@ timeoutMs = MD_CALL_TIMEOUT_MS) {
|
|
|
398
427
|
if (!response.ok) {
|
|
399
428
|
// The upstream body often names the real cause (unknown modelRef, empty tier pool, auth) —
|
|
400
429
|
// carry a short snippet so a failing leg stays actionable instead of a bare status code.
|
|
401
|
-
|
|
430
|
+
const detail = await errorSnippet(response);
|
|
431
|
+
// A vendor may refuse the pin itself: its enum can lack 'low', and a model
|
|
432
|
+
// with no thinking axis is clamped to 'none' by the gateway — which the
|
|
433
|
+
// openai wire forwards verbatim, and strict vendors 400 on that. Re-ask
|
|
434
|
+
// ONCE without the pin and remember the refusal for this ref.
|
|
435
|
+
const pinRejected = (response.status === 400 || response.status === 422) && /reasoning_effort/i.test(detail);
|
|
436
|
+
if (!pinRejected) {
|
|
437
|
+
return { error: `${model}: gateway returned HTTP ${response.status}${detail ? ` — ${detail}` : ''}` };
|
|
438
|
+
}
|
|
439
|
+
effortPinRejectedModels.add(model);
|
|
402
440
|
try {
|
|
403
|
-
|
|
441
|
+
response = await post(false);
|
|
442
|
+
}
|
|
443
|
+
catch (e) {
|
|
444
|
+
return { error: `${model}: ${e instanceof Error ? e.message : String(e)}` };
|
|
445
|
+
}
|
|
446
|
+
if (!response.ok) {
|
|
447
|
+
const retryDetail = await errorSnippet(response);
|
|
448
|
+
return { error: `${model}: gateway returned HTTP ${response.status}${retryDetail ? ` — ${retryDetail}` : ''}` };
|
|
404
449
|
}
|
|
405
|
-
catch { /* body unreadable — the status code is the whole message */ }
|
|
406
|
-
return { error: `${model}: gateway returned HTTP ${response.status}${detail ? ` — ${detail}` : ''}` };
|
|
407
450
|
}
|
|
408
451
|
const payload = (await response.json());
|
|
409
452
|
const choice = payload.choices?.[0];
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Harness domain vocabulary (ADR-0015).
|
|
3
3
|
*
|
|
4
|
-
* `client` = a runtime hooked for traffic (
|
|
4
|
+
* `client` = a runtime hooked for traffic (a client id, core or package-declared). `harness` = that runtime considered as an
|
|
5
5
|
* artifact host. They are deliberately different vocabularies: hosts like Cursor/Zed will never be
|
|
6
6
|
* traffic clients, and welding the two would pollute the traffic domain.
|
|
7
7
|
*/
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Harness domain vocabulary (ADR-0015).
|
|
3
3
|
*
|
|
4
|
-
* `client` = a runtime hooked for traffic (
|
|
4
|
+
* `client` = a runtime hooked for traffic (a client id, core or package-declared). `harness` = that runtime considered as an
|
|
5
5
|
* artifact host. They are deliberately different vocabularies: hosts like Cursor/Zed will never be
|
|
6
6
|
* traffic clients, and welding the two would pollute the traffic domain.
|
|
7
7
|
*/
|