@opengeni/react 1.4.2 → 1.4.4

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.
@@ -8,13 +8,13 @@ import {
8
8
  useBrowserSession,
9
9
  useBrowserSessions,
10
10
  useSiteAuthConnections
11
- } from "./chunk-VCSERYXH.js";
11
+ } from "./chunk-2OQA3CPB.js";
12
12
  import {
13
13
  ComputerViewer,
14
14
  useComputerFrameStream,
15
15
  useComputerSession,
16
16
  useComputerSessions
17
- } from "./chunk-MDIXFKA3.js";
17
+ } from "./chunk-I6OY3MWC.js";
18
18
  import {
19
19
  useInteractionInterventions,
20
20
  useInteractionInvalidation
@@ -28,7 +28,7 @@ import {
28
28
  setStartupDetails,
29
29
  useStartupDetails,
30
30
  userMessageLikelyNeedsDisclosure
31
- } from "./chunk-CREMJMVN.js";
31
+ } from "./chunk-EAOSEIXB.js";
32
32
  import "./chunk-B27E3V37.js";
33
33
  import "./chunk-JH7V627O.js";
34
34
  import "./chunk-2HVLQ26H.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opengeni/react",
3
- "version": "1.4.2",
3
+ "version": "1.4.4",
4
4
  "description": "React hooks and styled components for OpenGeni: live session streaming, chat composer, message timeline, session status, and fleet views — token-themed (CSS variables), dark-first, built on Tailwind v4 + Radix + Motion.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -153,8 +153,8 @@
153
153
  "@dnd-kit/utilities": "3.2.2",
154
154
  "@fontsource-variable/noto-sans-arabic": "5.2.10",
155
155
  "@fontsource-variable/noto-sans-jp": "5.2.10",
156
- "@opengeni/connect": "1.4.2",
157
- "@opengeni/sdk": "1.4.2",
156
+ "@opengeni/connect": "1.4.4",
157
+ "@opengeni/sdk": "1.4.4",
158
158
  "clsx": "^2.1.1",
159
159
  "dequal": "2.0.3",
160
160
  "lucide-react": "^1.8.0",
