@bitkyc08/opencodex 2.95.0 → 2.96.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/gui/dist/assets/{App-8yedBkhm.js → App-bwugJRKn.js} +18 -18
- package/gui/dist/assets/{Tray-erSMzxPG.js → Tray-BOPQyDbH.js} +1 -1
- package/gui/dist/assets/{index-D7DCm5eQ.js → index-ebuVUtB7.js} +2 -2
- package/gui/dist/assets/{quota-summary-BK4VuQNc.js → quota-summary-6HsrHQAy.js} +1 -1
- package/gui/dist/index.html +1 -1
- package/package.json +1 -1
- package/src/adapters/ollama-native.ts +10 -6
- package/src/adapters/openai-responses/canonical-forward.ts +50 -13
- package/src/adapters/openai-responses/passthrough.ts +3 -4
- package/src/adapters/openai-responses/transport.ts +17 -26
- package/src/adapters/qoder/adapter.ts +1 -1
- package/src/adapters/qoder/image-input.ts +5 -2
- package/src/cli/agent.ts +44 -15
- package/src/cli/capabilities-agents-routing.ts +9 -0
- package/src/cli/ensure-desired-integrations.ts +4 -3
- package/src/cli/index.ts +4 -1
- package/src/cli/message-command.ts +2 -1
- package/src/cli/message-mcp-command.ts +29 -0
- package/src/cli/registry.ts +1 -1
- package/src/codex/account-store.ts +1 -0
- package/src/codex/auth-context-provider.ts +15 -0
- package/src/codex/auth-context.ts +10 -19
- package/src/codex/forward-transport-headers.ts +33 -33
- package/src/codex/installation-id.ts +72 -0
- package/src/generated/compatibility-version.json +83 -47
- package/src/grok/sync.ts +10 -1
- package/src/lib/windows-secret-acl.ts +2 -2
- package/src/messaging/mcp-queue-rpc.ts +102 -0
- package/src/messaging/mcp-queue-server.ts +42 -0
- package/src/messaging/mcp-queue-tools.ts +39 -0
- package/src/oauth/anthropic-identity.ts +2 -6
- package/src/oauth/index.ts +5 -0
- package/src/providers/anthropic-subscription.ts +25 -0
- package/src/providers/claude-cli-usage.ts +15 -67
- package/src/providers/quota/anthropic-decision-windows.ts +5 -19
- package/src/providers/quota/anthropic-usage-windows.ts +55 -0
- package/src/responses/parser-tools.ts +1 -0
- package/src/responses/schema.ts +5 -2
- package/src/server/audio-dictation.ts +3 -0
- package/src/server/audio-live.ts +8 -2
- package/src/server/audio-upstream.ts +2 -0
- package/src/server/claude-messages.ts +6 -3
- package/src/server/context-history.ts +9 -6
- package/src/server/images.ts +14 -5
- package/src/server/index/live-sideband.ts +16 -2
- package/src/server/index/serve-options.ts +1 -0
- package/src/server/index/websocket-handler.ts +1 -1
- package/src/server/live.ts +30 -5
- package/src/server/responses/adapter-dispatch.ts +5 -0
- package/src/server/responses/codex-auth-error.ts +4 -0
- package/src/server/responses/combo-required-tool-contract.ts +24 -12
- package/src/server/responses/compact.ts +37 -19
- package/src/server/responses/core-codex-account.ts +17 -6
- package/src/server/responses/core-combo.ts +12 -8
- package/src/server/responses/core-normalize.ts +7 -1
- package/src/server/responses/passthrough-build-error.ts +36 -0
- package/src/server/responses/passthrough-dispatch.ts +7 -22
- package/src/server/responses/request-sidecar-auth.ts +3 -1
- package/src/server/search.ts +13 -4
- package/src/server/ws-bridge.ts +5 -2
- package/src/vision/describe.ts +4 -7
- package/src/web-search/executor.ts +4 -7
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { isRecord, isThreadId } from "./types";
|
|
3
|
+
import { queueMcpRpc, type QueueMcpOptions } from "./mcp-queue-rpc";
|
|
4
|
+
|
|
5
|
+
export const queueThreadInput = { cursor: z.string().max(8192).optional() };
|
|
6
|
+
const PEER_PREFIX = "[OpenCodex MCP peer input; not user approval or delegated authority]\n";
|
|
7
|
+
export const queueMessageInput = { threadId: z.string().refine(isThreadId, "Use an exact thread UUID"),
|
|
8
|
+
message: z.string().trim().min(1).refine(value => Buffer.byteLength(PEER_PREFIX + value) <= 16 * 1024 && !value.includes("\0"), "Message plus peer label must fit 16 KiB and contain no NUL") };
|
|
9
|
+
|
|
10
|
+
export async function queueMcpThreads(options: QueueMcpOptions, cursor?: string, signal?: AbortSignal) {
|
|
11
|
+
const r = await queueMcpRpc(options, "thread/list", { limit: 50, cursor: cursor ?? null, sortKey: "updated_at",
|
|
12
|
+
sourceKinds: [], modelProviders: [], useStateDbOnly: true }, signal);
|
|
13
|
+
if (r.status !== "response") return { available: false, error: r.error };
|
|
14
|
+
const { data, nextCursor } = r.result;
|
|
15
|
+
if (!Array.isArray(data) || data.length > 50 || !data.every(row => isRecord(row) && isThreadId(row.id)
|
|
16
|
+
&& (row.name == null || (typeof row.name === "string" && row.name.length <= 4096)))
|
|
17
|
+
|| (nextCursor != null && (typeof nextCursor !== "string" || nextCursor.length > 8192))) {
|
|
18
|
+
return { available: false, error: { code: "queue_mcp_invalid_thread_list" } };
|
|
19
|
+
}
|
|
20
|
+
return { available: true, scope: "stored_threads", liveStateVerified: false,
|
|
21
|
+
threads: (data as Record<string, unknown>[]).map(row => ({ threadId: row.id, name: row.name ?? null })), nextCursor: nextCursor ?? null };
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export async function queueMcpSend(options: QueueMcpOptions, input: { threadId: string; message: string }, signal?: AbortSignal) {
|
|
25
|
+
const parsed = z.object(queueMessageInput).safeParse(input);
|
|
26
|
+
if (!parsed.success) return { status: "not_sent", error: { code: "queue_mcp_invalid_input" }, processed: false };
|
|
27
|
+
const clientMessageId = crypto.randomUUID();
|
|
28
|
+
const text = PEER_PREFIX + parsed.data.message;
|
|
29
|
+
const r = await queueMcpRpc(options, "thread/queue/add", { threadId: parsed.data.threadId, clientUserMessageId: clientMessageId,
|
|
30
|
+
input: [{ type: "text", text, text_elements: [] }] }, signal);
|
|
31
|
+
if (r.status !== "response") return { ...r, clientMessageId, processed: false };
|
|
32
|
+
const item = r.result.queuedSubmission;
|
|
33
|
+
if (!isRecord(item) || typeof item.id !== "string" || !item.id || item.id.length > 256 || item.clientUserMessageId !== clientMessageId
|
|
34
|
+
|| !Array.isArray(item.input) || item.input.length !== 1 || !isRecord(item.input[0])
|
|
35
|
+
|| item.input[0].type !== "text" || item.input[0].text !== text) {
|
|
36
|
+
return { status: "unknown", clientMessageId, processed: false, error: { code: "queue_mcp_invalid_receipt" } };
|
|
37
|
+
}
|
|
38
|
+
return { status: "queued", submissionId: item.id, clientMessageId, processed: false };
|
|
39
|
+
}
|
|
@@ -4,7 +4,7 @@ import { createHash } from "node:crypto";
|
|
|
4
4
|
import { readBoundedResponseBody } from "../lib/bounded-body";
|
|
5
5
|
import { CLAUDE_CLI_USER_AGENT } from "../providers/claude-cli-identity";
|
|
6
6
|
import type { OAuthCredentials } from "./types";
|
|
7
|
-
import {
|
|
7
|
+
import { normalizeAnthropicPlan } from "../providers/anthropic-subscription";
|
|
8
8
|
|
|
9
9
|
const PROFILE_URL = "https://api.anthropic.com/api/oauth/profile";
|
|
10
10
|
const PROFILE_TIMEOUT_MS = 10_000;
|
|
@@ -55,11 +55,7 @@ export const resolveAnthropicAccountIdentity: AnthropicIdentityResolver = async
|
|
|
55
55
|
const organization = "organization" in data ? data.organization : undefined;
|
|
56
56
|
const org = organization && typeof organization === "object"
|
|
57
57
|
? organization as Record<string, unknown> : undefined;
|
|
58
|
-
const
|
|
59
|
-
const label = normalizeOAuthPlan(value);
|
|
60
|
-
return label ? normalizeOAuthPlan(label.startsWith(prefix) ? label.slice(prefix.length) : label) : undefined;
|
|
61
|
-
};
|
|
62
|
-
const plan = strip(org?.rate_limit_tier, "default_claude_") ?? strip(org?.organization_type, "claude_");
|
|
58
|
+
const plan = normalizeAnthropicPlan(org?.rate_limit_tier) ?? normalizeAnthropicPlan(org?.organization_type);
|
|
63
59
|
return { ...identity, ...(plan ? { plan } : {}) };
|
|
64
60
|
} catch {
|
|
65
61
|
// Unavailable identity is an explicit unresolved result, never an ownership guess.
|
package/src/oauth/index.ts
CHANGED
|
@@ -97,6 +97,7 @@ import { codexAccountNamespaceProviderCollisionError } from "../codex/account-na
|
|
|
97
97
|
|
|
98
98
|
import { REFRESH_SKEW_MS } from "./refresh-policy";
|
|
99
99
|
import { newerClaudeCredentialForInstance, captureAnthropicCredentialOwnerForInstance } from "./anthropic-continuity";
|
|
100
|
+
import { anthropicSubscriptionLabel } from "../providers/anthropic-subscription";
|
|
100
101
|
import { normalizeOAuthPlan, mergeOAuthPlan } from "./plan";
|
|
101
102
|
import { mergeAnthropicIdentity, type AnthropicIdentityResolver } from "./anthropic-identity";
|
|
102
103
|
import { AnthropicCrossInstanceDuplicateError, AnthropicLocalCliImportError, assertAnthropicCredentialSource } from "./store-anthropic-instance";
|
|
@@ -1819,6 +1820,8 @@ export interface OAuthAccountSummary {
|
|
|
1819
1820
|
* Missing or invalid labels remain null; quota percentages never establish a subscription.
|
|
1820
1821
|
*/
|
|
1821
1822
|
plan: string | null;
|
|
1823
|
+
/** Anthropic display-only subscription name; absent when no tier was observed. */
|
|
1824
|
+
planLabel?: string;
|
|
1822
1825
|
}
|
|
1823
1826
|
|
|
1824
1827
|
/**
|
|
@@ -1846,6 +1849,8 @@ export function getLoginStatus(provider: string, maskEmails = true, flowId?: str
|
|
|
1846
1849
|
expiresAt: a.credential.expires,
|
|
1847
1850
|
// Explicitly null rather than omitted when upstream tier metadata is unknown.
|
|
1848
1851
|
plan: normalizeOAuthPlan(a.credential.plan) ?? null,
|
|
1852
|
+
...((provider === "anthropic" || provider === "anthropic2") && anthropicSubscriptionLabel(a.credential.plan)
|
|
1853
|
+
? { planLabel: anthropicSubscriptionLabel(a.credential.plan) } : {}),
|
|
1849
1854
|
}));
|
|
1850
1855
|
|
|
1851
1856
|
// A stored credential counts as "logged in" when it exists and is not marked for
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/** Display metadata only: subscription names never prove identity, entitlement or capacity. */
|
|
2
|
+
import { normalizeOAuthPlan } from "../oauth/plan";
|
|
3
|
+
|
|
4
|
+
const knownPlans = ["pro", "max_5x", "max_20x", "team", "enterprise", "ultra"] as const;
|
|
5
|
+
|
|
6
|
+
/** Canonicalize known aliases only; retain an unfamiliar validated tier verbatim. */
|
|
7
|
+
export function normalizeAnthropicPlan(value: unknown): string | undefined {
|
|
8
|
+
const raw = normalizeOAuthPlan(value === "Ultra" ? "ultra" : value);
|
|
9
|
+
if (!raw) return undefined;
|
|
10
|
+
const short = raw.replace(/^(?:default_)?claude_/, "");
|
|
11
|
+
return knownPlans.some(plan => plan === short) ? short : raw;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function anthropicSubscriptionLabel(value: unknown): string | undefined {
|
|
15
|
+
const plan = normalizeAnthropicPlan(value);
|
|
16
|
+
switch (plan) {
|
|
17
|
+
case "pro": return "Pro";
|
|
18
|
+
case "max_5x": return "Max 5x";
|
|
19
|
+
case "ultra":
|
|
20
|
+
case "max_20x": return "Ultra";
|
|
21
|
+
case "team": return "Team";
|
|
22
|
+
case "enterprise": return "Enterprise";
|
|
23
|
+
default: return plan;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { markAnthropicFamilyEnumeration } from "./quota/anthropic-family-headers";
|
|
2
2
|
import { rawAnthropicUsageWindows } from "./quota/anthropic-decision-windows";
|
|
3
|
+
import { anthropicUsageBuckets } from "./quota/anthropic-usage-windows";
|
|
3
4
|
import { bindRawDecisionWindows } from "./quota-decision-publication";
|
|
4
5
|
import { decisionQuotaSinkActive } from "../lib/decision-quota-sink";
|
|
5
6
|
import { CLAUDE_CLI_USER_AGENT } from "./claude-cli-identity";
|
|
@@ -8,43 +9,6 @@ import type { ProviderQuota, ProviderQuotaWindow, QuotaFailureCode } from "./quo
|
|
|
8
9
|
import { httpQuotaFailure } from "./quota/failure-codes";
|
|
9
10
|
const hasQuotaRows = (q: ProviderQuota) => q.fiveHourPercent !== undefined || q.weeklyPercent !== undefined || Boolean(q.customWindows?.length);
|
|
10
11
|
|
|
11
|
-
function parseClaudeBucket(value: unknown): { percent?: number; resetAt?: number } | null {
|
|
12
|
-
const rec = asRecord(value);
|
|
13
|
-
if (!rec) return null;
|
|
14
|
-
const percent = normalizePercent(rec.utilization);
|
|
15
|
-
const resetAt = normalizeResetAt(rec.resets_at);
|
|
16
|
-
if (percent === undefined && resetAt === undefined) return null;
|
|
17
|
-
return { percent, resetAt };
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
const TERMINAL_CONTROL_CHARACTERS = /[\u0000-\u001f\u007f-\u009f]/gu;
|
|
21
|
-
|
|
22
|
-
function parseClaudeLimit(value: unknown): ProviderQuotaWindow | null {
|
|
23
|
-
const rec = asRecord(value);
|
|
24
|
-
if (!rec) return null;
|
|
25
|
-
const percent = normalizePercent(rec.percent);
|
|
26
|
-
if (percent === undefined) return null;
|
|
27
|
-
const scope = asRecord(rec.scope);
|
|
28
|
-
const model = asRecord(scope?.model);
|
|
29
|
-
const rawLabel = String(model?.display_name ?? "")
|
|
30
|
-
.replace(TERMINAL_CONTROL_CHARACTERS, "")
|
|
31
|
-
.trim();
|
|
32
|
-
if (!rawLabel) return null;
|
|
33
|
-
const lowerLabel = rawLabel.toLowerCase();
|
|
34
|
-
const label = lowerLabel.includes("fable") ? "Fable"
|
|
35
|
-
: lowerLabel.includes("opus") ? "Opus"
|
|
36
|
-
: lowerLabel.includes("sonnet") ? "Sonnet"
|
|
37
|
-
: null;
|
|
38
|
-
// An unrecognized display_name is never published as a quota label: stripping
|
|
39
|
-
// control characters still leaves attacker-chosen residue on the quota line.
|
|
40
|
-
if (label === null) return null;
|
|
41
|
-
const resetAt = normalizeResetAt(rec.resets_at);
|
|
42
|
-
// Model scope is proven structurally here, not guessed from text: the caller admits only
|
|
43
|
-
// `kind: "weekly_scoped"`, and a limit without a recognized `scope.model.display_name` has
|
|
44
|
-
// already returned null above. Routing keys on `scope`, never on `label`.
|
|
45
|
-
return { label, scope: "model", percent, ...(resetAt !== undefined ? { resetAt } : {}) };
|
|
46
|
-
}
|
|
47
|
-
|
|
48
12
|
/** Read the Anthropic OAuth usage endpoint for an access token and return the parsed quota, or null on a non-OK or malformed response. */
|
|
49
13
|
export async function readAnthropicUsageQuota(accessToken: string): Promise<ProviderQuota | null> {
|
|
50
14
|
return (await probeAnthropicUsageQuota(accessToken)).quota;
|
|
@@ -73,44 +37,28 @@ export async function probeAnthropicUsageQuota(accessToken: string): Promise<Ant
|
|
|
73
37
|
}
|
|
74
38
|
const body = asRecord(await readQuotaJson(response));
|
|
75
39
|
if (!body) return { quota: null, failure: "response_unusable" };
|
|
76
|
-
const
|
|
77
|
-
const
|
|
78
|
-
const fable = parseClaudeBucket(body.seven_day_fable);
|
|
79
|
-
const opus = parseClaudeBucket(body.seven_day_opus);
|
|
80
|
-
const sonnet = parseClaudeBucket(body.seven_day_sonnet);
|
|
40
|
+
const { buckets, familyEnumeration } = anthropicUsageBuckets(body);
|
|
41
|
+
const shared: Partial<ProviderQuota> = {};
|
|
81
42
|
const customWindows: ProviderQuotaWindow[] = [];
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
const limit = parseClaudeLimit(rawLimit);
|
|
93
|
-
if (!limit || knownLabels.has(limit.label.toLowerCase())) continue;
|
|
94
|
-
knownLabels.add(limit.label.toLowerCase());
|
|
95
|
-
customWindows.push(limit);
|
|
43
|
+
for (const { window, row, percentField } of buckets) {
|
|
44
|
+
const percent = normalizePercent(row[percentField]);
|
|
45
|
+
const resetAt = normalizeResetAt(row.resets_at);
|
|
46
|
+
if (window === "5h" || window === "weekly") {
|
|
47
|
+
if (percent !== undefined) shared[window === "5h" ? "fiveHourPercent" : "weeklyPercent"] = percent;
|
|
48
|
+
if (resetAt !== undefined) shared[window === "5h" ? "fiveHourResetAt" : "weeklyResetAt"] = resetAt;
|
|
49
|
+
} else if (percent !== undefined) {
|
|
50
|
+
const label = { fable: "Fable", opus: "Opus", sonnet: "Sonnet" }[window];
|
|
51
|
+
customWindows.push({ label, scope: "model", percent, ...(resetAt !== undefined ? { resetAt } : {}) });
|
|
52
|
+
}
|
|
96
53
|
}
|
|
97
54
|
const quota: ProviderQuota = {
|
|
98
|
-
|
|
99
|
-
// rows: report it in the canonical fields so the dashboard renders it with the standard
|
|
100
|
-
// "5-hour limit" label and ordering instead of as a generic extra window.
|
|
101
|
-
...(fiveHour?.percent !== undefined ? { fiveHourPercent: fiveHour.percent } : {}),
|
|
102
|
-
...(fiveHour?.resetAt !== undefined ? { fiveHourResetAt: fiveHour.resetAt } : {}),
|
|
103
|
-
...(sevenDay?.percent !== undefined ? { weeklyPercent: sevenDay.percent } : {}),
|
|
104
|
-
...(sevenDay?.resetAt !== undefined ? { weeklyResetAt: sevenDay.resetAt } : {}),
|
|
55
|
+
...shared,
|
|
105
56
|
...(customWindows.length > 0 ? { customWindows } : {}),
|
|
106
57
|
updatedAt: Date.now(),
|
|
107
58
|
};
|
|
108
59
|
if (decisionQuotaSinkActive()) bindRawDecisionWindows(quota, rawAnthropicUsageWindows(body, quota.updatedAt));
|
|
109
60
|
// Empty / schema-changed payloads must not cache as "success with no bars".
|
|
110
61
|
if (!hasQuotaRows(quota)) return { quota: null, failure: "response_unusable" };
|
|
111
|
-
return { quota: markAnthropicFamilyEnumeration(quota,
|
|
112
|
-
const kind = asRecord(raw)?.kind;
|
|
113
|
-
return kind === "session" || kind === "weekly_all" || kind === "weekly_scoped" && parseClaudeLimit(raw) !== null;
|
|
114
|
-
})) };
|
|
62
|
+
return { quota: markAnthropicFamilyEnumeration(quota, familyEnumeration) };
|
|
115
63
|
}
|
|
116
64
|
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
/** Raw advisory projection; compatibility display clamping/rounding remains unchanged. */
|
|
2
2
|
import type { DecisionQuotaWindow } from "../quota-decision-snapshot";
|
|
3
3
|
import { normalizeResetAt, toFiniteNumber } from "../quota-wire";
|
|
4
|
-
|
|
5
|
-
const record = (value: unknown): Record<string, unknown> | undefined =>
|
|
6
|
-
value && typeof value === "object" && !Array.isArray(value) ? value as Record<string, unknown> : undefined;
|
|
4
|
+
import { anthropicUsageBuckets } from "./anthropic-usage-windows";
|
|
7
5
|
/** Normalize a reset value; an explicit invalid reset becomes NaN so it cannot read as an undated valid measurement. */
|
|
8
6
|
function reset(value: unknown): number | undefined {
|
|
9
7
|
// Explicit invalid reset must not become an apparently undated valid measurement.
|
|
@@ -12,23 +10,11 @@ function reset(value: unknown): number | undefined {
|
|
|
12
10
|
/** Extract raw decision windows (5h, weekly and per-model families) from an Anthropic usage body, keeping invalid resets distinct from display parsing. */
|
|
13
11
|
export function rawAnthropicUsageWindows(body: Record<string, unknown>, observedAt: number): DecisionQuotaWindow[] {
|
|
14
12
|
const rows: DecisionQuotaWindow[] = [];
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
const
|
|
19
|
-
if (percent === undefined) return;
|
|
20
|
-
const resetAt = reset(row?.resets_at);
|
|
13
|
+
for (const { window, row, percentField } of anthropicUsageBuckets(body).buckets) {
|
|
14
|
+
const percent = toFiniteNumber(row[percentField]);
|
|
15
|
+
if (percent === undefined) continue;
|
|
16
|
+
const resetAt = reset(row.resets_at);
|
|
21
17
|
rows.push({ window, percent, observedAt, ...(resetAt !== undefined ? { resetAt } : {}) });
|
|
22
|
-
};
|
|
23
|
-
for (const [window, field] of [["5h", "five_hour"], ["weekly", "seven_day"], ["fable", "seven_day_fable"], ["opus", "seven_day_opus"], ["sonnet", "seven_day_sonnet"]] as const) add(window, body[field], "utilization");
|
|
24
|
-
for (const limit of Array.isArray(body.limits) ? body.limits : []) {
|
|
25
|
-
const row = record(limit);
|
|
26
|
-
if (row?.kind !== "weekly_scoped") continue;
|
|
27
|
-
const display = record(record(row.scope)?.model)?.display_name;
|
|
28
|
-
if (typeof display !== "string") continue;
|
|
29
|
-
const label = display.replace(/[\u0000-\u001f\u007f-\u009f]/gu, "").toLowerCase();
|
|
30
|
-
const family = (["fable", "opus", "sonnet"] as const).find(family => label.includes(family));
|
|
31
|
-
if (family) add(family, row, "percent");
|
|
32
18
|
}
|
|
33
19
|
return rows;
|
|
34
20
|
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/** One source selection for display and advisory usage; neither projection invents absent limits. */
|
|
2
|
+
import { asRecord, toFiniteNumber } from "../quota-wire";
|
|
3
|
+
|
|
4
|
+
type UsageWindow = "5h" | "weekly" | "fable" | "opus" | "sonnet";
|
|
5
|
+
export interface AnthropicUsageBucket {
|
|
6
|
+
window: UsageWindow;
|
|
7
|
+
row: Record<string, unknown>;
|
|
8
|
+
percentField: "percent" | "utilization";
|
|
9
|
+
}
|
|
10
|
+
const legacyFields = { "5h": "five_hour", weekly: "seven_day", fable: "seven_day_fable",
|
|
11
|
+
opus: "seven_day_opus", sonnet: "seven_day_sonnet" } as const;
|
|
12
|
+
|
|
13
|
+
/** Only these producer-proven model families may constrain routing. Unknown labels stay private. */
|
|
14
|
+
function scopedFamily(row: Record<string, unknown>): "fable" | "opus" | "sonnet" | undefined {
|
|
15
|
+
const display = asRecord(asRecord(row.scope)?.model)?.display_name;
|
|
16
|
+
if (typeof display !== "string") return undefined;
|
|
17
|
+
const label = display.replace(/[\u0000-\u001f\u007f-\u009f]/gu, "").toLowerCase();
|
|
18
|
+
return (["fable", "opus", "sonnet"] as const).find(family => label.includes(family));
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* A limits entry supersedes its legacy duplicate even when inactive or unusable.
|
|
23
|
+
* Missing is_active preserves the older limits contract; an unknown flag is not active.
|
|
24
|
+
* Unknown kinds/families leave usable shared windows intact but cannot clear family refusals.
|
|
25
|
+
*/
|
|
26
|
+
export function anthropicUsageBuckets(body: Record<string, unknown>): {
|
|
27
|
+
buckets: AnthropicUsageBucket[]; familyEnumeration: boolean;
|
|
28
|
+
} {
|
|
29
|
+
const selected = new Map<UsageWindow, AnthropicUsageBucket>();
|
|
30
|
+
const represented = new Set<UsageWindow>();
|
|
31
|
+
const limits = Array.isArray(body.limits) ? body.limits : [];
|
|
32
|
+
let familyEnumeration = Array.isArray(body.limits);
|
|
33
|
+
for (const raw of limits) {
|
|
34
|
+
const row = asRecord(raw);
|
|
35
|
+
const window = row?.kind === "session" ? "5h" : row?.kind === "weekly_all" ? "weekly"
|
|
36
|
+
: row?.kind === "weekly_scoped" ? scopedFamily(row) : undefined;
|
|
37
|
+
if (!row || !window) { familyEnumeration = false; continue; }
|
|
38
|
+
if (represented.has(window)) { familyEnumeration = false; continue; }
|
|
39
|
+
represented.add(window);
|
|
40
|
+
if (row.is_active === false) continue;
|
|
41
|
+
if (row.is_active !== undefined && row.is_active !== true) { familyEnumeration = false; continue; }
|
|
42
|
+
if (toFiniteNumber(row.percent) === undefined) familyEnumeration = false;
|
|
43
|
+
selected.set(window, { window, row, percentField: "percent" });
|
|
44
|
+
}
|
|
45
|
+
for (const window of Object.keys(legacyFields) as UsageWindow[]) {
|
|
46
|
+
if (represented.has(window)) continue;
|
|
47
|
+
const row = asRecord(body[legacyFields[window]]);
|
|
48
|
+
if (row) selected.set(window, { window, row, percentField: "utilization" });
|
|
49
|
+
}
|
|
50
|
+
// Stable canonical order, independent of how upstream orders limits.
|
|
51
|
+
return { buckets: (Object.keys(legacyFields) as UsageWindow[]).flatMap(window => {
|
|
52
|
+
const bucket = selected.get(window);
|
|
53
|
+
return bucket ? [bucket] : [];
|
|
54
|
+
}), familyEnumeration };
|
|
55
|
+
}
|
|
@@ -16,6 +16,7 @@ export function mapToolChoice(value: unknown): OcxRequestOptions["toolChoice"] {
|
|
|
16
16
|
if (t === "image_generation" || t === "image_gen") {
|
|
17
17
|
return { name: IMAGE_GEN_TOOL_NAME };
|
|
18
18
|
}
|
|
19
|
+
if (t === "tool_search") return { name: "tool_search" };
|
|
19
20
|
if (t === "allowed_tools" && Array.isArray(value.tools)) {
|
|
20
21
|
const names = value.tools
|
|
21
22
|
.map(allowedToolName)
|
package/src/responses/schema.ts
CHANGED
|
@@ -162,12 +162,15 @@ const builtinToolSchema = z.object({ type: z.string() }).loose();
|
|
|
162
162
|
*/
|
|
163
163
|
export const HOSTED_TOOL_TYPES = [
|
|
164
164
|
"web_search", "web_search_preview", "file_search", "computer_use_preview",
|
|
165
|
-
"code_interpreter", "image_generation", "mcp",
|
|
165
|
+
"code_interpreter", "image_generation", "mcp", "tool_search", "computer_use", "image_gen",
|
|
166
166
|
] as const;
|
|
167
167
|
|
|
168
168
|
const hostedToolType = z.enum(HOSTED_TOOL_TYPES);
|
|
169
169
|
|
|
170
|
-
const allowedToolEntrySchema = z.
|
|
170
|
+
const allowedToolEntrySchema = z.union([
|
|
171
|
+
z.object({ type: z.literal("mcp"), server_label: z.string().min(1), name: z.string().nullable().optional() }),
|
|
172
|
+
z.object({ type: z.string(), name: z.string().optional() }),
|
|
173
|
+
]);
|
|
171
174
|
|
|
172
175
|
export const toolChoiceSchema = z.union([
|
|
173
176
|
z.literal("auto"),
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { formatErrorResponse } from "../bridge";
|
|
2
|
+
import type { CodexAuthContext } from "../codex/auth-context";
|
|
2
3
|
import type { AdmissionLease } from "../lib/admission";
|
|
3
4
|
import type { OcxConfig } from "../types";
|
|
4
5
|
import type { AudioClient } from "./audio-client";
|
|
@@ -47,6 +48,7 @@ export function createDictationFrameValidator(): (frame: string | Buffer) => boo
|
|
|
47
48
|
}
|
|
48
49
|
|
|
49
50
|
export interface AudioSocketTarget {
|
|
51
|
+
authContext?: CodexAuthContext;
|
|
50
52
|
headers: Record<string, string>;
|
|
51
53
|
upstreamWsUrl: string;
|
|
52
54
|
protocols?: string[];
|
|
@@ -82,6 +84,7 @@ export async function resolveDictationSocket(
|
|
|
82
84
|
}
|
|
83
85
|
headers.delete("authorization");
|
|
84
86
|
return {
|
|
87
|
+
authContext: relay.authContext,
|
|
85
88
|
upstreamWsUrl: "wss://chatgpt.com/backend-api/dictation/stream",
|
|
86
89
|
headers: Object.fromEntries(headers),
|
|
87
90
|
protocols: ["chatgpt-dictation", `openai-bearer.${token}`, "codex-desktop"],
|
package/src/server/audio-live.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { createHash } from "node:crypto";
|
|
2
2
|
import { formatErrorResponse } from "../bridge";
|
|
3
3
|
import { MAIN_CODEX_ACCOUNT_ID } from "../codex/account-id";
|
|
4
|
+
import { isolateCodexPoolClientMetadata } from "../codex/forward-transport-headers";
|
|
5
|
+
import { CodexInstallationIdUnavailableError } from "../codex/installation-id";
|
|
4
6
|
import { cancelBodyOnAbort, clearableDeadline } from "../lib/abort";
|
|
5
7
|
import type { AdmissionLease } from "../lib/admission";
|
|
6
8
|
import { captureExplicitOpenAiCallerAuth } from "../providers/openai-sidecar";
|
|
@@ -73,7 +75,7 @@ export async function handleExternalLive(
|
|
|
73
75
|
if (offer instanceof Response) return offer;
|
|
74
76
|
if (!options.bindings.hasCapacity()) return formatErrorResponse(503, "server_busy", "Live call capacity reached");
|
|
75
77
|
const frameless = new URL(req.url).pathname === "/v1/live";
|
|
76
|
-
|
|
78
|
+
let session = offer.session ? { ...offer.session } : frameless ? {
|
|
77
79
|
model: LIVE_AUDIO_MODEL, instructions: "", audio: { output: { voice: "cove" } }, delegation: { type: "client" },
|
|
78
80
|
} : undefined;
|
|
79
81
|
if (session?.model === "gpt-live-1") session.model = LIVE_AUDIO_MODEL;
|
|
@@ -85,6 +87,8 @@ export async function handleExternalLive(
|
|
|
85
87
|
deadline.signal.throwIfAborted();
|
|
86
88
|
if (resolved instanceof Response) return resolved;
|
|
87
89
|
relay = resolved;
|
|
90
|
+
session = isolateCodexPoolClientMetadata(session, relay.authContext?.kind === "pool"
|
|
91
|
+
? relay.authContext.chatgptAccountId : undefined) as typeof session;
|
|
88
92
|
const headers = protocolHeaders(options.client, relay, frameless);
|
|
89
93
|
let body: BodyInit;
|
|
90
94
|
if (relay.keyed) {
|
|
@@ -129,7 +133,8 @@ export async function handleExternalLive(
|
|
|
129
133
|
"content-type": upstream.headers.get("content-type") ?? "application/sdp",
|
|
130
134
|
location: `/v1/${frameless ? "live" : "realtime/calls"}/${alias}`,
|
|
131
135
|
} });
|
|
132
|
-
} catch {
|
|
136
|
+
} catch (error) {
|
|
137
|
+
if (error instanceof CodexInstallationIdUnavailableError) return formatErrorResponse(503, "server_busy", error.message);
|
|
133
138
|
if (req.signal.aborted || controller.signal.aborted) {
|
|
134
139
|
outcome = undefined;
|
|
135
140
|
return formatErrorResponse(req.signal.aborted ? 499 : 503, "client_closed_request", "Live call canceled");
|
|
@@ -178,6 +183,7 @@ export async function resolveExternalLiveSocket(
|
|
|
178
183
|
return formatErrorResponse(409, "authentication_error", "Live call account is no longer available");
|
|
179
184
|
}
|
|
180
185
|
return {
|
|
186
|
+
authContext: relay.authContext,
|
|
181
187
|
headers: Object.fromEntries(protocolHeaders(client, relay, frameless)),
|
|
182
188
|
upstreamWsUrl: buildLiveSidebandUpstreamWsUrl(upstreamTarget, binding ? binding.sidebandBaseUrl : config.experimentalRealtimeWsBaseUrl),
|
|
183
189
|
maxSessionMs: LIVE_CALL_TTL_MS,
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { CodexInstallationIdUnavailableError } from "../codex/installation-id";
|
|
1
2
|
import { formatErrorResponse } from "../bridge";
|
|
2
3
|
import {
|
|
3
4
|
CodexAccountCooldownError,
|
|
@@ -175,6 +176,7 @@ export async function resolveAudioUpstream(
|
|
|
175
176
|
return formatErrorResponse(400, "invalid_request_error", "Audio requires a connected ChatGPT account or OpenAI API provider");
|
|
176
177
|
} catch (error) {
|
|
177
178
|
releaseCodexAuthContextProbeLease(context);
|
|
179
|
+
if (error instanceof CodexInstallationIdUnavailableError) return formatErrorResponse(503, "server_busy", error.message);
|
|
178
180
|
if (error instanceof CodexAccountCooldownError) return cooldownErrorResponse(error);
|
|
179
181
|
if (error instanceof CodexMainProfileDrainingError) return codexMainProfileDrainingResponse();
|
|
180
182
|
const mainCause = error instanceof CodexAuthContextError && error.accountId === MAIN_CODEX_ACCOUNT_ID ? error.cause : error;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { CodexInstallationIdUnavailableError } from "../codex/installation-id";
|
|
1
2
|
/**
|
|
2
3
|
* Anthropic Messages inbound (/v1/messages + /v1/messages/count_tokens) for Claude Code.
|
|
3
4
|
*
|
|
@@ -1030,13 +1031,15 @@ async function handleClaudeMessagesWithBudget(
|
|
|
1030
1031
|
openAiSidecar?.releaseProbeLease?.();
|
|
1031
1032
|
throw req.signal.reason ?? err;
|
|
1032
1033
|
}
|
|
1033
|
-
if (
|
|
1034
|
+
if (err instanceof CodexInstallationIdUnavailableError) {
|
|
1035
|
+
// An unavailable optional helper cannot displace an independent native route.
|
|
1036
|
+
nativeSelector.webSearchBackendAvailable = false;
|
|
1037
|
+
} else if (!(err instanceof errors.CodexPoolAuthenticationError) && !(err instanceof errors.CodexAuthContextError)
|
|
1034
1038
|
&& !(err instanceof errors.CodexAccountCooldownError) && !(err instanceof errors.CodexThreadAffinityExpiredError)
|
|
1035
1039
|
&& !(err instanceof errors.CodexMainProfileDrainingError)) {
|
|
1036
1040
|
openAiSidecar?.releaseProbeLease?.();
|
|
1037
1041
|
throw err;
|
|
1038
|
-
}
|
|
1039
|
-
if (probeLease && candidates.some(candidate => candidate.accountMode === "pool")) nativeSelector.webSearchBackendAvailable = true;
|
|
1042
|
+
} else if (probeLease && candidates.some(candidate => candidate.accountMode === "pool")) nativeSelector.webSearchBackendAvailable = true;
|
|
1040
1043
|
} finally { probeLease?.release(); }
|
|
1041
1044
|
}
|
|
1042
1045
|
try {
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { isolateCodexPoolClientMetadata, mergeCodexSelectedHeaders } from "../codex/forward-transport-headers";
|
|
2
|
+
import { CodexInstallationIdUnavailableError } from "../codex/installation-id";
|
|
1
3
|
/** Native history/notes JSON relay. No interpretation of encrypted tool arguments or retries. */
|
|
2
4
|
import { formatErrorResponse } from "../bridge";
|
|
3
5
|
import {
|
|
@@ -109,7 +111,8 @@ async function relayContextHistory(
|
|
|
109
111
|
"Context account ownership is unavailable; start a new session and preserve needed state before resetting context");
|
|
110
112
|
}
|
|
111
113
|
let authContext: Awaited<ReturnType<typeof resolveCodexAuthContext>>;
|
|
112
|
-
|
|
114
|
+
let upstreamBody: unknown = body;
|
|
115
|
+
let headers = new Headers(candidate.provider.headers);
|
|
113
116
|
try {
|
|
114
117
|
authContext = await resolveCodexAuthContext(contextSelectionHeaders(req.headers, sessionId), config, owner.kind === "stored" ? "pool" : "direct", {
|
|
115
118
|
// The same deadline bounds credential selection and refresh waits.
|
|
@@ -131,11 +134,10 @@ async function relayContextHistory(
|
|
|
131
134
|
logCtx.provider = formatCodexProviderForLog(candidate.providerName, codexLogAccountId(authContext), config);
|
|
132
135
|
// Materialization rechecks the current account policy after async selection.
|
|
133
136
|
// Synthetic lane IDs are local selection metadata, never upstream headers.
|
|
134
|
-
|
|
137
|
+
headers = mergeCodexSelectedHeaders(candidate.provider.headers, materializeCodexUpstreamAuth(req.headers, authContext, {
|
|
135
138
|
config, modelId: "context_history", admission, substituteMainCredential,
|
|
136
|
-
}))
|
|
137
|
-
|
|
138
|
-
}
|
|
139
|
+
}));
|
|
140
|
+
if (authContext.kind === "pool") upstreamBody = isolateCodexPoolClientMetadata(body, authContext.chatgptAccountId);
|
|
139
141
|
// Check the assembled outbound headers, including configured provider headers.
|
|
140
142
|
validateForwardAdmissionCredential(headers, config);
|
|
141
143
|
// Recheck actual wire identity after async selection/materialization. A replaced
|
|
@@ -148,6 +150,7 @@ async function relayContextHistory(
|
|
|
148
150
|
} catch (err) {
|
|
149
151
|
const cancelled = cancellationResponse(req, deadline);
|
|
150
152
|
if (cancelled) return cancelled;
|
|
153
|
+
if (err instanceof CodexInstallationIdUnavailableError) return formatErrorResponse(503, "server_busy", err.message);
|
|
151
154
|
if (err instanceof CodexAccountCooldownError) return cooldownErrorResponse(err);
|
|
152
155
|
if (err instanceof CodexMainProfileDrainingError) return codexMainProfileDrainingResponse();
|
|
153
156
|
if (err instanceof CodexThreadAffinityExpiredError) return formatErrorResponse(409, "invalid_request_error", "Codex thread account affinity expired; start a new session");
|
|
@@ -176,7 +179,7 @@ async function relayContextHistory(
|
|
|
176
179
|
let response: Response | undefined;
|
|
177
180
|
try {
|
|
178
181
|
response = await fetch(`${candidate.provider.baseUrl}/${endpoint}`, {
|
|
179
|
-
method: "POST", headers, body: JSON.stringify(
|
|
182
|
+
method: "POST", headers, body: JSON.stringify(upstreamBody), signal: deadline.signal, redirect: "manual",
|
|
180
183
|
});
|
|
181
184
|
const result = await readBoundedResponseBytes(response, {maxBytes: MAX_RESPONSE_BYTES, signal: deadline.signal});
|
|
182
185
|
if (result.oversized) return formatErrorResponse(502, "upstream_error", "Context response exceeded 16 MiB");
|
package/src/server/images.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { CodexInstallationIdUnavailableError } from "../codex/installation-id";
|
|
2
|
+
import { isolateCodexPoolClientMetadata, mergeCodexSelectedHeaders } from "../codex/forward-transport-headers";
|
|
1
3
|
/**
|
|
2
4
|
* /v1/images/{generations,edits} relay (issue #83).
|
|
3
5
|
*
|
|
@@ -730,7 +732,9 @@ export async function handleImages(
|
|
|
730
732
|
});
|
|
731
733
|
if (forward) logCtx.provider = formatCodexProviderForLog(forward.providerName, codexLogAccountId(forward.authContext), config);
|
|
732
734
|
} catch (err) {
|
|
733
|
-
if (err instanceof
|
|
735
|
+
if (err instanceof CodexInstallationIdUnavailableError) {
|
|
736
|
+
forwardAuthError = formatErrorResponse(503, "server_busy", err.message);
|
|
737
|
+
} else if (err instanceof CodexAccountCooldownError) {
|
|
734
738
|
forwardAuthError = cooldownErrorResponse(err);
|
|
735
739
|
} else if (err instanceof CodexMainProfileDrainingError) {
|
|
736
740
|
forwardAuthError = codexMainProfileDrainingResponse();
|
|
@@ -752,7 +756,7 @@ export async function handleImages(
|
|
|
752
756
|
}
|
|
753
757
|
}
|
|
754
758
|
|
|
755
|
-
|
|
759
|
+
let headers = new Headers({ "content-type": "application/json" });
|
|
756
760
|
const releaseForwardProbe = (): void => {
|
|
757
761
|
try { forward?.releaseProbeLease?.(); }
|
|
758
762
|
catch { console.error("[images] Failed to release probe lease"); }
|
|
@@ -773,8 +777,7 @@ export async function handleImages(
|
|
|
773
777
|
}
|
|
774
778
|
const { provider } = forward;
|
|
775
779
|
try {
|
|
776
|
-
|
|
777
|
-
for (const [name, value] of forward.headers) headers.set(name, value);
|
|
780
|
+
headers = mergeCodexSelectedHeaders({ "content-type": "application/json", ...provider.headers }, forward.headers);
|
|
778
781
|
assertImagesUpstreamAuthorization(headers, config);
|
|
779
782
|
} catch {
|
|
780
783
|
releaseForwardProbe();
|
|
@@ -866,7 +869,9 @@ export async function handleImages(
|
|
|
866
869
|
upstreamResponse = await fetch(url, {
|
|
867
870
|
method: "POST",
|
|
868
871
|
headers,
|
|
869
|
-
body: JSON.stringify(
|
|
872
|
+
body: JSON.stringify(isolateCodexPoolClientMetadata(
|
|
873
|
+
body, forward?.authContext.kind === "pool" ? forward.authContext.chatgptAccountId : undefined,
|
|
874
|
+
)),
|
|
870
875
|
signal: linkedSignal.signal,
|
|
871
876
|
// Do not follow a cross-origin 3xx while carrying Codex credentials. Bun strips
|
|
872
877
|
// `Authorization` across origins but forwards nonstandard headers, so
|
|
@@ -911,6 +916,10 @@ export async function handleImages(
|
|
|
911
916
|
releaseForwardProbe();
|
|
912
917
|
return formatErrorResponse(499, "client_closed_request", `image ${endpoint} request canceled by client`);
|
|
913
918
|
}
|
|
919
|
+
if (err instanceof CodexInstallationIdUnavailableError) {
|
|
920
|
+
releaseForwardProbe();
|
|
921
|
+
return formatErrorResponse(503, "server_busy", err.message);
|
|
922
|
+
}
|
|
914
923
|
if (linkedSignal.signal.aborted || (err instanceof Error && err.name === "TimeoutError")) {
|
|
915
924
|
forward?.recordOutcome?.("timeout");
|
|
916
925
|
// codex retries 5xx up to 4 more times; a retried 504 is acceptable for a transient hang.
|
|
@@ -19,6 +19,7 @@ import {
|
|
|
19
19
|
resolveLiveSidebandUpgrade,
|
|
20
20
|
} from "../live";
|
|
21
21
|
import { RESPONSE_TTL_MS } from "../../responses/state";
|
|
22
|
+
import { isolateCodexPoolClientMetadata } from "../../codex/forward-transport-headers";
|
|
22
23
|
|
|
23
24
|
export const MAX_WS_FRAME_BYTES = 50 * 1024 * 1024;
|
|
24
25
|
/**
|
|
@@ -124,7 +125,20 @@ function releaseLiveSidebandAdmission(ws: ServerWebSocket<WsData>): void {
|
|
|
124
125
|
* `Uint8Array.from` copies into a fresh `ArrayBuffer`-backed view, so a frame
|
|
125
126
|
* arriving from `node:buffer` still round-trips byte-for-byte.
|
|
126
127
|
*/
|
|
127
|
-
export function sendUpstreamFrame(upstream: WebSocket, frame: string | Buffer): void {
|
|
128
|
+
export function sendUpstreamFrame(upstream: WebSocket, frame: string | Buffer, context?: WsData["authContext"]): void {
|
|
129
|
+
if (context?.kind === "pool") {
|
|
130
|
+
let parsed: unknown;
|
|
131
|
+
try { parsed = JSON.parse(typeof frame === "string" ? frame : new TextDecoder("utf-8", { fatal: true }).decode(frame)); }
|
|
132
|
+
catch { /* Non-JSON frames retain their original bytes. */ }
|
|
133
|
+
const account = context.chatgptAccountId;
|
|
134
|
+
let isolated = isolateCodexPoolClientMetadata(parsed, account);
|
|
135
|
+
if (isolated && typeof isolated === "object" && !Array.isArray(isolated)) {
|
|
136
|
+
const record = isolated as Record<string, unknown>;
|
|
137
|
+
const session = isolateCodexPoolClientMetadata(record.session, account);
|
|
138
|
+
if (session !== record.session) isolated = { ...record, session };
|
|
139
|
+
}
|
|
140
|
+
if (isolated !== parsed) frame = typeof frame === "string" ? JSON.stringify(isolated) : Buffer.from(JSON.stringify(isolated));
|
|
141
|
+
}
|
|
128
142
|
if (typeof frame === "string") {
|
|
129
143
|
upstream.send(frame);
|
|
130
144
|
return;
|
|
@@ -574,7 +588,7 @@ export function attachLiveSidebandUpstream(
|
|
|
574
588
|
ws.data.livePendingBytes = undefined;
|
|
575
589
|
for (const frame of pending) {
|
|
576
590
|
try {
|
|
577
|
-
sendUpstreamFrame(upstream, frame);
|
|
591
|
+
sendUpstreamFrame(upstream, frame, ws.data.authContext);
|
|
578
592
|
} catch {
|
|
579
593
|
closeLiveSideband(ws, 1011, "upstream send failed");
|
|
580
594
|
return;
|
|
@@ -1838,6 +1838,7 @@ export function createServeOptions(ctx: ServeOptionsContext) {
|
|
|
1838
1838
|
...(audioClient?.protocol ? { headers: { "sec-websocket-protocol": audioClient.protocol } } : {}),
|
|
1839
1839
|
data: {
|
|
1840
1840
|
kind: "live-sideband",
|
|
1841
|
+
authContext: resolved.authContext,
|
|
1841
1842
|
liveUpstream: upstreamHandshake.socket,
|
|
1842
1843
|
liveUpstreamUrl: resolved.upstreamWsUrl,
|
|
1843
1844
|
liveUpstreamHeaders: resolved.headers,
|
|
@@ -179,7 +179,7 @@ export function createWebsocketHandler(
|
|
|
179
179
|
return;
|
|
180
180
|
}
|
|
181
181
|
try {
|
|
182
|
-
sendUpstreamFrame(upstream, raw);
|
|
182
|
+
sendUpstreamFrame(upstream, raw, ws.data.authContext);
|
|
183
183
|
if (ws.data.liveMaxSessionMs !== undefined && upstream.bufferedAmount > MAX_WS_FRAME_BYTES) {
|
|
184
184
|
closeLiveSideband(ws, 1013, "audio upstream backpressure");
|
|
185
185
|
}
|