@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,286 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
BrowserSession,
|
|
3
|
+
BrowserSessionMutationResponse,
|
|
4
|
+
CreateBrowserSessionRequest,
|
|
5
|
+
} from "@opengeni/sdk/interaction";
|
|
6
|
+
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
7
|
+
import type { EmbeddedBrowserInteractionClientLike } from "../client";
|
|
8
|
+
import {
|
|
9
|
+
type EmbeddedBrowserInteractionClientOverride,
|
|
10
|
+
useEmbeddedBrowserInteraction,
|
|
11
|
+
} from "../session-context";
|
|
12
|
+
import { useInteractionInvalidation } from "./use-interaction-invalidation";
|
|
13
|
+
|
|
14
|
+
export type UseBrowserSessionsOptions = EmbeddedBrowserInteractionClientOverride & {
|
|
15
|
+
/** Current agent/session relevance. Workspace peers remain in `sessions`. */
|
|
16
|
+
sessionId?: string | undefined;
|
|
17
|
+
enabled?: boolean | undefined;
|
|
18
|
+
/** Polling fallback used only while the workspace invalidation stream is unavailable. */
|
|
19
|
+
pollIntervalMs?: number | undefined;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export type UseBrowserSessionsResult = {
|
|
23
|
+
revision: number;
|
|
24
|
+
sessions: BrowserSession[];
|
|
25
|
+
relevantSessions: BrowserSession[];
|
|
26
|
+
loading: boolean;
|
|
27
|
+
refreshing: boolean;
|
|
28
|
+
error: Error | null;
|
|
29
|
+
refresh: () => Promise<void>;
|
|
30
|
+
create: (
|
|
31
|
+
request: Omit<CreateBrowserSessionRequest, "operationId"> & {
|
|
32
|
+
operationId?: string;
|
|
33
|
+
},
|
|
34
|
+
) => Promise<BrowserSessionMutationResponse>;
|
|
35
|
+
suspend: (
|
|
36
|
+
browserSessionId: string,
|
|
37
|
+
operationId?: string,
|
|
38
|
+
) => Promise<BrowserSessionMutationResponse>;
|
|
39
|
+
resume: (
|
|
40
|
+
browserSessionId: string,
|
|
41
|
+
operationId?: string,
|
|
42
|
+
) => Promise<BrowserSessionMutationResponse>;
|
|
43
|
+
end: (browserSessionId: string, operationId?: string) => Promise<BrowserSessionMutationResponse>;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Workspace-wide BrowserSession registry. Associations rank relevance but never
|
|
48
|
+
* hide peer resources; no explicit share ceremony or per-view ownership exists.
|
|
49
|
+
*/
|
|
50
|
+
export function useBrowserSessions(
|
|
51
|
+
options: UseBrowserSessionsOptions = {},
|
|
52
|
+
): UseBrowserSessionsResult {
|
|
53
|
+
const {
|
|
54
|
+
client,
|
|
55
|
+
workspaceId,
|
|
56
|
+
registerSessionReconciler,
|
|
57
|
+
workspaceInteractionEvent,
|
|
58
|
+
workspaceInteractionConnectionState,
|
|
59
|
+
} = useEmbeddedBrowserInteraction(options);
|
|
60
|
+
const enabled = options.enabled ?? true;
|
|
61
|
+
const [state, setState] = useState<{
|
|
62
|
+
workspaceId: string;
|
|
63
|
+
revision: number;
|
|
64
|
+
sessions: BrowserSession[];
|
|
65
|
+
loading: boolean;
|
|
66
|
+
refreshing: boolean;
|
|
67
|
+
error: Error | null;
|
|
68
|
+
}>(() => emptyState(workspaceId, enabled));
|
|
69
|
+
const requestRef = useRef<{ id: number; controller: AbortController | null }>({
|
|
70
|
+
id: 0,
|
|
71
|
+
controller: null,
|
|
72
|
+
});
|
|
73
|
+
const mountedRef = useRef(true);
|
|
74
|
+
|
|
75
|
+
const visibleState = state.workspaceId === workspaceId ? state : emptyState(workspaceId, enabled);
|
|
76
|
+
|
|
77
|
+
const cancelLoad = useCallback(() => {
|
|
78
|
+
const id = requestRef.current.id + 1;
|
|
79
|
+
requestRef.current.controller?.abort();
|
|
80
|
+
requestRef.current = { id, controller: null };
|
|
81
|
+
}, []);
|
|
82
|
+
|
|
83
|
+
const load = useCallback(
|
|
84
|
+
async (foreground: boolean): Promise<void> => {
|
|
85
|
+
if (!enabled) return;
|
|
86
|
+
const id = requestRef.current.id + 1;
|
|
87
|
+
requestRef.current.controller?.abort();
|
|
88
|
+
const controller = new AbortController();
|
|
89
|
+
requestRef.current = { id, controller };
|
|
90
|
+
setState((current) => ({
|
|
91
|
+
...(current.workspaceId === workspaceId ? current : emptyState(workspaceId, true)),
|
|
92
|
+
loading: foreground,
|
|
93
|
+
refreshing: !foreground,
|
|
94
|
+
error: foreground || current.workspaceId !== workspaceId ? null : current.error,
|
|
95
|
+
}));
|
|
96
|
+
try {
|
|
97
|
+
const response = await client.listBrowserSessions(workspaceId, {
|
|
98
|
+
signal: controller.signal,
|
|
99
|
+
});
|
|
100
|
+
if (!mountedRef.current || requestRef.current.id !== id) return;
|
|
101
|
+
setState({
|
|
102
|
+
workspaceId,
|
|
103
|
+
revision: response.revision,
|
|
104
|
+
sessions: sortBrowserSessions(response.sessions),
|
|
105
|
+
loading: false,
|
|
106
|
+
refreshing: false,
|
|
107
|
+
error: null,
|
|
108
|
+
});
|
|
109
|
+
} catch (cause) {
|
|
110
|
+
if (controller.signal.aborted || !mountedRef.current || requestRef.current.id !== id)
|
|
111
|
+
return;
|
|
112
|
+
const error = cause instanceof Error ? cause : new Error(String(cause));
|
|
113
|
+
setState((current) => ({
|
|
114
|
+
...(current.workspaceId === workspaceId ? current : emptyState(workspaceId, true)),
|
|
115
|
+
loading: false,
|
|
116
|
+
refreshing: false,
|
|
117
|
+
error,
|
|
118
|
+
}));
|
|
119
|
+
} finally {
|
|
120
|
+
if (requestRef.current.id === id) {
|
|
121
|
+
requestRef.current = { id, controller: null };
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
},
|
|
125
|
+
[client, enabled, workspaceId],
|
|
126
|
+
);
|
|
127
|
+
|
|
128
|
+
const refresh = useCallback(async () => await load(false), [load]);
|
|
129
|
+
|
|
130
|
+
useEffect(() => {
|
|
131
|
+
mountedRef.current = true;
|
|
132
|
+
if (!enabled) {
|
|
133
|
+
cancelLoad();
|
|
134
|
+
setState(emptyState(workspaceId, false));
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
void load(true);
|
|
138
|
+
return () => {
|
|
139
|
+
mountedRef.current = false;
|
|
140
|
+
cancelLoad();
|
|
141
|
+
};
|
|
142
|
+
}, [cancelLoad, enabled, load, workspaceId]);
|
|
143
|
+
|
|
144
|
+
useInteractionInvalidation({
|
|
145
|
+
workspaceId,
|
|
146
|
+
key: workspaceId,
|
|
147
|
+
enabled,
|
|
148
|
+
event: workspaceInteractionEvent,
|
|
149
|
+
connectionState: workspaceInteractionConnectionState,
|
|
150
|
+
knownRevision: visibleState.revision,
|
|
151
|
+
refresh,
|
|
152
|
+
fallbackPollIntervalMs: options.pollIntervalMs,
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
useEffect(() => {
|
|
156
|
+
if (!enabled || !options.sessionId) return;
|
|
157
|
+
return registerSessionReconciler(options.sessionId, `browser-sessions:${workspaceId}`, refresh);
|
|
158
|
+
}, [enabled, options.sessionId, refresh, registerSessionReconciler, workspaceId]);
|
|
159
|
+
|
|
160
|
+
const create = useCallback(
|
|
161
|
+
async (
|
|
162
|
+
request: Omit<CreateBrowserSessionRequest, "operationId"> & {
|
|
163
|
+
operationId?: string;
|
|
164
|
+
},
|
|
165
|
+
): Promise<BrowserSessionMutationResponse> => {
|
|
166
|
+
const response = await client.createBrowserSession(workspaceId, {
|
|
167
|
+
...request,
|
|
168
|
+
operationId: request.operationId ?? crypto.randomUUID(),
|
|
169
|
+
});
|
|
170
|
+
setState((current) => mergeSession(current, workspaceId, response.session));
|
|
171
|
+
return response;
|
|
172
|
+
},
|
|
173
|
+
[client, workspaceId],
|
|
174
|
+
);
|
|
175
|
+
|
|
176
|
+
const end = useCallback(
|
|
177
|
+
async (
|
|
178
|
+
browserSessionId: string,
|
|
179
|
+
operationId: string = crypto.randomUUID(),
|
|
180
|
+
): Promise<BrowserSessionMutationResponse> => {
|
|
181
|
+
const response = await client.endBrowserSession(workspaceId, browserSessionId, {
|
|
182
|
+
operationId,
|
|
183
|
+
});
|
|
184
|
+
setState((current) => mergeSession(current, workspaceId, response.session));
|
|
185
|
+
return response;
|
|
186
|
+
},
|
|
187
|
+
[client, workspaceId],
|
|
188
|
+
);
|
|
189
|
+
|
|
190
|
+
const suspend = useCallback(
|
|
191
|
+
async (
|
|
192
|
+
browserSessionId: string,
|
|
193
|
+
operationId: string = crypto.randomUUID(),
|
|
194
|
+
): Promise<BrowserSessionMutationResponse> => {
|
|
195
|
+
const response = await client.suspendBrowserSession(workspaceId, browserSessionId, {
|
|
196
|
+
operationId,
|
|
197
|
+
});
|
|
198
|
+
setState((current) => mergeSession(current, workspaceId, response.session));
|
|
199
|
+
return response;
|
|
200
|
+
},
|
|
201
|
+
[client, workspaceId],
|
|
202
|
+
);
|
|
203
|
+
|
|
204
|
+
const resume = useCallback(
|
|
205
|
+
async (
|
|
206
|
+
browserSessionId: string,
|
|
207
|
+
operationId: string = crypto.randomUUID(),
|
|
208
|
+
): Promise<BrowserSessionMutationResponse> => {
|
|
209
|
+
const response = await client.resumeBrowserSession(workspaceId, browserSessionId, {
|
|
210
|
+
operationId,
|
|
211
|
+
});
|
|
212
|
+
setState((current) => mergeSession(current, workspaceId, response.session));
|
|
213
|
+
return response;
|
|
214
|
+
},
|
|
215
|
+
[client, workspaceId],
|
|
216
|
+
);
|
|
217
|
+
|
|
218
|
+
const relevantSessions = useMemo(
|
|
219
|
+
() =>
|
|
220
|
+
options.sessionId
|
|
221
|
+
? visibleState.sessions.filter((session) =>
|
|
222
|
+
session.associations.some((association) => association.sessionId === options.sessionId),
|
|
223
|
+
)
|
|
224
|
+
: [],
|
|
225
|
+
[options.sessionId, visibleState.sessions],
|
|
226
|
+
);
|
|
227
|
+
|
|
228
|
+
return {
|
|
229
|
+
revision: visibleState.revision,
|
|
230
|
+
sessions: visibleState.sessions,
|
|
231
|
+
relevantSessions,
|
|
232
|
+
loading: visibleState.loading,
|
|
233
|
+
refreshing: visibleState.refreshing,
|
|
234
|
+
error: visibleState.error,
|
|
235
|
+
refresh,
|
|
236
|
+
create,
|
|
237
|
+
suspend,
|
|
238
|
+
resume,
|
|
239
|
+
end,
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
function emptyState(workspaceId: string, loading: boolean) {
|
|
244
|
+
return {
|
|
245
|
+
workspaceId,
|
|
246
|
+
revision: 0,
|
|
247
|
+
sessions: [] as BrowserSession[],
|
|
248
|
+
loading,
|
|
249
|
+
refreshing: false,
|
|
250
|
+
error: null as Error | null,
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
function sortBrowserSessions(sessions: readonly BrowserSession[]): BrowserSession[] {
|
|
255
|
+
return [...sessions].sort((left, right) => {
|
|
256
|
+
const live = Number(isLiveBrowser(right)) - Number(isLiveBrowser(left));
|
|
257
|
+
return (
|
|
258
|
+
live ||
|
|
259
|
+
timestamp(right.lastUsedAt) - timestamp(left.lastUsedAt) ||
|
|
260
|
+
left.id.localeCompare(right.id)
|
|
261
|
+
);
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
function isLiveBrowser(session: BrowserSession): boolean {
|
|
266
|
+
return !["ending", "ended", "failed", "lost"].includes(session.lifecycle);
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
function timestamp(value: string): number {
|
|
270
|
+
const parsed = Date.parse(value);
|
|
271
|
+
return Number.isFinite(parsed) ? parsed : 0;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
function mergeSession(
|
|
275
|
+
current: ReturnType<typeof emptyState>,
|
|
276
|
+
workspaceId: string,
|
|
277
|
+
session: BrowserSession,
|
|
278
|
+
): ReturnType<typeof emptyState> {
|
|
279
|
+
if (current.workspaceId !== workspaceId) return current;
|
|
280
|
+
const sessions = current.sessions.filter((candidate) => candidate.id !== session.id);
|
|
281
|
+
sessions.push(session);
|
|
282
|
+
return { ...current, sessions: sortBrowserSessions(sessions), error: null };
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
/** Exported for narrow proxy implementations and tests. */
|
|
286
|
+
export type BrowserSessionsClient = EmbeddedBrowserInteractionClientLike;
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import type { Channel, CreateChannelRequest, Session, UpdateChannelRequest } from "@opengeni/sdk";
|
|
2
|
+
import { useCallback } from "react";
|
|
3
|
+
import { useOpenGeni, type ClientOverride } from "../provider";
|
|
4
|
+
import { useMutationRunner, usePolledValue } from "./internal";
|
|
5
|
+
|
|
6
|
+
export type UseChannelsOptions = ClientOverride & {
|
|
7
|
+
pollIntervalMs?: number | undefined;
|
|
8
|
+
enabled?: boolean | undefined;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export type UseChannelsResult = {
|
|
12
|
+
channels: Channel[];
|
|
13
|
+
loading: boolean;
|
|
14
|
+
error: Error | null;
|
|
15
|
+
refresh: () => Promise<void>;
|
|
16
|
+
create: (request: CreateChannelRequest) => Promise<Channel | null>;
|
|
17
|
+
update: (channelId: string, request: UpdateChannelRequest) => Promise<Channel | null>;
|
|
18
|
+
remove: (channelId: string) => Promise<boolean>;
|
|
19
|
+
/** Re-file a session into a channel; null moves it back to the inbox. */
|
|
20
|
+
moveSession: (sessionId: string, channelId: string | null) => Promise<Session | null>;
|
|
21
|
+
mutating: boolean;
|
|
22
|
+
mutationError: Error | null;
|
|
23
|
+
clearMutationError: () => void;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Workspace-shared channels: rail organization for root sessions
|
|
28
|
+
* ("workstreams") by work type. Pure metadata — filing a session into a
|
|
29
|
+
* channel never affects execution.
|
|
30
|
+
*/
|
|
31
|
+
export function useChannels(options: UseChannelsOptions = {}): UseChannelsResult {
|
|
32
|
+
const { client, workspaceId } = useOpenGeni(options);
|
|
33
|
+
const load = useCallback(
|
|
34
|
+
async () => await client.listChannels(workspaceId),
|
|
35
|
+
[client, workspaceId],
|
|
36
|
+
);
|
|
37
|
+
const { data, loading, error, refresh } = usePolledValue(load, {
|
|
38
|
+
pollIntervalMs: options.pollIntervalMs,
|
|
39
|
+
enabled: options.enabled,
|
|
40
|
+
});
|
|
41
|
+
const { run, mutating, mutationError, clearMutationError } = useMutationRunner();
|
|
42
|
+
|
|
43
|
+
const create = useCallback(
|
|
44
|
+
async (request: CreateChannelRequest): Promise<Channel | null> => {
|
|
45
|
+
const result = await run(() => client.createChannel(workspaceId, request));
|
|
46
|
+
if (result) {
|
|
47
|
+
await refresh();
|
|
48
|
+
}
|
|
49
|
+
return result;
|
|
50
|
+
},
|
|
51
|
+
[client, workspaceId, run, refresh],
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
const update = useCallback(
|
|
55
|
+
async (channelId: string, request: UpdateChannelRequest): Promise<Channel | null> => {
|
|
56
|
+
const result = await run(() => client.updateChannel(workspaceId, channelId, request));
|
|
57
|
+
if (result) {
|
|
58
|
+
await refresh();
|
|
59
|
+
}
|
|
60
|
+
return result;
|
|
61
|
+
},
|
|
62
|
+
[client, workspaceId, run, refresh],
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
const remove = useCallback(
|
|
66
|
+
async (channelId: string): Promise<boolean> => {
|
|
67
|
+
const result = await run(async () => {
|
|
68
|
+
await client.deleteChannel(workspaceId, channelId);
|
|
69
|
+
return true;
|
|
70
|
+
});
|
|
71
|
+
if (result) {
|
|
72
|
+
await refresh();
|
|
73
|
+
}
|
|
74
|
+
return result === true;
|
|
75
|
+
},
|
|
76
|
+
[client, workspaceId, run, refresh],
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
const moveSession = useCallback(
|
|
80
|
+
async (sessionId: string, channelId: string | null): Promise<Session | null> => {
|
|
81
|
+
return await run(() => client.updateSessionChannel(workspaceId, sessionId, { channelId }));
|
|
82
|
+
},
|
|
83
|
+
[client, workspaceId, run],
|
|
84
|
+
);
|
|
85
|
+
|
|
86
|
+
return {
|
|
87
|
+
channels: data ?? [],
|
|
88
|
+
loading,
|
|
89
|
+
error,
|
|
90
|
+
refresh,
|
|
91
|
+
create,
|
|
92
|
+
update,
|
|
93
|
+
remove,
|
|
94
|
+
moveSession,
|
|
95
|
+
mutating,
|
|
96
|
+
mutationError,
|
|
97
|
+
clearMutationError,
|
|
98
|
+
};
|
|
99
|
+
}
|