@@ -1,5 +1,6 @@
1
1
  import type {
2
2
  ComputerAction,
3
+ ComputerActionReceipt,
3
4
  ComputerClipboard,
4
5
  ComputerFrame,
5
6
  ComputerObservation,
@@ -42,7 +43,11 @@ import {
42
43
  type ComputerFrameWebSocketFactory,
43
44
  useComputerFrameStream,
44
45
  } from "../hooks/use-computer-frame-stream";
45
- import { useComputerSession } from "../hooks/use-computer-session";
46
+ import {
47
+ computerActionReceiptError,
48
+ isStaleComputerActionResult,
49
+ useComputerSession,
50
+ } from "../hooks/use-computer-session";
46
51
  import { useComputerInputPosture } from "../hooks/use-computer-input-posture";
47
52
  import { useComputerSessions } from "../hooks/use-computer-sessions";
48
53
  import { useInteractionInterventions } from "../hooks/use-interaction-interventions";
@@ -174,6 +179,7 @@ export function ComputerViewer({
174
179
 
175
180
  const notifyError = useCallback(
176
181
  (cause: unknown, fallback: string) => {
182
+ if (isStaleComputerActionResult(cause)) return;
177
183
  onNotify?.({
178
184
  kind: "error",
179
185
  message: cause instanceof Error ? cause.message : fallback,
@@ -490,19 +496,24 @@ export function ComputerViewer({
490
496
  ]);
491
497
 
492
498
  const perform = useCallback(
493
- async (action: ComputerAction, frame: ComputerFrame | null): Promise<void> => {
499
+ async (
500
+ action: ComputerAction,
501
+ frame: ComputerFrame | null,
502
+ operationId?: string,
503
+ ): Promise<ComputerActionReceipt> => {
494
504
  if (computer.controlError) throw computer.controlError;
495
505
  if (inputDenied) throw new Error("Desktop is view only. Refresh to check desktop controls.");
496
506
  let receipt;
497
507
  if (action.type === "pointer") {
498
508
  if (!frame) throw new Error("Desktop view is not ready for pointer input.");
499
- receipt = await actFromFrame(action, frame);
509
+ receipt = await actFromFrame(action, frame, operationId);
500
510
  } else {
501
- receipt = await act(action);
511
+ receipt = await act(action, operationId);
502
512
  }
503
- if (receipt.state !== "completed") {
504
- throw new Error(receipt.error?.message ?? "Desktop input did not complete.");
513
+ if (!isStaleComputerActionResult(receipt) && receipt.state !== "completed") {
514
+ throw computerActionReceiptError(receipt);
505
515
  }
516
+ return receipt;
506
517
  },
507
518
  [act, actFromFrame, computer.controlError, inputDenied],
508
519
  );
@@ -519,14 +530,15 @@ export function ComputerViewer({
519
530
  return;
520
531
  event.preventDefault();
521
532
  event.stopPropagation();
522
- void perform({ type: "clipboard", operation: "copy" }, null)
523
- .then(() => computer.readClipboard())
524
- .then(async (clipboard) => {
525
- if (clipboard.text && !(await copyTextToClipboard(clipboard.text))) {
526
- throw new Error("Desktop text could not be copied to the local clipboard");
527
- }
528
- })
529
- .catch((cause) => notifyError(cause, "Could not copy from the desktop."));
533
+ void (async () => {
534
+ const receipt = await perform({ type: "clipboard", operation: "copy" }, null);
535
+ if (isStaleComputerActionResult(receipt)) return;
536
+ const clipboard = await computer.readClipboard();
537
+ if (isStaleComputerActionResult(receipt) || isStaleComputerActionResult(clipboard)) return;
538
+ if (clipboard.text && !(await copyTextToClipboard(clipboard.text))) {
539
+ throw new Error("Desktop text could not be copied to the local clipboard");
540
+ }
541
+ })().catch((cause) => notifyError(cause, "Could not copy from the desktop."));
530
542
  },
531
543
  [computer, notifyError, perform, rfbInputEnabled, rfbStream],
532
544
  );
@@ -543,8 +555,11 @@ export function ComputerViewer({
543
555
  // ownership is asynchronous, so a successful write response alone does
544
556
  // not prove that the graphical seat can already serve the selection.
545
557
  void (async () => {
546
- await perform({ type: "clipboard", operation: "write", text }, null);
547
- assertExactComputerClipboard(await computer.readClipboard(), text);
558
+ const receipt = await perform({ type: "clipboard", operation: "write", text }, null);
559
+ if (isStaleComputerActionResult(receipt)) return;
560
+ const clipboard = await computer.readClipboard();
561
+ if (isStaleComputerActionResult(receipt) || isStaleComputerActionResult(clipboard)) return;
562
+ assertExactComputerClipboard(clipboard, text);
548
563
  await perform({ type: "clipboard", operation: "paste" }, null);
549
564
  })().catch((cause) => notifyError(cause, "Could not paste into the desktop."));
550
565
  return true;
@@ -750,6 +765,10 @@ export function ComputerViewer({
750
765
  pointerInput={
751
766
  attachmentInputAllowed && computer.session?.capabilities?.pointerInput === true
752
767
  }
768
+ pointerClickContinuation={
769
+ attachmentInputAllowed &&
770
+ computer.session?.capabilities?.pointerClickContinuation === true
771
+ }
753
772
  keyboardInput={
754
773
  attachmentInputAllowed && computer.session?.capabilities?.keyboardInput === true
755
774
  }
@@ -1194,6 +1213,12 @@ function ComputerLifecyclePanel(props: {
1194
1213
  );
1195
1214
  }
1196
1215
 
1216
+ type ComputerQueuedAction = {
1217
+ operationId: string;
1218
+ started: Promise<boolean>;
1219
+ completion: Promise<void>;
1220
+ };
1221
+
1197
1222
  function ComputerViewport(props: {
1198
1223
  frame: ComputerFrame | null;
1199
1224
  observation: ComputerObservation | null;
@@ -1208,8 +1233,13 @@ function ComputerViewport(props: {
1208
1233
  backgroundInput: boolean;
1209
1234
  clipboardEnabled: boolean;
1210
1235
  pointerInput: boolean;
1236
+ pointerClickContinuation: boolean;
1211
1237
  keyboardInput: boolean;
1212
- onAction: (action: ComputerAction, frame: ComputerFrame | null) => Promise<void>;
1238
+ onAction: (
1239
+ action: ComputerAction,
1240
+ frame: ComputerFrame | null,
1241
+ operationId?: string,
1242
+ ) => Promise<ComputerActionReceipt>;
1213
1243
  onReadClipboard: () => Promise<ComputerClipboard>;
1214
1244
  onReconnect: () => void;
1215
1245
  onError: (cause: unknown) => void;
@@ -1224,6 +1254,11 @@ function ComputerViewport(props: {
1224
1254
  x: number;
1225
1255
  y: number;
1226
1256
  frame: ComputerFrame;
1257
+ clientX: number;
1258
+ clientY: number;
1259
+ canvasRect: Pick<DOMRect, "left" | "top" | "width" | "height">;
1260
+ pending: boolean;
1261
+ delivery: ComputerQueuedAction | null;
1227
1262
  } | null>(null);
1228
1263
  const wheelRef = useRef<{
1229
1264
  x: number;
@@ -1394,24 +1429,48 @@ function ComputerViewport(props: {
1394
1429
  action: ComputerAction,
1395
1430
  frame: ComputerFrame | null,
1396
1431
  after?: (isCurrent: () => boolean) => Promise<void>,
1432
+ continuation?: ComputerQueuedAction,
1397
1433
  ) => {
1398
1434
  const epoch = actionQueueEpochRef.current;
1399
1435
  const dispatch = actionRef.current;
1400
1436
  const isCurrent = () => mountedRef.current && epoch === actionQueueEpochRef.current;
1401
- actionTailRef.current = actionTailRef.current
1402
- .catch(() => undefined)
1403
- .then(async () => {
1404
- if (!isCurrent()) return;
1405
- await dispatch(action, frame);
1406
- if (!isCurrent()) return;
1407
- await after?.(isCurrent);
1437
+ const operationId = crypto.randomUUID();
1438
+ let markStarted!: (value: boolean) => void;
1439
+ const started = new Promise<boolean>((resolve) => {
1440
+ markStarted = resolve;
1441
+ });
1442
+ const previous = actionTailRef.current;
1443
+ // Only the real second click may start before its first HTTP receipt.
1444
+ // The controller queue and native causal proof still serialize delivery.
1445
+ const ready =
1446
+ continuation && previous === continuation.completion
1447
+ ? continuation.started
1448
+ : previous.then(() => true);
1449
+ const delivery = ready
1450
+ .then(async (firstStarted) => {
1451
+ if (!firstStarted || !isCurrent()) {
1452
+ markStarted(false);
1453
+ return;
1454
+ }
1455
+ const pending = dispatch(action, frame, operationId);
1456
+ markStarted(true);
1457
+ const receipt = await pending;
1458
+ const isCurrentResult = () => isCurrent() && !isStaleComputerActionResult(receipt);
1459
+ if (!isCurrentResult()) return;
1460
+ await after?.(isCurrentResult);
1408
1461
  })
1409
1462
  .catch((cause) => {
1410
- if (!isCurrent()) return;
1463
+ markStarted(false);
1464
+ if (!isCurrent() || isStaleComputerActionResult(cause)) return;
1411
1465
  actionQueueEpochRef.current += 1;
1412
1466
  clearBufferedInput();
1413
1467
  errorRef.current(cause);
1414
1468
  });
1469
+ const completion = continuation
1470
+ ? Promise.all([previous, delivery]).then(() => undefined)
1471
+ : delivery;
1472
+ actionTailRef.current = completion;
1473
+ return { operationId, started, completion };
1415
1474
  },
1416
1475
  [clearBufferedInput],
1417
1476
  );
@@ -1436,6 +1495,7 @@ function ComputerViewport(props: {
1436
1495
  if (clickTimerRef.current) clearTimeout(clickTimerRef.current);
1437
1496
  clickTimerRef.current = null;
1438
1497
  lastClickRef.current = null;
1498
+ if (!pending.pending) return;
1439
1499
  enqueue(
1440
1500
  {
1441
1501
  type: "pointer",
@@ -1469,7 +1529,13 @@ function ComputerViewport(props: {
1469
1529
 
1470
1530
  const pointerDown = (event: PointerEvent<HTMLCanvasElement>) => {
1471
1531
  const frame = paintedFrameRef.current;
1472
- if (!frame || props.mutating || !rawInputEnabled || event.button !== 0) return;
1532
+ if (
1533
+ !frame ||
1534
+ (!props.pointerClickContinuation && props.mutating) ||
1535
+ !rawInputEnabled ||
1536
+ event.button !== 0
1537
+ )
1538
+ return;
1473
1539
  // Preserve the keyboard sink's focus through the canvas pointer default action.
1474
1540
  event.preventDefault();
1475
1541
  if (keyboardInputEnabled) inputRef.current?.focus({ preventScroll: true });
@@ -1490,6 +1556,7 @@ function ComputerViewport(props: {
1490
1556
  const start = pointerStartRef.current;
1491
1557
  pointerStartRef.current = null;
1492
1558
  if (!start || start.pointerId !== event.pointerId) return;
1559
+ const canvasRect = event.currentTarget.getBoundingClientRect();
1493
1560
  const from = point(start.frame, start.x, start.y);
1494
1561
  const to = point(start.frame, event.clientX, event.clientY);
1495
1562
  if (!from || !to) return;
@@ -1514,8 +1581,18 @@ function ComputerViewport(props: {
1514
1581
  if (
1515
1582
  previous &&
1516
1583
  now - previous.at < 280 &&
1517
- Math.hypot(previous.x - to.x, previous.y - to.y) < 6 &&
1518
- sameFrameFence(previous.frame, start.frame)
1584
+ previous.pending === !props.pointerClickContinuation &&
1585
+ (props.pointerClickContinuation
1586
+ ? Math.hypot(previous.clientX - event.clientX, previous.clientY - event.clientY) < 6 &&
1587
+ previous.canvasRect.left === canvasRect.left &&
1588
+ previous.canvasRect.top === canvasRect.top &&
1589
+ previous.canvasRect.width === canvasRect.width &&
1590
+ previous.canvasRect.height === canvasRect.height &&
1591
+ sameComputerTarget(previous.frame, start.frame) &&
1592
+ previous.frame.width === start.frame.width &&
1593
+ previous.frame.height === start.frame.height
1594
+ : Math.hypot(previous.x - to.x, previous.y - to.y) < 6 &&
1595
+ sameFrameFence(previous.frame, start.frame))
1519
1596
  ) {
1520
1597
  if (clickTimerRef.current) clearTimeout(clickTimerRef.current);
1521
1598
  clickTimerRef.current = null;
@@ -1524,15 +1601,47 @@ function ComputerViewport(props: {
1524
1601
  {
1525
1602
  type: "pointer",
1526
1603
  frameId: start.frame.frameId,
1527
- action: "double_click",
1604
+ action: props.pointerClickContinuation ? "click" : "double_click",
1605
+ ...(props.pointerClickContinuation ? { clickCount: 2 as const } : {}),
1606
+ ...(previous.delivery
1607
+ ? { continuationOfOperationId: previous.delivery.operationId }
1608
+ : {}),
1609
+ x: to.x,
1610
+ y: to.y,
1611
+ },
1612
+ start.frame,
1613
+ undefined,
1614
+ previous.delivery ?? undefined,
1615
+ );
1616
+ return;
1617
+ }
1618
+ flushPendingClick();
1619
+ lastClickRef.current = {
1620
+ at: now,
1621
+ x: to.x,
1622
+ y: to.y,
1623
+ frame: start.frame,
1624
+ clientX: event.clientX,
1625
+ clientY: event.clientY,
1626
+ canvasRect,
1627
+ pending: !props.pointerClickContinuation,
1628
+ delivery: null,
1629
+ };
1630
+ if (props.pointerClickContinuation) {
1631
+ const delivery = enqueue(
1632
+ {
1633
+ type: "pointer",
1634
+ frameId: start.frame.frameId,
1635
+ action: "click",
1636
+ clickCount: 1,
1528
1637
  x: to.x,
1529
1638
  y: to.y,
1530
1639
  },
1531
1640
  start.frame,
1532
1641
  );
1642
+ if (lastClickRef.current) lastClickRef.current.delivery = delivery;
1533
1643
  return;
1534
1644
  }
1535
- lastClickRef.current = { at: now, x: to.x, y: to.y, frame: start.frame };
1536
1645
  clickTimerRef.current = setTimeout(() => {
1537
1646
  clickTimerRef.current = null;
1538
1647
  lastClickRef.current = null;
@@ -215,7 +215,7 @@ export function SessionList({
215
215
  {formatRelativeTime(session.updatedAt)}
216
216
  </span>
217
217
  </button>
218
- <span className="absolute right-1 top-1.5 hidden gap-0.5 group-focus-within:flex group-hover:flex">
218
+ <span className="absolute right-1 top-1.5 hidden gap-0.5 group-focus-within:flex group-hover:flex pointer-coarse:flex">
219
219
  {rename ? (
220
220
  <button
221
221
  type="button"