@opengeni/react 0.48.0 → 0.57.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 (325) hide show
  1. package/README.md +138 -2
  2. package/dist/artifacts-document.d.ts +3 -0
  3. package/dist/artifacts-document.js +17 -0
  4. package/dist/artifacts-document.js.map +1 -0
  5. package/dist/artifacts-presentation.d.ts +3 -0
  6. package/dist/artifacts-presentation.js +17 -0
  7. package/dist/artifacts-presentation.js.map +1 -0
  8. package/dist/artifacts-spreadsheet.d.ts +3 -0
  9. package/dist/artifacts-spreadsheet.js +17 -0
  10. package/dist/artifacts-spreadsheet.js.map +1 -0
  11. package/dist/artifacts.d.ts +2 -0
  12. package/dist/artifacts.js +199 -0
  13. package/dist/artifacts.js.map +1 -0
  14. package/dist/{chunk-NJ7M2B6Z.js → chunk-5UQPNLIO.js} +16 -8
  15. package/dist/{chunk-NJ7M2B6Z.js.map → chunk-5UQPNLIO.js.map} +1 -1
  16. package/dist/{chunk-LHLYWG5R.js → chunk-6KLX2RH5.js} +461 -38
  17. package/dist/chunk-6KLX2RH5.js.map +1 -0
  18. package/dist/chunk-7WCLAEFV.js +2828 -0
  19. package/dist/chunk-7WCLAEFV.js.map +1 -0
  20. package/dist/{chunk-I4MPFDRP.js → chunk-B6WPZSTT.js} +104 -104
  21. package/dist/{chunk-I4MPFDRP.js.map → chunk-B6WPZSTT.js.map} +1 -1
  22. package/dist/{chunk-EKZH6IDG.js → chunk-C5ZPSSS5.js} +111 -1
  23. package/dist/chunk-C5ZPSSS5.js.map +1 -0
  24. package/dist/{chunk-OL6QVXGF.js → chunk-HA46CYQK.js} +152 -8
  25. package/dist/chunk-HA46CYQK.js.map +1 -0
  26. package/dist/chunk-HUIKIDM5.js +2148 -0
  27. package/dist/chunk-HUIKIDM5.js.map +1 -0
  28. package/dist/{chunk-FWXGSNXT.js → chunk-IGC6A2ZI.js} +585 -34
  29. package/dist/chunk-IGC6A2ZI.js.map +1 -0
  30. package/dist/chunk-JVYQRRC4.js +53 -0
  31. package/dist/chunk-JVYQRRC4.js.map +1 -0
  32. package/dist/chunk-KCGXPP5V.js +157 -0
  33. package/dist/chunk-KCGXPP5V.js.map +1 -0
  34. package/dist/chunk-LLOLUHVG.js +5937 -0
  35. package/dist/chunk-LLOLUHVG.js.map +1 -0
  36. package/dist/{chunk-WYA65Y3F.js → chunk-MKPIAGVL.js} +13 -3
  37. package/dist/chunk-MKPIAGVL.js.map +1 -0
  38. package/dist/chunk-PEI6RANI.js +3234 -0
  39. package/dist/chunk-PEI6RANI.js.map +1 -0
  40. package/dist/chunk-R3AZOAB5.js +933 -0
  41. package/dist/chunk-R3AZOAB5.js.map +1 -0
  42. package/dist/{chunk-O4VXOBGF.js → chunk-WSK7G5LE.js} +70 -2
  43. package/dist/chunk-WSK7G5LE.js.map +1 -0
  44. package/dist/{chunk-23EJ676W.js → chunk-XBZWOM2K.js} +9 -4
  45. package/dist/chunk-XBZWOM2K.js.map +1 -0
  46. package/dist/{chunk-XCNTXWBB.js → chunk-Y7OEDUJ5.js} +856 -338
  47. package/dist/chunk-Y7OEDUJ5.js.map +1 -0
  48. package/dist/client.d.ts +10 -2
  49. package/dist/clipboard.d.ts +1 -0
  50. package/dist/clipboard.js +7 -0
  51. package/dist/clipboard.js.map +1 -0
  52. package/dist/commands/index.d.ts +3 -3
  53. package/dist/commands/registry.d.ts +1 -1
  54. package/dist/commands/types.d.ts +1 -1
  55. package/dist/components/approval-surface.d.ts +2 -2
  56. package/dist/components/artifacts/artifact-surface.d.ts +18 -0
  57. package/dist/components/artifacts/document-editor.d.ts +172 -0
  58. package/dist/components/artifacts/editable-artifact-ui.d.ts +13 -0
  59. package/dist/components/artifacts/editable-artifact-workbench.d.ts +49 -0
  60. package/dist/components/artifacts/editable-document.d.ts +24 -0
  61. package/dist/components/artifacts/editable-presentation.d.ts +24 -0
  62. package/dist/components/artifacts/editable-spreadsheet.d.ts +32 -0
  63. package/dist/components/artifacts/index.d.ts +9 -0
  64. package/dist/components/artifacts/presentation-editor.d.ts +297 -0
  65. package/dist/components/artifacts/published-html-artifact-frame.d.ts +14 -0
  66. package/dist/components/artifacts/spreadsheet-canvas.d.ts +120 -0
  67. package/dist/components/artifacts/spreadsheet-grid.d.ts +113 -0
  68. package/dist/components/browser-input.d.ts +7 -0
  69. package/dist/components/browser-viewer.d.ts +30 -0
  70. package/dist/components/chat-composer.d.ts +8 -8
  71. package/dist/components/code-editor.d.ts +25 -3
  72. package/dist/components/command-palette.d.ts +2 -2
  73. package/dist/components/composer-transcription-control.d.ts +2 -2
  74. package/dist/components/composer.d.ts +17 -17
  75. package/dist/components/computer-viewer.d.ts +24 -0
  76. package/dist/components/copy-button.d.ts +2 -2
  77. package/dist/components/desktop-viewer.d.ts +50 -22
  78. package/dist/components/diff-view.d.ts +1 -1
  79. package/dist/components/enrollment-consent.d.ts +1 -1
  80. package/dist/components/enrollment-device-flow.d.ts +1 -1
  81. package/dist/components/file-browser.d.ts +2 -2
  82. package/dist/components/fleet-tile.d.ts +1 -1
  83. package/dist/components/generated-video-player.d.ts +10 -0
  84. package/dist/components/human-input-form.d.ts +1 -1
  85. package/dist/components/human-input-surface.d.ts +2 -2
  86. package/dist/components/interaction-intervention-banner.d.ts +11 -0
  87. package/dist/components/interactive-workbench-viewers.d.ts +2 -0
  88. package/dist/components/machine-card.d.ts +2 -2
  89. package/dist/components/machine-dock-bar.d.ts +3 -3
  90. package/dist/components/machine-health-pill.d.ts +2 -2
  91. package/dist/components/machine-input-display.d.ts +1 -1
  92. package/dist/components/machine-metrics.d.ts +2 -2
  93. package/dist/components/machine-status-pill.d.ts +4 -4
  94. package/dist/components/machines/health.d.ts +1 -1
  95. package/dist/components/machines/machine-detail.d.ts +3 -3
  96. package/dist/components/machines/metric-history-chart.d.ts +1 -1
  97. package/dist/components/machines/metric-sparkline.d.ts +2 -2
  98. package/dist/components/machines/series.d.ts +2 -2
  99. package/dist/components/machines-dashboard.d.ts +2 -2
  100. package/dist/components/markdown.d.ts +1 -1
  101. package/dist/components/message-timeline.d.ts +12 -5
  102. package/dist/components/model-picker.d.ts +2 -2
  103. package/dist/components/model-policy-picker.d.ts +7 -7
  104. package/dist/components/pierre-diff.d.ts +1 -1
  105. package/dist/components/pierre-file.d.ts +1 -1
  106. package/dist/components/queue-draft-policy.d.ts +1 -1
  107. package/dist/components/queue-surface-implementation.d.ts +3 -3
  108. package/dist/components/queue-surface-state.d.ts +4 -4
  109. package/dist/components/queue-surface.d.ts +5 -5
  110. package/dist/components/sandbox-files.d.ts +3 -3
  111. package/dist/components/sandbox-terminal.d.ts +24 -4
  112. package/dist/components/sandbox-workspace.d.ts +28 -9
  113. package/dist/components/session-chrome.d.ts +4 -4
  114. package/dist/components/session-status.d.ts +2 -2
  115. package/dist/components/timeline-annotation-selection.d.ts +9 -0
  116. package/dist/components/timeline-annotations-dialog.d.ts +16 -0
  117. package/dist/components/timeline-annotations.d.ts +13 -0
  118. package/dist/components/tooltip.d.ts +4 -4
  119. package/dist/components/user-message-body.d.ts +2 -2
  120. package/dist/components/workbench-changes.d.ts +2 -2
  121. package/dist/components/workspace-dock.d.ts +1 -1
  122. package/dist/composer.d.ts +11 -11
  123. package/dist/composer.js +7 -7
  124. package/dist/hooks/internal.d.ts +1 -1
  125. package/dist/hooks/use-attached-browsers.d.ts +21 -0
  126. package/dist/hooks/use-auth-runs.d.ts +32 -0
  127. package/dist/hooks/use-available-models.d.ts +2 -2
  128. package/dist/hooks/use-billing-usage.d.ts +1 -1
  129. package/dist/hooks/use-browser-downloads.d.ts +25 -0
  130. package/dist/hooks/use-browser-frame-stream.d.ts +28 -0
  131. package/dist/hooks/use-browser-identities.d.ts +30 -0
  132. package/dist/hooks/use-browser-session.d.ts +29 -0
  133. package/dist/hooks/use-browser-sessions.d.ts +32 -0
  134. package/dist/hooks/use-channels.d.ts +26 -0
  135. package/dist/hooks/use-codex-accounts.d.ts +2 -2
  136. package/dist/hooks/use-composer.d.ts +36 -9
  137. package/dist/hooks/use-computer-frame-stream.d.ts +24 -0
  138. package/dist/hooks/use-computer-session.d.ts +29 -0
  139. package/dist/hooks/use-computer-sessions.d.ts +28 -0
  140. package/dist/hooks/use-desktop-stream.d.ts +5 -1
  141. package/dist/hooks/use-environments.d.ts +1 -1
  142. package/dist/hooks/use-file-attachments.d.ts +1 -1
  143. package/dist/hooks/use-goal.d.ts +2 -2
  144. package/dist/hooks/use-human-input.d.ts +2 -2
  145. package/dist/hooks/use-interaction-interventions.d.ts +27 -0
  146. package/dist/hooks/use-interaction-invalidation.d.ts +19 -0
  147. package/dist/hooks/use-last-started-turn-policy.d.ts +2 -2
  148. package/dist/hooks/use-machine-chip.d.ts +2 -2
  149. package/dist/hooks/use-machines.d.ts +4 -4
  150. package/dist/hooks/use-network-routes.d.ts +25 -0
  151. package/dist/hooks/use-packs.d.ts +7 -2
  152. package/dist/hooks/use-rigs.d.ts +1 -1
  153. package/dist/hooks/use-sandbox-files.d.ts +6 -4
  154. package/dist/hooks/use-sandbox-git.d.ts +6 -5
  155. package/dist/hooks/use-sandbox-terminal.d.ts +1 -1
  156. package/dist/hooks/use-scheduled-tasks.d.ts +1 -1
  157. package/dist/hooks/use-session-capabilities.d.ts +5 -4
  158. package/dist/hooks/use-session-control.d.ts +1 -1
  159. package/dist/hooks/use-session-events.d.ts +2 -2
  160. package/dist/hooks/use-session-lineage.d.ts +1 -1
  161. package/dist/hooks/use-session-mcp-approval-policy.d.ts +2 -2
  162. package/dist/hooks/use-session.d.ts +2 -2
  163. package/dist/hooks/use-site-auth-connections.d.ts +25 -0
  164. package/dist/hooks/use-slash-commands.d.ts +1 -1
  165. package/dist/hooks/use-supergrok-accounts.d.ts +26 -0
  166. package/dist/hooks/use-terminal-stream.d.ts +11 -2
  167. package/dist/hooks/use-turn-queue.d.ts +2 -2
  168. package/dist/hooks/use-video-artifact-playback.d.ts +9 -0
  169. package/dist/hooks/use-voice-input.d.ts +1 -1
  170. package/dist/hooks/use-workspace-capture.d.ts +1 -1
  171. package/dist/hooks/use-workspace-edit.d.ts +1 -1
  172. package/dist/hooks/use-workspace-sessions.d.ts +1 -1
  173. package/dist/hooks/use-workspaces.d.ts +1 -1
  174. package/dist/index.d.ts +162 -155
  175. package/dist/index.js +1822 -1703
  176. package/dist/index.js.map +1 -1
  177. package/dist/interaction.d.ts +33 -0
  178. package/dist/interaction.js +550 -0
  179. package/dist/interaction.js.map +1 -0
  180. package/dist/interactive-workbench-viewers-TOHBXJEE.js +15 -0
  181. package/dist/interactive-workbench-viewers-TOHBXJEE.js.map +1 -0
  182. package/dist/lib/host-platform.d.ts +5 -0
  183. package/dist/lib/relay-wire.d.ts +24 -1
  184. package/dist/lib/sandbox-liveness.d.ts +9 -0
  185. package/dist/lib/terminal-capability.d.ts +5 -0
  186. package/dist/lib/xterm-theme.d.ts +1 -1
  187. package/dist/machines.d.ts +30 -30
  188. package/dist/machines.js +2 -2
  189. package/dist/model-policy.d.ts +1 -1
  190. package/dist/model-policy.js +1 -1
  191. package/dist/provider.d.ts +6 -5
  192. package/dist/{queue-surface-implementation-U5JFG7HT.js → queue-surface-implementation-2KVJTYXH.js} +100 -48
  193. package/dist/queue-surface-implementation-2KVJTYXH.js.map +1 -0
  194. package/dist/realtime/dropdown-menu.d.ts +8 -8
  195. package/dist/realtime/realtime-control.d.ts +8 -8
  196. package/dist/realtime.d.ts +4 -4
  197. package/dist/realtime.js +38 -11
  198. package/dist/realtime.js.map +1 -1
  199. package/dist/session-context.d.ts +28 -2
  200. package/dist/session-ui.d.ts +14 -14
  201. package/dist/session-ui.js +5 -4
  202. package/dist/session.d.ts +28 -28
  203. package/dist/session.js +10 -10
  204. package/dist/timeline/activity-rail.d.ts +5 -3
  205. package/dist/timeline/disclosure-context.d.ts +1 -1
  206. package/dist/timeline/fleet-decision-projection.d.ts +1 -1
  207. package/dist/timeline/fleet-decision-row.d.ts +3 -3
  208. package/dist/timeline/index.d.ts +19 -19
  209. package/dist/timeline/parsers.d.ts +4 -1
  210. package/dist/timeline/projection.d.ts +3 -3
  211. package/dist/timeline/registry.d.ts +8 -2
  212. package/dist/timeline/screenshot-lightbox.d.ts +2 -2
  213. package/dist/timeline/shared.d.ts +21 -10
  214. package/dist/timeline/tool-diff.d.ts +2 -2
  215. package/dist/timeline/tool-renderers.d.ts +1 -1
  216. package/dist/timeline/turn-summary.d.ts +3 -3
  217. package/dist/timeline/types.d.ts +44 -3
  218. package/dist/timeline-annotation-selection-3L7LHGG2.js +187 -0
  219. package/dist/timeline-annotation-selection-3L7LHGG2.js.map +1 -0
  220. package/dist/timeline-annotations-dialog-U7EVLR75.js +196 -0
  221. package/dist/timeline-annotations-dialog-U7EVLR75.js.map +1 -0
  222. package/package.json +36 -7
  223. package/src/artifacts-document.ts +31 -0
  224. package/src/artifacts-presentation.ts +36 -0
  225. package/src/artifacts-spreadsheet.ts +21 -0
  226. package/src/artifacts.ts +89 -0
  227. package/src/client.ts +157 -1
  228. package/src/clipboard.ts +2 -0
  229. package/src/components/artifacts/artifact-surface.tsx +93 -0
  230. package/src/components/artifacts/document-editor.tsx +2255 -0
  231. package/src/components/artifacts/editable-artifact-ui.tsx +89 -0
  232. package/src/components/artifacts/editable-artifact-workbench.tsx +203 -0
  233. package/src/components/artifacts/editable-document.tsx +657 -0
  234. package/src/components/artifacts/editable-presentation.tsx +1020 -0
  235. package/src/components/artifacts/editable-spreadsheet.tsx +733 -0
  236. package/src/components/artifacts/index.ts +104 -0
  237. package/src/components/artifacts/presentation-editor.tsx +3148 -0
  238. package/src/components/artifacts/published-html-artifact-frame.tsx +38 -0
  239. package/src/components/artifacts/spreadsheet-canvas.ts +799 -0
  240. package/src/components/artifacts/spreadsheet-grid.tsx +2129 -0
  241. package/src/components/browser-input.ts +65 -0
  242. package/src/components/browser-viewer.tsx +2702 -0
  243. package/src/components/chat-composer.tsx +13 -0
  244. package/src/components/code-editor.tsx +89 -30
  245. package/src/components/composer-transcription-control.tsx +10 -6
  246. package/src/components/computer-viewer.tsx +1636 -0
  247. package/src/components/desktop-viewer.tsx +215 -74
  248. package/src/components/generated-video-player.tsx +89 -0
  249. package/src/components/interaction-intervention-banner.tsx +99 -0
  250. package/src/components/interactive-workbench-viewers.ts +2 -0
  251. package/src/components/machine-input-display.ts +3 -0
  252. package/src/components/machines/machine-detail.tsx +1 -1
  253. package/src/components/message-timeline.tsx +289 -32
  254. package/src/components/model-policy-picker.tsx +15 -0
  255. package/src/components/queue-surface-implementation.tsx +116 -60
  256. package/src/components/sandbox-files.tsx +2 -2
  257. package/src/components/sandbox-terminal.tsx +128 -46
  258. package/src/components/sandbox-workspace.tsx +256 -90
  259. package/src/components/session-chrome.tsx +53 -13
  260. package/src/components/timeline-annotation-selection.tsx +221 -0
  261. package/src/components/timeline-annotations-dialog.tsx +213 -0
  262. package/src/components/timeline-annotations.tsx +84 -0
  263. package/src/components/workbench-changes.tsx +188 -31
  264. package/src/components/workspace-dock.tsx +59 -5
  265. package/src/hooks/use-attached-browsers.ts +154 -0
  266. package/src/hooks/use-auth-runs.ts +278 -0
  267. package/src/hooks/use-browser-downloads.ts +218 -0
  268. package/src/hooks/use-browser-frame-stream.ts +425 -0
  269. package/src/hooks/use-browser-identities.ts +266 -0
  270. package/src/hooks/use-browser-session.ts +543 -0
  271. package/src/hooks/use-browser-sessions.ts +286 -0
  272. package/src/hooks/use-channels.ts +99 -0
  273. package/src/hooks/use-composer.ts +769 -24
  274. package/src/hooks/use-computer-frame-stream.ts +434 -0
  275. package/src/hooks/use-computer-session.ts +462 -0
  276. package/src/hooks/use-computer-sessions.ts +251 -0
  277. package/src/hooks/use-desktop-stream.ts +39 -7
  278. package/src/hooks/use-interaction-interventions.ts +242 -0
  279. package/src/hooks/use-interaction-invalidation.ts +66 -0
  280. package/src/hooks/use-machine-chip.ts +15 -3
  281. package/src/hooks/use-machines.ts +33 -3
  282. package/src/hooks/use-network-routes.ts +214 -0
  283. package/src/hooks/use-packs.ts +51 -0
  284. package/src/hooks/use-sandbox-files.ts +98 -55
  285. package/src/hooks/use-sandbox-git.ts +93 -38
  286. package/src/hooks/use-sandbox-terminal.ts +3 -2
  287. package/src/hooks/use-session-capabilities.ts +59 -46
  288. package/src/hooks/use-site-auth-connections.ts +226 -0
  289. package/src/hooks/use-supergrok-accounts.ts +81 -0
  290. package/src/hooks/use-terminal-stream.ts +359 -47
  291. package/src/hooks/use-video-artifact-playback.ts +28 -0
  292. package/src/hooks/use-workspace-edit.ts +2 -1
  293. package/src/index.ts +18 -0
  294. package/src/interaction.ts +101 -0
  295. package/src/lib/host-platform.ts +10 -0
  296. package/src/lib/relay-wire.ts +47 -4
  297. package/src/lib/sandbox-liveness.ts +11 -0
  298. package/src/lib/terminal-capability.ts +10 -0
  299. package/src/model-policy.ts +19 -4
  300. package/src/provider.tsx +133 -1
  301. package/src/realtime/realtime-control.tsx +34 -6
  302. package/src/session-context.ts +156 -1
  303. package/src/timeline/activity-rail.tsx +25 -3
  304. package/src/timeline/index.ts +3 -0
  305. package/src/timeline/parsers.ts +14 -1
  306. package/src/timeline/projection.ts +269 -14
  307. package/src/timeline/registry.ts +13 -1
  308. package/src/timeline/screenshot-lightbox.tsx +19 -9
  309. package/src/timeline/shared.tsx +56 -8
  310. package/src/timeline/tool-renderers.tsx +303 -50
  311. package/src/timeline/types.ts +57 -3
  312. package/styles/compiled.css +312 -21
  313. package/styles/index.css +15 -0
  314. package/styles/responsive.css +13 -1
  315. package/dist/chunk-23EJ676W.js.map +0 -1
  316. package/dist/chunk-EKZH6IDG.js.map +0 -1
  317. package/dist/chunk-FWXGSNXT.js.map +0 -1
  318. package/dist/chunk-LHLYWG5R.js.map +0 -1
  319. package/dist/chunk-O4VXOBGF.js.map +0 -1
  320. package/dist/chunk-OL6QVXGF.js.map +0 -1
  321. package/dist/chunk-WYA65Y3F.js.map +0 -1
  322. package/dist/chunk-XCNTXWBB.js.map +0 -1
  323. package/dist/fleet-decision-projection-SLNZMS42.js +0 -241
  324. package/dist/fleet-decision-projection-SLNZMS42.js.map +0 -1
  325. package/dist/queue-surface-implementation-U5JFG7HT.js.map +0 -1
