@fluidgrids/workflows 2026.1029.1 → 2026.1030.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.
Files changed (118) hide show
  1. package/README.md +112 -4
  2. package/dist/{activation-CESehfYi.d.cts → activation-DqUfpHzk.d.cts} +1 -1
  3. package/dist/{activation-BnVQMv9y.d.ts → activation-xpx1oWuo.d.ts} +1 -1
  4. package/dist/{chunk-MJ5TGYVG.js → chunk-2D3MYIIF.js} +969 -153
  5. package/dist/{chunk-2B37XAFQ.cjs → chunk-3U2NU7YC.cjs} +24 -11
  6. package/dist/{chunk-NEIUQASE.cjs → chunk-4QKB4ARC.cjs} +3 -3
  7. package/dist/{chunk-GBQ33SIZ.cjs → chunk-54FLQNUM.cjs} +12 -1
  8. package/dist/{chunk-2DDULZFM.js → chunk-5HIVIV53.js} +86 -75
  9. package/dist/chunk-5MFVJM76.js +1222 -0
  10. package/dist/{chunk-EWYADREB.cjs → chunk-672KMMBK.cjs} +2 -2
  11. package/dist/{chunk-KXJDRQ6G.js → chunk-6A2FGSUS.js} +22 -2
  12. package/dist/{chunk-OIX4O6UR.js → chunk-6OLN6BMB.js} +16 -3
  13. package/dist/{chunk-6FSHT5IL.js → chunk-7EZIANC7.js} +1 -1
  14. package/dist/chunk-A5SXCA62.cjs +93 -0
  15. package/dist/chunk-AC6ZEXVR.js +85 -0
  16. package/dist/{chunk-FWBRQWRX.js → chunk-AE5Q6ZAJ.js} +167 -10
  17. package/dist/{chunk-7ILGCUI6.js → chunk-C4F5KJTI.js} +142 -3
  18. package/dist/{chunk-WXXNCHUY.js → chunk-G5H32GIG.js} +1 -1
  19. package/dist/{chunk-OMY3CKUZ.cjs → chunk-GEQDGUGB.cjs} +1042 -226
  20. package/dist/{chunk-25BKWR2O.js → chunk-HCM7ZC7Q.js} +1 -1
  21. package/dist/{chunk-I47EENR4.cjs → chunk-HMZUGSMU.cjs} +673 -156
  22. package/dist/{chunk-NXFBVDOI.cjs → chunk-IQPXHQQQ.cjs} +8 -4
  23. package/dist/{chunk-RUQIMTN5.cjs → chunk-ISOIA7NV.cjs} +178 -15
  24. package/dist/chunk-JSC75O5C.cjs +167 -0
  25. package/dist/{chunk-BD7ZPG53.js → chunk-NWQ5WRLE.js} +10 -2
  26. package/dist/chunk-ODZ2IAR2.cjs +1247 -0
  27. package/dist/{chunk-FQSJI5NV.js → chunk-SR7TR5KX.js} +6 -2
  28. package/dist/{chunk-OKX3FYIM.cjs → chunk-TCTE7DX5.cjs} +3 -3
  29. package/dist/{chunk-3FIDHONL.cjs → chunk-TYF56RGB.cjs} +99 -80
  30. package/dist/{chunk-J3PYFGKA.cjs → chunk-VA4OFR72.cjs} +162 -4
  31. package/dist/chunk-VU5S5A7V.js +150 -0
  32. package/dist/{chunk-A36CCOWS.js → chunk-YEHR4NNE.js} +633 -128
  33. package/dist/{chunk-ELL2RBML.cjs → chunk-ZCGKGDCL.cjs} +23 -1
  34. package/dist/codegen/index.d.cts +2 -2
  35. package/dist/codegen/index.d.ts +2 -2
  36. package/dist/{collect-BTHjQaSp.d.ts → collect-6NIEufHd.d.ts} +20 -3
  37. package/dist/{collect-CSyOg5XC.d.cts → collect-CcTCKqx6.d.cts} +20 -3
  38. package/dist/{file-cgL9l9l8.d.cts → file-BxYpwjRQ.d.cts} +250 -15
  39. package/dist/{file-olQudcx5.d.ts → file-CFdPQJI9.d.ts} +250 -15
  40. package/dist/history/index.cjs +283 -106
  41. package/dist/history/index.d.cts +549 -10
  42. package/dist/history/index.d.ts +549 -10
  43. package/dist/history/index.js +5 -4
  44. package/dist/index.cjs +146 -53
  45. package/dist/index.d.cts +38 -14
  46. package/dist/index.d.ts +38 -14
  47. package/dist/index.js +6 -5
  48. package/dist/interceptors-CNcr2dlk.d.ts +159 -0
  49. package/dist/interceptors-CqkNZVfI.d.cts +159 -0
  50. package/dist/ir/index.cjs +339 -36
  51. package/dist/ir/index.d.cts +244 -8
  52. package/dist/ir/index.d.ts +244 -8
  53. package/dist/ir/index.js +306 -21
  54. package/dist/{lower-3S6PsqjJ.d.cts → lower-BtRfIW2A.d.cts} +23 -9
  55. package/dist/{lower-DmZpQ8hJ.d.ts → lower-CpsMFOFX.d.ts} +23 -9
  56. package/dist/{manifest-BJjrQt77.d.ts → manifest-D-I_twys.d.ts} +1 -1
  57. package/dist/{manifest-gRI2Q5Fj.d.cts → manifest-DahBQVM8.d.cts} +1 -1
  58. package/dist/node-evaluator-DGQDPSPI.cjs +24 -0
  59. package/dist/node-evaluator-LEEVD7H7.js +14 -0
  60. package/dist/payload-fields-BVRQn2yH.d.cts +122 -0
  61. package/dist/payload-fields-oOBWxDiG.d.ts +122 -0
  62. package/dist/quickjs/index.cjs +27 -27
  63. package/dist/quickjs/index.d.cts +6 -6
  64. package/dist/quickjs/index.d.ts +6 -6
  65. package/dist/quickjs/index.js +9 -9
  66. package/dist/roundtrip/index.cjs +72 -66
  67. package/dist/roundtrip/index.d.cts +25 -11
  68. package/dist/roundtrip/index.d.ts +25 -11
  69. package/dist/roundtrip/index.js +13 -11
  70. package/dist/runtime/index.cjs +19 -19
  71. package/dist/runtime/index.d.cts +139 -12
  72. package/dist/runtime/index.d.ts +139 -12
  73. package/dist/runtime/index.js +6 -6
  74. package/dist/testing/index.cjs +688 -121
  75. package/dist/testing/index.d.cts +174 -10
  76. package/dist/testing/index.d.ts +174 -10
  77. package/dist/testing/index.js +646 -82
  78. package/dist/{types-CnIOinoz.d.ts → types-Bv2i4cBX.d.cts} +126 -23
  79. package/dist/{types-CQKOhPTa.d.cts → types-DGx-b9eq.d.ts} +126 -23
  80. package/dist/{types-Bb2wRnJ5.d.cts → types-V7jEEUaL.d.cts} +1 -1
  81. package/dist/{types-Bb2wRnJ5.d.ts → types-V7jEEUaL.d.ts} +1 -1
  82. package/dist/{workflow-8uRU9rhL.d.ts → workflow-B18OeF7g.d.ts} +2 -2
  83. package/dist/{workflow-DWTPHFbt.d.ts → workflow-BGnv8SS6.d.ts} +261 -14
  84. package/dist/{workflow-CZOXUlQ5.d.cts → workflow-BJPFv3cp.d.cts} +2 -2
  85. package/dist/{workflow-O6e64ZcG.d.cts → workflow-DS32Gtws.d.cts} +261 -14
  86. package/fixtures/histories/activity-options-updated.history.json +159 -0
  87. package/fixtures/histories/activity-paused-unpaused.history.json +160 -0
  88. package/fixtures/histories/codec-opaque.history.json +229 -0
  89. package/fixtures/histories/dynamic-workflow.history.json +150 -0
  90. package/fixtures/histories/interceptor-headers.history.json +339 -0
  91. package/fixtures/histories/query-custom.history.json +213 -0
  92. package/fixtures/histories/query-default-handler.history.json +120 -0
  93. package/fixtures/histories/reset-forked-reapplied-signals.history.json +239 -0
  94. package/fixtures/histories/reset-reapplied-update-admitted.history.json +228 -0
  95. package/fixtures/histories/search-attributes-upserted.history.json +177 -0
  96. package/fixtures/histories/update-accepted-completed.history.json +45 -30
  97. package/fixtures/histories/update-default-handler.history.json +246 -0
  98. package/fixtures/histories/update-handler-awaits-activity.history.json +196 -0
  99. package/fixtures/histories/update-not-handled.history.json +138 -0
  100. package/fixtures/histories/update-rejected-no-event.history.json +190 -0
  101. package/fixtures/histories/update-with-start-admitted.history.json +150 -0
  102. package/fixtures/histories/user-activity-cancel.history.json +149 -0
  103. package/fixtures/histories/user-activity-retry.history.json +143 -0
  104. package/fixtures/histories/user-activity.history.json +149 -0
  105. package/package.json +1 -1
  106. package/schema/bridge-v2.schema.json +1062 -0
  107. package/schema/history-file.schema.json +255 -81
  108. package/schema/ir-v2.schema.json +246 -1
  109. package/schema/payload-fields.json +162 -0
  110. package/schema/run-event.schema.json +239 -80
  111. package/schema/workflow-command.schema.json +210 -84
  112. package/schema/workflow-task.schema.json +532 -167
  113. package/dist/chunk-6QPOJZT6.cjs +0 -1180
  114. package/dist/chunk-A2OHX3UQ.js +0 -1156
  115. package/dist/chunk-PWIUEWC3.js +0 -81
  116. package/dist/chunk-YHBVMOMK.cjs +0 -87
  117. package/dist/node-evaluator-SOADN23V.js +0 -14
  118. package/dist/node-evaluator-YGDEXK4U.cjs +0 -24
