@tangle-network/sandbox-ui 0.2.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 (70) hide show
  1. package/README.md +68 -0
  2. package/dist/auth.d.ts +57 -0
  3. package/dist/auth.js +14 -0
  4. package/dist/branding-DCi5VEik.d.ts +13 -0
  5. package/dist/button-BidTtuRS.d.ts +15 -0
  6. package/dist/chat.d.ts +121 -0
  7. package/dist/chat.js +25 -0
  8. package/dist/chunk-2UHPE5T7.js +201 -0
  9. package/dist/chunk-4EIWPJMJ.js +545 -0
  10. package/dist/chunk-6MQIDUPA.js +502 -0
  11. package/dist/chunk-B26TQ7SA.js +47 -0
  12. package/dist/chunk-E6FS7R4X.js +109 -0
  13. package/dist/chunk-GRYHFH5O.js +110 -0
  14. package/dist/chunk-HMND7JPA.js +868 -0
  15. package/dist/chunk-HRMUF35V.js +19 -0
  16. package/dist/chunk-HYEAX3DC.js +822 -0
  17. package/dist/chunk-KMXV7DDX.js +174 -0
  18. package/dist/chunk-KYY2X6LY.js +318 -0
  19. package/dist/chunk-L6ZDH5F4.js +334 -0
  20. package/dist/chunk-LTFK464G.js +103 -0
  21. package/dist/chunk-M34OA6PQ.js +233 -0
  22. package/dist/chunk-M6VLC32S.js +219 -0
  23. package/dist/chunk-MCGKDCOR.js +173 -0
  24. package/dist/chunk-NI2EI43H.js +294 -0
  25. package/dist/chunk-OU4TRNQZ.js +173 -0
  26. package/dist/chunk-QD4QE5P5.js +40 -0
  27. package/dist/chunk-QSQBDR3N.js +180 -0
  28. package/dist/chunk-RQHJBTEU.js +10 -0
  29. package/dist/chunk-U62G5TS7.js +472 -0
  30. package/dist/chunk-ZOL2TR5M.js +475 -0
  31. package/dist/dashboard.d.ts +111 -0
  32. package/dist/dashboard.js +26 -0
  33. package/dist/editor.d.ts +196 -0
  34. package/dist/editor.js +713 -0
  35. package/dist/expanded-tool-detail-OkXGqTHe.d.ts +52 -0
  36. package/dist/files.d.ts +66 -0
  37. package/dist/files.js +11 -0
  38. package/dist/hooks.d.ts +22 -0
  39. package/dist/hooks.js +107 -0
  40. package/dist/index.d.ts +107 -0
  41. package/dist/index.js +551 -0
  42. package/dist/markdown.d.ts +55 -0
  43. package/dist/markdown.js +17 -0
  44. package/dist/pages.d.ts +89 -0
  45. package/dist/pages.js +1181 -0
  46. package/dist/parts-CyGkM6Fp.d.ts +50 -0
  47. package/dist/primitives.d.ts +189 -0
  48. package/dist/primitives.js +161 -0
  49. package/dist/run-CtFZ6s-D.d.ts +41 -0
  50. package/dist/run.d.ts +14 -0
  51. package/dist/run.js +29 -0
  52. package/dist/sidecar-CFU2W9j1.d.ts +8 -0
  53. package/dist/stores.d.ts +28 -0
  54. package/dist/stores.js +49 -0
  55. package/dist/terminal.d.ts +44 -0
  56. package/dist/terminal.js +160 -0
  57. package/dist/tool-call-feed-D5Ume-Pt.d.ts +66 -0
  58. package/dist/tool-display-BvsVW_Ur.d.ts +32 -0
  59. package/dist/types.d.ts +6 -0
  60. package/dist/types.js +0 -0
  61. package/dist/usage-chart-DINgSVL5.d.ts +60 -0
  62. package/dist/use-sidecar-auth-Bb0-w3lX.d.ts +339 -0
  63. package/dist/utils.d.ts +28 -0
  64. package/dist/utils.js +28 -0
  65. package/dist/workspace.d.ts +113 -0
  66. package/dist/workspace.js +15 -0
  67. package/package.json +174 -0
  68. package/src/styles/globals.css +230 -0
  69. package/src/styles/tokens.css +73 -0
  70. package/tailwind.config.cjs +99 -0
