@meistrari/sandbox-sdk 1.4.0 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +67 -10
- package/dist/index.d.cts +69 -4
- package/dist/index.d.mts +69 -4
- package/dist/index.d.ts +69 -4
- package/dist/index.mjs +59 -11
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -429,6 +429,9 @@ class SandboxClient {
|
|
|
429
429
|
if (options.states && options.states.length > 0) {
|
|
430
430
|
params.set("state", options.states.join(","));
|
|
431
431
|
}
|
|
432
|
+
if (options.provider) {
|
|
433
|
+
params.set("provider", options.provider);
|
|
434
|
+
}
|
|
432
435
|
const query = params.size > 0 ? `?${params.toString()}` : "";
|
|
433
436
|
const response = await this.fetch(`/api/sandboxes${query}`);
|
|
434
437
|
return response.data;
|
|
@@ -543,6 +546,7 @@ class DataTokenAuthStrategy {
|
|
|
543
546
|
}
|
|
544
547
|
|
|
545
548
|
const SANDBOX_LIFECYCLE_TOPIC = "sandbox-lifecycle";
|
|
549
|
+
const RUN_LIFECYCLE_TOPIC = "run-lifecycle";
|
|
546
550
|
const SANDBOX_LIFECYCLE_ITEM = "lifecycle";
|
|
547
551
|
const SANDBOX_LIFECYCLE_EVENT_TYPES = [
|
|
548
552
|
"created",
|
|
@@ -553,27 +557,71 @@ const SANDBOX_LIFECYCLE_EVENT_TYPES = [
|
|
|
553
557
|
"failed",
|
|
554
558
|
"expired"
|
|
555
559
|
];
|
|
560
|
+
const RUN_LIFECYCLE_EVENT_TYPES = [
|
|
561
|
+
"created",
|
|
562
|
+
"started",
|
|
563
|
+
"completed",
|
|
564
|
+
"failed",
|
|
565
|
+
"timeout",
|
|
566
|
+
"cancelled"
|
|
567
|
+
];
|
|
568
|
+
const RUN_LIFECYCLE_TERMINAL_TYPES = ["completed", "failed", "timeout", "cancelled"];
|
|
569
|
+
function envSegment(value) {
|
|
570
|
+
return value.toUpperCase().replaceAll("-", "_");
|
|
571
|
+
}
|
|
572
|
+
function lifecycleTopicEnv(topic, binding = SANDBOX_LIFECYCLE_ITEM) {
|
|
573
|
+
return `KAFKA_${envSegment(binding)}_TOPIC_${envSegment(topic)}`;
|
|
574
|
+
}
|
|
556
575
|
function sandboxLifecycleTopicEnv(binding = SANDBOX_LIFECYCLE_ITEM) {
|
|
557
|
-
return
|
|
576
|
+
return lifecycleTopicEnv(SANDBOX_LIFECYCLE_TOPIC, binding);
|
|
577
|
+
}
|
|
578
|
+
function runLifecycleTopicEnv(binding = SANDBOX_LIFECYCLE_ITEM) {
|
|
579
|
+
return lifecycleTopicEnv(RUN_LIFECYCLE_TOPIC, binding);
|
|
580
|
+
}
|
|
581
|
+
function lifecycleSchemaRegistryEnv(binding = SANDBOX_LIFECYCLE_ITEM) {
|
|
582
|
+
return `KAFKA_${envSegment(binding)}_SCHEMA_REGISTRY_URL`;
|
|
583
|
+
}
|
|
584
|
+
function lifecycleSchemaSubject(topic) {
|
|
585
|
+
return `${topic}-value`;
|
|
586
|
+
}
|
|
587
|
+
function isRecord(value) {
|
|
588
|
+
return typeof value === "object" && value !== null;
|
|
589
|
+
}
|
|
590
|
+
function isOptionalString(value) {
|
|
591
|
+
return value === void 0 || value === null || typeof value === "string";
|
|
558
592
|
}
|
|
559
593
|
function isSandboxLifecycleEvent(value) {
|
|
560
|
-
if (
|
|
594
|
+
if (!isRecord(value)) {
|
|
561
595
|
return false;
|
|
562
596
|
}
|
|
563
|
-
|
|
564
|
-
|
|
597
|
+
return value.version === 1 && typeof value.eventId === "string" && SANDBOX_LIFECYCLE_EVENT_TYPES.includes(value.type) && typeof value.sandboxId === "string" && typeof value.workspaceId === "string" && typeof value.provider === "string" && typeof value.externalId === "string" && isOptionalString(value.image) && typeof value.state === "string" && isRecord(value.metadata) && typeof value.occurredAt === "string" && typeof value.source === "string";
|
|
598
|
+
}
|
|
599
|
+
function isRunLifecycleEvent(value) {
|
|
600
|
+
if (!isRecord(value)) {
|
|
601
|
+
return false;
|
|
602
|
+
}
|
|
603
|
+
return value.version === 1 && typeof value.eventId === "string" && RUN_LIFECYCLE_EVENT_TYPES.includes(value.type) && typeof value.runId === "string" && typeof value.workspaceId === "string" && isOptionalString(value.sandboxId) && isOptionalString(value.provider) && typeof value.language === "string" && typeof value.status === "string" && typeof value.occurredAt === "string" && typeof value.source === "string";
|
|
565
604
|
}
|
|
566
605
|
function parseSandboxLifecycleEvent(raw) {
|
|
606
|
+
const value = decoded(raw);
|
|
607
|
+
return isSandboxLifecycleEvent(value) ? value : null;
|
|
608
|
+
}
|
|
609
|
+
function parseRunLifecycleEvent(raw) {
|
|
610
|
+
const value = decoded(raw);
|
|
611
|
+
return isRunLifecycleEvent(value) ? value : null;
|
|
612
|
+
}
|
|
613
|
+
function decoded(raw) {
|
|
567
614
|
if (raw === null || raw === void 0) {
|
|
568
615
|
return null;
|
|
569
616
|
}
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
617
|
+
if (typeof raw === "string") {
|
|
618
|
+
try {
|
|
619
|
+
return JSON.parse(raw);
|
|
620
|
+
} catch {
|
|
621
|
+
return null;
|
|
622
|
+
}
|
|
576
623
|
}
|
|
624
|
+
return raw;
|
|
577
625
|
}
|
|
578
626
|
|
|
579
627
|
function sandbox(config) {
|
|
@@ -582,6 +630,9 @@ function sandbox(config) {
|
|
|
582
630
|
|
|
583
631
|
exports.DataTokenAuthStrategy = DataTokenAuthStrategy;
|
|
584
632
|
exports.FetchError = FetchError;
|
|
633
|
+
exports.RUN_LIFECYCLE_EVENT_TYPES = RUN_LIFECYCLE_EVENT_TYPES;
|
|
634
|
+
exports.RUN_LIFECYCLE_TERMINAL_TYPES = RUN_LIFECYCLE_TERMINAL_TYPES;
|
|
635
|
+
exports.RUN_LIFECYCLE_TOPIC = RUN_LIFECYCLE_TOPIC;
|
|
585
636
|
exports.SANDBOX_LIFECYCLE_EVENT_TYPES = SANDBOX_LIFECYCLE_EVENT_TYPES;
|
|
586
637
|
exports.SANDBOX_LIFECYCLE_ITEM = SANDBOX_LIFECYCLE_ITEM;
|
|
587
638
|
exports.SANDBOX_LIFECYCLE_TOPIC = SANDBOX_LIFECYCLE_TOPIC;
|
|
@@ -589,7 +640,13 @@ exports.SANDBOX_RUNTIMES = SANDBOX_RUNTIMES;
|
|
|
589
640
|
exports.Sandbox = Sandbox;
|
|
590
641
|
exports.SandboxClient = SandboxClient;
|
|
591
642
|
exports.SandboxRun = SandboxRun;
|
|
643
|
+
exports.isRunLifecycleEvent = isRunLifecycleEvent;
|
|
592
644
|
exports.isSandboxLifecycleEvent = isSandboxLifecycleEvent;
|
|
645
|
+
exports.lifecycleSchemaRegistryEnv = lifecycleSchemaRegistryEnv;
|
|
646
|
+
exports.lifecycleSchemaSubject = lifecycleSchemaSubject;
|
|
647
|
+
exports.lifecycleTopicEnv = lifecycleTopicEnv;
|
|
648
|
+
exports.parseRunLifecycleEvent = parseRunLifecycleEvent;
|
|
593
649
|
exports.parseSandboxLifecycleEvent = parseSandboxLifecycleEvent;
|
|
650
|
+
exports.runLifecycleTopicEnv = runLifecycleTopicEnv;
|
|
594
651
|
exports.sandbox = sandbox;
|
|
595
652
|
exports.sandboxLifecycleTopicEnv = sandboxLifecycleTopicEnv;
|
package/dist/index.d.cts
CHANGED
|
@@ -29,6 +29,8 @@ interface SandboxInfo {
|
|
|
29
29
|
interface ListSandboxesOptions {
|
|
30
30
|
metadata?: Record<string, string>;
|
|
31
31
|
states?: SandboxState[];
|
|
32
|
+
/** Backend to ask; the deployment's default when omitted. */
|
|
33
|
+
provider?: string;
|
|
32
34
|
}
|
|
33
35
|
interface ExecCommandOptions {
|
|
34
36
|
cwd?: string;
|
|
@@ -54,6 +56,8 @@ interface CreateRunRequest {
|
|
|
54
56
|
persistent?: boolean;
|
|
55
57
|
sandboxTtlSeconds?: number;
|
|
56
58
|
runtime?: SandboxRuntime;
|
|
59
|
+
/** Backend to run on (`agent-sandbox`, `lambda-microvm`, `e2b`); the deployment's default when omitted. */
|
|
60
|
+
provider?: string;
|
|
57
61
|
}
|
|
58
62
|
interface CreateSandboxRequest {
|
|
59
63
|
cpuSize?: number;
|
|
@@ -65,6 +69,8 @@ interface CreateSandboxRequest {
|
|
|
65
69
|
env?: Record<string, string>;
|
|
66
70
|
metadata?: Record<string, string>;
|
|
67
71
|
onTimeout?: SandboxOnTimeout;
|
|
72
|
+
/** Backend to host it; the deployment's default when omitted. */
|
|
73
|
+
provider?: string;
|
|
68
74
|
}
|
|
69
75
|
type FileCategory = 'input' | 'skill' | 'settings' | 'context' | 'workspace' | 'output';
|
|
70
76
|
interface FileInput {
|
|
@@ -89,6 +95,8 @@ interface BulkUploadResult {
|
|
|
89
95
|
}>;
|
|
90
96
|
}
|
|
91
97
|
type Status = 'pending' | 'running' | 'completed' | 'failed' | 'timeout' | 'cancelled';
|
|
98
|
+
/** A run's status, as `run-lifecycle` events and `RunResponse` report it. */
|
|
99
|
+
type RunStatus = Status;
|
|
92
100
|
interface RunResponse {
|
|
93
101
|
id: string;
|
|
94
102
|
workspaceId: string;
|
|
@@ -251,8 +259,22 @@ declare class FetchError extends Error {
|
|
|
251
259
|
static from(url: string, method: string, res: Response): Promise<FetchError>;
|
|
252
260
|
}
|
|
253
261
|
|
|
262
|
+
/**
|
|
263
|
+
* Lifecycle topics of the `lifecycle` Kafka item, one per aggregate and keyed
|
|
264
|
+
* by its id: `sandbox-lifecycle` by `sandboxId`, `run-lifecycle` by `runId`.
|
|
265
|
+
*
|
|
266
|
+
* Values are Avro in the Confluent wire format; the schema of each topic is
|
|
267
|
+
* registered under `<topic>-value` (`lifecycleSchemaSubject`). Decode with a
|
|
268
|
+
* registry client — `@kafkajs/confluent-schema-registry` against
|
|
269
|
+
* `KAFKA_<BINDING>_SCHEMA_REGISTRY_URL` — then narrow the decoded record with
|
|
270
|
+
* `isSandboxLifecycleEvent` / `isRunLifecycleEvent`. The message headers
|
|
271
|
+
* `event-type`, `event-id` and `workspace-id` carry enough to filter and
|
|
272
|
+
* dedupe without decoding.
|
|
273
|
+
*/
|
|
254
274
|
declare const SANDBOX_LIFECYCLE_TOPIC = "sandbox-lifecycle";
|
|
275
|
+
declare const RUN_LIFECYCLE_TOPIC = "run-lifecycle";
|
|
255
276
|
declare const SANDBOX_LIFECYCLE_ITEM = "lifecycle";
|
|
277
|
+
type LifecycleTopic = typeof SANDBOX_LIFECYCLE_TOPIC | typeof RUN_LIFECYCLE_TOPIC;
|
|
256
278
|
declare const SANDBOX_LIFECYCLE_EVENT_TYPES: readonly ["created", "ready", "suspended", "resumed", "terminated", "failed", "expired"];
|
|
257
279
|
type SandboxLifecycleEventType = (typeof SANDBOX_LIFECYCLE_EVENT_TYPES)[number];
|
|
258
280
|
type SandboxLifecycleSource = 'api' | 'provider-webhook' | 'provider-watch';
|
|
@@ -268,17 +290,60 @@ interface SandboxLifecycleEvent {
|
|
|
268
290
|
workspaceId: string;
|
|
269
291
|
provider: string;
|
|
270
292
|
externalId: string;
|
|
271
|
-
image?: string;
|
|
293
|
+
image?: string | null;
|
|
272
294
|
state: SandboxState;
|
|
273
295
|
metadata: Record<string, string>;
|
|
274
296
|
occurredAt: string;
|
|
275
297
|
source: SandboxLifecycleSource;
|
|
276
298
|
}
|
|
299
|
+
declare const RUN_LIFECYCLE_EVENT_TYPES: readonly ["created", "started", "completed", "failed", "timeout", "cancelled"];
|
|
300
|
+
type RunLifecycleEventType = (typeof RUN_LIFECYCLE_EVENT_TYPES)[number];
|
|
301
|
+
type RunLifecycleSource = 'api' | 'executor' | 'maintenance';
|
|
302
|
+
/**
|
|
303
|
+
* One run status transition, delivered at-least-once on the `run-lifecycle`
|
|
304
|
+
* topic keyed by `runId`. A run emits each `type` at most once; a terminal
|
|
305
|
+
* event carries the exit code, duration and Vault references of its output,
|
|
306
|
+
* so a consumer needs no `GET /api/runs/:id` to act on it.
|
|
307
|
+
*/
|
|
308
|
+
interface RunLifecycleEvent {
|
|
309
|
+
version: 1;
|
|
310
|
+
eventId: string;
|
|
311
|
+
type: RunLifecycleEventType;
|
|
312
|
+
runId: string;
|
|
313
|
+
workspaceId: string;
|
|
314
|
+
sandboxId?: string | null;
|
|
315
|
+
provider?: string | null;
|
|
316
|
+
language: string;
|
|
317
|
+
status: RunStatus;
|
|
318
|
+
exitCode?: number | null;
|
|
319
|
+
durationMs?: number | null;
|
|
320
|
+
errorMessage?: string | null;
|
|
321
|
+
stdoutVaultRef?: string | null;
|
|
322
|
+
stderrVaultRef?: string | null;
|
|
323
|
+
occurredAt: string;
|
|
324
|
+
source: RunLifecycleSource;
|
|
325
|
+
}
|
|
326
|
+
declare const RUN_LIFECYCLE_TERMINAL_TYPES: readonly RunLifecycleEventType[];
|
|
327
|
+
/** `KAFKA_<BINDING>_TOPIC_<TOPIC>`: the resolved topic name the chart injects. */
|
|
328
|
+
declare function lifecycleTopicEnv(topic: LifecycleTopic, binding?: string): string;
|
|
277
329
|
declare function sandboxLifecycleTopicEnv(binding?: string): string;
|
|
330
|
+
declare function runLifecycleTopicEnv(binding?: string): string;
|
|
331
|
+
/** `KAFKA_<BINDING>_SCHEMA_REGISTRY_URL`: the Confluent-compatible registry the values were encoded against. */
|
|
332
|
+
declare function lifecycleSchemaRegistryEnv(binding?: string): string;
|
|
333
|
+
/** The registry subject a topic's value schema lives under (TopicNameStrategy). */
|
|
334
|
+
declare function lifecycleSchemaSubject(topic: LifecycleTopic): string;
|
|
278
335
|
declare function isSandboxLifecycleEvent(value: unknown): value is SandboxLifecycleEvent;
|
|
279
|
-
declare function
|
|
336
|
+
declare function isRunLifecycleEvent(value: unknown): value is RunLifecycleEvent;
|
|
337
|
+
/**
|
|
338
|
+
* Narrows a decoded record to a sandbox event. Accepts the object a registry
|
|
339
|
+
* client decoded, or JSON text for a value that was re-serialised along the
|
|
340
|
+
* way; returns null for anything else, including the raw Avro bytes, which
|
|
341
|
+
* only the registry can decode.
|
|
342
|
+
*/
|
|
343
|
+
declare function parseSandboxLifecycleEvent(raw: unknown): SandboxLifecycleEvent | null;
|
|
344
|
+
declare function parseRunLifecycleEvent(raw: unknown): RunLifecycleEvent | null;
|
|
280
345
|
|
|
281
346
|
declare function sandbox(config: SandboxConfig): SandboxClient;
|
|
282
347
|
|
|
283
|
-
export { DataTokenAuthStrategy, FetchError, SANDBOX_LIFECYCLE_EVENT_TYPES, SANDBOX_LIFECYCLE_ITEM, SANDBOX_LIFECYCLE_TOPIC, SANDBOX_RUNTIMES, Sandbox, SandboxClient, SandboxRun, isSandboxLifecycleEvent, parseSandboxLifecycleEvent, sandbox, sandboxLifecycleTopicEnv };
|
|
284
|
-
export type { AuthStrategy, CreateRunRequest, CreateSandboxRequest, ExecCommandOptions, ExecCommandResult, ExecutionResult, FileInput, ListSandboxesOptions, RunCodeOptions, RunResponse, SandboxCommands, SandboxConfig, SandboxFiles, SandboxInfo, SandboxLifecycleEvent, SandboxLifecycleEventType, SandboxLifecycleSource, SandboxOnTimeout, SandboxRuntime, SandboxState, Status, StreamCallbacks, StreamEvent };
|
|
348
|
+
export { DataTokenAuthStrategy, FetchError, RUN_LIFECYCLE_EVENT_TYPES, RUN_LIFECYCLE_TERMINAL_TYPES, RUN_LIFECYCLE_TOPIC, SANDBOX_LIFECYCLE_EVENT_TYPES, SANDBOX_LIFECYCLE_ITEM, SANDBOX_LIFECYCLE_TOPIC, SANDBOX_RUNTIMES, Sandbox, SandboxClient, SandboxRun, isRunLifecycleEvent, isSandboxLifecycleEvent, lifecycleSchemaRegistryEnv, lifecycleSchemaSubject, lifecycleTopicEnv, parseRunLifecycleEvent, parseSandboxLifecycleEvent, runLifecycleTopicEnv, sandbox, sandboxLifecycleTopicEnv };
|
|
349
|
+
export type { AuthStrategy, CreateRunRequest, CreateSandboxRequest, ExecCommandOptions, ExecCommandResult, ExecutionResult, FileInput, LifecycleTopic, ListSandboxesOptions, RunCodeOptions, RunLifecycleEvent, RunLifecycleEventType, RunLifecycleSource, RunResponse, SandboxCommands, SandboxConfig, SandboxFiles, SandboxInfo, SandboxLifecycleEvent, SandboxLifecycleEventType, SandboxLifecycleSource, SandboxOnTimeout, SandboxRuntime, SandboxState, Status, StreamCallbacks, StreamEvent };
|
package/dist/index.d.mts
CHANGED
|
@@ -29,6 +29,8 @@ interface SandboxInfo {
|
|
|
29
29
|
interface ListSandboxesOptions {
|
|
30
30
|
metadata?: Record<string, string>;
|
|
31
31
|
states?: SandboxState[];
|
|
32
|
+
/** Backend to ask; the deployment's default when omitted. */
|
|
33
|
+
provider?: string;
|
|
32
34
|
}
|
|
33
35
|
interface ExecCommandOptions {
|
|
34
36
|
cwd?: string;
|
|
@@ -54,6 +56,8 @@ interface CreateRunRequest {
|
|
|
54
56
|
persistent?: boolean;
|
|
55
57
|
sandboxTtlSeconds?: number;
|
|
56
58
|
runtime?: SandboxRuntime;
|
|
59
|
+
/** Backend to run on (`agent-sandbox`, `lambda-microvm`, `e2b`); the deployment's default when omitted. */
|
|
60
|
+
provider?: string;
|
|
57
61
|
}
|
|
58
62
|
interface CreateSandboxRequest {
|
|
59
63
|
cpuSize?: number;
|
|
@@ -65,6 +69,8 @@ interface CreateSandboxRequest {
|
|
|
65
69
|
env?: Record<string, string>;
|
|
66
70
|
metadata?: Record<string, string>;
|
|
67
71
|
onTimeout?: SandboxOnTimeout;
|
|
72
|
+
/** Backend to host it; the deployment's default when omitted. */
|
|
73
|
+
provider?: string;
|
|
68
74
|
}
|
|
69
75
|
type FileCategory = 'input' | 'skill' | 'settings' | 'context' | 'workspace' | 'output';
|
|
70
76
|
interface FileInput {
|
|
@@ -89,6 +95,8 @@ interface BulkUploadResult {
|
|
|
89
95
|
}>;
|
|
90
96
|
}
|
|
91
97
|
type Status = 'pending' | 'running' | 'completed' | 'failed' | 'timeout' | 'cancelled';
|
|
98
|
+
/** A run's status, as `run-lifecycle` events and `RunResponse` report it. */
|
|
99
|
+
type RunStatus = Status;
|
|
92
100
|
interface RunResponse {
|
|
93
101
|
id: string;
|
|
94
102
|
workspaceId: string;
|
|
@@ -251,8 +259,22 @@ declare class FetchError extends Error {
|
|
|
251
259
|
static from(url: string, method: string, res: Response): Promise<FetchError>;
|
|
252
260
|
}
|
|
253
261
|
|
|
262
|
+
/**
|
|
263
|
+
* Lifecycle topics of the `lifecycle` Kafka item, one per aggregate and keyed
|
|
264
|
+
* by its id: `sandbox-lifecycle` by `sandboxId`, `run-lifecycle` by `runId`.
|
|
265
|
+
*
|
|
266
|
+
* Values are Avro in the Confluent wire format; the schema of each topic is
|
|
267
|
+
* registered under `<topic>-value` (`lifecycleSchemaSubject`). Decode with a
|
|
268
|
+
* registry client — `@kafkajs/confluent-schema-registry` against
|
|
269
|
+
* `KAFKA_<BINDING>_SCHEMA_REGISTRY_URL` — then narrow the decoded record with
|
|
270
|
+
* `isSandboxLifecycleEvent` / `isRunLifecycleEvent`. The message headers
|
|
271
|
+
* `event-type`, `event-id` and `workspace-id` carry enough to filter and
|
|
272
|
+
* dedupe without decoding.
|
|
273
|
+
*/
|
|
254
274
|
declare const SANDBOX_LIFECYCLE_TOPIC = "sandbox-lifecycle";
|
|
275
|
+
declare const RUN_LIFECYCLE_TOPIC = "run-lifecycle";
|
|
255
276
|
declare const SANDBOX_LIFECYCLE_ITEM = "lifecycle";
|
|
277
|
+
type LifecycleTopic = typeof SANDBOX_LIFECYCLE_TOPIC | typeof RUN_LIFECYCLE_TOPIC;
|
|
256
278
|
declare const SANDBOX_LIFECYCLE_EVENT_TYPES: readonly ["created", "ready", "suspended", "resumed", "terminated", "failed", "expired"];
|
|
257
279
|
type SandboxLifecycleEventType = (typeof SANDBOX_LIFECYCLE_EVENT_TYPES)[number];
|
|
258
280
|
type SandboxLifecycleSource = 'api' | 'provider-webhook' | 'provider-watch';
|
|
@@ -268,17 +290,60 @@ interface SandboxLifecycleEvent {
|
|
|
268
290
|
workspaceId: string;
|
|
269
291
|
provider: string;
|
|
270
292
|
externalId: string;
|
|
271
|
-
image?: string;
|
|
293
|
+
image?: string | null;
|
|
272
294
|
state: SandboxState;
|
|
273
295
|
metadata: Record<string, string>;
|
|
274
296
|
occurredAt: string;
|
|
275
297
|
source: SandboxLifecycleSource;
|
|
276
298
|
}
|
|
299
|
+
declare const RUN_LIFECYCLE_EVENT_TYPES: readonly ["created", "started", "completed", "failed", "timeout", "cancelled"];
|
|
300
|
+
type RunLifecycleEventType = (typeof RUN_LIFECYCLE_EVENT_TYPES)[number];
|
|
301
|
+
type RunLifecycleSource = 'api' | 'executor' | 'maintenance';
|
|
302
|
+
/**
|
|
303
|
+
* One run status transition, delivered at-least-once on the `run-lifecycle`
|
|
304
|
+
* topic keyed by `runId`. A run emits each `type` at most once; a terminal
|
|
305
|
+
* event carries the exit code, duration and Vault references of its output,
|
|
306
|
+
* so a consumer needs no `GET /api/runs/:id` to act on it.
|
|
307
|
+
*/
|
|
308
|
+
interface RunLifecycleEvent {
|
|
309
|
+
version: 1;
|
|
310
|
+
eventId: string;
|
|
311
|
+
type: RunLifecycleEventType;
|
|
312
|
+
runId: string;
|
|
313
|
+
workspaceId: string;
|
|
314
|
+
sandboxId?: string | null;
|
|
315
|
+
provider?: string | null;
|
|
316
|
+
language: string;
|
|
317
|
+
status: RunStatus;
|
|
318
|
+
exitCode?: number | null;
|
|
319
|
+
durationMs?: number | null;
|
|
320
|
+
errorMessage?: string | null;
|
|
321
|
+
stdoutVaultRef?: string | null;
|
|
322
|
+
stderrVaultRef?: string | null;
|
|
323
|
+
occurredAt: string;
|
|
324
|
+
source: RunLifecycleSource;
|
|
325
|
+
}
|
|
326
|
+
declare const RUN_LIFECYCLE_TERMINAL_TYPES: readonly RunLifecycleEventType[];
|
|
327
|
+
/** `KAFKA_<BINDING>_TOPIC_<TOPIC>`: the resolved topic name the chart injects. */
|
|
328
|
+
declare function lifecycleTopicEnv(topic: LifecycleTopic, binding?: string): string;
|
|
277
329
|
declare function sandboxLifecycleTopicEnv(binding?: string): string;
|
|
330
|
+
declare function runLifecycleTopicEnv(binding?: string): string;
|
|
331
|
+
/** `KAFKA_<BINDING>_SCHEMA_REGISTRY_URL`: the Confluent-compatible registry the values were encoded against. */
|
|
332
|
+
declare function lifecycleSchemaRegistryEnv(binding?: string): string;
|
|
333
|
+
/** The registry subject a topic's value schema lives under (TopicNameStrategy). */
|
|
334
|
+
declare function lifecycleSchemaSubject(topic: LifecycleTopic): string;
|
|
278
335
|
declare function isSandboxLifecycleEvent(value: unknown): value is SandboxLifecycleEvent;
|
|
279
|
-
declare function
|
|
336
|
+
declare function isRunLifecycleEvent(value: unknown): value is RunLifecycleEvent;
|
|
337
|
+
/**
|
|
338
|
+
* Narrows a decoded record to a sandbox event. Accepts the object a registry
|
|
339
|
+
* client decoded, or JSON text for a value that was re-serialised along the
|
|
340
|
+
* way; returns null for anything else, including the raw Avro bytes, which
|
|
341
|
+
* only the registry can decode.
|
|
342
|
+
*/
|
|
343
|
+
declare function parseSandboxLifecycleEvent(raw: unknown): SandboxLifecycleEvent | null;
|
|
344
|
+
declare function parseRunLifecycleEvent(raw: unknown): RunLifecycleEvent | null;
|
|
280
345
|
|
|
281
346
|
declare function sandbox(config: SandboxConfig): SandboxClient;
|
|
282
347
|
|
|
283
|
-
export { DataTokenAuthStrategy, FetchError, SANDBOX_LIFECYCLE_EVENT_TYPES, SANDBOX_LIFECYCLE_ITEM, SANDBOX_LIFECYCLE_TOPIC, SANDBOX_RUNTIMES, Sandbox, SandboxClient, SandboxRun, isSandboxLifecycleEvent, parseSandboxLifecycleEvent, sandbox, sandboxLifecycleTopicEnv };
|
|
284
|
-
export type { AuthStrategy, CreateRunRequest, CreateSandboxRequest, ExecCommandOptions, ExecCommandResult, ExecutionResult, FileInput, ListSandboxesOptions, RunCodeOptions, RunResponse, SandboxCommands, SandboxConfig, SandboxFiles, SandboxInfo, SandboxLifecycleEvent, SandboxLifecycleEventType, SandboxLifecycleSource, SandboxOnTimeout, SandboxRuntime, SandboxState, Status, StreamCallbacks, StreamEvent };
|
|
348
|
+
export { DataTokenAuthStrategy, FetchError, RUN_LIFECYCLE_EVENT_TYPES, RUN_LIFECYCLE_TERMINAL_TYPES, RUN_LIFECYCLE_TOPIC, SANDBOX_LIFECYCLE_EVENT_TYPES, SANDBOX_LIFECYCLE_ITEM, SANDBOX_LIFECYCLE_TOPIC, SANDBOX_RUNTIMES, Sandbox, SandboxClient, SandboxRun, isRunLifecycleEvent, isSandboxLifecycleEvent, lifecycleSchemaRegistryEnv, lifecycleSchemaSubject, lifecycleTopicEnv, parseRunLifecycleEvent, parseSandboxLifecycleEvent, runLifecycleTopicEnv, sandbox, sandboxLifecycleTopicEnv };
|
|
349
|
+
export type { AuthStrategy, CreateRunRequest, CreateSandboxRequest, ExecCommandOptions, ExecCommandResult, ExecutionResult, FileInput, LifecycleTopic, ListSandboxesOptions, RunCodeOptions, RunLifecycleEvent, RunLifecycleEventType, RunLifecycleSource, RunResponse, SandboxCommands, SandboxConfig, SandboxFiles, SandboxInfo, SandboxLifecycleEvent, SandboxLifecycleEventType, SandboxLifecycleSource, SandboxOnTimeout, SandboxRuntime, SandboxState, Status, StreamCallbacks, StreamEvent };
|
package/dist/index.d.ts
CHANGED
|
@@ -29,6 +29,8 @@ interface SandboxInfo {
|
|
|
29
29
|
interface ListSandboxesOptions {
|
|
30
30
|
metadata?: Record<string, string>;
|
|
31
31
|
states?: SandboxState[];
|
|
32
|
+
/** Backend to ask; the deployment's default when omitted. */
|
|
33
|
+
provider?: string;
|
|
32
34
|
}
|
|
33
35
|
interface ExecCommandOptions {
|
|
34
36
|
cwd?: string;
|
|
@@ -54,6 +56,8 @@ interface CreateRunRequest {
|
|
|
54
56
|
persistent?: boolean;
|
|
55
57
|
sandboxTtlSeconds?: number;
|
|
56
58
|
runtime?: SandboxRuntime;
|
|
59
|
+
/** Backend to run on (`agent-sandbox`, `lambda-microvm`, `e2b`); the deployment's default when omitted. */
|
|
60
|
+
provider?: string;
|
|
57
61
|
}
|
|
58
62
|
interface CreateSandboxRequest {
|
|
59
63
|
cpuSize?: number;
|
|
@@ -65,6 +69,8 @@ interface CreateSandboxRequest {
|
|
|
65
69
|
env?: Record<string, string>;
|
|
66
70
|
metadata?: Record<string, string>;
|
|
67
71
|
onTimeout?: SandboxOnTimeout;
|
|
72
|
+
/** Backend to host it; the deployment's default when omitted. */
|
|
73
|
+
provider?: string;
|
|
68
74
|
}
|
|
69
75
|
type FileCategory = 'input' | 'skill' | 'settings' | 'context' | 'workspace' | 'output';
|
|
70
76
|
interface FileInput {
|
|
@@ -89,6 +95,8 @@ interface BulkUploadResult {
|
|
|
89
95
|
}>;
|
|
90
96
|
}
|
|
91
97
|
type Status = 'pending' | 'running' | 'completed' | 'failed' | 'timeout' | 'cancelled';
|
|
98
|
+
/** A run's status, as `run-lifecycle` events and `RunResponse` report it. */
|
|
99
|
+
type RunStatus = Status;
|
|
92
100
|
interface RunResponse {
|
|
93
101
|
id: string;
|
|
94
102
|
workspaceId: string;
|
|
@@ -251,8 +259,22 @@ declare class FetchError extends Error {
|
|
|
251
259
|
static from(url: string, method: string, res: Response): Promise<FetchError>;
|
|
252
260
|
}
|
|
253
261
|
|
|
262
|
+
/**
|
|
263
|
+
* Lifecycle topics of the `lifecycle` Kafka item, one per aggregate and keyed
|
|
264
|
+
* by its id: `sandbox-lifecycle` by `sandboxId`, `run-lifecycle` by `runId`.
|
|
265
|
+
*
|
|
266
|
+
* Values are Avro in the Confluent wire format; the schema of each topic is
|
|
267
|
+
* registered under `<topic>-value` (`lifecycleSchemaSubject`). Decode with a
|
|
268
|
+
* registry client — `@kafkajs/confluent-schema-registry` against
|
|
269
|
+
* `KAFKA_<BINDING>_SCHEMA_REGISTRY_URL` — then narrow the decoded record with
|
|
270
|
+
* `isSandboxLifecycleEvent` / `isRunLifecycleEvent`. The message headers
|
|
271
|
+
* `event-type`, `event-id` and `workspace-id` carry enough to filter and
|
|
272
|
+
* dedupe without decoding.
|
|
273
|
+
*/
|
|
254
274
|
declare const SANDBOX_LIFECYCLE_TOPIC = "sandbox-lifecycle";
|
|
275
|
+
declare const RUN_LIFECYCLE_TOPIC = "run-lifecycle";
|
|
255
276
|
declare const SANDBOX_LIFECYCLE_ITEM = "lifecycle";
|
|
277
|
+
type LifecycleTopic = typeof SANDBOX_LIFECYCLE_TOPIC | typeof RUN_LIFECYCLE_TOPIC;
|
|
256
278
|
declare const SANDBOX_LIFECYCLE_EVENT_TYPES: readonly ["created", "ready", "suspended", "resumed", "terminated", "failed", "expired"];
|
|
257
279
|
type SandboxLifecycleEventType = (typeof SANDBOX_LIFECYCLE_EVENT_TYPES)[number];
|
|
258
280
|
type SandboxLifecycleSource = 'api' | 'provider-webhook' | 'provider-watch';
|
|
@@ -268,17 +290,60 @@ interface SandboxLifecycleEvent {
|
|
|
268
290
|
workspaceId: string;
|
|
269
291
|
provider: string;
|
|
270
292
|
externalId: string;
|
|
271
|
-
image?: string;
|
|
293
|
+
image?: string | null;
|
|
272
294
|
state: SandboxState;
|
|
273
295
|
metadata: Record<string, string>;
|
|
274
296
|
occurredAt: string;
|
|
275
297
|
source: SandboxLifecycleSource;
|
|
276
298
|
}
|
|
299
|
+
declare const RUN_LIFECYCLE_EVENT_TYPES: readonly ["created", "started", "completed", "failed", "timeout", "cancelled"];
|
|
300
|
+
type RunLifecycleEventType = (typeof RUN_LIFECYCLE_EVENT_TYPES)[number];
|
|
301
|
+
type RunLifecycleSource = 'api' | 'executor' | 'maintenance';
|
|
302
|
+
/**
|
|
303
|
+
* One run status transition, delivered at-least-once on the `run-lifecycle`
|
|
304
|
+
* topic keyed by `runId`. A run emits each `type` at most once; a terminal
|
|
305
|
+
* event carries the exit code, duration and Vault references of its output,
|
|
306
|
+
* so a consumer needs no `GET /api/runs/:id` to act on it.
|
|
307
|
+
*/
|
|
308
|
+
interface RunLifecycleEvent {
|
|
309
|
+
version: 1;
|
|
310
|
+
eventId: string;
|
|
311
|
+
type: RunLifecycleEventType;
|
|
312
|
+
runId: string;
|
|
313
|
+
workspaceId: string;
|
|
314
|
+
sandboxId?: string | null;
|
|
315
|
+
provider?: string | null;
|
|
316
|
+
language: string;
|
|
317
|
+
status: RunStatus;
|
|
318
|
+
exitCode?: number | null;
|
|
319
|
+
durationMs?: number | null;
|
|
320
|
+
errorMessage?: string | null;
|
|
321
|
+
stdoutVaultRef?: string | null;
|
|
322
|
+
stderrVaultRef?: string | null;
|
|
323
|
+
occurredAt: string;
|
|
324
|
+
source: RunLifecycleSource;
|
|
325
|
+
}
|
|
326
|
+
declare const RUN_LIFECYCLE_TERMINAL_TYPES: readonly RunLifecycleEventType[];
|
|
327
|
+
/** `KAFKA_<BINDING>_TOPIC_<TOPIC>`: the resolved topic name the chart injects. */
|
|
328
|
+
declare function lifecycleTopicEnv(topic: LifecycleTopic, binding?: string): string;
|
|
277
329
|
declare function sandboxLifecycleTopicEnv(binding?: string): string;
|
|
330
|
+
declare function runLifecycleTopicEnv(binding?: string): string;
|
|
331
|
+
/** `KAFKA_<BINDING>_SCHEMA_REGISTRY_URL`: the Confluent-compatible registry the values were encoded against. */
|
|
332
|
+
declare function lifecycleSchemaRegistryEnv(binding?: string): string;
|
|
333
|
+
/** The registry subject a topic's value schema lives under (TopicNameStrategy). */
|
|
334
|
+
declare function lifecycleSchemaSubject(topic: LifecycleTopic): string;
|
|
278
335
|
declare function isSandboxLifecycleEvent(value: unknown): value is SandboxLifecycleEvent;
|
|
279
|
-
declare function
|
|
336
|
+
declare function isRunLifecycleEvent(value: unknown): value is RunLifecycleEvent;
|
|
337
|
+
/**
|
|
338
|
+
* Narrows a decoded record to a sandbox event. Accepts the object a registry
|
|
339
|
+
* client decoded, or JSON text for a value that was re-serialised along the
|
|
340
|
+
* way; returns null for anything else, including the raw Avro bytes, which
|
|
341
|
+
* only the registry can decode.
|
|
342
|
+
*/
|
|
343
|
+
declare function parseSandboxLifecycleEvent(raw: unknown): SandboxLifecycleEvent | null;
|
|
344
|
+
declare function parseRunLifecycleEvent(raw: unknown): RunLifecycleEvent | null;
|
|
280
345
|
|
|
281
346
|
declare function sandbox(config: SandboxConfig): SandboxClient;
|
|
282
347
|
|
|
283
|
-
export { DataTokenAuthStrategy, FetchError, SANDBOX_LIFECYCLE_EVENT_TYPES, SANDBOX_LIFECYCLE_ITEM, SANDBOX_LIFECYCLE_TOPIC, SANDBOX_RUNTIMES, Sandbox, SandboxClient, SandboxRun, isSandboxLifecycleEvent, parseSandboxLifecycleEvent, sandbox, sandboxLifecycleTopicEnv };
|
|
284
|
-
export type { AuthStrategy, CreateRunRequest, CreateSandboxRequest, ExecCommandOptions, ExecCommandResult, ExecutionResult, FileInput, ListSandboxesOptions, RunCodeOptions, RunResponse, SandboxCommands, SandboxConfig, SandboxFiles, SandboxInfo, SandboxLifecycleEvent, SandboxLifecycleEventType, SandboxLifecycleSource, SandboxOnTimeout, SandboxRuntime, SandboxState, Status, StreamCallbacks, StreamEvent };
|
|
348
|
+
export { DataTokenAuthStrategy, FetchError, RUN_LIFECYCLE_EVENT_TYPES, RUN_LIFECYCLE_TERMINAL_TYPES, RUN_LIFECYCLE_TOPIC, SANDBOX_LIFECYCLE_EVENT_TYPES, SANDBOX_LIFECYCLE_ITEM, SANDBOX_LIFECYCLE_TOPIC, SANDBOX_RUNTIMES, Sandbox, SandboxClient, SandboxRun, isRunLifecycleEvent, isSandboxLifecycleEvent, lifecycleSchemaRegistryEnv, lifecycleSchemaSubject, lifecycleTopicEnv, parseRunLifecycleEvent, parseSandboxLifecycleEvent, runLifecycleTopicEnv, sandbox, sandboxLifecycleTopicEnv };
|
|
349
|
+
export type { AuthStrategy, CreateRunRequest, CreateSandboxRequest, ExecCommandOptions, ExecCommandResult, ExecutionResult, FileInput, LifecycleTopic, ListSandboxesOptions, RunCodeOptions, RunLifecycleEvent, RunLifecycleEventType, RunLifecycleSource, RunResponse, SandboxCommands, SandboxConfig, SandboxFiles, SandboxInfo, SandboxLifecycleEvent, SandboxLifecycleEventType, SandboxLifecycleSource, SandboxOnTimeout, SandboxRuntime, SandboxState, Status, StreamCallbacks, StreamEvent };
|
package/dist/index.mjs
CHANGED
|
@@ -427,6 +427,9 @@ class SandboxClient {
|
|
|
427
427
|
if (options.states && options.states.length > 0) {
|
|
428
428
|
params.set("state", options.states.join(","));
|
|
429
429
|
}
|
|
430
|
+
if (options.provider) {
|
|
431
|
+
params.set("provider", options.provider);
|
|
432
|
+
}
|
|
430
433
|
const query = params.size > 0 ? `?${params.toString()}` : "";
|
|
431
434
|
const response = await this.fetch(`/api/sandboxes${query}`);
|
|
432
435
|
return response.data;
|
|
@@ -541,6 +544,7 @@ class DataTokenAuthStrategy {
|
|
|
541
544
|
}
|
|
542
545
|
|
|
543
546
|
const SANDBOX_LIFECYCLE_TOPIC = "sandbox-lifecycle";
|
|
547
|
+
const RUN_LIFECYCLE_TOPIC = "run-lifecycle";
|
|
544
548
|
const SANDBOX_LIFECYCLE_ITEM = "lifecycle";
|
|
545
549
|
const SANDBOX_LIFECYCLE_EVENT_TYPES = [
|
|
546
550
|
"created",
|
|
@@ -551,31 +555,75 @@ const SANDBOX_LIFECYCLE_EVENT_TYPES = [
|
|
|
551
555
|
"failed",
|
|
552
556
|
"expired"
|
|
553
557
|
];
|
|
558
|
+
const RUN_LIFECYCLE_EVENT_TYPES = [
|
|
559
|
+
"created",
|
|
560
|
+
"started",
|
|
561
|
+
"completed",
|
|
562
|
+
"failed",
|
|
563
|
+
"timeout",
|
|
564
|
+
"cancelled"
|
|
565
|
+
];
|
|
566
|
+
const RUN_LIFECYCLE_TERMINAL_TYPES = ["completed", "failed", "timeout", "cancelled"];
|
|
567
|
+
function envSegment(value) {
|
|
568
|
+
return value.toUpperCase().replaceAll("-", "_");
|
|
569
|
+
}
|
|
570
|
+
function lifecycleTopicEnv(topic, binding = SANDBOX_LIFECYCLE_ITEM) {
|
|
571
|
+
return `KAFKA_${envSegment(binding)}_TOPIC_${envSegment(topic)}`;
|
|
572
|
+
}
|
|
554
573
|
function sandboxLifecycleTopicEnv(binding = SANDBOX_LIFECYCLE_ITEM) {
|
|
555
|
-
return
|
|
574
|
+
return lifecycleTopicEnv(SANDBOX_LIFECYCLE_TOPIC, binding);
|
|
575
|
+
}
|
|
576
|
+
function runLifecycleTopicEnv(binding = SANDBOX_LIFECYCLE_ITEM) {
|
|
577
|
+
return lifecycleTopicEnv(RUN_LIFECYCLE_TOPIC, binding);
|
|
578
|
+
}
|
|
579
|
+
function lifecycleSchemaRegistryEnv(binding = SANDBOX_LIFECYCLE_ITEM) {
|
|
580
|
+
return `KAFKA_${envSegment(binding)}_SCHEMA_REGISTRY_URL`;
|
|
581
|
+
}
|
|
582
|
+
function lifecycleSchemaSubject(topic) {
|
|
583
|
+
return `${topic}-value`;
|
|
584
|
+
}
|
|
585
|
+
function isRecord(value) {
|
|
586
|
+
return typeof value === "object" && value !== null;
|
|
587
|
+
}
|
|
588
|
+
function isOptionalString(value) {
|
|
589
|
+
return value === void 0 || value === null || typeof value === "string";
|
|
556
590
|
}
|
|
557
591
|
function isSandboxLifecycleEvent(value) {
|
|
558
|
-
if (
|
|
592
|
+
if (!isRecord(value)) {
|
|
559
593
|
return false;
|
|
560
594
|
}
|
|
561
|
-
|
|
562
|
-
|
|
595
|
+
return value.version === 1 && typeof value.eventId === "string" && SANDBOX_LIFECYCLE_EVENT_TYPES.includes(value.type) && typeof value.sandboxId === "string" && typeof value.workspaceId === "string" && typeof value.provider === "string" && typeof value.externalId === "string" && isOptionalString(value.image) && typeof value.state === "string" && isRecord(value.metadata) && typeof value.occurredAt === "string" && typeof value.source === "string";
|
|
596
|
+
}
|
|
597
|
+
function isRunLifecycleEvent(value) {
|
|
598
|
+
if (!isRecord(value)) {
|
|
599
|
+
return false;
|
|
600
|
+
}
|
|
601
|
+
return value.version === 1 && typeof value.eventId === "string" && RUN_LIFECYCLE_EVENT_TYPES.includes(value.type) && typeof value.runId === "string" && typeof value.workspaceId === "string" && isOptionalString(value.sandboxId) && isOptionalString(value.provider) && typeof value.language === "string" && typeof value.status === "string" && typeof value.occurredAt === "string" && typeof value.source === "string";
|
|
563
602
|
}
|
|
564
603
|
function parseSandboxLifecycleEvent(raw) {
|
|
604
|
+
const value = decoded(raw);
|
|
605
|
+
return isSandboxLifecycleEvent(value) ? value : null;
|
|
606
|
+
}
|
|
607
|
+
function parseRunLifecycleEvent(raw) {
|
|
608
|
+
const value = decoded(raw);
|
|
609
|
+
return isRunLifecycleEvent(value) ? value : null;
|
|
610
|
+
}
|
|
611
|
+
function decoded(raw) {
|
|
565
612
|
if (raw === null || raw === void 0) {
|
|
566
613
|
return null;
|
|
567
614
|
}
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
615
|
+
if (typeof raw === "string") {
|
|
616
|
+
try {
|
|
617
|
+
return JSON.parse(raw);
|
|
618
|
+
} catch {
|
|
619
|
+
return null;
|
|
620
|
+
}
|
|
574
621
|
}
|
|
622
|
+
return raw;
|
|
575
623
|
}
|
|
576
624
|
|
|
577
625
|
function sandbox(config) {
|
|
578
626
|
return new SandboxClient(config);
|
|
579
627
|
}
|
|
580
628
|
|
|
581
|
-
export { DataTokenAuthStrategy, FetchError, SANDBOX_LIFECYCLE_EVENT_TYPES, SANDBOX_LIFECYCLE_ITEM, SANDBOX_LIFECYCLE_TOPIC, SANDBOX_RUNTIMES, Sandbox, SandboxClient, SandboxRun, isSandboxLifecycleEvent, parseSandboxLifecycleEvent, sandbox, sandboxLifecycleTopicEnv };
|
|
629
|
+
export { DataTokenAuthStrategy, FetchError, RUN_LIFECYCLE_EVENT_TYPES, RUN_LIFECYCLE_TERMINAL_TYPES, RUN_LIFECYCLE_TOPIC, SANDBOX_LIFECYCLE_EVENT_TYPES, SANDBOX_LIFECYCLE_ITEM, SANDBOX_LIFECYCLE_TOPIC, SANDBOX_RUNTIMES, Sandbox, SandboxClient, SandboxRun, isRunLifecycleEvent, isSandboxLifecycleEvent, lifecycleSchemaRegistryEnv, lifecycleSchemaSubject, lifecycleTopicEnv, parseRunLifecycleEvent, parseSandboxLifecycleEvent, runLifecycleTopicEnv, sandbox, sandboxLifecycleTopicEnv };
|