@opengeni/react 3.8.0-canary.0 → 4.0.1-canary.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.
Files changed (111) hide show
  1. package/README.md +11 -24
  2. package/dist/artifacts.js +7 -7
  3. package/dist/{browser-viewer-SS46LUAC.js → browser-viewer-NTD6UIPR.js} +3 -3
  4. package/dist/{chunk-VEPNNDNG.js → chunk-24M4YBCL.js} +4 -4
  5. package/dist/chunk-5M6VTFJ5.js +171 -0
  6. package/dist/chunk-5M6VTFJ5.js.map +1 -0
  7. package/dist/{chunk-IOLVN74D.js → chunk-6J56T3MG.js} +15 -1
  8. package/dist/chunk-6J56T3MG.js.map +1 -0
  9. package/dist/{chunk-ELIYWBZR.js → chunk-BV5A4OTE.js} +4 -4
  10. package/dist/{chunk-3HIF5IFC.js → chunk-HO6X4FHG.js} +2597 -1030
  11. package/dist/chunk-HO6X4FHG.js.map +1 -0
  12. package/dist/{chunk-BXJOQFCD.js → chunk-HUMIRRYI.js} +84 -221
  13. package/dist/chunk-HUMIRRYI.js.map +1 -0
  14. package/dist/{chunk-ZFOFY5ST.js → chunk-NLTS7JHI.js} +16 -31
  15. package/dist/chunk-NLTS7JHI.js.map +1 -0
  16. package/dist/chunk-NOSYBS2D.js +208 -0
  17. package/dist/chunk-NOSYBS2D.js.map +1 -0
  18. package/dist/chunk-YBM6CQRU.js +292 -0
  19. package/dist/chunk-YBM6CQRU.js.map +1 -0
  20. package/dist/{chunk-BQGIXRKV.js → chunk-Z7WBDB4E.js} +416 -290
  21. package/dist/chunk-Z7WBDB4E.js.map +1 -0
  22. package/dist/chunk-ZYRGEKWS.js +216 -0
  23. package/dist/chunk-ZYRGEKWS.js.map +1 -0
  24. package/dist/components/composer.d.ts +4 -2
  25. package/dist/components/human-input-form.d.ts +3 -1
  26. package/dist/components/human-input-surface.d.ts +3 -2
  27. package/dist/components/message-timeline.d.ts +9 -2
  28. package/dist/components/session-conversation.d.ts +2 -0
  29. package/dist/components/timeline-annotation-chrome.d.ts +25 -0
  30. package/dist/components/timeline-annotation-layout.d.ts +42 -0
  31. package/dist/components/timeline-annotation-markers.d.ts +8 -0
  32. package/dist/components/timeline-annotation-reveal-context.d.ts +4 -0
  33. package/dist/components/timeline-annotation-shared.d.ts +31 -0
  34. package/dist/components/timeline-annotations-dialog.d.ts +1 -1
  35. package/dist/components/timeline-annotations.d.ts +8 -2
  36. package/dist/composer.js +3 -4
  37. package/dist/{computer-viewer-FWEZISW4.js → computer-viewer-7TEZC6Y2.js} +3 -3
  38. package/dist/hooks/use-codex-accounts.d.ts +11 -1
  39. package/dist/hooks/use-composer.d.ts +2 -0
  40. package/dist/hooks/use-session-events.d.ts +2 -2
  41. package/dist/index.d.ts +1 -1
  42. package/dist/index.js +50 -37
  43. package/dist/index.js.map +1 -1
  44. package/dist/interaction.js +3 -3
  45. package/dist/machines.js +1 -1
  46. package/dist/older-history.d.ts +3 -2
  47. package/dist/{platform-activity-row-BJHUHXAT.js → platform-activity-row-27LKAWZD.js} +2 -2
  48. package/dist/platform-activity-row-27LKAWZD.js.map +1 -0
  49. package/dist/{queue-surface-implementation-XL2A6PBM.js → queue-surface-implementation-LK3S4BIW.js} +5 -2
  50. package/dist/{queue-surface-implementation-XL2A6PBM.js.map → queue-surface-implementation-LK3S4BIW.js.map} +1 -1
  51. package/dist/realtime.js +3 -3
  52. package/dist/session-ui.js +11 -11
  53. package/dist/session.js +2 -2
  54. package/dist/timeline/types.d.ts +3 -0
  55. package/dist/timeline-annotation-markers-DRSTLEM6.js +165 -0
  56. package/dist/timeline-annotation-markers-DRSTLEM6.js.map +1 -0
  57. package/dist/timeline-annotation-selection-IHLUGVND.js +236 -0
  58. package/dist/timeline-annotation-selection-IHLUGVND.js.map +1 -0
  59. package/dist/timeline-annotations-dialog-6Q53N5FG.js +262 -0
  60. package/dist/timeline-annotations-dialog-6Q53N5FG.js.map +1 -0
  61. package/package.json +2 -6
  62. package/src/components/chat-composer.tsx +5 -2
  63. package/src/components/composer.tsx +40 -5
  64. package/src/components/copy-button.tsx +1 -0
  65. package/src/components/human-input-form.tsx +185 -53
  66. package/src/components/human-input-surface.tsx +3 -0
  67. package/src/components/machines-dashboard.tsx +1 -16
  68. package/src/components/message-timeline.tsx +397 -302
  69. package/src/components/session-commands-panel.tsx +7 -1
  70. package/src/components/session-conversation.tsx +4 -1
  71. package/src/components/timeline-annotation-chrome.tsx +183 -0
  72. package/src/components/timeline-annotation-layout.ts +268 -0
  73. package/src/components/timeline-annotation-markers.tsx +185 -0
  74. package/src/components/timeline-annotation-reveal-context.ts +9 -0
  75. package/src/components/timeline-annotation-selection.tsx +99 -54
  76. package/src/components/timeline-annotation-shared.ts +245 -0
  77. package/src/components/timeline-annotations-dialog.tsx +172 -128
  78. package/src/components/timeline-annotations.tsx +178 -45
  79. package/src/hooks/use-codex-accounts.ts +32 -5
  80. package/src/hooks/use-composer.ts +17 -0
  81. package/src/hooks/use-session-events.ts +16 -277
  82. package/src/index.ts +0 -1
  83. package/src/older-history.ts +22 -4
  84. package/src/timeline/platform-activity-row.tsx +4 -1
  85. package/src/timeline/projection.ts +99 -9
  86. package/src/timeline/types.ts +3 -0
  87. package/styles/compiled.css +86 -22
  88. package/dist/chat.d.ts +0 -37
  89. package/dist/chat.js +0 -315
  90. package/dist/chat.js.map +0 -1
  91. package/dist/chunk-3HIF5IFC.js.map +0 -1
  92. package/dist/chunk-BQGIXRKV.js.map +0 -1
  93. package/dist/chunk-BXJOQFCD.js.map +0 -1
  94. package/dist/chunk-F2CFHN3Y.js +0 -1415
  95. package/dist/chunk-F2CFHN3Y.js.map +0 -1
  96. package/dist/chunk-HQV2I5HV.js +0 -124
  97. package/dist/chunk-HQV2I5HV.js.map +0 -1
  98. package/dist/chunk-IOLVN74D.js.map +0 -1
  99. package/dist/chunk-W3OUAH6M.js +0 -170
  100. package/dist/chunk-W3OUAH6M.js.map +0 -1
  101. package/dist/chunk-ZFOFY5ST.js.map +0 -1
  102. package/dist/platform-activity-row-BJHUHXAT.js.map +0 -1
  103. package/dist/timeline-annotation-selection-3L7LHGG2.js +0 -187
  104. package/dist/timeline-annotation-selection-3L7LHGG2.js.map +0 -1
  105. package/dist/timeline-annotations-dialog-U7EVLR75.js +0 -196
  106. package/dist/timeline-annotations-dialog-U7EVLR75.js.map +0 -1
  107. package/src/chat.tsx +0 -393
  108. /package/dist/{browser-viewer-SS46LUAC.js.map → browser-viewer-NTD6UIPR.js.map} +0 -0
  109. /package/dist/{chunk-VEPNNDNG.js.map → chunk-24M4YBCL.js.map} +0 -0
  110. /package/dist/{chunk-ELIYWBZR.js.map → chunk-BV5A4OTE.js.map} +0 -0
  111. /package/dist/{computer-viewer-FWEZISW4.js.map → computer-viewer-7TEZC6Y2.js.map} +0 -0
