@opengeni/sdk 0.52.1 → 1.0.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 +1078 -33
- package/dist/accounts.d.ts +153 -0
- package/dist/accounts.js +307 -0
- package/dist/accounts.js.map +1 -0
- package/dist/adapters/express.d.ts +31 -0
- package/dist/adapters/express.js +87 -0
- package/dist/adapters/express.js.map +1 -0
- package/dist/adapters/hono.d.ts +16 -0
- package/dist/adapters/hono.js +8 -0
- package/dist/adapters/hono.js.map +1 -0
- package/dist/adapters/next.d.ts +29 -0
- package/dist/adapters/next.js +22 -0
- package/dist/adapters/next.js.map +1 -0
- package/dist/allowance-refusal.d.ts +2 -0
- package/dist/allowance-refusal.js +50 -0
- package/dist/allowance-refusal.js.map +1 -0
- package/dist/artifact-catalog.d.ts +31 -0
- package/dist/artifact-client.d.ts +23 -11
- package/dist/artifacts.d.ts +1 -1
- package/dist/artifacts.js +7 -5
- package/dist/automations-client.d.ts +17 -0
- package/dist/automations.d.ts +3 -0
- package/dist/automations.js +84 -0
- package/dist/automations.js.map +1 -0
- package/dist/browser.d.ts +11 -0
- package/dist/browser.js +47 -0
- package/dist/browser.js.map +1 -0
- package/dist/chat/fold.d.ts +75 -0
- package/dist/chat/handler.d.ts +41 -0
- package/dist/chat/http.d.ts +67 -0
- package/dist/chat/ids.d.ts +34 -0
- package/dist/chat/index.d.ts +9 -0
- package/dist/chat/index.js +1694 -0
- package/dist/chat/index.js.map +1 -0
- package/dist/chat/openai.d.ts +30 -0
- package/dist/chat/opengeni.d.ts +128 -0
- package/dist/chat/types.d.ts +207 -0
- package/dist/chat/vercel.d.ts +49 -0
- package/dist/chats.d.ts +8 -0
- package/dist/{chunk-KIHGPM7H.js → chunk-2UXZUCEZ.js} +309 -46
- package/dist/chunk-2UXZUCEZ.js.map +1 -0
- package/dist/chunk-4SMEOV3P.js +246 -0
- package/dist/chunk-4SMEOV3P.js.map +1 -0
- package/dist/{chunk-FHI4DFIG.js → chunk-AH5D5Q5V.js} +31 -35
- package/dist/chunk-AH5D5Q5V.js.map +1 -0
- package/dist/chunk-APXVSSSY.js +301 -0
- package/dist/chunk-APXVSSSY.js.map +1 -0
- package/dist/chunk-DUVIYER4.js +639 -0
- package/dist/chunk-DUVIYER4.js.map +1 -0
- package/dist/{chunk-ILQZR5N6.js → chunk-FG3OO5LM.js} +3484 -750
- package/dist/chunk-FG3OO5LM.js.map +1 -0
- package/dist/chunk-GZYZT22T.js +260 -0
- package/dist/chunk-GZYZT22T.js.map +1 -0
- package/dist/chunk-HMGADJGZ.js +150 -0
- package/dist/chunk-HMGADJGZ.js.map +1 -0
- package/dist/{chunk-DXDL7EEW.js → chunk-KWADQ227.js} +198 -114
- package/dist/chunk-KWADQ227.js.map +1 -0
- package/dist/chunk-LY2K6ELJ.js +126 -0
- package/dist/chunk-LY2K6ELJ.js.map +1 -0
- package/dist/chunk-MOTJYIYL.js +340 -0
- package/dist/chunk-MOTJYIYL.js.map +1 -0
- package/dist/{chunk-MZWTWOX6.js → chunk-NC57YMUO.js} +447 -3
- package/dist/chunk-NC57YMUO.js.map +1 -0
- package/dist/chunk-RWKB6YZG.js +1270 -0
- package/dist/chunk-RWKB6YZG.js.map +1 -0
- package/dist/chunk-U6CV2SXO.js +195 -0
- package/dist/chunk-U6CV2SXO.js.map +1 -0
- package/dist/chunk-UM4ZXXJR.js +9 -0
- package/dist/chunk-UM4ZXXJR.js.map +1 -0
- package/dist/chunk-V6GIY62B.js +229 -0
- package/dist/chunk-V6GIY62B.js.map +1 -0
- package/dist/chunk-WU6GQG25.js +268 -0
- package/dist/chunk-WU6GQG25.js.map +1 -0
- package/dist/{chunk-VWE2QIVO.js → chunk-XNG7YGR3.js} +23 -6
- package/dist/chunk-XNG7YGR3.js.map +1 -0
- package/dist/{chunk-FRJFNDIR.js → chunk-YIKA2QT4.js} +37 -2
- package/dist/chunk-YIKA2QT4.js.map +1 -0
- package/dist/chunk-ZKPY6YAJ.js +135 -0
- package/dist/chunk-ZKPY6YAJ.js.map +1 -0
- package/dist/client.d.ts +843 -107
- package/dist/codex-realtime-controller.d.ts +6 -0
- package/dist/codex-realtime-controller.js +2 -2
- package/dist/codex-realtime-v3.d.ts +13 -2
- package/dist/company-brain.d.ts +22 -0
- package/dist/company-profile.d.ts +14 -1
- package/dist/core.d.ts +9 -3
- package/dist/core.js +28 -9
- package/dist/deprecation.d.ts +47 -0
- package/dist/desktop.d.ts +8 -0
- package/dist/document-authority-client.d.ts +51 -0
- package/dist/document-authority.d.ts +2 -0
- package/dist/document-authority.js +12 -0
- package/dist/document-authority.js.map +1 -0
- package/dist/editable-artifacts/browser-session.d.ts +7 -3
- package/dist/editable-artifacts/controller.d.ts +4 -1
- package/dist/editable-artifacts/errors.d.ts +1 -1
- package/dist/editable-artifacts/http-live-transport.d.ts +6 -2
- package/dist/editable-artifacts/index.d.ts +2 -0
- package/dist/editable-artifacts/open-failure.d.ts +9 -0
- package/dist/editable-artifacts/types.d.ts +6 -3
- package/dist/editable-artifacts/worker/kernel-adapter.d.ts +1 -1
- package/dist/editable-artifacts-worker.js +44 -17
- package/dist/editable-artifacts-worker.js.map +1 -1
- package/dist/editable-artifacts.js +243 -124
- package/dist/editable-artifacts.js.map +1 -1
- package/dist/embedding-client.d.ts +129 -0
- package/dist/errors.d.ts +36 -1
- package/dist/feedback.d.ts +23 -0
- package/dist/gateway-realtime-transport.d.ts +1 -0
- package/dist/gateway-realtime-transport.js +5 -3
- package/dist/github-repositories.d.ts +10 -0
- package/dist/github-repositories.js +36 -0
- package/dist/github-repositories.js.map +1 -0
- package/dist/index.d.ts +61 -12
- package/dist/index.js +277 -126
- package/dist/index.js.map +1 -1
- package/dist/interaction-revision-stream.d.ts +11 -0
- package/dist/interaction.d.ts +687 -5
- package/dist/interaction.js +32 -1
- package/dist/knowledge.d.ts +7 -0
- package/dist/knowledge.js +20 -0
- package/dist/knowledge.js.map +1 -0
- package/dist/message-links.d.ts +68 -0
- package/dist/model-context.d.ts +68 -0
- package/dist/model-display.d.ts +2 -0
- package/dist/model-display.js +15 -0
- package/dist/model-display.js.map +1 -0
- package/dist/model-picker-order.d.ts +1 -0
- package/dist/model-picker-order.js +10 -0
- package/dist/model-picker-order.js.map +1 -0
- package/dist/organization-integration-policy.d.ts +26 -0
- package/dist/organization-integration-policy.js +26 -0
- package/dist/organization-integration-policy.js.map +1 -0
- package/dist/organization-private-session-settings.d.ts +6 -0
- package/dist/organization-private-session-settings.js +22 -0
- package/dist/organization-private-session-settings.js.map +1 -0
- package/dist/organization-user-setup.d.ts +8 -0
- package/dist/organization-user-setup.js +16 -0
- package/dist/organization-user-setup.js.map +1 -0
- package/dist/pr-review-client.d.ts +16 -0
- package/dist/pr-review.d.ts +4 -0
- package/dist/pr-review.js +62 -0
- package/dist/pr-review.js.map +1 -0
- package/dist/preference-registry.d.ts +9 -1
- package/dist/proxy.d.ts +7 -5
- package/dist/realtime.d.ts +6 -4
- package/dist/realtime.js +10 -6
- package/dist/realtime.js.map +1 -1
- package/dist/retained-artifacts.d.ts +5 -1
- package/dist/session-history-import.d.ts +22 -0
- package/dist/session-history-import.js +36 -0
- package/dist/session-history-import.js.map +1 -0
- package/dist/session-list-entries.d.ts +1 -0
- package/dist/session-list-entries.js +7 -0
- package/dist/session-list-entries.js.map +1 -0
- package/dist/session-message-search.d.ts +53 -0
- package/dist/session-proxy-client.d.ts +24 -0
- package/dist/session-proxy.d.ts +245 -0
- package/dist/session-proxy.js +24 -0
- package/dist/session-proxy.js.map +1 -0
- package/dist/session-titles.d.ts +2 -0
- package/dist/site-browser-entry.d.ts +1 -0
- package/dist/site-browser-runtime.gen.d.ts +1 -0
- package/dist/site-document.d.ts +5 -0
- package/dist/site-document.js +20 -0
- package/dist/site-document.js.map +1 -0
- package/dist/site-document.test.d.ts +1 -0
- package/dist/site-http.d.ts +16 -0
- package/dist/site-tool-bridge.d.ts +44 -0
- package/dist/site.d.ts +101 -0
- package/dist/site.js +49 -0
- package/dist/site.js.map +1 -0
- package/dist/skills.d.ts +75 -0
- package/dist/stream.d.ts +2 -0
- package/dist/tenant-workspaces.d.ts +47 -0
- package/dist/tenant-workspaces.js +8 -0
- package/dist/tenant-workspaces.js.map +1 -0
- package/dist/tool-auth.d.ts +87 -0
- package/dist/tool-auth.js +23 -0
- package/dist/tool-auth.js.map +1 -0
- package/dist/tool-display-metadata.d.ts +3 -0
- package/dist/tools-FXBLUWAE.js +12 -0
- package/dist/tools-FXBLUWAE.js.map +1 -0
- package/dist/tools.d.ts +61 -0
- package/dist/types.d.ts +3048 -406
- package/dist/usage-allowances.d.ts +36 -0
- package/dist/usage-allowances.js +80 -0
- package/dist/usage-allowances.js.map +1 -0
- package/dist/workspace-artifacts.d.ts +33 -5
- package/dist/workspace-instruction-policies.d.ts +24 -2
- package/dist/workspace-integrations.d.ts +74 -0
- package/dist/workspace-integrations.js +65 -0
- package/dist/workspace-integrations.js.map +1 -0
- package/dist/workspace-learning.d.ts +124 -0
- package/dist/workspace-live-stream.d.ts +14 -0
- package/dist/workspace-state.d.ts +8 -71
- package/package.json +108 -3
- package/src/accounts.ts +443 -0
- package/src/adapters/express.ts +136 -0
- package/src/adapters/hono.ts +18 -0
- package/src/adapters/next.ts +42 -0
- package/src/allowance-refusal.ts +5 -0
- package/src/artifact-catalog.ts +41 -0
- package/src/artifact-client.ts +43 -52
- package/src/artifacts.ts +7 -1
- package/src/automations-client.ts +124 -0
- package/src/automations.ts +15 -0
- package/src/browser.ts +54 -0
- package/src/chat/fold.ts +431 -0
- package/src/chat/handler.ts +240 -0
- package/src/chat/http.ts +257 -0
- package/src/chat/ids.ts +85 -0
- package/src/chat/index.ts +87 -0
- package/src/chat/openai.ts +439 -0
- package/src/chat/opengeni.ts +722 -0
- package/src/chat/types.ts +219 -0
- package/src/chat/vercel.ts +204 -0
- package/src/chats.ts +16 -0
- package/src/client.ts +5162 -792
- package/src/codex-realtime-controller.ts +260 -12
- package/src/codex-realtime-lifecycle.ts +1 -0
- package/src/codex-realtime-v3.ts +162 -31
- package/src/codex-realtime.ts +1 -1
- package/src/company-brain.ts +59 -0
- package/src/company-profile.ts +17 -1
- package/src/core.ts +23 -1
- package/src/deprecation.ts +149 -0
- package/src/desktop.ts +11 -1
- package/src/document-authority-client.ts +219 -0
- package/src/document-authority.ts +17 -0
- package/src/editable-artifacts/browser-session.ts +36 -22
- package/src/editable-artifacts/controller.ts +102 -47
- package/src/editable-artifacts/errors.ts +2 -0
- package/src/editable-artifacts/http-live-transport.ts +62 -37
- package/src/editable-artifacts/index.ts +6 -0
- package/src/editable-artifacts/open-failure.ts +79 -0
- package/src/editable-artifacts/storage.ts +31 -40
- package/src/editable-artifacts/types.ts +6 -3
- package/src/editable-artifacts/worker/kernel-adapter.ts +23 -7
- package/src/editable-artifacts/worker/runtime.ts +26 -13
- package/src/editable-artifacts/worker/wire-codec.ts +23 -5
- package/src/embedding-client.ts +519 -0
- package/src/errors.ts +185 -4
- package/src/feedback.ts +20 -0
- package/src/gateway-realtime-transport.ts +253 -110
- package/src/github-repositories.ts +60 -0
- package/src/index.ts +603 -54
- package/src/interaction-revision-stream.ts +117 -0
- package/src/interaction.ts +1367 -51
- package/src/knowledge.ts +72 -0
- package/src/message-links.ts +178 -0
- package/src/model-context.ts +112 -0
- package/src/model-display.ts +10 -0
- package/src/model-picker-order.ts +6 -0
- package/src/organization-integration-policy.ts +54 -0
- package/src/organization-private-session-settings.ts +33 -0
- package/src/organization-user-setup.ts +31 -0
- package/src/pr-review-client.ts +92 -0
- package/src/pr-review.ts +17 -0
- package/src/preference-registry.ts +11 -0
- package/src/proxy.ts +17 -6
- package/src/realtime.ts +15 -4
- package/src/retained-artifacts.ts +101 -0
- package/src/session-history-import.ts +84 -0
- package/src/session-list-entries.ts +1 -0
- package/src/session-message-search.ts +47 -0
- package/src/session-proxy-client.ts +64 -0
- package/src/session-proxy.ts +1473 -0
- package/src/session-titles.ts +10 -0
- package/src/site-browser-entry.ts +6 -0
- package/src/site-browser-runtime.gen.ts +2 -0
- package/src/site-document.test.ts +64 -0
- package/src/site-document.ts +18 -0
- package/src/site-http.ts +162 -0
- package/src/site-tool-bridge.ts +146 -0
- package/src/site.ts +585 -0
- package/src/skills.ts +69 -0
- package/src/sse.ts +8 -2
- package/src/stream.ts +38 -4
- package/src/tenant-workspaces.ts +148 -0
- package/src/tool-auth.ts +301 -0
- package/src/tool-display-metadata.ts +19 -0
- package/src/tools.ts +396 -0
- package/src/types.ts +3607 -493
- package/src/usage-allowances.ts +189 -0
- package/src/workspace-artifacts.ts +40 -6
- package/src/workspace-instruction-policies.ts +26 -1
- package/src/workspace-integrations.ts +402 -0
- package/src/workspace-learning.ts +138 -0
- package/src/workspace-live-stream.ts +137 -0
- package/src/workspace-state.ts +8 -82
- package/dist/chunk-DXDL7EEW.js.map +0 -1
- package/dist/chunk-FHI4DFIG.js.map +0 -1
- package/dist/chunk-FRJFNDIR.js.map +0 -1
- package/dist/chunk-ILQZR5N6.js.map +0 -1
- package/dist/chunk-KIHGPM7H.js.map +0 -1
- package/dist/chunk-MZWTWOX6.js.map +0 -1
- package/dist/chunk-V5F253OG.js +0 -116
- package/dist/chunk-V5F253OG.js.map +0 -1
- package/dist/chunk-VWE2QIVO.js.map +0 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
OpenGeniApiError
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-V6GIY62B.js";
|
|
4
4
|
|
|
5
5
|
// src/codex-realtime-v3-wire.ts
|
|
6
6
|
var CODEX_REALTIME_INITIAL_ITEMS_MAX_COUNT = 128;
|
|
@@ -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;
|
|
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
|
+
}
|
|
324
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) {
|
|
@@ -775,7 +873,7 @@ async function startCodexRealtimeWebrtc(options) {
|
|
|
775
873
|
);
|
|
776
874
|
throwIfAborted(options.signal);
|
|
777
875
|
if (answer.version !== "v3" || answer.model !== "gpt-live-1-boulder-alpha" || !answer.sdp) {
|
|
778
|
-
throw new Error("
|
|
876
|
+
throw new Error("Opengeni returned an incompatible Codex realtime answer");
|
|
779
877
|
}
|
|
780
878
|
await peerConnection.setRemoteDescription({
|
|
781
879
|
type: "answer",
|
|
@@ -951,7 +1049,7 @@ function projectSessionRealtimeLifecycle(events) {
|
|
|
951
1049
|
return projected;
|
|
952
1050
|
}
|
|
953
1051
|
function realtimeModel(value) {
|
|
954
|
-
return value === "gpt-live-1-boulder-alpha" || value === "opengeni-gateway/openai/gpt-realtime-2.1" || value === "opengeni-gateway/openai/gpt-realtime-mini" || value === "opengeni-gateway/xai/grok-voice-think-fast-2.0" || value === "workspace-gateway/openai/gpt-realtime-2.1" || value === "workspace-gateway/openai/gpt-realtime-mini" || value === "workspace-gateway/xai/grok-voice-think-fast-2.0" ? value : null;
|
|
1052
|
+
return value === "gpt-live-1-boulder-alpha" || value === "supergrok/grok-voice-think-fast-2.0" || value === "opengeni-gateway/openai/gpt-realtime-2.1" || value === "opengeni-gateway/openai/gpt-realtime-mini" || value === "opengeni-gateway/xai/grok-voice-think-fast-2.0" || value === "workspace-gateway/openai/gpt-realtime-2.1" || value === "workspace-gateway/openai/gpt-realtime-mini" || value === "workspace-gateway/xai/grok-voice-think-fast-2.0" ? value : null;
|
|
955
1053
|
}
|
|
956
1054
|
function recordValue(value) {
|
|
957
1055
|
return value !== null && typeof value === "object" && !Array.isArray(value) ? value : null;
|
|
@@ -972,9 +1070,33 @@ var OUTBOUND_SYNC_INTERVAL_MS = 1e3;
|
|
|
972
1070
|
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];
|
|
1073
|
+
var MAX_BROWSER_TIMEOUT_MS = 2147483647;
|
|
975
1074
|
var OWNER_RECORD_VERSION = 1;
|
|
1075
|
+
var OWNER_DELEGATION_REPLAY_VERSION = 1;
|
|
1076
|
+
var OWNER_DELEGATION_REPLAY_MAX_CALLS = 4096;
|
|
1077
|
+
var OWNER_DELEGATION_REPLAY_MAX_BYTES = 4 * 1024 * 1024;
|
|
1078
|
+
var SESSION_REALTIME_INBOUND_ENTRY_KEYS = /* @__PURE__ */ new Set([
|
|
1079
|
+
"operationId",
|
|
1080
|
+
"kind",
|
|
1081
|
+
"role",
|
|
1082
|
+
"providerEventId",
|
|
1083
|
+
"delegationItemId",
|
|
1084
|
+
"text",
|
|
1085
|
+
"payload",
|
|
1086
|
+
"modelContext"
|
|
1087
|
+
]);
|
|
1088
|
+
var SESSION_REALTIME_INBOUND_KINDS = /* @__PURE__ */ new Set([
|
|
1089
|
+
"user_transcript",
|
|
1090
|
+
"assistant_transcript",
|
|
1091
|
+
"delegation_call",
|
|
1092
|
+
"interruption",
|
|
1093
|
+
"error"
|
|
1094
|
+
]);
|
|
1095
|
+
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
1096
|
function sessionRealtimeOwnerStorageNamespace(model) {
|
|
977
|
-
|
|
1097
|
+
if (model === "gpt-live-1-boulder-alpha") return "codex-realtime-owner";
|
|
1098
|
+
if (model === "supergrok/grok-voice-think-fast-2.0") return "xai-realtime-owner";
|
|
1099
|
+
return "gateway-realtime-owner";
|
|
978
1100
|
}
|
|
979
1101
|
function sessionRealtimeOwnerStorageKey(workspaceId, sessionId, model) {
|
|
980
1102
|
return ownerStorageKey(workspaceId, sessionId, sessionRealtimeOwnerStorageNamespace(model));
|
|
@@ -999,6 +1121,7 @@ function createCodexRealtimeController(options) {
|
|
|
999
1121
|
);
|
|
1000
1122
|
const model = options.model ?? "gpt-live-1-boulder-alpha";
|
|
1001
1123
|
const randomUUID = options.randomUUID ?? defaultRandomUUID2;
|
|
1124
|
+
const now = options.now ?? (() => /* @__PURE__ */ new Date());
|
|
1002
1125
|
const scheduleInterval = options.setInterval ?? ((callback, delay) => globalThis.setInterval(callback, delay));
|
|
1003
1126
|
const unscheduleInterval = options.clearInterval ?? ((handle) => globalThis.clearInterval(handle));
|
|
1004
1127
|
const scheduleTimeout = options.setTimeout ?? ((callback, delay) => globalThis.setTimeout(callback, delay));
|
|
@@ -1039,6 +1162,7 @@ function createCodexRealtimeController(options) {
|
|
|
1039
1162
|
let rotationTimer = null;
|
|
1040
1163
|
let reconnectTimer = null;
|
|
1041
1164
|
let negotiationTimer = null;
|
|
1165
|
+
let lostOwnerExpiryTimer = null;
|
|
1042
1166
|
let closed = false;
|
|
1043
1167
|
let stopping = false;
|
|
1044
1168
|
let generation = 0;
|
|
@@ -1046,6 +1170,45 @@ function createCodexRealtimeController(options) {
|
|
|
1046
1170
|
let recoveryTerminal = false;
|
|
1047
1171
|
let mutationTail = Promise.resolve();
|
|
1048
1172
|
let connectionTask = null;
|
|
1173
|
+
const acceptedDelegationItemIds = new Set(
|
|
1174
|
+
owner?.delegationReplay?.acceptedDelegationItemIds ?? []
|
|
1175
|
+
);
|
|
1176
|
+
const pendingDelegations = new Map(
|
|
1177
|
+
(owner?.delegationReplay?.pendingDelegations ?? []).flatMap(
|
|
1178
|
+
(entry) => entry.delegationItemId ? [[entry.delegationItemId, entry]] : []
|
|
1179
|
+
)
|
|
1180
|
+
);
|
|
1181
|
+
const invalidateStoredOwner = () => {
|
|
1182
|
+
try {
|
|
1183
|
+
storage?.removeItem(storageKey);
|
|
1184
|
+
} catch {
|
|
1185
|
+
}
|
|
1186
|
+
};
|
|
1187
|
+
const persistDelegationReplay = (input) => {
|
|
1188
|
+
if (!owner || !storage) return;
|
|
1189
|
+
const delegationReplay = {
|
|
1190
|
+
version: OWNER_DELEGATION_REPLAY_VERSION,
|
|
1191
|
+
acceptedDelegationItemIds: [...input.acceptedDelegationItemIds],
|
|
1192
|
+
pendingDelegations: [...input.pendingDelegations.values()]
|
|
1193
|
+
};
|
|
1194
|
+
if (delegationReplay.pendingDelegations.length > CODEX_REALTIME_V3_PENDING_MAX_ENTRIES || delegationReplay.acceptedDelegationItemIds.length + delegationReplay.pendingDelegations.length > OWNER_DELEGATION_REPLAY_MAX_CALLS) {
|
|
1195
|
+
invalidateStoredOwner();
|
|
1196
|
+
throw new Error("Realtime delegation replay journal exceeded its call limit");
|
|
1197
|
+
}
|
|
1198
|
+
const next = { ...owner, delegationReplay };
|
|
1199
|
+
const serialized = JSON.stringify(next);
|
|
1200
|
+
if (new TextEncoder().encode(serialized).byteLength > OWNER_DELEGATION_REPLAY_MAX_BYTES) {
|
|
1201
|
+
invalidateStoredOwner();
|
|
1202
|
+
throw new Error("Realtime delegation replay journal exceeded its byte limit");
|
|
1203
|
+
}
|
|
1204
|
+
try {
|
|
1205
|
+
storage.setItem(storageKey, serialized);
|
|
1206
|
+
} catch (error) {
|
|
1207
|
+
invalidateStoredOwner();
|
|
1208
|
+
throw error;
|
|
1209
|
+
}
|
|
1210
|
+
owner = next;
|
|
1211
|
+
};
|
|
1049
1212
|
const publish = (patch) => {
|
|
1050
1213
|
state = { ...state, ...patch };
|
|
1051
1214
|
for (const listener of listeners) listener({ ...state });
|
|
@@ -1071,11 +1234,13 @@ function createCodexRealtimeController(options) {
|
|
|
1071
1234
|
if (rotationTimer !== null) unscheduleTimeout(rotationTimer);
|
|
1072
1235
|
if (reconnectTimer !== null) unscheduleTimeout(reconnectTimer);
|
|
1073
1236
|
if (negotiationTimer !== null) unscheduleTimeout(negotiationTimer);
|
|
1237
|
+
if (lostOwnerExpiryTimer !== null) unscheduleTimeout(lostOwnerExpiryTimer);
|
|
1074
1238
|
heartbeatTimer = null;
|
|
1075
1239
|
syncTimer = null;
|
|
1076
1240
|
rotationTimer = null;
|
|
1077
1241
|
reconnectTimer = null;
|
|
1078
1242
|
negotiationTimer = null;
|
|
1243
|
+
lostOwnerExpiryTimer = null;
|
|
1079
1244
|
};
|
|
1080
1245
|
const stopNegotiationTimers = () => {
|
|
1081
1246
|
if (heartbeatTimer !== null) unscheduleInterval(heartbeatTimer);
|
|
@@ -1115,6 +1280,8 @@ function createCodexRealtimeController(options) {
|
|
|
1115
1280
|
const clearOwner = () => {
|
|
1116
1281
|
owner = null;
|
|
1117
1282
|
storage?.removeItem(storageKey);
|
|
1283
|
+
acceptedDelegationItemIds.clear();
|
|
1284
|
+
pendingDelegations.clear();
|
|
1118
1285
|
};
|
|
1119
1286
|
const transitionEnded = (message = "Realtime mode ended") => {
|
|
1120
1287
|
stopping = false;
|
|
@@ -1153,16 +1320,20 @@ function createCodexRealtimeController(options) {
|
|
|
1153
1320
|
publish({ microphone: "active" });
|
|
1154
1321
|
return acquired;
|
|
1155
1322
|
} catch (error) {
|
|
1156
|
-
|
|
1157
|
-
|
|
1323
|
+
const microphoneError = error instanceof CodexRealtimeMicrophoneError ? error : signal.aborted && state.microphone === "acquiring" ? new CodexRealtimeMicrophoneError(
|
|
1324
|
+
"acquisition_failed",
|
|
1325
|
+
"Microphone did not become available before voice startup timed out"
|
|
1326
|
+
) : null;
|
|
1327
|
+
if (microphoneError) {
|
|
1328
|
+
const kind = microphoneError.code === "permission_denied" ? "permission_failure" : "device_failure";
|
|
1158
1329
|
publish({
|
|
1159
|
-
microphone:
|
|
1330
|
+
microphone: microphoneError.code,
|
|
1160
1331
|
status: state.mode?.state === "active" ? "recovering" : "error",
|
|
1161
|
-
diagnostic: diagnostic(kind,
|
|
1162
|
-
error:
|
|
1332
|
+
diagnostic: diagnostic(kind, microphoneError.message, true),
|
|
1333
|
+
error: microphoneError.message
|
|
1163
1334
|
});
|
|
1164
1335
|
}
|
|
1165
|
-
throw error;
|
|
1336
|
+
throw microphoneError ?? error;
|
|
1166
1337
|
}
|
|
1167
1338
|
};
|
|
1168
1339
|
const syncForGeneration = async (targetGeneration, realtimeId, request) => await exclusive(async () => {
|
|
@@ -1188,7 +1359,10 @@ function createCodexRealtimeController(options) {
|
|
|
1188
1359
|
});
|
|
1189
1360
|
return;
|
|
1190
1361
|
}
|
|
1191
|
-
publish({
|
|
1362
|
+
publish({
|
|
1363
|
+
audibleOutput: next,
|
|
1364
|
+
...next === "audible" ? { error: null } : {}
|
|
1365
|
+
});
|
|
1192
1366
|
};
|
|
1193
1367
|
const startActiveIntervals = () => {
|
|
1194
1368
|
if (heartbeatTimer === null) {
|
|
@@ -1505,6 +1679,10 @@ function createCodexRealtimeController(options) {
|
|
|
1505
1679
|
listen: false,
|
|
1506
1680
|
sync: async (request) => await syncForGeneration(targetGeneration, activated.mode.id, request),
|
|
1507
1681
|
randomUUID,
|
|
1682
|
+
...options.getModelContext ? { getModelContext: options.getModelContext } : {},
|
|
1683
|
+
acceptedDelegationItemIds,
|
|
1684
|
+
pendingDelegations,
|
|
1685
|
+
onDelegationReplayStateChange: persistDelegationReplay,
|
|
1508
1686
|
onSnapshot: (nextBridge) => {
|
|
1509
1687
|
if (active?.generation === targetGeneration) publish({ bridge: nextBridge });
|
|
1510
1688
|
},
|
|
@@ -1670,7 +1848,12 @@ function createCodexRealtimeController(options) {
|
|
|
1670
1848
|
await handleConnectionFailure(error, "reconnect", false);
|
|
1671
1849
|
} else {
|
|
1672
1850
|
clearOwner();
|
|
1673
|
-
publish({
|
|
1851
|
+
publish({
|
|
1852
|
+
status: "error",
|
|
1853
|
+
realtimeId: null,
|
|
1854
|
+
mode: null,
|
|
1855
|
+
error: safeError2(error)
|
|
1856
|
+
});
|
|
1674
1857
|
}
|
|
1675
1858
|
throw error;
|
|
1676
1859
|
}
|
|
@@ -1724,6 +1907,12 @@ function createCodexRealtimeController(options) {
|
|
|
1724
1907
|
if (!record2 || record2.operationId !== lifecycle.operationId) {
|
|
1725
1908
|
closeBrowserResources();
|
|
1726
1909
|
owner = null;
|
|
1910
|
+
const leaseExpiresAt = Date.parse(lifecycle.leaseExpiresAt);
|
|
1911
|
+
const remainingLeaseMs = leaseExpiresAt - now().getTime();
|
|
1912
|
+
if (Number.isFinite(remainingLeaseMs) && remainingLeaseMs <= 0) {
|
|
1913
|
+
transitionEnded("Realtime lease expired");
|
|
1914
|
+
return;
|
|
1915
|
+
}
|
|
1727
1916
|
const message = "Realtime is active in another browser owner. It can resume after that owner stops or its lease expires.";
|
|
1728
1917
|
publish({
|
|
1729
1918
|
status: "lost_owner",
|
|
@@ -1733,13 +1922,26 @@ function createCodexRealtimeController(options) {
|
|
|
1733
1922
|
diagnostic: diagnostic("lost_owner", message, false),
|
|
1734
1923
|
error: message
|
|
1735
1924
|
});
|
|
1925
|
+
if (Number.isFinite(remainingLeaseMs) && remainingLeaseMs <= MAX_BROWSER_TIMEOUT_MS) {
|
|
1926
|
+
const observedRealtimeId = lifecycle.realtimeId;
|
|
1927
|
+
lostOwnerExpiryTimer = scheduleTimeout(() => {
|
|
1928
|
+
lostOwnerExpiryTimer = null;
|
|
1929
|
+
if (state.status === "lost_owner" && state.realtimeId === observedRealtimeId) {
|
|
1930
|
+
transitionEnded("Realtime lease expired");
|
|
1931
|
+
}
|
|
1932
|
+
}, remainingLeaseMs);
|
|
1933
|
+
}
|
|
1736
1934
|
return;
|
|
1737
1935
|
}
|
|
1738
1936
|
if (connectionTask || state.status === "starting") return;
|
|
1739
1937
|
closed = false;
|
|
1740
1938
|
stopping = false;
|
|
1741
1939
|
owner = record2;
|
|
1742
|
-
publish({
|
|
1940
|
+
publish({
|
|
1941
|
+
status: "recovering",
|
|
1942
|
+
realtimeId: lifecycle.realtimeId,
|
|
1943
|
+
error: null
|
|
1944
|
+
});
|
|
1743
1945
|
connectionTask = begin(record2, true).then(() => void 0).catch(async (error) => {
|
|
1744
1946
|
connectionTask = null;
|
|
1745
1947
|
await handleConnectionFailure(error, "reload", false);
|
|
@@ -1906,18 +2108,79 @@ function ownerStorageKey(workspaceId, sessionId, namespace = "codex-realtime-own
|
|
|
1906
2108
|
function readOwnerRecord(storage, key, scope) {
|
|
1907
2109
|
const raw = storage?.getItem(key);
|
|
1908
2110
|
if (!raw) return null;
|
|
2111
|
+
if (new TextEncoder().encode(raw).byteLength > OWNER_DELEGATION_REPLAY_MAX_BYTES) {
|
|
2112
|
+
storage?.removeItem(key);
|
|
2113
|
+
return null;
|
|
2114
|
+
}
|
|
1909
2115
|
try {
|
|
1910
2116
|
const parsed = recordValue2(JSON.parse(raw));
|
|
1911
|
-
|
|
2117
|
+
const delegationReplay = readOwnerDelegationReplay(parsed?.delegationReplay);
|
|
2118
|
+
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) {
|
|
1912
2119
|
storage?.removeItem(key);
|
|
1913
2120
|
return null;
|
|
1914
2121
|
}
|
|
1915
|
-
return
|
|
2122
|
+
return {
|
|
2123
|
+
...parsed,
|
|
2124
|
+
...delegationReplay ? { delegationReplay } : {}
|
|
2125
|
+
};
|
|
1916
2126
|
} catch {
|
|
1917
2127
|
storage?.removeItem(key);
|
|
1918
2128
|
return null;
|
|
1919
2129
|
}
|
|
1920
2130
|
}
|
|
2131
|
+
function readOwnerDelegationReplay(value) {
|
|
2132
|
+
if (value === void 0) return void 0;
|
|
2133
|
+
const record2 = recordValue2(value);
|
|
2134
|
+
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) {
|
|
2135
|
+
return null;
|
|
2136
|
+
}
|
|
2137
|
+
const acceptedDelegationItemIds = [];
|
|
2138
|
+
const accepted = /* @__PURE__ */ new Set();
|
|
2139
|
+
for (const candidate of record2.acceptedDelegationItemIds) {
|
|
2140
|
+
if (typeof candidate !== "string" || candidate.length < 1 || candidate.length > 1024) {
|
|
2141
|
+
return null;
|
|
2142
|
+
}
|
|
2143
|
+
if (!accepted.has(candidate)) {
|
|
2144
|
+
accepted.add(candidate);
|
|
2145
|
+
acceptedDelegationItemIds.push(candidate);
|
|
2146
|
+
}
|
|
2147
|
+
}
|
|
2148
|
+
const pendingDelegations = [];
|
|
2149
|
+
const pendingIds = /* @__PURE__ */ new Set();
|
|
2150
|
+
for (const candidate of record2.pendingDelegations) {
|
|
2151
|
+
const parsed = readSessionRealtimeInboundEntry(candidate);
|
|
2152
|
+
if (!parsed || parsed.kind !== "delegation_call" || !parsed.delegationItemId || accepted.has(parsed.delegationItemId) || pendingIds.has(parsed.delegationItemId)) {
|
|
2153
|
+
return null;
|
|
2154
|
+
}
|
|
2155
|
+
pendingIds.add(parsed.delegationItemId);
|
|
2156
|
+
pendingDelegations.push(parsed);
|
|
2157
|
+
}
|
|
2158
|
+
const replay = {
|
|
2159
|
+
version: OWNER_DELEGATION_REPLAY_VERSION,
|
|
2160
|
+
acceptedDelegationItemIds,
|
|
2161
|
+
pendingDelegations
|
|
2162
|
+
};
|
|
2163
|
+
if (new TextEncoder().encode(JSON.stringify(replay)).byteLength > OWNER_DELEGATION_REPLAY_MAX_BYTES) {
|
|
2164
|
+
return null;
|
|
2165
|
+
}
|
|
2166
|
+
return replay;
|
|
2167
|
+
}
|
|
2168
|
+
function readSessionRealtimeInboundEntry(value) {
|
|
2169
|
+
const record2 = recordValue2(value);
|
|
2170
|
+
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)) {
|
|
2171
|
+
return null;
|
|
2172
|
+
}
|
|
2173
|
+
return record2;
|
|
2174
|
+
}
|
|
2175
|
+
function optionalNullableEnum(value, allowed) {
|
|
2176
|
+
return value === void 0 || value === null || typeof value === "string" && allowed.includes(value);
|
|
2177
|
+
}
|
|
2178
|
+
function optionalNullableBoundedString(value, maxLength) {
|
|
2179
|
+
return value === void 0 || value === null || typeof value === "string" && value.length <= maxLength;
|
|
2180
|
+
}
|
|
2181
|
+
function optionalModelContext(value) {
|
|
2182
|
+
return value === void 0 || typeof value === "string" && value.length >= 1 && value.length <= 32768 && value.trim() === value;
|
|
2183
|
+
}
|
|
1921
2184
|
function defaultStorage() {
|
|
1922
2185
|
return typeof sessionStorage === "undefined" ? void 0 : sessionStorage;
|
|
1923
2186
|
}
|
|
@@ -1990,6 +2253,10 @@ function safeError2(error) {
|
|
|
1990
2253
|
}
|
|
1991
2254
|
|
|
1992
2255
|
export {
|
|
2256
|
+
CodexRealtimeMicrophoneError,
|
|
2257
|
+
startCodexRealtimeWebrtc,
|
|
2258
|
+
acquireCodexRealtimeMicrophone,
|
|
2259
|
+
codexRealtimeMicrophoneHealthy,
|
|
1993
2260
|
CODEX_REALTIME_INITIAL_ITEMS_MAX_COUNT,
|
|
1994
2261
|
CODEX_REALTIME_INITIAL_ITEMS_MAX_TOKENS,
|
|
1995
2262
|
CODEX_REALTIME_CONTEXT_APPEND_MAX_BYTES,
|
|
@@ -2004,10 +2271,6 @@ export {
|
|
|
2004
2271
|
CODEX_REALTIME_V3_PENDING_MAX_ENTRIES,
|
|
2005
2272
|
CODEX_REALTIME_V3_PENDING_MAX_BYTES,
|
|
2006
2273
|
createCodexRealtimeV3Bridge,
|
|
2007
|
-
CodexRealtimeMicrophoneError,
|
|
2008
|
-
startCodexRealtimeWebrtc,
|
|
2009
|
-
acquireCodexRealtimeMicrophone,
|
|
2010
|
-
codexRealtimeMicrophoneHealthy,
|
|
2011
2274
|
projectSessionRealtimeLifecycle,
|
|
2012
2275
|
CODEX_REALTIME_NEGOTIATION_TIMEOUT_MS,
|
|
2013
2276
|
sessionRealtimeOwnerStorageNamespace,
|
|
@@ -2015,4 +2278,4 @@ export {
|
|
|
2015
2278
|
hasStoredSessionRealtimeOwnerProof,
|
|
2016
2279
|
createCodexRealtimeController
|
|
2017
2280
|
};
|
|
2018
|
-
//# sourceMappingURL=chunk-
|
|
2281
|
+
//# sourceMappingURL=chunk-2UXZUCEZ.js.map
|