@opengeni/react 0.52.1 → 1.0.1

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 (132) hide show
  1. package/README.md +51 -1
  2. package/dist/artifacts.d.ts +1 -1
  3. package/dist/artifacts.js +43 -14
  4. package/dist/artifacts.js.map +1 -1
  5. package/dist/{chunk-ROIRTM37.js → chunk-5UQPNLIO.js} +6 -6
  6. package/dist/{chunk-JR3QFY6B.js → chunk-6KLX2RH5.js} +49 -2
  7. package/dist/chunk-6KLX2RH5.js.map +1 -0
  8. package/dist/{chunk-FWS3KC3Z.js → chunk-B6WPZSTT.js} +104 -104
  9. package/dist/{chunk-FWS3KC3Z.js.map → chunk-B6WPZSTT.js.map} +1 -1
  10. package/dist/{chunk-HDBG7XGO.js → chunk-C5ZPSSS5.js} +50 -1
  11. package/dist/chunk-C5ZPSSS5.js.map +1 -0
  12. package/dist/{chunk-X4S56Y2H.js → chunk-HA46CYQK.js} +135 -11
  13. package/dist/chunk-HA46CYQK.js.map +1 -0
  14. package/dist/{chunk-724BW4TW.js → chunk-IGC6A2ZI.js} +2 -2
  15. package/dist/chunk-LLOLUHVG.js +5937 -0
  16. package/dist/chunk-LLOLUHVG.js.map +1 -0
  17. package/dist/{chunk-WYA65Y3F.js → chunk-MKPIAGVL.js} +13 -3
  18. package/dist/chunk-MKPIAGVL.js.map +1 -0
  19. package/dist/chunk-R3AZOAB5.js +933 -0
  20. package/dist/chunk-R3AZOAB5.js.map +1 -0
  21. package/dist/{chunk-23EJ676W.js → chunk-XBZWOM2K.js} +9 -4
  22. package/dist/chunk-XBZWOM2K.js.map +1 -0
  23. package/dist/{chunk-JAGDUCZQ.js → chunk-Y7OEDUJ5.js} +17 -13
  24. package/dist/chunk-Y7OEDUJ5.js.map +1 -0
  25. package/dist/client.d.ts +6 -4
  26. package/dist/components/artifacts/index.d.ts +1 -0
  27. package/dist/components/artifacts/published-html-artifact-frame.d.ts +14 -0
  28. package/dist/components/browser-input.d.ts +7 -0
  29. package/dist/components/browser-viewer.d.ts +5 -4
  30. package/dist/components/computer-viewer.d.ts +2 -1
  31. package/dist/components/desktop-viewer.d.ts +26 -2
  32. package/dist/components/interaction-intervention-banner.d.ts +11 -0
  33. package/dist/components/sandbox-terminal.d.ts +4 -1
  34. package/dist/components/sandbox-workspace.d.ts +3 -0
  35. package/dist/composer.js +6 -6
  36. package/dist/hooks/use-auth-runs.d.ts +32 -0
  37. package/dist/hooks/use-browser-downloads.d.ts +25 -0
  38. package/dist/hooks/use-browser-identities.d.ts +5 -1
  39. package/dist/hooks/use-browser-session.d.ts +2 -1
  40. package/dist/hooks/use-browser-sessions.d.ts +1 -1
  41. package/dist/hooks/use-channels.d.ts +26 -0
  42. package/dist/hooks/use-computer-frame-stream.d.ts +1 -1
  43. package/dist/hooks/use-computer-session.d.ts +2 -1
  44. package/dist/hooks/use-computer-sessions.d.ts +1 -1
  45. package/dist/hooks/use-desktop-stream.d.ts +4 -0
  46. package/dist/hooks/use-interaction-interventions.d.ts +27 -0
  47. package/dist/hooks/use-interaction-invalidation.d.ts +19 -0
  48. package/dist/hooks/use-network-routes.d.ts +25 -0
  49. package/dist/hooks/use-site-auth-connections.d.ts +25 -0
  50. package/dist/hooks/use-supergrok-accounts.d.ts +26 -0
  51. package/dist/hooks/use-terminal-stream.d.ts +3 -0
  52. package/dist/index.d.ts +4 -0
  53. package/dist/index.js +1220 -1545
  54. package/dist/index.js.map +1 -1
  55. package/dist/interaction.d.ts +13 -3
  56. package/dist/interaction.js +520 -6
  57. package/dist/interaction.js.map +1 -1
  58. package/dist/interactive-workbench-viewers-TOHBXJEE.js +15 -0
  59. package/dist/lib/host-platform.d.ts +5 -0
  60. package/dist/lib/relay-wire.d.ts +20 -1
  61. package/dist/machines.js +3 -3
  62. package/dist/model-policy.d.ts +1 -1
  63. package/dist/model-policy.js +1 -1
  64. package/dist/provider.d.ts +3 -2
  65. package/dist/realtime/realtime-control.d.ts +6 -2
  66. package/dist/realtime.js +138 -24
  67. package/dist/realtime.js.map +1 -1
  68. package/dist/session-context.d.ts +10 -2
  69. package/dist/session-ui.js +3 -3
  70. package/dist/session.js +11 -11
  71. package/dist/timeline/types.d.ts +5 -0
  72. package/package.json +2 -2
  73. package/src/artifacts.ts +3 -0
  74. package/src/client.ts +73 -3
  75. package/src/components/artifacts/index.ts +5 -0
  76. package/src/components/artifacts/published-html-artifact-frame.tsx +38 -0
  77. package/src/components/browser-input.ts +65 -0
  78. package/src/components/browser-viewer.tsx +1287 -177
  79. package/src/components/computer-viewer.tsx +611 -114
  80. package/src/components/desktop-viewer.tsx +114 -1
  81. package/src/components/interaction-intervention-banner.tsx +99 -0
  82. package/src/components/machines/machine-detail.tsx +1 -1
  83. package/src/components/model-policy-picker.tsx +15 -0
  84. package/src/components/sandbox-terminal.tsx +24 -7
  85. package/src/components/sandbox-workspace.tsx +42 -4
  86. package/src/components/workspace-dock.tsx +59 -5
  87. package/src/hooks/use-attached-browsers.ts +13 -11
  88. package/src/hooks/use-auth-runs.ts +278 -0
  89. package/src/hooks/use-browser-downloads.ts +218 -0
  90. package/src/hooks/use-browser-frame-stream.ts +168 -59
  91. package/src/hooks/use-browser-identities.ts +47 -6
  92. package/src/hooks/use-browser-session.ts +94 -27
  93. package/src/hooks/use-browser-sessions.ts +19 -14
  94. package/src/hooks/use-channels.ts +99 -0
  95. package/src/hooks/use-computer-frame-stream.ts +184 -61
  96. package/src/hooks/use-computer-session.ts +22 -2
  97. package/src/hooks/use-computer-sessions.ts +19 -13
  98. package/src/hooks/use-desktop-stream.ts +39 -7
  99. package/src/hooks/use-interaction-interventions.ts +242 -0
  100. package/src/hooks/use-interaction-invalidation.ts +66 -0
  101. package/src/hooks/use-machine-chip.ts +13 -3
  102. package/src/hooks/use-network-routes.ts +214 -0
  103. package/src/hooks/use-site-auth-connections.ts +226 -0
  104. package/src/hooks/use-supergrok-accounts.ts +81 -0
  105. package/src/hooks/use-terminal-stream.ts +288 -55
  106. package/src/index.ts +8 -0
  107. package/src/interaction.ts +30 -0
  108. package/src/lib/host-platform.ts +10 -0
  109. package/src/lib/relay-wire.ts +43 -4
  110. package/src/lib/terminal-capability.ts +1 -1
  111. package/src/model-policy.ts +19 -4
  112. package/src/provider.tsx +133 -1
  113. package/src/realtime/realtime-control.tsx +181 -26
  114. package/src/session-context.ts +66 -1
  115. package/src/timeline/activity-rail.tsx +6 -0
  116. package/src/timeline/projection.ts +58 -0
  117. package/src/timeline/types.ts +2 -0
  118. package/styles/compiled.css +64 -6
  119. package/dist/chunk-23EJ676W.js.map +0 -1
  120. package/dist/chunk-6BBWWOOU.js +0 -82
  121. package/dist/chunk-6BBWWOOU.js.map +0 -1
  122. package/dist/chunk-7I2KB3OK.js +0 -3895
  123. package/dist/chunk-7I2KB3OK.js.map +0 -1
  124. package/dist/chunk-HDBG7XGO.js.map +0 -1
  125. package/dist/chunk-JAGDUCZQ.js.map +0 -1
  126. package/dist/chunk-JR3QFY6B.js.map +0 -1
  127. package/dist/chunk-WYA65Y3F.js.map +0 -1
  128. package/dist/chunk-X4S56Y2H.js.map +0 -1
  129. package/dist/interactive-workbench-viewers-KHNOHWQE.js +0 -13
  130. /package/dist/{chunk-ROIRTM37.js.map → chunk-5UQPNLIO.js.map} +0 -0
  131. /package/dist/{chunk-724BW4TW.js.map → chunk-IGC6A2ZI.js.map} +0 -0
  132. /package/dist/{interactive-workbench-viewers-KHNOHWQE.js.map → interactive-workbench-viewers-TOHBXJEE.js.map} +0 -0
