@fastgpt-sdk/sandbox-adapter 0.0.30 → 0.0.32

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.
@@ -1,463 +0,0 @@
1
- import { N as NetworkPolicy, a as NetworkRule, S as Sandboxes, E as ExecdCommands, b as SandboxFiles, c as ExecdHealth, d as ExecdMetrics, L as ListSandboxesResponse, e as SandboxId, f as SandboxInfo, g as Execution, h as ExecutionHandlers, i as ServerStreamEvent, V as Volume, j as SandboxMetrics, R as RenewSandboxExpirationResponse, k as Endpoint } from './sandboxes-pbhLrfFS.js';
2
- export { C as CodeContextRequest, l as CommandExecution, m as CommandLogs, n as CommandStatus, o as ContentReplaceEntry, p as CreateSandboxRequest, q as CreateSandboxResponse, r as ExecutionComplete, s as ExecutionError, t as ExecutionInit, u as ExecutionResult, F as FileInfo, v as FileMetadata, w as FilesInfoResponse, H as Host, x as ListSandboxesParams, M as Metrics, y as MoveEntry, z as NetworkRuleAction, O as OutputMessage, P as PVC, A as Permission, B as PingResponse, D as RenameFileItem, G as RenewSandboxExpirationRequest, I as ReplaceFileContentItem, J as RunCommandOpts, K as SearchEntry, Q as SearchFilesResponse, T as SetPermissionEntry, U as SupportedLanguage, W as WriteEntry } from './sandboxes-pbhLrfFS.js';
3
-
4
- type SandboxErrorCode = "INTERNAL_UNKNOWN_ERROR" | "READY_TIMEOUT" | "UNHEALTHY" | "INVALID_ARGUMENT" | "UNEXPECTED_RESPONSE" | (string & {});
5
- /**
6
- * Structured error payload carried by {@link SandboxException}.
7
- *
8
- * - `code`: stable programmatic identifier
9
- * - `message`: optional human-readable message
10
- */
11
- declare class SandboxError {
12
- readonly code: SandboxErrorCode;
13
- readonly message?: string | undefined;
14
- static readonly INTERNAL_UNKNOWN_ERROR: SandboxErrorCode;
15
- static readonly READY_TIMEOUT: SandboxErrorCode;
16
- static readonly UNHEALTHY: SandboxErrorCode;
17
- static readonly INVALID_ARGUMENT: SandboxErrorCode;
18
- static readonly UNEXPECTED_RESPONSE: SandboxErrorCode;
19
- constructor(code: SandboxErrorCode, message?: string | undefined);
20
- }
21
- interface SandboxExceptionOpts {
22
- message?: string;
23
- cause?: unknown;
24
- error?: SandboxError;
25
- requestId?: string;
26
- }
27
- /**
28
- * Base exception class for all SDK errors.
29
- *
30
- * All errors thrown by this SDK are subclasses of {@link SandboxException}.
31
- */
32
- declare class SandboxException extends Error {
33
- readonly name: string;
34
- readonly error: SandboxError;
35
- readonly cause?: unknown;
36
- readonly requestId?: string;
37
- constructor(opts?: SandboxExceptionOpts);
38
- }
39
- declare class SandboxApiException extends SandboxException {
40
- readonly name: string;
41
- readonly statusCode?: number;
42
- readonly rawBody?: unknown;
43
- constructor(opts: SandboxExceptionOpts & {
44
- statusCode?: number;
45
- rawBody?: unknown;
46
- });
47
- }
48
- declare class SandboxInternalException extends SandboxException {
49
- readonly name: string;
50
- constructor(opts: {
51
- message?: string;
52
- cause?: unknown;
53
- });
54
- }
55
- declare class SandboxUnhealthyException extends SandboxException {
56
- readonly name: string;
57
- constructor(opts: {
58
- message?: string;
59
- cause?: unknown;
60
- });
61
- }
62
- declare class SandboxReadyTimeoutException extends SandboxException {
63
- readonly name: string;
64
- constructor(opts: {
65
- message?: string;
66
- cause?: unknown;
67
- });
68
- }
69
- declare class InvalidArgumentException extends SandboxException {
70
- readonly name: string;
71
- constructor(opts: {
72
- message?: string;
73
- cause?: unknown;
74
- });
75
- }
76
-
77
- type ConnectionProtocol = "http" | "https";
78
- /**
79
- * Options for {@link ConnectionConfig}.
80
- *
81
- * Most users only need `domain`, `protocol`, and `apiKey`.
82
- */
83
- interface ConnectionConfigOptions {
84
- /**
85
- * API server domain (host[:port]) without scheme.
86
- * Examples:
87
- * - "localhost:8080"
88
- * - "api.opensandbox.io"
89
- *
90
- * You may also pass a full URL (e.g. "http://localhost:8080" or "https://api.example.com").
91
- * If the URL includes a path, it will be preserved and `/v1` will be appended automatically.
92
- */
93
- domain?: string;
94
- protocol?: ConnectionProtocol;
95
- apiKey?: string;
96
- headers?: Record<string, string>;
97
- /**
98
- * Request timeout applied to all SDK HTTP calls (best-effort; wraps fetch).
99
- * Defaults to 30 seconds.
100
- */
101
- requestTimeoutSeconds?: number;
102
- /**
103
- * Enable basic debug logging for HTTP requests (best-effort).
104
- */
105
- debug?: boolean;
106
- /**
107
- * Use sandbox server as proxy for process execd requests.
108
- * Useful when the client SDK cannot access the created sandbox directly.
109
- */
110
- useServerProxy?: boolean;
111
- }
112
- declare class ConnectionConfig {
113
- readonly protocol: ConnectionProtocol;
114
- readonly domain: string;
115
- readonly apiKey?: string;
116
- readonly headers: Record<string, string>;
117
- private _fetch;
118
- private _sseFetch;
119
- readonly requestTimeoutSeconds: number;
120
- readonly debug: boolean;
121
- readonly userAgent: string;
122
- /**
123
- * Use sandbox server as proxy for endpoint requests (default false).
124
- */
125
- readonly useServerProxy: boolean;
126
- private _closeTransport;
127
- private _closePromise;
128
- private _transportInitialized;
129
- /**
130
- * Create a connection configuration.
131
- *
132
- * Environment variables (optional):
133
- * - `OPEN_SANDBOX_DOMAIN` (default: `localhost:8080`)
134
- * - `OPEN_SANDBOX_API_KEY`
135
- */
136
- constructor(opts?: ConnectionConfigOptions);
137
- get fetch(): typeof fetch;
138
- get sseFetch(): typeof fetch;
139
- getBaseUrl(): string;
140
- private initializeTransport;
141
- /**
142
- * Ensure this configuration has transport helpers (fetch/SSE) allocated.
143
- *
144
- * On Node.js this creates a dedicated `undici` dispatcher; on browsers it
145
- * simply reuses the global fetch. Returns either `this` or a cloned config
146
- * with the transport initialized.
147
- */
148
- withTransportIfMissing(): ConnectionConfig;
149
- /**
150
- * Close the Node.js agent owned by this configuration.
151
- */
152
- closeTransport(): Promise<void>;
153
- }
154
-
155
- interface Egress {
156
- getPolicy(): Promise<NetworkPolicy>;
157
- /**
158
- * Patch egress rules with sidecar merge semantics.
159
- *
160
- * Incoming rules take priority over existing rules with the same target.
161
- * Existing rules for other targets remain unchanged. Within one patch payload,
162
- * the first rule for a target wins. The current defaultAction is preserved.
163
- */
164
- patchRules(rules: NetworkRule[]): Promise<void>;
165
- }
166
-
167
- interface CreateLifecycleStackOptions {
168
- connectionConfig: ConnectionConfig;
169
- lifecycleBaseUrl: string;
170
- }
171
- interface LifecycleStack {
172
- sandboxes: Sandboxes;
173
- }
174
- interface CreateExecdStackOptions {
175
- connectionConfig: ConnectionConfig;
176
- execdBaseUrl: string;
177
- endpointHeaders?: Record<string, string>;
178
- }
179
- interface ExecdStack {
180
- commands: ExecdCommands;
181
- files: SandboxFiles;
182
- health: ExecdHealth;
183
- metrics: ExecdMetrics;
184
- }
185
- interface CreateEgressStackOptions {
186
- connectionConfig: ConnectionConfig;
187
- egressBaseUrl: string;
188
- endpointHeaders?: Record<string, string>;
189
- }
190
- interface EgressStack {
191
- egress: Egress;
192
- }
193
- /**
194
- * Factory abstraction to keep `Sandbox` and `SandboxManager` decoupled from concrete adapter implementations.
195
- *
196
- * This is primarily useful for advanced integrations (custom transports, dependency injection, testing).
197
- */
198
- interface AdapterFactory {
199
- createLifecycleStack(opts: CreateLifecycleStackOptions): LifecycleStack;
200
- createExecdStack(opts: CreateExecdStackOptions): ExecdStack;
201
- createEgressStack(opts: CreateEgressStackOptions): EgressStack;
202
- }
203
-
204
- declare class DefaultAdapterFactory implements AdapterFactory {
205
- createLifecycleStack(opts: CreateLifecycleStackOptions): LifecycleStack;
206
- createExecdStack(opts: CreateExecdStackOptions): ExecdStack;
207
- createEgressStack(opts: CreateEgressStackOptions): EgressStack;
208
- }
209
- declare function createDefaultAdapterFactory(): AdapterFactory;
210
-
211
- interface SandboxManagerOptions {
212
- /**
213
- * Connection configuration for calling the OpenSandbox Lifecycle API.
214
- */
215
- connectionConfig?: ConnectionConfig | ConnectionConfigOptions;
216
- /**
217
- * Advanced override: inject a custom adapter factory (custom transports, dependency injection).
218
- */
219
- adapterFactory?: AdapterFactory;
220
- }
221
- interface SandboxFilter {
222
- /**
223
- * Filter by sandbox lifecycle states.
224
- */
225
- states?: string[];
226
- /**
227
- * Filter by metadata key-value pairs.
228
- */
229
- metadata?: Record<string, string>;
230
- /**
231
- * Pagination page number (1-indexed).
232
- */
233
- page?: number;
234
- /**
235
- * Number of items per page.
236
- */
237
- pageSize?: number;
238
- }
239
- /**
240
- * Administrative interface for managing sandboxes (list/get/pause/resume/kill/renew).
241
- *
242
- * For interacting *inside* a sandbox, use {@link Sandbox}.
243
- */
244
- declare class SandboxManager {
245
- private readonly sandboxes;
246
- private readonly connectionConfig;
247
- private constructor();
248
- static create(opts?: SandboxManagerOptions): SandboxManager;
249
- listSandboxInfos(filter?: SandboxFilter): Promise<ListSandboxesResponse>;
250
- getSandboxInfo(sandboxId: SandboxId): Promise<SandboxInfo>;
251
- killSandbox(sandboxId: SandboxId): Promise<void>;
252
- pauseSandbox(sandboxId: SandboxId): Promise<void>;
253
- resumeSandbox(sandboxId: SandboxId): Promise<void>;
254
- /**
255
- * Renew expiration by setting expiresAt to now + timeoutSeconds.
256
- */
257
- renewSandbox(sandboxId: SandboxId, timeoutSeconds: number): Promise<void>;
258
- /**
259
- * Release the HTTP agent resources allocated for this manager instance.
260
- *
261
- * Each manager clone owns a scoped `ConnectionConfig` clone.
262
- *
263
- * This mirrors the Python SDK's default transport lifecycle.
264
- */
265
- close(): Promise<void>;
266
- }
267
-
268
- /**
269
- * Dispatches streamed execution events to handlers.
270
- *
271
- * This mutates the provided `execution` object (appending logs/results and setting fields like
272
- * `id`, `executionCount`, and `complete`) and invokes optional callbacks in {@link ExecutionHandlers}.
273
- */
274
- declare class ExecutionEventDispatcher {
275
- private readonly execution;
276
- private readonly handlers?;
277
- constructor(execution: Execution, handlers?: ExecutionHandlers | undefined);
278
- dispatch(ev: ServerStreamEvent): Promise<void>;
279
- }
280
-
281
- declare const DEFAULT_EXECD_PORT = 44772;
282
- declare const DEFAULT_EGRESS_PORT = 18080;
283
- declare const DEFAULT_ENTRYPOINT: string[];
284
- declare const DEFAULT_RESOURCE_LIMITS: Record<string, string>;
285
- declare const DEFAULT_TIMEOUT_SECONDS = 600;
286
- declare const DEFAULT_READY_TIMEOUT_SECONDS = 30;
287
- declare const DEFAULT_HEALTH_CHECK_POLLING_INTERVAL_MILLIS = 200;
288
- declare const DEFAULT_REQUEST_TIMEOUT_SECONDS = 30;
289
-
290
- interface SandboxCreateOptions {
291
- /**
292
- * Connection configuration for calling the OpenSandbox Lifecycle API and the sandbox's execd API.
293
- */
294
- connectionConfig?: ConnectionConfig | ConnectionConfigOptions;
295
- /**
296
- * Advanced override: inject a custom adapter factory (custom transports, dependency injection).
297
- */
298
- adapterFactory?: AdapterFactory;
299
- /**
300
- * Container image uri, e.g. `python:3.11`
301
- */
302
- image: string | {
303
- uri: string;
304
- auth?: {
305
- username: string;
306
- password: string;
307
- };
308
- };
309
- /**
310
- * Entrypoint command for the sandbox (defaults to tail -f /dev/null).
311
- */
312
- entrypoint?: string[];
313
- /**
314
- * Environment variables to inject into the sandbox runtime.
315
- */
316
- env?: Record<string, string>;
317
- /**
318
- * Custom metadata tags (used for filtering/management).
319
- */
320
- metadata?: Record<string, string>;
321
- /**
322
- * Optional outbound network policy for the sandbox.
323
- * If provided without defaultAction, defaults to "deny".
324
- */
325
- networkPolicy?: NetworkPolicy;
326
- /**
327
- * Optional list of volume mounts for persistent storage.
328
- * Each volume specifies a backend (host path or PVC) and mount configuration.
329
- */
330
- volumes?: Volume[];
331
- /**
332
- * Opaque extension parameters passed through to the server as-is.
333
- */
334
- extensions?: Record<string, string>;
335
- /**
336
- * Resource limits applied to the sandbox container.
337
- *
338
- * This is forwarded to the Lifecycle API as `resourceLimits`.
339
- */
340
- resource?: Record<string, string>;
341
- /**
342
- * Sandbox timeout in seconds. Set to `null` to require explicit cleanup.
343
- */
344
- timeoutSeconds?: number | null;
345
- /**
346
- * Skip readiness checks during create/connect.
347
- *
348
- * When true, the SDK will not wait for lifecycle state `Running` or perform the health check.
349
- * The returned sandbox instance may not be ready yet.
350
- */
351
- skipHealthCheck?: boolean;
352
- /**
353
- * Optional custom readiness check used by {@link Sandbox.waitUntilReady}.
354
- *
355
- * If provided, the SDK will call this function during readiness checks instead of
356
- * using the default `execd` ping check.
357
- */
358
- healthCheck?: (sbx: Sandbox) => boolean | Promise<boolean>;
359
- readyTimeoutSeconds?: number;
360
- healthCheckPollingInterval?: number;
361
- }
362
- interface SandboxConnectOptions {
363
- /**
364
- * Connection configuration for calling the OpenSandbox APIs.
365
- */
366
- connectionConfig?: ConnectionConfig | ConnectionConfigOptions;
367
- /**
368
- * Advanced override: inject a custom adapter factory (custom transports, dependency injection).
369
- */
370
- adapterFactory?: AdapterFactory;
371
- /**
372
- * ID of the existing sandbox to connect to.
373
- */
374
- sandboxId: SandboxId;
375
- /**
376
- * Skip readiness checks after connecting.
377
- */
378
- skipHealthCheck?: boolean;
379
- /**
380
- * Optional custom readiness check used by {@link Sandbox.waitUntilReady}.
381
- */
382
- healthCheck?: (sbx: Sandbox) => boolean | Promise<boolean>;
383
- /**
384
- * Max time to wait for readiness.
385
- */
386
- readyTimeoutSeconds?: number;
387
- /**
388
- * Polling interval for readiness checks (milliseconds).
389
- */
390
- healthCheckPollingInterval?: number;
391
- }
392
- declare class Sandbox {
393
- readonly id: SandboxId;
394
- readonly connectionConfig: ConnectionConfig;
395
- /**
396
- * Lifecycle (sandbox management) service.
397
- */
398
- readonly sandboxes: Sandboxes;
399
- /**
400
- * Execd services.
401
- */
402
- readonly commands: ExecdCommands;
403
- /**
404
- * High-level filesystem facade (JS-friendly).
405
- */
406
- readonly files: SandboxFiles;
407
- readonly health: ExecdHealth;
408
- readonly metrics: ExecdMetrics;
409
- /**
410
- * Internal state kept out of the public instance shape.
411
- *
412
- * This avoids nominal typing issues when multiple copies of the SDK exist in a dependency graph.
413
- */
414
- private static readonly _priv;
415
- private constructor();
416
- static create(opts: SandboxCreateOptions): Promise<Sandbox>;
417
- static connect(opts: SandboxConnectOptions): Promise<Sandbox>;
418
- getInfo(): Promise<SandboxInfo>;
419
- isHealthy(): Promise<boolean>;
420
- getMetrics(): Promise<SandboxMetrics>;
421
- pause(): Promise<void>;
422
- /**
423
- * Resume a paused sandbox and return a fresh, connected Sandbox instance.
424
- *
425
- * After resume, the execd endpoint may change, so this method returns a new
426
- * {@link Sandbox} instance with a refreshed execd base URL.
427
- */
428
- resume(opts?: {
429
- skipHealthCheck?: boolean;
430
- readyTimeoutSeconds?: number;
431
- healthCheckPollingInterval?: number;
432
- }): Promise<Sandbox>;
433
- /**
434
- * Resume a paused sandbox by id, then connect to its execd endpoint.
435
- */
436
- static resume(opts: SandboxConnectOptions): Promise<Sandbox>;
437
- kill(): Promise<void>;
438
- /**
439
- * Release any client-side resources (e.g. Node.js HTTP agents) owned by this Sandbox instance.
440
- */
441
- close(): Promise<void>;
442
- /**
443
- * Renew expiration by setting expiresAt to now + timeoutSeconds.
444
- */
445
- renew(timeoutSeconds: number): Promise<RenewSandboxExpirationResponse>;
446
- getEgressPolicy(): Promise<NetworkPolicy>;
447
- patchEgressRules(rules: NetworkRule[]): Promise<void>;
448
- /**
449
- * Get sandbox endpoint for a port (STRICT: no scheme), e.g. "localhost:44772" or "domain/route/.../44772".
450
- */
451
- getEndpoint(port: number): Promise<Endpoint>;
452
- /**
453
- * Get absolute endpoint URL with scheme (convenience for HTTP clients).
454
- */
455
- getEndpointUrl(port: number): Promise<string>;
456
- waitUntilReady(opts: {
457
- readyTimeoutSeconds: number;
458
- pollingIntervalMillis: number;
459
- healthCheck?: (sbx: Sandbox) => boolean | Promise<boolean>;
460
- }): Promise<void>;
461
- }
462
-
463
- export { type AdapterFactory, ConnectionConfig, type ConnectionConfigOptions, type ConnectionProtocol, DEFAULT_EGRESS_PORT, DEFAULT_ENTRYPOINT, DEFAULT_EXECD_PORT, DEFAULT_HEALTH_CHECK_POLLING_INTERVAL_MILLIS, DEFAULT_READY_TIMEOUT_SECONDS, DEFAULT_REQUEST_TIMEOUT_SECONDS, DEFAULT_RESOURCE_LIMITS, DEFAULT_TIMEOUT_SECONDS, DefaultAdapterFactory, Endpoint, ExecdCommands, ExecdHealth, ExecdMetrics, Execution, ExecutionEventDispatcher, ExecutionHandlers, InvalidArgumentException, ListSandboxesResponse, NetworkPolicy, NetworkRule, RenewSandboxExpirationResponse, Sandbox, SandboxApiException, type SandboxConnectOptions, type SandboxCreateOptions, SandboxError, SandboxException, SandboxFiles, type SandboxFilter, SandboxId, SandboxInfo, SandboxInternalException, SandboxManager, type SandboxManagerOptions, SandboxMetrics, SandboxReadyTimeoutException, SandboxUnhealthyException, Sandboxes, ServerStreamEvent, Volume, createDefaultAdapterFactory };