@bitkyc08/opencodex 2.99.0 → 2.100.0
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/AGENTS_INSTALL.md +19 -1
- package/README.md +37 -33
- package/SPONSORS.md +5 -1
- package/bin/ocx.mjs +1 -1
- package/gui/dist/assets/{App-C1hGwaN1.css → App-COo8Yopd.css} +1 -1
- package/gui/dist/assets/App-CitvEefy.js +59 -0
- package/gui/dist/assets/Tray-CeKVWQyB.js +1 -0
- package/gui/dist/assets/{brand-mark-wzPe3R-J.js → brand-mark-M92UnxX2.js} +1 -1
- package/gui/dist/assets/index-BP47do6-.js +94 -0
- package/gui/dist/assets/index-DmDooSAG.css +2 -0
- package/gui/dist/assets/{segment-thumb-features-fYEMxBaW.js → segment-thumb-features-CcxZBnxv.js} +1 -1
- package/gui/dist/classic/assets/App-aYgIQMxI.js +58 -0
- package/gui/dist/classic/assets/{Tray-BqZueZOx.js → Tray-D8jfUXpQ.js} +1 -1
- package/gui/dist/classic/assets/index-CfGqHooN.js +94 -0
- package/gui/dist/classic/assets/quota-summary-R-ih7OlS.js +1 -0
- package/gui/dist/classic/index.html +1 -1
- package/gui/dist/index.html +2 -2
- package/native/ocx-child/Cargo.lock +215 -0
- package/native/ocx-child/Cargo.toml +31 -0
- package/native/ocx-child/src/cli.rs +1901 -0
- package/native/ocx-child/src/codex_home.rs +429 -0
- package/native/ocx-child/src/codex_settings.rs +231 -0
- package/native/ocx-child/src/daemon.rs +363 -0
- package/native/ocx-child/src/http_wire.rs +619 -0
- package/native/ocx-child/src/journal.rs +977 -0
- package/native/ocx-child/src/lib.rs +22 -0
- package/native/ocx-child/src/main.rs +9 -0
- package/native/ocx-child/src/parity.rs +102 -0
- package/native/ocx-child/src/platform.rs +1487 -0
- package/native/ocx-child/src/relay.rs +1288 -0
- package/native/ocx-child/src/relay_auth.rs +166 -0
- package/native/ocx-child/src/routes.rs +236 -0
- package/native/ocx-child/src/state.rs +190 -0
- package/native/ocx-child/src/test_hooks.rs +58 -0
- package/native/ocx-child/src/toml_surgeon.rs +1156 -0
- package/package.json +8 -2
- package/src/adapters/anthropic.ts +28 -2
- package/src/adapters/claude-cli/adapter.ts +5 -25
- package/src/adapters/claude-cli/instruction-images.ts +31 -0
- package/src/adapters/claude-cli/stable-replay.ts +42 -14
- package/src/adapters/claude-cli/usage-admission.ts +53 -64
- package/src/adapters/coding-agent/protocol.ts +1 -1
- package/src/adapters/devin/live-models.ts +3 -0
- package/src/adapters/google-http.ts +3 -0
- package/src/adapters/google-vertex-key-project.ts +10 -2
- package/src/adapters/google.ts +40 -8
- package/src/adapters/kiro/usage.ts +3 -13
- package/src/adapters/openai-responses/passthrough.ts +5 -2
- package/src/adapters/openai-responses/request-strips.ts +32 -0
- package/src/adapters/openai-responses/tool-schema.ts +9 -4
- package/src/chat/inbound.ts +1 -1
- package/src/claude/auth-detect.ts +26 -8
- package/src/claude/inbound-content-options.ts +18 -3
- package/src/claude/inbound.ts +5 -2
- package/src/cli/bundled-bun-diagnostic.ts +91 -0
- package/src/cli/capabilities-agents-routing.ts +2 -2
- package/src/cli/capabilities-observe-system.ts +60 -0
- package/src/cli/combo-input.ts +6 -0
- package/src/cli/combo-result.ts +1 -1
- package/src/cli/combo.ts +4 -0
- package/src/cli/config-command.ts +16 -2
- package/src/cli/connect.ts +12 -10
- package/src/cli/dispatch.ts +4 -0
- package/src/cli/doctor.ts +11 -0
- package/src/cli/help.ts +1 -0
- package/src/cli/init.ts +4 -0
- package/src/cli/link-enrollment.ts +152 -25
- package/src/cli/link-local-control.ts +49 -0
- package/src/cli/link.ts +37 -10
- package/src/cli/provider-lifecycle-runtime.ts +4 -2
- package/src/cli/registry.ts +13 -0
- package/src/cli/star-prompt.ts +2 -0
- package/src/cli/status.ts +1 -1
- package/src/cli/telemetry-profile.ts +206 -0
- package/src/cli/telemetry.ts +260 -0
- package/src/client/hub-relay.ts +26 -0
- package/src/client/machine-api.ts +3 -0
- package/src/clients/config-export/t3code.ts +44 -5
- package/src/clients/omo-role-models.ts +1 -1
- package/src/codex/catalog/bundled.ts +44 -2
- package/src/codex/runtime.ts +12 -0
- package/src/codex/shim-restore-lock.ts +67 -30
- package/src/combos/types.ts +21 -1
- package/src/config/atomic-write.ts +24 -1
- package/src/config/diagnostics.ts +15 -0
- package/src/config/live-reconcile.ts +17 -0
- package/src/config/load-degrade.ts +16 -0
- package/src/config/provider-validation.ts +29 -0
- package/src/config/schema/config-schema.ts +24 -0
- package/src/config/schema/leaf-validators.ts +17 -0
- package/src/config/telemetry-carry.ts +30 -0
- package/src/config.ts +13 -1
- package/src/generated/compatibility-version.json +405 -153
- package/src/generated/model-metadata.ts +3 -3
- package/src/integrations/aside-profiles.ts +7 -1
- package/src/integrations/owned-refresh.ts +9 -2
- package/src/lab/artifacts/secure-fs.ts +12 -11
- package/src/lab/fabric/scratch.ts +11 -9
- package/src/lab/public/community.ts +2 -3
- package/src/lab/public/file-safety.ts +18 -20
- package/src/lab/public/mutation-lock.ts +109 -337
- package/src/lab/public/private-file.ts +4 -3
- package/src/lib/bun-runtime-preflight.ts +1 -1
- package/src/lib/codex-catalog-read-only.ts +122 -0
- package/src/lib/config-ownership.ts +49 -18
- package/src/lib/errors.ts +11 -0
- package/src/lib/gcp-adc.ts +167 -48
- package/src/lib/jsonc.ts +4 -2
- package/src/lib/local-control-socket.ts +88 -0
- package/src/lib/privacy.ts +15 -0
- package/src/lib/provider-client-headers.ts +3 -0
- package/src/lib/token-estimate.ts +13 -2
- package/src/link/child-binary-source.ts +228 -0
- package/src/link/ephemeral-child.ts +45 -0
- package/src/link/remote-plant.ts +306 -0
- package/src/link/remote-windows.ts +59 -5
- package/src/link/ssh-argv.ts +71 -8
- package/src/link/status-projection.ts +2 -0
- package/src/link/store.ts +5 -1
- package/src/oauth/claude-keychain-read.ts +165 -0
- package/src/oauth/local-token-detect.ts +14 -17
- package/src/protocols/envelope.ts +20 -2
- package/src/providers/api-key-selection.ts +8 -2
- package/src/providers/claude-cli-usage-state.ts +93 -0
- package/src/providers/github-copilot-auto.ts +25 -5
- package/src/providers/meta-muse-plan-refusal.ts +94 -0
- package/src/providers/model-rename-fields.ts +3 -0
- package/src/providers/quota/vendor-probes-key.ts +23 -4
- package/src/providers/quota/vendor-probes-oauth.ts +59 -0
- package/src/providers/quota/workbuddy.ts +2 -2
- package/src/providers/quota.ts +25 -18
- package/src/providers/registry/entries-core.ts +7 -4
- package/src/providers/registry/entries-extended.ts +39 -7
- package/src/providers/registry/model-seeds.ts +10 -2
- package/src/providers/resolved-model-policy.ts +4 -0
- package/src/providers/routed-config.ts +30 -3
- package/src/providers/stale-no-vision-seed-migration.ts +7 -0
- package/src/providers/vertex-environment-authority.ts +50 -0
- package/src/providers/workbuddy-credit-balance.ts +38 -6
- package/src/quota-pool/assemble.ts +14 -6
- package/src/router.ts +1 -0
- package/src/server/adapter-resolve.ts +11 -6
- package/src/server/audio-dictation.ts +21 -7
- package/src/server/auth-cors.ts +19 -0
- package/src/server/background-lifecycle.ts +71 -0
- package/src/server/chat-completions.ts +2 -0
- package/src/server/claude-messages.ts +30 -3
- package/src/server/index/live-sideband.ts +15 -1
- package/src/server/index/local-control-listener.ts +515 -0
- package/src/server/index/optional-listeners.ts +21 -1
- package/src/server/index/serve-options.ts +4 -3
- package/src/server/index/websocket-handler.ts +2 -0
- package/src/server/index.ts +3 -0
- package/src/server/management/combo-routes.ts +6 -1
- package/src/server/management/context.ts +1 -0
- package/src/server/management/link-child-preflight.ts +74 -0
- package/src/server/management/link-enrollment.ts +190 -25
- package/src/server/management/link-route-state.ts +6 -1
- package/src/server/management/link-routes.ts +27 -9
- package/src/server/management/model-rows.ts +4 -0
- package/src/server/management/oauth-account-routes.ts +9 -4
- package/src/server/management/provider-overwrite-carry.ts +9 -2
- package/src/server/management/provider-routes.ts +14 -0
- package/src/server/management/provider-thinking-display-patch.ts +54 -0
- package/src/server/management/route-registry.ts +7 -0
- package/src/server/management/session-routes.ts +4 -1
- package/src/server/management/telemetry-routes.ts +37 -0
- package/src/server/management/usage-aggregate-cache.ts +290 -67
- package/src/server/management-api.ts +11 -2
- package/src/server/messages-native-preflight.ts +166 -0
- package/src/server/messages-native.ts +143 -43
- package/src/server/messages-shared.ts +14 -0
- package/src/server/proxy-liveness.ts +99 -6
- package/src/server/request-log-conversation.ts +18 -2
- package/src/server/request-log.ts +7 -2
- package/src/server/responses/adapter-continuation.ts +1 -0
- package/src/server/responses/adapter-dispatch.ts +11 -28
- package/src/server/responses/adapter-failure-message.ts +68 -0
- package/src/server/responses/combo-stream-preflight.ts +14 -2
- package/src/server/responses/core-auth.ts +26 -5
- package/src/server/responses/core-codex-account.ts +8 -1
- package/src/server/responses/core-combo-failure.ts +6 -1
- package/src/server/responses/core-combo-native.ts +150 -37
- package/src/server/responses/core-combo.ts +15 -9
- package/src/server/responses/core-normalize.ts +1 -0
- package/src/server/responses/core-options.ts +7 -1
- package/src/server/responses/core-pipeline.ts +21 -1
- package/src/server/responses/fetch-helpers.ts +5 -0
- package/src/server/responses/opengateway-completion-guard.ts +7 -3
- package/src/server/responses/passthrough-delivery.ts +8 -1
- package/src/server/responses/passthrough-error.ts +22 -0
- package/src/server/responses/request-prepare.ts +7 -1
- package/src/server/responses/request-transport.ts +28 -5
- package/src/server/responses/run-turn-execution.ts +13 -0
- package/src/server/sse-frame-buffer.ts +5 -0
- package/src/server/ws-bridge.ts +10 -0
- package/src/service/launchd.ts +78 -4
- package/src/telemetry/aggregate.ts +348 -0
- package/src/telemetry/consent.ts +128 -0
- package/src/telemetry/contract.ts +403 -0
- package/src/telemetry/disclosure.ts +19 -0
- package/src/telemetry/install-id.ts +226 -0
- package/src/telemetry/payload.ts +129 -0
- package/src/telemetry/profile/client.ts +150 -0
- package/src/telemetry/profile/contract.ts +288 -0
- package/src/telemetry/profile/disclosure.ts +14 -0
- package/src/telemetry/profile/paths.ts +13 -0
- package/src/telemetry/profile/routes.ts +99 -0
- package/src/telemetry/profile/service.ts +234 -0
- package/src/telemetry/profile/state.ts +189 -0
- package/src/telemetry/profile/sync.ts +276 -0
- package/src/telemetry/routes.ts +183 -0
- package/src/telemetry/scheduler.ts +386 -0
- package/src/telemetry/sender.ts +97 -0
- package/src/telemetry/state.ts +334 -0
- package/src/types/combo-jev-effort-mode.ts +11 -0
- package/src/types/config.ts +3 -0
- package/src/types/provider.ts +11 -1
- package/src/types/request.ts +2 -0
- package/src/types/telemetry.ts +15 -0
- package/src/types/wire.ts +10 -0
- package/src/types.ts +5 -0
- package/src/update/index.ts +7 -1
- package/src/update/minisign.d.mts +17 -0
- package/src/update/minisign.mjs +88 -0
- package/src/update/signed-supply.d.mts +59 -0
- package/src/update/signed-supply.mjs +289 -0
- package/src/update/trust-root.json +38 -0
- package/src/update/update-bounded-json.d.mts +4 -0
- package/src/update/update-bounded-json.mjs +113 -0
- package/src/update/update-bytes.d.mts +2 -0
- package/src/update/update-bytes.mjs +23 -0
- package/src/update/update-candidate-id.d.mts +2 -0
- package/src/update/update-candidate-id.mjs +23 -0
- package/src/update/update-checkpoint-codec.d.mts +33 -0
- package/src/update/update-checkpoint-codec.mjs +217 -0
- package/src/update/update-contracts.d.mts +24 -0
- package/src/update/update-contracts.mjs +207 -0
- package/src/update/update-signature-threshold.d.mts +12 -0
- package/src/update/update-signature-threshold.mjs +47 -0
- package/src/update/update-signed-version.d.mts +5 -0
- package/src/update/update-signed-version.mjs +25 -0
- package/src/update/update-trust-anchor.d.mts +2 -0
- package/src/update/update-trust-anchor.mjs +2 -0
- package/src/usage/cache-diagnostic.ts +195 -50
- package/src/usage/expected-prices.ts +20 -2
- package/src/usage/filter-index.ts +1469 -0
- package/src/usage/ledger-scanner.ts +245 -4
- package/src/usage/source-filter.ts +10 -2
- package/src/usage/summary.ts +16 -0
- package/src/web-search/parse.ts +244 -38
- package/gui/dist/assets/App-BepstgEN.js +0 -59
- package/gui/dist/assets/Tray-BinxbEZo.js +0 -1
- package/gui/dist/assets/index-C-9X2yaI.js +0 -94
- package/gui/dist/assets/index-bnUWypyz.css +0 -2
- package/gui/dist/classic/assets/App-DX88_GCW.js +0 -58
- package/gui/dist/classic/assets/index-fSP71pLB.js +0 -94
- package/gui/dist/classic/assets/quota-summary-y2fl0WBv.js +0 -1
|
@@ -42,7 +42,7 @@ import {
|
|
|
42
42
|
} from "../providers/quota/account-cache";
|
|
43
43
|
import { parseQuotaFailureCode } from "../providers/quota-types";
|
|
44
44
|
import { getAccountSet } from "../oauth/store";
|
|
45
|
-
import { peekClaudeUsageObservation } from "../
|
|
45
|
+
import { claudeSignedInIdentity, peekClaudeUsageObservation } from "../providers/claude-cli-usage-state";
|
|
46
46
|
import {
|
|
47
47
|
QUOTA_POOL_SCHEMA,
|
|
48
48
|
type QuotaPool,
|
|
@@ -65,6 +65,8 @@ export interface QuotaPoolDeps {
|
|
|
65
65
|
now?: () => number;
|
|
66
66
|
/** Test seam for the Claude CLI admission file. */
|
|
67
67
|
claudeUsageStatePath?: string;
|
|
68
|
+
/** Test seam for a suspended passive Codex snapshot. */
|
|
69
|
+
codexSnapshot?: typeof listCodexAuthAccountsSnapshot;
|
|
68
70
|
}
|
|
69
71
|
|
|
70
72
|
export type QuotaPoolResult = { ok: true; pool: QuotaPool } | { ok: false; error: "quota_pool_identity_unavailable" };
|
|
@@ -272,8 +274,14 @@ function oauthAccounts(identity: QuotaPoolIdentity, provider: string, now: numbe
|
|
|
272
274
|
});
|
|
273
275
|
}
|
|
274
276
|
|
|
277
|
+
/**
|
|
278
|
+
* The signed-in Claude account's row, by the identity the last sign-in read recorded. The pool is a
|
|
279
|
+
* passive read and may not read the Keychain itself; the Home's dashboard and turns keep it current.
|
|
280
|
+
*/
|
|
275
281
|
function claudeCliAccounts(identity: QuotaPoolIdentity, provider: string, deps: QuotaPoolDeps, now: number): TrackedAccount[] {
|
|
276
|
-
const
|
|
282
|
+
const signedIn = claudeSignedInIdentity();
|
|
283
|
+
if (!signedIn) return [];
|
|
284
|
+
const observation = peekClaudeUsageObservation({ ...(deps.claudeUsageStatePath ? { statePath: deps.claudeUsageStatePath } : {}), identity: signedIn });
|
|
277
285
|
if (!observation) return [];
|
|
278
286
|
const windows = observation.quota ? providerQuotaWindows(observation.quota, "measured", now) : [];
|
|
279
287
|
if (finite(observation.refusalUntil) && observation.refusalUntil > now) {
|
|
@@ -305,7 +313,7 @@ async function assemble(config: OcxConfig, identity: QuotaPoolIdentity, deps: Qu
|
|
|
305
313
|
const names = Object.keys(config.providers).filter(name => enabled(config.providers[name])).sort();
|
|
306
314
|
const reports = new Map(heldProviderQuotaReports(names).reports.map(report => [report.provider, report]));
|
|
307
315
|
const codexPool = hasCodexPoolProvider(config);
|
|
308
|
-
const codex = codexPool ? (await listCodexAuthAccountsSnapshot(config)).accounts : [];
|
|
316
|
+
const codex = codexPool ? (await (deps.codexSnapshot ?? listCodexAuthAccountsSnapshot)(config)).accounts : [];
|
|
309
317
|
const providers: QuotaPoolProvider[] = [];
|
|
310
318
|
for (const name of names) {
|
|
311
319
|
const provider = config.providers[name]!;
|
|
@@ -328,9 +336,9 @@ async function assemble(config: OcxConfig, identity: QuotaPoolIdentity, deps: Qu
|
|
|
328
336
|
}
|
|
329
337
|
const report = reports.get(name);
|
|
330
338
|
if (!tracked && !report) continue;
|
|
331
|
-
// Account rows
|
|
332
|
-
//
|
|
333
|
-
const windows = poolFromRows && rows.length > 0
|
|
339
|
+
// Account rows carry their own observation times. Claude never falls back to a held report,
|
|
340
|
+
// which may have been captured before the most recent recorded identity change.
|
|
341
|
+
const windows = poolFromRows && (rows.length > 0 || provider.adapter === "claude-cli")
|
|
334
342
|
? pooledWindows(rows.map(row => row.pool), now)
|
|
335
343
|
: report ? providerQuotaWindows(report.quota, reportSource(report), now) : [];
|
|
336
344
|
const pooled: QuotaPoolProvider["pooled"] = { windows };
|
package/src/router.ts
CHANGED
|
@@ -318,6 +318,7 @@ function crossProviderRedirectTarget(config: OcxConfig, providerName: string, va
|
|
|
318
318
|
return usable ? value : undefined;
|
|
319
319
|
}
|
|
320
320
|
return authMode === "local" || effective.keyOptional === true || Boolean(effective.apiKey?.trim())
|
|
321
|
+
|| (authMode === "key" && effective.adapter === "google" && effective.googleMode === "vertex")
|
|
321
322
|
? value : undefined;
|
|
322
323
|
} catch {
|
|
323
324
|
return undefined;
|
|
@@ -4,6 +4,13 @@ import { isWirePinnedModel, MODEL_ADAPTER_OVERRIDE_ALLOWED, pinnedWireAdapter }
|
|
|
4
4
|
import { isCanonicalOpenAiForwardProvider } from "../providers/openai-tiers";
|
|
5
5
|
import { type InboundWire, providerModelWireDefault } from "../providers/registry";
|
|
6
6
|
import type { ResolvedModelPolicy } from "../providers/resolved-model-policy";
|
|
7
|
+
import { GCP_CREDENTIAL_MARKER_PREFIX } from "../providers/api-key-resolve";
|
|
8
|
+
|
|
9
|
+
function selectWire(provider: OcxProviderConfig, adapter: string): OcxProviderConfig {
|
|
10
|
+
const stripMarker = adapter !== "google" && provider.apiKey?.startsWith(GCP_CREDENTIAL_MARKER_PREFIX);
|
|
11
|
+
if (adapter === provider.adapter && !stripMarker) return provider;
|
|
12
|
+
return { ...provider, adapter, ...(stripMarker ? { apiKey: undefined } : {}) };
|
|
13
|
+
}
|
|
7
14
|
|
|
8
15
|
/**
|
|
9
16
|
* Resolve the wire a single model should use: a hard pin first, then a configured
|
|
@@ -28,13 +35,11 @@ export function resolveWireProtocolOverride(
|
|
|
28
35
|
// RouteResult policy is recaptured for the original inbound protocol whenever routing selects
|
|
29
36
|
// or replaces a destination, so every downstream rebuild consumes the same adapter authority.
|
|
30
37
|
if (staticPolicy) {
|
|
31
|
-
return staticPolicy.model.adapter
|
|
32
|
-
? { ...providerConfig, adapter: staticPolicy.model.adapter }
|
|
33
|
-
: providerConfig;
|
|
38
|
+
return selectWire(providerConfig, staticPolicy.model.adapter);
|
|
34
39
|
}
|
|
35
40
|
const pinned = pinnedWireAdapter(providerName, modelId, providerConfig);
|
|
36
41
|
if (pinned && providerConfig.adapter !== pinned) {
|
|
37
|
-
return
|
|
42
|
+
return selectWire(providerConfig, pinned);
|
|
38
43
|
}
|
|
39
44
|
// Re-check the allow-list here, not just in the config validator: the file may have
|
|
40
45
|
// been hand-edited, or written by a build that allowed more values.
|
|
@@ -51,9 +56,9 @@ export function resolveWireProtocolOverride(
|
|
|
51
56
|
// A forward provider hands the caller's own credential upstream; the chat adapter
|
|
52
57
|
// only ever sends provider.apiKey, so switching wires here would drop the auth.
|
|
53
58
|
&& !isCanonicalOpenAiForwardProvider(providerConfig)) {
|
|
54
|
-
return
|
|
59
|
+
return selectWire(providerConfig, requested);
|
|
55
60
|
}
|
|
56
|
-
return providerConfig;
|
|
61
|
+
return selectWire(providerConfig, providerConfig.adapter);
|
|
57
62
|
}
|
|
58
63
|
|
|
59
64
|
/** Build the provider adapter for a resolved provider config. */
|
|
@@ -7,13 +7,17 @@ import { resolveAudioUpstream, TRANSCRIPTION_MODEL, type AudioUpstream } from ".
|
|
|
7
7
|
import type { RequestLogContext } from "./request-log";
|
|
8
8
|
import { authorizationCredential } from "../lib/authorization-scheme";
|
|
9
9
|
|
|
10
|
-
export const DICTATION_SESSION_MAX_MS =
|
|
10
|
+
export const DICTATION_SESSION_MAX_MS = 600_000;
|
|
11
|
+
export const DICTATION_FINALIZATION_MAX_MS = 60_000;
|
|
11
12
|
const DICTATION_FRAME_MAX_BYTES = 64 * 1024;
|
|
12
13
|
type JsonObject = Record<string, unknown>;
|
|
13
14
|
function object(value: unknown): value is JsonObject { return !!value && typeof value === "object" && !Array.isArray(value); }
|
|
14
15
|
function integer(value: unknown, min: number, max: number): boolean {
|
|
15
16
|
return typeof value === "number" && Number.isInteger(value) && value >= min && value <= max;
|
|
16
17
|
}
|
|
18
|
+
function boundedString(value: unknown, max: number): boolean {
|
|
19
|
+
return typeof value === "string" && value.trim().length > 0 && Buffer.byteLength(value) <= max && !/[\u0000-\u001f\u007f]/.test(value);
|
|
20
|
+
}
|
|
17
21
|
|
|
18
22
|
export function createDictationFrameValidator(): (frame: string | Buffer) => boolean {
|
|
19
23
|
let started = false;
|
|
@@ -25,21 +29,29 @@ export function createDictationFrameValidator(): (frame: string | Buffer) => boo
|
|
|
25
29
|
if (!object(event)) return false;
|
|
26
30
|
if (event.type === "session.start" && !started) {
|
|
27
31
|
const config = event.config;
|
|
28
|
-
if (!object(config) || Object.keys(event).some(key =>
|
|
29
|
-
const
|
|
32
|
+
if (!object(config) || Object.keys(event).some(key => !["type", "config", "dictation_session_id", "attempt_id", "client_capabilities"].includes(key))) return false;
|
|
33
|
+
for (const key of ["dictation_session_id", "attempt_id"]) if (key in event && !boundedString(event[key], 128)) return false;
|
|
34
|
+
if ("client_capabilities" in event && (!Array.isArray(event.client_capabilities) || event.client_capabilities.length > 1
|
|
35
|
+
|| event.client_capabilities.some(value => value !== "server_stop_requested"))) return false;
|
|
36
|
+
const fields = new Set(["input_audio_format", "sample_rate_hz", "num_channels", "max_buffer_size_bytes", "max_utterance_duration_ms", "session_ttl_ms", "provider_mode", "transcript_delivery_mode", "session_asset_mode", "language", "vad"]);
|
|
37
|
+
if ("session_asset_mode" in config && config.session_asset_mode !== "none") return false;
|
|
38
|
+
if ("language" in config && !boundedString(config.language, 64)) return false;
|
|
30
39
|
if (Object.keys(config).some(key => !fields.has(key)) || config.input_audio_format !== "pcm16" || config.num_channels !== 1
|
|
31
40
|
|| !integer(config.sample_rate_hz, 8000, 192000) || !integer(config.max_buffer_size_bytes, 1, 4 * 1024 * 1024)
|
|
32
41
|
|| !integer(config.max_utterance_duration_ms, 1, 30000) || !integer(config.session_ttl_ms, 1, DICTATION_SESSION_MAX_MS)
|
|
33
|
-
|| !["buffered", "streaming_sse"].includes(
|
|
34
|
-
|| !["final_only", "segment", "delta"].includes(
|
|
42
|
+
|| typeof config.provider_mode !== "string" || !["buffered", "streaming_sse"].includes(config.provider_mode)
|
|
43
|
+
|| typeof config.transcript_delivery_mode !== "string" || !["final_only", "segment", "delta"].includes(config.transcript_delivery_mode)) return false;
|
|
35
44
|
const vad = config.vad;
|
|
36
45
|
if (!object(vad) || Object.keys(vad).some(key => !["type", "threshold", "prefix_padding_ms", "silence_duration_ms"].includes(key))
|
|
37
|
-
|| vad.type !== "server_vad"
|
|
38
|
-
||
|
|
46
|
+
|| vad.type !== "server_vad"
|
|
47
|
+
|| ("threshold" in vad && (typeof vad.threshold !== "number" || !Number.isFinite(vad.threshold) || vad.threshold < 0 || vad.threshold > 1))
|
|
48
|
+
|| ("prefix_padding_ms" in vad && !integer(vad.prefix_padding_ms, 0, 1000))
|
|
49
|
+
|| ("silence_duration_ms" in vad && !integer(vad.silence_duration_ms, 0, 5000))) return false;
|
|
39
50
|
started = true;
|
|
40
51
|
return true;
|
|
41
52
|
}
|
|
42
53
|
if (!started) return false;
|
|
54
|
+
if (event.type === "audio.flush" && Object.keys(event).length === 1) return true;
|
|
43
55
|
if (event.type === "session.close" && Object.keys(event).length === 1) { closed = true; return true; }
|
|
44
56
|
if (event.type !== "audio.append" || Object.keys(event).some(key => key !== "type" && key !== "audio") || typeof event.audio !== "string" || !event.audio) return false;
|
|
45
57
|
const bytes = Buffer.from(event.audio, "base64");
|
|
@@ -54,6 +66,7 @@ export interface AudioSocketTarget {
|
|
|
54
66
|
protocols?: string[];
|
|
55
67
|
validateFrame?: (frame: string | Buffer) => boolean;
|
|
56
68
|
maxSessionMs: number;
|
|
69
|
+
finalizationMs?: number;
|
|
57
70
|
finish: (outcome?: number | "timeout" | "connect_error") => void;
|
|
58
71
|
}
|
|
59
72
|
|
|
@@ -90,6 +103,7 @@ export async function resolveDictationSocket(
|
|
|
90
103
|
protocols: ["chatgpt-dictation", `openai-bearer.${token}`, "codex-desktop"],
|
|
91
104
|
validateFrame: createDictationFrameValidator(),
|
|
92
105
|
maxSessionMs: DICTATION_SESSION_MAX_MS,
|
|
106
|
+
finalizationMs: DICTATION_FINALIZATION_MAX_MS,
|
|
93
107
|
finish: finishAudioUpstream(relay),
|
|
94
108
|
};
|
|
95
109
|
}
|
package/src/server/auth-cors.ts
CHANGED
|
@@ -29,6 +29,8 @@ import {
|
|
|
29
29
|
providerHeadersConfigError,
|
|
30
30
|
providerForwardClientHeadersConfigError,
|
|
31
31
|
reasoningSummaryDeliveryRecordConfigError,
|
|
32
|
+
thinkingDisplayConfigError,
|
|
33
|
+
modelThinkingDisplayConfigError,
|
|
32
34
|
upstreamHttpVersionConfigError,
|
|
33
35
|
credentialPinnedProviderConfigError,
|
|
34
36
|
} from "../config/provider-validation";
|
|
@@ -949,6 +951,10 @@ export function providerManagementConfigError(
|
|
|
949
951
|
raw.modelSupportsReasoningSummaries,
|
|
950
952
|
);
|
|
951
953
|
if (reasoningSummaryDeliveryError) return `provider ${name} ${reasoningSummaryDeliveryError}`;
|
|
954
|
+
const thinkingDisplayError = thinkingDisplayConfigError(raw.thinkingDisplay);
|
|
955
|
+
if (thinkingDisplayError) return `provider ${name} ${thinkingDisplayError}`;
|
|
956
|
+
const modelThinkingDisplayError = modelThinkingDisplayConfigError(raw.modelThinkingDisplay);
|
|
957
|
+
if (modelThinkingDisplayError) return `provider ${name} ${modelThinkingDisplayError}`;
|
|
952
958
|
const modelAdaptersError = modelAdapterRecordConfigError(raw.modelAdapters, "modelAdapters", name, typed);
|
|
953
959
|
if (modelAdaptersError) return `provider ${name} ${modelAdaptersError}`;
|
|
954
960
|
const credentialPinError = credentialPinnedProviderConfigError(name, typed);
|
|
@@ -1175,6 +1181,8 @@ const PROVIDER_CONFIG_FIELD_POLICY = {
|
|
|
1175
1181
|
modelSupportsVerbosity: "editor",
|
|
1176
1182
|
supportsVerbosity: "editor",
|
|
1177
1183
|
modelReasoningSummaryDelivery: "editor",
|
|
1184
|
+
thinkingDisplay: "editor",
|
|
1185
|
+
modelThinkingDisplay: "editor",
|
|
1178
1186
|
modelPreferHostedTools: "editor",
|
|
1179
1187
|
supportsOpenAiWebSearchToolFields: "editor",
|
|
1180
1188
|
xaiResponsesXSearch: "editor",
|
|
@@ -1191,6 +1199,7 @@ const PROVIDER_CONFIG_FIELD_POLICY = {
|
|
|
1191
1199
|
noTemperatureModels: "editor",
|
|
1192
1200
|
noTopPModels: "editor",
|
|
1193
1201
|
noStopModels: "editor",
|
|
1202
|
+
arkKimiResponsesModels: "editor",
|
|
1194
1203
|
noPenaltyModels: "editor",
|
|
1195
1204
|
noStructuredOutputModels: "editor",
|
|
1196
1205
|
noJsonSchemaModels: "editor",
|
|
@@ -1360,6 +1369,16 @@ export function safeConfigDTO(config: OcxConfig): unknown {
|
|
|
1360
1369
|
hasApiKey: !!provider.apiKey,
|
|
1361
1370
|
hasHeaders: !!provider.headers && Object.keys(provider.headers).length > 0,
|
|
1362
1371
|
};
|
|
1372
|
+
const registry = getProviderRegistryEntry(name);
|
|
1373
|
+
const vertex = (provider.adapter === "google" && effectiveGoogleMode(name, provider) === "vertex")
|
|
1374
|
+
|| (registry?.adapter === "google" && (provider.googleMode ?? registry.googleMode) === "vertex"
|
|
1375
|
+
&& providerMatchesRegistryTransport(name, provider));
|
|
1376
|
+
if (vertex) {
|
|
1377
|
+
const key = provider.apiKey;
|
|
1378
|
+
dto.vertexCredentialKind = key?.startsWith("gcp-sa:") ? "marker"
|
|
1379
|
+
: !key?.trim() || key === "N/A" || key.startsWith("<") ? "ambient"
|
|
1380
|
+
: key.startsWith("keychain:") || /^\$\{?\w+\}?$/.test(key) ? "reference" : "api-key";
|
|
1381
|
+
}
|
|
1363
1382
|
if (name === "xai") {
|
|
1364
1383
|
dto.xaiResponsesOptInState = xaiResponsesOptInState(provider);
|
|
1365
1384
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
1
2
|
import type { OcxConfig, StorageCleanupPolicy } from "../types";
|
|
2
3
|
import { registerCodexLowQuotaProtection, type LowQuotaRegistration } from "../codex/low-quota-protection";
|
|
3
4
|
import { resolveLowQuotaDesktopSink } from "../codex/low-quota-desktop-notifier";
|
|
@@ -33,6 +34,10 @@ import {
|
|
|
33
34
|
type MemoryWatchdog,
|
|
34
35
|
} from "./memory-watchdog";
|
|
35
36
|
import { ensureQuotaPoolIdentity } from "../quota-pool/identity";
|
|
37
|
+
import { isTelemetryEnvOptOut } from "../telemetry/consent";
|
|
38
|
+
// The state module alone: the scheduler and its aggregation stay behind the dynamic import below.
|
|
39
|
+
import { TELEMETRY_ENV_OPT_OUT_REFRESH_MS, endTelemetryEnvOptOut, recordTelemetryEnvOptOut } from "../telemetry/state";
|
|
40
|
+
import { telemetryProfilePath } from "../telemetry/profile/paths";
|
|
36
41
|
|
|
37
42
|
type PolicyApply = (policy: StorageCleanupPolicy) => void;
|
|
38
43
|
|
|
@@ -60,6 +65,22 @@ export type ServerBackgroundLifecycleLease = {
|
|
|
60
65
|
const owners: LeaseOwner[] = [];
|
|
61
66
|
let processLoops: ProcessLoops | null = null;
|
|
62
67
|
let cleanupInProgress = false;
|
|
68
|
+
let telemetryLoopGeneration = 0;
|
|
69
|
+
let stopTelemetryLoop: (() => void) | null = null;
|
|
70
|
+
let stopProfileLoop: (() => void) | null = null;
|
|
71
|
+
// This process started under an env opt-out; its clean stop closes the opt-out period (D2).
|
|
72
|
+
let telemetryEnvOptOutObserved = false;
|
|
73
|
+
let telemetryEnvOptOutRefreshMsOverride: number | null = null;
|
|
74
|
+
let telemetryEnvOptOutRefresh: ReturnType<typeof setInterval> | null = null;
|
|
75
|
+
|
|
76
|
+
export function setTelemetryEnvOptOutRefreshMsForTests(ms: number | null): void {
|
|
77
|
+
telemetryEnvOptOutRefreshMsOverride = ms;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function clearTelemetryEnvOptOutRefresh(): void {
|
|
81
|
+
if (telemetryEnvOptOutRefresh) clearInterval(telemetryEnvOptOutRefresh);
|
|
82
|
+
telemetryEnvOptOutRefresh = null;
|
|
83
|
+
}
|
|
63
84
|
|
|
64
85
|
function setLivePolicyOwner(applyPolicy: PolicyApply | null): void {
|
|
65
86
|
setStorageCleanupPolicyLiveSink(applyPolicy);
|
|
@@ -124,8 +145,46 @@ function startProcessLoops(applyPolicy: PolicyApply): ProcessLoops {
|
|
|
124
145
|
.catch(() => {
|
|
125
146
|
// The next poll tick retries.
|
|
126
147
|
});
|
|
148
|
+
const generation = ++telemetryLoopGeneration;
|
|
149
|
+
if (isTelemetryEnvOptOut(process.env) === null) {
|
|
150
|
+
void import("../telemetry/scheduler")
|
|
151
|
+
.then(scheduler => {
|
|
152
|
+
if (generation !== telemetryLoopGeneration) return;
|
|
153
|
+
stopTelemetryLoop = scheduler.startTelemetryScheduler();
|
|
154
|
+
})
|
|
155
|
+
.catch(() => {
|
|
156
|
+
// Optional background loop.
|
|
157
|
+
});
|
|
158
|
+
} else {
|
|
159
|
+
telemetryEnvOptOutObserved = true;
|
|
160
|
+
// Recorded under this pid, so a proxy sharing the home cannot end the period while this one runs.
|
|
161
|
+
try { recordTelemetryEnvOptOut(undefined, undefined, process.pid); } catch { /* best-effort */ }
|
|
162
|
+
telemetryEnvOptOutRefresh = setInterval(() => {
|
|
163
|
+
try { recordTelemetryEnvOptOut(undefined, undefined, process.pid); } catch { /* best-effort */ }
|
|
164
|
+
}, telemetryEnvOptOutRefreshMsOverride ?? TELEMETRY_ENV_OPT_OUT_REFRESH_MS);
|
|
165
|
+
telemetryEnvOptOutRefresh.unref?.();
|
|
166
|
+
}
|
|
167
|
+
// The opt-in public profile loop runs only when a profile file exists, and independently of
|
|
168
|
+
// the anonymous env gate above: a disconnect that could not reach the collector is retried
|
|
169
|
+
// here even while anonymous telemetry is off. Sending stays gated on anonymous telemetry.
|
|
170
|
+
if (existsSync(telemetryProfilePath())) {
|
|
171
|
+
void import("../telemetry/profile/sync")
|
|
172
|
+
.then(sync => {
|
|
173
|
+
if (generation !== telemetryLoopGeneration) return;
|
|
174
|
+
stopProfileLoop = sync.startProfileScheduler();
|
|
175
|
+
})
|
|
176
|
+
.catch(() => {
|
|
177
|
+
// Optional background loop.
|
|
178
|
+
});
|
|
179
|
+
}
|
|
127
180
|
return { memoryWatchdog, stateStoreSweeper };
|
|
128
181
|
} catch (error) {
|
|
182
|
+
telemetryLoopGeneration += 1;
|
|
183
|
+
stopTelemetryLoop?.();
|
|
184
|
+
stopTelemetryLoop = null;
|
|
185
|
+
stopProfileLoop?.();
|
|
186
|
+
stopProfileLoop = null;
|
|
187
|
+
clearTelemetryEnvOptOutRefresh();
|
|
129
188
|
memoryWatchdog?.stop();
|
|
130
189
|
stateStoreSweeper?.stop();
|
|
131
190
|
stopStorageCleanupScheduler();
|
|
@@ -138,6 +197,18 @@ function startProcessLoops(applyPolicy: PolicyApply): ProcessLoops {
|
|
|
138
197
|
}
|
|
139
198
|
|
|
140
199
|
function stopProcessLoops(): void {
|
|
200
|
+
telemetryLoopGeneration += 1;
|
|
201
|
+
const stopTelemetry = stopTelemetryLoop;
|
|
202
|
+
stopTelemetryLoop = null;
|
|
203
|
+
stopTelemetry?.();
|
|
204
|
+
const stopProfile = stopProfileLoop;
|
|
205
|
+
stopProfileLoop = null;
|
|
206
|
+
stopProfile?.();
|
|
207
|
+
clearTelemetryEnvOptOutRefresh();
|
|
208
|
+
if (telemetryEnvOptOutObserved) {
|
|
209
|
+
telemetryEnvOptOutObserved = false;
|
|
210
|
+
try { endTelemetryEnvOptOut(undefined, undefined, process.pid); } catch { /* best-effort; the next tick ends it once this pid has exited */ }
|
|
211
|
+
}
|
|
141
212
|
const loops = processLoops;
|
|
142
213
|
processLoops = null;
|
|
143
214
|
loops?.memoryWatchdog.stop();
|
|
@@ -22,6 +22,7 @@ import { chatSettingsBody, chatToResponsesBody } from "../protocols/codecs/chat"
|
|
|
22
22
|
import { chatConversationToIr, chatIrRouteEvidence, withDirectChatConversation, type ChatIrConversation } from "../protocols/codecs/chat-ir";
|
|
23
23
|
import { antigravityDirectDeclineReason } from "./antigravity-direct-eligibility";
|
|
24
24
|
import { normalizeChatImageParts } from "../chat/image-parts";
|
|
25
|
+
import { chatHasInstructionImage } from "../adapters/claude-cli/instruction-images";
|
|
25
26
|
import {
|
|
26
27
|
chatCompletionsErrorResponse,
|
|
27
28
|
collectChatCompletion,
|
|
@@ -576,6 +577,7 @@ async function handleChatCompletionsWithBudget(
|
|
|
576
577
|
abortSignal: req.signal,
|
|
577
578
|
// Body is Responses-shaped by now, but the client spoke Chat Completions.
|
|
578
579
|
inboundWire: "chat",
|
|
580
|
+
chatInstructionImage: chatHasInstructionImage(chatBody),
|
|
579
581
|
chatRawReasoningVisible: rawReasoningVisible,
|
|
580
582
|
// A Chat caller may send an explicit empty `tools` array — a deny-all declaration the
|
|
581
583
|
// translation drops along with the whole catalog. Carried separately so the
|
|
@@ -97,6 +97,7 @@ import { clientWireOf } from "./inference/client-wire";
|
|
|
97
97
|
import { directEncodersApply } from "./inference/client-encoder-delivery";
|
|
98
98
|
import type { ClientEncoderOption } from "./responses/core-options";
|
|
99
99
|
import { handleResponses } from "./responses";
|
|
100
|
+
import { resolveComboId } from "../combos";
|
|
100
101
|
import { previewXaiOauthWireModel } from "./responses/core-normalize";
|
|
101
102
|
import { upstreamWireForAdapter } from "../protocols/contract";
|
|
102
103
|
import { createProtocolEnvelope, type ProtocolEnvelope } from "../protocols/envelope";
|
|
@@ -650,6 +651,7 @@ async function handleClaudeMessagesWithBudget(
|
|
|
650
651
|
}
|
|
651
652
|
// Model resolution reads this view; every other claudeCode setting keeps reading `config`.
|
|
652
653
|
const cc = claudeCodeForIngress(config.claudeCode, ingress.claudeIntercept === true);
|
|
654
|
+
let nativeComboSource = false;
|
|
653
655
|
|
|
654
656
|
let anthropicBody: unknown;
|
|
655
657
|
let internalBody: Rec;
|
|
@@ -742,7 +744,12 @@ async function handleClaudeMessagesWithBudget(
|
|
|
742
744
|
// proxy-owned `speed` + beta (anthropic-speed wire) and its usage.speed observation would be
|
|
743
745
|
// silently skipped. Translation reaches the adapter, which owns both.
|
|
744
746
|
const messagesBody = anthropicBody;
|
|
745
|
-
|
|
747
|
+
// An effort override rewrites the body below, so only an unrewritten body is a replay source;
|
|
748
|
+
// the envelope then keeps it by reference and charges no ingress copy.
|
|
749
|
+
nativeComboSource = !effortOverride && isRec(messagesBody) && typeof messagesBody.model === "string"
|
|
750
|
+
&& resolveComboId(config, resolveInboundModel(messagesBody.model, cc)) !== null
|
|
751
|
+
&& Object.keys(config.providers).some(name => resolveProtocolSettings(config, name).rollout.managedMessagesNative);
|
|
752
|
+
if (isRec(messagesBody) && (resolveProtocolSettings(config).unrepresentable === "reject" || nativeComboSource)) {
|
|
746
753
|
envelope = createProtocolEnvelope({ inbound: "messages", body: messagesBody, translatorBudget });
|
|
747
754
|
}
|
|
748
755
|
const sourceEnvelope = envelope;
|
|
@@ -1127,7 +1134,8 @@ async function handleClaudeMessagesWithBudget(
|
|
|
1127
1134
|
});
|
|
1128
1135
|
}
|
|
1129
1136
|
// Combo and policy children are judged per candidate (PF-07); an unknown model has no route.
|
|
1130
|
-
if (envelope &&
|
|
1137
|
+
if (envelope && resolveProtocolSettings(config).unrepresentable === "reject"
|
|
1138
|
+
&& settledRoute && !settledRoute.combo && settledRoute.routeKind !== "policy") {
|
|
1131
1139
|
const verdict = checkRepresentable({
|
|
1132
1140
|
inbound: "messages",
|
|
1133
1141
|
requestPath: requestPathForLane(
|
|
@@ -1147,7 +1155,8 @@ async function handleClaudeMessagesWithBudget(
|
|
|
1147
1155
|
}
|
|
1148
1156
|
// PF-10: opaque thinking state reaches only first-party Anthropic; under `reject` a native
|
|
1149
1157
|
// route to anyone else refuses the request instead of sending it without that state.
|
|
1150
|
-
if (envelope &&
|
|
1158
|
+
if (envelope && resolveProtocolSettings(config).unrepresentable === "reject"
|
|
1159
|
+
&& nativeMessagesRoute && !credentialDomainFor(nativeMessagesRoute.provider)?.firstPartyAnthropic
|
|
1151
1160
|
&& messagesBodyHasOpaqueState(anthropicBody as Rec)) {
|
|
1152
1161
|
markProtocolBlocked(logCtx, { inbound: "messages", reasonCodes: ["feature-unrepresentable", "opaque-state-stripped"], features: messagesFeatures });
|
|
1153
1162
|
logCtx.errorCode = "unsupported_feature";
|
|
@@ -1262,6 +1271,22 @@ async function handleClaudeMessagesWithBudget(
|
|
|
1262
1271
|
// over, and TTL-less breakpoints take the destination default.
|
|
1263
1272
|
cacheRetention: config.cacheRetention ?? callerCacheRetention(anthropicBody),
|
|
1264
1273
|
}, logCtx, {
|
|
1274
|
+
...(nativeComboSource && envelope && settledRoute?.combo ? {
|
|
1275
|
+
protocolSource: (await import("./messages-native")).createNativeMessagesComboSource({
|
|
1276
|
+
req, config, logCtx, envelope, requestedModel, translatorBudget, selector: nativeSelector,
|
|
1277
|
+
echoModel: clientFacingModelText(clientModelLabel),
|
|
1278
|
+
modelScope: resolveAdmissionModelScope(config, logIds?.admission),
|
|
1279
|
+
callerAnthropicBeta: req.headers.get("anthropic-beta"),
|
|
1280
|
+
clientIdentity: captureAnthropicClientIdentity(req.headers),
|
|
1281
|
+
sessionKey: anthropicSessionKeyFromParts({
|
|
1282
|
+
sessionIdHeader: req.headers.get("session_id")?.trim() || req.headers.get("x-claude-code-session-id"),
|
|
1283
|
+
threadIdHeader: req.headers.get("thread_id"),
|
|
1284
|
+
clientThreadId: logCtx.conversationId,
|
|
1285
|
+
promptCacheKey: typeof internalBody.prompt_cache_key === "string" ? internalBody.prompt_cache_key : null,
|
|
1286
|
+
promptCacheKeyIsSharedCohort: cacheKeySource === "system",
|
|
1287
|
+
}),
|
|
1288
|
+
}),
|
|
1289
|
+
} : {}),
|
|
1265
1290
|
// Routing keeps Claude-only sidecar overrides; admission policy must follow the live owner.
|
|
1266
1291
|
codexAuthPolicy: config,
|
|
1267
1292
|
...(logIds?.admission ? { admission: logIds.admission } : {}),
|
|
@@ -1309,6 +1334,8 @@ async function handleClaudeMessagesWithBudget(
|
|
|
1309
1334
|
? { directRequest: messagesDirectRequestOption(directPlan, anthropicBody, cc, translatorBudget) }
|
|
1310
1335
|
: {}),
|
|
1311
1336
|
});
|
|
1337
|
+
// Native combo children report through gated callbacks, not the Responses log inspector.
|
|
1338
|
+
if (clientWireOf(upstream) === "messages" && upstream.ok && settledRoute?.combo) return upstream;
|
|
1312
1339
|
const response = logIds ? responseWithDeferredRequestLog(upstream, logIds.requestId, logIds.start, logCtx) : upstream;
|
|
1313
1340
|
// Already in the Messages wire (direct encoder): no conversion.
|
|
1314
1341
|
if (clientWireOf(upstream) === "messages") return response;
|
|
@@ -306,6 +306,18 @@ export function closeLiveSideband(ws: ServerWebSocket<WsData>, code = 1000, reas
|
|
|
306
306
|
}
|
|
307
307
|
}
|
|
308
308
|
|
|
309
|
+
/** Only dictation opts in: a validated close gets a separate bounded drain window. */
|
|
310
|
+
export function beginAudioFinalization(ws: ServerWebSocket<WsData>, raw: string | Buffer): void {
|
|
311
|
+
if (ws.data.liveFinalizationMs === undefined || ws.data.liveFinalizing || ws.data.liveClosing) return;
|
|
312
|
+
// The frame validator has already accepted this JSON text frame.
|
|
313
|
+
if (typeof raw !== "string" || JSON.parse(raw).type !== "session.close") return;
|
|
314
|
+
ws.data.liveFinalizing = true;
|
|
315
|
+
if (ws.data.liveSessionTimer !== undefined) clearTimeout(ws.data.liveSessionTimer);
|
|
316
|
+
ws.data.liveSessionTimer = setTimeout(() => {
|
|
317
|
+
closeLiveSideband(ws, 1000, "audio finalization expired");
|
|
318
|
+
}, ws.data.liveFinalizationMs);
|
|
319
|
+
}
|
|
320
|
+
|
|
309
321
|
/**
|
|
310
322
|
* Dial the upstream sideband and report whether its handshake reached 101.
|
|
311
323
|
*
|
|
@@ -505,7 +517,9 @@ export function attachLiveSidebandUpstream(
|
|
|
505
517
|
ws.data.liveOutcome = "timeout";
|
|
506
518
|
closeLiveSideband(ws, 1011, "audio connection timed out");
|
|
507
519
|
}, 10_000);
|
|
508
|
-
ws.data.liveSessionTimer = setTimeout(() =>
|
|
520
|
+
ws.data.liveSessionTimer = setTimeout(() => {
|
|
521
|
+
closeLiveSideband(ws, 1000, "audio session expired");
|
|
522
|
+
}, ws.data.liveMaxSessionMs);
|
|
509
523
|
}
|
|
510
524
|
|
|
511
525
|
upstream.addEventListener("close", (event) => {
|