@bitkyc08/opencodex 2.92.0 → 2.93.0-preview.20261027
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/bin/ocx.mjs +10 -5
- package/gui/dist/assets/App-CJZoq-uF.js +58 -0
- package/gui/dist/assets/{Tray-BSsxznDm.js → Tray-BWQPcgZn.js} +1 -1
- package/gui/dist/assets/index-DRe8Hhfz.css +1 -0
- package/gui/dist/assets/{index-BlFE_VB_.js → index-Xfct8owH.js} +12 -12
- package/gui/dist/assets/{quota-summary-BRlbXgw0.js → quota-summary-DxToX1rV.js} +1 -1
- package/gui/dist/index.html +2 -2
- package/package.json +5 -5
- package/src/adapters/anthropic.ts +28 -5
- package/src/adapters/coding-agent/batch-dispatcher.ts +122 -0
- package/src/adapters/coding-agent/profile.ts +54 -16
- package/src/adapters/coding-agent/turn.ts +30 -2
- package/src/adapters/command-code.ts +114 -7
- package/src/adapters/cursor/native-exec-fs.ts +11 -9
- package/src/adapters/devin/live-models.ts +4 -0
- package/src/adapters/google-wire-compiler.ts +1 -2
- package/src/adapters/kiro/reasoning.ts +2 -0
- package/src/adapters/kiro-refusal.ts +6 -1
- package/src/adapters/kiro-wire.ts +1 -1
- package/src/adapters/openai-chat/messages.ts +8 -2
- package/src/adapters/openai-chat/passthrough.ts +35 -14
- package/src/adapters/openai-chat/reasoning-replay.ts +27 -16
- package/src/adapters/openai-chat/reasoning-wire.ts +117 -8
- package/src/adapters/openai-chat/required-tool-result.ts +64 -0
- package/src/adapters/openai-chat.ts +7 -8
- package/src/adapters/openai-responses/passthrough.ts +7 -4
- package/src/adapters/openai-responses/reasoning.ts +13 -0
- package/src/adapters/openai-responses/request-strips.ts +1 -1
- package/src/adapters/qoder/adapter.ts +129 -8
- package/src/adapters/qoder/scaffold-guard.ts +5 -0
- package/src/adapters/reasoning-controls.ts +16 -0
- package/src/adapters/tool-call-id.ts +1 -3
- package/src/bridge/errors.ts +27 -0
- package/src/bridge.ts +1 -1
- package/src/chat/inbound.ts +4 -1
- package/src/chat/outbound.ts +9 -2
- package/src/chat/reasoning-details.ts +28 -5
- package/src/claude/desktop-first-party.ts +54 -4
- package/src/claude/desktop-picker.ts +11 -8
- package/src/claude/first-party-settings.ts +3 -1
- package/src/claude/inbound.ts +2 -1
- package/src/claude/intercept/local-ca.ts +2 -1
- package/src/claude/intercept/picker-ca-cleanup.ts +4 -2
- package/src/claude/intercept/picker-ca-startup.ts +3 -1
- package/src/claude/intercept/picker-models.ts +6 -3
- package/src/claude/intercept/picker-runtime.ts +3 -2
- package/src/claude/intercept/runtime.ts +6 -3
- package/src/claude/model-info.ts +31 -8
- package/src/cli/account-api.ts +11 -0
- package/src/cli/capabilities-agents-routing.ts +2 -2
- package/src/cli/capabilities-base.ts +7 -1
- package/src/cli/capabilities-observe-system.ts +10 -0
- package/src/cli/claude-desktop.ts +9 -8
- package/src/cli/claude.ts +3 -2
- package/src/cli/codex-shim-autorestore.ts +9 -0
- package/src/cli/combo-result.ts +7 -0
- package/src/cli/combo.ts +18 -0
- package/src/cli/cross-home-owner.ts +13 -1
- package/src/cli/dispatch.ts +25 -6
- package/src/cli/ensure-desired-integrations.ts +8 -6
- package/src/cli/export-command.ts +4 -1
- package/src/cli/help.ts +2 -1
- package/src/cli/index.ts +45 -45
- package/src/cli/integration-plan-dto.ts +4 -0
- package/src/cli/opencode.ts +20 -9
- package/src/cli/registry.ts +6 -4
- package/src/cli/root.ts +9 -0
- package/src/cli/status.ts +59 -1
- package/src/cli/stop-restore.ts +113 -0
- package/src/cli/sync-expectation.ts +60 -0
- package/src/cli/uninstall-integrations.ts +41 -7
- package/src/client/connect.ts +40 -3
- package/src/client/link-home.ts +10 -1
- package/src/client/machine-api.ts +3 -1
- package/src/client/sync-expectation.ts +118 -0
- package/src/clients/config-export/agent-clients.ts +96 -0
- package/src/clients/config-export/contracts.ts +25 -7
- package/src/clients/config-export/qoder.ts +38 -23
- package/src/clients/config-export/reasoning-metadata.ts +55 -8
- package/src/clients/config-export.ts +12 -0
- package/src/clients/lazycodex.ts +7 -2
- package/src/clients/reasoning-controls.ts +49 -0
- package/src/codex/auth-api/account-identity.ts +14 -0
- package/src/codex/auth-api/account-list.ts +29 -2
- package/src/codex/auth-api/http.ts +13 -0
- package/src/codex/auth-api/main-account-probe.ts +2 -2
- package/src/codex/auth-api/pool-mode-gate.ts +16 -3
- package/src/codex/auth-api/pool-quota-probe.ts +15 -0
- package/src/codex/auth-context.ts +15 -12
- package/src/codex/catalog/build-entries.ts +22 -0
- package/src/codex/catalog/configured-tiers.ts +70 -0
- package/src/codex/catalog/effort.ts +44 -10
- package/src/codex/catalog/gather-capture.ts +1 -0
- package/src/codex/catalog/heal-observation.ts +155 -13
- package/src/codex/catalog/metadata.ts +6 -0
- package/src/codex/catalog/model-hints.ts +60 -11
- package/src/codex/catalog/model-visibility.ts +3 -2
- package/src/codex/catalog/native-models.ts +18 -3
- package/src/codex/catalog/parsing.ts +10 -8
- package/src/codex/catalog/pinned-models.ts +2 -1
- package/src/codex/catalog/provider-models.ts +4 -5
- package/src/codex/catalog/retained-sync.ts +2 -1
- package/src/codex/catalog/routed-gather.ts +19 -20
- package/src/codex/catalog/write-audit.ts +3 -2
- package/src/codex/catalog-self-heal.ts +43 -23
- package/src/codex/collision-identity.ts +30 -5
- package/src/codex/convergence.ts +4 -3
- package/src/codex/data/roster-pinned-models.json +177 -1
- package/src/codex/desired-state.ts +6 -1
- package/src/codex/desktop-compatibility/installed-build.ts +88 -12
- package/src/codex/desktop-compatibility/runtime.ts +29 -5
- package/src/codex/desktop-compatibility/usage-controller.ts +2 -0
- package/src/codex/desktop-compatibility/windows-certificate-trust.ts +46 -12
- package/src/codex/inject/config-toml.ts +0 -18
- package/src/codex/inject/plan.ts +18 -3
- package/src/codex/inject/remove.ts +6 -2
- package/src/codex/inject.ts +1 -1
- package/src/codex/journal.ts +61 -1
- package/src/codex/model-entitlements.ts +1 -1
- package/src/codex/native-main-owner.ts +27 -1
- package/src/codex/native-profile-store.ts +2 -1
- package/src/codex/pool-credit-policy.ts +35 -1
- package/src/codex/quota-types.ts +3 -0
- package/src/codex/quota.ts +24 -4
- package/src/codex/role-auto-assign.ts +6 -2
- package/src/codex/subagent-defaults.ts +49 -4
- package/src/combos/failover.ts +17 -2
- package/src/combos/jev-decision-contract.ts +22 -1
- package/src/combos/jev-service-exchange.ts +3 -1
- package/src/combos/jev.ts +95 -9
- package/src/combos/resolve.ts +45 -1
- package/src/combos/types.ts +24 -0
- package/src/config/load-degrade.ts +5 -0
- package/src/config/paths.ts +19 -3
- package/src/config/pending-teardown.ts +22 -1
- package/src/config/provider-validation.ts +15 -4
- package/src/config/removed-opencode-free.ts +11 -0
- package/src/config/schema/leaf-validators.ts +5 -0
- package/src/generated/compatibility-version.json +314 -230
- package/src/generated/model-metadata.ts +5 -5
- package/src/images/loop.ts +16 -2
- package/src/integrations/catalog-refresh.ts +1 -1
- package/src/integrations/hermes-profiles.ts +251 -0
- package/src/integrations/merge.ts +8 -0
- package/src/integrations/mutation-plan.ts +19 -4
- package/src/integrations/registry.ts +5 -0
- package/src/integrations/state.ts +36 -1
- package/src/integrations/writer.ts +18 -4
- package/src/lib/bun-path-runtime.mjs +2 -1
- package/src/lib/errors.ts +62 -0
- package/src/lib/eventstream-decoder.ts +81 -37
- package/src/lib/opaque-proxy-tunnel.ts +32 -8
- package/src/lib/pinned-http.ts +35 -2
- package/src/lib/process-control.ts +13 -1
- package/src/lib/socks5-fetch.ts +59 -64
- package/src/lib/socks5-upload-waiter.ts +50 -0
- package/src/lib/sse-decoder.ts +7 -2
- package/src/lib/state-store-sweeper.ts +40 -14
- package/src/lib/windows-native-principal-worker.ts +14 -0
- package/src/lib/windows-native-principal.ts +188 -0
- package/src/lib/windows-secret-acl.ts +39 -3
- package/src/lib/windows-user-principal.ts +62 -18
- package/src/link/ssh-config.ts +35 -3
- package/src/providers/account-quota-disk.ts +12 -4
- package/src/providers/codebuddy-models.ts +6 -0
- package/src/providers/codex-capacity.ts +3 -1
- package/src/providers/derive.ts +28 -0
- package/src/providers/kiro-models.ts +3 -0
- package/src/providers/mimo-thinking.ts +12 -0
- package/src/providers/model-rename-fields.ts +1 -0
- package/src/providers/model-rename-migration.ts +10 -0
- package/src/providers/openai-sidecar-credit.ts +2 -2
- package/src/providers/reasoning-capabilities.ts +76 -0
- package/src/providers/registry/entries-core.ts +14 -12
- package/src/providers/registry/entries-extended.ts +63 -20
- package/src/providers/registry/model-ids.ts +2 -0
- package/src/providers/registry/model-seeds.ts +93 -28
- package/src/providers/registry/types.ts +10 -1
- package/src/providers/resolved-model-policy.ts +26 -6
- package/src/providers/routed-config.ts +9 -1
- package/src/providers/stale-model-roster-migration.ts +44 -7
- package/src/remote-control/workspace-pi-runtime.ts +11 -6
- package/src/responses/compaction-summary.ts +45 -0
- package/src/responses/muse-tool-name-alias.ts +1 -2
- package/src/responses/parser.ts +3 -2
- package/src/responses/schema.ts +1 -0
- package/src/responses/thought-signature-replay.ts +10 -2
- package/src/routing/capability.ts +8 -2
- package/src/routing/history/ingest.ts +28 -3
- package/src/server/auth-cors.ts +3 -2
- package/src/server/chat-completions.ts +7 -0
- package/src/server/chat-native-eligibility.ts +7 -0
- package/src/server/chat-native-reasoning.ts +14 -4
- package/src/server/direct-local-http.ts +5 -2
- package/src/server/effort-policy.ts +5 -1
- package/src/server/index/live-sideband.ts +18 -15
- package/src/server/index/serve-options.ts +5 -4
- package/src/server/management/agent-settings-routes.ts +27 -15
- package/src/server/management/combo-routes.ts +4 -0
- package/src/server/management/config-routes.ts +2 -2
- package/src/server/management/decision-discovery.ts +12 -2
- package/src/server/management/hermes-profile-routes.ts +156 -0
- package/src/server/management/integration-routes.ts +85 -24
- package/src/server/management/model-routes.ts +2 -2
- package/src/server/management/model-row-export-metadata.ts +25 -6
- package/src/server/management/model-rows.ts +15 -20
- package/src/server/management/native-integration-routes.ts +11 -8
- package/src/server/management/route-registry.ts +4 -0
- package/src/server/management-api.ts +5 -0
- package/src/server/models-capabilities.ts +21 -3
- package/src/server/responses/adapter-delivery.ts +11 -1
- package/src/server/responses/adapter-dispatch.ts +2 -2
- package/src/server/responses/codex-ws-exchange.ts +39 -9
- package/src/server/responses/codex-ws-session.ts +38 -4
- package/src/server/responses/codex-ws-wire.ts +6 -1
- package/src/server/responses/combo-required-tool-contract.ts +103 -0
- package/src/server/responses/combo-stream-preflight.ts +8 -1
- package/src/server/responses/compact.ts +4 -3
- package/src/server/responses/context-overflow.ts +8 -1
- package/src/server/responses/core-combo-failure.ts +10 -0
- package/src/server/responses/core-combo.ts +23 -15
- package/src/server/responses/core-lifetime.ts +3 -0
- package/src/server/responses/core-normalize.ts +11 -1
- package/src/server/responses/core-options.ts +2 -0
- package/src/server/responses/main-hard-lock-routing.ts +60 -44
- package/src/server/responses/passthrough-delivery.ts +40 -2
- package/src/server/responses/policy-fallback.ts +6 -1
- package/src/server/responses/request-compression.ts +12 -7
- package/src/server/responses/request-prepare.ts +22 -2
- package/src/server/responses/request-sidecar-auth.ts +2 -0
- package/src/server/responses/response-effects.ts +22 -10
- package/src/server/responses/sidecar-execution.ts +11 -3
- package/src/server/stop-teardown.ts +36 -1
- package/src/server/ws-bridge.ts +1 -1
- package/src/service/desktop-supervision.d.mts +7 -4
- package/src/service/desktop-supervision.mjs +90 -13
- package/src/service/ownership-mutation-lease.mjs +21 -7
- package/src/types/config.ts +8 -2
- package/src/types/provider.ts +20 -6
- package/src/types/request.ts +10 -0
- package/src/types.ts +1 -0
- package/src/update/bind-probe.ts +29 -0
- package/src/update/job.ts +10 -29
- package/src/update/npm-install-job.ps1 +173 -0
- package/src/update/npm-install.mjs +70 -0
- package/src/update/stop-contract.d.mts +1 -0
- package/src/update/stop-contract.mjs +14 -0
- package/src/update/stop-decision.d.mts +1 -1
- package/src/update/stop-decision.mjs +13 -3
- package/src/update/teardown-handover.ts +166 -0
- package/src/update/transactional-install.d.mts +14 -3
- package/src/update/transactional-install.mjs +33 -7
- package/src/usage/expected-prices.ts +64 -31
- package/src/usage/timeline.ts +19 -9
- package/src/vision/eligibility.ts +15 -5
- package/src/vision/plan.ts +2 -2
- package/src/web-search/loop.ts +16 -2
- package/gui/dist/assets/App-sUf_8afJ.js +0 -58
- package/gui/dist/assets/index-DPeB9HpV.css +0 -1
|
@@ -1,11 +1,34 @@
|
|
|
1
|
+
import { resolveThinkingEnabled } from "../../clients/reasoning-controls";
|
|
2
|
+
import { declaredModelCapabilities, resolveReasoningCapabilities } from "../../providers/reasoning-capabilities";
|
|
3
|
+
import { registryEntryForProviderDestination } from "../../providers/registry";
|
|
1
4
|
import { modelInList, type OcxProviderConfig } from "../../types";
|
|
2
5
|
import type { AdapterRequest } from "../base";
|
|
6
|
+
import { declaresThinkingToggleWire, reasoningControlsAreUnsupported } from "../reasoning-controls";
|
|
3
7
|
import { isNativeOpenAIChatTarget } from "./wire";
|
|
4
8
|
|
|
5
9
|
export type ExplicitChatReasoningWireResult =
|
|
6
10
|
| { handled: false }
|
|
7
11
|
| { handled: true; reasoningLog?: AdapterRequest["reasoningLog"] };
|
|
8
12
|
|
|
13
|
+
function isThinkingToggleType(value: string | undefined): value is "enabled" | "disabled" | "adaptive" {
|
|
14
|
+
return value === "enabled" || value === "disabled" || value === "adaptive";
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** A legacy ladder alone must not opt a translated toggle wire into a second control. */
|
|
18
|
+
export function declaresIndependentChatReasoningEffort(provider: OcxProviderConfig, modelId: string): boolean {
|
|
19
|
+
const explicit = declaredModelCapabilities(provider.modelCapabilities, modelId)?.supportsReasoningEffort;
|
|
20
|
+
const registry = declaredModelCapabilities(registryEntryForProviderDestination(provider)?.modelCapabilities, modelId)?.supportsReasoningEffort;
|
|
21
|
+
return (explicit ?? registry) === true;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** Only explicit control axes opt legacy Chat destinations into independent projection. */
|
|
25
|
+
export function declaresIndependentChatReasoningControls(provider: OcxProviderConfig, modelId: string): boolean {
|
|
26
|
+
const explicit = declaredModelCapabilities(provider.modelCapabilities, modelId);
|
|
27
|
+
const registry = declaredModelCapabilities(registryEntryForProviderDestination(provider)?.modelCapabilities, modelId);
|
|
28
|
+
return (["supportsThinkingToggle", "supportsReasoningEffort"] as const)
|
|
29
|
+
.some(axis => typeof (explicit?.[axis] ?? registry?.[axis]) === "boolean");
|
|
30
|
+
}
|
|
31
|
+
|
|
9
32
|
/**
|
|
10
33
|
* Apply provider-declared reasoning wire policy after the effective provider is resolved.
|
|
11
34
|
* Unset declarations are a no-op so native Chat keeps forwarding the caller's raw field.
|
|
@@ -14,6 +37,7 @@ export function applyExplicitChatReasoningWirePolicy(options: {
|
|
|
14
37
|
provider: OcxProviderConfig;
|
|
15
38
|
modelId: string;
|
|
16
39
|
hasTools: boolean;
|
|
40
|
+
thinkingEnabled: boolean | undefined;
|
|
17
41
|
requestedEffort: string | undefined;
|
|
18
42
|
wireEffort: string | undefined;
|
|
19
43
|
reasoningDisabled: boolean;
|
|
@@ -23,19 +47,103 @@ export function applyExplicitChatReasoningWirePolicy(options: {
|
|
|
23
47
|
provider,
|
|
24
48
|
modelId,
|
|
25
49
|
hasTools,
|
|
50
|
+
thinkingEnabled,
|
|
26
51
|
requestedEffort,
|
|
27
|
-
wireEffort,
|
|
52
|
+
wireEffort: mappedWireEffort,
|
|
28
53
|
reasoningDisabled,
|
|
29
54
|
body,
|
|
30
55
|
} = options;
|
|
31
56
|
|
|
32
|
-
|
|
57
|
+
const capabilities = resolveReasoningCapabilities(provider, modelId);
|
|
58
|
+
if (reasoningDisabled || reasoningControlsAreUnsupported(provider, modelId)) {
|
|
59
|
+
delete body.reasoning_effort;
|
|
60
|
+
delete body.reasoning;
|
|
61
|
+
delete body.thinking;
|
|
62
|
+
return { handled: true };
|
|
63
|
+
}
|
|
64
|
+
const toggleWire = declaresThinkingToggleWire(provider, modelId);
|
|
65
|
+
const toggleDisabled = toggleWire && capabilities.supportsThinkingToggle === false;
|
|
66
|
+
// Legacy tool omission precedes discriminator mapping; independent switches are separate
|
|
67
|
+
// from strength omission and retain their declared behavior below.
|
|
68
|
+
if (hasTools && modelInList(provider.omitReasoningEffortWithToolsModels, modelId)
|
|
69
|
+
&& !declaresIndependentChatReasoningControls(provider, modelId)) {
|
|
70
|
+
delete body.reasoning_effort;
|
|
71
|
+
delete body.reasoning;
|
|
72
|
+
return { handled: true };
|
|
73
|
+
}
|
|
74
|
+
// Ignore legacy toggle discriminators on a disabled toggle axis, but retain real effort
|
|
75
|
+
// mappings (including omission) and run them through the shared effort policy below.
|
|
76
|
+
const requestedStrength = requestedEffort === "ultra" ? "max" : requestedEffort;
|
|
77
|
+
const wireEffort = toggleDisabled && isThinkingToggleType(mappedWireEffort) ? requestedStrength : mappedWireEffort;
|
|
78
|
+
if (capabilities.supportsReasoningEffort === false && !toggleWire) {
|
|
79
|
+
delete body.reasoning_effort;
|
|
80
|
+
delete body.reasoning;
|
|
81
|
+
if (capabilities.supportsThinkingToggle === false) delete body.thinking;
|
|
82
|
+
return { handled: true };
|
|
83
|
+
}
|
|
84
|
+
const resolvedThinkingEnabled = toggleWire && !toggleDisabled
|
|
85
|
+
? resolveThinkingEnabled(provider, modelId, { thinkingEnabled, reasoning: requestedEffort })
|
|
86
|
+
: undefined;
|
|
87
|
+
if (toggleDisabled) {
|
|
88
|
+
delete body.thinking;
|
|
89
|
+
delete body.reasoning;
|
|
90
|
+
delete body.reasoning_effort;
|
|
91
|
+
} else if (toggleWire) {
|
|
92
|
+
// These values are the provider's declared thinking discriminator, never strengths. This
|
|
93
|
+
// remains true when the catalog also advertises a separate, real effort axis.
|
|
94
|
+
if (isThinkingToggleType(wireEffort)) {
|
|
95
|
+
const thinkingType = resolvedThinkingEnabled === undefined
|
|
96
|
+
? wireEffort
|
|
97
|
+
: resolvedThinkingEnabled ? "enabled" : "disabled";
|
|
98
|
+
body.thinking = { type: thinkingType };
|
|
99
|
+
delete body.reasoning_effort;
|
|
100
|
+
delete body.reasoning;
|
|
101
|
+
return {
|
|
102
|
+
handled: true,
|
|
103
|
+
reasoningLog: {
|
|
104
|
+
effectiveEffort: thinkingType,
|
|
105
|
+
wireField: "thinking.type",
|
|
106
|
+
wireValue: thinkingType,
|
|
107
|
+
},
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
if (resolvedThinkingEnabled !== undefined) {
|
|
111
|
+
const thinkingType = resolvedThinkingEnabled ? "enabled" : "disabled";
|
|
112
|
+
body.thinking = { type: thinkingType };
|
|
113
|
+
// A second control still goes through tool omission and gateway projection below.
|
|
114
|
+
if (capabilities.supportsReasoningEffort === false) {
|
|
115
|
+
delete body.reasoning_effort;
|
|
116
|
+
delete body.reasoning;
|
|
117
|
+
return {
|
|
118
|
+
handled: true,
|
|
119
|
+
reasoningLog: {
|
|
120
|
+
effectiveEffort: thinkingType,
|
|
121
|
+
wireField: "thinking.type",
|
|
122
|
+
wireValue: thinkingType,
|
|
123
|
+
},
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
if (capabilities.supportsReasoningEffort === false) {
|
|
128
|
+
delete body.reasoning_effort;
|
|
129
|
+
delete body.reasoning;
|
|
130
|
+
return { handled: true };
|
|
131
|
+
}
|
|
132
|
+
}
|
|
33
133
|
if (hasTools && modelInList(provider.omitReasoningEffortWithToolsModels, modelId)) {
|
|
34
134
|
delete body.reasoning_effort;
|
|
35
135
|
delete body.reasoning;
|
|
36
136
|
return { handled: true };
|
|
37
137
|
}
|
|
38
|
-
if (provider.reasoningWireFormat !== "gateway-object")
|
|
138
|
+
if (provider.reasoningWireFormat !== "gateway-object") {
|
|
139
|
+
if (!toggleDisabled) return { handled: false };
|
|
140
|
+
if (wireEffort === undefined) return { handled: true };
|
|
141
|
+
body.reasoning_effort = wireEffort;
|
|
142
|
+
return {
|
|
143
|
+
handled: true,
|
|
144
|
+
reasoningLog: { effectiveEffort: wireEffort, wireField: "reasoning_effort", wireValue: wireEffort },
|
|
145
|
+
};
|
|
146
|
+
}
|
|
39
147
|
|
|
40
148
|
const nativeOpenAI = isNativeOpenAIChatTarget(provider);
|
|
41
149
|
if (requestedEffort === "none") {
|
|
@@ -52,17 +160,18 @@ export function applyExplicitChatReasoningWirePolicy(options: {
|
|
|
52
160
|
};
|
|
53
161
|
}
|
|
54
162
|
delete body.reasoning_effort;
|
|
55
|
-
|
|
163
|
+
const enabled = resolvedThinkingEnabled ?? false;
|
|
164
|
+
body.reasoning = { enabled };
|
|
56
165
|
return {
|
|
57
166
|
handled: true,
|
|
58
167
|
reasoningLog: {
|
|
59
|
-
effectiveEffort: "none",
|
|
168
|
+
effectiveEffort: enabled ? "enabled" : "none",
|
|
60
169
|
wireField: "reasoning.enabled",
|
|
61
|
-
wireValue:
|
|
170
|
+
wireValue: enabled,
|
|
62
171
|
},
|
|
63
172
|
};
|
|
64
173
|
}
|
|
65
|
-
if (wireEffort === undefined) return { handled:
|
|
174
|
+
if (wireEffort === undefined) return { handled: toggleDisabled };
|
|
66
175
|
|
|
67
176
|
if (nativeOpenAI) {
|
|
68
177
|
delete body.reasoning;
|
|
@@ -77,7 +186,7 @@ export function applyExplicitChatReasoningWirePolicy(options: {
|
|
|
77
186
|
};
|
|
78
187
|
}
|
|
79
188
|
delete body.reasoning_effort;
|
|
80
|
-
body.reasoning = { enabled: true, effort: wireEffort };
|
|
189
|
+
body.reasoning = { enabled: resolvedThinkingEnabled ?? true, effort: wireEffort };
|
|
81
190
|
return {
|
|
82
191
|
handled: true,
|
|
83
192
|
reasoningLog: {
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type { ProviderAdapter } from "../base";
|
|
2
|
+
import { requiresToolCall, type AdapterEvent, type OcxParsedRequest } from "../../types";
|
|
3
|
+
import { releaseTranslatedEvent, retainTranslatedEvent, type TranslatorBudget } from "../../lib/translator-budget";
|
|
4
|
+
import type { AdapterTierMetadata } from "../../providers/fastwire";
|
|
5
|
+
import { isTruncatedStopReason } from "../../responses/truncated-stop-reason";
|
|
6
|
+
|
|
7
|
+
function requiresClientCall(parsed: OcxParsedRequest): boolean {
|
|
8
|
+
if (!requiresToolCall(parsed.options.toolChoice)) return false;
|
|
9
|
+
// Sidecars own their own tool lifecycle; this boundary validates client-executed calls only.
|
|
10
|
+
return !(parsed.context.tools ?? []).some(t => t.webSearch || t.imageGeneration || t.videoGeneration || t.advisor);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function terminalGuard(required: boolean): (event: AdapterEvent) => AdapterEvent {
|
|
14
|
+
// The shared response bridge owns tool-choice authorization and alias restoration.
|
|
15
|
+
// Count a completed call here without introducing a second, narrower name resolver.
|
|
16
|
+
let pending = false;
|
|
17
|
+
let fulfilled = false;
|
|
18
|
+
let failed = false;
|
|
19
|
+
return event => {
|
|
20
|
+
if (event.type === "tool_call_start") pending = true;
|
|
21
|
+
if (event.type === "tool_call_end") { fulfilled ||= pending; pending = false; }
|
|
22
|
+
if (event.type === "error" || event.type === "incomplete") failed = true;
|
|
23
|
+
if (event.type !== "done" || !required || fulfilled || failed || isTruncatedStopReason(event.stopReason)) return event;
|
|
24
|
+
// Preserve delivered output and consumption. A mandatory call is a contract, not a hint
|
|
25
|
+
// that permits replaying an already-visible turn or silently reporting text as success.
|
|
26
|
+
return {
|
|
27
|
+
type: "error", status: 502, errorType: "upstream_error", code: "required_tool_not_called",
|
|
28
|
+
message: "The upstream response completed without the required client tool call.",
|
|
29
|
+
retryable: false, usage: event.usage,
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** Keep the same per-request lifetime as the Chat adapter's tool-name registry. */
|
|
35
|
+
export function withRequiredChatToolResult(adapter: ProviderAdapter): ProviderAdapter {
|
|
36
|
+
let required = false;
|
|
37
|
+
return {
|
|
38
|
+
...adapter,
|
|
39
|
+
buildRequest(parsed, incoming) {
|
|
40
|
+
required = requiresClientCall(parsed);
|
|
41
|
+
return adapter.buildRequest(parsed, incoming);
|
|
42
|
+
},
|
|
43
|
+
async *parseStream(response, budget, tierMetadata) {
|
|
44
|
+
const guard = terminalGuard(required);
|
|
45
|
+
for await (const event of adapter.parseStream(response, budget, tierMetadata)) yield guard(event);
|
|
46
|
+
},
|
|
47
|
+
...(adapter.parseResponse ? {
|
|
48
|
+
async parseResponse(response: Response, budget: TranslatorBudget, tierMetadata?: AdapterTierMetadata) {
|
|
49
|
+
const events = await adapter.parseResponse!(response, budget, tierMetadata);
|
|
50
|
+
const guard = terminalGuard(required);
|
|
51
|
+
for (let i = 0; i < events.length; i++) {
|
|
52
|
+
const original = events[i]!;
|
|
53
|
+
const guarded = guard(original);
|
|
54
|
+
if (guarded !== original) {
|
|
55
|
+
releaseTranslatedEvent(original, budget);
|
|
56
|
+
retainTranslatedEvent(guarded, budget);
|
|
57
|
+
events[i] = guarded;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return events;
|
|
61
|
+
},
|
|
62
|
+
} : {}),
|
|
63
|
+
};
|
|
64
|
+
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
+
import { withRequiredChatToolResult } from "./openai-chat/required-tool-result";
|
|
1
2
|
import { hasShrinkableOpenAIChatImages, normalizeOpenAIChatImages } from "./openai-chat-images";
|
|
2
3
|
import { protectGlmSummaryBudget, resolveMaxTokens } from "./openai-chat/summary-budget";
|
|
3
4
|
import { chatParallelToolCallsWireValue } from "./openai-chat/parallel-tool-calls";
|
|
4
|
-
import { applyExplicitChatReasoningWirePolicy } from "./openai-chat/reasoning-wire";
|
|
5
|
+
import { applyExplicitChatReasoningWirePolicy, declaresIndependentChatReasoningEffort } from "./openai-chat/reasoning-wire";
|
|
5
6
|
import type { AdapterRequest, IncomingMeta, ProviderAdapter } from "./base";
|
|
6
|
-
import type
|
|
7
|
-
import { modelInList } from "../types";
|
|
7
|
+
import { modelInList, type AdapterEvent, type OcxParsedRequest, type OcxProviderConfig, type OcxUsage } from "../types";
|
|
8
8
|
import { mapReasoningEffort } from "../reasoning-effort";
|
|
9
9
|
import { debugProviderDiagnostic } from "../lib/debug";
|
|
10
10
|
import { sseFieldValue } from "../lib/sse-decoder";
|
|
@@ -49,7 +49,6 @@ import { openAIChatTransport, stripBracketedModelSuffix } from "./openai-chat/wi
|
|
|
49
49
|
import { toolChoiceToChatFormat, toolsToChatFormatForProvider } from "./openai-chat/tool-schema";
|
|
50
50
|
import { freeformToolsByWireName, type FreeformToolIdentity, reconcileStructuredToolCall, reconcileStructuredToolCalls } from "./openai-chat/serialized-tool-call-content";
|
|
51
51
|
import { StandaloneBareToolCallBuffer, reconcileStandaloneBareToolCallEvents } from "./openai-chat/standalone-bare-tool-calls";
|
|
52
|
-
|
|
53
52
|
export { stripBracketedModelSuffix } from "./openai-chat/wire";
|
|
54
53
|
export { buildOpenAIChatPassthroughRequest } from "./openai-chat/passthrough";
|
|
55
54
|
export { formatOpenAIChatErrorBody } from "./openai-chat/errors";
|
|
@@ -91,7 +90,7 @@ function canSerializeOpenAIChatServiceTier(
|
|
|
91
90
|
export function createOpenAIChatAdapter(provider: OcxProviderConfig): ProviderAdapter {
|
|
92
91
|
let lastRequestedModelId: string | undefined;
|
|
93
92
|
let freeformTools = new Map<string, FreeformToolIdentity>();
|
|
94
|
-
return withOpenAIChatToolNames(toolNames => ({
|
|
93
|
+
return withRequiredChatToolResult(withOpenAIChatToolNames(toolNames => ({
|
|
95
94
|
name: "openai-chat",
|
|
96
95
|
|
|
97
96
|
formatErrorBody: formatOpenAIChatErrorBody,
|
|
@@ -153,7 +152,7 @@ export function createOpenAIChatAdapter(provider: OcxProviderConfig): ProviderAd
|
|
|
153
152
|
const explicitReasoning = applyExplicitChatReasoningWirePolicy({
|
|
154
153
|
provider,
|
|
155
154
|
modelId: parsed.modelId,
|
|
156
|
-
hasTools: !!tools,
|
|
155
|
+
hasTools: !!tools, thinkingEnabled: parsed.options.thinkingEnabled,
|
|
157
156
|
requestedEffort,
|
|
158
157
|
wireEffort: reasoningEffort,
|
|
159
158
|
reasoningDisabled,
|
|
@@ -173,7 +172,7 @@ export function createOpenAIChatAdapter(provider: OcxProviderConfig): ProviderAd
|
|
|
173
172
|
wireValue: budget,
|
|
174
173
|
};
|
|
175
174
|
}
|
|
176
|
-
} else if (modelInList(provider.thinkingToggleModels, parsed.modelId)) {
|
|
175
|
+
} else if (modelInList(provider.thinkingToggleModels, parsed.modelId) && !declaresIndependentChatReasoningEffort(provider, parsed.modelId)) {
|
|
177
176
|
if (reasoningEffort === "enabled" || reasoningEffort === "disabled" || reasoningEffort === "adaptive") {
|
|
178
177
|
body.thinking = { type: reasoningEffort };
|
|
179
178
|
reasoningLog = {
|
|
@@ -818,5 +817,5 @@ export function createOpenAIChatAdapter(provider: OcxProviderConfig): ProviderAd
|
|
|
818
817
|
budget.releaseRetained(responseBytes, { kind: "retained_collectors" });
|
|
819
818
|
}
|
|
820
819
|
},
|
|
821
|
-
}));
|
|
820
|
+
})));
|
|
822
821
|
}
|
|
@@ -39,8 +39,8 @@ import {
|
|
|
39
39
|
createAdapterTierMetadata,
|
|
40
40
|
emittedFastWire,
|
|
41
41
|
} from "../../providers/fastwire";
|
|
42
|
-
import { dropResponsesReasoningInputItems, mapRoutedResponsesReasoningEffort, normalizeConfiguredReasoningSummaryDelivery, sanitizeReasoningInputContent, stripDisabledReasoningSummaries, stripDisabledVerbosity, stripNoneReasoningSummary, stripUnsupportedReasoningSummaryDelivery } from "./reasoning";
|
|
43
|
-
import { scrubOcxCompactionItems, stripCanonicalOnlyInputItems, stripCanonicalOnlyToolFields, stripCanonicalOnlyTopLevelFields, stripInternalChatMessageMetadataPassthrough, stripInvalidItemIds, stripItemIdsWhenUnstored, stripProviderInputItemMetadata, stripRejectedSamplingParams } from "./request-strips";
|
|
42
|
+
import { dropResponsesReasoningInputItems, mapRoutedResponsesReasoningEffort, normalizeConfiguredReasoningSummaryDelivery, sanitizeReasoningInputContent, stripDisabledReasoningSummaries, stripDisabledVerbosity, stripInternalReasoningEnabled, stripNoneReasoningSummary, stripUnsupportedReasoningSummaryDelivery } from "./reasoning";
|
|
43
|
+
import { repairUrlCitationAnnotations, scrubOcxCompactionItems, stripCanonicalOnlyInputItems, stripCanonicalOnlyToolFields, stripCanonicalOnlyTopLevelFields, stripInternalChatMessageMetadataPassthrough, stripInvalidItemIds, stripItemIdsWhenUnstored, stripProviderInputItemMetadata, stripRejectedSamplingParams } from "./request-strips";
|
|
44
44
|
import { notePlaintextReasoningDropped } from "./plaintext-reasoning-notice";
|
|
45
45
|
import { stripCanonicalForwardPromptCacheOptions, stripDeprecatedPromptCacheRetention } from "./prompt-cache";
|
|
46
46
|
import { isPlainObject } from "./internal";
|
|
@@ -315,7 +315,7 @@ export function createResponsesPassthroughAdapter(provider: OcxProviderConfig):
|
|
|
315
315
|
outBody = repairLegacyDottedToolCallNames(outBody);
|
|
316
316
|
// Shared HTTP/WS outbound projection, including concrete combo/fallback destinations.
|
|
317
317
|
if (isOpenAiOperatedResponsesDestination(provider)) {
|
|
318
|
-
outBody = stripProviderInputItemMetadata(outBody);
|
|
318
|
+
outBody = repairUrlCitationAnnotations(stripProviderInputItemMetadata(outBody));
|
|
319
319
|
}
|
|
320
320
|
if (!isCanonicalOpenAiForwardProvider(provider)) {
|
|
321
321
|
if (provider.preserveResponsesMessageMetadata !== true) {
|
|
@@ -515,7 +515,10 @@ export function createResponsesPassthroughAdapter(provider: OcxProviderConfig):
|
|
|
515
515
|
if (!isCanonicalOpenAiForwardProvider(provider)) {
|
|
516
516
|
validateFinalCustomToolCompatibility(finalBody, provider.supportsResponsesCustomTools);
|
|
517
517
|
}
|
|
518
|
-
|
|
518
|
+
let wireBody = applyGithubCopilotContextTier(finalBody, provider, parsed.modelId, incoming.providerName);
|
|
519
|
+
if (isOpenAiOperatedResponsesDestination(provider) || provider.reasoningWireFormat !== "gateway-object") {
|
|
520
|
+
wireBody = stripInternalReasoningEnabled(wireBody);
|
|
521
|
+
}
|
|
519
522
|
const body = JSON.stringify(wireBody);
|
|
520
523
|
const releaseBodyObservation = translatorBudget.observeExternallyCapped(
|
|
521
524
|
"passthrough_serialization",
|
|
@@ -325,6 +325,19 @@ export function stripDisabledVerbosity(
|
|
|
325
325
|
};
|
|
326
326
|
}
|
|
327
327
|
|
|
328
|
+
/**
|
|
329
|
+
* `reasoning.enabled` is an OCX inbound compatibility extension, not an OpenAI Responses
|
|
330
|
+
* parameter. Strip it at Responses egress unless a custom destination explicitly declares
|
|
331
|
+
* the gateway-object wire; thinking capability alone does not declare a wire format.
|
|
332
|
+
*/
|
|
333
|
+
export function stripInternalReasoningEnabled(body: unknown): unknown {
|
|
334
|
+
if (!isPlainObject(body) || !isPlainObject(body.reasoning) || !Object.hasOwn(body.reasoning, "enabled")) {
|
|
335
|
+
return body;
|
|
336
|
+
}
|
|
337
|
+
const { enabled: _enabled, ...reasoning } = body.reasoning;
|
|
338
|
+
return { ...body, ...(Object.keys(reasoning).length > 0 ? { reasoning } : { reasoning: undefined }) };
|
|
339
|
+
}
|
|
340
|
+
|
|
328
341
|
/**
|
|
329
342
|
* Normalize only the delivery enum Codex already emitted. Do not inject a field into callers that
|
|
330
343
|
* did not request summaries, and leave every unconfigured provider/model byte-for-byte unchanged.
|
|
@@ -24,7 +24,7 @@ export function stripProviderInputItemMetadata(body: unknown): unknown {
|
|
|
24
24
|
input ??= [...body.input];
|
|
25
25
|
input[index] = next;
|
|
26
26
|
}
|
|
27
|
-
return
|
|
27
|
+
return input ? { ...body, input } : body;
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
function isUrlCitationIndex(value: unknown): value is number {
|
|
@@ -7,6 +7,7 @@ import { buildCodingAgentToolCatalog, CodingAgentToolCatalogError } from "../cod
|
|
|
7
7
|
import { baseScopedEnv, runCodingAgentTurn, type CodingAgentDeps, type CodingAgentToolBridgeInput, type CodingAgentFailure } from "../coding-agent/turn";
|
|
8
8
|
import { QODER_PROFILES, resolveQoderProfile, type QoderProfile } from "./profiles";
|
|
9
9
|
import { QoderScaffoldFilter, QODER_SCAFFOLD_ERROR_CODE, qoderScaffoldErrorMessage } from "./scaffold-guard";
|
|
10
|
+
import { ToolEnvelopeEchoFilter } from "../../lib/tool-envelope-echo-filter";
|
|
10
11
|
|
|
11
12
|
export type QoderAdapterDeps = CodingAgentDeps;
|
|
12
13
|
|
|
@@ -50,6 +51,8 @@ function classifyQoderFailure(failure: CodingAgentFailure): Extract<AdapterEvent
|
|
|
50
51
|
|
|
51
52
|
const QODER_MCP_SERVER_NAME = "opencodex";
|
|
52
53
|
const QODER_MCP_SERVER_PATH = fileURLToPath(new URL("../coding-agent/mcp-server.ts", import.meta.url));
|
|
54
|
+
const MAX_PENDING_BOUNDARY_CHARS = 64 * 1024;
|
|
55
|
+
const MAX_PENDING_BOUNDARY_EVENTS = 1024;
|
|
53
56
|
|
|
54
57
|
export function buildQoderChildEnv(profile: QoderProfile, apiKey: string, systemPrompt?: string): Record<string, string> {
|
|
55
58
|
// Each build reads its own brand prefix with no fallback: qodercn ignores QODER_EXPOSE_TOKEN_USAGE.
|
|
@@ -79,6 +82,8 @@ export function buildQoderArgs(parsed: OcxParsedRequest, provider: OcxProviderCo
|
|
|
79
82
|
|
|
80
83
|
/**
|
|
81
84
|
* Wrap the turn's outbound channel with the scaffolding guard (#4190).
|
|
85
|
+
* Vendor-cleaned assistant text also uses the shared replay-envelope recognizer
|
|
86
|
+
* (#7517), so internal history scaffolding cannot become a successful answer.
|
|
82
87
|
*
|
|
83
88
|
* The vendor CLI can put its own agent layer into the text channel despite built-in tools
|
|
84
89
|
* being disabled, and the shared stream-json parser forwards a text delta
|
|
@@ -93,11 +98,18 @@ export function buildQoderArgs(parsed: OcxParsedRequest, provider: OcxProviderCo
|
|
|
93
98
|
export function guardQoderScaffolding(emit: (event: AdapterEvent) => void): (event: AdapterEvent) => void {
|
|
94
99
|
const textFilter = new QoderScaffoldFilter();
|
|
95
100
|
const thinkingFilter = new QoderScaffoldFilter();
|
|
101
|
+
let replayFilter = new ToolEnvelopeEchoFilter();
|
|
96
102
|
let closed = false;
|
|
103
|
+
let boundaries: { offset: number; event: AdapterEvent }[] = [];
|
|
104
|
+
let boundaryChars = 0;
|
|
105
|
+
let textCarry = "";
|
|
97
106
|
|
|
98
107
|
const refuse = (reason: string): void => {
|
|
99
108
|
if (closed) return;
|
|
100
109
|
closed = true;
|
|
110
|
+
boundaries = [];
|
|
111
|
+
boundaryChars = 0;
|
|
112
|
+
textCarry = "";
|
|
101
113
|
emit({
|
|
102
114
|
type: "error",
|
|
103
115
|
message: qoderScaffoldErrorMessage(reason),
|
|
@@ -110,26 +122,134 @@ export function guardQoderScaffolding(emit: (event: AdapterEvent) => void): (eve
|
|
|
110
122
|
});
|
|
111
123
|
};
|
|
112
124
|
|
|
125
|
+
const forwardText = (text: string, refuseOnMatch = true): void => {
|
|
126
|
+
const safe = replayFilter.feed(text);
|
|
127
|
+
// An overflowing fenced hold can release an unverified marker. Refuse it
|
|
128
|
+
// before publication rather than leaking the envelope under a memory cap.
|
|
129
|
+
if (replayFilter.unverifiedMarker) {
|
|
130
|
+
if (refuseOnMatch) refuse("replayed tool envelope");
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
if (safe) emit({ type: "text_delta", text: safe });
|
|
134
|
+
if (replayFilter.matched && refuseOnMatch) refuse("replayed tool envelope");
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
/*
|
|
138
|
+
* Any other event ends the text block before it. Settle text the replay filter
|
|
139
|
+
* still holds so the event cannot overtake it, and refuse before publishing the
|
|
140
|
+
* event when that text completes an envelope. Heartbeats carry no content and
|
|
141
|
+
* must not split a marker. The next text block starts at a line start, so an
|
|
142
|
+
* envelope opening it is recognized even when the previous block ended mid-line.
|
|
143
|
+
*/
|
|
144
|
+
const settleText = (refuseOnMatch = true): boolean => {
|
|
145
|
+
const tail = replayFilter.finish();
|
|
146
|
+
if (replayFilter.matched || replayFilter.unverifiedMarker) {
|
|
147
|
+
if (refuseOnMatch) refuse("replayed tool envelope");
|
|
148
|
+
return false;
|
|
149
|
+
}
|
|
150
|
+
if (tail) emit({ type: "text_delta", text: tail });
|
|
151
|
+
replayFilter = new ToolEnvelopeEchoFilter();
|
|
152
|
+
return true;
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
const forwardEvent = (event: AdapterEvent): void => {
|
|
156
|
+
// A vendor prefix can still turn a replay marker into ordinary prose. Keep
|
|
157
|
+
// its event cuts until the vendor filter resolves it instead of flushing it.
|
|
158
|
+
const offset = textFilter.pendingTextLength + textCarry.length;
|
|
159
|
+
if (offset > 0) {
|
|
160
|
+
const size = event.type === "thinking_delta" ? event.thinking.length : JSON.stringify(event).length;
|
|
161
|
+
if (boundaryChars + size > MAX_PENDING_BOUNDARY_CHARS
|
|
162
|
+
|| boundaries.length >= MAX_PENDING_BOUNDARY_EVENTS) {
|
|
163
|
+
refuse("an unresolved text boundary exceeding its buffer limit");
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
boundaryChars += size;
|
|
167
|
+
const last = boundaries.at(-1);
|
|
168
|
+
if (last?.offset === offset
|
|
169
|
+
&& last.event.type === "thinking_delta" && event.type === "thinking_delta") {
|
|
170
|
+
last.event = { type: "thinking_delta", thinking: last.event.thinking + event.thinking };
|
|
171
|
+
} else boundaries.push({ offset, event });
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
if (settleText() && (event.type !== "thinking_delta" || event.thinking)) emit(event);
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
const drainBoundaries = (text: string, refuseOnMatch = true): void => {
|
|
178
|
+
const queued = boundaries;
|
|
179
|
+
boundaries = [];
|
|
180
|
+
boundaryChars = 0;
|
|
181
|
+
let at = 0;
|
|
182
|
+
for (const boundary of queued) {
|
|
183
|
+
// A suppressed prefix contributes no text; surviving prefixes keep their offsets.
|
|
184
|
+
let end = text ? Math.min(text.length, Math.max(at, boundary.offset)) : 0;
|
|
185
|
+
const before = text.charCodeAt(end - 1), after = text.charCodeAt(end);
|
|
186
|
+
// A scalar completed by a later input belongs before events between its halves.
|
|
187
|
+
if (before >= 0xd800 && before <= 0xdbff && after >= 0xdc00 && after <= 0xdfff) end++;
|
|
188
|
+
forwardText(text.slice(at, end), refuseOnMatch);
|
|
189
|
+
if (closed || !settleText(refuseOnMatch)) return;
|
|
190
|
+
if (boundary.event.type !== "thinking_delta" || boundary.event.thinking) emit(boundary.event);
|
|
191
|
+
at = end;
|
|
192
|
+
}
|
|
193
|
+
if (!closed) forwardText(text.slice(at), refuseOnMatch);
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
const prepareText = (text: string, terminal = false): string => {
|
|
197
|
+
let complete = textCarry + text;
|
|
198
|
+
textCarry = "";
|
|
199
|
+
const last = complete.charCodeAt(complete.length - 1);
|
|
200
|
+
if (!terminal && last >= 0xd800 && last <= 0xdbff) {
|
|
201
|
+
textCarry = complete.slice(-1);
|
|
202
|
+
complete = complete.slice(0, -1);
|
|
203
|
+
}
|
|
204
|
+
return complete.toWellFormed();
|
|
205
|
+
};
|
|
206
|
+
|
|
207
|
+
const pushText = (text: string, refuseOnMatch = true): string | null => {
|
|
208
|
+
let at = 0;
|
|
209
|
+
while (boundaries.length && at < text.length) {
|
|
210
|
+
const width = text.codePointAt(at)! > 0xffff ? 2 : 1;
|
|
211
|
+
const cleaned = textFilter.push(text.slice(at, at + width));
|
|
212
|
+
at += width;
|
|
213
|
+
if (cleaned.fail) {
|
|
214
|
+
if (refuseOnMatch) refuse(cleaned.fail);
|
|
215
|
+
return cleaned.fail;
|
|
216
|
+
}
|
|
217
|
+
// A pending vendor suffix is one marker prefix, starting with its only
|
|
218
|
+
// '<'. Its first release resolves the entire suffix and its saved cuts.
|
|
219
|
+
if (cleaned.text || textFilter.pendingTextLength === 0) drainBoundaries(cleaned.text, refuseOnMatch);
|
|
220
|
+
if (closed) return null;
|
|
221
|
+
}
|
|
222
|
+
const cleaned = textFilter.push(text.slice(at));
|
|
223
|
+
if (cleaned.text) forwardText(cleaned.text, refuseOnMatch);
|
|
224
|
+
if (cleaned.fail && refuseOnMatch) refuse(cleaned.fail);
|
|
225
|
+
return cleaned.fail;
|
|
226
|
+
};
|
|
227
|
+
|
|
113
228
|
return (event: AdapterEvent): void => {
|
|
114
229
|
if (closed) return;
|
|
115
230
|
if (event.type === "text_delta") {
|
|
116
|
-
|
|
117
|
-
if (cleaned.text) emit({ ...event, text: cleaned.text });
|
|
118
|
-
if (cleaned.fail) refuse(cleaned.fail);
|
|
231
|
+
if (event.text) pushText(prepareText(event.text));
|
|
119
232
|
return;
|
|
120
233
|
}
|
|
121
234
|
if (event.type === "thinking_delta") {
|
|
122
235
|
const cleaned = thinkingFilter.push(event.thinking);
|
|
123
|
-
|
|
236
|
+
forwardEvent({ ...event, thinking: cleaned.text });
|
|
124
237
|
if (cleaned.fail) refuse(cleaned.fail);
|
|
125
238
|
return;
|
|
126
239
|
}
|
|
127
240
|
if (event.type === "done" || event.type === "error" || event.type === "incomplete") {
|
|
241
|
+
const carryFailure = textCarry ? pushText(prepareText("", true), false) : null;
|
|
128
242
|
const tail = textFilter.flush();
|
|
129
243
|
const reasoning = thinkingFilter.flush();
|
|
130
|
-
|
|
131
|
-
if (
|
|
132
|
-
const
|
|
244
|
+
drainBoundaries(tail.text, false);
|
|
245
|
+
if (closed) return;
|
|
246
|
+
const replayTail = replayFilter.finish();
|
|
247
|
+
if (replayTail && !replayFilter.unverifiedMarker) emit({ type: "text_delta", text: replayTail });
|
|
248
|
+
if (reasoning.text && !replayFilter.matched && !replayFilter.unverifiedMarker) {
|
|
249
|
+
emit({ type: "thinking_delta", thinking: reasoning.text });
|
|
250
|
+
}
|
|
251
|
+
const fail = carryFailure ?? tail.fail ?? reasoning.fail
|
|
252
|
+
?? (replayFilter.matched || replayFilter.unverifiedMarker ? "replayed tool envelope" : null);
|
|
133
253
|
// A vendor error already carries the better explanation for why the turn ended;
|
|
134
254
|
// only a terminal that claims success is replaced.
|
|
135
255
|
if (fail && event.type !== "error") {
|
|
@@ -140,7 +260,8 @@ export function guardQoderScaffolding(emit: (event: AdapterEvent) => void): (eve
|
|
|
140
260
|
emit(event);
|
|
141
261
|
return;
|
|
142
262
|
}
|
|
143
|
-
emit(event);
|
|
263
|
+
if (event.type === "heartbeat") emit(event);
|
|
264
|
+
else forwardEvent(event);
|
|
144
265
|
};
|
|
145
266
|
}
|
|
146
267
|
|
|
@@ -138,6 +138,11 @@ export class QoderScaffoldFilter {
|
|
|
138
138
|
/** Open reminder blocks; only the closer that unwinds the last one ends suppression. */
|
|
139
139
|
private suppressDepth = 0;
|
|
140
140
|
|
|
141
|
+
/** Unpublished marker-prefix characters; excludes suppressed block content. */
|
|
142
|
+
get pendingTextLength(): number {
|
|
143
|
+
return this.pending.length;
|
|
144
|
+
}
|
|
145
|
+
|
|
141
146
|
push(chunk: string): ScaffoldFilterResult {
|
|
142
147
|
if (this.failed || !chunk) return { text: "", fail: null };
|
|
143
148
|
let cleared = "";
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { registryEntryForProviderDestination } from "../providers/registry";
|
|
2
|
+
import { resolveReasoningCapabilities } from "../providers/reasoning-capabilities";
|
|
3
|
+
import { modelInList, type OcxProviderConfig } from "../types";
|
|
4
|
+
|
|
5
|
+
/** A thinking toggle is serialized only on a provider-declared wire. */
|
|
6
|
+
export function declaresThinkingToggleWire(provider: OcxProviderConfig, modelId: string): boolean {
|
|
7
|
+
return modelInList(provider.thinkingToggleModels, modelId)
|
|
8
|
+
|| modelInList(registryEntryForProviderDestination(provider)?.thinkingToggleModels, modelId);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/** Explicitly unavailable controls constrain both translated and native requests. */
|
|
12
|
+
export function reasoningControlsAreUnsupported(provider: OcxProviderConfig, modelId: string): boolean {
|
|
13
|
+
const capabilities = resolveReasoningCapabilities(provider, modelId);
|
|
14
|
+
return capabilities.supportsReasoning === false
|
|
15
|
+
|| (capabilities.supportsThinkingToggle === false && capabilities.supportsReasoningEffort === false);
|
|
16
|
+
}
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { createHash } from "node:crypto";
|
|
2
|
-
|
|
3
1
|
/**
|
|
4
2
|
* Anthropic rejects a `tool_use.id` longer than this. Collision disambiguation has to fit
|
|
5
3
|
* inside it too, which is why candidates are assembled from parts instead of sliced at the end.
|
|
@@ -27,7 +25,7 @@ function toolCallIdComponents(rawId: string | undefined): { cleaned: string; has
|
|
|
27
25
|
const raw = rawId ?? "";
|
|
28
26
|
if (raw.length === 0) return undefined;
|
|
29
27
|
const cleaned = raw.replace(/[^a-zA-Z0-9_-]/g, "_");
|
|
30
|
-
const hash =
|
|
28
|
+
const hash = Bun.SHA256.hash(raw, "hex").slice(0, TOOL_CALL_ID_HASH_WIDTH);
|
|
31
29
|
return { cleaned, hash };
|
|
32
30
|
}
|
|
33
31
|
|
package/src/bridge/errors.ts
CHANGED
|
@@ -12,6 +12,10 @@ import {
|
|
|
12
12
|
cyberPolicyErrorType,
|
|
13
13
|
CYBER_POLICY_ERROR_CODE,
|
|
14
14
|
isCyberPolicyCode,
|
|
15
|
+
isModelNotInPlanRefusal,
|
|
16
|
+
markVerifiedModelNotInPlanResponse,
|
|
17
|
+
MODEL_NOT_IN_PLAN_CODE,
|
|
18
|
+
REQUIRED_TOOL_CONTRACT_CODE,
|
|
15
19
|
SPEND_LEDGER_STORAGE_UNAVAILABLE_CODE,
|
|
16
20
|
UNDECLARED_TOOL_CALL_ERROR_CODE,
|
|
17
21
|
type OcxErrorPayload,
|
|
@@ -54,6 +58,11 @@ export function formatErrorResponse(
|
|
|
54
58
|
// survives so the Anthropic translator can classify it instead of folding it into a
|
|
55
59
|
// retryable overload (and so clients see the SSE path's rejection identity).
|
|
56
60
|
if (options?.code === UNDECLARED_TOOL_CALL_ERROR_CODE) error.code = options.code;
|
|
61
|
+
if (options?.code === REQUIRED_TOOL_CONTRACT_CODE && error.code !== CYBER_POLICY_ERROR_CODE) error.code = options.code;
|
|
62
|
+
// A plan refusal keeps its wire code so clients can branch on it. The code is not provenance:
|
|
63
|
+
// run-turn combo children pass an adapter event's own code here, so only the boundary that
|
|
64
|
+
// verified the refusal marks the envelope (`markVerifiedModelNotInPlanResponse`).
|
|
65
|
+
if (options?.code === MODEL_NOT_IN_PLAN_CODE) error.code = options.code;
|
|
57
66
|
// Only the allowlisted transport verdicts survive this formatter. Do not forward
|
|
58
67
|
// arbitrary provider codes, and preserve the existing cyber-policy precedence.
|
|
59
68
|
const replayBlocked = error.code !== CYBER_POLICY_ERROR_CODE
|
|
@@ -80,6 +89,7 @@ export function formatErrorResponse(
|
|
|
80
89
|
// and no wait of its own does not stop a client that retries every 429 by default.
|
|
81
90
|
const refusal = isReplayRefusalCode(error.code) && replayBlocked;
|
|
82
91
|
if (refusal) applyReplayRefusalClientHeaders(headers);
|
|
92
|
+
if (error.code === REQUIRED_TOOL_CONTRACT_CODE && finalStatus === 400) applyReplayRefusalClientHeaders(headers);
|
|
83
93
|
const response = new Response(JSON.stringify({ error }), {
|
|
84
94
|
status: finalStatus,
|
|
85
95
|
headers,
|
|
@@ -92,6 +102,23 @@ export function formatErrorResponse(
|
|
|
92
102
|
return response;
|
|
93
103
|
}
|
|
94
104
|
|
|
105
|
+
/**
|
|
106
|
+
* `formatErrorResponse` for an upstream failure that may be the adapter-normalized plan refusal
|
|
107
|
+
* (#7684). Only a verified refusal (`isModelNotInPlanRefusal` on the response the adapter marked)
|
|
108
|
+
* keeps `model_not_in_plan` and carries the in-memory mark policy fallback reads; the wire code
|
|
109
|
+
* alone is never provenance. Every other failure formats exactly as `formatErrorResponse` does.
|
|
110
|
+
*/
|
|
111
|
+
export function formatUpstreamFailureResponse(
|
|
112
|
+
source: Response,
|
|
113
|
+
sourceCode: string | undefined,
|
|
114
|
+
...[status, type, message, options]: Parameters<typeof formatErrorResponse>
|
|
115
|
+
): Response {
|
|
116
|
+
if (!isModelNotInPlanRefusal(source, sourceCode)) return formatErrorResponse(status, type, message, options);
|
|
117
|
+
const failure = formatErrorResponse(status, type, message, { ...options, code: MODEL_NOT_IN_PLAN_CODE });
|
|
118
|
+
markVerifiedModelNotInPlanResponse(failure);
|
|
119
|
+
return failure;
|
|
120
|
+
}
|
|
121
|
+
|
|
95
122
|
/**
|
|
96
123
|
* A spent usage window, in the shape the Codex client treats as final (#6991): HTTP 429 with
|
|
97
124
|
* `error.type: "usage_limit_reached"` and, when the reset is known, `resets_at` in epoch
|