@sealant/sdk-next 0.40.0-next.973 → 0.40.0-next.975
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/README.md +34 -13
- package/dist/client.d.ts +12 -2
- package/dist/client.js +22 -2
- package/dist/effect/api-client.d.ts +37 -11
- package/dist/effect/api-client.js +71 -28
- package/dist/effect/config.d.ts +47 -0
- package/dist/effect/config.js +36 -0
- package/dist/effect/context.d.ts +27 -0
- package/dist/effect/context.js +29 -0
- package/dist/effect/endpoint.d.ts +10 -0
- package/dist/effect/endpoint.js +1 -0
- package/dist/effect/errors.d.ts +113 -0
- package/dist/effect/errors.js +104 -0
- package/dist/effect/events/layer.d.ts +14 -0
- package/dist/effect/events/layer.js +109 -0
- package/dist/effect/events/observe.d.ts +19 -0
- package/dist/effect/events/observe.js +15 -0
- package/dist/effect/events/service.d.ts +62 -0
- package/dist/effect/events/service.js +3 -0
- package/dist/effect/http.d.ts +42 -0
- package/dist/effect/http.js +76 -0
- package/dist/effect/index.d.ts +49 -16
- package/dist/effect/index.js +45 -17
- package/dist/effect/layer.d.ts +24 -0
- package/dist/effect/layer.js +21 -0
- package/dist/effect/operations.d.ts +107 -30
- package/dist/effect/operations.js +7 -0
- package/dist/effect/read-retry.d.ts +4 -2
- package/dist/effect/read-retry.js +9 -2
- package/dist/effect/runs/layer.d.ts +9 -0
- package/dist/effect/runs/layer.js +94 -0
- package/dist/effect/runs/service.d.ts +51 -0
- package/dist/effect/runs/service.js +3 -0
- package/dist/effect/runs/wait.d.ts +15 -0
- package/dist/effect/runs/wait.js +16 -0
- package/dist/effect/runtime.d.ts +33 -14
- package/dist/effect/runtime.js +42 -50
- package/dist/effect/sessions/attach.d.ts +12 -0
- package/dist/effect/sessions/attach.js +142 -0
- package/dist/effect/sessions/layer.d.ts +10 -0
- package/dist/effect/sessions/layer.js +149 -0
- package/dist/effect/sessions/service.d.ts +83 -0
- package/dist/effect/sessions/service.js +3 -0
- package/dist/effect/websocket.d.ts +11 -0
- package/dist/effect/websocket.js +16 -0
- package/dist/effect/workspaces/layer.d.ts +9 -0
- package/dist/effect/workspaces/layer.js +148 -0
- package/dist/effect/workspaces/service.d.ts +75 -0
- package/dist/effect/workspaces/service.js +3 -0
- package/dist/effect/workspaces/wait.d.ts +216 -0
- package/dist/effect/workspaces/wait.js +158 -0
- package/dist/facade/exec-sync.d.ts +4 -0
- package/dist/facade/exec-sync.js +38 -0
- package/dist/facade/run.js +19 -20
- package/dist/facade/session.js +75 -89
- package/dist/facade/workspace.d.ts +5 -20
- package/dist/facade/workspace.js +122 -277
- package/dist/index.d.ts +1 -0
- package/dist/index.js +2 -0
- package/dist/internal/map-error.js +20 -1
- package/dist/internal/workspace-phase.d.ts +41 -0
- package/dist/internal/workspace-phase.js +95 -0
- package/dist/types.d.ts +42 -6
- package/package.json +3 -3
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The SDK's services as one layer. `SealantLayerNoInfra` leaves the infrastructure open, for an
|
|
3
|
+
* Effect app that already has an `HttpClient` (its own middleware, tracer, test client) and a
|
|
4
|
+
* `WebSocketConstructor`; `SealantLayer` provides fetch and the global `WebSocket` and needs only
|
|
5
|
+
* the config:
|
|
6
|
+
*
|
|
7
|
+
* const AppLayer = SealantLayer.pipe(Layer.provide(SealantConfig.layerFromEnv))
|
|
8
|
+
*
|
|
9
|
+
* Every service's `layer` provides the same contract client and events layers, so the graph builds
|
|
10
|
+
* one of each however many services it holds.
|
|
11
|
+
*/
|
|
12
|
+
import { Layer } from "effect";
|
|
13
|
+
import { type HttpClient } from "effect/http";
|
|
14
|
+
import type { Socket } from "effect/socket";
|
|
15
|
+
import { SealantApiClient } from "./api-client.js";
|
|
16
|
+
import type { SealantConfig } from "./config.js";
|
|
17
|
+
import type { SealantEvents } from "./events/service.js";
|
|
18
|
+
import type { Runs } from "./runs/service.js";
|
|
19
|
+
import type { Sessions } from "./sessions/service.js";
|
|
20
|
+
import type { Workspaces } from "./workspaces/service.js";
|
|
21
|
+
/** Every service the SDK provides. */
|
|
22
|
+
export type SealantServices = SealantApiClient | SealantEvents | Workspaces | Runs | Sessions;
|
|
23
|
+
export declare const SealantLayerNoInfra: Layer.Layer<SealantServices, never, SealantConfig | HttpClient.HttpClient | Socket.WebSocketConstructor>;
|
|
24
|
+
export declare const SealantLayer: Layer.Layer<SealantServices, never, SealantConfig>;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The SDK's services as one layer. `SealantLayerNoInfra` leaves the infrastructure open, for an
|
|
3
|
+
* Effect app that already has an `HttpClient` (its own middleware, tracer, test client) and a
|
|
4
|
+
* `WebSocketConstructor`; `SealantLayer` provides fetch and the global `WebSocket` and needs only
|
|
5
|
+
* the config:
|
|
6
|
+
*
|
|
7
|
+
* const AppLayer = SealantLayer.pipe(Layer.provide(SealantConfig.layerFromEnv))
|
|
8
|
+
*
|
|
9
|
+
* Every service's `layer` provides the same contract client and events layers, so the graph builds
|
|
10
|
+
* one of each however many services it holds.
|
|
11
|
+
*/
|
|
12
|
+
import { Layer } from "effect";
|
|
13
|
+
import { FetchHttpClient } from "effect/http";
|
|
14
|
+
import { SealantApiClient } from "./api-client.js";
|
|
15
|
+
import * as SealantEventsLayer from "./events/layer.js";
|
|
16
|
+
import * as RunsLayer from "./runs/layer.js";
|
|
17
|
+
import * as SessionsLayer from "./sessions/layer.js";
|
|
18
|
+
import { WebSocketConstructorLayer } from "./websocket.js";
|
|
19
|
+
import * as WorkspacesLayer from "./workspaces/layer.js";
|
|
20
|
+
export const SealantLayerNoInfra = Layer.mergeAll(SealantApiClient.layer, SealantEventsLayer.layer, WorkspacesLayer.layer, RunsLayer.layer, SessionsLayer.layer);
|
|
21
|
+
export const SealantLayer = SealantLayerNoInfra.pipe(Layer.provide([FetchHttpClient.layer, WebSocketConstructorLayer]));
|
|
@@ -375,6 +375,83 @@ export declare const execWorkspaceAsUserOp: (workspaceId: string, payload: ExecW
|
|
|
375
375
|
readonly createdAt: string;
|
|
376
376
|
readonly updatedAt: string;
|
|
377
377
|
}, import("@sealant/api-contracts").BudgetExceededError | import("effect/http/HttpClientError").HttpClientError | import("@sealant/api-contracts").RequestRefusedError | Schema.SchemaError | import("@sealant/api-contracts").WorkspaceBadGatewayError | import("@sealant/api-contracts").WorkspaceBadRequestError | import("@sealant/api-contracts").WorkspaceConflictError | import("@sealant/api-contracts").WorkspaceInternalServerError | import("@sealant/api-contracts").WorkspaceNotFoundError, SealantApiClient>;
|
|
378
|
+
/**
|
|
379
|
+
* `execWorkspaceOp` answered in its request once the run settled: the run, and each started
|
|
380
|
+
* command's exit code and bounded output (`POST /v1/workspaces/:id/exec-sync`).
|
|
381
|
+
*/
|
|
382
|
+
export declare const execWorkspaceSyncOp: (workspaceId: string, payload: ExecWorkspaceRequest) => Effect.Effect<{
|
|
383
|
+
readonly run: {
|
|
384
|
+
readonly runId: string;
|
|
385
|
+
readonly workspaceId: string;
|
|
386
|
+
readonly attemptId?: string | undefined;
|
|
387
|
+
readonly ownerUserId: string;
|
|
388
|
+
readonly harnessId: string;
|
|
389
|
+
readonly mode: "interactive" | "one-shot";
|
|
390
|
+
readonly status: "cancelled" | "completed" | "failed" | "queued" | "running";
|
|
391
|
+
readonly prompt?: string | undefined;
|
|
392
|
+
readonly command?: {
|
|
393
|
+
readonly executable: string;
|
|
394
|
+
readonly args: readonly string[];
|
|
395
|
+
readonly cwd?: string | undefined;
|
|
396
|
+
readonly argCount?: number | undefined;
|
|
397
|
+
readonly argLengths?: readonly number[] | undefined;
|
|
398
|
+
} | undefined;
|
|
399
|
+
readonly metadata?: {
|
|
400
|
+
readonly [x: string]: unknown;
|
|
401
|
+
} | undefined;
|
|
402
|
+
readonly user?: string | undefined;
|
|
403
|
+
readonly exitCode?: number | undefined;
|
|
404
|
+
readonly errorMessage?: string | undefined;
|
|
405
|
+
readonly startedAt?: string | undefined;
|
|
406
|
+
readonly finishedAt?: string | undefined;
|
|
407
|
+
readonly recordDeletedAt?: string | undefined;
|
|
408
|
+
readonly createdAt: string;
|
|
409
|
+
readonly updatedAt: string;
|
|
410
|
+
};
|
|
411
|
+
readonly results: readonly {
|
|
412
|
+
readonly exitCode: number | null;
|
|
413
|
+
readonly stdout: string;
|
|
414
|
+
readonly stderr: string;
|
|
415
|
+
readonly truncated: boolean;
|
|
416
|
+
}[];
|
|
417
|
+
}, import("@sealant/api-contracts").BudgetExceededError | import("effect/http/HttpClientError").HttpClientError | import("@sealant/api-contracts").RequestRefusedError | Schema.SchemaError | import("@sealant/api-contracts").WorkspaceBadGatewayError | import("@sealant/api-contracts").WorkspaceBadRequestError | import("@sealant/api-contracts").WorkspaceConflictError | import("@sealant/api-contracts").WorkspaceInternalServerError | import("@sealant/api-contracts").WorkspaceNotFoundError, SealantApiClient>;
|
|
418
|
+
/** `execWorkspaceSyncOp` as a Linux user: its own route, which an older control plane answers 404. */
|
|
419
|
+
export declare const execWorkspaceSyncAsUserOp: (workspaceId: string, payload: ExecWorkspaceAsUserRequest) => Effect.Effect<{
|
|
420
|
+
readonly run: {
|
|
421
|
+
readonly runId: string;
|
|
422
|
+
readonly workspaceId: string;
|
|
423
|
+
readonly attemptId?: string | undefined;
|
|
424
|
+
readonly ownerUserId: string;
|
|
425
|
+
readonly harnessId: string;
|
|
426
|
+
readonly mode: "interactive" | "one-shot";
|
|
427
|
+
readonly status: "cancelled" | "completed" | "failed" | "queued" | "running";
|
|
428
|
+
readonly prompt?: string | undefined;
|
|
429
|
+
readonly command?: {
|
|
430
|
+
readonly executable: string;
|
|
431
|
+
readonly args: readonly string[];
|
|
432
|
+
readonly cwd?: string | undefined;
|
|
433
|
+
readonly argCount?: number | undefined;
|
|
434
|
+
readonly argLengths?: readonly number[] | undefined;
|
|
435
|
+
} | undefined;
|
|
436
|
+
readonly metadata?: {
|
|
437
|
+
readonly [x: string]: unknown;
|
|
438
|
+
} | undefined;
|
|
439
|
+
readonly user?: string | undefined;
|
|
440
|
+
readonly exitCode?: number | undefined;
|
|
441
|
+
readonly errorMessage?: string | undefined;
|
|
442
|
+
readonly startedAt?: string | undefined;
|
|
443
|
+
readonly finishedAt?: string | undefined;
|
|
444
|
+
readonly recordDeletedAt?: string | undefined;
|
|
445
|
+
readonly createdAt: string;
|
|
446
|
+
readonly updatedAt: string;
|
|
447
|
+
};
|
|
448
|
+
readonly results: readonly {
|
|
449
|
+
readonly exitCode: number | null;
|
|
450
|
+
readonly stdout: string;
|
|
451
|
+
readonly stderr: string;
|
|
452
|
+
readonly truncated: boolean;
|
|
453
|
+
}[];
|
|
454
|
+
}, import("@sealant/api-contracts").BudgetExceededError | import("effect/http/HttpClientError").HttpClientError | import("@sealant/api-contracts").RequestRefusedError | Schema.SchemaError | import("@sealant/api-contracts").WorkspaceBadGatewayError | import("@sealant/api-contracts").WorkspaceBadRequestError | import("@sealant/api-contracts").WorkspaceConflictError | import("@sealant/api-contracts").WorkspaceInternalServerError | import("@sealant/api-contracts").WorkspaceNotFoundError, SealantApiClient>;
|
|
378
455
|
export declare const applyWorkspaceDotfilesOp: (workspaceId: string, payload: ApplyWorkspaceDotfilesRequest) => Effect.Effect<{
|
|
379
456
|
readonly runId: string;
|
|
380
457
|
readonly workspaceId: string;
|
|
@@ -550,71 +627,71 @@ export declare const listWorkspaceRuntimesOp: () => Effect.Effect<{
|
|
|
550
627
|
readonly runtime: "boat" | "cloudflare" | "docker" | "host-vm" | "k3s" | "k8s" | "microvm";
|
|
551
628
|
readonly os: {
|
|
552
629
|
readonly ubuntu: {
|
|
630
|
+
readonly supported: true;
|
|
631
|
+
} | {
|
|
553
632
|
readonly supported: false;
|
|
554
633
|
readonly message: string;
|
|
555
|
-
} | {
|
|
556
|
-
readonly supported: true;
|
|
557
634
|
};
|
|
558
635
|
readonly nix: {
|
|
636
|
+
readonly supported: true;
|
|
637
|
+
} | {
|
|
559
638
|
readonly supported: false;
|
|
560
639
|
readonly message: string;
|
|
561
|
-
} | {
|
|
562
|
-
readonly supported: true;
|
|
563
640
|
};
|
|
564
641
|
readonly arch: {
|
|
642
|
+
readonly supported: true;
|
|
643
|
+
} | {
|
|
565
644
|
readonly supported: false;
|
|
566
645
|
readonly message: string;
|
|
567
|
-
} | {
|
|
568
|
-
readonly supported: true;
|
|
569
646
|
};
|
|
570
647
|
readonly fedora: {
|
|
648
|
+
readonly supported: true;
|
|
649
|
+
} | {
|
|
571
650
|
readonly supported: false;
|
|
572
651
|
readonly message: string;
|
|
573
|
-
} | {
|
|
574
|
-
readonly supported: true;
|
|
575
652
|
};
|
|
576
653
|
};
|
|
577
654
|
readonly customImage: {
|
|
655
|
+
readonly supported: true;
|
|
656
|
+
} | {
|
|
578
657
|
readonly supported: false;
|
|
579
658
|
readonly message: string;
|
|
580
|
-
} | {
|
|
581
|
-
readonly supported: true;
|
|
582
659
|
};
|
|
583
660
|
readonly hostDirectories: {
|
|
661
|
+
readonly supported: true;
|
|
662
|
+
} | {
|
|
584
663
|
readonly supported: false;
|
|
585
664
|
readonly message: string;
|
|
586
|
-
} | {
|
|
587
|
-
readonly supported: true;
|
|
588
665
|
};
|
|
589
666
|
readonly docker: {
|
|
667
|
+
readonly supported: true;
|
|
668
|
+
} | {
|
|
590
669
|
readonly supported: false;
|
|
591
670
|
readonly message: string;
|
|
592
|
-
} | {
|
|
593
|
-
readonly supported: true;
|
|
594
671
|
};
|
|
595
672
|
readonly gvisor: {
|
|
673
|
+
readonly supported: true;
|
|
674
|
+
} | {
|
|
596
675
|
readonly supported: false;
|
|
597
676
|
readonly message: string;
|
|
598
|
-
} | {
|
|
599
|
-
readonly supported: true;
|
|
600
677
|
};
|
|
601
678
|
readonly clusterEnv: {
|
|
679
|
+
readonly supported: true;
|
|
680
|
+
} | {
|
|
602
681
|
readonly supported: false;
|
|
603
682
|
readonly message: string;
|
|
604
|
-
} | {
|
|
605
|
-
readonly supported: true;
|
|
606
683
|
};
|
|
607
684
|
readonly gitSource: {
|
|
685
|
+
readonly supported: true;
|
|
686
|
+
} | {
|
|
608
687
|
readonly supported: false;
|
|
609
688
|
readonly message: string;
|
|
610
|
-
} | {
|
|
611
|
-
readonly supported: true;
|
|
612
689
|
};
|
|
613
690
|
readonly dotfilesArchives: {
|
|
691
|
+
readonly supported: true;
|
|
692
|
+
} | {
|
|
614
693
|
readonly supported: false;
|
|
615
694
|
readonly message: string;
|
|
616
|
-
} | {
|
|
617
|
-
readonly supported: true;
|
|
618
695
|
};
|
|
619
696
|
readonly screen: {
|
|
620
697
|
readonly supported: false;
|
|
@@ -637,28 +714,28 @@ export declare const listWorkspaceRuntimesOp: () => Effect.Effect<{
|
|
|
637
714
|
};
|
|
638
715
|
readonly networkPolicy?: {
|
|
639
716
|
readonly vmIsolation: {
|
|
717
|
+
readonly supported: true;
|
|
718
|
+
} | {
|
|
640
719
|
readonly supported: false;
|
|
641
720
|
readonly message: string;
|
|
642
|
-
} | {
|
|
643
|
-
readonly supported: true;
|
|
644
721
|
};
|
|
645
722
|
readonly restricted: {
|
|
723
|
+
readonly supported: true;
|
|
724
|
+
} | {
|
|
646
725
|
readonly supported: false;
|
|
647
726
|
readonly message: string;
|
|
648
|
-
} | {
|
|
649
|
-
readonly supported: true;
|
|
650
727
|
};
|
|
651
728
|
readonly restrictedWithDocker: {
|
|
729
|
+
readonly supported: true;
|
|
730
|
+
} | {
|
|
652
731
|
readonly supported: false;
|
|
653
732
|
readonly message: string;
|
|
654
|
-
} | {
|
|
655
|
-
readonly supported: true;
|
|
656
733
|
};
|
|
657
734
|
readonly brokeredSecrets: {
|
|
735
|
+
readonly supported: true;
|
|
736
|
+
} | {
|
|
658
737
|
readonly supported: false;
|
|
659
738
|
readonly message: string;
|
|
660
|
-
} | {
|
|
661
|
-
readonly supported: true;
|
|
662
739
|
};
|
|
663
740
|
} | undefined;
|
|
664
741
|
}[];
|
|
@@ -19,6 +19,13 @@ export const listWorkspacesOp = (query) => Effect.flatMap(SealantApiClient, (cli
|
|
|
19
19
|
export const execWorkspaceOp = (workspaceId, payload) => Effect.flatMap(SealantApiClient, (client) => client.workspaces.execWorkspace({ params: { workspaceId }, payload }));
|
|
20
20
|
/** An exec as a Linux user: its own route, which a control plane that cannot run one answers 404. */
|
|
21
21
|
export const execWorkspaceAsUserOp = (workspaceId, payload) => Effect.flatMap(SealantApiClient, (client) => client.workspaces.execWorkspaceAsUser({ params: { workspaceId }, payload }));
|
|
22
|
+
/**
|
|
23
|
+
* `execWorkspaceOp` answered in its request once the run settled: the run, and each started
|
|
24
|
+
* command's exit code and bounded output (`POST /v1/workspaces/:id/exec-sync`).
|
|
25
|
+
*/
|
|
26
|
+
export const execWorkspaceSyncOp = (workspaceId, payload) => Effect.flatMap(SealantApiClient, (client) => client.workspaces.execWorkspaceSync({ params: { workspaceId }, payload }));
|
|
27
|
+
/** `execWorkspaceSyncOp` as a Linux user: its own route, which an older control plane answers 404. */
|
|
28
|
+
export const execWorkspaceSyncAsUserOp = (workspaceId, payload) => Effect.flatMap(SealantApiClient, (client) => client.workspaces.execWorkspaceSyncAsUser({ params: { workspaceId }, payload }));
|
|
22
29
|
export const applyWorkspaceDotfilesOp = (workspaceId, payload) => Effect.flatMap(SealantApiClient, (client) => client.workspaces.applyWorkspaceDotfiles({ params: { workspaceId }, payload }));
|
|
23
30
|
export const bindWorkspaceOp = (workspaceId, payload) => Effect.flatMap(SealantApiClient, (client) => client.workspaces.bindWorkspace({ params: { workspaceId }, payload }));
|
|
24
31
|
export const flushWorkspaceCaptureOp = (workspaceId, payload) => Effect.flatMap(SealantApiClient, (client) => client.workspaces.flushWorkspaceCapture({ params: { workspaceId }, payload }));
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Effect } from "effect";
|
|
2
2
|
import { SealantApiError } from "../errors.js";
|
|
3
|
+
import { SealantTransportError } from "./errors.js";
|
|
3
4
|
/** The most one read waits across all its retries: a whole budget window, and no more. */
|
|
4
5
|
export declare const READ_RETRY_BUDGET_MS = 60000;
|
|
5
6
|
/**
|
|
@@ -20,11 +21,12 @@ export declare const retryRead: <A, E, R>(read: Effect.Effect<A, E, R>, options:
|
|
|
20
21
|
}) => Effect.Effect<A, SealantApiError, R>;
|
|
21
22
|
/**
|
|
22
23
|
* Retries an idempotent workspace status read on transient transport errors and 5xx responses,
|
|
23
|
-
* within {@link READ_RETRY_BUDGET_MS} and `deadline
|
|
24
|
+
* within {@link READ_RETRY_BUDGET_MS} and `deadline`, failing with `SealantTransportError` naming
|
|
25
|
+
* the workspace once they run out. Non-retryable failures — including 429
|
|
24
26
|
* budget refusals, which callers translate into `workspace_readiness_refused` /
|
|
25
27
|
* `workspace_stop_observation_refused` — fail immediately unchanged.
|
|
26
28
|
*/
|
|
27
29
|
export declare const retryWorkspaceRead: <A, E, R>(read: Effect.Effect<A, E, R>, options: {
|
|
28
30
|
readonly workspaceId: string;
|
|
29
31
|
readonly deadline: number;
|
|
30
|
-
}) => Effect.Effect<A, E |
|
|
32
|
+
}) => Effect.Effect<A, E | SealantTransportError, R>;
|
|
@@ -11,6 +11,7 @@ import { HttpClientError } from "effect/http";
|
|
|
11
11
|
import { SealantApiError } from "../errors.js";
|
|
12
12
|
import { elapsed } from "../internal/clock.js";
|
|
13
13
|
import { toSealantError } from "../internal/map-error.js";
|
|
14
|
+
import { SealantTransportError } from "./errors.js";
|
|
14
15
|
import { CurrentRetryPolicy, NO_HTTP_RETRY_POLICY, parseRetryAfterMs } from "./retry-middleware.js";
|
|
15
16
|
/** The first backoff when the answer names no `Retry-After`; it doubles up to the cap. */
|
|
16
17
|
const READ_RETRY_FIRST_MS = 100;
|
|
@@ -90,7 +91,8 @@ export const retryRead = (read, options) => Effect.gen(function* () {
|
|
|
90
91
|
});
|
|
91
92
|
/**
|
|
92
93
|
* Retries an idempotent workspace status read on transient transport errors and 5xx responses,
|
|
93
|
-
* within {@link READ_RETRY_BUDGET_MS} and `deadline
|
|
94
|
+
* within {@link READ_RETRY_BUDGET_MS} and `deadline`, failing with `SealantTransportError` naming
|
|
95
|
+
* the workspace once they run out. Non-retryable failures — including 429
|
|
94
96
|
* budget refusals, which callers translate into `workspace_readiness_refused` /
|
|
95
97
|
* `workspace_stop_observation_refused` — fail immediately unchanged.
|
|
96
98
|
*/
|
|
@@ -111,7 +113,12 @@ export const retryWorkspaceRead = (read, options) => Effect.gen(function* () {
|
|
|
111
113
|
const mapped = toSealantError(error);
|
|
112
114
|
const status = statusOf(error);
|
|
113
115
|
const tries = attempt === 0 ? "" : ` (read ${String(attempt + 1)} times)`;
|
|
114
|
-
return yield*
|
|
116
|
+
return yield* new SealantTransportError({
|
|
117
|
+
operation: "Workspaces.get",
|
|
118
|
+
message: `Reading workspace ${options.workspaceId} failed${tries}: ${mapped.message}`,
|
|
119
|
+
...(status === undefined ? {} : { status }),
|
|
120
|
+
cause: error,
|
|
121
|
+
});
|
|
115
122
|
}
|
|
116
123
|
yield* Effect.sleep(Duration.millis(delay));
|
|
117
124
|
waited += delay;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Effect, Layer } from "effect";
|
|
2
|
+
import type { HttpClient } from "effect/http";
|
|
3
|
+
import { SealantApiClient } from "../api-client.js";
|
|
4
|
+
import { SealantConfig } from "../config.js";
|
|
5
|
+
import { SealantEvents } from "../events/service.js";
|
|
6
|
+
import { Runs } from "./service.js";
|
|
7
|
+
export declare const make: Effect.Effect<Runs["Service"], never, SealantApiClient | SealantEvents | SealantConfig>;
|
|
8
|
+
export declare const layerNoDeps: Layer.Layer<Runs, never, SealantApiClient | SealantEvents | SealantConfig>;
|
|
9
|
+
export declare const layer: Layer.Layer<Runs, never, SealantConfig | HttpClient.HttpClient>;
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { Duration, Effect, Layer, Option, Stream } from "effect";
|
|
2
|
+
import { SealantApiClient } from "../api-client.js";
|
|
3
|
+
import { SealantConfig } from "../config.js";
|
|
4
|
+
import { currentOwner } from "../context.js";
|
|
5
|
+
import { SealantWaitTimeoutError, transported } from "../errors.js";
|
|
6
|
+
import * as SealantEventsLayer from "../events/layer.js";
|
|
7
|
+
import { SealantEvents } from "../events/service.js";
|
|
8
|
+
import { Runs } from "./service.js";
|
|
9
|
+
import { awaitRunSettled, TERMINAL_RUN_STATUSES, untraced } from "./wait.js";
|
|
10
|
+
/** How often a stream reads the record while the run is going: new entries are not pushed. */
|
|
11
|
+
const STREAM_POLL = Duration.millis(500);
|
|
12
|
+
const timedOut = (operation, code, timeout, message) => new SealantWaitTimeoutError({
|
|
13
|
+
operation,
|
|
14
|
+
code,
|
|
15
|
+
message,
|
|
16
|
+
timeoutMs: Duration.toMillis(Duration.fromInputUnsafe(timeout)),
|
|
17
|
+
});
|
|
18
|
+
export const make = Effect.gen(function* () {
|
|
19
|
+
const client = yield* SealantApiClient;
|
|
20
|
+
const events = yield* SealantEvents;
|
|
21
|
+
const config = yield* SealantConfig;
|
|
22
|
+
const owner = currentOwner.pipe(Effect.provideService(SealantConfig, config));
|
|
23
|
+
const get = Effect.fnUntraced(function* (runId) {
|
|
24
|
+
const ownerUserId = yield* owner;
|
|
25
|
+
return yield* client.runs
|
|
26
|
+
.getRun({ params: { runId }, query: { ownerUserId } })
|
|
27
|
+
.pipe(transported("Runs.get"));
|
|
28
|
+
});
|
|
29
|
+
const timeline = Effect.fnUntraced(function* (runId, options = {}) {
|
|
30
|
+
const ownerUserId = yield* owner;
|
|
31
|
+
const response = yield* client.runs
|
|
32
|
+
.getRunTimeline({
|
|
33
|
+
params: { runId },
|
|
34
|
+
query: {
|
|
35
|
+
ownerUserId,
|
|
36
|
+
...(options.from === undefined ? {} : { fromSequence: options.from.toString() }),
|
|
37
|
+
...(options.kinds === undefined ? {} : { kinds: options.kinds.join(",") }),
|
|
38
|
+
},
|
|
39
|
+
})
|
|
40
|
+
.pipe(transported("Runs.timeline"));
|
|
41
|
+
return response.items;
|
|
42
|
+
});
|
|
43
|
+
const changes = Effect.fnUntraced(function* (runId) {
|
|
44
|
+
const ownerUserId = yield* owner;
|
|
45
|
+
return yield* client.runs
|
|
46
|
+
.getRunChanges({ params: { runId }, query: { ownerUserId } })
|
|
47
|
+
.pipe(transported("Runs.changes"));
|
|
48
|
+
});
|
|
49
|
+
const wait = Effect.fn("sealant.sdk.wait_run_settled")(function* (runId, options = {}) {
|
|
50
|
+
const ownerUserId = yield* owner;
|
|
51
|
+
const wakeups = yield* events.watch({ ownerUserId, runId });
|
|
52
|
+
const settled = awaitRunSettled(wakeups, untraced(get(runId)));
|
|
53
|
+
const { timeout } = options;
|
|
54
|
+
if (timeout === undefined)
|
|
55
|
+
return yield* settled;
|
|
56
|
+
return yield* settled.pipe(Effect.timeoutOrElse({
|
|
57
|
+
duration: timeout,
|
|
58
|
+
orElse: () => Effect.fail(timedOut("Runs.wait", "run_wait_timeout", timeout, `Run ${runId} was not terminal ${Duration.format(Duration.fromInputUnsafe(timeout))} after the wait started.`)),
|
|
59
|
+
}));
|
|
60
|
+
}, Effect.scoped);
|
|
61
|
+
const stream = (runId, options = {}) => {
|
|
62
|
+
const tail = Stream.unwrap(Effect.gen(function* () {
|
|
63
|
+
const ownerUserId = yield* owner;
|
|
64
|
+
const wakeups = yield* events.watch({ ownerUserId, runId });
|
|
65
|
+
const initial = { from: options.from, read: "first" };
|
|
66
|
+
return Stream.paginate(initial, Effect.fnUntraced(function* (cursor) {
|
|
67
|
+
if (cursor.read === "following") {
|
|
68
|
+
yield* wakeups.next({ poll: STREAM_POLL, atMost: STREAM_POLL });
|
|
69
|
+
}
|
|
70
|
+
// The first read is the caller's; the ones that follow are polls.
|
|
71
|
+
const read = (effect) => cursor.read === "following" ? untraced(effect) : effect;
|
|
72
|
+
const entries = yield* read(timeline(runId, { from: cursor.from }));
|
|
73
|
+
const last = entries.at(-1);
|
|
74
|
+
const from = last === undefined ? cursor.from : BigInt(last.sequence) + 1n;
|
|
75
|
+
// The read after the run was seen terminal catches what was written as it ended.
|
|
76
|
+
if (cursor.read === "final")
|
|
77
|
+
return [entries, Option.none()];
|
|
78
|
+
const run = yield* read(get(runId));
|
|
79
|
+
const next = {
|
|
80
|
+
from,
|
|
81
|
+
read: TERMINAL_RUN_STATUSES.has(run.status) ? "final" : "following",
|
|
82
|
+
};
|
|
83
|
+
return [entries, Option.some(next)];
|
|
84
|
+
}));
|
|
85
|
+
}));
|
|
86
|
+
const { timeout } = options;
|
|
87
|
+
if (timeout === undefined)
|
|
88
|
+
return tail;
|
|
89
|
+
return tail.pipe(Stream.interruptWhen(Effect.flatMap(Effect.sleep(timeout), () => Effect.fail(timedOut("Runs.stream", "run_stream_timeout", timeout, `Run ${runId} was still going when its record stream's ${Duration.format(Duration.fromInputUnsafe(timeout))} timeout passed.`)))));
|
|
90
|
+
};
|
|
91
|
+
return Runs.of({ get, timeline, changes, wait, stream });
|
|
92
|
+
});
|
|
93
|
+
export const layerNoDeps = Layer.effect(Runs, make);
|
|
94
|
+
export const layer = layerNoDeps.pipe(Layer.provide([SealantEventsLayer.layer, SealantApiClient.layer]));
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `Runs`: a run's record and its lifecycle as Effects, in the contract's wire types. A run is read
|
|
3
|
+
* as the acting owner (`ActingOwner`, else the configured owner).
|
|
4
|
+
*/
|
|
5
|
+
import type { Run, RunChangesResponse, TimelineEntry } from "@sealant/api-contracts";
|
|
6
|
+
import { Context, type Duration, type Effect, type Stream } from "effect";
|
|
7
|
+
import type { EndpointError } from "../endpoint.js";
|
|
8
|
+
import type { SealantWaitTimeoutError } from "../errors.js";
|
|
9
|
+
export interface TimelineOptions {
|
|
10
|
+
/** The first sequence to read (inclusive). Default: the record's start. */
|
|
11
|
+
readonly from?: bigint | undefined;
|
|
12
|
+
/** Only these event kinds, e.g. `["processStarted", "processExited"]`. */
|
|
13
|
+
readonly kinds?: ReadonlyArray<string> | undefined;
|
|
14
|
+
}
|
|
15
|
+
export interface WaitOptions {
|
|
16
|
+
/** Fail with `SealantWaitTimeoutError` (`run_wait_timeout`) once this passes. Default: no bound. */
|
|
17
|
+
readonly timeout?: Duration.Input | undefined;
|
|
18
|
+
}
|
|
19
|
+
export interface StreamOptions {
|
|
20
|
+
/** The first sequence to read (inclusive). Default: the record's start. */
|
|
21
|
+
readonly from?: bigint | undefined;
|
|
22
|
+
/**
|
|
23
|
+
* Fail with `SealantWaitTimeoutError` (`run_stream_timeout`) once this passes with the run
|
|
24
|
+
* still going. Default: no bound; the stream follows the run for as long as it lives.
|
|
25
|
+
*/
|
|
26
|
+
readonly timeout?: Duration.Input | undefined;
|
|
27
|
+
}
|
|
28
|
+
export type RunReadError = EndpointError<"runs", "getRun">;
|
|
29
|
+
export type TimelineReadError = EndpointError<"runs", "getRunTimeline">;
|
|
30
|
+
export interface RunsShape {
|
|
31
|
+
readonly get: (runId: string) => Effect.Effect<Run, RunReadError>;
|
|
32
|
+
/** One page of the run's record from `from`. */
|
|
33
|
+
readonly timeline: (runId: string, options?: TimelineOptions) => Effect.Effect<ReadonlyArray<TimelineEntry>, TimelineReadError>;
|
|
34
|
+
/** The files the run changed, once it is terminal. */
|
|
35
|
+
readonly changes: (runId: string) => Effect.Effect<RunChangesResponse, EndpointError<"runs", "getRunChanges">>;
|
|
36
|
+
/**
|
|
37
|
+
* Waits until the run is completed, failed or cancelled, woken by its `run.status` events, and
|
|
38
|
+
* answers with it. A failed run is an answer, not an error.
|
|
39
|
+
*/
|
|
40
|
+
readonly wait: (runId: string, options?: WaitOptions) => Effect.Effect<Run, RunReadError | SealantWaitTimeoutError>;
|
|
41
|
+
/**
|
|
42
|
+
* The run's record as it is written: every entry from `from`, then each new one, until the run
|
|
43
|
+
* is terminal (with a final read for entries written as it ended). New entries are not pushed,
|
|
44
|
+
* so while the run is going the record is read every half second; its end is pushed.
|
|
45
|
+
*/
|
|
46
|
+
readonly stream: (runId: string, options?: StreamOptions) => Stream.Stream<TimelineEntry, RunReadError | TimelineReadError | SealantWaitTimeoutError>;
|
|
47
|
+
}
|
|
48
|
+
declare const Runs_base: Context.ServiceClass<Runs, "@sealant/sdk/Runs", RunsShape>;
|
|
49
|
+
export declare class Runs extends Runs_base {
|
|
50
|
+
}
|
|
51
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Waiting on a run: read it, and read again when its `run.status` event (or a `resync`) says it
|
|
3
|
+
* changed, until it is completed, failed or cancelled. With no push channel, read every half second.
|
|
4
|
+
*/
|
|
5
|
+
import type { Run } from "@sealant/api-contracts";
|
|
6
|
+
import { Effect } from "effect";
|
|
7
|
+
import type { Wakeups } from "../events/service.js";
|
|
8
|
+
export declare const TERMINAL_RUN_STATUSES: ReadonlySet<string>;
|
|
9
|
+
/** The run, read with `read`, once it is terminal. */
|
|
10
|
+
export declare const awaitRunSettled: <E, R>(wakeups: Wakeups, read: Effect.Effect<Run, E, R>) => Effect.Effect<Run, E, R>;
|
|
11
|
+
/**
|
|
12
|
+
* A read the SDK makes while it waits, in no trace: a wait that lasts as long as an agent does
|
|
13
|
+
* never grows its caller's trace by a span per read.
|
|
14
|
+
*/
|
|
15
|
+
export declare const untraced: <A, E, R>(effect: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Duration, Effect } from "effect";
|
|
2
|
+
import { done, observe, waitFor } from "../events/observe.js";
|
|
3
|
+
export const TERMINAL_RUN_STATUSES = new Set([
|
|
4
|
+
"completed",
|
|
5
|
+
"failed",
|
|
6
|
+
"cancelled",
|
|
7
|
+
]);
|
|
8
|
+
/** With no push channel, how often a wait reads the run. */
|
|
9
|
+
const WAIT_POLL = Duration.millis(500);
|
|
10
|
+
/** The run, read with `read`, once it is terminal. */
|
|
11
|
+
export const awaitRunSettled = (wakeups, read) => observe(wakeups, read, (run) => Effect.succeed(TERMINAL_RUN_STATUSES.has(run.status) ? done(run) : waitFor({ poll: WAIT_POLL })));
|
|
12
|
+
/**
|
|
13
|
+
* A read the SDK makes while it waits, in no trace: a wait that lasts as long as an agent does
|
|
14
|
+
* never grows its caller's trace by a span per read.
|
|
15
|
+
*/
|
|
16
|
+
export const untraced = (effect) => Effect.withTracerEnabled(effect, false);
|
package/dist/effect/runtime.d.ts
CHANGED
|
@@ -1,27 +1,46 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The SDK runtime
|
|
2
|
+
* The SDK runtime: the one bridge from the Promise facade to the Effect services.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
4
|
+
* A `ManagedRuntime` over the SDK's layer, built lazily on the first call and once: the contract
|
|
5
|
+
* client, the events channel and the services, over a fetch `HttpClient` (the configured `fetch`,
|
|
6
|
+
* else the global one) and the global `WebSocket`. Every facade call runs one effect on it and
|
|
7
|
+
* surfaces a plain `SealantError` (the typed failure is squashed and mapped here). A call given an
|
|
8
|
+
* `AbortSignal` is interrupted when it aborts. `dispose()` interrupts every call still running,
|
|
9
|
+
* then releases the layer.
|
|
10
10
|
*/
|
|
11
|
-
import { Effect } from "effect";
|
|
11
|
+
import { type Context, type Effect, Layer, Stream } from "effect";
|
|
12
|
+
import type { Socket } from "effect/socket";
|
|
12
13
|
import type { SealantInternalConfig } from "../internal/config.js";
|
|
13
|
-
import { SealantApiClient } from "./api-client.js";
|
|
14
|
+
import type { SealantApiClient } from "./api-client.js";
|
|
15
|
+
import type { SealantConfig } from "./config.js";
|
|
16
|
+
import type { SealantEvents } from "./events/service.js";
|
|
17
|
+
import { type SealantServices } from "./layer.js";
|
|
14
18
|
import { type CallerTrace } from "./trace.js";
|
|
15
|
-
/**
|
|
16
|
-
|
|
19
|
+
/**
|
|
20
|
+
* Services the facade's effects may require: the contract client, the events channel the waits
|
|
21
|
+
* are woken by, the config they read the owner from, and the attach socket's constructor.
|
|
22
|
+
*/
|
|
23
|
+
export type SdkServices = SealantApiClient | SealantEvents | SealantConfig | Socket.WebSocketConstructor;
|
|
17
24
|
export interface SdkRuntime {
|
|
18
25
|
/**
|
|
19
26
|
* Provide the app context and run an operation effect, surfacing plain `SealantError`s. The
|
|
20
27
|
* effect continues `trace` when given, else the caller's trace captured when `run` is called
|
|
21
|
-
* (see `captureCallerTrace`).
|
|
28
|
+
* (see `captureCallerTrace`), and is interrupted when `signal` aborts.
|
|
29
|
+
*/
|
|
30
|
+
readonly run: <A, E>(effect: Effect.Effect<A, E, SdkServices>, trace?: CallerTrace, signal?: AbortSignal) => Promise<A>;
|
|
31
|
+
/**
|
|
32
|
+
* The stream as an async iterable on the runtime, failing with plain `SealantError`s. Breaking
|
|
33
|
+
* out of the loop interrupts the stream.
|
|
22
34
|
*/
|
|
23
|
-
readonly
|
|
24
|
-
/**
|
|
35
|
+
readonly iterate: <A, E>(stream: Stream.Stream<A, E, SdkServices>) => AsyncIterable<A>;
|
|
36
|
+
/** Interrupt every call still running and release the layer. Idempotent. */
|
|
25
37
|
readonly dispose: () => Promise<void>;
|
|
26
38
|
}
|
|
39
|
+
/** The SDK's layer over the facade's resolved config, with its config in the context too. */
|
|
40
|
+
export declare const sdkLayer: (config: SealantInternalConfig) => Layer.Layer<SealantServices | SdkServices>;
|
|
41
|
+
/**
|
|
42
|
+
* `stream` as an async iterable over the context `context` resolves (a runtime's, built on the
|
|
43
|
+
* first `next`), its failures mapped to plain `SealantError`s.
|
|
44
|
+
*/
|
|
45
|
+
export declare const iterateOn: <A, E, R>(context: () => Promise<Context.Context<R>>, stream: Stream.Stream<A, E, R>) => AsyncIterable<A>;
|
|
27
46
|
export declare const makeSdkRuntime: (config: SealantInternalConfig) => SdkRuntime;
|