@opengeni/sdk 0.57.0 → 1.0.1
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 +6 -0
- package/dist/artifacts.js +3 -3
- package/dist/{chunk-HJ3HHUT5.js → chunk-4DV37UUA.js} +2 -2
- package/dist/chunk-4DV37UUA.js.map +1 -0
- package/dist/{chunk-JDLDDRNE.js → chunk-A5DC5WEM.js} +269 -32
- package/dist/chunk-A5DC5WEM.js.map +1 -0
- package/dist/{chunk-JRPFWI6T.js → chunk-TYZ4JL4J.js} +2 -2
- package/dist/{chunk-PKQ377ED.js → chunk-YGH5P47G.js} +2 -2
- package/dist/chunk-YGH5P47G.js.map +1 -0
- package/dist/client.d.ts +2 -2
- package/dist/codex-realtime-controller.d.ts +2 -0
- package/dist/codex-realtime-controller.js +1 -1
- package/dist/codex-realtime-v3.d.ts +13 -2
- package/dist/core.js +2 -2
- package/dist/editable-artifacts.js +1 -1
- package/dist/index.js +4 -4
- package/dist/realtime.js +1 -1
- package/dist/types.d.ts +16 -5
- package/package.json +2 -2
- package/src/client.ts +2 -2
- package/src/codex-realtime-controller.ts +214 -5
- package/src/codex-realtime-v3.ts +162 -31
- package/src/types.ts +17 -5
- package/dist/chunk-HJ3HHUT5.js.map +0 -1
- package/dist/chunk-JDLDDRNE.js.map +0 -1
- package/dist/chunk-PKQ377ED.js.map +0 -1
- /package/dist/{chunk-JRPFWI6T.js.map → chunk-TYZ4JL4J.js.map} +0 -0
|
@@ -231,6 +231,7 @@ var CODEX_REALTIME_V3_PENDING_MAX_ENTRIES = 256;
|
|
|
231
231
|
var CODEX_REALTIME_V3_PENDING_MAX_BYTES = 16 * 1024 * 1024;
|
|
232
232
|
var REALTIME_DELEGATION_TRANSCRIPT_MAX_BYTES = 65536;
|
|
233
233
|
var REALTIME_DELEGATION_INPUT_MAX_BYTES = 65536;
|
|
234
|
+
var REALTIME_MODEL_CONTEXT_MAX_CHARACTERS = 32768;
|
|
234
235
|
function createCodexRealtimeV3Bridge(options) {
|
|
235
236
|
let closed = false;
|
|
236
237
|
let sealed = false;
|
|
@@ -253,9 +254,27 @@ function createCodexRealtimeV3Bridge(options) {
|
|
|
253
254
|
const clientReceivedSequences = /* @__PURE__ */ new Set();
|
|
254
255
|
const sentSequences = /* @__PURE__ */ new Set();
|
|
255
256
|
const finalizedTurnIds = /* @__PURE__ */ new Set();
|
|
257
|
+
const acceptedDelegationItemIds = options.acceptedDelegationItemIds ?? /* @__PURE__ */ new Set();
|
|
258
|
+
const pendingDelegations = options.pendingDelegations ?? /* @__PURE__ */ new Map();
|
|
259
|
+
const locallyQueuedDelegationItemIds = /* @__PURE__ */ new Set();
|
|
256
260
|
let transcriptSinceDelegation = [];
|
|
257
261
|
let pendingDelegationUserTranscript = null;
|
|
258
262
|
const randomUUID = options.randomUUID ?? defaultRandomUUID;
|
|
263
|
+
const currentModelContext = () => {
|
|
264
|
+
let context;
|
|
265
|
+
try {
|
|
266
|
+
context = options.getModelContext?.()?.trim();
|
|
267
|
+
} catch {
|
|
268
|
+
lastError = "Realtime model context callback failed; the provider message continued without application context";
|
|
269
|
+
return void 0;
|
|
270
|
+
}
|
|
271
|
+
if (!context) return void 0;
|
|
272
|
+
if (context.length > REALTIME_MODEL_CONTEXT_MAX_CHARACTERS) {
|
|
273
|
+
lastError = "Realtime model context exceeded the 32768-character limit; the provider message continued without application context";
|
|
274
|
+
return void 0;
|
|
275
|
+
}
|
|
276
|
+
return context;
|
|
277
|
+
};
|
|
259
278
|
const snapshot = () => ({
|
|
260
279
|
connectionId: options.connectionId,
|
|
261
280
|
connectionEpoch: options.connectionEpoch,
|
|
@@ -274,9 +293,9 @@ function createCodexRealtimeV3Bridge(options) {
|
|
|
274
293
|
fatal
|
|
275
294
|
});
|
|
276
295
|
const publish = () => options.onSnapshot?.(snapshot());
|
|
277
|
-
const
|
|
296
|
+
const triggerFatalCode = (code, message) => {
|
|
278
297
|
if (closed || fatal) return;
|
|
279
|
-
fatal = { code
|
|
298
|
+
fatal = { code, message };
|
|
280
299
|
lastError = message;
|
|
281
300
|
publish();
|
|
282
301
|
try {
|
|
@@ -284,6 +303,9 @@ function createCodexRealtimeV3Bridge(options) {
|
|
|
284
303
|
} catch {
|
|
285
304
|
}
|
|
286
305
|
};
|
|
306
|
+
const triggerFatal = (message) => {
|
|
307
|
+
triggerFatalCode("pending_overflow", message);
|
|
308
|
+
};
|
|
287
309
|
const enqueue = (entry) => {
|
|
288
310
|
if (closed || sealed || fatal) return false;
|
|
289
311
|
const bytes = utf8ByteLength2(JSON.stringify(entry));
|
|
@@ -296,6 +318,9 @@ function createCodexRealtimeV3Bridge(options) {
|
|
|
296
318
|
pendingInboundBytes += bytes;
|
|
297
319
|
return true;
|
|
298
320
|
};
|
|
321
|
+
for (const [delegationItemId, entry] of pendingDelegations) {
|
|
322
|
+
if (enqueue(entry)) locallyQueuedDelegationItemIds.add(delegationItemId);
|
|
323
|
+
}
|
|
299
324
|
const hasWork = () => pendingInbound.length > 0 || !providerStartedAccepted && providerStarted !== void 0 || clientAckThroughSequence !== null || forceSync;
|
|
300
325
|
const runFlush = async () => {
|
|
301
326
|
while (true) {
|
|
@@ -321,7 +346,41 @@ function createCodexRealtimeV3Bridge(options) {
|
|
|
321
346
|
pendingInbound = [...batch, ...pendingInbound];
|
|
322
347
|
throw error;
|
|
323
348
|
}
|
|
349
|
+
const acceptedAfterSync = new Set(acceptedDelegationItemIds);
|
|
350
|
+
const pendingAfterSync = new Map(pendingDelegations);
|
|
351
|
+
let delegationReplayChanged = false;
|
|
324
352
|
for (const item of batch) {
|
|
353
|
+
if (item.entry.kind === "delegation_call" && item.entry.delegationItemId) {
|
|
354
|
+
delegationReplayChanged = true;
|
|
355
|
+
acceptedAfterSync.add(item.entry.delegationItemId);
|
|
356
|
+
if (pendingAfterSync.get(item.entry.delegationItemId) === item.entry) {
|
|
357
|
+
pendingAfterSync.delete(item.entry.delegationItemId);
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
if (delegationReplayChanged) {
|
|
362
|
+
try {
|
|
363
|
+
options.onDelegationReplayStateChange?.({
|
|
364
|
+
acceptedDelegationItemIds: acceptedAfterSync,
|
|
365
|
+
pendingDelegations: pendingAfterSync
|
|
366
|
+
});
|
|
367
|
+
} catch (error) {
|
|
368
|
+
pendingInbound = [...batch, ...pendingInbound];
|
|
369
|
+
triggerFatalCode(
|
|
370
|
+
"replay_journal_failed",
|
|
371
|
+
`Codex realtime delegation replay journal failed: ${safeError(error)}`
|
|
372
|
+
);
|
|
373
|
+
return;
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
for (const item of batch) {
|
|
377
|
+
if (item.entry.kind === "delegation_call" && item.entry.delegationItemId) {
|
|
378
|
+
acceptedDelegationItemIds.add(item.entry.delegationItemId);
|
|
379
|
+
if (pendingDelegations.get(item.entry.delegationItemId) === item.entry) {
|
|
380
|
+
pendingDelegations.delete(item.entry.delegationItemId);
|
|
381
|
+
}
|
|
382
|
+
locallyQueuedDelegationItemIds.delete(item.entry.delegationItemId);
|
|
383
|
+
}
|
|
325
384
|
pendingInboundCount -= 1;
|
|
326
385
|
pendingInboundBytes -= item.bytes;
|
|
327
386
|
}
|
|
@@ -423,27 +482,60 @@ function createCodexRealtimeV3Bridge(options) {
|
|
|
423
482
|
}
|
|
424
483
|
} else if (event.type === "input_transcript.added" || event.type === "output_transcript.added") {
|
|
425
484
|
} else if (event.type === "delegation.created") {
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
485
|
+
if (acceptedDelegationItemIds.has(event.delegationItemId)) {
|
|
486
|
+
ignoredEventCount += 1;
|
|
487
|
+
lastIgnoredEventType = event.type;
|
|
488
|
+
} else if (locallyQueuedDelegationItemIds.has(event.delegationItemId)) {
|
|
489
|
+
ignoredEventCount += 1;
|
|
490
|
+
lastIgnoredEventType = event.type;
|
|
491
|
+
durable = true;
|
|
492
|
+
} else {
|
|
493
|
+
let entry = pendingDelegations.get(event.delegationItemId);
|
|
494
|
+
if (!entry) {
|
|
495
|
+
const transcript = delegationTranscript(transcriptSinceDelegation, event.inputTranscript);
|
|
496
|
+
const coveredTurnIds = transcriptSinceDelegation.map((item) => item.turnId);
|
|
497
|
+
const modelContext = currentModelContext();
|
|
498
|
+
entry = {
|
|
499
|
+
operationId: randomUUID(),
|
|
500
|
+
kind: "delegation_call",
|
|
501
|
+
providerEventId: event.providerEventId,
|
|
502
|
+
delegationItemId: event.delegationItemId,
|
|
503
|
+
text: renderRealtimeDelegationInput(event.inputTranscript, transcript),
|
|
504
|
+
payload: {
|
|
505
|
+
offsetMs: event.offsetMs,
|
|
506
|
+
inputTranscript: event.inputTranscript,
|
|
507
|
+
transcriptFenceTurnIds: coveredTurnIds
|
|
508
|
+
},
|
|
509
|
+
...modelContext ? { modelContext } : {}
|
|
510
|
+
};
|
|
511
|
+
pendingDelegations.set(event.delegationItemId, entry);
|
|
512
|
+
}
|
|
513
|
+
try {
|
|
514
|
+
options.onDelegationReplayStateChange?.({
|
|
515
|
+
acceptedDelegationItemIds,
|
|
516
|
+
pendingDelegations
|
|
517
|
+
});
|
|
518
|
+
} catch (error) {
|
|
519
|
+
triggerFatalCode(
|
|
520
|
+
"replay_journal_failed",
|
|
521
|
+
`Codex realtime delegation replay journal failed: ${safeError(error)}`
|
|
522
|
+
);
|
|
523
|
+
return Promise.resolve();
|
|
524
|
+
}
|
|
525
|
+
durable = enqueue(entry);
|
|
526
|
+
if (durable) {
|
|
527
|
+
locallyQueuedDelegationItemIds.add(event.delegationItemId);
|
|
528
|
+
activeDelegationId = event.delegationItemId;
|
|
529
|
+
const frozenInputTranscript = typeof entry.payload.inputTranscript === "string" ? entry.payload.inputTranscript : event.inputTranscript;
|
|
530
|
+
const alreadyFinalized = transcriptSinceDelegation.some(
|
|
531
|
+
(item) => item.role === "user" && normalizedTranscript(item.text) === normalizedTranscript(frozenInputTranscript)
|
|
532
|
+
);
|
|
533
|
+
pendingDelegationUserTranscript = alreadyFinalized ? null : {
|
|
534
|
+
delegationItemId: event.delegationItemId,
|
|
535
|
+
text: frozenInputTranscript
|
|
536
|
+
};
|
|
537
|
+
transcriptSinceDelegation = [];
|
|
439
538
|
}
|
|
440
|
-
});
|
|
441
|
-
if (durable) {
|
|
442
|
-
const alreadyFinalized = transcriptSinceDelegation.some(
|
|
443
|
-
(entry) => entry.role === "user" && normalizedTranscript(entry.text) === normalizedTranscript(event.inputTranscript)
|
|
444
|
-
);
|
|
445
|
-
pendingDelegationUserTranscript = alreadyFinalized ? null : { delegationItemId: event.delegationItemId, text: event.inputTranscript };
|
|
446
|
-
transcriptSinceDelegation = [];
|
|
447
539
|
}
|
|
448
540
|
} else if (event.type === "output_audio.delta") {
|
|
449
541
|
speaking = true;
|
|
@@ -451,7 +543,9 @@ function createCodexRealtimeV3Bridge(options) {
|
|
|
451
543
|
speaking = false;
|
|
452
544
|
if (event.transcript.length > 0 && !finalizedTurnIds.has(event.turnId)) {
|
|
453
545
|
const coveredByDelegationItemId = event.role === "user" && pendingDelegationUserTranscript !== null && normalizedTranscript(event.transcript) === normalizedTranscript(pendingDelegationUserTranscript.text) ? pendingDelegationUserTranscript.delegationItemId : null;
|
|
454
|
-
durable = enqueue(
|
|
546
|
+
durable = enqueue(
|
|
547
|
+
finalTranscript(randomUUID, event, coveredByDelegationItemId, currentModelContext())
|
|
548
|
+
);
|
|
455
549
|
if (durable) {
|
|
456
550
|
finalizedTurnIds.add(event.turnId);
|
|
457
551
|
if (coveredByDelegationItemId) {
|
|
@@ -508,7 +602,7 @@ function createCodexRealtimeV3Bridge(options) {
|
|
|
508
602
|
}
|
|
509
603
|
};
|
|
510
604
|
}
|
|
511
|
-
function finalTranscript(randomUUID, event, coveredByDelegationItemId) {
|
|
605
|
+
function finalTranscript(randomUUID, event, coveredByDelegationItemId, modelContext) {
|
|
512
606
|
return {
|
|
513
607
|
operationId: randomUUID(),
|
|
514
608
|
kind: event.role === "user" ? "user_transcript" : "assistant_transcript",
|
|
@@ -517,7 +611,8 @@ function finalTranscript(randomUUID, event, coveredByDelegationItemId) {
|
|
|
517
611
|
payload: {
|
|
518
612
|
turnId: event.turnId,
|
|
519
613
|
...coveredByDelegationItemId ? { coveredByDelegationItemId } : {}
|
|
520
|
-
}
|
|
614
|
+
},
|
|
615
|
+
...modelContext ? { modelContext } : {}
|
|
521
616
|
};
|
|
522
617
|
}
|
|
523
618
|
function delegationTranscript(entries, inputTranscript) {
|
|
@@ -573,7 +668,10 @@ function sendOutbound(events, entry) {
|
|
|
573
668
|
delegationItemId: entry.delegationItemId,
|
|
574
669
|
text,
|
|
575
670
|
channel: payloadChannel ?? "speakable"
|
|
576
|
-
}) : encodeCodexRealtimeV3SessionContextAppend({
|
|
671
|
+
}) : encodeCodexRealtimeV3SessionContextAppend({
|
|
672
|
+
text,
|
|
673
|
+
channel: payloadChannel
|
|
674
|
+
});
|
|
577
675
|
for (const message of messages) events.send(JSON.stringify(message));
|
|
578
676
|
}
|
|
579
677
|
function sendDelegationProgress(events, delegationItemId, entries) {
|
|
@@ -973,6 +1071,27 @@ var CODEX_REALTIME_NEGOTIATION_TIMEOUT_MS = 2e4;
|
|
|
973
1071
|
var DEFAULT_CONNECTION_ROTATION_INTERVAL_MS = 15 * 6e4;
|
|
974
1072
|
var DEFAULT_RECONNECT_BACKOFF_MS = [250, 1e3, 2e3, 5e3];
|
|
975
1073
|
var OWNER_RECORD_VERSION = 1;
|
|
1074
|
+
var OWNER_DELEGATION_REPLAY_VERSION = 1;
|
|
1075
|
+
var OWNER_DELEGATION_REPLAY_MAX_CALLS = 4096;
|
|
1076
|
+
var OWNER_DELEGATION_REPLAY_MAX_BYTES = 4 * 1024 * 1024;
|
|
1077
|
+
var SESSION_REALTIME_INBOUND_ENTRY_KEYS = /* @__PURE__ */ new Set([
|
|
1078
|
+
"operationId",
|
|
1079
|
+
"kind",
|
|
1080
|
+
"role",
|
|
1081
|
+
"providerEventId",
|
|
1082
|
+
"delegationItemId",
|
|
1083
|
+
"text",
|
|
1084
|
+
"payload",
|
|
1085
|
+
"modelContext"
|
|
1086
|
+
]);
|
|
1087
|
+
var SESSION_REALTIME_INBOUND_KINDS = /* @__PURE__ */ new Set([
|
|
1088
|
+
"user_transcript",
|
|
1089
|
+
"assistant_transcript",
|
|
1090
|
+
"delegation_call",
|
|
1091
|
+
"interruption",
|
|
1092
|
+
"error"
|
|
1093
|
+
]);
|
|
1094
|
+
var UUID_PATTERN = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/iu;
|
|
976
1095
|
function sessionRealtimeOwnerStorageNamespace(model) {
|
|
977
1096
|
if (model === "gpt-live-1-boulder-alpha") return "codex-realtime-owner";
|
|
978
1097
|
if (model === "supergrok/grok-voice-think-fast-2.0") return "xai-realtime-owner";
|
|
@@ -1048,6 +1167,45 @@ function createCodexRealtimeController(options) {
|
|
|
1048
1167
|
let recoveryTerminal = false;
|
|
1049
1168
|
let mutationTail = Promise.resolve();
|
|
1050
1169
|
let connectionTask = null;
|
|
1170
|
+
const acceptedDelegationItemIds = new Set(
|
|
1171
|
+
owner?.delegationReplay?.acceptedDelegationItemIds ?? []
|
|
1172
|
+
);
|
|
1173
|
+
const pendingDelegations = new Map(
|
|
1174
|
+
(owner?.delegationReplay?.pendingDelegations ?? []).flatMap(
|
|
1175
|
+
(entry) => entry.delegationItemId ? [[entry.delegationItemId, entry]] : []
|
|
1176
|
+
)
|
|
1177
|
+
);
|
|
1178
|
+
const invalidateStoredOwner = () => {
|
|
1179
|
+
try {
|
|
1180
|
+
storage?.removeItem(storageKey);
|
|
1181
|
+
} catch {
|
|
1182
|
+
}
|
|
1183
|
+
};
|
|
1184
|
+
const persistDelegationReplay = (input) => {
|
|
1185
|
+
if (!owner || !storage) return;
|
|
1186
|
+
const delegationReplay = {
|
|
1187
|
+
version: OWNER_DELEGATION_REPLAY_VERSION,
|
|
1188
|
+
acceptedDelegationItemIds: [...input.acceptedDelegationItemIds],
|
|
1189
|
+
pendingDelegations: [...input.pendingDelegations.values()]
|
|
1190
|
+
};
|
|
1191
|
+
if (delegationReplay.pendingDelegations.length > CODEX_REALTIME_V3_PENDING_MAX_ENTRIES || delegationReplay.acceptedDelegationItemIds.length + delegationReplay.pendingDelegations.length > OWNER_DELEGATION_REPLAY_MAX_CALLS) {
|
|
1192
|
+
invalidateStoredOwner();
|
|
1193
|
+
throw new Error("Realtime delegation replay journal exceeded its call limit");
|
|
1194
|
+
}
|
|
1195
|
+
const next = { ...owner, delegationReplay };
|
|
1196
|
+
const serialized = JSON.stringify(next);
|
|
1197
|
+
if (new TextEncoder().encode(serialized).byteLength > OWNER_DELEGATION_REPLAY_MAX_BYTES) {
|
|
1198
|
+
invalidateStoredOwner();
|
|
1199
|
+
throw new Error("Realtime delegation replay journal exceeded its byte limit");
|
|
1200
|
+
}
|
|
1201
|
+
try {
|
|
1202
|
+
storage.setItem(storageKey, serialized);
|
|
1203
|
+
} catch (error) {
|
|
1204
|
+
invalidateStoredOwner();
|
|
1205
|
+
throw error;
|
|
1206
|
+
}
|
|
1207
|
+
owner = next;
|
|
1208
|
+
};
|
|
1051
1209
|
const publish = (patch) => {
|
|
1052
1210
|
state = { ...state, ...patch };
|
|
1053
1211
|
for (const listener of listeners) listener({ ...state });
|
|
@@ -1117,6 +1275,8 @@ function createCodexRealtimeController(options) {
|
|
|
1117
1275
|
const clearOwner = () => {
|
|
1118
1276
|
owner = null;
|
|
1119
1277
|
storage?.removeItem(storageKey);
|
|
1278
|
+
acceptedDelegationItemIds.clear();
|
|
1279
|
+
pendingDelegations.clear();
|
|
1120
1280
|
};
|
|
1121
1281
|
const transitionEnded = (message = "Realtime mode ended") => {
|
|
1122
1282
|
stopping = false;
|
|
@@ -1194,7 +1354,10 @@ function createCodexRealtimeController(options) {
|
|
|
1194
1354
|
});
|
|
1195
1355
|
return;
|
|
1196
1356
|
}
|
|
1197
|
-
publish({
|
|
1357
|
+
publish({
|
|
1358
|
+
audibleOutput: next,
|
|
1359
|
+
...next === "audible" ? { error: null } : {}
|
|
1360
|
+
});
|
|
1198
1361
|
};
|
|
1199
1362
|
const startActiveIntervals = () => {
|
|
1200
1363
|
if (heartbeatTimer === null) {
|
|
@@ -1511,6 +1674,10 @@ function createCodexRealtimeController(options) {
|
|
|
1511
1674
|
listen: false,
|
|
1512
1675
|
sync: async (request) => await syncForGeneration(targetGeneration, activated.mode.id, request),
|
|
1513
1676
|
randomUUID,
|
|
1677
|
+
...options.getModelContext ? { getModelContext: options.getModelContext } : {},
|
|
1678
|
+
acceptedDelegationItemIds,
|
|
1679
|
+
pendingDelegations,
|
|
1680
|
+
onDelegationReplayStateChange: persistDelegationReplay,
|
|
1514
1681
|
onSnapshot: (nextBridge) => {
|
|
1515
1682
|
if (active?.generation === targetGeneration) publish({ bridge: nextBridge });
|
|
1516
1683
|
},
|
|
@@ -1676,7 +1843,12 @@ function createCodexRealtimeController(options) {
|
|
|
1676
1843
|
await handleConnectionFailure(error, "reconnect", false);
|
|
1677
1844
|
} else {
|
|
1678
1845
|
clearOwner();
|
|
1679
|
-
publish({
|
|
1846
|
+
publish({
|
|
1847
|
+
status: "error",
|
|
1848
|
+
realtimeId: null,
|
|
1849
|
+
mode: null,
|
|
1850
|
+
error: safeError2(error)
|
|
1851
|
+
});
|
|
1680
1852
|
}
|
|
1681
1853
|
throw error;
|
|
1682
1854
|
}
|
|
@@ -1745,7 +1917,11 @@ function createCodexRealtimeController(options) {
|
|
|
1745
1917
|
closed = false;
|
|
1746
1918
|
stopping = false;
|
|
1747
1919
|
owner = record2;
|
|
1748
|
-
publish({
|
|
1920
|
+
publish({
|
|
1921
|
+
status: "recovering",
|
|
1922
|
+
realtimeId: lifecycle.realtimeId,
|
|
1923
|
+
error: null
|
|
1924
|
+
});
|
|
1749
1925
|
connectionTask = begin(record2, true).then(() => void 0).catch(async (error) => {
|
|
1750
1926
|
connectionTask = null;
|
|
1751
1927
|
await handleConnectionFailure(error, "reload", false);
|
|
@@ -1912,18 +2088,79 @@ function ownerStorageKey(workspaceId, sessionId, namespace = "codex-realtime-own
|
|
|
1912
2088
|
function readOwnerRecord(storage, key, scope) {
|
|
1913
2089
|
const raw = storage?.getItem(key);
|
|
1914
2090
|
if (!raw) return null;
|
|
2091
|
+
if (new TextEncoder().encode(raw).byteLength > OWNER_DELEGATION_REPLAY_MAX_BYTES) {
|
|
2092
|
+
storage?.removeItem(key);
|
|
2093
|
+
return null;
|
|
2094
|
+
}
|
|
1915
2095
|
try {
|
|
1916
2096
|
const parsed = recordValue2(JSON.parse(raw));
|
|
1917
|
-
|
|
2097
|
+
const delegationReplay = readOwnerDelegationReplay(parsed?.delegationReplay);
|
|
2098
|
+
if (parsed?.version !== OWNER_RECORD_VERSION || parsed.workspaceId !== scope.workspaceId || parsed.sessionId !== scope.sessionId || !stringValue2(parsed.operationId) || !stringValue2(parsed.browserInstanceId) || !stringValue2(parsed.ownerKey) || String(parsed.ownerKey).length < 32 || delegationReplay === null) {
|
|
1918
2099
|
storage?.removeItem(key);
|
|
1919
2100
|
return null;
|
|
1920
2101
|
}
|
|
1921
|
-
return
|
|
2102
|
+
return {
|
|
2103
|
+
...parsed,
|
|
2104
|
+
...delegationReplay ? { delegationReplay } : {}
|
|
2105
|
+
};
|
|
1922
2106
|
} catch {
|
|
1923
2107
|
storage?.removeItem(key);
|
|
1924
2108
|
return null;
|
|
1925
2109
|
}
|
|
1926
2110
|
}
|
|
2111
|
+
function readOwnerDelegationReplay(value) {
|
|
2112
|
+
if (value === void 0) return void 0;
|
|
2113
|
+
const record2 = recordValue2(value);
|
|
2114
|
+
if (record2?.version !== OWNER_DELEGATION_REPLAY_VERSION || !Array.isArray(record2.acceptedDelegationItemIds) || !Array.isArray(record2.pendingDelegations) || record2.acceptedDelegationItemIds.length + record2.pendingDelegations.length > OWNER_DELEGATION_REPLAY_MAX_CALLS || record2.pendingDelegations.length > CODEX_REALTIME_V3_PENDING_MAX_ENTRIES) {
|
|
2115
|
+
return null;
|
|
2116
|
+
}
|
|
2117
|
+
const acceptedDelegationItemIds = [];
|
|
2118
|
+
const accepted = /* @__PURE__ */ new Set();
|
|
2119
|
+
for (const candidate of record2.acceptedDelegationItemIds) {
|
|
2120
|
+
if (typeof candidate !== "string" || candidate.length < 1 || candidate.length > 1024) {
|
|
2121
|
+
return null;
|
|
2122
|
+
}
|
|
2123
|
+
if (!accepted.has(candidate)) {
|
|
2124
|
+
accepted.add(candidate);
|
|
2125
|
+
acceptedDelegationItemIds.push(candidate);
|
|
2126
|
+
}
|
|
2127
|
+
}
|
|
2128
|
+
const pendingDelegations = [];
|
|
2129
|
+
const pendingIds = /* @__PURE__ */ new Set();
|
|
2130
|
+
for (const candidate of record2.pendingDelegations) {
|
|
2131
|
+
const parsed = readSessionRealtimeInboundEntry(candidate);
|
|
2132
|
+
if (!parsed || parsed.kind !== "delegation_call" || !parsed.delegationItemId || accepted.has(parsed.delegationItemId) || pendingIds.has(parsed.delegationItemId)) {
|
|
2133
|
+
return null;
|
|
2134
|
+
}
|
|
2135
|
+
pendingIds.add(parsed.delegationItemId);
|
|
2136
|
+
pendingDelegations.push(parsed);
|
|
2137
|
+
}
|
|
2138
|
+
const replay = {
|
|
2139
|
+
version: OWNER_DELEGATION_REPLAY_VERSION,
|
|
2140
|
+
acceptedDelegationItemIds,
|
|
2141
|
+
pendingDelegations
|
|
2142
|
+
};
|
|
2143
|
+
if (new TextEncoder().encode(JSON.stringify(replay)).byteLength > OWNER_DELEGATION_REPLAY_MAX_BYTES) {
|
|
2144
|
+
return null;
|
|
2145
|
+
}
|
|
2146
|
+
return replay;
|
|
2147
|
+
}
|
|
2148
|
+
function readSessionRealtimeInboundEntry(value) {
|
|
2149
|
+
const record2 = recordValue2(value);
|
|
2150
|
+
if (!record2 || Object.keys(record2).some((key) => !SESSION_REALTIME_INBOUND_ENTRY_KEYS.has(key)) || typeof record2.operationId !== "string" || !UUID_PATTERN.test(record2.operationId) || typeof record2.kind !== "string" || !SESSION_REALTIME_INBOUND_KINDS.has(record2.kind) || !optionalNullableEnum(record2.role, ["user", "assistant"]) || !optionalNullableBoundedString(record2.providerEventId, 1024) || !optionalNullableBoundedString(record2.delegationItemId, 1024) || !optionalNullableBoundedString(record2.text, 131072) || record2.payload !== void 0 && recordValue2(record2.payload) === null || !optionalModelContext(record2.modelContext)) {
|
|
2151
|
+
return null;
|
|
2152
|
+
}
|
|
2153
|
+
return record2;
|
|
2154
|
+
}
|
|
2155
|
+
function optionalNullableEnum(value, allowed) {
|
|
2156
|
+
return value === void 0 || value === null || typeof value === "string" && allowed.includes(value);
|
|
2157
|
+
}
|
|
2158
|
+
function optionalNullableBoundedString(value, maxLength) {
|
|
2159
|
+
return value === void 0 || value === null || typeof value === "string" && value.length <= maxLength;
|
|
2160
|
+
}
|
|
2161
|
+
function optionalModelContext(value) {
|
|
2162
|
+
return value === void 0 || typeof value === "string" && value.length >= 1 && value.length <= 32768 && value.trim() === value;
|
|
2163
|
+
}
|
|
1927
2164
|
function defaultStorage() {
|
|
1928
2165
|
return typeof sessionStorage === "undefined" ? void 0 : sessionStorage;
|
|
1929
2166
|
}
|
|
@@ -2021,4 +2258,4 @@ export {
|
|
|
2021
2258
|
hasStoredSessionRealtimeOwnerProof,
|
|
2022
2259
|
createCodexRealtimeController
|
|
2023
2260
|
};
|
|
2024
|
-
//# sourceMappingURL=chunk-
|
|
2261
|
+
//# sourceMappingURL=chunk-A5DC5WEM.js.map
|