@intella/sdk 0.0.1 → 0.0.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 (120) hide show
  1. package/dist/agent-manager.d.ts +47 -0
  2. package/dist/agent-manager.d.ts.map +1 -0
  3. package/dist/agent-manager.js +90 -0
  4. package/dist/agent-manager.js.map +1 -0
  5. package/dist/agents/base-agent.d.ts +41 -0
  6. package/dist/agents/base-agent.d.ts.map +1 -0
  7. package/dist/agents/base-agent.js +139 -0
  8. package/dist/agents/base-agent.js.map +1 -0
  9. package/dist/agents/claude-agent.d.ts +24 -0
  10. package/dist/agents/claude-agent.d.ts.map +1 -0
  11. package/dist/agents/claude-agent.js +65 -0
  12. package/dist/agents/claude-agent.js.map +1 -0
  13. package/dist/agents/codex-agent.d.ts +25 -0
  14. package/dist/agents/codex-agent.d.ts.map +1 -0
  15. package/dist/agents/codex-agent.js +62 -0
  16. package/dist/agents/codex-agent.js.map +1 -0
  17. package/dist/agents/intella-lite-agent.d.ts +21 -0
  18. package/dist/agents/intella-lite-agent.d.ts.map +1 -0
  19. package/dist/agents/intella-lite-agent.js +43 -0
  20. package/dist/agents/intella-lite-agent.js.map +1 -0
  21. package/dist/agents/opencode-agent.d.ts +20 -0
  22. package/dist/agents/opencode-agent.d.ts.map +1 -0
  23. package/dist/agents/opencode-agent.js +36 -0
  24. package/dist/agents/opencode-agent.js.map +1 -0
  25. package/dist/filesystem/agentfs-provider.d.ts +42 -0
  26. package/dist/filesystem/agentfs-provider.d.ts.map +1 -0
  27. package/dist/filesystem/agentfs-provider.js +308 -0
  28. package/dist/filesystem/agentfs-provider.js.map +1 -0
  29. package/dist/filesystem/base-provider.d.ts +55 -0
  30. package/dist/filesystem/base-provider.d.ts.map +1 -0
  31. package/dist/filesystem/base-provider.js +44 -0
  32. package/dist/filesystem/base-provider.js.map +1 -0
  33. package/dist/filesystem/index.d.ts +4 -0
  34. package/dist/filesystem/index.d.ts.map +1 -0
  35. package/{src/filesystem/index.ts → dist/filesystem/index.js} +1 -1
  36. package/dist/filesystem/index.js.map +1 -0
  37. package/dist/filesystem/memory-provider.d.ts +44 -0
  38. package/dist/filesystem/memory-provider.d.ts.map +1 -0
  39. package/dist/filesystem/memory-provider.js +227 -0
  40. package/dist/filesystem/memory-provider.js.map +1 -0
  41. package/dist/filesystem-manager.d.ts +75 -0
  42. package/dist/filesystem-manager.d.ts.map +1 -0
  43. package/dist/filesystem-manager.js +164 -0
  44. package/dist/filesystem-manager.js.map +1 -0
  45. package/dist/index.d.ts +18 -0
  46. package/dist/index.d.ts.map +1 -0
  47. package/{src/index.ts → dist/index.js} +3 -46
  48. package/dist/index.js.map +1 -0
  49. package/dist/orchestrator.d.ts +32 -0
  50. package/dist/orchestrator.d.ts.map +1 -0
  51. package/dist/orchestrator.js +136 -0
  52. package/dist/orchestrator.js.map +1 -0
  53. package/dist/sandbox/base-provider.d.ts +106 -0
  54. package/dist/sandbox/base-provider.d.ts.map +1 -0
  55. package/dist/sandbox/base-provider.js +73 -0
  56. package/dist/sandbox/base-provider.js.map +1 -0
  57. package/dist/sandbox/daytona-provider.d.ts +93 -0
  58. package/dist/sandbox/daytona-provider.d.ts.map +1 -0
  59. package/dist/sandbox/daytona-provider.js +378 -0
  60. package/dist/sandbox/daytona-provider.js.map +1 -0
  61. package/dist/sandbox/e2b-provider.d.ts +85 -0
  62. package/dist/sandbox/e2b-provider.d.ts.map +1 -0
  63. package/dist/sandbox/e2b-provider.js +342 -0
  64. package/dist/sandbox/e2b-provider.js.map +1 -0
  65. package/dist/sandbox/modal-provider.d.ts +92 -0
  66. package/dist/sandbox/modal-provider.d.ts.map +1 -0
  67. package/dist/sandbox/modal-provider.js +516 -0
  68. package/dist/sandbox/modal-provider.js.map +1 -0
  69. package/dist/sandbox-manager.d.ts +59 -0
  70. package/dist/sandbox-manager.d.ts.map +1 -0
  71. package/dist/sandbox-manager.js +141 -0
  72. package/dist/sandbox-manager.js.map +1 -0
  73. package/dist/sdk.d.ts +173 -0
  74. package/dist/sdk.d.ts.map +1 -0
  75. package/dist/sdk.js +273 -0
  76. package/dist/sdk.js.map +1 -0
  77. package/dist/types.d.ts +419 -0
  78. package/dist/types.d.ts.map +1 -0
  79. package/dist/types.js +2 -0
  80. package/dist/types.js.map +1 -0
  81. package/dist/utils/code-extractor.d.ts +103 -0
  82. package/dist/utils/code-extractor.d.ts.map +1 -0
  83. package/dist/utils/code-extractor.js +133 -0
  84. package/dist/utils/code-extractor.js.map +1 -0
  85. package/package.json +6 -1
  86. package/examples/claude-code/README.md +0 -178
  87. package/examples/claude-code/advanced-config.ts +0 -55
  88. package/examples/claude-code/basic-usage.ts +0 -56
  89. package/examples/claude-code/model-comparison.ts +0 -50
  90. package/examples/claude-code/orchestration.ts +0 -70
  91. package/examples/claude-code/streaming.ts +0 -69
  92. package/examples/claude-code/tsconfig.json +0 -19
  93. package/examples/code-extractor/README.md +0 -77
  94. package/examples/code-extractor/example.ts +0 -145
  95. package/examples/filesystem/basic-usage.ts +0 -84
  96. package/examples/integrated-task/README.md +0 -68
  97. package/examples/integrated-task/integrated-usage.ts +0 -193
  98. package/examples/integrated-task/simple-example.ts +0 -51
  99. package/examples/integrated-task/tsconfig.json +0 -19
  100. package/examples/sandbox/basic-usage.ts +0 -173
  101. package/src/agent-manager.ts +0 -104
  102. package/src/agents/base-agent.ts +0 -166
  103. package/src/agents/claude-agent.ts +0 -77
  104. package/src/agents/codex-agent.ts +0 -72
  105. package/src/agents/intella-lite-agent.ts +0 -55
  106. package/src/agents/opencode-agent.ts +0 -45
  107. package/src/filesystem/agentfs-provider.ts +0 -328
  108. package/src/filesystem/base-provider.ts +0 -98
  109. package/src/filesystem/memory-provider.ts +0 -267
  110. package/src/filesystem-manager.ts +0 -213
  111. package/src/orchestrator.ts +0 -177
  112. package/src/sandbox/base-provider.ts +0 -184
  113. package/src/sandbox/daytona-provider.ts +0 -462
  114. package/src/sandbox/e2b-provider.ts +0 -419
  115. package/src/sandbox/modal-provider.ts +0 -597
  116. package/src/sandbox-manager.ts +0 -175
  117. package/src/sdk.ts +0 -401
  118. package/src/types.ts +0 -451
  119. package/src/utils/code-extractor.ts +0 -194
  120. package/tsconfig.json +0 -25
