@archboard/codex-realtime-voice 0.5.0 → 0.6.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/README.md +32 -41
- package/dist/browser.d.mts +1 -3
- package/dist/browser.mjs +67 -66
- package/dist/{contract-CDS04znV.d.mts → contract-B2ILifH5.d.mts} +3 -3
- package/dist/{contract-qg6q9-vH.d.mts → contract-CkitFygd.d.mts} +97 -3054
- package/dist/{contract-DkiXnfc8.d.mts → contract-D9_WuSxD.d.mts} +3 -3
- package/dist/contract.d.mts +1 -1
- package/dist/controllers.d.mts +221 -6
- package/dist/controllers.mjs +3 -3
- package/dist/{gateway-envelope-DRBUhFx9.d.mts → gateway-envelope-O67wCRD7.d.mts} +3 -2
- package/dist/{realtime-state-CTBmCjt1.mjs → gateway-envelope-jUP82Pq1.mjs} +71 -3
- package/dist/identity-capabilities-3Q_2tJiT.d.mts +147 -0
- package/dist/instructions-B-6HVmoD.mjs +1024 -0
- package/dist/{contract-JI3xv17m.d.mts → instructions-C6TkBWcp.d.mts} +14 -998
- package/dist/{model-DnitkA24.mjs → model-MSyAviwx.mjs} +1652 -85
- package/dist/react.d.mts +1 -1
- package/dist/{realtime-contract-wHmSyUIe.d.mts → realtime-contract-C-1bMn-F.d.mts} +1 -22
- package/dist/realtime.d.mts +2 -3
- package/dist/realtime.mjs +1 -3
- package/dist/runtime.d.mts +3 -18
- package/dist/runtime.mjs +2 -2
- package/dist/schemas.d.mts +3 -13
- package/dist/schemas.mjs +1 -1
- package/dist/server.d.mts +977 -217
- package/dist/server.mjs +17771 -10076
- package/dist/{snapshot-BCrCORmt.d.mts → snapshot-DCl2vsJl.d.mts} +9 -154
- package/dist/{transport-Bqb8KE5T.mjs → transport-DVUz3EK0.mjs} +17 -13
- package/package.json +1 -1
- package/dist/app-server-contract-D4E5bibD.mjs +0 -177
- package/dist/gateway-envelope-DXTRMB3q.mjs +0 -45
- package/dist/instructions-8ACs49yJ.mjs +0 -8980
- package/dist/media-state-CNkFo93s.d.mts +0 -215
- package/dist/realtime-contract-DwkCluo2.mjs +0 -1167
- package/dist/realtime-state-DT4uvrIV.d.mts +0 -16
|
@@ -1,151 +1,14 @@
|
|
|
1
|
+
import { _ as RealtimeSessionId, c as BrowserCommandId, d as DynamicToolCallId, f as ItemId, g as QueuedSubmissionId, h as OperationId, l as ChildEpoch, m as LoginId, n as IdentityAuthority, o as AnyIdentity, p as JsonRpcRequestId, r as OperationAuthority, s as ApprovalId, u as ChildId, v as ThreadId, y as TurnId } from "./identity-capabilities-3Q_2tJiT.mjs";
|
|
1
2
|
import { z } from "zod";
|
|
2
|
-
declare const
|
|
3
|
-
type
|
|
4
|
-
type BrandedIdentity<Domain extends IdentityDomain> = string & {
|
|
5
|
-
readonly [identityBrand]: Domain;
|
|
6
|
-
};
|
|
7
|
-
type JsonRpcRequestIdWireValue = string | number;
|
|
8
|
-
type ChildId = BrandedIdentity<"child">;
|
|
9
|
-
type ChildEpoch = BrandedIdentity<"epoch">;
|
|
10
|
-
type BrowserCommandId = BrandedIdentity<"browser-command">;
|
|
11
|
-
type ThreadId = BrandedIdentity<"thread">;
|
|
12
|
-
type TurnId = BrandedIdentity<"turn">;
|
|
13
|
-
type ItemId = BrandedIdentity<"item">;
|
|
14
|
-
type QueuedSubmissionId = BrandedIdentity<"queued-submission">;
|
|
15
|
-
type LoginId = BrandedIdentity<"login">;
|
|
16
|
-
type JsonRpcRequestId = BrandedIdentity<"json-rpc-request">;
|
|
17
|
-
type DynamicToolCallId = BrandedIdentity<"dynamic-tool-call">;
|
|
18
|
-
type RealtimeSessionId = BrandedIdentity<"realtime-session">;
|
|
19
|
-
type ApprovalId = BrandedIdentity<"approval">;
|
|
20
|
-
/** A server-issued workbench mutation correlation, bound to one child epoch. */
|
|
21
|
-
type OperationId = BrandedIdentity<"operation">;
|
|
22
|
-
type AnyIdentity = ChildId | ChildEpoch | BrowserCommandId | ThreadId | TurnId | ItemId | QueuedSubmissionId | LoginId | JsonRpcRequestId | DynamicToolCallId | RealtimeSessionId | ApprovalId | OperationId;
|
|
23
|
-
/** Identities that may appear in Codex requests or reverse requests. */
|
|
24
|
-
type CodexIdentity = ThreadId | TurnId | ItemId | QueuedSubmissionId | LoginId | JsonRpcRequestId | DynamicToolCallId | ApprovalId;
|
|
25
|
-
interface WireRequestCorrelation {
|
|
26
|
-
readonly child: ChildId;
|
|
27
|
-
readonly epoch: ChildEpoch;
|
|
28
|
-
readonly requestId: JsonRpcRequestId;
|
|
29
|
-
}
|
|
30
|
-
interface LogicalToolCallCorrelation {
|
|
31
|
-
readonly child: ChildId;
|
|
32
|
-
readonly epoch: ChildEpoch;
|
|
33
|
-
readonly threadId: ThreadId;
|
|
34
|
-
readonly turnId: TurnId;
|
|
35
|
-
readonly callId: DynamicToolCallId;
|
|
36
|
-
readonly namespace: string;
|
|
37
|
-
readonly tool: string;
|
|
38
|
-
readonly manifestHash: string;
|
|
39
|
-
}
|
|
40
|
-
interface WireRequestCorrelationInput {
|
|
41
|
-
readonly requestId: JsonRpcRequestId;
|
|
42
|
-
}
|
|
43
|
-
interface LogicalToolCallCorrelationInput {
|
|
44
|
-
readonly threadId: ThreadId;
|
|
45
|
-
readonly turnId: TurnId;
|
|
46
|
-
readonly callId: DynamicToolCallId;
|
|
47
|
-
readonly namespace: string;
|
|
48
|
-
readonly tool: string;
|
|
49
|
-
readonly manifestHash: string;
|
|
50
|
-
}
|
|
51
|
-
/** Raw server identities collected from one decoded app-server response. */
|
|
52
|
-
interface CodexResponseIdentityBatch {
|
|
53
|
-
readonly threadIds?: readonly unknown[];
|
|
54
|
-
readonly turnIds?: readonly unknown[];
|
|
55
|
-
readonly itemIds?: readonly unknown[];
|
|
56
|
-
readonly queuedSubmissionIds?: readonly unknown[];
|
|
57
|
-
readonly loginIds?: readonly unknown[];
|
|
58
|
-
}
|
|
59
|
-
/** Branded identities returned in the same order as one response batch. */
|
|
60
|
-
interface AdoptedCodexResponseIdentityBatch {
|
|
61
|
-
readonly threadIds: readonly ThreadId[];
|
|
62
|
-
readonly turnIds: readonly TurnId[];
|
|
63
|
-
readonly itemIds: readonly ItemId[];
|
|
64
|
-
readonly queuedSubmissionIds: readonly QueuedSubmissionId[];
|
|
65
|
-
readonly loginIds: readonly LoginId[];
|
|
66
|
-
}
|
|
67
|
-
interface IdentityValidator {
|
|
68
|
-
readonly childId: ChildId;
|
|
69
|
-
readonly epoch: ChildEpoch;
|
|
70
|
-
readonly isCurrentEpoch: (child: ChildId, epoch: ChildEpoch) => boolean;
|
|
71
|
-
readonly assertCurrentEpoch: (child: ChildId, epoch: ChildEpoch) => void;
|
|
72
|
-
}
|
|
73
|
-
/** The only capability ordinary mutation owners need to validate an OperationId. */
|
|
74
|
-
interface OperationIdValidator {
|
|
75
|
-
readonly isCurrentOperationId: (operationId: OperationId) => boolean;
|
|
76
|
-
readonly assertCurrentOperationId: (operationId: OperationId) => void;
|
|
77
|
-
}
|
|
78
|
-
/** Server-owned IDs are minted here; app-server-owned IDs can only enter via the trusted decoder. */
|
|
79
|
-
interface IdentityIssuer {
|
|
80
|
-
readonly mintBrowserCommandId: () => BrowserCommandId;
|
|
81
|
-
readonly mintJsonRpcRequestId: () => JsonRpcRequestId;
|
|
82
|
-
readonly mintRealtimeSessionId: () => RealtimeSessionId;
|
|
83
|
-
readonly mintChildEpoch: () => ChildEpoch;
|
|
84
|
-
}
|
|
85
|
-
/** The only capability that can issue a server-owned OperationId. */
|
|
86
|
-
interface OperationIdIssuer {
|
|
87
|
-
readonly mintOperationId: () => OperationId;
|
|
88
|
-
}
|
|
3
|
+
declare const JsonValueSchema: z.ZodJSONSchema;
|
|
4
|
+
type JsonValue = z.infer<typeof JsonValueSchema>;
|
|
89
5
|
/**
|
|
90
|
-
*
|
|
91
|
-
*
|
|
6
|
+
* Narrows an untrusted value to JSON.
|
|
7
|
+
* @param value - Any value.
|
|
8
|
+
* @returns The value, known to be JSON.
|
|
9
|
+
* @throws {ZodError} when the value holds anything JSON cannot carry.
|
|
92
10
|
*/
|
|
93
|
-
|
|
94
|
-
readonly parseChildId: (value: unknown) => ChildId;
|
|
95
|
-
readonly parseChildEpoch: (value: unknown) => ChildEpoch;
|
|
96
|
-
readonly parseBrowserCommandId: (value: unknown) => BrowserCommandId;
|
|
97
|
-
readonly parseThreadId: (value: unknown) => ThreadId;
|
|
98
|
-
readonly parseTurnId: (value: unknown) => TurnId;
|
|
99
|
-
readonly parseItemId: (value: unknown) => ItemId;
|
|
100
|
-
readonly parseQueuedSubmissionId: (value: unknown) => QueuedSubmissionId;
|
|
101
|
-
readonly parseLoginId: (value: unknown) => LoginId;
|
|
102
|
-
readonly parseJsonRpcRequestId: (value: unknown) => JsonRpcRequestId;
|
|
103
|
-
readonly parseDynamicToolCallId: (value: unknown) => DynamicToolCallId;
|
|
104
|
-
readonly parseRealtimeSessionId: (value: unknown) => RealtimeSessionId;
|
|
105
|
-
readonly parseApprovalId: (value: unknown) => ApprovalId;
|
|
106
|
-
/** Resolves a raw Codex thread id only when this authority already issued it. */
|
|
107
|
-
readonly resolveThreadId: (raw: unknown) => ThreadId;
|
|
108
|
-
/** Resolves a raw Codex item id only when this authority already issued it. */
|
|
109
|
-
readonly resolveItemId: (raw: unknown) => ItemId;
|
|
110
|
-
readonly adoptThreadId: (raw: unknown) => ThreadId;
|
|
111
|
-
readonly adoptTurnId: (raw: unknown) => TurnId;
|
|
112
|
-
readonly adoptItemId: (raw: unknown) => ItemId;
|
|
113
|
-
readonly adoptQueuedSubmissionId: (raw: unknown) => QueuedSubmissionId;
|
|
114
|
-
readonly adoptLoginId: (raw: unknown) => LoginId;
|
|
115
|
-
readonly adoptJsonRpcRequestId: (raw: unknown) => JsonRpcRequestId;
|
|
116
|
-
readonly adoptDynamicToolCallId: (raw: unknown) => DynamicToolCallId;
|
|
117
|
-
readonly adoptApprovalId: (raw: unknown) => ApprovalId;
|
|
118
|
-
/** Validates a complete decoded response before adopting any identity from it. */
|
|
119
|
-
readonly adoptCodexResponseIdentities: (batch: CodexResponseIdentityBatch) => AdoptedCodexResponseIdentityBatch;
|
|
120
|
-
readonly serializeCodexIdentity: (identity: CodexIdentity) => string;
|
|
121
|
-
readonly serializeJsonRpcRequestId: (identity: JsonRpcRequestId) => JsonRpcRequestIdWireValue;
|
|
122
|
-
readonly createWireRequestCorrelation: (input: WireRequestCorrelationInput) => WireRequestCorrelation;
|
|
123
|
-
readonly parseWireRequestCorrelation: (value: unknown) => WireRequestCorrelation;
|
|
124
|
-
readonly createLogicalToolCallCorrelation: (input: LogicalToolCallCorrelationInput) => LogicalToolCallCorrelation;
|
|
125
|
-
readonly parseLogicalToolCallCorrelation: (value: unknown) => LogicalToolCallCorrelation;
|
|
126
|
-
}
|
|
127
|
-
/** Trusted protocol code may parse and serialize, but never adopt, OperationIds. */
|
|
128
|
-
interface TrustedOperationIdDecoder {
|
|
129
|
-
readonly parseOperationId: (value: unknown) => OperationId;
|
|
130
|
-
readonly serializeOperationId: (identity: OperationId) => string;
|
|
131
|
-
}
|
|
132
|
-
/** The complete operation capability is composed only at the authority boundary. */
|
|
133
|
-
interface OperationAuthority {
|
|
134
|
-
readonly validator: OperationIdValidator;
|
|
135
|
-
readonly issuer: OperationIdIssuer;
|
|
136
|
-
readonly decoder: TrustedOperationIdDecoder;
|
|
137
|
-
}
|
|
138
|
-
interface IdentityAuthority {
|
|
139
|
-
readonly validator: IdentityValidator;
|
|
140
|
-
readonly issuer: IdentityIssuer;
|
|
141
|
-
readonly decoder: TrustedIdentityDecoder;
|
|
142
|
-
}
|
|
143
|
-
/** The factory return type composes legacy identity capabilities with operation capabilities. */
|
|
144
|
-
interface IdentityAuthorities {
|
|
145
|
-
readonly identity: IdentityAuthority;
|
|
146
|
-
readonly operation: OperationAuthority;
|
|
147
|
-
}
|
|
148
|
-
declare const JsonValueSchema: z.ZodJSONSchema;
|
|
11
|
+
declare function parseJsonValue(value: unknown): JsonValue;
|
|
149
12
|
/**
|
|
150
13
|
* A non-empty string bounded in both characters and UTF-8 bytes, without NUL,
|
|
151
14
|
* so a browser payload can never exceed what its wire budget assumed.
|
|
@@ -1522,7 +1385,6 @@ declare const DeliveryOutcomeSchema: z.ZodEnum<{
|
|
|
1522
1385
|
not_delivered: "not_delivered";
|
|
1523
1386
|
outcome_unknown: "outcome_unknown";
|
|
1524
1387
|
}>;
|
|
1525
|
-
declare const BROWSER_VOICE_CONTEXT_BRIEF_MAX_UTF8_BYTES = 8192;
|
|
1526
1388
|
/**
|
|
1527
1389
|
* Builds every browser DTO schema bound to one identity authority, plus the
|
|
1528
1390
|
* snapshot that composes them and the union the transport accepts.
|
|
@@ -8573,20 +8435,13 @@ declare function createBrowserSchemas(identity: IdentitySchemas, context: Identi
|
|
|
8573
8435
|
};
|
|
8574
8436
|
type BrowserSchemas = ReturnType<typeof createBrowserSchemas>;
|
|
8575
8437
|
type BrowserReadiness = z.infer<BrowserSchemas["BrowserReadinessSchema"]>;
|
|
8576
|
-
type BrowserAccount = z.infer<BrowserSchemas["BrowserAccountSchema"]>;
|
|
8577
|
-
type BrowserLogin = z.infer<BrowserSchemas["BrowserLoginSchema"]>;
|
|
8578
8438
|
type BrowserThreadLink = z.infer<BrowserSchemas["BrowserThreadLinkSchema"]>;
|
|
8579
8439
|
type BrowserTimeline = z.infer<BrowserSchemas["BrowserTimelineSchema"]>;
|
|
8580
8440
|
type BrowserQueue = z.infer<BrowserSchemas["BrowserQueueSchema"]>;
|
|
8581
|
-
type BrowserSettings = z.infer<BrowserSchemas["BrowserSettingsSchema"]>;
|
|
8582
8441
|
type BrowserWorkhorses = z.infer<BrowserSchemas["BrowserWorkhorsesSchema"]>;
|
|
8583
8442
|
type BrowserApproval = z.infer<BrowserSchemas["BrowserApprovalSchema"]>;
|
|
8584
|
-
type BrowserContextDelivery = z.infer<BrowserSchemas["BrowserContextDeliverySchema"]>;
|
|
8585
|
-
type BrowserCoordinator = z.infer<BrowserSchemas["BrowserCoordinatorSchema"]>;
|
|
8586
8443
|
type BrowserSpokenApproval = z.infer<BrowserSchemas["BrowserSpokenApprovalSchema"]>;
|
|
8587
|
-
type BrowserVoiceContext = z.infer<BrowserSchemas["BrowserVoiceContextSchema"]>;
|
|
8588
8444
|
type BrowserCommandLease = z.infer<BrowserSchemas["BrowserCommandLeaseSchema"]>;
|
|
8589
|
-
type BrowserOperationOutcome = z.infer<BrowserSchemas["BrowserOperationOutcomeSchema"]>;
|
|
8590
8445
|
type BrowserCommand = z.infer<BrowserSchemas["BrowserCommandSchema"]>;
|
|
8591
8446
|
/** The narrative a voice session starts to present: host-defined JSON. */
|
|
8592
8447
|
type VoiceNarrative = NonNullable<Extract<BrowserCommand, {
|
|
@@ -8594,4 +8449,4 @@ type VoiceNarrative = NonNullable<Extract<BrowserCommand, {
|
|
|
8594
8449
|
}>["narrative"]>;
|
|
8595
8450
|
type BrowserSnapshot = z.infer<BrowserSchemas["BrowserSnapshotSchema"]>;
|
|
8596
8451
|
type DeliveryOutcome = z.infer<typeof DeliveryOutcomeSchema>;
|
|
8597
|
-
export {
|
|
8452
|
+
export { parseJsonValue as C, boundedText as S, DynamicApprovalCanonicalEffect as _, BrowserReadiness as a, DYNAMIC_APPROVAL_DECISIONS as b, BrowserSpokenApproval as c, BrowserWorkhorses as d, DeliveryOutcome as f, BrowserDynamicApprovalResponse as g, BrowserDynamicApprovalEffect as h, BrowserQueue as i, BrowserThreadLink as l, BrowserDynamicApproval as m, BrowserCommand as n, BrowserSchemas as o, VoiceNarrative as p, BrowserCommandLease as r, BrowserSnapshot as s, BrowserApproval as t, BrowserTimeline as u, canonicalDynamicApprovalJson as v, IdentityContext as x, dynamicApprovalHashForCanonicalJson as y };
|
|
@@ -1,12 +1,18 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { r as
|
|
3
|
-
import { a as transitionRealtimeState, t as INITIAL_REALTIME_STATE } from "./realtime-state-CTBmCjt1.mjs";
|
|
4
|
-
import { t as BROWSER_GATEWAY_ERROR_CODES } from "./gateway-envelope-DXTRMB3q.mjs";
|
|
1
|
+
import { S as JsonValueSchema, f as parseRealtimeSessionId, n as browserSnapshotRelationshipIssues, o as expiresAt, s as ms, t as createCodexBrowserModel, u as parseRealtimeCorrelationId, x as DeliveryOutcomeSchema } from "./model-MSyAviwx.mjs";
|
|
2
|
+
import { a as transitionRealtimeState, o as after, r as INITIAL_REALTIME_STATE, t as BROWSER_GATEWAY_ERROR_CODES } from "./gateway-envelope-jUP82Pq1.mjs";
|
|
5
3
|
import { z } from "zod";
|
|
6
4
|
// src/ui/output-level/clients/level-source.ts
|
|
7
5
|
/** The RMS level at or above which the model counts as speaking. */
|
|
8
6
|
const VOICE_OUTPUT_SPEAKING_LEVEL = .02;
|
|
9
7
|
/**
|
|
8
|
+
* Whether a published level counts as the model speaking.
|
|
9
|
+
* @param level The RMS level, 0..1.
|
|
10
|
+
* @returns True at or above the speaking level.
|
|
11
|
+
*/
|
|
12
|
+
function isSpeakingLevel(level) {
|
|
13
|
+
return level >= VOICE_OUTPUT_SPEAKING_LEVEL;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
10
16
|
* The browser's own animation frames.
|
|
11
17
|
* @returns A scheduler over requestAnimationFrame.
|
|
12
18
|
*/
|
|
@@ -868,7 +874,7 @@ async function openMicrophone(run, devices) {
|
|
|
868
874
|
*/
|
|
869
875
|
async function adoptMicrophone(controller, run, stream) {
|
|
870
876
|
run.localStream = stream;
|
|
871
|
-
run.startDeadline = controller.environment.now()
|
|
877
|
+
run.startDeadline = expiresAt("codex.realtimeStart", controller.environment.now());
|
|
872
878
|
const localTrack = stream.getAudioTracks()[0];
|
|
873
879
|
if (controller.inactive(run)) return controller.settleCancelled(run);
|
|
874
880
|
if (localTrack === void 0) {
|
|
@@ -1447,7 +1453,7 @@ function createRealtimeMediaSession(server, options = {}) {
|
|
|
1447
1453
|
*/
|
|
1448
1454
|
const stopServer = (run) => {
|
|
1449
1455
|
if (!run.offerSent) return Promise.resolve(true);
|
|
1450
|
-
run.serverStop ??= bounded(run, environment, () => server.stop(run.correlation).then((outcome) => stopConfirmed(run, outcome), () => false),
|
|
1456
|
+
run.serverStop ??= bounded(run, environment, () => server.stop(run.correlation).then((outcome) => stopConfirmed(run, outcome), () => false), ms("codex.realtimeStop"), false).then((result) => result === true);
|
|
1451
1457
|
return run.serverStop;
|
|
1452
1458
|
};
|
|
1453
1459
|
/**
|
|
@@ -3640,10 +3646,8 @@ function deferred() {
|
|
|
3640
3646
|
* @param pending The request.
|
|
3641
3647
|
*/
|
|
3642
3648
|
function clearPendingTimer(pending) {
|
|
3643
|
-
|
|
3644
|
-
|
|
3645
|
-
pending.timer = null;
|
|
3646
|
-
}
|
|
3649
|
+
pending.timer?.();
|
|
3650
|
+
pending.timer = null;
|
|
3647
3651
|
}
|
|
3648
3652
|
/**
|
|
3649
3653
|
* Reject every pending request of a run with one reason.
|
|
@@ -3703,7 +3707,7 @@ function sendRequest(run, ports, spec) {
|
|
|
3703
3707
|
timer: null
|
|
3704
3708
|
};
|
|
3705
3709
|
run.pending.set(requestId, pending);
|
|
3706
|
-
pending.timer =
|
|
3710
|
+
pending.timer = after("codex.requestSettlement", () => expirePending(run, requestId, pending));
|
|
3707
3711
|
try {
|
|
3708
3712
|
run.socket.send(JSON.stringify(request));
|
|
3709
3713
|
} catch (error) {
|
|
@@ -4002,7 +4006,7 @@ function setBackoff(core, run, reason) {
|
|
|
4002
4006
|
connection: "reconnecting",
|
|
4003
4007
|
snapshot: run.snapshot,
|
|
4004
4008
|
sequence: run.sequence,
|
|
4005
|
-
retryAtMs: core.now()
|
|
4009
|
+
retryAtMs: expiresAt("codex.clientReconnect", core.now()),
|
|
4006
4010
|
reason
|
|
4007
4011
|
});
|
|
4008
4012
|
}
|
|
@@ -5165,4 +5169,4 @@ function createBrowserWorkbenchTransport(transportOptions = {}) {
|
|
|
5165
5169
|
dispose: disposeTransport
|
|
5166
5170
|
});
|
|
5167
5171
|
}
|
|
5168
|
-
export {
|
|
5172
|
+
export { isSpeakingLevel as a, browserAudioElements as i, BrowserWorkbenchTransportError as n, createBrowserWorkbenchMediaOwner as r, createBrowserWorkbenchTransport as t };
|
package/package.json
CHANGED
|
@@ -1,177 +0,0 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
2
|
-
// ../codex-app-server/src/shared/protocol/app-server-contract.ts
|
|
3
|
-
/** JSON representation of one generated ts-rs bigint/i64 field. */
|
|
4
|
-
const CodexSafeI64Schema = z.number().int().safe().brand();
|
|
5
|
-
/** Client requests this client implements, checked against the generated request union. */
|
|
6
|
-
const CODEX_CLIENT_REQUEST_METHODS = [
|
|
7
|
-
"initialize",
|
|
8
|
-
"config/read",
|
|
9
|
-
"configRequirements/read",
|
|
10
|
-
"account/read",
|
|
11
|
-
"account/login/start",
|
|
12
|
-
"account/login/cancel",
|
|
13
|
-
"account/logout",
|
|
14
|
-
"model/list",
|
|
15
|
-
"thread/start",
|
|
16
|
-
"thread/fork",
|
|
17
|
-
"thread/list",
|
|
18
|
-
"thread/loaded/list",
|
|
19
|
-
"thread/read",
|
|
20
|
-
"thread/turns/list",
|
|
21
|
-
"thread/items/list",
|
|
22
|
-
"thread/delete",
|
|
23
|
-
"thread/unsubscribe",
|
|
24
|
-
"thread/settings/update",
|
|
25
|
-
"turn/start",
|
|
26
|
-
"turn/steer",
|
|
27
|
-
"turn/interrupt",
|
|
28
|
-
"thread/queue/add",
|
|
29
|
-
"thread/queue/list",
|
|
30
|
-
"thread/queue/update",
|
|
31
|
-
"thread/queue/delete",
|
|
32
|
-
"thread/queue/reorder",
|
|
33
|
-
"thread/queue/start",
|
|
34
|
-
"thread/inject_items",
|
|
35
|
-
"thread/realtime/start",
|
|
36
|
-
"thread/realtime/appendText",
|
|
37
|
-
"thread/realtime/appendSpeech",
|
|
38
|
-
"thread/realtime/stop",
|
|
39
|
-
"thread/timeline/list"
|
|
40
|
-
];
|
|
41
|
-
const CodexThreadStatusSchema = z.discriminatedUnion("type", [
|
|
42
|
-
z.looseObject({ type: z.literal("notLoaded") }),
|
|
43
|
-
z.looseObject({ type: z.literal("idle") }),
|
|
44
|
-
z.looseObject({ type: z.literal("systemError") }),
|
|
45
|
-
z.looseObject({
|
|
46
|
-
type: z.literal("active"),
|
|
47
|
-
activeFlags: z.array(z.enum(["waitingOnApproval", "waitingOnUserInput"]))
|
|
48
|
-
})
|
|
49
|
-
]);
|
|
50
|
-
const CODEX_THREAD_STATUS_TYPES = [
|
|
51
|
-
"notLoaded",
|
|
52
|
-
"idle",
|
|
53
|
-
"systemError",
|
|
54
|
-
"active"
|
|
55
|
-
];
|
|
56
|
-
const CodexThreadStatusTypeSchema = z.enum(CODEX_THREAD_STATUS_TYPES);
|
|
57
|
-
const CodexTurnStatusSchema = z.enum([
|
|
58
|
-
"completed",
|
|
59
|
-
"interrupted",
|
|
60
|
-
"failed",
|
|
61
|
-
"inProgress"
|
|
62
|
-
]);
|
|
63
|
-
const CodexTurnPlanStepStatusSchema = z.enum({
|
|
64
|
-
pending: "pending",
|
|
65
|
-
inProgress: "inProgress",
|
|
66
|
-
completed: "completed"
|
|
67
|
-
});
|
|
68
|
-
const CodexPatchChangeKindTypeSchema = z.enum({
|
|
69
|
-
add: "add",
|
|
70
|
-
delete: "delete",
|
|
71
|
-
update: "update"
|
|
72
|
-
});
|
|
73
|
-
/** One token usage breakdown, closed to exactly the fields Codex reports. */
|
|
74
|
-
const CodexTokenUsageBreakdownSchema = z.strictObject({
|
|
75
|
-
totalTokens: z.number(),
|
|
76
|
-
inputTokens: z.number(),
|
|
77
|
-
cachedInputTokens: z.number(),
|
|
78
|
-
cacheWriteInputTokens: z.number(),
|
|
79
|
-
outputTokens: z.number(),
|
|
80
|
-
reasoningOutputTokens: z.number()
|
|
81
|
-
});
|
|
82
|
-
/**
|
|
83
|
-
* Builds the schema for a command-execution approval decision. It is a
|
|
84
|
-
* factory because a caller that already constrains strings (the browser
|
|
85
|
-
* model's bounded text) can plug its own text and host schemas into the
|
|
86
|
-
* amendment branches while keeping the vendor shape.
|
|
87
|
-
* @param options - Optional replacements for the plain string schemas.
|
|
88
|
-
* @param options.text - The schema for execpolicy amendment entries.
|
|
89
|
-
* @param options.host - The schema for the network amendment host; defaults to `text`.
|
|
90
|
-
* @returns A zod union accepting the four bare decisions and both amendment forms.
|
|
91
|
-
*/
|
|
92
|
-
function createCodexCommandExecutionApprovalDecisionSchema(options = {}) {
|
|
93
|
-
const text = options.text ?? z.string();
|
|
94
|
-
const host = options.host ?? text;
|
|
95
|
-
return z.union([
|
|
96
|
-
z.enum([
|
|
97
|
-
"accept",
|
|
98
|
-
"acceptForSession",
|
|
99
|
-
"decline",
|
|
100
|
-
"cancel"
|
|
101
|
-
]),
|
|
102
|
-
z.strictObject({ acceptWithExecpolicyAmendment: z.strictObject({ execpolicy_amendment: z.array(text) }) }),
|
|
103
|
-
z.strictObject({ applyNetworkPolicyAmendment: z.strictObject({ network_policy_amendment: z.strictObject({
|
|
104
|
-
host,
|
|
105
|
-
action: z.enum(["allow", "deny"])
|
|
106
|
-
}) }) })
|
|
107
|
-
]);
|
|
108
|
-
}
|
|
109
|
-
const CodexCommandExecutionApprovalDecisionSchema = createCodexCommandExecutionApprovalDecisionSchema();
|
|
110
|
-
const CodexFileChangeApprovalDecisionSchema = z.enum([
|
|
111
|
-
"accept",
|
|
112
|
-
"acceptForSession",
|
|
113
|
-
"decline",
|
|
114
|
-
"cancel"
|
|
115
|
-
]);
|
|
116
|
-
/**
|
|
117
|
-
* Normalizes a JSON scalar, refusing the values JSON cannot carry: non-finite
|
|
118
|
-
* numbers and bigints.
|
|
119
|
-
* @param value - A primitive that is not an object.
|
|
120
|
-
* @param path - Where the value sits in the payload, for the error message.
|
|
121
|
-
* @returns The scalar unchanged.
|
|
122
|
-
* @throws {TypeError} When the scalar is not representable in Codex JSON.
|
|
123
|
-
*/
|
|
124
|
-
function normalizeScalar(value, path) {
|
|
125
|
-
if (value === null || typeof value === "string" || typeof value === "boolean") return value;
|
|
126
|
-
if (typeof value === "number") return normalizeNumber(value, path);
|
|
127
|
-
if (typeof value === "bigint") throw new TypeError(`${path} is bigint; Codex JSON i64 values must be safe numbers`);
|
|
128
|
-
throw new TypeError(`${path} is not a JSON value`);
|
|
129
|
-
}
|
|
130
|
-
/**
|
|
131
|
-
* Accepts only the numbers JSON can spell.
|
|
132
|
-
* @param value - A number.
|
|
133
|
-
* @param path - Where the number sits in the payload, for the error message.
|
|
134
|
-
* @returns The number unchanged.
|
|
135
|
-
* @throws {TypeError} When the number is NaN or infinite.
|
|
136
|
-
*/
|
|
137
|
-
function normalizeNumber(value, path) {
|
|
138
|
-
if (!Number.isFinite(value)) throw new TypeError(`${path} is not a finite JSON number`);
|
|
139
|
-
return value;
|
|
140
|
-
}
|
|
141
|
-
/**
|
|
142
|
-
* Normalizes a JSON object, accepting only plain objects so a class instance
|
|
143
|
-
* or a prototype-carrying value never reaches an ingress parser.
|
|
144
|
-
* @param value - A non-null, non-array object.
|
|
145
|
-
* @param path - Where the object sits in the payload, for the error message.
|
|
146
|
-
* @returns A fresh plain object with every entry normalized.
|
|
147
|
-
* @throws {TypeError} When the object has a prototype other than Object or null.
|
|
148
|
-
*/
|
|
149
|
-
function normalizeObject(value, path) {
|
|
150
|
-
const prototype = Object.getPrototypeOf(value);
|
|
151
|
-
if (prototype !== Object.prototype && prototype !== null) throw new TypeError(`${path} is not a plain JSON object`);
|
|
152
|
-
return Object.fromEntries(Object.entries(value).map(([key, entry]) => [key, normalizeValue(entry, `${path}.${key}`)]));
|
|
153
|
-
}
|
|
154
|
-
/**
|
|
155
|
-
* Recursively normalizes one untrusted value into the closed Codex JSON
|
|
156
|
-
* vocabulary, naming the offending path when something is not JSON.
|
|
157
|
-
* @param value - Any value decoded from the app-server stream.
|
|
158
|
-
* @param path - Where the value sits in the payload, for the error message.
|
|
159
|
-
* @returns The equivalent value built only from JSON scalars, arrays and plain objects.
|
|
160
|
-
* @throws {TypeError} When the value or anything inside it is not Codex JSON.
|
|
161
|
-
*/
|
|
162
|
-
function normalizeValue(value, path) {
|
|
163
|
-
if (Array.isArray(value)) return value.map((entry, index) => normalizeValue(entry, `${path}[${index}]`));
|
|
164
|
-
if (typeof value === "object" && value !== null) return normalizeObject(value, path);
|
|
165
|
-
return normalizeScalar(value, path);
|
|
166
|
-
}
|
|
167
|
-
/**
|
|
168
|
-
* Normalizes untrusted app-server JSON before any handwritten ingress parser runs.
|
|
169
|
-
* @param value - The decoded payload, or undefined when a message carried none.
|
|
170
|
-
* @returns The normalized payload, or undefined when there was none.
|
|
171
|
-
* @throws {TypeError} When the payload is not Codex JSON.
|
|
172
|
-
*/
|
|
173
|
-
function normalizeCodexJsonWire(value) {
|
|
174
|
-
if (value === void 0) return;
|
|
175
|
-
return normalizeValue(value, "$codex");
|
|
176
|
-
}
|
|
177
|
-
export { CodexPatchChangeKindTypeSchema as a, CodexThreadStatusTypeSchema as c, CodexTurnStatusSchema as d, createCodexCommandExecutionApprovalDecisionSchema as f, CodexFileChangeApprovalDecisionSchema as i, CodexTokenUsageBreakdownSchema as l, CODEX_THREAD_STATUS_TYPES as n, CodexSafeI64Schema as o, normalizeCodexJsonWire as p, CodexCommandExecutionApprovalDecisionSchema as r, CodexThreadStatusSchema as s, CODEX_CLIENT_REQUEST_METHODS as t, CodexTurnPlanStepStatusSchema as u };
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
// src/shared/protocol/gateway-envelope.ts
|
|
2
|
-
const BROWSER_GATEWAY_ERROR_CODES = [
|
|
3
|
-
"disposed",
|
|
4
|
-
"invalid_input",
|
|
5
|
-
"invalid_command",
|
|
6
|
-
"invalid_projection",
|
|
7
|
-
"not_ready",
|
|
8
|
-
"thread_capability_required",
|
|
9
|
-
"link_required",
|
|
10
|
-
"link_changed",
|
|
11
|
-
"lease_required",
|
|
12
|
-
"lease_expired",
|
|
13
|
-
"lease_released",
|
|
14
|
-
"lease_transferred",
|
|
15
|
-
"child_disconnected",
|
|
16
|
-
"approval_not_pending",
|
|
17
|
-
"dynamic_approval_not_pending",
|
|
18
|
-
"unsupported_command",
|
|
19
|
-
"command_failed",
|
|
20
|
-
"outcome_unknown",
|
|
21
|
-
"work_stopping",
|
|
22
|
-
"stop_unconfirmed"
|
|
23
|
-
];
|
|
24
|
-
/** Every snapshot field a delta may carry, in snapshot order. */
|
|
25
|
-
const BROWSER_SNAPSHOT_DELTA_KEYS = [
|
|
26
|
-
"readiness",
|
|
27
|
-
"account",
|
|
28
|
-
"login",
|
|
29
|
-
"threadLink",
|
|
30
|
-
"timeline",
|
|
31
|
-
"queue",
|
|
32
|
-
"settings",
|
|
33
|
-
"approvals",
|
|
34
|
-
"dynamicApprovals",
|
|
35
|
-
"contextDelivery",
|
|
36
|
-
"coordinator",
|
|
37
|
-
"voice",
|
|
38
|
-
"spokenApproval",
|
|
39
|
-
"voiceContext",
|
|
40
|
-
"coordinatorTimeline",
|
|
41
|
-
"workhorses",
|
|
42
|
-
"lease",
|
|
43
|
-
"operation"
|
|
44
|
-
];
|
|
45
|
-
export { BROWSER_SNAPSHOT_DELTA_KEYS as n, BROWSER_GATEWAY_ERROR_CODES as t };
|