@leitwerk-dev/worker-runners 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-6BSZBMHH.js → chunk-2P3CWUP3.js} +1 -7
- package/dist/chunk-2P3CWUP3.js.map +1 -0
- package/dist/{chunk-D56NJQ5X.js → chunk-6UZ2REWV.js} +1 -1
- package/dist/chunk-6UZ2REWV.js.map +1 -0
- package/dist/{chunk-7NF2P2VP.js → chunk-A3XSYWA5.js} +2 -2
- package/dist/chunk-A3XSYWA5.js.map +1 -0
- package/dist/{chunk-YBSX4N2K.js → chunk-BRIIMAZX.js} +13 -13
- package/dist/chunk-BRIIMAZX.js.map +1 -0
- package/dist/{chunk-OSS62AOL.js → chunk-DFPYUJIK.js} +4 -1
- package/dist/chunk-DFPYUJIK.js.map +1 -0
- package/dist/{chunk-63BBCX7B.js → chunk-H4JEE3ZT.js} +2 -1
- package/dist/chunk-H4JEE3ZT.js.map +1 -0
- package/dist/chunk-ISH4647R.js +506 -0
- package/dist/chunk-ISH4647R.js.map +1 -0
- package/dist/{chunk-ISEDLYKQ.js → chunk-V7TTFLGE.js} +30 -12
- package/dist/chunk-V7TTFLGE.js.map +1 -0
- package/dist/{chunk-YJMHXKNO.js → chunk-YDYI3BD2.js} +13 -6
- package/dist/chunk-YDYI3BD2.js.map +1 -0
- package/dist/{chunk-7X5FBNT7.js → chunk-ZGFD76I6.js} +3 -1
- package/dist/chunk-ZGFD76I6.js.map +1 -0
- package/dist/docker-client-public.d.ts +2 -0
- package/dist/docker-client-public.d.ts.map +1 -0
- package/dist/docker-client-public.js +7 -0
- package/dist/docker-client-public.js.map +1 -0
- package/dist/{docker-engine-client-CnXspTGq.d.ts → docker-engine-client-Btw6ZTXk.d.ts} +45 -18
- package/dist/docker-engine-client.d.ts +44 -17
- package/dist/docker-engine-client.d.ts.map +1 -1
- package/dist/docker-engine-http-client.d.ts +18 -1
- package/dist/docker-engine-http-client.d.ts.map +1 -1
- package/dist/docker-engine-http-client.js +1 -1
- package/dist/docker-public.d.ts +2 -0
- package/dist/docker-public.d.ts.map +1 -0
- package/dist/docker-public.js +13 -0
- package/dist/docker-public.js.map +1 -0
- package/dist/docker-worker-runner.d.ts +19 -9
- package/dist/docker-worker-runner.d.ts.map +1 -1
- package/dist/docker-worker-runner.js +6 -6
- package/dist/index.d.ts +2 -12
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -260
- package/dist/index.js.map +1 -1
- package/dist/{kubernetes-api-client-DD2YevYP.d.ts → kubernetes-api-client-CEe7pHC4.d.ts} +212 -88
- package/dist/kubernetes-api-client.d.ts +80 -0
- package/dist/kubernetes-api-client.d.ts.map +1 -1
- package/dist/kubernetes-client-public.d.ts +2 -0
- package/dist/kubernetes-client-public.d.ts.map +1 -0
- package/dist/kubernetes-client-public.js +9 -0
- package/dist/kubernetes-client-public.js.map +1 -0
- package/dist/kubernetes-http-client.d.ts +11 -0
- package/dist/kubernetes-http-client.d.ts.map +1 -1
- package/dist/kubernetes-http-client.js +5 -500
- package/dist/kubernetes-http-client.js.map +1 -1
- package/dist/kubernetes-manifests.d.ts +151 -8
- package/dist/kubernetes-manifests.d.ts.map +1 -1
- package/dist/kubernetes-public.d.ts +2 -0
- package/dist/kubernetes-public.d.ts.map +1 -0
- package/dist/kubernetes-public.js +13 -0
- package/dist/kubernetes-public.js.map +1 -0
- package/dist/kubernetes-volume-pool-api.d.ts +46 -1
- package/dist/kubernetes-volume-pool-api.d.ts.map +1 -1
- package/dist/kubernetes-volume-pool.d.ts +18 -1
- package/dist/kubernetes-volume-pool.d.ts.map +1 -1
- package/dist/kubernetes-worker-runner.d.ts +27 -11
- package/dist/kubernetes-worker-runner.d.ts.map +1 -1
- package/dist/kubernetes-worker-runner.js +6 -6
- package/dist/local-public.d.ts +2 -0
- package/dist/local-public.d.ts.map +1 -0
- package/dist/local-public.js +11 -0
- package/dist/local-public.js.map +1 -0
- package/dist/local-worker-runner.d.ts +15 -8
- package/dist/local-worker-runner.d.ts.map +1 -1
- package/dist/local-worker-runner.js +2 -2
- package/dist/process-volume-retention.d.ts +15 -0
- package/dist/process-volume-retention.d.ts.map +1 -1
- package/dist/runner-utils.d.ts +5 -0
- package/dist/runner-utils.d.ts.map +1 -1
- package/dist/session-transfer-helper-cli.js +1 -1
- package/dist/session-transfer-helper.d.ts +3 -0
- package/dist/session-transfer-helper.d.ts.map +1 -1
- package/dist/session-transfer-helper.js +1 -1
- package/dist/types-public.d.ts +3 -0
- package/dist/types-public.d.ts.map +1 -0
- package/dist/types-public.js +7 -0
- package/dist/types-public.js.map +1 -0
- package/dist/types.d.ts +87 -29
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +1 -1
- package/dist/worker-labels.d.ts +29 -2
- package/dist/worker-labels.d.ts.map +1 -1
- package/package.json +23 -28
- package/src/docker-client-public.ts +1 -0
- package/src/docker-engine-client.ts +59 -20
- package/src/docker-engine-http-client.ts +13 -0
- package/src/docker-public.ts +1 -0
- package/src/docker-worker-runner.ts +19 -9
- package/src/index.ts +0 -98
- package/src/kubernetes-api-client.ts +112 -6
- package/src/kubernetes-client-public.ts +1 -0
- package/src/kubernetes-http-client.ts +11 -0
- package/src/kubernetes-manifests.ts +211 -16
- package/src/kubernetes-public.ts +1 -0
- package/src/kubernetes-volume-pool-api.ts +58 -4
- package/src/kubernetes-volume-pool.ts +19 -1
- package/src/kubernetes-worker-runner.ts +54 -14
- package/src/local-public.ts +1 -0
- package/src/local-worker-runner.ts +15 -8
- package/src/process-volume-retention.ts +15 -0
- package/src/runner-utils.ts +8 -1
- package/src/session-transfer-helper.ts +3 -0
- package/src/types-public.ts +12 -0
- package/src/types.ts +90 -30
- package/src/worker-labels.ts +29 -2
- package/dist/chunk-63BBCX7B.js.map +0 -1
- package/dist/chunk-6BSZBMHH.js.map +0 -1
- package/dist/chunk-7NF2P2VP.js.map +0 -1
- package/dist/chunk-7X5FBNT7.js.map +0 -1
- package/dist/chunk-D56NJQ5X.js.map +0 -1
- package/dist/chunk-ISEDLYKQ.js.map +0 -1
- package/dist/chunk-OSS62AOL.js.map +0 -1
- package/dist/chunk-YBSX4N2K.js.map +0 -1
- package/dist/chunk-YJMHXKNO.js.map +0 -1
|
@@ -73,23 +73,17 @@ export {
|
|
|
73
73
|
WORKER_LABEL_MANAGED_BY,
|
|
74
74
|
WORKER_LABEL_COMPONENT,
|
|
75
75
|
WORKER_LABEL_INSTANCE_ID,
|
|
76
|
-
WORKER_LABEL_WORKER_ID,
|
|
77
|
-
WORKER_LABEL_SERVER_EPOCH,
|
|
78
76
|
WORKER_LABEL_MANAGED_BY_VALUE,
|
|
79
|
-
WORKER_LABEL_COMPONENT_VALUE,
|
|
80
77
|
PROCESS_NAMESPACE_COMPONENT_VALUE,
|
|
81
78
|
PROCESS_VOLUME_COMPONENT_VALUE,
|
|
82
79
|
PROCESS_SERVER_CA_COMPONENT_VALUE,
|
|
83
80
|
PROCESS_IMAGE_PULL_SECRET_COMPONENT_VALUE,
|
|
84
|
-
EXPORT_HELPER_COMPONENT_VALUE,
|
|
85
|
-
EXPORT_HELPER_LABEL_EXPORT_ID,
|
|
86
81
|
buildWorkerUnitLabels,
|
|
87
82
|
buildProcessResourceLabels,
|
|
88
83
|
managedProcessNamespaceLabelSelector,
|
|
89
84
|
buildExportHelperLabels,
|
|
90
85
|
managedExportHelperLabelSelector,
|
|
91
|
-
isManagedWorkerUnitLabels,
|
|
92
86
|
parseWorkerUnitIdentity,
|
|
93
87
|
managedWorkerLabelSelector
|
|
94
88
|
};
|
|
95
|
-
//# sourceMappingURL=chunk-
|
|
89
|
+
//# sourceMappingURL=chunk-2P3CWUP3.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/worker-labels.ts"],"sourcesContent":["/**\n * Shared labelling for worker units across runner modes.\n *\n * Labels are how the server reconciles which workers exist after a restart:\n * there is no pid registry, the container/pod runtime is the source of truth.\n * Both the Docker and Kubernetes runners stamp these labels at start and read\n * them back during the adoption scan, so the keys and parse rules live here\n * rather than in a runtime-specific body.\n */\n\n/** @internal */\nexport const WORKER_LABEL_MANAGED_BY = \"leitwerk.dev/managed-by\";\n/** @internal */\nexport const WORKER_LABEL_COMPONENT = \"leitwerk.dev/component\";\n/** @internal */\nexport const WORKER_LABEL_INSTANCE_ID = \"leitwerk.dev/instance-id\";\n/** @internal */\nexport const WORKER_LABEL_WORKER_ID = \"leitwerk.dev/worker-id\";\n/** @internal */\nexport const WORKER_LABEL_SERVER_EPOCH = \"leitwerk.dev/server-epoch\";\n\n/** @internal */\nexport const WORKER_LABEL_MANAGED_BY_VALUE = \"leitwerk\";\n/** @internal */\nexport const WORKER_LABEL_COMPONENT_VALUE = \"worker\";\n/** @internal */\nexport const PROCESS_NAMESPACE_COMPONENT_VALUE = \"process-namespace\";\n/** @internal */\nexport const PROCESS_VOLUME_COMPONENT_VALUE = \"process-volume\";\n/** @internal */\nexport const PROCESS_SERVER_CA_COMPONENT_VALUE = \"server-ca\";\n/** @internal */\nexport const PROCESS_IMAGE_PULL_SECRET_COMPONENT_VALUE = \"image-pull-secret\";\n/** @internal */\nexport const EXPORT_HELPER_COMPONENT_VALUE = \"session-export-helper\";\n/** @internal */\nexport const EXPORT_HELPER_LABEL_EXPORT_ID = \"leitwerk.dev/export-id\";\n\n/** @internal */\nexport interface WorkerUnitIdentity {\n\t/** @internal */\n\tinstanceId: string;\n\t/** @internal */\n\tworkerId: string;\n\t/** @internal */\n\tserverEpoch: string;\n}\n\n/**\n * Builds the canonical label set for a worker unit. Extra labels are merged in\n * but can never override the managed identity keys.\n */\n/** @internal */\nexport function buildWorkerUnitLabels(\n\tidentity: WorkerUnitIdentity,\n\textra: Record<string, string> = {},\n): Record<string, string> {\n\treturn {\n\t\t...extra,\n\t\t[WORKER_LABEL_MANAGED_BY]: WORKER_LABEL_MANAGED_BY_VALUE,\n\t\t[WORKER_LABEL_COMPONENT]: WORKER_LABEL_COMPONENT_VALUE,\n\t\t[WORKER_LABEL_INSTANCE_ID]: identity.instanceId,\n\t\t[WORKER_LABEL_WORKER_ID]: identity.workerId,\n\t\t[WORKER_LABEL_SERVER_EPOCH]: identity.serverEpoch,\n\t};\n}\n\n/**\n * Builds labels for durable process-scoped resources (namespace/PVC). These\n * intentionally omit worker-id and server-epoch because the resources outlive a\n * specific worker lease and are not adoption targets.\n */\n/** @internal */\nexport function buildProcessResourceLabels(\n\targs: {\n\t\t/** @internal */\n\t\tinstanceId: string;\n\t\t/** @internal */\n\t\tcomponent:\n\t\t\t| typeof PROCESS_NAMESPACE_COMPONENT_VALUE\n\t\t\t| typeof PROCESS_VOLUME_COMPONENT_VALUE\n\t\t\t| typeof PROCESS_SERVER_CA_COMPONENT_VALUE\n\t\t\t| typeof PROCESS_IMAGE_PULL_SECRET_COMPONENT_VALUE;\n\t},\n\textra: Record<string, string> = {},\n): Record<string, string> {\n\treturn {\n\t\t...extra,\n\t\t[WORKER_LABEL_MANAGED_BY]: WORKER_LABEL_MANAGED_BY_VALUE,\n\t\t[WORKER_LABEL_COMPONENT]: args.component,\n\t\t[WORKER_LABEL_INSTANCE_ID]: args.instanceId,\n\t};\n}\n\n/** Selector for the two managed-by/component keys shared by every managed resource. */\nfunction managedResourceLabelSelector(component: string): Record<string, string> {\n\treturn {\n\t\t[WORKER_LABEL_MANAGED_BY]: WORKER_LABEL_MANAGED_BY_VALUE,\n\t\t[WORKER_LABEL_COMPONENT]: component,\n\t};\n}\n\n/** @internal */\nexport function managedProcessNamespaceLabelSelector(): Record<string, string> {\n\treturn managedResourceLabelSelector(PROCESS_NAMESPACE_COMPONENT_VALUE);\n}\n\n/** @internal */\nexport function buildExportHelperLabels(input: {\n\t/** @internal */\n\tinstanceId: string;\n\t/** @internal */\n\texportId: string;\n}): Record<string, string> {\n\treturn {\n\t\t[WORKER_LABEL_MANAGED_BY]: WORKER_LABEL_MANAGED_BY_VALUE,\n\t\t[WORKER_LABEL_COMPONENT]: EXPORT_HELPER_COMPONENT_VALUE,\n\t\t[WORKER_LABEL_INSTANCE_ID]: input.instanceId,\n\t\t[EXPORT_HELPER_LABEL_EXPORT_ID]: input.exportId,\n\t};\n}\n\n/** @internal */\nexport function managedExportHelperLabelSelector(): Record<string, string> {\n\treturn managedResourceLabelSelector(EXPORT_HELPER_COMPONENT_VALUE);\n}\n\n/** True when the labels identify an leitwerk-managed worker unit. @internal */\nexport function isManagedWorkerUnitLabels(labels: Record<string, string>): boolean {\n\treturn (\n\t\tlabels[WORKER_LABEL_MANAGED_BY] === WORKER_LABEL_MANAGED_BY_VALUE &&\n\t\tlabels[WORKER_LABEL_COMPONENT] === WORKER_LABEL_COMPONENT_VALUE\n\t);\n}\n\n/**\n * Recovers the worker identity from a unit's labels, or `null` when the labels\n * do not describe a complete leitwerk-managed worker.\n */\n/** @internal */\nexport function parseWorkerUnitIdentity(labels: Record<string, string>): WorkerUnitIdentity | null {\n\tif (!isManagedWorkerUnitLabels(labels)) {\n\t\treturn null;\n\t}\n\tconst instanceId = labels[WORKER_LABEL_INSTANCE_ID];\n\tconst workerId = labels[WORKER_LABEL_WORKER_ID];\n\tconst serverEpoch = labels[WORKER_LABEL_SERVER_EPOCH];\n\tif (!instanceId || !workerId || !serverEpoch) {\n\t\treturn null;\n\t}\n\treturn { instanceId, workerId, serverEpoch };\n}\n\n/** Label selector for listing managed worker units in a runtime query. @internal */\nexport function managedWorkerLabelSelector(): Record<string, string> {\n\treturn managedResourceLabelSelector(WORKER_LABEL_COMPONENT_VALUE);\n}\n"],"mappings":";AAWO,IAAM,0BAA0B;AAEhC,IAAM,yBAAyB;AAE/B,IAAM,2BAA2B;AAEjC,IAAM,yBAAyB;AAE/B,IAAM,4BAA4B;AAGlC,IAAM,gCAAgC;AAEtC,IAAM,+BAA+B;AAErC,IAAM,oCAAoC;AAE1C,IAAM,iCAAiC;AAEvC,IAAM,oCAAoC;AAE1C,IAAM,4CAA4C;AAElD,IAAM,gCAAgC;AAEtC,IAAM,gCAAgC;AAiBtC,SAAS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AAAA,EACR;AACA,SAAO,EAAE,YAAY,UAAU,YAAY;AAC5C;AAGO,SAAS,6BAAqD;AACpE,SAAO,6BAA6B,4BAA4B;AACjE;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/session-transfer-helper.ts"],"sourcesContent":["import path from \"node:path\";\nimport { Readable } from \"node:stream\";\nimport {\n\tparseSessionTransferHelperSpec,\n\tprepareTransferArchive,\n} from \"@leitwerk-dev/session-transfer\";\n\n/** @internal */\nexport const SESSION_TRANSFER_HELPER_ENTRY_PATH =\n\t\"/app/packages/worker-runners/dist/session-transfer-helper-cli.js\";\n/** @internal */\nexport const SESSION_TRANSFER_HELPER_MOUNT_PATH = \"/state\";\n\ninterface HelperEnvironment {\n\texportId: string;\n\tcredential: string;\n\tserverUrl: URL;\n}\n\nfunction required(name: string): string {\n\tconst value = process.env[name]?.trim();\n\tif (!value) throw new Error(`Missing ${name}`);\n\treturn value;\n}\n\nfunction readEnvironment(): HelperEnvironment {\n\tconst serverUrl = new URL(required(\"LEITWERK_EXPORT_SERVER_URL\"));\n\tif (!/^https?:$/.test(serverUrl.protocol) || serverUrl.username || serverUrl.password) {\n\t\tthrow new Error(\"Invalid helper server URL\");\n\t}\n\treturn {\n\t\texportId: required(\"LEITWERK_EXPORT_ID\"),\n\t\tcredential: required(\"LEITWERK_EXPORT_CREDENTIAL\"),\n\t\tserverUrl,\n\t};\n}\n\nfunction helperUrl(environment: HelperEnvironment, suffix: string): URL {\n\treturn new URL(\n\t\t`/internal/session-transfer-exports/${encodeURIComponent(environment.exportId)}${suffix}`,\n\t\tenvironment.serverUrl,\n\t);\n}\n\nasync function helperFetch(\n\tenvironment: HelperEnvironment,\n\tsuffix: string,\n\tinit: RequestInit & { duplex?: \"half\" },\n): Promise<Response> {\n\tconst response = await fetch(helperUrl(environment, suffix), {\n\t\t...init,\n\t\tredirect: \"manual\",\n\t\theaders: {\n\t\t\t...init.headers,\n\t\t\tAuthorization: `Bearer ${environment.credential}`,\n\t\t},\n\t});\n\tif (response.status < 200 || response.status >= 300) {\n\t\tthrow new Error(`Helper request failed with HTTP ${response.status}`);\n\t}\n\treturn response;\n}\n\nasync function helperRequest(\n\tenvironment: HelperEnvironment,\n\tsuffix: string,\n\tinit: RequestInit & { duplex?: \"half\" },\n): Promise<void> {\n\tconst response = await helperFetch(environment, suffix, init);\n\tawait response.arrayBuffer();\n}\n\nasync function readHelperSpec(environment: HelperEnvironment) {\n\tconst response = await helperFetch(environment, \"/spec\", { method: \"GET\" });\n\treturn parseSessionTransferHelperSpec(await response.json());\n}\n\n/** @internal */\nexport async function runSessionTransferHelper(): Promise<void> {\n\tconst environment = readEnvironment();\n\tconst spec = await readHelperSpec(environment);\n\tconst workspaceRoot = path.join(SESSION_TRANSFER_HELPER_MOUNT_PATH, \"workspace\");\n\tconst sessionFile = path.join(SESSION_TRANSFER_HELPER_MOUNT_PATH, \"tree\", \"primary.jsonl\");\n\tconst prepared = await prepareTransferArchive({\n\t\tworkspaceRoot,\n\t\tsessionFile,\n\t\tmanifest: spec.manifest,\n\t\tlimits: spec.limits,\n\t});\n\tawait helperRequest(environment, \"/preflight\", {\n\t\tmethod: \"POST\",\n\t\theaders: { \"Content-Type\": \"application/json\" },\n\t\tbody: JSON.stringify({\n\t\t\tmanifest: prepared.manifest,\n\t\t\tpreflight: {\n\t\t\t\tentriesTotal: prepared.preflight.entriesTotal,\n\t\t\t\tlogicalBytesTotal: prepared.preflight.logicalBytesTotal,\n\t\t\t},\n\t\t}),\n\t});\n\tconst archive = prepared.stream({});\n\tawait helperRequest(environment, \"/stream\", {\n\t\tmethod: \"PUT\",\n\t\theaders: { \"Content-Type\": \"application/vnd.leitwerk.session-transfer+tar+zstd\" },\n\t\tbody: Readable.toWeb(archive) as ReadableStream,\n\t\tduplex: \"half\",\n\t});\n}\n"],"mappings":";AAAA,OAAO,UAAU;AACjB,SAAS,gBAAgB;AACzB;AAAA,EACC;AAAA,EACA;AAAA,OACM;AAGA,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AC5D;AAGA,eAAsB,2BAA0C;AAC/D,QAAM,cAAc,gBAAgB;AACpC,QAAM,OAAO,MAAM,eAAe,WAAW;AAC7C,QAAM,gBAAgB,KAAK,KAAK,oCAAoC,WAAW;AAC/E,QAAM,cAAc,KAAK,KAAK,oCAAoC,QAAQ,eAAe;AACzF,QAAM,WAAW,MAAM,uBAAuB;AAAA,IAC7C;AAAA,IACA;AAAA,IACA,UAAU,KAAK;AAAA,IACf,QAAQ,KAAK;AAAA,EACd,CAAC;AACD,QAAM,cAAc,aAAa,cAAc;AAAA,IAC9C,QAAQ;AAAA,IACR,SAAS,EAAE,gBAAgB,mBAAmB;AAAA,IAC9C,MAAM,KAAK,UAAU;AAAA,MACpB,UAAU,SAAS;AAAA,MACnB,WAAW;AAAA,QACV,cAAc,SAAS,UAAU;AAAA,QACjC,mBAAmB,SAAS,UAAU;AAAA,MACvC;AAAA,IACD,CAAC;AAAA,EACF,CAAC;AACD,QAAM,UAAU,SAAS,OAAO,CAAC,CAAC;AAClC,QAAM,cAAc,aAAa,WAAW;AAAA,IAC3C,QAAQ;AAAA,IACR,SAAS,EAAE,gBAAgB,qDAAqD;AAAA,IAChF,MAAM,SAAS,MAAM,OAAO;AAAA,IAC5B,QAAQ;AAAA,EACT,CAAC;AACF;","names":[]}
|
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
} from "./chunk-UGKQOL5E.js";
|
|
4
4
|
import {
|
|
5
5
|
UnitExitNotifier
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-DFPYUJIK.js";
|
|
7
7
|
|
|
8
8
|
// src/local-worker-runner.ts
|
|
9
9
|
import { execFile, spawn } from "child_process";
|
|
@@ -170,4 +170,4 @@ export {
|
|
|
170
170
|
resolveLocalWorkerSpawnArgs,
|
|
171
171
|
createLocalWorkerRunner
|
|
172
172
|
};
|
|
173
|
-
//# sourceMappingURL=chunk-
|
|
173
|
+
//# sourceMappingURL=chunk-A3XSYWA5.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/local-worker-runner.ts"],"sourcesContent":["import { type ChildProcess, execFile, spawn } from \"node:child_process\";\nimport { existsSync } from \"node:fs\";\nimport path from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\nimport { promisify } from \"node:util\";\nimport { createFilesystemProcessStateExporter } from \"./filesystem-process-state-exporter.js\";\nimport { UnitExitNotifier } from \"./runner-utils.js\";\nimport type {\n\tLocalStartWorkerInput,\n\tProcessStateExporter,\n\tStopWorkerOptions,\n\tWorkerExitInfo,\n\tWorkerRunner,\n\tWorkerUnit,\n\tWorkerUnitDescriptor,\n\tWorkerUnitRef,\n} from \"./types.js\";\n\n/** @internal */\nexport const DEFAULT_LOCAL_WORKER_ENTRY_SPECIFIER = \"@leitwerk-dev/worker/worker-entry\";\n\n/** @internal */\nexport interface LocalWorkerRunnerOptions {\n\t/** Command used to launch the worker. Defaults to `node`. @internal */\n\tcommand?: string;\n\t/** Worker entry args. The default package subpath is resolved to the installed entry file. @internal */\n\targs?: readonly string[];\n\t/** Working directory for the spawned worker. Defaults to the installed server package dir. @internal */\n\tcwd?: string;\n\t/** Process storage roots used by the read-only session exporter. @internal */\n\tprocessWorkspacesDir?: string;\n\t/** @internal */\n\ttreeFilesDir?: string;\n\t/** Explicit acknowledgement that Docker processes inherit host Docker authority. @internal */\n\tallowHostDocker?: boolean;\n\t/** Test seam. Production uses node's spawn directly. @internal */\n\tlocalWorkerSpawnImpl?: typeof spawn;\n\t/** Test seam for the shared host-Docker preflight. @internal */\n\tdockerPreflightImpl?: (timeoutMs: number) => Promise<void>;\n}\n\n/** Verifies that the inherited Docker CLI context can reach its daemon. @internal */\nexport async function preflightHostDocker(timeoutMs: number): Promise<void> {\n\tif (!Number.isFinite(timeoutMs) || timeoutMs <= 0) {\n\t\tthrow new Error(\"Docker preflight requires a positive startup timeout\");\n\t}\n\ttry {\n\t\tawait promisify(execFile)(\"docker\", [\"info\"], {\n\t\t\tenv: process.env,\n\t\t\ttimeout: timeoutMs,\n\t\t\tkillSignal: \"SIGKILL\",\n\t\t});\n\t} catch (error) {\n\t\tif (error && typeof error === \"object\" && \"killed\" in error && error.killed) {\n\t\t\tthrow new Error(`Docker preflight timed out after ${timeoutMs}ms`, { cause: error });\n\t\t}\n\t\tthrow error;\n\t}\n}\n\ninterface LocalWorkerUnitState {\n\tref: WorkerUnitRef;\n\tchild: ChildProcess;\n\tstatus: \"running\" | \"stopping\" | \"exited\";\n}\n\nlet localUnitCounter = 0;\n\nfunction nextUnitId(instanceId: string, workerId: string): string {\n\tlocalUnitCounter += 1;\n\treturn `local_${instanceId}_${workerId}_${localUnitCounter}`;\n}\n\nfunction findServerPackageDir(): string {\n\tlet current = path.dirname(fileURLToPath(import.meta.url));\n\twhile (true) {\n\t\tconst candidate = path.join(current, \"package.json\");\n\t\tif (existsSync(candidate)) return current;\n\t\tconst parent = path.dirname(current);\n\t\tif (parent === current) return process.cwd();\n\t\tcurrent = parent;\n\t}\n}\n\nfunction resolveDefaultWorkerEntryPath(): string {\n\treturn fileURLToPath(import.meta.resolve(DEFAULT_LOCAL_WORKER_ENTRY_SPECIFIER));\n}\n\n/** @internal */\nexport function resolveLocalWorkerSpawnArgs(args: readonly string[]): string[] {\n\treturn args[0] === DEFAULT_LOCAL_WORKER_ENTRY_SPECIFIER\n\t\t? [resolveDefaultWorkerEntryPath(), ...args.slice(1)]\n\t\t: [...args];\n}\n\nfunction exitInfo(code: number | null, signal: NodeJS.Signals | null): WorkerExitInfo {\n\treturn { exitCode: code, signal };\n}\n\n/**\n * Best-effort local development/test {@link WorkerRunner}.\n *\n * This runner implements the shared runner contract needed to start and stop a\n * local worker over the production WebSocket IPC path. It is not an isolation\n * boundary, has no restart adoption, and ignores image/resource profile semantics.\n * Docker and Kubernetes remain the contract-defining production runners.\n */\n/** @internal */\nexport function createLocalWorkerRunner(options: LocalWorkerRunnerOptions): {\n\t/** @internal */\n\trunner: WorkerRunner<LocalStartWorkerInput>;\n\t/** @internal */\n\texporter: ProcessStateExporter;\n} {\n\tconst command = options.command ?? \"node\";\n\tconst args = resolveLocalWorkerSpawnArgs(options.args ?? [DEFAULT_LOCAL_WORKER_ENTRY_SPECIFIER]);\n\tconst cwd = options.cwd ?? findServerPackageDir();\n\tconst localWorkerSpawnImpl = options.localWorkerSpawnImpl ?? spawn;\n\tconst dockerPreflightImpl = options.dockerPreflightImpl ?? preflightHostDocker;\n\tconst units = new Map<string, LocalWorkerUnitState>();\n\tconst exitNotifier = new UnitExitNotifier();\n\n\tfunction wrap(ref: WorkerUnitRef): WorkerUnit {\n\t\treturn exitNotifier.wrapUnit(ref, ref.unitId);\n\t}\n\n\tconst runner: WorkerRunner<LocalStartWorkerInput> = {\n\t\tasync start(input: LocalStartWorkerInput, observer): Promise<WorkerUnit> {\n\t\t\tobserver?.report(\"preparing_runtime\");\n\t\t\tif (input.docker) {\n\t\t\t\tif (options.allowHostDocker !== true) {\n\t\t\t\t\tthrow new Error(\"Docker-requiring processes need local_worker.allow_host_docker: true\");\n\t\t\t\t}\n\t\t\t\ttry {\n\t\t\t\t\tconst configuredTimeoutMs = Number.parseInt(\n\t\t\t\t\t\tinput.env.LEITWERK_WORKER_STARTUP_TIMEOUT_MS ?? \"30000\",\n\t\t\t\t\t\t10,\n\t\t\t\t\t);\n\t\t\t\t\tconst deadlineMs = Number.parseInt(\n\t\t\t\t\t\tinput.env.LEITWERK_WORKER_STARTUP_DEADLINE_MS ?? \"\",\n\t\t\t\t\t\t10,\n\t\t\t\t\t);\n\t\t\t\t\tconst timeoutMs = Number.isFinite(deadlineMs)\n\t\t\t\t\t\t? Math.min(configuredTimeoutMs, deadlineMs - Date.now())\n\t\t\t\t\t\t: configuredTimeoutMs;\n\t\t\t\t\tif (timeoutMs <= 0)\n\t\t\t\t\t\tthrow new Error(\"Worker startup deadline expired before Docker preflight\");\n\t\t\t\t\tawait dockerPreflightImpl(timeoutMs);\n\t\t\t\t\tif (Date.now() >= deadlineMs) {\n\t\t\t\t\t\tthrow new Error(\"Worker startup deadline expired during Docker preflight\");\n\t\t\t\t\t}\n\t\t\t\t} catch (error) {\n\t\t\t\t\tthrow new Error(\"Local Docker preflight failed: Docker CLI or daemon is unavailable\", {\n\t\t\t\t\t\tcause: error,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\t\t\tconst unitId = nextUnitId(input.instanceId, input.workerId);\n\t\t\tconst ref: WorkerUnitRef = { instanceId: input.instanceId, workerId: input.workerId, unitId };\n\t\t\tobserver?.report(\"starting_runtime\");\n\t\t\tconst child = localWorkerSpawnImpl(command, args, {\n\t\t\t\tcwd,\n\t\t\t\tstdio: [\"ignore\", \"inherit\", \"inherit\"],\n\t\t\t\tenv: {\n\t\t\t\t\t...Object.fromEntries(\n\t\t\t\t\t\tObject.entries(process.env).filter(\n\t\t\t\t\t\t\t([key]) => !/(?:^|_)(?:TOKEN|API_KEY|PASSWORD|SECRET)$/.test(key),\n\t\t\t\t\t\t),\n\t\t\t\t\t),\n\t\t\t\t\t...input.env,\n\t\t\t\t},\n\t\t\t});\n\t\t\tconst state: LocalWorkerUnitState = {\n\t\t\t\tref,\n\t\t\t\tchild,\n\t\t\t\tstatus: \"running\",\n\t\t\t};\n\t\t\tunits.set(unitId, state);\n\t\t\tchild.once(\"exit\", (code, signal) => {\n\t\t\t\tstate.status = \"exited\";\n\t\t\t\texitNotifier.fireExit(unitId, exitInfo(code, signal));\n\t\t\t});\n\t\t\tchild.once(\"error\", (error) => {\n\t\t\t\tstate.status = \"exited\";\n\t\t\t\texitNotifier.fireExit(unitId, {\n\t\t\t\t\texitCode: null,\n\t\t\t\t\tsignal: null,\n\t\t\t\t\treason: error instanceof Error ? error.message : String(error),\n\t\t\t\t});\n\t\t\t});\n\t\t\treturn wrap(ref);\n\t\t},\n\t\tasync stop(ref: WorkerUnitRef, opts: StopWorkerOptions): Promise<void> {\n\t\t\tconst state = units.get(ref.unitId);\n\t\t\tif (!state || state.status === \"exited\") return;\n\t\t\tstate.status = \"stopping\";\n\t\t\tconst child = state.child;\n\t\t\tconst exited = new Promise<void>((resolve) => child.once(\"exit\", () => resolve()));\n\t\t\tchild.kill(\"SIGTERM\");\n\t\t\tconst timedOut = await Promise.race([\n\t\t\t\texited.then(() => false),\n\t\t\t\tnew Promise<boolean>((resolve) => setTimeout(() => resolve(true), opts.graceMs)),\n\t\t\t]);\n\t\t\tif (timedOut) child.kill(\"SIGKILL\");\n\t\t},\n\t\tasync list(): Promise<WorkerUnitDescriptor[]> {\n\t\t\treturn [];\n\t\t},\n\t\tasync adopt(descriptor: WorkerUnitDescriptor): Promise<WorkerUnit> {\n\t\t\tthrow new Error(\n\t\t\t\t`Cannot adopt local worker ${descriptor.unitId}: local runner does not support adoption`,\n\t\t\t);\n\t\t},\n\t};\n\n\tconst processWorkspacesDir = path.resolve(\n\t\toptions.processWorkspacesDir ?? \"/tmp/leitwerk/workspaces\",\n\t);\n\tconst treeFilesDir = path.resolve(options.treeFilesDir ?? \"/tmp/leitwerk/trees\");\n\tconst exporter = createFilesystemProcessStateExporter({\n\t\tallowedRoots: [processWorkspacesDir, treeFilesDir],\n\t\tresolveSource: (instanceId) => ({\n\t\t\tworkspaceRoot: path.join(processWorkspacesDir, instanceId),\n\t\t\tsessionFile: path.join(treeFilesDir, `${instanceId}.jsonl`),\n\t\t}),\n\t});\n\treturn { runner, exporter };\n}\n"],"mappings":";;;;;;;;AAAA,SAA4B,UAAU,aAAa;AACnD,SAAS,kBAAkB;AAC3B,OAAO,UAAU;AACjB,SAAS,qBAAqB;AAC9B,SAAS,iBAAiB;AAenB,IAAM,uCAAuC;AAuBpD,eAAsB,oBAAoB,WAAkC;AAC3E,MAAI,CAAC,OAAO,SAAS,SAAS,KAAK,aAAa,GAAG;AAClD,UAAM,IAAI,MAAM,sDAAsD;AAAA,EACvE;AACA,MAAI;AACH,UAAM,UAAU,QAAQ,EAAE,UAAU,CAAC,MAAM,GAAG;AAAA,MAC7C,KAAK,QAAQ;AAAA,MACb,SAAS;AAAA,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AAA,EACjC;AACA,QAAM,eAAe,KAAK,QAAQ,QAAQ,gBAAgB,qBAAqB;AAC/E,QAAM,WAAW,qCAAqC;AAAA,IACrD,cAAc,CAAC,sBAAsB,YAAY;AAAA,IACjD,eAAe,CAAC,gBAAgB;AAAA,MAC/B,eAAe,KAAK,KAAK,sBAAsB,UAAU;AAAA,MACzD,aAAa,KAAK,KAAK,cAAc,GAAG,UAAU,QAAQ;AAAA,IAC3D;AAAA,EACD,CAAC;AACD,SAAO,EAAE,QAAQ,SAAS;AAC3B;","names":[]}
|
|
@@ -1,27 +1,27 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createFilesystemProcessStateExporter
|
|
3
|
+
} from "./chunk-UGKQOL5E.js";
|
|
1
4
|
import {
|
|
2
5
|
isDockerEngineNotFoundError
|
|
3
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-H4JEE3ZT.js";
|
|
4
7
|
import {
|
|
5
8
|
createHelperProcessStateExporter,
|
|
6
9
|
exportHelperEnvironment
|
|
7
10
|
} from "./chunk-4F7EMXMU.js";
|
|
11
|
+
import {
|
|
12
|
+
UnitExitNotifier
|
|
13
|
+
} from "./chunk-DFPYUJIK.js";
|
|
14
|
+
import {
|
|
15
|
+
SESSION_TRANSFER_HELPER_ENTRY_PATH,
|
|
16
|
+
SESSION_TRANSFER_HELPER_MOUNT_PATH
|
|
17
|
+
} from "./chunk-6UZ2REWV.js";
|
|
8
18
|
import {
|
|
9
19
|
buildExportHelperLabels,
|
|
10
20
|
buildWorkerUnitLabels,
|
|
11
21
|
managedExportHelperLabelSelector,
|
|
12
22
|
managedWorkerLabelSelector,
|
|
13
23
|
parseWorkerUnitIdentity
|
|
14
|
-
} from "./chunk-
|
|
15
|
-
import {
|
|
16
|
-
createFilesystemProcessStateExporter
|
|
17
|
-
} from "./chunk-UGKQOL5E.js";
|
|
18
|
-
import {
|
|
19
|
-
UnitExitNotifier
|
|
20
|
-
} from "./chunk-OSS62AOL.js";
|
|
21
|
-
import {
|
|
22
|
-
SESSION_TRANSFER_HELPER_ENTRY_PATH,
|
|
23
|
-
SESSION_TRANSFER_HELPER_MOUNT_PATH
|
|
24
|
-
} from "./chunk-D56NJQ5X.js";
|
|
24
|
+
} from "./chunk-2P3CWUP3.js";
|
|
25
25
|
|
|
26
26
|
// src/docker-worker-runner.ts
|
|
27
27
|
import { mkdirSync } from "fs";
|
|
@@ -336,4 +336,4 @@ function createDockerWorkerRunner(options) {
|
|
|
336
336
|
export {
|
|
337
337
|
createDockerWorkerRunner
|
|
338
338
|
};
|
|
339
|
-
//# sourceMappingURL=chunk-
|
|
339
|
+
//# sourceMappingURL=chunk-BRIIMAZX.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/docker-worker-runner.ts"],"sourcesContent":["import { mkdirSync } from \"node:fs\";\nimport path from \"node:path\";\nimport type {\n\tDockerContainerExit,\n\tDockerEngineClient,\n\tDockerMountSpec,\n} from \"./docker-engine-client.js\";\nimport { isDockerEngineNotFoundError } from \"./docker-engine-http-client.js\";\nimport { createFilesystemProcessStateExporter } from \"./filesystem-process-state-exporter.js\";\nimport {\n\tcreateHelperProcessStateExporter,\n\texportHelperEnvironment,\n} from \"./helper-process-state-exporter.js\";\nimport { UnitExitNotifier } from \"./runner-utils.js\";\nimport {\n\tSESSION_TRANSFER_HELPER_ENTRY_PATH,\n\tSESSION_TRANSFER_HELPER_MOUNT_PATH,\n} from \"./session-transfer-helper.js\";\nimport type {\n\tIsolatedStartWorkerInput,\n\tProcessStateExporter,\n\tProcessStateExportHelperRelayProvider,\n\tProcessVolume,\n\tStopWorkerOptions,\n\tWorkerExitInfo,\n\tWorkerRunner,\n\tWorkerUnit,\n\tWorkerUnitDescriptor,\n\tWorkerUnitRef,\n} from \"./types.js\";\nimport {\n\tbuildExportHelperLabels,\n\tbuildWorkerUnitLabels,\n\tmanagedExportHelperLabelSelector,\n\tmanagedWorkerLabelSelector,\n\tparseWorkerUnitIdentity,\n} from \"./worker-labels.js\";\n\n/** @internal */\nexport type DockerProcessVolumeMode = \"bind\" | \"named_volume\";\n\n/** @internal */\nexport interface DockerProcessVolumeOptions {\n\t/** @internal */\n\tmode: DockerProcessVolumeMode;\n\t/** Host root for per-process bind mounts (bind mode). @internal */\n\thostRoot: string;\n\t/** Mount path injected into worker containers. @internal */\n\tmountPath: string;\n\t/** Prefix for named volumes (named_volume mode). @internal */\n\tnamedVolumePrefix?: string;\n}\n\n/** @internal */\nexport interface DockerWorkerRunnerOptions {\n\t/** @internal */\n\tengine: DockerEngineClient;\n\t/** @internal */\n\tvolume: DockerProcessVolumeOptions;\n\t/** Shared private network attached to every worker container. @internal */\n\tdefaultNetwork: string;\n\t/** Exact isolation used for Docker-requiring processes. Omit to make them unavailable. @internal */\n\tprivateDaemonIsolation?: \"privileged\" | \"sysbox-runc\";\n\t/** Host CA bundle mounted read-only into workers and export helpers. @internal */\n\tserverCaFile?: string;\n\t/** Stable internal URL used by named-volume export helpers. @internal */\n\tserverUrl?: string;\n\t/** Trusted image containing the bundled session-transfer helper entrypoint. @internal */\n\texporterImage?: string;\n\t/** Server-owned relay registry used by named-volume export helpers. @internal */\n\thelperRelays?: ProcessStateExportHelperRelayProvider;\n}\n\nconst DEFAULT_NAMED_VOLUME_PREFIX = \"leitwerk-process-\";\nconst NANO_CPUS_PER_CPU = 1_000_000_000;\nconst PRIVATE_DOCKER_ENV = \"LEITWERK_PRIVATE_DOCKER\";\nconst PROCESS_VOLUME_MOUNT_PATH_ENV = \"LEITWERK_PROCESS_VOLUME_MOUNT_PATH\";\nconst WORKER_SERVER_CA_MOUNT_PATH = \"/leitwerk/server-ca.pem\";\n\n/** Replaces characters Docker rejects in container names. */\nfunction sanitizeNameSegment(value: string): string {\n\tconst cleaned = value.replace(/[^a-zA-Z0-9_.-]/g, \"-\");\n\treturn cleaned.length > 0 ? cleaned : \"x\";\n}\n\nfunction containerName(instanceId: string, workerId: string): string {\n\treturn `leitwerk-worker-${sanitizeNameSegment(instanceId)}-${sanitizeNameSegment(workerId)}`;\n}\n\nfunction toEnvList(env: Record<string, string>): string[] {\n\treturn Object.entries(env).map(([key, value]) => `${key}=${value}`);\n}\n\nfunction parseCpuToNanoCpus(cpu: string | undefined): number | undefined {\n\tif (cpu === undefined) {\n\t\treturn undefined;\n\t}\n\tconst parsed = Number.parseFloat(cpu);\n\tif (!Number.isFinite(parsed) || parsed <= 0) {\n\t\treturn undefined;\n\t}\n\treturn Math.round(parsed * NANO_CPUS_PER_CPU);\n}\n\nconst MEMORY_SUFFIX_MULTIPLIERS: ReadonlyArray<[string, number]> = [\n\t[\"Gi\", 1024 ** 3],\n\t[\"Mi\", 1024 ** 2],\n\t[\"Ki\", 1024],\n\t[\"G\", 1000 ** 3],\n\t[\"M\", 1000 ** 2],\n\t[\"K\", 1000],\n\t[\"g\", 1024 ** 3],\n\t[\"m\", 1024 ** 2],\n\t[\"k\", 1024],\n\t[\"b\", 1],\n\t[\"B\", 1],\n];\n\nfunction parseMemoryToBytes(memory: string | undefined): number | undefined {\n\tif (memory === undefined) {\n\t\treturn undefined;\n\t}\n\tconst trimmed = memory.trim();\n\tfor (const [suffix, multiplier] of MEMORY_SUFFIX_MULTIPLIERS) {\n\t\tif (trimmed.endsWith(suffix)) {\n\t\t\tconst value = Number.parseFloat(trimmed.slice(0, -suffix.length));\n\t\t\tif (!Number.isFinite(value) || value <= 0) {\n\t\t\t\treturn undefined;\n\t\t\t}\n\t\t\treturn Math.round(value * multiplier);\n\t\t}\n\t}\n\tconst bytes = Number.parseInt(trimmed, 10);\n\treturn Number.isFinite(bytes) && bytes > 0 ? bytes : undefined;\n}\n\nfunction mapExit(info: DockerContainerExit): WorkerExitInfo {\n\treturn {\n\t\texitCode: Number.isFinite(info.statusCode) ? info.statusCode : null,\n\t\tsignal: info.signal ?? null,\n\t\t...(info.oomKilled !== undefined ? { oomKilled: info.oomKilled } : {}),\n\t\t...(info.error !== undefined ? { reason: info.error } : {}),\n\t};\n}\n\n/**\n * Docker Engine API {@link ProcessVolume} / {@link WorkerRunner}.\n *\n * Container-per-process, labelled for adoption, bind- or named-volume backed.\n * The server never reads the volume; it only injects the mount. Physical\n * container exits are observed via the engine's wait call and mapped into the\n * supervisor's existing failure paths through `onExit`.\n */\n/** @internal */\nexport function createDockerWorkerRunner(options: DockerWorkerRunnerOptions): {\n\t/** @internal */\n\trunner: WorkerRunner<IsolatedStartWorkerInput>;\n\t/** @internal */\n\tvolume: ProcessVolume;\n\t/** @internal */\n\texporter: ProcessStateExporter;\n} {\n\tif (\n\t\toptions.volume.mode === \"named_volume\" &&\n\t\t(!options.serverUrl || !options.exporterImage || !options.helperRelays)\n\t) {\n\t\tthrow new Error(\"Docker named-volume transfer exporter is not configured\");\n\t}\n\tconst { engine } = options;\n\tconst mountPath = options.volume.mountPath;\n\tconst namedVolumePrefix = options.volume.namedVolumePrefix ?? DEFAULT_NAMED_VOLUME_PREFIX;\n\tfunction volumeId(instanceId: string): string {\n\t\tif (options.volume.mode === \"named_volume\") {\n\t\t\treturn `${namedVolumePrefix}${instanceId}`;\n\t\t}\n\t\treturn path.join(options.volume.hostRoot, instanceId);\n\t}\n\n\tasync function releaseManagedStorage(instanceId: string): Promise<void> {\n\t\tif (options.volume.mode === \"named_volume\") {\n\t\t\tawait engine.removeVolume(volumeId(instanceId));\n\t\t}\n\t\t// Bind mounts are retained on the host filesystem; retention/GC of the\n\t\t// host directory is an operator concern, not a runner action.\n\t}\n\n\tconst volume: ProcessVolume = {\n\t\tasync ensure(instanceId) {\n\t\t\tconst id = volumeId(instanceId);\n\t\t\tif (options.volume.mode === \"named_volume\") {\n\t\t\t\tawait engine.ensureVolume(id);\n\t\t\t} else {\n\t\t\t\tmkdirSync(id, { recursive: true });\n\t\t\t}\n\t\t\treturn { instanceId, id, mountPath };\n\t\t},\n\t\trelease: releaseManagedStorage,\n\t\tdeleteProcessResources: releaseManagedStorage,\n\t};\n\n\tconst exitNotifier = new UnitExitNotifier();\n\tconst watched = new Set<string>();\n\tconst stopPromises = new Map<string, Promise<void>>();\n\n\tfunction stopAndRemove(ref: WorkerUnitRef, opts: StopWorkerOptions): Promise<void> {\n\t\tconst existing = stopPromises.get(ref.unitId);\n\t\tif (existing) return existing;\n\t\tconst operation = Promise.resolve()\n\t\t\t.then(async () => {\n\t\t\t\tconst timeoutSeconds = Math.max(0, Math.ceil(opts.graceMs / 1000));\n\t\t\t\ttry {\n\t\t\t\t\tawait engine.stopContainer(ref.unitId, { timeoutSeconds });\n\t\t\t\t} catch (error) {\n\t\t\t\t\tif (!isDockerEngineNotFoundError(error)) throw error;\n\t\t\t\t}\n\t\t\t\ttry {\n\t\t\t\t\tawait engine.removeContainer(ref.unitId, { force: true });\n\t\t\t\t} catch (error) {\n\t\t\t\t\tif (!isDockerEngineNotFoundError(error)) throw error;\n\t\t\t\t}\n\t\t\t})\n\t\t\t.finally(() => stopPromises.delete(ref.unitId));\n\t\tstopPromises.set(ref.unitId, operation);\n\t\treturn operation;\n\t}\n\n\tfunction applyServerCa(mounts: DockerMountSpec[], env: Record<string, string>): void {\n\t\tif (options.serverCaFile) {\n\t\t\tmounts.push({\n\t\t\t\tsource: options.serverCaFile,\n\t\t\t\ttarget: WORKER_SERVER_CA_MOUNT_PATH,\n\t\t\t\treadOnly: true,\n\t\t\t});\n\t\t\tenv.NODE_EXTRA_CA_CERTS = WORKER_SERVER_CA_MOUNT_PATH;\n\t\t}\n\t}\n\n\tfunction watchForExit(unitId: string): void {\n\t\tif (watched.has(unitId)) return;\n\t\twatched.add(unitId);\n\t\tengine\n\t\t\t.waitContainer(unitId)\n\t\t\t.then((exit) => exitNotifier.fireExit(unitId, mapExit(exit)))\n\t\t\t.catch(() =>\n\t\t\t\texitNotifier.fireExit(unitId, { exitCode: null, signal: null, reason: \"wait_failed\" }),\n\t\t\t)\n\t\t\t.finally(() => watched.delete(unitId));\n\t}\n\n\tconst runner: WorkerRunner<IsolatedStartWorkerInput> = {\n\t\tasync start(input: IsolatedStartWorkerInput, observer) {\n\t\t\tobserver?.report(\"preparing_runtime\");\n\t\t\tconst volume = input.volume;\n\t\t\tconst labels = buildWorkerUnitLabels({\n\t\t\t\tinstanceId: input.instanceId,\n\t\t\t\tworkerId: input.workerId,\n\t\t\t\tserverEpoch: input.serverEpoch,\n\t\t\t});\n\t\t\tconst mounts: DockerMountSpec[] = [{ source: volume.id, target: volume.mountPath }];\n\t\t\tconst env: Record<string, string> = {\n\t\t\t\t...input.env,\n\t\t\t\t[PROCESS_VOLUME_MOUNT_PATH_ENV]: volume.mountPath,\n\t\t\t};\n\t\t\tapplyServerCa(mounts, env);\n\t\t\tconst isolation = input.docker ? options.privateDaemonIsolation : undefined;\n\t\t\tif (input.docker && !isolation) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Cannot start Docker-requiring process ${input.instanceId}: docker.private_daemon is not configured`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (input.docker) env[PRIVATE_DOCKER_ENV] = \"1\";\n\t\t\tconst privileged = isolation === \"privileged\";\n\t\t\tconst sysbox = isolation === \"sysbox-runc\";\n\t\t\tobserver?.report(\"allocating_runtime\");\n\t\t\tconst { id } = await engine.createContainer({\n\t\t\t\tname: containerName(input.instanceId, input.workerId),\n\t\t\t\timage: input.image.reference,\n\t\t\t\tenv: toEnvList(env),\n\t\t\t\tlabels,\n\t\t\t\tmounts,\n\t\t\t\tnetworkMode: options.defaultNetwork,\n\t\t\t\tprivileged,\n\t\t\t\t...(sysbox ? { runtime: \"sysbox-runc\" } : {}),\n\t\t\t\tnanoCpus: parseCpuToNanoCpus(input.resources?.cpu),\n\t\t\t\tmemoryBytes: parseMemoryToBytes(input.resources?.memory),\n\t\t\t});\n\t\t\tobserver?.report(\"starting_runtime\");\n\t\t\tawait engine.startContainer(id);\n\t\t\tconst ref: WorkerUnitRef = {\n\t\t\t\tinstanceId: input.instanceId,\n\t\t\t\tworkerId: input.workerId,\n\t\t\t\tunitId: id,\n\t\t\t};\n\t\t\twatchForExit(id);\n\t\t\treturn exitNotifier.wrapUnit(ref, ref.unitId, {\n\t\t\t\treplacementHandoff: \"stop-before-replacement\",\n\t\t\t});\n\t\t},\n\t\tasync stop(ref: WorkerUnitRef, opts: StopWorkerOptions) {\n\t\t\tawait stopAndRemove(ref, opts);\n\t\t\t// Container removal is the replacement handoff boundary. The process volume,\n\t\t\t// including private daemon state, remains available to the replacement.\n\t\t},\n\t\tasync list(): Promise<WorkerUnitDescriptor[]> {\n\t\t\tconst summaries = await engine.listContainers({\n\t\t\t\tlabels: managedWorkerLabelSelector(),\n\t\t\t});\n\t\t\tconst descriptors: WorkerUnitDescriptor[] = [];\n\t\t\tfor (const summary of summaries) {\n\t\t\t\tconst identity = parseWorkerUnitIdentity(summary.labels);\n\t\t\t\tif (!identity) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tdescriptors.push({\n\t\t\t\t\tinstanceId: identity.instanceId,\n\t\t\t\t\tworkerId: identity.workerId,\n\t\t\t\t\tunitId: summary.id,\n\t\t\t\t\tobservedState: \"running\",\n\t\t\t\t});\n\t\t\t}\n\t\t\treturn descriptors;\n\t\t},\n\t\tasync adopt(descriptor: WorkerUnitDescriptor): Promise<WorkerUnit> {\n\t\t\tconst inspect = await engine.inspectContainer(descriptor.unitId);\n\t\t\tconst identity = parseWorkerUnitIdentity(inspect.labels);\n\t\t\tif (\n\t\t\t\t!identity ||\n\t\t\t\tidentity.instanceId !== descriptor.instanceId ||\n\t\t\t\tidentity.workerId !== descriptor.workerId\n\t\t\t) {\n\t\t\t\tthrow new Error(`Cannot adopt worker unit ${descriptor.unitId}: labels changed`);\n\t\t\t}\n\t\t\tif (!inspect.running) {\n\t\t\t\tthrow new Error(`Cannot adopt worker unit ${descriptor.unitId}: not running`);\n\t\t\t}\n\t\t\tconst ref: WorkerUnitRef = {\n\t\t\t\tinstanceId: descriptor.instanceId,\n\t\t\t\tworkerId: descriptor.workerId,\n\t\t\t\tunitId: descriptor.unitId,\n\t\t\t};\n\t\t\twatchForExit(descriptor.unitId);\n\t\t\treturn exitNotifier.wrapUnit(ref, ref.unitId, {\n\t\t\t\treplacementHandoff: \"stop-before-replacement\",\n\t\t\t});\n\t\t},\n\t};\n\n\tconst exporterServerUrl = options.serverUrl ?? \"\";\n\tconst exporterImage = options.exporterImage ?? \"\";\n\tconst helperRelays = options.helperRelays as ProcessStateExportHelperRelayProvider;\n\tconst exporter =\n\t\toptions.volume.mode === \"bind\"\n\t\t\t? createFilesystemProcessStateExporter({\n\t\t\t\t\tallowedRoots: [options.volume.hostRoot],\n\t\t\t\t\tresolveSource: async (instanceId) => {\n\t\t\t\t\t\tconst { id } = await volume.ensure(instanceId);\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tworkspaceRoot: path.join(id, \"workspace\"),\n\t\t\t\t\t\t\tsessionFile: path.join(id, \"tree\", \"primary.jsonl\"),\n\t\t\t\t\t\t};\n\t\t\t\t\t},\n\t\t\t\t})\n\t\t\t: createHelperProcessStateExporter({\n\t\t\t\t\tvolume,\n\t\t\t\t\thelperRelays,\n\t\t\t\t\tasync launch(input) {\n\t\t\t\t\t\tconst mounts: DockerMountSpec[] = [\"workspace\", \"tree\"].map((volumeSubpath) => ({\n\t\t\t\t\t\t\tsource: input.volume.id,\n\t\t\t\t\t\t\ttarget: path.posix.join(SESSION_TRANSFER_HELPER_MOUNT_PATH, volumeSubpath),\n\t\t\t\t\t\t\treadOnly: true,\n\t\t\t\t\t\t\tvolumeSubpath,\n\t\t\t\t\t\t}));\n\t\t\t\t\t\tconst env = exportHelperEnvironment({\n\t\t\t\t\t\t\tserverUrl: exporterServerUrl,\n\t\t\t\t\t\t\texportId: input.exportId,\n\t\t\t\t\t\t\tcredential: input.credential,\n\t\t\t\t\t\t});\n\t\t\t\t\t\tapplyServerCa(mounts, env);\n\t\t\t\t\t\tconst created = await engine.createContainer({\n\t\t\t\t\t\t\tname: sanitizeNameSegment(input.name),\n\t\t\t\t\t\t\timage: exporterImage,\n\t\t\t\t\t\t\tcommand: [\"node\", SESSION_TRANSFER_HELPER_ENTRY_PATH],\n\t\t\t\t\t\t\tenv: toEnvList(env),\n\t\t\t\t\t\t\tlabels: buildExportHelperLabels({\n\t\t\t\t\t\t\t\tinstanceId: input.instanceId,\n\t\t\t\t\t\t\t\texportId: input.exportId,\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\tmounts,\n\t\t\t\t\t\t\tnetworkMode: options.defaultNetwork,\n\t\t\t\t\t\t\tprivileged: false,\n\t\t\t\t\t\t});\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tawait engine.startContainer(created.id);\n\t\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\tawait engine.removeContainer(created.id, { force: true });\n\t\t\t\t\t\t\t} catch (cleanupError) {\n\t\t\t\t\t\t\t\tif (!isDockerEngineNotFoundError(cleanupError)) throw cleanupError;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tthrow error;\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\twait: async () => {\n\t\t\t\t\t\t\t\tconst exit = await engine.waitContainer(created.id);\n\t\t\t\t\t\t\t\treturn { exitCode: exit.statusCode, reason: exit.error };\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tremove: async () => {\n\t\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\t\tawait engine.removeContainer(created.id, { force: true });\n\t\t\t\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t\t\t\tif (!isDockerEngineNotFoundError(error)) throw error;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t};\n\t\t\t\t\t},\n\t\t\t\t\tasync reconcileHelpers() {\n\t\t\t\t\t\tconst helpers = await engine.listContainers({\n\t\t\t\t\t\t\tlabels: managedExportHelperLabelSelector(),\n\t\t\t\t\t\t});\n\t\t\t\t\t\tawait Promise.all(\n\t\t\t\t\t\t\thelpers.map(async (helper) => {\n\t\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\t\tawait engine.removeContainer(helper.id, { force: true });\n\t\t\t\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t\t\t\tif (!isDockerEngineNotFoundError(error)) throw error;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t);\n\t\t\t\t\t},\n\t\t\t\t});\n\treturn { runner, volume, exporter };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAAS,iBAAiB;AAC1B,OAAO,UAAU;AAwEjB,IAAM,8BAA8B;AACpC,IAAM,oBAAoB;AAC1B,IAAM,qBAAqB;AAC3B,IAAM,gCAAgC;AACtC,IAAM,8BAA8B;AAGpC,SAAS,oBAAoB,OAAuB;AACnD,QAAM,UAAU,MAAM,QAAQ,oBAAoB,GAAG;AACrD,SAAO,QAAQ,SAAS,IAAI,UAAU;AACvC;AAEA,SAAS,cAAc,YAAoB,UAA0B;AACpE,SAAO,mBAAmB,oBAAoB,UAAU,CAAC,IAAI,oBAAoB,QAAQ,CAAC;AAC3F;AAEA,SAAS,UAAU,KAAuC;AACzD,SAAO,OAAO,QAAQ,GAAG,EAAE,IAAI,CAAC,CAAC,KAAK,KAAK,MAAM,GAAG,GAAG,IAAI,KAAK,EAAE;AACnE;AAEA,SAAS,mBAAmB,KAA6C;AACxE,MAAI,QAAQ,QAAW;AACtB,WAAO;AAAA,EACR;AACA,QAAM,SAAS,OAAO,WAAW,GAAG;AACpC,MAAI,CAAC,OAAO,SAAS,MAAM,KAAK,UAAU,GAAG;AAC5C,WAAO;AAAA,EACR;AACA,SAAO,KAAK,MAAM,SAAS,iBAAiB;AAC7C;AAEA,IAAM,4BAA6D;AAAA,EAClE,CAAC,MAAM,QAAQ,CAAC;AAAA,EAChB,CAAC,MAAM,QAAQ,CAAC;AAAA,EAChB,CAAC,MAAM,IAAI;AAAA,EACX,CAAC,KAAK,OAAQ,CAAC;AAAA,EACf,CAAC,KAAK,OAAQ,CAAC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,YAAM,UAAU,MAAM,OAAO,eAAe;AAAA,QAC3C,QAAQ,iCAAiC;AAAA,MAC1C,CAAC;AACD,YAAM,QAAQ;AAAA,QACb,QAAQ,IAAI,OAAO,WAAW;AAC7B,cAAI;AACH,kBAAM,OAAO,gBAAgB,OAAO,IAAI,EAAE,OAAO,KAAK,CAAC;AAAA,UACxD,SAAS,OAAO;AACf,gBAAI,CAAC,4BAA4B,KAAK,EAAG,OAAM;AAAA,UAChD;AAAA,QACD,CAAC;AAAA,MACF;AAAA,IACD;AAAA,EACD,CAAC;AACJ,SAAO,EAAE,QAAQ,QAAQ,SAAS;AACnC;","names":["volume"]}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
var UnitExitNotifier = class {
|
|
3
3
|
listeners = /* @__PURE__ */ new Map();
|
|
4
4
|
exited = /* @__PURE__ */ new Map();
|
|
5
|
+
/** @internal */
|
|
5
6
|
onExit(key, listener) {
|
|
6
7
|
const exit = this.exited.get(key);
|
|
7
8
|
if (exit) {
|
|
@@ -12,6 +13,7 @@ var UnitExitNotifier = class {
|
|
|
12
13
|
list.push(listener);
|
|
13
14
|
this.listeners.set(key, list);
|
|
14
15
|
}
|
|
16
|
+
/** @internal */
|
|
15
17
|
fireExit(key, info) {
|
|
16
18
|
if (this.exited.has(key)) return;
|
|
17
19
|
this.exited.set(key, info);
|
|
@@ -20,6 +22,7 @@ var UnitExitNotifier = class {
|
|
|
20
22
|
this.listeners.delete(key);
|
|
21
23
|
for (const listener of list.splice(0)) listener(info);
|
|
22
24
|
}
|
|
25
|
+
/** @internal */
|
|
23
26
|
wrapUnit(ref, key, options) {
|
|
24
27
|
return {
|
|
25
28
|
...ref,
|
|
@@ -32,4 +35,4 @@ var UnitExitNotifier = class {
|
|
|
32
35
|
export {
|
|
33
36
|
UnitExitNotifier
|
|
34
37
|
};
|
|
35
|
-
//# sourceMappingURL=chunk-
|
|
38
|
+
//# sourceMappingURL=chunk-DFPYUJIK.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/runner-utils.ts"],"sourcesContent":["import type { WorkerExitInfo, WorkerUnit, WorkerUnitRef } from \"./types.js\";\n\n/**\n * Shared exit-notification machinery used by every {@link WorkerRunner}.\n *\n * Each runner implementation tracks physical unit exits and maps them to\n * `WorkerUnit.onExit` callbacks. This utility captures the identical map +\n * fire/wrap logic and leaves only the unit-keying to each runner.\n */\n/** @internal */\nexport class UnitExitNotifier {\n\tprivate readonly listeners = new Map<string, Array<(info: WorkerExitInfo) => void>>();\n\tprivate readonly exited = new Map<string, WorkerExitInfo>();\n\n\t/** @internal */\n\tonExit(key: string, listener: (info: WorkerExitInfo) => void): void {\n\t\tconst exit = this.exited.get(key);\n\t\tif (exit) {\n\t\t\tqueueMicrotask(() => listener(exit));\n\t\t\treturn;\n\t\t}\n\t\tconst list = this.listeners.get(key) ?? [];\n\t\tlist.push(listener);\n\t\tthis.listeners.set(key, list);\n\t}\n\n\t/** @internal */\n\tfireExit(key: string, info: WorkerExitInfo): void {\n\t\tif (this.exited.has(key)) return;\n\t\tthis.exited.set(key, info);\n\t\tconst list = this.listeners.get(key);\n\t\tif (!list) return;\n\t\tthis.listeners.delete(key);\n\t\tfor (const listener of list.splice(0)) listener(info);\n\t}\n\n\t/** @internal */\n\twrapUnit<T extends WorkerUnitRef>(\n\t\tref: T,\n\t\tkey: string,\n\t\toptions?: {\n\t\t\t/** @internal */\n\t\t\treplacementHandoff?: WorkerUnit[\"replacementHandoff\"];\n\t\t},\n\t): WorkerUnit {\n\t\treturn {\n\t\t\t...ref,\n\t\t\t...(options?.replacementHandoff ? { replacementHandoff: options.replacementHandoff } : {}),\n\t\t\tonExit: (listener) => this.onExit(key, listener),\n\t\t};\n\t}\n}\n"],"mappings":";AAUO,IAAM,mBAAN,MAAuB;AAAA,EACZ,YAAY,oBAAI,IAAmD;AAAA,EACnE,SAAS,oBAAI,IAA4B;AAAA;AAAA,EAG1D,OAAO,KAAa,UAAgD;AACnE,UAAM,OAAO,KAAK,OAAO,IAAI,GAAG;AAChC,QAAI,MAAM;AACT,qBAAe,MAAM,SAAS,IAAI,CAAC;AACnC;AAAA,IACD;AACA,UAAM,OAAO,KAAK,UAAU,IAAI,GAAG,KAAK,CAAC;AACzC,SAAK,KAAK,QAAQ;AAClB,SAAK,UAAU,IAAI,KAAK,IAAI;AAAA,EAC7B;AAAA;AAAA,EAGA,SAAS,KAAa,MAA4B;AACjD,QAAI,KAAK,OAAO,IAAI,GAAG,EAAG;AAC1B,SAAK,OAAO,IAAI,KAAK,IAAI;AACzB,UAAM,OAAO,KAAK,UAAU,IAAI,GAAG;AACnC,QAAI,CAAC,KAAM;AACX,SAAK,UAAU,OAAO,GAAG;AACzB,eAAW,YAAY,KAAK,OAAO,CAAC,EAAG,UAAS,IAAI;AAAA,EACrD;AAAA;AAAA,EAGA,SACC,KACA,KACA,SAIa;AACb,WAAO;AAAA,MACN,GAAG;AAAA,MACH,GAAI,SAAS,qBAAqB,EAAE,oBAAoB,QAAQ,mBAAmB,IAAI,CAAC;AAAA,MACxF,QAAQ,CAAC,aAAa,KAAK,OAAO,KAAK,QAAQ;AAAA,IAChD;AAAA,EACD;AACD;","names":[]}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import http from "http";
|
|
3
3
|
import { text as readText } from "stream/consumers";
|
|
4
4
|
var DockerEngineHttpError = class extends Error {
|
|
5
|
+
/** @internal */
|
|
5
6
|
constructor(message, statusCode, body) {
|
|
6
7
|
super(message);
|
|
7
8
|
this.statusCode = statusCode;
|
|
@@ -196,4 +197,4 @@ export {
|
|
|
196
197
|
parseDockerEngineSocket,
|
|
197
198
|
createDockerEngineHttpClient
|
|
198
199
|
};
|
|
199
|
-
//# sourceMappingURL=chunk-
|
|
200
|
+
//# sourceMappingURL=chunk-H4JEE3ZT.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/docker-engine-http-client.ts"],"sourcesContent":["import http from \"node:http\";\nimport { text as readText } from \"node:stream/consumers\";\nimport type {\n\tDockerContainerExit,\n\tDockerContainerInspect,\n\tDockerContainerSpec,\n\tDockerEngineClient,\n} from \"./docker-engine-client.js\";\n\n/** @internal */\nexport class DockerEngineHttpError extends Error {\n\t/** @internal */\n\tconstructor(\n\t\tmessage: string,\n\t\t/** @internal */\n\t\treadonly statusCode: number,\n\t\t/** @internal */\n\t\treadonly body: string,\n\t) {\n\t\tsuper(message);\n\t}\n}\n\n/** @internal */\nexport function isDockerEngineNotFoundError(error: unknown): boolean {\n\treturn error instanceof DockerEngineHttpError && error.statusCode === 404;\n}\n\n/** @internal */\nexport interface ParsedDockerEngineSocket {\n\t/** @internal */\n\tsocketPath?: string;\n\t/** @internal */\n\tbaseUrl?: URL;\n}\n\n/** @internal */\nexport function parseDockerEngineSocket(value: string): ParsedDockerEngineSocket {\n\tif (value.startsWith(\"unix://\")) {\n\t\tconst socketPath = value.slice(\"unix://\".length);\n\t\tif (!socketPath.startsWith(\"/\"))\n\t\t\tthrow new Error(\"docker.socket unix:// URL must contain an absolute path\");\n\t\treturn { socketPath };\n\t}\n\tif (value.startsWith(\"http://\")) return { baseUrl: new URL(value) };\n\tif (value.startsWith(\"https://\")) {\n\t\tthrow new Error(\n\t\t\t\"docker.socket https:// is not supported by the built-in Docker adapter; use unix:// or http://\",\n\t\t);\n\t}\n\tif (value.startsWith(\"/\")) return { socketPath: value };\n\tthrow new Error(\n\t\t`Unsupported docker.socket value '${value}'; expected unix:///path/to/docker.sock`,\n\t);\n}\n\n/** @internal */\nexport interface DockerEngineHttpClientOptions {\n\t/** @internal */\n\tsocket: string;\n\t/** @internal */\n\tapiVersion?: string;\n}\n\ninterface DockerApiRequest {\n\tmethod: \"GET\" | \"POST\" | \"DELETE\";\n\tpath: string;\n\tquery?: Record<string, string>;\n\tbody?: unknown;\n}\n\nfunction encodeQuery(query?: Record<string, string>): string {\n\tif (!query) return \"\";\n\tconst params = new URLSearchParams(query);\n\tconst text = params.toString();\n\treturn text ? `?${text}` : \"\";\n}\n\nfunction toMounts(spec: DockerContainerSpec): Array<Record<string, unknown>> {\n\treturn spec.mounts.map((mount) => ({\n\t\tType: mount.source.startsWith(\"/\") ? \"bind\" : \"volume\",\n\t\tSource: mount.source,\n\t\tTarget: mount.target,\n\t\tReadOnly: mount.readOnly ?? false,\n\t\t...(mount.volumeSubpath !== undefined\n\t\t\t? { VolumeOptions: { Subpath: mount.volumeSubpath, NoCopy: true } }\n\t\t\t: {}),\n\t}));\n}\n\nfunction requireVolumeSubpathApiVersion(value: unknown): string {\n\tif (typeof value === \"string\" && /^\\d+\\.\\d+$/.test(value)) {\n\t\tconst [major = 0, minor = 0] = value.split(\".\").map(Number);\n\t\tif (major > 1 || (major === 1 && minor >= 45)) return value;\n\t}\n\tthrow new Error(\"Scoped Docker volume mounts require Docker Engine 26.0 or newer (API 1.45+)\");\n}\n\nfunction toContainerCreateBody(spec: DockerContainerSpec): Record<string, unknown> {\n\treturn {\n\t\tImage: spec.image,\n\t\tEnv: spec.env,\n\t\tLabels: spec.labels,\n\t\t...(spec.command ? { Cmd: spec.command } : {}),\n\t\tHostConfig: {\n\t\t\tMounts: toMounts(spec),\n\t\t\tNetworkMode: spec.networkMode,\n\t\t\tPrivileged: spec.privileged,\n\t\t\t...(spec.runtime ? { Runtime: spec.runtime } : {}),\n\t\t\t...(spec.nanoCpus ? { NanoCpus: spec.nanoCpus } : {}),\n\t\t\t...(spec.memoryBytes ? { Memory: spec.memoryBytes } : {}),\n\t\t},\n\t};\n}\n\ninterface DockerInspectResponse {\n\tId: string;\n\tState?: { Running?: boolean };\n\tConfig?: { Labels?: Record<string, string> };\n}\n\ninterface DockerWaitResponse {\n\tStatusCode?: number;\n\tError?: { Message?: string };\n}\n\ninterface DockerCreateResponse {\n\tId: string;\n}\n\ninterface DockerListContainerResponse {\n\tId: string;\n\tLabels?: Record<string, string>;\n}\n\nfunction mapInspect(raw: DockerInspectResponse): DockerContainerInspect {\n\treturn {\n\t\tid: raw.Id,\n\t\trunning: raw.State?.Running === true,\n\t\tlabels: raw.Config?.Labels ?? {},\n\t};\n}\n\nfunction mapWait(raw: DockerWaitResponse): DockerContainerExit {\n\treturn {\n\t\tstatusCode: Number(raw.StatusCode ?? 0),\n\t\t...(raw.Error?.Message ? { error: raw.Error.Message } : {}),\n\t};\n}\n\n/** @internal */\nexport function createDockerEngineHttpClient(\n\toptions: DockerEngineHttpClientOptions,\n): DockerEngineClient {\n\tconst endpoint = parseDockerEngineSocket(options.socket);\n\tconst configuredApiVersion = options.apiVersion?.replace(/^v/, \"\");\n\tasync function request<T>(\n\t\tapiReq: DockerApiRequest,\n\t\tapiVersion = configuredApiVersion,\n\t): Promise<T> {\n\t\tconst prefix = apiVersion ? `/v${apiVersion}` : \"\";\n\t\tconst path = `${prefix}${apiReq.path}${encodeQuery(apiReq.query)}`;\n\t\tconst body = apiReq.body === undefined ? undefined : JSON.stringify(apiReq.body);\n\t\tconst response = await new Promise<http.IncomingMessage>((resolve, reject) => {\n\t\t\tconst req = http.request(\n\t\t\t\t{\n\t\t\t\t\tmethod: apiReq.method,\n\t\t\t\t\tpath: endpoint.baseUrl ? `${endpoint.baseUrl.pathname.replace(/\\/$/, \"\")}${path}` : path,\n\t\t\t\t\tsocketPath: endpoint.socketPath,\n\t\t\t\t\thostname: endpoint.baseUrl?.hostname,\n\t\t\t\t\tport: endpoint.baseUrl?.port,\n\t\t\t\t\theaders: body\n\t\t\t\t\t\t? { \"content-type\": \"application/json\", \"content-length\": Buffer.byteLength(body) }\n\t\t\t\t\t\t: undefined,\n\t\t\t\t},\n\t\t\t\tresolve,\n\t\t\t);\n\t\t\treq.on(\"error\", reject);\n\t\t\treq.end(body);\n\t\t});\n\t\tconst text = await readText(response);\n\t\tif ((response.statusCode ?? 500) >= 400) {\n\t\t\tthrow new DockerEngineHttpError(\n\t\t\t\t`Docker Engine ${apiReq.method} ${apiReq.path} failed with ${response.statusCode}: ${text}`,\n\t\t\t\tresponse.statusCode ?? 500,\n\t\t\t\ttext,\n\t\t\t);\n\t\t}\n\t\treturn (text ? JSON.parse(text) : undefined) as T;\n\t}\n\treturn {\n\t\tasync createContainer(spec) {\n\t\t\tlet apiVersion = configuredApiVersion;\n\t\t\tif (spec.mounts.some((mount) => mount.volumeSubpath !== undefined)) {\n\t\t\t\tconst version =\n\t\t\t\t\tconfiguredApiVersion ??\n\t\t\t\t\t(await request<{ ApiVersion?: string }>({ method: \"GET\", path: \"/version\" })).ApiVersion;\n\t\t\t\t// Pin this request to an API that understands Subpath. An older daemon\n\t\t\t\t// must reject the request, never ignore the option and mount the volume root.\n\t\t\t\tapiVersion = requireVolumeSubpathApiVersion(version);\n\t\t\t}\n\t\t\tconst raw = await request<DockerCreateResponse>(\n\t\t\t\t{\n\t\t\t\t\tmethod: \"POST\",\n\t\t\t\t\tpath: \"/containers/create\",\n\t\t\t\t\tquery: { name: spec.name },\n\t\t\t\t\tbody: toContainerCreateBody(spec),\n\t\t\t\t},\n\t\t\t\tapiVersion,\n\t\t\t);\n\t\t\treturn { id: raw.Id };\n\t\t},\n\t\tasync startContainer(id) {\n\t\t\tawait request({ method: \"POST\", path: `/containers/${encodeURIComponent(id)}/start` });\n\t\t},\n\t\tasync stopContainer(id, opts) {\n\t\t\tawait request({\n\t\t\t\tmethod: \"POST\",\n\t\t\t\tpath: `/containers/${encodeURIComponent(id)}/stop`,\n\t\t\t\tquery: { t: String(opts.timeoutSeconds) },\n\t\t\t});\n\t\t},\n\t\tasync removeContainer(id, opts) {\n\t\t\tawait request({\n\t\t\t\tmethod: \"DELETE\",\n\t\t\t\tpath: `/containers/${encodeURIComponent(id)}`,\n\t\t\t\tquery: { force: opts.force ? \"1\" : \"0\", v: \"1\" },\n\t\t\t});\n\t\t},\n\t\tasync inspectContainer(id) {\n\t\t\treturn mapInspect(\n\t\t\t\tawait request<DockerInspectResponse>({\n\t\t\t\t\tmethod: \"GET\",\n\t\t\t\t\tpath: `/containers/${encodeURIComponent(id)}/json`,\n\t\t\t\t}),\n\t\t\t);\n\t\t},\n\t\tasync listContainers(filter) {\n\t\t\tconst raw = await request<DockerListContainerResponse[]>({\n\t\t\t\tmethod: \"GET\",\n\t\t\t\tpath: \"/containers/json\",\n\t\t\t\tquery: {\n\t\t\t\t\tfilters: JSON.stringify({\n\t\t\t\t\t\tlabel: Object.entries(filter.labels).map(([key, value]) => `${key}=${value}`),\n\t\t\t\t\t}),\n\t\t\t\t},\n\t\t\t});\n\t\t\treturn raw.map((c) => ({ id: c.Id, labels: c.Labels ?? {} }));\n\t\t},\n\t\tasync waitContainer(id) {\n\t\t\treturn mapWait(\n\t\t\t\tawait request<DockerWaitResponse>({\n\t\t\t\t\tmethod: \"POST\",\n\t\t\t\t\tpath: `/containers/${encodeURIComponent(id)}/wait`,\n\t\t\t\t}),\n\t\t\t);\n\t\t},\n\t\tasync ensureVolume(name) {\n\t\t\tawait request({ method: \"POST\", path: \"/volumes/create\", body: { Name: name } });\n\t\t},\n\t\tasync removeVolume(name) {\n\t\t\ttry {\n\t\t\t\tawait request({ method: \"DELETE\", path: `/volumes/${encodeURIComponent(name)}` });\n\t\t\t} catch (error) {\n\t\t\t\tif (!isDockerEngineNotFoundError(error)) throw error;\n\t\t\t}\n\t\t},\n\t};\n}\n"],"mappings":";AAAA,OAAO,UAAU;AACjB,SAAS,QAAQ,gBAAgB;AAS1B,IAAM,wBAAN,cAAoC,MAAM;AAAA;AAAA,EAEhD,YACC,SAES,YAEA,MACR;AACD,UAAM,OAAO;AAJJ;AAEA;AAAA,EAGV;AAAA,EALU;AAAA,EAEA;AAIX;AAGO,SAAS,4BAA4B,OAAyB;AACpE,SAAO,iBAAiB,yBAAyB,MAAM,eAAe;AACvE;AAWO,SAAS,wBAAwB,OAAyC;AAChF,MAAI,MAAM,WAAW,SAAS,GAAG;AAChC,UAAM,aAAa,MAAM,MAAM,UAAU,MAAM;AAC/C,QAAI,CAAC,WAAW,WAAW,GAAG;AAC7B,YAAM,IAAI,MAAM,yDAAyD;AAC1E,WAAO,EAAE,WAAW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