@lostgradient/weft 0.15.0 → 0.17.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 (147) hide show
  1. package/README.md +1 -1
  2. package/dist/alerting/alert-manager.d.ts +5 -3
  3. package/dist/alerting/alert-manager.js +26 -5
  4. package/dist/alerting/index.d.ts +1 -1
  5. package/dist/alerting/types.d.ts +17 -13
  6. package/dist/alerting/types.js +5 -0
  7. package/dist/cli/api.js +5 -19
  8. package/dist/cli/console.d.ts +12 -0
  9. package/dist/cli/console.js +62 -0
  10. package/dist/cli/generated/operation-catalog.snapshot.json +71 -0
  11. package/dist/cli/generated/operation-client.generated.d.ts +15 -2
  12. package/dist/cli/generated/operation-client.generated.js +2 -0
  13. package/dist/cli/help-text.d.ts +1 -1
  14. package/dist/cli/help-text.js +1 -0
  15. package/dist/cli/index.d.ts +1 -0
  16. package/dist/cli/index.js +1 -0
  17. package/dist/cli/json-input.d.ts +20 -0
  18. package/dist/cli/json-input.js +33 -0
  19. package/dist/cli/parse-arguments.js +2 -0
  20. package/dist/cli/schedule.js +7 -9
  21. package/dist/cli/types.d.ts +1 -0
  22. package/dist/cli/workflow-commands.js +5 -25
  23. package/dist/cli-main.js +4 -2
  24. package/dist/core/engine/disposal.js +7 -0
  25. package/dist/core/engine/engine-runtime-helpers.d.ts +3 -1
  26. package/dist/core/engine/engine-runtime-helpers.js +2 -2
  27. package/dist/core/engine/errors.d.ts +20 -0
  28. package/dist/core/engine/errors.js +8 -0
  29. package/dist/core/engine/index.d.ts +39 -14
  30. package/dist/core/engine/index.js +84 -9
  31. package/dist/core/engine/inline-launch-queue.d.ts +6 -2
  32. package/dist/core/engine/inline-launch-queue.js +41 -6
  33. package/dist/core/engine/internals.d.ts +2 -0
  34. package/dist/core/engine/lease-manager.d.ts +3 -2
  35. package/dist/core/engine/lease-manager.js +7 -3
  36. package/dist/core/engine/operations-time.js +6 -0
  37. package/dist/core/execution-strategy.d.ts +8 -0
  38. package/dist/core/inline-execution-strategy.d.ts +1 -0
  39. package/dist/core/inline-execution-strategy.js +33 -20
  40. package/dist/core/weft-error.d.ts +1 -1
  41. package/dist/core/weft-error.js +1 -0
  42. package/dist/core/worker-execution-strategy.d.ts +2 -0
  43. package/dist/core/worker-execution-strategy.js +7 -2
  44. package/dist/core/worker-turn-watchdog.d.ts +4 -1
  45. package/dist/core/worker-turn-watchdog.js +9 -4
  46. package/dist/diagnostics/recommendations.js +1 -9
  47. package/dist/http.js +2 -2
  48. package/dist/index.d.ts +2 -2
  49. package/dist/index.js +1 -0
  50. package/dist/indexeddb.js +1 -1
  51. package/dist/json-schema.js +1 -1
  52. package/dist/mcp/tools.js +1 -3
  53. package/dist/server/authorization-scope.d.ts +1 -1
  54. package/dist/server/authorization-scope.js +0 -2
  55. package/dist/server/dashboard-assets.d.ts +37 -0
  56. package/dist/server/dashboard-assets.js +209 -0
  57. package/dist/server/index.d.ts +10 -1
  58. package/dist/server/index.js +11 -2
  59. package/dist/server/interactive-operations.js +1 -0
  60. package/dist/server/operations/aggregate-workflows.js +0 -7
  61. package/dist/server/operations/async-activity.js +5 -24
  62. package/dist/server/operations/bulk-cancel-workflows.js +3 -8
  63. package/dist/server/operations/bulk-delete-workflows.js +3 -8
  64. package/dist/server/operations/bulk-mutate-workflow-tags.js +3 -8
  65. package/dist/server/operations/bulk-operation-helpers.d.ts +2 -10
  66. package/dist/server/operations/bulk-operation-helpers.js +0 -6
  67. package/dist/server/operations/bulk-retry-failed-workflows.js +3 -8
  68. package/dist/server/operations/bulk-signal-workflows.js +3 -8
  69. package/dist/server/operations/cancel-schedule.js +1 -3
  70. package/dist/server/operations/cancel-workflow.js +1 -3
  71. package/dist/server/operations/create-schedule.js +21 -49
  72. package/dist/server/operations/fork-workflow.js +2 -3
  73. package/dist/server/operations/get-checkpoint-at.js +1 -6
  74. package/dist/server/operations/get-registry.js +1 -7
  75. package/dist/server/operations/get-retention-overview.js +2 -15
  76. package/dist/server/operations/get-review.js +2 -15
  77. package/dist/server/operations/get-schedule.js +2 -8
  78. package/dist/server/operations/get-stream-chunks.js +2 -6
  79. package/dist/server/operations/get-system-lease.js +1 -7
  80. package/dist/server/operations/get-system-metrics.js +0 -4
  81. package/dist/server/operations/get-task-diagnostics.js +2 -13
  82. package/dist/server/operations/get-update-result.js +1 -6
  83. package/dist/server/operations/get-workflow-attributes.js +2 -15
  84. package/dist/server/operations/get-workflow-events.js +2 -15
  85. package/dist/server/operations/get-workflow-observability.js +2 -5
  86. package/dist/server/operations/get-workflow-result.js +0 -7
  87. package/dist/server/operations/get-workflow-timeline.js +1 -6
  88. package/dist/server/operations/get-workflow.d.ts +3 -6
  89. package/dist/server/operations/get-workflow.js +2 -12
  90. package/dist/server/operations/list-alerts.d.ts +29 -0
  91. package/dist/server/operations/list-alerts.js +47 -0
  92. package/dist/server/operations/list-checkpoints.js +1 -6
  93. package/dist/server/operations/list-reviews.js +0 -7
  94. package/dist/server/operations/list-schedules.js +3 -8
  95. package/dist/server/operations/list-task-queues.js +0 -4
  96. package/dist/server/operations/list-workers.js +0 -4
  97. package/dist/server/operations/list-workflows.js +0 -7
  98. package/dist/server/operations/pause-schedule.js +1 -3
  99. package/dist/server/operations/purge-workflows.js +2 -5
  100. package/dist/server/operations/query-workflow.js +4 -15
  101. package/dist/server/operations/replay-workflow.js +2 -6
  102. package/dist/server/operations/resume-schedule.js +1 -3
  103. package/dist/server/operations/resume-workflow.js +1 -3
  104. package/dist/server/operations/schedule-faults.d.ts +9 -1
  105. package/dist/server/operations/schedule-faults.js +51 -0
  106. package/dist/server/operations/set-workflow-attributes.js +3 -15
  107. package/dist/server/operations/signal-workflow.js +3 -12
  108. package/dist/server/operations/single-workflow-tag-mutation.js +0 -7
  109. package/dist/server/operations/start-or-signal-workflow.js +2 -3
  110. package/dist/server/operations/start-workflow.js +2 -3
  111. package/dist/server/operations/storage-capabilities.js +1 -3
  112. package/dist/server/operations/storage.js +7 -13
  113. package/dist/server/operations/submit-review-decision.js +3 -12
  114. package/dist/server/operations/suspend-workflow.js +1 -3
  115. package/dist/server/operations/timeout-workflow.js +1 -3
  116. package/dist/server/operations/update-schedule.js +7 -56
  117. package/dist/server/operations/update-workflow.js +2 -3
  118. package/dist/server/operations/worker-drain.js +0 -8
  119. package/dist/server/rest-binding.d.ts +3 -2
  120. package/dist/server/rest-bindings.js +3 -0
  121. package/dist/server/route-model.d.ts +2 -0
  122. package/dist/server/route-model.js +1 -1
  123. package/dist/server/runtime/task-reconciliation.d.ts +10 -1
  124. package/dist/server/runtime/task-reconciliation.js +26 -2
  125. package/dist/server/serve-internals.js +12 -6
  126. package/dist/service-worker/index.d.ts +4 -1
  127. package/dist/service-worker/index.js +2 -2
  128. package/dist/service-worker/setup.d.ts +20 -0
  129. package/dist/service-worker/setup.js +5 -5
  130. package/dist/storage/bun-sql.js +13 -31
  131. package/dist/storage/indexeddb.js +28 -48
  132. package/dist/storage/lmdb.js +1 -1
  133. package/dist/storage/memory.js +1 -1
  134. package/dist/storage/neon.js +2 -2
  135. package/dist/storage/postgres.js +2 -2
  136. package/dist/storage/resolve.js +1 -1
  137. package/dist/storage/scoped-storage.js +1 -1
  138. package/dist/storage/testing.d.ts +6 -3
  139. package/dist/storage/testing.js +1 -1
  140. package/dist/storage/turso.js +2 -2
  141. package/dist/version.d.ts +1 -1
  142. package/dist/version.js +1 -1
  143. package/dist/web-extension.js +1 -1
  144. package/dist/worker/protocol-schemas.d.ts +2 -2
  145. package/dist/worker/protocol-schemas.js +2 -2
  146. package/dist/worker/protocol.js +1 -1
  147. package/package.json +5 -1
