@lostgradient/weft 0.18.0 → 0.19.0

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.
Files changed (167) hide show
  1. package/README.md +3 -1
  2. package/dist/cli/conformance.js +14 -18
  3. package/dist/cli/generated/operation-catalog.snapshot.json +258 -16
  4. package/dist/cli/generated/operation-client.generated.d.ts +30 -6
  5. package/dist/cli/generated/operation-client.generated.js +4 -0
  6. package/dist/core/context/child-workflow-pipe.d.ts +1 -1
  7. package/dist/core/context/child-workflow-pipe.js +1 -1
  8. package/dist/core/engine/construction.d.ts +2 -0
  9. package/dist/core/engine/construction.js +3 -0
  10. package/dist/core/engine/index.js +1 -0
  11. package/dist/core/engine/listing.d.ts +1 -0
  12. package/dist/core/engine/listing.js +6 -4
  13. package/dist/core/weft-error.d.ts +1 -1
  14. package/dist/core/weft-error.js +2 -1
  15. package/dist/core/worker-execution-dispatcher.d.ts +8 -0
  16. package/dist/core/worker-execution-dispatcher.js +4 -0
  17. package/dist/core/worker-execution-strategy-options.d.ts +16 -0
  18. package/dist/core/worker-execution-strategy.js +71 -89
  19. package/dist/core/worker-fault-handling.d.ts +45 -0
  20. package/dist/core/worker-fault-handling.js +88 -0
  21. package/dist/core/worker-protocol.d.ts +18 -1
  22. package/dist/core/worker-protocol.js +1 -1
  23. package/dist/core/worker-realm-readiness.d.ts +78 -0
  24. package/dist/core/worker-realm-readiness.js +127 -0
  25. package/dist/index.d.ts +3 -1
  26. package/dist/index.js +28 -1
  27. package/dist/json-schema.js +1 -1
  28. package/dist/runtime/portable.d.ts +14 -0
  29. package/dist/runtime/portable.js +10 -0
  30. package/dist/server/index.d.ts +71 -8
  31. package/dist/server/index.js +7 -3
  32. package/dist/server/operations/get-task-diagnostics.d.ts +43 -18
  33. package/dist/server/operations/get-task-diagnostics.js +87 -126
  34. package/dist/server/operations/get-worker-diagnostics.d.ts +177 -0
  35. package/dist/server/operations/get-worker-diagnostics.js +117 -0
  36. package/dist/server/operations/list-worker-registration-rejections.d.ts +79 -0
  37. package/dist/server/operations/list-worker-registration-rejections.js +60 -0
  38. package/dist/server/operations/list-workers.js +1 -3
  39. package/dist/server/operations/static-registrations.js +5 -20
  40. package/dist/server/rest-bindings.js +31 -2
  41. package/dist/server/runtime/authentication-bridge.js +6 -14
  42. package/dist/server/runtime/context.d.ts +23 -0
  43. package/dist/server/runtime/task-dispatch.d.ts +7 -1
  44. package/dist/server/runtime/task-dispatch.js +126 -55
  45. package/dist/server/runtime/task-ledger-completion.d.ts +68 -0
  46. package/dist/server/runtime/task-ledger-completion.js +72 -0
  47. package/dist/server/runtime/task-ledger-recovery.d.ts +55 -0
  48. package/dist/server/runtime/task-ledger-recovery.js +73 -0
  49. package/dist/server/runtime/task-ledger-runtime.d.ts +64 -0
  50. package/dist/server/runtime/task-ledger-runtime.js +34 -0
  51. package/dist/server/runtime/task-metrics.d.ts +6 -4
  52. package/dist/server/runtime/task-polling.d.ts +14 -12
  53. package/dist/server/runtime/task-polling.js +106 -82
  54. package/dist/server/runtime/task-reconciliation.d.ts +35 -8
  55. package/dist/server/runtime/task-reconciliation.js +75 -74
  56. package/dist/server/runtime/task-result-resolution.d.ts +2 -10
  57. package/dist/server/runtime/task-result-resolution.js +0 -67
  58. package/dist/server/runtime/task-result-view.d.ts +82 -0
  59. package/dist/server/runtime/task-result-view.js +48 -0
  60. package/dist/server/runtime/websocket-worker-messaging.d.ts +16 -0
  61. package/dist/server/runtime/websocket-worker-messaging.js +32 -0
  62. package/dist/server/runtime/websocket-worker-registration.d.ts +41 -0
  63. package/dist/server/runtime/websocket-worker-registration.js +134 -0
  64. package/dist/server/runtime/websocket-worker.d.ts +0 -1
  65. package/dist/server/runtime/websocket-worker.js +64 -116
  66. package/dist/server/serve-internals.d.ts +9 -6
  67. package/dist/server/serve-internals.js +14 -40
  68. package/dist/server/task-ledger-codec.d.ts +40 -0
  69. package/dist/server/task-ledger-codec.js +195 -0
  70. package/dist/server/task-ledger-keys.d.ts +13 -0
  71. package/dist/server/task-ledger-keys.js +5 -0
  72. package/dist/server/task-ledger-limits.d.ts +34 -0
  73. package/dist/server/task-ledger-limits.js +5 -0
  74. package/dist/server/task-ledger-transition-helpers.d.ts +38 -0
  75. package/dist/server/task-ledger-transition-helpers.js +42 -0
  76. package/dist/server/task-ledger-transitions-cancellation.d.ts +31 -0
  77. package/dist/server/task-ledger-transitions-cancellation.js +73 -0
  78. package/dist/server/task-ledger-transitions.d.ts +129 -0
  79. package/dist/server/task-ledger-transitions.js +162 -0
  80. package/dist/server/task-ledger-types.d.ts +220 -0
  81. package/dist/server/task-ledger-types.js +1 -0
  82. package/dist/server/task-ledger.d.ts +17 -0
  83. package/dist/server/task-ledger.js +24 -0
  84. package/dist/server/task-state.d.ts +25 -152
  85. package/dist/server/task-state.js +0 -188
  86. package/dist/server/worker-admission-policy.d.ts +70 -0
  87. package/dist/server/worker-admission-policy.js +0 -0
  88. package/dist/storage/compressed-storage.js +1 -1
  89. package/dist/storage/index.d.ts +0 -2
  90. package/dist/storage/interface.d.ts +0 -2
  91. package/dist/storage/interface.js +1 -1
  92. package/dist/storage/lmdb.js +1 -1
  93. package/dist/storage/memory.js +1 -1
  94. package/dist/storage/neon.js +1 -1
  95. package/dist/storage/postgres.js +1 -1
  96. package/dist/storage/resolve.js +1 -1
  97. package/dist/storage/scoped-storage.js +1 -1
  98. package/dist/storage/testing.js +1 -1
  99. package/dist/storage/turso.js +1 -1
  100. package/dist/storage/web-extension.js +2 -2
  101. package/dist/version.d.ts +1 -1
  102. package/dist/version.js +1 -1
  103. package/dist/web-extension.js +1 -1
  104. package/dist/worker/index.d.ts +2 -0
  105. package/dist/worker/index.js +30 -4
  106. package/dist/worker/manifest/canonical-json.d.ts +20 -0
  107. package/dist/worker/manifest/canonical-json.js +13 -0
  108. package/dist/worker/manifest/capabilities.d.ts +24 -0
  109. package/dist/worker/manifest/capabilities.js +74 -0
  110. package/dist/worker/manifest/content-digest.d.ts +20 -0
  111. package/dist/worker/manifest/content-digest.js +13 -0
  112. package/dist/worker/manifest/declared-shape-digest.d.ts +14 -0
  113. package/dist/worker/manifest/declared-shape-digest.js +4 -0
  114. package/dist/worker/manifest/digest.d.ts +82 -0
  115. package/dist/worker/manifest/digest.js +9 -0
  116. package/dist/worker/manifest/execution-identity.d.ts +92 -0
  117. package/dist/worker/manifest/execution-identity.js +36 -0
  118. package/dist/worker/manifest/failure.d.ts +59 -0
  119. package/dist/worker/manifest/failure.js +4 -0
  120. package/dist/worker/manifest/index.d.ts +22 -0
  121. package/dist/worker/manifest/index.js +23 -0
  122. package/dist/worker/manifest/internal-realm.d.ts +50 -0
  123. package/dist/worker/manifest/internal-realm.js +39 -0
  124. package/dist/worker/manifest/is-record.d.ts +12 -0
  125. package/dist/worker/manifest/is-record.js +6 -0
  126. package/dist/worker/manifest/json-scan.d.ts +26 -0
  127. package/dist/worker/manifest/json-scan.js +88 -0
  128. package/dist/worker/manifest/limits.d.ts +138 -0
  129. package/dist/worker/manifest/limits.js +1 -0
  130. package/dist/worker/manifest/normalize.d.ts +63 -0
  131. package/dist/worker/manifest/normalize.js +73 -0
  132. package/dist/worker/manifest/parse-json.d.ts +24 -0
  133. package/dist/worker/manifest/parse-json.js +15 -0
  134. package/dist/worker/manifest/parse.d.ts +86 -0
  135. package/dist/worker/manifest/parse.js +188 -0
  136. package/dist/worker/manifest/registry-contract-builder.d.ts +120 -0
  137. package/dist/worker/manifest/registry-contract-builder.js +65 -0
  138. package/dist/worker/manifest/types.d.ts +263 -0
  139. package/dist/worker/manifest/types.js +1 -0
  140. package/dist/worker/manifest/utf8.d.ts +13 -0
  141. package/dist/worker/manifest/utf8.js +7 -0
  142. package/dist/worker/options.d.ts +55 -8
  143. package/dist/worker/options.js +65 -9
  144. package/dist/worker/protocol-internals.d.ts +1 -2
  145. package/dist/worker/protocol-internals.js +0 -5
  146. package/dist/worker/protocol-messages.d.ts +33 -17
  147. package/dist/worker/protocol-schemas.d.ts +36 -74
  148. package/dist/worker/protocol-schemas.js +25 -18
  149. package/dist/worker/protocol-version.d.ts +18 -14
  150. package/dist/worker/protocol-version.js +1 -1
  151. package/dist/worker/protocol.js +1 -1
  152. package/dist/worker/registry/deployment-consistency.d.ts +78 -0
  153. package/dist/worker/registry/deployment-consistency.js +27 -0
  154. package/dist/worker/registry/drain.d.ts +14 -0
  155. package/dist/worker/registry/drain.js +24 -0
  156. package/dist/worker/registry/rejections.d.ts +31 -0
  157. package/dist/worker/registry/rejections.js +10 -0
  158. package/dist/worker/registry/summary.d.ts +0 -3
  159. package/dist/worker/registry/summary.js +2 -5
  160. package/dist/worker/registry/types.d.ts +10 -3
  161. package/dist/worker/registry.d.ts +47 -2
  162. package/dist/worker/registry.js +45 -32
  163. package/dist/workers/workflow-worker-entry.d.ts +12 -7
  164. package/dist/workers/workflow-worker-entry.js +9 -2
  165. package/package.json +3 -3
  166. package/dist/server/task-resolved-record.d.ts +0 -12
  167. package/dist/server/task-resolved-record.js +0 -35
