@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.
- package/dist/WorkflowGraph-B-NsdYz_.js +1961 -0
- package/dist/assets.d.ts +214 -206
- package/dist/assets.js +1057 -908
- package/dist/auth-CWe17Hly.js +37 -0
- package/dist/auth.d.ts +2 -30
- package/dist/auth.js +2 -15
- package/dist/chat-BOvFAe6p.js +903 -0
- package/dist/chat.d.ts +2 -230
- package/dist/chat.js +2 -34
- package/dist/connectors.d.ts +52 -49
- package/dist/connectors.js +595 -643
- package/dist/dashboard-CZ3VgNPR.js +4969 -0
- package/dist/dashboard.d.ts +4 -1297
- package/dist/dashboard.js +4 -152
- package/dist/editor.d.ts +2 -1
- package/dist/editor.js +2 -31
- package/dist/files.d.ts +2 -6
- package/dist/files.js +2 -33
- package/dist/globals.css +63 -3
- package/dist/hooks.d.ts +146 -148
- package/dist/hooks.js +222 -55
- package/dist/index-CKRaj1pM.d.ts +776 -0
- package/dist/index-CXX5IpH2.d.ts +2 -0
- package/dist/index-DPePq7c8.d.ts +1340 -0
- package/dist/index-DiyLLZuJ.d.ts +230 -0
- package/dist/index-DvmZLMT1.d.ts +30 -0
- package/dist/index-I8ZLVtHd.d.ts +330 -0
- package/dist/index-PRM636Ex.d.ts +86 -0
- package/dist/index.d.ts +21 -33
- package/dist/index.js +21 -701
- package/dist/info-panel-C9cqDzOL.js +594 -0
- package/dist/integrations.d.ts +133 -139
- package/dist/integrations.js +491 -673
- package/dist/markdown.d.ts +2 -1
- package/dist/markdown.js +2 -13
- package/dist/model-I-NIxeM-.js +1250 -0
- package/dist/model-brand-B9A4H9pJ.d.ts +98 -0
- package/dist/model-brand-hMyDTUqB.js +624 -0
- package/dist/motion-DkyBRJb9.js +37 -0
- package/dist/openui.d.ts +2 -1
- package/dist/openui.js +2 -7
- package/dist/pages.d.ts +307 -300
- package/dist/pages.js +4404 -4181
- package/dist/primitives-Dh1vG6J3.js +113 -0
- package/dist/primitives.d.ts +2 -74
- package/dist/primitives.js +2 -204
- package/dist/provider-logo-DjqmConF.js +311 -0
- package/dist/run.d.ts +2 -1
- package/dist/run.js +2 -23
- package/dist/sdk-hooks.d.ts +3 -4
- package/dist/sdk-hooks.js +3 -31
- package/dist/sidecar-DgH_vQ6m.d.ts +9 -0
- package/dist/stores.d.ts +14 -15
- package/dist/stores.js +13 -81
- package/dist/styles.css +63 -3
- package/dist/template-card-L-4gmjx2.d.ts +90 -0
- package/dist/terminal-CN9ZgHRt.js +197 -0
- package/dist/terminal.d.ts +60 -60
- package/dist/terminal.js +2 -10
- package/dist/tokens.css +51 -0
- package/dist/types.d.ts +4 -11
- package/dist/types.js +0 -1
- package/dist/use-pty-session-C8cE0adT.js +669 -0
- package/dist/use-sidecar-auth-CCTJcrq7.d.ts +145 -0
- package/dist/use-sidecar-auth-DkdcufOz.js +742 -0
- package/dist/utils-DzWbktWG.js +2 -0
- package/dist/utils.d.ts +2 -1
- package/dist/utils.js +2 -37
- package/dist/workbench-BCaCKl-J.js +8347 -0
- package/dist/workbench.d.ts +2 -310
- package/dist/workbench.js +2 -44
- package/dist/workflows.d.ts +341 -339
- package/dist/workflows.js +74 -109
- package/dist/workspace-B6AtI6ld.js +2510 -0
- package/dist/workspace.d.ts +2 -761
- package/dist/workspace.js +2 -51
- package/package.json +46 -40
- package/dist/WorkflowGraph-2QOORYIR.js +0 -1722
- package/dist/chunk-2BUPSB7O.js +0 -0
- package/dist/chunk-3KBNPQQF.js +0 -2697
- package/dist/chunk-3LIXVEEE.js +0 -279
- package/dist/chunk-72UF2H5H.js +0 -707
- package/dist/chunk-AI25G5MX.js +0 -944
- package/dist/chunk-ANSC5AFC.js +0 -314
- package/dist/chunk-AZ3AWMTM.js +0 -8
- package/dist/chunk-BGVEHENC.js +0 -10
- package/dist/chunk-CZ7CSFO4.js +0 -39
- package/dist/chunk-DYXXYGS4.js +0 -4700
- package/dist/chunk-EI44GEQ5.js +0 -6
- package/dist/chunk-IACRDXER.js +0 -219
- package/dist/chunk-IOB2PW5Z.js +0 -55
- package/dist/chunk-M4K7ZGR2.js +0 -24
- package/dist/chunk-MYZAW4RX.js +0 -665
- package/dist/chunk-OMUIPJQZ.js +0 -555
- package/dist/chunk-RQZRXKMR.js +0 -398
- package/dist/chunk-SOKKTB7W.js +0 -230
- package/dist/chunk-TADGS4Q7.js +0 -1010
- package/dist/chunk-UCQNOUN3.js +0 -7964
- package/dist/chunk-ULPLRBMF.js +0 -34
- package/dist/chunk-WID73FPH.js +0 -89
- package/dist/chunk-X3YXP7FG.js +0 -38
- package/dist/logo-DiAjq759.d.ts +0 -15
- package/dist/model-brand-BNnaUKKZ.d.ts +0 -99
- package/dist/ports-list-CDIvTNnX.d.ts +0 -17
- package/dist/sdk-hooks-Djkjq4cp.d.ts +0 -145
- package/dist/template-card-Bn-Bw5xC.d.ts +0 -87
package/dist/hooks.d.ts
CHANGED
|
@@ -1,46 +1,42 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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
|
|
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
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
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
|
-
|
|
93
|
-
|
|
94
|
-
|
|
88
|
+
export interface LatencyPercentiles {
|
|
89
|
+
p50: number | null;
|
|
90
|
+
p95: number | null;
|
|
91
|
+
sampleCount: number;
|
|
95
92
|
}
|
|
96
|
-
interface SandboxLatencyMetrics {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
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
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
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
|
-
|
|
120
|
-
|
|
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
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
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
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
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
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
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
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
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
|
|
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):
|
|
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):
|
|
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):
|
|
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):
|
|
204
|
-
|
|
205
|
-
|
|
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
|
|
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
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
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 };
|