@@ -87,12 +87,6 @@ function extractListWorkflowsInput(request) {
87
87
  filter.include = includes;
88
88
  return filter;
89
89
  }
90
- function shapeListWorkflowsSuccess(result) {
91
- return new Response(JSON.stringify(result), {
92
- status: 200,
93
- headers: { "Content-Type": "application/json" }
94
- });
95
- }
96
90
  function shapeListWorkflowsFault(fault) {
97
91
  if (fault.code === "Unprocessable")
98
92
  return shapeRestFault(fault, { status: 400 });
@@ -119,6 +113,5 @@ export const listWorkflowsRestBinding = {
119
113
  },
120
114
  extractInput: async (request) => extractListWorkflowsInput(request),
121
115
  success: { kind: "json", status: 200 },
122
- shapeSuccess: (output) => shapeListWorkflowsSuccess(output),
123
116
  shapeFault: shapeListWorkflowsFault
124
117
  };
@@ -1,6 +1,5 @@
1
1
  import { z } from "zod";
2
2
  import { defineOperation } from "../operation-registry.js";
3
- import { shapeRestFault } from "./operation-helpers.js";
4
3
  import { mapScheduleErrorToFault } from "./schedule-faults.js";
5
4
  const pauseScheduleInput = z.object({
6
5
  scheduleId: z.string().min(1)
@@ -38,6 +37,5 @@ export const pauseScheduleOperation = defineOperation({
38
37
  extractInput: async (_request, pathParams) => ({
39
38
  scheduleId: pathParams.id ?? ""
40
39
  }),
41
- success: { kind: "empty", status: 204 },
42
- shapeFault: shapeRestFault
40
+ success: { kind: "empty", status: 204 }
43
41
  };
@@ -8,8 +8,7 @@ import {
8
8
  parseBulkListFilterFromBody,
9
9
  readOptionalJsonBody
10
10
  } from "./bulk-filter-helpers.js";
11
- import { shapeBulkJsonSuccess } from "./bulk-operation-helpers.js";
12
- import { invalidParamsFault, shapeRestFault } from "./operation-helpers.js";
11
+ import { invalidParamsFault } from "./operation-helpers.js";
13
12
  const purgeWorkflowsOutput = z.unknown();
14
13
  export const purgeWorkflowsOperation = defineOperation({
15
14
  name: "weft.workflows.purge",
@@ -51,7 +50,5 @@ export const purgeWorkflowsOperation = defineOperation({
51
50
  throw invalidParamsFault(faultMessage(error));
52
51
  }
53
52
  },
54
- success: { kind: "json", status: 200 },
55
- shapeSuccess: (output) => shapeBulkJsonSuccess(output),
56
- shapeFault: shapeRestFault
53
+ success: { kind: "json", status: 200 }
57
54
  };
@@ -1,7 +1,7 @@
1
1
  import { z } from "zod";
2
2
  import { defineOperation } from "../operation-registry.js";
3
3
  import { readRestTextBody } from "../rest-body.js";
4
- import { invalidParamsFault, shapeRestFault } from "./operation-helpers.js";
4
+ import { invalidParamsFault } from "./operation-helpers.js";
5
5
  const queryWorkflowInput = z.object({
6
6
  workflowId: z.string().min(1),
7
7
  queryName: z.string().min(1),
@@ -39,14 +39,7 @@ export const queryWorkflowOperation = defineOperation({
39
39
  };
40
40
  }
41
41
  }
42
- });
43
- function shapeQueryWorkflowSuccess(result) {
44
- return new Response(JSON.stringify(result), {
45
- status: 200,
46
- headers: { "Content-Type": "application/json" }
47
- });
48
- }
49
- export const queryWorkflowRestBinding = {
42
+ }), queryWorkflowRestBinding = {
50
43
  method: "GET",
51
44
  path: "/v1/workflows/:id/query/:name",
52
45
  pathParamNames: ["id", "name"],
@@ -59,9 +52,7 @@ export const queryWorkflowRestBinding = {
59
52
  workflowId: pathParams.id ?? "",
60
53
  queryName: pathParams.name ?? ""
61
54
  }),
62
- success: { kind: "json", status: 200 },
63
- shapeSuccess: (output) => shapeQueryWorkflowSuccess(output),
64
- shapeFault: shapeRestFault
55
+ success: { kind: "json", status: 200 }
65
56
  }, queryWorkflowWithInputRestBinding = {
66
57
  method: "POST",
67
58
  path: "/v1/workflows/:id/query/:name",
@@ -94,7 +85,5 @@ export const queryWorkflowRestBinding = {
94
85
  input: body.input
95
86
  };
96
87
  },
97
- success: { kind: "json", status: 200 },
98
- shapeSuccess: (output) => shapeQueryWorkflowSuccess(output),
99
- shapeFault: shapeRestFault
88
+ success: { kind: "json", status: 200 }
100
89
  };
