@sealant/sdk-next 0.40.0-next.777 → 0.40.0-next.783

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.
@@ -4,7 +4,7 @@
4
4
  * maps the typed Effect failure -> a plain `SealantError`. Keeping these here (rather than inline in
5
5
  * the facade) keeps the wire surface in one place and unit-testable.
6
6
  */
7
- import type { ApplyWorkspaceDotfilesRequest, BindWorkspaceRequest, CancelWorkspaceCreateRequest, FlushWorkspaceCaptureRequest, GetWorkspaceCaptureStatusQuery, CloseSessionRequest, CreateAccessTokenRequest, ConnectedAccountProvider, CreateConnectedAccountRequest, CreateSshKeyRequest, EnsureUserRequest, PersonBindingWire, CreateRunRequest, CreateSessionAsUserRequest, CreateSessionRequest, CreateWorkspaceRequest, ExecWorkspaceAsUserRequest, ExecWorkspaceRequest, ExpireWorkspaceRequest, ClearWorkspaceSshUserQuery, GetRunScrollbackQuery, GetRunTimelineQuery, GetSessionOutputQuery, InferenceRespondRequest, ListResourceDomainMembersQuery, ResourceDomainBudgetLimits, SetResourceDomainBudgetRequest, ListRunsQuery, ListSessionsQuery, ListWorkspacesQuery, MarkConnectedAccountInvalidRequest, ReplanWorkspaceCaptureRequest, RecoverWorkspaceRequest, RestartWorkspaceRequest, SessionInputRequest, InspectWorkspaceImageRequest, PutWorkspaceCredentialsRequest, ResourceDomainMemberDecisionRequest, PruneWorkspaceCredentialsRequest, ReleaseWorkspaceCredentialsQuery, ListWorkspaceCredentialsQuery, SessionResizeRequest, SessionSignalRequest, SetConnectedAccountDefaultRequest, StopWorkspaceRequest, UpdateRunRequest } from "@sealant/api-contracts";
7
+ import type { ApplyWorkspaceDotfilesRequest, BindWorkspaceRequest, CancelWorkspaceCreateRequest, FlushWorkspaceCaptureRequest, GetWorkspaceCaptureStatusQuery, CloseSessionRequest, CreateAccessTokenRequest, ConnectedAccountProvider, CreateConnectedAccountRequest, CreateSshKeyRequest, EnsureUserRequest, PersonBindingWire, CreateRunRequest, CreateSessionAsUserRequest, CreateSessionRequest, CreateWorkspaceRequest, ExecWorkspaceAsUserRequest, ExecWorkspaceRequest, ExpireWorkspaceRequest, ClearWorkspaceSshUserQuery, GetRunScrollbackQuery, GetRunTimelineQuery, GetSessionOutputQuery, InferenceRespondRequest, ListResourceDomainMembersQuery, ResourceDomainBudgetLimits, SetResourceDomainBudgetRequest, ListRunsQuery, ListSessionsQuery, ListWorkspacesQuery, MarkConnectedAccountInvalidRequest, ReplanWorkspaceCaptureRequest, RecoverWorkspaceRequest, RestartWorkspaceRequest, SessionInputRequest, InspectWorkspaceImageRequest, PutWorkspaceCredentialsRequest, ResourceDomainMemberDecisionRequest, PruneWorkspaceCredentialsRequest, ReleaseWorkspaceCredentialsQuery, ListWorkspaceCredentialsQuery, SessionResizeRequest, SessionSignalRequest, SetConnectedAccountDefaultRequest, StopWorkspaceRequest, UpdateRunRequest, UpResourceInstanceRequest } from "@sealant/api-contracts";
8
8
  import { Effect } from "effect";
9
9
  import { SealantApiClient } from "./api-client.js";
10
10
  export declare const createWorkspaceOp: (payload: CreateWorkspaceRequest, idempotencyKey?: string) => Effect.Effect<{
@@ -1220,3 +1220,276 @@ export declare const setResourceDomainBudgetOp: (resourceDomainId: string, paylo
1220
1220
  readonly warning: "80-percent" | "95-percent" | "full" | "none";
1221
1221
  };
1222
1222
  }, import("effect/http/HttpClientError").HttpClientError | import("@sealant/api-contracts").RequestRefusedError | import("@sealant/api-contracts").ResourceDomainBudgetRevisionConflictError | import("@sealant/api-contracts").ResourceDomainForbiddenError | import("@sealant/api-contracts").ResourceDomainInternalServerError | import("@sealant/api-contracts").ResourceDomainNotFoundError | import("effect/Schema").SchemaError, SealantApiClient>;
