@bitkyc08/opencodex 2.91.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 +47 -8
- package/gui/dist/assets/App-CJZoq-uF.js +58 -0
- package/gui/dist/assets/{Tray-BuLy7hL1.js → Tray-BWQPcgZn.js} +1 -1
- package/gui/dist/assets/index-DRe8Hhfz.css +1 -0
- package/gui/dist/assets/index-Xfct8owH.js +94 -0
- package/gui/dist/assets/quota-summary-DxToX1rV.js +1 -0
- package/gui/dist/index.html +2 -2
- package/gui/dist/provider-icons/workbuddy-color.svg +29 -0
- package/package.json +8 -7
- 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-vertex-endpoint.ts +9 -1
- package/src/adapters/google-vertex-key-project.ts +223 -0
- package/src/adapters/google-wire-compiler.ts +1 -2
- package/src/adapters/google.ts +13 -3
- 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/tool-name-registry.ts +3 -1
- package/src/adapters/openai-chat.ts +9 -10
- 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 +60 -0
- 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/registry.ts +5 -0
- package/src/adapters/tool-call-id.ts +1 -3
- package/src/adapters/workbuddy-schema.ts +61 -0
- package/src/adapters/workbuddy.ts +68 -0
- package/src/bridge/errors.ts +27 -0
- package/src/bridge/response-json.ts +1 -1
- package/src/bridge/sse.ts +1 -1
- package/src/bridge.ts +1 -1
- package/src/chat/inbound.ts +4 -1
- package/src/chat/outbound.ts +20 -6
- 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 +3 -3
- 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-cli-update.ts +8 -0
- package/src/cli/codex-shim-autorestore.ts +9 -0
- package/src/cli/combo-result.ts +13 -0
- package/src/cli/combo-stats.ts +3 -0
- package/src/cli/combo.ts +83 -41
- 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/launcher-context.ts +49 -2
- package/src/cli/link.ts +45 -32
- package/src/cli/opencode.ts +20 -9
- package/src/cli/provider.ts +2 -1
- 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/cli/usage-compare.ts +68 -12
- package/src/client/connect.ts +40 -3
- package/src/client/link-home.ts +10 -1
- package/src/client/link-ingress.ts +1 -1
- package/src/client/link-readiness.ts +97 -0
- package/src/client/link-relay-transport.ts +79 -11
- package/src/client/link-relay.ts +74 -15
- package/src/client/link-tunnel.ts +45 -18
- package/src/client/machine-api.ts +3 -1
- package/src/client/machine-listener.ts +20 -2
- package/src/client/runtime.ts +20 -2
- 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/account-store.ts +17 -3
- package/src/codex/app-server-restart-service.ts +6 -5
- 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 +52 -11
- package/src/codex/catalog/gather-capture.ts +5 -2
- 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 +18 -13
- 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/chatgpt-refresh-failure.ts +6 -2
- package/src/codex/cli-install-provenance.ts +418 -0
- package/src/codex/cli-installation-targets.ts +5 -1
- package/src/codex/cli-update-plan.ts +43 -16
- 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-app/picker-freshness.ts +10 -8
- 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-activation.ts +2 -1
- package/src/codex/desktop-compatibility/usage-controller.ts +9 -1
- 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/pool-refresh-backoff.ts +3 -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/codex/user-identity.ts +35 -6
- package/src/codex/windows-current-sid.ts +162 -0
- package/src/combos/failover.ts +17 -2
- package/src/combos/jev-decision-contract.ts +22 -1
- package/src/combos/jev-quota-activation.ts +5 -1
- package/src/combos/jev-quota-route.ts +1 -1
- package/src/combos/jev-quota.ts +9 -1
- package/src/combos/jev-service-exchange.ts +3 -1
- package/src/combos/jev-session-pin-config.ts +51 -0
- package/src/combos/jev.ts +101 -9
- package/src/combos/resolve.ts +45 -1
- package/src/combos/types.ts +43 -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 +22 -4
- package/src/config/removed-opencode-free.ts +11 -0
- package/src/config/schema/leaf-validators.ts +6 -0
- package/src/generated/compatibility-version.json +467 -311
- 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/decision-quota-sink.ts +10 -0
- 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/translator-budget.ts +4 -4
- package/src/lib/upstream-retry.ts +4 -1
- 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/diagnostics.ts +193 -0
- package/src/link/relay-auth.ts +6 -0
- package/src/link/ssh-config.ts +35 -3
- package/src/link/status-projection.ts +39 -0
- package/src/link/supervisor.ts +45 -12
- package/src/link/tunnel-history.ts +109 -0
- package/src/link/tunnel-state.ts +80 -17
- package/src/messaging/remote-files.ts +24 -1
- package/src/oauth/generic-account-failover.ts +91 -7
- package/src/oauth/index.ts +15 -0
- package/src/oauth/model-discovery-auth.ts +5 -0
- package/src/oauth/store.ts +4 -1
- package/src/oauth/token-guardian.ts +7 -0
- package/src/oauth/types.ts +9 -0
- package/src/oauth/workbuddy.ts +139 -0
- package/src/providers/account-quota-disk.ts +12 -4
- package/src/providers/antigravity-quota-identity.ts +37 -0
- package/src/providers/base-url-choices.ts +8 -5
- package/src/providers/codebuddy-models.ts +6 -0
- package/src/providers/codex-capacity.ts +3 -1
- package/src/providers/derive.ts +51 -3
- package/src/providers/kiro-models.ts +3 -0
- package/src/providers/mimo-thinking.ts +12 -0
- package/src/providers/model-discovery.ts +2 -0
- package/src/providers/model-rename-fields.ts +2 -0
- package/src/providers/model-rename-migration.ts +10 -0
- package/src/providers/openai-sidecar-credit.ts +2 -2
- package/src/providers/quota/account-cache.ts +3 -2
- package/src/providers/quota/antigravity.ts +25 -14
- package/src/providers/quota/report-cache.ts +13 -4
- package/src/providers/quota/vendor-probes-key.ts +60 -0
- package/src/providers/quota/workbuddy.ts +83 -0
- package/src/providers/quota-decision-antigravity.ts +64 -0
- package/src/providers/quota-decision-publication.ts +11 -0
- package/src/providers/quota-decision-snapshot.ts +21 -4
- package/src/providers/quota-types.ts +2 -0
- package/src/providers/quota.ts +3 -1
- package/src/providers/reasoning-capabilities.ts +76 -0
- package/src/providers/registry/entries-core.ts +23 -12
- package/src/providers/registry/entries-extended.ts +83 -27
- package/src/providers/registry/model-ids.ts +5 -0
- package/src/providers/registry/model-seeds.ts +120 -56
- package/src/providers/registry/types.ts +29 -2
- package/src/providers/resolved-model-policy.ts +30 -10
- package/src/providers/routed-config.ts +24 -1
- package/src/providers/stale-model-roster-migration.ts +123 -18
- package/src/providers/workbuddy-credit-balance.ts +81 -0
- package/src/providers/workbuddy-models.ts +37 -0
- package/src/providers/workbuddy.ts +60 -0
- 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/reasoning-replay-cache.ts +18 -14
- package/src/responses/schema.ts +1 -0
- package/src/responses/thought-signature-replay.ts +10 -2
- package/src/router.ts +2 -0
- package/src/routing/analytics.ts +2 -3
- package/src/routing/capability.ts +8 -2
- package/src/routing/fallback-policy.ts +3 -3
- package/src/routing/history/ingest.ts +28 -3
- package/src/server/auth-cors.ts +4 -2
- package/src/server/chat-completions.ts +21 -1
- package/src/server/chat-native-eligibility.ts +7 -0
- package/src/server/chat-native-reasoning.ts +24 -7
- package/src/server/chat-native.ts +13 -2
- package/src/server/claude-messages.ts +3 -0
- package/src/server/direct-local-http.ts +5 -2
- package/src/server/effort-policy.ts +5 -1
- package/src/server/index/link-relay-sessions.ts +9 -5
- package/src/server/index/live-sideband.ts +18 -15
- package/src/server/index/optional-listeners.ts +4 -0
- package/src/server/index/serve-options.ts +5 -4
- package/src/server/local-management-read-client.ts +3 -1
- package/src/server/management/agent-settings-routes.ts +27 -15
- package/src/server/management/combo-routes.ts +14 -4
- 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/link-routes.ts +5 -2
- 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/provider-routes.ts +1 -1
- 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/port-reclaim.ts +51 -9
- package/src/server/request-log-conversation.ts +49 -0
- package/src/server/request-log.ts +2 -0
- package/src/server/responses/adapter-delivery.ts +11 -1
- package/src/server/responses/adapter-dispatch.ts +2 -2
- package/src/server/responses/anthropic-thinking-recovery.ts +1 -0
- 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 +14 -5
- 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 +74 -44
- package/src/server/responses/core-lifetime.ts +5 -2
- package/src/server/responses/core-normalize.ts +17 -4
- package/src/server/responses/core-opaque-recovery.ts +1 -0
- package/src/server/responses/core-options.ts +7 -0
- package/src/server/responses/core-replay.ts +2 -1
- package/src/server/responses/jev-combo-choice.ts +39 -0
- package/src/server/responses/jev-session-pin.ts +203 -0
- package/src/server/responses/main-hard-lock-routing.ts +60 -44
- package/src/server/responses/passthrough-delivery.ts +44 -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 +32 -7
- package/src/server/responses/request-sidecar-auth.ts +2 -0
- package/src/server/responses/request-transport.ts +25 -6
- package/src/server/responses/response-effects.ts +22 -10
- package/src/server/responses/run-turn-execution.ts +2 -4
- package/src/server/responses/sidecar-execution.ts +13 -7
- package/src/server/responses-phase-inference.ts +267 -0
- package/src/server/sse-payload-rewrite.ts +14 -1
- package/src/server/stop-teardown.ts +36 -1
- package/src/server/ws-bridge.ts +1 -1
- package/src/service/definition.ts +20 -8
- 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 +14 -2
- package/src/types/provider.ts +29 -7
- package/src/types/request.ts +11 -0
- package/src/types/wire.ts +1 -0
- package/src/types.ts +1 -0
- package/src/update/bind-probe.ts +29 -0
- package/src/update/codex-cli-update-launch-policy.d.mts +9 -0
- package/src/update/codex-cli-update-launch-policy.mjs +30 -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/jev-stats.ts +54 -14
- 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-nZ34cR5G.js +0 -58
- package/gui/dist/assets/index-DGXS51sp.js +0 -94
- package/gui/dist/assets/index-DPeB9HpV.css +0 -1
- package/gui/dist/assets/quota-summary-DO1Sx5TM.js +0 -1
package/src/routing/analytics.ts
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
* sample for the full history.
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
|
-
import type
|
|
14
|
+
import { normalizePersistedUsageRow, type PersistedUsageEntry } from "../usage/log";
|
|
15
15
|
import { computeEntryCost } from "../usage/summary";
|
|
16
16
|
import { openRequestHistoryIndex, requestHistoryDb } from "./history/indexer";
|
|
17
17
|
|
|
@@ -141,8 +141,7 @@ function classifyRow(row: ScannedRow): "success" | "failure" | "cancelled" {
|
|
|
141
141
|
|
|
142
142
|
function parseEntry(rowJson: string): PersistedUsageEntry | null {
|
|
143
143
|
try {
|
|
144
|
-
|
|
145
|
-
return parsed && typeof parsed === "object" && typeof parsed.requestId === "string" ? parsed : null;
|
|
144
|
+
return normalizePersistedUsageRow(JSON.parse(rowJson)) ?? null;
|
|
146
145
|
} catch {
|
|
147
146
|
return null;
|
|
148
147
|
}
|
|
@@ -182,7 +182,8 @@ export function candidateCapabilityEvidence(
|
|
|
182
182
|
? (nativeOpenAiContextWindow(modelId, nativeContextLimits(config)) ?? rawContextWindow)
|
|
183
183
|
: rawContextWindow;
|
|
184
184
|
|
|
185
|
-
//
|
|
185
|
+
// Exact capability declarations precede legacy vision hints, matching runtime eligibility.
|
|
186
|
+
// `noVisionModels` is checked before the remaining modality chain because that is the order
|
|
186
187
|
// `isModelTextOnly` uses: it matches the no-vision list and returns true before it
|
|
187
188
|
// ever reads `modelInputModalities` (`src/vision/index.ts:32`). So a `gpt-oss`
|
|
188
189
|
// no-vision entry beats an exact `gpt-oss:120b` entry that lists "image", and
|
|
@@ -191,10 +192,15 @@ export function candidateCapabilityEvidence(
|
|
|
191
192
|
// #2086: routing *acts* on this evidence, so it would select the candidate for image
|
|
192
193
|
// work that execution then rejects.
|
|
193
194
|
const noVision = modelInList(provider?.noVisionModels, modelId);
|
|
194
|
-
const
|
|
195
|
+
const explicitModalities = Object.hasOwn(provider?.modelCapabilities ?? {}, modelId)
|
|
196
|
+
? provider?.modelCapabilities?.[modelId]?.inputModalities : undefined;
|
|
197
|
+
const modalities = explicitModalities?.length ? explicitModalities : noVision
|
|
195
198
|
? ["text"]
|
|
196
199
|
: (modelRecordValue(provider?.modelInputModalities, modelId)
|
|
197
200
|
?? modelRecordValue(registryEntry?.modelInputModalities, modelId)
|
|
201
|
+
// Provider-wide declaration, for ids the per-model maps do not list. Read from the
|
|
202
|
+
// provider only: a name-only registry lookup would apply it to a custom destination.
|
|
203
|
+
?? provider?.inputModalities
|
|
198
204
|
?? catalogRow?.inputModalities
|
|
199
205
|
?? (isNative ? nativeInputModalities(modelId) : undefined));
|
|
200
206
|
const image = Array.isArray(modalities)
|
|
@@ -192,9 +192,9 @@ export type FallbackGuardResult =
|
|
|
192
192
|
ok: true;
|
|
193
193
|
kind: OcxFallbackKind | null;
|
|
194
194
|
/**
|
|
195
|
-
* Record the hop as taken
|
|
196
|
-
*
|
|
197
|
-
*
|
|
195
|
+
* Record the hop as taken at the site's admission boundary (body rewrite, send-budget
|
|
196
|
+
* reservation, or accepted candidate). This does not prove upstream contact or billing;
|
|
197
|
+
* later preparation may still refuse. Idempotent; a no-op for a same-target retry.
|
|
198
198
|
*/
|
|
199
199
|
commit: () => void;
|
|
200
200
|
}
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
import type { Database } from "bun:sqlite";
|
|
10
|
-
import { closeSync, fstatSync, openSync, readSync } from "node:fs";
|
|
10
|
+
import { closeSync, fstatSync, openSync, readSync, type BigIntStats } from "node:fs";
|
|
11
11
|
import {
|
|
12
12
|
encodePersistedRequestedModel,
|
|
13
13
|
exactFileIdentity,
|
|
@@ -23,6 +23,20 @@ export const REQUEST_HISTORY_READ_CHUNK_BYTES = 64 * 1024;
|
|
|
23
23
|
// never truncated or rewritten by the indexer.
|
|
24
24
|
export const REQUEST_HISTORY_MAX_RECORD_BYTES = 1024 * 1024;
|
|
25
25
|
|
|
26
|
+
// One small observation per live database handle, never retained ledger bytes. An
|
|
27
|
+
// unterminated tail cannot advance indexedOffset, but need not be reread until its
|
|
28
|
+
// exact file revision changes. The indexer's schema/identity/quick_check gates still run.
|
|
29
|
+
const tailObservations = new WeakMap<Database, {
|
|
30
|
+
path: string;
|
|
31
|
+
revision: string;
|
|
32
|
+
nextOffset: number;
|
|
33
|
+
endOffset: number | undefined;
|
|
34
|
+
}>();
|
|
35
|
+
|
|
36
|
+
function tailRevision(stat: BigIntStats): string {
|
|
37
|
+
return [stat.dev, stat.ino, stat.birthtimeNs, stat.size, stat.mtimeNs, stat.ctimeNs].join(":");
|
|
38
|
+
}
|
|
39
|
+
|
|
26
40
|
/** The ledger at the recorded path is no longer the file the rebuild started from. */
|
|
27
41
|
export class RequestHistoryIndexStaleError extends Error {
|
|
28
42
|
constructor(message: string) {
|
|
@@ -51,6 +65,7 @@ function metaNumber(dbHandle: Database, key: string): number {
|
|
|
51
65
|
}
|
|
52
66
|
|
|
53
67
|
export function resetAndCreateSchema(dbHandle: Database): void {
|
|
68
|
+
tailObservations.delete(dbHandle);
|
|
54
69
|
dbHandle.exec("DROP TABLE IF EXISTS requests");
|
|
55
70
|
dbHandle.exec("DROP TABLE IF EXISTS schema_meta");
|
|
56
71
|
dbHandle.exec(HISTORY_DDL);
|
|
@@ -62,6 +77,7 @@ export function resetAndCreateSchema(dbHandle: Database): void {
|
|
|
62
77
|
}
|
|
63
78
|
|
|
64
79
|
export function recordSourceMeta(dbHandle: Database, revision: UsageLogRevision | null): void {
|
|
80
|
+
tailObservations.delete(dbHandle);
|
|
65
81
|
setMeta(dbHandle, HISTORY_META_KEYS.sourcePath, revision?.path ?? "");
|
|
66
82
|
setMeta(dbHandle, HISTORY_META_KEYS.sourceDev, revision?.dev ?? 0);
|
|
67
83
|
setMeta(dbHandle, HISTORY_META_KEYS.sourceIno, revision?.ino ?? 0);
|
|
@@ -176,7 +192,7 @@ export function ingestSourceTail(
|
|
|
176
192
|
};
|
|
177
193
|
|
|
178
194
|
fd = openSync(path, "r");
|
|
179
|
-
const stat = fstatSync(fd);
|
|
195
|
+
const stat = fstatSync(fd, { bigint: true });
|
|
180
196
|
const expected = options.expected;
|
|
181
197
|
if (expected) {
|
|
182
198
|
const opened = exactFileIdentity(fd);
|
|
@@ -184,6 +200,12 @@ export function ingestSourceTail(
|
|
|
184
200
|
throw new RequestHistoryIndexStaleError("usage log changed before indexing");
|
|
185
201
|
}
|
|
186
202
|
}
|
|
203
|
+
const revision = tailRevision(stat);
|
|
204
|
+
const observed = tailObservations.get(dbHandle);
|
|
205
|
+
if (observed?.path === path && observed.revision === revision
|
|
206
|
+
&& observed.nextOffset === fromOffset && observed.endOffset === options.endOffset) return 0;
|
|
207
|
+
// A failed or interrupted attempt must never publish a reusable observation.
|
|
208
|
+
tailObservations.delete(dbHandle);
|
|
187
209
|
const size = options.endOffset === undefined
|
|
188
210
|
? Number(stat.size)
|
|
189
211
|
: Math.min(Number(stat.size), options.endOffset);
|
|
@@ -230,8 +252,11 @@ export function ingestSourceTail(
|
|
|
230
252
|
setMeta(dbHandle, HISTORY_META_KEYS.indexedOffset, nextOffset);
|
|
231
253
|
setMeta(dbHandle, HISTORY_META_KEYS.indexedRows, indexedRows + inserted);
|
|
232
254
|
setMeta(dbHandle, HISTORY_META_KEYS.sourceSize, size);
|
|
233
|
-
setMeta(dbHandle, HISTORY_META_KEYS.sourceMtimeMs, Number(stat.
|
|
255
|
+
setMeta(dbHandle, HISTORY_META_KEYS.sourceMtimeMs, Number(stat.mtimeNs) / 1_000_000);
|
|
234
256
|
setMeta(dbHandle, HISTORY_META_KEYS.builtAtMs, Date.now());
|
|
257
|
+
if (nextOffset < size && tailRevision(fstatSync(fd, { bigint: true })) === revision) {
|
|
258
|
+
tailObservations.set(dbHandle, { path, revision, nextOffset, endOffset: options.endOffset });
|
|
259
|
+
}
|
|
235
260
|
return inserted;
|
|
236
261
|
} finally {
|
|
237
262
|
if (fd !== undefined) closeSync(fd);
|
package/src/server/auth-cors.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { providerRelativeSendPathConfigError } from "../config/provider-relative-send-path";
|
|
2
|
-
import { contextTierRecordConfigError, modelCapabilitiesConfigError } from "../config/provider-validation";
|
|
2
|
+
import { contextTierRecordConfigError, modelCapabilitiesConfigError, providerInputModalitiesConfigError } from "../config/provider-validation";
|
|
3
3
|
import { createHmac, randomBytes, timingSafeEqual } from "node:crypto";
|
|
4
4
|
import { initialModelSelection } from "../providers/initial-model-selection";
|
|
5
5
|
import { extractAccountId } from "../oauth/chatgpt";
|
|
@@ -747,7 +747,7 @@ export function providerManagementConfigError(
|
|
|
747
747
|
}
|
|
748
748
|
const contextTiersError = contextTierRecordConfigError(raw.modelContextTiers);
|
|
749
749
|
if (contextTiersError) return contextTiersError;
|
|
750
|
-
const capabilitiesError = modelCapabilitiesConfigError(raw.modelCapabilities);
|
|
750
|
+
const capabilitiesError = providerInputModalitiesConfigError(raw.inputModalities) ?? modelCapabilitiesConfigError(raw.modelCapabilities);
|
|
751
751
|
if (capabilitiesError) return capabilitiesError;
|
|
752
752
|
const pinsError = providerReasoningPinsConfigError(raw);
|
|
753
753
|
if (pinsError) return pinsError;
|
|
@@ -1110,6 +1110,7 @@ const PROVIDER_CONFIG_FIELD_POLICY = {
|
|
|
1110
1110
|
modelContextWindows: "editor",
|
|
1111
1111
|
modelContextTiers: "editor",
|
|
1112
1112
|
modelInputModalities: "editor",
|
|
1113
|
+
inputModalities: "editor",
|
|
1113
1114
|
modelCapabilities: "editor",
|
|
1114
1115
|
modelMaxInputTokens: "runtime",
|
|
1115
1116
|
modelAutoCompactTokenLimits: "editor",
|
|
@@ -1195,6 +1196,7 @@ const PROVIDER_CONFIG_FIELD_POLICY = {
|
|
|
1195
1196
|
desktopExecutor: "redacted",
|
|
1196
1197
|
unsafeAllowNativeLocalExec: "editor",
|
|
1197
1198
|
nativeLocalExec: "editor",
|
|
1199
|
+
messagePhaseInference: "editor",
|
|
1198
1200
|
tlsProfile: "editor",
|
|
1199
1201
|
} as const satisfies Record<keyof OcxProviderConfig, ProviderConfigFieldPolicy>;
|
|
1200
1202
|
|
|
@@ -40,6 +40,9 @@ import { evidenceFromBody } from "../routing/request-evidence";
|
|
|
40
40
|
import { resolveWireProtocolOverride } from "./adapter-resolve";
|
|
41
41
|
import { resolveOpenCodeGoTransport } from "../providers/opencode-go-transport";
|
|
42
42
|
import {
|
|
43
|
+
assignNativeLogConversationId,
|
|
44
|
+
fillHermesLogConversationFallback,
|
|
45
|
+
nativeLogConversationIdFromHeaders,
|
|
43
46
|
getOrAllocateRequestSessionLane,
|
|
44
47
|
linkRequestSessionLane,
|
|
45
48
|
} from "./request-log-conversation";
|
|
@@ -69,7 +72,7 @@ import {
|
|
|
69
72
|
assertRouteAllowedByScope,
|
|
70
73
|
resolveAdmissionModelScope,
|
|
71
74
|
} from "./admission-model-scope";
|
|
72
|
-
import type
|
|
75
|
+
import { resolveContextPrincipal, type DataPlaneAdmission } from "./auth-cors";
|
|
73
76
|
import { tryClaimNativeMainProfileForTurn } from "../codex/native-main-admission";
|
|
74
77
|
import {
|
|
75
78
|
createTranslatorBudget,
|
|
@@ -114,6 +117,10 @@ export async function handleChatCompletions(
|
|
|
114
117
|
logCtx: RequestLogContext,
|
|
115
118
|
logIds?: { requestId: string; start: number; turnAdmissionLease?: AdmissionLease; admission?: DataPlaneAdmission },
|
|
116
119
|
): Promise<Response> {
|
|
120
|
+
// Set before routing so pre-dispatch refusals stay correlated. A Hermes-only id is marked as a
|
|
121
|
+
// fallback, so a native id resolved later on the Responses bridge still replaces it.
|
|
122
|
+
assignNativeLogConversationId(logCtx, nativeLogConversationIdFromHeaders(req.headers));
|
|
123
|
+
fillHermesLogConversationFallback(logCtx, req.headers);
|
|
117
124
|
const translatorBudget = createTranslatorBudget();
|
|
118
125
|
try {
|
|
119
126
|
let response = await handleChatCompletionsWithBudget(req, config, logCtx, translatorBudget, logIds);
|
|
@@ -343,6 +350,13 @@ async function handleChatCompletionsWithBudget(
|
|
|
343
350
|
// and sends the core only the request settings.
|
|
344
351
|
if (directRoute) {
|
|
345
352
|
directConversation = chatConversationToIr(chatBody, chatBody.model as string);
|
|
353
|
+
// Unlike the bridge body below, the settings-only projection does not contain the
|
|
354
|
+
// conversation. Account for the retained IR itself before an adapter materializes it
|
|
355
|
+
// again; reasoning placeholders can be larger than the source Chat message.
|
|
356
|
+
translatorBudget.chargeRetained(
|
|
357
|
+
Buffer.byteLength(JSON.stringify(directConversation), "utf8"),
|
|
358
|
+
{ kind: "request_copies" },
|
|
359
|
+
);
|
|
346
360
|
internalBody = chatSettingsBody(chatBody);
|
|
347
361
|
} else {
|
|
348
362
|
internalBody = chatToResponsesBody(chatBody, {
|
|
@@ -420,6 +434,7 @@ async function handleChatCompletionsWithBudget(
|
|
|
420
434
|
// Unresolved combos are checked after their concrete child route is selected in Responses.
|
|
421
435
|
if (settledRoute && !settledRoute.combo && isCanonicalOpenAiForwardProvider(settledRoute.provider)
|
|
422
436
|
&& isCodexReserveHelperUnsupported(config, settledRoute.modelId, logIds?.admission, visionDescribeTerminal)) {
|
|
437
|
+
if (logIds) addFinalRequestLog(logIds.requestId, logIds.start, logCtx, 400, { closeReason: "non_stream" });
|
|
423
438
|
return chatCompletionsErrorResponse(400, CODEX_RESERVE_HELPER_UNSUPPORTED_MESSAGE, "invalid_request_error");
|
|
424
439
|
}
|
|
425
440
|
const nativeCallerAuth = captureExplicitOpenAiCallerAuth(req.headers, config);
|
|
@@ -498,6 +513,8 @@ async function handleChatCompletionsWithBudget(
|
|
|
498
513
|
// #1686: the Chat surface translates its body and replays here, so the admission fact has
|
|
499
514
|
// to ride along or a bearer-admitted Chat caller would still be refused by Direct.
|
|
500
515
|
...(logIds?.admission ? { admission: logIds.admission } : {}),
|
|
516
|
+
// The bridge request carries no caller credential, so resolve the replay principal here.
|
|
517
|
+
replayPrincipal: { clientPrincipalId: resolveContextPrincipal(req, config, logIds?.admission) },
|
|
501
518
|
abortSignal: req.signal,
|
|
502
519
|
// Body is Responses-shaped by now, but the client spoke Chat Completions.
|
|
503
520
|
inboundWire: "chat",
|
|
@@ -512,6 +529,9 @@ async function handleChatCompletionsWithBudget(
|
|
|
512
529
|
...(envelope && nativeChatCombos ? {
|
|
513
530
|
protocolSource: createNativeChatComboSource({
|
|
514
531
|
req, config, envelope, requestedModel, requestedStream: stream, translatorBudget,
|
|
532
|
+
// Children run without logIds; the request's admission rides the source so their
|
|
533
|
+
// replay scope resolves the same caller principal as every other surface.
|
|
534
|
+
...(logIds?.admission ? { admission: logIds.admission } : {}),
|
|
515
535
|
}),
|
|
516
536
|
} : {}),
|
|
517
537
|
// Terminal vision-describe marker (roadmap 180): the bridge rebuilds
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { chatBodyCarriesImage, chatBodyCarriesToolResultImage } from "../chat/image-parts";
|
|
2
|
+
import { chatBodyCarriesAnthropicReasoningState } from "../chat/reasoning-details";
|
|
2
3
|
import type { ProtocolReasonCode } from "../protocols/contract";
|
|
3
4
|
import type { RouteResult } from "../router";
|
|
4
5
|
import type { OcxConfig } from "../types";
|
|
@@ -20,6 +21,7 @@ export type NativeChatDeclineReason = Extract<
|
|
|
20
21
|
| "tool-result-image"
|
|
21
22
|
| "vision-preprocessing"
|
|
22
23
|
| "hosted-tool"
|
|
24
|
+
| "opaque-state-stripped"
|
|
23
25
|
>;
|
|
24
26
|
|
|
25
27
|
/**
|
|
@@ -40,6 +42,11 @@ export function nativeChatDeclineReason(
|
|
|
40
42
|
if (rawBody.store === true || rawBody.background === true) return "responses-only-feature";
|
|
41
43
|
if (typeof rawBody.previous_response_id === "string" && rawBody.previous_response_id.length > 0) return "responses-only-feature";
|
|
42
44
|
if (rawBody.compaction_trigger !== undefined) return "responses-only-feature";
|
|
45
|
+
// Native Chat preserves caller message objects verbatim. Anthropic reasoning state — an entry
|
|
46
|
+
// with the anthropic-claude-v1 marker or an unmarked signed reasoning.text the inbound replay
|
|
47
|
+
// accepts — can contain signatures or redacted-thinking ciphertext, so use the bridge that
|
|
48
|
+
// projects it to plaintext rather than disclosing it to an unrelated Chat destination.
|
|
49
|
+
if (chatBodyCarriesAnthropicReasoningState(rawBody)) return "opaque-state-stripped";
|
|
43
50
|
// A standard Chat tool message accepts a string or text parts, not image_url, so
|
|
44
51
|
// normalizing a Pi/Anthropic tool image into image_url is not enough on its own —
|
|
45
52
|
// the part is still inside a tool message. The translated adapter already places
|
|
@@ -7,11 +7,17 @@ import { reasoningReplayConversationIdFromResponsesRequest, sessionIdHeaderFromR
|
|
|
7
7
|
|
|
8
8
|
type Rec = Record<string, unknown>;
|
|
9
9
|
|
|
10
|
-
export function nativeChatReplayScope(
|
|
10
|
+
export function nativeChatReplayScope(
|
|
11
|
+
headers: Headers,
|
|
12
|
+
clientPrincipalId: string | undefined,
|
|
13
|
+
): OcxReasoningReplayScopeRef | undefined {
|
|
11
14
|
const clientThreadId = reasoningReplayConversationIdFromResponsesRequest({
|
|
12
15
|
threadIdHeader: headers.get("thread-id"), sessionIdHeader: sessionIdHeaderFromRequest(headers),
|
|
13
16
|
});
|
|
14
|
-
return clientThreadId ? {
|
|
17
|
+
return clientThreadId ? {
|
|
18
|
+
clientThreadId,
|
|
19
|
+
...(clientPrincipalId ? { clientPrincipalId } : {}),
|
|
20
|
+
} : undefined;
|
|
15
21
|
}
|
|
16
22
|
|
|
17
23
|
/** Rebind before EVERY build: a key rotation must not retrieve another credential's reasoning. */
|
|
@@ -42,7 +48,8 @@ export function nativeChatReasoningCapture(
|
|
|
42
48
|
const maxBytes = 256 * 1024;
|
|
43
49
|
let bytes = 0;
|
|
44
50
|
let callCount = 0;
|
|
45
|
-
let disabled = !scope?.
|
|
51
|
+
let disabled = !scope?.clientPrincipalId || !scope.current
|
|
52
|
+
|| !chatReasoningReplayPolicy(provider, modelId).preserve;
|
|
46
53
|
const discard = () => {
|
|
47
54
|
budget.releaseRetained(bytes, accounting);
|
|
48
55
|
bytes = 0;
|
|
@@ -75,8 +82,13 @@ export function nativeChatReasoningCapture(
|
|
|
75
82
|
return previous + fragment;
|
|
76
83
|
} finally { reservation.release(); }
|
|
77
84
|
};
|
|
78
|
-
|
|
79
|
-
|
|
85
|
+
const rText = typeof delta.reasoning_content === "string" && delta.reasoning_content.length > 0
|
|
86
|
+
? delta.reasoning_content
|
|
87
|
+
: typeof delta.reasoning === "string" && delta.reasoning.length > 0
|
|
88
|
+
? delta.reasoning
|
|
89
|
+
: undefined;
|
|
90
|
+
if (rText !== undefined) {
|
|
91
|
+
const text = append(state.text, rText);
|
|
80
92
|
if (text === undefined) return;
|
|
81
93
|
state.text = text;
|
|
82
94
|
}
|
|
@@ -114,8 +126,13 @@ export function nativeChatReasoningCapture(
|
|
|
114
126
|
for (const choice of value.choices) {
|
|
115
127
|
if (!isChatRecord(choice) || !isChatRecord(choice.message)) continue;
|
|
116
128
|
const message = choice.message;
|
|
117
|
-
|
|
118
|
-
|
|
129
|
+
const rText = typeof message.reasoning_content === "string" && message.reasoning_content.length > 0
|
|
130
|
+
? message.reasoning_content
|
|
131
|
+
: typeof message.reasoning === "string" && message.reasoning.length > 0
|
|
132
|
+
? message.reasoning
|
|
133
|
+
: undefined;
|
|
134
|
+
if (rText === undefined || !Array.isArray(message.tool_calls)) continue;
|
|
135
|
+
remember(rText, message.tool_calls.filter(isChatRecord)
|
|
119
136
|
.flatMap(tool => typeof tool.id === "string" ? [tool.id] : []));
|
|
120
137
|
}
|
|
121
138
|
},
|
|
@@ -24,6 +24,7 @@ import {
|
|
|
24
24
|
} from "../lib/errors";
|
|
25
25
|
import { reportDispatchSends, type RequestExecutionBudget, type SingleUseDispatchPermit } from "../lib/request-execution-budget";
|
|
26
26
|
import type { AdmissionLease } from "../lib/admission";
|
|
27
|
+
import { resolveContextPrincipal, type DataPlaneAdmission } from "./auth-cors";
|
|
27
28
|
import { readBoundedResponseBody } from "../lib/bounded-body";
|
|
28
29
|
import { redactSecretString } from "../lib/redact";
|
|
29
30
|
import { resolveClientRetryAfter } from "../lib/retry-after";
|
|
@@ -179,7 +180,7 @@ export interface HandleNativeChatOptions {
|
|
|
179
180
|
req: Request;
|
|
180
181
|
config: OcxConfig;
|
|
181
182
|
logCtx: RequestLogContext;
|
|
182
|
-
logIds?: { requestId: string; start: number; turnAdmissionLease?: AdmissionLease };
|
|
183
|
+
logIds?: { requestId: string; start: number; turnAdmissionLease?: AdmissionLease; admission?: DataPlaneAdmission };
|
|
183
184
|
route: RouteResult;
|
|
184
185
|
chatBody: Rec;
|
|
185
186
|
requestedModel: string;
|
|
@@ -209,6 +210,12 @@ export interface NativeChatExecution extends HandleNativeChatOptions {
|
|
|
209
210
|
onFirstOutput?: () => void;
|
|
210
211
|
/** The lease a streamed body holds; defaults to `logIds.turnAdmissionLease`. */
|
|
211
212
|
turnAdmissionLease?: AdmissionLease;
|
|
213
|
+
/**
|
|
214
|
+
* The request's resolved data-plane admission, when the caller carries it without `logIds`.
|
|
215
|
+
* A combo child runs on the parent's log row, so it receives the admitted identity here or
|
|
216
|
+
* its reasoning replay scope can never establish a caller principal (PF-07).
|
|
217
|
+
*/
|
|
218
|
+
admission?: DataPlaneAdmission;
|
|
212
219
|
}
|
|
213
220
|
|
|
214
221
|
/**
|
|
@@ -246,6 +253,8 @@ export function createNativeChatComboSource(input: {
|
|
|
246
253
|
requestedModel: string;
|
|
247
254
|
requestedStream: boolean;
|
|
248
255
|
translatorBudget: TranslatorBudget;
|
|
256
|
+
/** The request's data-plane admission; native children inherit it for replay scope. */
|
|
257
|
+
admission?: DataPlaneAdmission;
|
|
249
258
|
}): ComboProtocolSource {
|
|
250
259
|
return {
|
|
251
260
|
inbound: "chat",
|
|
@@ -264,6 +273,7 @@ export function createNativeChatComboSource(input: {
|
|
|
264
273
|
comboDispatchPermit: child.comboDispatchPermit,
|
|
265
274
|
onFirstOutput: child.onFirstOutput,
|
|
266
275
|
...(child.turnAdmissionLease ? { turnAdmissionLease: child.turnAdmissionLease } : {}),
|
|
276
|
+
...(input.admission ? { admission: input.admission } : {}),
|
|
267
277
|
}, child.attemptHandle),
|
|
268
278
|
};
|
|
269
279
|
}
|
|
@@ -340,7 +350,8 @@ export async function runNativeChatAttempt(
|
|
|
340
350
|
const physicalBudget = sendBudget ?? createInferenceSendBudget(req, logCtx);
|
|
341
351
|
let activeAdapter: ProviderAdapter = createOpenAIChatAdapter(activeProvider);
|
|
342
352
|
let activeRequest: AdapterRequest;
|
|
343
|
-
const replayScope = nativeChatReplayScope(req.headers
|
|
353
|
+
const replayScope = nativeChatReplayScope(req.headers,
|
|
354
|
+
resolveContextPrincipal(req, config, execution.admission ?? logIds?.admission));
|
|
344
355
|
let retainedRequestBytes = 0;
|
|
345
356
|
const releaseRetainedRequest = () => {
|
|
346
357
|
if (retainedRequestBytes === 0) return;
|
|
@@ -100,6 +100,7 @@ import {
|
|
|
100
100
|
isApiAuthRequired,
|
|
101
101
|
isDataPlaneAdmissionSecret,
|
|
102
102
|
isProxyAdmissionSecret,
|
|
103
|
+
resolveContextPrincipal,
|
|
103
104
|
type RequestPolicyView,
|
|
104
105
|
type DataPlaneAdmission,
|
|
105
106
|
} from "./auth-cors";
|
|
@@ -1117,6 +1118,8 @@ async function handleClaudeMessagesWithBudget(
|
|
|
1117
1118
|
// Routing keeps Claude-only sidecar overrides; admission policy must follow the live owner.
|
|
1118
1119
|
codexAuthPolicy: config,
|
|
1119
1120
|
...(logIds?.admission ? { admission: logIds.admission } : {}),
|
|
1121
|
+
// The translated request never forwards the caller credential; resolve the principal first.
|
|
1122
|
+
replayPrincipal: { clientPrincipalId: resolveContextPrincipal(req, config, logIds?.admission) },
|
|
1120
1123
|
...(logIds?.turnAdmissionLease ? { turnAdmissionLease: logIds.turnAdmissionLease } : {}),
|
|
1121
1124
|
abortSignal: req.signal,
|
|
1122
1125
|
promptCacheKeyIsSharedCohort: cacheKeySource === "system",
|
|
@@ -7,6 +7,8 @@ type DirectLocalHttpIo = {
|
|
|
7
7
|
timeoutMs?: number;
|
|
8
8
|
connect?: (hostname: string, port: number) => Socket;
|
|
9
9
|
scheduleDeadline?: (onTimeout: () => void, timeoutMs: number) => () => void;
|
|
10
|
+
/** Observe a parsed response status before reading its bounded body. */
|
|
11
|
+
onResponseStatus?: (status: number) => void;
|
|
10
12
|
};
|
|
11
13
|
|
|
12
14
|
function abortReason(signal: AbortSignal): Error {
|
|
@@ -96,7 +98,7 @@ function parseResponseHead(bytes: Buffer, boundary: number): {
|
|
|
96
98
|
return { status, statusText: match[2] ?? "", headers };
|
|
97
99
|
}
|
|
98
100
|
|
|
99
|
-
function advanceResponseFraming(bytes: Buffer, initial: ResponseFraming): ResponseFraming {
|
|
101
|
+
function advanceResponseFraming(bytes: Buffer, initial: ResponseFraming, onResponseStatus?: (status: number) => void): ResponseFraming {
|
|
100
102
|
let framing = initial;
|
|
101
103
|
for (;;) {
|
|
102
104
|
if (framing.kind === "complete" || framing.kind === "close") return framing;
|
|
@@ -107,6 +109,7 @@ function advanceResponseFraming(bytes: Buffer, initial: ResponseFraming): Respon
|
|
|
107
109
|
return { kind: "head", searchFrom: Math.max(0, bytes.length - 3) };
|
|
108
110
|
}
|
|
109
111
|
const { status, headers } = parseResponseHead(bytes, boundary);
|
|
112
|
+
onResponseStatus?.(status);
|
|
110
113
|
const bodyStart = boundary + 4;
|
|
111
114
|
if (status === 204 || status === 205 || status === 304) {
|
|
112
115
|
if (bytes.length > bodyStart) {
|
|
@@ -350,7 +353,7 @@ export async function directLocalHttpFetch(
|
|
|
350
353
|
}
|
|
351
354
|
bytes.copy(responseBytes, receivedBytes - bytes.byteLength);
|
|
352
355
|
try {
|
|
353
|
-
framing = advanceResponseFraming(responseBytes.subarray(0, receivedBytes), framing);
|
|
356
|
+
framing = advanceResponseFraming(responseBytes.subarray(0, receivedBytes), framing, io.onResponseStatus);
|
|
354
357
|
if (framing.kind === "complete") finish();
|
|
355
358
|
} catch (error) {
|
|
356
359
|
finish(error instanceof Error ? error : new Error(String(error)));
|
|
@@ -232,6 +232,7 @@ interface EffortSnapshot {
|
|
|
232
232
|
modelId: string;
|
|
233
233
|
reasoningPresent: boolean;
|
|
234
234
|
reasoning: OcxParsedRequest["options"]["reasoning"];
|
|
235
|
+
thinkingEnabled: boolean | undefined;
|
|
235
236
|
rawEffortPresent: boolean;
|
|
236
237
|
rawEffort: unknown;
|
|
237
238
|
}
|
|
@@ -239,7 +240,7 @@ interface EffortSnapshot {
|
|
|
239
240
|
const effortSnapshots = new WeakMap<OcxParsedRequest, EffortSnapshot>();
|
|
240
241
|
|
|
241
242
|
/** Capture effective synthetic/combo defaults before final model namespace rewriting.
|
|
242
|
-
* A different destination restores effort
|
|
243
|
+
* A different destination restores effort and thinking choice; intervening summary edits survive.
|
|
243
244
|
* Credential retries do not change the destination and retain their existing decision.
|
|
244
245
|
*/
|
|
245
246
|
export function prepareEffortNormalization(
|
|
@@ -255,6 +256,7 @@ export function prepareEffortNormalization(
|
|
|
255
256
|
modelId: route.modelId,
|
|
256
257
|
reasoningPresent: Object.hasOwn(parsed.options, "reasoning"),
|
|
257
258
|
reasoning: parsed.options.reasoning,
|
|
259
|
+
thinkingEnabled: parsed.options.thinkingEnabled,
|
|
258
260
|
rawEffortPresent: !!raw?.reasoning && Object.hasOwn(raw.reasoning, "effort"),
|
|
259
261
|
rawEffort: raw?.reasoning?.effort,
|
|
260
262
|
});
|
|
@@ -265,6 +267,8 @@ export function prepareEffortNormalization(
|
|
|
265
267
|
}
|
|
266
268
|
if (previous.reasoningPresent) parsed.options.reasoning = previous.reasoning;
|
|
267
269
|
else delete parsed.options.reasoning;
|
|
270
|
+
if (previous.thinkingEnabled !== undefined) parsed.options.thinkingEnabled = previous.thinkingEnabled;
|
|
271
|
+
else delete parsed.options.thinkingEnabled;
|
|
268
272
|
if (raw && previous.rawEffortPresent) {
|
|
269
273
|
if (!raw.reasoning || typeof raw.reasoning !== "object") raw.reasoning = {};
|
|
270
274
|
raw.reasoning.effort = previous.rawEffort;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Server } from "bun";
|
|
2
2
|
import {
|
|
3
3
|
LINK_RELAY_AUTH_PATH, LINK_RELAY_AUTH_TIMEOUT_MS, LINK_RELAY_AUTH_VERSION,
|
|
4
|
-
LINK_RELAY_SESSION_HEADER, linkRelayProof, linkRelayProofMatches,
|
|
4
|
+
LINK_RELAY_PROBE_HEADER, LINK_RELAY_SESSION_HEADER, linkRelayProof, linkRelayProofMatches,
|
|
5
5
|
} from "../../link/relay-auth";
|
|
6
6
|
import { parseLinkPeerReport, type LinkPeerObservations } from "../../link/peer-report";
|
|
7
7
|
|
|
@@ -81,13 +81,17 @@ export function createLinkRelaySessions(options: LinkRelaySessionOptions) {
|
|
|
81
81
|
linkRelayProofMatches(q.get("proof"), linkRelayProof(candidate, "caller", keyId, linkId, nonce)));
|
|
82
82
|
if (!fingerprint) return refuse();
|
|
83
83
|
options.peers?.observe(linkId, LINK_RELAY_AUTH_VERSION, parseLinkPeerReport(req.headers));
|
|
84
|
-
const
|
|
85
|
-
const timer = setTimeout(() => { consume(nonce)?.release(); }, reservationMs);
|
|
86
|
-
sessions.set(nonce, { peer, keyId, linkId, fingerprint, release, timer, expiresAt: Date.now() + reservationMs });
|
|
87
|
-
return new Response(null, { status: 204, headers: {
|
|
84
|
+
const answer = () => new Response(null, { status: 204, headers: {
|
|
88
85
|
"x-opencodex-link-proof": linkRelayProof(fingerprint, "listener", keyId, linkId, nonce)!,
|
|
89
86
|
"cache-control": "no-store",
|
|
90
87
|
} });
|
|
88
|
+
// A readiness probe closes after this answer and sends no data request, so it reserves
|
|
89
|
+
// nothing: no session to consume, no capacity and no drain lease held until expiry.
|
|
90
|
+
if (req.headers.get(LINK_RELAY_PROBE_HEADER) === "1") return answer();
|
|
91
|
+
const release = acquire();
|
|
92
|
+
const timer = setTimeout(() => { consume(nonce)?.release(); }, reservationMs);
|
|
93
|
+
sessions.set(nonce, { peer, keyId, linkId, fingerprint, release, timer, expiresAt: Date.now() + reservationMs });
|
|
94
|
+
return answer();
|
|
91
95
|
}
|
|
92
96
|
const nonce = req.headers.get(LINK_RELAY_SESSION_HEADER);
|
|
93
97
|
let release: () => void;
|
|
@@ -184,6 +184,19 @@ function finalizeLiveSideband(ws: ServerWebSocket<WsData>, upstream?: WebSocket)
|
|
|
184
184
|
finally { releaseLiveSidebandAdmission(ws); }
|
|
185
185
|
}
|
|
186
186
|
|
|
187
|
+
function forceCloseLiveSidebandUpstream(upstream: WebSocket): void {
|
|
188
|
+
// Bun 1.4.4 waits for the peer's closing handshake; another close() while
|
|
189
|
+
// CLOSING does not finish it. Stop the transport after the graceful window,
|
|
190
|
+
// but leave admission release to the close event or an observed CLOSED state.
|
|
191
|
+
try {
|
|
192
|
+
const socket = upstream as WebSocket & { terminate?: () => void };
|
|
193
|
+
if (typeof socket.terminate === "function") socket.terminate();
|
|
194
|
+
else upstream.close(1000, "upstream close timeout");
|
|
195
|
+
} catch {
|
|
196
|
+
/* retain ownership until transport closure is confirmed */
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
187
200
|
function armLiveSidebandCloseFallback(ws: ServerWebSocket<WsData>, upstream: WebSocket): void {
|
|
188
201
|
if (ws.data.liveCloseFallback !== undefined) return;
|
|
189
202
|
ws.data.liveCloseFallback = setTimeout(() => {
|
|
@@ -193,13 +206,7 @@ function armLiveSidebandCloseFallback(ws: ServerWebSocket<WsData>, upstream: Web
|
|
|
193
206
|
finalizeLiveSideband(ws, upstream);
|
|
194
207
|
return;
|
|
195
208
|
}
|
|
196
|
-
|
|
197
|
-
// native-main ownership while the authenticated transport remains live.
|
|
198
|
-
try {
|
|
199
|
-
upstream.close(1000, "upstream close timeout");
|
|
200
|
-
} catch {
|
|
201
|
-
/* upstream is already unusable */
|
|
202
|
-
}
|
|
209
|
+
forceCloseLiveSidebandUpstream(upstream);
|
|
203
210
|
// Some implementations transition synchronously without delivering the
|
|
204
211
|
// close event. That is still an observed CLOSED transport and is safe to
|
|
205
212
|
// finalize. CONNECTING/CLOSING peers keep the lease so profile switching
|
|
@@ -238,17 +245,13 @@ export function closeLiveSidebandBeforeUpgrade(
|
|
|
238
245
|
releaseOnce();
|
|
239
246
|
return;
|
|
240
247
|
}
|
|
241
|
-
|
|
242
|
-
upstream.close(1000, "upstream close timeout");
|
|
243
|
-
} catch {
|
|
244
|
-
/* retain ownership until CLOSED is observed */
|
|
245
|
-
}
|
|
248
|
+
forceCloseLiveSidebandUpstream(upstream);
|
|
246
249
|
if ((upstream.readyState as number) === 3) releaseOnce();
|
|
247
250
|
}, LIVE_SIDEBAND_CLOSE_FALLBACK_MS);
|
|
248
251
|
try {
|
|
249
252
|
upstream.close(code, reason);
|
|
250
253
|
} catch {
|
|
251
|
-
/* the bounded fallback
|
|
254
|
+
/* the bounded fallback stops the transport before releasing ownership */
|
|
252
255
|
}
|
|
253
256
|
if ((upstream.readyState as number) === 3) releaseOnce();
|
|
254
257
|
}
|
|
@@ -272,12 +275,12 @@ export function closeLiveSideband(ws: ServerWebSocket<WsData>, code = 1000, reas
|
|
|
272
275
|
// The sideband holds a native-main admission lease. Do not release it just
|
|
273
276
|
// because the downstream left: its authenticated upstream remains live
|
|
274
277
|
// until the close event arrives or the transport is observed CLOSED. The
|
|
275
|
-
// bounded fallback
|
|
278
|
+
// bounded fallback terminates the transport; it cannot release a live lease.
|
|
276
279
|
armLiveSidebandCloseFallback(ws, upstream);
|
|
277
280
|
try {
|
|
278
281
|
upstream.close(code, reason);
|
|
279
282
|
} catch {
|
|
280
|
-
/* the fallback
|
|
283
|
+
/* the fallback stops the transport without releasing a live lease */
|
|
281
284
|
}
|
|
282
285
|
}
|
|
283
286
|
try {
|
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
type LinkListenerStatus,
|
|
15
15
|
} from "./link-listener";
|
|
16
16
|
import { createLinkSupervisor, type LinkSupervisor } from "../../link/supervisor";
|
|
17
|
+
import { flushLinkDiagnostics, recordLinkDiagnostic } from "../../link/diagnostics";
|
|
17
18
|
import { linkManagementRouteAllowed } from "../../link/management-routes";
|
|
18
19
|
import { linkChildParityRouteAllowed } from "../../link/child-parity";
|
|
19
20
|
import { saveConfigPreservingClaudeCode } from "../../config/live-reconcile";
|
|
@@ -56,6 +57,9 @@ export function createOptionalListenerSet<T>(linkDeps: LinkListenerDeps = {}): O
|
|
|
56
57
|
let activeConfig: OcxConfig | undefined;
|
|
57
58
|
let stopJevQuotaActivation: (() => void) | undefined;
|
|
58
59
|
const supervisor = createLinkSupervisor({
|
|
60
|
+
// Tunnel state changes and their causes reach <configDir>/link/diagnostics.jsonl (bounded).
|
|
61
|
+
diagnostic: recordLinkDiagnostic,
|
|
62
|
+
flushDiagnostics: flushLinkDiagnostics,
|
|
59
63
|
apiKeys: () => activeConfig?.apiKeys ?? [],
|
|
60
64
|
revokeApiKey: id => {
|
|
61
65
|
if (!activeConfig) return false;
|
|
@@ -1304,9 +1304,10 @@ export function createServeOptions(ctx: ServeOptionsContext) {
|
|
|
1304
1304
|
...(effectiveId !== publicId ? { native_id: publicId } : {}),
|
|
1305
1305
|
...grokEffortFields(m.reasoningEfforts ?? [], m.defaultReasoningEffort),
|
|
1306
1306
|
...modelCapabilityFields({
|
|
1307
|
+
supportsReasoning: m.supportsReasoning, supportsReasoningEffort: m.supportsReasoningEffort,
|
|
1308
|
+
supportsThinkingToggle: m.supportsThinkingToggle, defaultThinkingEnabled: m.defaultThinkingEnabled,
|
|
1307
1309
|
reasoningEfforts: m.reasoningEfforts,
|
|
1308
|
-
//
|
|
1309
|
-
// operator knob and over-reports models whose real window sits below it.
|
|
1310
|
+
// Use the post-cap window; the raw contextCap can exceed a model's real window.
|
|
1310
1311
|
contextWindow: m.contextWindow,
|
|
1311
1312
|
maxOutputTokens: m.maxOutputTokens,
|
|
1312
1313
|
inputModalities: m.inputModalities,
|
|
@@ -1766,7 +1767,7 @@ export function createServeOptions(ctx: ServeOptionsContext) {
|
|
|
1766
1767
|
if (audioController) registerTurn(audioController, turnAdmissionLease);
|
|
1767
1768
|
const acquisition = audioController
|
|
1768
1769
|
? clearableDeadline(120_000, AbortSignal.any([req.signal, audioController.signal])) : undefined;
|
|
1769
|
-
const detachClientAbort = turnAdmissionLease.bindAbortSignal(req.signal);
|
|
1770
|
+
const detachClientAbort = turnAdmissionLease.bindAbortSignal(req.signal); // detached at the dial; then close/CLOSED owns release
|
|
1770
1771
|
const releaseAcquisition = () => {
|
|
1771
1772
|
detachClientAbort();
|
|
1772
1773
|
acquisition?.clear();
|
|
@@ -1819,6 +1820,7 @@ export function createServeOptions(ctx: ServeOptionsContext) {
|
|
|
1819
1820
|
finally { finalizeLiveRequest(499, { closeReason: "client_cancel" }); }
|
|
1820
1821
|
return withCors(formatErrorResponse(499, "client_closed_request", "Audio connection canceled"), req, policy);
|
|
1821
1822
|
}
|
|
1823
|
+
detachClientAbort();
|
|
1822
1824
|
const upstreamHandshake = await openLiveSidebandUpstream(
|
|
1823
1825
|
resolved.upstreamWsUrl,
|
|
1824
1826
|
resolved.headers,
|
|
@@ -1887,7 +1889,6 @@ export function createServeOptions(ctx: ServeOptionsContext) {
|
|
|
1887
1889
|
return withCors(formatErrorResponse(502, "upstream_error", "Audio WebSocket upgrade failed"), req, policy);
|
|
1888
1890
|
}
|
|
1889
1891
|
if (upgraded) {
|
|
1890
|
-
detachClientAbort();
|
|
1891
1892
|
acquisition?.clear();
|
|
1892
1893
|
finalizeLiveRequest(101);
|
|
1893
1894
|
return undefined as unknown as Response;
|
|
@@ -51,7 +51,7 @@ export interface LocalManagementReadRequestDeps extends LocalManagementReadDeps
|
|
|
51
51
|
*/
|
|
52
52
|
export async function fetchBoundLocalManagementRead(
|
|
53
53
|
target: LiveProxy,
|
|
54
|
-
path: LocalManagementReadPath
|
|
54
|
+
path: LocalManagementReadPath | `${LocalManagementReadPath}?${string}`,
|
|
55
55
|
deps: LocalManagementReadRequestDeps = {},
|
|
56
56
|
): Promise<LocalManagementReadResult> {
|
|
57
57
|
if (
|
|
@@ -89,6 +89,8 @@ export async function fetchBoundLocalManagementRead(
|
|
|
89
89
|
const timeoutMs = deps.timeoutMs ?? 4_000;
|
|
90
90
|
const url = `http://${probeHostname(target.hostname)}:${target.port}${path}`;
|
|
91
91
|
const init: RequestInit = {
|
|
92
|
+
redirect: "error",
|
|
93
|
+
credentials: "omit",
|
|
92
94
|
headers: {
|
|
93
95
|
[LOCAL_MANAGEMENT_EXPECTED_PID_HEADER]: String(target.pid),
|
|
94
96
|
[LOCAL_MANAGEMENT_NONCE_HEADER]: nonce,
|