@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
package/README.md
CHANGED
|
@@ -19,24 +19,45 @@ await run.record.replay();
|
|
|
19
19
|
|
|
20
20
|
## Design
|
|
21
21
|
|
|
22
|
-
- **Plain-Promise facade over
|
|
23
|
-
Effect
|
|
24
|
-
|
|
25
|
-
and the typed contract errors on the failure channel (no squashing) —
|
|
22
|
+
- **Plain-Promise facade over Effect services.** The default export is ordinary `async`/`await`. An
|
|
23
|
+
Effect program uses the services in `@sealant/sdk/effect` directly, with typed errors and no
|
|
24
|
+
Promise in the way. One layer serves every user: `ActingOwner` scopes a call to one, per fiber.
|
|
26
25
|
|
|
27
26
|
```ts
|
|
28
|
-
import { Effect } from "effect";
|
|
29
|
-
import {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
27
|
+
import { Effect, Layer } from "effect";
|
|
28
|
+
import {
|
|
29
|
+
ActingOwner,
|
|
30
|
+
SealantConfig,
|
|
31
|
+
SealantLayer,
|
|
32
|
+
Sessions,
|
|
33
|
+
Workspaces,
|
|
34
|
+
} from "@sealant/sdk/effect";
|
|
35
|
+
|
|
36
|
+
const program = Effect.gen(function* () {
|
|
37
|
+
const workspaces = yield* Workspaces;
|
|
38
|
+
// Woken by the workspace's events (`GET /v1/events`), not a timer.
|
|
39
|
+
yield* workspaces.waitReady("ws_123");
|
|
40
|
+
const { results } = yield* workspaces.execSync("ws_123", {
|
|
41
|
+
commands: [{ executable: "git", args: ["status", "--short"] }],
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
// A scoped duplex socket: reopened from the next record if it is cut.
|
|
45
|
+
const sessions = yield* Sessions;
|
|
46
|
+
const attached = yield* sessions.attach("ses_456");
|
|
47
|
+
yield* attached.write("ls\n");
|
|
48
|
+
return yield* attached.exit;
|
|
49
|
+
}).pipe(
|
|
50
|
+
Effect.scoped,
|
|
51
|
+
Effect.provideService(ActingOwner, "usr_alice"),
|
|
52
|
+
Effect.catchTag("WorkspaceSettledError", (error) => Effect.die(error)),
|
|
37
53
|
);
|
|
54
|
+
|
|
55
|
+
program.pipe(Effect.provide(SealantLayer.pipe(Layer.provide(SealantConfig.layerFromEnv))));
|
|
38
56
|
```
|
|
39
57
|
|
|
58
|
+
`SealantLayerNoInfra` leaves the `HttpClient` and `WebSocketConstructor` to the app, so its own
|
|
59
|
+
middleware, tracer and test clients see every request.
|
|
60
|
+
|
|
40
61
|
- **Decoupled public types.** The types in [`src/types.ts`](src/types.ts) are hand-written and kept
|
|
41
62
|
independent of the Effect-core and `@sealant/telemetry` internal shapes, so the public surface
|
|
42
63
|
stays stable across internal change. The whole surface is typed now, including operations not yet
|
package/dist/client.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type ScopesNamespace } from "./scopes.js";
|
|
2
|
-
import type { AccessTokensNamespace, BoatAccountsNamespace, ConnectedAccountsNamespace, CreateOptions, InferenceNamespace, ListOptions, Run, SealantFeatures, SshKeysNamespace, Workspace, WorkspaceCreateState, WorkspaceImageInspection, WorkspaceRuntimes, WorkspaceSshNamespace, SealantConfig, UsersNamespace } from "./types.js";
|
|
2
|
+
import type { AccessTokensNamespace, BoatAccountsNamespace, ConnectedAccountsNamespace, CreateOptions, InferenceNamespace, ListOptions, Run, SealantFeatures, SshKeysNamespace, Workspace, WorkspaceCreateState, WorkspaceExecOptions, WorkspaceExecSyncResult, WorkspaceImageInspection, WorkspaceRuntimes, WorkspaceSshNamespace, SealantConfig, UsersNamespace } from "./types.js";
|
|
3
3
|
export declare class Sealant {
|
|
4
4
|
#private;
|
|
5
5
|
/**
|
|
@@ -17,6 +17,11 @@ export declare class Sealant {
|
|
|
17
17
|
features(): Promise<SealantFeatures>;
|
|
18
18
|
/** Workspace lifecycle: create, fetch, and list live environments. */
|
|
19
19
|
readonly workspaces: {
|
|
20
|
+
/**
|
|
21
|
+
* `workspace.execSync()` by the workspace's id, with no read of the workspace first: one
|
|
22
|
+
* command run in one request, answered with its exit code and bounded output.
|
|
23
|
+
*/
|
|
24
|
+
execSync: (workspaceId: string, argv: readonly string[], options?: WorkspaceExecOptions) => Promise<WorkspaceExecSyncResult>;
|
|
20
25
|
create: (options: CreateOptions) => Promise<Workspace>;
|
|
21
26
|
get: (id: string) => Promise<Workspace>;
|
|
22
27
|
/**
|
|
@@ -101,7 +106,12 @@ export declare class Sealant {
|
|
|
101
106
|
readonly runs: {
|
|
102
107
|
get: (runId: string) => Promise<Run>;
|
|
103
108
|
};
|
|
104
|
-
/**
|
|
109
|
+
/**
|
|
110
|
+
* Release what the client holds: interrupt every call still running (a `ready()`, a `wait()`, a
|
|
111
|
+
* stream) and close its HTTP client and event subscriptions. Calls made after it fail.
|
|
112
|
+
*/
|
|
105
113
|
close(): Promise<void>;
|
|
114
|
+
/** {@link close}, by the name an Effect `ManagedRuntime` uses. */
|
|
115
|
+
dispose(): Promise<void>;
|
|
106
116
|
[Symbol.asyncDispose](): Promise<void>;
|
|
107
117
|
}
|
package/dist/client.js
CHANGED
|
@@ -4,6 +4,7 @@ import { makeSdkRuntime } from "./effect/runtime.js";
|
|
|
4
4
|
import { withCallerTrace } from "./effect/trace.js";
|
|
5
5
|
import { SealantBudgetExceededError, SealantError } from "./errors.js";
|
|
6
6
|
import { captureTrace } from "./facade/context.js";
|
|
7
|
+
import { execWorkspaceSync } from "./facade/exec-sync.js";
|
|
7
8
|
import { makeRun } from "./facade/run.js";
|
|
8
9
|
import { makeWorkspace, registerHarnessExecutors, toRuntimeInfo, toWorkspaceImage, } from "./facade/workspace.js";
|
|
9
10
|
import { buildCreateWorkspaceRequest } from "./internal/blueprint.js";
|
|
@@ -12,7 +13,7 @@ import { parseTtlSeconds } from "./internal/duration.js";
|
|
|
12
13
|
import { readFeatures, requireConnectedAccountDefaults, requireConnectedAccountEndpoints, requireConnectedAccountLoginClass, requireInferenceAllowedLogin, } from "./internal/features.js";
|
|
13
14
|
import { imageSpecKey } from "./internal/image-key.js";
|
|
14
15
|
import { buildInferenceRespondRequest, mapInferenceResponse } from "./internal/inference.js";
|
|
15
|
-
import { requireSshUser } from "./internal/process-user.js";
|
|
16
|
+
import { requireProcessUser, requireSshUser } from "./internal/process-user.js";
|
|
16
17
|
import { mapSshKey, mapWorkspaceSshInfo } from "./internal/ssh.js";
|
|
17
18
|
import { makeScopes } from "./scopes.js";
|
|
18
19
|
/** An idempotent create's state as the SDK reports it (an unknown wire state fails closed). */
|
|
@@ -87,6 +88,18 @@ export class Sealant {
|
|
|
87
88
|
}
|
|
88
89
|
/** Workspace lifecycle: create, fetch, and list live environments. */
|
|
89
90
|
workspaces = {
|
|
91
|
+
/**
|
|
92
|
+
* `workspace.execSync()` by the workspace's id, with no read of the workspace first: one
|
|
93
|
+
* command run in one request, answered with its exit code and bounded output.
|
|
94
|
+
*/
|
|
95
|
+
execSync: async (workspaceId, argv, options) => {
|
|
96
|
+
const trace = captureTrace(this.#ctx);
|
|
97
|
+
const user = options?.user;
|
|
98
|
+
if (user !== undefined) {
|
|
99
|
+
await withCallerTrace(trace, () => requireProcessUser(this.#ctx, user));
|
|
100
|
+
}
|
|
101
|
+
return execWorkspaceSync(this.#ctx, workspaceId, argv, options, trace);
|
|
102
|
+
},
|
|
90
103
|
create: async (options) => {
|
|
91
104
|
// Every request create makes, readiness polls included, continues the caller's trace.
|
|
92
105
|
const trace = captureTrace(this.#ctx);
|
|
@@ -428,10 +441,17 @@ export class Sealant {
|
|
|
428
441
|
return makeRun(this.#ctx, { wire });
|
|
429
442
|
},
|
|
430
443
|
};
|
|
431
|
-
/**
|
|
444
|
+
/**
|
|
445
|
+
* Release what the client holds: interrupt every call still running (a `ready()`, a `wait()`, a
|
|
446
|
+
* stream) and close its HTTP client and event subscriptions. Calls made after it fail.
|
|
447
|
+
*/
|
|
432
448
|
async close() {
|
|
433
449
|
await this.#runtime.dispose();
|
|
434
450
|
}
|
|
451
|
+
/** {@link close}, by the name an Effect `ManagedRuntime` uses. */
|
|
452
|
+
dispose() {
|
|
453
|
+
return this.close();
|
|
454
|
+
}
|
|
435
455
|
[Symbol.asyncDispose]() {
|
|
436
456
|
return this.close();
|
|
437
457
|
}
|
|
@@ -1,12 +1,31 @@
|
|
|
1
1
|
import { Context, Effect, Layer } from "effect";
|
|
2
|
-
import { HttpClient } from "effect/http";
|
|
2
|
+
import { HttpClient, HttpClientRequest } from "effect/http";
|
|
3
3
|
import { HttpApiClient } from "effect/http-api";
|
|
4
|
-
import {
|
|
5
|
-
import type {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
|
|
4
|
+
import type { SealantInternalConfig } from "../internal/config.js";
|
|
5
|
+
import type { SealantConfig as PublicSealantConfig } from "../types.js";
|
|
6
|
+
import { SealantConfig } from "./config.js";
|
|
7
|
+
import { type RequestPriorityLevel } from "./context.js";
|
|
8
|
+
/**
|
|
9
|
+
* An operation's own priority, used when the caller set none: session controls provide
|
|
10
|
+
* `interactive`. Providing it never changes concurrent requests.
|
|
11
|
+
*/
|
|
12
|
+
export declare const CurrentRequestPriority: Context.Reference<RequestPriorityLevel | undefined>;
|
|
13
|
+
/**
|
|
14
|
+
* A host that is not Effect resolves its priority at each dispatch (the Promise facade's
|
|
15
|
+
* `requestPriority`, read from its own request context). Read once, when the client is built.
|
|
16
|
+
*/
|
|
17
|
+
export declare const HostRequestPriority: Context.Reference<(() => import("../types.js").RequestPriority) | import("../types.js").RequestPriority | undefined>;
|
|
18
|
+
/**
|
|
19
|
+
* The priority header's value: the caller's `RequestPriority`, else the host's, else the
|
|
20
|
+
* operation's own, else `normal`.
|
|
21
|
+
*/
|
|
22
|
+
export declare const requestPriorityHeader: (caller: RequestPriorityLevel | undefined, host: PublicSealantConfig["requestPriority"], operation: RequestPriorityLevel | undefined) => RequestPriorityLevel;
|
|
23
|
+
/**
|
|
24
|
+
* The headers every request carries: its priority, the caller's trace when no exporting tracer
|
|
25
|
+
* propagates it, and the API key. Read in the request's own fiber, so per-call references apply.
|
|
26
|
+
*/
|
|
27
|
+
export declare const authorize: (config: SealantConfig["Service"], host: PublicSealantConfig["requestPriority"]) => (request: HttpClientRequest.HttpClientRequest) => Effect.Effect<HttpClientRequest.HttpClientRequest, never, never>;
|
|
28
|
+
declare const makeControlPlaneClient: Effect.Effect<{
|
|
10
29
|
readonly accessTokens: {
|
|
11
30
|
readonly createAccessToken: HttpApiClient.Client.Method<import("effect/http-api/HttpApiEndpoint").HttpApiEndpoint<"createAccessToken", "POST", "/v1/access-tokens/", never, never, import("effect/Schema").toCodecJson<import("effect/Schema").Struct<{
|
|
12
31
|
readonly ownerUserId: import("effect/Schema").String;
|
|
@@ -5025,9 +5044,9 @@ declare const buildControlPlaneClient: (config: SealantInternalConfig) => Effect
|
|
|
5025
5044
|
}>>;
|
|
5026
5045
|
}>>, import("effect/Schema").toCodecJson<typeof import("@sealant/api-contracts").WorkspaceBadRequestError | typeof import("@sealant/api-contracts").WorkspaceNotFoundError | typeof import("@sealant/api-contracts").WorkspaceConflictError | typeof import("@sealant/api-contracts").WorkspaceBadGatewayError | typeof import("@sealant/api-contracts").WorkspaceInternalServerError>, import("@sealant/api-contracts").RequestBudget | import("@sealant/api-contracts").RequestRefusal, never>, never, never>;
|
|
5027
5046
|
};
|
|
5028
|
-
}, never, HttpClient.HttpClient>;
|
|
5047
|
+
}, never, HttpClient.HttpClient | SealantConfig>;
|
|
5029
5048
|
/** The fully-typed control-plane client, derived from the `@sealant/api-contracts` HttpApi. */
|
|
5030
|
-
export type ControlPlaneClient = Effect.Success<
|
|
5049
|
+
export type ControlPlaneClient = Effect.Success<typeof makeControlPlaneClient>;
|
|
5031
5050
|
declare const SealantApiClient_base: Context.ServiceClass<SealantApiClient, "@sealant/sdk/SealantApiClient", {
|
|
5032
5051
|
readonly accessTokens: {
|
|
5033
5052
|
readonly createAccessToken: HttpApiClient.Client.Method<import("effect/http-api/HttpApiEndpoint").HttpApiEndpoint<"createAccessToken", "POST", "/v1/access-tokens/", never, never, import("effect/Schema").toCodecJson<import("effect/Schema").Struct<{
|
|
@@ -10049,10 +10068,17 @@ declare const SealantApiClient_base: Context.ServiceClass<SealantApiClient, "@se
|
|
|
10049
10068
|
};
|
|
10050
10069
|
}>;
|
|
10051
10070
|
export declare class SealantApiClient extends SealantApiClient_base {
|
|
10071
|
+
/** The client over the `HttpClient` the composition root provides. */
|
|
10072
|
+
static readonly layer: Layer.Layer<SealantApiClient, never, SealantConfig | HttpClient.HttpClient>;
|
|
10052
10073
|
}
|
|
10074
|
+
/** `SealantConfig` from the Promise facade's resolved config. */
|
|
10075
|
+
export declare const sealantConfigFrom: (config: SealantInternalConfig) => Layer.Layer<SealantConfig>;
|
|
10076
|
+
/** A fetch `HttpClient` over the configured `fetch`, else the global one. */
|
|
10077
|
+
export declare const fetchHttpClientFrom: (config: SealantInternalConfig) => Layer.Layer<HttpClient.HttpClient>;
|
|
10053
10078
|
/**
|
|
10054
|
-
*
|
|
10055
|
-
*
|
|
10079
|
+
* The client over a fetch `HttpClient` (the configured `fetch`, else the global one), with an
|
|
10080
|
+
* optional bearer token: the Promise facade's form. An Effect app provides `SealantApiClient.layer`
|
|
10081
|
+
* its own `SealantConfig` and `HttpClient` instead.
|
|
10056
10082
|
*/
|
|
10057
10083
|
export declare const sealantApiClientLayer: (config: SealantInternalConfig) => Layer.Layer<SealantApiClient>;
|
|
10058
10084
|
export {};
|
|
@@ -7,44 +7,87 @@
|
|
|
7
7
|
* `TaggedError`s the server declares. No codegen step, no generated artifact, no drift — change the
|
|
8
8
|
* contract and these call sites move with it. (OpenAPI/`buf generate` is reserved for non-TypeScript
|
|
9
9
|
* clients, per SEALANT-PLAN §8.)
|
|
10
|
+
*
|
|
11
|
+
* The client is built over whatever `HttpClient` the composition root provides (`FetchHttpClient`,
|
|
12
|
+
* a platform client, a test client), so an Effect app's own middleware, tracer and test doubles see
|
|
13
|
+
* every request the SDK makes.
|
|
10
14
|
*/
|
|
11
15
|
import { ControlPlaneAPI } from "@sealant/api-contracts";
|
|
12
|
-
import { Context, Effect, Layer } from "effect";
|
|
16
|
+
import { Context, Effect, Layer, Option, Redacted } from "effect";
|
|
13
17
|
import { FetchHttpClient, HttpClient, HttpClientRequest } from "effect/http";
|
|
14
18
|
import { HttpApiClient } from "effect/http-api";
|
|
15
|
-
import {
|
|
19
|
+
import { SealantConfig } from "./config.js";
|
|
20
|
+
import { RequestPriority } from "./context.js";
|
|
16
21
|
import { withHttpRetryMiddleware } from "./retry-middleware.js";
|
|
17
22
|
import { CallerTraceState, DirectTraceparent, endpointRoutes, instrumentClient } from "./trace.js";
|
|
18
|
-
/**
|
|
23
|
+
/**
|
|
24
|
+
* An operation's own priority, used when the caller set none: session controls provide
|
|
25
|
+
* `interactive`. Providing it never changes concurrent requests.
|
|
26
|
+
*/
|
|
19
27
|
export const CurrentRequestPriority = Context.Reference("@sealant/sdk/CurrentRequestPriority", { defaultValue: () => undefined });
|
|
28
|
+
/**
|
|
29
|
+
* A host that is not Effect resolves its priority at each dispatch (the Promise facade's
|
|
30
|
+
* `requestPriority`, read from its own request context). Read once, when the client is built.
|
|
31
|
+
*/
|
|
32
|
+
export const HostRequestPriority = Context.Reference("@sealant/sdk/HostRequestPriority", { defaultValue: () => undefined });
|
|
33
|
+
/**
|
|
34
|
+
* The priority header's value: the caller's `RequestPriority`, else the host's, else the
|
|
35
|
+
* operation's own, else `normal`.
|
|
36
|
+
*/
|
|
37
|
+
export const requestPriorityHeader = (caller, host, operation) => caller ?? (typeof host === "function" ? host() : host) ?? operation ?? "normal";
|
|
38
|
+
/**
|
|
39
|
+
* The headers every request carries: its priority, the caller's trace when no exporting tracer
|
|
40
|
+
* propagates it, and the API key. Read in the request's own fiber, so per-call references apply.
|
|
41
|
+
*/
|
|
42
|
+
export const authorize = (config, host) => Effect.fnUntraced(function* (request) {
|
|
43
|
+
const caller = yield* RequestPriority;
|
|
44
|
+
const operation = yield* CurrentRequestPriority;
|
|
45
|
+
const traceparent = yield* DirectTraceparent;
|
|
46
|
+
const tracestate = yield* CallerTraceState;
|
|
47
|
+
const headed = HttpClientRequest.setHeaders(request, {
|
|
48
|
+
"x-sealant-request-priority": requestPriorityHeader(caller, host, operation),
|
|
49
|
+
// Effect's own propagation is off whenever `DirectTraceparent` is set, so this header is the
|
|
50
|
+
// one that reaches the server.
|
|
51
|
+
...(traceparent === undefined ? {} : { traceparent }),
|
|
52
|
+
...(tracestate === undefined ? {} : { tracestate }),
|
|
53
|
+
});
|
|
54
|
+
return Option.match(config.apiKey, {
|
|
55
|
+
onNone: () => headed,
|
|
56
|
+
onSome: (key) => HttpClientRequest.bearerToken(headed, Redacted.value(key)),
|
|
57
|
+
});
|
|
58
|
+
});
|
|
20
59
|
const CONTROL_PLANE_ROUTES = endpointRoutes(ControlPlaneAPI);
|
|
21
|
-
|
|
22
|
-
const
|
|
23
|
-
|
|
60
|
+
const makeControlPlaneClient = Effect.gen(function* () {
|
|
61
|
+
const config = yield* SealantConfig;
|
|
62
|
+
const host = yield* HostRequestPriority;
|
|
63
|
+
const client = yield* HttpApiClient.make(ControlPlaneAPI, {
|
|
24
64
|
baseUrl: config.baseUrl,
|
|
25
|
-
transformClient: (
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
const prioritized = HttpClientRequest.setHeaders(request, {
|
|
30
|
-
"x-sealant-request-priority": resolveRequestPriority(config.requestPriority, priority),
|
|
31
|
-
// Effect's own propagation is off whenever `DirectTraceparent` is set, so this
|
|
32
|
-
// header is the one that reaches the server.
|
|
33
|
-
...(traceparent === undefined ? {} : { traceparent }),
|
|
34
|
-
...(tracestate === undefined ? {} : { tracestate }),
|
|
35
|
-
});
|
|
36
|
-
return config.apiKey === undefined
|
|
37
|
-
? prioritized
|
|
38
|
-
: HttpClientRequest.bearerToken(prioritized, config.apiKey);
|
|
39
|
-
}))),
|
|
40
|
-
}), (client) => instrumentClient(client, CONTROL_PLANE_ROUTES));
|
|
41
|
-
};
|
|
65
|
+
transformClient: (http) => withHttpRetryMiddleware(HttpClient.mapRequestEffect(http, authorize(config, host))),
|
|
66
|
+
});
|
|
67
|
+
return instrumentClient(client, CONTROL_PLANE_ROUTES);
|
|
68
|
+
});
|
|
42
69
|
export class SealantApiClient extends Context.Service()("@sealant/sdk/SealantApiClient") {
|
|
70
|
+
/** The client over the `HttpClient` the composition root provides. */
|
|
71
|
+
static layer = Layer.effect(SealantApiClient, makeControlPlaneClient);
|
|
43
72
|
}
|
|
73
|
+
/** `SealantConfig` from the Promise facade's resolved config. */
|
|
74
|
+
export const sealantConfigFrom = (config) => SealantConfig.layer({
|
|
75
|
+
baseUrl: config.baseUrl,
|
|
76
|
+
apiKey: config.apiKey === undefined ? undefined : Redacted.make(config.apiKey),
|
|
77
|
+
ownerUserId: config.hostLocal.ownerUserId,
|
|
78
|
+
registryId: config.hostLocal.registryId,
|
|
79
|
+
});
|
|
80
|
+
/** A fetch `HttpClient` over the configured `fetch`, else the global one. */
|
|
81
|
+
export const fetchHttpClientFrom = (config) => config.fetch === undefined
|
|
82
|
+
? FetchHttpClient.layer
|
|
83
|
+
: FetchHttpClient.layer.pipe(Layer.provide(Layer.succeed(FetchHttpClient.Fetch, config.fetch)));
|
|
44
84
|
/**
|
|
45
|
-
*
|
|
46
|
-
*
|
|
85
|
+
* The client over a fetch `HttpClient` (the configured `fetch`, else the global one), with an
|
|
86
|
+
* optional bearer token: the Promise facade's form. An Effect app provides `SealantApiClient.layer`
|
|
87
|
+
* its own `SealantConfig` and `HttpClient` instead.
|
|
47
88
|
*/
|
|
48
|
-
export const sealantApiClientLayer = (config) =>
|
|
49
|
-
|
|
50
|
-
|
|
89
|
+
export const sealantApiClientLayer = (config) => SealantApiClient.layer.pipe(Layer.provide([
|
|
90
|
+
sealantConfigFrom(config),
|
|
91
|
+
fetchHttpClientFrom(config),
|
|
92
|
+
Layer.succeed(HostRequestPriority, config.requestPriority),
|
|
93
|
+
]));
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where the control plane is and how to authenticate to it: the one value every SDK service
|
|
3
|
+
* reads. It is infrastructure configuration, so it is its own tag and the composition root picks
|
|
4
|
+
* how it is built: from values (`SealantConfig.layer`), from a `Config` recipe
|
|
5
|
+
* (`SealantConfig.layerConfig`), or from the environment (`SealantConfig.layerFromEnv`).
|
|
6
|
+
*
|
|
7
|
+
* Who a call acts for is not configuration: `ActingOwner` (see `context.ts`) carries it per fiber,
|
|
8
|
+
* and `ownerUserId` here is only the owner a call falls back to when none is set.
|
|
9
|
+
*/
|
|
10
|
+
import { Config, Context, Layer, Option, type Redacted } from "effect";
|
|
11
|
+
/** The owner a call acts for when neither `ActingOwner` nor `ownerUserId` names one. */
|
|
12
|
+
export declare const DEFAULT_OWNER_USER_ID = "usr_local";
|
|
13
|
+
/** The registry a workspace image is published to when none is configured. */
|
|
14
|
+
export declare const DEFAULT_REGISTRY_ID = "default";
|
|
15
|
+
/** What `SealantConfig.layer` takes. */
|
|
16
|
+
export interface SealantConfigOptions {
|
|
17
|
+
/** The control plane's base URL, e.g. `https://sealant.example.com`. */
|
|
18
|
+
readonly baseUrl: string;
|
|
19
|
+
/**
|
|
20
|
+
* A service key, which may act for any owner, or a scoped access token (session surface only).
|
|
21
|
+
* Absent for a local control plane with no auth.
|
|
22
|
+
*/
|
|
23
|
+
readonly apiKey?: Redacted.Redacted | undefined;
|
|
24
|
+
/** The owner a call acts for when `ActingOwner` is unset. Default `usr_local`. */
|
|
25
|
+
readonly ownerUserId?: string | undefined;
|
|
26
|
+
/** The registry a workspace image is published to. Default `default`. */
|
|
27
|
+
readonly registryId?: string | undefined;
|
|
28
|
+
}
|
|
29
|
+
export interface SealantConfigShape {
|
|
30
|
+
readonly baseUrl: string;
|
|
31
|
+
readonly apiKey: Option.Option<Redacted.Redacted>;
|
|
32
|
+
readonly ownerUserId: string;
|
|
33
|
+
readonly registryId: string;
|
|
34
|
+
}
|
|
35
|
+
declare const SealantConfig_base: Context.ServiceClass<SealantConfig, "@sealant/sdk/SealantConfig", SealantConfigShape>;
|
|
36
|
+
export declare class SealantConfig extends SealantConfig_base {
|
|
37
|
+
/** The config from values the caller already has. */
|
|
38
|
+
static readonly layer: (options: SealantConfigOptions) => Layer.Layer<SealantConfig>;
|
|
39
|
+
/** The config read through a `Config` recipe for each option. */
|
|
40
|
+
static readonly layerConfig: (config: Config.Wrap<SealantConfigOptions>) => Layer.Layer<SealantConfig, Config.ConfigError>;
|
|
41
|
+
/**
|
|
42
|
+
* The config from the environment: `SEALANT_BASE_URL` (required), `SEALANT_API_KEY`,
|
|
43
|
+
* `SEALANT_OWNER_USER_ID` and `SEALANT_REGISTRY_ID`, all optional.
|
|
44
|
+
*/
|
|
45
|
+
static readonly layerFromEnv: Layer.Layer<SealantConfig, Config.ConfigError>;
|
|
46
|
+
}
|
|
47
|
+
export {};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where the control plane is and how to authenticate to it: the one value every SDK service
|
|
3
|
+
* reads. It is infrastructure configuration, so it is its own tag and the composition root picks
|
|
4
|
+
* how it is built: from values (`SealantConfig.layer`), from a `Config` recipe
|
|
5
|
+
* (`SealantConfig.layerConfig`), or from the environment (`SealantConfig.layerFromEnv`).
|
|
6
|
+
*
|
|
7
|
+
* Who a call acts for is not configuration: `ActingOwner` (see `context.ts`) carries it per fiber,
|
|
8
|
+
* and `ownerUserId` here is only the owner a call falls back to when none is set.
|
|
9
|
+
*/
|
|
10
|
+
import { Config, Context, Effect, Layer, Option } from "effect";
|
|
11
|
+
/** The owner a call acts for when neither `ActingOwner` nor `ownerUserId` names one. */
|
|
12
|
+
export const DEFAULT_OWNER_USER_ID = "usr_local";
|
|
13
|
+
/** The registry a workspace image is published to when none is configured. */
|
|
14
|
+
export const DEFAULT_REGISTRY_ID = "default";
|
|
15
|
+
const resolve = (options) => ({
|
|
16
|
+
baseUrl: options.baseUrl,
|
|
17
|
+
apiKey: Option.fromUndefinedOr(options.apiKey),
|
|
18
|
+
ownerUserId: options.ownerUserId ?? DEFAULT_OWNER_USER_ID,
|
|
19
|
+
registryId: options.registryId ?? DEFAULT_REGISTRY_ID,
|
|
20
|
+
});
|
|
21
|
+
export class SealantConfig extends Context.Service()("@sealant/sdk/SealantConfig") {
|
|
22
|
+
/** The config from values the caller already has. */
|
|
23
|
+
static layer = (options) => Layer.succeed(SealantConfig, resolve(options));
|
|
24
|
+
/** The config read through a `Config` recipe for each option. */
|
|
25
|
+
static layerConfig = (config) => Layer.effect(SealantConfig, Effect.map(Config.unwrap(config), resolve));
|
|
26
|
+
/**
|
|
27
|
+
* The config from the environment: `SEALANT_BASE_URL` (required), `SEALANT_API_KEY`,
|
|
28
|
+
* `SEALANT_OWNER_USER_ID` and `SEALANT_REGISTRY_ID`, all optional.
|
|
29
|
+
*/
|
|
30
|
+
static layerFromEnv = SealantConfig.layerConfig({
|
|
31
|
+
baseUrl: Config.String("SEALANT_BASE_URL"),
|
|
32
|
+
apiKey: Config.Redacted("SEALANT_API_KEY").pipe(Config.option, Config.map(Option.getOrUndefined)),
|
|
33
|
+
ownerUserId: Config.String("SEALANT_OWNER_USER_ID").pipe(Config.option, Config.map(Option.getOrUndefined)),
|
|
34
|
+
registryId: Config.String("SEALANT_REGISTRY_ID").pipe(Config.option, Config.map(Option.getOrUndefined)),
|
|
35
|
+
});
|
|
36
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Per-fiber context every SDK call reads: who it acts for and how urgent it is. Both are
|
|
3
|
+
* `Context.Reference`s with a truthful default, so they add no requirement and one shared layer
|
|
4
|
+
* serves every caller:
|
|
5
|
+
*
|
|
6
|
+
* workspaces.get(id).pipe(Effect.provideService(ActingOwner, userId))
|
|
7
|
+
*
|
|
8
|
+
* scopes one call to one user, with no client per user. Forked fibers inherit both, so a scope set
|
|
9
|
+
* around a request handler reaches everything the handler starts.
|
|
10
|
+
*/
|
|
11
|
+
import { Context, Effect } from "effect";
|
|
12
|
+
import { SealantConfig } from "./config.js";
|
|
13
|
+
/**
|
|
14
|
+
* The user a call acts for. Unset (`undefined`), a call acts for `SealantConfig.ownerUserId`. A
|
|
15
|
+
* service key may act for any owner; a user's access token only for its own.
|
|
16
|
+
*/
|
|
17
|
+
export declare const ActingOwner: Context.Reference<string | undefined>;
|
|
18
|
+
/**
|
|
19
|
+
* How a request is queued at the control plane. `interactive` may use capacity the server keeps for
|
|
20
|
+
* a person waiting on the answer (a keystroke, a click); `normal` is everything else. Unset, the
|
|
21
|
+
* operation decides: session controls go `interactive`, everything else `normal`.
|
|
22
|
+
*/
|
|
23
|
+
export type RequestPriorityLevel = "normal" | "interactive";
|
|
24
|
+
/** The caller's priority for the requests a call makes (see {@link RequestPriorityLevel}). */
|
|
25
|
+
export declare const RequestPriority: Context.Reference<RequestPriorityLevel | undefined>;
|
|
26
|
+
/** The owner the current fiber acts for: `ActingOwner`, else the configured owner. */
|
|
27
|
+
export declare const currentOwner: Effect.Effect<string, never, SealantConfig>;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Per-fiber context every SDK call reads: who it acts for and how urgent it is. Both are
|
|
3
|
+
* `Context.Reference`s with a truthful default, so they add no requirement and one shared layer
|
|
4
|
+
* serves every caller:
|
|
5
|
+
*
|
|
6
|
+
* workspaces.get(id).pipe(Effect.provideService(ActingOwner, userId))
|
|
7
|
+
*
|
|
8
|
+
* scopes one call to one user, with no client per user. Forked fibers inherit both, so a scope set
|
|
9
|
+
* around a request handler reaches everything the handler starts.
|
|
10
|
+
*/
|
|
11
|
+
import { Context, Effect } from "effect";
|
|
12
|
+
import { SealantConfig } from "./config.js";
|
|
13
|
+
/**
|
|
14
|
+
* The user a call acts for. Unset (`undefined`), a call acts for `SealantConfig.ownerUserId`. A
|
|
15
|
+
* service key may act for any owner; a user's access token only for its own.
|
|
16
|
+
*/
|
|
17
|
+
export const ActingOwner = Context.Reference("@sealant/sdk/ActingOwner", {
|
|
18
|
+
defaultValue: () => undefined,
|
|
19
|
+
});
|
|
20
|
+
/** The caller's priority for the requests a call makes (see {@link RequestPriorityLevel}). */
|
|
21
|
+
export const RequestPriority = Context.Reference("@sealant/sdk/RequestPriority", { defaultValue: () => undefined });
|
|
22
|
+
/** The owner the current fiber acts for: `ActingOwner`, else the configured owner. */
|
|
23
|
+
export const currentOwner = Effect.gen(function* () {
|
|
24
|
+
const acting = yield* ActingOwner;
|
|
25
|
+
if (acting !== undefined)
|
|
26
|
+
return acting;
|
|
27
|
+
const config = yield* SealantConfig;
|
|
28
|
+
return config.ownerUserId;
|
|
29
|
+
});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The error a contract endpoint's call fails with, read off the derived client's own type: every
|
|
3
|
+
* error the contract declares for it (the endpoint's, the admission middleware's), with transport
|
|
4
|
+
* and decode failures as `SealantTransportError`. A service method's error type is its endpoint's,
|
|
5
|
+
* so a change to the contract moves it.
|
|
6
|
+
*/
|
|
7
|
+
import type { Effect } from "effect";
|
|
8
|
+
import type { ControlPlaneClient } from "./api-client.js";
|
|
9
|
+
import type { Transported } from "./errors.js";
|
|
10
|
+
export type EndpointError<Group extends keyof ControlPlaneClient, Name extends keyof ControlPlaneClient[Group]> = ControlPlaneClient[Group][Name] extends (...args: never) => Effect.Effect<unknown, infer E, unknown> ? Transported<E> : never;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The errors the Effect SDK's own services fail with, beside the contract's (`WorkspaceNotFoundError`,
|
|
3
|
+
* `SessionConflictError`, …), which reach callers unchanged. Every one is a `Schema.TaggedError`, so
|
|
4
|
+
* `Effect.catchTag` reaches it and nothing needs a status code or a message to tell them apart.
|
|
5
|
+
*
|
|
6
|
+
* - `SealantTransportError`: a request that never got an answer the contract describes: the
|
|
7
|
+
* connection failed, or the answer did not decode.
|
|
8
|
+
* - `SealantStreamRefusedError`: a streaming endpoint (events, session output) refused the request
|
|
9
|
+
* with a status a retry cannot change (401, 403, 404, …).
|
|
10
|
+
* - `SealantWaitTimeoutError`: a wait the caller bounded ran out.
|
|
11
|
+
* - `WorkspaceSettledError`: a workspace being waited on settled where the wait cannot end.
|
|
12
|
+
* - `SessionAttachError`: the attach socket could not be opened, or kept being cut.
|
|
13
|
+
* - `SessionEndedError`: input for a session that has ended.
|
|
14
|
+
*/
|
|
15
|
+
import { Effect, Schema } from "effect";
|
|
16
|
+
import { HttpClientError } from "effect/http";
|
|
17
|
+
declare const SealantTransportError_base: Schema.Class<SealantTransportError, Schema.TaggedStruct<"SealantTransportError", {
|
|
18
|
+
/** The SDK operation, e.g. `Workspaces.get`. */
|
|
19
|
+
readonly operation: Schema.String;
|
|
20
|
+
readonly message: Schema.String;
|
|
21
|
+
/** The response's status, when there was a response. */
|
|
22
|
+
readonly status: Schema.optional<Schema.Number>;
|
|
23
|
+
readonly cause: Schema.Defect;
|
|
24
|
+
}>, import("effect/Cause").YieldableError>;
|
|
25
|
+
/** A request that got no answer the contract describes: the transport failed or the body did not decode. */
|
|
26
|
+
export declare class SealantTransportError extends SealantTransportError_base {
|
|
27
|
+
/** A transport failure or a 5xx may succeed when asked again; a body that did not decode will not. */
|
|
28
|
+
get isRetryable(): boolean;
|
|
29
|
+
}
|
|
30
|
+
declare const SealantStreamRefusedError_base: Schema.Class<SealantStreamRefusedError, Schema.TaggedStruct<"SealantStreamRefusedError", {
|
|
31
|
+
/** The stream, e.g. `GET /v1/events`. */
|
|
32
|
+
readonly stream: Schema.String;
|
|
33
|
+
readonly status: Schema.Number;
|
|
34
|
+
readonly message: Schema.String;
|
|
35
|
+
}>, import("effect/Cause").YieldableError>;
|
|
36
|
+
/** A streaming endpoint refused the request with a status asking again would not change. */
|
|
37
|
+
export declare class SealantStreamRefusedError extends SealantStreamRefusedError_base {
|
|
38
|
+
}
|
|
39
|
+
declare const SealantWaitTimeoutError_base: Schema.Class<SealantWaitTimeoutError, Schema.TaggedStruct<"SealantWaitTimeoutError", {
|
|
40
|
+
/** The wait, e.g. `Runs.wait`. */
|
|
41
|
+
readonly operation: Schema.String;
|
|
42
|
+
/** Stable: `workspace_ready_timeout`, `workspace_image_build_stalled`, `run_wait_timeout`, … */
|
|
43
|
+
readonly code: Schema.String;
|
|
44
|
+
readonly message: Schema.String;
|
|
45
|
+
/** The bound the caller set, when the wait ran out of one the caller set. */
|
|
46
|
+
readonly timeoutMs: Schema.optional<Schema.Number>;
|
|
47
|
+
}>, import("effect/Cause").YieldableError>;
|
|
48
|
+
/** A wait the caller bounded ran out before what it waited for happened. */
|
|
49
|
+
export declare class SealantWaitTimeoutError extends SealantWaitTimeoutError_base {
|
|
50
|
+
}
|
|
51
|
+
declare const WorkspaceSettledError_base: Schema.Class<WorkspaceSettledError, Schema.TaggedStruct<"WorkspaceSettledError", {
|
|
52
|
+
readonly workspaceId: Schema.String;
|
|
53
|
+
readonly status: Schema.Literals<readonly ["queued", "running", "ready", "failed", "cancelled", "stopped", "retained"]>;
|
|
54
|
+
readonly message: Schema.String;
|
|
55
|
+
/** The control plane's account of the failure (its `code`, and Boat's own, when Boat refused). */
|
|
56
|
+
readonly error: Schema.optional<Schema.Struct<{
|
|
57
|
+
readonly message: Schema.String;
|
|
58
|
+
readonly code: Schema.optional<Schema.String>;
|
|
59
|
+
readonly boat: Schema.optional<Schema.Struct<{
|
|
60
|
+
readonly kind: Schema.Literals<readonly ["key-refused", "key-expired", "permission-missing", "sandbox-outside-key", "organization-mismatch", "account-suspended", "billing-required", "running-limit", "member-cap", "rate-limited", "trial-restricted", "no-machine", "snapshot-allowance-full", "no-answer", "refused"]>;
|
|
61
|
+
readonly retryable: Schema.Boolean;
|
|
62
|
+
readonly operation: Schema.optional<Schema.String>;
|
|
63
|
+
readonly code: Schema.optional<Schema.String>;
|
|
64
|
+
readonly message: Schema.optional<Schema.String>;
|
|
65
|
+
readonly requestId: Schema.optional<Schema.String>;
|
|
66
|
+
readonly status: Schema.optional<Schema.Int>;
|
|
67
|
+
readonly permission: Schema.optional<Schema.String>;
|
|
68
|
+
readonly retryAfterSeconds: Schema.optional<Schema.Int>;
|
|
69
|
+
readonly retryAt: Schema.optional<Schema.String>;
|
|
70
|
+
readonly billingUrl: Schema.optional<Schema.String>;
|
|
71
|
+
}>>;
|
|
72
|
+
}>>;
|
|
73
|
+
}>, import("effect/Cause").YieldableError>;
|
|
74
|
+
/**
|
|
75
|
+
* A workspace being waited on settled where the wait cannot end: `waitReady` saw it fail, stop or
|
|
76
|
+
* be cancelled before it was ready. `error` is the control plane's own account, when it gave one.
|
|
77
|
+
*/
|
|
78
|
+
export declare class WorkspaceSettledError extends WorkspaceSettledError_base {
|
|
79
|
+
}
|
|
80
|
+
declare const SessionAttachError_base: Schema.Class<SessionAttachError, Schema.TaggedStruct<"SessionAttachError", {
|
|
81
|
+
readonly sessionId: Schema.String;
|
|
82
|
+
readonly message: Schema.String;
|
|
83
|
+
/** The last close code, when the socket closed rather than failed to open. */
|
|
84
|
+
readonly closeCode: Schema.optional<Schema.Number>;
|
|
85
|
+
readonly cause: Schema.optional<Schema.Defect>;
|
|
86
|
+
}>, import("effect/Cause").YieldableError>;
|
|
87
|
+
/** The attach socket could not be opened, or was cut more times in a row than the backoff allows. */
|
|
88
|
+
export declare class SessionAttachError extends SessionAttachError_base {
|
|
89
|
+
}
|
|
90
|
+
declare const SessionEndedError_base: Schema.Class<SessionEndedError, Schema.TaggedStruct<"SessionEndedError", {
|
|
91
|
+
readonly sessionId: Schema.String;
|
|
92
|
+
readonly ended: Schema.Struct<{
|
|
93
|
+
readonly status: Schema.Literals<readonly ["exited", "failed"]>;
|
|
94
|
+
readonly exitCode: Schema.optional<Schema.Int>;
|
|
95
|
+
readonly exitSignal: Schema.optional<Schema.Int>;
|
|
96
|
+
}>;
|
|
97
|
+
}>, import("effect/Cause").YieldableError>;
|
|
98
|
+
/** Input, a resize or a signal for a session that has already ended. */
|
|
99
|
+
export declare class SessionEndedError extends SessionEndedError_base {
|
|
100
|
+
get message(): string;
|
|
101
|
+
}
|
|
102
|
+
/** Every error the SDK's own services add to the contract's. */
|
|
103
|
+
export type SealantSdkError = SealantTransportError | SealantStreamRefusedError | SealantWaitTimeoutError | WorkspaceSettledError | SessionAttachError | SessionEndedError;
|
|
104
|
+
/** The two failures the contract does not describe: a failed transport, an answer that did not decode. */
|
|
105
|
+
type TransportFailure = HttpClientError.HttpClientError | Schema.SchemaError;
|
|
106
|
+
/** `E` with its transport failures as {@link SealantTransportError}. */
|
|
107
|
+
export type Transported<E> = Exclude<E, TransportFailure> | SealantTransportError;
|
|
108
|
+
/**
|
|
109
|
+
* Names `effect`'s transport and decode failures as `operation`'s `SealantTransportError`, leaving
|
|
110
|
+
* every contract error as it is, so a caller matches either with `Effect.catchTag`.
|
|
111
|
+
*/
|
|
112
|
+
export declare const transported: (operation: string) => <A, E, R>(effect: Effect.Effect<A, E, R>) => Effect.Effect<A, Transported<E>, R>;
|
|
113
|
+
export {};
|