@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.
- package/README.md +138 -2
- package/dist/artifacts-document.d.ts +3 -0
- package/dist/artifacts-document.js +17 -0
- package/dist/artifacts-document.js.map +1 -0
- package/dist/artifacts-presentation.d.ts +3 -0
- package/dist/artifacts-presentation.js +17 -0
- package/dist/artifacts-presentation.js.map +1 -0
- package/dist/artifacts-spreadsheet.d.ts +3 -0
- package/dist/artifacts-spreadsheet.js +17 -0
- package/dist/artifacts-spreadsheet.js.map +1 -0
- package/dist/artifacts.d.ts +2 -0
- package/dist/artifacts.js +199 -0
- package/dist/artifacts.js.map +1 -0
- package/dist/{chunk-NJ7M2B6Z.js → chunk-5UQPNLIO.js} +16 -8
- package/dist/{chunk-NJ7M2B6Z.js.map → chunk-5UQPNLIO.js.map} +1 -1
- package/dist/{chunk-LHLYWG5R.js → chunk-6KLX2RH5.js} +461 -38
- package/dist/chunk-6KLX2RH5.js.map +1 -0
- package/dist/chunk-7WCLAEFV.js +2828 -0
- package/dist/chunk-7WCLAEFV.js.map +1 -0
- package/dist/{chunk-I4MPFDRP.js → chunk-B6WPZSTT.js} +104 -104
- package/dist/{chunk-I4MPFDRP.js.map → chunk-B6WPZSTT.js.map} +1 -1
- package/dist/{chunk-EKZH6IDG.js → chunk-C5ZPSSS5.js} +111 -1
- package/dist/chunk-C5ZPSSS5.js.map +1 -0
- package/dist/{chunk-OL6QVXGF.js → chunk-HA46CYQK.js} +152 -8
- package/dist/chunk-HA46CYQK.js.map +1 -0
- package/dist/chunk-HUIKIDM5.js +2148 -0
- package/dist/chunk-HUIKIDM5.js.map +1 -0
- package/dist/{chunk-FWXGSNXT.js → chunk-IGC6A2ZI.js} +585 -34
- package/dist/chunk-IGC6A2ZI.js.map +1 -0
- package/dist/chunk-JVYQRRC4.js +53 -0
- package/dist/chunk-JVYQRRC4.js.map +1 -0
- package/dist/chunk-KCGXPP5V.js +157 -0
- package/dist/chunk-KCGXPP5V.js.map +1 -0
- package/dist/chunk-LLOLUHVG.js +5937 -0
- package/dist/chunk-LLOLUHVG.js.map +1 -0
- package/dist/{chunk-WYA65Y3F.js → chunk-MKPIAGVL.js} +13 -3
- package/dist/chunk-MKPIAGVL.js.map +1 -0
- package/dist/chunk-PEI6RANI.js +3234 -0
- package/dist/chunk-PEI6RANI.js.map +1 -0
- package/dist/chunk-R3AZOAB5.js +933 -0
- package/dist/chunk-R3AZOAB5.js.map +1 -0
- package/dist/{chunk-O4VXOBGF.js → chunk-WSK7G5LE.js} +70 -2
- package/dist/chunk-WSK7G5LE.js.map +1 -0
- package/dist/{chunk-23EJ676W.js → chunk-XBZWOM2K.js} +9 -4
- package/dist/chunk-XBZWOM2K.js.map +1 -0
- package/dist/{chunk-XCNTXWBB.js → chunk-Y7OEDUJ5.js} +856 -338
- package/dist/chunk-Y7OEDUJ5.js.map +1 -0
- package/dist/client.d.ts +10 -2
- package/dist/clipboard.d.ts +1 -0
- package/dist/clipboard.js +7 -0
- package/dist/clipboard.js.map +1 -0
- package/dist/commands/index.d.ts +3 -3
- package/dist/commands/registry.d.ts +1 -1
- package/dist/commands/types.d.ts +1 -1
- package/dist/components/approval-surface.d.ts +2 -2
- package/dist/components/artifacts/artifact-surface.d.ts +18 -0
- package/dist/components/artifacts/document-editor.d.ts +172 -0
- package/dist/components/artifacts/editable-artifact-ui.d.ts +13 -0
- package/dist/components/artifacts/editable-artifact-workbench.d.ts +49 -0
- package/dist/components/artifacts/editable-document.d.ts +24 -0
- package/dist/components/artifacts/editable-presentation.d.ts +24 -0
- package/dist/components/artifacts/editable-spreadsheet.d.ts +32 -0
- package/dist/components/artifacts/index.d.ts +9 -0
- package/dist/components/artifacts/presentation-editor.d.ts +297 -0
- package/dist/components/artifacts/published-html-artifact-frame.d.ts +14 -0
- package/dist/components/artifacts/spreadsheet-canvas.d.ts +120 -0
- package/dist/components/artifacts/spreadsheet-grid.d.ts +113 -0
- package/dist/components/browser-input.d.ts +7 -0
- package/dist/components/browser-viewer.d.ts +30 -0
- package/dist/components/chat-composer.d.ts +8 -8
- package/dist/components/code-editor.d.ts +25 -3
- package/dist/components/command-palette.d.ts +2 -2
- package/dist/components/composer-transcription-control.d.ts +2 -2
- package/dist/components/composer.d.ts +17 -17
- package/dist/components/computer-viewer.d.ts +24 -0
- package/dist/components/copy-button.d.ts +2 -2
- package/dist/components/desktop-viewer.d.ts +50 -22
- package/dist/components/diff-view.d.ts +1 -1
- package/dist/components/enrollment-consent.d.ts +1 -1
- package/dist/components/enrollment-device-flow.d.ts +1 -1
- package/dist/components/file-browser.d.ts +2 -2
- package/dist/components/fleet-tile.d.ts +1 -1
- package/dist/components/generated-video-player.d.ts +10 -0
- package/dist/components/human-input-form.d.ts +1 -1
- package/dist/components/human-input-surface.d.ts +2 -2
- package/dist/components/interaction-intervention-banner.d.ts +11 -0
- package/dist/components/interactive-workbench-viewers.d.ts +2 -0
- package/dist/components/machine-card.d.ts +2 -2
- package/dist/components/machine-dock-bar.d.ts +3 -3
- package/dist/components/machine-health-pill.d.ts +2 -2
- package/dist/components/machine-input-display.d.ts +1 -1
- package/dist/components/machine-metrics.d.ts +2 -2
- package/dist/components/machine-status-pill.d.ts +4 -4
- package/dist/components/machines/health.d.ts +1 -1
- package/dist/components/machines/machine-detail.d.ts +3 -3
- package/dist/components/machines/metric-history-chart.d.ts +1 -1
- package/dist/components/machines/metric-sparkline.d.ts +2 -2
- package/dist/components/machines/series.d.ts +2 -2
- package/dist/components/machines-dashboard.d.ts +2 -2
- package/dist/components/markdown.d.ts +1 -1
- package/dist/components/message-timeline.d.ts +12 -5
- package/dist/components/model-picker.d.ts +2 -2
- package/dist/components/model-policy-picker.d.ts +7 -7
- package/dist/components/pierre-diff.d.ts +1 -1
- package/dist/components/pierre-file.d.ts +1 -1
- package/dist/components/queue-draft-policy.d.ts +1 -1
- package/dist/components/queue-surface-implementation.d.ts +3 -3
- package/dist/components/queue-surface-state.d.ts +4 -4
- package/dist/components/queue-surface.d.ts +5 -5
- package/dist/components/sandbox-files.d.ts +3 -3
- package/dist/components/sandbox-terminal.d.ts +24 -4
- package/dist/components/sandbox-workspace.d.ts +28 -9
- package/dist/components/session-chrome.d.ts +4 -4
- package/dist/components/session-status.d.ts +2 -2
- package/dist/components/timeline-annotation-selection.d.ts +9 -0
- package/dist/components/timeline-annotations-dialog.d.ts +16 -0
- package/dist/components/timeline-annotations.d.ts +13 -0
- package/dist/components/tooltip.d.ts +4 -4
- package/dist/components/user-message-body.d.ts +2 -2
- package/dist/components/workbench-changes.d.ts +2 -2
- package/dist/components/workspace-dock.d.ts +1 -1
- package/dist/composer.d.ts +11 -11
- package/dist/composer.js +7 -7
- package/dist/hooks/internal.d.ts +1 -1
- package/dist/hooks/use-attached-browsers.d.ts +21 -0
- package/dist/hooks/use-auth-runs.d.ts +32 -0
- package/dist/hooks/use-available-models.d.ts +2 -2
- package/dist/hooks/use-billing-usage.d.ts +1 -1
- package/dist/hooks/use-browser-downloads.d.ts +25 -0
- package/dist/hooks/use-browser-frame-stream.d.ts +28 -0
- package/dist/hooks/use-browser-identities.d.ts +30 -0
- package/dist/hooks/use-browser-session.d.ts +29 -0
- package/dist/hooks/use-browser-sessions.d.ts +32 -0
- package/dist/hooks/use-channels.d.ts +26 -0
- package/dist/hooks/use-codex-accounts.d.ts +2 -2
- package/dist/hooks/use-composer.d.ts +36 -9
- package/dist/hooks/use-computer-frame-stream.d.ts +24 -0
- package/dist/hooks/use-computer-session.d.ts +29 -0
- package/dist/hooks/use-computer-sessions.d.ts +28 -0
- package/dist/hooks/use-desktop-stream.d.ts +5 -1
- package/dist/hooks/use-environments.d.ts +1 -1
- package/dist/hooks/use-file-attachments.d.ts +1 -1
- package/dist/hooks/use-goal.d.ts +2 -2
- package/dist/hooks/use-human-input.d.ts +2 -2
- package/dist/hooks/use-interaction-interventions.d.ts +27 -0
- package/dist/hooks/use-interaction-invalidation.d.ts +19 -0
- package/dist/hooks/use-last-started-turn-policy.d.ts +2 -2
- package/dist/hooks/use-machine-chip.d.ts +2 -2
- package/dist/hooks/use-machines.d.ts +4 -4
- package/dist/hooks/use-network-routes.d.ts +25 -0
- package/dist/hooks/use-packs.d.ts +7 -2
- package/dist/hooks/use-rigs.d.ts +1 -1
- package/dist/hooks/use-sandbox-files.d.ts +6 -4
- package/dist/hooks/use-sandbox-git.d.ts +6 -5
- package/dist/hooks/use-sandbox-terminal.d.ts +1 -1
- package/dist/hooks/use-scheduled-tasks.d.ts +1 -1
- package/dist/hooks/use-session-capabilities.d.ts +5 -4
- package/dist/hooks/use-session-control.d.ts +1 -1
- package/dist/hooks/use-session-events.d.ts +2 -2
- package/dist/hooks/use-session-lineage.d.ts +1 -1
- package/dist/hooks/use-session-mcp-approval-policy.d.ts +2 -2
- package/dist/hooks/use-session.d.ts +2 -2
- package/dist/hooks/use-site-auth-connections.d.ts +25 -0
- package/dist/hooks/use-slash-commands.d.ts +1 -1
- package/dist/hooks/use-supergrok-accounts.d.ts +26 -0
- package/dist/hooks/use-terminal-stream.d.ts +11 -2
- package/dist/hooks/use-turn-queue.d.ts +2 -2
- package/dist/hooks/use-video-artifact-playback.d.ts +9 -0
- package/dist/hooks/use-voice-input.d.ts +1 -1
- package/dist/hooks/use-workspace-capture.d.ts +1 -1
- package/dist/hooks/use-workspace-edit.d.ts +1 -1
- package/dist/hooks/use-workspace-sessions.d.ts +1 -1
- package/dist/hooks/use-workspaces.d.ts +1 -1
- package/dist/index.d.ts +162 -155
- package/dist/index.js +1822 -1703
- package/dist/index.js.map +1 -1
- package/dist/interaction.d.ts +33 -0
- package/dist/interaction.js +550 -0
- package/dist/interaction.js.map +1 -0
- package/dist/interactive-workbench-viewers-TOHBXJEE.js +15 -0
- package/dist/interactive-workbench-viewers-TOHBXJEE.js.map +1 -0
- package/dist/lib/host-platform.d.ts +5 -0
- package/dist/lib/relay-wire.d.ts +24 -1
- package/dist/lib/sandbox-liveness.d.ts +9 -0
- package/dist/lib/terminal-capability.d.ts +5 -0
- package/dist/lib/xterm-theme.d.ts +1 -1
- package/dist/machines.d.ts +30 -30
- package/dist/machines.js +2 -2
- package/dist/model-policy.d.ts +1 -1
- package/dist/model-policy.js +1 -1
- package/dist/provider.d.ts +6 -5
- package/dist/{queue-surface-implementation-U5JFG7HT.js → queue-surface-implementation-2KVJTYXH.js} +100 -48
- package/dist/queue-surface-implementation-2KVJTYXH.js.map +1 -0
- package/dist/realtime/dropdown-menu.d.ts +8 -8
- package/dist/realtime/realtime-control.d.ts +8 -8
- package/dist/realtime.d.ts +4 -4
- package/dist/realtime.js +38 -11
- package/dist/realtime.js.map +1 -1
- package/dist/session-context.d.ts +28 -2
- package/dist/session-ui.d.ts +14 -14
- package/dist/session-ui.js +5 -4
- package/dist/session.d.ts +28 -28
- package/dist/session.js +10 -10
- package/dist/timeline/activity-rail.d.ts +5 -3
- package/dist/timeline/disclosure-context.d.ts +1 -1
- package/dist/timeline/fleet-decision-projection.d.ts +1 -1
- package/dist/timeline/fleet-decision-row.d.ts +3 -3
- package/dist/timeline/index.d.ts +19 -19
- package/dist/timeline/parsers.d.ts +4 -1
- package/dist/timeline/projection.d.ts +3 -3
- package/dist/timeline/registry.d.ts +8 -2
- package/dist/timeline/screenshot-lightbox.d.ts +2 -2
- package/dist/timeline/shared.d.ts +21 -10
- package/dist/timeline/tool-diff.d.ts +2 -2
- package/dist/timeline/tool-renderers.d.ts +1 -1
- package/dist/timeline/turn-summary.d.ts +3 -3
- package/dist/timeline/types.d.ts +44 -3
- package/dist/timeline-annotation-selection-3L7LHGG2.js +187 -0
- package/dist/timeline-annotation-selection-3L7LHGG2.js.map +1 -0
- package/dist/timeline-annotations-dialog-U7EVLR75.js +196 -0
- package/dist/timeline-annotations-dialog-U7EVLR75.js.map +1 -0
- package/package.json +36 -7
- package/src/artifacts-document.ts +31 -0
- package/src/artifacts-presentation.ts +36 -0
- package/src/artifacts-spreadsheet.ts +21 -0
- package/src/artifacts.ts +89 -0
- package/src/client.ts +157 -1
- package/src/clipboard.ts +2 -0
- package/src/components/artifacts/artifact-surface.tsx +93 -0
- package/src/components/artifacts/document-editor.tsx +2255 -0
- package/src/components/artifacts/editable-artifact-ui.tsx +89 -0
- package/src/components/artifacts/editable-artifact-workbench.tsx +203 -0
- package/src/components/artifacts/editable-document.tsx +657 -0
- package/src/components/artifacts/editable-presentation.tsx +1020 -0
- package/src/components/artifacts/editable-spreadsheet.tsx +733 -0
- package/src/components/artifacts/index.ts +104 -0
- package/src/components/artifacts/presentation-editor.tsx +3148 -0
- package/src/components/artifacts/published-html-artifact-frame.tsx +38 -0
- package/src/components/artifacts/spreadsheet-canvas.ts +799 -0
- package/src/components/artifacts/spreadsheet-grid.tsx +2129 -0
- package/src/components/browser-input.ts +65 -0
- package/src/components/browser-viewer.tsx +2702 -0
- package/src/components/chat-composer.tsx +13 -0
- package/src/components/code-editor.tsx +89 -30
- package/src/components/composer-transcription-control.tsx +10 -6
- package/src/components/computer-viewer.tsx +1636 -0
- package/src/components/desktop-viewer.tsx +215 -74
- package/src/components/generated-video-player.tsx +89 -0
- package/src/components/interaction-intervention-banner.tsx +99 -0
- package/src/components/interactive-workbench-viewers.ts +2 -0
- package/src/components/machine-input-display.ts +3 -0
- package/src/components/machines/machine-detail.tsx +1 -1
- package/src/components/message-timeline.tsx +289 -32
- package/src/components/model-policy-picker.tsx +15 -0
- package/src/components/queue-surface-implementation.tsx +116 -60
- package/src/components/sandbox-files.tsx +2 -2
- package/src/components/sandbox-terminal.tsx +128 -46
- package/src/components/sandbox-workspace.tsx +256 -90
- package/src/components/session-chrome.tsx +53 -13
- package/src/components/timeline-annotation-selection.tsx +221 -0
- package/src/components/timeline-annotations-dialog.tsx +213 -0
- package/src/components/timeline-annotations.tsx +84 -0
- package/src/components/workbench-changes.tsx +188 -31
- package/src/components/workspace-dock.tsx +59 -5
- package/src/hooks/use-attached-browsers.ts +154 -0
- package/src/hooks/use-auth-runs.ts +278 -0
- package/src/hooks/use-browser-downloads.ts +218 -0
- package/src/hooks/use-browser-frame-stream.ts +425 -0
- package/src/hooks/use-browser-identities.ts +266 -0
- package/src/hooks/use-browser-session.ts +543 -0
- package/src/hooks/use-browser-sessions.ts +286 -0
- package/src/hooks/use-channels.ts +99 -0
- package/src/hooks/use-composer.ts +769 -24
- package/src/hooks/use-computer-frame-stream.ts +434 -0
- package/src/hooks/use-computer-session.ts +462 -0
- package/src/hooks/use-computer-sessions.ts +251 -0
- package/src/hooks/use-desktop-stream.ts +39 -7
- package/src/hooks/use-interaction-interventions.ts +242 -0
- package/src/hooks/use-interaction-invalidation.ts +66 -0
- package/src/hooks/use-machine-chip.ts +15 -3
- package/src/hooks/use-machines.ts +33 -3
- package/src/hooks/use-network-routes.ts +214 -0
- package/src/hooks/use-packs.ts +51 -0
- package/src/hooks/use-sandbox-files.ts +98 -55
- package/src/hooks/use-sandbox-git.ts +93 -38
- package/src/hooks/use-sandbox-terminal.ts +3 -2
- package/src/hooks/use-session-capabilities.ts +59 -46
- package/src/hooks/use-site-auth-connections.ts +226 -0
- package/src/hooks/use-supergrok-accounts.ts +81 -0
- package/src/hooks/use-terminal-stream.ts +359 -47
- package/src/hooks/use-video-artifact-playback.ts +28 -0
- package/src/hooks/use-workspace-edit.ts +2 -1
- package/src/index.ts +18 -0
- package/src/interaction.ts +101 -0
- package/src/lib/host-platform.ts +10 -0
- package/src/lib/relay-wire.ts +47 -4
- package/src/lib/sandbox-liveness.ts +11 -0
- package/src/lib/terminal-capability.ts +10 -0
- package/src/model-policy.ts +19 -4
- package/src/provider.tsx +133 -1
- package/src/realtime/realtime-control.tsx +34 -6
- package/src/session-context.ts +156 -1
- package/src/timeline/activity-rail.tsx +25 -3
- package/src/timeline/index.ts +3 -0
- package/src/timeline/parsers.ts +14 -1
- package/src/timeline/projection.ts +269 -14
- package/src/timeline/registry.ts +13 -1
- package/src/timeline/screenshot-lightbox.tsx +19 -9
- package/src/timeline/shared.tsx +56 -8
- package/src/timeline/tool-renderers.tsx +303 -50
- package/src/timeline/types.ts +57 -3
- package/styles/compiled.css +312 -21
- package/styles/index.css +15 -0
- package/styles/responsive.css +13 -1
- package/dist/chunk-23EJ676W.js.map +0 -1
- package/dist/chunk-EKZH6IDG.js.map +0 -1
- package/dist/chunk-FWXGSNXT.js.map +0 -1
- package/dist/chunk-LHLYWG5R.js.map +0 -1
- package/dist/chunk-O4VXOBGF.js.map +0 -1
- package/dist/chunk-OL6QVXGF.js.map +0 -1
- package/dist/chunk-WYA65Y3F.js.map +0 -1
- package/dist/chunk-XCNTXWBB.js.map +0 -1
- package/dist/fleet-decision-projection-SLNZMS42.js +0 -241
- package/dist/fleet-decision-projection-SLNZMS42.js.map +0 -1
- package/dist/queue-surface-implementation-U5JFG7HT.js.map +0 -1
|
@@ -0,0 +1,543 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
BrowserAction,
|
|
3
|
+
BrowserActionBatch,
|
|
4
|
+
BrowserActionReceipt,
|
|
5
|
+
BrowserClipboard,
|
|
6
|
+
BrowserDiagnosticBatch,
|
|
7
|
+
BrowserDiagnosticsOptions,
|
|
8
|
+
BrowserFrame,
|
|
9
|
+
BrowserObservation,
|
|
10
|
+
BrowserSession,
|
|
11
|
+
BrowserTarget,
|
|
12
|
+
} from "@opengeni/sdk/interaction";
|
|
13
|
+
import { OpenGeniApiError } from "@opengeni/sdk";
|
|
14
|
+
import { useCallback, useEffect, useRef, useState } from "react";
|
|
15
|
+
import {
|
|
16
|
+
type EmbeddedBrowserInteractionClientOverride,
|
|
17
|
+
useEmbeddedBrowserInteraction,
|
|
18
|
+
} from "../session-context";
|
|
19
|
+
import { usePageLiveActivity } from "./internal";
|
|
20
|
+
|
|
21
|
+
export type UseBrowserSessionOptions = EmbeddedBrowserInteractionClientOverride & {
|
|
22
|
+
browserSessionId: string | null;
|
|
23
|
+
enabled?: boolean | undefined;
|
|
24
|
+
pollIntervalMs?: number | undefined;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export type UseBrowserSessionResult = {
|
|
28
|
+
session: BrowserSession | null;
|
|
29
|
+
targets: BrowserTarget[];
|
|
30
|
+
selectedTarget: BrowserTarget | null;
|
|
31
|
+
observation: BrowserObservation | null;
|
|
32
|
+
loading: boolean;
|
|
33
|
+
mutating: boolean;
|
|
34
|
+
error: Error | null;
|
|
35
|
+
refresh: () => Promise<void>;
|
|
36
|
+
selectTarget: (targetId: string) => Promise<BrowserTarget>;
|
|
37
|
+
openTarget: (url?: string) => Promise<BrowserTarget>;
|
|
38
|
+
closeTarget: (targetId: string) => Promise<void>;
|
|
39
|
+
act: (
|
|
40
|
+
action: BrowserAction | BrowserActionBatch,
|
|
41
|
+
operationId?: string,
|
|
42
|
+
) => Promise<BrowserActionReceipt>;
|
|
43
|
+
/** Dispatch input against the exact image a human saw. Stale images fail at
|
|
44
|
+
* the controller fence instead of targeting a newer page. */
|
|
45
|
+
actFromFrame: (
|
|
46
|
+
action: BrowserAction | BrowserActionBatch,
|
|
47
|
+
frame: BrowserFrame,
|
|
48
|
+
operationId?: string,
|
|
49
|
+
) => Promise<BrowserActionReceipt>;
|
|
50
|
+
readClipboard: () => Promise<BrowserClipboard>;
|
|
51
|
+
diagnostics: (options?: BrowserDiagnosticsOptions) => Promise<BrowserDiagnosticBatch>;
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
/** Selected BrowserSession control state. All human actions use the same
|
|
55
|
+
* generation-fenced controller operation stream as agent actions. */
|
|
56
|
+
export function useBrowserSession(options: UseBrowserSessionOptions): UseBrowserSessionResult {
|
|
57
|
+
const { client, workspaceId } = useEmbeddedBrowserInteraction(options);
|
|
58
|
+
const browserSessionId = options.browserSessionId;
|
|
59
|
+
const enabled = (options.enabled ?? true) && browserSessionId !== null;
|
|
60
|
+
const pageLive = usePageLiveActivity();
|
|
61
|
+
const pollIntervalMs = Math.max(750, options.pollIntervalMs ?? 2_000);
|
|
62
|
+
const [state, setState] = useState<{
|
|
63
|
+
browserSessionId: string | null;
|
|
64
|
+
session: BrowserSession | null;
|
|
65
|
+
targets: BrowserTarget[];
|
|
66
|
+
selectedTargetId: string | null;
|
|
67
|
+
observation: BrowserObservation | null;
|
|
68
|
+
loading: boolean;
|
|
69
|
+
mutating: boolean;
|
|
70
|
+
error: Error | null;
|
|
71
|
+
}>(() => emptyState(browserSessionId, enabled));
|
|
72
|
+
const visible =
|
|
73
|
+
state.browserSessionId === browserSessionId ? state : emptyState(browserSessionId, enabled);
|
|
74
|
+
const selectedTargetIdRef = useRef<string | null>(visible.selectedTargetId);
|
|
75
|
+
selectedTargetIdRef.current = visible.selectedTargetId;
|
|
76
|
+
const observationRef = useRef<{
|
|
77
|
+
browserSessionId: string | null;
|
|
78
|
+
observation: BrowserObservation | null;
|
|
79
|
+
}>({ browserSessionId, observation: visible.observation });
|
|
80
|
+
if (observationRef.current.browserSessionId !== browserSessionId) {
|
|
81
|
+
observationRef.current = {
|
|
82
|
+
browserSessionId,
|
|
83
|
+
observation: visible.observation,
|
|
84
|
+
};
|
|
85
|
+
} else {
|
|
86
|
+
observationRef.current.observation = visible.observation;
|
|
87
|
+
}
|
|
88
|
+
const requestRef = useRef<{ id: number; controller: AbortController | null }>({
|
|
89
|
+
id: 0,
|
|
90
|
+
controller: null,
|
|
91
|
+
});
|
|
92
|
+
const mutationRef = useRef<{
|
|
93
|
+
browserSessionId: string | null;
|
|
94
|
+
count: number;
|
|
95
|
+
}>({
|
|
96
|
+
browserSessionId,
|
|
97
|
+
count: 0,
|
|
98
|
+
});
|
|
99
|
+
const mountedRef = useRef(true);
|
|
100
|
+
|
|
101
|
+
const invalidateRefresh = useCallback(() => {
|
|
102
|
+
const id = requestRef.current.id + 1;
|
|
103
|
+
requestRef.current.controller?.abort();
|
|
104
|
+
requestRef.current = { id, controller: null };
|
|
105
|
+
}, []);
|
|
106
|
+
|
|
107
|
+
const refresh = useCallback(async (): Promise<void> => {
|
|
108
|
+
if (!enabled || !browserSessionId) return;
|
|
109
|
+
const id = requestRef.current.id + 1;
|
|
110
|
+
requestRef.current.controller?.abort();
|
|
111
|
+
const controller = new AbortController();
|
|
112
|
+
requestRef.current = { id, controller };
|
|
113
|
+
try {
|
|
114
|
+
const [session, targetResponse] = await Promise.all([
|
|
115
|
+
client.getBrowserSession(workspaceId, browserSessionId, {
|
|
116
|
+
signal: controller.signal,
|
|
117
|
+
}),
|
|
118
|
+
client.listBrowserTargets(workspaceId, browserSessionId, {
|
|
119
|
+
signal: controller.signal,
|
|
120
|
+
}),
|
|
121
|
+
]);
|
|
122
|
+
if (!mountedRef.current || requestRef.current.id !== id) return;
|
|
123
|
+
const selected = chooseTarget(targetResponse.targets, selectedTargetIdRef.current);
|
|
124
|
+
selectedTargetIdRef.current = selected?.id ?? null;
|
|
125
|
+
observationRef.current = { browserSessionId, observation: null };
|
|
126
|
+
setState((current) =>
|
|
127
|
+
current.browserSessionId === browserSessionId
|
|
128
|
+
? {
|
|
129
|
+
...current,
|
|
130
|
+
session,
|
|
131
|
+
targets: targetResponse.targets,
|
|
132
|
+
selectedTargetId: selected?.id ?? null,
|
|
133
|
+
observation: null,
|
|
134
|
+
loading: false,
|
|
135
|
+
error: null,
|
|
136
|
+
}
|
|
137
|
+
: current,
|
|
138
|
+
);
|
|
139
|
+
if (!selected) return;
|
|
140
|
+
try {
|
|
141
|
+
const observation = await client.observeBrowserTarget(
|
|
142
|
+
workspaceId,
|
|
143
|
+
browserSessionId,
|
|
144
|
+
selected.id,
|
|
145
|
+
{ signal: controller.signal },
|
|
146
|
+
);
|
|
147
|
+
if (!mountedRef.current || requestRef.current.id !== id) return;
|
|
148
|
+
observationRef.current = { browserSessionId, observation };
|
|
149
|
+
setState((current) =>
|
|
150
|
+
current.browserSessionId === browserSessionId &&
|
|
151
|
+
current.selectedTargetId === observation.target.id
|
|
152
|
+
? { ...current, observation }
|
|
153
|
+
: current,
|
|
154
|
+
);
|
|
155
|
+
} catch (cause) {
|
|
156
|
+
if (controller.signal.aborted || !mountedRef.current || requestRef.current.id !== id)
|
|
157
|
+
return;
|
|
158
|
+
// Target inventory and the media plane remain authoritative for the
|
|
159
|
+
// human-facing browser. A failed semantic snapshot must not blank or
|
|
160
|
+
// disable an otherwise live visual browser.
|
|
161
|
+
void cause;
|
|
162
|
+
}
|
|
163
|
+
} catch (cause) {
|
|
164
|
+
if (controller.signal.aborted || !mountedRef.current || requestRef.current.id !== id) return;
|
|
165
|
+
setState((current) =>
|
|
166
|
+
current.browserSessionId === browserSessionId
|
|
167
|
+
? {
|
|
168
|
+
...current,
|
|
169
|
+
loading: false,
|
|
170
|
+
error: cause instanceof Error ? cause : new Error(String(cause)),
|
|
171
|
+
}
|
|
172
|
+
: current,
|
|
173
|
+
);
|
|
174
|
+
} finally {
|
|
175
|
+
if (requestRef.current.id === id) {
|
|
176
|
+
requestRef.current = { id, controller: null };
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}, [browserSessionId, client, enabled, workspaceId]);
|
|
180
|
+
|
|
181
|
+
useEffect(() => {
|
|
182
|
+
mountedRef.current = true;
|
|
183
|
+
if (!enabled) {
|
|
184
|
+
invalidateRefresh();
|
|
185
|
+
setState(emptyState(browserSessionId, false));
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
setState((current) =>
|
|
189
|
+
current.browserSessionId === browserSessionId
|
|
190
|
+
? { ...current, loading: true }
|
|
191
|
+
: emptyState(browserSessionId, true),
|
|
192
|
+
);
|
|
193
|
+
void refresh();
|
|
194
|
+
return () => {
|
|
195
|
+
mountedRef.current = false;
|
|
196
|
+
invalidateRefresh();
|
|
197
|
+
};
|
|
198
|
+
}, [browserSessionId, enabled, invalidateRefresh, refresh]);
|
|
199
|
+
|
|
200
|
+
useEffect(() => {
|
|
201
|
+
if (!enabled || !pageLive || visible.mutating) return;
|
|
202
|
+
const timer = setInterval(() => {
|
|
203
|
+
if (!requestRef.current.controller) void refresh();
|
|
204
|
+
}, pollIntervalMs);
|
|
205
|
+
return () => clearInterval(timer);
|
|
206
|
+
}, [enabled, pageLive, pollIntervalMs, refresh, visible.mutating]);
|
|
207
|
+
|
|
208
|
+
useEffect(() => {
|
|
209
|
+
if (!enabled || !browserSessionId || !pageLive) return;
|
|
210
|
+
let disposed = false;
|
|
211
|
+
const heartbeat = () => {
|
|
212
|
+
void client.heartbeatBrowserSession(workspaceId, browserSessionId).catch(() => {
|
|
213
|
+
if (!disposed) void refresh();
|
|
214
|
+
});
|
|
215
|
+
};
|
|
216
|
+
const timer = setInterval(heartbeat, 30_000);
|
|
217
|
+
return () => {
|
|
218
|
+
disposed = true;
|
|
219
|
+
clearInterval(timer);
|
|
220
|
+
};
|
|
221
|
+
}, [browserSessionId, client, enabled, pageLive, refresh, workspaceId]);
|
|
222
|
+
|
|
223
|
+
const runMutation = useCallback(
|
|
224
|
+
async <T>(scopeBrowserSessionId: string, operation: () => Promise<T>): Promise<T> => {
|
|
225
|
+
invalidateRefresh();
|
|
226
|
+
if (mutationRef.current.browserSessionId !== scopeBrowserSessionId) {
|
|
227
|
+
mutationRef.current = {
|
|
228
|
+
browserSessionId: scopeBrowserSessionId,
|
|
229
|
+
count: 0,
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
mutationRef.current.count += 1;
|
|
233
|
+
setState((current) =>
|
|
234
|
+
current.browserSessionId === scopeBrowserSessionId
|
|
235
|
+
? { ...current, mutating: true, error: null }
|
|
236
|
+
: current,
|
|
237
|
+
);
|
|
238
|
+
try {
|
|
239
|
+
return await operation();
|
|
240
|
+
} catch (cause) {
|
|
241
|
+
const error = cause instanceof Error ? cause : new Error(String(cause));
|
|
242
|
+
setState((current) =>
|
|
243
|
+
current.browserSessionId === scopeBrowserSessionId ? { ...current, error } : current,
|
|
244
|
+
);
|
|
245
|
+
throw error;
|
|
246
|
+
} finally {
|
|
247
|
+
if (mutationRef.current.browserSessionId === scopeBrowserSessionId) {
|
|
248
|
+
mutationRef.current.count = Math.max(0, mutationRef.current.count - 1);
|
|
249
|
+
const mutating = mutationRef.current.count > 0;
|
|
250
|
+
setState((current) =>
|
|
251
|
+
current.browserSessionId === scopeBrowserSessionId ? { ...current, mutating } : current,
|
|
252
|
+
);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
},
|
|
256
|
+
[invalidateRefresh],
|
|
257
|
+
);
|
|
258
|
+
|
|
259
|
+
const selectTarget = useCallback(
|
|
260
|
+
async (targetId: string): Promise<BrowserTarget> => {
|
|
261
|
+
if (!browserSessionId) throw new Error("No BrowserSession is selected.");
|
|
262
|
+
return await runMutation(browserSessionId, async () => {
|
|
263
|
+
let targets = visible.targets;
|
|
264
|
+
let target: BrowserTarget;
|
|
265
|
+
let observation: BrowserObservation;
|
|
266
|
+
try {
|
|
267
|
+
observation = await client.selectBrowserTarget(workspaceId, browserSessionId, targetId);
|
|
268
|
+
target = observation.target;
|
|
269
|
+
} catch (cause) {
|
|
270
|
+
if (!isMissingBrowserTarget(cause)) throw cause;
|
|
271
|
+
// A physical/attached tab may disappear between inventory and click.
|
|
272
|
+
// Reconcile once from the authoritative controller inventory and move
|
|
273
|
+
// to its live selected/first page instead of leaving a dead tab ID in
|
|
274
|
+
// React state. Session-level 404s are deliberately not swallowed.
|
|
275
|
+
const response = await client.listBrowserTargets(workspaceId, browserSessionId);
|
|
276
|
+
targets = response.targets;
|
|
277
|
+
const fallback = chooseTarget(targets, null);
|
|
278
|
+
if (!fallback) {
|
|
279
|
+
selectedTargetIdRef.current = null;
|
|
280
|
+
observationRef.current = { browserSessionId, observation: null };
|
|
281
|
+
setState((current) =>
|
|
282
|
+
current.browserSessionId === browserSessionId
|
|
283
|
+
? {
|
|
284
|
+
...current,
|
|
285
|
+
targets,
|
|
286
|
+
selectedTargetId: null,
|
|
287
|
+
observation: null,
|
|
288
|
+
}
|
|
289
|
+
: current,
|
|
290
|
+
);
|
|
291
|
+
throw cause;
|
|
292
|
+
}
|
|
293
|
+
observation = await client.selectBrowserTarget(
|
|
294
|
+
workspaceId,
|
|
295
|
+
browserSessionId,
|
|
296
|
+
fallback.id,
|
|
297
|
+
);
|
|
298
|
+
target = observation.target;
|
|
299
|
+
}
|
|
300
|
+
selectedTargetIdRef.current = target.id;
|
|
301
|
+
observationRef.current = { browserSessionId, observation };
|
|
302
|
+
setState((current) =>
|
|
303
|
+
current.browserSessionId === browserSessionId
|
|
304
|
+
? {
|
|
305
|
+
...current,
|
|
306
|
+
targets: targets.map((candidate) => ({
|
|
307
|
+
...candidate,
|
|
308
|
+
selected: candidate.id === target.id,
|
|
309
|
+
})),
|
|
310
|
+
selectedTargetId: target.id,
|
|
311
|
+
observation,
|
|
312
|
+
}
|
|
313
|
+
: current,
|
|
314
|
+
);
|
|
315
|
+
return target;
|
|
316
|
+
});
|
|
317
|
+
},
|
|
318
|
+
[browserSessionId, client, runMutation, visible.targets, workspaceId],
|
|
319
|
+
);
|
|
320
|
+
|
|
321
|
+
const openTarget = useCallback(
|
|
322
|
+
async (url?: string): Promise<BrowserTarget> => {
|
|
323
|
+
if (!browserSessionId) throw new Error("No BrowserSession is selected.");
|
|
324
|
+
return await runMutation(browserSessionId, async () => {
|
|
325
|
+
const observation = await client.openBrowserTarget(
|
|
326
|
+
workspaceId,
|
|
327
|
+
browserSessionId,
|
|
328
|
+
url === undefined ? {} : { url },
|
|
329
|
+
);
|
|
330
|
+
const target = observation.target;
|
|
331
|
+
selectedTargetIdRef.current = target.id;
|
|
332
|
+
observationRef.current = { browserSessionId, observation };
|
|
333
|
+
setState((current) =>
|
|
334
|
+
current.browserSessionId === browserSessionId
|
|
335
|
+
? {
|
|
336
|
+
...current,
|
|
337
|
+
targets: [
|
|
338
|
+
...current.targets.map((candidate) => ({
|
|
339
|
+
...candidate,
|
|
340
|
+
selected: false,
|
|
341
|
+
})),
|
|
342
|
+
target,
|
|
343
|
+
],
|
|
344
|
+
selectedTargetId: target.id,
|
|
345
|
+
observation,
|
|
346
|
+
}
|
|
347
|
+
: current,
|
|
348
|
+
);
|
|
349
|
+
return target;
|
|
350
|
+
});
|
|
351
|
+
},
|
|
352
|
+
[browserSessionId, client, runMutation, workspaceId],
|
|
353
|
+
);
|
|
354
|
+
|
|
355
|
+
const closeTarget = useCallback(
|
|
356
|
+
async (targetId: string): Promise<void> => {
|
|
357
|
+
if (!browserSessionId) throw new Error("No BrowserSession is selected.");
|
|
358
|
+
await runMutation(browserSessionId, async () => {
|
|
359
|
+
const response = await client.closeBrowserTarget(workspaceId, browserSessionId, targetId);
|
|
360
|
+
const selected = chooseTarget(response.targets, null);
|
|
361
|
+
const observation = selected
|
|
362
|
+
? await client.observeBrowserTarget(workspaceId, browserSessionId, selected.id)
|
|
363
|
+
: null;
|
|
364
|
+
selectedTargetIdRef.current = selected?.id ?? null;
|
|
365
|
+
observationRef.current = { browserSessionId, observation };
|
|
366
|
+
setState((current) =>
|
|
367
|
+
current.browserSessionId === browserSessionId
|
|
368
|
+
? {
|
|
369
|
+
...current,
|
|
370
|
+
targets: response.targets,
|
|
371
|
+
selectedTargetId: selected?.id ?? null,
|
|
372
|
+
observation,
|
|
373
|
+
}
|
|
374
|
+
: current,
|
|
375
|
+
);
|
|
376
|
+
});
|
|
377
|
+
},
|
|
378
|
+
[browserSessionId, client, runMutation, workspaceId],
|
|
379
|
+
);
|
|
380
|
+
|
|
381
|
+
const dispatchAction = useCallback(
|
|
382
|
+
async (
|
|
383
|
+
action: BrowserAction | BrowserActionBatch,
|
|
384
|
+
operationId: string,
|
|
385
|
+
frame: BrowserFrame | null,
|
|
386
|
+
): Promise<BrowserActionReceipt> => {
|
|
387
|
+
if (!browserSessionId) throw new Error("No BrowserSession is selected.");
|
|
388
|
+
if (frame && frame.browserSessionId !== browserSessionId) {
|
|
389
|
+
throw new Error("The displayed browser frame belongs to another BrowserSession.");
|
|
390
|
+
}
|
|
391
|
+
const currentObservation =
|
|
392
|
+
observationRef.current.browserSessionId === browserSessionId
|
|
393
|
+
? observationRef.current.observation
|
|
394
|
+
: null;
|
|
395
|
+
const fence = frame
|
|
396
|
+
? {
|
|
397
|
+
targetId: frame.targetId,
|
|
398
|
+
expectedTargetGeneration: frame.targetGeneration,
|
|
399
|
+
expectedDocumentGeneration: frame.documentGeneration,
|
|
400
|
+
expectedFrameId: frame.frameId,
|
|
401
|
+
}
|
|
402
|
+
: currentObservation
|
|
403
|
+
? {
|
|
404
|
+
targetId: currentObservation.target.id,
|
|
405
|
+
expectedTargetGeneration: currentObservation.target.targetGeneration,
|
|
406
|
+
expectedDocumentGeneration: currentObservation.target.documentGeneration,
|
|
407
|
+
expectedFrameId: currentObservation.frameId,
|
|
408
|
+
}
|
|
409
|
+
: null;
|
|
410
|
+
if (!fence) {
|
|
411
|
+
throw new Error("The browser page is not ready for input.");
|
|
412
|
+
}
|
|
413
|
+
try {
|
|
414
|
+
const receipt = await client.actInBrowser(workspaceId, browserSessionId, {
|
|
415
|
+
operationId,
|
|
416
|
+
...fence,
|
|
417
|
+
observationMode: "none",
|
|
418
|
+
action,
|
|
419
|
+
});
|
|
420
|
+
if (receipt.observation) {
|
|
421
|
+
observationRef.current = {
|
|
422
|
+
browserSessionId,
|
|
423
|
+
observation: receipt.observation,
|
|
424
|
+
};
|
|
425
|
+
setState((current) =>
|
|
426
|
+
current.browserSessionId === browserSessionId
|
|
427
|
+
? {
|
|
428
|
+
...current,
|
|
429
|
+
observation: receipt.observation,
|
|
430
|
+
targets: replaceTarget(current.targets, receipt.observation!.target),
|
|
431
|
+
}
|
|
432
|
+
: current,
|
|
433
|
+
);
|
|
434
|
+
}
|
|
435
|
+
return receipt;
|
|
436
|
+
} catch (cause) {
|
|
437
|
+
const error = cause instanceof Error ? cause : new Error(String(cause));
|
|
438
|
+
setState((current) =>
|
|
439
|
+
current.browserSessionId === browserSessionId ? { ...current, error } : current,
|
|
440
|
+
);
|
|
441
|
+
throw error;
|
|
442
|
+
}
|
|
443
|
+
},
|
|
444
|
+
[browserSessionId, client, workspaceId],
|
|
445
|
+
);
|
|
446
|
+
|
|
447
|
+
const act = useCallback(
|
|
448
|
+
async (
|
|
449
|
+
action: BrowserAction | BrowserActionBatch,
|
|
450
|
+
operationId: string = crypto.randomUUID(),
|
|
451
|
+
): Promise<BrowserActionReceipt> => await dispatchAction(action, operationId, null),
|
|
452
|
+
[dispatchAction],
|
|
453
|
+
);
|
|
454
|
+
|
|
455
|
+
const actFromFrame = useCallback(
|
|
456
|
+
async (
|
|
457
|
+
action: BrowserAction | BrowserActionBatch,
|
|
458
|
+
frame: BrowserFrame,
|
|
459
|
+
operationId: string = crypto.randomUUID(),
|
|
460
|
+
): Promise<BrowserActionReceipt> => await dispatchAction(action, operationId, frame),
|
|
461
|
+
[dispatchAction],
|
|
462
|
+
);
|
|
463
|
+
|
|
464
|
+
const diagnostics = useCallback(
|
|
465
|
+
async (diagnosticOptions: BrowserDiagnosticsOptions = {}): Promise<BrowserDiagnosticBatch> => {
|
|
466
|
+
const targetId = selectedTargetIdRef.current;
|
|
467
|
+
if (!browserSessionId || !targetId) {
|
|
468
|
+
throw new Error("No browser tab is selected.");
|
|
469
|
+
}
|
|
470
|
+
return await client.listBrowserDiagnostics(
|
|
471
|
+
workspaceId,
|
|
472
|
+
browserSessionId,
|
|
473
|
+
targetId,
|
|
474
|
+
diagnosticOptions,
|
|
475
|
+
);
|
|
476
|
+
},
|
|
477
|
+
[browserSessionId, client, workspaceId],
|
|
478
|
+
);
|
|
479
|
+
|
|
480
|
+
const readClipboard = useCallback(async (): Promise<BrowserClipboard> => {
|
|
481
|
+
if (!browserSessionId) throw new Error("No BrowserSession is selected.");
|
|
482
|
+
const clipboard = await client.readBrowserClipboard(workspaceId, browserSessionId);
|
|
483
|
+
if (clipboard.browserSessionId !== browserSessionId) {
|
|
484
|
+
throw new Error("Browser clipboard belongs to another BrowserSession.");
|
|
485
|
+
}
|
|
486
|
+
return clipboard;
|
|
487
|
+
}, [browserSessionId, client, workspaceId]);
|
|
488
|
+
|
|
489
|
+
return {
|
|
490
|
+
session: visible.session,
|
|
491
|
+
targets: visible.targets,
|
|
492
|
+
selectedTarget:
|
|
493
|
+
visible.targets.find((target) => target.id === visible.selectedTargetId) ?? null,
|
|
494
|
+
observation: visible.observation,
|
|
495
|
+
loading: visible.loading,
|
|
496
|
+
mutating: visible.mutating,
|
|
497
|
+
error: visible.error,
|
|
498
|
+
refresh,
|
|
499
|
+
selectTarget,
|
|
500
|
+
openTarget,
|
|
501
|
+
closeTarget,
|
|
502
|
+
act,
|
|
503
|
+
actFromFrame,
|
|
504
|
+
readClipboard,
|
|
505
|
+
diagnostics,
|
|
506
|
+
};
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
function emptyState(browserSessionId: string | null, loading: boolean) {
|
|
510
|
+
return {
|
|
511
|
+
browserSessionId,
|
|
512
|
+
session: null as BrowserSession | null,
|
|
513
|
+
targets: [] as BrowserTarget[],
|
|
514
|
+
selectedTargetId: null as string | null,
|
|
515
|
+
observation: null as BrowserObservation | null,
|
|
516
|
+
loading,
|
|
517
|
+
mutating: false,
|
|
518
|
+
error: null as Error | null,
|
|
519
|
+
};
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
function chooseTarget(
|
|
523
|
+
targets: readonly BrowserTarget[],
|
|
524
|
+
preferredId: string | null,
|
|
525
|
+
): BrowserTarget | null {
|
|
526
|
+
return (
|
|
527
|
+
targets.find((target) => target.id === preferredId) ??
|
|
528
|
+
targets.find((target) => target.selected && target.kind === "page") ??
|
|
529
|
+
targets.find((target) => target.kind === "page") ??
|
|
530
|
+
targets[0] ??
|
|
531
|
+
null
|
|
532
|
+
);
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
function replaceTarget(targets: readonly BrowserTarget[], target: BrowserTarget): BrowserTarget[] {
|
|
536
|
+
const next = targets.filter((candidate) => candidate.id !== target.id);
|
|
537
|
+
next.push(target);
|
|
538
|
+
return next.sort((left, right) => left.createdAt.localeCompare(right.createdAt));
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
function isMissingBrowserTarget(error: unknown): boolean {
|
|
542
|
+
return error instanceof OpenGeniApiError && error.code === "target_not_found";
|
|
543
|
+
}
|