@@ -1,4 +1,5 @@
1
1
  import type { ActivityInterceptor } from '../core/interceptor.ts';
2
+ import type { WorkerManifest } from './manifest/index.ts';
2
3
  import { type RegisterMessage, type RemoteWorkerCapabilities } from './protocol.ts';
3
4
  import type { RemoteWorkerWorkflowDefinition } from './workflow-activity-binding.ts';
4
5
  /**
@@ -9,6 +10,10 @@ import type { RemoteWorkerWorkflowDefinition } from './workflow-activity-binding
9
10
  * `${workflowType}.${activityName}` table that the protocol expects and
10
11
  * validates that each outer key matches the inner `workflow.name`. This is the
11
12
  * API the engine-side builder produces, and it is required.
13
+ *
14
+ * `deploymentName` and `buildId` are required — defaulting them risks a false
15
+ * deployment-conflict collision between two unrelated apps that both skip the
16
+ * option and happen to declare different workflows.
12
17
  */
13
18
  export interface RemoteWorkerOptions {
14
19
  serverUrl: string;
@@ -22,10 +27,35 @@ export interface RemoteWorkerOptions {
22
27
  concurrency?: number;
23
28
  queue?: string;
24
29
  disconnectTimeoutMs?: number;
25
- deploymentName?: string;
26
- buildId?: string;
30
+ /** Logical service this worker instance belongs to. */
31
+ deploymentName: string;
32
+ /** Operator-visible release this worker instance is running. */
33
+ buildId: string;
34
+ /**
35
+ * Trusted digest of the executable artifact this instance loaded. When
36
+ * omitted, a placeholder digest is derived from the declared workflow and
37
+ * activity names — tagged `declared-shape:...` so it is never mistaken for
38
+ * a real content digest. Real build tooling should supply this. Ignored
39
+ * when `manifest` is supplied, which carries its own `deployment.artifactDigest`.
40
+ */
41
+ artifactDigest?: string;
42
+ /**
43
+ * A complete, real manifest built ahead of time — typically by
44
+ * `buildWorkerManifestFromRegistry` (WFT-29) from the engine's canonical
45
+ * workflow registry. When supplied, it is advertised verbatim at
46
+ * registration instead of the `declared-shape:` placeholder this module
47
+ * otherwise derives from `workflows`, and every other manifest-shaping
48
+ * option (`deploymentName`, `buildId`, `artifactDigest`, `runtimeVersion`,
49
+ * `capabilities`) is ignored.
50
+ *
51
+ * The constructor requires `manifest.workflows` to declare exactly the
52
+ * same set of workflow types as `workflows` — a manifest advertising
53
+ * contracts this instance's dispatch table cannot execute (or omitting
54
+ * ones it can) is rejected at construction rather than at registration.
55
+ */
56
+ manifest?: WorkerManifest;
57
+ /** Runtime version string. Defaults to `detectRuntimeVersion()`. */
27
58
  runtimeVersion?: string;
28
- gitSha?: string;
29
59
  startedAt?: number;
30
60
  capabilities?: RemoteWorkerCapabilities;
31
61
  /**
@@ -58,9 +88,26 @@ export type PendingRegistration = {
58
88
  reject: (error: Error) => void;
59
89
  };
60
90
  /**
61
- * Build the `register` frame from the worker's resolved options and advertised
62
- * activity names. Optional identity/capability fields are omitted entirely when
63
- * undefined so the wire frame stays minimal. `workerId`, `concurrency`, and
64
- * `queue` are resolved to defaults by the constructor before this runs.
91
+ * Copy a caller-supplied `workflows` map so later mutation of the caller's
92
+ * own object cannot desync the manifest a future `connect()` advertises from
93
+ * the activity dispatch table the constructor already built from the same
94
+ * shape. `buildRegisterMessage` re-derives the manifest from `options.workflows`
95
+ * on every `connect()`; without this copy that field stays a live reference
96
+ * to the caller's object for the instance's whole lifetime.
97
+ */
98
+ export declare function snapshotWorkflows(workflows: Record<string, RemoteWorkerWorkflowDefinition>): Record<string, RemoteWorkerWorkflowDefinition>;
99
+ /**
100
+ * Assert that a caller-supplied real manifest (`options.manifest`) declares
101
+ * exactly the workflow types the SDK's own `workflows` dispatch table
102
+ * declares — no more, no fewer. Called once, at construction, so a mismatch
103
+ * between build-tool output and the live dispatch table fails fast rather
104
+ * than surfacing later as a confusing registration rejection or a routed
105
+ * task this instance cannot actually execute.
106
+ */
107
+ export declare function assertManifestMatchesWorkflows(manifest: WorkerManifest, workflows: Record<string, RemoteWorkerWorkflowDefinition>): void;
108
+ /**
109
+ * Build the `register` frame from the worker's resolved options. `workerId`
110
+ * and `concurrency` are resolved to defaults by the constructor before this
111
+ * runs; `manifest` carries every identity claim protocol v3 validates.
65
112
  */
66
- export declare function buildRegisterMessage(workerId: string, activities: readonly string[], options: RemoteWorkerOptions): RegisterMessage;
113
+ export declare function buildRegisterMessage(workerId: string, options: RemoteWorkerOptions): RegisterMessage;
@@ -1,19 +1,75 @@
1
+ import { DEFAULT_WORKFLOW_VERSION } from "../core/versioning.js";
2
+ import { detectRuntime, detectRuntimeVersion } from "../runtime/portable.js";
3
+ import { VERSION } from "../version.js";
4
+ import { declaredShapeDigest } from "./manifest/declared-shape-digest.js";
5
+ import { WORKER_MANIFEST_VERSION } from "./manifest/index.js";
1
6
  import {
2
7
  REMOTE_WORKER_PROTOCOL_VERSION
3
8
  } from "./protocol.js";
4
- export function buildRegisterMessage(workerId, activities, options) {
9
+ export function snapshotWorkflows(workflows) {
10
+ const snapshot = {};
11
+ for (const [workflowType, workflow] of Object.entries(workflows))
12
+ snapshot[workflowType] = { name: workflow.name, activities: { ...workflow.activities } };
13
+ return snapshot;
14
+ }
15
+ function buildWorkflowContract(workflowType, workflow) {
16
+ const activityNames = Object.keys(workflow.activities).toSorted(), workflowShapeDigest = declaredShapeDigest(`${workflowType}:${activityNames.join(",")}`), activities = {};
17
+ for (const activityName of activityNames) {
18
+ const activityShapeDigest = declaredShapeDigest(`${workflowType}.${activityName}`);
19
+ activities[activityName] = {
20
+ contractHash: activityShapeDigest,
21
+ implementationRevision: activityShapeDigest
22
+ };
23
+ }
24
+ return {
25
+ workflowVersion: DEFAULT_WORKFLOW_VERSION,
26
+ workflowRevision: workflowShapeDigest,
27
+ contractHash: workflowShapeDigest,
28
+ activities
29
+ };
30
+ }
31
+ function deriveArtifactDigest(workflows) {
32
+ const qualifiedNames = Object.entries(workflows).flatMap(([workflowType, workflow]) => Object.keys(workflow.activities).map((activityName) => `${workflowType}.${activityName}`)).toSorted();
33
+ return declaredShapeDigest(qualifiedNames.join(","));
34
+ }
35
+ export function assertManifestMatchesWorkflows(manifest, workflows) {
36
+ const manifestTypes = new Set(Object.keys(manifest.workflows)), declaredTypes = new Set(Object.keys(workflows)), missingFromManifest = [...declaredTypes].filter((type) => !manifestTypes.has(type)).toSorted(), extraInManifest = [...manifestTypes].filter((type) => !declaredTypes.has(type)).toSorted();
37
+ if (missingFromManifest.length === 0 && extraInManifest.length === 0)
38
+ return;
39
+ const parts = [];
40
+ if (missingFromManifest.length > 0)
41
+ parts.push(`missing from manifest: ${missingFromManifest.join(", ")}`);
42
+ if (extraInManifest.length > 0)
43
+ parts.push(`not in workflows: ${extraInManifest.join(", ")}`);
44
+ throw Error(`RemoteWorkerOptions.manifest.workflows must declare exactly the workflow types in \`workflows\` (${parts.join("; ")}).`);
45
+ }
46
+ function buildManifest(options) {
47
+ if (options.manifest !== void 0)
48
+ return options.manifest;
49
+ const workflows = {};
50
+ for (const [workflowType, workflow] of Object.entries(options.workflows))
51
+ workflows[workflowType] = buildWorkflowContract(workflowType, workflow);
52
+ return {
53
+ manifestVersion: WORKER_MANIFEST_VERSION,
54
+ protocolVersion: REMOTE_WORKER_PROTOCOL_VERSION,
55
+ sdkVersion: VERSION,
56
+ runtime: { name: detectRuntime(), version: options.runtimeVersion ?? detectRuntimeVersion() },
57
+ deployment: {
58
+ name: options.deploymentName,
59
+ buildId: options.buildId,
60
+ artifactDigest: options.artifactDigest ?? deriveArtifactDigest(options.workflows)
61
+ },
62
+ workflows,
63
+ capabilities: options.capabilities ?? {}
64
+ };
65
+ }
66
+ export function buildRegisterMessage(workerId, options) {
5
67
  return {
6
68
  type: "register",
7
69
  protocolVersion: REMOTE_WORKER_PROTOCOL_VERSION,
8
70
  workerId,
9
- activities: [...activities],
71
+ manifest: buildManifest(options),
10
72
  ...options.concurrency !== void 0 ? { concurrency: options.concurrency } : {},
11
- ...options.queue !== void 0 ? { queue: options.queue } : {},
12
- ...options.deploymentName !== void 0 ? { deploymentName: options.deploymentName } : {},
13
- ...options.buildId !== void 0 ? { buildId: options.buildId } : {},
14
- ...options.runtimeVersion !== void 0 ? { runtimeVersion: options.runtimeVersion } : {},
15
- ...options.gitSha !== void 0 ? { gitSha: options.gitSha } : {},
16
- ...options.startedAt !== void 0 ? { startedAt: options.startedAt } : {},
17
- ...options.capabilities !== void 0 ? { capabilities: options.capabilities } : {}
73
+ ...options.startedAt !== void 0 ? { startedAt: options.startedAt } : {}
18
74
  };
19
75
  }
@@ -9,7 +9,7 @@
9
9
  *
10
10
  * @module worker/protocol-internals
11
11
  */
12
- import type { ProtocolErrorMessage, RegisterErrorMessage, RemoteWorkerCapabilities, RemoteWorkerJsonValue } from './protocol-messages.ts';
12
+ import type { ProtocolErrorMessage, RegisterErrorMessage, RemoteWorkerJsonValue } from './protocol-messages.ts';
13
13
  /**
14
14
  * Protocol parse failure with a machine-readable code.
15
15
  *
@@ -63,7 +63,6 @@ export declare function isRemoteWorkerJsonValue(value: unknown): value is Remote
63
63
  export declare function isNonEmptyString(value: unknown): value is string;
64
64
  export declare function isStringArray(value: unknown): value is string[];
65
65
  export declare function isStringRecord(value: unknown): value is Record<string, string>;
66
- export declare function isRemoteWorkerCapabilities(value: unknown): value is RemoteWorkerCapabilities;
67
66
  export declare function isFiniteNumber(value: unknown): value is number;
68
67
  export declare function protocolFailure(code: RemoteWorkerProtocolFailure['code'], message: string, requestedProtocolVersion?: number): RemoteWorkerProtocolParseResult<never>;
69
68
  export type FieldSpec = readonly [
@@ -21,11 +21,6 @@ export function isStringRecord(value) {
21
21
  return !1;
22
22
  return Object.values(value).every((entry) => typeof entry === "string");
23
23
  }
24
- export function isRemoteWorkerCapabilities(value) {
25
- if (!isRecord(value))
26
- return !1;
27
- return Object.values(value).every(isRemoteWorkerJsonValue);
28
- }
29
24
  export function isFiniteNumber(value) {
30
25
  return typeof value === "number" && Number.isFinite(value);
31
26
  }
@@ -37,8 +37,14 @@ export type RemoteWorkerCapabilities = Readonly<Record<string, RemoteWorkerJsonV
37
37
  /**
38
38
  * Worker registration message sent immediately after opening a worker stream.
39
39
  *
40
- * Each entry of `activities` is a qualified `${workflowType}.${activityName}`
41
- * name; bare activity names were retired in protocol v2.
40
+ * Protocol v3 replaced the parallel top-level identity fields
41
+ * (`activities`, `queue`, `deploymentName`, `buildId`, `runtimeVersion`,
42
+ * `gitSha`, `capabilities`) with a single `manifest`. The server derives
43
+ * routing activities from `manifest.workflows`, reads the queue from the
44
+ * worker-stream URL rather than a field a worker could disagree with, and
45
+ * validates every other identity claim through `parseWorkerManifest()`.
46
+ * `manifest` is `unknown` here deliberately — this module only proves wire
47
+ * shape; deep manifest validation happens where the manifest is accepted.
42
48
  *
43
49
  * @example
44
50
  * ```ts
@@ -46,9 +52,9 @@ export type RemoteWorkerCapabilities = Readonly<Record<string, RemoteWorkerJsonV
46
52
  *
47
53
  * const message: RegisterMessage = {
48
54
  * type: 'register',
49
- * protocolVersion: 2,
55
+ * protocolVersion: 3,
50
56
  * workerId: 'worker-1',
51
- * activities: ['welcome.sendEmail'],
57
+ * manifest: { manifestVersion: 1 },
52
58
  * };
53
59
  * ```
54
60
  */
@@ -56,15 +62,9 @@ export type RegisterMessage = {
56
62
  readonly type: 'register';
57
63
  readonly protocolVersion: RemoteWorkerProtocolVersion;
58
64
  readonly workerId: string;
59
- readonly activities: readonly string[];
65
+ readonly manifest: unknown;
60
66
  readonly concurrency?: number;
61
- readonly queue?: string;
62
- readonly deploymentName?: string;
63
- readonly buildId?: string;
64
- readonly runtimeVersion?: string;
65
- readonly gitSha?: string;
66
67
  readonly startedAt?: number;
67
- readonly capabilities?: RemoteWorkerCapabilities;
68
68
  };
69
69
  /**
70
70
  * Worker heartbeat message.
@@ -157,17 +157,24 @@ export type CancelledTaskResultMessage = {
157
157
  /**
158
158
  * Registration acknowledgement sent after a worker is accepted.
159
159
  *
160
+ * `acceptedManifestDigest` is the digest of the canonical manifest the server
161
+ * actually stored — a worker can confirm the server saw the manifest it
162
+ * intended to send. `serverCapabilities` replaces echoing `activities` back
163
+ * (the worker already knows what it sent); it is a bounded list of
164
+ * server-side capability names, currently always empty.
165
+ *
160
166
  * @example
161
167
  * ```ts
162
168
  * import type { RegisterAckMessage } from '@lostgradient/weft/worker-protocol';
163
169
  *
164
170
  * const message: RegisterAckMessage = {
165
171
  * type: 'registerAck',
166
- * protocolVersion: 2,
172
+ * protocolVersion: 3,
167
173
  * workerId: 'worker-1',
168
174
  * queue: 'default',
169
- * activities: ['welcome.sendEmail'],
170
175
  * concurrency: 10,
176
+ * acceptedManifestDigest: 'sha256:41d0e2',
177
+ * serverCapabilities: [],
171
178
  * };
172
179
  * ```
173
180
  */
@@ -176,12 +183,21 @@ export type RegisterAckMessage = {
176
183
  readonly protocolVersion: RemoteWorkerProtocolVersion;
177
184
  readonly workerId: string;
178
185
  readonly queue: string;
179
- readonly activities: readonly string[];
180
186
  readonly concurrency: number;
187
+ readonly acceptedManifestDigest: string;
188
+ readonly serverCapabilities: readonly string[];
181
189
  };
182
190
  /**
183
191
  * Registration rejection sent before closing an unsupported worker stream.
184
192
  *
193
+ * `deployment_conflict` means the manifest's `(deploymentName, buildId)` pair
194
+ * was already registered with a different `artifactDigest`.
195
+ * `registration_rejected` means a configured `WorkerAdmissionPolicy` refused
196
+ * the worker. `supportedProtocolVersions` describes the *other* peer's
197
+ * supported versions — for a worker parsing a rejection from a server
198
+ * running a different release, that is deliberately not narrowed to
199
+ * `RemoteWorkerProtocolVersion`.
200
+ *
185
201
  * @example
186
202
  * ```ts
187
203
  * import type { RegisterErrorMessage } from '@lostgradient/weft/worker-protocol';
@@ -190,16 +206,16 @@ export type RegisterAckMessage = {
190
206
  * type: 'registerError',
191
207
  * code: 'unsupported_protocol_version',
192
208
  * message: 'Unsupported RemoteWorker protocol version: 1',
193
- * supportedProtocolVersions: [2],
209
+ * supportedProtocolVersions: [3],
194
210
  * requestedProtocolVersion: 1,
195
211
  * };
196
212
  * ```
197
213
  */
198
214
  export type RegisterErrorMessage = {
199
215
  readonly type: 'registerError';
200
- readonly code: 'invalid_registration' | 'unsupported_protocol_version';
216
+ readonly code: 'invalid_registration' | 'unsupported_protocol_version' | 'deployment_conflict' | 'registration_rejected';
201
217
  readonly message: string;
202
- readonly supportedProtocolVersions: readonly RemoteWorkerProtocolVersion[];
218
+ readonly supportedProtocolVersions: readonly number[];
203
219
  readonly requestedProtocolVersion?: number;
204
220
  };
205
221
  /**
@@ -26,7 +26,7 @@ export declare const REMOTE_WORKER_MESSAGE_SCHEMAS: {
26
26
  readonly register: {
27
27
  readonly type: "object";
28
28
  readonly additionalProperties: false;
29
- readonly required: readonly ["type", "protocolVersion", "workerId", "activities"];
29
+ readonly required: readonly ["type", "protocolVersion", "workerId", "manifest"];
30
30
  readonly properties: {
31
31
  readonly type: {
32
32
  readonly const: "register";
@@ -36,42 +36,17 @@ export declare const REMOTE_WORKER_MESSAGE_SCHEMAS: {
36
36
  readonly type: "string";
37
37
  readonly minLength: 1;
38
38
  };
39
- readonly activities: {
40
- readonly type: "array";
41
- readonly items: {
42
- readonly type: "string";
43
- readonly minLength: 1;
44
- };
39
+ readonly manifest: {
40
+ readonly type: "object";
45
41
  };
46
42
  readonly concurrency: {
47
43
  readonly type: "number";
48
44
  readonly minimum: 1;
49
45
  readonly maximum: 1000;
50
46
  };
51
- readonly queue: {
52
- readonly type: "string";
53
- readonly minLength: 1;
54
- };
55
- readonly deploymentName: {
56
- readonly type: "string";
57
- readonly minLength: 1;
58
- };
59
- readonly buildId: {
60
- readonly type: "string";
61
- readonly minLength: 1;
62
- };
63
- readonly runtimeVersion: {
64
- readonly type: "string";
65
- readonly minLength: 1;
66
- };
67
- readonly gitSha: {
68
- readonly type: "string";
69
- readonly minLength: 1;
70
- };
71
47
  readonly startedAt: {
72
48
  readonly type: "number";
73
49
  };
74
- readonly capabilities: JsonSchemaObject;
75
50
  };
76
51
  };
77
52
  readonly heartbeat: {
@@ -220,7 +195,7 @@ export declare const REMOTE_WORKER_MESSAGE_SCHEMAS: {
220
195
  readonly registerAck: {
221
196
  readonly type: "object";
222
197
  readonly additionalProperties: false;
223
- readonly required: readonly ["type", "protocolVersion", "workerId", "queue", "activities", "concurrency"];
198
+ readonly required: readonly ["type", "protocolVersion", "workerId", "queue", "concurrency", "acceptedManifestDigest", "serverCapabilities"];
224
199
  readonly properties: {
225
200
  readonly type: {
226
201
  readonly const: "registerAck";
@@ -234,18 +209,22 @@ export declare const REMOTE_WORKER_MESSAGE_SCHEMAS: {
234
209
  readonly type: "string";
235
210
  readonly minLength: 1;
236
211
  };
237
- readonly activities: {
212
+ readonly concurrency: {
213
+ readonly type: "number";
214
+ readonly minimum: 1;
215
+ readonly maximum: 1000;
216
+ };
217
+ readonly acceptedManifestDigest: {
218
+ readonly type: "string";
219
+ readonly minLength: 1;
220
+ };
221
+ readonly serverCapabilities: {
238
222
  readonly type: "array";
239
223
  readonly items: {
240
224
  readonly type: "string";
241
225
  readonly minLength: 1;
242
226
  };
243
227
  };
244
- readonly concurrency: {
245
- readonly type: "number";
246
- readonly minimum: 1;
247
- readonly maximum: 1000;
248
- };
249
228
  };
250
229
  };
251
230
  readonly registerError: {
@@ -257,14 +236,16 @@ export declare const REMOTE_WORKER_MESSAGE_SCHEMAS: {
257
236
  readonly const: "registerError";
258
237
  };
259
238
  readonly code: {
260
- readonly enum: readonly ["invalid_registration", "unsupported_protocol_version"];
239
+ readonly enum: readonly ["invalid_registration", "unsupported_protocol_version", "deployment_conflict", "registration_rejected"];
261
240
  };
262
241
  readonly message: {
263
242
  readonly type: "string";
264
243
  };
265
244
  readonly supportedProtocolVersions: {
266
245
  readonly type: "array";
267
- readonly items: JsonSchemaObject;
246
+ readonly items: {
247
+ readonly type: "number";
248
+ };
268
249
  };
269
250
  readonly requestedProtocolVersion: {
270
251
  readonly type: "number";
@@ -332,7 +313,7 @@ export declare const REMOTE_WORKER_PROTOCOL_JSON_SCHEMA: {
332
313
  readonly register: {
333
314
  readonly type: "object";
334
315
  readonly additionalProperties: false;
335
- readonly required: readonly ["type", "protocolVersion", "workerId", "activities"];
316
+ readonly required: readonly ["type", "protocolVersion", "workerId", "manifest"];
336
317
  readonly properties: {
337
318
  readonly type: {
338
319
  readonly const: "register";
@@ -342,42 +323,17 @@ export declare const REMOTE_WORKER_PROTOCOL_JSON_SCHEMA: {
342
323
  readonly type: "string";
343
324
  readonly minLength: 1;
344
325
  };
345
- readonly activities: {
346
- readonly type: "array";
347
- readonly items: {
348
- readonly type: "string";
349
- readonly minLength: 1;
350
- };
326
+ readonly manifest: {
327
+ readonly type: "object";
351
328
  };
352
329
  readonly concurrency: {
353
330
  readonly type: "number";
354
331
  readonly minimum: 1;
355
332
  readonly maximum: 1000;
356
333
  };
357
- readonly queue: {
358
- readonly type: "string";
359
- readonly minLength: 1;
360
- };
361
- readonly deploymentName: {
362
- readonly type: "string";
363
- readonly minLength: 1;
364
- };
365
- readonly buildId: {
366
- readonly type: "string";
367
- readonly minLength: 1;
368
- };
369
- readonly runtimeVersion: {
370
- readonly type: "string";
371
- readonly minLength: 1;
372
- };
373
- readonly gitSha: {
374
- readonly type: "string";
375
- readonly minLength: 1;
376
- };
377
334
  readonly startedAt: {
378
335
  readonly type: "number";
379
336
  };
380
- readonly capabilities: JsonSchemaObject;
381
337
  };
382
338
  };
383
339
  readonly heartbeat: {
@@ -526,7 +482,7 @@ export declare const REMOTE_WORKER_PROTOCOL_JSON_SCHEMA: {
526
482
  readonly registerAck: {
527
483
  readonly type: "object";
528
484
  readonly additionalProperties: false;
529
- readonly required: readonly ["type", "protocolVersion", "workerId", "queue", "activities", "concurrency"];
485
+ readonly required: readonly ["type", "protocolVersion", "workerId", "queue", "concurrency", "acceptedManifestDigest", "serverCapabilities"];
530
486
  readonly properties: {
531
487
  readonly type: {
532
488
  readonly const: "registerAck";
@@ -540,18 +496,22 @@ export declare const REMOTE_WORKER_PROTOCOL_JSON_SCHEMA: {
540
496
  readonly type: "string";
541
497
  readonly minLength: 1;
542
498
  };
543
- readonly activities: {
499
+ readonly concurrency: {
500
+ readonly type: "number";
501
+ readonly minimum: 1;
502
+ readonly maximum: 1000;
503
+ };
504
+ readonly acceptedManifestDigest: {
505
+ readonly type: "string";
506
+ readonly minLength: 1;
507
+ };
508
+ readonly serverCapabilities: {
544
509
  readonly type: "array";
545
510
  readonly items: {
546
511
  readonly type: "string";
547
512
  readonly minLength: 1;
548
513
  };
549
514
  };
550
- readonly concurrency: {
551
- readonly type: "number";
552
- readonly minimum: 1;
553
- readonly maximum: 1000;
554
- };
555
515
  };
556
516
  };
557
517
  readonly registerError: {
@@ -563,14 +523,16 @@ export declare const REMOTE_WORKER_PROTOCOL_JSON_SCHEMA: {
563
523
  readonly const: "registerError";
564
524
  };
565
525
  readonly code: {
566
- readonly enum: readonly ["invalid_registration", "unsupported_protocol_version"];
526
+ readonly enum: readonly ["invalid_registration", "unsupported_protocol_version", "deployment_conflict", "registration_rejected"];
567
527
  };
568
528
  readonly message: {
569
529
  readonly type: "string";
570
530
  };
571
531
  readonly supportedProtocolVersions: {
572
532
  readonly type: "array";
573
- readonly items: JsonSchemaObject;
533
+ readonly items: {
534
+ readonly type: "number";
535
+ };
574
536
  };
575
537
  readonly requestedProtocolVersion: {
576
538
  readonly type: "number";
@@ -14,23 +14,14 @@ export const REMOTE_WORKER_MESSAGE_SCHEMAS = {
14
14
  register: {
15
15
  type: "object",
16
16
  additionalProperties: !1,
17
- required: ["type", "protocolVersion", "workerId", "activities"],
17
+ required: ["type", "protocolVersion", "workerId", "manifest"],
18
18
  properties: {
19
19
  type: { const: "register" },
20
20
  protocolVersion: protocolVersionSchema,
21
21
  workerId: { type: "string", minLength: 1 },
22
- activities: {
23
- type: "array",
24
- items: { type: "string", minLength: 1 }
25
- },
22
+ manifest: { type: "object" },
26
23
  concurrency: { type: "number", minimum: 1, maximum: 1000 },
27
- queue: { type: "string", minLength: 1 },
28
- deploymentName: { type: "string", minLength: 1 },
29
- buildId: { type: "string", minLength: 1 },
30
- runtimeVersion: { type: "string", minLength: 1 },
31
- gitSha: { type: "string", minLength: 1 },
32
- startedAt: { type: "number" },
33
- capabilities: jsonObjectSchema
24
+ startedAt: { type: "number" }
34
25
  }
35
26
  },
36
27
  heartbeat: {
@@ -118,17 +109,26 @@ export const REMOTE_WORKER_MESSAGE_SCHEMAS = {
118
109
  registerAck: {
119
110
  type: "object",
120
111
  additionalProperties: !1,
121
- required: ["type", "protocolVersion", "workerId", "queue", "activities", "concurrency"],
112
+ required: [
113
+ "type",
114
+ "protocolVersion",
115
+ "workerId",
116
+ "queue",
117
+ "concurrency",
118
+ "acceptedManifestDigest",
119
+ "serverCapabilities"
120
+ ],
122
121
  properties: {
123
122
  type: { const: "registerAck" },
124
123
  protocolVersion: protocolVersionSchema,
125
124
  workerId: { type: "string", minLength: 1 },
126
125
  queue: { type: "string", minLength: 1 },
127
- activities: {
126
+ concurrency: { type: "number", minimum: 1, maximum: 1000 },
127
+ acceptedManifestDigest: { type: "string", minLength: 1 },
128
+ serverCapabilities: {
128
129
  type: "array",
129
130
  items: { type: "string", minLength: 1 }
130
- },
131
- concurrency: { type: "number", minimum: 1, maximum: 1000 }
131
+ }
132
132
  }
133
133
  },
134
134
  registerError: {
@@ -137,11 +137,18 @@ export const REMOTE_WORKER_MESSAGE_SCHEMAS = {
137
137
  required: ["type", "code", "message", "supportedProtocolVersions"],
138
138
  properties: {
139
139
  type: { const: "registerError" },
140
- code: { enum: ["invalid_registration", "unsupported_protocol_version"] },
140
+ code: {
141
+ enum: [
142
+ "invalid_registration",
143
+ "unsupported_protocol_version",
144
+ "deployment_conflict",
145
+ "registration_rejected"
146
+ ]
147
+ },
141
148
  message: { type: "string" },
142
149
  supportedProtocolVersions: {
143
150
  type: "array",
144
- items: protocolVersionSchema
151
+ items: { type: "number" }
145
152
  },
146
153
  requestedProtocolVersion: { type: "number" }
147
154
  }