@tangle-network/sandbox-ui 0.13.0 → 0.15.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.
- package/dist/auth.d.ts +1 -74
- package/dist/auth.js +1 -4
- package/dist/chat.d.ts +1 -136
- package/dist/chat.js +2 -15
- package/dist/chunk-2BUPSB7O.js +0 -0
- package/dist/chunk-3J6FG3FJ.js +18 -0
- package/dist/chunk-76IQLPW2.js +206 -0
- package/dist/chunk-7ZA5SEK3.js +239 -0
- package/dist/{chunk-ESVYBDGA.js → chunk-AG7QDC2Q.js} +182 -2
- package/dist/chunk-AHBZCBDO.js +2960 -0
- package/dist/chunk-AZ3AWMTM.js +8 -0
- package/dist/chunk-CMY7W45U.js +380 -0
- package/dist/{chunk-QMU2PWOU.js → chunk-DNZ4DTNA.js} +71 -17
- package/dist/chunk-EI44GEQ5.js +6 -0
- package/dist/{chunk-5OQ27N57.js → chunk-GPT7VKK6.js} +34 -38
- package/dist/chunk-JBGKGLD7.js +16 -0
- package/dist/chunk-NJNME4J4.js +14 -0
- package/dist/chunk-QPAJR74X.js +20 -0
- package/dist/chunk-TK46XFLM.js +28 -0
- package/dist/chunk-WID73FPH.js +89 -0
- package/dist/chunk-YVXK4XRO.js +30 -0
- package/dist/dashboard.d.ts +538 -4
- package/dist/dashboard.js +15 -886
- package/dist/editor.d.ts +1 -120
- package/dist/editor.js +1 -5
- package/dist/files.d.ts +1 -129
- package/dist/files.js +2 -7
- package/dist/globals.css +5 -1265
- package/dist/hooks.d.ts +114 -11
- package/dist/hooks.js +17 -88
- package/dist/index.d.ts +24 -99
- package/dist/index.js +247 -252
- package/dist/markdown.d.ts +1 -29
- package/dist/markdown.js +2 -2
- package/dist/openui.d.ts +8 -115
- package/dist/openui.js +1 -6
- package/dist/pages.d.ts +1 -2
- package/dist/pages.js +68 -66
- package/dist/primitives.d.ts +14 -49
- package/dist/primitives.js +69 -77
- package/dist/run.d.ts +1 -14
- package/dist/run.js +2 -22
- package/dist/sdk-hooks.d.ts +3 -283
- package/dist/sdk-hooks.js +10 -14
- package/dist/stores.d.ts +2 -14
- package/dist/stores.js +11 -39
- package/dist/styles.css +5 -1265
- package/dist/{usage-chart-CPTcNlGs.d.ts → template-card-UhV3pmRC.d.ts} +16 -1
- package/dist/terminal.js +39 -2
- package/dist/types.d.ts +11 -8
- package/dist/types.js +1 -0
- package/dist/utils.d.ts +1 -44
- package/dist/utils.js +6 -12
- package/dist/workspace.d.ts +5 -10
- package/dist/workspace.js +3 -19
- package/package.json +23 -54
- package/dist/active-sessions-store-CeOmXgv5.d.ts +0 -85
- package/dist/artifact-pane-Bh45Ssco.d.ts +0 -24
- package/dist/branding-DCi5VEik.d.ts +0 -13
- package/dist/button-CMQuQEW_.d.ts +0 -17
- package/dist/chat-container-f4yEs6KN.d.ts +0 -106
- package/dist/chunk-34A66VBG.js +0 -214
- package/dist/chunk-34I7UFSX.js +0 -92
- package/dist/chunk-36QY2W5G.js +0 -802
- package/dist/chunk-4CLN43XT.js +0 -45
- package/dist/chunk-54SQQMMM.js +0 -156
- package/dist/chunk-66EZOYZR.js +0 -102
- package/dist/chunk-BX6AQMUS.js +0 -183
- package/dist/chunk-DI3NZ5ZX.js +0 -192
- package/dist/chunk-DPGIXDAI.js +0 -220
- package/dist/chunk-DXMIEK4K.js +0 -1426
- package/dist/chunk-GSZA3TSY.js +0 -79
- package/dist/chunk-HB5Y37YU.js +0 -54
- package/dist/chunk-LQNEZDRM.js +0 -109
- package/dist/chunk-MA7YKRUP.js +0 -131
- package/dist/chunk-MKTSMWVD.js +0 -109
- package/dist/chunk-MQXABZTB.js +0 -1348
- package/dist/chunk-MT5FJ3ZT.js +0 -186
- package/dist/chunk-NKUPJC34.js +0 -2070
- package/dist/chunk-OEX7NZE3.js +0 -321
- package/dist/chunk-OKLQVY3Y.js +0 -139
- package/dist/chunk-Q56BYXQF.js +0 -61
- package/dist/chunk-QD4QE5P5.js +0 -40
- package/dist/chunk-QDH5GEGY.js +0 -630
- package/dist/chunk-QID2OOMG.js +0 -133
- package/dist/chunk-RQHJBTEU.js +0 -10
- package/dist/chunk-T7HMZEVO.js +0 -216
- package/dist/chunk-U6QTHMY6.js +0 -1290
- package/dist/chunk-US6JKJKH.js +0 -124
- package/dist/chunk-VX3XOUEB.js +0 -63
- package/dist/chunk-XLG757B6.js +0 -933
- package/dist/chunk-ZMNSRDMH.js +0 -127
- package/dist/chunk-ZNCEM5CD.js +0 -316
- package/dist/document-editor-pane-A70-EhdQ.d.ts +0 -124
- package/dist/document-editor-pane-TLPVRBBU.js +0 -11
- package/dist/expanded-tool-detail-Dh99mcbY.d.ts +0 -63
- package/dist/file-tabs-BLfxfmAH.d.ts +0 -51
- package/dist/parts-CyGkM6Fp.d.ts +0 -50
- package/dist/run-CtFZ6s-D.d.ts +0 -41
- package/dist/sidebar-drop-zone-tDBsuOH5.d.ts +0 -301
- package/dist/sidecar-CFU2W9j1.d.ts +0 -8
- package/dist/template-card-BAtvcAkU.d.ts +0 -18
- package/dist/tool-call-feed-Bs3MyQMT.d.ts +0 -68
- package/dist/tool-display-Ct9nFAzJ.d.ts +0 -32
- package/dist/use-sandbox-metrics-B64diPqN.d.ts +0 -141
- package/dist/variant-list-BrHYcBCk.d.ts +0 -540
package/dist/chunk-DPGIXDAI.js
DELETED
|
@@ -1,220 +0,0 @@
|
|
|
1
|
-
// src/hooks/use-auth.ts
|
|
2
|
-
import * as React from "react";
|
|
3
|
-
function useAuth({
|
|
4
|
-
apiBaseUrl,
|
|
5
|
-
revalidateOnFocus = false,
|
|
6
|
-
shouldRetryOnError = false
|
|
7
|
-
}) {
|
|
8
|
-
const [user, setUser] = React.useState(null);
|
|
9
|
-
const [isLoading, setIsLoading] = React.useState(true);
|
|
10
|
-
const [error, setError] = React.useState(null);
|
|
11
|
-
const retryTimerRef = React.useRef(null);
|
|
12
|
-
const abortRef = React.useRef(null);
|
|
13
|
-
const fetchSession = React.useCallback(async () => {
|
|
14
|
-
abortRef.current?.abort();
|
|
15
|
-
const controller = new AbortController();
|
|
16
|
-
abortRef.current = controller;
|
|
17
|
-
setIsLoading(true);
|
|
18
|
-
setError(null);
|
|
19
|
-
try {
|
|
20
|
-
const res = await fetch(`${apiBaseUrl}/auth/session`, {
|
|
21
|
-
credentials: "include",
|
|
22
|
-
signal: controller.signal
|
|
23
|
-
});
|
|
24
|
-
if (!res.ok) {
|
|
25
|
-
throw new Error("Not authenticated");
|
|
26
|
-
}
|
|
27
|
-
const data = await res.json();
|
|
28
|
-
if (data.success && data.data) {
|
|
29
|
-
setUser(data.data);
|
|
30
|
-
} else {
|
|
31
|
-
setUser(null);
|
|
32
|
-
}
|
|
33
|
-
} catch (err) {
|
|
34
|
-
if (err.name === "AbortError") return;
|
|
35
|
-
setError(err instanceof Error ? err : new Error("Unknown error"));
|
|
36
|
-
setUser(null);
|
|
37
|
-
if (shouldRetryOnError) {
|
|
38
|
-
if (retryTimerRef.current) clearTimeout(retryTimerRef.current);
|
|
39
|
-
retryTimerRef.current = setTimeout(fetchSession, 5e3);
|
|
40
|
-
}
|
|
41
|
-
} finally {
|
|
42
|
-
if (!controller.signal.aborted) {
|
|
43
|
-
setIsLoading(false);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
}, [apiBaseUrl, shouldRetryOnError]);
|
|
47
|
-
React.useEffect(() => {
|
|
48
|
-
fetchSession();
|
|
49
|
-
return () => {
|
|
50
|
-
abortRef.current?.abort();
|
|
51
|
-
if (retryTimerRef.current) clearTimeout(retryTimerRef.current);
|
|
52
|
-
};
|
|
53
|
-
}, [fetchSession]);
|
|
54
|
-
React.useEffect(() => {
|
|
55
|
-
if (!revalidateOnFocus) return;
|
|
56
|
-
const handleFocus = () => {
|
|
57
|
-
fetchSession();
|
|
58
|
-
};
|
|
59
|
-
window.addEventListener("focus", handleFocus);
|
|
60
|
-
return () => window.removeEventListener("focus", handleFocus);
|
|
61
|
-
}, [revalidateOnFocus, fetchSession]);
|
|
62
|
-
return {
|
|
63
|
-
user,
|
|
64
|
-
isLoading,
|
|
65
|
-
isError: !!error,
|
|
66
|
-
error,
|
|
67
|
-
mutate: fetchSession
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
function createAuthFetcher(_apiBaseUrl) {
|
|
71
|
-
return async function authFetcher(url, options) {
|
|
72
|
-
const res = await fetch(url, {
|
|
73
|
-
...options,
|
|
74
|
-
credentials: "include",
|
|
75
|
-
headers: {
|
|
76
|
-
...options?.headers
|
|
77
|
-
}
|
|
78
|
-
});
|
|
79
|
-
if (!res.ok) {
|
|
80
|
-
throw new Error(`Request failed with status ${res.status}`);
|
|
81
|
-
}
|
|
82
|
-
return res.json();
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
|
-
function useApiKey() {
|
|
86
|
-
const [apiKey, setApiKey] = React.useState(null);
|
|
87
|
-
React.useEffect(() => {
|
|
88
|
-
if (typeof window !== "undefined") {
|
|
89
|
-
setApiKey(localStorage.getItem("apiKey"));
|
|
90
|
-
}
|
|
91
|
-
}, []);
|
|
92
|
-
return apiKey;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
// src/hooks/use-live-time.ts
|
|
96
|
-
import * as React2 from "react";
|
|
97
|
-
function useLiveTime(intervalMs = 1e3) {
|
|
98
|
-
const [now, setNow] = React2.useState(() => Date.now());
|
|
99
|
-
React2.useEffect(() => {
|
|
100
|
-
const requested = Number.isFinite(intervalMs) && intervalMs > 0 ? intervalMs : 1e3;
|
|
101
|
-
const delay = Math.max(requested, 100);
|
|
102
|
-
const id = window.setInterval(() => {
|
|
103
|
-
setNow(Date.now());
|
|
104
|
-
}, delay);
|
|
105
|
-
return () => {
|
|
106
|
-
window.clearInterval(id);
|
|
107
|
-
};
|
|
108
|
-
}, [intervalMs]);
|
|
109
|
-
return now;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
// src/hooks/use-sandbox-metrics.ts
|
|
113
|
-
import * as React3 from "react";
|
|
114
|
-
function useSandboxMetrics({
|
|
115
|
-
apiBaseUrl,
|
|
116
|
-
sandboxId,
|
|
117
|
-
token,
|
|
118
|
-
enabled = true,
|
|
119
|
-
intervalMs = 3e3
|
|
120
|
-
}) {
|
|
121
|
-
const [metrics, setMetrics] = React3.useState(null);
|
|
122
|
-
const [loading, setLoading] = React3.useState(false);
|
|
123
|
-
const [error, setError] = React3.useState(null);
|
|
124
|
-
const [lastUpdatedAt, setLastUpdatedAt] = React3.useState(null);
|
|
125
|
-
const sampleRef = React3.useRef(null);
|
|
126
|
-
const hasLoadedRef = React3.useRef(false);
|
|
127
|
-
const prevSandboxIdRef = React3.useRef(null);
|
|
128
|
-
React3.useEffect(() => {
|
|
129
|
-
const sandboxCleared = !sandboxId || !apiBaseUrl;
|
|
130
|
-
const sandboxChanged = prevSandboxIdRef.current !== null && prevSandboxIdRef.current !== sandboxId;
|
|
131
|
-
if (sandboxCleared && prevSandboxIdRef.current !== null || sandboxChanged) {
|
|
132
|
-
sampleRef.current = null;
|
|
133
|
-
hasLoadedRef.current = false;
|
|
134
|
-
setMetrics(null);
|
|
135
|
-
setLastUpdatedAt(null);
|
|
136
|
-
setError(null);
|
|
137
|
-
if (sandboxCleared) setLoading(false);
|
|
138
|
-
}
|
|
139
|
-
prevSandboxIdRef.current = sandboxId ?? null;
|
|
140
|
-
if (!enabled || sandboxCleared) {
|
|
141
|
-
return;
|
|
142
|
-
}
|
|
143
|
-
const controller = new AbortController();
|
|
144
|
-
let cancelled = false;
|
|
145
|
-
let timeoutId = null;
|
|
146
|
-
const delay = Math.max(intervalMs, 500);
|
|
147
|
-
const fetchOnce = async () => {
|
|
148
|
-
if (!hasLoadedRef.current) setLoading(true);
|
|
149
|
-
try {
|
|
150
|
-
const headers = {};
|
|
151
|
-
if (token) headers.Authorization = `Bearer ${token}`;
|
|
152
|
-
const res = await fetch(
|
|
153
|
-
`${apiBaseUrl}/v1/sidecar-proxy/${encodeURIComponent(sandboxId)}/metrics/json`,
|
|
154
|
-
{
|
|
155
|
-
method: "GET",
|
|
156
|
-
credentials: "include",
|
|
157
|
-
headers,
|
|
158
|
-
signal: controller.signal
|
|
159
|
-
}
|
|
160
|
-
);
|
|
161
|
-
if (!res.ok) {
|
|
162
|
-
throw new Error(`Metrics request failed (HTTP ${res.status})`);
|
|
163
|
-
}
|
|
164
|
-
const data = await res.json();
|
|
165
|
-
const user = data?.process?.cpuSeconds?.user ?? 0;
|
|
166
|
-
const system = data?.process?.cpuSeconds?.system ?? 0;
|
|
167
|
-
const cpuSeconds = user + system;
|
|
168
|
-
const wallMs = Date.now();
|
|
169
|
-
if (cancelled) return;
|
|
170
|
-
let cpuPercent = null;
|
|
171
|
-
const prev = sampleRef.current;
|
|
172
|
-
if (prev && prev.sandboxId === sandboxId) {
|
|
173
|
-
const dCpu = cpuSeconds - prev.cpuSeconds;
|
|
174
|
-
const dWallSec = (wallMs - prev.wallMs) / 1e3;
|
|
175
|
-
if (dWallSec > 0 && dCpu >= 0) {
|
|
176
|
-
cpuPercent = dCpu / dWallSec * 100;
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
sampleRef.current = { cpuSeconds, wallMs, sandboxId };
|
|
180
|
-
setMetrics({
|
|
181
|
-
cpuPercent,
|
|
182
|
-
rssBytes: data?.process?.memoryBytes?.rss ?? 0,
|
|
183
|
-
heapUsedBytes: data?.process?.memoryBytes?.heapUsed ?? 0,
|
|
184
|
-
heapTotalBytes: data?.process?.memoryBytes?.heapTotal ?? 0
|
|
185
|
-
});
|
|
186
|
-
setLastUpdatedAt(wallMs);
|
|
187
|
-
setError(null);
|
|
188
|
-
hasLoadedRef.current = true;
|
|
189
|
-
setLoading(false);
|
|
190
|
-
} catch (err) {
|
|
191
|
-
if (cancelled || err instanceof DOMException && err.name === "AbortError") {
|
|
192
|
-
return;
|
|
193
|
-
}
|
|
194
|
-
setError(err instanceof Error ? err : new Error(String(err)));
|
|
195
|
-
if (!hasLoadedRef.current) setLoading(false);
|
|
196
|
-
}
|
|
197
|
-
};
|
|
198
|
-
const runLoop = async () => {
|
|
199
|
-
if (cancelled) return;
|
|
200
|
-
await fetchOnce();
|
|
201
|
-
if (cancelled) return;
|
|
202
|
-
timeoutId = window.setTimeout(runLoop, delay);
|
|
203
|
-
};
|
|
204
|
-
runLoop();
|
|
205
|
-
return () => {
|
|
206
|
-
cancelled = true;
|
|
207
|
-
controller.abort();
|
|
208
|
-
if (timeoutId !== null) window.clearTimeout(timeoutId);
|
|
209
|
-
};
|
|
210
|
-
}, [apiBaseUrl, sandboxId, token, enabled, intervalMs]);
|
|
211
|
-
return { metrics, loading, error, lastUpdatedAt };
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
export {
|
|
215
|
-
useAuth,
|
|
216
|
-
createAuthFetcher,
|
|
217
|
-
useApiKey,
|
|
218
|
-
useLiveTime,
|
|
219
|
-
useSandboxMetrics
|
|
220
|
-
};
|