@tangle-network/sandbox-ui 0.113.6 → 0.114.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (106) hide show
  1. package/dist/WorkflowGraph-B-NsdYz_.js +1961 -0
  2. package/dist/assets.d.ts +214 -206
  3. package/dist/assets.js +1057 -908
  4. package/dist/auth-CWe17Hly.js +37 -0
  5. package/dist/auth.d.ts +2 -30
  6. package/dist/auth.js +2 -15
  7. package/dist/chat-BOvFAe6p.js +903 -0
  8. package/dist/chat.d.ts +2 -230
  9. package/dist/chat.js +2 -34
  10. package/dist/connectors.d.ts +52 -49
  11. package/dist/connectors.js +595 -643
  12. package/dist/dashboard-CZ3VgNPR.js +4969 -0
  13. package/dist/dashboard.d.ts +4 -1297
  14. package/dist/dashboard.js +4 -152
  15. package/dist/editor.d.ts +2 -1
  16. package/dist/editor.js +2 -31
  17. package/dist/files.d.ts +2 -6
  18. package/dist/files.js +2 -33
  19. package/dist/globals.css +63 -3
  20. package/dist/hooks.d.ts +146 -148
  21. package/dist/hooks.js +222 -55
  22. package/dist/index-CKRaj1pM.d.ts +776 -0
  23. package/dist/index-CXX5IpH2.d.ts +2 -0
  24. package/dist/index-DPePq7c8.d.ts +1340 -0
  25. package/dist/index-DiyLLZuJ.d.ts +230 -0
  26. package/dist/index-DvmZLMT1.d.ts +30 -0
  27. package/dist/index-I8ZLVtHd.d.ts +330 -0
  28. package/dist/index-PRM636Ex.d.ts +86 -0
  29. package/dist/index.d.ts +21 -33
  30. package/dist/index.js +21 -701
  31. package/dist/info-panel-C9cqDzOL.js +594 -0
  32. package/dist/integrations.d.ts +133 -139
  33. package/dist/integrations.js +491 -673
  34. package/dist/markdown.d.ts +2 -1
  35. package/dist/markdown.js +2 -13
  36. package/dist/model-I-NIxeM-.js +1250 -0
  37. package/dist/model-brand-B9A4H9pJ.d.ts +98 -0
  38. package/dist/model-brand-hMyDTUqB.js +624 -0
  39. package/dist/motion-DkyBRJb9.js +37 -0
  40. package/dist/openui.d.ts +2 -1
  41. package/dist/openui.js +2 -7
  42. package/dist/pages.d.ts +307 -300
  43. package/dist/pages.js +4404 -4181
  44. package/dist/primitives-Dh1vG6J3.js +113 -0
  45. package/dist/primitives.d.ts +2 -74
  46. package/dist/primitives.js +2 -204
  47. package/dist/provider-logo-DjqmConF.js +311 -0
  48. package/dist/run.d.ts +2 -1
  49. package/dist/run.js +2 -23
  50. package/dist/sdk-hooks.d.ts +3 -4
  51. package/dist/sdk-hooks.js +3 -31
  52. package/dist/sidecar-DgH_vQ6m.d.ts +9 -0
  53. package/dist/stores.d.ts +14 -15
  54. package/dist/stores.js +13 -81
  55. package/dist/styles.css +63 -3
  56. package/dist/template-card-L-4gmjx2.d.ts +90 -0
  57. package/dist/terminal-CN9ZgHRt.js +197 -0
  58. package/dist/terminal.d.ts +60 -60
  59. package/dist/terminal.js +2 -10
  60. package/dist/tokens.css +51 -0
  61. package/dist/types.d.ts +4 -11
  62. package/dist/types.js +0 -1
  63. package/dist/use-pty-session-C8cE0adT.js +669 -0
  64. package/dist/use-sidecar-auth-CCTJcrq7.d.ts +145 -0
  65. package/dist/use-sidecar-auth-DkdcufOz.js +742 -0
  66. package/dist/utils-DzWbktWG.js +2 -0
  67. package/dist/utils.d.ts +2 -1
  68. package/dist/utils.js +2 -37
  69. package/dist/workbench-BCaCKl-J.js +8347 -0
  70. package/dist/workbench.d.ts +2 -310
  71. package/dist/workbench.js +2 -44
  72. package/dist/workflows.d.ts +341 -339
  73. package/dist/workflows.js +74 -109
  74. package/dist/workspace-B6AtI6ld.js +2510 -0
  75. package/dist/workspace.d.ts +2 -761
  76. package/dist/workspace.js +2 -51
  77. package/package.json +46 -40
  78. package/dist/WorkflowGraph-2QOORYIR.js +0 -1722
  79. package/dist/chunk-2BUPSB7O.js +0 -0
  80. package/dist/chunk-3KBNPQQF.js +0 -2697
  81. package/dist/chunk-3LIXVEEE.js +0 -279
  82. package/dist/chunk-72UF2H5H.js +0 -707
  83. package/dist/chunk-AI25G5MX.js +0 -944
  84. package/dist/chunk-ANSC5AFC.js +0 -314
  85. package/dist/chunk-AZ3AWMTM.js +0 -8
  86. package/dist/chunk-BGVEHENC.js +0 -10
  87. package/dist/chunk-CZ7CSFO4.js +0 -39
  88. package/dist/chunk-DYXXYGS4.js +0 -4700
  89. package/dist/chunk-EI44GEQ5.js +0 -6
  90. package/dist/chunk-IACRDXER.js +0 -219
  91. package/dist/chunk-IOB2PW5Z.js +0 -55
  92. package/dist/chunk-M4K7ZGR2.js +0 -24
  93. package/dist/chunk-MYZAW4RX.js +0 -665
  94. package/dist/chunk-OMUIPJQZ.js +0 -555
  95. package/dist/chunk-RQZRXKMR.js +0 -398
  96. package/dist/chunk-SOKKTB7W.js +0 -230
  97. package/dist/chunk-TADGS4Q7.js +0 -1010
  98. package/dist/chunk-UCQNOUN3.js +0 -7964
  99. package/dist/chunk-ULPLRBMF.js +0 -34
  100. package/dist/chunk-WID73FPH.js +0 -89
  101. package/dist/chunk-X3YXP7FG.js +0 -38
  102. package/dist/logo-DiAjq759.d.ts +0 -15
  103. package/dist/model-brand-BNnaUKKZ.d.ts +0 -99
  104. package/dist/ports-list-CDIvTNnX.d.ts +0 -17
  105. package/dist/sdk-hooks-Djkjq4cp.d.ts +0 -145
  106. package/dist/template-card-Bn-Bw5xC.d.ts +0 -87