@@ -1,597 +0,0 @@
1
- import { BaseSandboxProvider } from './base-provider.js';
2
- import type { SandboxConfig, CommandResult, CodeExecutionResult, SandboxInfo } from '../types.js';
3
- import { ModalClient, Sandbox } from 'modal';
4
-
5
- /**
6
- * Modal Sandbox Provider
7
- * Provides sandbox execution capabilities using Modal
8
- */
9
- export class ModalSandboxProvider extends BaseSandboxProvider {
10
- protected client: ModalClient | null = null;
11
- private sandboxInstance: Sandbox | null = null;
12
- private app: any | null = null;
13
- private image: any | null = null;
14
-
15
- constructor(config?: SandboxConfig) {
16
- super('modal');
17
- if (config) {
18
- this.config = config;
19
- }
20
- }
21
-
22
- getClient(): ModalClient {
23
- if (!this.client) {
24
- const tokenId = this.config.apiKey || process.env.MODAL_TOKEN_ID;
25
- const tokenSecret = process.env.MODAL_TOKEN_SECRET;
26
- if (tokenId && tokenSecret) {
27
- this.client = new ModalClient({
28
- tokenId,
29
- tokenSecret,
30
- });
31
- } else {
32
- console.warn('Modal token ID and secret are not set. Using environment variables.');
33
- try {
34
- this.client = new ModalClient();
35
- } catch (error) {
36
- throw new Error('Failed to initialize Modal client: ' + (error instanceof Error ? error.message : String(error)));
37
- }
38
- }
39
- }
40
- return this.client;
41
- }
42
-
43
- /**
44
- * Initialize/create a Modal sandbox
45
- */
46
- protected async initializeSandbox(config?: SandboxConfig): Promise<void> {
47
- if (config) {
48
- this.config = { ...this.config, ...config };
49
- }
50
-
51
- try {
52
- // Dynamic import to handle optional dependency
53
-
54
- // Initialize Modal client
55
- // ModalClient can be initialized without parameters if MODAL_TOKEN_ID and MODAL_TOKEN_SECRET are in env
56
- const modalClient = this.getClient()!;
57
-
58
- // Get or create app
59
- const appName = (this.config.appName as string) || 'intella-sandbox';
60
- this.app = await modalClient.apps.fromName(appName, {
61
- createIfMissing: true,
62
- });
63
-
64
- // Create or get image
65
- const imageName = (this.config.imageName as string) || 'python:3.13-slim';
66
- if (imageName.includes(':')) {
67
- // Registry image (e.g., "python:3.13-slim")
68
- this.image = modalClient.images.fromRegistry(imageName);
69
- } else {
70
- // Try named image first, fallback to registry if not found
71
- try {
72
- this.image = modalClient.images.fromId(this.config.fromSandboxId || '');
73
- } catch {
74
- // If named image doesn't exist, try as registry image
75
- this.image = modalClient.images.fromRegistry(imageName);
76
- }
77
- }
78
-
79
- // Create sandbox with configuration
80
- const sandboxOptions: any = {
81
- timeout: Math.floor((this.config.timeout || 5 * 60 * 1000) / 1000), // Convert to seconds
82
- };
83
-
84
- if (this.config.env) {
85
- const secret = await modalClient.secrets.fromObject(this.config.env);
86
- sandboxOptions.secrets = [secret];
87
- }
88
-
89
- if (this.config.workdir) {
90
- sandboxOptions.workdir = this.config.workdir;
91
- }
92
-
93
- this.sandboxInstance = await modalClient.sandboxes.create(
94
- this.app,
95
- this.image,
96
- sandboxOptions
97
- );
98
-
99
- this.sandboxId = this.sandboxInstance.sandboxId || '';
100
- this.initialized = true;
101
- } catch (error) {
102
- throw new Error(
103
- `Failed to initialize Modal sandbox: ${error instanceof Error ? error.message : String(error)}`
104
- );
105
- }
106
- }
107
-
108
- /**
109
- * Connect to an existing Modal sandbox by ID
110
- */
111
- async fromSandbox(sandboxId: string, config?: SandboxConfig): Promise<Sandbox> {
112
- if (config) {
113
- this.config = { ...this.config, ...config };
114
- }
115
-
116
- try {
117
- // Initialize Modal client
118
- const modalClient = this.getClient()!;
119
-
120
- // Get or create app (needed for fromId)
121
- const appName = (this.config.appName as string) || 'intella-sandbox';
122
- this.app = await modalClient.apps.fromName(appName, {
123
- createIfMissing: true,
124
- });
125
-
126
- // Get existing sandbox by ID
127
- this.sandboxInstance = await modalClient.sandboxes.fromId(sandboxId);
128
-
129
- this.sandboxId = this.sandboxInstance.sandboxId || sandboxId;
130
- this.initialized = true;
131
- return this.sandboxInstance;
132
- } catch (error) {
133
- throw new Error(
134
- `Failed to connect to Modal sandbox: ${error instanceof Error ? error.message : String(error)}`
135
- );
136
- }
137
- }
138
-
139
- /**
140
- * Close/cleanup the Modal sandbox
141
- */
142
- async close(): Promise<void> {
143
- if (this.sandboxInstance && this.initialized) {
144
- try {
145
- await this.sandboxInstance.terminate();
146
- } catch (error) {
147
- // Ignore errors during cleanup
148
- console.warn('Error closing Modal sandbox:', error);
149
- }
150
- this.sandboxInstance = null;
151
- this.client = null;
152
- this.app = null;
153
- this.image = null;
154
- this.sandboxId = null;
155
- this.initialized = false;
156
- }
157
- }
158
-
159
- /**
160
- * Execute a command in the Modal sandbox
161
- */
162
- async executeCommand(
163
- command: string,
164
- options?: {
165
- cwd?: string;
166
- env?: Record<string, string>;
167
- timeout?: number;
168
- }
169
- ): Promise<CommandResult> {
170
- this.ensureInitialized();
171
-
172
- const startTime = Date.now();
173
- try {
174
- // Parse command string into array
175
- // Handle quoted arguments properly
176
- const commandParts = command.match(/(?:[^\s"]+|"[^"]*")+/g) || [command];
177
- const cmdArray = commandParts.map((part) => part.replace(/^"|"$/g, ''));
178
-
179
- const execOptions: any = {
180
- timeout: Math.floor((options?.timeout || this.config.timeout || 3000) / 1000), // Convert to seconds
181
- };
182
-
183
- // Execute command
184
- const process = await this.sandboxInstance!.exec(cmdArray, execOptions);
185
-
186
- // Read stdout and stderr
187
- let stdout = '';
188
- let stderr = '';
189
-
190
- // Read stdout
191
- try {
192
- stdout = await process.stdout.readText();
193
- } catch (e) {
194
- // If readText is not available, try iterating
195
- if (process.stdout && typeof process.stdout[Symbol.asyncIterator] === 'function') {
196
- for await (const chunk of process.stdout) {
197
- stdout += typeof chunk === 'string' ? chunk : [chunk as string].toString();
198
- }
199
- }
200
- }
201
-
202
- // Read stderr
203
- try {
204
- stderr = await process.stderr.readText();
205
- } catch (e) {
206
- // If readText is not available, try iterating
207
- if (process.stderr && typeof process.stderr[Symbol.asyncIterator] === 'function') {
208
- for await (const chunk of process.stderr) {
209
- stderr += typeof chunk === 'string' ? chunk : [chunk as string].toString();
210
- }
211
- }
212
- }
213
-
214
- // Wait for process to complete
215
- await process.wait();
216
-
217
- const executionTime = Date.now() - startTime;
218
-
219
- return {
220
- exitCode: process.returncode || 0,
221
- stdout: stdout || '',
222
- stderr: stderr || '',
223
- executionTime,
224
- };
225
- } catch (error) {
226
- const executionTime = Date.now() - startTime;
227
- return {
228
- exitCode: 1,
229
- stdout: '',
230
- stderr: error instanceof Error ? error.message : String(error),
231
- executionTime,
232
- };
233
- }
234
- }
235
-
236
- /**
237
- * Run code (e.g., Python, JavaScript) in the Modal sandbox
238
- */
239
- async runCode(
240
- code: string,
241
- options?: {
242
- language?: string;
243
- env?: Record<string, string>;
244
- timeout?: number;
245
- onStdout?: (data: string) => void;
246
- onStderr?: (data: string) => void;
247
- }
248
- ): Promise<CodeExecutionResult> {
249
- this.ensureInitialized();
250
-
251
- const startTime = Date.now();
252
- try {
253
- // Determine interpreter based on language
254
- const language = options?.language || 'python';
255
- const interpreterMap: Record<string, string[]> = {
256
- python: ['python', '-c'],
257
- javascript: ['node', '-e'],
258
- typescript: ['ts-node', '-e'],
259
- bash: ['bash', '-c'],
260
- sh: ['sh', '-c'],
261
- };
262
-
263
- const interpreter = interpreterMap[language.toLowerCase()] || ['python', '-c'];
264
-
265
- const execOptions: any = {
266
- timeout: (options?.timeout || this.config.timeout || 30000) / 1000, // Convert to seconds
267
- };
268
-
269
- // Execute code
270
- const process = await this.sandboxInstance!.exec(
271
- [...interpreter, code],
272
- execOptions
273
- );
274
-
275
- // Stream stdout/stderr if callbacks provided
276
- const stdoutChunks: string[] = [];
277
- const stderrChunks: string[] = [];
278
-
279
- // Handle stdout
280
- if (options?.onStdout && process.stdout && typeof process.stdout[Symbol.asyncIterator] === 'function') {
281
- // Stream mode with callback
282
- for await (const line of process.stdout) {
283
- const text = typeof line === 'string' ? line : [line as string].toString();
284
- stdoutChunks.push(text);
285
- options.onStdout(text);
286
- }
287
- } else {
288
- // Read all at once
289
- try {
290
- const stdoutText = await process.stdout.readText();
291
- const lines = stdoutText.split('\n');
292
- stdoutChunks.push(...lines);
293
- } catch (e) {
294
- // Fallback to iteration
295
- if (process.stdout && typeof process.stdout[Symbol.asyncIterator] === 'function') {
296
- for await (const line of process.stdout) {
297
- const text = typeof line === 'string' ? line : [line as string].toString();
298
- stdoutChunks.push(text);
299
- }
300
- }
301
- }
302
- }
303
-
304
- // Handle stderr
305
- if (options?.onStderr && process.stderr && typeof process.stderr[Symbol.asyncIterator] === 'function') {
306
- // Stream mode with callback
307
- for await (const line of process.stderr) {
308
- const text = typeof line === 'string' ? line : [line as string].toString();
309
- stderrChunks.push(text);
310
- options.onStderr(text);
311
- }
312
- } else {
313
- // Read all at once
314
- try {
315
- const stderrText = await process.stderr.readText();
316
- const lines = stderrText.split('\n');
317
- stderrChunks.push(...lines);
318
- } catch (e) {
319
- // Fallback to iteration
320
- if (process.stderr && typeof process.stderr[Symbol.asyncIterator] === 'function') {
321
- for await (const line of process.stderr) {
322
- const text = typeof line === 'string' ? line : [line as string].toString();
323
- stderrChunks.push(text);
324
- }
325
- }
326
- }
327
- }
328
-
329
- // Wait for process to complete
330
- await process.wait();
331
-
332
- const stdout = stdoutChunks.join('\n');
333
- const stderr = stderrChunks.join('\n');
334
- const executionTime = Date.now() - startTime;
335
-
336
- return {
337
- text: stdout || undefined,
338
- results: stdout ? [{ text: stdout }] : [],
339
- stdout: stdoutChunks,
340
- stderr: stderrChunks,
341
- error:
342
- process.returncode !== 0
343
- ? {
344
- name: 'CodeExecutionError',
345
- value: stderr || 'Code execution failed',
346
- traceback: stderr || '',
347
- }
348
- : undefined,
349
- executionTime,
350
- };
351
- } catch (error) {
352
- const executionTime = Date.now() - startTime;
353
- return {
354
- text: undefined,
355
- results: [],
356
- stdout: [],
357
- stderr: [error instanceof Error ? error.message : String(error)],
358
- error: {
359
- name: 'CodeExecutionError',
360
- value: error instanceof Error ? error.message : String(error),
361
- traceback: error instanceof Error ? error.stack || '' : '',
362
- },
363
- executionTime,
364
- };
365
- }
366
- }
367
-
368
- /**
369
- * Upload a file to the Modal sandbox
370
- * Uses the filesystem API
371
- */
372
- async uploadFile(localPath: string, remotePath: string): Promise<void> {
373
- this.ensureInitialized();
374
-
375
- try {
376
- const fs = await import('fs/promises');
377
- const content = await fs.readFile(localPath);
378
-
379
- // Use filesystem API to write file
380
- const file = await this.sandboxInstance!.open(remotePath, 'w');
381
- await file.write(content);
382
- file.close();
383
- } catch (error) {
384
- throw new Error(
385
- `Failed to upload file to Modal sandbox: ${error instanceof Error ? error.message : String(error)}`
386
- );
387
- }
388
- }
389
-
390
- /**
391
- * Download a file from the Modal sandbox
392
- * Uses the filesystem API
393
- */
394
- async downloadFile(remotePath: string, localPath: string): Promise<void> {
395
- this.ensureInitialized();
396
-
397
- try {
398
- // Use filesystem API to read file
399
- const file = await this.sandboxInstance!.open(remotePath, 'r');
400
- const content = await file.read();
401
- file.close();
402
-
403
- const fs = await import('fs/promises');
404
- // Handle Buffer or Uint8Array
405
- const buffer = Buffer.isBuffer(content) ? content : Buffer.from(content);
406
- await fs.writeFile(localPath, buffer);
407
- } catch (error) {
408
- throw new Error(
409
- `Failed to download file from Modal sandbox: ${error instanceof Error ? error.message : String(error)}`
410
- );
411
- }
412
- }
413
-
414
- /**
415
- * Read a file from the Modal sandbox
416
- * Uses the filesystem API
417
- */
418
- async readFile(path: string): Promise<string> {
419
- this.ensureInitialized();
420
-
421
- try {
422
- // Use filesystem API to read file
423
- const file = await this.sandboxInstance!.open(path, 'r');
424
- const content = await file.read();
425
- file.close();
426
- return typeof content === 'string' ? content : [content as unknown as string].toString();
427
- } catch (error) {
428
- throw new Error(
429
- `Failed to read file from Modal sandbox: ${error instanceof Error ? error.message : String(error)}`
430
- );
431
- }
432
- }
433
-
434
- /**
435
- * Write a file to the Modal sandbox
436
- * Uses the filesystem API
437
- */
438
- async writeFile(path: string, content: string): Promise<void> {
439
- this.ensureInitialized();
440
-
441
- try {
442
- // Use filesystem API to write file
443
- const file = await this.sandboxInstance!.open(path, 'w');
444
- file.write(Buffer.from(content, 'utf-8'));
445
- file.close();
446
- } catch (error) {
447
- throw new Error(
448
- `Failed to write file to Modal sandbox: ${error instanceof Error ? error.message : String(error)}`
449
- );
450
- }
451
- }
452
-
453
- /**
454
- * List files in a directory
455
- * Uses exec to run ls command
456
- */
457
- async listFiles(path: string): Promise<string[]> {
458
- this.ensureInitialized();
459
-
460
- try {
461
- const process = await this.sandboxInstance!.exec(['ls', '-1', path], {
462
- timeoutMs: 5000,
463
- });
464
-
465
- let output = '';
466
- try {
467
- output = await process.stdout.readText();
468
- } catch (e) {
469
- // Fallback to iteration
470
- if (process.stdout && typeof process.stdout[Symbol.asyncIterator] === 'function') {
471
- for await (const chunk of process.stdout) {
472
- output += typeof chunk === 'string' ? chunk : [chunk as string].toString();
473
- }
474
- }
475
- }
476
-
477
- await process.wait();
478
-
479
- // Parse ls output
480
- return output
481
- .split('\n')
482
- .map((line: string) => line.trim())
483
- .filter((line: string) => line.length > 0);
484
- } catch (error) {
485
- throw new Error(
486
- `Failed to list files in Modal sandbox: ${error instanceof Error ? error.message : String(error)}`
487
- );
488
- }
489
- }
490
-
491
- /**
492
- * Check if a file exists
493
- */
494
- async fileExists(path: string): Promise<boolean> {
495
- this.ensureInitialized();
496
-
497
- try {
498
- const process = await this.sandboxInstance!.exec(['test', '-f', path], {
499
- timeoutMs: 5000,
500
- });
501
- await process.wait();
502
- return (process.returncode || 0) === 0;
503
- } catch {
504
- return false;
505
- }
506
- }
507
-
508
- /**
509
- * Delete a file
510
- * Uses exec to run rm command
511
- */
512
- async deleteFile(path: string): Promise<void> {
513
- this.ensureInitialized();
514
-
515
- try {
516
- const process = await this.sandboxInstance!.exec(['rm', path], {
517
- timeoutMs: 5000,
518
- });
519
- await process.wait();
520
-
521
- if ((process.returncode || 0) !== 0) {
522
- let stderr = '';
523
- try {
524
- stderr = await process.stderr.readText();
525
- } catch (e) {
526
- // Ignore read errors
527
- }
528
- throw new Error(`Failed to delete file: ${stderr || 'Unknown error'}`);
529
- }
530
- } catch (error) {
531
- throw new Error(
532
- `Failed to delete file in Modal sandbox: ${error instanceof Error ? error.message : String(error)}`
533
- );
534
- }
535
- }
536
-
537
- /**
538
- * Get sandbox status
539
- */
540
- async getStatus(): Promise<{
541
- isRunning: boolean;
542
- createdAt?: number;
543
- [key: string]: unknown;
544
- }> {
545
- this.ensureInitialized();
546
-
547
- try {
548
- // Modal sandboxes don't expose a direct status endpoint
549
- // We can check if the sandbox instance is available
550
- return {
551
- isRunning: this.initialized && this.sandboxInstance !== null,
552
- sandboxId: this.sandboxId,
553
- };
554
- } catch {
555
- return {
556
- isRunning: false,
557
- };
558
- }
559
- }
560
-
561
- /**
562
- * Get detailed sandbox information
563
- */
564
- async getInfo(sandboxId?: string): Promise<SandboxInfo> {
565
-
566
- if (!sandboxId && this.sandboxInstance) {
567
- this.ensureInitialized();
568
- const info = this.sandboxInstance
569
- const isRunning = await info.poll();
570
- return {
571
- sandboxId: this.sandboxId!,
572
- provider: this.type,
573
- isRunning: isRunning === null,
574
- isInitialized: this.initialized,
575
- createdAt: new Date(),
576
- metadata: {
577
- error: isRunning
578
- },
579
- info: this.sandboxInstance,
580
- };
581
- } else if (sandboxId) {
582
- const sandbox = await this.client!.sandboxes.fromId(sandboxId);
583
- const isRunning = await sandbox.poll();
584
- return {
585
- sandboxId: sandbox.sandboxId,
586
- provider: this.type,
587
- isRunning: isRunning === null,
588
- isInitialized: this.initialized,
589
- createdAt: new Date(),
590
- metadata: {},
591
- info: sandbox,
592
- };
593
- } else {
594
- throw new Error('Sandbox ID or active instance is required to get sandbox info');
595
- }
596
- }
597
- }