@@ -1,7 +1,7 @@
1
1
  import { z } from "zod";
2
2
  import { negotiatedResponse } from "../handler/response-helpers.js";
3
3
  import { defineOperation } from "../operation-registry.js";
4
- import { invalidParamsFault, shapeRestFault } from "./operation-helpers.js";
4
+ import { invalidParamsFault } from "./operation-helpers.js";
5
5
  const replayWorkflowInput = z.object({
6
6
  workflowId: z.string().min(1),
7
7
  step: z.union([z.string(), z.number()])
@@ -44,9 +44,6 @@ export const replayWorkflowOperation = defineOperation({
44
44
  return replay;
45
45
  }
46
46
  });
47
- function shapeReplayWorkflowFault(fault) {
48
- return shapeRestFault(fault);
49
- }
50
47
  function shapeReplayWorkflowSuccess(output, request) {
51
48
  return negotiatedResponse(request, output, 200);
52
49
  }
@@ -64,6 +61,5 @@ export const replayWorkflowRestBinding = {
64
61
  step: pathParams.step ?? "0"
65
62
  }),
66
63
  success: { kind: "json", status: 200 },
67
- shapeSuccess: (output, request) => shapeReplayWorkflowSuccess(output, request),
68
- shapeFault: shapeReplayWorkflowFault
64
+ shapeSuccess: (output, request) => shapeReplayWorkflowSuccess(output, request)
69
65
  };
@@ -1,6 +1,5 @@
1
1
  import { z } from "zod";
2
2
  import { defineOperation } from "../operation-registry.js";
3
- import { shapeRestFault } from "./operation-helpers.js";
4
3
  import { mapScheduleErrorToFault } from "./schedule-faults.js";