package/dist/hooks.d.ts CHANGED
@@ -1,46 +1,42 @@
1
- export { AgentStreamEvent, AppendUserMessageOptions, ApplySdkEventOptions, AuthUser, AutomationStreamEvent, BeginAssistantMessageOptions, BotStreamEvent, CompleteAssistantMessageOptions, ConnectionState, RealtimeSessionOptions, RealtimeSessionRegistry, RealtimeSessionRegistryProps, RealtimeSessionState, RealtimeSessionTarget, SSEEvent, SdkSessionAttachment, SdkSessionEvent, SdkSessionSeed, TaskStreamEvent, TerminalStreamEvent, UseAuthOptions, UseAuthResult, UseRunGroupsOptions, UseSSEStreamOptions, UseSSEStreamResult, UseSdkSessionOptions, UseSdkSessionReturn, UseToolCallStreamReturn, createAuthFetcher, useApiKey, useAuth, useAutoScroll, useDropdownMenu, useLiveTime, useRealtimeSession, useRunCollapseState, useRunGroups, useSSEStream, useSdkSession, useToolCallStream } from '@tangle-network/ui/hooks';
2
- import { AgentInteractiveSessionControlClaim } from '@tangle-network/agent-interface';
3
- import * as _tanstack_react_query from '@tanstack/react-query';
4
- import { Session } from './types.js';
5
- export { f as SESSION_STREAM_RECONNECT_DELAY_MS, g as SendMessageOptions, S as SessionDegradation, a as SessionInfo, h as SessionStreamError, b as SidecarAuth, U as UseSessionStreamOptions, c as UseSessionStreamResult, d as UseSidecarAuthOptions, u as useSessionStream, e as useSidecarAuth } from './sdk-hooks-Djkjq4cp.js';
6
- import '@tangle-network/ui/types';
7
- import '@tangle-network/ui/stores';
8
- import '@tangle-network/ui/sdk-hooks';
9
-
10
- interface UsePtySessionOptions {
11
- /** Base URL of the sidecar (e.g. "http://localhost:9100"). */
12
- apiUrl: string;
13
- /** Bearer token for authentication. */
14
- token: string;
15
- /** Called with raw PTY output (may contain ANSI escape codes). */
16
- onData: (data: string) => void;
17
- /**
18
- * Stable id identifying this terminal connection to the sidecar.
19
- * Reused on every connect/reconnect so the sidecar restores the same
20
- * PTY session (within its reconnect window) instead of spawning a
21
- * fresh shell. When omitted, a random id is generated per connect —
22
- * so the session does not survive a remount.
23
- */
24
- connectionId?: string;
25
- /**
26
- * Exact incarnation issued for an interactive agent session. When present,
27
- * it must be sent with `control` on every WebSocket init frame.
28
- */
29
- incarnationId?: string;
30
- /** Write claim for the exact interactive agent session. */
31
- control?: AgentInteractiveSessionControlClaim;
1
+ import { t as Session } from "./sidecar-DgH_vQ6m.js";
2
+ import { a as SendMessageOptions, c as SessionStreamError, d as useSessionStream, i as SESSION_STREAM_RECONNECT_DELAY_MS, l as UseSessionStreamOptions, n as UseSidecarAuthOptions, o as SessionDegradation, r as useSidecarAuth, s as SessionInfo, t as SidecarAuth, u as UseSessionStreamResult } from "./use-sidecar-auth-CCTJcrq7.js";
3
+ import { AgentInteractiveSessionControlClaim } from "@tangle-network/agent-interface";
4
+ import { AgentStreamEvent, AppendUserMessageOptions, ApplySdkEventOptions, AuthUser, AutomationStreamEvent, BeginAssistantMessageOptions, BotStreamEvent, CompleteAssistantMessageOptions, ConnectionState, RealtimeSessionOptions, RealtimeSessionRegistry, RealtimeSessionRegistryProps, RealtimeSessionState, RealtimeSessionTarget, SSEEvent, SdkSessionAttachment, SdkSessionEvent, SdkSessionSeed, TaskStreamEvent, TerminalStreamEvent, UseAuthOptions, UseAuthResult, UseRunGroupsOptions, UseSSEStreamOptions, UseSSEStreamResult, UseSdkSessionOptions, UseSdkSessionReturn, UseToolCallStreamReturn, createAuthFetcher, useApiKey, useAuth, useAutoScroll, useDropdownMenu, useLiveTime, useRealtimeSession, useRunCollapseState, useRunGroups, useSSEStream, useSdkSession, useToolCallStream } from "@tangle-network/ui/hooks";
5
+ //#region src/hooks/use-pty-session.d.ts
6
+ export interface UsePtySessionOptions {
7
+ /** Base URL of the sidecar (e.g. "http://localhost:9100"). */
8
+ apiUrl: string;
9
+ /** Bearer token for authentication. */
10
+ token: string;
11
+ /** Called with raw PTY output (may contain ANSI escape codes). */
12
+ onData: (data: string) => void;
13
+ /**
14
+ * Stable id identifying this terminal connection to the sidecar.
15
+ * Reused on every connect/reconnect so the sidecar restores the same
16
+ * PTY session (within its reconnect window) instead of spawning a
17
+ * fresh shell. When omitted, a random id is generated per connect —
18
+ * so the session does not survive a remount.
19
+ */
20
+ connectionId?: string;
21
+ /**
22
+ * Exact incarnation issued for an interactive agent session. When present,
23
+ * it must be sent with `control` on every WebSocket init frame.
24
+ */
25
+ incarnationId?: string;
26
+ /** Write claim for the exact interactive agent session. */
27
+ control?: AgentInteractiveSessionControlClaim;
32
28
  }
33
- interface UsePtySessionReturn {
34
- /** Whether the underlying transport is connected and receiving data. */
35
- isConnected: boolean;
36
- /** Connection or API error, if any. */
37
- error: string | null;
38
- /** Send a command to the PTY session. */
39
- sendCommand: (command: string) => Promise<void>;
40
- /** Safely resize the remote PTY. */
41
- resizeTerminal: (cols: number, rows: number) => Promise<void>;
42
- /** Tear down and reconnect. */
43
- reconnect: () => void;
29
+ export interface UsePtySessionReturn {
30
+ /** Whether the underlying transport is connected and receiving data. */
31
+ isConnected: boolean;
32
+ /** Connection or API error, if any. */
33
+ error: string | null;
34
+ /** Send a command to the PTY session. */
35
+ sendCommand: (command: string) => Promise<void>;
36
+ /** Safely resize the remote PTY. */
37
+ resizeTerminal: (cols: number, rows: number) => Promise<void>;
38
+ /** Tear down and reconnect. */
39
+ reconnect: () => void;
44
40
  }
45
41
  /**
46
42
  * Manages a PTY session against the sidecar terminal API.
@@ -66,143 +62,145 @@ interface UsePtySessionReturn {
66
62
  * preserved as a fallback so the hook keeps working against
67
63
  * deployments that have not yet shipped the WS endpoint.
68
64
  */
69
- declare function usePtySession({ apiUrl, token, onData, connectionId: providedConnectionId, incarnationId, control, }: UsePtySessionOptions): UsePtySessionReturn;
70
-
65
+ export declare function usePtySession({ apiUrl, token, onData, connectionId: providedConnectionId, incarnationId, control }: UsePtySessionOptions): UsePtySessionReturn;
66
+ //#endregion
67
+ //#region src/hooks/use-sandbox-metrics.d.ts
71
68
  /**
72
69
  * Sandbox-level telemetry collected by the sidecar from cgroup v2
73
70
  * (Docker) or /proc (Firecracker guest). `cpuPercent` is computed
74
71
  * server-side from consecutive samples; sections are null when the
75
72
  * source cannot provide them.
76
73
  */
77
- interface SystemMetricsSnapshot {
78
- cpuPercent: number | null;
79
- cpuCores: number;
80
- memory: {
81
- usedBytes: number;
82
- totalBytes: number;
83
- } | null;
84
- disk: {
85
- usedBytes: number;
86
- totalBytes: number;
87
- path: string;
88
- } | null;
89
- source: "cgroup-v2" | "proc";
74
+ export interface SystemMetricsSnapshot {
75
+ cpuPercent: number | null;
76
+ cpuCores: number;
77
+ memory: {
78
+ usedBytes: number;
79
+ totalBytes: number;
80
+ } | null;
81
+ disk: {
82
+ usedBytes: number;
83
+ totalBytes: number;
84
+ path: string;
85
+ } | null;
86
+ source: "cgroup-v2" | "proc";
90
87
  }
91
- interface LatencyPercentiles {
92
- p50: number | null;
93
- p95: number | null;
94
- sampleCount: number;
88
+ export interface LatencyPercentiles {
89
+ p50: number | null;
90
+ p95: number | null;
91
+ sampleCount: number;
95
92
  }
96
- interface SandboxLatencyMetrics {
97
- ttftMs: LatencyPercentiles;
98
- firstResponseMs: LatencyPercentiles;
99
- runDurationMs: LatencyPercentiles;
93
+ export interface SandboxLatencyMetrics {
94
+ ttftMs: LatencyPercentiles;
95
+ firstResponseMs: LatencyPercentiles;
96
+ runDurationMs: LatencyPercentiles;
100
97
  }
101
98
  /**
102
99
  * Shape returned by the sidecar `/metrics/json` endpoint. Only the
103
100
  * fields read by this hook are modeled; the sidecar may add more.
104
101
  */
105
- interface SidecarMetricsPayload {
106
- process?: {
107
- memoryBytes?: {
108
- rss?: number;
109
- heapTotal?: number;
110
- heapUsed?: number;
111
- external?: number;
112
- arrayBuffers?: number;
113
- };
114
- cpuSeconds?: {
115
- user?: number;
116
- system?: number;
117
- };
102
+ export interface SidecarMetricsPayload {
103
+ process?: {
104
+ memoryBytes?: {
105
+ rss?: number;
106
+ heapTotal?: number;
107
+ heapUsed?: number;
108
+ external?: number;
109
+ arrayBuffers?: number;
118
110
  };
119
- system?: SystemMetricsSnapshot | null;
120
- latency?: SandboxLatencyMetrics;
111
+ cpuSeconds?: {
112
+ user?: number;
113
+ system?: number;
114
+ };
115
+ };
116
+ system?: SystemMetricsSnapshot | null;
117
+ latency?: SandboxLatencyMetrics;
121
118
  }
122
119
  /**
123
120
  * One polled time-series point, sourced from the sandbox-level
124
121
  * `system` section. Null values mean the sidecar could not provide
125
122
  * that reading — charts must render a gap, not a zero.
126
123
  */
127
- interface SandboxMetricsSample {
128
- /** Wall-clock ms when the sample was committed client-side. */
129
- at: number;
130
- cpuPercent: number | null;
131
- memoryUsedBytes: number | null;
132
- memoryTotalBytes: number | null;
133
- diskUsedBytes: number | null;
134
- diskTotalBytes: number | null;
124
+ export interface SandboxMetricsSample {
125
+ /** Wall-clock ms when the sample was committed client-side. */
126
+ at: number;
127
+ cpuPercent: number | null;
128
+ memoryUsedBytes: number | null;
129
+ memoryTotalBytes: number | null;
130
+ diskUsedBytes: number | null;
131
+ diskTotalBytes: number | null;
135
132
  }
136
- interface SandboxMetrics {
137
- /**
138
- * CPU% derived from consecutive samples. `null` on the first sample
139
- * because a delta is required. Can exceed 100 on multi-core hosts.
140
- */
141
- cpuPercent: number | null;
142
- rssBytes: number;
143
- heapUsedBytes: number;
144
- heapTotalBytes: number;
133
+ export interface SandboxMetrics {
134
+ /**
135
+ * CPU% derived from consecutive samples. `null` on the first sample
136
+ * because a delta is required. Can exceed 100 on multi-core hosts.
137
+ */
138
+ cpuPercent: number | null;
139
+ rssBytes: number;
140
+ heapUsedBytes: number;
141
+ heapTotalBytes: number;
145
142
  }
146
- interface UseSandboxMetricsOptions {
147
- /** Sandbox API base URL, e.g. `https://api.tangle.tools`. */
148
- apiBaseUrl: string;
149
- /** Sandbox id; when falsy the hook stays idle. */
150
- sandboxId?: string | null;
151
- /**
152
- * Optional bearer token. When omitted the fetch still sends
153
- * credentials so a cookie session can authenticate the proxy.
154
- */
155
- token?: string | null;
156
- /** Pause polling when false. Defaults to true. */
157
- enabled?: boolean;
158
- /** Poll cadence; clamped to a 500ms floor. Defaults to 3000. */
159
- intervalMs?: number;
160
- /** Max retained history samples for charting. Defaults to 120. */
161
- historyLimit?: number;
143
+ export interface UseSandboxMetricsOptions {
144
+ /** Sandbox API base URL, e.g. `https://api.tangle.tools`. */
145
+ apiBaseUrl: string;
146
+ /** Sandbox id; when falsy the hook stays idle. */
147
+ sandboxId?: string | null;
148
+ /**
149
+ * Optional bearer token. When omitted the fetch still sends
150
+ * credentials so a cookie session can authenticate the proxy.
151
+ */
152
+ token?: string | null;
153
+ /** Pause polling when false. Defaults to true. */
154
+ enabled?: boolean;
155
+ /** Poll cadence; clamped to a 500ms floor. Defaults to 3000. */
156
+ intervalMs?: number;
157
+ /** Max retained history samples for charting. Defaults to 120. */
158
+ historyLimit?: number;
162
159
  }
163
- interface UseSandboxMetricsResult {
164
- metrics: SandboxMetrics | null;
165
- /**
166
- * Sandbox-level (container/VM) telemetry. Null until the sidecar
167
- * reports a `system` section — older sidecars never will, and
168
- * consumers must surface that as "unavailable", not zeros.
169
- */
170
- system: SystemMetricsSnapshot | null;
171
- /** Agent latency percentiles (TTFT, first response, run duration). */
172
- latency: SandboxLatencyMetrics | null;
173
- /**
174
- * Rolling window of system samples (oldest first), capped at
175
- * `historyLimit`. Cleared when the target sandbox changes.
176
- */
177
- history: SandboxMetricsSample[];
178
- /**
179
- * True only until the first successful sample has arrived (or the
180
- * first one after the target `sandboxId` changes). Subsequent polls
181
- * do not flip this back to true, so consumers can gate a spinner
182
- * on it without it flashing on every cycle.
183
- */
184
- loading: boolean;
185
- error: Error | null;
186
- /** Wall-clock ms of the last successful sample, or null. */
187
- lastUpdatedAt: number | null;
160
+ export interface UseSandboxMetricsResult {
161
+ metrics: SandboxMetrics | null;
162
+ /**
163
+ * Sandbox-level (container/VM) telemetry. Null until the sidecar
164
+ * reports a `system` section — older sidecars never will, and
165
+ * consumers must surface that as "unavailable", not zeros.
166
+ */
167
+ system: SystemMetricsSnapshot | null;
168
+ /** Agent latency percentiles (TTFT, first response, run duration). */
169
+ latency: SandboxLatencyMetrics | null;
170
+ /**
171
+ * Rolling window of system samples (oldest first), capped at
172
+ * `historyLimit`. Cleared when the target sandbox changes.
173
+ */
174
+ history: SandboxMetricsSample[];
175
+ /**
176
+ * True only until the first successful sample has arrived (or the
177
+ * first one after the target `sandboxId` changes). Subsequent polls
178
+ * do not flip this back to true, so consumers can gate a spinner
179
+ * on it without it flashing on every cycle.
180
+ */
181
+ loading: boolean;
182
+ error: Error | null;
183
+ /** Wall-clock ms of the last successful sample, or null. */
184
+ lastUpdatedAt: number | null;
188
185
  }
189
186
  /**
190
187
  * Polls the sandbox's sidecar metrics through the API proxy and
191
188
  * derives a CPU% value from consecutive cumulative-CPU samples. Used
192
189
  * by the sandbox overview dashboard to drive live CPU/memory panels.
193
190
  */
194
- declare function useSandboxMetrics({ apiBaseUrl, sandboxId, token, enabled, intervalMs, historyLimit, }: UseSandboxMetricsOptions): UseSandboxMetricsResult;
195
-
191
+ export declare function useSandboxMetrics({ apiBaseUrl, sandboxId, token, enabled, intervalMs, historyLimit }: UseSandboxMetricsOptions): UseSandboxMetricsResult;
192
+ //#endregion
193
+ //#region src/hooks/use-session-crud.d.ts
196
194
  /** List all sessions for a sidecar. */
197
- declare function useSessions(apiUrl: string, token: string | null): _tanstack_react_query.UseQueryResult<NoInfer<Session[]>, Error>;
195
+ export declare function useSessions(apiUrl: string, token: string | null): import("@tanstack/react-query").UseQueryResult<Session[], Error>;
198
196
  /** Create a new session. */
199
- declare function useCreateSession(apiUrl: string, token: string | null): _tanstack_react_query.UseMutationResult<Session, Error, string, unknown>;
197
+ export declare function useCreateSession(apiUrl: string, token: string | null): import("@tanstack/react-query").UseMutationResult<Session, Error, string, unknown>;
200
198
  /** Delete a session by ID. */
201
- declare function useDeleteSession(apiUrl: string, token: string | null): _tanstack_react_query.UseMutationResult<unknown, Error, string, unknown>;
199
+ export declare function useDeleteSession(apiUrl: string, token: string | null): import("@tanstack/react-query").UseMutationResult<unknown, Error, string, unknown>;
202
200
  /** Rename a session. */
203
- declare function useRenameSession(apiUrl: string, token: string | null): _tanstack_react_query.UseMutationResult<Session, Error, {
204
- sessionId: string;
205
- title: string;
201
+ export declare function useRenameSession(apiUrl: string, token: string | null): import("@tanstack/react-query").UseMutationResult<Session, Error, {
202
+ sessionId: string;
203
+ title: string;
206
204
  }, unknown>;
207
-
208
- export { type LatencyPercentiles, type SandboxLatencyMetrics, type SandboxMetrics, type SandboxMetricsSample, type SidecarMetricsPayload, type SystemMetricsSnapshot, type UsePtySessionOptions, type UsePtySessionReturn, type UseSandboxMetricsOptions, type UseSandboxMetricsResult, useCreateSession, useDeleteSession, usePtySession, useRenameSession, useSandboxMetrics, useSessions };
205
+ //#endregion
206
+ export { type AgentStreamEvent, type AppendUserMessageOptions, type ApplySdkEventOptions, type AuthUser, type AutomationStreamEvent, type BeginAssistantMessageOptions, type BotStreamEvent, type CompleteAssistantMessageOptions, type ConnectionState, type RealtimeSessionOptions, RealtimeSessionRegistry, type RealtimeSessionRegistryProps, type RealtimeSessionState, type RealtimeSessionTarget, SESSION_STREAM_RECONNECT_DELAY_MS, type SSEEvent, type SdkSessionAttachment, type SdkSessionEvent, type SdkSessionSeed, SendMessageOptions, SessionDegradation, SessionInfo, SessionStreamError, SidecarAuth, type TaskStreamEvent, type TerminalStreamEvent, type UseAuthOptions, type UseAuthResult, type UseRunGroupsOptions, type UseSSEStreamOptions, type UseSSEStreamResult, type UseSdkSessionOptions, type UseSdkSessionReturn, UseSessionStreamOptions, UseSessionStreamResult, UseSidecarAuthOptions, type UseToolCallStreamReturn, createAuthFetcher, useApiKey, useAuth, useAutoScroll, useDropdownMenu, useLiveTime, useRealtimeSession, useRunCollapseState, useRunGroups, useSSEStream, useSdkSession, useSessionStream, useSidecarAuth, useToolCallStream };
package/dist/hooks.js CHANGED
@@ -1,55 +1,222 @@
1
- import {
2
- RealtimeSessionRegistry,
3
- createAuthFetcher,
4
- useApiKey,
5
- useAuth,
6
- useAutoScroll,
7
- useCreateSession,
8
- useDeleteSession,
9
- useDropdownMenu,
10
- useLiveTime,
11
- useRealtimeSession,
12
- useRenameSession,
13
- useRunCollapseState,
14
- useRunGroups,
15
- useSSEStream,
16
- useSandboxMetrics,
17
- useSdkSession,
18
- useSessions,
19
- useToolCallStream
20
- } from "./chunk-SOKKTB7W.js";
21
- import {
22
- SESSION_STREAM_RECONNECT_DELAY_MS,
23
- SessionStreamError,
24
- useSessionStream,
25
- useSidecarAuth
26
- } from "./chunk-72UF2H5H.js";
27
- import {
28
- usePtySession
29
- } from "./chunk-MYZAW4RX.js";
30
- import "./chunk-CZ7CSFO4.js";
31
- export {
32
- RealtimeSessionRegistry,
33
- SESSION_STREAM_RECONNECT_DELAY_MS,
34
- SessionStreamError,
35
- createAuthFetcher,
36
- useApiKey,
37
- useAuth,
38
- useAutoScroll,
39
- useCreateSession,
40
- useDeleteSession,
41
- useDropdownMenu,
42
- useLiveTime,
43
- usePtySession,
44
- useRealtimeSession,
45
- useRenameSession,
46
- useRunCollapseState,
47
- useRunGroups,
48
- useSSEStream,
49
- useSandboxMetrics,
50
- useSdkSession,
51
- useSessionStream,
52
- useSessions,
53
- useSidecarAuth,
54
- useToolCallStream
55
- };
1
+ import { t as usePtySession } from "./use-pty-session-C8cE0adT.js";
2
+ import { i as useSessionStream, n as SESSION_STREAM_RECONNECT_DELAY_MS, r as SessionStreamError, t as useSidecarAuth } from "./use-sidecar-auth-DkdcufOz.js";
3
+ import * as React$1 from "react";
4
+ import { RealtimeSessionRegistry, createAuthFetcher, useApiKey, useAuth, useAutoScroll, useDropdownMenu, useLiveTime, useRealtimeSession, useRunCollapseState, useRunGroups, useSSEStream, useSdkSession, useToolCallStream } from "@tangle-network/ui/hooks";
5
+ import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
6
+ //#region src/hooks/use-sandbox-metrics.ts
7
+ /**
8
+ * Polls the sandbox's sidecar metrics through the API proxy and
9
+ * derives a CPU% value from consecutive cumulative-CPU samples. Used
10
+ * by the sandbox overview dashboard to drive live CPU/memory panels.
11
+ */
12
+ function useSandboxMetrics({ apiBaseUrl, sandboxId, token, enabled = true, intervalMs = 3e3, historyLimit = 120 }) {
13
+ const [metrics, setMetrics] = React$1.useState(null);
14
+ const [system, setSystem] = React$1.useState(null);
15
+ const [latency, setLatency] = React$1.useState(null);
16
+ const [history, setHistory] = React$1.useState([]);
17
+ const [loading, setLoading] = React$1.useState(false);
18
+ const [error, setError] = React$1.useState(null);
19
+ const [lastUpdatedAt, setLastUpdatedAt] = React$1.useState(null);
20
+ const sampleRef = React$1.useRef(null);
21
+ const hasLoadedRef = React$1.useRef(false);
22
+ const prevSandboxIdRef = React$1.useRef(null);
23
+ React$1.useEffect(() => {
24
+ const sandboxCleared = !sandboxId || !apiBaseUrl;
25
+ const sandboxChanged = prevSandboxIdRef.current !== null && prevSandboxIdRef.current !== sandboxId;
26
+ if (sandboxCleared && prevSandboxIdRef.current !== null || sandboxChanged) {
27
+ sampleRef.current = null;
28
+ hasLoadedRef.current = false;
29
+ setMetrics(null);
30
+ setSystem(null);
31
+ setLatency(null);
32
+ setHistory([]);
33
+ setLastUpdatedAt(null);
34
+ setError(null);
35
+ if (sandboxCleared) setLoading(false);
36
+ }
37
+ prevSandboxIdRef.current = sandboxId ?? null;
38
+ if (!enabled || sandboxCleared) return;
39
+ const controller = new AbortController();
40
+ let cancelled = false;
41
+ let timeoutId = null;
42
+ const delay = Math.max(intervalMs, 500);
43
+ const fetchOnce = async () => {
44
+ if (!hasLoadedRef.current) setLoading(true);
45
+ try {
46
+ const headers = {};
47
+ if (token) headers.Authorization = `Bearer ${token}`;
48
+ const res = await fetch(`${apiBaseUrl}/v1/sidecar-proxy/${encodeURIComponent(sandboxId)}/metrics/json`, {
49
+ method: "GET",
50
+ credentials: "include",
51
+ headers,
52
+ signal: controller.signal
53
+ });
54
+ if (!res.ok) throw new Error(`Metrics request failed (HTTP ${res.status})`);
55
+ const data = await res.json();
56
+ const cpuSeconds = (data?.process?.cpuSeconds?.user ?? 0) + (data?.process?.cpuSeconds?.system ?? 0);
57
+ const wallMs = Date.now();
58
+ if (cancelled) return;
59
+ let cpuPercent = null;
60
+ const prev = sampleRef.current;
61
+ if (prev && prev.sandboxId === sandboxId) {
62
+ const dCpu = cpuSeconds - prev.cpuSeconds;
63
+ const dWallSec = (wallMs - prev.wallMs) / 1e3;
64
+ if (dWallSec > 0 && dCpu >= 0) cpuPercent = dCpu / dWallSec * 100;
65
+ }
66
+ sampleRef.current = {
67
+ cpuSeconds,
68
+ wallMs,
69
+ sandboxId
70
+ };
71
+ setMetrics({
72
+ cpuPercent,
73
+ rssBytes: data?.process?.memoryBytes?.rss ?? 0,
74
+ heapUsedBytes: data?.process?.memoryBytes?.heapUsed ?? 0,
75
+ heapTotalBytes: data?.process?.memoryBytes?.heapTotal ?? 0
76
+ });
77
+ const sys = data?.system ?? null;
78
+ setSystem(sys);
79
+ setLatency(data?.latency ?? null);
80
+ if (sys) {
81
+ const sample = {
82
+ at: wallMs,
83
+ cpuPercent: sys.cpuPercent,
84
+ memoryUsedBytes: sys.memory?.usedBytes ?? null,
85
+ memoryTotalBytes: sys.memory?.totalBytes ?? null,
86
+ diskUsedBytes: sys.disk?.usedBytes ?? null,
87
+ diskTotalBytes: sys.disk?.totalBytes ?? null
88
+ };
89
+ setHistory((prevHistory) => {
90
+ const next = [...prevHistory, sample];
91
+ return next.length > historyLimit ? next.slice(next.length - historyLimit) : next;
92
+ });
93
+ }
94
+ setLastUpdatedAt(wallMs);
95
+ setError(null);
96
+ hasLoadedRef.current = true;
97
+ setLoading(false);
98
+ } catch (err) {
99
+ if (cancelled || err instanceof DOMException && err.name === "AbortError") return;
100
+ setError(err instanceof Error ? err : new Error(String(err)));
101
+ if (!hasLoadedRef.current) setLoading(false);
102
+ }
103
+ };
104
+ const runLoop = async () => {
105
+ if (cancelled) return;
106
+ await fetchOnce();
107
+ if (cancelled) return;
108
+ timeoutId = window.setTimeout(runLoop, delay);
109
+ };
110
+ runLoop();
111
+ return () => {
112
+ cancelled = true;
113
+ controller.abort();
114
+ if (timeoutId !== null) window.clearTimeout(timeoutId);
115
+ };
116
+ }, [
117
+ apiBaseUrl,
118
+ sandboxId,
119
+ token,
120
+ enabled,
121
+ intervalMs,
122
+ historyLimit
123
+ ]);
124
+ return {
125
+ metrics,
126
+ system,
127
+ latency,
128
+ history,
129
+ loading,
130
+ error,
131
+ lastUpdatedAt
132
+ };
133
+ }
134
+ //#endregion
135
+ //#region src/hooks/use-session-crud.ts
136
+ async function sessionFetch(apiUrl, token, path, opts) {
137
+ const res = await fetch(`${apiUrl}${path}`, {
138
+ ...opts,
139
+ headers: {
140
+ "Content-Type": "application/json",
141
+ Authorization: `Bearer ${token}`,
142
+ ...opts?.headers ?? {}
143
+ }
144
+ });
145
+ if (!res.ok) {
146
+ const text = await res.text();
147
+ throw new Error(text || `API error: ${res.status}`);
148
+ }
149
+ return res.json();
150
+ }
151
+ /** List all sessions for a sidecar. */
152
+ function useSessions(apiUrl, token) {
153
+ return useQuery({
154
+ queryKey: [
155
+ "sessions",
156
+ apiUrl,
157
+ token
158
+ ],
159
+ queryFn: () => sessionFetch(apiUrl, token, "/session/sessions"),
160
+ enabled: !!token,
161
+ staleTime: 3e4
162
+ });
163
+ }
164
+ /** Create a new session. */
165
+ function useCreateSession(apiUrl, token) {
166
+ const queryClient = useQueryClient();
167
+ return useMutation({
168
+ mutationFn: async (title) => {
169
+ return sessionFetch(apiUrl, token, "/session/sessions", {
170
+ method: "POST",
171
+ body: JSON.stringify({
172
+ title,
173
+ backend: { type: "opencode" }
174
+ })
175
+ });
176
+ },
177
+ onSuccess: () => {
178
+ queryClient.invalidateQueries({ queryKey: [
179
+ "sessions",
180
+ apiUrl,
181
+ token
182
+ ] });
183
+ }
184
+ });
185
+ }
186
+ /** Delete a session by ID. */
187
+ function useDeleteSession(apiUrl, token) {
188
+ const queryClient = useQueryClient();
189
+ return useMutation({
190
+ mutationFn: async (sessionId) => {
191
+ return sessionFetch(apiUrl, token, `/session/sessions/${encodeURIComponent(sessionId)}`, { method: "DELETE" });
192
+ },
193
+ onSuccess: () => {
194
+ queryClient.invalidateQueries({ queryKey: [
195
+ "sessions",
196
+ apiUrl,
197
+ token
198
+ ] });
199
+ }
200
+ });
201
+ }
202
+ /** Rename a session. */
203
+ function useRenameSession(apiUrl, token) {
204
+ const queryClient = useQueryClient();
205
+ return useMutation({
206
+ mutationFn: async ({ sessionId, title }) => {
207
+ return sessionFetch(apiUrl, token, `/session/sessions/${encodeURIComponent(sessionId)}`, {
208
+ method: "PATCH",
209
+ body: JSON.stringify({ title })
210
+ });
211
+ },
212
+ onSuccess: () => {
213
+ queryClient.invalidateQueries({ queryKey: [
214
+ "sessions",
215
+ apiUrl,
216
+ token
217
+ ] });
218
+ }
219
+ });
220
+ }
221
+ //#endregion
222
+ export { RealtimeSessionRegistry, SESSION_STREAM_RECONNECT_DELAY_MS, SessionStreamError, createAuthFetcher, useApiKey, useAuth, useAutoScroll, useCreateSession, useDeleteSession, useDropdownMenu, useLiveTime, usePtySession, useRealtimeSession, useRenameSession, useRunCollapseState, useRunGroups, useSSEStream, useSandboxMetrics, useSdkSession, useSessionStream, useSessions, useSidecarAuth, useToolCallStream };