@@ -0,0 +1,425 @@
1
+ import {
2
+ browserFrameSocketUrl,
3
+ decodeBrowserFrameMessage,
4
+ type BrowserFrame,
5
+ type BrowserFrameStreamOptions,
6
+ type BrowserSessionAttachment,
7
+ } from "@opengeni/sdk/interaction";
8
+ import { useCallback, useEffect, useRef, useState } from "react";
9
+ import {
10
+ type EmbeddedBrowserInteractionClientOverride,
11
+ useEmbeddedBrowserInteraction,
12
+ } from "../session-context";
13
+ import {
14
+ decodeStreamFrame,
15
+ decodeStreamOpenAck,
16
+ encodeStreamClose,
17
+ encodeStreamOpen,
18
+ STREAM_CLOSE_REASON_NORMAL,
19
+ STREAM_KIND_BROWSER,
20
+ STREAM_ROLE_CLIENT,
21
+ } from "../lib/relay-wire";
22
+
23
+ export type BrowserFrameConnectionState =
24
+ | "idle"
25
+ | "attaching"
26
+ | "connecting"
27
+ | "live"
28
+ | "reconnecting"
29
+ | "error";
30
+
31
+ export type BrowserFrameWebSocket = Pick<
32
+ WebSocket,
33
+ "binaryType" | "readyState" | "close" | "addEventListener" | "removeEventListener"
34
+ > & { send(data: ArrayBuffer): void };
35
+
36
+ export type BrowserFrameWebSocketFactory = (
37
+ url: string,
38
+ protocols: string[],
39
+ ) => BrowserFrameWebSocket;
40
+
41
+ const RELAY_TAG_OPEN = 1;
42
+ const RELAY_TAG_OPEN_ACK = 2;
43
+ const RELAY_TAG_FRAME = 3;
44
+ const RELAY_TAG_CLOSE = 4;
45
+ const MAX_AUTOMATIC_RECONNECTS_WITHOUT_A_FRAME = 2;
46
+
47
+ export type UseBrowserFrameStreamOptions = EmbeddedBrowserInteractionClientOverride & {
48
+ browserSessionId: string | null;
49
+ targetId: string | null;
50
+ enabled?: boolean | undefined;
51
+ stream?: BrowserFrameStreamOptions | undefined;
52
+ webSocketFactory?: BrowserFrameWebSocketFactory | undefined;
53
+ };
54
+
55
+ export type UseBrowserFrameStreamResult = {
56
+ state: BrowserFrameConnectionState;
57
+ frame: BrowserFrame | null;
58
+ attachment: Pick<
59
+ BrowserSessionAttachment,
60
+ "browserSessionId" | "controllerGeneration" | "targetId" | "expiresAt"
61
+ > | null;
62
+ error: Error | null;
63
+ reconnect: () => void;
64
+ };
65
+
66
+ /**
67
+ * Reconnecting, latest-only BrowserSession media attachment. Direct placement
68
+ * grants travel as a WebSocket subprotocol; connected-machine grants stay in the
69
+ * relay's first authenticated binary message. Neither transport puts a grant in
70
+ * a URL, event, log, or separately exposed React state.
71
+ */
72
+ export function useBrowserFrameStream(
73
+ options: UseBrowserFrameStreamOptions,
74
+ ): UseBrowserFrameStreamResult {
75
+ const { client, workspaceId } = useEmbeddedBrowserInteraction(options);
76
+ const enabled = options.enabled ?? true;
77
+ const [nonce, setNonce] = useState(0);
78
+ const [result, setResult] = useState<Omit<UseBrowserFrameStreamResult, "reconnect">>({
79
+ state: "idle",
80
+ frame: null,
81
+ attachment: null,
82
+ error: null,
83
+ });
84
+ const latestRef = useRef<{ key: string; sequence: number }>({
85
+ key: "",
86
+ sequence: -1,
87
+ });
88
+ const factoryRef = useRef(options.webSocketFactory);
89
+ const streamRef = useRef(options.stream);
90
+ factoryRef.current = options.webSocketFactory;
91
+ streamRef.current = options.stream;
92
+
93
+ const reconnect = useCallback(() => setNonce((value) => value + 1), []);
94
+
95
+ useEffect(() => {
96
+ const browserSessionId = options.browserSessionId;
97
+ const targetId = options.targetId;
98
+ if (!enabled || !browserSessionId || !targetId || typeof window === "undefined") {
99
+ setResult({ state: "idle", frame: null, attachment: null, error: null });
100
+ return;
101
+ }
102
+
103
+ // Never render or target input against a frame from the previously selected
104
+ // resource while its replacement attachment is negotiating.
105
+ latestRef.current = { key: "", sequence: -1 };
106
+ setResult({
107
+ state: "attaching",
108
+ frame: null,
109
+ attachment: null,
110
+ error: null,
111
+ });
112
+
113
+ let disposed = false;
114
+ let socket: BrowserFrameWebSocket | null = null;
115
+ let socketHandlers: {
116
+ open: () => void;
117
+ message: (event: MessageEvent) => void;
118
+ error: () => void;
119
+ close: () => void;
120
+ } | null = null;
121
+ let reconnectTimer: ReturnType<typeof setTimeout> | null = null;
122
+ let expiryTimer: ReturnType<typeof setTimeout> | null = null;
123
+ let failures = 0;
124
+ let controllerGeneration: string | null = null;
125
+ let activeAttachment: BrowserSessionAttachment | null = null;
126
+ let activeStream: BrowserSessionAttachment["stream"] | null = null;
127
+ let attachmentExpiresAt = 0;
128
+ let lastRelaySequence: string | null = null;
129
+ let relayAccepted = false;
130
+ let pendingFrame: { bytes: Uint8Array; source: BrowserFrameWebSocket } | null = null;
131
+ let decodingFrame = false;
132
+ const attachmentAbort = new AbortController();
133
+
134
+ const clearSocket = (terminateProducer = false) => {
135
+ if (!socket) return;
136
+ const current = socket;
137
+ const handlers = socketHandlers;
138
+ if (terminateProducer && activeStream?.kind === "relay" && socket.readyState === 1) {
139
+ try {
140
+ socket.send(
141
+ relayDatagram(
142
+ RELAY_TAG_CLOSE,
143
+ encodeStreamClose({
144
+ channelId: activeStream.channel.channelId,
145
+ reason: STREAM_CLOSE_REASON_NORMAL,
146
+ message: "viewer detached",
147
+ }),
148
+ ),
149
+ );
150
+ } catch {
151
+ // OPEN can race a transport close. Local teardown must still finish.
152
+ }
153
+ }
154
+ if (handlers) {
155
+ current.removeEventListener("open", handlers.open);
156
+ current.removeEventListener("message", handlers.message);
157
+ current.removeEventListener("error", handlers.error);
158
+ current.removeEventListener("close", handlers.close);
159
+ }
160
+ if (current.readyState === 0 || current.readyState === 1) {
161
+ current.close(1000, "viewer detached");
162
+ }
163
+ socket = null;
164
+ socketHandlers = null;
165
+ pendingFrame = null;
166
+ };
167
+
168
+ const scheduleReconnect = () => {
169
+ if (disposed || reconnectTimer) return;
170
+ if (failures >= MAX_AUTOMATIC_RECONNECTS_WITHOUT_A_FRAME) return;
171
+ const delay = Math.min(5_000, 250 * 2 ** Math.min(failures, 5));
172
+ failures += 1;
173
+ setResult((current) => ({ ...current, state: "reconnecting" }));
174
+ reconnectTimer = setTimeout(() => {
175
+ reconnectTimer = null;
176
+ connectSocket();
177
+ }, delay);
178
+ };
179
+
180
+ const fail = (cause: unknown, reconnectAutomatically = true) => {
181
+ if (disposed) return;
182
+ const error = cause instanceof Error ? cause : new Error(String(cause));
183
+ setResult((current) => ({ ...current, state: "error", error }));
184
+ clearSocket();
185
+ if (reconnectAutomatically) scheduleReconnect();
186
+ };
187
+
188
+ const onOpen = (source: BrowserFrameWebSocket) => {
189
+ if (disposed || source !== socket) return;
190
+ if (activeStream?.kind === "relay") {
191
+ const body = encodeStreamOpen({
192
+ channel: {
193
+ ...activeStream.channel,
194
+ kind: STREAM_KIND_BROWSER,
195
+ },
196
+ token: activeStream.token,
197
+ role: STREAM_ROLE_CLIENT,
198
+ resumeFromSeq:
199
+ lastRelaySequence === null ? "0" : (BigInt(lastRelaySequence) + 1n).toString(),
200
+ });
201
+ try {
202
+ source.send(relayDatagram(RELAY_TAG_OPEN, body));
203
+ } catch (error) {
204
+ fail(error);
205
+ }
206
+ return;
207
+ }
208
+ setResult((current) => ({ ...current, state: "live", error: null }));
209
+ };
210
+
211
+ const drainLatestFrame = async () => {
212
+ if (decodingFrame) return;
213
+ decodingFrame = true;
214
+ try {
215
+ while (pendingFrame) {
216
+ if (disposed) break;
217
+ const pending = pendingFrame;
218
+ pendingFrame = null;
219
+ const { bytes, source } = pending;
220
+ const frame = decodeBrowserFrameMessage(bytes);
221
+ if (disposed || source !== socket) continue;
222
+ if (frame.browserSessionId !== browserSessionId || frame.targetId !== targetId) {
223
+ throw new Error("browser frame belongs to another resource");
224
+ }
225
+ if (!controllerGeneration || frame.controllerGeneration !== controllerGeneration) {
226
+ throw new Error("browser frame belongs to a stale controller");
227
+ }
228
+ const key = `${browserSessionId}:${targetId}:${frame.controllerGeneration}:${frame.targetGeneration}:${frame.documentGeneration}`;
229
+ if (latestRef.current.key === key && frame.sequence <= latestRef.current.sequence)
230
+ continue;
231
+ latestRef.current = { key, sequence: frame.sequence };
232
+ failures = 0;
233
+ setResult((current) => ({
234
+ ...current,
235
+ state: "live",
236
+ frame,
237
+ error: null,
238
+ }));
239
+ }
240
+ } catch (cause) {
241
+ fail(cause);
242
+ } finally {
243
+ decodingFrame = false;
244
+ if (!disposed && pendingFrame) void drainLatestFrame();
245
+ }
246
+ };
247
+
248
+ const onMessage = (source: BrowserFrameWebSocket, event: MessageEvent) => {
249
+ void (async () => {
250
+ try {
251
+ const bytes = await messageBytes(event.data);
252
+ if (disposed || source !== socket) return;
253
+ let frameBytes = bytes;
254
+ if (activeStream?.kind === "relay") {
255
+ if (bytes.length < 1) throw new Error("browser relay returned an empty message");
256
+ const tag = bytes[0];
257
+ const body = bytes.subarray(1);
258
+ if (tag === RELAY_TAG_OPEN_ACK) {
259
+ const ack = decodeStreamOpenAck(body);
260
+ if (!ack.accepted) {
261
+ activeAttachment = null;
262
+ activeStream = null;
263
+ attachmentExpiresAt = 0;
264
+ throw new Error(ack.error?.message ?? "browser stream was rejected by the relay");
265
+ }
266
+ relayAccepted = true;
267
+ return;
268
+ }
269
+ if (tag === RELAY_TAG_CLOSE) {
270
+ activeAttachment = null;
271
+ activeStream = null;
272
+ attachmentExpiresAt = 0;
273
+ lastRelaySequence = null;
274
+ relayAccepted = false;
275
+ fail(new Error("Browser frame source ended."), false);
276
+ return;
277
+ }
278
+ if (tag !== RELAY_TAG_FRAME || !relayAccepted) return;
279
+ const relayFrame = decodeStreamFrame(body);
280
+ lastRelaySequence = relayFrame.seq;
281
+ frameBytes = relayFrame.data;
282
+ }
283
+ pendingFrame = { bytes: frameBytes, source };
284
+ void drainLatestFrame();
285
+ } catch (cause) {
286
+ fail(cause);
287
+ }
288
+ })();
289
+ };
290
+
291
+ const onError = (source: BrowserFrameWebSocket) => {
292
+ if (source !== socket) return;
293
+ fail(new Error("Browser view lost connection."));
294
+ };
295
+
296
+ const onClose = (source: BrowserFrameWebSocket) => {
297
+ if (disposed || source !== socket) return;
298
+ clearSocket();
299
+ scheduleReconnect();
300
+ };
301
+
302
+ const connectSocket = () => {
303
+ if (disposed) return;
304
+ clearSocket();
305
+ if (!activeAttachment || !activeStream || attachmentExpiresAt <= Date.now() + 1_000) {
306
+ void attach();
307
+ return;
308
+ }
309
+ relayAccepted = false;
310
+ setResult((current) => ({
311
+ ...current,
312
+ state: "connecting",
313
+ error: null,
314
+ }));
315
+ const createSocket =
316
+ factoryRef.current ?? ((url: string, protocols: string[]) => new WebSocket(url, protocols));
317
+ const openedSocket = createSocket(
318
+ activeStream.kind === "relay"
319
+ ? activeStream.url
320
+ : browserFrameSocketUrl(activeAttachment, streamRef.current),
321
+ activeStream.kind === "direct_websocket" ? [...activeStream.protocols] : [],
322
+ );
323
+ socket = openedSocket;
324
+ socketHandlers = {
325
+ open: () => onOpen(openedSocket),
326
+ message: (event) => onMessage(openedSocket, event),
327
+ error: () => onError(openedSocket),
328
+ close: () => onClose(openedSocket),
329
+ };
330
+ openedSocket.binaryType = "arraybuffer";
331
+ openedSocket.addEventListener("open", socketHandlers.open);
332
+ openedSocket.addEventListener("message", socketHandlers.message);
333
+ openedSocket.addEventListener("error", socketHandlers.error);
334
+ openedSocket.addEventListener("close", socketHandlers.close);
335
+ };
336
+
337
+ const attach = async () => {
338
+ if (disposed) return;
339
+ clearSocket();
340
+ if (expiryTimer) clearTimeout(expiryTimer);
341
+ setResult((current) => ({
342
+ ...current,
343
+ state: current.attachment ? "reconnecting" : "attaching",
344
+ error: null,
345
+ }));
346
+ try {
347
+ const attachment = await client.attachBrowserSession(
348
+ workspaceId,
349
+ browserSessionId,
350
+ {
351
+ targetId,
352
+ expiresInSeconds: 120,
353
+ ...(streamRef.current ? { stream: streamRef.current } : {}),
354
+ },
355
+ { signal: attachmentAbort.signal },
356
+ );
357
+ if (disposed) return;
358
+ if (attachment.browserSessionId !== browserSessionId || attachment.targetId !== targetId) {
359
+ throw new Error("browser attachment does not match the requested resource");
360
+ }
361
+ controllerGeneration = attachment.controllerGeneration;
362
+ activeAttachment = attachment;
363
+ activeStream = attachment.stream;
364
+ attachmentExpiresAt = Date.parse(attachment.expiresAt);
365
+ lastRelaySequence = null;
366
+ relayAccepted = false;
367
+ setResult((current) => ({
368
+ ...current,
369
+ state: "connecting",
370
+ attachment: {
371
+ browserSessionId: attachment.browserSessionId,
372
+ controllerGeneration: attachment.controllerGeneration,
373
+ targetId: attachment.targetId,
374
+ expiresAt: attachment.expiresAt,
375
+ },
376
+ error: null,
377
+ }));
378
+ const refreshIn = Number.isFinite(attachmentExpiresAt)
379
+ ? Math.max(1_000, attachmentExpiresAt - Date.now() - 5_000)
380
+ : 60_000;
381
+ expiryTimer = setTimeout(() => {
382
+ if (disposed) return;
383
+ clearSocket(true);
384
+ activeAttachment = null;
385
+ activeStream = null;
386
+ attachmentExpiresAt = 0;
387
+ void attach();
388
+ }, refreshIn);
389
+ connectSocket();
390
+ } catch (cause) {
391
+ if (attachmentAbort.signal.aborted || disposed) return;
392
+ fail(cause);
393
+ }
394
+ };
395
+
396
+ void attach();
397
+ return () => {
398
+ disposed = true;
399
+ attachmentAbort.abort();
400
+ if (reconnectTimer) clearTimeout(reconnectTimer);
401
+ if (expiryTimer) clearTimeout(expiryTimer);
402
+ clearSocket(true);
403
+ };
404
+ }, [client, enabled, nonce, options.browserSessionId, options.targetId, workspaceId]);
405
+
406
+ return { ...result, reconnect };
407
+ }
408
+
409
+ function relayDatagram(tag: number, body: Uint8Array): ArrayBuffer {
410
+ const message = new Uint8Array(body.length + 1);
411
+ message[0] = tag;
412
+ message.set(body, 1);
413
+ return message.buffer as ArrayBuffer;
414
+ }
415
+
416
+ async function messageBytes(value: unknown): Promise<Uint8Array> {
417
+ if (value instanceof ArrayBuffer) return new Uint8Array(value);
418
+ if (ArrayBuffer.isView(value)) {
419
+ return new Uint8Array(value.buffer, value.byteOffset, value.byteLength).slice();
420
+ }
421
+ if (typeof Blob !== "undefined" && value instanceof Blob) {
422
+ return new Uint8Array(await value.arrayBuffer());
423
+ }
424
+ throw new Error("browser frame stream returned a non-binary message");
425
+ }
@@ -0,0 +1,266 @@
1
+ import type {
2
+ BrowserIdentity,
3
+ BrowserIdentityMutationResponse,
4
+ BrowserRevisionListResponse,
5
+ CreateBrowserIdentityRequest,
6
+ PublishBrowserRevisionRequest,
7
+ PublishBrowserRevisionResponse,
8
+ UpdateBrowserIdentityRequest,
9
+ } from "@opengeni/sdk/interaction";
10
+ import { useCallback, useEffect, useRef, useState } from "react";
11
+ import type { EmbeddedBrowserInteractionClientLike } from "../client";
12
+ import {
13
+ type EmbeddedBrowserInteractionClientOverride,
14
+ useEmbeddedBrowserInteraction,
15
+ } from "../session-context";
16
+ import { useInteractionInvalidation } from "./use-interaction-invalidation";
17
+
18
+ export type UseBrowserIdentitiesOptions = EmbeddedBrowserInteractionClientOverride & {
19
+ enabled?: boolean | undefined;
20
+ includeArchived?: boolean | undefined;
21
+ };
22
+
23
+ export type UseBrowserIdentitiesResult = {
24
+ revision: number;
25
+ identities: BrowserIdentity[];
26
+ loading: boolean;
27
+ refreshing: boolean;
28
+ mutating: boolean;
29
+ error: Error | null;
30
+ refresh: () => Promise<void>;
31
+ create: (
32
+ request: Omit<CreateBrowserIdentityRequest, "operationId"> & {
33
+ operationId?: string;
34
+ },
35
+ ) => Promise<BrowserIdentityMutationResponse>;
36
+ update: (
37
+ identityId: string,
38
+ request: Omit<UpdateBrowserIdentityRequest, "operationId"> & { operationId?: string },
39
+ ) => Promise<BrowserIdentityMutationResponse>;
40
+ revisions: (identityId: string) => Promise<BrowserRevisionListResponse>;
41
+ publish: (
42
+ browserSessionId: string,
43
+ request: Omit<PublishBrowserRevisionRequest, "operationId"> & {
44
+ operationId?: string;
45
+ },
46
+ ) => Promise<PublishBrowserRevisionResponse>;
47
+ };
48
+
49
+ /** Workspace browser-profile library and explicit immutable-version mutations. */
50
+ export function useBrowserIdentities(
51
+ options: UseBrowserIdentitiesOptions = {},
52
+ ): UseBrowserIdentitiesResult {
53
+ const { client, workspaceId, workspaceInteractionEvent, workspaceInteractionConnectionState } =
54
+ useEmbeddedBrowserInteraction(options);
55
+ const enabled = options.enabled ?? true;
56
+ const includeArchived = options.includeArchived ?? false;
57
+ const [state, setState] = useState(() => emptyState(workspaceId, enabled));
58
+ const [mutationCount, setMutationCount] = useState(0);
59
+ const requestRef = useRef<{ id: number; controller: AbortController | null }>({
60
+ id: 0,
61
+ controller: null,
62
+ });
63
+ const mountedRef = useRef(true);
64
+ const visibleState = state.workspaceId === workspaceId ? state : emptyState(workspaceId, enabled);
65
+
66
+ const cancelLoad = useCallback(() => {
67
+ const id = requestRef.current.id + 1;
68
+ requestRef.current.controller?.abort();
69
+ requestRef.current = { id, controller: null };
70
+ }, []);
71
+
72
+ const load = useCallback(
73
+ async (foreground: boolean): Promise<void> => {
74
+ if (!enabled) return;
75
+ const id = requestRef.current.id + 1;
76
+ requestRef.current.controller?.abort();
77
+ const controller = new AbortController();
78
+ requestRef.current = { id, controller };
79
+ setState((current) => ({
80
+ ...(current.workspaceId === workspaceId ? current : emptyState(workspaceId, true)),
81
+ loading: foreground,
82
+ refreshing: !foreground,
83
+ error: foreground || current.workspaceId !== workspaceId ? null : current.error,
84
+ }));
85
+ try {
86
+ const response = await client.listBrowserIdentities(workspaceId, {
87
+ includeArchived,
88
+ signal: controller.signal,
89
+ });
90
+ if (!mountedRef.current || requestRef.current.id !== id) return;
91
+ setState({
92
+ workspaceId,
93
+ revision: response.revision,
94
+ identities: sortIdentities(response.identities),
95
+ loading: false,
96
+ refreshing: false,
97
+ error: null,
98
+ });
99
+ } catch (cause) {
100
+ if (controller.signal.aborted || !mountedRef.current || requestRef.current.id !== id)
101
+ return;
102
+ setState((current) => ({
103
+ ...(current.workspaceId === workspaceId ? current : emptyState(workspaceId, true)),
104
+ loading: false,
105
+ refreshing: false,
106
+ error: cause instanceof Error ? cause : new Error(String(cause)),
107
+ }));
108
+ } finally {
109
+ if (requestRef.current.id === id) requestRef.current = { id, controller: null };
110
+ }
111
+ },
112
+ [client, enabled, includeArchived, workspaceId],
113
+ );
114
+
115
+ const refresh = useCallback(async () => await load(false), [load]);
116
+
117
+ useEffect(() => {
118
+ mountedRef.current = true;
119
+ if (!enabled) {
120
+ cancelLoad();
121
+ setState(emptyState(workspaceId, false));
122
+ return;
123
+ }
124
+ void load(true);
125
+ return () => {
126
+ mountedRef.current = false;
127
+ cancelLoad();
128
+ };
129
+ }, [cancelLoad, enabled, load, workspaceId]);
130
+
131
+ useInteractionInvalidation({
132
+ workspaceId,
133
+ key: workspaceId,
134
+ enabled,
135
+ event: workspaceInteractionEvent,
136
+ connectionState: workspaceInteractionConnectionState,
137
+ knownRevision: visibleState.revision,
138
+ refresh,
139
+ });
140
+
141
+ const mutate = useCallback(async <T>(operation: () => Promise<T>): Promise<T> => {
142
+ setMutationCount((count) => count + 1);
143
+ try {
144
+ return await operation();
145
+ } finally {
146
+ if (mountedRef.current) setMutationCount((count) => Math.max(0, count - 1));
147
+ }
148
+ }, []);
149
+
150
+ const create = useCallback(
151
+ async (
152
+ request: Omit<CreateBrowserIdentityRequest, "operationId"> & {
153
+ operationId?: string;
154
+ },
155
+ ): Promise<BrowserIdentityMutationResponse> =>
156
+ await mutate(async () => {
157
+ const response = await client.createBrowserIdentity(workspaceId, {
158
+ ...request,
159
+ operationId: request.operationId ?? crypto.randomUUID(),
160
+ });
161
+ setState((current) => mergeIdentity(current, workspaceId, response.identity));
162
+ return response;
163
+ }),
164
+ [client, mutate, workspaceId],
165
+ );
166
+
167
+ const revisions = useCallback(
168
+ async (identityId: string): Promise<BrowserRevisionListResponse> =>
169
+ await client.listBrowserRevisions(workspaceId, identityId),
170
+ [client, workspaceId],
171
+ );
172
+
173
+ const update = useCallback(
174
+ async (
175
+ identityId: string,
176
+ request: Omit<UpdateBrowserIdentityRequest, "operationId"> & { operationId?: string },
177
+ ): Promise<BrowserIdentityMutationResponse> =>
178
+ await mutate(async () => {
179
+ const response = await client.updateBrowserIdentity(workspaceId, identityId, {
180
+ ...request,
181
+ operationId: request.operationId ?? crypto.randomUUID(),
182
+ });
183
+ setState((current) =>
184
+ mergeIdentity(current, workspaceId, response.identity, includeArchived),
185
+ );
186
+ return response;
187
+ }),
188
+ [client, includeArchived, mutate, workspaceId],
189
+ );
190
+
191
+ const publish = useCallback(
192
+ async (
193
+ browserSessionId: string,
194
+ request: Omit<PublishBrowserRevisionRequest, "operationId"> & {
195
+ operationId?: string;
196
+ },
197
+ ): Promise<PublishBrowserRevisionResponse> =>
198
+ await mutate(async () => {
199
+ const response = await client.publishBrowserRevision(workspaceId, browserSessionId, {
200
+ ...request,
201
+ operationId: request.operationId ?? crypto.randomUUID(),
202
+ });
203
+ setState((current) => mergeIdentity(current, workspaceId, response.identity));
204
+ return response;
205
+ }),
206
+ [client, mutate, workspaceId],
207
+ );
208
+
209
+ return {
210
+ revision: visibleState.revision,
211
+ identities: visibleState.identities,
212
+ loading: visibleState.loading,
213
+ refreshing: visibleState.refreshing,
214
+ mutating: mutationCount > 0,
215
+ error: visibleState.error,
216
+ refresh,
217
+ create,
218
+ update,
219
+ revisions,
220
+ publish,
221
+ };
222
+ }
223
+
224
+ function emptyState(workspaceId: string, loading: boolean) {
225
+ return {
226
+ workspaceId,
227
+ revision: 0,
228
+ identities: [] as BrowserIdentity[],
229
+ loading,
230
+ refreshing: false,
231
+ error: null as Error | null,
232
+ };
233
+ }
234
+
235
+ function sortIdentities(identities: readonly BrowserIdentity[]): BrowserIdentity[] {
236
+ return [...identities].sort(
237
+ (left, right) =>
238
+ timestamp(right.updatedAt) - timestamp(left.updatedAt) || left.name.localeCompare(right.name),
239
+ );
240
+ }
241
+
242
+ function timestamp(value: string): number {
243
+ const parsed = Date.parse(value);
244
+ return Number.isFinite(parsed) ? parsed : 0;
245
+ }
246
+
247
+ function mergeIdentity(
248
+ current: ReturnType<typeof emptyState>,
249
+ workspaceId: string,
250
+ identity: BrowserIdentity,
251
+ includeArchived = false,
252
+ ): ReturnType<typeof emptyState> {
253
+ if (current.workspaceId !== workspaceId) return current;
254
+ return {
255
+ ...current,
256
+ identities: sortIdentities(
257
+ identity.status === "archived" && !includeArchived
258
+ ? current.identities.filter((candidate) => candidate.id !== identity.id)
259
+ : [...current.identities.filter((candidate) => candidate.id !== identity.id), identity],
260
+ ),
261
+ error: null,
262
+ };
263
+ }
264
+
265
+ /** Exported for narrow proxy implementations and tests. */
266
+ export type BrowserIdentitiesClient = EmbeddedBrowserInteractionClientLike;