@ebowwa/sandbox 0.1.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.
Files changed (108) hide show
  1. package/dist/compilers/index.d.ts +24 -0
  2. package/dist/compilers/index.d.ts.map +1 -0
  3. package/dist/compilers/index.js +42 -0
  4. package/dist/compilers/index.js.map +1 -0
  5. package/dist/compilers/javascript.d.ts +117 -0
  6. package/dist/compilers/javascript.d.ts.map +1 -0
  7. package/dist/compilers/javascript.js +462 -0
  8. package/dist/compilers/javascript.js.map +1 -0
  9. package/dist/compilers/python.d.ts +140 -0
  10. package/dist/compilers/python.d.ts.map +1 -0
  11. package/dist/compilers/python.js +650 -0
  12. package/dist/compilers/python.js.map +1 -0
  13. package/dist/compilers/typescript.d.ts +99 -0
  14. package/dist/compilers/typescript.d.ts.map +1 -0
  15. package/dist/compilers/typescript.js +323 -0
  16. package/dist/compilers/typescript.js.map +1 -0
  17. package/dist/core/cell.d.ts +160 -0
  18. package/dist/core/cell.d.ts.map +1 -0
  19. package/dist/core/cell.js +319 -0
  20. package/dist/core/cell.js.map +1 -0
  21. package/dist/core/compiler.d.ts +126 -0
  22. package/dist/core/compiler.d.ts.map +1 -0
  23. package/dist/core/compiler.js +123 -0
  24. package/dist/core/compiler.js.map +1 -0
  25. package/dist/core/index.d.ts +19 -0
  26. package/dist/core/index.d.ts.map +1 -0
  27. package/dist/core/index.js +14 -0
  28. package/dist/core/index.js.map +1 -0
  29. package/dist/core/limits.d.ts +173 -0
  30. package/dist/core/limits.d.ts.map +1 -0
  31. package/dist/core/limits.js +440 -0
  32. package/dist/core/limits.js.map +1 -0
  33. package/dist/core/permissions.d.ts +103 -0
  34. package/dist/core/permissions.d.ts.map +1 -0
  35. package/dist/core/permissions.js +341 -0
  36. package/dist/core/permissions.js.map +1 -0
  37. package/dist/core/runtime.d.ts +127 -0
  38. package/dist/core/runtime.d.ts.map +1 -0
  39. package/dist/core/runtime.js +325 -0
  40. package/dist/core/runtime.js.map +1 -0
  41. package/dist/core/types.d.ts +380 -0
  42. package/dist/core/types.d.ts.map +1 -0
  43. package/dist/core/types.js +67 -0
  44. package/dist/core/types.js.map +1 -0
  45. package/dist/index.d.ts +145 -0
  46. package/dist/index.d.ts.map +1 -0
  47. package/dist/index.js +279 -0
  48. package/dist/index.js.map +1 -0
  49. package/dist/multi/index.d.ts +9 -0
  50. package/dist/multi/index.d.ts.map +1 -0
  51. package/dist/multi/index.js +7 -0
  52. package/dist/multi/index.js.map +1 -0
  53. package/dist/multi/polyglot.d.ts +179 -0
  54. package/dist/multi/polyglot.d.ts.map +1 -0
  55. package/dist/multi/polyglot.js +319 -0
  56. package/dist/multi/polyglot.js.map +1 -0
  57. package/dist/runtimes/docker.d.ts +97 -0
  58. package/dist/runtimes/docker.d.ts.map +1 -0
  59. package/dist/runtimes/docker.js +368 -0
  60. package/dist/runtimes/docker.js.map +1 -0
  61. package/dist/runtimes/index.d.ts +11 -0
  62. package/dist/runtimes/index.d.ts.map +1 -0
  63. package/dist/runtimes/index.js +9 -0
  64. package/dist/runtimes/index.js.map +1 -0
  65. package/dist/runtimes/process.d.ts +47 -0
  66. package/dist/runtimes/process.d.ts.map +1 -0
  67. package/dist/runtimes/process.js +230 -0
  68. package/dist/runtimes/process.js.map +1 -0
  69. package/dist/session/index.d.ts +12 -0
  70. package/dist/session/index.d.ts.map +1 -0
  71. package/dist/session/index.js +9 -0
  72. package/dist/session/index.js.map +1 -0
  73. package/dist/session/kernel.d.ts +199 -0
  74. package/dist/session/kernel.d.ts.map +1 -0
  75. package/dist/session/kernel.js +400 -0
  76. package/dist/session/kernel.js.map +1 -0
  77. package/dist/session/notebook.d.ts +168 -0
  78. package/dist/session/notebook.d.ts.map +1 -0
  79. package/dist/session/notebook.js +499 -0
  80. package/dist/session/notebook.js.map +1 -0
  81. package/dist/session/repl.d.ts +159 -0
  82. package/dist/session/repl.d.ts.map +1 -0
  83. package/dist/session/repl.js +409 -0
  84. package/dist/session/repl.js.map +1 -0
  85. package/package.json +142 -0
  86. package/src/compilers/index.ts +80 -0
  87. package/src/compilers/javascript.ts +571 -0
  88. package/src/compilers/python.ts +785 -0
  89. package/src/compilers/typescript.ts +442 -0
  90. package/src/core/cell.ts +439 -0
  91. package/src/core/compiler.ts +250 -0
  92. package/src/core/index.ts +123 -0
  93. package/src/core/limits.ts +508 -0
  94. package/src/core/permissions.ts +409 -0
  95. package/src/core/runtime.ts +499 -0
  96. package/src/core/types.ts +528 -0
  97. package/src/global.d.ts +59 -0
  98. package/src/index.ts +515 -0
  99. package/src/multi/index.ts +22 -0
  100. package/src/multi/polyglot.ts +461 -0
  101. package/src/runtimes/docker.ts +501 -0
  102. package/src/runtimes/index.ts +21 -0
  103. package/src/runtimes/process.ts +316 -0
  104. package/src/session/index.ts +41 -0
  105. package/src/session/kernel.ts +553 -0
  106. package/src/session/notebook.ts +635 -0
  107. package/src/session/repl.ts +521 -0
  108. package/src/wasm2wasm.d.ts +35 -0