@@ -66,13 +66,17 @@ function isRecord(value) {
66
66
 
67
67
  // src/older-history.ts
68
68
  var activeReceiptCapture;
69
- function invokeOlderHistoryLoaderWithReceiptCapture(load, capture) {
69
+ var preserveTailForAutomaticLoad = false;
70
+ function invokeOlderHistoryLoaderWithReceiptCapture(load, capture, preserveTail = false) {
70
71
  const previousCapture = activeReceiptCapture;
72
+ const previousPreserveTail = preserveTailForAutomaticLoad;
71
73
  activeReceiptCapture = capture;
74
+ preserveTailForAutomaticLoad = preserveTail;
72
75
  try {
73
76
  return load();
74
77
  } finally {
75
78
  activeReceiptCapture = previousCapture;
79
+ preserveTailForAutomaticLoad = previousPreserveTail;
76
80
  }
77
81
  }
78
82
  function createOlderHistoryLoadReceipt(load) {
@@ -83,11 +87,18 @@ function createOlderHistoryLoadReceipt(load) {
83
87
  rejectResult = reject;
84
88
  });
85
89
  result.committed = false;
90
+ result.tailPreserved = false;
86
91
  activeReceiptCapture?.(result);
87
92
  try {
88
- const loaded = load(() => {
89
- result.committed = true;
90
- });
93
+ const loaded = load(
94
+ () => {
95
+ result.committed = true;
96
+ },
97
+ preserveTailForAutomaticLoad,
98
+ () => {
99
+ result.tailPreserved = true;
100
+ }
101
+ );
91
102
  Promise.resolve(loaded).then(resolveResult, rejectResult);
92
103
  } catch (error) {
93
104
  rejectResult(error);
@@ -403,6 +414,7 @@ function buildTimeline(events) {
403
414
  const ordered = orderTimelineEvents(events, prescan);
404
415
  const pendingWaitOutcomeByTurn = /* @__PURE__ */ new Map();
405
416
  const latestAgentResponseByTurn = /* @__PURE__ */ new Map();
417
+ const identifiedMessages = /* @__PURE__ */ new Map();
406
418
  const humanInputRequests = humanInputRequestsById(events);
407
419
  const humanInputToolCallIds = new Set(
408
420
  [...humanInputRequests.values()].map((request) => stringValue(request.toolCallId)).filter(Boolean)
@@ -414,7 +426,7 @@ function buildTimeline(events) {
414
426
  let startupTurnId = null;
415
427
  let startupAttemptId = null;
416
428
  let startupRecoveryRevision = 0;
417
- const settleStartupPhase = (phase, status, duration, outcome, mode = 0, explicitStartedAt, explicitId) => {
429
+ const settleStartupPhase = (phase, status, duration, outcome, mode = 0, explicitStartedAt, explicitId, blockedReason) => {
418
430
  const key = `${startupTurnId}:${phase}`;
419
431
  const priorState = startupPhases.get(key);
420
432
  const prior = priorState?.[0];
@@ -430,6 +442,7 @@ function buildTimeline(events) {
430
442
  open.completedAt = startupEvent.occurredAt;
431
443
  open.durationMs = duration === null ? elapsedDurationMs(open.startedAt, startupEvent.occurredAt) : Math.max(0, duration);
432
444
  open.outcome = outcome ?? open.outcome;
445
+ open.blockedReason = blockedReason;
433
446
  return;
434
447
  }
435
448
  const running = status === "running";
@@ -444,6 +457,7 @@ function buildTimeline(events) {
444
457
  completedAt: running ? null : startupEvent.occurredAt,
445
458
  durationMs,
446
459
  outcome,
460
+ blockedReason,
447
461
  occurredAt: startedAt
448
462
  });
449
463
  startupPhases.set(key, [prior, startupAttemptId, startupRecoveryRevision]);
@@ -459,6 +473,7 @@ function buildTimeline(events) {
459
473
  completedAt: running ? null : startupEvent.occurredAt,
460
474
  durationMs,
461
475
  outcome,
476
+ blockedReason,
462
477
  occurredAt: startedAt
463
478
  };
464
479
  items.push(item);
@@ -601,8 +616,28 @@ function buildTimeline(events) {
601
616
  if (!text) {
602
617
  break;
603
618
  }
619
+ const messageId = stringValue(payload.messageId);
620
+ const messageKey = messageId ? JSON.stringify([turnId, messageId]) : null;
621
+ const identified = messageKey ? identifiedMessages.get(messageKey) : void 0;
622
+ if (identified) {
623
+ if (identified.annotationSource?.eventType !== "agent.message.completed") {
624
+ identified.text += text;
625
+ rememberAgentResponse(turnId, identified, false);
626
+ }
627
+ break;
628
+ }
604
629
  const open = last();
605
- if (open?.kind === "agent-message" && open.streaming && open.turnId === turnId) {
630
+ if (!messageKey && open?.kind === "tool-call" && open.status === "running") {
631
+ const previous = latestAgentResponseByTurn.get(turnId);
632
+ const previousIndex = previous ? items.indexOf(previous.item) : -1;
633
+ if (previous && !previous.completed && previousIndex >= 0 && items.slice(previousIndex + 1).every(
634
+ (item2) => item2.kind === "tool-call" && item2.turnId === turnId && item2.status === "running"
635
+ )) {
636
+ previous.item.text += text;
637
+ break;
638
+ }
639
+ }
640
+ if (!messageKey && open?.kind === "agent-message" && open.streaming && open.turnId === turnId) {
606
641
  open.text += text;
607
642
  rememberAgentResponse(turnId, open, false);
608
643
  break;
@@ -617,14 +652,17 @@ function buildTimeline(events) {
617
652
  occurredAt: event.occurredAt
618
653
  };
619
654
  items.push(item);
655
+ if (messageKey) identifiedMessages.set(messageKey, item);
620
656
  rememberAgentResponse(turnId, item, false);
621
657
  break;
622
658
  }
623
659
  case "agent.message.completed": {
624
660
  const text = stringValue(payload.text);
661
+ const messageId = stringValue(payload.messageId);
662
+ const messageKey = messageId ? JSON.stringify([turnId, messageId]) : null;
625
663
  const phase = assistantMessagePhase(payload.phase);
626
- let openIndex = -1;
627
- for (let index = items.length - 1; index >= 0; index -= 1) {
664
+ let openIndex = messageKey ? items.indexOf(identifiedMessages.get(messageKey)) : -1;
665
+ for (let index = messageKey ? -1 : items.length - 1; index >= 0; index -= 1) {
628
666
  const candidate2 = items[index];
629
667
  if (candidate2?.kind === "agent-message" && candidate2.turnId === turnId) {
630
668
  openIndex = index;
@@ -633,8 +671,8 @@ function buildTimeline(events) {
633
671
  }
634
672
  const candidate = openIndex >= 0 ? items[openIndex] : void 0;
635
673
  const open = candidate?.kind === "agent-message" ? candidate : void 0;
636
- if (open && (open.streaming || !open.text || text === open.text || text.startsWith(open.text))) {
637
- if (!open.text || text && text.startsWith(open.text)) {
674
+ if (open && (messageKey || open.streaming || !open.text || text === open.text || text.startsWith(open.text))) {
675
+ if (!open.text || text && (messageKey || text.startsWith(open.text))) {
638
676
  open.text = text || open.text;
639
677
  }
640
678
  open.streaming = false;
@@ -674,6 +712,7 @@ function buildTimeline(events) {
674
712
  }
675
713
  };
676
714
  items.push(item);
715
+ if (messageKey) identifiedMessages.set(messageKey, item);
677
716
  rememberAgentResponse(turnId, item, true);
678
717
  }
679
718
  break;
@@ -823,7 +862,16 @@ function buildTimeline(events) {
823
862
  const startupPhase = startupPhaseForSandboxOperation(name);
824
863
  if (startupPhase) {
825
864
  closeStreamingTail();
826
- settleStartupPhase(startupPhase, status, numberOrNull(payload.durationMs), origin);
865
+ settleStartupPhase(
866
+ startupPhase,
867
+ status,
868
+ numberOrNull(payload.durationMs),
869
+ origin,
870
+ 0,
871
+ void 0,
872
+ void 0,
873
+ status === "cancelled" && payload.failureCode === "rotation_in_progress" ? "rotation_in_progress" : void 0
874
+ );
827
875
  break;
828
876
  }
829
877
  if ((name === "repository-clone" || name === "file-resource-download") && status !== "failed") {
@@ -1063,8 +1111,12 @@ ${message}` : message;
1063
1111
  }
1064
1112
  }
1065
1113
  finalizeOpen(turnId, "complete", event.occurredAt);
1066
- items.push(turnEndItem(event, "complete", null));
1114
+ const completedTurn = turnEndItem(event, "complete", null);
1115
+ items.push(completedTurn);
1067
1116
  const hasCompletedFinalResponse = latestAgentResponse?.completed === true && latestAgentResponse.item.phase !== "commentary" && Boolean(visibleTrackedResponse);
1117
+ if (!hasAuthoritativeFinalOutput && pendingWaitOutcome) {
1118
+ completedTurn.preserveWaitResponse = true;
1119
+ }
1068
1120
  if (!hasAuthoritativeFinalOutput && !hasCompletedFinalResponse && pendingWaitOutcome) {
1069
1121
  items.push({
1070
1122
  kind: "notice",
@@ -1615,7 +1667,13 @@ function foldSettledTurn(groups, turnEnd) {
1615
1667
  if (collected.length === 0) {
1616
1668
  return;
1617
1669
  }
1618
- const finalMessage = extractFinalAgentMessage(collected, turnEnd);
1670
+ const waitMessages = turnEnd.preserveWaitResponse ? collected.filter(
1671
+ (group) => group.kind === "item" && group.item.kind === "agent-message" && !group.item.streaming && group.item.text.trim().length > 0 && belongsToTurn(group.item, turnEnd.turnId)
1672
+ ) : [];
1673
+ const waitResponse = waitMessages.slice().reverse().find(
1674
+ (group) => group.item.kind === "agent-message" && group.item.phase !== "commentary" && group.item.annotationSource?.eventType === "agent.message.completed"
1675
+ ) ?? waitMessages.at(-1);
1676
+ const finalMessage = waitResponse ?? extractFinalAgentMessage(collected, turnEnd);
1619
1677
  const fallbackMessage = finalMessage || hasOrdinaryFinalAgentMessage(collected, turnEnd) ? null : extractLatestCompletedCommentary(collected, turnEnd);
1620
1678
  const visibleMessage = finalMessage ?? fallbackMessage;
1621
1679
  const body = visibleMessage ? collected.filter((group) => group !== visibleMessage) : collected;
@@ -2157,32 +2215,8 @@ var FOREGROUND_COMPACT_CATCHUP_MAX_GROUPS = 16;
2157
2215
  var FOREGROUND_COMPACT_CATCHUP_MAX_BYTES = 512 * 1024;
2158
2216
  var EMPTY_EVENTS = [];
2159
2217
  var encoder = new TextEncoder();
2160
- var decoder = new TextDecoder();
2161
- var BROWSER_EVENT_TYPE_MAX_BYTES = 256;
2162
- var BROWSER_EVENT_ID_MAX_BYTES = 256;
2163
- var BROWSER_EVENT_CLIENT_ID_MAX_BYTES = 4 * 1024;
2164
- var BROWSER_EVENT_DUPLICATE_REASON_MAX_BYTES = 4 * 1024;
2165
- var BROWSER_EVENT_PAYLOAD_PREVIEW_MAX_BYTES = 48 * 1024;
2166
- var BROWSER_EVENT_PAYLOAD_IDENTITY_FIELDS = [
2167
- "id",
2168
- "callId",
2169
- "call_id",
2170
- "name",
2171
- "toolName",
2172
- "status",
2173
- "code",
2174
- "isError",
2175
- "stream",
2176
- "commandId",
2177
- "sequence",
2178
- "coalescedUntil",
2179
- "coalescedCount",
2180
- "firstSequence",
2181
- "lastSequence"
2182
- ];
2183
2218
  var SESSION_EVENT_BROWSER_MAX_BYTES = 8 * 1024 * 1024;
2184
2219
  var SESSION_EVENT_BROWSER_MAX_COUNT = 1e4;
2185
- var SESSION_EVENT_BROWSER_SINGLE_EVENT_MAX_BYTES = 96 * 1024;
2186
2220
  var SESSION_EVENT_BROWSER_PENDING_MAX_BYTES = 1024 * 1024;
2187
2221
  var SESSION_EVENT_BROWSER_PENDING_MAX_COUNT = 256;
2188
2222
  var EMPTY_EVENT_WINDOW = {
@@ -2455,7 +2489,7 @@ function useSessionEvents(sessionId, options = {}) {
2455
2489
  });
2456
2490
  for await (const event of stream) {
2457
2491
  if (!isCurrent()) break;
2458
- const boundedEvent = boundBrowserLegacyEvent(event);
2492
+ const boundedEvent = event;
2459
2493
  const boundedEventBytes = browserJsonBytes(boundedEvent);
2460
2494
  const separatorBytes = pending.length === 0 ? 0 : 1;
2461
2495
  if (pending.length > 0 && (pending.length >= SESSION_EVENT_BROWSER_PENDING_MAX_COUNT || pendingBytes + separatorBytes + boundedEventBytes > SESSION_EVENT_BROWSER_PENDING_MAX_BYTES)) {
@@ -2510,7 +2544,7 @@ function useSessionEvents(sessionId, options = {}) {
2510
2544
  ]);
2511
2545
  const navigationBusy = () => loadingOlderRef.current || loadingNewerRef.current || loadingOldestRef.current || loadingLatestRef.current;
2512
2546
  const loadOlder = useCallback(
2513
- () => createOlderHistoryLoadReceipt(async (markCommitted) => {
2547
+ () => createOlderHistoryLoadReceipt(async (markCommitted, preserveTail, markTailPreserved) => {
2514
2548
  if (!sessionId || navigationBusy() || !hasOlderRef.current) {
2515
2549
  return false;
2516
2550
  }
@@ -2543,11 +2577,15 @@ function useSessionEvents(sessionId, options = {}) {
2543
2577
  }
2544
2578
  const current = eventWindowRef.current;
2545
2579
  assertPrependOrder(current.events, window.events);
2546
- streamAbortRef.current?.abort();
2547
- const status = observeSessionStatus(window.events, sessionStatusRef);
2548
2580
  const next = boundBrowserSessionEventWindow([...window.events, ...current.events], {
2549
2581
  direction: "oldest"
2550
2582
  });
2583
+ if (preserveTail && maxResumeSequence(next.events) < maxResumeSequence(current.events)) {
2584
+ markTailPreserved();
2585
+ return false;
2586
+ }
2587
+ streamAbortRef.current?.abort();
2588
+ const status = observeSessionStatus(window.events, sessionStatusRef);
2551
2589
  const retained = {
2552
2590
  ...next,
2553
2591
  truncated: current.truncated || next.truncated
@@ -2820,7 +2858,7 @@ function useSessionEvents(sessionId, options = {}) {
2820
2858
  function boundBrowserSessionEventWindow(events, options = {}) {
2821
2859
  const maxBytes = Math.max(1024, options.maxBytes ?? SESSION_EVENT_BROWSER_MAX_BYTES);
2822
2860
  const maxCount = Math.max(1, Math.floor(options.maxCount ?? SESSION_EVENT_BROWSER_MAX_COUNT));
2823
- const safe = events.map(boundBrowserLegacyEvent);
2861
+ const safe = events;
2824
2862
  const selected = [];
2825
2863
  let bytes = 2;
2826
2864
  const direction = options.direction ?? "newest";
@@ -2831,7 +2869,7 @@ function boundBrowserSessionEventWindow(events, options = {}) {
2831
2869
  const event = safe[index];
2832
2870
  const eventBytes = browserJsonBytes(event);
2833
2871
  const separator = selected.length === 0 ? 0 : 1;
2834
- if (bytes + separator + eventBytes > maxBytes) break;
2872
+ if (selected.length > 0 && bytes + separator + eventBytes > maxBytes) break;
2835
2873
  selected.push(event);
2836
2874
  bytes += separator + eventBytes;
2837
2875
  }
@@ -2842,182 +2880,8 @@ function boundBrowserSessionEventWindow(events, options = {}) {
2842
2880
  truncated: selected.length < safe.length
2843
2881
  };
2844
2882
  }
2845
- function boundBrowserLegacyEvent(event) {
2846
- const serialized = browserSerialize(event);
2847
- const originalBytes = serialized.serializable ? encoder.encode(serialized.value).byteLength : null;
2848
- const typeIsSafe = browserUtf8Bytes(event.type) <= BROWSER_EVENT_TYPE_MAX_BYTES && !event.type.includes("\n") && !event.type.includes("\r");
2849
- const clientEventId = boundBrowserOptionalText(
2850
- event.clientEventId,
2851
- BROWSER_EVENT_CLIENT_ID_MAX_BYTES
2852
- );
2853
- const duplicateReason = boundBrowserOptionalText(
2854
- event.duplicateReason,
2855
- BROWSER_EVENT_DUPLICATE_REASON_MAX_BYTES
2856
- );
2857
- if (serialized.serializable && originalBytes !== null && originalBytes <= SESSION_EVENT_BROWSER_SINGLE_EVENT_MAX_BYTES && typeIsSafe && clientEventId === event.clientEventId && duplicateReason === event.duplicateReason) {
2858
- return event;
2859
- }
2860
- const envelopeProjection = [
2861
- !typeIsSafe ? browserEnvelopeFieldProjection("type", event.type, "session.event.envelope_omitted") : null,
2862
- clientEventId !== event.clientEventId ? browserEnvelopeFieldProjection("clientEventId", event.clientEventId, clientEventId) : null,
2863
- duplicateReason !== event.duplicateReason ? browserEnvelopeFieldProjection("duplicateReason", event.duplicateReason, duplicateReason) : null
2864
- ].filter((field) => field !== null);
2865
- const payloadSerialization = browserSerialize(event.payload);
2866
- const payloadBytes = payloadSerialization.serializable ? encoder.encode(payloadSerialization.value).byteLength : null;
2867
- const preview = truncateBrowserUtf8Middle(
2868
- payloadSerialization.value,
2869
- BROWSER_EVENT_PAYLOAD_PREVIEW_MAX_BYTES
2870
- );
2871
- const truncation = {
2872
- truncated: true,
2873
- surface: "browser_legacy_guard",
2874
- reason: serialized.serializable ? "event_envelope_bytes_exceeded" : "event_not_serializable",
2875
- originalBytes,
2876
- deliveredBytes: 0,
2877
- omittedBytes: originalBytes,
2878
- estimatedOriginalTokens: originalBytes === null ? null : Math.ceil(originalBytes / 4),
2879
- estimatedDeliveredTokens: 0,
2880
- fullEvidence: { available: false, reason: "not_retained" },
2881
- details: [
2882
- {
2883
- path: "$.payload",
2884
- kind: "payload_preview",
2885
- originalBytes: payloadBytes,
2886
- deliveredBytes: browserUtf8Bytes(preview)
2887
- }
2888
- ]
2889
- };
2890
- const payload = {
2891
- ...browserPayloadIdentity(event.payload),
2892
- preview,
2893
- ...envelopeProjection.length > 0 ? {
2894
- originalType: boundBrowserText(event.type, BROWSER_EVENT_TYPE_MAX_BYTES),
2895
- envelopeProjection: {
2896
- truncated: true,
2897
- surface: "browser_legacy_guard",
2898
- fields: envelopeProjection
2899
- }
2900
- } : {},
2901
- truncation
2902
- };
2903
- const bounded = {
2904
- id: boundBrowserText(event.id, BROWSER_EVENT_ID_MAX_BYTES),
2905
- workspaceId: boundBrowserText(event.workspaceId, BROWSER_EVENT_ID_MAX_BYTES),
2906
- sessionId: boundBrowserText(event.sessionId, BROWSER_EVENT_ID_MAX_BYTES),
2907
- sequence: event.sequence,
2908
- type: typeIsSafe ? event.type : "session.event.envelope_omitted",
2909
- payload,
2910
- occurredAt: boundBrowserText(event.occurredAt, BROWSER_EVENT_ID_MAX_BYTES),
2911
- clientEventId,
2912
- turnId: boundBrowserOptionalText(event.turnId, BROWSER_EVENT_ID_MAX_BYTES),
2913
- turnGeneration: event.turnGeneration,
2914
- turnAttemptId: boundBrowserOptionalText(event.turnAttemptId, BROWSER_EVENT_ID_MAX_BYTES),
2915
- turnAssociation: event.turnAssociation,
2916
- duplicateOfEventId: boundBrowserOptionalText(
2917
- event.duplicateOfEventId,
2918
- BROWSER_EVENT_ID_MAX_BYTES
2919
- ),
2920
- duplicateReason
2921
- };
2922
- settleBrowserEventTruncation(bounded, truncation);
2923
- if (browserJsonBytes(bounded) > SESSION_EVENT_BROWSER_SINGLE_EVENT_MAX_BYTES) {
2924
- payload.preview = truncateBrowserUtf8Middle(String(payload.preview), 4 * 1024);
2925
- truncation.details = truncation.details.slice(0, 1);
2926
- settleBrowserEventTruncation(bounded, truncation);
2927
- }
2928
- if (browserJsonBytes(bounded) > SESSION_EVENT_BROWSER_SINGLE_EVENT_MAX_BYTES) {
2929
- bounded.clientEventId = null;
2930
- bounded.duplicateReason = null;
2931
- payload.preview = "[legacy event omitted at the browser byte boundary]";
2932
- settleBrowserEventTruncation(bounded, truncation);
2933
- }
2934
- return bounded;
2935
- }
2936
2883
  function browserJsonBytes(value) {
2937
- return encoder.encode(browserSerialize(value).value).byteLength;
2938
- }
2939
- function browserSerialize(value) {
2940
- try {
2941
- const serialized = JSON.stringify(value);
2942
- return { value: serialized === void 0 ? "null" : serialized, serializable: true };
2943
- } catch {
2944
- return {
2945
- value: '"[unserializable event payload omitted at browser boundary]"',
2946
- serializable: false
2947
- };
2948
- }
2949
- }
2950
- function browserPayloadIdentity(payload) {
2951
- if (!payload || typeof payload !== "object" || Array.isArray(payload)) return {};
2952
- const record = payload;
2953
- const identity = {};
2954
- for (const field of BROWSER_EVENT_PAYLOAD_IDENTITY_FIELDS) {
2955
- const value = record[field];
2956
- if (typeof value === "string") {
2957
- identity[field] = boundBrowserText(value, BROWSER_EVENT_ID_MAX_BYTES);
2958
- } else if (typeof value === "number" || typeof value === "boolean" || value === null) {
2959
- identity[field] = value;
2960
- }
2961
- }
2962
- return identity;
2963
- }
2964
- function browserEnvelopeFieldProjection(field, original, delivered) {
2965
- return {
2966
- field,
2967
- originalBytes: typeof original === "string" ? browserUtf8Bytes(original) : 0,
2968
- deliveredBytes: typeof delivered === "string" ? browserUtf8Bytes(delivered) : 0
2969
- };
2970
- }
2971
- function boundBrowserOptionalText(value, maxBytes) {
2972
- return typeof value === "string" ? boundBrowserText(value, maxBytes) : value;
2973
- }
2974
- function boundBrowserText(value, maxBytes) {
2975
- const bytes = encoder.encode(value);
2976
- if (bytes.byteLength <= maxBytes) return value;
2977
- const marker = "\u2026[truncated]";
2978
- const prefixBudget = Math.max(0, maxBytes - browserUtf8Bytes(marker));
2979
- let prefixEnd = Math.min(prefixBudget, bytes.byteLength);
2980
- while (prefixEnd > 0 && prefixEnd < bytes.byteLength && isBrowserUtf8Continuation(bytes[prefixEnd])) {
2981
- prefixEnd -= 1;
2982
- }
2983
- return `${decoder.decode(bytes.subarray(0, prefixEnd))}${marker}`;
2984
- }
2985
- function truncateBrowserUtf8Middle(value, maxBytes) {
2986
- const bytes = encoder.encode(value);
2987
- if (bytes.byteLength <= maxBytes) return value;
2988
- const marker = `\u2026[${bytes.byteLength - maxBytes} bytes omitted]\u2026`;
2989
- const contentBudget = Math.max(0, maxBytes - browserUtf8Bytes(marker));
2990
- const leftBudget = Math.floor(contentBudget / 2);
2991
- const rightBudget = contentBudget - leftBudget;
2992
- let leftEnd = Math.min(leftBudget, bytes.byteLength);
2993
- while (leftEnd > 0 && leftEnd < bytes.byteLength && isBrowserUtf8Continuation(bytes[leftEnd])) {
2994
- leftEnd -= 1;
2995
- }
2996
- let rightStart = Math.max(0, bytes.byteLength - rightBudget);
2997
- while (rightStart < bytes.byteLength && isBrowserUtf8Continuation(bytes[rightStart])) {
2998
- rightStart += 1;
2999
- }
3000
- return `${decoder.decode(bytes.subarray(0, leftEnd))}${marker}${decoder.decode(bytes.subarray(rightStart))}`;
3001
- }
3002
- function settleBrowserEventTruncation(event, truncation) {
3003
- for (let attempt = 0; attempt < 16; attempt += 1) {
3004
- const deliveredBytes = browserJsonBytes(event);
3005
- const omittedBytes = truncation.originalBytes === null ? null : Math.max(0, truncation.originalBytes - deliveredBytes);
3006
- const estimatedDeliveredTokens = Math.ceil(deliveredBytes / 4);
3007
- if (truncation.deliveredBytes === deliveredBytes && truncation.omittedBytes === omittedBytes && truncation.estimatedDeliveredTokens === estimatedDeliveredTokens) {
3008
- return;
3009
- }
3010
- truncation.deliveredBytes = deliveredBytes;
3011
- truncation.omittedBytes = omittedBytes;
3012
- truncation.estimatedDeliveredTokens = estimatedDeliveredTokens;
3013
- }
3014
- throw new RangeError("Browser event byte accounting did not converge");
3015
- }
3016
- function browserUtf8Bytes(value) {
3017
- return encoder.encode(value).byteLength;
3018
- }
3019
- function isBrowserUtf8Continuation(value) {
3020
- return (value & 192) === 128;
2884
+ return encoder.encode(JSON.stringify(value)).byteLength;
3021
2885
  }
3022
2886
  function observeSessionStatus(events, ref) {
3023
2887
  let latest = null;
@@ -3050,7 +2914,7 @@ async function planForegroundCatchup(client, workspaceId, sessionId, cursor, opt
3050
2914
  pageSize: rawGap,
3051
2915
  ...options.signal ? { signal: options.signal } : {}
3052
2916
  });
3053
- const events = page.filter((event) => eventResumeSequence(event) > cursor).map(boundBrowserLegacyEvent);
2917
+ const events = page.filter((event) => eventResumeSequence(event) > cursor);
3054
2918
  if (events.length === 0) {
3055
2919
  return { kind: "reload" };
3056
2920
  }
@@ -3846,7 +3710,6 @@ export {
3846
3710
  extractSessionRef,
3847
3711
  SESSION_EVENT_BROWSER_MAX_BYTES,
3848
3712
  SESSION_EVENT_BROWSER_MAX_COUNT,
3849
- SESSION_EVENT_BROWSER_SINGLE_EVENT_MAX_BYTES,
3850
3713
  SESSION_EVENT_BROWSER_PENDING_MAX_BYTES,
3851
3714
  SESSION_EVENT_BROWSER_PENDING_MAX_COUNT,
3852
3715
  useSessionEvents,
@@ -3858,4 +3721,4 @@ export {
3858
3721
  isHumanInputEvent,
3859
3722
  useHumanInputRequests
3860
3723
  };
3861
- //# sourceMappingURL=chunk-BXJOQFCD.js.map
3724
+ //# sourceMappingURL=chunk-HUMIRRYI.js.map