@tangle-network/sandbox-ui 0.14.0 → 0.15.2

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/auth.d.ts +1 -74
  2. package/dist/auth.js +1 -4
  3. package/dist/chat.d.ts +1 -136
  4. package/dist/chat.js +2 -15
  5. package/dist/chunk-2BUPSB7O.js +0 -0
  6. package/dist/chunk-3J6FG3FJ.js +18 -0
  7. package/dist/chunk-76IQLPW2.js +206 -0
  8. package/dist/chunk-7ZA5SEK3.js +239 -0
  9. package/dist/chunk-AZ3AWMTM.js +8 -0
  10. package/dist/chunk-CMY7W45U.js +380 -0
  11. package/dist/chunk-EI44GEQ5.js +6 -0
  12. package/dist/chunk-ENMWGVDL.js +858 -0
  13. package/dist/{chunk-5OQ27N57.js → chunk-GPT7VKK6.js} +34 -38
  14. package/dist/chunk-HLZTKSGT.js +2652 -0
  15. package/dist/chunk-JBGKGLD7.js +16 -0
  16. package/dist/chunk-NJNME4J4.js +14 -0
  17. package/dist/chunk-QPAJR74X.js +20 -0
  18. package/dist/chunk-TK46XFLM.js +28 -0
  19. package/dist/chunk-WID73FPH.js +89 -0
  20. package/dist/chunk-YVXK4XRO.js +30 -0
  21. package/dist/dashboard.d.ts +450 -4
  22. package/dist/dashboard.js +20 -891
  23. package/dist/editor.d.ts +1 -120
  24. package/dist/editor.js +1 -5
  25. package/dist/files.d.ts +1 -129
  26. package/dist/files.js +2 -7
  27. package/dist/globals.css +2 -1265
  28. package/dist/hooks.d.ts +114 -11
  29. package/dist/hooks.js +17 -88
  30. package/dist/index.d.ts +24 -99
  31. package/dist/index.js +251 -256
  32. package/dist/markdown.d.ts +1 -29
  33. package/dist/markdown.js +2 -2
  34. package/dist/openui.d.ts +8 -115
  35. package/dist/openui.js +1 -6
  36. package/dist/pages.d.ts +13 -12
  37. package/dist/pages.js +91 -115
  38. package/dist/primitives.d.ts +14 -49
  39. package/dist/primitives.js +69 -77
  40. package/dist/run.d.ts +1 -14
  41. package/dist/run.js +2 -22
  42. package/dist/sdk-hooks.d.ts +3 -283
  43. package/dist/sdk-hooks.js +10 -14
  44. package/dist/stores.d.ts +2 -14
  45. package/dist/stores.js +11 -39
  46. package/dist/styles.css +2 -1265
  47. package/dist/template-card-DStb8boW.d.ts +183 -0
  48. package/dist/types.d.ts +11 -8
  49. package/dist/types.js +1 -0
  50. package/dist/utils.d.ts +1 -44
  51. package/dist/utils.js +6 -12
  52. package/dist/workspace.d.ts +5 -10
  53. package/dist/workspace.js +3 -19
  54. package/package.json +19 -54
  55. package/dist/active-sessions-store-CeOmXgv5.d.ts +0 -85
  56. package/dist/artifact-pane-Bh45Ssco.d.ts +0 -24
  57. package/dist/branding-DCi5VEik.d.ts +0 -13
  58. package/dist/button-CMQuQEW_.d.ts +0 -17
  59. package/dist/chat-container-f4yEs6KN.d.ts +0 -106
  60. package/dist/chunk-34A66VBG.js +0 -214
  61. package/dist/chunk-34I7UFSX.js +0 -92
  62. package/dist/chunk-36QY2W5G.js +0 -802
  63. package/dist/chunk-4CLN43XT.js +0 -45
  64. package/dist/chunk-54SQQMMM.js +0 -156
  65. package/dist/chunk-66EZOYZR.js +0 -102
  66. package/dist/chunk-BX6AQMUS.js +0 -183
  67. package/dist/chunk-DI3NZ5ZX.js +0 -192
  68. package/dist/chunk-DPGIXDAI.js +0 -220
  69. package/dist/chunk-DXMIEK4K.js +0 -1426
  70. package/dist/chunk-GSZA3TSY.js +0 -79
  71. package/dist/chunk-HB5Y37YU.js +0 -54
  72. package/dist/chunk-LQNEZDRM.js +0 -109
  73. package/dist/chunk-MA7YKRUP.js +0 -131
  74. package/dist/chunk-MKTSMWVD.js +0 -109
  75. package/dist/chunk-MQXABZTB.js +0 -1348
  76. package/dist/chunk-MT5FJ3ZT.js +0 -186
  77. package/dist/chunk-NKUPJC34.js +0 -2070
  78. package/dist/chunk-OEX7NZE3.js +0 -321
  79. package/dist/chunk-OKLQVY3Y.js +0 -139
  80. package/dist/chunk-Q56BYXQF.js +0 -61
  81. package/dist/chunk-QD4QE5P5.js +0 -40
  82. package/dist/chunk-QDH5GEGY.js +0 -630
  83. package/dist/chunk-QID2OOMG.js +0 -133
  84. package/dist/chunk-QMU2PWOU.js +0 -493
  85. package/dist/chunk-RQHJBTEU.js +0 -10
  86. package/dist/chunk-T7HMZEVO.js +0 -216
  87. package/dist/chunk-U6QTHMY6.js +0 -1290
  88. package/dist/chunk-US6JKJKH.js +0 -124
  89. package/dist/chunk-VX3XOUEB.js +0 -63
  90. package/dist/chunk-XLG757B6.js +0 -933
  91. package/dist/chunk-ZMNSRDMH.js +0 -127
  92. package/dist/chunk-ZNCEM5CD.js +0 -316
  93. package/dist/document-editor-pane-A70-EhdQ.d.ts +0 -124
  94. package/dist/document-editor-pane-TLPVRBBU.js +0 -11
  95. package/dist/expanded-tool-detail-Dh99mcbY.d.ts +0 -63
  96. package/dist/file-tabs-BLfxfmAH.d.ts +0 -51
  97. package/dist/parts-CyGkM6Fp.d.ts +0 -50
  98. package/dist/run-CtFZ6s-D.d.ts +0 -41
  99. package/dist/sidebar-drop-zone-tDBsuOH5.d.ts +0 -301
  100. package/dist/sidecar-CFU2W9j1.d.ts +0 -8
  101. package/dist/template-card-BAtvcAkU.d.ts +0 -18
  102. package/dist/tool-call-feed-Bs3MyQMT.d.ts +0 -68
  103. package/dist/tool-display-Ct9nFAzJ.d.ts +0 -32
  104. package/dist/usage-chart-CPTcNlGs.d.ts +0 -73
  105. package/dist/use-sandbox-metrics-DWc0k9Xm.d.ts +0 -153
  106. package/dist/variant-list-BrHYcBCk.d.ts +0 -540
@@ -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
- };