@@ -4,7 +4,7 @@ var chunkG4UEPUGO_cjs = require('./chunk-G4UEPUGO.cjs');
4
4
  var chunkGVTZMA5C_cjs = require('./chunk-GVTZMA5C.cjs');
5
5
  var chunkTBDXTV22_cjs = require('./chunk-TBDXTV22.cjs');
6
6
  var chunkSAENRNBJ_cjs = require('./chunk-SAENRNBJ.cjs');
7
- var chunkJ3PYFGKA_cjs = require('./chunk-J3PYFGKA.cjs');
7
+ var chunkVA4OFR72_cjs = require('./chunk-VA4OFR72.cjs');
8
8
 
9
9
  // src/builder/descriptors.ts
10
10
  function op(nodeType, version, operation) {
@@ -63,7 +63,11 @@ var internalNodes = {
63
63
  respondToWebhook: op("internal:respond-to-webhook"),
64
64
  sendAndWait: op("internal:send-and-wait"),
65
65
  codeWorkflow: op("internal:code-workflow"),
66
- waitForSignal: op("internal:wait-for-signal")
66
+ waitForSignal: op("internal:wait-for-signal"),
67
+ /** Phase C: signal another run (`fluidgrids.run-control`). */
68
+ signalRun: op("internal:signal-run"),
69
+ /** Phase C: upsert the run's search attributes (`fluidgrids.search-attributes`). */
70
+ setSearchAttributes: op("internal:set-search-attributes")
67
71
  };
68
72
  var nodes = {
69
73
  internal: internalNodes,
@@ -334,7 +338,7 @@ var WorkflowBuilder = class {
334
338
  let workflowFn;
335
339
  let definition;
336
340
  if (typeof fn === "string" && fn !== "") workflowFn = fn;
337
- else if (chunkJ3PYFGKA_cjs.isDurableWorkflow(fn)) {
341
+ else if (chunkVA4OFR72_cjs.isDurableWorkflow(fn)) {
338
342
  definition = fn;
339
343
  workflowFn = fn.name;
340
344
  } else throw new chunkGVTZMA5C_cjs.BuilderError("wf.codeWorkflow needs a workflow() function or its export name");
@@ -755,7 +759,7 @@ function assembleRecording(recording, options = {}) {
755
759
  const authoring = options.authoring ?? {
756
760
  mode: "canvas",
757
761
  generator: "sdk-ts",
758
- generatorVersion: chunkJ3PYFGKA_cjs.SDK_VERSION
762
+ generatorVersion: chunkVA4OFR72_cjs.SDK_VERSION
759
763
  };
760
764
  const out = { schemaVersion: 2 };
761
765
  for (const key of ["key", "name", "description", "interface", "code"]) {
@@ -1,6 +1,7 @@
1
1
  'use strict';
2
2
 
3
- var chunk3FIDHONL_cjs = require('./chunk-3FIDHONL.cjs');
3
+ var chunkA5SXCA62_cjs = require('./chunk-A5SXCA62.cjs');
4
+ var chunkTYF56RGB_cjs = require('./chunk-TYF56RGB.cjs');
4
5
 
5
6
  // src/history/commands.ts
6
7
  var COMMAND_FEATURES = [
@@ -31,6 +32,39 @@ var PHASE_B_PARITY_FEATURES = /* @__PURE__ */ new Set([
31
32
  "parity.canOptions",
32
33
  "parity.workflowIdTarget"
33
34
  ]);
35
+ var PHASE_C_FEATURES = [
36
+ "c.updates",
37
+ "c.searchAttributes",
38
+ "c.userActivity"
39
+ ];
40
+ var PHASE_C_FEATURE_FLAGS = {
41
+ "c.updates": "fluidgrids.run-control",
42
+ "c.searchAttributes": "fluidgrids.search-attributes",
43
+ "c.userActivity": "fluidgrids.self-hosted-workers"
44
+ };
45
+ var CODE_FEATURE_FLAGS = {
46
+ localActivity: "fluidgrids.durable-parity",
47
+ externalCancel: "fluidgrids.durable-parity",
48
+ childOptions: "fluidgrids.durable-parity",
49
+ canOptions: "fluidgrids.durable-parity",
50
+ autoUpgrade: "fluidgrids.durable-parity",
51
+ runRetry: "fluidgrids.durable-parity",
52
+ timeouts: "fluidgrids.durable-parity",
53
+ userActivity: "fluidgrids.self-hosted-workers",
54
+ updates: "fluidgrids.run-control",
55
+ queries: "fluidgrids.run-control",
56
+ dynamic: "fluidgrids.run-control",
57
+ interceptors: "fluidgrids.run-control",
58
+ searchAttributes: "fluidgrids.search-attributes"
59
+ };
60
+ var PHASE_C_CODE_FEATURES = [
61
+ "userActivity",
62
+ "updates",
63
+ "queries",
64
+ "searchAttributes",
65
+ "dynamic",
66
+ "interceptors"
67
+ ];
34
68
  var CORE_CHILD_OPTIONS = /* @__PURE__ */ new Set([
35
69
  "parentClosePolicy",
36
70
  "cancellationType",
@@ -43,7 +77,9 @@ var CORE_CHILD_OPTIONS = /* @__PURE__ */ new Set([
43
77
  "startDelay",
44
78
  "executionTimeout",
45
79
  "runTimeout",
46
- "workflowTaskTimeout"
80
+ "workflowTaskTimeout",
81
+ "fairnessKey",
82
+ "fairnessWeight"
47
83
  ]);
48
84
  var CORE_CAN_OPTIONS = /* @__PURE__ */ new Set([
49
85
  "taskQueue",
@@ -70,6 +106,9 @@ function hasOtherKeys(value, allowed) {
70
106
  function commandFeatures(command) {
71
107
  const needed = /* @__PURE__ */ new Set();
72
108
  switch (command.type) {
109
+ case "SCHEDULE_ACTIVITY":
110
+ needed.add(command.kind === "user" ? "c.userActivity" : "core");
111
+ break;
73
112
  case "START_CHILD_RUN":
74
113
  needed.add("core");
75
114
  if (hasOtherKeys(command.options, CORE_CHILD_OPTIONS)) needed.add("parity.childOptions");
@@ -108,22 +147,44 @@ function commandFeatures(command) {
108
147
  return COMMAND_FEATURES.filter((feature) => needed.has(feature));
109
148
  }
110
149
  function isCommandEnabled(type, enabled = "core") {
111
- if (chunk3FIDHONL_cjs.PHASE_C_COMMANDS.has(type)) return false;
112
- if (chunk3FIDHONL_cjs.PHASE_B_CORE_COMMANDS.has(type)) return true;
113
- return enabled === "parity" && chunk3FIDHONL_cjs.PHASE_B_PARITY_COMMANDS.has(type);
150
+ if (chunkTYF56RGB_cjs.PHASE_C_COMMANDS.has(type)) return false;
151
+ if (chunkTYF56RGB_cjs.PHASE_B_CORE_COMMANDS.has(type)) return true;
152
+ return enabled === "parity" && chunkTYF56RGB_cjs.PHASE_B_PARITY_COMMANDS.has(type);
153
+ }
154
+ function phaseCFeaturesOf(command) {
155
+ return commandFeatures(command).filter((feature) => feature.startsWith("c."));
114
156
  }
115
157
  function isWorkflowCommandEnabled(command, enabled = "core") {
116
158
  if (typeof enabled === "string") {
159
+ if (phaseCFeaturesOf(command).length > 0) return false;
117
160
  if (command.type === "REQUEST_CANCEL_EXTERNAL_RUN" && "childId" in command.target) return true;
118
161
  return isCommandEnabled(command.type, enabled);
119
162
  }
120
163
  return commandFeatures(command).every((feature) => enabled.has(feature));
121
164
  }
165
+ function codeFeaturesEnabledBy(enabled) {
166
+ if (typeof enabled === "string") return [];
167
+ const flags = /* @__PURE__ */ new Set(["fluidgrids.durable-functions"]);
168
+ for (const feature of enabled) {
169
+ if (PHASE_B_PARITY_FEATURES.has(feature) && !PHASE_B_CORE_FEATURES.has(feature))
170
+ flags.add("fluidgrids.durable-parity");
171
+ const flag = PHASE_C_FEATURE_FLAGS[feature];
172
+ if (flag !== void 0) flags.add(flag);
173
+ }
174
+ return Object.keys(CODE_FEATURE_FLAGS).filter((feature) => flags.has(CODE_FEATURE_FLAGS[feature] ?? "")).sort();
175
+ }
122
176
  function unsupportedMessage(command, enabled = "core") {
123
- if (typeof enabled === "string") return `${command.type} is not supported in this release`;
124
- const missing = commandFeatures(command).filter((feature) => !enabled.has(feature));
125
- const parity = missing.filter((feature) => feature.startsWith("parity."));
126
- const flag = parity.length > 0 ? " (needs the fluidgrids.durable-parity flag)" : "";
177
+ const missing = typeof enabled === "string" ? phaseCFeaturesOf(command) : commandFeatures(command).filter((feature) => !enabled.has(feature));
178
+ if (missing.length === 0) return `${command.type} is not supported in this release`;
179
+ const flags = /* @__PURE__ */ new Set();
180
+ if (missing.some((feature) => feature.startsWith("parity.")))
181
+ flags.add("fluidgrids.durable-parity");
182
+ for (const feature of missing) {
183
+ const flag2 = PHASE_C_FEATURE_FLAGS[feature];
184
+ if (flag2 !== void 0) flags.add(flag2);
185
+ }
186
+ const names = [...flags];
187
+ const flag = names.length === 0 ? "" : ` (needs the ${names.join(" and ")} flag${names.length === 1 ? "" : "s"})`;
127
188
  return `${command.type} needs ${missing.join(", ")}, which this workspace does not enable${flag}`;
128
189
  }
129
190
  function isReliefCommand(command, lease) {
@@ -132,8 +193,9 @@ function isReliefCommand(command, lease) {
132
193
  return lease.grantedLocalActivityIds.includes(command.localActivityId);
133
194
  case "ACCEPT_UPDATE":
134
195
  case "REJECT_UPDATE":
135
- case "COMPLETE_UPDATE":
136
196
  return lease.deliveredUpdateIds.includes(command.updateId);
197
+ case "COMPLETE_UPDATE":
198
+ return true;
137
199
  default:
138
200
  return false;
139
201
  }
@@ -189,10 +251,10 @@ function walk(history) {
189
251
  continue;
190
252
  }
191
253
  }
192
- if (chunk3FIDHONL_cjs.isInputEvent(event)) {
254
+ if (chunkTYF56RGB_cjs.isInputEvent(event)) {
193
255
  if (started) afterStarted.push(event);
194
256
  else pending.push(event);
195
- } else if (chunk3FIDHONL_cjs.isCommandEvent(event) && last?.recorded) {
257
+ } else if (chunkTYF56RGB_cjs.isCommandEvent(event) && last?.recorded) {
196
258
  last.recorded.push(event);
197
259
  }
198
260
  }
@@ -238,9 +300,19 @@ function initialRunState() {
238
300
  sideEffects: {},
239
301
  markers: {},
240
302
  signalsReceived: 0,
241
- context: {}
303
+ context: {},
304
+ updates: {},
305
+ searchAttributes: {}
242
306
  };
243
307
  }
308
+ function mergeSearchAttributes(current, entries) {
309
+ const out = { ...current };
310
+ for (const [key, value] of Object.entries(entries)) {
311
+ if (value === null) delete out[key];
312
+ else out[key] = value;
313
+ }
314
+ return out;
315
+ }
244
316
  function utf8Bytes(text) {
245
317
  let bytes = 0;
246
318
  for (let index = 0; index < text.length; index++) {
@@ -315,6 +387,8 @@ function applyEvent(state, event) {
315
387
  state.input = p["input"] ?? null;
316
388
  if (typeof p["context"] === "object" && p["context"] !== null && !Array.isArray(p["context"]))
317
389
  state.context = { ...p["context"] };
390
+ if (typeof p["searchAttributes"] === "object" && p["searchAttributes"] !== null && !Array.isArray(p["searchAttributes"]))
391
+ state.searchAttributes = mergeSearchAttributes({}, p["searchAttributes"]);
318
392
  break;
319
393
  case "WORKFLOW_TASK_SCHEDULED":
320
394
  state.task = { state: "SCHEDULED", taskId: str(p, "taskId"), attempt: state.task.attempt };
@@ -339,11 +413,14 @@ function applyEvent(state, event) {
339
413
  const id = str(p, "activityId");
340
414
  if (state.activities[id])
341
415
  throw new HistoryStateError(`Activity "${id}" is scheduled twice`, event.seq);
416
+ const user = p["kind"] === "user";
342
417
  state.activities[id] = {
343
418
  status: "SCHEDULED",
344
419
  attempt: 0,
420
+ kind: user ? "user" : "node",
345
421
  nodeType: str(p, "nodeType"),
346
422
  operation: str(p, "operation"),
423
+ ...user ? { activityName: str(p, "activityName"), taskQueue: str(p, "taskQueue") } : {},
347
424
  scheduledSeq: event.seq,
348
425
  ...typeof p["cancellationType"] === "string" ? { cancellationType: p["cancellationType"] } : {},
349
426
  ...typeof p["summary"] === "string" ? { summary: p["summary"] } : {}
@@ -492,6 +569,43 @@ function applyEvent(state, event) {
492
569
  case "MARKER_RECORDED":
493
570
  state.markers[str(p, "markerId")] = p["data"] ?? null;
494
571
  break;
572
+ case "UPDATE_ADMITTED": {
573
+ const id = str(p, "updateId");
574
+ if (state.updates[id])
575
+ throw new HistoryStateError(`Update "${id}" is admitted twice`, event.seq);
576
+ state.updates[id] = { status: "ADMITTED", name: str(p, "name"), seq: event.seq };
577
+ break;
578
+ }
579
+ case "UPDATE_ACCEPTED": {
580
+ const id = str(p, "updateId");
581
+ const found = state.updates[id];
582
+ if (found && found.status !== "ADMITTED")
583
+ throw new HistoryStateError(`Update "${id}" is accepted twice`, event.seq);
584
+ state.updates[id] = {
585
+ status: "ACCEPTED",
586
+ name: found?.name ?? str(p, "name"),
587
+ seq: found?.seq ?? event.seq
588
+ };
589
+ break;
590
+ }
591
+ case "UPDATE_COMPLETED": {
592
+ const id = str(p, "updateId");
593
+ const found = state.updates[id];
594
+ if (!found || found.status !== "ACCEPTED")
595
+ throw new HistoryStateError(
596
+ `UPDATE_COMPLETED for update "${id}" that is not accepted`,
597
+ event.seq
598
+ );
599
+ found.status = "COMPLETED";
600
+ if (failureOf(p)) found.failed = true;
601
+ break;
602
+ }
603
+ case "SEARCH_ATTRIBUTES_UPSERTED": {
604
+ const attributes = p["attributes"];
605
+ if (typeof attributes === "object" && attributes !== null && !Array.isArray(attributes))
606
+ state.searchAttributes = mergeSearchAttributes(state.searchAttributes, attributes);
607
+ break;
608
+ }
495
609
  case "CONTEXT_UPSERTED": {
496
610
  const entries = p["entries"];
497
611
  if (typeof entries === "object" && entries !== null && !Array.isArray(entries))
@@ -547,6 +661,11 @@ function payloadOf(command) {
547
661
  }
548
662
  return out;
549
663
  }
664
+ function completedPayload(command) {
665
+ if (command.failure !== void 0)
666
+ return { updateId: command.updateId, failure: command.failure };
667
+ return { updateId: command.updateId, result: command.result ?? null };
668
+ }
550
669
  function eventsForCommands(state, commands, context) {
551
670
  const issues = [];
552
671
  const events = [];
@@ -565,6 +684,8 @@ function eventsForCommands(state, commands, context) {
565
684
  const externals = new Set(Object.keys(state.externals));
566
685
  const sideEffects = new Set(Object.keys(state.sideEffects));
567
686
  const localActivities = new Set(Object.keys(state.localActivities));
687
+ const updates = new Map(Object.entries(state.updates).map(([id, u]) => [id, u.status]));
688
+ const answered = /* @__PURE__ */ new Set();
568
689
  let unsupported = false;
569
690
  commands.forEach((command, index) => {
570
691
  if (!isWorkflowCommandEnabled(command, context.enabled) && !(context.relief !== void 0 && isReliefCommand(command, context.relief))) {
@@ -572,14 +693,14 @@ function eventsForCommands(state, commands, context) {
572
693
  reject(index, "commands.unsupported", unsupportedMessage(command, context.enabled));
573
694
  return;
574
695
  }
575
- if (chunk3FIDHONL_cjs.TERMINAL_COMMANDS.has(command.type) && index !== commands.length - 1)
696
+ if (chunkTYF56RGB_cjs.TERMINAL_COMMANDS.has(command.type) && index !== commands.length - 1)
576
697
  reject(index, "commands.terminalNotLast", `${command.type} must be last`);
577
698
  const base = { taskId: context.taskId };
578
699
  switch (command.type) {
579
700
  case "SCHEDULE_ACTIVITY":
580
701
  if (activities.has(command.activityId))
581
702
  reject(index, "activity.duplicate", `Activity "${command.activityId}" already exists`);
582
- if (!chunk3FIDHONL_cjs.isActivityNodeTypeAllowed(command.nodeType))
703
+ if (command.kind === "node" && !chunkA5SXCA62_cjs.isActivityNodeTypeAllowed(command.nodeType))
583
704
  reject(
584
705
  index,
585
706
  "durable.activityTypeNotAllowed",
@@ -676,6 +797,42 @@ function eventsForCommands(state, commands, context) {
676
797
  case "CONTINUE_AS_NEW":
677
798
  events.push({ ...base, type: "WORKFLOW_CONTINUED_AS_NEW", payload: payloadOf(command) });
678
799
  break;
800
+ case "UPSERT_SEARCH_ATTRIBUTES":
801
+ events.push({ ...base, type: "SEARCH_ATTRIBUTES_UPSERTED", payload: payloadOf(command) });
802
+ break;
803
+ case "ACCEPT_UPDATE":
804
+ case "REJECT_UPDATE": {
805
+ const id = command.updateId;
806
+ const status = updates.get(id);
807
+ const delivered = context.updates?.[id];
808
+ if (answered.has(id) || status !== void 0 && status !== "ADMITTED") {
809
+ reject(index, "update.answered", `Update "${id}" is already answered`);
810
+ break;
811
+ }
812
+ if (status === void 0 && delivered === void 0) {
813
+ reject(index, "update.unknown", `Update "${id}" was not delivered to this task`);
814
+ break;
815
+ }
816
+ answered.add(id);
817
+ if (command.type === "REJECT_UPDATE") break;
818
+ updates.set(id, "ACCEPTED");
819
+ const admitted = state.updates[id];
820
+ const payload = { updateId: id, name: admitted?.name ?? delivered?.name ?? "" };
821
+ if (delivered?.args !== void 0) payload["args"] = delivered.args;
822
+ if (delivered?.headers !== void 0) payload["headers"] = { ...delivered.headers };
823
+ events.push({ ...base, type: "UPDATE_ACCEPTED", payload });
824
+ break;
825
+ }
826
+ case "COMPLETE_UPDATE": {
827
+ const id = command.updateId;
828
+ if (updates.get(id) !== "ACCEPTED") {
829
+ reject(index, "update.notAccepted", `Update "${id}" is not accepted`);
830
+ break;
831
+ }
832
+ updates.set(id, "COMPLETED");
833
+ events.push({ ...base, type: "UPDATE_COMPLETED", payload: completedPayload(command) });
834
+ break;
835
+ }
679
836
  }
680
837
  });
681
838
  if (issues.length > 0)
@@ -721,13 +878,18 @@ var CHILD_DEFAULT_CANCELLATION_TYPE = "WAIT_CANCELLATION_COMPLETED";
721
878
 
722
879
  exports.CHILD_DEFAULT_CANCELLATION_TYPE = CHILD_DEFAULT_CANCELLATION_TYPE;
723
880
  exports.CHILD_DEFAULT_PARENT_CLOSE_POLICY = CHILD_DEFAULT_PARENT_CLOSE_POLICY;
881
+ exports.CODE_FEATURE_FLAGS = CODE_FEATURE_FLAGS;
724
882
  exports.COMMAND_FEATURES = COMMAND_FEATURES;
725
883
  exports.CORE_CAN_OPTIONS = CORE_CAN_OPTIONS;
726
884
  exports.CORE_CHILD_OPTIONS = CORE_CHILD_OPTIONS;
727
885
  exports.HistoryStateError = HistoryStateError;
728
886
  exports.PHASE_B_CORE_FEATURES = PHASE_B_CORE_FEATURES;
729
887
  exports.PHASE_B_PARITY_FEATURES = PHASE_B_PARITY_FEATURES;
888
+ exports.PHASE_C_CODE_FEATURES = PHASE_C_CODE_FEATURES;
889
+ exports.PHASE_C_FEATURES = PHASE_C_FEATURES;
890
+ exports.PHASE_C_FEATURE_FLAGS = PHASE_C_FEATURE_FLAGS;
730
891
  exports.applyEvent = applyEvent;
892
+ exports.codeFeaturesEnabledBy = codeFeaturesEnabledBy;
731
893
  exports.codeWorkflowParentClosePolicy = codeWorkflowParentClosePolicy;
732
894
  exports.commandFeatures = commandFeatures;
733
895
  exports.continueAsNewRetryShape = continueAsNewRetryShape;
@@ -739,6 +901,7 @@ exports.isChildOpen = isChildOpen;
739
901
  exports.isCommandEnabled = isCommandEnabled;
740
902
  exports.isReliefCommand = isReliefCommand;
741
903
  exports.isWorkflowCommandEnabled = isWorkflowCommandEnabled;
904
+ exports.mergeSearchAttributes = mergeSearchAttributes;
742
905
  exports.pendingCounts = pendingCounts;
743
906
  exports.projectRunState = projectRunState;
744
907
  exports.splitActivations = splitActivations;
@@ -0,0 +1,167 @@
1
+ 'use strict';
2
+
3
+ // src/history/payload-fields.ts
4
+ var ENCODED_PAYLOAD_MARKER = "$fgp";
5
+ var ENCODED_PAYLOAD_VERSION = 1;
6
+ var PAYLOAD_ENCODINGS = [
7
+ "json/plain",
8
+ "binary/plain",
9
+ "binary/encrypted",
10
+ "kms/envelope"
11
+ ];
12
+ var ENCODED_KEYS = /* @__PURE__ */ new Set(["$fgp", "encoding", "metadata", "data"]);
13
+ var BASE64 = /^[A-Za-z0-9+/]*={0,2}$/;
14
+ function isEncodedPayload(value) {
15
+ if (typeof value !== "object" || value === null || Array.isArray(value)) return false;
16
+ const record = value;
17
+ if (record[ENCODED_PAYLOAD_MARKER] !== ENCODED_PAYLOAD_VERSION) return false;
18
+ if (!Object.keys(record).every((key) => ENCODED_KEYS.has(key))) return false;
19
+ const encoding = record["encoding"];
20
+ if (typeof encoding !== "string" || encoding === "" || encoding === "json/plain") return false;
21
+ const data = record["data"];
22
+ if (typeof data !== "string" || data.length % 4 !== 0 || !BASE64.test(data)) return false;
23
+ const metadata = record["metadata"];
24
+ if (metadata === void 0) return true;
25
+ if (typeof metadata !== "object" || metadata === null || Array.isArray(metadata)) return false;
26
+ return Object.values(metadata).every((entry) => typeof entry === "string");
27
+ }
28
+ function payloadEncodingOf(value) {
29
+ return isEncodedPayload(value) ? value.encoding : "json/plain";
30
+ }
31
+ var PAYLOAD_FIELDS = {
32
+ WORKFLOW_STARTED: ["/input", "/lastCompletionResult", "/context"],
33
+ ACTIVITY_SCHEDULED: ["/args"],
34
+ ACTIVITY_HEARTBEAT: ["/details"],
35
+ ACTIVITY_COMPLETED: ["/result"],
36
+ ACTIVITY_CANCELLED: ["/details"],
37
+ SIGNAL_RECEIVED: ["/payload"],
38
+ UPDATE_ADMITTED: ["/args"],
39
+ UPDATE_ACCEPTED: ["/args"],
40
+ UPDATE_COMPLETED: ["/result"],
41
+ CHILD_RUN_INITIATED: ["/input", "/options/context"],
42
+ CHILD_RUN_COMPLETED: ["/result"],
43
+ EXTERNAL_RUN_SIGNALED: ["/payload"],
44
+ SIDE_EFFECT_RECORDED: ["/value"],
45
+ LOCAL_ACTIVITY_COMPLETED: ["/result"],
46
+ CONTEXT_UPSERTED: ["/entries"],
47
+ MARKER_RECORDED: ["/data/currentDetails"],
48
+ WORKFLOW_COMPLETED: ["/output"],
49
+ WORKFLOW_CANCELLED: ["/details"],
50
+ WORKFLOW_CONTINUED_AS_NEW: ["/input", "/options/context"]
51
+ };
52
+ var FAILURE_FIELDS = {
53
+ WORKFLOW_STARTED: ["/lastFailure"],
54
+ ACTIVITY_FAILED: ["/failure"],
55
+ ACTIVITY_TIMED_OUT: ["/failure"],
56
+ UPDATE_COMPLETED: ["/failure"],
57
+ CHILD_RUN_FAILED: ["/failure"],
58
+ EXTERNAL_RUN_SIGNALED: ["/failure"],
59
+ EXTERNAL_RUN_CANCEL_RESOLVED: ["/failure"],
60
+ LOCAL_ACTIVITY_FAILED: ["/failure"],
61
+ WORKFLOW_FAILED: ["/failure"],
62
+ WORKFLOW_TIMED_OUT: ["/failure"]
63
+ };
64
+ var COMMAND_PAYLOAD_FIELDS = {
65
+ SCHEDULE_ACTIVITY: ["/args"],
66
+ START_CHILD_RUN: ["/input", "/options/context"],
67
+ SIGNAL_RUN: ["/payload"],
68
+ RECORD_SIDE_EFFECT: ["/value"],
69
+ RECORD_MARKER: ["/data/currentDetails"],
70
+ COMPLETE_WORKFLOW: ["/output"],
71
+ UPSERT_CONTEXT: ["/entries"],
72
+ RECORD_LOCAL_ACTIVITY: ["/result"],
73
+ CONTINUE_AS_NEW: ["/input", "/options/context"],
74
+ COMPLETE_UPDATE: ["/result"]
75
+ };
76
+ var COMMAND_FAILURE_FIELDS = {
77
+ FAIL_WORKFLOW: ["/failure"],
78
+ RECORD_LOCAL_ACTIVITY: ["/failure"],
79
+ REJECT_UPDATE: ["/failure"],
80
+ COMPLETE_UPDATE: ["/failure"]
81
+ };
82
+ var FAILURE_PAYLOAD_FIELDS = ["/details"];
83
+ var FAILURE_CAUSE_FIELD = "/cause";
84
+ var PAYLOAD_FIELDS_FORMAT = "fluidgrids.payload-fields";
85
+ var PAYLOAD_FIELDS_DOCUMENT = {
86
+ format: PAYLOAD_FIELDS_FORMAT,
87
+ formatVersion: 2,
88
+ description: 'JSON pointers of user payloads per event type (relative to the payload) and per command type (relative to the command). `events` and `commands` are plain payload pointers. `eventFailures` and `commandFailures` point at failure objects: the payloads of a failure are the `failure.payloads` pointers relative to it, and the same rule applies again to the failure at `failure.cause` (recursively, to the end of the cause chain). Payload codecs and the at-rest envelope apply to these pointers only; everything else stays in clear text. A value that is not plain JSON is carried as {"$fgp": 1, "encoding", "metadata"?, "data" (base64)}.',
89
+ encodedMarker: ENCODED_PAYLOAD_MARKER,
90
+ encodedVersion: ENCODED_PAYLOAD_VERSION,
91
+ encodings: [...PAYLOAD_ENCODINGS],
92
+ events: PAYLOAD_FIELDS,
93
+ commands: COMMAND_PAYLOAD_FIELDS,
94
+ eventFailures: FAILURE_FIELDS,
95
+ commandFailures: COMMAND_FAILURE_FIELDS,
96
+ failure: { payloads: FAILURE_PAYLOAD_FIELDS, cause: FAILURE_CAUSE_FIELD }
97
+ };
98
+ function tokensOf(pointer) {
99
+ if (pointer === "") return [];
100
+ return pointer.slice(1).split("/").map((token) => token.replace(/~1/g, "/").replace(/~0/g, "~"));
101
+ }
102
+ function locate(root, pointer) {
103
+ const tokens = tokensOf(pointer);
104
+ const key = tokens.pop();
105
+ if (key === void 0) return void 0;
106
+ let holder = root;
107
+ for (const token of tokens) {
108
+ if (typeof holder !== "object" || holder === null || Array.isArray(holder)) return void 0;
109
+ holder = holder[token];
110
+ }
111
+ if (typeof holder !== "object" || holder === null || Array.isArray(holder)) return void 0;
112
+ const parent = holder;
113
+ if (!Object.hasOwn(parent, key) || parent[key] === void 0) return void 0;
114
+ return { parent, key };
115
+ }
116
+ function mapAt(root, pointer, fn) {
117
+ const found = locate(root, pointer);
118
+ if (found === void 0) return;
119
+ const current = found.parent[found.key];
120
+ if (current !== void 0) found.parent[found.key] = fn(current, pointer);
121
+ }
122
+ function mapFailureAt(root, pointer, fn) {
123
+ let failure = pointer;
124
+ for (; ; ) {
125
+ const found = locate(root, failure);
126
+ if (found === void 0) return;
127
+ const value = found.parent[found.key];
128
+ if (typeof value !== "object" || value === null || Array.isArray(value)) return;
129
+ for (const field of FAILURE_PAYLOAD_FIELDS) mapAt(root, failure + field, fn);
130
+ failure += FAILURE_CAUSE_FIELD;
131
+ }
132
+ }
133
+ function mapPayloadFields(record, pointers, fn, failures = []) {
134
+ const copy = JSON.parse(JSON.stringify(record));
135
+ for (const pointer of pointers) mapAt(copy, pointer, fn);
136
+ for (const pointer of failures) mapFailureAt(copy, pointer, fn);
137
+ return copy;
138
+ }
139
+ function mapEventPayloads(type, payload, fn) {
140
+ return mapPayloadFields(payload, PAYLOAD_FIELDS[type] ?? [], fn, FAILURE_FIELDS[type] ?? []);
141
+ }
142
+ function mapCommandPayloads(command, fn) {
143
+ const record = command;
144
+ return mapPayloadFields(
145
+ record,
146
+ COMMAND_PAYLOAD_FIELDS[command.type] ?? [],
147
+ fn,
148
+ COMMAND_FAILURE_FIELDS[command.type] ?? []
149
+ );
150
+ }
151
+
152
+ exports.COMMAND_FAILURE_FIELDS = COMMAND_FAILURE_FIELDS;
153
+ exports.COMMAND_PAYLOAD_FIELDS = COMMAND_PAYLOAD_FIELDS;
154
+ exports.ENCODED_PAYLOAD_MARKER = ENCODED_PAYLOAD_MARKER;
155
+ exports.ENCODED_PAYLOAD_VERSION = ENCODED_PAYLOAD_VERSION;
156
+ exports.FAILURE_CAUSE_FIELD = FAILURE_CAUSE_FIELD;
157
+ exports.FAILURE_FIELDS = FAILURE_FIELDS;
158
+ exports.FAILURE_PAYLOAD_FIELDS = FAILURE_PAYLOAD_FIELDS;
159
+ exports.PAYLOAD_ENCODINGS = PAYLOAD_ENCODINGS;
160
+ exports.PAYLOAD_FIELDS = PAYLOAD_FIELDS;
161
+ exports.PAYLOAD_FIELDS_DOCUMENT = PAYLOAD_FIELDS_DOCUMENT;
162
+ exports.PAYLOAD_FIELDS_FORMAT = PAYLOAD_FIELDS_FORMAT;
163
+ exports.isEncodedPayload = isEncodedPayload;
164
+ exports.mapCommandPayloads = mapCommandPayloads;
165
+ exports.mapEventPayloads = mapEventPayloads;
166
+ exports.mapPayloadFields = mapPayloadFields;
167
+ exports.payloadEncodingOf = payloadEncodingOf;
@@ -47,9 +47,17 @@ var EXECUTOR_INTERNAL_TYPES = /* @__PURE__ */ new Set([
47
47
  ]);
48
48
  var CODE_WORKFLOW_NODE_TYPE = "internal:code-workflow";
49
49
  var WAIT_FOR_SIGNAL_NODE_TYPE = "internal:wait-for-signal";
50
+ var SIGNAL_RUN_NODE_TYPE = "internal:signal-run";
51
+ var SET_SEARCH_ATTRIBUTES_NODE_TYPE = "internal:set-search-attributes";
50
52
  var V2_NODE_TYPES = /* @__PURE__ */ new Set([
51
53
  CODE_WORKFLOW_NODE_TYPE,
52
- WAIT_FOR_SIGNAL_NODE_TYPE
54
+ WAIT_FOR_SIGNAL_NODE_TYPE,
55
+ SIGNAL_RUN_NODE_TYPE,
56
+ SET_SEARCH_ATTRIBUTES_NODE_TYPE
57
+ ]);
58
+ var PHASE_C_NODE_TYPES = /* @__PURE__ */ new Set([
59
+ SIGNAL_RUN_NODE_TYPE,
60
+ SET_SEARCH_ATTRIBUTES_NODE_TYPE
53
61
  ]);
54
62
  var INTERNAL_TRIGGER_TYPES = /* @__PURE__ */ new Set([
55
63
  "internal:api",
@@ -260,4 +268,4 @@ function buildIdOf(bundle) {
260
268
  return sha256Tagged(bundle);
261
269
  }
262
270
 
263
- export { CODE_WORKFLOW_NODE_TYPE, INTERNAL_TRIGGER_TYPES, V2_NODE_TYPES, WAIT_FOR_SIGNAL_NODE_TYPE, buildIdOf, hashedProjection, irHash, normalizeDefinition, sourceHash, usesMergedParameters };
271
+ export { CODE_WORKFLOW_NODE_TYPE, INTERNAL_TRIGGER_TYPES, PHASE_C_NODE_TYPES, SET_SEARCH_ATTRIBUTES_NODE_TYPE, SIGNAL_RUN_NODE_TYPE, V2_NODE_TYPES, WAIT_FOR_SIGNAL_NODE_TYPE, buildIdOf, hashedProjection, irHash, normalizeDefinition, sourceHash, usesMergedParameters };