@@ -0,0 +1,110 @@
1
+ // src/hooks/use-pty-session.ts
2
+ import { useState, useEffect, useRef, useCallback } from "react";
3
+ function usePtySession({ apiUrl, token, onData }) {
4
+ const [isConnected, setIsConnected] = useState(false);
5
+ const [error, setError] = useState(null);
6
+ const sessionIdRef = useRef(null);
7
+ const eventSourceRef = useRef(null);
8
+ const retryTimerRef = useRef(void 0);
9
+ const mountedRef = useRef(true);
10
+ const onDataRef = useRef(onData);
11
+ onDataRef.current = onData;
12
+ const cleanup = useCallback(() => {
13
+ if (retryTimerRef.current) {
14
+ clearTimeout(retryTimerRef.current);
15
+ retryTimerRef.current = void 0;
16
+ }
17
+ if (eventSourceRef.current) {
18
+ eventSourceRef.current.close();
19
+ eventSourceRef.current = null;
20
+ }
21
+ if (sessionIdRef.current) {
22
+ const sid = sessionIdRef.current;
23
+ sessionIdRef.current = null;
24
+ fetch(`${apiUrl}/terminals/${sid}`, {
25
+ method: "DELETE",
26
+ headers: { Authorization: `Bearer ${token}` }
27
+ }).catch(() => {
28
+ });
29
+ }
30
+ setIsConnected(false);
31
+ }, [apiUrl, token]);
32
+ const connect = useCallback(async () => {
33
+ cleanup();
34
+ setError(null);
35
+ try {
36
+ const res = await fetch(`${apiUrl}/terminals`, {
37
+ method: "POST",
38
+ headers: {
39
+ Authorization: `Bearer ${token}`,
40
+ "Content-Type": "application/json"
41
+ }
42
+ });
43
+ if (!res.ok) {
44
+ throw new Error(`Failed to create terminal: ${res.status}`);
45
+ }
46
+ const body = await res.json();
47
+ const sessionId = body.data?.sessionId ?? body.sessionId;
48
+ if (!sessionId) throw new Error("No sessionId in response");
49
+ if (!mountedRef.current) return;
50
+ sessionIdRef.current = sessionId;
51
+ const streamUrl = `${apiUrl}/terminals/${sessionId}/stream?token=${encodeURIComponent(token)}`;
52
+ const es = new EventSource(streamUrl);
53
+ eventSourceRef.current = es;
54
+ es.onopen = () => {
55
+ if (mountedRef.current) {
56
+ setIsConnected(true);
57
+ setError(null);
58
+ }
59
+ };
60
+ es.onmessage = (event) => {
61
+ if (mountedRef.current && event.data) {
62
+ onDataRef.current(event.data);
63
+ }
64
+ };
65
+ es.onerror = () => {
66
+ if (!mountedRef.current) return;
67
+ es.close();
68
+ eventSourceRef.current = null;
69
+ setIsConnected(false);
70
+ retryTimerRef.current = setTimeout(() => {
71
+ if (mountedRef.current) connect();
72
+ }, 3e3);
73
+ };
74
+ } catch (err) {
75
+ if (mountedRef.current) {
76
+ setError(err instanceof Error ? err.message : "Terminal connection failed");
77
+ setIsConnected(false);
78
+ }
79
+ }
80
+ }, [apiUrl, token, cleanup]);
81
+ const sendCommand = useCallback(async (command) => {
82
+ const sid = sessionIdRef.current;
83
+ if (!sid) return;
84
+ const res = await fetch(`${apiUrl}/terminals/${sid}/execute`, {
85
+ method: "POST",
86
+ headers: {
87
+ Authorization: `Bearer ${token}`,
88
+ "Content-Type": "application/json"
89
+ },
90
+ body: JSON.stringify({ command })
91
+ });
92
+ if (!res.ok) {
93
+ const text = await res.text();
94
+ throw new Error(text || `Execute failed: ${res.status}`);
95
+ }
96
+ }, [apiUrl, token]);
97
+ useEffect(() => {
98
+ mountedRef.current = true;
99
+ connect();
100
+ return () => {
101
+ mountedRef.current = false;
102
+ cleanup();
103
+ };
104
+ }, [connect, cleanup]);
105
+ return { isConnected, error, sendCommand, reconnect: connect };
106
+ }
107
+
108
+ export {
109
+ usePtySession
110
+ };