@meistrari/sandbox-sdk 1.4.0 → 1.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +67 -10
- package/dist/index.d.cts +92 -4
- package/dist/index.d.mts +92 -4
- package/dist/index.d.ts +92 -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,31 @@ 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;
|
|
61
|
+
/**
|
|
62
|
+
* Backend to try when `provider` does not deliver. Naming it is asking for
|
|
63
|
+
* the swap, so it applies even when `provider` is named. Rejected on a run
|
|
64
|
+
* that targets an existing `sandboxId`.
|
|
65
|
+
*/
|
|
66
|
+
fallback?: string;
|
|
67
|
+
/**
|
|
68
|
+
* How long getting a sandbox ready may take. `timeoutMs` is the other
|
|
69
|
+
* half: how long the code may then run. Either omitted leaves the
|
|
70
|
+
* deployment's own limit in place; exceeding either ends the run as
|
|
71
|
+
* `timeout`.
|
|
72
|
+
*/
|
|
73
|
+
startTimeoutMs?: number;
|
|
74
|
+
/**
|
|
75
|
+
* What a blown budget does. `start` retries on the fallback and defaults
|
|
76
|
+
* to true — no code has executed yet, so it duplicates nothing. `session`
|
|
77
|
+
* runs the code a second time and defaults to false: the first attempt may
|
|
78
|
+
* have sent requests or written data before it hung.
|
|
79
|
+
*/
|
|
80
|
+
retry?: {
|
|
81
|
+
start?: boolean;
|
|
82
|
+
session?: boolean;
|
|
83
|
+
};
|
|
57
84
|
}
|
|
58
85
|
interface CreateSandboxRequest {
|
|
59
86
|
cpuSize?: number;
|
|
@@ -65,6 +92,8 @@ interface CreateSandboxRequest {
|
|
|
65
92
|
env?: Record<string, string>;
|
|
66
93
|
metadata?: Record<string, string>;
|
|
67
94
|
onTimeout?: SandboxOnTimeout;
|
|
95
|
+
/** Backend to host it; the deployment's default when omitted. */
|
|
96
|
+
provider?: string;
|
|
68
97
|
}
|
|
69
98
|
type FileCategory = 'input' | 'skill' | 'settings' | 'context' | 'workspace' | 'output';
|
|
70
99
|
interface FileInput {
|
|
@@ -89,6 +118,8 @@ interface BulkUploadResult {
|
|
|
89
118
|
}>;
|
|
90
119
|
}
|
|
91
120
|
type Status = 'pending' | 'running' | 'completed' | 'failed' | 'timeout' | 'cancelled';
|
|
121
|
+
/** A run's status, as `run-lifecycle` events and `RunResponse` report it. */
|
|
122
|
+
type RunStatus = Status;
|
|
92
123
|
interface RunResponse {
|
|
93
124
|
id: string;
|
|
94
125
|
workspaceId: string;
|
|
@@ -251,8 +282,22 @@ declare class FetchError extends Error {
|
|
|
251
282
|
static from(url: string, method: string, res: Response): Promise<FetchError>;
|
|
252
283
|
}
|
|
253
284
|
|
|
285
|
+
/**
|
|
286
|
+
* Lifecycle topics of the `lifecycle` Kafka item, one per aggregate and keyed
|
|
287
|
+
* by its id: `sandbox-lifecycle` by `sandboxId`, `run-lifecycle` by `runId`.
|
|
288
|
+
*
|
|
289
|
+
* Values are Avro in the Confluent wire format; the schema of each topic is
|
|
290
|
+
* registered under `<topic>-value` (`lifecycleSchemaSubject`). Decode with a
|
|
291
|
+
* registry client — `@kafkajs/confluent-schema-registry` against
|
|
292
|
+
* `KAFKA_<BINDING>_SCHEMA_REGISTRY_URL` — then narrow the decoded record with
|
|
293
|
+
* `isSandboxLifecycleEvent` / `isRunLifecycleEvent`. The message headers
|
|
294
|
+
* `event-type`, `event-id` and `workspace-id` carry enough to filter and
|
|
295
|
+
* dedupe without decoding.
|
|
296
|
+
*/
|
|
254
297
|
declare const SANDBOX_LIFECYCLE_TOPIC = "sandbox-lifecycle";
|
|
298
|
+
declare const RUN_LIFECYCLE_TOPIC = "run-lifecycle";
|
|
255
299
|
declare const SANDBOX_LIFECYCLE_ITEM = "lifecycle";
|
|
300
|
+
type LifecycleTopic = typeof SANDBOX_LIFECYCLE_TOPIC | typeof RUN_LIFECYCLE_TOPIC;
|
|
256
301
|
declare const SANDBOX_LIFECYCLE_EVENT_TYPES: readonly ["created", "ready", "suspended", "resumed", "terminated", "failed", "expired"];
|
|
257
302
|
type SandboxLifecycleEventType = (typeof SANDBOX_LIFECYCLE_EVENT_TYPES)[number];
|
|
258
303
|
type SandboxLifecycleSource = 'api' | 'provider-webhook' | 'provider-watch';
|
|
@@ -268,17 +313,60 @@ interface SandboxLifecycleEvent {
|
|
|
268
313
|
workspaceId: string;
|
|
269
314
|
provider: string;
|
|
270
315
|
externalId: string;
|
|
271
|
-
image?: string;
|
|
316
|
+
image?: string | null;
|
|
272
317
|
state: SandboxState;
|
|
273
318
|
metadata: Record<string, string>;
|
|
274
319
|
occurredAt: string;
|
|
275
320
|
source: SandboxLifecycleSource;
|
|
276
321
|
}
|
|
322
|
+
declare const RUN_LIFECYCLE_EVENT_TYPES: readonly ["created", "started", "completed", "failed", "timeout", "cancelled"];
|
|
323
|
+
type RunLifecycleEventType = (typeof RUN_LIFECYCLE_EVENT_TYPES)[number];
|
|
324
|
+
type RunLifecycleSource = 'api' | 'executor' | 'maintenance';
|
|
325
|
+
/**
|
|
326
|
+
* One run status transition, delivered at-least-once on the `run-lifecycle`
|
|
327
|
+
* topic keyed by `runId`. A run emits each `type` at most once; a terminal
|
|
328
|
+
* event carries the exit code, duration and Vault references of its output,
|
|
329
|
+
* so a consumer needs no `GET /api/runs/:id` to act on it.
|
|
330
|
+
*/
|
|
331
|
+
interface RunLifecycleEvent {
|
|
332
|
+
version: 1;
|
|
333
|
+
eventId: string;
|
|
334
|
+
type: RunLifecycleEventType;
|
|
335
|
+
runId: string;
|
|
336
|
+
workspaceId: string;
|
|
337
|
+
sandboxId?: string | null;
|
|
338
|
+
provider?: string | null;
|
|
339
|
+
language: string;
|
|
340
|
+
status: RunStatus;
|
|
341
|
+
exitCode?: number | null;
|
|
342
|
+
durationMs?: number | null;
|
|
343
|
+
errorMessage?: string | null;
|
|
344
|
+
stdoutVaultRef?: string | null;
|
|
345
|
+
stderrVaultRef?: string | null;
|
|
346
|
+
occurredAt: string;
|
|
347
|
+
source: RunLifecycleSource;
|
|
348
|
+
}
|
|
349
|
+
declare const RUN_LIFECYCLE_TERMINAL_TYPES: readonly RunLifecycleEventType[];
|
|
350
|
+
/** `KAFKA_<BINDING>_TOPIC_<TOPIC>`: the resolved topic name the chart injects. */
|
|
351
|
+
declare function lifecycleTopicEnv(topic: LifecycleTopic, binding?: string): string;
|
|
277
352
|
declare function sandboxLifecycleTopicEnv(binding?: string): string;
|
|
353
|
+
declare function runLifecycleTopicEnv(binding?: string): string;
|
|
354
|
+
/** `KAFKA_<BINDING>_SCHEMA_REGISTRY_URL`: the Confluent-compatible registry the values were encoded against. */
|
|
355
|
+
declare function lifecycleSchemaRegistryEnv(binding?: string): string;
|
|
356
|
+
/** The registry subject a topic's value schema lives under (TopicNameStrategy). */
|
|
357
|
+
declare function lifecycleSchemaSubject(topic: LifecycleTopic): string;
|
|
278
358
|
declare function isSandboxLifecycleEvent(value: unknown): value is SandboxLifecycleEvent;
|
|
279
|
-
declare function
|
|
359
|
+
declare function isRunLifecycleEvent(value: unknown): value is RunLifecycleEvent;
|
|
360
|
+
/**
|
|
361
|
+
* Narrows a decoded record to a sandbox event. Accepts the object a registry
|
|
362
|
+
* client decoded, or JSON text for a value that was re-serialised along the
|
|
363
|
+
* way; returns null for anything else, including the raw Avro bytes, which
|
|
364
|
+
* only the registry can decode.
|
|
365
|
+
*/
|
|
366
|
+
declare function parseSandboxLifecycleEvent(raw: unknown): SandboxLifecycleEvent | null;
|
|
367
|
+
declare function parseRunLifecycleEvent(raw: unknown): RunLifecycleEvent | null;
|
|
280
368
|
|
|
281
369
|
declare function sandbox(config: SandboxConfig): SandboxClient;
|
|
282
370
|
|
|
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 };
|
|
371
|
+
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 };
|
|
372
|
+
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,31 @@ 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;
|
|
61
|
+
/**
|
|
62
|
+
* Backend to try when `provider` does not deliver. Naming it is asking for
|
|
63
|
+
* the swap, so it applies even when `provider` is named. Rejected on a run
|
|
64
|
+
* that targets an existing `sandboxId`.
|
|
65
|
+
*/
|
|
66
|
+
fallback?: string;
|
|
67
|
+
/**
|
|
68
|
+
* How long getting a sandbox ready may take. `timeoutMs` is the other
|
|
69
|
+
* half: how long the code may then run. Either omitted leaves the
|
|
70
|
+
* deployment's own limit in place; exceeding either ends the run as
|
|
71
|
+
* `timeout`.
|
|
72
|
+
*/
|
|
73
|
+
startTimeoutMs?: number;
|
|
74
|
+
/**
|
|
75
|
+
* What a blown budget does. `start` retries on the fallback and defaults
|
|
76
|
+
* to true — no code has executed yet, so it duplicates nothing. `session`
|
|
77
|
+
* runs the code a second time and defaults to false: the first attempt may
|
|
78
|
+
* have sent requests or written data before it hung.
|
|
79
|
+
*/
|
|
80
|
+
retry?: {
|
|
81
|
+
start?: boolean;
|
|
82
|
+
session?: boolean;
|
|
83
|
+
};
|
|
57
84
|
}
|
|
58
85
|
interface CreateSandboxRequest {
|
|
59
86
|
cpuSize?: number;
|
|
@@ -65,6 +92,8 @@ interface CreateSandboxRequest {
|
|
|
65
92
|
env?: Record<string, string>;
|
|
66
93
|
metadata?: Record<string, string>;
|
|
67
94
|
onTimeout?: SandboxOnTimeout;
|
|
95
|
+
/** Backend to host it; the deployment's default when omitted. */
|
|
96
|
+
provider?: string;
|
|
68
97
|
}
|
|
69
98
|
type FileCategory = 'input' | 'skill' | 'settings' | 'context' | 'workspace' | 'output';
|
|
70
99
|
interface FileInput {
|
|
@@ -89,6 +118,8 @@ interface BulkUploadResult {
|
|
|
89
118
|
}>;
|
|
90
119
|
}
|
|
91
120
|
type Status = 'pending' | 'running' | 'completed' | 'failed' | 'timeout' | 'cancelled';
|
|
121
|
+
/** A run's status, as `run-lifecycle` events and `RunResponse` report it. */
|
|
122
|
+
type RunStatus = Status;
|
|
92
123
|
interface RunResponse {
|
|
93
124
|
id: string;
|
|
94
125
|
workspaceId: string;
|
|
@@ -251,8 +282,22 @@ declare class FetchError extends Error {
|
|
|
251
282
|
static from(url: string, method: string, res: Response): Promise<FetchError>;
|
|
252
283
|
}
|
|
253
284
|
|
|
285
|
+
/**
|
|
286
|
+
* Lifecycle topics of the `lifecycle` Kafka item, one per aggregate and keyed
|
|
287
|
+
* by its id: `sandbox-lifecycle` by `sandboxId`, `run-lifecycle` by `runId`.
|
|
288
|
+
*
|
|
289
|
+
* Values are Avro in the Confluent wire format; the schema of each topic is
|
|
290
|
+
* registered under `<topic>-value` (`lifecycleSchemaSubject`). Decode with a
|
|
291
|
+
* registry client — `@kafkajs/confluent-schema-registry` against
|
|
292
|
+
* `KAFKA_<BINDING>_SCHEMA_REGISTRY_URL` — then narrow the decoded record with
|
|
293
|
+
* `isSandboxLifecycleEvent` / `isRunLifecycleEvent`. The message headers
|
|
294
|
+
* `event-type`, `event-id` and `workspace-id` carry enough to filter and
|
|
295
|
+
* dedupe without decoding.
|
|
296
|
+
*/
|
|
254
297
|
declare const SANDBOX_LIFECYCLE_TOPIC = "sandbox-lifecycle";
|
|
298
|
+
declare const RUN_LIFECYCLE_TOPIC = "run-lifecycle";
|
|
255
299
|
declare const SANDBOX_LIFECYCLE_ITEM = "lifecycle";
|
|
300
|
+
type LifecycleTopic = typeof SANDBOX_LIFECYCLE_TOPIC | typeof RUN_LIFECYCLE_TOPIC;
|
|
256
301
|
declare const SANDBOX_LIFECYCLE_EVENT_TYPES: readonly ["created", "ready", "suspended", "resumed", "terminated", "failed", "expired"];
|
|
257
302
|
type SandboxLifecycleEventType = (typeof SANDBOX_LIFECYCLE_EVENT_TYPES)[number];
|
|
258
303
|
type SandboxLifecycleSource = 'api' | 'provider-webhook' | 'provider-watch';
|
|
@@ -268,17 +313,60 @@ interface SandboxLifecycleEvent {
|
|
|
268
313
|
workspaceId: string;
|
|
269
314
|
provider: string;
|
|
270
315
|
externalId: string;
|
|
271
|
-
image?: string;
|
|
316
|
+
image?: string | null;
|
|
272
317
|
state: SandboxState;
|
|
273
318
|
metadata: Record<string, string>;
|
|
274
319
|
occurredAt: string;
|
|
275
320
|
source: SandboxLifecycleSource;
|
|
276
321
|
}
|
|
322
|
+
declare const RUN_LIFECYCLE_EVENT_TYPES: readonly ["created", "started", "completed", "failed", "timeout", "cancelled"];
|
|
323
|
+
type RunLifecycleEventType = (typeof RUN_LIFECYCLE_EVENT_TYPES)[number];
|
|
324
|
+
type RunLifecycleSource = 'api' | 'executor' | 'maintenance';
|
|
325
|
+
/**
|
|
326
|
+
* One run status transition, delivered at-least-once on the `run-lifecycle`
|
|
327
|
+
* topic keyed by `runId`. A run emits each `type` at most once; a terminal
|
|
328
|
+
* event carries the exit code, duration and Vault references of its output,
|
|
329
|
+
* so a consumer needs no `GET /api/runs/:id` to act on it.
|
|
330
|
+
*/
|
|
331
|
+
interface RunLifecycleEvent {
|
|
332
|
+
version: 1;
|
|
333
|
+
eventId: string;
|
|
334
|
+
type: RunLifecycleEventType;
|
|
335
|
+
runId: string;
|
|
336
|
+
workspaceId: string;
|
|
337
|
+
sandboxId?: string | null;
|
|
338
|
+
provider?: string | null;
|
|
339
|
+
language: string;
|
|
340
|
+
status: RunStatus;
|
|
341
|
+
exitCode?: number | null;
|
|
342
|
+
durationMs?: number | null;
|
|
343
|
+
errorMessage?: string | null;
|
|
344
|
+
stdoutVaultRef?: string | null;
|
|
345
|
+
stderrVaultRef?: string | null;
|
|
346
|
+
occurredAt: string;
|
|
347
|
+
source: RunLifecycleSource;
|
|
348
|
+
}
|
|
349
|
+
declare const RUN_LIFECYCLE_TERMINAL_TYPES: readonly RunLifecycleEventType[];
|
|
350
|
+
/** `KAFKA_<BINDING>_TOPIC_<TOPIC>`: the resolved topic name the chart injects. */
|
|
351
|
+
declare function lifecycleTopicEnv(topic: LifecycleTopic, binding?: string): string;
|
|
277
352
|
declare function sandboxLifecycleTopicEnv(binding?: string): string;
|
|
353
|
+
declare function runLifecycleTopicEnv(binding?: string): string;
|
|
354
|
+
/** `KAFKA_<BINDING>_SCHEMA_REGISTRY_URL`: the Confluent-compatible registry the values were encoded against. */
|
|
355
|
+
declare function lifecycleSchemaRegistryEnv(binding?: string): string;
|
|
356
|
+
/** The registry subject a topic's value schema lives under (TopicNameStrategy). */
|
|
357
|
+
declare function lifecycleSchemaSubject(topic: LifecycleTopic): string;
|
|
278
358
|
declare function isSandboxLifecycleEvent(value: unknown): value is SandboxLifecycleEvent;
|
|
279
|
-
declare function
|
|
359
|
+
declare function isRunLifecycleEvent(value: unknown): value is RunLifecycleEvent;
|
|
360
|
+
/**
|
|
361
|
+
* Narrows a decoded record to a sandbox event. Accepts the object a registry
|
|
362
|
+
* client decoded, or JSON text for a value that was re-serialised along the
|
|
363
|
+
* way; returns null for anything else, including the raw Avro bytes, which
|
|
364
|
+
* only the registry can decode.
|
|
365
|
+
*/
|
|
366
|
+
declare function parseSandboxLifecycleEvent(raw: unknown): SandboxLifecycleEvent | null;
|
|
367
|
+
declare function parseRunLifecycleEvent(raw: unknown): RunLifecycleEvent | null;
|
|
280
368
|
|
|
281
369
|
declare function sandbox(config: SandboxConfig): SandboxClient;
|
|
282
370
|
|
|
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 };
|
|
371
|
+
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 };
|
|
372
|
+
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,31 @@ 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;
|
|
61
|
+
/**
|
|
62
|
+
* Backend to try when `provider` does not deliver. Naming it is asking for
|
|
63
|
+
* the swap, so it applies even when `provider` is named. Rejected on a run
|
|
64
|
+
* that targets an existing `sandboxId`.
|
|
65
|
+
*/
|
|
66
|
+
fallback?: string;
|
|
67
|
+
/**
|
|
68
|
+
* How long getting a sandbox ready may take. `timeoutMs` is the other
|
|
69
|
+
* half: how long the code may then run. Either omitted leaves the
|
|
70
|
+
* deployment's own limit in place; exceeding either ends the run as
|
|
71
|
+
* `timeout`.
|
|
72
|
+
*/
|
|
73
|
+
startTimeoutMs?: number;
|
|
74
|
+
/**
|
|
75
|
+
* What a blown budget does. `start` retries on the fallback and defaults
|
|
76
|
+
* to true — no code has executed yet, so it duplicates nothing. `session`
|
|
77
|
+
* runs the code a second time and defaults to false: the first attempt may
|
|
78
|
+
* have sent requests or written data before it hung.
|
|
79
|
+
*/
|
|
80
|
+
retry?: {
|
|
81
|
+
start?: boolean;
|
|
82
|
+
session?: boolean;
|
|
83
|
+
};
|
|
57
84
|
}
|
|
58
85
|
interface CreateSandboxRequest {
|
|
59
86
|
cpuSize?: number;
|
|
@@ -65,6 +92,8 @@ interface CreateSandboxRequest {
|
|
|
65
92
|
env?: Record<string, string>;
|
|
66
93
|
metadata?: Record<string, string>;
|
|
67
94
|
onTimeout?: SandboxOnTimeout;
|
|
95
|
+
/** Backend to host it; the deployment's default when omitted. */
|
|
96
|
+
provider?: string;
|
|
68
97
|
}
|
|
69
98
|
type FileCategory = 'input' | 'skill' | 'settings' | 'context' | 'workspace' | 'output';
|
|
70
99
|
interface FileInput {
|
|
@@ -89,6 +118,8 @@ interface BulkUploadResult {
|
|
|
89
118
|
}>;
|
|
90
119
|
}
|
|
91
120
|
type Status = 'pending' | 'running' | 'completed' | 'failed' | 'timeout' | 'cancelled';
|
|
121
|
+
/** A run's status, as `run-lifecycle` events and `RunResponse` report it. */
|
|
122
|
+
type RunStatus = Status;
|
|
92
123
|
interface RunResponse {
|
|
93
124
|
id: string;
|
|
94
125
|
workspaceId: string;
|
|
@@ -251,8 +282,22 @@ declare class FetchError extends Error {
|
|
|
251
282
|
static from(url: string, method: string, res: Response): Promise<FetchError>;
|
|
252
283
|
}
|
|
253
284
|
|
|
285
|
+
/**
|
|
286
|
+
* Lifecycle topics of the `lifecycle` Kafka item, one per aggregate and keyed
|
|
287
|
+
* by its id: `sandbox-lifecycle` by `sandboxId`, `run-lifecycle` by `runId`.
|
|
288
|
+
*
|
|
289
|
+
* Values are Avro in the Confluent wire format; the schema of each topic is
|
|
290
|
+
* registered under `<topic>-value` (`lifecycleSchemaSubject`). Decode with a
|
|
291
|
+
* registry client — `@kafkajs/confluent-schema-registry` against
|
|
292
|
+
* `KAFKA_<BINDING>_SCHEMA_REGISTRY_URL` — then narrow the decoded record with
|
|
293
|
+
* `isSandboxLifecycleEvent` / `isRunLifecycleEvent`. The message headers
|
|
294
|
+
* `event-type`, `event-id` and `workspace-id` carry enough to filter and
|
|
295
|
+
* dedupe without decoding.
|
|
296
|
+
*/
|
|
254
297
|
declare const SANDBOX_LIFECYCLE_TOPIC = "sandbox-lifecycle";
|
|
298
|
+
declare const RUN_LIFECYCLE_TOPIC = "run-lifecycle";
|
|
255
299
|
declare const SANDBOX_LIFECYCLE_ITEM = "lifecycle";
|
|
300
|
+
type LifecycleTopic = typeof SANDBOX_LIFECYCLE_TOPIC | typeof RUN_LIFECYCLE_TOPIC;
|
|
256
301
|
declare const SANDBOX_LIFECYCLE_EVENT_TYPES: readonly ["created", "ready", "suspended", "resumed", "terminated", "failed", "expired"];
|
|
257
302
|
type SandboxLifecycleEventType = (typeof SANDBOX_LIFECYCLE_EVENT_TYPES)[number];
|
|
258
303
|
type SandboxLifecycleSource = 'api' | 'provider-webhook' | 'provider-watch';
|
|
@@ -268,17 +313,60 @@ interface SandboxLifecycleEvent {
|
|
|
268
313
|
workspaceId: string;
|
|
269
314
|
provider: string;
|
|
270
315
|
externalId: string;
|
|
271
|
-
image?: string;
|
|
316
|
+
image?: string | null;
|
|
272
317
|
state: SandboxState;
|
|
273
318
|
metadata: Record<string, string>;
|
|
274
319
|
occurredAt: string;
|
|
275
320
|
source: SandboxLifecycleSource;
|
|
276
321
|
}
|
|
322
|
+
declare const RUN_LIFECYCLE_EVENT_TYPES: readonly ["created", "started", "completed", "failed", "timeout", "cancelled"];
|
|
323
|
+
type RunLifecycleEventType = (typeof RUN_LIFECYCLE_EVENT_TYPES)[number];
|
|
324
|
+
type RunLifecycleSource = 'api' | 'executor' | 'maintenance';
|
|
325
|
+
/**
|
|
326
|
+
* One run status transition, delivered at-least-once on the `run-lifecycle`
|
|
327
|
+
* topic keyed by `runId`. A run emits each `type` at most once; a terminal
|
|
328
|
+
* event carries the exit code, duration and Vault references of its output,
|
|
329
|
+
* so a consumer needs no `GET /api/runs/:id` to act on it.
|
|
330
|
+
*/
|
|
331
|
+
interface RunLifecycleEvent {
|
|
332
|
+
version: 1;
|
|
333
|
+
eventId: string;
|
|
334
|
+
type: RunLifecycleEventType;
|
|
335
|
+
runId: string;
|
|
336
|
+
workspaceId: string;
|
|
337
|
+
sandboxId?: string | null;
|
|
338
|
+
provider?: string | null;
|
|
339
|
+
language: string;
|
|
340
|
+
status: RunStatus;
|
|
341
|
+
exitCode?: number | null;
|
|
342
|
+
durationMs?: number | null;
|
|
343
|
+
errorMessage?: string | null;
|
|
344
|
+
stdoutVaultRef?: string | null;
|
|
345
|
+
stderrVaultRef?: string | null;
|
|
346
|
+
occurredAt: string;
|
|
347
|
+
source: RunLifecycleSource;
|
|
348
|
+
}
|
|
349
|
+
declare const RUN_LIFECYCLE_TERMINAL_TYPES: readonly RunLifecycleEventType[];
|
|
350
|
+
/** `KAFKA_<BINDING>_TOPIC_<TOPIC>`: the resolved topic name the chart injects. */
|
|
351
|
+
declare function lifecycleTopicEnv(topic: LifecycleTopic, binding?: string): string;
|
|
277
352
|
declare function sandboxLifecycleTopicEnv(binding?: string): string;
|
|
353
|
+
declare function runLifecycleTopicEnv(binding?: string): string;
|
|
354
|
+
/** `KAFKA_<BINDING>_SCHEMA_REGISTRY_URL`: the Confluent-compatible registry the values were encoded against. */
|
|
355
|
+
declare function lifecycleSchemaRegistryEnv(binding?: string): string;
|
|
356
|
+
/** The registry subject a topic's value schema lives under (TopicNameStrategy). */
|
|
357
|
+
declare function lifecycleSchemaSubject(topic: LifecycleTopic): string;
|
|
278
358
|
declare function isSandboxLifecycleEvent(value: unknown): value is SandboxLifecycleEvent;
|
|
279
|
-
declare function
|
|
359
|
+
declare function isRunLifecycleEvent(value: unknown): value is RunLifecycleEvent;
|
|
360
|
+
/**
|
|
361
|
+
* Narrows a decoded record to a sandbox event. Accepts the object a registry
|
|
362
|
+
* client decoded, or JSON text for a value that was re-serialised along the
|
|
363
|
+
* way; returns null for anything else, including the raw Avro bytes, which
|
|
364
|
+
* only the registry can decode.
|
|
365
|
+
*/
|
|
366
|
+
declare function parseSandboxLifecycleEvent(raw: unknown): SandboxLifecycleEvent | null;
|
|
367
|
+
declare function parseRunLifecycleEvent(raw: unknown): RunLifecycleEvent | null;
|
|
280
368
|
|
|
281
369
|
declare function sandbox(config: SandboxConfig): SandboxClient;
|
|
282
370
|
|
|
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 };
|
|
371
|
+
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 };
|
|
372
|
+
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 };
|