@bitkyc08/opencodex 2.100.6 → 2.100.7-preview.20261120.1
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/gui/dist/assets/App-Te21Q-Fv.js +65 -0
- package/gui/dist/assets/App-hklyKJR5.css +1 -0
- package/gui/dist/assets/{Tray-CVqm4S4W.js → Tray-Bto-DJ6b.js} +1 -1
- package/gui/dist/assets/brand-mark-CCRs3Ywg.js +1 -0
- package/gui/dist/assets/index-B85uU8rK.css +2 -0
- package/gui/dist/assets/index-Befqr0m8.js +138 -0
- package/gui/dist/assets/{segment-thumb-features-COdzmORE.js → segment-thumb-features-CKFf9DaQ.js} +1 -1
- package/gui/dist/classic/assets/App-BPkhxI3i.js +64 -0
- package/gui/dist/classic/assets/App-DSivR528.css +1 -0
- package/gui/dist/classic/assets/{Tray-BDlcOLDK.js → Tray-CSRN8p3a.js} +1 -1
- package/gui/dist/classic/assets/index-BHM1aTF8.js +138 -0
- package/gui/dist/classic/assets/usage-companion-chart-DC8ve7g8.js +1 -0
- package/gui/dist/classic/index.html +1 -1
- package/gui/dist/index.html +2 -2
- package/package.json +2 -2
- package/src/adapters/coding-agent/process-tree.ts +30 -0
- package/src/adapters/coding-agent/profile.ts +1 -1
- package/src/adapters/coding-agent/turn.ts +2 -9
- package/src/adapters/command-code-decision-guard.ts +25 -0
- package/src/adapters/cursor/catalog.ts +14 -0
- package/src/adapters/cursor/effort-map.ts +3 -0
- package/src/adapters/google-usage.ts +28 -0
- package/src/adapters/google.ts +9 -26
- package/src/adapters/qoder/adapter.ts +197 -13
- package/src/adapters/registry.ts +13 -0
- package/src/adapters/step-cli/adapter.ts +401 -0
- package/src/adapters/step-cli/constants.ts +11 -0
- package/src/adapters/step-cli/conversation.ts +159 -0
- package/src/adapters/step-cli/env.ts +49 -0
- package/src/adapters/step-cli/errors.ts +76 -0
- package/src/adapters/step-cli/events.ts +227 -0
- package/src/adapters/step-cli/profiles.ts +134 -0
- package/src/adapters/step-cli/projection.ts +242 -0
- package/src/adapters/step-cli/registry.ts +181 -0
- package/src/adapters/step-cli/session-pool.ts +225 -0
- package/src/adapters/step-cli/session.ts +842 -0
- package/src/adapters/step-cli/stdio-frames.ts +330 -0
- package/src/adapters/step-cli/tool-bridge.ts +92 -0
- package/src/cli/claude.ts +5 -2
- package/src/client/link-management-relay.ts +11 -0
- package/src/client/machine-listener.ts +6 -2
- package/src/codex/account-label.ts +1 -1
- package/src/codex/catalog/gather-capture.ts +2 -1
- package/src/codex/catalog/metadata.ts +48 -2
- package/src/codex/catalog/model-hints.ts +19 -5
- package/src/codex/catalog/model-visibility.ts +4 -7
- package/src/codex/catalog/native-ultrafast.ts +8 -6
- package/src/generated/compatibility-version.json +137 -61
- package/src/generated/model-metadata.ts +1 -1
- package/src/lib/client-error-body.ts +2 -0
- package/src/lib/messages-error-body.ts +3 -1
- package/src/lib/optional-shutdown-hooks.ts +55 -5
- package/src/lib/process-control.ts +3 -2
- package/src/lib/shutdown-budget.ts +5 -0
- package/src/link/remote-platform.ts +24 -9
- package/src/link/ssh-argv.ts +8 -2
- package/src/link/ssh-runner.ts +15 -2
- package/src/oauth/m365-copilot-web-session.ts +28 -4
- package/src/protocols/dto.ts +24 -12
- package/src/protocols/settings.ts +20 -16
- package/src/protocols/shadow.ts +2 -3
- package/src/protocols/trace.ts +24 -2
- package/src/providers/command-code-decision-models.ts +65 -0
- package/src/providers/quota.ts +4 -4
- package/src/providers/registry/entries-core.ts +18 -7
- package/src/providers/registry/entries-extended.ts +41 -0
- package/src/providers/registry/model-seeds.ts +42 -0
- package/src/providers/resolved-model-policy-merge.ts +8 -0
- package/src/providers/resolved-model-policy.ts +185 -165
- package/src/providers/slug-codec.ts +5 -0
- package/src/server/chat-native-eligibility.ts +5 -0
- package/src/server/credential-recovery-attempt.ts +2 -2
- package/src/server/gemini-inbound.ts +15 -11
- package/src/server/gemini-native-catalog.ts +27 -2
- package/src/server/gemini-native-wire.ts +71 -6
- package/src/server/gemini-native.ts +129 -34
- package/src/server/index/gemini-routes.ts +6 -1
- package/src/server/lifecycle.ts +2 -1
- package/src/server/management/agent-settings-routes.ts +26 -28
- package/src/server/management/api-access.ts +5 -3
- package/src/server/management/protocol-routes.ts +3 -1
- package/src/server/management/protocol-settings-patch.ts +25 -10
- package/src/server/management/shared.ts +20 -5
- package/src/server/messages-native-eligibility.ts +4 -0
- package/src/server/messages-native-tool-guard.ts +18 -5
- package/src/server/request-log-generation-window.ts +7 -2
- package/src/server/responses/command-code-decision-refusal.ts +24 -0
- package/src/server/responses/compact.ts +2 -2
- package/src/server/responses/core-combo.ts +18 -3
- package/src/server/responses/core-pipeline.ts +6 -0
- package/src/server/responses/sidecar-execution.ts +10 -7
- package/src/types/config.ts +2 -0
- package/src/usage/expected-prices.ts +17 -0
- package/src/usage/telemetry-contract.ts +3 -0
- package/gui/dist/assets/App-BI8LQ7Qk.css +0 -1
- package/gui/dist/assets/App-CsZ1Gr7S.js +0 -60
- package/gui/dist/assets/brand-mark-BebhnAtV.js +0 -1
- package/gui/dist/assets/index-BtwVlpeQ.css +0 -2
- package/gui/dist/assets/index-CEeMegqE.js +0 -138
- package/gui/dist/classic/assets/App-BJgUWNJ8.js +0 -59
- package/gui/dist/classic/assets/App-CoiVLRW3.css +0 -1
- package/gui/dist/classic/assets/index-B9Jgli_W.js +0 -138
- package/gui/dist/classic/assets/usage-companion-chart-vbzDcND0.js +0 -1
|
@@ -47,7 +47,7 @@ const DATA: Record<string, readonly Row[]> = {
|
|
|
47
47
|
"azure-openai": [["gpt-4.1",1047576,32768,"text,image",0,null,2,8,0.5,0],["gpt-4o",128000,16384,"text,image",0,null,2.5,10,1.25,0],["gpt-4o-mini",128000,16384,"text,image",0,null,0.15,0.6,0.075,0],["o3",200000,100000,"text,image",1,null,2,8,0.5,0],["o3-mini",200000,100000,"text",1,null,1.1,4.4,0.55,0]],
|
|
48
48
|
"cerebras": [["gemma-4-31b",131072,40960,"text,image",1,null,0.99,1.49,0,0],["gpt-oss-120b",131072,40960,"text",1,null,0.35,0.75,0,0],["llama3.1-8b",32000,8000,"text",0,null,0.1,0.1,0,0],["qwen-3-235b-a22b-instruct-2507",131000,32000,"text",0,null,0.6,1.2,0,0],["qwen-3-coder-480b",131072,32768,"text",0,null,0,0,0,0],["zai-glm-4.6",131072,32768,"text",0,null,0,0,0,0],["zai-glm-4.7",131072,40960,"text",1,null,2.25,2.75,2.25,0]],
|
|
49
49
|
"deepseek": [["deepseek-v4-flash",1048576,384000,"text",1,null,0.14,0.28,0.0028,0],["deepseek-v4-pro",1048576,384000,"text",1,null,0.435,0.87,0.003625,0]],
|
|
50
|
-
"google": [["deep-research-max-preview-04-2026",131072,65536,"text,image",1,null,2,12,0.2,0],["deep-research-preview-04-2026",131072,65536,"text,image",1,null,2,12,0.2,0],["gemini-1.5-flash",1000000,8192,"text,image",0,null,0.075,0.3,0.01875,0],["gemini-1.5-flash-8b",1000000,8192,"text,image",0,null,0.0375,0.15,0.01,0],["gemini-1.5-pro",1000000,8192,"text,image",0,null,1.25,5,0.3125,0],["gemini-2.0-flash",1048576,8192,"text,image",0,null,0.1,0.4,0.025,0],["gemini-2.0-flash-lite",1048576,8192,"text,image",0,null,0.075,0.3,0,0],["gemini-2.5-computer-use-preview-10-2025",131072,65536,"text,image",1,null,1.25,10,0,0],["gemini-2.5-flash",1048576,65536,"text,image",1,null,0.3,2.5,0.03,0],["gemini-2.5-flash-lite",1048576,65536,"text,image",1,null,0.1,0.4,0.01,0],["gemini-2.5-flash-lite-preview-06-17",1048576,65536,"text,image",1,null,0.1,0.4,0.025,0],["gemini-2.5-flash-lite-preview-09-2025",1048576,65536,"text,image",1,null,0.1,0.4,0.025,0],["gemini-2.5-flash-preview-04-17",1048576,65536,"text,image",1,null,0.15,0.6,0.0375,0],["gemini-2.5-flash-preview-05-20",1048576,65536,"text,image",1,null,0.15,0.6,0.0375,0],["gemini-2.5-flash-preview-09-2025",1048576,65536,"text,image",1,null,0.3,2.5,0.075,0],["gemini-2.5-pro",1048576,65536,"text,image",1,null,1.25,10,0.125,0],["gemini-2.5-pro-preview-05-06",1048576,65536,"text,image",1,null,1.25,10,0.31,0],["gemini-2.5-pro-preview-06-05",1048576,65536,"text,image",1,null,1.25,10,0.31,0],["gemini-3-flash-preview",1048576,65536,"text,image",1,null,0.5,3,0.05,0],["gemini-3-pro-preview",1048576,65536,"text,image",1,null,2,12,0.2,0],["gemini-3.1-flash-lite",1048576,65536,"text,image",1,null,0.25,1.5,0.025,0],["gemini-3.1-flash-lite-image",65536,65536,"text,image",1,null,0.25,30,0,0],["gemini-3.1-flash-lite-preview",1048576,65536,"text,image",1,null,0.25,1.5,0.025,0],["gemini-3.1-flash-live-preview",131072,65536,"text,image",1,null,0.75,4.5,0,0],["gemini-3.1-pro-preview",1048576,65536,"text,image",1,null,2,12,0.2,0],["gemini-3.1-pro-preview-customtools",1048576,65536,"text,image",1,null,2,12,0.2,0],["gemini-3.5-flash",1048576,65536,"text,image",1,null,1.5,9,0.15,0],["gemini-3.5-flash-lite",1048576,65536,"text,image",1,null,0.3,2.5,0.03,0],["gemini-3.6-flash",1048576,65536,"text,image",1,null,1.5,7.5,0.15,0],["gemini-3.7-flash",1048576,65536,"text,image",1],["gemini-3.8-flash",1048576,65536,"text,image",1],["gemini-4-argon",1048576,65536,"text,image",1],["gemini-4-carbon",1048576,65536,"text,image",1],["gemini-4-hydrogen",1048576,65536,"text,image",1],["gemini-flash-latest",1048576,65536,"text,image",1,null,1.5,9,0.15,0],["gemini-flash-lite-latest",1048576,65536,"text,image",1,null,0.25,1.5,0.025,0],["gemini-live-2.5-flash",128000,8000,"text,image",1,null,0.5,2,0,0],["gemini-live-2.5-flash-preview-native-audio",131072,65536,"text",1,null,0.5,2,0,0],["gemini-robotics-er-1.6-preview",131072,65536,"text,image",1,null,1,5,0,0],["gemma-3-27b-it",131072,8192,"text,image",0,null,0,0,0,0],["gemma-4-26b",256000,8192,"text,image",1,null,0,0,0,0],["gemma-4-26b-a4b-it",262144,32768,"text,image",1,null,0,0,0,0],["gemma-4-26b-it",256000,8192,"text,image",1,null,0,0,0,0],["gemma-4-31b",256000,8192,"text,image",1,null,0,0,0,0],["gemma-4-31b-it",262144,32768,"text,image",1,null,0,0,0,0],["gemma-4-E2B-it",131072,8192,"text,image",1,null,0,0,0,0],["gemma-4-E4B-it",131072,8192,"text,image",1,null,0,0,0,0]],
|
|
50
|
+
"google": [["deep-research-max-preview-04-2026",131072,65536,"text,image",1,null,2,12,0.2,0],["deep-research-preview-04-2026",131072,65536,"text,image",1,null,2,12,0.2,0],["gemini-1.5-flash",1000000,8192,"text,image",0,null,0.075,0.3,0.01875,0],["gemini-1.5-flash-8b",1000000,8192,"text,image",0,null,0.0375,0.15,0.01,0],["gemini-1.5-pro",1000000,8192,"text,image",0,null,1.25,5,0.3125,0],["gemini-2.0-flash",1048576,8192,"text,image",0,null,0.1,0.4,0.025,0],["gemini-2.0-flash-lite",1048576,8192,"text,image",0,null,0.075,0.3,0,0],["gemini-2.5-computer-use-preview-10-2025",131072,65536,"text,image",1,null,1.25,10,0,0],["gemini-2.5-flash",1048576,65536,"text,image",1,null,0.3,2.5,0.03,0],["gemini-2.5-flash-lite",1048576,65536,"text,image",1,null,0.1,0.4,0.01,0],["gemini-2.5-flash-lite-preview-06-17",1048576,65536,"text,image",1,null,0.1,0.4,0.025,0],["gemini-2.5-flash-lite-preview-09-2025",1048576,65536,"text,image",1,null,0.1,0.4,0.025,0],["gemini-2.5-flash-preview-04-17",1048576,65536,"text,image",1,null,0.15,0.6,0.0375,0],["gemini-2.5-flash-preview-05-20",1048576,65536,"text,image",1,null,0.15,0.6,0.0375,0],["gemini-2.5-flash-preview-09-2025",1048576,65536,"text,image",1,null,0.3,2.5,0.075,0],["gemini-2.5-pro",1048576,65536,"text,image",1,null,1.25,10,0.125,0],["gemini-2.5-pro-preview-05-06",1048576,65536,"text,image",1,null,1.25,10,0.31,0],["gemini-2.5-pro-preview-06-05",1048576,65536,"text,image",1,null,1.25,10,0.31,0],["gemini-3-flash-preview",1048576,65536,"text,image",1,null,0.5,3,0.05,0],["gemini-3-pro-preview",1048576,65536,"text,image",1,null,2,12,0.2,0],["gemini-3.1-flash-lite",1048576,65536,"text,image",1,null,0.25,1.5,0.025,0],["gemini-3.1-flash-lite-image",65536,65536,"text,image",1,null,0.25,30,0,0],["gemini-3.1-flash-lite-preview",1048576,65536,"text,image",1,null,0.25,1.5,0.025,0],["gemini-3.1-flash-live-preview",131072,65536,"text,image",1,null,0.75,4.5,0,0],["gemini-3.1-pro-preview",1048576,65536,"text,image",1,null,2,12,0.2,0],["gemini-3.1-pro-preview-customtools",1048576,65536,"text,image",1,null,2,12,0.2,0],["gemini-3.5-flash",1048576,65536,"text,image",1,null,1.5,9,0.15,0],["gemini-3.5-flash-lite",1048576,65536,"text,image",1,null,0.3,2.5,0.03,0],["gemini-3.6-flash",1048576,65536,"text,image",1,null,1.5,7.5,0.15,0],["gemini-3.7-flash",1048576,65536,"text,image",1],["gemini-3.8-flash",1048576,65536,"text,image",1],["gemini-4-argon",1048576,65536,"text,image",1],["gemini-4-carbon",1048576,65536,"text,image",1],["gemini-4-hydrogen",1048576,65536,"text,image",1],["gemini-4-neon",1048576,65536,"text,image",1],["gemini-flash-latest",1048576,65536,"text,image",1,null,1.5,9,0.15,0],["gemini-flash-lite-latest",1048576,65536,"text,image",1,null,0.25,1.5,0.025,0],["gemini-live-2.5-flash",128000,8000,"text,image",1,null,0.5,2,0,0],["gemini-live-2.5-flash-preview-native-audio",131072,65536,"text",1,null,0.5,2,0,0],["gemini-robotics-er-1.6-preview",131072,65536,"text,image",1,null,1,5,0,0],["gemma-3-27b-it",131072,8192,"text,image",0,null,0,0,0,0],["gemma-4-26b",256000,8192,"text,image",1,null,0,0,0,0],["gemma-4-26b-a4b-it",262144,32768,"text,image",1,null,0,0,0,0],["gemma-4-26b-it",256000,8192,"text,image",1,null,0,0,0,0],["gemma-4-31b",256000,8192,"text,image",1,null,0,0,0,0],["gemma-4-31b-it",262144,32768,"text,image",1,null,0,0,0,0],["gemma-4-E2B-it",131072,8192,"text,image",1,null,0,0,0,0],["gemma-4-E4B-it",131072,8192,"text,image",1,null,0,0,0,0]],
|
|
51
51
|
"minimax": [["MiniMax-M2",196608,128000,"text",1,null,0.3,1.2,0,0],["MiniMax-M2.1",204800,131072,"text",1,null,0.3,1.2,0,0],["MiniMax-M2.5",204800,131072,"text",1,null,0.3,1.2,0.03,0.375],["MiniMax-M2.5-highspeed",204800,131072,"text",1,null,0.6,2.4,0.06,0.375],["MiniMax-M2.5-lightning",204800,32000,"text",1,null,0.3,2.4,0,0],["MiniMax-M2.7",204800,131072,"text",1,null,0.3,1.2,0.06,0.375],["MiniMax-M2.7-highspeed",204800,131072,"text",1,null,0.6,2.4,0.06,0.375],["minimax-m3",512000,128000,"text,image",1,null,0.6,2.4,0.12,0],["MiniMax-M3",1000000,128000,"text,image,video",1,null,0.3,1.2,0.06,0],["MiniMax-M3.1-Flash",1000000,524288,"text,image,video",1,null,0.15,0.6,0.015,0]],
|
|
52
52
|
"mistral": [["codestral-latest",256000,4096,"text",0,null,0.3,0.9,0,0],["devstral-2512",262144,262144,"text",0,null,0.4,2,0,0],["devstral-latest",262144,262144,"text",0,null,0.4,2,0,0],["devstral-medium-2507",128000,128000,"text",0,null,0.4,2,0,0],["devstral-medium-latest",262144,262144,"text",0,null,0.4,2,0,0],["devstral-small-2505",128000,128000,"text",0,null,0.1,0.3,0,0],["devstral-small-2507",128000,128000,"text",0,null,0.1,0.3,0,0],["labs-devstral-small-2512",256000,256000,"text,image",0,null,0,0,0,0],["magistral-medium-latest",128000,16384,"text",1,null,2,5,0,0],["magistral-small",128000,128000,"text",1,null,0.5,1.5,0,0],["ministral-3b-latest",128000,128000,"text",0,null,0.04,0.04,0,0],["ministral-8b-latest",128000,128000,"text",0,null,0.1,0.1,0,0],["mistral-large-2411",131072,16384,"text",0,null,2,6,0,0],["mistral-large-2512",262144,262144,"text,image",0,null,0.5,1.5,0,0],["mistral-large-latest",262144,262144,"text,image",0,null,0.5,1.5,0,0],["mistral-medium-2505",131072,131072,"text,image",0,null,0.4,2,0,0],["mistral-medium-2508",262144,262144,"text,image",0,null,0.4,2,0,0],["mistral-medium-2604",262144,262144,"text,image",1,null,1.5,7.5,0,0],["mistral-medium-latest",262144,262144,"text,image",1,null,1.5,7.5,0,0],["mistral-nemo",128000,128000,"text",0,null,0.15,0.15,0,0],["mistral-small-2506",128000,16384,"text,image",0,null,0.1,0.3,0,0],["mistral-small-2603",256000,256000,"text,image",1,null,0.15,0.6,0,0],["mistral-small-latest",256000,256000,"text,image",1,null,0.15,0.6,0,0],["open-mistral-7b",8000,8000,"text",0,null,0.25,0.25,0,0],["open-mistral-nemo",128000,128000,"text",0,null,0.15,0.15,0,0],["open-mixtral-8x22b",64000,64000,"text",0,null,2,6,0,0],["open-mixtral-8x7b",32000,32000,"text",0,null,0.7,0.7,0,0],["pixtral-12b",128000,128000,"text,image",0,null,0.15,0.15,0,0],["pixtral-large-latest",128000,128000,"text,image",0,null,2,6,0,0]],
|
|
53
53
|
"moonshot": [["kimi-k2.5",262144,65536,"text,image",1,null,0,0,0,0]],
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { CYBER_POLICY_FALLBACK_MESSAGE, classifyError } from "./errors";
|
|
2
2
|
import { classifyUpstreamCondition, upstreamConditionMessage, type UpstreamConditionEvidence } from "./upstream-condition";
|
|
3
3
|
import { isDeveloperRoleRejection } from "./developer-role-rejection";
|
|
4
|
+
import { COMMAND_CODE_DECISION_MODEL_MESSAGE } from "../providers/command-code-decision-models";
|
|
4
5
|
|
|
5
6
|
const openaiTypes = ["invalid_request_error", "authentication_error", "permission_error", "not_found_error", "rate_limit_error", "server_error", "upstream_error", "insufficient_quota", "client_cancelled", "cyber_policy", "model_not_allowed_for_key", "api_error", "overloaded_error"] as const;
|
|
6
7
|
const openaiCodes = [
|
|
@@ -230,6 +231,7 @@ const PROXY_FIXED_MESSAGES: ReadonlyMap<string, string> = literalMap([
|
|
|
230
231
|
"upstream stream stalled without meaningful progress",
|
|
231
232
|
"routed provider emitted a client tool call outside the current request's explicit tool catalog",
|
|
232
233
|
"upstream stream ended before a terminal frame (truncated response)",
|
|
234
|
+
COMMAND_CODE_DECISION_MODEL_MESSAGE,
|
|
233
235
|
] as const);
|
|
234
236
|
export function fixedProxyErrorMessage(message: unknown): string | undefined {
|
|
235
237
|
return typeof message === "string" ? PROXY_FIXED_MESSAGES.get(message) : undefined;
|
|
@@ -2,7 +2,7 @@ import { carryReplayRefusal, isNonReplayableResponse, markResponseNonReplayable
|
|
|
2
2
|
import { appendClientRetryIn } from "./client-retry-after";
|
|
3
3
|
import {
|
|
4
4
|
ANTHROPIC_ERROR_CODES, ANTHROPIC_ERROR_TYPES, CLAUDE_CONTEXT_OVERFLOW_MESSAGE,
|
|
5
|
-
CLIENT_ERROR_CONTRACTS, clientErrorCodeMessage, actionableRefusalMessage, isProxyError, attachComboFailureEvidence, carryProxyError, proxyErrorPresentation, comboFailureEvidence, markProxyError, type ProxyErrorPresentation, type ClientErrorContract,
|
|
5
|
+
CLIENT_ERROR_CONTRACTS, clientErrorCodeMessage, actionableRefusalMessage, isProxyError, attachComboFailureEvidence, carryProxyError, proxyErrorPresentation, comboFailureEvidence, markProxyError, fixedProxyErrorMessage, type ProxyErrorPresentation, type ClientErrorContract,
|
|
6
6
|
} from "./client-error-body";
|
|
7
7
|
import { classifyUpstreamCondition, upstreamConditionMessage, type UpstreamCondition, type UpstreamConditionEvidence } from "./upstream-condition";
|
|
8
8
|
|
|
@@ -84,6 +84,8 @@ export function ownedAnthropicErrorPayload(options: OwnedAnthropicErrorOptions):
|
|
|
84
84
|
: options.localError && isProxyError(options.localError) ? fixedLocalMessage(options.localError, options.evidence.code ?? code, options.evidence.type) ?? options.localError.message
|
|
85
85
|
: actionableRefusalMessage(options.evidence, code ?? null, options.contract)
|
|
86
86
|
?? (options.contract ? CLIENT_ERROR_CONTRACTS[options.contract] : undefined)
|
|
87
|
+
// The same fixed proxy sentences the Chat presenter passes through (ownedChatErrorPayload).
|
|
88
|
+
?? (options.contract === undefined ? fixedProxyErrorMessage(options.evidence.message) : undefined)
|
|
87
89
|
?? (options.condition ? upstreamConditionMessage(options.condition) : undefined)
|
|
88
90
|
?? clientErrorCodeMessage(code)
|
|
89
91
|
?? upstreamConditionMessage(classifyUpstreamCondition(options.evidence) ?? "upstream_failed");
|
|
@@ -12,16 +12,19 @@
|
|
|
12
12
|
* A subsystem registers its teardown when it activates. A process that never activates it
|
|
13
13
|
* registers nothing, so shutdown does no work and loads no module.
|
|
14
14
|
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
* `server.stop` — from running.
|
|
15
|
+
* Synchronous hooks are best-effort. Subsystems that own processes can register an
|
|
16
|
+
* asynchronous cleanup receipt with its own bounded wait after the active-turn drain.
|
|
18
17
|
*
|
|
19
18
|
* See devlog/_fin/260814_lab_core_decoupling/010_lifecycle_shutdown_registry.md
|
|
20
19
|
*/
|
|
21
20
|
|
|
21
|
+
import { OPTIONAL_SHUTDOWN_GRACE_MS } from "./shutdown-budget";
|
|
22
|
+
|
|
22
23
|
type ShutdownHook = () => void;
|
|
24
|
+
type AsyncShutdownHook = { run: (deadlineMs: number) => Promise<void>; onIncomplete?: ShutdownHook };
|
|
23
25
|
|
|
24
26
|
const hooks = new Map<string, ShutdownHook>();
|
|
27
|
+
const asyncHooks = new Map<string, AsyncShutdownHook>();
|
|
25
28
|
let hooksRan = false;
|
|
26
29
|
|
|
27
30
|
/**
|
|
@@ -47,13 +50,24 @@ export function registerOptionalShutdownHook(key: string, hook: ShutdownHook): (
|
|
|
47
50
|
};
|
|
48
51
|
}
|
|
49
52
|
|
|
53
|
+
/** The async hook shares the absolute stop deadline. Its fallback must finish synchronously. */
|
|
54
|
+
export function registerAsyncOptionalShutdownHook(
|
|
55
|
+
key: string,
|
|
56
|
+
run: AsyncShutdownHook["run"],
|
|
57
|
+
onIncomplete?: ShutdownHook,
|
|
58
|
+
): void {
|
|
59
|
+
asyncHooks.set(key, { run, onIncomplete });
|
|
60
|
+
}
|
|
61
|
+
|
|
50
62
|
/** Whether `runOptionalShutdownHooks` has run at least once since the last test reset. */
|
|
51
63
|
export function didRunOptionalShutdownHooks(): boolean {
|
|
52
64
|
return hooksRan;
|
|
53
65
|
}
|
|
54
66
|
|
|
55
|
-
/** Run every
|
|
56
|
-
export function runOptionalShutdownHooks(
|
|
67
|
+
/** Run every teardown, reporting whether the asynchronous work completed successfully. */
|
|
68
|
+
export async function runOptionalShutdownHooks(
|
|
69
|
+
{ deadlineMs = Date.now() + OPTIONAL_SHUTDOWN_GRACE_MS }: { deadlineMs?: number } = {},
|
|
70
|
+
): Promise<boolean> {
|
|
57
71
|
hooksRan = true;
|
|
58
72
|
for (const [key, hook] of [...hooks]) {
|
|
59
73
|
try {
|
|
@@ -65,11 +79,47 @@ export function runOptionalShutdownHooks(): void {
|
|
|
65
79
|
);
|
|
66
80
|
}
|
|
67
81
|
}
|
|
82
|
+
if (asyncHooks.size === 0) return true;
|
|
83
|
+
const incomplete = new Map(asyncHooks);
|
|
84
|
+
let timer: ReturnType<typeof setTimeout> | undefined;
|
|
85
|
+
try {
|
|
86
|
+
const deadline = new Promise<null>(resolve => {
|
|
87
|
+
const remainingMs = deadlineMs - Date.now();
|
|
88
|
+
if (remainingMs <= 0) resolve(null);
|
|
89
|
+
else timer = setTimeout(() => resolve(null), remainingMs);
|
|
90
|
+
});
|
|
91
|
+
const cleanup = Promise.all([...incomplete].map(async ([key, hook]) => {
|
|
92
|
+
try {
|
|
93
|
+
await hook.run(deadlineMs);
|
|
94
|
+
incomplete.delete(key);
|
|
95
|
+
return true;
|
|
96
|
+
} catch {
|
|
97
|
+
console.warn(`[shutdown] optional subsystem "${key}" teardown failed`);
|
|
98
|
+
return false;
|
|
99
|
+
}
|
|
100
|
+
}));
|
|
101
|
+
const results = await Promise.race([deadline, cleanup]);
|
|
102
|
+
if (results === null || Date.now() >= deadlineMs) {
|
|
103
|
+
console.warn("[shutdown] optional subsystem teardown timed out");
|
|
104
|
+
return false;
|
|
105
|
+
}
|
|
106
|
+
return results.every(Boolean);
|
|
107
|
+
} finally {
|
|
108
|
+
clearTimeout(timer);
|
|
109
|
+
for (const [key, hook] of incomplete) {
|
|
110
|
+
try {
|
|
111
|
+
hook.onIncomplete?.();
|
|
112
|
+
} catch {
|
|
113
|
+
console.warn(`[shutdown] optional subsystem "${key}" emergency teardown failed`);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
68
117
|
}
|
|
69
118
|
|
|
70
119
|
/** Test-only reset so an isolated lifecycle test does not inherit registrations. */
|
|
71
120
|
export function resetOptionalShutdownHooksForTests(): void {
|
|
72
121
|
hooks.clear();
|
|
122
|
+
asyncHooks.clear();
|
|
73
123
|
drainStartHooks.clear();
|
|
74
124
|
drainStartHooksRan = false;
|
|
75
125
|
hooksRan = false;
|
|
@@ -4,6 +4,7 @@ import { loadConfig } from "../config";
|
|
|
4
4
|
import { readRuntimePort } from "../config/process-state";
|
|
5
5
|
import { directLocalHttpFetch } from "../server/direct-local-http";
|
|
6
6
|
import { configuredAdminToken } from "./admin-secrets";
|
|
7
|
+
import { PROXY_STOP_EXIT_GRACE_MS } from "./shutdown-budget";
|
|
7
8
|
|
|
8
9
|
export function isProcessAlive(pid: number): boolean {
|
|
9
10
|
try {
|
|
@@ -350,9 +351,9 @@ async function stopProxyGracefullyDetailed(
|
|
|
350
351
|
|
|
351
352
|
function drainDeadlineMs(): number {
|
|
352
353
|
try {
|
|
353
|
-
return (loadConfig().shutdownTimeoutMs ?? 5000) +
|
|
354
|
+
return Math.max(0, loadConfig().shutdownTimeoutMs ?? 5000) + PROXY_STOP_EXIT_GRACE_MS;
|
|
354
355
|
} catch {
|
|
355
|
-
return
|
|
356
|
+
return 5000 + PROXY_STOP_EXIT_GRACE_MS;
|
|
356
357
|
}
|
|
357
358
|
}
|
|
358
359
|
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/** Extra time the stop controller gives the proxy after its configured turn drain. */
|
|
2
|
+
export const PROXY_STOP_EXIT_GRACE_MS = 3_000;
|
|
3
|
+
|
|
4
|
+
/** Leave one second of the controller's grace for listener teardown and process exit. */
|
|
5
|
+
export const OPTIONAL_SHUTDOWN_GRACE_MS = PROXY_STOP_EXIT_GRACE_MS - 1_000;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/** Remote platform is discovered only through the link's pinned SSH host key. */
|
|
2
2
|
import { buildExecArgv, buildWindowsProbeArgv, REMOTE_COMMAND_NOT_FOUND, REMOTE_PLATFORM_UNSUPPORTED } from "./ssh-argv";
|
|
3
3
|
import type { ExplicitRoute } from "./explicit-route";
|
|
4
|
-
import type
|
|
4
|
+
import { SshDiagnosticError, sshFailureHint, type SshRunner, type SshRunResult } from "./ssh-runner";
|
|
5
5
|
|
|
6
6
|
export type RemotePlatform = "windows" | "posix" | "unknown";
|
|
7
7
|
|
|
@@ -22,6 +22,21 @@ export function isWindowsShellRefusal(output: string): boolean {
|
|
|
22
22
|
return WINDOWS_SHELL_REFUSAL.test(output);
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
+
/**
|
|
26
|
+
* Is this one line cmd's answer to WINDOWS_OS_PROBE? cmd may print the closing quote of the
|
|
27
|
+
* `cmd.exe /c "<command>"` line Win32-OpenSSH builds (#8972), so one trailing `"` is accepted;
|
|
28
|
+
* nothing else is.
|
|
29
|
+
*/
|
|
30
|
+
export function isWindowsNtAnswer(line: string): boolean {
|
|
31
|
+
return /^Windows_NT"?$/.test(line.trim());
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** A platform failure that tells the dashboard why: the message, then the failing call's stderr reason. */
|
|
35
|
+
function platformError(message: string, failed: SshRunResult): SshDiagnosticError {
|
|
36
|
+
const reason = sshFailureHint(failed.stderr);
|
|
37
|
+
return new SshDiagnosticError(message, reason ? `${message}: ${reason}` : message);
|
|
38
|
+
}
|
|
39
|
+
|
|
25
40
|
/** Classify one remote command result. Transport failures and odd output stay unknown. */
|
|
26
41
|
export function classifyRemotePlatform(result: SshRunResult): RemotePlatform {
|
|
27
42
|
if (result.code === REMOTE_PLATFORM_UNSUPPORTED) return "windows";
|
|
@@ -45,7 +60,7 @@ export function mayBeWindowsShell(result: SshRunResult): boolean {
|
|
|
45
60
|
export async function confirmWindowsShell(runner: SshRunner, alias: string, route: ExplicitRoute | null, knownHostsFile: string, timeoutMs = 30_000): Promise<boolean> {
|
|
46
61
|
try {
|
|
47
62
|
const result = await runner.run(buildWindowsProbeArgv({ alias, knownHostsFile, route }), { timeoutMs });
|
|
48
|
-
return result.code === 0 && result.stdout.trim().split(/\r?\n/)[0]
|
|
63
|
+
return result.code === 0 && isWindowsNtAnswer(result.stdout.trim().split(/\r?\n/)[0] ?? "");
|
|
49
64
|
} catch { return false; }
|
|
50
65
|
}
|
|
51
66
|
|
|
@@ -69,23 +84,23 @@ export async function requireRemotePlatform(
|
|
|
69
84
|
const timeoutMs = over.timeoutMs ?? 10_000;
|
|
70
85
|
const runOptions = over.signal ? { timeoutMs, signal: over.signal } : { timeoutMs };
|
|
71
86
|
const windows = await runner.run(buildWindowsProbeArgv({ alias, knownHostsFile, destination: over.destination, route }), runOptions);
|
|
72
|
-
if (windows.code === 255) throw
|
|
73
|
-
if (windows.code === 0 && windows.stdout
|
|
87
|
+
if (windows.code === 255) throw platformError("SSH platform discovery failed", windows);
|
|
88
|
+
if (windows.code === 0 && isWindowsNtAnswer(windows.stdout)) return "windows";
|
|
74
89
|
const result = await runner.run(buildExecArgv({ alias, knownHostsFile, destination: over.destination, argv: REMOTE_UNAME_ARGV, route }), runOptions);
|
|
75
90
|
const platform = classifyRemotePlatform(result);
|
|
76
|
-
if (platform === "unknown") throw
|
|
91
|
+
if (platform === "unknown") throw platformError("Remote platform could not be determined", result);
|
|
77
92
|
return platform;
|
|
78
93
|
}
|
|
79
94
|
|
|
80
95
|
/** Fan-out ignores login-shell output and trusts only one framed uname line. */
|
|
81
96
|
export async function requireRemotePlatformFramed(runner: Pick<SshRunner, "run">, alias: string, route: ExplicitRoute | null, knownHostsFile: string): Promise<"posix" | "windows"> {
|
|
82
97
|
const windows = await runner.run(buildWindowsProbeArgv({ alias, knownHostsFile, route }), { timeoutMs: 10_000 });
|
|
83
|
-
if (windows.code === SSH_TRANSPORT_FAILURE) throw
|
|
84
|
-
if (windows.code === 0 && windows.stdout.split(/\r?\n/).some(
|
|
98
|
+
if (windows.code === SSH_TRANSPORT_FAILURE) throw platformError("SSH platform discovery failed", windows);
|
|
99
|
+
if (windows.code === 0 && windows.stdout.split(/\r?\n/).some(isWindowsNtAnswer)) return "windows";
|
|
85
100
|
const result = await runner.run(buildExecArgv({ alias, knownHostsFile, argv: REMOTE_FRAMED_UNAME_ARGV, route }), { timeoutMs: 10_000 });
|
|
86
|
-
if (result.code === SSH_TRANSPORT_FAILURE) throw
|
|
101
|
+
if (result.code === SSH_TRANSPORT_FAILURE) throw platformError("SSH platform discovery failed", result);
|
|
87
102
|
const frames = result.stdout.split(/\r?\n/).filter(line => line.startsWith("ocx-platform:"));
|
|
88
103
|
const name = frames.length === 1 ? frames[0]!.slice("ocx-platform:".length) : "";
|
|
89
|
-
if (result.code !== 0 || !POSIX_UNAME.test(name)) throw
|
|
104
|
+
if (result.code !== 0 || !POSIX_UNAME.test(name)) throw platformError("Remote platform could not be determined", result);
|
|
90
105
|
return WINDOWS_UNAME.test(name) ? "windows" : "posix";
|
|
91
106
|
}
|
package/src/link/ssh-argv.ts
CHANGED
|
@@ -371,10 +371,16 @@ export function buildRouteProbeArgv(options: RouteProbeArgvOptions): string[] {
|
|
|
371
371
|
|
|
372
372
|
/**
|
|
373
373
|
* Locale-independent Windows check for a host whose SSH shell is cmd.exe or PowerShell. Both run
|
|
374
|
-
* `cmd /c echo %OS%`, and cmd expands it to `Windows_NT` regardless of display language. The
|
|
374
|
+
* `cmd.exe /c echo %OS%`, and cmd expands it to `Windows_NT` regardless of display language. The
|
|
375
375
|
* command is a fixed literal; a POSIX shell answers "command not found" and nothing else.
|
|
376
|
+
*
|
|
377
|
+
* It names `cmd.exe`, never bare `cmd` (#8972). Win32-OpenSSH with the default cmd.exe shell runs an
|
|
378
|
+
* exec request as `cmd.exe /c "<command>"`, and cmd keeps those quotes when the quoted text starts
|
|
379
|
+
* with the name of something runnable: `cmd /c echo %OS%` then prints `Windows_NT"`. With
|
|
380
|
+
* `cmd.exe` the outer cmd strips the quotes. The parser still accepts the stray quote
|
|
381
|
+
* (`isWindowsNtAnswer`), so a shell that adds it anyway is understood.
|
|
376
382
|
*/
|
|
377
|
-
export const WINDOWS_OS_PROBE = "cmd /c echo %OS%";
|
|
383
|
+
export const WINDOWS_OS_PROBE = "cmd.exe /c echo %OS%";
|
|
378
384
|
|
|
379
385
|
/** Run WINDOWS_OS_PROBE against an already trusted (pinned or just-probed) host key only. */
|
|
380
386
|
export function buildWindowsProbeArgv(options: { alias: string; knownHostsFile: string; destination?: string; route: ExplicitRoute | null }): string[] {
|
package/src/link/ssh-runner.ts
CHANGED
|
@@ -61,9 +61,10 @@ export function sshFailureHint(stderr: string): string | undefined {
|
|
|
61
61
|
return undefined;
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
-
/** The runner's own failure (spawn, timeout, output limit) as a hint; other errors give none. */
|
|
64
|
+
/** The runner's own failure (spawn, timeout, output limit) or a diagnosed remote failure as a hint; other errors give none. */
|
|
65
65
|
export function sshRunnerErrorHint(error: unknown): string | undefined {
|
|
66
|
-
|
|
66
|
+
if (error instanceof SshRunnerError) return boundHint(error.message);
|
|
67
|
+
return error instanceof SshDiagnosticError ? boundHint(error.hint) : undefined;
|
|
67
68
|
}
|
|
68
69
|
|
|
69
70
|
export interface SshRunResult {
|
|
@@ -116,6 +117,18 @@ export class SshRunnerError extends Error {
|
|
|
116
117
|
}
|
|
117
118
|
}
|
|
118
119
|
|
|
120
|
+
/**
|
|
121
|
+
* A remote step that ran and could not be interpreted, such as platform discovery (#8972). `hint` is
|
|
122
|
+
* built from the step's own message and its bounded stderr hint, so the dashboard learns why instead of
|
|
123
|
+
* reading every such failure as an SSH outage.
|
|
124
|
+
*/
|
|
125
|
+
export class SshDiagnosticError extends Error {
|
|
126
|
+
constructor(message: string, readonly hint: string) {
|
|
127
|
+
super(message);
|
|
128
|
+
this.name = "SshDiagnosticError";
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
119
132
|
/** SIGTERM to SIGKILL, and SIGKILL to giving up on observing the exit, for confirmed-termination runs. */
|
|
120
133
|
export const RUN_KILL_GRACE_MS = 2_000;
|
|
121
134
|
|
|
@@ -1,7 +1,25 @@
|
|
|
1
|
-
import { M365_COPILOT_WEB_URL, M365_COPILOT_WEB_COOKIE_NAMES, normalizeM365WebSession } from "../providers/m365-copilot-discovery";
|
|
1
|
+
import { M365_COPILOT_WEB_URL, M365_COPILOT_WEB_COOKIE_NAMES, normalizeM365WebSession, parseM365ModelBootstrap } from "../providers/m365-copilot-discovery";
|
|
2
2
|
import type { M365CopilotWebSession } from "./types";
|
|
3
3
|
|
|
4
4
|
interface BrowserCommands { command(method: string, params?: Record<string, unknown>, sessionId?: string): Promise<any> }
|
|
5
|
+
// The web app deletes its hydration global after startup, so the server HTML is the fallback source.
|
|
6
|
+
// The page-side read is bounded like discovery (2 MiB) and in time, and it rejects a response whose
|
|
7
|
+
// final URL left the Copilot origin, so a huge, stalled or redirected body never reaches the parser.
|
|
8
|
+
const M365_CHAT_HTML_MAX_BYTES = 2 * 1024 * 1024;
|
|
9
|
+
const M365_CHAT_HTML_TIMEOUT_MS = 10_000;
|
|
10
|
+
const M365_WEB_ORIGIN = JSON.stringify(new URL(M365_COPILOT_WEB_URL).origin);
|
|
11
|
+
const fetchChatHtml = "location.origin===" + M365_WEB_ORIGIN + "?(async()=>{"
|
|
12
|
+
+ "const c=new AbortController(),t=setTimeout(()=>c.abort()," + M365_CHAT_HTML_TIMEOUT_MS + ");"
|
|
13
|
+
+ "try{const r=await fetch(" + JSON.stringify(M365_COPILOT_WEB_URL) + ",{credentials:'include',signal:c.signal});"
|
|
14
|
+
+ "if(!r.ok||!r.body||new URL(r.url).origin!==" + M365_WEB_ORIGIN + "){c.abort();return''}"
|
|
15
|
+
+ "const rd=r.body.getReader(),d=new TextDecoder();let s='',n=0;"
|
|
16
|
+
+ "for(;;){const{done,value}=await rd.read();if(done)break;n+=value.byteLength;"
|
|
17
|
+
+ "if(n>" + M365_CHAT_HTML_MAX_BYTES + "){c.abort();return''}s+=d.decode(value,{stream:true})}"
|
|
18
|
+
+ "return s+d.decode()}catch{return''}finally{clearTimeout(t)}})():''";
|
|
19
|
+
function bootstrapAccountId(html: unknown) {
|
|
20
|
+
if (typeof html !== "string" || !html) return "";
|
|
21
|
+
try { return parseM365ModelBootstrap(html).accountId; } catch { return ""; }
|
|
22
|
+
}
|
|
5
23
|
export async function readM365BrowserWebSession(browser: BrowserCommands, context: string, signal: AbortSignal): Promise<M365CopilotWebSession> {
|
|
6
24
|
const expression = "(()=>{const r=window.__staticRouterHydrationData?.loaderData?.root;const a=r?.store?.accountInfo;return a?.objectId&&a?.tenantId&&r?.__queryState?.queries?.some(q=>q.state?.data?.bizchatAsAgentGpt?.clientPreferences?.modelSelectorMetadata)?a.objectId+'@'+a.tenantId:''})()";
|
|
7
25
|
await browser.command("Page.navigate", { url: M365_COPILOT_WEB_URL }, context);
|
|
@@ -9,8 +27,14 @@ export async function readM365BrowserWebSession(browser: BrowserCommands, contex
|
|
|
9
27
|
while (Date.now() < deadline) {
|
|
10
28
|
signal.throwIfAborted();
|
|
11
29
|
const result = await browser.command("Runtime.evaluate", { expression, returnByValue: true }, context).catch(() => null);
|
|
12
|
-
|
|
13
|
-
if (typeof accountId
|
|
30
|
+
let accountId = result?.result?.value;
|
|
31
|
+
if (typeof accountId !== "string" || !accountId) {
|
|
32
|
+
const page = await browser.command("Runtime.evaluate", { expression: fetchChatHtml, awaitPromise: true, returnByValue: true }, context).catch(() => null);
|
|
33
|
+
// The fallback fetch can outlive a cancelled login; never read cookies after an abort.
|
|
34
|
+
signal.throwIfAborted();
|
|
35
|
+
accountId = bootstrapAccountId(page?.result?.value);
|
|
36
|
+
}
|
|
37
|
+
if (accountId) {
|
|
14
38
|
const { cookies } = await browser.command("Network.getCookies", { urls: [M365_COPILOT_WEB_URL] }, context);
|
|
15
39
|
const cookie = (Array.isArray(cookies) ? cookies : []).filter(c =>
|
|
16
40
|
["copilot.cloud.microsoft", ".copilot.cloud.microsoft"].includes(c.domain)
|
|
@@ -19,7 +43,7 @@ export async function readM365BrowserWebSession(browser: BrowserCommands, contex
|
|
|
19
43
|
const session = normalizeM365WebSession({ cookie, accountId });
|
|
20
44
|
if (session) return session;
|
|
21
45
|
}
|
|
22
|
-
await Bun.sleep(
|
|
46
|
+
await Bun.sleep(1_000);
|
|
23
47
|
}
|
|
24
48
|
throw new Error("Microsoft 365 Copilot web sign-in did not expose a work-account model picker; retry login");
|
|
25
49
|
}
|
package/src/protocols/dto.ts
CHANGED
|
@@ -87,15 +87,18 @@ export interface ProtocolAttemptTraceV1 {
|
|
|
87
87
|
responsePath?: ProtocolHop[];
|
|
88
88
|
}
|
|
89
89
|
|
|
90
|
+
/** A hop in an observed trace. Gemini native delivery does not go through the protocol planner. */
|
|
91
|
+
export type ProtocolTraceHop = ProtocolHop | "gemini";
|
|
92
|
+
|
|
90
93
|
/** What one request actually did, recorded at the send boundary and persisted with the log row. */
|
|
91
94
|
export interface ProtocolTraceV1 {
|
|
92
95
|
v: typeof PROTOCOL_TRACE_SCHEMA_VERSION;
|
|
93
|
-
inbound: Protocol;
|
|
96
|
+
inbound: Protocol | "gemini";
|
|
94
97
|
/** Final attempt's mode, or `blocked` when refused before any send. */
|
|
95
98
|
mode: DeliveryMode;
|
|
96
|
-
upstream?: UpstreamWire;
|
|
97
|
-
requestPath:
|
|
98
|
-
responsePath:
|
|
99
|
+
upstream?: UpstreamWire | "gemini";
|
|
100
|
+
requestPath: ProtocolTraceHop[];
|
|
101
|
+
responsePath: ProtocolTraceHop[];
|
|
99
102
|
reasonCodes: ProtocolReasonCode[];
|
|
100
103
|
featureEffects?: ProtocolFeatureEffectV1[];
|
|
101
104
|
attempts?: ProtocolAttemptTraceV1[];
|
|
@@ -202,15 +205,24 @@ function isAttemptTrace(value: unknown): value is ProtocolAttemptTraceV1 {
|
|
|
202
205
|
&& (value.responsePath === undefined || isPath(value.responsePath));
|
|
203
206
|
}
|
|
204
207
|
|
|
208
|
+
function isNativeGeminiPath(value: unknown): boolean {
|
|
209
|
+
return Array.isArray(value) && value.length === 2 && value[0] === "gemini" && value[1] === "gemini";
|
|
210
|
+
}
|
|
211
|
+
|
|
205
212
|
export function isProtocolTraceV1(value: unknown): value is ProtocolTraceV1 {
|
|
206
|
-
if (!isRec(value) || value.v !== PROTOCOL_TRACE_SCHEMA_VERSION) return false;
|
|
207
|
-
if (
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
213
|
+
if (!isRec(value) || value.v !== PROTOCOL_TRACE_SCHEMA_VERSION || !isDeliveryMode(value.mode)) return false;
|
|
214
|
+
if (value.inbound === "gemini") {
|
|
215
|
+
if (value.mode !== "native" || value.upstream !== "gemini" || value.attempts !== undefined
|
|
216
|
+
|| !isNativeGeminiPath(value.requestPath) || !isNativeGeminiPath(value.responsePath)) return false;
|
|
217
|
+
} else {
|
|
218
|
+
if (!isProtocol(value.inbound) || (value.upstream !== undefined && !isUpstreamWire(value.upstream))) return false;
|
|
219
|
+
const pathsOk = value.mode === "blocked"
|
|
220
|
+
? Array.isArray(value.requestPath) && value.requestPath.length === 0
|
|
221
|
+
&& Array.isArray(value.responsePath) && value.responsePath.length === 0
|
|
222
|
+
: isPath(value.requestPath) && isPath(value.responsePath);
|
|
223
|
+
if (!pathsOk) return false;
|
|
224
|
+
}
|
|
225
|
+
if (!isReasonCodes(value.reasonCodes) || typeof value.contractVersion !== "string") return false;
|
|
214
226
|
if (value.featureEffects !== undefined
|
|
215
227
|
&& !boundedArray(value.featureEffects, PROTOCOL_DTO_LIMITS.featureEffects, isFeatureEffect)) return false;
|
|
216
228
|
if (value.attempts !== undefined && !boundedArray(value.attempts, PROTOCOL_DTO_LIMITS.attempts, isAttemptTrace)) return false;
|
|
@@ -13,6 +13,8 @@ import type { Protocol } from "./contract";
|
|
|
13
13
|
export type ApiSurfaceSource =
|
|
14
14
|
/** Responses and Chat Completions: always served. */
|
|
15
15
|
| "fixed"
|
|
16
|
+
/** Gemini: open when no setting is supplied. */
|
|
17
|
+
| "default"
|
|
16
18
|
/** An explicit boolean in `apiSurfaces`. */
|
|
17
19
|
| "api-surfaces"
|
|
18
20
|
/** No explicit value; inherited from `claudeCode.enabled`. */
|
|
@@ -32,28 +34,30 @@ function isRec(value: unknown): value is Rec {
|
|
|
32
34
|
return !!value && typeof value === "object" && !Array.isArray(value);
|
|
33
35
|
}
|
|
34
36
|
|
|
35
|
-
function
|
|
36
|
-
|
|
37
|
-
if (raw
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
}
|
|
49
|
-
return { enabled: config.claudeCode?.enabled !== false, source: "claude-code-legacy" };
|
|
37
|
+
function resolveOptionalSurface(raw: unknown, name: "messages" | "gemini", fallback: ApiSurfaceSetting): ApiSurfaceSetting {
|
|
38
|
+
if (raw === undefined) return fallback;
|
|
39
|
+
if (!isRec(raw)) return { enabled: false, source: "invalid" };
|
|
40
|
+
const surface = raw[name];
|
|
41
|
+
if (surface === undefined) return fallback;
|
|
42
|
+
if (!isRec(surface)) return { enabled: false, source: "invalid" };
|
|
43
|
+
if (!Object.hasOwn(surface, "enabled")) return fallback;
|
|
44
|
+
return typeof surface.enabled === "boolean"
|
|
45
|
+
? { enabled: surface.enabled, source: "api-surfaces" }
|
|
46
|
+
: { enabled: false, source: "invalid" };
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function resolveGeminiApiSurface(config: Pick<OcxConfig, "apiSurfaces">): ApiSurfaceSetting {
|
|
50
|
+
return resolveOptionalSurface(config.apiSurfaces, "gemini", { enabled: true, source: "default" });
|
|
50
51
|
}
|
|
51
52
|
|
|
52
53
|
export function resolveApiSurfaceSettings(config: Pick<OcxConfig, "apiSurfaces" | "claudeCode">): ApiSurfaceSettings {
|
|
53
54
|
return Object.freeze({
|
|
54
55
|
responses: Object.freeze({ enabled: true, source: "fixed" as const }),
|
|
55
56
|
chat: Object.freeze({ enabled: true, source: "fixed" as const }),
|
|
56
|
-
messages: Object.freeze(
|
|
57
|
+
messages: Object.freeze(resolveOptionalSurface(config.apiSurfaces, "messages", {
|
|
58
|
+
enabled: config.claudeCode?.enabled !== false,
|
|
59
|
+
source: "claude-code-legacy",
|
|
60
|
+
})),
|
|
57
61
|
});
|
|
58
62
|
}
|
|
59
63
|
|
package/src/protocols/shadow.ts
CHANGED
|
@@ -18,8 +18,7 @@
|
|
|
18
18
|
* - A blocked trace agrees with a blocked plan. A compatibility reject is Claude-integration
|
|
19
19
|
* policy the planner does not model, so it is not compared.
|
|
20
20
|
*/
|
|
21
|
-
import type {
|
|
22
|
-
import type { ProtocolPlanCandidateV1, ProtocolPlanV1, ProtocolTraceV1 } from "./dto";
|
|
21
|
+
import type { ProtocolPlanCandidateV1, ProtocolPlanV1, ProtocolTraceHop, ProtocolTraceV1 } from "./dto";
|
|
23
22
|
|
|
24
23
|
/** The route the request settled on, as the request log context records it. */
|
|
25
24
|
export interface ShadowSettledRoute {
|
|
@@ -27,7 +26,7 @@ export interface ShadowSettledRoute {
|
|
|
27
26
|
model?: string;
|
|
28
27
|
}
|
|
29
28
|
|
|
30
|
-
function samePath(a: readonly
|
|
29
|
+
function samePath(a: readonly ProtocolTraceHop[], b: readonly ProtocolTraceHop[]): boolean {
|
|
31
30
|
return a.length === b.length && a.every((hop, index) => hop === b[index]);
|
|
32
31
|
}
|
|
33
32
|
|
package/src/protocols/trace.ts
CHANGED
|
@@ -62,7 +62,7 @@ export interface ProtocolTraceAttempt {
|
|
|
62
62
|
adapter: string;
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
-
const requestMarks = new WeakMap<object, EntryMark | BlockedMark>();
|
|
65
|
+
const requestMarks = new WeakMap<object, EntryMark | BlockedMark | { kind: "gemini-native" }>();
|
|
66
66
|
const attemptMarks = new WeakMap<object, AttemptMark>();
|
|
67
67
|
const shadowInputs = new WeakMap<object, ProtocolPlanInput>();
|
|
68
68
|
const suppressedContexts = new WeakSet<object>();
|
|
@@ -121,12 +121,22 @@ export function markProtocolEntry(
|
|
|
121
121
|
}
|
|
122
122
|
}
|
|
123
123
|
|
|
124
|
+
/** Record an actual native Gemini send without inspecting the payload. */
|
|
125
|
+
export function markNativeGeminiProtocol(logCtx: object): void {
|
|
126
|
+
if (protocolTraceSuppressed(logCtx)) return;
|
|
127
|
+
try {
|
|
128
|
+
requestMarks.set(logCtx, { kind: "gemini-native" });
|
|
129
|
+
} catch {
|
|
130
|
+
/* a trace must never fail the request it describes */
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
124
134
|
/** Features the request's entry or blocked mark recorded, for the shadow plan input. */
|
|
125
135
|
export function protocolMarkFeatures(logCtx: object): readonly ProtocolFeature[] | undefined {
|
|
126
136
|
if (protocolTraceSuppressed(logCtx)) return undefined;
|
|
127
137
|
try {
|
|
128
138
|
const mark = requestMarks.get(logCtx);
|
|
129
|
-
return mark ? [...mark.features] : undefined;
|
|
139
|
+
return mark && mark.kind !== "gemini-native" ? [...mark.features] : undefined;
|
|
130
140
|
} catch {
|
|
131
141
|
return undefined;
|
|
132
142
|
}
|
|
@@ -292,6 +302,18 @@ function observedTrace(
|
|
|
292
302
|
): ProtocolTraceV1 | undefined {
|
|
293
303
|
try {
|
|
294
304
|
const mark = requestMarks.get(logCtx);
|
|
305
|
+
if (mark?.kind === "gemini-native") {
|
|
306
|
+
return {
|
|
307
|
+
v: PROTOCOL_TRACE_SCHEMA_VERSION,
|
|
308
|
+
inbound: "gemini",
|
|
309
|
+
upstream: "gemini",
|
|
310
|
+
mode: "native",
|
|
311
|
+
requestPath: ["gemini", "gemini"],
|
|
312
|
+
responsePath: ["gemini", "gemini"],
|
|
313
|
+
reasonCodes: ["same-wire-native"],
|
|
314
|
+
contractVersion: PROTOCOL_CONTRACT_VERSION,
|
|
315
|
+
};
|
|
316
|
+
}
|
|
295
317
|
if (mark?.kind === "blocked") {
|
|
296
318
|
return {
|
|
297
319
|
v: PROTOCOL_TRACE_SCHEMA_VERSION,
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Command Code's System One decision models (#8997).
|
|
3
|
+
*
|
|
4
|
+
* Command Code lists `typesafe/jev` and its versioned ids in `/provider/v1/models` next to its chat
|
|
5
|
+
* models, but serves them only at `POST /provider/v1/systemone` with the `{model, state, questions}`
|
|
6
|
+
* decision contract (https://commandcode.ai/docs/provider). Its chat endpoints answer 403 for them,
|
|
7
|
+
* so they are neither catalog chat rows nor chat routes; a JEV combo reaches them through a
|
|
8
|
+
* `jev-decision` provider pointed at the System One endpoint.
|
|
9
|
+
*
|
|
10
|
+
* Dependency-free so the provider registry (discovery filter) and the adapter registry (request
|
|
11
|
+
* guard) share one definition.
|
|
12
|
+
*/
|
|
13
|
+
import type { ProviderModelDiscoveryFilter } from "./registry/types";
|
|
14
|
+
|
|
15
|
+
/** The native id fragment every decision model carries. */
|
|
16
|
+
export const COMMAND_CODE_DECISION_MODEL_ID_FRAGMENT = "typesafe/jev";
|
|
17
|
+
/** The same fragment with the slash folded to a dash, as Codex-facing encoded slugs carry it. */
|
|
18
|
+
const ENCODED_DECISION_MODEL_ID_FRAGMENT = "typesafe-jev";
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Discovery admission shared by both Command Code presets: decision rows are not chat rows. Both
|
|
22
|
+
* spellings are matched so discovery hides exactly the ids request admission refuses.
|
|
23
|
+
*/
|
|
24
|
+
export const COMMAND_CODE_DECISION_MODEL_DISCOVERY_FILTER: ProviderModelDiscoveryFilter = {
|
|
25
|
+
noneOf: [{ path: ["id"], containsAny: [COMMAND_CODE_DECISION_MODEL_ID_FRAGMENT, ENCODED_DECISION_MODEL_ID_FRAGMENT], caseInsensitive: true }],
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
/** Where Command Code serves the decision models. */
|
|
29
|
+
export const COMMAND_CODE_SYSTEMONE_ENDPOINT = "https://api.commandcode.ai/provider/v1/systemone";
|
|
30
|
+
|
|
31
|
+
/** Command Code's API host, shared by the OAuth (`command-code`) and API-key (`commandcode`) presets. */
|
|
32
|
+
export const COMMAND_CODE_API_HOST = "api.commandcode.ai";
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* True for a Command Code decision model id: the id, with every slash folded to a dash, contains
|
|
36
|
+
* `typesafe-jev` (case-insensitive). On native ids this is exactly the discovery filter (either
|
|
37
|
+
* spelling), and it also covers the Codex-facing encoded slug of every id discovery hides, which a
|
|
38
|
+
* stale selection can still send after discovery stopped listing the row.
|
|
39
|
+
*/
|
|
40
|
+
export function isCommandCodeDecisionModel(modelId: string): boolean {
|
|
41
|
+
return modelId.toLowerCase().replaceAll("/", "-").includes(ENCODED_DECISION_MODEL_ID_FRAGMENT);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** True when a provider's baseUrl points at Command Code, whatever the provider is named. */
|
|
45
|
+
export function isCommandCodeHost(baseUrl: string | undefined): boolean {
|
|
46
|
+
try {
|
|
47
|
+
return new URL(baseUrl ?? "").hostname.toLowerCase() === COMMAND_CODE_API_HOST;
|
|
48
|
+
} catch {
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** True when this provider/model pair is a Command Code decision model, whatever the provider is named. */
|
|
54
|
+
export function isCommandCodeDecisionRoute(provider: { baseUrl?: string }, modelId: string): boolean {
|
|
55
|
+
return isCommandCodeHost(provider.baseUrl) && isCommandCodeDecisionModel(modelId);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Client copy for a chat request that named a decision model. A fixed sentence of proxy literals
|
|
60
|
+
* only (no model id), so the Chat and Messages presenters can pass it through instead of replacing
|
|
61
|
+
* it with generic "rejected" copy; it is registered in client-error-body's PROXY_FIXED_MESSAGES.
|
|
62
|
+
*/
|
|
63
|
+
export const COMMAND_CODE_DECISION_MODEL_MESSAGE = "Command Code serves its typesafe/jev System One decision models only at POST "
|
|
64
|
+
+ COMMAND_CODE_SYSTEMONE_ENDPOINT + "; they cannot answer chat requests. Use one as the decision service of a "
|
|
65
|
+
+ "JEV combo (a jev-decision provider pointed at that endpoint), or choose a chat model.";
|