5
4
  const resumeScheduleInput = z.object({
6
5
  scheduleId: z.string().min(1)
@@ -38,6 +37,5 @@ export const resumeScheduleOperation = defineOperation({
38
37
  extractInput: async (_request, pathParams) => ({
39
38
  scheduleId: pathParams.id ?? ""
40
39
  }),
41
- success: { kind: "empty", status: 204 },
42
- shapeFault: shapeRestFault
40
+ success: { kind: "empty", status: 204 }
43
41
  };
@@ -1,5 +1,4 @@
1
1
  import { z } from "zod";
2
- import { shapeRestFault } from "./operation-helpers.js";
3
2
  import {
4
3
  createSingleWorkflowControlOperation,
5
4
  extractWorkflowIdFromPath
@@ -35,6 +34,5 @@ export const resumeWorkflowOperation = createSingleWorkflowControlOperation({
35
34
  workflowId: { kind: "path", pathParam: "id" }
36
35
  },
37
36
  extractInput: async (_request, pathParams) => extractWorkflowIdFromPath(pathParams),
38
- success: { kind: "json", status: 200 },
39
- shapeFault: shapeRestFault
37
+ success: { kind: "json", status: 200 }
40
38
  };
@@ -1,6 +1,14 @@
1
- import type { ScheduleSpec } from '../../core/types.ts';
1
+ import type { ScheduleSpec, ScheduleUpdateOptions } from '../../core/types.ts';
2
2
  import type { OperationFault } from '../operation-fault.ts';
3
3
  export { isOperationFault } from './operation-helpers.ts';
4
+ export type ScheduleMutableOptionsInput = {
5
+ description?: unknown;
6
+ overlap?: unknown;
7
+ backfill?: unknown;
8
+ jitter?: unknown;
9
+ };
10
+ /** Validate the mutable schedule options shared by create and update. */
11
+ export declare function validateScheduleMutableOptions(input: ScheduleMutableOptionsInput): ScheduleUpdateOptions;
4
12
  export declare function mapScheduleErrorToFault(scheduleId: string, error: unknown): OperationFault;
5
13
  /**
6
14
  * Validate the mutually exclusive schedule cadence fields (`cronExpression` or
@@ -1,5 +1,56 @@
1
+ import {
2
+ isValidScheduleOverlapPolicy,
3
+ normalizeScheduleUpdateOptions
4
+ } from "../../core/engine/validation/schedule.js";
1
5
  import { invalidParamsFault } from "./operation-helpers.js";
2
6
  export { isOperationFault } from "./operation-helpers.js";
7
+ export function validateScheduleMutableOptions(input) {
8
+ const description = validateScheduleDescription(input.description), overlap = validateScheduleOverlap(input.overlap), backfill = validateScheduleBackfill(input.backfill), jitter = validateScheduleJitter(input.jitter);
9
+ return {
10
+ ...description !== void 0 ? { description } : {},
11
+ ...overlap !== void 0 ? { overlap } : {},
12
+ ...backfill !== void 0 ? { backfill } : {},
13
+ ...jitter !== void 0 ? { jitter } : {}
14
+ };
15
+ }
16
+ function validateScheduleDescription(value) {
17
+ if (value === void 0)
18
+ return;
19
+ if (typeof value !== "string")
20
+ throw invalidParamsFault('Field "description" must be a string');
21
+ return value;
22
+ }
23
+ function validateScheduleOverlap(value) {
24
+ if (value === void 0)
25
+ return;
26
+ if (!isValidScheduleOverlapPolicy(value))
27
+ throw invalidParamsFault('Field "overlap" must be one of skip, queue, cancel-running, allow');
28
+ return value;
29
+ }
30
+ function validateScheduleBackfill(value) {
31
+ if (value === void 0)
32
+ return;
33
+ if (typeof value !== "boolean")
34
+ throw invalidParamsFault('Field "backfill" must be a boolean');
35
+ return value;
36
+ }
37
+ function validateScheduleJitter(value) {
38
+ if (value === void 0)
39
+ return;
40
+ if (typeof value !== "string" && typeof value !== "number")
41
+ throw invalidParamsFault('Field "jitter" must be a duration string or a number of milliseconds');
42
+ try {
43
+ normalizeScheduleUpdateOptions({ jitter: value });
44
+ } catch (error) {
45
+ const message = error instanceof Error ? error.message : String(error);
46
+ throw invalidParamsFault(formatJitterValidationMessage(message));
47
+ }
48
+ return value;
49
+ }
50
+ function formatJitterValidationMessage(message) {
51
+ const enginePrefix = "Invalid options.jitter: ", hasEnginePrefix = message.startsWith(enginePrefix), wireDetail = (hasEnginePrefix ? message.slice(enginePrefix.length) : message).replaceAll("options.jitter", 'Field "jitter"');
52
+ return hasEnginePrefix ? `Field "jitter" is invalid: ${wireDetail}` : wireDetail;
53
+ }
3
54
  export function mapScheduleErrorToFault(scheduleId, error) {
4
55
  const message = error instanceof Error ? error.message : String(error), normalizedMessage = message.toLowerCase();
5
56
  if (normalizedMessage.includes("not found"))
@@ -1,7 +1,7 @@
1
1
  import { z } from "zod";
2
2
  import { defineOperation } from "../operation-registry.js";
3
3
  import { readRestJsonBody } from "../rest-body.js";
4
- import { isOperationFault, shapeRestFault } from "./operation-helpers.js";
4
+ import { isOperationFault } from "./operation-helpers.js";
5
5
  const setWorkflowAttributesInput = z.object({
6
6
  workflowId: z.string().min(1),
7
7
  attributes: z.unknown().optional()
@@ -32,17 +32,7 @@ export const setWorkflowAttributesOperation = defineOperation({
32
32
  };
33
33
  }
34
34
  }
35
- });
36
- function shapeSetWorkflowAttributesSuccess(output) {
37
- return new Response(JSON.stringify(output), {
38
- status: 200,
39
- headers: { "Content-Type": "application/json" }
40
- });
41
- }
42
- function shapeSetWorkflowAttributesFault(fault) {
43
- return shapeRestFault(fault);
44
- }
45
- export const setWorkflowAttributesRestBinding = {
35
+ }), setWorkflowAttributesRestBinding = {
46
36
  method: "PATCH",
47
37
  path: "/v1/workflows/:id/attributes",
48
38
  pathParamNames: ["id"],
@@ -64,7 +54,5 @@ export const setWorkflowAttributesRestBinding = {
64
54
  attributes: typeof body === "object" ? body.attributes : void 0
65
55
  };
66
56
  },
67
- success: { kind: "json", status: 200 },
68
- shapeSuccess: (output) => shapeSetWorkflowAttributesSuccess(output),
69
- shapeFault: shapeSetWorkflowAttributesFault
57
+ success: { kind: "json", status: 200 }
70
58
  };
@@ -1,7 +1,7 @@
1
1
  import { z } from "zod";
2
2
  import { isSignalIdWithinByteLimit } from "../../core/signal-id.js";
3
3
  import { readRestJsonBody } from "../rest-body.js";
4
- import { isOperationFault, shapeRestFault } from "./operation-helpers.js";
4
+ import { isOperationFault } from "./operation-helpers.js";
5
5
  import {
6
6
  createSingleWorkflowControlOperation,
7
7
  extractWorkflowIdFromPath
@@ -27,14 +27,7 @@ export const signalWorkflowOperation = createSingleWorkflowControlOperation({
27
27
  await engine.signal(input.workflowId, input.signalName, input.payload, input.signalId === void 0 ? void 0 : { signalId: input.signalId });
28
28
  return { ok: !0 };
29
29
  }
30
- });
31
- function shapeSignalWorkflowSuccess(output) {
32
- return new Response(JSON.stringify(output), {
33
- status: 200,
34
- headers: { "Content-Type": "application/json" }
35
- });
36
- }
37
- export const signalWorkflowRestBinding = {
30
+ }), signalWorkflowRestBinding = {
38
31
  method: "POST",
39
32
  path: "/v1/workflows/:id/signal/:name",
40
33
  pathParamNames: ["id", "name"],
@@ -57,7 +50,5 @@ export const signalWorkflowRestBinding = {
57
50
  ...signalId === void 0 ? {} : { signalId }
58
51
  };
59
52
  },
60
- success: { kind: "json", status: 200 },
61
- shapeSuccess: (output) => shapeSignalWorkflowSuccess(output),
62
- shapeFault: shapeRestFault
53
+ success: { kind: "json", status: 200 }
63
54
  };
@@ -66,16 +66,9 @@ export function createSingleWorkflowTagMutationRestBinding(configuration) {
66
66
  };
67
67
  },
68
68
  success: { kind: "json", status: 200 },
69
- shapeSuccess: shapeSingleWorkflowTagMutationSuccess,
70
69
  shapeFault: shapeSingleWorkflowTagMutationFault
71
70
  };
72
71
  }
73
- function shapeSingleWorkflowTagMutationSuccess(output) {
74
- return new Response(JSON.stringify(output), {
75
- status: 200,
76
- headers: { "Content-Type": "application/json" }
77
- });
78
- }
79
72
  function shapeSingleWorkflowTagMutationFault(fault) {
80
73
  if (fault.code === "Unprocessable")
81
74
  return shapeRestFault(fault, { status: 400 });
@@ -9,7 +9,7 @@ import { runtimeWorkflowEngine } from "../../core/runtime-workflow-engine.js";
9
9
  import { isSignalIdWithinByteLimit } from "../../core/signal-id.js";
10
10
  import { StartWorkflowValidationError } from "../../core/start-workflow-validation.js";
11
11
  import { defineOperation } from "../operation-registry.js";
12
- import { invalidParamsFault, shapeRestFault } from "./operation-helpers.js";
12
+ import { invalidParamsFault } from "./operation-helpers.js";
13
13
  import { buildStartOrSignalWorkflowOptions } from "./start-workflow-options.js";
14
14
  import {
15
15
  extractSharedStartWorkflowRestFields,
@@ -136,6 +136,5 @@ export const startOrSignalWorkflowOperation = defineOperation({
136
136
  onTerminalConflict: record.onTerminalConflict
137
137
  };
138
138
  },
139
- success: { kind: "json", status: 201 },
140
- shapeFault: shapeRestFault
139
+ success: { kind: "json", status: 201 }
141
140
  };
@@ -7,7 +7,7 @@ import {
7
7
  import { runtimeWorkflowEngine } from "../../core/runtime-workflow-engine.js";
8
8
  import { StartWorkflowValidationError } from "../../core/start-workflow-validation.js";
9
9
  import { defineOperation } from "../operation-registry.js";
10
- import { invalidParamsFault, shapeRestFault } from "./operation-helpers.js";
10
+ import { invalidParamsFault } from "./operation-helpers.js";
11
11
  import { buildSharedStartWorkflowOptions } from "./start-workflow-options.js";
12
12
  import {
13
13
  extractSharedStartWorkflowRestFields,
@@ -99,6 +99,5 @@ export const startWorkflowOperation = defineOperation({
99
99
  extractInput: async (request, _pathParams, context) => {
100
100
  return extractSharedStartWorkflowRestFields(await parseStartWorkflowRequestRecord(request, context));
101
101
  },
102
- success: { kind: "json", status: 201 },
103
- shapeFault: shapeRestFault
102
+ success: { kind: "json", status: 201 }
104
103
  };
@@ -1,6 +1,5 @@
1
1
  import { z } from "zod";
2
2
  import { defineOperation } from "../operation-registry.js";
3
- import { shapeRestFault } from "./operation-helpers.js";
4
3
  const storageCapabilitiesInput = z.object({}), storageCapabilitiesOutput = z.object({
5
4
  persistence: z.enum(["ephemeral", "local", "remote"]),
6
5
  readAfterWrite: z.enum(["linearizable", "session", "eventual"]),
@@ -33,6 +32,5 @@ export const storageCapabilitiesOperation = defineOperation({
33
32
  inputSources: {},
34
33
  extractInput: async () => ({}),
35
34
  success: { kind: "json", status: 200 },
36
- shapeSuccess: (output) => Response.json(output),
37
- shapeFault: shapeRestFault
35
+ shapeSuccess: (output) => Response.json(output)
38
36
  };
@@ -11,7 +11,7 @@ import { raiseFault } from "../operation-catalog.js";
11
11
  import { defineOperation } from "../operation-registry.js";
12
12
  import { isAuthenticated } from "../principal.js";
13
13
  import { readRestBodyBounded, readRestJsonBody } from "../rest-body.js";
14
- import { invalidParamsFault, isOperationFault, shapeRestFault } from "./operation-helpers.js";
14
+ import { invalidParamsFault, isOperationFault } from "./operation-helpers.js";
15
15
  const rawStorageAccess = {
16
16
  kind: "scoped",
17
17
  scopes: { kind: "anyOf", scopes: ["storage:admin"] }
@@ -283,8 +283,7 @@ export const storageGetOperation = defineOperation({
283
283
  },
284
284
  extractInput: async (_request, pathParams) => ({ key: storageKeyFromPath(pathParams) }),
285
285
  success: { kind: "streaming", mediaType: "application/octet-stream" },
286
- shapeSuccess: (output) => createBinaryResponse(output),
287
- shapeFault: shapeRestFault
286
+ shapeSuccess: (output) => createBinaryResponse(output)
288
287
  }, storagePutRestBinding = {
289
288
  method: "PUT",
290
289
  path: "/v1/storage/:key",
@@ -299,8 +298,7 @@ export const storageGetOperation = defineOperation({
299
298
  value: await readRestBodyBounded(request, context)
300
299
  }),
301
300
  success: { kind: "empty", status: 204 },
302
- shapeSuccess: createNoContentResponse,
303
- shapeFault: shapeRestFault
301
+ shapeSuccess: createNoContentResponse
304
302
  }, storageDeleteRestBinding = {
305
303
  method: "DELETE",
306
304
  path: "/v1/storage/:key",
@@ -311,8 +309,7 @@ export const storageGetOperation = defineOperation({
311
309
  },
312
310
  extractInput: async (_request, pathParams) => ({ key: storageKeyFromPath(pathParams) }),
313
311
  success: { kind: "empty", status: 204 },
314
- shapeSuccess: createNoContentResponse,
315
- shapeFault: shapeRestFault
312
+ shapeSuccess: createNoContentResponse
316
313
  }, storageScanRestBinding = {
317
314
  method: "GET",
318
315
  path: "/v1/storage",
@@ -329,8 +326,7 @@ export const storageGetOperation = defineOperation({
329
326
  },
330
327
  extractInput: async (request) => extractStorageScanInput(request),
331
328
  success: { kind: "streaming", mediaType: "application/x-ndjson" },
332
- shapeSuccess: (output) => createNdjsonResponse(output),
333
- shapeFault: shapeRestFault
329
+ shapeSuccess: (output) => createNdjsonResponse(output)
334
330
  }, storageBatchRestBinding = {
335
331
  method: "POST",
336
332
  path: "/v1/storage/-/batch",
@@ -341,8 +337,7 @@ export const storageGetOperation = defineOperation({
341
337
  },
342
338
  extractInput: async (request, _pathParams, context) => readJsonRequestBody(request, context),
343
339
  success: { kind: "empty", status: 204 },
344
- shapeSuccess: createNoContentResponse,
345
- shapeFault: shapeRestFault
340
+ shapeSuccess: createNoContentResponse
346
341
  }, storageConditionalBatchRestBinding = {
347
342
  method: "POST",
348
343
  path: "/v1/storage/-/conditional-batch",
@@ -354,6 +349,5 @@ export const storageGetOperation = defineOperation({
354
349
  },
355
350
  extractInput: async (request, _pathParams, context) => readJsonRequestBody(request, context),
356
351
  success: { kind: "json", status: 200 },
357
- shapeSuccess: (output) => Response.json(output),
358
- shapeFault: shapeRestFault
352
+ shapeSuccess: (output) => Response.json(output)
359
353
  };
@@ -1,7 +1,7 @@
1
1
  import { z } from "zod";
2
2
  import { defineOperation } from "../operation-registry.js";
3
3
  import { readRestJsonBody } from "../rest-body.js";
4
- import { isOperationFault, shapeRestFault } from "./operation-helpers.js";
4
+ import { isOperationFault } from "./operation-helpers.js";
5
5
  const VALID_DECISIONS = [
6
6
  "approved",
7
7
  "rejected",
@@ -92,14 +92,7 @@ export const submitReviewDecisionOperation = defineOperation({
92
92
  mapReviewDecisionError(error, input.reviewId);
93
93
  }
94
94
  }
95
- });
96
- function shapeSubmitReviewDecisionSuccess(output) {
97
- return new Response(JSON.stringify(output), {
98
- status: 200,
99
- headers: { "Content-Type": "application/json" }
100
- });
101
- }
102
- export const submitReviewDecisionRestBinding = {
95
+ }), submitReviewDecisionRestBinding = {
103
96
  method: "POST",
104
97
  path: "/v1/reviews/:reviewId/decision",
105
98
  pathParamNames: ["reviewId"],
@@ -127,7 +120,5 @@ export const submitReviewDecisionRestBinding = {
127
120
  workflowId: record.workflowId
128
121
  };
129
122
  },
130
- success: { kind: "json", status: 200 },
131
- shapeSuccess: (output) => shapeSubmitReviewDecisionSuccess(output),
132
- shapeFault: shapeRestFault
123
+ success: { kind: "json", status: 200 }
133
124
  };
@@ -1,6 +1,5 @@
1
1
  import { z } from "zod";
2
2
  import { WorkflowSuspendNotSupportedError } from "../../core/engine/errors.js";
3
- import { shapeRestFault } from "./operation-helpers.js";
4
3
  import {
5
4
  createSingleWorkflowControlOperation,
6
5
  extractWorkflowIdFromPath
@@ -31,6 +30,5 @@ export const suspendWorkflowOperation = createSingleWorkflowControlOperation({
31
30
  workflowId: { kind: "path", pathParam: "id" }
32
31
  },
33
32
  extractInput: async (_request, pathParams) => extractWorkflowIdFromPath(pathParams),
34
- success: { kind: "empty", status: 204 },
35
- shapeFault: shapeRestFault
33
+ success: { kind: "empty", status: 204 }
36
34
  };
@@ -1,5 +1,4 @@
1
1
  import { z } from "zod";
2
- import { shapeRestFault } from "./operation-helpers.js";
3
2
  import {
4
3
  createSingleWorkflowControlOperation,
5
4
  extractWorkflowIdFromPath
@@ -29,6 +28,5 @@ export const timeoutWorkflowOperation = createSingleWorkflowControlOperation({
29
28
  workflowId: { kind: "path", pathParam: "id" }
30
29
  },
31
30
  extractInput: async (_request, pathParams) => extractWorkflowIdFromPath(pathParams),
32
- success: { kind: "empty", status: 204 },
33
- shapeFault: shapeRestFault
31
+ success: { kind: "empty", status: 204 }
34
32
  };
@@ -1,8 +1,10 @@
1
1
  import { z } from "zod";
2
- import { normalizeScheduleUpdateOptions } from "../../core/engine/validation/schedule.js";
3
2
  import { defineOperation } from "../operation-registry.js";
4
- import { invalidParamsFault, shapeRestFault } from "./operation-helpers.js";
5
- import { mapScheduleErrorToFault, validateScheduleInputCadence } from "./schedule-faults.js";
3
+ import {
4
+ mapScheduleErrorToFault,
5
+ validateScheduleInputCadence,
6
+ validateScheduleMutableOptions
7
+ } from "./schedule-faults.js";
6
8
  import {
7
9
  extractSharedScheduleRestFields,
8
10
  parseScheduleRestBodyRequestRecord
@@ -16,56 +18,6 @@ const updateScheduleInput = z.object({
16
18
  backfill: z.unknown().optional(),
17
19
  jitter: z.unknown().optional()
18
20
  });
19
- function isScheduleOverlapPolicy(value) {
20
- return value === "skip" || value === "queue" || value === "cancel-running" || value === "allow";
21
- }
22
- function validateDescription(value) {
23
- if (value === void 0)
24
- return;
25
- if (typeof value !== "string")
26
- throw invalidParamsFault('Field "description" must be a string');
27
- return value;
28
- }
29
- function validateOverlap(value) {
30
- if (value === void 0)
31
- return;
32
- if (typeof value !== "string" || !isScheduleOverlapPolicy(value))
33
- throw invalidParamsFault('Field "overlap" must be one of skip, queue, cancel-running, allow');
34
- return value;
35
- }
36
- function validateBackfill(value) {
37
- if (value === void 0)
38
- return;
39
- if (typeof value !== "boolean")
40
- throw invalidParamsFault('Field "backfill" must be a boolean');
41
- return value;
42
- }
43
- function formatJitterValidationMessage(message) {
44
- const enginePrefix = "Invalid options.jitter: ", hasEnginePrefix = message.startsWith(enginePrefix), wireDetail = (hasEnginePrefix ? message.slice(enginePrefix.length) : message).replaceAll("options.jitter", 'Field "jitter"');
45
- return hasEnginePrefix ? `Field "jitter" is invalid: ${wireDetail}` : wireDetail;
46
- }
47
- function validateJitter(value) {
48
- if (value === void 0)
49
- return;
50
- if (typeof value !== "string" && typeof value !== "number")
51
- throw invalidParamsFault('Field "jitter" must be a duration string or a number of milliseconds');
52
- try {
53
- normalizeScheduleUpdateOptions({ jitter: value });
54
- } catch (error) {
55
- const message = error instanceof Error ? error.message : String(error);
56
- throw invalidParamsFault(formatJitterValidationMessage(message));
57
- }
58
- return value;
59
- }
60
- function validateScheduleUpdateOptions(input) {
61
- const description = validateDescription(input.description), overlap = validateOverlap(input.overlap), backfill = validateBackfill(input.backfill), jitter = validateJitter(input.jitter);
62
- return {
63
- ...description !== void 0 ? { description } : {},
64
- ...overlap !== void 0 ? { overlap } : {},
65
- ...backfill !== void 0 ? { backfill } : {},
66
- ...jitter !== void 0 ? { jitter } : {}
67
- };
68
- }
69
21
  export const updateScheduleOperation = defineOperation({
70
22
  name: "weft.schedules.update",
71
23
  mcpExposable: !1,
@@ -80,7 +32,7 @@ export const updateScheduleOperation = defineOperation({
80
32
  transports: { http: !0, jsonRpcHttp: !0, jsonRpcWebSocket: !0, jsonRpcStdio: !0 },
81
33
  unknownKeyPolicy: { http: "strip", jsonRpc: "reject" },
82
34
  invoke: async ({ input, engine }) => {
83
- const typedEngine = engine, spec = validateScheduleInputCadence(input), options = validateScheduleUpdateOptions(input);
35
+ const typedEngine = engine, spec = validateScheduleInputCadence(input), options = validateScheduleMutableOptions(input);
84
36
  try {
85
37
  await typedEngine.updateSchedule(input.scheduleId, spec, options);
86
38
  return null;
@@ -109,6 +61,5 @@ export const updateScheduleOperation = defineOperation({
109
61
  ...extractSharedScheduleRestFields(record)
110
62
  };
111
63
  },
112
- success: { kind: "empty", status: 204 },
113
- shapeFault: shapeRestFault
64
+ success: { kind: "empty", status: 204 }
114
65
  };
@@ -6,7 +6,7 @@ import {
6
6
  } from "../../core/updates.js";
7
7
  import { defineOperation } from "../operation-registry.js";
8
8
  import { readRestJsonBody } from "../rest-body.js";
9
- import { isOperationFault, shapeRestFault } from "./operation-helpers.js";
9
+ import { isOperationFault } from "./operation-helpers.js";
10
10
  const DEFAULT_UPDATE_TIMEOUT_MS = 30000, updateWorkflowInput = z.object({
11
11
  workflowId: z.string().min(1),
12
12
  updateName: z.string().min(1),
@@ -108,6 +108,5 @@ export const updateWorkflowOperation = defineOperation({
108
108
  ...idempotencyKey !== void 0 ? { idempotencyKey } : {}
109
109
  };
110
110
  },
111
- success: { kind: "json", status: 200 },
112
- shapeFault: shapeRestFault
111
+ success: { kind: "json", status: 200 }
113
112
  };
@@ -159,7 +159,6 @@ function createWorkerDrainRestBinding(method, operationName) {
159
159
  ...method === "POST" ? await readDrainBody(request, context) : {}
160
160
  }),
161
161
  success: { kind: "json", status: 200 },
162
- shapeSuccess: shapeDrainSuccess,
163
162
  shapeFault: shapeOperationFaultAsJson
164
163
  };
165
164
  }
@@ -178,16 +177,9 @@ function createDeploymentDrainRestBinding(method, operationName) {
178
177
  ...method === "POST" ? await readDrainBody(request, context) : {}
179
178
  }),
180
179
  success: { kind: "json", status: 200 },
181
- shapeSuccess: shapeDrainSuccess,
182
180
  shapeFault: shapeOperationFaultAsJson
183
181
  };
184
182
  }
185
- function shapeDrainSuccess(output) {
186
- return new Response(JSON.stringify(output), {
187
- status: 200,
188
- headers: { "Content-Type": "application/json" }
189
- });
190
- }
191
183
  async function readDrainBody(request, context) {
192
184
  const text = await readRestTextBody(request, context);
193
185
  if (text.trim().length === 0)
@@ -98,8 +98,9 @@ export type RestBinding<Input, Output> = {
98
98
  readonly success: ResponseShape;
99
99
  /**
100
100
  * Optional override for response construction. When absent, transport
101
- * adapters default to `Response.json(output, { status: success.status })`
102
- * (or `new Response(null, { status })` for `empty`). Provide this
101
+ * adapters default to `jsonResponse(output, success.status)`, which emits
102
+ * `JSON.stringify(output)` with `Content-Type: application/json` (or
103
+ * `new Response(null, { status })` for `empty`). Provide this
103
104
  * when the wire representation differs from `output` verbatim.
104
105
  *
105
106
  * Receives the original `Request` so REST-only response shaping —