1223
+ export declare const upResourceInstanceOp: (resourceDomainId: string, key: string, payload: UpResourceInstanceRequest) => Effect.Effect<{
1224
+ readonly resourceInstanceId: string & import("effect/Brand").Brand<"ResourceInstanceId">;
1225
+ readonly key: string & import("effect/Brand").Brand<"ResourceInstanceKey">;
1226
+ readonly alias: string & import("effect/Brand").Brand<"ResourceInstanceAlias">;
1227
+ readonly worktreeKey: (string & import("effect/Brand").Brand<"ResourceWorktreeKey">) | null;
1228
+ readonly specDigest: string;
1229
+ readonly desired: "archived" | "running" | "stopped";
1230
+ readonly stopReason: {
1231
+ readonly kind: "idle";
1232
+ } | {
1233
+ readonly kind: "person";
1234
+ readonly by: string;
1235
+ } | null;
1236
+ readonly state: {
1237
+ readonly kind: "not-started";
1238
+ } | {
1239
+ readonly kind: "starting";
1240
+ readonly since: string;
1241
+ } | {
1242
+ readonly kind: "running";
1243
+ readonly since: string;
1244
+ } | {
1245
+ readonly kind: "stopped";
1246
+ readonly at: string;
1247
+ readonly reason: {
1248
+ readonly kind: "idle";
1249
+ } | {
1250
+ readonly kind: "person";
1251
+ readonly by: string;
1252
+ };
1253
+ } | {
1254
+ readonly kind: "exited";
1255
+ readonly at: string;
1256
+ readonly exitCode: number | null;
1257
+ } | {
1258
+ readonly kind: "failed";
1259
+ readonly at: string;
1260
+ readonly message: string;
1261
+ } | {
1262
+ readonly kind: "archived";
1263
+ readonly at: string;
1264
+ };
1265
+ readonly observedAt: string;
1266
+ readonly startedAt: string | null;
1267
+ readonly lastReachedAt: string | null;
1268
+ readonly volumes: readonly {
1269
+ readonly name: string;
1270
+ readonly dockerName: string;
1271
+ }[];
1272
+ }, import("effect/http/HttpClientError").HttpClientError | import("@sealant/api-contracts").RequestRefusedError | import("@sealant/api-contracts").ResourceDomainForbiddenError | import("@sealant/api-contracts").ResourceDomainInternalServerError | import("@sealant/api-contracts").ResourceDomainNotActiveError | import("@sealant/api-contracts").ResourceDomainNotFoundError | import("@sealant/api-contracts").ResourceInstanceAliasTakenError | import("@sealant/api-contracts").ResourceInstanceArchivedError | import("@sealant/api-contracts").ResourceInstanceSpecRefusedError | import("@sealant/api-contracts").ResourceRuntimeUnsupportedError | import("effect/Schema").SchemaError | import("effect/Cause").UnknownError, SealantApiClient>;
1273
+ export declare const getResourceInstanceOp: (resourceDomainId: string, key: string) => Effect.Effect<{
1274
+ readonly resourceInstanceId: string & import("effect/Brand").Brand<"ResourceInstanceId">;
1275
+ readonly key: string & import("effect/Brand").Brand<"ResourceInstanceKey">;
1276
+ readonly alias: string & import("effect/Brand").Brand<"ResourceInstanceAlias">;
1277
+ readonly worktreeKey: (string & import("effect/Brand").Brand<"ResourceWorktreeKey">) | null;
1278
+ readonly specDigest: string;
1279
+ readonly desired: "archived" | "running" | "stopped";
1280
+ readonly stopReason: {
1281
+ readonly kind: "idle";
1282
+ } | {
1283
+ readonly kind: "person";
1284
+ readonly by: string;
1285
+ } | null;
1286
+ readonly state: {
1287
+ readonly kind: "not-started";
1288
+ } | {
1289
+ readonly kind: "starting";
1290
+ readonly since: string;
1291
+ } | {
1292
+ readonly kind: "running";
1293
+ readonly since: string;
1294
+ } | {
1295
+ readonly kind: "stopped";
1296
+ readonly at: string;
1297
+ readonly reason: {
1298
+ readonly kind: "idle";
1299
+ } | {
1300
+ readonly kind: "person";
1301
+ readonly by: string;
1302
+ };
1303
+ } | {
1304
+ readonly kind: "exited";
1305
+ readonly at: string;
1306
+ readonly exitCode: number | null;
1307
+ } | {
1308
+ readonly kind: "failed";
1309
+ readonly at: string;
1310
+ readonly message: string;
1311
+ } | {
1312
+ readonly kind: "archived";
1313
+ readonly at: string;
1314
+ };
1315
+ readonly observedAt: string;
1316
+ readonly startedAt: string | null;
1317
+ readonly lastReachedAt: string | null;
1318
+ readonly volumes: readonly {
1319
+ readonly name: string;
1320
+ readonly dockerName: string;
1321
+ }[];
1322
+ }, import("effect/http/HttpClientError").HttpClientError | import("@sealant/api-contracts").RequestRefusedError | import("@sealant/api-contracts").ResourceDomainForbiddenError | import("@sealant/api-contracts").ResourceDomainInternalServerError | import("@sealant/api-contracts").ResourceDomainNotFoundError | import("@sealant/api-contracts").ResourceInstanceNotFoundError | import("effect/Schema").SchemaError | import("effect/Cause").UnknownError, SealantApiClient>;
1323
+ export declare const listResourceInstancesOp: (resourceDomainId: string, archived: boolean) => Effect.Effect<{
1324
+ readonly items: readonly {
1325
+ readonly resourceInstanceId: string & import("effect/Brand").Brand<"ResourceInstanceId">;
1326
+ readonly key: string & import("effect/Brand").Brand<"ResourceInstanceKey">;
1327
+ readonly alias: string & import("effect/Brand").Brand<"ResourceInstanceAlias">;
1328
+ readonly worktreeKey: (string & import("effect/Brand").Brand<"ResourceWorktreeKey">) | null;
1329
+ readonly specDigest: string;
1330
+ readonly desired: "archived" | "running" | "stopped";
1331
+ readonly stopReason: {
1332
+ readonly kind: "idle";
1333
+ } | {
1334
+ readonly kind: "person";
1335
+ readonly by: string;
1336
+ } | null;
1337
+ readonly state: {
1338
+ readonly kind: "not-started";
1339
+ } | {
1340
+ readonly kind: "starting";
1341
+ readonly since: string;
1342
+ } | {
1343
+ readonly kind: "running";
1344
+ readonly since: string;
1345
+ } | {
1346
+ readonly kind: "stopped";
1347
+ readonly at: string;
1348
+ readonly reason: {
1349
+ readonly kind: "idle";
1350
+ } | {
1351
+ readonly kind: "person";
1352
+ readonly by: string;
1353
+ };
1354
+ } | {
1355
+ readonly kind: "exited";
1356
+ readonly at: string;
1357
+ readonly exitCode: number | null;
1358
+ } | {
1359
+ readonly kind: "failed";
1360
+ readonly at: string;
1361
+ readonly message: string;
1362
+ } | {
1363
+ readonly kind: "archived";
1364
+ readonly at: string;
1365
+ };
1366
+ readonly observedAt: string;
1367
+ readonly startedAt: string | null;
1368
+ readonly lastReachedAt: string | null;
1369
+ readonly volumes: readonly {
1370
+ readonly name: string;
1371
+ readonly dockerName: string;
1372
+ }[];
1373
+ }[];
1374
+ }, import("effect/http/HttpClientError").HttpClientError | import("@sealant/api-contracts").RequestRefusedError | import("@sealant/api-contracts").ResourceDomainForbiddenError | import("@sealant/api-contracts").ResourceDomainInternalServerError | import("@sealant/api-contracts").ResourceDomainNotFoundError | import("effect/Schema").SchemaError, SealantApiClient>;
1375
+ export declare const stopResourceInstanceOp: (resourceDomainId: string, key: string, by: string) => Effect.Effect<{
1376
+ readonly resourceInstanceId: string & import("effect/Brand").Brand<"ResourceInstanceId">;
1377
+ readonly key: string & import("effect/Brand").Brand<"ResourceInstanceKey">;
1378
+ readonly alias: string & import("effect/Brand").Brand<"ResourceInstanceAlias">;
1379
+ readonly worktreeKey: (string & import("effect/Brand").Brand<"ResourceWorktreeKey">) | null;
1380
+ readonly specDigest: string;
1381
+ readonly desired: "archived" | "running" | "stopped";
1382
+ readonly stopReason: {
1383
+ readonly kind: "idle";
1384
+ } | {
1385
+ readonly kind: "person";
1386
+ readonly by: string;
1387
+ } | null;
1388
+ readonly state: {
1389
+ readonly kind: "not-started";
1390
+ } | {
1391
+ readonly kind: "starting";
1392
+ readonly since: string;
1393
+ } | {
1394
+ readonly kind: "running";
1395
+ readonly since: string;
1396
+ } | {
1397
+ readonly kind: "stopped";
1398
+ readonly at: string;
1399
+ readonly reason: {
1400
+ readonly kind: "idle";
1401
+ } | {
1402
+ readonly kind: "person";
1403
+ readonly by: string;
1404
+ };
1405
+ } | {
1406
+ readonly kind: "exited";
1407
+ readonly at: string;
1408
+ readonly exitCode: number | null;
1409
+ } | {
1410
+ readonly kind: "failed";
1411
+ readonly at: string;
1412
+ readonly message: string;
1413
+ } | {
1414
+ readonly kind: "archived";
1415
+ readonly at: string;
1416
+ };
1417
+ readonly observedAt: string;
1418
+ readonly startedAt: string | null;
1419
+ readonly lastReachedAt: string | null;
1420
+ readonly volumes: readonly {
1421
+ readonly name: string;
1422
+ readonly dockerName: string;
1423
+ }[];
1424
+ }, import("effect/http/HttpClientError").HttpClientError | import("@sealant/api-contracts").RequestRefusedError | import("@sealant/api-contracts").ResourceDomainForbiddenError | import("@sealant/api-contracts").ResourceDomainInternalServerError | import("@sealant/api-contracts").ResourceDomainNotFoundError | import("@sealant/api-contracts").ResourceInstanceArchivedError | import("@sealant/api-contracts").ResourceInstanceNotFoundError | import("@sealant/api-contracts").ResourceRuntimeUnsupportedError | import("effect/Schema").SchemaError | import("effect/Cause").UnknownError, SealantApiClient>;
1425
+ export declare const archiveResourceInstanceOp: (resourceDomainId: string, key: string) => Effect.Effect<{
1426
+ readonly instance: {
1427
+ readonly resourceInstanceId: string & import("effect/Brand").Brand<"ResourceInstanceId">;
1428
+ readonly key: string & import("effect/Brand").Brand<"ResourceInstanceKey">;
1429
+ readonly alias: string & import("effect/Brand").Brand<"ResourceInstanceAlias">;
1430
+ readonly worktreeKey: (string & import("effect/Brand").Brand<"ResourceWorktreeKey">) | null;
1431
+ readonly specDigest: string;
1432
+ readonly desired: "archived" | "running" | "stopped";
1433
+ readonly stopReason: {
1434
+ readonly kind: "idle";
1435
+ } | {
1436
+ readonly kind: "person";
1437
+ readonly by: string;
1438
+ } | null;
1439
+ readonly state: {
1440
+ readonly kind: "not-started";
1441
+ } | {
1442
+ readonly kind: "starting";
1443
+ readonly since: string;
1444
+ } | {
1445
+ readonly kind: "running";
1446
+ readonly since: string;
1447
+ } | {
1448
+ readonly kind: "stopped";
1449
+ readonly at: string;
1450
+ readonly reason: {
1451
+ readonly kind: "idle";
1452
+ } | {
1453
+ readonly kind: "person";
1454
+ readonly by: string;
1455
+ };
1456
+ } | {
1457
+ readonly kind: "exited";
1458
+ readonly at: string;
1459
+ readonly exitCode: number | null;
1460
+ } | {
1461
+ readonly kind: "failed";
1462
+ readonly at: string;
1463
+ readonly message: string;
1464
+ } | {
1465
+ readonly kind: "archived";
1466
+ readonly at: string;
1467
+ };
1468
+ readonly observedAt: string;
1469
+ readonly startedAt: string | null;
1470
+ readonly lastReachedAt: string | null;
1471
+ readonly volumes: readonly {
1472
+ readonly name: string;
1473
+ readonly dockerName: string;
1474
+ }[];
1475
+ };
1476
+ readonly volumes: readonly {
1477
+ readonly instanceKey: string & import("effect/Brand").Brand<"ResourceInstanceKey">;
1478
+ readonly name: string;
1479
+ readonly dockerName: string;
1480
+ readonly bytes: number | null;
1481
+ }[];
1482
+ }, import("effect/http/HttpClientError").HttpClientError | import("@sealant/api-contracts").RequestRefusedError | import("@sealant/api-contracts").ResourceDomainForbiddenError | import("@sealant/api-contracts").ResourceDomainInternalServerError | import("@sealant/api-contracts").ResourceDomainNotFoundError | import("@sealant/api-contracts").ResourceInstanceNotFoundError | import("@sealant/api-contracts").ResourceRuntimeUnsupportedError | import("effect/Schema").SchemaError | import("effect/Cause").UnknownError, SealantApiClient>;
1483
+ export declare const linkResourceWorkspaceOp: (resourceDomainId: string, workspaceId: string, worktreeKey: string) => Effect.Effect<{
1484
+ readonly workspaceId: string;
1485
+ readonly worktreeKey: string & import("effect/Brand").Brand<"ResourceWorktreeKey">;
1486
+ readonly attachedExecutors: number;
1487
+ }, import("effect/http/HttpClientError").HttpClientError | import("@sealant/api-contracts").RequestRefusedError | import("@sealant/api-contracts").ResourceDomainForbiddenError | import("@sealant/api-contracts").ResourceDomainInternalServerError | import("@sealant/api-contracts").ResourceDomainNotActiveError | import("@sealant/api-contracts").ResourceDomainNotFoundError | import("@sealant/api-contracts").ResourceRuntimeUnsupportedError | import("@sealant/api-contracts").ResourceWorkspaceLinkedElsewhereError | import("@sealant/api-contracts").ResourceWorkspaceNotFoundError | import("effect/Schema").SchemaError | import("effect/Cause").UnknownError, SealantApiClient>;
1488
+ export declare const archiveResourceDomainOp: (resourceDomainId: string) => Effect.Effect<{
1489
+ readonly volumes: readonly {
1490
+ readonly instanceKey: string & import("effect/Brand").Brand<"ResourceInstanceKey">;
1491
+ readonly name: string;
1492
+ readonly dockerName: string;
1493
+ readonly bytes: number | null;
1494
+ }[];
1495
+ }, import("effect/http/HttpClientError").HttpClientError | import("@sealant/api-contracts").RequestRefusedError | import("@sealant/api-contracts").ResourceDomainForbiddenError | import("@sealant/api-contracts").ResourceDomainInternalServerError | import("@sealant/api-contracts").ResourceDomainNotFoundError | import("@sealant/api-contracts").ResourceRuntimeUnsupportedError | import("effect/Schema").SchemaError, SealantApiClient>;
@@ -1,3 +1,4 @@
1
+ import { ResourceInstanceKey, ResourceWorktreeKey } from "@sealant/api-contracts";
1
2
  import { Effect } from "effect";
