@illuma-ai/code-sandbox 1.0.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/src/types.ts ADDED
@@ -0,0 +1,179 @@
1
+ /**
2
+ * @illuma-ai/code-sandbox — Type definitions
3
+ *
4
+ * Core types for the browser-native code sandbox.
5
+ * Covers file maps, runtime states, git operations, and component props.
6
+ */
7
+
8
+ // ---------------------------------------------------------------------------
9
+ // File System
10
+ // ---------------------------------------------------------------------------
11
+
12
+ /** A flat map of file paths to their string contents */
13
+ export type FileMap = Record<string, string>;
14
+
15
+ /** Represents a single file or directory node in the tree */
16
+ export interface FileNode {
17
+ name: string;
18
+ path: string;
19
+ type: "file" | "directory";
20
+ children?: FileNode[];
21
+ }
22
+
23
+ // ---------------------------------------------------------------------------
24
+ // Runtime (Nodepod lifecycle)
25
+ // ---------------------------------------------------------------------------
26
+
27
+ /** Boot stages shown during the loading animation */
28
+ export type BootStage =
29
+ | "initializing" // Nodepod.boot() in progress
30
+ | "writing-files" // Writing project files to virtual FS
31
+ | "installing" // npm install running
32
+ | "starting" // Entry command executing (e.g., node server.js)
33
+ | "ready" // Server is listening, preview iframe can load
34
+ | "error"; // Something failed
35
+
36
+ export interface BootProgress {
37
+ stage: BootStage;
38
+ message: string;
39
+ /** 0-100 percent, approximate */
40
+ percent: number;
41
+ }
42
+
43
+ /** Configuration for the Nodepod runtime */
44
+ export interface RuntimeConfig {
45
+ /** Project files to write into the virtual filesystem */
46
+ files: FileMap;
47
+ /** Command to start the dev server, e.g. "node server.js" */
48
+ entryCommand: string;
49
+ /** Working directory inside Nodepod (default: "/app") */
50
+ workdir?: string;
51
+ /** Environment variables passed to processes */
52
+ env?: Record<string, string>;
53
+ /** Port to watch for server readiness (default: 3000) */
54
+ port?: number;
55
+ }
56
+
57
+ /** State exposed by the runtime to UI components */
58
+ export interface RuntimeState {
59
+ status: BootStage;
60
+ progress: BootProgress;
61
+ /** URL for the preview iframe once server is ready, e.g. "/__virtual__/3000/" */
62
+ previewUrl: string | null;
63
+ /** All terminal output lines (stdout + stderr) */
64
+ terminalOutput: string[];
65
+ /** Current files in the virtual FS (may differ from original after edits) */
66
+ files: FileMap;
67
+ /** Error message if status is 'error' */
68
+ error: string | null;
69
+ }
70
+
71
+ // ---------------------------------------------------------------------------
72
+ // Git (GitHub API integration)
73
+ // ---------------------------------------------------------------------------
74
+
75
+ export interface GitHubRepo {
76
+ owner: string;
77
+ repo: string;
78
+ branch?: string; // default: 'main'
79
+ path?: string; // subdirectory to clone (default: root)
80
+ }
81
+
82
+ export interface GitCommitRequest {
83
+ owner: string;
84
+ repo: string;
85
+ /** Branch to create for the commit */
86
+ branch: string;
87
+ /** Base branch to fork from (default: 'main') */
88
+ baseBranch?: string;
89
+ /** Map of file paths to new contents (only changed files) */
90
+ changes: FileMap;
91
+ /** Commit message */
92
+ message: string;
93
+ }
94
+
95
+ export interface GitPRRequest extends GitCommitRequest {
96
+ /** PR title */
97
+ title: string;
98
+ /** PR body/description */
99
+ body?: string;
100
+ }
101
+
102
+ export interface GitPRResult {
103
+ number: number;
104
+ url: string;
105
+ branch: string;
106
+ }
107
+
108
+ // ---------------------------------------------------------------------------
109
+ // Component Props
110
+ // ---------------------------------------------------------------------------
111
+
112
+ export interface CodeSandboxProps {
113
+ /** Pass files directly */
114
+ files?: FileMap;
115
+ /** OR load from GitHub */
116
+ github?: GitHubRepo;
117
+ /** GitHub personal access token (for private repos and write-back) */
118
+ gitToken?: string;
119
+ /** OR use a built-in template name */
120
+ template?: string;
121
+ /** Command to start the dev server (default inferred from package.json or template) */
122
+ entryCommand?: string;
123
+ /** Port the server listens on (default: 3000) */
124
+ port?: number;
125
+ /** Environment variables */
126
+ env?: Record<string, string>;
127
+
128
+ // Callbacks
129
+ /** Fires when a file is modified in the editor */
130
+ onFileChange?: (path: string, content: string) => void;
131
+ /** Fires when the dev server is ready */
132
+ onServerReady?: (port: number, url: string) => void;
133
+ /** Fires on boot progress changes */
134
+ onProgress?: (progress: BootProgress) => void;
135
+ /** Fires on errors */
136
+ onError?: (error: string) => void;
137
+
138
+ // Layout
139
+ /** CSS class name for the root element */
140
+ className?: string;
141
+ /** Height of the sandbox (default: '100vh') */
142
+ height?: string;
143
+ }
144
+
145
+ export interface FileTreeProps {
146
+ files: FileNode[];
147
+ selectedFile: string | null;
148
+ onSelectFile: (path: string) => void;
149
+ onCreateFile?: (path: string) => void;
150
+ onCreateFolder?: (path: string) => void;
151
+ onDeleteFile?: (path: string) => void;
152
+ onRenameFile?: (oldPath: string, newPath: string) => void;
153
+ }
154
+
155
+ export interface CodeEditorProps {
156
+ files: FileMap;
157
+ activeFile: string | null;
158
+ openFiles: string[];
159
+ onSelectFile: (path: string) => void;
160
+ onCloseFile: (path: string) => void;
161
+ onFileChange: (path: string, content: string) => void;
162
+ readOnly?: boolean;
163
+ }
164
+
165
+ export interface TerminalProps {
166
+ output: string[];
167
+ className?: string;
168
+ }
169
+
170
+ export interface PreviewProps {
171
+ url: string | null;
172
+ className?: string;
173
+ onRefresh?: () => void;
174
+ }
175
+
176
+ export interface BootOverlayProps {
177
+ progress: BootProgress;
178
+ className?: string;
179
+ }