@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,5 +1,3 @@
|
|
|
1
|
-
import { a as CodexPatchChangeKindTypeSchema, c as CodexThreadStatusTypeSchema, d as CodexTurnStatusSchema, f as createCodexCommandExecutionApprovalDecisionSchema, i as CodexFileChangeApprovalDecisionSchema, l as CodexTokenUsageBreakdownSchema, u as CodexTurnPlanStepStatusSchema } from "./app-server-contract-D4E5bibD.mjs";
|
|
2
|
-
import { n as parseRealtimeItemId, r as parseRealtimeSessionId } from "./realtime-contract-DwkCluo2.mjs";
|
|
3
1
|
import { z } from "zod";
|
|
4
2
|
// ../codex-app-server/src/shared/constants/app-server-capacity.ts
|
|
5
3
|
/**
|
|
@@ -31,9 +29,221 @@ const CODEX_APP_SERVER_CAPACITY = Object.freeze({
|
|
|
31
29
|
}),
|
|
32
30
|
listenersPerEvent: 1
|
|
33
31
|
});
|
|
32
|
+
// ../codex-app-server/src/shared/protocol/app-server-contract.ts
|
|
33
|
+
/** JSON representation of one generated ts-rs bigint/i64 field. */
|
|
34
|
+
const CodexSafeI64Schema = z.number().int().safe().brand();
|
|
35
|
+
/** Client requests this client implements, checked against the generated request union. */
|
|
36
|
+
const CODEX_CLIENT_REQUEST_METHODS = [
|
|
37
|
+
"initialize",
|
|
38
|
+
"config/read",
|
|
39
|
+
"configRequirements/read",
|
|
40
|
+
"account/read",
|
|
41
|
+
"account/login/start",
|
|
42
|
+
"account/login/cancel",
|
|
43
|
+
"account/logout",
|
|
44
|
+
"model/list",
|
|
45
|
+
"thread/start",
|
|
46
|
+
"thread/fork",
|
|
47
|
+
"thread/list",
|
|
48
|
+
"thread/loaded/list",
|
|
49
|
+
"thread/read",
|
|
50
|
+
"thread/turns/list",
|
|
51
|
+
"thread/items/list",
|
|
52
|
+
"thread/delete",
|
|
53
|
+
"thread/unsubscribe",
|
|
54
|
+
"thread/settings/update",
|
|
55
|
+
"turn/start",
|
|
56
|
+
"turn/steer",
|
|
57
|
+
"turn/interrupt",
|
|
58
|
+
"thread/queue/add",
|
|
59
|
+
"thread/queue/list",
|
|
60
|
+
"thread/queue/update",
|
|
61
|
+
"thread/queue/delete",
|
|
62
|
+
"thread/queue/reorder",
|
|
63
|
+
"thread/queue/start",
|
|
64
|
+
"thread/inject_items",
|
|
65
|
+
"thread/realtime/start",
|
|
66
|
+
"thread/realtime/appendText",
|
|
67
|
+
"thread/realtime/appendSpeech",
|
|
68
|
+
"thread/realtime/stop",
|
|
69
|
+
"thread/timeline/list"
|
|
70
|
+
];
|
|
71
|
+
const CodexThreadStatusSchema = z.discriminatedUnion("type", [
|
|
72
|
+
z.looseObject({ type: z.literal("notLoaded") }),
|
|
73
|
+
z.looseObject({ type: z.literal("idle") }),
|
|
74
|
+
z.looseObject({ type: z.literal("systemError") }),
|
|
75
|
+
z.looseObject({
|
|
76
|
+
type: z.literal("active"),
|
|
77
|
+
activeFlags: z.array(z.enum(["waitingOnApproval", "waitingOnUserInput"]))
|
|
78
|
+
})
|
|
79
|
+
]);
|
|
80
|
+
const CodexThreadStatusTypeSchema = z.enum([
|
|
81
|
+
"notLoaded",
|
|
82
|
+
"idle",
|
|
83
|
+
"systemError",
|
|
84
|
+
"active"
|
|
85
|
+
]);
|
|
86
|
+
/**
|
|
87
|
+
* Tells whether a value is one of the thread status types the app server
|
|
88
|
+
* declares, so a status read off the wire narrows without a cast.
|
|
89
|
+
* @param value - Any value, usually `status.type` from a thread payload.
|
|
90
|
+
* @returns True when the value names a declared thread status type.
|
|
91
|
+
*/
|
|
92
|
+
function isCodexThreadStatusType(value) {
|
|
93
|
+
return CodexThreadStatusTypeSchema.safeParse(value).success;
|
|
94
|
+
}
|
|
95
|
+
const CodexTurnStatusSchema = z.enum([
|
|
96
|
+
"completed",
|
|
97
|
+
"interrupted",
|
|
98
|
+
"failed",
|
|
99
|
+
"inProgress"
|
|
100
|
+
]);
|
|
101
|
+
const CodexTurnPlanStepStatusSchema = z.enum({
|
|
102
|
+
pending: "pending",
|
|
103
|
+
inProgress: "inProgress",
|
|
104
|
+
completed: "completed"
|
|
105
|
+
});
|
|
106
|
+
const CodexPatchChangeKindTypeSchema = z.enum({
|
|
107
|
+
add: "add",
|
|
108
|
+
delete: "delete",
|
|
109
|
+
update: "update"
|
|
110
|
+
});
|
|
111
|
+
/** One token usage breakdown, closed to exactly the fields Codex reports. */
|
|
112
|
+
const CodexTokenUsageBreakdownSchema = z.strictObject({
|
|
113
|
+
totalTokens: z.number(),
|
|
114
|
+
inputTokens: z.number(),
|
|
115
|
+
cachedInputTokens: z.number(),
|
|
116
|
+
cacheWriteInputTokens: z.number(),
|
|
117
|
+
outputTokens: z.number(),
|
|
118
|
+
reasoningOutputTokens: z.number()
|
|
119
|
+
});
|
|
120
|
+
/**
|
|
121
|
+
* Builds the schema for a command-execution approval decision. It is a
|
|
122
|
+
* factory because a caller that already constrains strings (the browser
|
|
123
|
+
* model's bounded text) can plug its own text and host schemas into the
|
|
124
|
+
* amendment branches while keeping the vendor shape.
|
|
125
|
+
* @param options - Optional replacements for the plain string schemas.
|
|
126
|
+
* @param options.text - The schema for execpolicy amendment entries.
|
|
127
|
+
* @param options.host - The schema for the network amendment host; defaults to `text`.
|
|
128
|
+
* @returns A zod union accepting the four bare decisions and both amendment forms.
|
|
129
|
+
*/
|
|
130
|
+
function createCodexCommandExecutionApprovalDecisionSchema(options = {}) {
|
|
131
|
+
const text = options.text ?? z.string();
|
|
132
|
+
const host = options.host ?? text;
|
|
133
|
+
return z.union([
|
|
134
|
+
z.enum([
|
|
135
|
+
"accept",
|
|
136
|
+
"acceptForSession",
|
|
137
|
+
"decline",
|
|
138
|
+
"cancel"
|
|
139
|
+
]),
|
|
140
|
+
z.strictObject({ acceptWithExecpolicyAmendment: z.strictObject({ execpolicy_amendment: z.array(text) }) }),
|
|
141
|
+
z.strictObject({ applyNetworkPolicyAmendment: z.strictObject({ network_policy_amendment: z.strictObject({
|
|
142
|
+
host,
|
|
143
|
+
action: z.enum(["allow", "deny"])
|
|
144
|
+
}) }) })
|
|
145
|
+
]);
|
|
146
|
+
}
|
|
147
|
+
const CodexCommandExecutionApprovalDecisionSchema = createCodexCommandExecutionApprovalDecisionSchema();
|
|
148
|
+
const CodexFileChangeApprovalDecisionSchema = z.enum([
|
|
149
|
+
"accept",
|
|
150
|
+
"acceptForSession",
|
|
151
|
+
"decline",
|
|
152
|
+
"cancel"
|
|
153
|
+
]);
|
|
154
|
+
/**
|
|
155
|
+
* The schemas of the closed Codex vocabularies that another package composes into its own
|
|
156
|
+
* schemas, each checked against the generated protocol here.
|
|
157
|
+
*/
|
|
158
|
+
const CODEX_FIELD_SCHEMAS = Object.freeze({
|
|
159
|
+
threadStatusType: CodexThreadStatusTypeSchema,
|
|
160
|
+
turnStatus: CodexTurnStatusSchema,
|
|
161
|
+
turnPlanStepStatus: CodexTurnPlanStepStatusSchema,
|
|
162
|
+
patchChangeKindType: CodexPatchChangeKindTypeSchema,
|
|
163
|
+
tokenUsageBreakdown: CodexTokenUsageBreakdownSchema,
|
|
164
|
+
fileChangeApprovalDecision: CodexFileChangeApprovalDecisionSchema
|
|
165
|
+
});
|
|
166
|
+
/**
|
|
167
|
+
* The schema of one closed Codex vocabulary, for a caller that composes it into its own schema.
|
|
168
|
+
* @param field - The vocabulary, such as `threadStatusType`.
|
|
169
|
+
* @returns Its schema.
|
|
170
|
+
*/
|
|
171
|
+
function codexFieldSchema(field) {
|
|
172
|
+
return CODEX_FIELD_SCHEMAS[field];
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Normalizes a JSON scalar, refusing the values JSON cannot carry: non-finite
|
|
176
|
+
* numbers and bigints.
|
|
177
|
+
* @param value - A primitive that is not an object.
|
|
178
|
+
* @param path - Where the value sits in the payload, for the error message.
|
|
179
|
+
* @returns The scalar unchanged.
|
|
180
|
+
* @throws {TypeError} When the scalar is not representable in Codex JSON.
|
|
181
|
+
*/
|
|
182
|
+
function normalizeScalar(value, path) {
|
|
183
|
+
if (value === null || typeof value === "string" || typeof value === "boolean") return value;
|
|
184
|
+
if (typeof value === "number") return normalizeNumber(value, path);
|
|
185
|
+
if (typeof value === "bigint") throw new TypeError(`${path} is bigint; Codex JSON i64 values must be safe numbers`);
|
|
186
|
+
throw new TypeError(`${path} is not a JSON value`);
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Accepts only the numbers JSON can spell.
|
|
190
|
+
* @param value - A number.
|
|
191
|
+
* @param path - Where the number sits in the payload, for the error message.
|
|
192
|
+
* @returns The number unchanged.
|
|
193
|
+
* @throws {TypeError} When the number is NaN or infinite.
|
|
194
|
+
*/
|
|
195
|
+
function normalizeNumber(value, path) {
|
|
196
|
+
if (!Number.isFinite(value)) throw new TypeError(`${path} is not a finite JSON number`);
|
|
197
|
+
return value;
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Normalizes a JSON object, accepting only plain objects so a class instance
|
|
201
|
+
* or a prototype-carrying value never reaches an ingress parser.
|
|
202
|
+
* @param value - A non-null, non-array object.
|
|
203
|
+
* @param path - Where the object sits in the payload, for the error message.
|
|
204
|
+
* @returns A fresh plain object with every entry normalized.
|
|
205
|
+
* @throws {TypeError} When the object has a prototype other than Object or null.
|
|
206
|
+
*/
|
|
207
|
+
function normalizeObject(value, path) {
|
|
208
|
+
const prototype = Object.getPrototypeOf(value);
|
|
209
|
+
if (prototype !== Object.prototype && prototype !== null) throw new TypeError(`${path} is not a plain JSON object`);
|
|
210
|
+
return Object.fromEntries(Object.entries(value).map(([key, entry]) => [key, normalizeValue(entry, `${path}.${key}`)]));
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Recursively normalizes one untrusted value into the closed Codex JSON
|
|
214
|
+
* vocabulary, naming the offending path when something is not JSON.
|
|
215
|
+
* @param value - Any value decoded from the app-server stream.
|
|
216
|
+
* @param path - Where the value sits in the payload, for the error message.
|
|
217
|
+
* @returns The equivalent value built only from JSON scalars, arrays and plain objects.
|
|
218
|
+
* @throws {TypeError} When the value or anything inside it is not Codex JSON.
|
|
219
|
+
*/
|
|
220
|
+
function normalizeValue(value, path) {
|
|
221
|
+
if (Array.isArray(value)) return value.map((entry, index) => normalizeValue(entry, `${path}[${index}]`));
|
|
222
|
+
if (typeof value === "object" && value !== null) return normalizeObject(value, path);
|
|
223
|
+
return normalizeScalar(value, path);
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Normalizes untrusted app-server JSON before any handwritten ingress parser runs.
|
|
227
|
+
* @param value - The decoded payload, or undefined when a message carried none.
|
|
228
|
+
* @returns The normalized payload, or undefined when there was none.
|
|
229
|
+
* @throws {TypeError} When the payload is not Codex JSON.
|
|
230
|
+
*/
|
|
231
|
+
function normalizeCodexJsonWire(value) {
|
|
232
|
+
if (value === void 0) return;
|
|
233
|
+
return normalizeValue(value, "$codex");
|
|
234
|
+
}
|
|
34
235
|
// src/shared/browser/schemas/scalars.ts
|
|
35
236
|
const JsonValueSchema = z.json();
|
|
36
237
|
/**
|
|
238
|
+
* Narrows an untrusted value to JSON.
|
|
239
|
+
* @param value - Any value.
|
|
240
|
+
* @returns The value, known to be JSON.
|
|
241
|
+
* @throws {ZodError} when the value holds anything JSON cannot carry.
|
|
242
|
+
*/
|
|
243
|
+
function parseJsonValue(value) {
|
|
244
|
+
return JsonValueSchema.parse(value);
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
37
247
|
* A non-empty string bounded in both characters and UTF-8 bytes, without NUL,
|
|
38
248
|
* so a browser payload can never exceed what its wire budget assumed.
|
|
39
249
|
* @param maximum - The limit, applied to both the length and the encoded byte size.
|
|
@@ -364,7 +574,7 @@ function createBrowserApprovalSchemas(identity, context) {
|
|
|
364
574
|
approvalKind: z.literal("file_change"),
|
|
365
575
|
...ApprovalEnvelope,
|
|
366
576
|
...ApprovalReason,
|
|
367
|
-
availableDecisions: z.array(
|
|
577
|
+
availableDecisions: z.array(codexFieldSchema("fileChangeApprovalDecision"))
|
|
368
578
|
}).strict(),
|
|
369
579
|
z.object({
|
|
370
580
|
kind: z.literal("approval"),
|
|
@@ -823,7 +1033,7 @@ function createBrowserSessionSchemas(identity) {
|
|
|
823
1033
|
function createBrowserThreadSchemas(identity, context) {
|
|
824
1034
|
const { ApprovalIdSchema, ChildEpochSchema, ChildIdSchema, ItemIdSchema, OperationIdSchema, QueuedSubmissionIdSchema, ThreadIdSchema, TurnIdSchema } = identity;
|
|
825
1035
|
const NullableReasonSchema = optionalNullableText(512);
|
|
826
|
-
const ThreadLinkStatusSchema =
|
|
1036
|
+
const ThreadLinkStatusSchema = codexFieldSchema("threadStatusType");
|
|
827
1037
|
const BrowserThreadLinkSourcePresentationSchema = z.enum([
|
|
828
1038
|
"standard",
|
|
829
1039
|
"subagent",
|
|
@@ -879,7 +1089,7 @@ function createBrowserThreadSchemas(identity, context) {
|
|
|
879
1089
|
const LineCountSchema = z.number().int().nonnegative();
|
|
880
1090
|
const BrowserTimelineFileChangeSchema = z.object({
|
|
881
1091
|
path: boundedText(BROWSER_TIMELINE_LIMITS.path),
|
|
882
|
-
kind:
|
|
1092
|
+
kind: codexFieldSchema("patchChangeKindType"),
|
|
883
1093
|
movePath: boundedText(BROWSER_TIMELINE_LIMITS.path).nullable(),
|
|
884
1094
|
added: LineCountSchema,
|
|
885
1095
|
removed: LineCountSchema
|
|
@@ -972,12 +1182,12 @@ function createBrowserThreadSchemas(identity, context) {
|
|
|
972
1182
|
explanation: boundedText(BROWSER_TIMELINE_LIMITS.planExplanation).nullable(),
|
|
973
1183
|
steps: z.array(z.object({
|
|
974
1184
|
step: boundedText(BROWSER_TIMELINE_LIMITS.planStep),
|
|
975
|
-
status:
|
|
1185
|
+
status: codexFieldSchema("turnPlanStepStatus")
|
|
976
1186
|
}).strict()).max(BROWSER_TIMELINE_LIMITS.planSteps)
|
|
977
1187
|
}).strict();
|
|
978
1188
|
const BrowserTimelineTurnSchema = z.object({
|
|
979
1189
|
turnId: TurnIdSchema,
|
|
980
|
-
status:
|
|
1190
|
+
status: codexFieldSchema("turnStatus"),
|
|
981
1191
|
items: z.array(BrowserTimelineItemSchema),
|
|
982
1192
|
summary: boundedText(512),
|
|
983
1193
|
outputsIncluded: z.boolean(),
|
|
@@ -995,8 +1205,8 @@ function createBrowserThreadSchemas(identity, context) {
|
|
|
995
1205
|
}).strict();
|
|
996
1206
|
/** The thread's latest token usage, and the context window it counts against. */
|
|
997
1207
|
const BrowserTimelineUsageSchema = z.object({
|
|
998
|
-
total:
|
|
999
|
-
last:
|
|
1208
|
+
total: codexFieldSchema("tokenUsageBreakdown"),
|
|
1209
|
+
last: codexFieldSchema("tokenUsageBreakdown"),
|
|
1000
1210
|
modelContextWindow: z.number().nonnegative().nullable()
|
|
1001
1211
|
}).strict();
|
|
1002
1212
|
const BrowserTimelineSchema = z.object({
|
|
@@ -1041,6 +1251,1178 @@ function createBrowserThreadSchemas(identity, context) {
|
|
|
1041
1251
|
}).strict()
|
|
1042
1252
|
};
|
|
1043
1253
|
}
|
|
1254
|
+
// ../codex-app-server/src/shared/schemas/identity-values.ts
|
|
1255
|
+
const RECORD_PREFIX_SOURCE = `[a-z][a-z0-9-]{0,15}`;
|
|
1256
|
+
const RECORD_PREFIX_PATTERN = new RegExp(`^${RECORD_PREFIX_SOURCE}$`, "u");
|
|
1257
|
+
const RAW_ID_LIMIT_BYTES = 4096;
|
|
1258
|
+
const CANONICAL_ITEM_ID_MAX_LENGTH = 8215;
|
|
1259
|
+
const TOKEN_PATTERN = new RegExp(`^[A-Za-z0-9][A-Za-z0-9._~-]{0,8192}$`, "u");
|
|
1260
|
+
const WIRE_PATTERN = new RegExp(`^(${RECORD_PREFIX_SOURCE}):([a-z-]+):([A-Za-z0-9][A-Za-z0-9._~-]{0,8192})$`, "u");
|
|
1261
|
+
const EPOCH_TOKEN_PATTERN = new RegExp(`^([A-Za-z0-9][A-Za-z0-9._~-]{0,8192})\\.([A-Za-z0-9][A-Za-z0-9._~-]{0,8192})$`, "u");
|
|
1262
|
+
const IDENTITY_DOMAINS = /* @__PURE__ */ new Set([
|
|
1263
|
+
"child",
|
|
1264
|
+
"epoch",
|
|
1265
|
+
"browser-command",
|
|
1266
|
+
"thread",
|
|
1267
|
+
"turn",
|
|
1268
|
+
"item",
|
|
1269
|
+
"queued-submission",
|
|
1270
|
+
"login",
|
|
1271
|
+
"json-rpc-request",
|
|
1272
|
+
"dynamic-tool-call",
|
|
1273
|
+
"realtime-session",
|
|
1274
|
+
"approval",
|
|
1275
|
+
"operation"
|
|
1276
|
+
]);
|
|
1277
|
+
var IdentityValidationError = class extends Error {
|
|
1278
|
+
code;
|
|
1279
|
+
domain;
|
|
1280
|
+
/**
|
|
1281
|
+
* Creates a refusal that names both the rule broken and, when known, the
|
|
1282
|
+
* identity domain it was broken in.
|
|
1283
|
+
* @param code - Which validation rule refused the value.
|
|
1284
|
+
* @param message - The human-readable reason.
|
|
1285
|
+
* @param domain - The identity domain being validated, when one applies.
|
|
1286
|
+
*/
|
|
1287
|
+
constructor(code, message, domain) {
|
|
1288
|
+
super(message);
|
|
1289
|
+
this.name = "IdentityValidationError";
|
|
1290
|
+
this.code = code;
|
|
1291
|
+
this.domain = domain;
|
|
1292
|
+
}
|
|
1293
|
+
};
|
|
1294
|
+
/**
|
|
1295
|
+
* Refuses a value with a typed validation error. Declared `never` so a caller
|
|
1296
|
+
* can `return fail(...)` inside a function that must otherwise produce a value.
|
|
1297
|
+
* @param code - Which validation rule refused the value.
|
|
1298
|
+
* @param message - The human-readable reason.
|
|
1299
|
+
* @param domain - The identity domain being validated, when one applies.
|
|
1300
|
+
* @throws {IdentityValidationError} Always.
|
|
1301
|
+
*/
|
|
1302
|
+
function fail(code, message, domain) {
|
|
1303
|
+
throw new IdentityValidationError(code, message, domain);
|
|
1304
|
+
}
|
|
1305
|
+
/**
|
|
1306
|
+
* Tells whether a string names one of the identity domains.
|
|
1307
|
+
* @param value - The domain segment of a wire value.
|
|
1308
|
+
* @returns True when it is a declared identity domain.
|
|
1309
|
+
*/
|
|
1310
|
+
function isIdentityDomain(value) {
|
|
1311
|
+
return IDENTITY_DOMAINS.has(value);
|
|
1312
|
+
}
|
|
1313
|
+
/**
|
|
1314
|
+
* Brands a string that has already been validated as a canonical wire value
|
|
1315
|
+
* of `domain`. This is the one site that manufactures a branded identity; every
|
|
1316
|
+
* other path reaches a brand only by validating first.
|
|
1317
|
+
* @param value - A string already checked against the wire pattern for `domain`.
|
|
1318
|
+
* @returns The same string, carrying the domain brand.
|
|
1319
|
+
*/
|
|
1320
|
+
function brand(value) {
|
|
1321
|
+
return value;
|
|
1322
|
+
}
|
|
1323
|
+
/**
|
|
1324
|
+
* Splits a canonical wire value into its record prefix, domain and token segments.
|
|
1325
|
+
* @param value - The string to match.
|
|
1326
|
+
* @returns The three segments, or null when the string is not a wire value.
|
|
1327
|
+
*/
|
|
1328
|
+
function wireSegments(value) {
|
|
1329
|
+
const match = WIRE_PATTERN.exec(value);
|
|
1330
|
+
if (match === null) return null;
|
|
1331
|
+
const [, prefix, domain, token] = match;
|
|
1332
|
+
if (prefix === void 0 || domain === void 0 || token === void 0) return null;
|
|
1333
|
+
return {
|
|
1334
|
+
prefix,
|
|
1335
|
+
domain,
|
|
1336
|
+
token
|
|
1337
|
+
};
|
|
1338
|
+
}
|
|
1339
|
+
/**
|
|
1340
|
+
* Validates that a value is a canonical wire identity of `domain` and returns
|
|
1341
|
+
* its token, refusing with the most specific code available.
|
|
1342
|
+
* @param value - The untrusted value.
|
|
1343
|
+
* @param domain - The domain the caller expects.
|
|
1344
|
+
* @returns The token segment after the domain.
|
|
1345
|
+
* @throws {IdentityValidationError} When the value is not a wire identity of that domain.
|
|
1346
|
+
*/
|
|
1347
|
+
function requireToken(value, domain) {
|
|
1348
|
+
if (typeof value !== "string") return fail("invalid-shape", `${domain} identity must be a string.`, domain);
|
|
1349
|
+
if (value.length === 0) return fail("empty", `${domain} identity must not be empty.`, domain);
|
|
1350
|
+
if (value.trim() !== value) return fail("invalid-shape", `${domain} identity must not have surrounding whitespace.`, domain);
|
|
1351
|
+
const segments = wireSegments(value);
|
|
1352
|
+
if (segments === null) return fail("invalid-shape", `Invalid ${domain} identity wire value.`, domain);
|
|
1353
|
+
if (segments.domain !== domain) return fail("wrong-domain", `Expected a ${domain} identity.`, domain);
|
|
1354
|
+
return segments.token;
|
|
1355
|
+
}
|
|
1356
|
+
/**
|
|
1357
|
+
* Spells a canonical wire value from a record prefix, a domain and a token.
|
|
1358
|
+
* @param prefix - A valid record prefix: `prefixOf` an identity, or one `requireRecordPrefix` passed.
|
|
1359
|
+
* @param domain - The identity domain.
|
|
1360
|
+
* @param token - The token, which must match the token grammar.
|
|
1361
|
+
* @returns The branded `<prefix>:<domain>:<token>` value.
|
|
1362
|
+
* @throws {IdentityValidationError} When the token does not fit the grammar.
|
|
1363
|
+
*/
|
|
1364
|
+
function wireValue(prefix, domain, token) {
|
|
1365
|
+
if (!TOKEN_PATTERN.test(token)) return fail("invalid-shape", `Invalid ${domain} identity token.`, domain);
|
|
1366
|
+
return brand(`${prefix}:${domain}:${token}`);
|
|
1367
|
+
}
|
|
1368
|
+
/**
|
|
1369
|
+
* Checks a host's record prefix, which every identity its ledger spells begins with.
|
|
1370
|
+
* @param prefix - The untrusted prefix.
|
|
1371
|
+
* @returns The same prefix.
|
|
1372
|
+
* @throws {TypeError} When it is not 1 to 16 characters of `[a-z][a-z0-9-]*`.
|
|
1373
|
+
*/
|
|
1374
|
+
function requireRecordPrefix(prefix) {
|
|
1375
|
+
if (typeof prefix !== "string" || !RECORD_PREFIX_PATTERN.test(prefix)) throw new TypeError(`A record prefix must match ^${RECORD_PREFIX_SOURCE}$.`);
|
|
1376
|
+
return prefix;
|
|
1377
|
+
}
|
|
1378
|
+
/**
|
|
1379
|
+
* Mints a fresh random token for a server-owned identity.
|
|
1380
|
+
* @returns Thirty-two lowercase hexadecimal characters.
|
|
1381
|
+
*/
|
|
1382
|
+
function mintToken() {
|
|
1383
|
+
return crypto.randomUUID().replaceAll("-", "");
|
|
1384
|
+
}
|
|
1385
|
+
/**
|
|
1386
|
+
* Reads the token segment back out of a branded identity.
|
|
1387
|
+
* @param value - A branded identity of any domain.
|
|
1388
|
+
* @returns The token after the domain segment.
|
|
1389
|
+
* @throws {IdentityValidationError} When the string is not canonical after all.
|
|
1390
|
+
*/
|
|
1391
|
+
function tokenOf(value) {
|
|
1392
|
+
const segments = wireSegments(value);
|
|
1393
|
+
if (segments === null) return fail("invalid-shape", "Identity is not a canonical wire value.");
|
|
1394
|
+
return segments.token;
|
|
1395
|
+
}
|
|
1396
|
+
/**
|
|
1397
|
+
* Reads the record prefix back out of a branded identity.
|
|
1398
|
+
* @param value - A branded identity of any domain.
|
|
1399
|
+
* @returns The prefix before the domain segment.
|
|
1400
|
+
* @throws {IdentityValidationError} When the string is not canonical after all.
|
|
1401
|
+
*/
|
|
1402
|
+
function prefixOf(value) {
|
|
1403
|
+
const segments = wireSegments(value);
|
|
1404
|
+
if (segments === null) return fail("invalid-shape", "Identity is not a canonical wire value.");
|
|
1405
|
+
return segments.prefix;
|
|
1406
|
+
}
|
|
1407
|
+
/**
|
|
1408
|
+
* Mints a server-owned identity whose token is marked with the `h` prefix.
|
|
1409
|
+
* @param prefix - The host's record prefix.
|
|
1410
|
+
* @param domain - The identity domain to mint in.
|
|
1411
|
+
* @returns A fresh branded identity.
|
|
1412
|
+
* @throws {TypeError} When the record prefix is not of its shape.
|
|
1413
|
+
*/
|
|
1414
|
+
function mintServerValue(prefix, domain) {
|
|
1415
|
+
return wireValue(requireRecordPrefix(prefix), domain, `h${mintToken()}`);
|
|
1416
|
+
}
|
|
1417
|
+
/**
|
|
1418
|
+
* Validates an untrusted value as a wire identity of `domain` and brands it.
|
|
1419
|
+
* @param value - The untrusted value.
|
|
1420
|
+
* @param domain - The domain the caller expects.
|
|
1421
|
+
* @returns The value, branded.
|
|
1422
|
+
* @throws {IdentityValidationError} When the value is not a wire identity of that domain.
|
|
1423
|
+
*/
|
|
1424
|
+
function parseValue(value, domain) {
|
|
1425
|
+
requireToken(value, domain);
|
|
1426
|
+
return brand(String(value));
|
|
1427
|
+
}
|
|
1428
|
+
/**
|
|
1429
|
+
* Validates a child epoch, whose token is `<child token>.<epoch token>`, and
|
|
1430
|
+
* optionally checks that it belongs to one particular child.
|
|
1431
|
+
* @param value - The untrusted value.
|
|
1432
|
+
* @param expectedChild - When given, the child the epoch must belong to.
|
|
1433
|
+
* @returns The value, branded as an epoch.
|
|
1434
|
+
* @throws {IdentityValidationError} When it is not an epoch or belongs to another child.
|
|
1435
|
+
*/
|
|
1436
|
+
function parseEpochValue(value, expectedChild) {
|
|
1437
|
+
const token = requireToken(value, "epoch");
|
|
1438
|
+
const match = EPOCH_TOKEN_PATTERN.exec(token);
|
|
1439
|
+
if (!match) return fail("invalid-shape", "A child epoch must bind to a child identity.", "epoch");
|
|
1440
|
+
const epoch = brand(String(value));
|
|
1441
|
+
if (expectedChild !== void 0 && (match[1] !== tokenOf(expectedChild) || prefixOf(epoch) !== prefixOf(expectedChild))) return fail("wrong-child", "The child epoch belongs to another child.", "epoch");
|
|
1442
|
+
return epoch;
|
|
1443
|
+
}
|
|
1444
|
+
/**
|
|
1445
|
+
* Mints a new epoch bound to `child`.
|
|
1446
|
+
* @param child - The child the epoch belongs to.
|
|
1447
|
+
* @returns A fresh branded epoch.
|
|
1448
|
+
*/
|
|
1449
|
+
function mintEpochValue(child) {
|
|
1450
|
+
return wireValue(prefixOf(child), "epoch", `${tokenOf(child)}.h${mintToken()}`);
|
|
1451
|
+
}
|
|
1452
|
+
/**
|
|
1453
|
+
* Tells whether a UTF-16 code unit opens a surrogate pair.
|
|
1454
|
+
* @param codeUnit - The code unit.
|
|
1455
|
+
* @returns True for a high surrogate.
|
|
1456
|
+
*/
|
|
1457
|
+
function isHighSurrogate(codeUnit) {
|
|
1458
|
+
return codeUnit >= 55296 && codeUnit <= 56319;
|
|
1459
|
+
}
|
|
1460
|
+
/**
|
|
1461
|
+
* Tells whether a UTF-16 code unit closes a surrogate pair.
|
|
1462
|
+
* @param codeUnit - The code unit, or NaN past the end of the string.
|
|
1463
|
+
* @returns True for a low surrogate.
|
|
1464
|
+
*/
|
|
1465
|
+
function isLowSurrogate(codeUnit) {
|
|
1466
|
+
return codeUnit >= 56320 && codeUnit <= 57343;
|
|
1467
|
+
}
|
|
1468
|
+
/**
|
|
1469
|
+
* Tells whether a string has no lone surrogates, so its UTF-8 encoding is a
|
|
1470
|
+
* faithful and reversible spelling of it.
|
|
1471
|
+
* @param value - The string to check.
|
|
1472
|
+
* @returns True when every surrogate is part of a complete pair.
|
|
1473
|
+
*/
|
|
1474
|
+
function isWellFormedUnicode(value) {
|
|
1475
|
+
for (let index = 0; index < value.length; index++) {
|
|
1476
|
+
const codeUnit = value.charCodeAt(index);
|
|
1477
|
+
if (isHighSurrogate(codeUnit)) {
|
|
1478
|
+
if (!isLowSurrogate(value.charCodeAt(index + 1))) return false;
|
|
1479
|
+
index++;
|
|
1480
|
+
} else if (isLowSurrogate(codeUnit)) return false;
|
|
1481
|
+
}
|
|
1482
|
+
return true;
|
|
1483
|
+
}
|
|
1484
|
+
/**
|
|
1485
|
+
* Spells bytes as lowercase hexadecimal.
|
|
1486
|
+
* @param bytes - The bytes to spell.
|
|
1487
|
+
* @returns Two hexadecimal characters per byte.
|
|
1488
|
+
*/
|
|
1489
|
+
function hex(bytes) {
|
|
1490
|
+
let encoded = "";
|
|
1491
|
+
for (const byte of bytes) encoded += byte.toString(16).padStart(2, "0");
|
|
1492
|
+
return encoded;
|
|
1493
|
+
}
|
|
1494
|
+
/**
|
|
1495
|
+
* Encodes a raw server-issued id into a token that fits the wire grammar
|
|
1496
|
+
* whatever characters the server used: hex of its UTF-8 bytes, marked `s`.
|
|
1497
|
+
* @param raw - The id exactly as the server sent it.
|
|
1498
|
+
* @param domain - The domain it belongs to, for error messages.
|
|
1499
|
+
* @returns The `s`-prefixed hexadecimal token.
|
|
1500
|
+
* @throws {IdentityValidationError} When the id is empty, ill-formed, too large or contains NUL.
|
|
1501
|
+
*/
|
|
1502
|
+
function encodeRawIdentity(raw, domain) {
|
|
1503
|
+
if (raw.length === 0) return fail("empty", `${domain} identity must not be empty.`, domain);
|
|
1504
|
+
if (!isWellFormedUnicode(raw)) return fail("invalid-shape", `The server ${domain} identity contains ill-formed Unicode.`, domain);
|
|
1505
|
+
const bytes = new TextEncoder().encode(raw);
|
|
1506
|
+
if (bytes.byteLength > RAW_ID_LIMIT_BYTES || raw.includes("\0")) return fail("invalid-shape", `The server ${domain} identity is not a valid wire value.`, domain);
|
|
1507
|
+
return `s${hex(bytes)}`;
|
|
1508
|
+
}
|
|
1509
|
+
/**
|
|
1510
|
+
* Encodes a JSON-RPC request id, which the protocol allows to be a string or
|
|
1511
|
+
* an integer, keeping the two kinds apart with different token markers so
|
|
1512
|
+
* the original can be given back unchanged.
|
|
1513
|
+
* @param raw - The id as the server sent it.
|
|
1514
|
+
* @returns An `s`-prefixed token for a string, an `n`-prefixed one for an integer.
|
|
1515
|
+
* @throws {IdentityValidationError} When the id is neither, or too large.
|
|
1516
|
+
*/
|
|
1517
|
+
function encodeRawJsonRpcRequestId(raw) {
|
|
1518
|
+
if (typeof raw === "string") return encodeRawIdentity(raw, "json-rpc-request");
|
|
1519
|
+
if (!Number.isSafeInteger(raw)) return fail("invalid-shape", "The server json-rpc-request identity must be a string or integer.", "json-rpc-request");
|
|
1520
|
+
const encoded = new TextEncoder().encode(Object.is(raw, -0) ? "-0" : String(raw));
|
|
1521
|
+
if (encoded.byteLength > RAW_ID_LIMIT_BYTES) return fail("invalid-shape", "The server json-rpc-request identity is too large.", "json-rpc-request");
|
|
1522
|
+
return `n${hex(encoded)}`;
|
|
1523
|
+
}
|
|
1524
|
+
/**
|
|
1525
|
+
* Reads the domain of an untrusted value that should be a wire identity.
|
|
1526
|
+
* @param value - The untrusted value.
|
|
1527
|
+
* @returns The identity domain the value names.
|
|
1528
|
+
* @throws {IdentityValidationError} When the value is not a canonical workbench identity.
|
|
1529
|
+
*/
|
|
1530
|
+
function identityDomain(value) {
|
|
1531
|
+
if (typeof value !== "string") return fail("invalid-shape", "Identity must be a string.");
|
|
1532
|
+
const segments = wireSegments(value);
|
|
1533
|
+
if (segments === null || !isIdentityDomain(segments.domain)) return fail("invalid-shape", "Identity is not a canonical workbench identity.");
|
|
1534
|
+
return segments.domain;
|
|
1535
|
+
}
|
|
1536
|
+
/**
|
|
1537
|
+
* The longest canonical item id, so a schema of another package bounds an item id as this one does.
|
|
1538
|
+
* @returns The length, in characters.
|
|
1539
|
+
*/
|
|
1540
|
+
function canonicalItemIdMaxLength() {
|
|
1541
|
+
return CANONICAL_ITEM_ID_MAX_LENGTH;
|
|
1542
|
+
}
|
|
1543
|
+
// ../codex-app-server/src/shared/rules/identity-correlations.ts
|
|
1544
|
+
const TEXT_LIMIT = 256;
|
|
1545
|
+
const CORRELATION_KEYS = [
|
|
1546
|
+
"child",
|
|
1547
|
+
"epoch",
|
|
1548
|
+
"requestId"
|
|
1549
|
+
];
|
|
1550
|
+
const TOOL_CORRELATION_KEYS = [
|
|
1551
|
+
"child",
|
|
1552
|
+
"epoch",
|
|
1553
|
+
"threadId",
|
|
1554
|
+
"turnId",
|
|
1555
|
+
"callId",
|
|
1556
|
+
"namespace",
|
|
1557
|
+
"tool",
|
|
1558
|
+
"manifestHash"
|
|
1559
|
+
];
|
|
1560
|
+
/**
|
|
1561
|
+
* Stable identity for one logical dynamic-tool call across wire retries and owners.
|
|
1562
|
+
* @param call - The correlation to key.
|
|
1563
|
+
* @returns A JSON array of every field, in declaration order, as one string.
|
|
1564
|
+
*/
|
|
1565
|
+
function logicalToolCallKey(call) {
|
|
1566
|
+
return JSON.stringify([
|
|
1567
|
+
call.child,
|
|
1568
|
+
call.epoch,
|
|
1569
|
+
call.threadId,
|
|
1570
|
+
call.turnId,
|
|
1571
|
+
call.callId,
|
|
1572
|
+
call.namespace,
|
|
1573
|
+
call.tool,
|
|
1574
|
+
call.manifestHash
|
|
1575
|
+
]);
|
|
1576
|
+
}
|
|
1577
|
+
/**
|
|
1578
|
+
* Tells whether a value is a non-array object, so its keys can be read.
|
|
1579
|
+
* @param value - The untrusted value.
|
|
1580
|
+
* @returns True for a plain record shape.
|
|
1581
|
+
*/
|
|
1582
|
+
function isRecord(value) {
|
|
1583
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
1584
|
+
}
|
|
1585
|
+
/**
|
|
1586
|
+
* Refuses a record that carries any key, string or symbol, outside `keys`.
|
|
1587
|
+
* @param record - The record to inspect.
|
|
1588
|
+
* @param keys - The only keys allowed.
|
|
1589
|
+
* @throws {IdentityValidationError} As `extra-field` when another key is present.
|
|
1590
|
+
*/
|
|
1591
|
+
function assertOnlyKeys(record, keys) {
|
|
1592
|
+
for (const key of Reflect.ownKeys(record)) if (typeof key !== "string" || !keys.includes(key)) fail("extra-field", "An identity correlation contains an unexpected field.");
|
|
1593
|
+
}
|
|
1594
|
+
/**
|
|
1595
|
+
* Refuses a record missing any of `keys` as an own property.
|
|
1596
|
+
* @param record - The record to inspect.
|
|
1597
|
+
* @param keys - The keys that must all be present.
|
|
1598
|
+
* @throws {IdentityValidationError} As `invalid-shape` naming the first missing key.
|
|
1599
|
+
*/
|
|
1600
|
+
function assertAllKeys(record, keys) {
|
|
1601
|
+
for (const key of keys) if (!Object.prototype.hasOwnProperty.call(record, key)) fail("invalid-shape", `Missing correlation field "${key}".`);
|
|
1602
|
+
}
|
|
1603
|
+
/**
|
|
1604
|
+
* Narrows an untrusted value to a record with exactly the given keys.
|
|
1605
|
+
* @param value - The untrusted value.
|
|
1606
|
+
* @param keys - The complete key set the record must have.
|
|
1607
|
+
* @returns The value as a record.
|
|
1608
|
+
* @throws {IdentityValidationError} When it is not a record or its key set differs.
|
|
1609
|
+
*/
|
|
1610
|
+
function requireRecord(value, keys) {
|
|
1611
|
+
if (!isRecord(value)) return fail("invalid-shape", "An identity correlation must be a record.");
|
|
1612
|
+
assertOnlyKeys(value, keys);
|
|
1613
|
+
assertAllKeys(value, keys);
|
|
1614
|
+
return value;
|
|
1615
|
+
}
|
|
1616
|
+
/**
|
|
1617
|
+
* Validates a bounded text field of a correlation: non-empty, trimmed, short,
|
|
1618
|
+
* and free of NUL.
|
|
1619
|
+
* @param value - The untrusted value.
|
|
1620
|
+
* @param field - The field name, for the error message.
|
|
1621
|
+
* @returns The text unchanged.
|
|
1622
|
+
* @throws {IdentityValidationError} As `invalid-field` when the text is unacceptable.
|
|
1623
|
+
*/
|
|
1624
|
+
function assertText(value, field) {
|
|
1625
|
+
if (typeof value !== "string" || value.length === 0 || value.trim() !== value || value.length > TEXT_LIMIT) return fail("invalid-field", `${field} must be a non-empty bounded string.`);
|
|
1626
|
+
if (value.includes("\0")) return fail("invalid-field", `${field} must not contain NUL.`);
|
|
1627
|
+
return value;
|
|
1628
|
+
}
|
|
1629
|
+
/**
|
|
1630
|
+
* Refuses a correlation that names another child or an earlier epoch.
|
|
1631
|
+
* @param child - The child the correlation names.
|
|
1632
|
+
* @param epoch - The epoch the correlation names.
|
|
1633
|
+
* @param currentChild - This session's child.
|
|
1634
|
+
* @param currentEpoch - This session's epoch.
|
|
1635
|
+
* @throws {IdentityValidationError} As `wrong-child` or `stale-epoch`.
|
|
1636
|
+
*/
|
|
1637
|
+
function assertCurrent(child, epoch, currentChild, currentEpoch) {
|
|
1638
|
+
if (child !== currentChild) fail("wrong-child", "The correlation belongs to another child.");
|
|
1639
|
+
if (epoch !== currentEpoch) fail("stale-epoch", "The correlation belongs to a stale child epoch.");
|
|
1640
|
+
}
|
|
1641
|
+
/**
|
|
1642
|
+
* Refuses an identity this session never issued, whatever its shape.
|
|
1643
|
+
* @param value - The branded identity.
|
|
1644
|
+
* @param domain - Its domain.
|
|
1645
|
+
* @param issued - The issuance ledger, by domain.
|
|
1646
|
+
* @throws {IdentityValidationError} As `unissued` when the ledger lacks it.
|
|
1647
|
+
*/
|
|
1648
|
+
function assertIssued(value, domain, issued) {
|
|
1649
|
+
if (!issued.get(domain)?.has(value)) fail("unissued", `The ${domain} identity was not issued by this workbench session.`, domain);
|
|
1650
|
+
}
|
|
1651
|
+
/**
|
|
1652
|
+
* Decodes a wire request correlation and proves every part of it current
|
|
1653
|
+
* and issued here.
|
|
1654
|
+
* @param value - The untrusted record.
|
|
1655
|
+
* @param childId - This session's child.
|
|
1656
|
+
* @param epoch - This session's epoch.
|
|
1657
|
+
* @param issued - The issuance ledger, by domain.
|
|
1658
|
+
* @returns The frozen correlation.
|
|
1659
|
+
* @throws {IdentityValidationError} When any field is malformed, foreign, stale or unissued.
|
|
1660
|
+
*/
|
|
1661
|
+
function parseWireRequestCorrelationValue(value, childId, epoch, issued) {
|
|
1662
|
+
const record = requireRecord(value, CORRELATION_KEYS);
|
|
1663
|
+
const child = parseValue(record["child"], "child");
|
|
1664
|
+
const parsedEpoch = parseEpochValue(record["epoch"], child);
|
|
1665
|
+
const requestId = parseValue(record["requestId"], "json-rpc-request");
|
|
1666
|
+
assertCurrent(child, parsedEpoch, childId, epoch);
|
|
1667
|
+
assertIssued(child, "child", issued);
|
|
1668
|
+
assertIssued(parsedEpoch, "epoch", issued);
|
|
1669
|
+
assertIssued(requestId, "json-rpc-request", issued);
|
|
1670
|
+
return Object.freeze({
|
|
1671
|
+
child,
|
|
1672
|
+
epoch: parsedEpoch,
|
|
1673
|
+
requestId
|
|
1674
|
+
});
|
|
1675
|
+
}
|
|
1676
|
+
/**
|
|
1677
|
+
* Decodes a logical tool-call correlation and proves every identity in it
|
|
1678
|
+
* current and issued here, and every text field bounded.
|
|
1679
|
+
* @param value - The untrusted record.
|
|
1680
|
+
* @param childId - This session's child.
|
|
1681
|
+
* @param epoch - This session's epoch.
|
|
1682
|
+
* @param issued - The issuance ledger, by domain.
|
|
1683
|
+
* @returns The frozen correlation.
|
|
1684
|
+
* @throws {IdentityValidationError} When any field is malformed, foreign, stale or unissued.
|
|
1685
|
+
*/
|
|
1686
|
+
function parseLogicalToolCallCorrelationValue(value, childId, epoch, issued) {
|
|
1687
|
+
const record = requireRecord(value, TOOL_CORRELATION_KEYS);
|
|
1688
|
+
const child = parseValue(record["child"], "child");
|
|
1689
|
+
const parsedEpoch = parseEpochValue(record["epoch"], child);
|
|
1690
|
+
const threadId = parseValue(record["threadId"], "thread");
|
|
1691
|
+
const turnId = parseValue(record["turnId"], "turn");
|
|
1692
|
+
const callId = parseValue(record["callId"], "dynamic-tool-call");
|
|
1693
|
+
assertCurrent(child, parsedEpoch, childId, epoch);
|
|
1694
|
+
assertIssued(child, "child", issued);
|
|
1695
|
+
assertIssued(parsedEpoch, "epoch", issued);
|
|
1696
|
+
assertIssued(threadId, "thread", issued);
|
|
1697
|
+
assertIssued(turnId, "turn", issued);
|
|
1698
|
+
assertIssued(callId, "dynamic-tool-call", issued);
|
|
1699
|
+
return Object.freeze({
|
|
1700
|
+
child,
|
|
1701
|
+
epoch: parsedEpoch,
|
|
1702
|
+
threadId,
|
|
1703
|
+
turnId,
|
|
1704
|
+
callId,
|
|
1705
|
+
namespace: assertText(record["namespace"], "namespace"),
|
|
1706
|
+
tool: assertText(record["tool"], "tool"),
|
|
1707
|
+
manifestHash: assertText(record["manifestHash"], "manifestHash")
|
|
1708
|
+
});
|
|
1709
|
+
}
|
|
1710
|
+
const OPERATION_TOKEN_PATTERN = new RegExp(`^([A-Za-z0-9][A-Za-z0-9._~-]{0,8192})\\.(h[0-9a-f]{32})$`, "u");
|
|
1711
|
+
const OPERATION_NONCE_PATTERN = /^[0-9a-f]{32}$/u;
|
|
1712
|
+
/**
|
|
1713
|
+
* Spells an operation identity from the epoch it is issued in and a nonce.
|
|
1714
|
+
* @param epoch - The current child epoch.
|
|
1715
|
+
* @param nonce - Thirty-two lowercase hexadecimal characters.
|
|
1716
|
+
* @returns The branded operation identity.
|
|
1717
|
+
* @throws {IdentityValidationError} When the nonce is malformed or the value exceeds the byte limit.
|
|
1718
|
+
*/
|
|
1719
|
+
function operationWireValue(epoch, nonce) {
|
|
1720
|
+
if (typeof nonce !== "string" || !OPERATION_NONCE_PATTERN.test(nonce)) return fail("invalid-shape", "Operation identity nonce must be 32 lowercase hexadecimal characters.", "operation");
|
|
1721
|
+
const value = wireValue(prefixOf(epoch), "operation", `${tokenOf(epoch)}.h${nonce}`);
|
|
1722
|
+
if (new TextEncoder().encode(value).byteLength > 128) return fail("invalid-shape", `Operation identity exceeds 128 UTF-8 bytes.`, "operation");
|
|
1723
|
+
return value;
|
|
1724
|
+
}
|
|
1725
|
+
/**
|
|
1726
|
+
* Names why an operation's epoch token is not the current one: it belongs to
|
|
1727
|
+
* an earlier epoch of the same child, or to another child altogether.
|
|
1728
|
+
* @param epochToken - The epoch token carried by the operation.
|
|
1729
|
+
* @param childId - The current child.
|
|
1730
|
+
* @returns Never; always refuses with the matching code.
|
|
1731
|
+
* @throws {IdentityValidationError} Always, as `stale-epoch` or `wrong-child`.
|
|
1732
|
+
*/
|
|
1733
|
+
function refuseForeignEpoch(epochToken, childId) {
|
|
1734
|
+
if (epochToken.startsWith(`${tokenOf(childId)}.`)) return fail("stale-epoch", "The operation belongs to a stale child epoch.", "operation");
|
|
1735
|
+
return fail("wrong-child", "The operation belongs to another child.", "operation");
|
|
1736
|
+
}
|
|
1737
|
+
/**
|
|
1738
|
+
* Validates an operation identity against the current child and epoch and
|
|
1739
|
+
* returns its token.
|
|
1740
|
+
* @param value - The untrusted value.
|
|
1741
|
+
* @param childId - The current child.
|
|
1742
|
+
* @param epoch - The current epoch.
|
|
1743
|
+
* @returns The token segment of the operation identity.
|
|
1744
|
+
* @throws {IdentityValidationError} When the value is malformed, oversized, stale or foreign.
|
|
1745
|
+
*/
|
|
1746
|
+
function requireOperationToken(value, childId, epoch) {
|
|
1747
|
+
const token = requireToken(value, "operation");
|
|
1748
|
+
if (new TextEncoder().encode(String(value)).byteLength > 128) return fail("invalid-shape", `Operation identity exceeds 128 UTF-8 bytes.`, "operation");
|
|
1749
|
+
const epochToken = OPERATION_TOKEN_PATTERN.exec(token)?.[1];
|
|
1750
|
+
if (epochToken === void 0 || !EPOCH_TOKEN_PATTERN.test(epochToken)) return fail("invalid-shape", "Operation identity must carry a durable epoch token.", "operation");
|
|
1751
|
+
if (epochToken !== tokenOf(epoch)) return refuseForeignEpoch(epochToken, childId);
|
|
1752
|
+
return token;
|
|
1753
|
+
}
|
|
1754
|
+
// ../codex-app-server/src/shared/rules/identity-ledger.ts
|
|
1755
|
+
/** The domains whose identities may be handed back to Codex on the wire. */
|
|
1756
|
+
const CODEX_WIRE_DOMAINS = /* @__PURE__ */ new Set([
|
|
1757
|
+
"thread",
|
|
1758
|
+
"turn",
|
|
1759
|
+
"item",
|
|
1760
|
+
"queued-submission",
|
|
1761
|
+
"login",
|
|
1762
|
+
"json-rpc-request",
|
|
1763
|
+
"dynamic-tool-call",
|
|
1764
|
+
"approval"
|
|
1765
|
+
]);
|
|
1766
|
+
/**
|
|
1767
|
+
* Records a token as issued in `domain` and remembers the raw value it stands
|
|
1768
|
+
* for, so it can later be proven issued and serialized back.
|
|
1769
|
+
* @param ledger - The ledger to write to.
|
|
1770
|
+
* @param domain - The identity domain.
|
|
1771
|
+
* @param token - The token to spell the wire value from.
|
|
1772
|
+
* @param raw - The value the token stands for: the app-server's own value, or for a server
|
|
1773
|
+
* identity the unprefixed nonce the token was spelled from.
|
|
1774
|
+
* @returns The branded identity.
|
|
1775
|
+
*/
|
|
1776
|
+
function issue(ledger, domain, token, raw) {
|
|
1777
|
+
const value = wireValue(prefixOf(ledger.childId), domain, token);
|
|
1778
|
+
let values = ledger.issued.get(domain);
|
|
1779
|
+
if (values === void 0) {
|
|
1780
|
+
values = /* @__PURE__ */ new Set();
|
|
1781
|
+
ledger.issued.set(domain, values);
|
|
1782
|
+
}
|
|
1783
|
+
values.add(value);
|
|
1784
|
+
ledger.rawByIdentity.set(value, raw);
|
|
1785
|
+
return value;
|
|
1786
|
+
}
|
|
1787
|
+
/**
|
|
1788
|
+
* Records an already-branded identity as issued.
|
|
1789
|
+
* @param ledger - The ledger to write to.
|
|
1790
|
+
* @param domain - The identity domain.
|
|
1791
|
+
* @param value - The branded identity.
|
|
1792
|
+
* @param raw - The app-server's raw value, or the token for a server identity.
|
|
1793
|
+
* @returns The same identity.
|
|
1794
|
+
*/
|
|
1795
|
+
function issueExisting(ledger, domain, value, raw) {
|
|
1796
|
+
return issue(ledger, domain, tokenOf(value), raw);
|
|
1797
|
+
}
|
|
1798
|
+
/**
|
|
1799
|
+
* Mints and records a server-owned identity.
|
|
1800
|
+
* @param ledger - The ledger to write to.
|
|
1801
|
+
* @param domain - The identity domain.
|
|
1802
|
+
* @returns The fresh branded identity.
|
|
1803
|
+
*/
|
|
1804
|
+
function mint(ledger, domain) {
|
|
1805
|
+
const raw = mintToken();
|
|
1806
|
+
return issue(ledger, domain, `h${raw}`, raw);
|
|
1807
|
+
}
|
|
1808
|
+
/**
|
|
1809
|
+
* Mints and records a new epoch for the ledger's child.
|
|
1810
|
+
* @param ledger - The ledger to write to.
|
|
1811
|
+
* @returns The fresh branded epoch.
|
|
1812
|
+
*/
|
|
1813
|
+
function mintEpoch(ledger) {
|
|
1814
|
+
const nextEpoch = mintEpochValue(ledger.childId);
|
|
1815
|
+
issueExisting(ledger, "epoch", nextEpoch, tokenOf(nextEpoch));
|
|
1816
|
+
return nextEpoch;
|
|
1817
|
+
}
|
|
1818
|
+
/**
|
|
1819
|
+
* Mints an operation identity bound to the current epoch, retrying a bounded
|
|
1820
|
+
* number of times should the random nonce collide with one already issued.
|
|
1821
|
+
* @param ledger - The ledger to write to.
|
|
1822
|
+
* @returns The fresh branded operation identity.
|
|
1823
|
+
* @throws {IdentityValidationError} As `issuance-exhausted` after too many collisions.
|
|
1824
|
+
*/
|
|
1825
|
+
function mintOperation(ledger) {
|
|
1826
|
+
for (let attempt = 0; attempt < 16; attempt++) {
|
|
1827
|
+
const value = operationWireValue(ledger.epoch, mintToken());
|
|
1828
|
+
if (ledger.issued.get("operation")?.has(value) !== true) return issue(ledger, "operation", tokenOf(value), value);
|
|
1829
|
+
}
|
|
1830
|
+
return fail("issuance-exhausted", `Could not issue a unique operation identity after 16 attempts.`, "operation");
|
|
1831
|
+
}
|
|
1832
|
+
/**
|
|
1833
|
+
* Adopts a raw server-issued string id into `domain`, recording it as issued.
|
|
1834
|
+
* @param ledger - The ledger to write to.
|
|
1835
|
+
* @param domain - The identity domain.
|
|
1836
|
+
* @param rawValue - The id as the server sent it.
|
|
1837
|
+
* @returns The branded identity.
|
|
1838
|
+
* @throws {IdentityValidationError} When the raw id is not an acceptable string.
|
|
1839
|
+
*/
|
|
1840
|
+
function adopt(ledger, domain, rawValue) {
|
|
1841
|
+
if (typeof rawValue !== "string") return fail("invalid-shape", `The server ${domain} identity must be a string.`, domain);
|
|
1842
|
+
return issue(ledger, domain, encodeRawIdentity(rawValue, domain), rawValue);
|
|
1843
|
+
}
|
|
1844
|
+
/**
|
|
1845
|
+
* Tells whether a raw value is a JSON-RPC id the protocol allows: a string
|
|
1846
|
+
* or a safe integer.
|
|
1847
|
+
* @param rawValue - The id as the server sent it.
|
|
1848
|
+
* @returns True when it may be adopted.
|
|
1849
|
+
*/
|
|
1850
|
+
function isJsonRpcRequestIdWireValue(rawValue) {
|
|
1851
|
+
return typeof rawValue === "string" || Number.isSafeInteger(rawValue);
|
|
1852
|
+
}
|
|
1853
|
+
/**
|
|
1854
|
+
* Adopts a raw server-issued JSON-RPC request id, which may be a string or an
|
|
1855
|
+
* integer, recording it as issued.
|
|
1856
|
+
* @param ledger - The ledger to write to.
|
|
1857
|
+
* @param rawValue - The id as the server sent it.
|
|
1858
|
+
* @returns The branded request id.
|
|
1859
|
+
* @throws {IdentityValidationError} When the id is neither a string nor a safe integer.
|
|
1860
|
+
*/
|
|
1861
|
+
function adoptJsonRpcRequestId(ledger, rawValue) {
|
|
1862
|
+
if (!isJsonRpcRequestIdWireValue(rawValue)) return fail("invalid-shape", "The server json-rpc-request identity must be a string or integer.", "json-rpc-request");
|
|
1863
|
+
return issue(ledger, "json-rpc-request", encodeRawJsonRpcRequestId(rawValue), rawValue);
|
|
1864
|
+
}
|
|
1865
|
+
/**
|
|
1866
|
+
* Validates one raw response identity without recording it yet.
|
|
1867
|
+
* @param domain - The identity domain.
|
|
1868
|
+
* @param rawValue - The id as the server sent it.
|
|
1869
|
+
* @returns The staged identity, ready to commit.
|
|
1870
|
+
* @throws {IdentityValidationError} When the raw id is not an acceptable string.
|
|
1871
|
+
*/
|
|
1872
|
+
function stageResponseIdentity(domain, rawValue) {
|
|
1873
|
+
if (typeof rawValue !== "string") return fail("invalid-shape", `The server ${domain} identity must be a string.`, domain);
|
|
1874
|
+
return {
|
|
1875
|
+
domain,
|
|
1876
|
+
raw: rawValue,
|
|
1877
|
+
token: encodeRawIdentity(rawValue, domain)
|
|
1878
|
+
};
|
|
1879
|
+
}
|
|
1880
|
+
/**
|
|
1881
|
+
* Stages every raw identity of one domain from a response.
|
|
1882
|
+
* @param domain - The identity domain.
|
|
1883
|
+
* @param values - The raw ids, absent when the response carried none.
|
|
1884
|
+
* @returns The staged identities in the same order.
|
|
1885
|
+
*/
|
|
1886
|
+
function stageResponseIdentities(domain, values) {
|
|
1887
|
+
return (values ?? []).map((value) => stageResponseIdentity(domain, value));
|
|
1888
|
+
}
|
|
1889
|
+
/**
|
|
1890
|
+
* Records staged identities as issued.
|
|
1891
|
+
* @param ledger - The ledger to write to.
|
|
1892
|
+
* @param values - The staged identities.
|
|
1893
|
+
* @returns The branded identities in the same order.
|
|
1894
|
+
*/
|
|
1895
|
+
function commitResponseIdentities(ledger, values) {
|
|
1896
|
+
return values.map(({ domain, raw, token }) => issue(ledger, domain, token, raw));
|
|
1897
|
+
}
|
|
1898
|
+
/**
|
|
1899
|
+
* Validates a complete decoded response before adopting any identity from it.
|
|
1900
|
+
* Staging every domain first makes a hostile late field fail without trusting
|
|
1901
|
+
* the valid identities that preceded it in the response.
|
|
1902
|
+
* @param ledger - The ledger to write to.
|
|
1903
|
+
* @param batch - The raw identities collected from one response.
|
|
1904
|
+
* @returns The branded identities, frozen, in the batch's order.
|
|
1905
|
+
* @throws {IdentityValidationError} When any raw identity is unacceptable.
|
|
1906
|
+
*/
|
|
1907
|
+
function adoptCodexResponseIdentities(ledger, batch) {
|
|
1908
|
+
const threadIds = stageResponseIdentities("thread", batch.threadIds);
|
|
1909
|
+
const turnIds = stageResponseIdentities("turn", batch.turnIds);
|
|
1910
|
+
const itemIds = stageResponseIdentities("item", batch.itemIds);
|
|
1911
|
+
const queuedSubmissionIds = stageResponseIdentities("queued-submission", batch.queuedSubmissionIds);
|
|
1912
|
+
const loginIds = stageResponseIdentities("login", batch.loginIds);
|
|
1913
|
+
return Object.freeze({
|
|
1914
|
+
threadIds: Object.freeze(commitResponseIdentities(ledger, threadIds)),
|
|
1915
|
+
turnIds: Object.freeze(commitResponseIdentities(ledger, turnIds)),
|
|
1916
|
+
itemIds: Object.freeze(commitResponseIdentities(ledger, itemIds)),
|
|
1917
|
+
queuedSubmissionIds: Object.freeze(commitResponseIdentities(ledger, queuedSubmissionIds)),
|
|
1918
|
+
loginIds: Object.freeze(commitResponseIdentities(ledger, loginIds))
|
|
1919
|
+
});
|
|
1920
|
+
}
|
|
1921
|
+
/**
|
|
1922
|
+
* Parses an untrusted value as an identity of `domain` that this ledger issued.
|
|
1923
|
+
* @param ledger - The ledger to check against.
|
|
1924
|
+
* @param domain - The identity domain.
|
|
1925
|
+
* @param value - The untrusted value.
|
|
1926
|
+
* @returns The branded identity.
|
|
1927
|
+
* @throws {IdentityValidationError} When malformed or unissued.
|
|
1928
|
+
*/
|
|
1929
|
+
function parseIssued(ledger, domain, value) {
|
|
1930
|
+
const parsed = parseValue(value, domain);
|
|
1931
|
+
assertIssued(parsed, domain, ledger.issued);
|
|
1932
|
+
return parsed;
|
|
1933
|
+
}
|
|
1934
|
+
/**
|
|
1935
|
+
* Parses an untrusted value as an operation identity issued in the current
|
|
1936
|
+
* epoch of this ledger.
|
|
1937
|
+
* @param ledger - The ledger to check against.
|
|
1938
|
+
* @param value - The untrusted value.
|
|
1939
|
+
* @returns The branded operation identity.
|
|
1940
|
+
* @throws {IdentityValidationError} When malformed, stale, foreign or unissued.
|
|
1941
|
+
*/
|
|
1942
|
+
function parseOperation(ledger, value) {
|
|
1943
|
+
const parsed = parseValue(value, "operation");
|
|
1944
|
+
requireOperationToken(parsed, ledger.childId, ledger.epoch);
|
|
1945
|
+
assertIssued(parsed, "operation", ledger.issued);
|
|
1946
|
+
return parsed;
|
|
1947
|
+
}
|
|
1948
|
+
/**
|
|
1949
|
+
* Parses an untrusted value as the current child epoch of this ledger.
|
|
1950
|
+
* @param ledger - The ledger to check against.
|
|
1951
|
+
* @param value - The untrusted value.
|
|
1952
|
+
* @returns The branded epoch.
|
|
1953
|
+
* @throws {IdentityValidationError} When malformed, foreign or unissued.
|
|
1954
|
+
*/
|
|
1955
|
+
function parseIssuedEpoch(ledger, value) {
|
|
1956
|
+
const parsed = parseEpochValue(value, ledger.childId);
|
|
1957
|
+
assertIssued(parsed, "epoch", ledger.issued);
|
|
1958
|
+
return parsed;
|
|
1959
|
+
}
|
|
1960
|
+
/**
|
|
1961
|
+
* Resolves a raw Codex id to the identity this ledger already adopted for it,
|
|
1962
|
+
* refusing an id that was never adopted.
|
|
1963
|
+
* @param ledger - The ledger to check against.
|
|
1964
|
+
* @param domain - The identity domain.
|
|
1965
|
+
* @param rawValue - The id as the server sent it.
|
|
1966
|
+
* @returns The branded identity.
|
|
1967
|
+
* @throws {IdentityValidationError} When the raw id is unacceptable or unissued.
|
|
1968
|
+
*/
|
|
1969
|
+
function resolve(ledger, domain, rawValue) {
|
|
1970
|
+
if (typeof rawValue !== "string") return fail("invalid-shape", `The server ${domain} identity must be a string.`, domain);
|
|
1971
|
+
return parseIssued(ledger, domain, wireValue(prefixOf(ledger.childId), domain, encodeRawIdentity(rawValue, domain)));
|
|
1972
|
+
}
|
|
1973
|
+
/**
|
|
1974
|
+
* Gives back the raw wire value an issued identity stands for.
|
|
1975
|
+
* @param ledger - The ledger to read from.
|
|
1976
|
+
* @param value - The branded identity.
|
|
1977
|
+
* @param domain - Its domain, already checked by the caller.
|
|
1978
|
+
* @returns The raw value recorded at issuance.
|
|
1979
|
+
* @throws {IdentityValidationError} As `unissued` when the ledger has no raw value for it.
|
|
1980
|
+
*/
|
|
1981
|
+
function rawValueOf(ledger, value, domain) {
|
|
1982
|
+
assertIssued(value, domain, ledger.issued);
|
|
1983
|
+
const raw = ledger.rawByIdentity.get(value);
|
|
1984
|
+
if (raw === void 0) return fail("unissued", "Identity has no trusted wire value.", domain);
|
|
1985
|
+
return raw;
|
|
1986
|
+
}
|
|
1987
|
+
/**
|
|
1988
|
+
* Serializes a Codex identity back to the string the server knows it by.
|
|
1989
|
+
* @param ledger - The ledger to read from.
|
|
1990
|
+
* @param value - The branded identity.
|
|
1991
|
+
* @returns The server's raw id as a string.
|
|
1992
|
+
* @throws {IdentityValidationError} When the identity is not a Codex wire identity or unissued.
|
|
1993
|
+
*/
|
|
1994
|
+
function serialize(ledger, value) {
|
|
1995
|
+
const domain = identityDomain(value);
|
|
1996
|
+
if (!CODEX_WIRE_DOMAINS.has(domain)) return fail("wrong-domain", "Identity is not a Codex wire identity.", domain);
|
|
1997
|
+
return String(rawValueOf(ledger, value, domain));
|
|
1998
|
+
}
|
|
1999
|
+
/**
|
|
2000
|
+
* Serializes a JSON-RPC request identity back to the exact value, string or
|
|
2001
|
+
* integer, the server used.
|
|
2002
|
+
* @param ledger - The ledger to read from.
|
|
2003
|
+
* @param value - The branded request id.
|
|
2004
|
+
* @returns The server's raw id.
|
|
2005
|
+
* @throws {IdentityValidationError} When the identity is not a request id or unissued.
|
|
2006
|
+
*/
|
|
2007
|
+
function serializeJsonRpc(ledger, value) {
|
|
2008
|
+
const domain = identityDomain(value);
|
|
2009
|
+
if (domain !== "json-rpc-request") return fail("wrong-domain", "Identity is not a JSON-RPC request identity.", domain);
|
|
2010
|
+
return rawValueOf(ledger, value, domain);
|
|
2011
|
+
}
|
|
2012
|
+
/**
|
|
2013
|
+
* Builds a wire request correlation for a request id this ledger issued.
|
|
2014
|
+
* @param ledger - The ledger to check against.
|
|
2015
|
+
* @param input - The request id.
|
|
2016
|
+
* @returns The frozen correlation bound to the current child and epoch.
|
|
2017
|
+
* @throws {IdentityValidationError} When the request id was not issued here.
|
|
2018
|
+
*/
|
|
2019
|
+
function createWireRequestCorrelation(ledger, input) {
|
|
2020
|
+
const requestId = parseIssued(ledger, "json-rpc-request", input.requestId);
|
|
2021
|
+
return Object.freeze({
|
|
2022
|
+
child: ledger.childId,
|
|
2023
|
+
epoch: ledger.epoch,
|
|
2024
|
+
requestId
|
|
2025
|
+
});
|
|
2026
|
+
}
|
|
2027
|
+
/**
|
|
2028
|
+
* Builds a logical tool-call correlation from identities this ledger issued
|
|
2029
|
+
* and bounded text fields.
|
|
2030
|
+
* @param ledger - The ledger to check against.
|
|
2031
|
+
* @param input - The identities and text of the call.
|
|
2032
|
+
* @returns The frozen correlation bound to the current child and epoch.
|
|
2033
|
+
* @throws {IdentityValidationError} When an identity was not issued here or a text field is unacceptable.
|
|
2034
|
+
*/
|
|
2035
|
+
function createLogicalToolCallCorrelation(ledger, input) {
|
|
2036
|
+
const threadId = parseIssued(ledger, "thread", input.threadId);
|
|
2037
|
+
const turnId = parseIssued(ledger, "turn", input.turnId);
|
|
2038
|
+
const callId = parseIssued(ledger, "dynamic-tool-call", input.callId);
|
|
2039
|
+
return Object.freeze({
|
|
2040
|
+
child: ledger.childId,
|
|
2041
|
+
epoch: ledger.epoch,
|
|
2042
|
+
threadId,
|
|
2043
|
+
turnId,
|
|
2044
|
+
callId,
|
|
2045
|
+
namespace: assertText(input.namespace, "namespace"),
|
|
2046
|
+
tool: assertText(input.tool, "tool"),
|
|
2047
|
+
manifestHash: assertText(input.manifestHash, "manifestHash")
|
|
2048
|
+
});
|
|
2049
|
+
}
|
|
2050
|
+
// ../codex-app-server/src/shared/rules/workbench-identity.ts
|
|
2051
|
+
/**
|
|
2052
|
+
* Builds the validator: the epoch facts every owner may compare against.
|
|
2053
|
+
* @param ledger - The ledger the validator reads.
|
|
2054
|
+
* @returns A frozen validator.
|
|
2055
|
+
*/
|
|
2056
|
+
function createValidator(ledger) {
|
|
2057
|
+
const { childId, epoch } = ledger;
|
|
2058
|
+
return Object.freeze({
|
|
2059
|
+
childId,
|
|
2060
|
+
epoch,
|
|
2061
|
+
/**
|
|
2062
|
+
* Tells whether a child and epoch are this session's current ones.
|
|
2063
|
+
* @param child - The child to compare.
|
|
2064
|
+
* @param candidateEpoch - The epoch to compare.
|
|
2065
|
+
* @returns True when both match.
|
|
2066
|
+
*/
|
|
2067
|
+
isCurrentEpoch: (child, candidateEpoch) => child === childId && candidateEpoch === epoch,
|
|
2068
|
+
/**
|
|
2069
|
+
* Refuses a child and epoch that are not this session's current ones.
|
|
2070
|
+
* @param child - The child to compare.
|
|
2071
|
+
* @param candidateEpoch - The epoch to compare.
|
|
2072
|
+
*/
|
|
2073
|
+
assertCurrentEpoch: (child, candidateEpoch) => {
|
|
2074
|
+
assertCurrent(child, candidateEpoch, childId, epoch);
|
|
2075
|
+
}
|
|
2076
|
+
});
|
|
2077
|
+
}
|
|
2078
|
+
/**
|
|
2079
|
+
* Builds the issuer: the server-owned identities this session may mint.
|
|
2080
|
+
* @param ledger - The ledger the issuer records into.
|
|
2081
|
+
* @returns A frozen issuer.
|
|
2082
|
+
*/
|
|
2083
|
+
function createIssuer(ledger) {
|
|
2084
|
+
return Object.freeze({
|
|
2085
|
+
/**
|
|
2086
|
+
* Mints a browser command id.
|
|
2087
|
+
* @returns The fresh id.
|
|
2088
|
+
*/
|
|
2089
|
+
mintBrowserCommandId: () => mint(ledger, "browser-command"),
|
|
2090
|
+
/**
|
|
2091
|
+
* Mints a JSON-RPC request id for a request this server sends.
|
|
2092
|
+
* @returns The fresh id.
|
|
2093
|
+
*/
|
|
2094
|
+
mintJsonRpcRequestId: () => mint(ledger, "json-rpc-request"),
|
|
2095
|
+
/**
|
|
2096
|
+
* Mints a realtime session id.
|
|
2097
|
+
* @returns The fresh id.
|
|
2098
|
+
*/
|
|
2099
|
+
mintRealtimeSessionId: () => mint(ledger, "realtime-session"),
|
|
2100
|
+
/**
|
|
2101
|
+
* Mints and records a new epoch for this session's child.
|
|
2102
|
+
* @returns The fresh epoch.
|
|
2103
|
+
*/
|
|
2104
|
+
mintChildEpoch: () => mintEpoch(ledger)
|
|
2105
|
+
});
|
|
2106
|
+
}
|
|
2107
|
+
/**
|
|
2108
|
+
* Builds the trusted decoder: parsing, adopting and serializing identities
|
|
2109
|
+
* against the ledger.
|
|
2110
|
+
* @param ledger - The ledger the decoder reads and records into.
|
|
2111
|
+
* @returns A frozen decoder.
|
|
2112
|
+
*/
|
|
2113
|
+
function createDecoder(ledger) {
|
|
2114
|
+
const { childId, epoch, issued } = ledger;
|
|
2115
|
+
return Object.freeze({
|
|
2116
|
+
/**
|
|
2117
|
+
* Parses a child id this session issued.
|
|
2118
|
+
* @param value - The untrusted value.
|
|
2119
|
+
* @returns The issued child id.
|
|
2120
|
+
*/
|
|
2121
|
+
parseChildId: (value) => parseIssued(ledger, "child", value),
|
|
2122
|
+
/**
|
|
2123
|
+
* Parses an epoch of this session's child that it issued.
|
|
2124
|
+
* @param value - The untrusted value.
|
|
2125
|
+
* @returns The issued epoch of this child.
|
|
2126
|
+
*/
|
|
2127
|
+
parseChildEpoch: (value) => parseIssuedEpoch(ledger, value),
|
|
2128
|
+
/**
|
|
2129
|
+
* Parses a browser command id this session issued.
|
|
2130
|
+
* @param value - The untrusted value.
|
|
2131
|
+
* @returns The issued browser command id.
|
|
2132
|
+
*/
|
|
2133
|
+
parseBrowserCommandId: (value) => parseIssued(ledger, "browser-command", value),
|
|
2134
|
+
/**
|
|
2135
|
+
* Parses a thread id this session issued or adopted.
|
|
2136
|
+
* @param value - The untrusted value.
|
|
2137
|
+
* @returns The issued thread id.
|
|
2138
|
+
*/
|
|
2139
|
+
parseThreadId: (value) => parseIssued(ledger, "thread", value),
|
|
2140
|
+
/**
|
|
2141
|
+
* Parses a turn id this session issued or adopted.
|
|
2142
|
+
* @param value - The untrusted value.
|
|
2143
|
+
* @returns The issued turn id.
|
|
2144
|
+
*/
|
|
2145
|
+
parseTurnId: (value) => parseIssued(ledger, "turn", value),
|
|
2146
|
+
/**
|
|
2147
|
+
* Parses an item id this session issued or adopted.
|
|
2148
|
+
* @param value - The untrusted value.
|
|
2149
|
+
* @returns The issued item id.
|
|
2150
|
+
*/
|
|
2151
|
+
parseItemId: (value) => parseIssued(ledger, "item", value),
|
|
2152
|
+
/**
|
|
2153
|
+
* Parses a queued submission id this session adopted.
|
|
2154
|
+
* @param value - The untrusted value.
|
|
2155
|
+
* @returns The issued queued submission id.
|
|
2156
|
+
*/
|
|
2157
|
+
parseQueuedSubmissionId: (value) => parseIssued(ledger, "queued-submission", value),
|
|
2158
|
+
/**
|
|
2159
|
+
* Parses a login id this session adopted.
|
|
2160
|
+
* @param value - The untrusted value.
|
|
2161
|
+
* @returns The issued login id.
|
|
2162
|
+
*/
|
|
2163
|
+
parseLoginId: (value) => parseIssued(ledger, "login", value),
|
|
2164
|
+
/**
|
|
2165
|
+
* Parses a JSON-RPC request id this session issued or adopted.
|
|
2166
|
+
* @param value - The untrusted value.
|
|
2167
|
+
* @returns The issued JSON-RPC request id.
|
|
2168
|
+
*/
|
|
2169
|
+
parseJsonRpcRequestId: (value) => parseIssued(ledger, "json-rpc-request", value),
|
|
2170
|
+
/**
|
|
2171
|
+
* Parses a dynamic tool call id this session adopted.
|
|
2172
|
+
* @param value - The untrusted value.
|
|
2173
|
+
* @returns The issued dynamic tool call id.
|
|
2174
|
+
*/
|
|
2175
|
+
parseDynamicToolCallId: (value) => parseIssued(ledger, "dynamic-tool-call", value),
|
|
2176
|
+
/**
|
|
2177
|
+
* Parses a realtime session id this session issued.
|
|
2178
|
+
* @param value - The untrusted value.
|
|
2179
|
+
* @returns The issued realtime session id.
|
|
2180
|
+
*/
|
|
2181
|
+
parseRealtimeSessionId: (value) => parseIssued(ledger, "realtime-session", value),
|
|
2182
|
+
/**
|
|
2183
|
+
* Parses an approval id this session adopted.
|
|
2184
|
+
* @param value - The untrusted value.
|
|
2185
|
+
* @returns The issued approval id.
|
|
2186
|
+
*/
|
|
2187
|
+
parseApprovalId: (value) => parseIssued(ledger, "approval", value),
|
|
2188
|
+
/**
|
|
2189
|
+
* Looks up the thread id already adopted for a raw Codex thread id.
|
|
2190
|
+
* @param raw - The raw Codex thread id.
|
|
2191
|
+
* @returns The thread id already adopted for it.
|
|
2192
|
+
*/
|
|
2193
|
+
resolveThreadId: (raw) => resolve(ledger, "thread", raw),
|
|
2194
|
+
/**
|
|
2195
|
+
* Looks up the item id already adopted for a raw Codex item id.
|
|
2196
|
+
* @param raw - The raw Codex item id.
|
|
2197
|
+
* @returns The item id already adopted for it.
|
|
2198
|
+
*/
|
|
2199
|
+
resolveItemId: (raw) => resolve(ledger, "item", raw),
|
|
2200
|
+
/**
|
|
2201
|
+
* Adopts a raw Codex thread id into this session.
|
|
2202
|
+
* @param raw - The raw Codex thread id.
|
|
2203
|
+
* @returns The newly adopted thread id.
|
|
2204
|
+
*/
|
|
2205
|
+
adoptThreadId: (raw) => adopt(ledger, "thread", raw),
|
|
2206
|
+
/**
|
|
2207
|
+
* Adopts a raw Codex turn id into this session.
|
|
2208
|
+
* @param raw - The raw Codex turn id.
|
|
2209
|
+
* @returns The newly adopted turn id.
|
|
2210
|
+
*/
|
|
2211
|
+
adoptTurnId: (raw) => adopt(ledger, "turn", raw),
|
|
2212
|
+
/**
|
|
2213
|
+
* Adopts a raw Codex item id into this session.
|
|
2214
|
+
* @param raw - The raw Codex item id.
|
|
2215
|
+
* @returns The newly adopted item id.
|
|
2216
|
+
*/
|
|
2217
|
+
adoptItemId: (raw) => adopt(ledger, "item", raw),
|
|
2218
|
+
/**
|
|
2219
|
+
* Adopts a raw Codex queued submission id into this session.
|
|
2220
|
+
* @param raw - The raw Codex queued submission id.
|
|
2221
|
+
* @returns The newly adopted queued submission id.
|
|
2222
|
+
*/
|
|
2223
|
+
adoptQueuedSubmissionId: (raw) => adopt(ledger, "queued-submission", raw),
|
|
2224
|
+
/**
|
|
2225
|
+
* Adopts a raw Codex login id into this session.
|
|
2226
|
+
* @param raw - The raw Codex login id.
|
|
2227
|
+
* @returns The newly adopted login id.
|
|
2228
|
+
*/
|
|
2229
|
+
adoptLoginId: (raw) => adopt(ledger, "login", raw),
|
|
2230
|
+
/**
|
|
2231
|
+
* Adopts a raw JSON-RPC request id the server chose.
|
|
2232
|
+
* @param raw - The raw JSON-RPC request id, string or integer.
|
|
2233
|
+
* @returns The newly adopted request id.
|
|
2234
|
+
*/
|
|
2235
|
+
adoptJsonRpcRequestId: (raw) => adoptJsonRpcRequestId(ledger, raw),
|
|
2236
|
+
/**
|
|
2237
|
+
* Adopts a raw Codex dynamic tool call id into this session.
|
|
2238
|
+
* @param raw - The raw Codex dynamic tool call id.
|
|
2239
|
+
* @returns The newly adopted call id.
|
|
2240
|
+
*/
|
|
2241
|
+
adoptDynamicToolCallId: (raw) => adopt(ledger, "dynamic-tool-call", raw),
|
|
2242
|
+
/**
|
|
2243
|
+
* Adopts a raw Codex approval id into this session.
|
|
2244
|
+
* @param raw - The raw Codex approval id.
|
|
2245
|
+
* @returns The newly adopted approval id.
|
|
2246
|
+
*/
|
|
2247
|
+
adoptApprovalId: (raw) => adopt(ledger, "approval", raw),
|
|
2248
|
+
/**
|
|
2249
|
+
* Adopts every identity of one decoded response, all or none.
|
|
2250
|
+
* @param batch - The raw identities of one decoded response.
|
|
2251
|
+
* @returns The adopted identities, or nothing adopted when any is bad.
|
|
2252
|
+
*/
|
|
2253
|
+
adoptCodexResponseIdentities: (batch) => adoptCodexResponseIdentities(ledger, batch),
|
|
2254
|
+
/**
|
|
2255
|
+
* Serializes an issued Codex identity back to the server's raw id.
|
|
2256
|
+
* @param identity - An issued Codex identity.
|
|
2257
|
+
* @returns The raw string the server knows it by.
|
|
2258
|
+
*/
|
|
2259
|
+
serializeCodexIdentity: (identity) => serialize(ledger, identity),
|
|
2260
|
+
/**
|
|
2261
|
+
* Serializes an issued request id back to the exact value the server used.
|
|
2262
|
+
* @param identity - An issued JSON-RPC request id.
|
|
2263
|
+
* @returns The raw value, string or integer, the server used.
|
|
2264
|
+
*/
|
|
2265
|
+
serializeJsonRpcRequestId: (identity) => serializeJsonRpc(ledger, identity),
|
|
2266
|
+
/**
|
|
2267
|
+
* Correlates an issued request id with the current child and epoch.
|
|
2268
|
+
* @param input - The request id to correlate.
|
|
2269
|
+
* @returns The correlation bound to the current child and epoch.
|
|
2270
|
+
*/
|
|
2271
|
+
createWireRequestCorrelation: (input) => createWireRequestCorrelation(ledger, input),
|
|
2272
|
+
/**
|
|
2273
|
+
* Parses a wire request correlation and proves it current.
|
|
2274
|
+
* @param value - The untrusted correlation record.
|
|
2275
|
+
* @returns The proven-current correlation.
|
|
2276
|
+
*/
|
|
2277
|
+
parseWireRequestCorrelation: (value) => parseWireRequestCorrelationValue(value, childId, epoch, issued),
|
|
2278
|
+
/**
|
|
2279
|
+
* Correlates issued call identities and bounded text with the current child and epoch.
|
|
2280
|
+
* @param input - The identities and text of the call.
|
|
2281
|
+
* @returns The correlation bound to the current child and epoch.
|
|
2282
|
+
*/
|
|
2283
|
+
createLogicalToolCallCorrelation: (input) => createLogicalToolCallCorrelation(ledger, input),
|
|
2284
|
+
/**
|
|
2285
|
+
* Parses a logical tool-call correlation and proves it current.
|
|
2286
|
+
* @param value - The untrusted correlation record.
|
|
2287
|
+
* @returns The proven-current correlation.
|
|
2288
|
+
*/
|
|
2289
|
+
parseLogicalToolCallCorrelation: (value) => parseLogicalToolCallCorrelationValue(value, childId, epoch, issued)
|
|
2290
|
+
});
|
|
2291
|
+
}
|
|
2292
|
+
/**
|
|
2293
|
+
* Builds the operation capability: validation, issuance and decoding of
|
|
2294
|
+
* operation identities, kept apart from the identity capability so ordinary
|
|
2295
|
+
* owners can be handed only the validator.
|
|
2296
|
+
* @param ledger - The ledger the capability reads and records into.
|
|
2297
|
+
* @returns A frozen operation authority.
|
|
2298
|
+
*/
|
|
2299
|
+
function createOperationAuthority(ledger) {
|
|
2300
|
+
/**
|
|
2301
|
+
* Refuses an operation id that is not current and issued here.
|
|
2302
|
+
* @param value - The operation id.
|
|
2303
|
+
*/
|
|
2304
|
+
const assertCurrentOperationId = (value) => {
|
|
2305
|
+
parseOperation(ledger, value);
|
|
2306
|
+
};
|
|
2307
|
+
/**
|
|
2308
|
+
* Tells whether an operation id is current and issued here, letting
|
|
2309
|
+
* only validation refusals answer false.
|
|
2310
|
+
* @param value - The operation id.
|
|
2311
|
+
* @returns True when it validates.
|
|
2312
|
+
*/
|
|
2313
|
+
const isCurrentOperationId = (value) => {
|
|
2314
|
+
try {
|
|
2315
|
+
assertCurrentOperationId(value);
|
|
2316
|
+
return true;
|
|
2317
|
+
} catch (error) {
|
|
2318
|
+
if (error instanceof IdentityValidationError) return false;
|
|
2319
|
+
throw error;
|
|
2320
|
+
}
|
|
2321
|
+
};
|
|
2322
|
+
return Object.freeze({
|
|
2323
|
+
validator: Object.freeze({
|
|
2324
|
+
isCurrentOperationId,
|
|
2325
|
+
assertCurrentOperationId
|
|
2326
|
+
}),
|
|
2327
|
+
issuer: Object.freeze({
|
|
2328
|
+
/**
|
|
2329
|
+
* Mints an operation id in the current epoch.
|
|
2330
|
+
* @returns The fresh operation id.
|
|
2331
|
+
*/
|
|
2332
|
+
mintOperationId: () => mintOperation(ledger) }),
|
|
2333
|
+
decoder: Object.freeze({
|
|
2334
|
+
/**
|
|
2335
|
+
* Parses an operation id issued in the current epoch.
|
|
2336
|
+
* @param value - The untrusted value.
|
|
2337
|
+
* @returns The proven-current operation id.
|
|
2338
|
+
*/
|
|
2339
|
+
parseOperationId: (value) => parseOperation(ledger, value),
|
|
2340
|
+
/**
|
|
2341
|
+
* Serializes an operation id; a canonical value is its own wire form.
|
|
2342
|
+
* @param value - An operation id.
|
|
2343
|
+
* @returns The same value, once proven current; it is its own wire form.
|
|
2344
|
+
*/
|
|
2345
|
+
serializeOperationId: (value) => parseOperation(ledger, value)
|
|
2346
|
+
})
|
|
2347
|
+
});
|
|
2348
|
+
}
|
|
2349
|
+
/**
|
|
2350
|
+
* Composes every capability over one ledger, first recording the ledger's own
|
|
2351
|
+
* child and epoch as issued.
|
|
2352
|
+
* @param ledger - The ledger to build over.
|
|
2353
|
+
* @returns The identity and operation authorities.
|
|
2354
|
+
*/
|
|
2355
|
+
function createAuthority(ledger) {
|
|
2356
|
+
issueExisting(ledger, "child", ledger.childId, tokenOf(ledger.childId));
|
|
2357
|
+
issueExisting(ledger, "epoch", ledger.epoch, tokenOf(ledger.epoch));
|
|
2358
|
+
return {
|
|
2359
|
+
identity: Object.freeze({
|
|
2360
|
+
validator: createValidator(ledger),
|
|
2361
|
+
issuer: createIssuer(ledger),
|
|
2362
|
+
decoder: createDecoder(ledger)
|
|
2363
|
+
}),
|
|
2364
|
+
operation: createOperationAuthority(ledger)
|
|
2365
|
+
};
|
|
2366
|
+
}
|
|
2367
|
+
/** The record prefix of a ledger that no host names: the authorities made without one. */
|
|
2368
|
+
const UNNAMED_RECORD_PREFIX = "codex";
|
|
2369
|
+
/**
|
|
2370
|
+
* Starts a fresh ledger with a newly minted child and epoch.
|
|
2371
|
+
* @param recordPrefix - The host's record prefix, `^[a-z][a-z0-9-]{0,15}$`. The child is minted
|
|
2372
|
+
* with it, and every identity the ledger spells after that copies the child's.
|
|
2373
|
+
* @returns An empty ledger for a new process.
|
|
2374
|
+
* @throws {TypeError} When the record prefix is not of its shape.
|
|
2375
|
+
*/
|
|
2376
|
+
function createIdentityLedger(recordPrefix) {
|
|
2377
|
+
const childId = mintServerValue(recordPrefix, "child");
|
|
2378
|
+
return {
|
|
2379
|
+
childId,
|
|
2380
|
+
epoch: mintEpochValue(childId),
|
|
2381
|
+
issued: /* @__PURE__ */ new Map(),
|
|
2382
|
+
rawByIdentity: /* @__PURE__ */ new Map()
|
|
2383
|
+
};
|
|
2384
|
+
}
|
|
2385
|
+
/**
|
|
2386
|
+
* Builds authorities over a ledger, by default a fresh one that no host names.
|
|
2387
|
+
* @param ledger - The ledger to build over.
|
|
2388
|
+
* @returns The identity and operation authorities.
|
|
2389
|
+
*/
|
|
2390
|
+
function createIdentityAuthorities(ledger = createIdentityLedger(UNNAMED_RECORD_PREFIX)) {
|
|
2391
|
+
return createAuthority(ledger);
|
|
2392
|
+
}
|
|
2393
|
+
// src/shared/protocol/realtime-contract.ts
|
|
2394
|
+
const BrowserRealtimeIdentitySchemas = {
|
|
2395
|
+
session: z.string().brand(),
|
|
2396
|
+
correlation: z.string().brand(),
|
|
2397
|
+
item: z.string().min(1).max(canonicalItemIdMaxLength()).refine((value) => !value.includes("\0")).brand()
|
|
2398
|
+
};
|
|
2399
|
+
/**
|
|
2400
|
+
* Narrows an untrusted value to a realtime session id.
|
|
2401
|
+
* @param value - The raw value from the wire.
|
|
2402
|
+
* @returns The validated session id.
|
|
2403
|
+
* @throws {ZodError} when the value is not a well-formed session id.
|
|
2404
|
+
*/
|
|
2405
|
+
function parseRealtimeSessionId(value) {
|
|
2406
|
+
return BrowserRealtimeIdentitySchemas.session.parse(value);
|
|
2407
|
+
}
|
|
2408
|
+
/**
|
|
2409
|
+
* Narrows an untrusted value to a realtime correlation id.
|
|
2410
|
+
* @param value - The raw value from the wire.
|
|
2411
|
+
* @returns The validated correlation id.
|
|
2412
|
+
* @throws {ZodError} when the value is not a well-formed correlation id.
|
|
2413
|
+
*/
|
|
2414
|
+
function parseRealtimeCorrelationId(value) {
|
|
2415
|
+
return BrowserRealtimeIdentitySchemas.correlation.parse(value);
|
|
2416
|
+
}
|
|
2417
|
+
/**
|
|
2418
|
+
* Narrows an untrusted value to a realtime item id.
|
|
2419
|
+
* @param value - The raw value from the wire.
|
|
2420
|
+
* @returns The validated item id.
|
|
2421
|
+
* @throws {ZodError} when the value is not a well-formed item id.
|
|
2422
|
+
*/
|
|
2423
|
+
function parseRealtimeItemId(value) {
|
|
2424
|
+
return BrowserRealtimeIdentitySchemas.item.parse(value);
|
|
2425
|
+
}
|
|
1044
2426
|
// src/shared/browser/schemas/voice.ts
|
|
1045
2427
|
/**
|
|
1046
2428
|
* Builds the context delivery, coordinator, voice and voice context schemas.
|
|
@@ -1172,31 +2554,115 @@ function createBrowserVoiceSchemas(identity) {
|
|
|
1172
2554
|
})
|
|
1173
2555
|
};
|
|
1174
2556
|
}
|
|
1175
|
-
// ../timing/src/shared/constants/
|
|
2557
|
+
// ../timing/src/shared/constants/uses.ts
|
|
2558
|
+
/**
|
|
2559
|
+
* Declare a bound on one piece of work.
|
|
2560
|
+
* @param ms How long the work may take.
|
|
2561
|
+
* @param waitingFor What the work is, for its timeout message.
|
|
2562
|
+
* @returns The declaration.
|
|
2563
|
+
*/
|
|
2564
|
+
function bound(ms, waitingFor) {
|
|
2565
|
+
return {
|
|
2566
|
+
use: "bound",
|
|
2567
|
+
ms,
|
|
2568
|
+
waitingFor
|
|
2569
|
+
};
|
|
2570
|
+
}
|
|
2571
|
+
/**
|
|
2572
|
+
* Declare a wait that looks again until its condition holds.
|
|
2573
|
+
* @param ms How long the wait may take.
|
|
2574
|
+
* @param waitingFor What the wait is for, for its timeout message.
|
|
2575
|
+
* @returns The declaration.
|
|
2576
|
+
*/
|
|
2577
|
+
function polled(ms, waitingFor) {
|
|
2578
|
+
return {
|
|
2579
|
+
use: "polled",
|
|
2580
|
+
ms,
|
|
2581
|
+
waitingFor
|
|
2582
|
+
};
|
|
2583
|
+
}
|
|
2584
|
+
/**
|
|
2585
|
+
* Declare a delay before something runs once.
|
|
2586
|
+
* @param ms The delay.
|
|
2587
|
+
* @param waitingFor What a timeout at its end waited for, when its end is one.
|
|
2588
|
+
* @returns The declaration.
|
|
2589
|
+
*/
|
|
2590
|
+
function delay(ms, waitingFor) {
|
|
2591
|
+
return waitingFor === void 0 ? {
|
|
2592
|
+
use: "delay",
|
|
2593
|
+
ms
|
|
2594
|
+
} : {
|
|
2595
|
+
use: "delay",
|
|
2596
|
+
ms,
|
|
2597
|
+
waitingFor
|
|
2598
|
+
};
|
|
2599
|
+
}
|
|
2600
|
+
/**
|
|
2601
|
+
* Declare a span measured from a stamp.
|
|
2602
|
+
* @param ms How long the span runs.
|
|
2603
|
+
* @param waitingFor What a person waits for while it runs, when its end is a timeout.
|
|
2604
|
+
* @returns The declaration.
|
|
2605
|
+
*/
|
|
2606
|
+
function span(ms, waitingFor) {
|
|
2607
|
+
return waitingFor === void 0 ? {
|
|
2608
|
+
use: "span",
|
|
2609
|
+
ms
|
|
2610
|
+
} : {
|
|
2611
|
+
use: "span",
|
|
2612
|
+
ms,
|
|
2613
|
+
waitingFor
|
|
2614
|
+
};
|
|
2615
|
+
}
|
|
1176
2616
|
/**
|
|
1177
|
-
*
|
|
1178
|
-
*
|
|
1179
|
-
*
|
|
1180
|
-
* @
|
|
1181
|
-
* @returns The same group, frozen.
|
|
2617
|
+
* Declare a delay that doubles after each failed attempt.
|
|
2618
|
+
* @param ms The first delay.
|
|
2619
|
+
* @param max The longest delay.
|
|
2620
|
+
* @returns The declaration.
|
|
1182
2621
|
*/
|
|
1183
|
-
function
|
|
1184
|
-
return
|
|
2622
|
+
function backoff$1(ms, max) {
|
|
2623
|
+
return {
|
|
2624
|
+
use: "backoff",
|
|
2625
|
+
ms,
|
|
2626
|
+
max
|
|
2627
|
+
};
|
|
2628
|
+
}
|
|
2629
|
+
/**
|
|
2630
|
+
* Declare a duration another owner needs as a number.
|
|
2631
|
+
* @param ms The duration.
|
|
2632
|
+
* @returns The declaration.
|
|
2633
|
+
*/
|
|
2634
|
+
function handed(ms) {
|
|
2635
|
+
return {
|
|
2636
|
+
use: "handed",
|
|
2637
|
+
ms
|
|
2638
|
+
};
|
|
1185
2639
|
}
|
|
1186
2640
|
// ../timing/src/shared/constants/codex.ts
|
|
1187
|
-
/**
|
|
1188
|
-
const
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
2641
|
+
/** `codex.composedShutdown`, named once so that its other uses last as long. */
|
|
2642
|
+
const COMPOSED_SHUTDOWN_MS = 1e4;
|
|
2643
|
+
/** `codex.termGrace`, named once so that a failed server start's cleanup gets the same grace. */
|
|
2644
|
+
const TERM_GRACE_MS = 5e3;
|
|
2645
|
+
/** `codex.dynamicWait`, named once so that its looks last as long. */
|
|
2646
|
+
const DYNAMIC_WAIT_MS = 12e4;
|
|
2647
|
+
/** `codex.requestSettlement`, named once so that the child's readiness can wait as long. */
|
|
2648
|
+
const REQUEST_SETTLEMENT_MS = 3e4;
|
|
2649
|
+
/** The `codex app-server` child: its readiness, its restart backoff and its ordered shutdown. */
|
|
2650
|
+
const CODEX_PROCESS = {
|
|
2651
|
+
/**
|
|
2652
|
+
* Restart delay: it doubles after each failed child attempt from its first second, caps at the
|
|
2653
|
+
* maximum, and resets only after one account-ready session. Its cap pulls against request
|
|
2654
|
+
* settlement and the backoff ceiling.
|
|
2655
|
+
*/
|
|
2656
|
+
"codex.restart": backoff$1(1e3, 3e4),
|
|
2657
|
+
/** How long a spawned child may take to acknowledge typed readiness: one request settlement. */
|
|
2658
|
+
"codex.readiness": delay(REQUEST_SETTLEMENT_MS, "the Codex app-server to acknowledge typed readiness"),
|
|
1193
2659
|
/**
|
|
1194
2660
|
* Stdin EOF grace lets the child consume drained frames before TERM and ends on closure.
|
|
1195
2661
|
* Realtime stop, EOF and TERM leave one second of the composed cap for group absence proof.
|
|
1196
2662
|
*/
|
|
1197
|
-
stdinEofGrace: 1e3,
|
|
2663
|
+
"codex.stdinEofGrace": bound(1e3, "the Codex child to exit on stdin EOF"),
|
|
1198
2664
|
/** TERM grace classification. Pulls against realtime stop before TERM-to-KILL escalation. */
|
|
1199
|
-
termGrace:
|
|
2665
|
+
"codex.termGrace": polled(TERM_GRACE_MS, "a TERMed Codex process group to exit"),
|
|
1200
2666
|
/**
|
|
1201
2667
|
* How long KILL waits for the TERMed group to freeze. A group freezes in a few
|
|
1202
2668
|
* observation polls, but a member in a killable kernel wait never reads as stopped
|
|
@@ -1204,77 +2670,72 @@ const CODEX_PROCESS_MS = durations({
|
|
|
1204
2670
|
* shutdown cap keeps, so a freeze that cannot finish leaves time to prove the
|
|
1205
2671
|
* killed group gone.
|
|
1206
2672
|
*/
|
|
1207
|
-
groupFreeze: 500,
|
|
2673
|
+
"codex.groupFreeze": polled(500, "a TERMed Codex process group to freeze"),
|
|
2674
|
+
/** How long a killed group may take to disappear: the rest of the composed cap. */
|
|
2675
|
+
"codex.killDrain": polled(COMPOSED_SHUTDOWN_MS, "a killed Codex process group to disappear"),
|
|
1208
2676
|
/** Composed-shutdown cap classification. Pulls against realtime stop, stdin EOF grace, and TERM grace. */
|
|
1209
|
-
composedShutdown:
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
*/
|
|
1218
|
-
function codexRestartDelayMs(restartAttempt) {
|
|
1219
|
-
return Math.min(CODEX_PROCESS_MS.restartMax, CODEX_PROCESS_MS.restartBase * 2 ** Math.min(restartAttempt, 30));
|
|
1220
|
-
}
|
|
2677
|
+
"codex.composedShutdown": bound(COMPOSED_SHUTDOWN_MS, "the Codex child and its process group to shut down"),
|
|
2678
|
+
/** How long the transport waits for the child to close once it shut down, before it aborts. */
|
|
2679
|
+
"codex.transportShutdown": delay(COMPOSED_SHUTDOWN_MS),
|
|
2680
|
+
/** The composed cap, handed to the cleanup of a failed server start. */
|
|
2681
|
+
"codex.startupCleanup": handed(COMPOSED_SHUTDOWN_MS),
|
|
2682
|
+
/** The TERM grace, handed to the cleanup of a failed server start. */
|
|
2683
|
+
"codex.startupGrace": handed(TERM_GRACE_MS)
|
|
2684
|
+
};
|
|
1221
2685
|
/** Requests to the app-server session, and how often its thread state is read. */
|
|
1222
|
-
const
|
|
2686
|
+
const CODEX_SESSION = {
|
|
1223
2687
|
/**
|
|
1224
2688
|
* How long an explanation waits for the turn of a message that an idle thread took from the
|
|
1225
2689
|
* queue by itself, before it tells the reader to look at the conversation.
|
|
1226
2690
|
*/
|
|
1227
|
-
explanationTurnStart: 15e3,
|
|
2691
|
+
"codex.explanationTurnStart": bound(15e3, "Codex to start the turn of a queued message"),
|
|
1228
2692
|
/** How often an answer that Codex writes reaches the panel: a reader sees it arrive in steps. */
|
|
1229
|
-
explanationText: 150,
|
|
1230
|
-
/** Uncertainty-bound classification. Pulls against a lost non-idempotent response before `outcome_unknown`. */
|
|
1231
|
-
requestSettlement: 3e4,
|
|
2693
|
+
"codex.explanationText": delay(150),
|
|
1232
2694
|
/**
|
|
1233
|
-
*
|
|
1234
|
-
*
|
|
1235
|
-
* observation cannot cross the settlement boundary.
|
|
2695
|
+
* Uncertainty-bound classification. Pulls against a lost non-idempotent response before
|
|
2696
|
+
* `outcome_unknown`. Each request, and the coordinator's settings notification, waits this long.
|
|
1236
2697
|
*/
|
|
1237
|
-
|
|
2698
|
+
"codex.requestSettlement": delay(REQUEST_SETTLEMENT_MS, "Codex to answer a request"),
|
|
2699
|
+
/** The request settlement, handed to the bounded `codex --version` proof. */
|
|
2700
|
+
"codex.versionProof": handed(REQUEST_SETTLEMENT_MS),
|
|
1238
2701
|
/**
|
|
1239
|
-
*
|
|
1240
|
-
*
|
|
2702
|
+
* The longest dynamic wait an agent may ask for on the threads it waits on; each wait names
|
|
2703
|
+
* its own length up to this. Pulls against the browser-command lease, which outlasts it.
|
|
2704
|
+
*/
|
|
2705
|
+
"codex.dynamicWait": bound(DYNAMIC_WAIT_MS, "the awaited threads to report"),
|
|
2706
|
+
/** The looks of a dynamic wait at the thread status, inside its bound. */
|
|
2707
|
+
"codex.dynamicWaitLook": polled(DYNAMIC_WAIT_MS, "the awaited threads to report"),
|
|
2708
|
+
/**
|
|
2709
|
+
* Read-amplification floor classification. Pulls against request settlement above.
|
|
1241
2710
|
*
|
|
1242
2711
|
* Serving a browser snapshot request re-reads the authoritative workhorse
|
|
1243
2712
|
* queue, which is a paginated app-server call. A client is free to ask for a
|
|
1244
2713
|
* snapshot as often as it likes, so the server coalesces concurrent re-reads and
|
|
1245
|
-
* will not start a new one inside this floor. It sits
|
|
1246
|
-
*
|
|
1247
|
-
* observes thread state at, and far below request settlement, so a person's
|
|
1248
|
-
* refresh still reads as immediate.
|
|
1249
|
-
*/
|
|
1250
|
-
queueRereadFloor: 1e3,
|
|
1251
|
-
/**
|
|
1252
|
-
* How often a workhorse stop reads its work tree again after it sent interrupts. Pulls against
|
|
1253
|
-
* the wait-target poll, the same cadence the server observes thread state at, and against the
|
|
1254
|
-
* stop settlement below, which must hold several passes.
|
|
2714
|
+
* will not start a new one inside this floor. It sits far below request settlement,
|
|
2715
|
+
* so a person's refresh still reads as immediate.
|
|
1255
2716
|
*/
|
|
1256
|
-
|
|
2717
|
+
"codex.queueRereadFloor": span(1e3),
|
|
1257
2718
|
/**
|
|
1258
2719
|
* How long a workhorse stop observes its work tree before it reports what still runs as a
|
|
1259
2720
|
* partial or unconfirmed stop. Pulls against the coordinator's tool call, which waits for the
|
|
1260
2721
|
* stop while the person waits for the voice to answer, and against an interrupt's settlement,
|
|
1261
2722
|
* which Codex acknowledges before the turn reports that it ended.
|
|
1262
2723
|
*/
|
|
1263
|
-
|
|
1264
|
-
}
|
|
2724
|
+
"codex.workTreeStop": polled(5e3, "the workhorse's work tree to stop")
|
|
2725
|
+
};
|
|
1265
2726
|
/**
|
|
1266
2727
|
* The voice: its realtime start, stop, recovery and the freshness it needs, and how soon the
|
|
1267
2728
|
* browser's voice client opens its socket again.
|
|
1268
2729
|
*/
|
|
1269
|
-
const
|
|
2730
|
+
const CODEX_REALTIME = {
|
|
1270
2731
|
/** Realtime-readiness timeout classification. Pulls against permission-independent SDP/start readiness. */
|
|
1271
|
-
|
|
2732
|
+
"codex.realtimeStart": span(15e3, "the voice to start"),
|
|
1272
2733
|
/** Realtime-stop timeout classification. Pulls against TERM grace so realtime stops first. */
|
|
1273
|
-
|
|
2734
|
+
"codex.realtimeStop": handed(3e3),
|
|
1274
2735
|
/** Realtime-recovery window classification. Pulls against context freshness while reconnecting. */
|
|
1275
|
-
|
|
2736
|
+
"codex.realtimeRecovery": span(45e3),
|
|
1276
2737
|
/** How long an announced context change stays fresh enough to deliver. Pulls against realtime recovery. */
|
|
1277
|
-
contextFreshness: 3e4,
|
|
2738
|
+
"codex.contextFreshness": span(3e4),
|
|
1278
2739
|
/**
|
|
1279
2740
|
* How long the voice client waits before opening its socket again after the
|
|
1280
2741
|
* socket is lost, and between failed attempts after that. Pulls against the tab
|
|
@@ -1282,24 +2743,132 @@ const CODEX_REALTIME_MS = durations({
|
|
|
1282
2743
|
* ends the conversation before the client is back. It is also the beat of a
|
|
1283
2744
|
* retry, so a shorter value would hammer a server that is restarting.
|
|
1284
2745
|
*/
|
|
1285
|
-
clientReconnect: 3e3
|
|
1286
|
-
|
|
2746
|
+
"codex.clientReconnect": span(3e3),
|
|
2747
|
+
/**
|
|
2748
|
+
* How long a browser tab's conversation outlives its last browser socket. Pulls against a
|
|
2749
|
+
* reload plus `codex.clientReconnect` redials, which it must outlast or a reload loses the
|
|
2750
|
+
* conversation, and `codex.approvalExpiry`, which it must stay under so a closed tab's approvals
|
|
2751
|
+
* end as "tab session ended" rather than expiring unanswered.
|
|
2752
|
+
*/
|
|
2753
|
+
"codex.tabSessionGrace": {
|
|
2754
|
+
...delay(6e4),
|
|
2755
|
+
background: true
|
|
2756
|
+
}
|
|
2757
|
+
};
|
|
1287
2758
|
/** A browser command an agent leases, and the approvals a person answers. */
|
|
1288
|
-
const
|
|
2759
|
+
const CODEX_APPROVAL = {
|
|
1289
2760
|
/** Browser-command lease classification. Pulls against the public browser wait contract and approval expiry. */
|
|
1290
|
-
browserCommandLease: 15e4,
|
|
2761
|
+
"codex.browserCommandLease": span(15e4),
|
|
1291
2762
|
/** Visual-approval expiry classification. Pulls against the browser-command lease. */
|
|
1292
|
-
|
|
2763
|
+
"codex.approvalExpiry": span(9e4),
|
|
1293
2764
|
/** Spoken-approval gate expiry classification. Pulls against visual approval expiry. */
|
|
1294
|
-
spokenGate: 6e4
|
|
2765
|
+
"codex.spokenGate": span(6e4)
|
|
2766
|
+
};
|
|
2767
|
+
/** Every duration of the Codex workbench. */
|
|
2768
|
+
const CODEX = {
|
|
2769
|
+
...CODEX_PROCESS,
|
|
2770
|
+
...CODEX_SESSION,
|
|
2771
|
+
...CODEX_REALTIME,
|
|
2772
|
+
...CODEX_APPROVAL
|
|
2773
|
+
};
|
|
2774
|
+
// ../timing/src/shared/constants/git.ts
|
|
2775
|
+
/**
|
|
2776
|
+
* Grace after Git termination for the detached group, leader and both output
|
|
2777
|
+
* pipes to disappear. A killed group normally leaves within milliseconds. The
|
|
2778
|
+
* macOS group once seen to outlive one second was not slow: a child forked
|
|
2779
|
+
* during the stop had escaped both group signals, which the stop barrier now
|
|
2780
|
+
* prevents. Three seconds stays below `git.command`, so failed cleanup is still
|
|
2781
|
+
* diagnosed before the command timeout would be. Each of its three uses below has
|
|
2782
|
+
* a name of its own.
|
|
2783
|
+
*/
|
|
2784
|
+
const GROUP_CLEANUP_MS = 3e3;
|
|
2785
|
+
/** Default for both the bounded Git runner and the runners that accept a number. */
|
|
2786
|
+
const COMMAND_MS = 5e3;
|
|
2787
|
+
/** One Git command: its bound, and the end of its detached process group. */
|
|
2788
|
+
const GIT = {
|
|
2789
|
+
/**
|
|
2790
|
+
* Outer bound for one Git identity probe while an operation captures its checkout snapshot. Snapshot
|
|
2791
|
+
* work runs before a model lock or synchronous note write, so this never extends either critical
|
|
2792
|
+
* section. It is longer than the server mutation-drain refusal window: stop may refuse and keep the
|
|
2793
|
+
* application intact while a slow probe is still cancellable by its request or application owner.
|
|
2794
|
+
* The exception is code-target's probe of the checkout that holds the model: its Git calls, at
|
|
2795
|
+
* most three, are synchronous for a synchronous check, so each can block the event loop this long.
|
|
2796
|
+
* Handed to the command runner, which a caller may give a longer bound of its own.
|
|
2797
|
+
*/
|
|
2798
|
+
"git.command": handed(COMMAND_MS),
|
|
2799
|
+
/** The asynchronous runner's bound before it starts termination and proves cleanup. */
|
|
2800
|
+
"git.commandRun": bound(COMMAND_MS, "a Git command to finish"),
|
|
2801
|
+
/** How long a terminated Git command's output and exit may take to settle. */
|
|
2802
|
+
"git.groupCleanup": bound(GROUP_CLEANUP_MS, "a terminated Git command to settle"),
|
|
2803
|
+
/** How long a terminated Git group may take to disappear. */
|
|
2804
|
+
"git.groupGone": polled(GROUP_CLEANUP_MS, "a terminated Git process group to disappear"),
|
|
2805
|
+
/** How long a stopped Git group may take to freeze before it is killed. */
|
|
2806
|
+
"git.groupFreeze": polled(GROUP_CLEANUP_MS, "a stopped Git process group to freeze"),
|
|
2807
|
+
/**
|
|
2808
|
+
* Outer grace before an interrupted CLI restores the signal's default action.
|
|
2809
|
+
* Git may spend one cleanup grace terminating and cancelling its leader and
|
|
2810
|
+
* pipes, then another proving the detached group is absent. A third grace is
|
|
2811
|
+
* reserved for that settled failure to cross the command runner before the CLI
|
|
2812
|
+
* re-signals itself; the outer owner must never pre-empt either inner proof.
|
|
2813
|
+
*/
|
|
2814
|
+
"git.cliInterruptCleanup": delay(3 * GROUP_CLEANUP_MS)
|
|
2815
|
+
};
|
|
2816
|
+
// ../timing/src/shared/constants/published-waits.ts
|
|
2817
|
+
/** Every duration the published package declares, by its name. */
|
|
2818
|
+
const WAITS = Object.freeze({
|
|
2819
|
+
...CODEX,
|
|
2820
|
+
...GIT
|
|
1295
2821
|
});
|
|
1296
2822
|
/**
|
|
1297
|
-
* How long a
|
|
1298
|
-
*
|
|
1299
|
-
*
|
|
1300
|
-
* end as "tab session ended" rather than expiring unanswered.
|
|
2823
|
+
* How long a declared duration is.
|
|
2824
|
+
* @param wait Its name.
|
|
2825
|
+
* @returns Its length, in milliseconds.
|
|
1301
2826
|
*/
|
|
1302
|
-
|
|
2827
|
+
function lengthOf(wait) {
|
|
2828
|
+
return WAITS[wait].ms;
|
|
2829
|
+
}
|
|
2830
|
+
// ../timing/src/shared/operations/spans.ts
|
|
2831
|
+
/** The most doublings a backoff takes, past which every cap is reached anyway. */
|
|
2832
|
+
const MOST_DOUBLINGS = 30;
|
|
2833
|
+
/**
|
|
2834
|
+
* When a span that starts at a stamp ends.
|
|
2835
|
+
* @param wait The span.
|
|
2836
|
+
* @param from Its stamp, in milliseconds on any clock.
|
|
2837
|
+
* @returns Its end, on the same clock.
|
|
2838
|
+
*/
|
|
2839
|
+
function expiresAt(wait, from) {
|
|
2840
|
+
return from + lengthOf(wait);
|
|
2841
|
+
}
|
|
2842
|
+
/**
|
|
2843
|
+
* Whether a span that started at a stamp has run out: more than its length has passed.
|
|
2844
|
+
* @param wait The span.
|
|
2845
|
+
* @param since Its stamp, in milliseconds on any clock.
|
|
2846
|
+
* @param now The time now, on the same clock. Defaults to the wall clock.
|
|
2847
|
+
* @returns True once more than the span has passed since the stamp.
|
|
2848
|
+
*/
|
|
2849
|
+
function lapsed(wait, since, now = Date.now()) {
|
|
2850
|
+
return now - since > lengthOf(wait);
|
|
2851
|
+
}
|
|
2852
|
+
/**
|
|
2853
|
+
* The delay before the next attempt of something that failed: the first delay doubled once for
|
|
2854
|
+
* every attempt already made, up to the cap.
|
|
2855
|
+
* @param wait The backoff.
|
|
2856
|
+
* @param attempt Attempts already made since the last success.
|
|
2857
|
+
* @returns The delay, in milliseconds.
|
|
2858
|
+
*/
|
|
2859
|
+
function backoff(wait, attempt) {
|
|
2860
|
+
const { ms: first, max } = WAITS[wait];
|
|
2861
|
+
return Math.min(max, first * 2 ** Math.min(attempt, MOST_DOUBLINGS));
|
|
2862
|
+
}
|
|
2863
|
+
/**
|
|
2864
|
+
* A duration another owner needs as a number, or how long a motion takes. Every other duration
|
|
2865
|
+
* is served by the operation of its use and cannot be read.
|
|
2866
|
+
* @param wait The duration.
|
|
2867
|
+
* @returns It, in milliseconds.
|
|
2868
|
+
*/
|
|
2869
|
+
function ms(wait) {
|
|
2870
|
+
return WAITS[wait].ms;
|
|
2871
|
+
}
|
|
1303
2872
|
// src/shared/dynamic-approval/schemas/effects.ts
|
|
1304
2873
|
/**
|
|
1305
2874
|
* The host domain namespace a dynamic approval belongs to. The host names it, and the server makes
|
|
@@ -1806,8 +3375,7 @@ function createDynamicApprovalBrowserSchemas(identity, context, effectSchemas) {
|
|
|
1806
3375
|
resumable: z.literal(false)
|
|
1807
3376
|
}).strict().superRefine((approval, refinementContext) => {
|
|
1808
3377
|
validateIdentityAndBrowserEffect(approval.identity, approval.effect, refinementContext);
|
|
1809
|
-
|
|
1810
|
-
if (window <= 0 || window > CODEX_APPROVAL_MS.expiry) addIssue(refinementContext, ["expiresAtMs"], `approval expiry must be after creation and at most ${CODEX_APPROVAL_MS.expiry}ms after it`);
|
|
3378
|
+
if (approval.expiresAtMs - approval.createdAtMs <= 0 || lapsed("codex.approvalExpiry", approval.createdAtMs, approval.expiresAtMs)) addIssue(refinementContext, ["expiresAtMs"], `approval expiry must be after creation and no later than ${expiresAt("codex.approvalExpiry", approval.createdAtMs)}`);
|
|
1811
3379
|
validateDecisionEcho(approval.identity, approval.effectHash, approval.decision, refinementContext);
|
|
1812
3380
|
validateDynamicApprovalState(approval, refinementContext);
|
|
1813
3381
|
});
|
|
@@ -2279,11 +3847,10 @@ function createDynamicApprovalSchemas(identity, context) {
|
|
|
2279
3847
|
expiresAtMs: NonNegativeIntegerSchema
|
|
2280
3848
|
}).strict().superRefine((request, refinementContext) => {
|
|
2281
3849
|
validateIdentityAndEffect(request.identity, request.effect, refinementContext);
|
|
2282
|
-
|
|
2283
|
-
if (window <= 0 || window > CODEX_APPROVAL_MS.expiry) refinementContext.addIssue({
|
|
3850
|
+
if (request.expiresAtMs - request.createdAtMs <= 0 || lapsed("codex.approvalExpiry", request.createdAtMs, request.expiresAtMs)) refinementContext.addIssue({
|
|
2284
3851
|
code: "custom",
|
|
2285
3852
|
path: ["expiresAtMs"],
|
|
2286
|
-
message: `expiry must be after creation and
|
|
3853
|
+
message: `expiry must be after creation and no later than ${expiresAt("codex.approvalExpiry", request.createdAtMs)}`
|
|
2287
3854
|
});
|
|
2288
3855
|
if (request.effectHash !== effectHashFor(canonicalHashInput(request.identity, request.effect))) refinementContext.addIssue({
|
|
2289
3856
|
code: "custom",
|
|
@@ -2340,7 +3907,7 @@ const BROWSER_SPOKEN_APPROVAL_REASONS = Object.freeze([
|
|
|
2340
3907
|
"child_exit",
|
|
2341
3908
|
"disposed"
|
|
2342
3909
|
]);
|
|
2343
|
-
|
|
3910
|
+
Object.freeze({
|
|
2344
3911
|
kind: "spoken_approval",
|
|
2345
3912
|
state: "idle",
|
|
2346
3913
|
approval: null,
|
|
@@ -2818,4 +4385,4 @@ function createCodexBrowserModel(context) {
|
|
|
2818
4385
|
...createBrowserSchemas(identity, normalizedContext)
|
|
2819
4386
|
};
|
|
2820
4387
|
}
|
|
2821
|
-
export { JsonValueSchema as _,
|
|
4388
|
+
export { CodexThreadStatusSchema as A, boundedText as C, CodexCommandExecutionApprovalDecisionSchema as D, CODEX_CLIENT_REQUEST_METHODS as E, CODEX_APP_SERVER_CAPACITY as F, codexFieldSchema as M, isCodexThreadStatusType as N, CodexFileChangeApprovalDecisionSchema as O, normalizeCodexJsonWire as P, JsonValueSchema as S, parseJsonValue as T, BROWSER_PERMISSION_FILE_ACCESS as _, backoff as a, BROWSER_VOICE_CONTEXT_BRIEF_MAX_UTF8_BYTES as b, WAITS as c, parseRealtimeItemId as d, parseRealtimeSessionId as f, IdentityValidationError as g, logicalToolCallKey as h, dynamicApprovalHashForCanonicalJson as i, CodexTurnStatusSchema as j, CodexSafeI64Schema as k, lengthOf as l, createIdentityLedger as m, browserSnapshotRelationshipIssues as n, expiresAt as o, createIdentityAuthorities as p, canonicalDynamicApprovalJson as r, ms as s, createCodexBrowserModel as t, parseRealtimeCorrelationId as u, BROWSER_TIMELINE_LIMITS as v, boundedWireText as w, DeliveryOutcomeSchema as x, BROWSER_VOICE_CONTEXT_BODY_MAX_UTF8_BYTES as y };
|