2
3
  import { SealantApiClient } from "./api-client.js";
3
4
  // ---- workspaces ----
@@ -103,3 +104,27 @@ export const getResourceDomainMemberOp = (resourceDomainId, userId) => Effect.fl
103
104
  export const listResourceDomainMembersOp = (resourceDomainId, query) => Effect.flatMap(SealantApiClient, (client) => client.resourceDomains.listResourceDomainMembers({ params: { resourceDomainId }, query }));
104
105
  export const getResourceDomainBudgetOp = (resourceDomainId) => Effect.flatMap(SealantApiClient, (client) => client.resourceDomains.getResourceDomainBudget({ params: { resourceDomainId } }));
105
106
  export const setResourceDomainBudgetOp = (resourceDomainId, payload) => Effect.flatMap(SealantApiClient, (client) => client.resourceDomains.setResourceDomainBudget({ params: { resourceDomainId }, payload }));
107
+ // ---- resource instances (a scope's `instances`, `workspaces` and `archive`) ----
108
+ /** The key, checked as the contract checks it; an invalid one fails before any request. */
109
+ const instanceKey = (key) => Effect.try(() => ResourceInstanceKey.make(key));
110
+ export const upResourceInstanceOp = (resourceDomainId, key, payload) => Effect.flatMap(Effect.all([SealantApiClient, instanceKey(key)]), ([client, checked]) => client.resourceInstances.upResourceInstance({
111
+ params: { resourceDomainId, key: checked },
112
+ payload,
113
+ }));
114
+ export const getResourceInstanceOp = (resourceDomainId, key) => Effect.flatMap(Effect.all([SealantApiClient, instanceKey(key)]), ([client, checked]) => client.resourceInstances.getResourceInstance({ params: { resourceDomainId, key: checked } }));
115
+ export const listResourceInstancesOp = (resourceDomainId, archived) => Effect.flatMap(SealantApiClient, (client) => client.resourceInstances.listResourceInstances({
116
+ params: { resourceDomainId },
117
+ query: { archived: archived ? "true" : "false" },
118
+ }));
119
+ export const stopResourceInstanceOp = (resourceDomainId, key, by) => Effect.flatMap(Effect.all([SealantApiClient, instanceKey(key)]), ([client, checked]) => client.resourceInstances.stopResourceInstance({
120
+ params: { resourceDomainId, key: checked },
121
+ payload: { by },
122
+ }));
123
+ export const archiveResourceInstanceOp = (resourceDomainId, key) => Effect.flatMap(Effect.all([SealantApiClient, instanceKey(key)]), ([client, checked]) => client.resourceInstances.archiveResourceInstance({
124
+ params: { resourceDomainId, key: checked },
125
+ }));
126
+ export const linkResourceWorkspaceOp = (resourceDomainId, workspaceId, worktreeKey) => Effect.flatMap(Effect.all([SealantApiClient, Effect.try(() => ResourceWorktreeKey.make(worktreeKey))]), ([client, checked]) => client.resourceInstances.linkResourceWorkspace({
127
+ params: { resourceDomainId, workspaceId },
128
+ payload: { worktreeKey: checked },
129
+ }));
130
+ export const archiveResourceDomainOp = (resourceDomainId) => Effect.flatMap(SealantApiClient, (client) => client.resourceInstances.archiveResourceDomain({ params: { resourceDomainId } }));
package/dist/index.d.ts CHANGED
@@ -19,5 +19,6 @@ export { claudeCode, codex, customHarness, opencode, pi } from "./harness.js";
19
19
  export { ForwardDialError, type ForwardDialFailure, type ForwardDialReason, ForwardResetError, SealantApiError, SealantError, SealantNotImplementedError, SealantRuntimeError, } from "./errors.js";