@@ -0,0 +1,528 @@
1
+ /**
2
+ * Core Types for @ebowwa/sandbox
3
+ *
4
+ * Composable primitives for multi-language sandboxed execution.
5
+ * Each type is designed to be independently usable.
6
+ */
7
+
8
+ // ============================================
9
+ // LANGUAGE & FORMAT TYPES
10
+ // ============================================
11
+
12
+ /** Supported input languages/formats */
13
+ export type Language =
14
+ | "wasm" // Pre-compiled WASM bytes
15
+ | "javascript" // JavaScript
16
+ | "typescript" // TypeScript
17
+ | "assemblyscript" // AssemblyScript (TS-like)
18
+ | "python" // Python (via Pyodide/RustPython WASM)
19
+ | "json" // JSON data
20
+ | "markdown" // Markdown (documentation cells)
21
+ | "custom"; // Custom DSL (via registered compiler)
22
+
23
+ /** Language capability flags */
24
+ export interface LanguageCapabilities {
25
+ supportsREPL: boolean;
26
+ supportsState: boolean; // Can maintain state between cells
27
+ requiresCompilation: boolean;
28
+ hasGarbageCollection: boolean;
29
+ canImportModules: boolean;
30
+ canAccessFS: boolean;
31
+ canAccessNetwork: boolean;
32
+ }
33
+
34
+ // ============================================
35
+ // PERMISSION TYPES (Composable)
36
+ // ============================================
37
+
38
+ /** Permission level - escalating access */
39
+ export type PermissionLevel =
40
+ | "isolated" // Completely sandboxed, no I/O
41
+ | "readonly" // Read-only filesystem
42
+ | "network" // Network + read-only fs
43
+ | "filesystem" // Full filesystem + network
44
+ | "admin" // Admin capabilities
45
+ | "sudo"; // Root/sudo access (DANGEROUS)
46
+
47
+ /** Individual permission flags - composable */
48
+ export interface Permissions {
49
+ fs?: FileSystemPermission;
50
+ network?: NetworkPermission;
51
+ env?: EnvironmentPermission;
52
+ process?: ProcessPermission;
53
+ memory?: {
54
+ maxBytes?: number;
55
+ };
56
+ cpu?: CpuPermission;
57
+ }
58
+
59
+ /** Filesystem permission */
60
+ export interface FileSystemPermission {
61
+ read?: boolean;
62
+ write?: boolean;
63
+ delete?: boolean;
64
+ allowedPaths?: string[];
65
+ deniedPaths?: string[];
66
+ }
67
+
68
+ /** Network permission */
69
+ export interface NetworkPermission {
70
+ outbound?: boolean;
71
+ inbound?: boolean;
72
+ allowedHosts?: string[];
73
+ deniedHosts?: string[];
74
+ }
75
+
76
+ /** Environment permission */
77
+ export interface EnvironmentPermission {
78
+ read?: boolean;
79
+ write?: boolean;
80
+ allowedKeys?: string[];
81
+ }
82
+
83
+ /** Process permission */
84
+ export interface ProcessPermission {
85
+ spawn?: boolean;
86
+ allowedCommands?: string[];
87
+ }
88
+
89
+ /** CPU permission */
90
+ export interface CpuPermission {
91
+ maxPercent?: number;
92
+ maxTimeMs?: number;
93
+ }
94
+
95
+ /** Convert permission level to permissions object */
96
+ export function permissionsFromLevel(level: PermissionLevel): Permissions {
97
+ switch (level) {
98
+ case "isolated":
99
+ return {};
100
+ case "readonly":
101
+ return { fs: { read: true } };
102
+ case "network":
103
+ return { fs: { read: true }, network: { outbound: true } };
104
+ case "filesystem":
105
+ return {
106
+ fs: { read: true, write: true, delete: true },
107
+ network: { outbound: true, inbound: true }
108
+ };
109
+ case "admin":
110
+ return {
111
+ fs: { read: true, write: true, delete: true },
112
+ network: { outbound: true, inbound: true },
113
+ env: { read: true, write: true },
114
+ process: { spawn: true }
115
+ };
116
+ case "sudo":
117
+ return {
118
+ fs: { read: true, write: true, delete: true },
119
+ network: { outbound: true, inbound: true },
120
+ env: { read: true, write: true },
121
+ process: { spawn: true }
122
+ };
123
+ }
124
+ }
125
+
126
+ // ============================================
127
+ // RESOURCE LIMITS (Composable)
128
+ // ============================================
129
+
130
+ /** Resource limits for execution */
131
+ export interface Limits {
132
+ /** Memory limit (bytes or string like "64MB") */
133
+ memory?: number | string;
134
+ /** Execution timeout (ms or string like "5s") */
135
+ timeout?: number | string;
136
+ /** CPU time limit (ms) */
137
+ cpuTime?: number;
138
+ /** Max WASM instructions (gas/fuel) */
139
+ maxInstructions?: number;
140
+ /** Max output size (bytes) */
141
+ maxOutputSize?: number;
142
+ /** Max call stack depth */
143
+ maxStackDepth?: number;
144
+ /** Network bandwidth limits */
145
+ network?: {
146
+ maxBandwidth?: string;
147
+ maxConnections?: number;
148
+ };
149
+ /** Filesystem limits */
150
+ filesystem?: {
151
+ maxFileSize?: string;
152
+ maxTotalSize?: string;
153
+ maxOpenFiles?: number;
154
+ };
155
+ }
156
+
157
+ /** Parse memory string to bytes */
158
+ export function parseMemory(mem: number | string | undefined): number {
159
+ if (mem === undefined) return 16 * 1024 * 1024; // 16MB default
160
+ if (typeof mem === "number") return mem;
161
+ const match = mem.match(/^(\d+(?:\.\d+)?)\s*(b|kb|mb|gb)?$/i);
162
+ if (!match) return 16 * 1024 * 1024;
163
+ const [, num, unit] = match;
164
+ const multipliers: Record<string, number> = {
165
+ b: 1, kb: 1024, mb: 1024 ** 2, gb: 1024 ** 3
166
+ };
167
+ return Math.floor(parseFloat(num) * (multipliers[unit?.toLowerCase() ?? "b"] ?? 1));
168
+ }
169
+
170
+ /** Parse time string to milliseconds */
171
+ export function parseTime(time: number | string | undefined): number {
172
+ if (time === undefined) return 30000; // 30s default
173
+ if (typeof time === "number") return time;
174
+ const match = time.match(/^(\d+(?:\.\d+)?)\s*(ms|s|m|h)?$/i);
175
+ if (!match) return 30000;
176
+ const [, num, unit] = match;
177
+ const multipliers: Record<string, number> = {
178
+ ms: 1, s: 1000, m: 60000, h: 3600000
179
+ };
180
+ return Math.floor(parseFloat(num) * (multipliers[unit?.toLowerCase() ?? "ms"] ?? 1));
181
+ }
182
+
183
+ // ============================================
184
+ // EXECUTION TYPES
185
+ // ============================================
186
+
187
+ /** Code cell for notebook/repl execution */
188
+ export interface Cell {
189
+ id: string;
190
+ language: Language;
191
+ source: string;
192
+ metadata?: Record<string, unknown>;
193
+ }
194
+
195
+ /** Result from another cell (for imports) */
196
+ export interface CellResult {
197
+ success: boolean;
198
+ value?: unknown;
199
+ error?: { message: string; type: string };
200
+ exports?: Map<string, unknown>;
201
+ }
202
+
203
+ /** Execution context passed to runtimes */
204
+ export interface ExecutionContext {
205
+ cellId: string;
206
+ permissions: Permissions;
207
+ limits: Limits;
208
+ environment: Record<string, string>;
209
+ workingDirectory?: string;
210
+ /** Shared state from previous cells */
211
+ state?: Map<string, unknown>;
212
+ /** Imports from other cells */
213
+ imports?: Map<string, CellResult>;
214
+ /** Abort signal for cancellation */
215
+ signal?: AbortSignal;
216
+ }
217
+
218
+ /** Execution options */
219
+ export interface ExecutionOptions {
220
+ entrypoint?: string;
221
+ args?: unknown[];
222
+ input?: unknown;
223
+ timeout?: number;
224
+ signal?: AbortSignal;
225
+ /** Pass state from previous execution */
226
+ state?: Map<string, unknown>;
227
+ }
228
+
229
+ /** Result of cell/execution */
230
+ export interface ExecutionResult<T = unknown> {
231
+ /** Execution succeeded */
232
+ success: boolean;
233
+ /** Return value */
234
+ value?: T;
235
+ /** Error if failed */
236
+ error?: ExecutionError;
237
+ /** Execution metrics */
238
+ metrics: ExecutionMetrics;
239
+ /** Captured output */
240
+ output: {
241
+ stdout: string[];
242
+ stderr: string[];
243
+ displays: DisplayOutput[]; // For rich output (images, HTML, etc.)
244
+ };
245
+ /** State to pass to next cells */
246
+ state?: Map<string, unknown>;
247
+ /** Exports for other cells to import */
248
+ exports?: Map<string, unknown>;
249
+ }
250
+
251
+ /** Error during execution */
252
+ export interface ExecutionError {
253
+ message: string;
254
+ stack?: string;
255
+ type: "compile" | "runtime" | "permission" | "limit" | "timeout" | "cancel";
256
+ language?: Language;
257
+ line?: number;
258
+ column?: number;
259
+ }
260
+
261
+ /** Execution metrics */
262
+ export interface ExecutionMetrics {
263
+ /** Wall clock time in ms */
264
+ duration: number;
265
+ /** Memory used in bytes */
266
+ memoryUsed: number;
267
+ /** CPU time in ms */
268
+ cpuTime?: number;
269
+ /** WASM instructions executed */
270
+ instructionsExecuted?: number;
271
+ /** Bytes received over network */
272
+ networkIn?: number;
273
+ /** Bytes sent over network */
274
+ networkOut?: number;
275
+ }
276
+
277
+ /** Rich display output (Jupyter-style) */
278
+ export interface DisplayOutput {
279
+ type: "text" | "html" | "image" | "json" | "markdown" | "javascript";
280
+ data: string | Record<string, unknown>;
281
+ metadata?: Record<string, unknown>;
282
+ }
283
+
284
+ // ============================================
285
+ // COMPILER INTERFACE
286
+ // ============================================
287
+
288
+ /** Compiler: Language → WASM */
289
+ export interface Compiler {
290
+ /** Language this compiler handles */
291
+ language: Language;
292
+ /** Check if code is valid for this language */
293
+ validate(code: string): Promise<{ valid: boolean; error?: string }>;
294
+ /** Compile source to WASM bytes */
295
+ compile(code: string, options: CompileOptions): Promise<Uint8Array>;
296
+ /** Check if compiler is available */
297
+ isAvailable(): Promise<boolean>;
298
+ }
299
+
300
+ /** Compilation options */
301
+ export interface CompileOptions {
302
+ permissions: Permissions;
303
+ limits: Limits;
304
+ optimize?: boolean;
305
+ /** Additional compiler-specific options */
306
+ extra?: Record<string, unknown>;
307
+ }
308
+
309
+ // ============================================
310
+ // RUNTIME INTERFACE
311
+ // ============================================
312
+
313
+ /** Runtime: WASM → Execution */
314
+ export interface Runtime {
315
+ /** Runtime name */
316
+ name: string;
317
+ /** Initialize runtime */
318
+ init(): Promise<void>;
319
+ /** Check if runtime is available */
320
+ isAvailable(): Promise<boolean>;
321
+ /** Execute WASM bytes */
322
+ execute(
323
+ wasmBytes: Uint8Array,
324
+ options: ExecutionOptions,
325
+ context: ExecutionContext
326
+ ): Promise<ExecutionResult>;
327
+ /** Terminate runtime and cleanup */
328
+ terminate(): Promise<void>;
329
+ }
330
+
331
+ // ============================================
332
+ // KERNEL INTERFACE (REPL/Notebook)
333
+ // ============================================
334
+
335
+ /** Kernel: Language-specific execution session */
336
+ export interface Kernel {
337
+ /** Language this kernel handles */
338
+ language: Language;
339
+ /** Kernel display name */
340
+ displayName: string;
341
+ /** Initialize kernel */
342
+ start(): Promise<void>;
343
+ /** Check if kernel is running */
344
+ isRunning(): boolean;
345
+ /** Execute code in kernel */
346
+ execute(code: string, options?: ExecutionOptions): Promise<ExecutionResult>;
347
+ /** Complete code at position (autocomplete) */
348
+ complete(code: string, position: number): Promise<CompletionResult>;
349
+ /** Inspect object at position */
350
+ inspect(code: string, position: number): Promise<InspectResult>;
351
+ /** Get current kernel state */
352
+ getState(): Map<string, unknown>;
353
+ /** Restart kernel (clear state) */
354
+ restart(): Promise<void>;
355
+ /** Shutdown kernel */
356
+ shutdown(): Promise<void>;
357
+ }
358
+
359
+ /** Autocomplete result */
360
+ export interface CompletionResult {
361
+ matches: string[];
362
+ cursorStart: number;
363
+ cursorEnd: number;
364
+ metadata?: Record<string, unknown>;
365
+ }
366
+
367
+ /** Inspect result (hover/tooltip) */
368
+ export interface InspectResult {
369
+ found: boolean;
370
+ details?: {
371
+ type: string;
372
+ documentation?: string;
373
+ signature?: string;
374
+ };
375
+ }
376
+
377
+ // ============================================
378
+ // NOTEBOOK INTERFACE
379
+ // ============================================
380
+
381
+ /** Notebook: Multi-cell, multi-language document */
382
+ export interface Notebook {
383
+ id: string;
384
+ cells: Cell[];
385
+ metadata: NotebookMetadata;
386
+ /** Execute cells in order */
387
+ runAll(options?: NotebookRunOptions): Promise<NotebookResult[]>;
388
+ /** Execute single cell */
389
+ runCell(cellId: string, options?: ExecutionOptions): Promise<NotebookResult>;
390
+ /** Execute cells from index */
391
+ runFrom(startIndex: number): Promise<NotebookResult[]>;
392
+ /** Add cell */
393
+ addCell(cell: Omit<Cell, "id">): Cell;
394
+ /** Remove cell */
395
+ removeCell(cellId: string): void;
396
+ /** Move cell */
397
+ moveCell(cellId: string, newIndex: number): void;
398
+ /** Get cell by id */
399
+ getCell(cellId: string): Cell | undefined;
400
+ /** Export to format */
401
+ export(format: "ipynb" | "json" | "markdown"): string;
402
+ }
403
+
404
+ /** Notebook metadata */
405
+ export interface NotebookMetadata {
406
+ name: string;
407
+ language?: Language; // Default language
408
+ kernelspec?: {
409
+ name: string;
410
+ display_name: string;
411
+ language: string;
412
+ };
413
+ created: Date;
414
+ modified: Date;
415
+ tags?: string[];
416
+ }
417
+
418
+ /** Notebook run options */
419
+ export interface NotebookRunOptions {
420
+ /** Stop on first error */
421
+ stopOnError?: boolean;
422
+ /** Parallel execution where possible */
423
+ parallel?: boolean;
424
+ /** Continue from last successful cell */
425
+ continueFrom?: string;
426
+ }
427
+
428
+ /** Result of notebook cell execution */
429
+ export interface NotebookResult {
430
+ cellId: string;
431
+ executionCount: number;
432
+ result: ExecutionResult;
433
+ timestamp: Date;
434
+ }
435
+
436
+ // ============================================
437
+ // SESSION INTERFACE
438
+ // ============================================
439
+
440
+ /** Session: Stateful execution context */
441
+ export interface Session {
442
+ id: string;
443
+ /** Get active kernel for language */
444
+ getKernel(language: Language): Kernel | undefined;
445
+ /** Start a kernel for language */
446
+ startKernel(language: Language): Promise<Kernel>;
447
+ /** Execute code (auto-selects kernel) */
448
+ execute(code: string, language: Language, options?: ExecutionOptions): Promise<ExecutionResult>;
449
+ /** Get shared state across all kernels */
450
+ getSharedState(): Map<string, unknown>;
451
+ /** Set shared state */
452
+ setSharedState(key: string, value: unknown): void;
453
+ /** Register language compiler */
454
+ registerCompiler(compiler: Compiler): void;
455
+ /** Register runtime */
456
+ registerRuntime(runtime: Runtime): void;
457
+ /** Shutdown session */
458
+ shutdown(): Promise<void>;
459
+ }
460
+
461
+ // ============================================
462
+ // POLYGLOT / MULTI-LANGUAGE
463
+ // ============================================
464
+
465
+ /** Polyglot cell - code that can run in multiple languages */
466
+ export interface PolyglotCell {
467
+ id: string;
468
+ variants: Map<Language, string>; // Same logic, different languages
469
+ preferredLanguage?: Language;
470
+ }
471
+
472
+ /** Bridge for passing data between languages */
473
+ export interface LanguageBridge {
474
+ from: Language;
475
+ to: Language;
476
+ /** Serialize value from source language */
477
+ serialize(value: unknown): Uint8Array;
478
+ /** Deserialize value in target language */
479
+ deserialize(bytes: Uint8Array): unknown;
480
+ /** Can these types be bridged? */
481
+ canBridge(type: string): boolean;
482
+ }
483
+
484
+ // ============================================
485
+ // SANDBOX (MAIN INTERFACE)
486
+ // ============================================
487
+
488
+ /** Main Sandbox interface - combines all primitives */
489
+ export interface Sandbox {
490
+ /** Create a session for interactive use */
491
+ createSession(options?: SessionOptions): Session;
492
+ /** Create a notebook */
493
+ createNotebook(options?: NotebookOptions): Notebook;
494
+ /** Quick execute (isolated, no state) */
495
+ execute(
496
+ code: string,
497
+ language: Language,
498
+ options?: SandboxOptions
499
+ ): Promise<ExecutionResult>;
500
+ /** Quick execute with preset */
501
+ quick(
502
+ code: string,
503
+ preset?: "isolated" | "trusted" | "admin"
504
+ ): Promise<ExecutionResult>;
505
+ }
506
+
507
+ /** Sandbox configuration */
508
+ export interface SandboxOptions {
509
+ permissions?: PermissionLevel | Permissions;
510
+ limits?: Limits;
511
+ language?: Language;
512
+ environment?: Record<string, string>;
513
+ workingDirectory?: string;
514
+ }
515
+
516
+ /** Session options */
517
+ export interface SessionOptions extends SandboxOptions {
518
+ /** Languages to pre-warm kernels for */
519
+ languages?: Language[];
520
+ /** Enable shared memory between kernels */
521
+ sharedMemory?: boolean;
522
+ }
523
+
524
+ /** Notebook options */
525
+ export interface NotebookOptions extends SandboxOptions {
526
+ name?: string;
527
+ defaultLanguage?: Language;
528
+ }
@@ -0,0 +1,59 @@
1
+ /**
2
+ * Global type declarations for @ebowwa/sandbox
3
+ */
4
+
5
+ // WebAssembly types (for environments without DOM lib)
6
+ declare namespace WebAssembly {
7
+ interface Module {}
8
+ interface Instance {
9
+ exports: Exports;
10
+ }
11
+ interface Exports extends Record<string, Function | Memory | Table | Global> {}
12
+ interface Memory {
13
+ buffer: ArrayBuffer;
14
+ grow(pages: number): number;
15
+ }
16
+ interface Table {
17
+ length: number;
18
+ get(index: number): Function | null;
19
+ set(index: number, value: Function | null): void;
20
+ grow(delta: number): number;
21
+ }
22
+ interface Global {
23
+ value: any;
24
+ valueOf(): any;
25
+ }
26
+ interface CompileError extends Error {}
27
+ interface RuntimeError extends Error {}
28
+ interface ModuleExportDescriptor {
29
+ name: string;
30
+ kind: string;
31
+ }
32
+ interface ModuleImportDescriptor {
33
+ module: string;
34
+ name: string;
35
+ kind: string;
36
+ }
37
+
38
+ function validate(bytes: BufferSource): boolean;
39
+ function compile(bytes: BufferSource): Promise<Module>;
40
+ function instantiate(bytes: BufferSource, importObject?: Imports): Promise<Instance>;
41
+ function instantiate(module: Module, importObject?: Imports): Promise<Instance>;
42
+
43
+ namespace Module {
44
+ function exports(module: Module): ModuleExportDescriptor[];
45
+ function imports(module: Module): ModuleImportDescriptor[];
46
+ function customSections(module: Module, sectionName: string): ArrayBuffer[];
47
+ }
48
+ }
49
+
50
+ // Missing CellResult type - alias to ExecutionResult for now
51
+ export interface CellResult {
52
+ success: boolean;
53
+ value?: unknown;
54
+ error?: {
55
+ message: string;
56
+ type: string;
57
+ };
58
+ exports?: Map<string, unknown>;
59
+ }