@opengeni/react 1.4.4 → 1.4.5-canary.37485542607001

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 (249) hide show
  1. package/README.md +17 -6
  2. package/dist/artifacts.d.ts +1 -0
  3. package/dist/artifacts.js +22 -15
  4. package/dist/artifacts.js.map +1 -1
  5. package/dist/{browser-viewer-5EEAS3IU.js → browser-viewer-CV23VIHB.js} +8 -6
  6. package/dist/{chunk-XS67YG5R.js → chunk-4O7OE7ON.js} +45 -4
  7. package/dist/chunk-4O7OE7ON.js.map +1 -0
  8. package/dist/{chunk-JHTIMBOL.js → chunk-5JSUNNQN.js} +26 -4
  9. package/dist/{chunk-JHTIMBOL.js.map → chunk-5JSUNNQN.js.map} +1 -1
  10. package/dist/{chunk-QMMCJGFI.js → chunk-6BAMPGBV.js} +6 -3
  11. package/dist/chunk-6BAMPGBV.js.map +1 -0
  12. package/dist/{chunk-I6OY3MWC.js → chunk-6FOTSVWU.js} +2 -2
  13. package/dist/{chunk-LVS3MH5T.js → chunk-ATIRUHBZ.js} +128 -10
  14. package/dist/chunk-ATIRUHBZ.js.map +1 -0
  15. package/dist/chunk-BOFEQC6K.js +162 -0
  16. package/dist/chunk-BOFEQC6K.js.map +1 -0
  17. package/dist/{chunk-2OQA3CPB.js → chunk-CESBPQP5.js} +19 -5
  18. package/dist/chunk-CESBPQP5.js.map +1 -0
  19. package/dist/{chunk-YVFRBXST.js → chunk-GMNGUPMX.js} +2 -2
  20. package/dist/{chunk-PHBFJCEU.js → chunk-I5EGRXXG.js} +110 -7
  21. package/dist/chunk-I5EGRXXG.js.map +1 -0
  22. package/dist/{chunk-PBCZL4JP.js → chunk-INIZSNXT.js} +2 -2
  23. package/dist/chunk-IZV5FTJC.js +55 -0
  24. package/dist/chunk-IZV5FTJC.js.map +1 -0
  25. package/dist/chunk-JDJJMBB3.js +1883 -0
  26. package/dist/chunk-JDJJMBB3.js.map +1 -0
  27. package/dist/chunk-LHF6BVM4.js +83 -0
  28. package/dist/chunk-LHF6BVM4.js.map +1 -0
  29. package/dist/{chunk-C5BF4L26.js → chunk-LSMWZSCJ.js} +7 -7
  30. package/dist/chunk-LTKGTXUQ.js +174 -0
  31. package/dist/chunk-LTKGTXUQ.js.map +1 -0
  32. package/dist/chunk-N7S72EXK.js +25 -0
  33. package/dist/chunk-N7S72EXK.js.map +1 -0
  34. package/dist/{chunk-CVYCLFMH.js → chunk-PEHTX3V7.js} +19 -1
  35. package/dist/chunk-PEHTX3V7.js.map +1 -0
  36. package/dist/chunk-R5R5RQQD.js +51 -0
  37. package/dist/chunk-R5R5RQQD.js.map +1 -0
  38. package/dist/{chunk-IYQCWGU5.js → chunk-RGTZ2VDR.js} +35 -62
  39. package/dist/chunk-RGTZ2VDR.js.map +1 -0
  40. package/dist/chunk-RI42H5IU.js +326 -0
  41. package/dist/chunk-RI42H5IU.js.map +1 -0
  42. package/dist/{chunk-EAOSEIXB.js → chunk-RRRS5D5T.js} +727 -1983
  43. package/dist/chunk-RRRS5D5T.js.map +1 -0
  44. package/dist/{chunk-JH7V627O.js → chunk-SHLZMAJN.js} +2 -11
  45. package/dist/chunk-SHLZMAJN.js.map +1 -0
  46. package/dist/{chunk-IUHHPMAX.js → chunk-SZOCY5VG.js} +18 -87
  47. package/dist/chunk-SZOCY5VG.js.map +1 -0
  48. package/dist/{chunk-L2J3PU7A.js → chunk-VYIPNDUZ.js} +29 -100
  49. package/dist/chunk-VYIPNDUZ.js.map +1 -0
  50. package/dist/{chunk-G6YRCIYJ.js → chunk-YK6QMGVL.js} +55 -60
  51. package/dist/chunk-YK6QMGVL.js.map +1 -0
  52. package/dist/chunk-ZIB4H5LN.js +101 -0
  53. package/dist/chunk-ZIB4H5LN.js.map +1 -0
  54. package/dist/client.d.ts +9 -3
  55. package/dist/clipboard.js +1 -1
  56. package/dist/components/browser-viewer.d.ts +6 -0
  57. package/dist/components/composer.d.ts +3 -69
  58. package/dist/components/human-input-form.d.ts +3 -32
  59. package/dist/components/markdown.d.ts +8 -0
  60. package/dist/components/model-policy-picker.d.ts +4 -37
  61. package/dist/components/opper-mark.d.ts +7 -0
  62. package/dist/components/provider-recovery-notice.d.ts +15 -0
  63. package/dist/components/remark-soft-line-breaks.d.ts +38 -0
  64. package/dist/components/sandbox-workspace.d.ts +13 -0
  65. package/dist/components/session-chrome.d.ts +5 -3
  66. package/dist/components/session-conversation.d.ts +15 -3
  67. package/dist/composer-messages.d.ts +74 -0
  68. package/dist/composer-messages.js +9 -0
  69. package/dist/composer.js +15 -10
  70. package/dist/{computer-viewer-ELNLZGHI.js → computer-viewer-K4CKYRX6.js} +4 -4
  71. package/dist/connect-setup.d.ts +2 -0
  72. package/dist/connect.d.ts +1 -1
  73. package/dist/connect.js +21 -6
  74. package/dist/connect.js.map +1 -1
  75. package/dist/{embedded-voice-NIL4RDX3.js → embedded-voice-K7SOZVVZ.js} +6 -4
  76. package/dist/{embedded-voice-NIL4RDX3.js.map → embedded-voice-K7SOZVVZ.js.map} +1 -1
  77. package/dist/hooks/shared-machines-list.d.ts +4 -0
  78. package/dist/hooks/use-client-config-flags.d.ts +6 -0
  79. package/dist/hooks/use-goal.d.ts +2 -1
  80. package/dist/hooks/use-new-session-draft.d.ts +74 -0
  81. package/dist/human-input-model.d.ts +40 -0
  82. package/dist/index.d.ts +4 -1
  83. package/dist/index.js +116 -73
  84. package/dist/index.js.map +1 -1
  85. package/dist/interaction.js +5 -5
  86. package/dist/{latest-question-2POFPYNB.js → latest-question-27HGRPVF.js} +3 -3
  87. package/dist/lib/clipboard.d.ts +7 -0
  88. package/dist/lib/provider-recovery.d.ts +49 -0
  89. package/dist/lib/transient-retry.d.ts +25 -0
  90. package/dist/machines.js +2 -2
  91. package/dist/model-mark-paths.d.ts +34 -0
  92. package/dist/model-mark-paths.js +16 -0
  93. package/dist/model-picker-model.d.ts +111 -0
  94. package/dist/model-picker-model.js +25 -0
  95. package/dist/model-picker-model.js.map +1 -0
  96. package/dist/{model-policy-picker-menu-WRNSRFQC.js → model-policy-picker-menu-I5KPC3D6.js} +6 -4
  97. package/dist/model-policy-picker-menu-I5KPC3D6.js.map +1 -0
  98. package/dist/model-policy.d.ts +10 -0
  99. package/dist/model-policy.js +5 -1
  100. package/dist/new-session-draft.d.ts +7 -0
  101. package/dist/new-session-draft.js +639 -0
  102. package/dist/new-session-draft.js.map +1 -0
  103. package/dist/organization-model.d.ts +32 -0
  104. package/dist/organization-model.js +65 -0
  105. package/dist/organization-model.js.map +1 -0
  106. package/dist/{platform-activity-row-PJJVATTZ.js → platform-activity-row-NJ47YBXW.js} +7 -84
  107. package/dist/platform-activity-row-NJ47YBXW.js.map +1 -0
  108. package/dist/queue-presentation-model.d.ts +72 -0
  109. package/dist/queue-presentation-model.js +38 -0
  110. package/dist/queue-presentation-model.js.map +1 -0
  111. package/dist/{queue-surface-implementation-67FS7FUI.js → queue-surface-implementation-YPJFQ3O6.js} +24 -252
  112. package/dist/queue-surface-implementation-YPJFQ3O6.js.map +1 -0
  113. package/dist/realtime.js +5 -3
  114. package/dist/{sandbox-files-34CJJNOY.js → sandbox-files-2DGDO6NI.js} +5 -5
  115. package/dist/sandbox-files-2DGDO6NI.js.map +1 -0
  116. package/dist/sandbox-label-model.d.ts +23 -0
  117. package/dist/sandbox-label-model.js +28 -0
  118. package/dist/sandbox-label-model.js.map +1 -0
  119. package/dist/session-agents-model.d.ts +10 -0
  120. package/dist/session-agents-model.js +25 -0
  121. package/dist/session-agents-model.js.map +1 -0
  122. package/dist/session-attention-model.d.ts +8 -0
  123. package/dist/session-attention-model.js +46 -0
  124. package/dist/session-attention-model.js.map +1 -0
  125. package/dist/session-feedback-model.d.ts +20 -0
  126. package/dist/session-feedback-model.js +56 -0
  127. package/dist/session-feedback-model.js.map +1 -0
  128. package/dist/session-list-model.d.ts +119 -0
  129. package/dist/session-list-model.js +244 -0
  130. package/dist/session-list-model.js.map +1 -0
  131. package/dist/session-status-model.d.ts +19 -0
  132. package/dist/session-ui.js +26 -17
  133. package/dist/session-ui.js.map +1 -1
  134. package/dist/session.js +8 -6
  135. package/dist/testing/session-scenarios.d.ts +10 -0
  136. package/dist/testing/session-scenarios.js +303 -0
  137. package/dist/testing/session-scenarios.js.map +1 -0
  138. package/dist/timeline/genie-copy.d.ts +3 -0
  139. package/dist/timeline/genie-loading.d.ts +11 -0
  140. package/dist/timeline/index.d.ts +1 -1
  141. package/dist/timeline/notice-presentation.d.ts +7 -0
  142. package/dist/timeline/patch-apply-command.d.ts +18 -0
  143. package/dist/timeline/platform-activity-presentation.d.ts +7 -0
  144. package/dist/timeline/presented-image.d.ts +6 -1
  145. package/dist/timeline/question-nav-model.d.ts +23 -0
  146. package/dist/timeline/registry.d.ts +10 -1
  147. package/dist/timeline/retained-loaders.d.ts +1 -1
  148. package/dist/timeline/tool-presentation.d.ts +172 -0
  149. package/dist/timeline/turn-summary-model.d.ts +90 -0
  150. package/dist/timeline/turn-summary.d.ts +4 -74
  151. package/dist/timeline/work-presentation.d.ts +42 -0
  152. package/dist/timeline-model.d.ts +24 -0
  153. package/dist/timeline-model.js +152 -0
  154. package/dist/timeline-model.js.map +1 -0
  155. package/package.json +55 -3
  156. package/src/artifacts.ts +1 -0
  157. package/src/client.ts +9 -3
  158. package/src/components/browser-viewer.tsx +23 -2
  159. package/src/components/claude-mark.tsx +2 -1
  160. package/src/components/composer.tsx +8 -146
  161. package/src/components/grok-mark.tsx +2 -1
  162. package/src/components/human-input-form.tsx +13 -124
  163. package/src/components/markdown.tsx +19 -1
  164. package/src/components/message-timeline.tsx +45 -99
  165. package/src/components/model-mark.tsx +2 -1
  166. package/src/components/model-policy-picker-menu.tsx +30 -85
  167. package/src/components/model-policy-picker.tsx +20 -150
  168. package/src/components/opper-mark.tsx +18 -0
  169. package/src/components/provider-recovery-notice.tsx +41 -0
  170. package/src/components/queue-surface-implementation.tsx +20 -349
  171. package/src/components/remark-soft-line-breaks.ts +166 -0
  172. package/src/components/sandbox-workspace.tsx +17 -1
  173. package/src/components/session-chrome.tsx +114 -99
  174. package/src/components/session-conversation.tsx +55 -6
  175. package/src/components/session-status.tsx +17 -16
  176. package/src/composer-messages.ts +150 -0
  177. package/src/connect-setup.tsx +45 -11
  178. package/src/connect.ts +1 -1
  179. package/src/hooks/shared-machines-list.ts +34 -1
  180. package/src/hooks/use-client-config-flags.ts +8 -0
  181. package/src/hooks/use-goal.ts +66 -10
  182. package/src/hooks/use-new-session-draft.ts +813 -0
  183. package/src/human-input-model.ts +147 -0
  184. package/src/index.ts +16 -0
  185. package/src/lib/clipboard.ts +29 -0
  186. package/src/lib/format.ts +7 -0
  187. package/src/lib/provider-recovery.ts +202 -0
  188. package/src/lib/transient-retry.ts +99 -0
  189. package/src/model-mark-paths.ts +53 -0
  190. package/src/model-picker-model.ts +330 -0
  191. package/src/model-policy.ts +75 -5
  192. package/src/new-session-draft.ts +22 -0
  193. package/src/organization-model.ts +118 -0
  194. package/src/queue-presentation-model.ts +464 -0
  195. package/src/sandbox-label-model.ts +41 -0
  196. package/src/session-agents-model.ts +33 -0
  197. package/src/session-attention-model.ts +59 -0
  198. package/src/session-feedback-model.ts +95 -0
  199. package/src/session-list-model.ts +377 -0
  200. package/src/session-status-model.ts +62 -0
  201. package/src/testing/session-scenarios.ts +326 -0
  202. package/src/timeline/activity-rail.tsx +54 -24
  203. package/src/timeline/genie-copy.ts +19 -0
  204. package/src/timeline/genie-loading.tsx +15 -19
  205. package/src/timeline/index.ts +1 -0
  206. package/src/timeline/notice-presentation.ts +22 -0
  207. package/src/timeline/patch-apply-command.tsx +135 -0
  208. package/src/timeline/platform-activity-presentation.ts +122 -0
  209. package/src/timeline/platform-activity-row.tsx +6 -96
  210. package/src/timeline/presented-image.ts +16 -2
  211. package/src/timeline/projection.ts +12 -1
  212. package/src/timeline/question-nav-model.ts +28 -0
  213. package/src/timeline/registry.ts +11 -1
  214. package/src/timeline/retained-loaders.ts +9 -4
  215. package/src/timeline/rolling-activity.tsx +7 -19
  216. package/src/timeline/tool-presentation.ts +1316 -0
  217. package/src/timeline/tool-renderers.tsx +254 -1024
  218. package/src/timeline/turn-summary-model.ts +338 -0
  219. package/src/timeline/turn-summary.tsx +21 -326
  220. package/src/timeline/work-presentation.ts +139 -0
  221. package/src/timeline-model.ts +108 -0
  222. package/styles/compiled.css +17 -4
  223. package/styles/connect.css +4 -0
  224. package/styles/responsive.css +11 -2
  225. package/dist/chunk-2OQA3CPB.js.map +0 -1
  226. package/dist/chunk-CVYCLFMH.js.map +0 -1
  227. package/dist/chunk-EAOSEIXB.js.map +0 -1
  228. package/dist/chunk-G6YRCIYJ.js.map +0 -1
  229. package/dist/chunk-HXYOSSQO.js +0 -117
  230. package/dist/chunk-HXYOSSQO.js.map +0 -1
  231. package/dist/chunk-IUHHPMAX.js.map +0 -1
  232. package/dist/chunk-IYQCWGU5.js.map +0 -1
  233. package/dist/chunk-JH7V627O.js.map +0 -1
  234. package/dist/chunk-L2J3PU7A.js.map +0 -1
  235. package/dist/chunk-LVS3MH5T.js.map +0 -1
  236. package/dist/chunk-PHBFJCEU.js.map +0 -1
  237. package/dist/chunk-QMMCJGFI.js.map +0 -1
  238. package/dist/chunk-XS67YG5R.js.map +0 -1
  239. package/dist/platform-activity-row-PJJVATTZ.js.map +0 -1
  240. package/dist/queue-surface-implementation-67FS7FUI.js.map +0 -1
  241. /package/dist/{browser-viewer-5EEAS3IU.js.map → browser-viewer-CV23VIHB.js.map} +0 -0
  242. /package/dist/{chunk-I6OY3MWC.js.map → chunk-6FOTSVWU.js.map} +0 -0
  243. /package/dist/{chunk-YVFRBXST.js.map → chunk-GMNGUPMX.js.map} +0 -0
  244. /package/dist/{chunk-PBCZL4JP.js.map → chunk-INIZSNXT.js.map} +0 -0
  245. /package/dist/{chunk-C5BF4L26.js.map → chunk-LSMWZSCJ.js.map} +0 -0
  246. /package/dist/{computer-viewer-ELNLZGHI.js.map → composer-messages.js.map} +0 -0
  247. /package/dist/{model-policy-picker-menu-WRNSRFQC.js.map → computer-viewer-K4CKYRX6.js.map} +0 -0
  248. /package/dist/{latest-question-2POFPYNB.js.map → latest-question-27HGRPVF.js.map} +0 -0
  249. /package/dist/{sandbox-files-34CJJNOY.js.map → model-mark-paths.js.map} +0 -0
