computesdk 1.8.2 → 1.8.4
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/dist/index.d.mts +110 -7
- package/dist/index.d.ts +110 -7
- package/dist/index.js +49 -44
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +49 -44
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import * as _computesdk_client from '@computesdk/client';
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* Sandbox Types
|
|
3
5
|
*
|
|
@@ -200,6 +202,86 @@ interface TypedSandbox<TProvider extends Provider$1> extends Omit<Sandbox<Extrac
|
|
|
200
202
|
/** Get the native provider sandbox instance with proper typing */
|
|
201
203
|
getInstance(): ExtractProviderSandboxType<TProvider>;
|
|
202
204
|
}
|
|
205
|
+
/**
|
|
206
|
+
* Enhanced sandbox type that includes ComputeClient features
|
|
207
|
+
*
|
|
208
|
+
* When a sandbox is created with an API key/JWT, it gets wrapped with ComputeClient
|
|
209
|
+
* which adds powerful features like WebSocket terminals, file watchers, and signals.
|
|
210
|
+
*
|
|
211
|
+
* @example
|
|
212
|
+
* ```typescript
|
|
213
|
+
* const sandbox = await compute.sandbox.create();
|
|
214
|
+
*
|
|
215
|
+
* // ComputeClient features (only available when API key is configured)
|
|
216
|
+
* const terminal = await sandbox.createTerminal();
|
|
217
|
+
* const watcher = await sandbox.createWatcher('/home/project');
|
|
218
|
+
* const signals = await sandbox.startSignals();
|
|
219
|
+
*
|
|
220
|
+
* // Original sandbox features still work
|
|
221
|
+
* await sandbox.runCommand('ls');
|
|
222
|
+
* const instance = sandbox.getInstance();
|
|
223
|
+
* ```
|
|
224
|
+
*/
|
|
225
|
+
type ComputeEnhancedSandbox<TSandbox = any> = Sandbox<TSandbox> & {
|
|
226
|
+
/** The original provider sandbox instance */
|
|
227
|
+
__originalSandbox: Sandbox<TSandbox>;
|
|
228
|
+
/** Create a persistent terminal session with WebSocket integration */
|
|
229
|
+
createTerminal(shell?: string, encoding?: 'raw' | 'base64'): Promise<_computesdk_client.Terminal>;
|
|
230
|
+
/** Create a file watcher with real-time change notifications */
|
|
231
|
+
createWatcher(path: string, options?: {
|
|
232
|
+
includeContent?: boolean;
|
|
233
|
+
ignored?: string[];
|
|
234
|
+
encoding?: 'raw' | 'base64';
|
|
235
|
+
}): Promise<_computesdk_client.FileWatcher>;
|
|
236
|
+
/** Start the signal service for port and error monitoring */
|
|
237
|
+
startSignals(): Promise<_computesdk_client.SignalService>;
|
|
238
|
+
/** Execute a one-off command without creating a persistent terminal */
|
|
239
|
+
execute(options: {
|
|
240
|
+
command: string;
|
|
241
|
+
shell?: string;
|
|
242
|
+
}): Promise<any>;
|
|
243
|
+
/** List all active terminals */
|
|
244
|
+
listTerminals(): Promise<any[]>;
|
|
245
|
+
/** Get terminal by ID */
|
|
246
|
+
getTerminal(id: string): Promise<any>;
|
|
247
|
+
/** List all active file watchers */
|
|
248
|
+
listWatchers(): Promise<any>;
|
|
249
|
+
/** Get file watcher by ID */
|
|
250
|
+
getWatcher(id: string): Promise<any>;
|
|
251
|
+
/** Get signal service status */
|
|
252
|
+
getSignalStatus(): Promise<any>;
|
|
253
|
+
/** Create a session token (requires access token) */
|
|
254
|
+
createSessionToken(options?: {
|
|
255
|
+
description?: string;
|
|
256
|
+
expiresIn?: number;
|
|
257
|
+
}): Promise<any>;
|
|
258
|
+
/** List all session tokens (requires access token) */
|
|
259
|
+
listSessionTokens(): Promise<any>;
|
|
260
|
+
/** Get session token details (requires access token) */
|
|
261
|
+
getSessionToken(tokenId: string): Promise<any>;
|
|
262
|
+
/** Revoke a session token (requires access token) */
|
|
263
|
+
revokeSessionToken(tokenId: string): Promise<void>;
|
|
264
|
+
/** Create a magic link for browser authentication (requires access token) */
|
|
265
|
+
createMagicLink(options?: {
|
|
266
|
+
redirectUrl?: string;
|
|
267
|
+
}): Promise<any>;
|
|
268
|
+
/** Check authentication status */
|
|
269
|
+
getAuthStatus(): Promise<any>;
|
|
270
|
+
/** Get authentication information */
|
|
271
|
+
getAuthInfo(): Promise<any>;
|
|
272
|
+
/** Set authentication token manually */
|
|
273
|
+
setToken(token: string): void;
|
|
274
|
+
/** Get current authentication token */
|
|
275
|
+
getToken(): string | null;
|
|
276
|
+
/** Get current sandbox URL */
|
|
277
|
+
getSandboxUrl(): string;
|
|
278
|
+
/** Disconnect WebSocket connection */
|
|
279
|
+
disconnect(): Promise<void>;
|
|
280
|
+
};
|
|
281
|
+
/**
|
|
282
|
+
* Typed enhanced sandbox that preserves both provider typing and ComputeClient features
|
|
283
|
+
*/
|
|
284
|
+
type TypedEnhancedSandbox<TProvider extends Provider$1> = ComputeEnhancedSandbox<ExtractProviderSandboxType<TProvider>> & Omit<TypedSandbox<TProvider>, keyof Sandbox>;
|
|
203
285
|
|
|
204
286
|
/**
|
|
205
287
|
* Common options for creating snapshots
|
|
@@ -299,7 +381,9 @@ interface ComputeConfig<TProvider extends Provider = Provider> {
|
|
|
299
381
|
provider?: TProvider;
|
|
300
382
|
/** API key for compute CLI authentication */
|
|
301
383
|
apiKey?: string;
|
|
302
|
-
/**
|
|
384
|
+
/** Access token for compute CLI authentication */
|
|
385
|
+
accessToken?: string;
|
|
386
|
+
/** @deprecated Use accessToken instead. Kept for backwards compatibility */
|
|
303
387
|
jwt?: string;
|
|
304
388
|
}
|
|
305
389
|
/**
|
|
@@ -341,17 +425,18 @@ interface ComputeAPI {
|
|
|
341
425
|
}
|
|
342
426
|
/**
|
|
343
427
|
* Typed Compute API interface that preserves provider type information
|
|
428
|
+
* When auth (apiKey/accessToken) is configured, returns enhanced sandboxes with ComputeClient features
|
|
344
429
|
*/
|
|
345
|
-
interface TypedComputeAPI<TProvider extends Provider> extends Omit<ComputeAPI, 'sandbox' | 'setConfig'> {
|
|
430
|
+
interface TypedComputeAPI<TProvider extends Provider, TIsEnhanced extends boolean = boolean> extends Omit<ComputeAPI, 'sandbox' | 'setConfig'> {
|
|
346
431
|
/** Configuration management that returns typed compute instance */
|
|
347
432
|
setConfig<T extends Provider>(config: ComputeConfig<T>): TypedComputeAPI<T>;
|
|
348
433
|
sandbox: {
|
|
349
434
|
/** Create a sandbox from the configured provider with proper typing */
|
|
350
|
-
create(params?: Omit<CreateSandboxParamsWithOptionalProvider, 'provider'>): Promise<TypedSandbox<TProvider>>;
|
|
435
|
+
create(params?: Omit<CreateSandboxParamsWithOptionalProvider, 'provider'>): Promise<TIsEnhanced extends true ? TypedEnhancedSandbox<TProvider> : TypedSandbox<TProvider>>;
|
|
351
436
|
/** Get an existing sandbox by ID from the configured provider with proper typing */
|
|
352
|
-
getById(sandboxId: string): Promise<TypedSandbox<TProvider> | null>;
|
|
437
|
+
getById(sandboxId: string): Promise<TIsEnhanced extends true ? TypedEnhancedSandbox<TProvider> : TypedSandbox<TProvider> | null>;
|
|
353
438
|
/** List all active sandboxes from the configured provider with proper typing */
|
|
354
|
-
list(): Promise<TypedSandbox<TProvider>[]>;
|
|
439
|
+
list(): Promise<TIsEnhanced extends true ? TypedEnhancedSandbox<TProvider>[] : TypedSandbox<TProvider>[]>;
|
|
355
440
|
/** Destroy a sandbox via the configured provider */
|
|
356
441
|
destroy(sandboxId: string): Promise<void>;
|
|
357
442
|
};
|
|
@@ -375,15 +460,33 @@ declare const compute: ComputeAPI;
|
|
|
375
460
|
* import { e2b } from '@computesdk/e2b'
|
|
376
461
|
* import { createCompute } from 'computesdk'
|
|
377
462
|
*
|
|
463
|
+
* // With API key (automatically gets access token from license server)
|
|
378
464
|
* const compute = createCompute({
|
|
379
465
|
* defaultProvider: e2b({ apiKey: 'your-key' }),
|
|
466
|
+
* apiKey: 'computesdk_live_...' // Returns enhanced sandboxes
|
|
467
|
+
* });
|
|
468
|
+
*
|
|
469
|
+
* // Or with direct access token
|
|
470
|
+
* const compute2 = createCompute({
|
|
471
|
+
* defaultProvider: e2b({ apiKey: 'your-key' }),
|
|
472
|
+
* accessToken: 'your-access-token' // Returns enhanced sandboxes
|
|
380
473
|
* });
|
|
381
474
|
*
|
|
382
475
|
* const sandbox = await compute.sandbox.create();
|
|
383
476
|
* const instance = sandbox.getInstance(); // ✅ Properly typed E2B Sandbox!
|
|
477
|
+
* await sandbox.createTerminal(); // ✅ Enhanced sandbox features!
|
|
384
478
|
* ```
|
|
385
479
|
*/
|
|
386
|
-
declare function createCompute<TProvider extends Provider>(config: ComputeConfig<TProvider>
|
|
480
|
+
declare function createCompute<TProvider extends Provider>(config: ComputeConfig<TProvider> & {
|
|
481
|
+
apiKey: string;
|
|
482
|
+
}): TypedComputeAPI<TProvider, true>;
|
|
483
|
+
declare function createCompute<TProvider extends Provider>(config: ComputeConfig<TProvider> & {
|
|
484
|
+
accessToken: string;
|
|
485
|
+
}): TypedComputeAPI<TProvider, true>;
|
|
486
|
+
declare function createCompute<TProvider extends Provider>(config: ComputeConfig<TProvider> & {
|
|
487
|
+
jwt: string;
|
|
488
|
+
}): TypedComputeAPI<TProvider, true>;
|
|
489
|
+
declare function createCompute<TProvider extends Provider>(config: ComputeConfig<TProvider>): TypedComputeAPI<TProvider, false>;
|
|
387
490
|
|
|
388
491
|
/**
|
|
389
492
|
* Simplified Request Handler for Web Framework Integration
|
|
@@ -525,4 +628,4 @@ interface ProviderConfig<TSandbox = any, TConfig = any, TTemplate = any, TSnapsh
|
|
|
525
628
|
*/
|
|
526
629
|
declare function createProvider<TSandbox, TConfig = any, TTemplate = any, TSnapshot = any>(providerConfig: ProviderConfig<TSandbox, TConfig, TTemplate, TSnapshot>): (config: TConfig) => Provider<TSandbox, TTemplate, TSnapshot>;
|
|
527
630
|
|
|
528
|
-
export { CommandExitError, type ComputeAPI, type ComputeConfig, type ComputeRequest, type ComputeResponse, type CreateSandboxOptions, type CreateSandboxParams, type CreateSandboxParamsWithOptionalProvider, type CreateSnapshotOptions, type CreateTemplateOptions, type ExecutionResult, type ExtractSandboxInstanceType, type FileEntry, type HandleComputeRequestParams, type ListSnapshotsOptions, type ListTemplatesOptions, type Provider, type ProviderConfig, type ProviderSandboxManager, type ProviderSandboxTypeMap, type ProviderSnapshotManager, type ProviderTemplateManager, type RunCommandOptions, type Runtime, type Sandbox, type SandboxFileSystem, type SandboxInfo, type SandboxMethods, type SandboxStatus, type SnapshotMethods, type TemplateMethods, type TypedComputeAPI, type TypedSandbox, compute, createBackgroundCommand, createCompute, createProvider, handleComputeRequest, isCommandExitError };
|
|
631
|
+
export { CommandExitError, type ComputeAPI, type ComputeConfig, type ComputeEnhancedSandbox, type ComputeRequest, type ComputeResponse, type CreateSandboxOptions, type CreateSandboxParams, type CreateSandboxParamsWithOptionalProvider, type CreateSnapshotOptions, type CreateTemplateOptions, type ExecutionResult, type ExtractSandboxInstanceType, type FileEntry, type HandleComputeRequestParams, type ListSnapshotsOptions, type ListTemplatesOptions, type Provider, type ProviderConfig, type ProviderSandboxManager, type ProviderSandboxTypeMap, type ProviderSnapshotManager, type ProviderTemplateManager, type RunCommandOptions, type Runtime, type Sandbox, type SandboxFileSystem, type SandboxInfo, type SandboxMethods, type SandboxStatus, type SnapshotMethods, type TemplateMethods, type TypedComputeAPI, type TypedEnhancedSandbox, type TypedSandbox, compute, createBackgroundCommand, createCompute, createProvider, handleComputeRequest, isCommandExitError };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import * as _computesdk_client from '@computesdk/client';
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* Sandbox Types
|
|
3
5
|
*
|
|
@@ -200,6 +202,86 @@ interface TypedSandbox<TProvider extends Provider$1> extends Omit<Sandbox<Extrac
|
|
|
200
202
|
/** Get the native provider sandbox instance with proper typing */
|
|
201
203
|
getInstance(): ExtractProviderSandboxType<TProvider>;
|
|
202
204
|
}
|
|
205
|
+
/**
|
|
206
|
+
* Enhanced sandbox type that includes ComputeClient features
|
|
207
|
+
*
|
|
208
|
+
* When a sandbox is created with an API key/JWT, it gets wrapped with ComputeClient
|
|
209
|
+
* which adds powerful features like WebSocket terminals, file watchers, and signals.
|
|
210
|
+
*
|
|
211
|
+
* @example
|
|
212
|
+
* ```typescript
|
|
213
|
+
* const sandbox = await compute.sandbox.create();
|
|
214
|
+
*
|
|
215
|
+
* // ComputeClient features (only available when API key is configured)
|
|
216
|
+
* const terminal = await sandbox.createTerminal();
|
|
217
|
+
* const watcher = await sandbox.createWatcher('/home/project');
|
|
218
|
+
* const signals = await sandbox.startSignals();
|
|
219
|
+
*
|
|
220
|
+
* // Original sandbox features still work
|
|
221
|
+
* await sandbox.runCommand('ls');
|
|
222
|
+
* const instance = sandbox.getInstance();
|
|
223
|
+
* ```
|
|
224
|
+
*/
|
|
225
|
+
type ComputeEnhancedSandbox<TSandbox = any> = Sandbox<TSandbox> & {
|
|
226
|
+
/** The original provider sandbox instance */
|
|
227
|
+
__originalSandbox: Sandbox<TSandbox>;
|
|
228
|
+
/** Create a persistent terminal session with WebSocket integration */
|
|
229
|
+
createTerminal(shell?: string, encoding?: 'raw' | 'base64'): Promise<_computesdk_client.Terminal>;
|
|
230
|
+
/** Create a file watcher with real-time change notifications */
|
|
231
|
+
createWatcher(path: string, options?: {
|
|
232
|
+
includeContent?: boolean;
|
|
233
|
+
ignored?: string[];
|
|
234
|
+
encoding?: 'raw' | 'base64';
|
|
235
|
+
}): Promise<_computesdk_client.FileWatcher>;
|
|
236
|
+
/** Start the signal service for port and error monitoring */
|
|
237
|
+
startSignals(): Promise<_computesdk_client.SignalService>;
|
|
238
|
+
/** Execute a one-off command without creating a persistent terminal */
|
|
239
|
+
execute(options: {
|
|
240
|
+
command: string;
|
|
241
|
+
shell?: string;
|
|
242
|
+
}): Promise<any>;
|
|
243
|
+
/** List all active terminals */
|
|
244
|
+
listTerminals(): Promise<any[]>;
|
|
245
|
+
/** Get terminal by ID */
|
|
246
|
+
getTerminal(id: string): Promise<any>;
|
|
247
|
+
/** List all active file watchers */
|
|
248
|
+
listWatchers(): Promise<any>;
|
|
249
|
+
/** Get file watcher by ID */
|
|
250
|
+
getWatcher(id: string): Promise<any>;
|
|
251
|
+
/** Get signal service status */
|
|
252
|
+
getSignalStatus(): Promise<any>;
|
|
253
|
+
/** Create a session token (requires access token) */
|
|
254
|
+
createSessionToken(options?: {
|
|
255
|
+
description?: string;
|
|
256
|
+
expiresIn?: number;
|
|
257
|
+
}): Promise<any>;
|
|
258
|
+
/** List all session tokens (requires access token) */
|
|
259
|
+
listSessionTokens(): Promise<any>;
|
|
260
|
+
/** Get session token details (requires access token) */
|
|
261
|
+
getSessionToken(tokenId: string): Promise<any>;
|
|
262
|
+
/** Revoke a session token (requires access token) */
|
|
263
|
+
revokeSessionToken(tokenId: string): Promise<void>;
|
|
264
|
+
/** Create a magic link for browser authentication (requires access token) */
|
|
265
|
+
createMagicLink(options?: {
|
|
266
|
+
redirectUrl?: string;
|
|
267
|
+
}): Promise<any>;
|
|
268
|
+
/** Check authentication status */
|
|
269
|
+
getAuthStatus(): Promise<any>;
|
|
270
|
+
/** Get authentication information */
|
|
271
|
+
getAuthInfo(): Promise<any>;
|
|
272
|
+
/** Set authentication token manually */
|
|
273
|
+
setToken(token: string): void;
|
|
274
|
+
/** Get current authentication token */
|
|
275
|
+
getToken(): string | null;
|
|
276
|
+
/** Get current sandbox URL */
|
|
277
|
+
getSandboxUrl(): string;
|
|
278
|
+
/** Disconnect WebSocket connection */
|
|
279
|
+
disconnect(): Promise<void>;
|
|
280
|
+
};
|
|
281
|
+
/**
|
|
282
|
+
* Typed enhanced sandbox that preserves both provider typing and ComputeClient features
|
|
283
|
+
*/
|
|
284
|
+
type TypedEnhancedSandbox<TProvider extends Provider$1> = ComputeEnhancedSandbox<ExtractProviderSandboxType<TProvider>> & Omit<TypedSandbox<TProvider>, keyof Sandbox>;
|
|
203
285
|
|
|
204
286
|
/**
|
|
205
287
|
* Common options for creating snapshots
|
|
@@ -299,7 +381,9 @@ interface ComputeConfig<TProvider extends Provider = Provider> {
|
|
|
299
381
|
provider?: TProvider;
|
|
300
382
|
/** API key for compute CLI authentication */
|
|
301
383
|
apiKey?: string;
|
|
302
|
-
/**
|
|
384
|
+
/** Access token for compute CLI authentication */
|
|
385
|
+
accessToken?: string;
|
|
386
|
+
/** @deprecated Use accessToken instead. Kept for backwards compatibility */
|
|
303
387
|
jwt?: string;
|
|
304
388
|
}
|
|
305
389
|
/**
|
|
@@ -341,17 +425,18 @@ interface ComputeAPI {
|
|
|
341
425
|
}
|
|
342
426
|
/**
|
|
343
427
|
* Typed Compute API interface that preserves provider type information
|
|
428
|
+
* When auth (apiKey/accessToken) is configured, returns enhanced sandboxes with ComputeClient features
|
|
344
429
|
*/
|
|
345
|
-
interface TypedComputeAPI<TProvider extends Provider> extends Omit<ComputeAPI, 'sandbox' | 'setConfig'> {
|
|
430
|
+
interface TypedComputeAPI<TProvider extends Provider, TIsEnhanced extends boolean = boolean> extends Omit<ComputeAPI, 'sandbox' | 'setConfig'> {
|
|
346
431
|
/** Configuration management that returns typed compute instance */
|
|
347
432
|
setConfig<T extends Provider>(config: ComputeConfig<T>): TypedComputeAPI<T>;
|
|
348
433
|
sandbox: {
|
|
349
434
|
/** Create a sandbox from the configured provider with proper typing */
|
|
350
|
-
create(params?: Omit<CreateSandboxParamsWithOptionalProvider, 'provider'>): Promise<TypedSandbox<TProvider>>;
|
|
435
|
+
create(params?: Omit<CreateSandboxParamsWithOptionalProvider, 'provider'>): Promise<TIsEnhanced extends true ? TypedEnhancedSandbox<TProvider> : TypedSandbox<TProvider>>;
|
|
351
436
|
/** Get an existing sandbox by ID from the configured provider with proper typing */
|
|
352
|
-
getById(sandboxId: string): Promise<TypedSandbox<TProvider> | null>;
|
|
437
|
+
getById(sandboxId: string): Promise<TIsEnhanced extends true ? TypedEnhancedSandbox<TProvider> : TypedSandbox<TProvider> | null>;
|
|
353
438
|
/** List all active sandboxes from the configured provider with proper typing */
|
|
354
|
-
list(): Promise<TypedSandbox<TProvider>[]>;
|
|
439
|
+
list(): Promise<TIsEnhanced extends true ? TypedEnhancedSandbox<TProvider>[] : TypedSandbox<TProvider>[]>;
|
|
355
440
|
/** Destroy a sandbox via the configured provider */
|
|
356
441
|
destroy(sandboxId: string): Promise<void>;
|
|
357
442
|
};
|
|
@@ -375,15 +460,33 @@ declare const compute: ComputeAPI;
|
|
|
375
460
|
* import { e2b } from '@computesdk/e2b'
|
|
376
461
|
* import { createCompute } from 'computesdk'
|
|
377
462
|
*
|
|
463
|
+
* // With API key (automatically gets access token from license server)
|
|
378
464
|
* const compute = createCompute({
|
|
379
465
|
* defaultProvider: e2b({ apiKey: 'your-key' }),
|
|
466
|
+
* apiKey: 'computesdk_live_...' // Returns enhanced sandboxes
|
|
467
|
+
* });
|
|
468
|
+
*
|
|
469
|
+
* // Or with direct access token
|
|
470
|
+
* const compute2 = createCompute({
|
|
471
|
+
* defaultProvider: e2b({ apiKey: 'your-key' }),
|
|
472
|
+
* accessToken: 'your-access-token' // Returns enhanced sandboxes
|
|
380
473
|
* });
|
|
381
474
|
*
|
|
382
475
|
* const sandbox = await compute.sandbox.create();
|
|
383
476
|
* const instance = sandbox.getInstance(); // ✅ Properly typed E2B Sandbox!
|
|
477
|
+
* await sandbox.createTerminal(); // ✅ Enhanced sandbox features!
|
|
384
478
|
* ```
|
|
385
479
|
*/
|
|
386
|
-
declare function createCompute<TProvider extends Provider>(config: ComputeConfig<TProvider>
|
|
480
|
+
declare function createCompute<TProvider extends Provider>(config: ComputeConfig<TProvider> & {
|
|
481
|
+
apiKey: string;
|
|
482
|
+
}): TypedComputeAPI<TProvider, true>;
|
|
483
|
+
declare function createCompute<TProvider extends Provider>(config: ComputeConfig<TProvider> & {
|
|
484
|
+
accessToken: string;
|
|
485
|
+
}): TypedComputeAPI<TProvider, true>;
|
|
486
|
+
declare function createCompute<TProvider extends Provider>(config: ComputeConfig<TProvider> & {
|
|
487
|
+
jwt: string;
|
|
488
|
+
}): TypedComputeAPI<TProvider, true>;
|
|
489
|
+
declare function createCompute<TProvider extends Provider>(config: ComputeConfig<TProvider>): TypedComputeAPI<TProvider, false>;
|
|
387
490
|
|
|
388
491
|
/**
|
|
389
492
|
* Simplified Request Handler for Web Framework Integration
|
|
@@ -525,4 +628,4 @@ interface ProviderConfig<TSandbox = any, TConfig = any, TTemplate = any, TSnapsh
|
|
|
525
628
|
*/
|
|
526
629
|
declare function createProvider<TSandbox, TConfig = any, TTemplate = any, TSnapshot = any>(providerConfig: ProviderConfig<TSandbox, TConfig, TTemplate, TSnapshot>): (config: TConfig) => Provider<TSandbox, TTemplate, TSnapshot>;
|
|
527
630
|
|
|
528
|
-
export { CommandExitError, type ComputeAPI, type ComputeConfig, type ComputeRequest, type ComputeResponse, type CreateSandboxOptions, type CreateSandboxParams, type CreateSandboxParamsWithOptionalProvider, type CreateSnapshotOptions, type CreateTemplateOptions, type ExecutionResult, type ExtractSandboxInstanceType, type FileEntry, type HandleComputeRequestParams, type ListSnapshotsOptions, type ListTemplatesOptions, type Provider, type ProviderConfig, type ProviderSandboxManager, type ProviderSandboxTypeMap, type ProviderSnapshotManager, type ProviderTemplateManager, type RunCommandOptions, type Runtime, type Sandbox, type SandboxFileSystem, type SandboxInfo, type SandboxMethods, type SandboxStatus, type SnapshotMethods, type TemplateMethods, type TypedComputeAPI, type TypedSandbox, compute, createBackgroundCommand, createCompute, createProvider, handleComputeRequest, isCommandExitError };
|
|
631
|
+
export { CommandExitError, type ComputeAPI, type ComputeConfig, type ComputeEnhancedSandbox, type ComputeRequest, type ComputeResponse, type CreateSandboxOptions, type CreateSandboxParams, type CreateSandboxParamsWithOptionalProvider, type CreateSnapshotOptions, type CreateTemplateOptions, type ExecutionResult, type ExtractSandboxInstanceType, type FileEntry, type HandleComputeRequestParams, type ListSnapshotsOptions, type ListTemplatesOptions, type Provider, type ProviderConfig, type ProviderSandboxManager, type ProviderSandboxTypeMap, type ProviderSnapshotManager, type ProviderTemplateManager, type RunCommandOptions, type Runtime, type Sandbox, type SandboxFileSystem, type SandboxInfo, type SandboxMethods, type SandboxStatus, type SnapshotMethods, type TemplateMethods, type TypedComputeAPI, type TypedEnhancedSandbox, type TypedSandbox, compute, createBackgroundCommand, createCompute, createProvider, handleComputeRequest, isCommandExitError };
|
package/dist/index.js
CHANGED
|
@@ -61,7 +61,7 @@ async function authorizeApiKey(apiKey) {
|
|
|
61
61
|
}
|
|
62
62
|
const data = await response.json();
|
|
63
63
|
if (!data.access_token) {
|
|
64
|
-
throw new Error("No
|
|
64
|
+
throw new Error("No access token received from license server");
|
|
65
65
|
}
|
|
66
66
|
if (!data.sandbox_url) {
|
|
67
67
|
throw new Error("No sandbox_url received from license server");
|
|
@@ -70,7 +70,7 @@ async function authorizeApiKey(apiKey) {
|
|
|
70
70
|
throw new Error("No preview_url received from license server");
|
|
71
71
|
}
|
|
72
72
|
return {
|
|
73
|
-
|
|
73
|
+
access_token: data.access_token,
|
|
74
74
|
sandbox_url: data.sandbox_url,
|
|
75
75
|
preview_url: data.preview_url
|
|
76
76
|
};
|
|
@@ -82,15 +82,15 @@ async function installComputeInSandbox(sandbox, config) {
|
|
|
82
82
|
try {
|
|
83
83
|
console.log("Installing and starting compute CLI in sandbox...");
|
|
84
84
|
let authResponse = null;
|
|
85
|
-
let
|
|
86
|
-
if (config?.apiKey && !
|
|
87
|
-
console.log("Authorizing API key and getting
|
|
85
|
+
let accessToken = config?.accessToken;
|
|
86
|
+
if (config?.apiKey && !accessToken) {
|
|
87
|
+
console.log("Authorizing API key and getting access token...");
|
|
88
88
|
authResponse = await authorizeApiKey(config.apiKey);
|
|
89
|
-
|
|
89
|
+
accessToken = authResponse.access_token;
|
|
90
90
|
}
|
|
91
91
|
let installCommand = "curl -fsSL https://computesdk.com/install.sh | sh";
|
|
92
|
-
if (
|
|
93
|
-
installCommand = `curl -fsSL https://computesdk.com/install.sh | sh -s -- --
|
|
92
|
+
if (accessToken) {
|
|
93
|
+
installCommand = `curl -fsSL https://computesdk.com/install.sh | sh -s -- --access-token ${accessToken}`;
|
|
94
94
|
}
|
|
95
95
|
const result = await sandbox.runCommand("sh", ["-c", installCommand]);
|
|
96
96
|
if (result.exitCode !== 0) {
|
|
@@ -105,7 +105,6 @@ async function installComputeInSandbox(sandbox, config) {
|
|
|
105
105
|
var ComputeManager = class {
|
|
106
106
|
constructor() {
|
|
107
107
|
this.config = null;
|
|
108
|
-
this.typedState = { isTyped: false, provider: null };
|
|
109
108
|
this.computeAuth = {};
|
|
110
109
|
this.sandbox = {
|
|
111
110
|
/**
|
|
@@ -132,18 +131,7 @@ var ComputeManager = class {
|
|
|
132
131
|
const options = params?.options;
|
|
133
132
|
const sandbox = await provider.sandbox.create(options);
|
|
134
133
|
const authResponse = await installComputeInSandbox(sandbox, this.computeAuth);
|
|
135
|
-
|
|
136
|
-
if (authResponse) {
|
|
137
|
-
finalSandbox = new import_client.ComputeClient({
|
|
138
|
-
sandboxUrl: authResponse.sandbox_url,
|
|
139
|
-
sandboxId: sandbox.sandboxId,
|
|
140
|
-
provider: sandbox.provider,
|
|
141
|
-
token: authResponse.jwt
|
|
142
|
-
});
|
|
143
|
-
}
|
|
144
|
-
if (this.typedState.isTyped && (!params || !("provider" in params && params.provider))) {
|
|
145
|
-
return finalSandbox;
|
|
146
|
-
}
|
|
134
|
+
const finalSandbox = authResponse ? this.wrapWithComputeClient(sandbox, authResponse) : sandbox;
|
|
147
135
|
return finalSandbox;
|
|
148
136
|
},
|
|
149
137
|
/**
|
|
@@ -152,11 +140,7 @@ var ComputeManager = class {
|
|
|
152
140
|
getById: async (providerOrSandboxId, sandboxId) => {
|
|
153
141
|
if (typeof providerOrSandboxId === "string") {
|
|
154
142
|
const provider = this.getDefaultProvider();
|
|
155
|
-
|
|
156
|
-
if (this.typedState.isTyped && sandbox) {
|
|
157
|
-
return sandbox;
|
|
158
|
-
}
|
|
159
|
-
return sandbox;
|
|
143
|
+
return await provider.sandbox.getById(providerOrSandboxId);
|
|
160
144
|
} else {
|
|
161
145
|
if (!sandboxId) {
|
|
162
146
|
throw new Error("sandboxId is required when provider is specified");
|
|
@@ -169,11 +153,7 @@ var ComputeManager = class {
|
|
|
169
153
|
*/
|
|
170
154
|
list: async (provider) => {
|
|
171
155
|
const actualProvider = provider || this.getDefaultProvider();
|
|
172
|
-
|
|
173
|
-
if (this.typedState.isTyped && !provider) {
|
|
174
|
-
return sandboxes;
|
|
175
|
-
}
|
|
176
|
-
return sandboxes;
|
|
156
|
+
return await actualProvider.sandbox.list();
|
|
177
157
|
},
|
|
178
158
|
/**
|
|
179
159
|
* Destroy a sandbox via a provider (or default provider if configured)
|
|
@@ -202,19 +182,16 @@ var ComputeManager = class {
|
|
|
202
182
|
console.warn("Both defaultProvider and provider specified in setConfig. Using defaultProvider. The provider key is deprecated, please use defaultProvider instead.");
|
|
203
183
|
}
|
|
204
184
|
const actualProvider = config.defaultProvider || config.provider;
|
|
185
|
+
const accessToken = config.accessToken || config.jwt;
|
|
205
186
|
this.config = {
|
|
206
187
|
provider: actualProvider,
|
|
207
188
|
defaultProvider: actualProvider,
|
|
208
189
|
apiKey: config.apiKey,
|
|
209
|
-
|
|
190
|
+
accessToken
|
|
210
191
|
};
|
|
211
192
|
this.computeAuth = {
|
|
212
193
|
apiKey: config.apiKey,
|
|
213
|
-
|
|
214
|
-
};
|
|
215
|
-
this.typedState = {
|
|
216
|
-
isTyped: true,
|
|
217
|
-
provider: actualProvider
|
|
194
|
+
accessToken
|
|
218
195
|
};
|
|
219
196
|
}
|
|
220
197
|
/**
|
|
@@ -241,6 +218,26 @@ var ComputeManager = class {
|
|
|
241
218
|
}
|
|
242
219
|
return provider;
|
|
243
220
|
}
|
|
221
|
+
/**
|
|
222
|
+
* Wrap a provider sandbox with ComputeClient while preserving the original sandbox
|
|
223
|
+
* This adds powerful features like WebSocket terminals, file watchers, and signals
|
|
224
|
+
*/
|
|
225
|
+
wrapWithComputeClient(originalSandbox, authResponse) {
|
|
226
|
+
const client = new import_client.ComputeClient({
|
|
227
|
+
sandboxUrl: authResponse.sandbox_url,
|
|
228
|
+
sandboxId: originalSandbox.sandboxId,
|
|
229
|
+
provider: originalSandbox.provider,
|
|
230
|
+
token: authResponse.access_token
|
|
231
|
+
});
|
|
232
|
+
const wrappedSandbox = Object.assign(client, {
|
|
233
|
+
__originalSandbox: originalSandbox,
|
|
234
|
+
// Override getInstance to return the original provider's instance
|
|
235
|
+
getInstance: () => originalSandbox.getInstance(),
|
|
236
|
+
// Override getProvider to return the original provider
|
|
237
|
+
getProvider: () => originalSandbox.getProvider()
|
|
238
|
+
});
|
|
239
|
+
return wrappedSandbox;
|
|
240
|
+
}
|
|
244
241
|
// Future: compute.blob.*, compute.database.*, compute.git.* will be added here
|
|
245
242
|
// blob = new BlobManager();
|
|
246
243
|
// database = new DatabaseManager();
|
|
@@ -250,20 +247,18 @@ var compute = new ComputeManager();
|
|
|
250
247
|
function createCompute(config) {
|
|
251
248
|
const manager = new ComputeManager();
|
|
252
249
|
const actualProvider = config.defaultProvider || config.provider;
|
|
250
|
+
const accessToken = config.accessToken || config.jwt;
|
|
253
251
|
manager["config"] = {
|
|
254
252
|
provider: actualProvider,
|
|
255
253
|
defaultProvider: actualProvider,
|
|
256
254
|
apiKey: config.apiKey,
|
|
257
|
-
|
|
258
|
-
};
|
|
259
|
-
manager["typedState"] = {
|
|
260
|
-
isTyped: true,
|
|
261
|
-
provider: actualProvider
|
|
255
|
+
accessToken
|
|
262
256
|
};
|
|
263
257
|
manager["computeAuth"] = {
|
|
264
258
|
apiKey: config.apiKey,
|
|
265
|
-
|
|
259
|
+
accessToken
|
|
266
260
|
};
|
|
261
|
+
const isEnhanced = !!(config.apiKey || config.accessToken || config.jwt);
|
|
267
262
|
return {
|
|
268
263
|
setConfig: (cfg) => createCompute(cfg),
|
|
269
264
|
getConfig: () => manager.getConfig(),
|
|
@@ -271,14 +266,24 @@ function createCompute(config) {
|
|
|
271
266
|
sandbox: {
|
|
272
267
|
create: async (params) => {
|
|
273
268
|
const sandbox = await manager.sandbox.create(params);
|
|
269
|
+
if (isEnhanced) {
|
|
270
|
+
return sandbox;
|
|
271
|
+
}
|
|
274
272
|
return sandbox;
|
|
275
273
|
},
|
|
276
274
|
getById: async (sandboxId) => {
|
|
277
275
|
const sandbox = await manager.sandbox.getById(sandboxId);
|
|
278
|
-
|
|
276
|
+
if (!sandbox) return null;
|
|
277
|
+
if (isEnhanced) {
|
|
278
|
+
return sandbox;
|
|
279
|
+
}
|
|
280
|
+
return sandbox;
|
|
279
281
|
},
|
|
280
282
|
list: async () => {
|
|
281
283
|
const sandboxes = await manager.sandbox.list();
|
|
284
|
+
if (isEnhanced) {
|
|
285
|
+
return sandboxes;
|
|
286
|
+
}
|
|
282
287
|
return sandboxes;
|
|
283
288
|
},
|
|
284
289
|
destroy: async (sandboxId) => {
|