@@ -0,0 +1,226 @@
1
+ import type {
2
+ CreateSiteAuthConnectionRequest,
3
+ SiteAuthConnection,
4
+ SiteAuthConnectionMutationResponse,
5
+ UpdateSiteAuthConnectionRequest,
6
+ } from "@opengeni/sdk/interaction";
7
+ import { useCallback, useEffect, useRef, useState } from "react";
8
+ import type { EmbeddedBrowserInteractionClientLike } from "../client";
9
+ import {
10
+ type EmbeddedBrowserInteractionClientOverride,
11
+ useEmbeddedBrowserInteraction,
12
+ } from "../session-context";
13
+ import { useInteractionInvalidation } from "./use-interaction-invalidation";
14
+
15
+ export type UseSiteAuthConnectionsOptions = EmbeddedBrowserInteractionClientOverride & {
16
+ enabled?: boolean | undefined;
17
+ includeArchived?: boolean | undefined;
18
+ };
19
+
20
+ export type UseSiteAuthConnectionsResult = {
21
+ revision: number;
22
+ connections: SiteAuthConnection[];
23
+ loading: boolean;
24
+ refreshing: boolean;
25
+ mutating: boolean;
26
+ error: Error | null;
27
+ refresh: () => Promise<void>;
28
+ create: (
29
+ request: Omit<CreateSiteAuthConnectionRequest, "operationId"> & { operationId?: string },
30
+ ) => Promise<SiteAuthConnectionMutationResponse>;
31
+ update: (
32
+ connectionId: string,
33
+ request: Omit<UpdateSiteAuthConnectionRequest, "operationId"> & {
34
+ operationId?: string;
35
+ },
36
+ ) => Promise<SiteAuthConnectionMutationResponse>;
37
+ };
38
+
39
+ /** Secret-free workspace login recipes and their verified health. */
40
+ export function useSiteAuthConnections(
41
+ options: UseSiteAuthConnectionsOptions = {},
42
+ ): UseSiteAuthConnectionsResult {
43
+ const { client, workspaceId, workspaceInteractionEvent, workspaceInteractionConnectionState } =
44
+ useEmbeddedBrowserInteraction(options);
45
+ const enabled = options.enabled ?? true;
46
+ const includeArchived = options.includeArchived ?? false;
47
+ const key = `${workspaceId}:${includeArchived ? "all" : "active"}`;
48
+ const [state, setState] = useState(() => emptyState(key, enabled));
49
+ const [mutationCount, setMutationCount] = useState(0);
50
+ const requestRef = useRef<{ id: number; controller: AbortController | null }>({
51
+ id: 0,
52
+ controller: null,
53
+ });
54
+ const mountedRef = useRef(true);
55
+ const visible = state.key === key ? state : emptyState(key, enabled);
56
+
57
+ const cancelLoad = useCallback(() => {
58
+ requestRef.current.controller?.abort();
59
+ requestRef.current = { id: requestRef.current.id + 1, controller: null };
60
+ }, []);
61
+
62
+ const load = useCallback(
63
+ async (foreground: boolean): Promise<void> => {
64
+ if (!enabled) return;
65
+ const id = requestRef.current.id + 1;
66
+ requestRef.current.controller?.abort();
67
+ const controller = new AbortController();
68
+ requestRef.current = { id, controller };
69
+ setState((current) => ({
70
+ ...(current.key === key ? current : emptyState(key, true)),
71
+ loading: foreground,
72
+ refreshing: !foreground,
73
+ error: foreground || current.key !== key ? null : current.error,
74
+ }));
75
+ try {
76
+ const response = await client.listSiteAuthConnections(workspaceId, {
77
+ includeArchived,
78
+ signal: controller.signal,
79
+ });
80
+ if (!mountedRef.current || requestRef.current.id !== id) return;
81
+ setState({
82
+ key,
83
+ revision: response.revision,
84
+ connections: sortConnections(response.connections),
85
+ loading: false,
86
+ refreshing: false,
87
+ error: null,
88
+ });
89
+ } catch (cause) {
90
+ if (controller.signal.aborted || !mountedRef.current || requestRef.current.id !== id)
91
+ return;
92
+ setState((current) => ({
93
+ ...(current.key === key ? current : emptyState(key, true)),
94
+ loading: false,
95
+ refreshing: false,
96
+ error: asError(cause),
97
+ }));
98
+ } finally {
99
+ if (requestRef.current.id === id) requestRef.current = { id, controller: null };
100
+ }
101
+ },
102
+ [client, enabled, includeArchived, key, workspaceId],
103
+ );
104
+
105
+ const refresh = useCallback(async () => await load(false), [load]);
106
+
107
+ useEffect(() => {
108
+ mountedRef.current = true;
109
+ if (!enabled) {
110
+ cancelLoad();
111
+ setState(emptyState(key, false));
112
+ return;
113
+ }
114
+ void load(true);
115
+ return () => {
116
+ mountedRef.current = false;
117
+ cancelLoad();
118
+ };
119
+ }, [cancelLoad, enabled, key, load]);
120
+
121
+ useInteractionInvalidation({
122
+ workspaceId,
123
+ key,
124
+ enabled,
125
+ event: workspaceInteractionEvent,
126
+ connectionState: workspaceInteractionConnectionState,
127
+ knownRevision: visible.revision,
128
+ refresh,
129
+ });
130
+
131
+ const mutate = useCallback(async <T>(operation: () => Promise<T>): Promise<T> => {
132
+ setMutationCount((count) => count + 1);
133
+ try {
134
+ return await operation();
135
+ } finally {
136
+ if (mountedRef.current) setMutationCount((count) => Math.max(0, count - 1));
137
+ }
138
+ }, []);
139
+
140
+ const merge = useCallback(
141
+ (connection: SiteAuthConnection) => {
142
+ setState((current) => {
143
+ if (current.key !== key) return current;
144
+ const connections = current.connections.filter(
145
+ (candidate) => candidate.id !== connection.id,
146
+ );
147
+ if (includeArchived || connection.status !== "archived") connections.push(connection);
148
+ return { ...current, connections: sortConnections(connections), error: null };
149
+ });
150
+ },
151
+ [includeArchived, key],
152
+ );
153
+
154
+ const create = useCallback(
155
+ async (
156
+ request: Omit<CreateSiteAuthConnectionRequest, "operationId"> & {
157
+ operationId?: string;
158
+ },
159
+ ): Promise<SiteAuthConnectionMutationResponse> =>
160
+ await mutate(async () => {
161
+ const response = await client.createSiteAuthConnection(workspaceId, {
162
+ ...request,
163
+ operationId: request.operationId ?? crypto.randomUUID(),
164
+ });
165
+ merge(response.connection);
166
+ return response;
167
+ }),
168
+ [client, merge, mutate, workspaceId],
169
+ );
170
+
171
+ const update = useCallback(
172
+ async (
173
+ connectionId: string,
174
+ request: Omit<UpdateSiteAuthConnectionRequest, "operationId"> & {
175
+ operationId?: string;
176
+ },
177
+ ): Promise<SiteAuthConnectionMutationResponse> =>
178
+ await mutate(async () => {
179
+ const response = await client.updateSiteAuthConnection(workspaceId, connectionId, {
180
+ ...request,
181
+ operationId: request.operationId ?? crypto.randomUUID(),
182
+ });
183
+ merge(response.connection);
184
+ return response;
185
+ }),
186
+ [client, merge, mutate, workspaceId],
187
+ );
188
+
189
+ return {
190
+ revision: visible.revision,
191
+ connections: visible.connections,
192
+ loading: visible.loading,
193
+ refreshing: visible.refreshing,
194
+ mutating: mutationCount > 0,
195
+ error: visible.error,
196
+ refresh,
197
+ create,
198
+ update,
199
+ };
200
+ }
201
+
202
+ function emptyState(key: string, loading: boolean) {
203
+ return {
204
+ key,
205
+ revision: 0,
206
+ connections: [] as SiteAuthConnection[],
207
+ loading,
208
+ refreshing: false,
209
+ error: null as Error | null,
210
+ };
211
+ }
212
+
213
+ function sortConnections(connections: readonly SiteAuthConnection[]): SiteAuthConnection[] {
214
+ return [...connections].sort(
215
+ (left, right) =>
216
+ Number(left.status === "archived") - Number(right.status === "archived") ||
217
+ left.name.localeCompare(right.name) ||
218
+ left.accountLabel.localeCompare(right.accountLabel),
219
+ );
220
+ }
221
+
222
+ function asError(cause: unknown): Error {
223
+ return cause instanceof Error ? cause : new Error(String(cause));
224
+ }
225
+
226
+ export type SiteAuthConnectionsClient = EmbeddedBrowserInteractionClientLike;
@@ -0,0 +1,81 @@
1
+ import type { SuperGrokAccount, SuperGrokAccountsResponse } from "@opengeni/sdk";
2
+ import { useCallback } from "react";
3
+
4
+ import { useOpenGeni, type ClientOverride } from "../provider";
5
+ import { useMutationRunner, usePolledValue } from "./internal";
6
+
7
+ export type SuperGrokAccountsClientLike = {
8
+ listSuperGrokAccounts: (workspaceId: string) => Promise<SuperGrokAccountsResponse>;
9
+ activateSuperGrokAccount?: (
10
+ workspaceId: string,
11
+ accountId: string,
12
+ ) => Promise<{ activated: boolean; accountId: string }>;
13
+ };
14
+
15
+ export type UseSuperGrokAccountsOptions = ClientOverride & {
16
+ enabled?: boolean | undefined;
17
+ pollIntervalMs?: number | undefined;
18
+ supergrokClient?: SuperGrokAccountsClientLike | undefined;
19
+ };
20
+
21
+ export type UseSuperGrokAccountsResult = {
22
+ accounts: SuperGrokAccount[];
23
+ activeAccountId: string | null;
24
+ settings: SuperGrokAccountsResponse["settings"];
25
+ loading: boolean;
26
+ refresh: () => Promise<void>;
27
+ activate: (accountId: string) => Promise<boolean>;
28
+ activating: boolean;
29
+ mutationError: Error | null;
30
+ };
31
+
32
+ const EMPTY: SuperGrokAccountsResponse = {
33
+ accounts: [],
34
+ activeAccountId: null,
35
+ settings: {
36
+ rotationEnabled: false,
37
+ rotationStrategy: "sharded",
38
+ activeCredentialId: null,
39
+ },
40
+ };
41
+
42
+ /** Workspace-visible xAI accounts. Workspace scope is the connection default. */
43
+ export function useSuperGrokAccounts(
44
+ options: UseSuperGrokAccountsOptions = {},
45
+ ): UseSuperGrokAccountsResult {
46
+ const { client, workspaceId } = useOpenGeni(options);
47
+ const supergrokClient =
48
+ options.supergrokClient ?? (client as unknown as SuperGrokAccountsClientLike);
49
+ const load = useCallback(
50
+ async () => await supergrokClient.listSuperGrokAccounts(workspaceId),
51
+ [supergrokClient, workspaceId],
52
+ );
53
+ const { data, loading, refresh } = usePolledValue(load, {
54
+ enabled: options.enabled,
55
+ pollIntervalMs: options.pollIntervalMs,
56
+ });
57
+ const { run, mutating: activating, mutationError } = useMutationRunner();
58
+ const activate = useCallback(
59
+ async (accountId: string): Promise<boolean> => {
60
+ if (!supergrokClient.activateSuperGrokAccount) return false;
61
+ const result = await run(async () => {
62
+ await supergrokClient.activateSuperGrokAccount!(workspaceId, accountId);
63
+ return true;
64
+ });
65
+ if (result) await refresh();
66
+ return result === true;
67
+ },
68
+ [refresh, run, supergrokClient, workspaceId],
69
+ );
70
+ const state = data ?? EMPTY;
71
+ return {
72
+ accounts: state.accounts,
73
+ activeAccountId: state.activeAccountId,
74
+ settings: state.settings,
75
+ loading,
76
+ refresh,
77
+ activate,
78
+ activating,
79
+ mutationError,
80
+ };
81
+ }