@@ -0,0 +1,464 @@
1
+ /**
2
+ * Queue presentation shared by the web queue surface and native docks: the
3
+ * bounded head/tail previews of queued prompts, and the reorder plan and its
4
+ * optimistic projection. No DOM, no React.
5
+ */
6
+ import type { SessionQueueSnapshot, SessionTurn } from "@opengeni/sdk";
7
+ import { QUEUE_ITEM_CONTENT_UNAVAILABLE, queueItemContent } from "./components/queue-item-content";
8
+
9
+ export { QUEUE_ITEM_CONTENT_UNAVAILABLE, queueItemContent };
10
+
11
+ export const QUEUE_ROW_PREVIEW_CHARACTERS = 360;
12
+ export const QUEUE_COLLAPSED_PREVIEW_CHARACTERS = 180;
13
+ const QUEUE_PREVIEW_GRAPHEME_CONTEXT_CHARACTERS = 32;
14
+ const QUEUE_PREVIEW_REFERENCE_SAMPLE_CHARACTERS = 32;
15
+ const QUEUE_VISIBLE_END_IDENTITY_CHARACTERS = 18;
16
+ const QUEUE_PREVIEW_SEPARATOR = " … ";
17
+ // Hermes (React Native) has no Intl.Segmenter; there, previews fall back to
18
+ // code points, which keeps every boundary rule except grapheme joining.
19
+ let queuePreviewSegmenterCache: Intl.Segmenter | null | undefined;
20
+ function queuePreviewSegments(sample: string): string[] {
21
+ if (queuePreviewSegmenterCache === undefined) {
22
+ queuePreviewSegmenterCache =
23
+ typeof Intl !== "undefined" && typeof Intl.Segmenter === "function"
24
+ ? new Intl.Segmenter(undefined, { granularity: "grapheme" })
25
+ : null;
26
+ }
27
+ if (!queuePreviewSegmenterCache) return Array.from(sample);
28
+ return Array.from(queuePreviewSegmenterCache.segment(sample), (part) => part.segment);
29
+ }
30
+ const queuePromptNonRenderingCodePoint =
31
+ /[\p{White_Space}\p{Control}\p{Default_Ignorable_Code_Point}]/u;
32
+
33
+ type BoundedPromptSample = {
34
+ value: string;
35
+ characters: number;
36
+ truncated: boolean;
37
+ };
38
+
39
+ export type QueuePromptPreview = {
40
+ summary: string;
41
+ collapsedVisual: string;
42
+ visibleStart: string;
43
+ visibleIdentity: string | null;
44
+ visibleIdentityLabel: "End" | "Safe boundary" | null;
45
+ isFallback: boolean;
46
+ };
47
+
48
+ function labelQueuePreview(summary: string): QueuePromptPreview {
49
+ return {
50
+ summary,
51
+ collapsedVisual: summary,
52
+ visibleStart: summary,
53
+ visibleIdentity: null,
54
+ visibleIdentityLabel: null,
55
+ isFallback: false,
56
+ };
57
+ }
58
+
59
+ export function queueTurnPreview(
60
+ turn: SessionTurn | undefined,
61
+ maxCharacters: number,
62
+ ): QueuePromptPreview {
63
+ if (!turn) return queuePromptPreview("", maxCharacters);
64
+ return queueContentPreview(turn.prompt, turn.annotations?.length ?? 0, maxCharacters);
65
+ }
66
+
67
+ export function queueContentPreview(
68
+ prompt: string,
69
+ annotationCount: number,
70
+ maxCharacters: number,
71
+ ): QueuePromptPreview {
72
+ switch (queueItemContent(prompt, annotationCount)) {
73
+ case "text":
74
+ return queuePromptPreview(prompt, maxCharacters);
75
+ case "annotations":
76
+ return labelQueuePreview(
77
+ `${annotationCount} timeline ${annotationCount === 1 ? "annotation" : "annotations"}`,
78
+ );
79
+ case "unavailable":
80
+ return labelQueuePreview(QUEUE_ITEM_CONTENT_UNAVAILABLE);
81
+ }
82
+ }
83
+
84
+ /**
85
+ * Build a bounded head/tail summary of an arbitrary queued prompt. Sampling
86
+ * both ends distinguishes prompts with equal long prefixes. Each sampled edge
87
+ * has a small amount of grapheme context so ordinary emoji/combining sequences
88
+ * can be retained whole. A cluster that exceeds that context is omitted rather
89
+ * than fragmented, and malformed UTF-16 is replaced only in the summary. The
90
+ * durable prompt remains exact and no operation scans or copies it in full.
91
+ */
92
+ export function queuePromptPreview(prompt: string, maxCharacters: number): QueuePromptPreview {
93
+ const wholePromptProbe = samplePromptStart(prompt, maxCharacters + 1);
94
+ if (!wholePromptProbe.truncated && wholePromptProbe.characters <= maxCharacters) {
95
+ const summary = replaceLoneSurrogates(wholePromptProbe.value);
96
+ return hasVisiblePromptContent(summary)
97
+ ? {
98
+ summary,
99
+ collapsedVisual: summary,
100
+ visibleStart: summary,
101
+ visibleIdentity: null,
102
+ visibleIdentityLabel: null,
103
+ isFallback: false,
104
+ }
105
+ : fallbackPromptPreview(prompt.length, wholePromptProbe.value, wholePromptProbe.value);
106
+ }
107
+
108
+ const suffixCharacters = Math.min(Math.floor(maxCharacters / 3), 120);
109
+ const prefixCharacters =
110
+ maxCharacters - codePointLength(QUEUE_PREVIEW_SEPARATOR) - suffixCharacters;
111
+ const prefixSample = samplePromptStart(
112
+ prompt,
113
+ prefixCharacters + QUEUE_PREVIEW_GRAPHEME_CONTEXT_CHARACTERS,
114
+ );
115
+ const suffixSample = samplePromptEnd(
116
+ prompt,
117
+ suffixCharacters + QUEUE_PREVIEW_GRAPHEME_CONTEXT_CHARACTERS,
118
+ );
119
+ const prefixSegments = segmentPromptSample(prefixSample.value);
120
+ const suffixSegments = segmentPromptSample(suffixSample.value);
121
+
122
+ // A cluster at a truncated sampling edge may continue outside the sample.
123
+ // Prefix sampling starts at the true source start, so only its last segment
124
+ // is ambiguous. Suffix sampling ends at the true source end, so its first is.
125
+ if (prefixSample.truncated) prefixSegments.pop();
126
+ if (suffixSample.truncated) {
127
+ let ambiguousSegment = suffixSegments.shift();
128
+ // A locally segmented leading fragment ending in ZWJ can join the next
129
+ // pictographic segment when omitted left context supplies its base. Keep
130
+ // backing off until that uncertainty no longer propagates to the right.
131
+ while (ambiguousSegment?.endsWith("\u200d") && suffixSegments.length > 0) {
132
+ ambiguousSegment = suffixSegments.shift();
133
+ }
134
+ // Regional Indicator pairing depends on the parity of the preceding run.
135
+ // If that run reaches the unknown sample boundary, omit all of its visible
136
+ // leading segments rather than potentially recombining halves of flags.
137
+ while (suffixSegments[0] && startsWithRegionalIndicator(suffixSegments[0])) {
138
+ suffixSegments.shift();
139
+ }
140
+ }
141
+
142
+ const prefix = takeWholeGraphemesFromStart(prefixSegments, prefixCharacters);
143
+ const suffix = takeWholeGraphemesFromEnd(suffixSegments, suffixCharacters);
144
+ const reference = boundedPromptSampleReference(
145
+ prompt.length,
146
+ prefixSample.value,
147
+ suffixSample.value,
148
+ );
149
+
150
+ if (!hasVisiblePromptContent(prefix) && !hasVisiblePromptContent(suffix)) {
151
+ return fallbackPromptPreview(prompt.length, prefixSample.value, suffixSample.value);
152
+ }
153
+
154
+ const safeSuffix = hasVisiblePromptContent(suffix)
155
+ ? suffix
156
+ : promptPreviewFallbackLabel(reference);
157
+ const summary = `${prefix}${QUEUE_PREVIEW_SEPARATOR}${safeSuffix}`;
158
+ if (!hasVisiblePromptContent(prefix)) {
159
+ return {
160
+ summary,
161
+ collapsedVisual: summary,
162
+ visibleStart: safeSuffix,
163
+ visibleIdentity: null,
164
+ visibleIdentityLabel: null,
165
+ isFallback: false,
166
+ };
167
+ }
168
+
169
+ const endIdentity = takeWholeGraphemesFromEnd(
170
+ suffixSegments,
171
+ QUEUE_VISIBLE_END_IDENTITY_CHARACTERS,
172
+ );
173
+ return {
174
+ summary,
175
+ collapsedVisual: summary,
176
+ visibleStart: prefix,
177
+ visibleIdentity: hasVisiblePromptContent(endIdentity) ? endIdentity : `ref ${reference}`,
178
+ visibleIdentityLabel: hasVisiblePromptContent(endIdentity) ? "End" : "Safe boundary",
179
+ isFallback: false,
180
+ };
181
+ }
182
+
183
+ function fallbackPromptPreview(
184
+ promptLength: number,
185
+ startSample: string,
186
+ endSample: string,
187
+ ): QueuePromptPreview {
188
+ const reference = boundedPromptSampleReference(promptLength, startSample, endSample);
189
+ const summary = promptPreviewFallbackLabel(reference);
190
+ return {
191
+ summary,
192
+ collapsedVisual: `Omitted · ${reference}`,
193
+ // The complete fallback remains the canonical accessible summary. Narrow
194
+ // collapsed/row layouts paint the bounded reference in a compact truthful
195
+ // form so ellipsis cannot hide the only identifying portion.
196
+ visibleStart: `Omitted · ${reference}`,
197
+ visibleIdentity: null,
198
+ visibleIdentityLabel: null,
199
+ isFallback: true,
200
+ };
201
+ }
202
+
203
+ function promptPreviewFallbackLabel(reference: string): string {
204
+ return `Content omitted at safe boundary · ref ${reference}`;
205
+ }
206
+
207
+ function boundedPromptSampleReference(
208
+ promptLength: number,
209
+ startSample: string,
210
+ endSample: string,
211
+ ): string {
212
+ const head = samplePromptStart(startSample, QUEUE_PREVIEW_REFERENCE_SAMPLE_CHARACTERS).value;
213
+ const tail = samplePromptEnd(endSample, QUEUE_PREVIEW_REFERENCE_SAMPLE_CHARACTERS).value;
214
+ let hash = 0x811c9dc5;
215
+ for (const value of [String(promptLength), head, tail]) {
216
+ for (let index = 0; index < value.length; index += 1) {
217
+ hash ^= value.charCodeAt(index);
218
+ hash = Math.imul(hash, 0x01000193);
219
+ }
220
+ hash ^= 0xffff;
221
+ hash = Math.imul(hash, 0x01000193);
222
+ }
223
+ return (hash >>> 0).toString(16).padStart(8, "0").toUpperCase();
224
+ }
225
+
226
+ function hasVisiblePromptContent(value: string): boolean {
227
+ // Callers pass only the already-bounded whole/head/tail preview samples.
228
+ // Default-ignorables and controls can survive trim() while painting no row
229
+ // identity at all (for example ZWJ, VS16, bidi controls, and tag characters).
230
+ for (const character of value) {
231
+ if (!queuePromptNonRenderingCodePoint.test(character)) return true;
232
+ }
233
+ return false;
234
+ }
235
+
236
+ function samplePromptStart(prompt: string, maxCharacters: number): BoundedPromptSample {
237
+ let end = 0;
238
+ let characters = 0;
239
+ while (end < prompt.length && characters < maxCharacters) {
240
+ const first = prompt.charCodeAt(end);
241
+ end +=
242
+ isHighSurrogate(first) &&
243
+ end + 1 < prompt.length &&
244
+ isLowSurrogate(prompt.charCodeAt(end + 1))
245
+ ? 2
246
+ : 1;
247
+ characters += 1;
248
+ }
249
+ return { value: prompt.slice(0, end), characters, truncated: end < prompt.length };
250
+ }
251
+
252
+ function samplePromptEnd(prompt: string, maxCharacters: number): BoundedPromptSample {
253
+ let start = prompt.length;
254
+ let characters = 0;
255
+ while (start > 0 && characters < maxCharacters) {
256
+ start -= 1;
257
+ if (
258
+ isLowSurrogate(prompt.charCodeAt(start)) &&
259
+ start > 0 &&
260
+ isHighSurrogate(prompt.charCodeAt(start - 1))
261
+ ) {
262
+ start -= 1;
263
+ }
264
+ characters += 1;
265
+ }
266
+ return { value: prompt.slice(start), characters, truncated: start > 0 };
267
+ }
268
+
269
+ function segmentPromptSample(sample: string): string[] {
270
+ return queuePreviewSegments(replaceLoneSurrogates(sample));
271
+ }
272
+
273
+ function replaceLoneSurrogates(value: string): string {
274
+ let sanitized = "";
275
+ for (let index = 0; index < value.length; index += 1) {
276
+ const current = value.charCodeAt(index);
277
+ if (
278
+ isHighSurrogate(current) &&
279
+ index + 1 < value.length &&
280
+ isLowSurrogate(value.charCodeAt(index + 1))
281
+ ) {
282
+ sanitized += value.slice(index, index + 2);
283
+ index += 1;
284
+ } else if (isHighSurrogate(current) || isLowSurrogate(current)) {
285
+ sanitized += "�";
286
+ } else {
287
+ sanitized += value[index];
288
+ }
289
+ }
290
+ return sanitized;
291
+ }
292
+
293
+ function takeWholeGraphemesFromStart(segments: string[], maxCharacters: number): string {
294
+ const selected: string[] = [];
295
+ let characters = 0;
296
+ for (const segment of segments) {
297
+ const segmentCharacters = codePointLength(segment);
298
+ if (characters + segmentCharacters > maxCharacters) break;
299
+ selected.push(segment);
300
+ characters += segmentCharacters;
301
+ }
302
+ while (selected.at(-1)?.trim().length === 0) selected.pop();
303
+ return selected.join("");
304
+ }
305
+
306
+ function takeWholeGraphemesFromEnd(segments: string[], maxCharacters: number): string {
307
+ const selected: string[] = [];
308
+ let characters = 0;
309
+ for (let index = segments.length - 1; index >= 0; index -= 1) {
310
+ const segment = segments[index];
311
+ if (!segment) continue;
312
+ const segmentCharacters = codePointLength(segment);
313
+ if (characters + segmentCharacters > maxCharacters) break;
314
+ selected.unshift(segment);
315
+ characters += segmentCharacters;
316
+ }
317
+ while (selected[0]?.trim().length === 0) selected.shift();
318
+ while (selected.at(-1)?.trim().length === 0) selected.pop();
319
+ return selected.join("");
320
+ }
321
+
322
+ function codePointLength(value: string): number {
323
+ let characters = 0;
324
+ for (const _character of value) characters += 1;
325
+ return characters;
326
+ }
327
+
328
+ function startsWithRegionalIndicator(value: string): boolean {
329
+ const codePoint = value.codePointAt(0);
330
+ return codePoint !== undefined && codePoint >= 0x1f1e6 && codePoint <= 0x1f1ff;
331
+ }
332
+
333
+ function isHighSurrogate(codeUnit: number): boolean {
334
+ return codeUnit >= 0xd800 && codeUnit <= 0xdbff;
335
+ }
336
+
337
+ function isLowSurrogate(codeUnit: number): boolean {
338
+ return codeUnit >= 0xdc00 && codeUnit <= 0xdfff;
339
+ }
340
+
341
+ /** Move one item, as dnd-kit's arrayMove does. */
342
+ export function moveQueueItem<T>(items: readonly T[], from: number, to: number): T[] {
343
+ const next = items.slice();
344
+ const [item] = next.splice(from, 1);
345
+ if (item === undefined) return next;
346
+ next.splice(to < 0 ? next.length + to : to, 0, item);
347
+ return next;
348
+ }
349
+
350
+ export type QueueMovePlan = {
351
+ /** The turn ids in their new order. */
352
+ turnIds: string[];
353
+ /** The server anchor: the turn the moved one now precedes, null for last. */
354
+ beforeTurnId: string | null;
355
+ /** The bounded destination index. */
356
+ index: number;
357
+ };
358
+
359
+ /** The reorder request for moving a queued turn to an index, or null for a no-op. */
360
+ export function queueMovePlan(
361
+ queue: readonly SessionTurn[],
362
+ turnId: string,
363
+ nextIndex: number,
364
+ ): QueueMovePlan | null {
365
+ const oldIndex = queue.findIndex((turn) => turn.id === turnId);
366
+ if (oldIndex < 0) return null;
367
+ const index = Math.max(0, Math.min(nextIndex, queue.length - 1));
368
+ if (oldIndex === index) return null;
369
+ const ordered = moveQueueItem(queue, oldIndex, index);
370
+ return {
371
+ turnIds: ordered.map((turn) => turn.id),
372
+ beforeTurnId: ordered[index + 1]?.id ?? null,
373
+ index,
374
+ };
375
+ }
376
+
377
+ export type PendingQueueMove = { baseVersion: number | null; turnIds: string[] };
378
+
379
+ /**
380
+ * The queue as shown while a move is in flight: the optimistic order, unless
381
+ * any authoritative change arrived. A projection never omits or invents a row.
382
+ */
383
+ export function projectPendingQueueMove(
384
+ queue: SessionTurn[],
385
+ pendingMove: PendingQueueMove | null,
386
+ snapshot: Pick<SessionQueueSnapshot, "version"> | null,
387
+ ): SessionTurn[] {
388
+ if (
389
+ !pendingMove ||
390
+ pendingMove.baseVersion === null ||
391
+ snapshot?.version !== pendingMove.baseVersion
392
+ ) {
393
+ return queue;
394
+ }
395
+ const byId = new Map(queue.map((turn) => [turn.id, turn]));
396
+ const projected = pendingMove.turnIds.map((turnId) => byId.get(turnId));
397
+ if (projected.some((turn) => !turn) || projected.length !== queue.length) {
398
+ return queue;
399
+ }
400
+ return projected as SessionTurn[];
401
+ }
402
+
403
+ /** Copy for the "replace your draft with this queued prompt" confirmation. */
404
+ export const QUEUE_REPLACE_DRAFT_COPY = {
405
+ title: "Your composer already has a draft. Replace it with this queued prompt?",
406
+ detail:
407
+ "The current draft will be permanently discarded; this queued prompt is preserved until you confirm.",
408
+ keep: "Keep current draft",
409
+ replace: "Replace and edit",
410
+ } as const;
411
+
412
+ export type QueuedTurnPresentation = {
413
+ kind: "prompt" | "realtime_voice" | "realtime_voice_handoff";
414
+ text: string;
415
+ };
416
+
417
+ function objectValue(value: unknown): Record<string, unknown> | null {
418
+ return value !== null && typeof value === "object" && !Array.isArray(value)
419
+ ? (value as Record<string, unknown>)
420
+ : null;
421
+ }
422
+
423
+ /** What a queued row shows: the prompt, or the transcript of a voice request. */
424
+ export function queuedTurnPresentation(turn: SessionTurn): QueuedTurnPresentation {
425
+ const realtimeDelegation = objectValue(turn.metadata.realtimeDelegation);
426
+ const inputTranscript = realtimeDelegation?.inputTranscript;
427
+ if (typeof inputTranscript === "string" && inputTranscript.trim()) {
428
+ return { kind: "realtime_voice", text: inputTranscript.trim() };
429
+ }
430
+ if (objectValue(turn.metadata.realtimeTailFlush)) {
431
+ return { kind: "realtime_voice_handoff", text: "Remaining voice context" };
432
+ }
433
+ return { kind: "prompt", text: turn.prompt };
434
+ }
435
+
436
+ export function isSteeringTurn(turn: SessionTurn): boolean {
437
+ return turn.metadata.delivery === "steer";
438
+ }
439
+
440
+ /** A queued turn that is really waiting: not already a steer in flight. */
441
+ export function isAuthoritativeQueuedTurn(
442
+ turn: SessionTurn,
443
+ mutationFor: (turnId: string) => string | null,
444
+ ): boolean {
445
+ return !isSteeringTurn(turn) && mutationFor(turn.id) !== "steer";
446
+ }
447
+
448
+ export function countAuthoritativeQueuedTurns(
449
+ turns: readonly SessionTurn[],
450
+ mutationFor: (turnId: string) => string | null,
451
+ ): number {
452
+ return turns.filter((turn) => isAuthoritativeQueuedTurn(turn, mutationFor)).length;
453
+ }
454
+
455
+ /** The move anchors for one row's Move up / Move down. */
456
+ export function queueNeighborAnchors(
457
+ turns: readonly SessionTurn[],
458
+ index: number,
459
+ ): { beforeUp: string | null; beforeDown: string | null } {
460
+ return {
461
+ beforeUp: index > 0 ? (turns[index - 1]?.id ?? null) : null,
462
+ beforeDown: index < turns.length - 1 ? (turns[index + 2]?.id ?? null) : null,
463
+ };
464
+ }
@@ -0,0 +1,41 @@
1
+ /**
2
+ * User-facing names for where a session's commands run, shared by the web
3
+ * sandbox switcher and every timeline that labels command rows ("on Cloud
4
+ * sandbox · …"). No DOM, no React.
5
+ */
6
+ import type { SandboxBackend } from "@opengeni/sdk";
7
+ import type { MachineView } from "./types/machines";
8
+
9
+ export const CLOUD_SANDBOX_LABEL = "Cloud sandbox";
10
+ export const NO_SANDBOX_LABEL = "No sandbox";
11
+ export const LOCAL_SANDBOX_LABEL = "Local sandbox";
12
+
13
+ /**
14
+ * User-facing name for a session's own managed box. Hosting vendors (Modal,
15
+ * Daytona, ...) are deployment detail, not something a user chose, so hosted
16
+ * providers read as the neutral "Cloud sandbox" and the local-dev Docker box as
17
+ * "Local sandbox". The local backend runs directly on the host, so it keeps the
18
+ * honest "this computer" instead of implying isolation. Connected Machines keep
19
+ * their own names.
20
+ */
21
+ export function sessionSandboxLabel(backend: SandboxBackend | string): string {
22
+ if (backend === "none") return NO_SANDBOX_LABEL;
23
+ if (backend === "local") return "this computer";
24
+ if (backend === "docker") return LOCAL_SANDBOX_LABEL;
25
+ return CLOUD_SANDBOX_LABEL;
26
+ }
27
+
28
+ /** Display name for a fleet row: the session's own box never shows its vendor. */
29
+ export function machineDisplayName(
30
+ machine: Pick<MachineView, "isSessionGroup" | "kind" | "name">,
31
+ ): string {
32
+ return machine.isSessionGroup ? sessionSandboxLabel(machine.kind) : machine.name;
33
+ }
34
+
35
+ /** The compute label a session timeline shows: the active machine, else the cloud box. */
36
+ export function sessionComputeLabel(
37
+ machines: readonly Pick<MachineView, "active" | "isSessionGroup" | "kind" | "name">[],
38
+ ): string {
39
+ const active = machines.find((machine) => machine.active);
40
+ return active ? machineDisplayName(active) : CLOUD_SANDBOX_LABEL;
41
+ }
@@ -0,0 +1,33 @@
1
+ import type { LineageNode, SessionGoal } from "@opengeni/sdk";
2
+
3
+ /* Renderer-neutral session chrome signals shared by the web dock and native
4
+ apps: the sub-agents chip and the goal chip. */
5
+
6
+ export type SessionAgentsSignal = {
7
+ count: number;
8
+ detail: string;
9
+ tone: "running" | "waiting" | "neutral";
10
+ };
11
+
12
+ /** The agents chip for a session's spawned workers, or undefined without any. */
13
+ export function sessionAgentsSignal(
14
+ agents: readonly Pick<LineageNode, "session">[],
15
+ ): SessionAgentsSignal | undefined {
16
+ if (agents.length === 0) return undefined;
17
+ const running = agents.filter(
18
+ (node) => node.session.status === "running" && node.session.effectiveControl.state === "active",
19
+ ).length;
20
+ const paused = agents.filter((node) => node.session.effectiveControl.state === "paused").length;
21
+ return {
22
+ count: agents.length,
23
+ detail: running > 0 ? `${running} running` : paused > 0 ? `${paused} paused` : "Idle",
24
+ tone: running > 0 ? "running" : paused > 0 ? "waiting" : "neutral",
25
+ };
26
+ }
27
+
28
+ /** One human word for a goal's state, as the web goal pill reads. */
29
+ export function sessionGoalStateLabel(goal: Pick<SessionGoal, "status">): string {
30
+ if (goal.status === "completed") return "Completed";
31
+ if (goal.status === "paused") return "Paused";
32
+ return "Active";
33
+ }
@@ -0,0 +1,59 @@
1
+ import type { SessionEvent } from "@opengeni/sdk";
2
+
3
+ // Keep this client scheduling predicate aligned with the meaningful-attention
4
+ // predicate in packages/db/src/session-meaningful-events.ts. The server remains
5
+ // authoritative; this only avoids personal-state writes for streaming activity.
6
+ export const SESSION_ATTENTION_EVENT_TYPES: ReadonlySet<string> = new Set([
7
+ "agent.message.completed",
8
+ "turn.completed",
9
+ "turn.failed",
10
+ "session.requiresAction",
11
+ "session.humanInput.requested",
12
+ "tool.auth_needed",
13
+ "credential.auth_needed",
14
+ "goal.completed",
15
+ "goal.paused",
16
+ "goal.progress",
17
+ "goal.rewrite.proposed",
18
+ "rig.setup.failed",
19
+ "sandbox.operation.failed",
20
+ "sandbox.box.lost",
21
+ "workspace.revision.degraded",
22
+ "machine.op.failed",
23
+ "machine.link.lost",
24
+ "session.event.envelope_omitted",
25
+ ]);
26
+
27
+ /**
28
+ * The latest delivered attention boundary, independent of raw token activity.
29
+ * A foreground reader acknowledges through this sequence, so streaming flushes
30
+ * never cause a personal-state write and later activity stays unread.
31
+ */
32
+ export function sessionAttentionReadThroughSequence(events: readonly SessionEvent[]): number {
33
+ for (let index = events.length - 1; index >= 0; index -= 1) {
34
+ const event = events[index]!;
35
+ if (
36
+ !SESSION_ATTENTION_EVENT_TYPES.has(event.type) ||
37
+ event.duplicateOfEventId ||
38
+ (event.turnAssociation != null && event.turnAssociation !== "current")
39
+ )
40
+ continue;
41
+ const payload =
42
+ event.payload && typeof event.payload === "object"
43
+ ? (event.payload as Record<string, unknown>)
44
+ : {};
45
+ if (
46
+ event.type === "agent.message.completed" &&
47
+ (payload.phase === "commentary" || payload.text == null || payload.text === "")
48
+ )
49
+ continue;
50
+ if (event.type === "turn.completed") {
51
+ if (Object.hasOwn(payload, "maintenance") || Object.hasOwn(payload, "segmentLimit")) continue;
52
+ const output = payload.output ?? payload.result;
53
+ if ((output == null || output === "") && (payload.reply == null || payload.reply === ""))
54
+ continue;
55
+ }
56
+ return event.sequence;
57
+ }
58
+ return 0;
59
+ }
@@ -0,0 +1,95 @@
1
+ // Reply and session feedback shared by web and native: the one feedback read
2
+ // per session (with recovery), saved turn ratings, the submission payload with
3
+ // a retained idempotency key, and the dialog copy. No DOM, no React.
4
+ import type {
5
+ CreateFeedbackRequest,
6
+ Feedback,
7
+ FeedbackSentiment,
8
+ OpenGeniClient,
9
+ } from "@opengeni/sdk";
10
+
11
+ export type FeedbackClient = Pick<OpenGeniClient, "createFeedback" | "listOwnFeedback">;
12
+
13
+ /** One shared read per session, with recovery after a transient network failure. */
14
+ export function loadSessionFeedback(
15
+ client: Pick<OpenGeniClient, "listOwnFeedback">,
16
+ workspaceId: string,
17
+ sessionId: string,
18
+ onLoaded: (result: Awaited<ReturnType<OpenGeniClient["listOwnFeedback"]>>) => void,
19
+ ): () => void {
20
+ let current = true;
21
+ let delay = 1_000;
22
+ let timer: ReturnType<typeof setTimeout> | undefined;
23
+ const load = () => {
24
+ void client.listOwnFeedback(workspaceId, { sessionId, includeTurns: true }).then(
25
+ (result) => {
26
+ if (current) onLoaded(result);
27
+ },
28
+ () => {
29
+ if (!current) return;
30
+ timer = setTimeout(load, delay);
31
+ delay = Math.min(delay * 2, 30_000);
32
+ },
33
+ );
34
+ };
35
+ load();
36
+ return () => {
37
+ current = false;
38
+ clearTimeout(timer);
39
+ };
40
+ }
41
+
42
+ /** The first saved rating per turn (the list is newest-first). */
43
+ export function turnRatingsFromFeedback(
44
+ feedback: readonly Feedback[],
45
+ ): Record<string, FeedbackSentiment> {
46
+ const ratings: Record<string, FeedbackSentiment> = {};
47
+ for (const entry of feedback) {
48
+ if (entry.turnId && entry.sentiment && !ratings[entry.turnId])
49
+ ratings[entry.turnId] = entry.sentiment;
50
+ }
51
+ return ratings;
52
+ }
53
+
54
+ export type FeedbackPayload = Omit<CreateFeedbackRequest, "idempotencyKey">;
55
+
56
+ /**
57
+ * The request to send, reusing the previous idempotency key when the user
58
+ * retries the identical submission (a lost response must not duplicate it).
59
+ */
60
+ export function feedbackSubmission(
61
+ payload: FeedbackPayload,
62
+ previous: CreateFeedbackRequest | null,
63
+ newKey: () => string,
64
+ ): CreateFeedbackRequest {
65
+ if (
66
+ previous &&
67
+ previous.sessionId === payload.sessionId &&
68
+ previous.turnId === payload.turnId &&
69
+ previous.sentiment === payload.sentiment &&
70
+ previous.comment === payload.comment
71
+ ) {
72
+ return previous;
73
+ }
74
+ return { ...payload, idempotencyKey: newKey() };
75
+ }
76
+
77
+ export function feedbackDialogCopy(target: {
78
+ sessionId?: string | undefined;
79
+ turnId?: string | undefined;
80
+ }) {
81
+ return {
82
+ title: target.turnId
83
+ ? "Rate this reply"
84
+ : target.sessionId
85
+ ? "Rate this session"
86
+ : "Send feedback",
87
+ description: target.sessionId
88
+ ? "Share what worked or what could be better."
89
+ : "Tell us what could make Opengeni better.",
90
+ };
91
+ }
92
+
93
+ export function feedbackSentimentLabel(sentiment: FeedbackSentiment): string {
94
+ return sentiment === "positive" ? "Thumbs up" : "Thumbs down";
95
+ }