20
20
  export type * from "./types.js";
21
21
  export type { EnsuredScope, ScopeBudget, ScopeBudgetDimension, ScopeBudgetLimits, ScopeBudgets, ScopeClient, ScopeInfo, ScopeMember, ScopeMemberDecision, ScopeMemberPage, ScopeMembers, ScopesNamespace, } from "./scopes.js";
22
+ export type { ScopeArchivedVolume, ScopeExecResult, ScopeInstance, ScopeInstances, ScopeInstanceSpec, ScopeInstanceState, ScopeInstanceStopReason, ScopeWorkspaces, } from "./scope-instances.js";
22
23
  export { findWorkspaceEnvReservedRule, findWorkspaceSecretEnvReservedRule, formatWorkspaceEnvIssue, parseWorkspaceEnv, parseWorkspaceSecretEnv, WORKSPACE_ENV_MAX_ENTRIES, WORKSPACE_ENV_MAX_NAME_LENGTH, WORKSPACE_ENV_MAX_TOTAL_BYTES, WORKSPACE_ENV_MAX_VALUE_BYTES, WORKSPACE_ENV_NAME_PATTERN, WORKSPACE_ENV_SECRET_MARKERS, } from "@sealant/api-contracts/workspace-environment";
23
24
  export type { WorkspaceEnvIssue, WorkspaceEnvParseResult, WorkspaceEnvReservedRule, } from "@sealant/api-contracts/workspace-environment";
@@ -0,0 +1,171 @@
1
+ import type { SdkRuntime } from "./effect/runtime.js";
2
+ import type { SealantInternalConfig } from "./internal/config.js";
3
+ /**
4
+ * What an instance runs. It has no field for privileged mode, capabilities, host networking, host
5
+ * paths, devices, the Docker socket or shared namespaces; a spec sent with one is refused (400
6
+ * `ResourceInstanceSpecRefusedError`, naming each).
7
+ */
8
+ export interface ScopeInstanceSpec {
9
+ /** The DNS name a linked workspace reaches it by (`db`). */
10
+ readonly alias: string;
11
+ /** Null: every linked workspace reaches it. Set: only workspaces linked with this worktree key. */
12
+ readonly worktreeKey: string | null;
13
+ /** Pinned by digest: `<repository>[:tag]@sha256:<64 hex>`. */
14
+ readonly image: string;
15
+ /** Replaces the image's CMD; its ENTRYPOINT always runs. */
16
+ readonly command: ReadonlyArray<string> | null;
17
+ /** Plain env. Not for secrets: put a secret in an exec's stdin. */
18
+ readonly env: Readonly<Record<string, string>>;
19
+ /** Named volumes; every image `VOLUME` gets one too. None is ever deleted by Sealant. */
20
+ readonly volumes: ReadonlyArray<{
21
+ readonly name: string;
22
+ readonly mountPath: string;
23
+ }>;
24
+ readonly limits: {
25
+ readonly cpuMillicores: number;
26
+ readonly memoryBytes: number;
27
+ };
28
+ readonly ready: {
29
+ readonly kind: "tcp";
30
+ readonly port: number;
31
+ } | {
32
+ readonly kind: "exec";
33
+ readonly argv: ReadonlyArray<string>;
34
+ readonly user: string | null;
35
+ };
36
+ /** Seconds with no live linked workspace reaching it before Sealant stops it. */
37
+ readonly idleStopAfterSeconds: number;
38
+ }
39
+ export type ScopeInstanceStopReason = {
40
+ readonly kind: "idle";
41
+ } | {
42
+ readonly kind: "person";
43
+ readonly by: string;
44
+ };
45
+ /** What Sealant last observed of an instance. */
46
+ export type ScopeInstanceState = {
47
+ readonly kind: "not-started";
48
+ } | {
49
+ readonly kind: "starting";
50
+ readonly since: Date;
51
+ }
52
+ /** Its ready check answered. */
53
+ | {
54
+ readonly kind: "running";
55
+ readonly since: Date;
56
+ } | {
57
+ readonly kind: "stopped";
58
+ readonly at: Date;
59
+ readonly reason: ScopeInstanceStopReason;
60
+ }
61
+ /** It ended on its own; Sealant starts it again. */
62
+ | {
63
+ readonly kind: "exited";
64
+ readonly at: Date;
65
+ readonly exitCode: number | null;
66
+ }
67
+ /** A start that could not finish (an image pull, the ready check), and why. */
68
+ | {
69
+ readonly kind: "failed";
70
+ readonly at: Date;
71
+ readonly message: string;
72
+ } | {
73
+ readonly kind: "archived";
74
+ readonly at: Date;
75
+ };
76
+ export interface ScopeInstance {
77
+ /** `rin:<uuid>`. */
78
+ readonly id: string;
79
+ readonly key: string;
80
+ readonly alias: string;
81
+ readonly worktreeKey: string | null;
82
+ readonly specDigest: string;
83
+ /** What was asked of it. */
84
+ readonly desired: "running" | "stopped" | "archived";
85
+ /** Set while it is stopped: a person's stop holds until a person starts it. */
86
+ readonly stopReason: ScopeInstanceStopReason | null;
87
+ readonly state: ScopeInstanceState;
88
+ readonly observedAt: Date;
89
+ readonly startedAt: Date | null;
90
+ readonly lastReachedAt: Date | null;
91
+ readonly volumes: ReadonlyArray<{
92
+ readonly name: string;
93
+ readonly dockerName: string;
94
+ }>;
95
+ }
96
+ export interface ScopeArchivedVolume {
97
+ readonly instanceKey: string;
98
+ readonly name: string;
99
+ readonly dockerName: string;
100
+ /** Measured at archive; null when it could not be. */
101
+ readonly bytes: number | null;
102
+ }
103
+ export interface ScopeExecResult {
104
+ /** Null when the command was killed at its timeout. */
105
+ readonly exitCode: number | null;
106
+ /** The tail of stdout, at most 1 MiB. */
107
+ readonly stdout: string;
108
+ readonly stderr: string;
109
+ /** Either output was longer than 1 MiB, and only its tail is here. */
110
+ readonly truncated: boolean;
111
+ readonly timedOut: boolean;
112
+ }
113
+ export interface ScopeInstances {
114
+ /**
115
+ * Create or update the instance by key, start it and answer once its ready check passed or its
116
+ * start failed (`state.kind`). `cause: "use"` (a launch, a wake) leaves an instance a person
117
+ * stopped stopped, and answers it so; `cause: "person"` (a person's Start) starts it. The same
118
+ * spec twice is one instance; a changed spec replaces its container and keeps its volumes.
119
+ */
120
+ up(key: string, spec: ScopeInstanceSpec, options: {
121
+ readonly cause: "use" | "person";
122
+ }): Promise<ScopeInstance>;
123
+ /** Rejects with 404 `ResourceInstanceNotFoundError` when the scope has none by this key. */
124
+ get(key: string): Promise<ScopeInstance>;
125
+ /** The scope's instances; `archived: true` lists the archived ones, whose volumes are kept. */
126
+ list(options?: {
127
+ readonly archived?: boolean;
128
+ }): Promise<ReadonlyArray<ScopeInstance>>;
129
+ /** Graceful. Its container, volumes and reach stay; it stays stopped until a person's `up`. */
130
+ stop(key: string, reason: {
131
+ readonly kind: "person";
132
+ readonly by: string;
133
+ }): Promise<ScopeInstance>;
134
+ /**
135
+ * Run `argv` in the running instance. `stdin` streams in (a dump of any size); stdout and stderr
136
+ * come back as tails of at most 1 MiB each. Nothing of argv or stdin is logged or recorded: put
137
+ * a secret in stdin. `timeoutMs` defaults to 10 minutes, at most 6 hours.
138
+ */
139
+ exec(key: string, options: {
140
+ readonly argv: ReadonlyArray<string>;
141
+ readonly user?: string;
142
+ readonly stdin?: AsyncIterable<Uint8Array> | ReadableStream<Uint8Array>;
143
+ readonly timeoutMs?: number;
144
+ }): Promise<ScopeExecResult>;
145
+ /** Stop it and remove its container. Every volume stays, listed here with its size. */
146
+ archive(key: string): Promise<{
147
+ readonly instance: ScopeInstance;
148
+ readonly volumes: ReadonlyArray<ScopeArchivedVolume>;
149
+ }>;
150
+ }
151
+ export interface ScopeWorkspaces {
152
+ /**
153
+ * Let this workspace reach the scope's project instances, and those of `worktreeKey`, by alias:
154
+ * now, and across executor replacements, until the workspace ends. Linking again moves it to
155
+ * another worktree key; a workspace linked to another scope rejects (409
156
+ * `ResourceWorkspaceLinkedElsewhereError`). Answers once its running executors are attached.
157
+ */
158
+ link(workspaceId: string, options: {
159
+ readonly worktreeKey: string;
160
+ }): Promise<{
161
+ readonly worktreeKey: string;
162
+ readonly attachedExecutors: number;
163
+ }>;
164
+ }
165
+ export declare const makeScopeInstances: (runtime: SdkRuntime, config: SealantInternalConfig, scopeId: string) => {
166
+ readonly instances: ScopeInstances;
167
+ readonly workspaces: ScopeWorkspaces;
168
+ readonly archive: () => Promise<{
169
+ readonly volumes: ReadonlyArray<ScopeArchivedVolume>;
170
+ }>;
171
+ };
@@ -0,0 +1,153 @@
1
+ /**
2
+ * A scope's long-running instances (a project's Postgres, Redis or any image), the workspaces that
3
+ * reach them, and the scope's archive. Instances run on Docker only: on any other runtime every
4
+ * call rejects with 409 `ResourceRuntimeUnsupportedError` (`resources run on Docker; this Sealant
5
+ * runs <runtime>`).
6
+ */
7
+ import { RESOURCE_INSTANCE_EXEC, } from "@sealant/api-contracts";
8
+ import { archiveResourceDomainOp, archiveResourceInstanceOp, getResourceInstanceOp, linkResourceWorkspaceOp, listResourceInstancesOp, stopResourceInstanceOp, upResourceInstanceOp, } from "./effect/operations.js";
9
+ import { SealantApiError, SealantError } from "./errors.js";
10
+ const date = (value) => new Date(value);
11
+ const maybeDate = (value) => (value === null ? null : new Date(value));
12
+ const toState = (state) => {
13
+ switch (state.kind) {
14
+ case "not-started":
15
+ return { kind: "not-started" };
16
+ case "starting":
17
+ return { kind: "starting", since: date(state.since) };
18
+ case "running":
19
+ return { kind: "running", since: date(state.since) };
20
+ case "stopped":
21
+ return { kind: "stopped", at: date(state.at), reason: state.reason };
22
+ case "exited":
23
+ return { kind: "exited", at: date(state.at), exitCode: state.exitCode };
24
+ case "failed":
25
+ return { kind: "failed", at: date(state.at), message: state.message };
26
+ case "archived":
27
+ return { kind: "archived", at: date(state.at) };
28
+ }
29
+ };
30
+ const toInstance = (wire) => ({
31
+ id: wire.resourceInstanceId,
32
+ key: wire.key,
33
+ alias: wire.alias,
34
+ worktreeKey: wire.worktreeKey,
35
+ specDigest: wire.specDigest,
36
+ desired: wire.desired,
37
+ stopReason: wire.stopReason,
38
+ state: toState(wire.state),
39
+ observedAt: date(wire.observedAt),
40
+ startedAt: maybeDate(wire.startedAt),
41
+ lastReachedAt: maybeDate(wire.lastReachedAt),
42
+ volumes: wire.volumes,
43
+ });
44
+ const toVolume = (wire) => ({
45
+ instanceKey: wire.instanceKey,
46
+ name: wire.name,
47
+ dockerName: wire.dockerName,
48
+ bytes: wire.bytes,
49
+ });
50
+ /** The exec body: the frame's line, then stdin as it arrives. */
51
+ const execBody = (frame, stdin) => {
52
+ const chunks = async function* () {
53
+ yield new TextEncoder().encode(`${frame}\n`);
54
+ if (stdin === undefined)
55
+ return;
56
+ if (stdin instanceof ReadableStream) {
57
+ const reader = stdin.getReader();
58
+ for (;;) {
59
+ const next = await reader.read();
60
+ if (next.done)
61
+ return;
62
+ yield next.value;
63
+ }
64
+ }
65
+ yield* stdin;
66
+ };
67
+ const iterator = chunks();
68
+ return new ReadableStream({
69
+ pull: async (controller) => {
70
+ const next = await iterator.next();
71
+ if (next.done === true)
72
+ controller.close();
73
+ else
74
+ controller.enqueue(next.value);
75
+ },
76
+ cancel: async () => {
77
+ await iterator.return(undefined);
78
+ },
79
+ });
80
+ };
81
+ const isRecord = (value) => typeof value === "object" && value !== null;
82
+ const execResultOf = (body) => {
83
+ if (!isRecord(body))
84
+ return undefined;
85
+ const { exitCode, stdout, stderr, truncated, timedOut } = body;
86
+ if ((exitCode !== null && typeof exitCode !== "number") ||
87
+ typeof stdout !== "string" ||
88
+ typeof stderr !== "string" ||
89
+ typeof truncated !== "boolean" ||
90
+ typeof timedOut !== "boolean") {
91
+ return undefined;
92
+ }
93
+ return { exitCode, stdout, stderr, truncated, timedOut };
94
+ };
95
+ const exec = async (config, scopeId, key, options) => {
96
+ const path = RESOURCE_INSTANCE_EXEC.path
97
+ .replace(":resourceDomainId", encodeURIComponent(scopeId))
98
+ .replace(":key", encodeURIComponent(key));
99
+ const frame = JSON.stringify({
100
+ argv: options.argv,
101
+ user: options.user ?? null,
102
+ timeoutMs: options.timeoutMs ?? RESOURCE_INSTANCE_EXEC.defaultTimeoutMs,
103
+ });
104
+ // A streamed request body needs half duplex in every fetch that streams one (Node's included).
105
+ const init = {
106
+ method: "POST",
107
+ headers: {
108
+ "content-type": "application/octet-stream",
109
+ ...(config.apiKey === undefined ? {} : { authorization: `Bearer ${config.apiKey}` }),
110
+ },
111
+ body: execBody(frame, options.stdin),
112
+ duplex: "half",
113
+ };
114
+ const response = await (config.fetch ?? fetch)(new URL(path, config.baseUrl), init);
115
+ const body = await response.json().catch(() => undefined);
116
+ if (!response.ok) {
117
+ const tag = isRecord(body) && typeof body["_tag"] === "string" ? body["_tag"] : undefined;
118
+ const message = isRecord(body) && typeof body["message"] === "string"
119
+ ? body["message"]
120
+ : `The exec was refused (${String(response.status)}).`;
121
+ throw new SealantApiError(message, {
122
+ status: response.status,
123
+ ...(tag === undefined ? {} : { code: tag }),
124
+ });
125
+ }
126
+ const result = execResultOf(body);
127
+ if (result === undefined)
128
+ throw new SealantError("The exec answered something that is not a result.");
129
+ return result;
130
+ };
131
+ export const makeScopeInstances = (runtime, config, scopeId) => ({
132
+ instances: {
133
+ up: async (key, spec, { cause }) => toInstance(await runtime.run(upResourceInstanceOp(scopeId, key, { spec: { ...spec }, cause }))),
134
+ get: async (key) => toInstance(await runtime.run(getResourceInstanceOp(scopeId, key))),
135
+ list: async (options) => (await runtime.run(listResourceInstancesOp(scopeId, options?.archived === true))).items.map(toInstance),
136
+ stop: async (key, reason) => toInstance(await runtime.run(stopResourceInstanceOp(scopeId, key, reason.by))),
137
+ exec: (key, options) => exec(config, scopeId, key, options),
138
+ archive: async (key) => {
139
+ const answer = await runtime.run(archiveResourceInstanceOp(scopeId, key));
140
+ return { instance: toInstance(answer.instance), volumes: answer.volumes.map(toVolume) };
141
+ },
142
+ },
143
+ workspaces: {
144
+ link: async (workspaceId, { worktreeKey }) => {
145
+ const answer = await runtime.run(linkResourceWorkspaceOp(scopeId, workspaceId, worktreeKey));
146
+ return { worktreeKey: answer.worktreeKey, attachedExecutors: answer.attachedExecutors };
147
+ },
148
+ },
149
+ archive: async () => {
150
+ const answer = await runtime.run(archiveResourceDomainOp(scopeId));
151
+ return { volumes: answer.volumes.map(toVolume) };
152
+ },
153
+ });