@leitwerk-dev/process-sdk 0.2.0 → 0.3.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 (187) hide show
  1. package/README.md +12 -0
  2. package/dist/browser-ui-extension.d.ts +20 -0
  3. package/dist/browser-ui-extension.d.ts.map +1 -1
  4. package/dist/capabilities.d.ts +6 -0
  5. package/dist/capabilities.d.ts.map +1 -1
  6. package/dist/{chunk-LIIP7FMU.js → chunk-5R6MVLHC.js} +1 -1
  7. package/dist/chunk-5R6MVLHC.js.map +1 -0
  8. package/dist/chunk-DVXW2ZUV.js +1 -0
  9. package/dist/chunk-DVXW2ZUV.js.map +1 -0
  10. package/dist/{chunk-TA4KO53Q.js → chunk-I7U6HCLN.js} +1 -7
  11. package/dist/chunk-I7U6HCLN.js.map +1 -0
  12. package/dist/{chunk-WFY2WWZE.js → chunk-TM2LTSW4.js} +1 -1
  13. package/dist/chunk-TM2LTSW4.js.map +1 -0
  14. package/dist/codecs.d.ts +1 -0
  15. package/dist/codecs.d.ts.map +1 -1
  16. package/dist/commit-message.d.ts +5 -0
  17. package/dist/commit-message.d.ts.map +1 -1
  18. package/dist/core-capabilities.d.ts +338 -20
  19. package/dist/core-capabilities.d.ts.map +1 -1
  20. package/dist/define-process.d.ts +195 -18
  21. package/dist/define-process.d.ts.map +1 -1
  22. package/dist/event-bus.d.ts +1 -0
  23. package/dist/event-bus.d.ts.map +1 -1
  24. package/dist/{extension-api-CcqZCYJx.d.ts → extension-api-3Vr3RE8S.d.ts} +1000 -108
  25. package/dist/extension-api.d.ts +385 -50
  26. package/dist/extension-api.d.ts.map +1 -1
  27. package/dist/external-action-source.d.ts +3 -1
  28. package/dist/external-action-source.d.ts.map +1 -1
  29. package/dist/external-source-poll.d.ts +18 -5
  30. package/dist/external-source-poll.d.ts.map +1 -1
  31. package/dist/flow.d.ts +308 -11
  32. package/dist/flow.d.ts.map +1 -1
  33. package/dist/form-contract.d.ts +1 -1
  34. package/dist/form-contract.d.ts.map +1 -1
  35. package/dist/fs-utils.d.ts +4 -0
  36. package/dist/fs-utils.d.ts.map +1 -1
  37. package/dist/git-binary.d.ts +2 -1
  38. package/dist/git-binary.d.ts.map +1 -1
  39. package/dist/git-binary.js.map +1 -1
  40. package/dist/graph-fragments.d.ts +16 -0
  41. package/dist/graph-fragments.d.ts.map +1 -1
  42. package/dist/host-capabilities.d.ts +9 -3
  43. package/dist/host-capabilities.d.ts.map +1 -1
  44. package/dist/index.d.ts +26 -26
  45. package/dist/index.d.ts.map +1 -1
  46. package/dist/index.js +270 -81
  47. package/dist/index.js.map +1 -1
  48. package/dist/integration-http.d.ts +14 -3
  49. package/dist/integration-http.d.ts.map +1 -1
  50. package/dist/json-data.d.ts +1 -1
  51. package/dist/json-data.d.ts.map +1 -1
  52. package/dist/leaf-outcome-renderer.d.ts +35 -0
  53. package/dist/leaf-outcome-renderer.d.ts.map +1 -1
  54. package/dist/leaf-outcome-renderer.js +12 -0
  55. package/dist/leaf-outcome-renderer.js.map +1 -1
  56. package/dist/leaf-outcomes.d.ts +3 -0
  57. package/dist/leaf-outcomes.d.ts.map +1 -1
  58. package/dist/model-provider.d.ts +144 -12
  59. package/dist/model-provider.d.ts.map +1 -1
  60. package/dist/pi-config-public.d.ts +2 -0
  61. package/dist/pi-config-public.d.ts.map +1 -0
  62. package/dist/pi-config-public.js +15 -0
  63. package/dist/pi-config-public.js.map +1 -0
  64. package/dist/pi-config.d.ts +40 -0
  65. package/dist/pi-config.d.ts.map +1 -1
  66. package/dist/pi-config.js +1 -1
  67. package/dist/process-definition-internals.d.ts +4 -0
  68. package/dist/process-definition-internals.d.ts.map +1 -1
  69. package/dist/process-flow-view.d.ts +2 -0
  70. package/dist/process-flow-view.d.ts.map +1 -1
  71. package/dist/process-graph.d.ts +34 -0
  72. package/dist/process-graph.d.ts.map +1 -1
  73. package/dist/process-launcher-builder.d.ts +5 -0
  74. package/dist/process-launcher-builder.d.ts.map +1 -1
  75. package/dist/process-watcher-builder.d.ts +5 -0
  76. package/dist/process-watcher-builder.d.ts.map +1 -1
  77. package/dist/process-watcher-source.d.ts +3 -1
  78. package/dist/process-watcher-source.d.ts.map +1 -1
  79. package/dist/project-binding.d.ts +5 -1
  80. package/dist/project-binding.d.ts.map +1 -1
  81. package/dist/registry-utils.d.ts +6 -0
  82. package/dist/registry-utils.d.ts.map +1 -1
  83. package/dist/repository-feedback.d.ts +36 -12
  84. package/dist/repository-feedback.d.ts.map +1 -1
  85. package/dist/repository-git-env.d.ts +6 -2
  86. package/dist/repository-git-env.d.ts.map +1 -1
  87. package/dist/repository-http.d.ts +13 -1
  88. package/dist/repository-http.d.ts.map +1 -1
  89. package/dist/repository-https.d.ts +1 -1
  90. package/dist/repository-https.d.ts.map +1 -1
  91. package/dist/repository-issue-watcher.d.ts +31 -6
  92. package/dist/repository-issue-watcher.d.ts.map +1 -1
  93. package/dist/repository-reconciliation.d.ts +5 -0
  94. package/dist/repository-reconciliation.d.ts.map +1 -0
  95. package/dist/repository-source-config.d.ts +29 -18
  96. package/dist/repository-source-config.d.ts.map +1 -1
  97. package/dist/repository-types.d.ts +28 -1
  98. package/dist/repository-types.d.ts.map +1 -1
  99. package/dist/review-flow-public.d.ts +2 -0
  100. package/dist/review-flow-public.d.ts.map +1 -0
  101. package/dist/review-flow-public.js +11 -0
  102. package/dist/review-flow-public.js.map +1 -0
  103. package/dist/review-flow.d.ts +6 -0
  104. package/dist/review-flow.d.ts.map +1 -1
  105. package/dist/review-flow.js +1 -1
  106. package/dist/runtime-internals-public.d.ts +2 -0
  107. package/dist/runtime-internals-public.d.ts.map +1 -0
  108. package/dist/runtime-internals-public.js +16 -0
  109. package/dist/runtime-internals-public.js.map +1 -0
  110. package/dist/runtime-internals.js +2 -1
  111. package/dist/server-events.d.ts +67 -0
  112. package/dist/server-events.d.ts.map +1 -1
  113. package/dist/server-process-builder.d.ts +7 -0
  114. package/dist/server-process-builder.d.ts.map +1 -1
  115. package/dist/state-helpers.d.ts +6 -0
  116. package/dist/state-helpers.d.ts.map +1 -1
  117. package/dist/subprocess-env.d.ts +3 -0
  118. package/dist/subprocess-env.d.ts.map +1 -1
  119. package/dist/tool-arguments.d.ts +4 -2
  120. package/dist/tool-arguments.d.ts.map +1 -1
  121. package/dist/tool-renderers.d.ts +6 -0
  122. package/dist/tool-renderers.d.ts.map +1 -1
  123. package/dist/turn-semantics.d.ts +14 -1
  124. package/dist/turn-semantics.d.ts.map +1 -1
  125. package/dist/types.d.ts +205 -24
  126. package/dist/types.d.ts.map +1 -1
  127. package/dist/ui-process-builder.d.ts +5 -0
  128. package/dist/ui-process-builder.d.ts.map +1 -1
  129. package/dist/worker-process-builder.d.ts +5 -0
  130. package/dist/worker-process-builder.d.ts.map +1 -1
  131. package/package.json +16 -15
  132. package/src/browser-ui-extension.ts +20 -0
  133. package/src/capabilities.ts +9 -1
  134. package/src/codecs.ts +1 -0
  135. package/src/commit-message.ts +5 -0
  136. package/src/core-capabilities.ts +398 -35
  137. package/src/define-process.ts +198 -23
  138. package/src/event-bus.ts +1 -0
  139. package/src/extension-api.ts +399 -55
  140. package/src/external-action-source.ts +7 -2
  141. package/src/external-source-poll.ts +72 -6
  142. package/src/flow.ts +352 -23
  143. package/src/form-contract.ts +0 -4
  144. package/src/fs-utils.ts +4 -0
  145. package/src/git-binary.ts +2 -1
  146. package/src/graph-fragments.ts +16 -0
  147. package/src/host-capabilities.ts +9 -6
  148. package/src/index.ts +14 -202
  149. package/src/integration-http.ts +15 -3
  150. package/src/json-data.ts +1 -1
  151. package/src/leaf-outcome-renderer.ts +35 -0
  152. package/src/leaf-outcomes.ts +3 -0
  153. package/src/model-provider.ts +169 -20
  154. package/src/pi-config-public.ts +7 -0
  155. package/src/pi-config.ts +47 -2
  156. package/src/process-definition-internals.ts +4 -0
  157. package/src/process-flow-view.ts +2 -0
  158. package/src/process-graph.ts +34 -0
  159. package/src/process-launcher-builder.ts +5 -0
  160. package/src/process-watcher-builder.ts +5 -0
  161. package/src/process-watcher-source.ts +6 -4
  162. package/src/project-binding.ts +5 -1
  163. package/src/registry-utils.ts +6 -0
  164. package/src/repository-feedback.ts +59 -5
  165. package/src/repository-git-env.ts +6 -2
  166. package/src/repository-http.ts +19 -2
  167. package/src/repository-https.ts +1 -1
  168. package/src/repository-issue-watcher.ts +64 -7
  169. package/src/repository-reconciliation.ts +30 -0
  170. package/src/repository-source-config.ts +66 -4
  171. package/src/repository-types.ts +43 -5
  172. package/src/review-flow-public.ts +5 -0
  173. package/src/review-flow.ts +6 -0
  174. package/src/runtime-internals-public.ts +7 -0
  175. package/src/server-events.ts +67 -0
  176. package/src/server-process-builder.ts +10 -1
  177. package/src/state-helpers.ts +6 -0
  178. package/src/subprocess-env.ts +3 -0
  179. package/src/tool-arguments.ts +4 -2
  180. package/src/tool-renderers.ts +6 -0
  181. package/src/turn-semantics.ts +15 -2
  182. package/src/types.ts +212 -30
  183. package/src/ui-process-builder.ts +8 -1
  184. package/src/worker-process-builder.ts +8 -1
  185. package/dist/chunk-LIIP7FMU.js.map +0 -1
  186. package/dist/chunk-TA4KO53Q.js.map +0 -1
  187. package/dist/chunk-WFY2WWZE.js.map +0 -1
package/dist/index.js CHANGED
@@ -1,19 +1,7 @@
1
1
  import {
2
- FRAMEWORK_LLM_TOOL_NAMES,
3
- PI_BUILT_IN_TOOL_NAMES,
4
2
  RESERVED_INTEGRATION_TOOL_NAMES,
5
- TURN_COMPLETION_MODES,
6
- TURN_CONTEXT_MODES,
7
- collectProcessAvailableToolNames,
8
- resolveTurnAvailableToolNames,
9
3
  validatePiBuiltInToolArray
10
- } from "./chunk-TA4KO53Q.js";
11
- import {
12
- buildPlanSavedEventPayload,
13
- buildReviewCompletedEventPayload,
14
- buildReviewRequestedEventPayload,
15
- filterStringArray
16
- } from "./chunk-LIIP7FMU.js";
4
+ } from "./chunk-I7U6HCLN.js";
17
5
  import {
18
6
  cloneArrayValueMap,
19
7
  cloneMap,
@@ -21,7 +9,7 @@ import {
21
9
  markDefinedProcess,
22
10
  registerUnique,
23
11
  setProcessTurnTransitions
24
- } from "./chunk-WFY2WWZE.js";
12
+ } from "./chunk-TM2LTSW4.js";
25
13
 
26
14
  // src/capabilities.ts
27
15
  function createCapabilityToken(id, options = {}) {
@@ -47,7 +35,9 @@ var BUILT_IN_COMMIT_MESSAGE_RULES = "Write a concise imperative subject that sum
47
35
 
48
36
  // src/core-capabilities.ts
49
37
  var coreHostCapabilities = {
38
+ /** @public */
50
39
  serverSetup: createCapabilityToken("core:serverSetup"),
40
+ /** @internal */
51
41
  processModelSelection: createCapabilityToken(
52
42
  "core:processModelSelection"
53
43
  )
@@ -1131,12 +1121,6 @@ function humanTurn(input) {
1131
1121
  kind: "human"
1132
1122
  };
1133
1123
  }
1134
- function externalTurn(input) {
1135
- return {
1136
- ...input,
1137
- kind: "external"
1138
- };
1139
- }
1140
1124
 
1141
1125
  // src/event-bus.ts
1142
1126
  function createEventBus() {
@@ -1169,6 +1153,7 @@ function createEventBus() {
1169
1153
 
1170
1154
  // src/extension-api.ts
1171
1155
  var SafeLaunchPreparationError = class extends Error {
1156
+ /** @public */
1172
1157
  constructor(message, safeSummary) {
1173
1158
  super(message);
1174
1159
  this.safeSummary = safeSummary;
@@ -1189,7 +1174,11 @@ function defineExternalActionSource(metadata) {
1189
1174
 
1190
1175
  // src/external-source-poll.ts
1191
1176
  function createExternalSourcePollReporter(sources, result, options = {}) {
1177
+ const isCurrent = (kind, armed) => sources.listArmed(kind).some((current2) => sameSubscription(armed, current2));
1178
+ const current = (armed) => options.currentKinds === void 0 || options.currentKinds.some((kind) => isCurrent(kind, armed));
1192
1179
  return {
1180
+ isCurrent,
1181
+ /** @public */
1193
1182
  async poll(kind, read) {
1194
1183
  for (const armed of sources.listArmed(kind)) {
1195
1184
  try {
@@ -1201,7 +1190,9 @@ function createExternalSourcePollReporter(sources, result, options = {}) {
1201
1190
  }
1202
1191
  }
1203
1192
  },
1193
+ /** @public */
1204
1194
  async fire(armed, event, mergeKey) {
1195
+ if (!current(armed)) return false;
1205
1196
  const fired = await sources.fire({
1206
1197
  instanceId: armed.instanceId,
1207
1198
  armingId: armed.id,
@@ -1213,8 +1204,9 @@ function createExternalSourcePollReporter(sources, result, options = {}) {
1213
1204
  else result.errors.push(`${armed.id}:fire_failed`);
1214
1205
  return fired.ok;
1215
1206
  },
1207
+ /** @public */
1216
1208
  observe(armed, input) {
1217
- if (sources.observe && armed.generation)
1209
+ if (current(armed) && sources.observe && armed.generation)
1218
1210
  return sources.observe({
1219
1211
  instanceId: armed.instanceId,
1220
1212
  armingId: armed.id,
@@ -1224,6 +1216,9 @@ function createExternalSourcePollReporter(sources, result, options = {}) {
1224
1216
  }
1225
1217
  };
1226
1218
  }
1219
+ function sameSubscription(captured, current) {
1220
+ return current.id === captured.id && current.instanceId === captured.instanceId && current.generation === captured.generation && JSON.stringify(current.resolved) === JSON.stringify(captured.resolved);
1221
+ }
1227
1222
 
1228
1223
  // src/flow.ts
1229
1224
  import path2 from "path";
@@ -1332,18 +1327,12 @@ function getProcessGraph(registry, processId) {
1332
1327
  }
1333
1328
  return toProcessGraphView(definition);
1334
1329
  }
1335
- function getAllProcessGraphs(registry) {
1336
- return [...registry.values()].map((definition) => toProcessGraphView(definition));
1337
- }
1338
1330
  function getProcessTurnGraph(registry, processId, turnId) {
1339
1331
  return getProcessGraph(registry, processId).turns.get(turnId);
1340
1332
  }
1341
1333
  function getTurnTransitionsForProcessGraph(registry, processId, turnId) {
1342
1334
  return getProcessTurnGraph(registry, processId, turnId)?.transitions ?? [];
1343
1335
  }
1344
- function getReachableTurnIdsForProcessGraph(registry, processId) {
1345
- return [...getProcessGraph(registry, processId).turns.keys()];
1346
- }
1347
1336
  function isTurnAvailableForProcessGraph(registry, processId, turnId) {
1348
1337
  return getProcessGraph(registry, processId).turns.has(turnId);
1349
1338
  }
@@ -1438,7 +1427,6 @@ function validateProcessGraphTurnTransitions(graph) {
1438
1427
 
1439
1428
  // src/flow.ts
1440
1429
  var DEFAULT_PLAN_RESULT_OUTCOME_ID = "plan_saved";
1441
- var DEFAULT_FLOW_PRODUCT_NAME = "default";
1442
1430
  var ASSISTANT_OUTPUT_TURN_RESULT = { mode: "assistant_output", required: true };
1443
1431
  var OUTCOME_TOOL_MARKDOWN_PARAMETER_NAME = "markdown";
1444
1432
  var OUTCOME_TOOL_ARGUMENT_TURN_RESULT = {
@@ -1632,8 +1620,11 @@ function wrapOutcomeCallback(callback) {
1632
1620
  });
1633
1621
  }
1634
1622
  var RouteAndEffectBuilder = class {
1623
+ /** @internal */
1635
1624
  target = null;
1625
+ /** @internal */
1636
1626
  flowEffect;
1627
+ /** @internal */
1637
1628
  setTarget(next) {
1638
1629
  if (this.target && next) {
1639
1630
  throw new Error("Flow route already declares a target");
@@ -1641,30 +1632,38 @@ var RouteAndEffectBuilder = class {
1641
1632
  this.target = next;
1642
1633
  return this;
1643
1634
  }
1635
+ /** @public */
1644
1636
  to(turnId) {
1645
1637
  return this.setTarget({ kind: "to", turnId });
1646
1638
  }
1639
+ /** @public */
1647
1640
  complete() {
1648
1641
  return this.setTarget({ kind: "complete" });
1649
1642
  }
1643
+ /** @public */
1650
1644
  lifecycleStatus(status) {
1651
1645
  return this.setTarget({ kind: "lifecycleStatus", status });
1652
1646
  }
1647
+ /** @internal */
1653
1648
  stay() {
1654
1649
  this.target = null;
1655
1650
  return this;
1656
1651
  }
1652
+ /** @public */
1657
1653
  state(fn) {
1658
1654
  this.flowEffect = async (input) => ({ state: await fn(input) });
1659
1655
  return this;
1660
1656
  }
1657
+ /** @public */
1661
1658
  effect(fn) {
1662
1659
  this.flowEffect = fn;
1663
1660
  return this;
1664
1661
  }
1662
+ /** @internal */
1665
1663
  hasRoute() {
1666
1664
  return this.target !== null;
1667
1665
  }
1666
+ /** @internal */
1668
1667
  buildRouteTarget() {
1669
1668
  return buildRouteTargetSpec(this.target);
1670
1669
  }
@@ -1685,11 +1684,15 @@ function isStringArray(value) {
1685
1684
  return Array.isArray(value) && value.every((entry) => typeof entry === "string");
1686
1685
  }
1687
1686
  var ParameterizedOutcomeBuilder = class extends RouteAndEffectBuilder {
1687
+ /** @internal */
1688
1688
  outcomeDescription = null;
1689
+ /** @internal */
1689
1690
  parameters = {};
1691
+ /** @internal */
1690
1692
  publishedMarkdownParameter = null;
1693
+ /** @internal */
1691
1694
  summaryParameter = null;
1692
- /** Optional concise result publication, separate from the full Markdown. */
1695
+ /** Optional concise result publication, separate from the full Markdown. @public */
1693
1696
  resultSummary(name = "resultSummary") {
1694
1697
  this.summaryParameter = name;
1695
1698
  return this.parameter(name, {
@@ -1697,16 +1700,21 @@ var ParameterizedOutcomeBuilder = class extends RouteAndEffectBuilder {
1697
1700
  description: "Concise summary of this attempt\u2019s outcome."
1698
1701
  });
1699
1702
  }
1703
+ /** @internal */
1700
1704
  publishedMarkdownFields() {
1701
1705
  return this.publishedMarkdownParameter ? {
1706
+ /** @internal */
1702
1707
  publishedProduct: this.publishedMarkdownParameter,
1708
+ /** @internal */
1703
1709
  turnResultMarkdownParameter: this.publishedMarkdownParameter
1704
1710
  } : {};
1705
1711
  }
1712
+ /** @public */
1706
1713
  description(text) {
1707
1714
  this.outcomeDescription = text;
1708
1715
  return this;
1709
1716
  }
1717
+ /** @internal */
1710
1718
  parameter(name, spec) {
1711
1719
  if (name.trim() === "") {
1712
1720
  throw new Error("Outcome parameter name must be non-empty");
@@ -1734,9 +1742,11 @@ var ParameterizedOutcomeBuilder = class extends RouteAndEffectBuilder {
1734
1742
  ...type === "array" ? { items: resolved.items ?? { type: "string" } } : {}
1735
1743
  });
1736
1744
  }
1745
+ /** @internal */
1737
1746
  string(name, options = {}) {
1738
1747
  return this.typedParameter(name, "string", options);
1739
1748
  }
1749
+ /** @public */
1740
1750
  markdown(name, options = {}) {
1741
1751
  const resolved = typeof options === "string" ? { description: options } : options;
1742
1752
  const { publish, ...parameterOptions } = resolved;
@@ -1753,27 +1763,35 @@ var ParameterizedOutcomeBuilder = class extends RouteAndEffectBuilder {
1753
1763
  requiredErrorCode: resolved.requiredErrorCode ?? (publish ? `${name}_required` : void 0)
1754
1764
  });
1755
1765
  }
1766
+ /** @public */
1756
1767
  requiredString(name, options = {}) {
1757
1768
  return this.typedParameter(name, "string", this.withRequired(name, options));
1758
1769
  }
1770
+ /** @internal */
1759
1771
  number(name, options = {}) {
1760
1772
  return this.typedParameter(name, "number", options);
1761
1773
  }
1774
+ /** @internal */
1762
1775
  requiredNumber(name, options = {}) {
1763
1776
  return this.typedParameter(name, "number", this.withRequired(name, options));
1764
1777
  }
1778
+ /** @internal */
1765
1779
  boolean(name, options = {}) {
1766
1780
  return this.typedParameter(name, "boolean", options);
1767
1781
  }
1782
+ /** @internal */
1768
1783
  requiredBoolean(name, options = {}) {
1769
1784
  return this.typedParameter(name, "boolean", this.withRequired(name, options));
1770
1785
  }
1786
+ /** @internal */
1771
1787
  stringArray(name, options = {}) {
1772
1788
  return this.typedParameter(name, "array", options);
1773
1789
  }
1790
+ /** @internal */
1774
1791
  requiredStringArray(name, options = {}) {
1775
1792
  return this.typedParameter(name, "array", this.withRequired(name, options));
1776
1793
  }
1794
+ /** @internal */
1777
1795
  enum(name, valuesOrOptions) {
1778
1796
  const resolved = isStringArray(valuesOrOptions) ? { values: [...valuesOrOptions] } : valuesOrOptions;
1779
1797
  const { values = [], ...options } = resolved;
@@ -1784,15 +1802,18 @@ var ParameterizedOutcomeBuilder = class extends RouteAndEffectBuilder {
1784
1802
  enum: [...values]
1785
1803
  });
1786
1804
  }
1805
+ /** @public */
1787
1806
  object(name, options = {}) {
1788
1807
  return this.typedParameter(name, "object", options);
1789
1808
  }
1809
+ /** @internal */
1790
1810
  array(name, options = {}) {
1791
1811
  return this.typedParameter(name, "array", options);
1792
1812
  }
1793
1813
  };
1794
1814
  var OutcomeToolBuilder = class extends ParameterizedOutcomeBuilder {
1795
1815
  stateRouting;
1816
+ /** @public */
1796
1817
  routeByState(branches, choose) {
1797
1818
  if (this.hasRoute() || this.stateRouting) {
1798
1819
  throw new Error("State-routed outcome cannot declare another route");
@@ -1803,6 +1824,7 @@ var OutcomeToolBuilder = class extends ParameterizedOutcomeBuilder {
1803
1824
  this.stateRouting = { branches, choose };
1804
1825
  return this;
1805
1826
  }
1827
+ /** @internal */
1806
1828
  build() {
1807
1829
  if (!this.outcomeDescription) {
1808
1830
  throw new Error("LLM outcome tool must declare .description(...)");
@@ -1831,11 +1853,13 @@ var OutcomeToolBuilder = class extends ParameterizedOutcomeBuilder {
1831
1853
  };
1832
1854
  var AutomaticOutcomeBuilder = class extends ParameterizedOutcomeBuilder {
1833
1855
  waits = false;
1856
+ /** @public */
1834
1857
  wait() {
1835
1858
  if (this.hasRoute()) throw new Error("Waiting outcome cannot declare another route");
1836
1859
  this.waits = true;
1837
1860
  return this;
1838
1861
  }
1862
+ /** @internal */
1839
1863
  build() {
1840
1864
  if (!this.outcomeDescription) {
1841
1865
  throw new Error("Automatic outcome must declare .description(...)");
@@ -1863,10 +1887,12 @@ var PlanResultBuilder = class extends RouteAndEffectBuilder {
1863
1887
  summarySpec = null;
1864
1888
  acceptanceCriteriaSpec = null;
1865
1889
  reviewTurnId = null;
1890
+ /** @internal */
1866
1891
  description(text) {
1867
1892
  this.resultDescription = text;
1868
1893
  return this;
1869
1894
  }
1895
+ /** @internal */
1870
1896
  summary(options = {}) {
1871
1897
  const resolved = typeof options === "string" ? { description: options } : options;
1872
1898
  this.summarySpec = textField({
@@ -1875,6 +1901,7 @@ var PlanResultBuilder = class extends RouteAndEffectBuilder {
1875
1901
  });
1876
1902
  return this;
1877
1903
  }
1904
+ /** @internal */
1878
1905
  acceptanceCriteria(options = {}) {
1879
1906
  const resolved = typeof options === "string" ? { description: options } : options;
1880
1907
  this.acceptanceCriteriaSpec = stringArrayField({
@@ -1885,10 +1912,12 @@ var PlanResultBuilder = class extends RouteAndEffectBuilder {
1885
1912
  });
1886
1913
  return this;
1887
1914
  }
1915
+ /** @internal */
1888
1916
  review(turnId) {
1889
1917
  this.reviewTurnId = turnId;
1890
1918
  return this.setTarget({ kind: "to", turnId });
1891
1919
  }
1920
+ /** @internal */
1892
1921
  buildOutcome() {
1893
1922
  if (!this.summarySpec) {
1894
1923
  throw new Error("plan result must declare .summary(...)");
@@ -1920,6 +1949,7 @@ var PlanResultBuilder = class extends RouteAndEffectBuilder {
1920
1949
  }
1921
1950
  };
1922
1951
  var TurnEndBuilder = class extends RouteAndEffectBuilder {
1952
+ /** @internal */
1923
1953
  constructor(outcomeId, parent) {
1924
1954
  super();
1925
1955
  this.outcomeId = outcomeId;
@@ -1931,12 +1961,15 @@ var TurnEndBuilder = class extends RouteAndEffectBuilder {
1931
1961
  if (!this.parent) throw new Error(`${this.builderName} builder is not attached to a turn`);
1932
1962
  return this.parent;
1933
1963
  }
1964
+ /** @internal */
1934
1965
  get id() {
1935
1966
  return this.turn.id;
1936
1967
  }
1968
+ /** @internal */
1937
1969
  get definition() {
1938
1970
  return this.turn.definition;
1939
1971
  }
1972
+ /** @internal */
1940
1973
  buildResult() {
1941
1974
  const effect = this.flowEffect ? wrapOutcomeCallback(this.flowEffect) : void 0;
1942
1975
  return {
@@ -1947,30 +1980,39 @@ var TurnEndBuilder = class extends RouteAndEffectBuilder {
1947
1980
  }
1948
1981
  };
1949
1982
  var PublishedResultBuilder = class extends TurnEndBuilder {
1983
+ /** @internal */
1950
1984
  builderName = "Published result";
1985
+ /** @internal */
1951
1986
  buildTurnEnd() {
1952
1987
  return this.buildResult();
1953
1988
  }
1954
1989
  };
1955
1990
  var LlmTurnEndBuilder = class extends TurnEndBuilder {
1991
+ /** @internal */
1956
1992
  builderName = "LLM turn end";
1993
+ /** @internal */
1957
1994
  constructor(outcomeId, parent) {
1958
1995
  super(outcomeId, parent);
1959
1996
  if (outcomeId.trim() === "") throw new Error("LLM turn end outcome must be non-empty");
1960
1997
  }
1998
+ /** @internal */
1961
1999
  build() {
1962
2000
  return this.buildResult();
1963
2001
  }
1964
2002
  };
1965
2003
  var DescribedTurnBuilder = class {
2004
+ /** @internal */
1966
2005
  constructor(turnId) {
1967
2006
  this.turnId = turnId;
1968
2007
  }
1969
2008
  turnId;
2009
+ /** @internal */
1970
2010
  turnDescription = null;
2011
+ /** @internal */
1971
2012
  get id() {
1972
2013
  return this.turnId;
1973
2014
  }
2015
+ /** @public */
1974
2016
  description(description) {
1975
2017
  this.turnDescription = description;
1976
2018
  return this;
@@ -1993,34 +2035,41 @@ var LlmFlowBuilder = class extends DescribedTurnBuilder {
1993
2035
  publishedResult = null;
1994
2036
  endResult = null;
1995
2037
  outcomeToolBuilders = /* @__PURE__ */ new Map();
2038
+ /** @internal */
1996
2039
  get definition() {
1997
2040
  return this.buildDefinition();
1998
2041
  }
2042
+ /** @internal */
1999
2043
  modelPurpose(purpose) {
2000
2044
  this.modelPurposeValue = purpose;
2001
2045
  return this;
2002
2046
  }
2047
+ /** @public */
2003
2048
  tools(...tools) {
2004
2049
  this.availableTools = tools;
2005
2050
  return this;
2006
2051
  }
2052
+ /** @public */
2007
2053
  integrationTools(...tools) {
2008
2054
  this.availableIntegrationTools = tools.map((tool) => tool.trim());
2009
2055
  return this;
2010
2056
  }
2057
+ /** @public */
2011
2058
  resolveIntegrationTools(resolver) {
2012
2059
  this.integrationToolResolver = resolver;
2013
2060
  return this;
2014
2061
  }
2062
+ /** @public */
2015
2063
  prepare(fn) {
2016
2064
  this.preparation = fn;
2017
2065
  return this;
2018
2066
  }
2019
- /** Enable durable operator questions for this LLM turn. */
2067
+ /** Enable durable operator questions for this LLM turn. @public */
2020
2068
  askQuestions() {
2021
2069
  this.questionsEnabled = true;
2022
2070
  return this;
2023
2071
  }
2072
+ /** @public */
2024
2073
  freshPrimary() {
2025
2074
  this.branchType = "primary";
2026
2075
  this.context = "fresh";
@@ -2028,6 +2077,7 @@ var LlmFlowBuilder = class extends DescribedTurnBuilder {
2028
2077
  this.restorePrimaryLeafAfterTurn = void 0;
2029
2078
  return this;
2030
2079
  }
2080
+ /** @internal */
2031
2081
  freshSeededPrimary() {
2032
2082
  this.branchType = "primary";
2033
2083
  this.context = "fresh_seeded";
@@ -2035,17 +2085,20 @@ var LlmFlowBuilder = class extends DescribedTurnBuilder {
2035
2085
  this.restorePrimaryLeafAfterTurn = void 0;
2036
2086
  return this;
2037
2087
  }
2088
+ /** @public */
2038
2089
  fullPrimary() {
2039
2090
  this.branchType = "primary";
2040
2091
  this.context = "full";
2041
2092
  return this;
2042
2093
  }
2094
+ /** @internal */
2043
2095
  rootBranchReview() {
2044
2096
  this.branchType = "root_branch";
2045
2097
  this.context = "full";
2046
2098
  this.restorePrimaryLeafAfterTurn = true;
2047
2099
  return this;
2048
2100
  }
2101
+ /** @public */
2049
2102
  continueFromPrimaryLeaf() {
2050
2103
  this.startFrom = {
2051
2104
  kind: "semantic_ref",
@@ -2054,6 +2107,7 @@ var LlmFlowBuilder = class extends DescribedTurnBuilder {
2054
2107
  };
2055
2108
  return this;
2056
2109
  }
2110
+ /** @internal */
2057
2111
  continueFromReviewBranch() {
2058
2112
  this.startFrom = {
2059
2113
  kind: "semantic_ref",
@@ -2062,9 +2116,11 @@ var LlmFlowBuilder = class extends DescribedTurnBuilder {
2062
2116
  };
2063
2117
  return this;
2064
2118
  }
2119
+ /** @internal */
2065
2120
  continueFromProductBranch(productName, fallback = { kind: "current_leaf" }) {
2066
2121
  return this.startFromProductBranch(productName, fallback);
2067
2122
  }
2123
+ /** @internal */
2068
2124
  startFromReviewBranch() {
2069
2125
  this.startFrom = {
2070
2126
  kind: "semantic_ref",
@@ -2073,6 +2129,7 @@ var LlmFlowBuilder = class extends DescribedTurnBuilder {
2073
2129
  };
2074
2130
  return this;
2075
2131
  }
2132
+ /** @internal */
2076
2133
  startFromProductBranch(productName, fallback = { kind: "session_root" }) {
2077
2134
  this.startFrom = {
2078
2135
  kind: "product_ref",
@@ -2081,18 +2138,22 @@ var LlmFlowBuilder = class extends DescribedTurnBuilder {
2081
2138
  };
2082
2139
  return this;
2083
2140
  }
2141
+ /** @internal */
2084
2142
  startFromRoot() {
2085
2143
  this.startFrom = { kind: "session_root" };
2086
2144
  return this;
2087
2145
  }
2146
+ /** @public */
2088
2147
  consume(productName) {
2089
2148
  this.consumedProductNames.add(normalizeProductName(productName));
2090
2149
  return this;
2091
2150
  }
2151
+ /** @public */
2092
2152
  optionalConsume(productName) {
2093
2153
  this.optionalConsumedProductNames.add(normalizeProductName(productName));
2094
2154
  return this;
2095
2155
  }
2156
+ /** @public */
2096
2157
  publish(productName) {
2097
2158
  const normalized = normalizeProductName(productName);
2098
2159
  if (this.publishedResult) {
@@ -2105,6 +2166,7 @@ var LlmFlowBuilder = class extends DescribedTurnBuilder {
2105
2166
  this.publishedResult = { productName: normalized, builder };
2106
2167
  return builder;
2107
2168
  }
2169
+ /** @public */
2108
2170
  end(outcomeId) {
2109
2171
  if (this.endResult) {
2110
2172
  throw new Error(`LLM turn '${this.turnId}' declares duplicate .end(...) completion`);
@@ -2118,6 +2180,7 @@ var LlmFlowBuilder = class extends DescribedTurnBuilder {
2118
2180
  this.endResult = new LlmTurnEndBuilder(outcomeId, this);
2119
2181
  return this.endResult;
2120
2182
  }
2183
+ /** @public */
2121
2184
  buildPrompt(fn) {
2122
2185
  this.promptBuilder = (ctx) => fn(
2123
2186
  createFlowPromptContext(ctx, [...this.consumedProductNames], [
@@ -2126,10 +2189,12 @@ var LlmFlowBuilder = class extends DescribedTurnBuilder {
2126
2189
  );
2127
2190
  return this;
2128
2191
  }
2192
+ /** @public */
2129
2193
  prompt(prompt) {
2130
2194
  this.promptBuilder = prompt;
2131
2195
  return this;
2132
2196
  }
2197
+ /** @public */
2133
2198
  outcomeTool(id, configure) {
2134
2199
  if (id.trim() === "") {
2135
2200
  throw new Error(`LLM turn '${this.turnId}' declares an empty outcome tool id`);
@@ -2176,6 +2241,7 @@ var LlmFlowBuilder = class extends DescribedTurnBuilder {
2176
2241
  prompt
2177
2242
  };
2178
2243
  }
2244
+ /** @internal */
2179
2245
  producesPlan(configure) {
2180
2246
  const definition = this.buildBaseDefinition();
2181
2247
  const plan = configure(new PlanResultBuilder());
@@ -2273,6 +2339,7 @@ var LlmFlowBuilder = class extends DescribedTurnBuilder {
2273
2339
  };
2274
2340
  var ExternalActionTurnBuilder = class extends DescribedTurnBuilder {
2275
2341
  externalActionBuilders = /* @__PURE__ */ new Map();
2342
+ /** @public */
2276
2343
  externalAction(externalActionId, source, configure) {
2277
2344
  if (this.externalActionBuilders.has(externalActionId)) {
2278
2345
  throw new Error(
@@ -2287,6 +2354,7 @@ var ExternalActionTurnBuilder = class extends DescribedTurnBuilder {
2287
2354
  );
2288
2355
  return this;
2289
2356
  }
2357
+ /** @internal */
2290
2358
  buildExternalActions() {
2291
2359
  return this.externalActionBuilders.size > 0 ? Object.fromEntries(
2292
2360
  [...this.externalActionBuilders].map(([id, builder]) => [id, builder.build()])
@@ -2294,21 +2362,26 @@ var ExternalActionTurnBuilder = class extends DescribedTurnBuilder {
2294
2362
  }
2295
2363
  };
2296
2364
  var AutomaticFlowBuilder = class extends ExternalActionTurnBuilder {
2365
+ /** @internal */
2297
2366
  turnKind = "Automatic";
2298
2367
  runFn = null;
2299
2368
  outcomeBuilders = /* @__PURE__ */ new Map();
2300
2369
  availableIntegrationTools = [];
2370
+ /** @internal */
2301
2371
  get definition() {
2302
2372
  return this.buildDefinition();
2303
2373
  }
2374
+ /** @public */
2304
2375
  run(fn) {
2305
2376
  this.runFn = fn;
2306
2377
  return this;
2307
2378
  }
2379
+ /** @public */
2308
2380
  integrationTools(...tools) {
2309
2381
  this.availableIntegrationTools = tools.map((tool) => tool.trim());
2310
2382
  return this;
2311
2383
  }
2384
+ /** @public */
2312
2385
  outcome(id, configure) {
2313
2386
  if (id.trim() === "") {
2314
2387
  throw new Error(`Automatic turn '${this.turnId}' declares an empty outcome id`);
@@ -2358,51 +2431,63 @@ function inferAcceptanceState(actionId) {
2358
2431
  return "neutral";
2359
2432
  }
2360
2433
  var HumanActionBuilder = class {
2434
+ /** @internal */
2361
2435
  constructor(actionId) {
2362
2436
  this.actionId = actionId;
2363
2437
  }
2364
2438
  actionId;
2365
2439
  spec = {};
2440
+ /** @public */
2366
2441
  label(label) {
2367
2442
  this.spec.label = label;
2368
2443
  return this;
2369
2444
  }
2445
+ /** @internal */
2370
2446
  description(description) {
2371
2447
  this.spec.description = description;
2372
2448
  return this;
2373
2449
  }
2450
+ /** @public */
2374
2451
  acceptanceState(state) {
2375
2452
  this.spec.acceptanceState = state;
2376
2453
  return this;
2377
2454
  }
2455
+ /** @public */
2378
2456
  form(form) {
2379
2457
  this.spec.form = form;
2380
2458
  return this;
2381
2459
  }
2460
+ /** @public */
2382
2461
  to(turnId) {
2383
2462
  this.spec.to = turnId;
2384
2463
  return this;
2385
2464
  }
2465
+ /** @internal */
2386
2466
  complete() {
2387
2467
  this.spec.complete = true;
2388
2468
  return this;
2389
2469
  }
2470
+ /** @public */
2390
2471
  lifecycleStatus(status) {
2391
2472
  this.spec.lifecycleStatus = status;
2392
2473
  return this;
2393
2474
  }
2475
+ /** @internal */
2394
2476
  trigger(trigger) {
2395
2477
  this.spec.trigger = trigger;
2396
2478
  return this;
2397
2479
  }
2480
+ /** @internal */
2398
2481
  schedulable(value = true) {
2399
2482
  this.spec.schedulable = value;
2400
2483
  return this;
2401
2484
  }
2485
+ /** @public */
2402
2486
  effect(effect) {
2403
2487
  this.spec.effect = effect;
2404
2488
  return this;
2405
2489
  }
2490
+ /** @internal */
2406
2491
  build() {
2407
2492
  return {
2408
2493
  label: typeof this.spec.label === "string" ? this.spec.label : humanizeProcessLabel(this.actionId),
@@ -2413,33 +2498,41 @@ var HumanActionBuilder = class {
2413
2498
  };
2414
2499
  var ExternalActionBuilder = class {
2415
2500
  spec;
2501
+ /** @internal */
2416
2502
  constructor(actionId, source) {
2417
2503
  this.spec = { id: actionId, source };
2418
2504
  }
2505
+ /** @public */
2419
2506
  label(label) {
2420
2507
  this.spec.label = label;
2421
2508
  return this;
2422
2509
  }
2510
+ /** @public */
2423
2511
  description(description) {
2424
2512
  this.spec.description = description;
2425
2513
  return this;
2426
2514
  }
2515
+ /** @public */
2427
2516
  when(condition) {
2428
2517
  this.spec.when = condition;
2429
2518
  return this;
2430
2519
  }
2520
+ /** @public */
2431
2521
  to(turnId) {
2432
2522
  this.spec.to = turnId;
2433
2523
  return this;
2434
2524
  }
2525
+ /** @internal */
2435
2526
  complete() {
2436
2527
  this.spec.complete = true;
2437
2528
  return this;
2438
2529
  }
2530
+ /** @public */
2439
2531
  lifecycleStatus(status) {
2440
2532
  this.spec.lifecycleStatus = status;
2441
2533
  return this;
2442
2534
  }
2535
+ /** @internal */
2443
2536
  publishInput(productName, options) {
2444
2537
  this.spec.publishInput = {
2445
2538
  productName: normalizeProductName(productName),
@@ -2447,15 +2540,18 @@ var ExternalActionBuilder = class {
2447
2540
  };
2448
2541
  return this;
2449
2542
  }
2543
+ /** @public */
2450
2544
  effect(effect) {
2451
2545
  this.spec.effect = effect;
2452
2546
  return this;
2453
2547
  }
2548
+ /** @internal */
2454
2549
  build() {
2455
2550
  return this.spec;
2456
2551
  }
2457
2552
  };
2458
2553
  var HumanFlowBuilder = class extends ExternalActionTurnBuilder {
2554
+ /** @internal */
2459
2555
  turnKind = "Human";
2460
2556
  reviewProductName;
2461
2557
  reviewSemanticRef;
@@ -2463,6 +2559,7 @@ var HumanFlowBuilder = class extends ExternalActionTurnBuilder {
2463
2559
  turnCommentary;
2464
2560
  notes;
2465
2561
  actions = /* @__PURE__ */ new Map();
2562
+ /** @public */
2466
2563
  get definition() {
2467
2564
  if (!this.turnDescription) {
2468
2565
  throw new Error(`Human turn '${this.turnId}' must declare .description(...)`);
@@ -2482,24 +2579,29 @@ var HumanFlowBuilder = class extends ExternalActionTurnBuilder {
2482
2579
  ...externalActions ? { externalActions } : {}
2483
2580
  };
2484
2581
  }
2582
+ /** @public */
2485
2583
  reviewProduct(productName) {
2486
2584
  const normalized = normalizeProductName(productName);
2487
2585
  this.reviewProductName = normalized;
2488
2586
  this.reviewSemanticRef = normalized === "plan" ? "plan" : normalized === "review" ? "review" : void 0;
2489
2587
  return this;
2490
2588
  }
2589
+ /** @public */
2491
2590
  operatorAttention(attention) {
2492
2591
  this.operatorAttentionValue = attention;
2493
2592
  return this;
2494
2593
  }
2594
+ /** @internal */
2495
2595
  commentary(commentary) {
2496
2596
  this.turnCommentary = commentary;
2497
2597
  return this;
2498
2598
  }
2599
+ /** @internal */
2499
2600
  notesFields(notes) {
2500
2601
  this.notes = notes;
2501
2602
  return this;
2502
2603
  }
2604
+ /** @public */
2503
2605
  action(actionId, configure) {
2504
2606
  if (this.actions.has(actionId)) {
2505
2607
  throw new Error(`Human turn '${this.turnId}' declares duplicate action '${actionId}'`);
@@ -2511,6 +2613,7 @@ var HumanFlowBuilder = class extends ExternalActionTurnBuilder {
2511
2613
  }
2512
2614
  };
2513
2615
  var ExternalRouteBuilder = class {
2616
+ /** @internal */
2514
2617
  constructor(parent, source) {
2515
2618
  this.parent = parent;
2516
2619
  this.source = source;
@@ -2519,9 +2622,11 @@ var ExternalRouteBuilder = class {
2519
2622
  source;
2520
2623
  externalEffect;
2521
2624
  target = null;
2625
+ /** @internal */
2522
2626
  get id() {
2523
2627
  return this.parent.id;
2524
2628
  }
2629
+ /** @internal */
2525
2630
  get definition() {
2526
2631
  return this.parent.definition;
2527
2632
  }
@@ -2532,35 +2637,46 @@ var ExternalRouteBuilder = class {
2532
2637
  this.target = next;
2533
2638
  return this;
2534
2639
  }
2640
+ /** @public */
2535
2641
  to(turnId) {
2536
2642
  return this.setTarget({ kind: "to", turnId });
2537
2643
  }
2644
+ /** @internal */
2538
2645
  complete() {
2539
2646
  return this.setTarget({ kind: "complete" });
2540
2647
  }
2648
+ /** @internal */
2541
2649
  lifecycleStatus(status) {
2542
2650
  return this.setTarget({ kind: "lifecycleStatus", status });
2543
2651
  }
2652
+ /** @internal */
2544
2653
  state(fn) {
2545
2654
  this.externalEffect = async (ctx) => ({
2546
2655
  state: await fn({ ctx, event: ctx.event, input: ctx.input })
2547
2656
  });
2548
2657
  return this;
2549
2658
  }
2659
+ /** @internal */
2550
2660
  effect(fn) {
2551
2661
  this.externalEffect = (ctx) => fn({ ctx, event: ctx.event, input: ctx.input });
2552
2662
  return this;
2553
2663
  }
2664
+ /** @internal */
2554
2665
  build() {
2555
2666
  return {
2667
+ /** @internal */
2556
2668
  source: this.source,
2557
2669
  ...buildRouteTargetSpec(this.target),
2558
- ...this.externalEffect ? { effect: this.externalEffect } : {}
2670
+ ...this.externalEffect ? {
2671
+ /** @internal */
2672
+ effect: this.externalEffect
2673
+ } : {}
2559
2674
  };
2560
2675
  }
2561
2676
  };
2562
2677
  var ExternalFlowBuilder = class extends DescribedTurnBuilder {
2563
2678
  routeBuilders = [];
2679
+ /** @internal */
2564
2680
  get definition() {
2565
2681
  if (!this.turnDescription) {
2566
2682
  this.turnDescription = this.routeBuilders[0]?.build().source.description ?? "Wait for an external source";
@@ -2574,6 +2690,7 @@ var ExternalFlowBuilder = class extends DescribedTurnBuilder {
2574
2690
  transitions: this.routeBuilders.map((builder) => builder.build())
2575
2691
  };
2576
2692
  }
2693
+ /** @public */
2577
2694
  from(source) {
2578
2695
  const builder = new ExternalRouteBuilder(this, source);
2579
2696
  this.routeBuilders.push(
@@ -2588,27 +2705,37 @@ function chainHooks(hooks) {
2588
2705
  };
2589
2706
  }
2590
2707
  var FlowComponentBuilder = class {
2708
+ /** @internal */
2591
2709
  turns = [];
2710
+ /** @internal */
2592
2711
  serverHooks = [];
2712
+ /** @internal */
2593
2713
  uiHooks = [];
2714
+ /** @internal */
2594
2715
  launcherHooks = [];
2716
+ /** @internal */
2595
2717
  watcherHooks = [];
2718
+ /** @public */
2596
2719
  turn(turn) {
2597
2720
  this.turns.push(turn);
2598
2721
  return this;
2599
2722
  }
2723
+ /** @internal */
2600
2724
  server(hook) {
2601
2725
  this.serverHooks.push(hook);
2602
2726
  return this;
2603
2727
  }
2728
+ /** @internal */
2604
2729
  action(definition) {
2605
2730
  this.serverHooks.push((api) => api.action(definition));
2606
2731
  return this;
2607
2732
  }
2733
+ /** @internal */
2608
2734
  ui(hook) {
2609
2735
  this.uiHooks.push(hook);
2610
2736
  return this;
2611
2737
  }
2738
+ /** @public */
2612
2739
  launcher(definitionOrHook) {
2613
2740
  if (typeof definitionOrHook === "function") {
2614
2741
  this.launcherHooks.push(definitionOrHook);
@@ -2617,6 +2744,7 @@ var FlowComponentBuilder = class {
2617
2744
  }
2618
2745
  return this;
2619
2746
  }
2747
+ /** @public */
2620
2748
  watcher(definitionOrHook) {
2621
2749
  if (typeof definitionOrHook === "function") {
2622
2750
  this.watcherHooks.push(definitionOrHook);
@@ -2627,7 +2755,9 @@ var FlowComponentBuilder = class {
2627
2755
  }
2628
2756
  };
2629
2757
  var FlowFragmentBuilder = class extends FlowComponentBuilder {
2758
+ /** @internal */
2630
2759
  name;
2760
+ /** @internal */
2631
2761
  constructor(name) {
2632
2762
  super();
2633
2763
  if (name.trim() === "") {
@@ -2650,6 +2780,7 @@ var FlowProcessBuilder = class extends FlowComponentBuilder {
2650
2780
  processPiConfig;
2651
2781
  developmentTools = false;
2652
2782
  docker = false;
2783
+ /** @internal */
2653
2784
  constructor(processId) {
2654
2785
  super();
2655
2786
  if (processId.trim() === "") {
@@ -2657,15 +2788,17 @@ var FlowProcessBuilder = class extends FlowComponentBuilder {
2657
2788
  }
2658
2789
  this.processId = processId;
2659
2790
  }
2791
+ /** @public */
2660
2792
  displayName(displayName) {
2661
2793
  this.processDisplayName = displayName;
2662
2794
  return this;
2663
2795
  }
2796
+ /** @public */
2664
2797
  entry(turnId) {
2665
2798
  this.entryTurnId = turnId;
2666
2799
  return this;
2667
2800
  }
2668
- /** Declare an additional turn that launchers may select as the first turn. */
2801
+ /** Declare an additional turn that launchers may select as the first turn. @internal */
2669
2802
  alternateEntry(turnId) {
2670
2803
  this.alternateEntryTurnIds.push(turnId);
2671
2804
  return this;
@@ -2675,38 +2808,44 @@ var FlowProcessBuilder = class extends FlowComponentBuilder {
2675
2808
  * through. Flow diagrams render this as the main line. Must start at the entry
2676
2809
  * turn and reference only declared turns without repeats.
2677
2810
  */
2811
+ /** @public */
2678
2812
  happyPath(...turnIds) {
2679
2813
  this.happyPathTurnIds = turnIds;
2680
2814
  return this;
2681
2815
  }
2816
+ /** @public */
2682
2817
  codecs(input) {
2683
2818
  this.paramsCodec = input.params;
2684
2819
  this.stateCodec = input.state;
2685
2820
  return this;
2686
2821
  }
2822
+ /** @public */
2687
2823
  initialState(fn) {
2688
2824
  this.initialStateFn = fn;
2689
2825
  return this;
2690
2826
  }
2827
+ /** @public */
2691
2828
  repositoryCredentials(fn) {
2692
2829
  this.repositoryCredentialsFn = fn;
2693
2830
  return this;
2694
2831
  }
2695
- /** Resolve new process-volume capacity on the server; operator configuration wins. */
2832
+ /** Resolve new process-volume capacity on the server; operator configuration wins. @internal */
2696
2833
  resolveStorageSize(fn) {
2697
2834
  this.storageSizeResolver = fn;
2698
2835
  return this;
2699
2836
  }
2837
+ /** @public */
2700
2838
  piConfig(config) {
2701
2839
  this.processPiConfig = config;
2702
2840
  return this;
2703
2841
  }
2704
- /** Declare runner-provided process runtime capabilities. */
2842
+ /** Declare runner-provided process runtime capabilities. @public */
2705
2843
  runtime(capabilities) {
2706
2844
  this.developmentTools = capabilities.developmentTools === true;
2707
2845
  this.docker = capabilities.docker === true;
2708
2846
  return this;
2709
2847
  }
2848
+ /** @internal */
2710
2849
  use(fragment) {
2711
2850
  this.turns.push(...fragment.turns);
2712
2851
  this.serverHooks.push(...fragment.serverHooks);
@@ -2715,6 +2854,7 @@ var FlowProcessBuilder = class extends FlowComponentBuilder {
2715
2854
  this.watcherHooks.push(...fragment.watcherHooks);
2716
2855
  return this;
2717
2856
  }
2857
+ /** @public */
2718
2858
  define() {
2719
2859
  if (!this.processDisplayName) {
2720
2860
  throw new Error(`Flow process '${this.processId}' must declare .displayName(...)`);
@@ -2769,21 +2909,27 @@ var FlowProcessBuilder = class extends FlowComponentBuilder {
2769
2909
  }
2770
2910
  };
2771
2911
  var flow = {
2912
+ /** @public */
2772
2913
  llm(turnId) {
2773
2914
  return new LlmFlowBuilder(turnId);
2774
2915
  },
2916
+ /** @public */
2775
2917
  automatic(turnId) {
2776
2918
  return new AutomaticFlowBuilder(turnId);
2777
2919
  },
2920
+ /** @public */
2778
2921
  human(turnId) {
2779
2922
  return new HumanFlowBuilder(turnId);
2780
2923
  },
2924
+ /** @public */
2781
2925
  external(turnId) {
2782
2926
  return new ExternalFlowBuilder(turnId);
2783
2927
  },
2928
+ /** @public */
2784
2929
  fragment(name) {
2785
2930
  return new FlowFragmentBuilder(name);
2786
2931
  },
2932
+ /** @public */
2787
2933
  process(processId) {
2788
2934
  return new FlowProcessBuilder(processId);
2789
2935
  }
@@ -2891,6 +3037,7 @@ function createCapabilityAccessor(provided = []) {
2891
3037
 
2892
3038
  // src/integration-http.ts
2893
3039
  var IntegrationHttpError = class extends Error {
3040
+ /** @public */
2894
3041
  constructor(status, message) {
2895
3042
  super(message);
2896
3043
  this.status = status;
@@ -2898,7 +3045,13 @@ var IntegrationHttpError = class extends Error {
2898
3045
  status;
2899
3046
  };
2900
3047
  var IntegrationHttpClient = class {
2901
- constructor(provider, baseUrl, headers, pagination = { key: "per_page", size: 100 }) {
3048
+ /** @internal */
3049
+ constructor(provider, baseUrl, headers, pagination = {
3050
+ /** @internal */
3051
+ key: "per_page",
3052
+ /** @internal */
3053
+ size: 100
3054
+ }) {
2902
3055
  this.provider = provider;
2903
3056
  this.baseUrl = baseUrl;
2904
3057
  this.headers = headers;
@@ -2908,6 +3061,7 @@ var IntegrationHttpClient = class {
2908
3061
  baseUrl;
2909
3062
  headers;
2910
3063
  pagination;
3064
+ /** @internal */
2911
3065
  async response(path3, init = {}) {
2912
3066
  const response = await fetch(`${this.baseUrl}${path3}`, {
2913
3067
  ...init,
@@ -2924,13 +3078,16 @@ var IntegrationHttpClient = class {
2924
3078
  );
2925
3079
  return response;
2926
3080
  }
3081
+ /** @internal */
2927
3082
  async request(path3, init = {}) {
2928
3083
  const response = await this.response(path3, init);
2929
3084
  return response.status === 204 ? void 0 : response.json();
2930
3085
  }
3086
+ /** @internal */
2931
3087
  writeJson(path3, method, body, signal) {
2932
3088
  return this.request(path3, { method, body: JSON.stringify(body), signal });
2933
3089
  }
3090
+ /** @internal */
2934
3091
  async pages(path3, signal) {
2935
3092
  const items = [];
2936
3093
  const { key, size } = this.pagination;
@@ -3654,8 +3811,11 @@ function repositoryFeedbackBatch(unseen, config, now) {
3654
3811
  const latest = Math.max(...unseen.map((item) => Date.parse(item.createdAt) || 0));
3655
3812
  if (now - latest < config.quietPeriodMs) return null;
3656
3813
  const cursors = {
3814
+ /** @public */
3657
3815
  conversationCursor: config.conversationCursor,
3816
+ /** @public */
3658
3817
  reviewCursor: config.reviewCursor,
3818
+ /** @public */
3659
3819
  inlineCursor: config.inlineCursor
3660
3820
  };
3661
3821
  for (const item of unseen) {
@@ -3663,7 +3823,19 @@ function repositoryFeedbackBatch(unseen, config, now) {
3663
3823
  cursors[key] = Math.max(cursors[key], item.id);
3664
3824
  }
3665
3825
  return {
3666
- event: { feedbackIds: unseen.map(({ kind, id }) => ({ kind, id })), cursors },
3826
+ /** @public */
3827
+ event: {
3828
+ /** @public */
3829
+ feedbackIds: unseen.map(({ kind, id }) => ({
3830
+ /** @public */
3831
+ kind,
3832
+ /** @public */
3833
+ id
3834
+ })),
3835
+ /** @public */
3836
+ cursors
3837
+ },
3838
+ /** @public */
3667
3839
  mergeKey: `${cursors.conversationCursor}:${cursors.reviewCursor}:${cursors.inlineCursor}`
3668
3840
  };
3669
3841
  }
@@ -3767,20 +3939,24 @@ function shellQuote(value) {
3767
3939
 
3768
3940
  // src/repository-http.ts
3769
3941
  var RepositoryHttpClient = class extends IntegrationHttpClient {
3942
+ /** @internal */
3770
3943
  repositoryPath(owner, repo) {
3771
3944
  return `/repos/${owner}/${repo}`;
3772
3945
  }
3946
+ /** @internal */
3773
3947
  getIssue(owner, repo, number, signal) {
3774
3948
  return this.request(`${this.repositoryPath(owner, repo)}/issues/${number}`, {
3775
3949
  signal
3776
3950
  });
3777
3951
  }
3952
+ /** @public */
3778
3953
  listIssueComments(owner, repo, number, signal) {
3779
3954
  return this.pages(
3780
3955
  `${this.repositoryPath(owner, repo)}/issues/${number}/comments`,
3781
3956
  signal
3782
3957
  );
3783
3958
  }
3959
+ /** @public */
3784
3960
  addIssueComment(owner, repo, number, body, signal) {
3785
3961
  return this.writeJson(
3786
3962
  `${this.repositoryPath(owner, repo)}/issues/${number}/comments`,
@@ -3789,6 +3965,7 @@ var RepositoryHttpClient = class extends IntegrationHttpClient {
3789
3965
  signal
3790
3966
  );
3791
3967
  }
3968
+ /** @public */
3792
3969
  createPullRequest(owner, repo, input) {
3793
3970
  return this.writeJson(
3794
3971
  `${this.repositoryPath(owner, repo)}/pulls`,
@@ -3796,17 +3973,20 @@ var RepositoryHttpClient = class extends IntegrationHttpClient {
3796
3973
  input
3797
3974
  );
3798
3975
  }
3976
+ /** @public */
3799
3977
  getPullRequest(owner, repo, number, signal) {
3800
3978
  return this.request(
3801
3979
  `${this.repositoryPath(owner, repo)}/pulls/${number}`,
3802
3980
  { signal }
3803
3981
  );
3804
3982
  }
3983
+ /** @internal */
3805
3984
  listPullRequests(owner, repo, state = "open") {
3806
3985
  return this.pages(
3807
3986
  `${this.repositoryPath(owner, repo)}/pulls?state=${encodeURIComponent(state)}`
3808
3987
  );
3809
3988
  }
3989
+ /** @public */
3810
3990
  updatePullRequest(owner, repo, number, patch, signal) {
3811
3991
  return this.writeJson(
3812
3992
  `${this.repositoryPath(owner, repo)}/pulls/${number}`,
@@ -3877,16 +4057,26 @@ function parseRepositoryIssueWatcherConfig(raw, legacyType, distinctLabels = fal
3877
4057
  if (distinctLabels && parsed.labels.trigger === parsed.labels.done)
3878
4058
  throw new Error("Trigger and done labels must differ");
3879
4059
  return {
4060
+ /** @public */
3880
4061
  config: parsed,
4062
+ /** @public */
3881
4063
  enabled: config.enabled,
4064
+ /** @public */
3882
4065
  launchModelConfig: parseProcessWatcherLaunchModelConfig(config.launch)
3883
4066
  };
3884
4067
  }
3885
4068
  function presentRepositoryIssueWatcherConfig(config) {
3886
4069
  return {
4070
+ /** @public */
3887
4071
  targetSummary: `Profile ${config.profile} \xB7 trigger ${config.labels.trigger}`,
4072
+ /** @public */
3888
4073
  details: [
3889
- { label: "Profile", value: config.profile },
4074
+ {
4075
+ /** @public */
4076
+ label: "Profile",
4077
+ /** @public */
4078
+ value: config.profile
4079
+ },
3890
4080
  { label: "Included repositories", value: config.repositories.include.join(", ") || "all" },
3891
4081
  { label: "Excluded repositories", value: config.repositories.exclude.join(", ") || "none" },
3892
4082
  { label: "Trigger label", value: config.labels.trigger },
@@ -3896,6 +4086,30 @@ function presentRepositoryIssueWatcherConfig(config) {
3896
4086
  };
3897
4087
  }
3898
4088
 
4089
+ // src/repository-reconciliation.ts
4090
+ async function existingObject(read) {
4091
+ try {
4092
+ return await read();
4093
+ } catch (error) {
4094
+ if (error instanceof IntegrationHttpError && error.status === 404) return null;
4095
+ throw error;
4096
+ }
4097
+ }
4098
+ function matchesPatch(current, patch) {
4099
+ const fields = current;
4100
+ return Object.entries(patch).every(([key, expected]) => {
4101
+ const labelKey = Array.isArray(expected) && typeof expected[0] === "number" ? "id" : "name";
4102
+ const normalize = (value) => key === "labels" && Array.isArray(value) ? [
4103
+ ...new Set(
4104
+ value.map(
4105
+ (label) => typeof label === "object" && label !== null ? label[labelKey] : label
4106
+ )
4107
+ )
4108
+ ].sort() : value;
4109
+ return JSON.stringify(normalize(fields[key])) === JSON.stringify(normalize(expected));
4110
+ });
4111
+ }
4112
+
3899
4113
  // src/repository-source-config.ts
3900
4114
  import { asUnknownRecord as asUnknownRecord2 } from "@leitwerk-dev/domain";
3901
4115
  function parseRepositoryPullRequestConfig(value) {
@@ -3904,12 +4118,19 @@ function parseRepositoryPullRequestConfig(value) {
3904
4118
  return null;
3905
4119
  const terminalOutcome = config.terminalOutcome === "merged" || config.terminalOutcome === "closed" ? config.terminalOutcome : void 0;
3906
4120
  return {
4121
+ /** @public */
3907
4122
  profile: config.profile,
4123
+ /** @public */
3908
4124
  owner: config.owner,
4125
+ /** @public */
3909
4126
  repo: config.repo,
4127
+ /** @public */
3910
4128
  prNumber: config.prNumber,
4129
+ /** @public */
3911
4130
  pollInterval: typeof config.pollInterval === "string" ? config.pollInterval : "30s",
4131
+ /** @public */
3912
4132
  terminalOutcome,
4133
+ /** @public */
3913
4134
  disabled: config.disabled === true
3914
4135
  };
3915
4136
  }
@@ -3919,9 +4140,13 @@ function parseRepositoryFeedbackConfig(value) {
3919
4140
  if (!base) return null;
3920
4141
  return {
3921
4142
  ...base,
4143
+ /** @public */
3922
4144
  conversationCursor: typeof config.conversationCursor === "number" ? config.conversationCursor : 0,
4145
+ /** @public */
3923
4146
  reviewCursor: typeof config.reviewCursor === "number" ? config.reviewCursor : 0,
4147
+ /** @public */
3924
4148
  inlineCursor: typeof config.inlineCursor === "number" ? config.inlineCursor : 0,
4149
+ /** @public */
3925
4150
  quietPeriodMs: typeof config.quietPeriodMs === "number" ? config.quietPeriodMs : 12e4
3926
4151
  };
3927
4152
  }
@@ -3930,11 +4155,17 @@ function parseRepositoryIssueCancelledConfig(value) {
3930
4155
  if (typeof config.profile !== "string" || typeof config.owner !== "string" || typeof config.repo !== "string" || typeof config.issueNumber !== "number" || typeof config.triggerLabel !== "string")
3931
4156
  return null;
3932
4157
  return {
4158
+ /** @public */
3933
4159
  profile: config.profile,
4160
+ /** @public */
3934
4161
  owner: config.owner,
4162
+ /** @public */
3935
4163
  repo: config.repo,
4164
+ /** @public */
3936
4165
  issueNumber: config.issueNumber,
4166
+ /** @public */
3937
4167
  triggerLabel: config.triggerLabel,
4168
+ /** @public */
3938
4169
  pollInterval: typeof config.pollInterval === "string" ? config.pollInterval : "30s"
3939
4170
  };
3940
4171
  }
@@ -4020,7 +4251,6 @@ function validateToolCallRendererDefinition(def) {
4020
4251
  }
4021
4252
 
4022
4253
  // src/turn-semantics.ts
4023
- import { defaultProcessTurnStartSelection } from "@leitwerk-dev/domain";
4024
4254
  function isLlmTurnDefinition(turnDef) {
4025
4255
  return turnDef.kind === "llm";
4026
4256
  }
@@ -4539,57 +4769,30 @@ function createWorkerProcessBuilder() {
4539
4769
  };
4540
4770
  }
4541
4771
  export {
4542
- AutomaticFlowBuilder,
4543
4772
  AutomaticOutcomeBuilder,
4544
4773
  BUILT_IN_COMMIT_MESSAGE_RULES,
4545
4774
  COMMIT_MESSAGE_PROJECT_METADATA_KEY,
4546
4775
  CORE_TOOL_CALL_RENDERERS,
4547
- DEFAULT_FLOW_PRODUCT_NAME,
4548
- DEFAULT_PLAN_RESULT_OUTCOME_ID,
4549
- ExternalActionBuilder,
4550
- ExternalFlowBuilder,
4551
- ExternalRouteBuilder,
4552
- FRAMEWORK_LLM_TOOL_NAMES,
4553
4776
  FlowFragmentBuilder,
4554
- FlowProcessBuilder,
4555
- HumanActionBuilder,
4556
4777
  HumanFlowBuilder,
4557
4778
  IntegrationHttpClient,
4558
4779
  IntegrationHttpError,
4559
- LlmFlowBuilder,
4560
- LlmTurnEndBuilder,
4561
- MARKDOWN_RESULT_TOOL_MARKDOWN_PATH,
4562
4780
  MARKDOWN_RESULT_TOOL_NAME,
4563
- MARKDOWN_RESULT_TOOL_RENDERER,
4564
- OutcomeToolBuilder,
4565
- PI_BUILT_IN_TOOL_NAMES,
4566
- PlanResultBuilder,
4567
- PublishedResultBuilder,
4568
4781
  REQUIRED_MARKDOWN_RESULT_TURN_RESULT,
4569
4782
  RESERVED_INTEGRATION_TOOL_NAMES,
4570
4783
  RepositoryHttpClient,
4571
4784
  SafeLaunchPreparationError,
4572
- TOOL_CALL_RENDERER_VALUE_KINDS,
4573
- TOOL_CALL_RENDERER_VALUE_SOURCES,
4574
- TURN_COMPLETION_MODES,
4575
- TURN_CONTEXT_MODES,
4576
- WORKER_SUBPROCESS_SENSITIVE_ENV_KEYS,
4577
4785
  acceptedReviewHandoffAction,
4578
4786
  assertValidLlmTurnDefinition,
4579
4787
  atomicWriteUtf8,
4580
4788
  automaticTurn,
4581
- buildPlanSavedEventPayload,
4582
4789
  buildProcessFlowView,
4583
4790
  buildProcessLaunchers,
4584
4791
  buildProcessWatchers,
4585
- buildReviewCompletedEventPayload,
4586
- buildReviewRequestedEventPayload,
4587
4792
  buildUiProcessDefinition,
4588
4793
  builtinPiProvider,
4589
4794
  clearRepositoryGitHttpsHelpers,
4590
4795
  clearRepositoryGitSshWrappers,
4591
- collapseRoutingTurns,
4592
- collectProcessAvailableToolNames,
4593
4796
  configuredPiProvider,
4594
4797
  coreHostCapabilities,
4595
4798
  createCapabilityAccessor,
@@ -4597,7 +4800,6 @@ export {
4597
4800
  createEmptyStructuralProcessState,
4598
4801
  createEventBus,
4599
4802
  createExternalSourcePollReporter,
4600
- createFlowAutomaticRunContext,
4601
4803
  createFlowPromptContext,
4602
4804
  createProcessLauncherBuilder,
4603
4805
  createProcessWatcherBuilder,
@@ -4606,7 +4808,6 @@ export {
4606
4808
  createUiProcessBuilder,
4607
4809
  createWorkerProcessBuilder,
4608
4810
  credentialBasedModelStatuses,
4609
- defaultProcessTurnStartSelection as defaultTurnStartSelection,
4610
4811
  defineExternalActionSource,
4611
4812
  defineModelProvider,
4612
4813
  defineModelProviders,
@@ -4617,18 +4818,15 @@ export {
4617
4818
  defineProviderOptions,
4618
4819
  defineWorkerConfig,
4619
4820
  emptyParamsCodec,
4620
- externalTurn,
4821
+ existingObject,
4621
4822
  filterProviderOptionsForDefinition,
4622
- filterStringArray,
4623
4823
  findUiLauncherById,
4624
4824
  flow,
4625
- getAllProcessGraphs,
4626
4825
  getExternalActionArmingId,
4627
4826
  getExternalActionTransitionTrigger,
4628
4827
  getExternalSourceTransitionId,
4629
4828
  getProcessGraph,
4630
4829
  getProcessTurnGraph,
4631
- getReachableTurnIdsForProcessGraph,
4632
4830
  getTurnTransitionsForProcessGraph,
4633
4831
  hasErrorCode,
4634
4832
  hasProcessGraph,
@@ -4642,6 +4840,7 @@ export {
4642
4840
  isTurnAvailableForProcessGraph,
4643
4841
  listLlmTurnIdsForProcessGraph,
4644
4842
  llmTurn,
4843
+ matchesPatch,
4645
4844
  matchesRepository,
4646
4845
  normalizeLeafOutcomeCaptureResult,
4647
4846
  normalizeRepositoryFeedback,
@@ -4658,18 +4857,14 @@ export {
4658
4857
  piWorker,
4659
4858
  presentRepositoryIssueWatcherConfig,
4660
4859
  projectParameters,
4661
- queuedInstructionAction,
4662
4860
  repositoryFeedbackBatch,
4663
4861
  repositoryGitArgs,
4664
4862
  repositoryGitSubprocessEnv,
4665
4863
  repositoryHttpsUrl,
4666
4864
  resolveHumanTurnView,
4667
4865
  resolveLlmTurnRestorePrimaryLeafAfterTurn,
4668
- resolveLlmTurnStartSelection,
4669
4866
  resolveProviderOptions,
4670
4867
  resolveRepositoryProjectBinding,
4671
- resolveTurnAvailableToolNames as resolveTurnActiveToolNames,
4672
- resolveTurnAvailableToolNames,
4673
4868
  revisionAction,
4674
4869
  routeTurnOutcomes,
4675
4870
  sanitizeWorkerSubprocessEnv,
@@ -4679,16 +4874,10 @@ export {
4679
4874
  stringArg,
4680
4875
  structuralStateCodec,
4681
4876
  toProcessGraphView,
4682
- validateAutomaticTurnDefinition,
4683
- validateExternalTurnDefinition,
4684
- validateHumanTurnDefinition,
4685
4877
  validateLeafOutcomeCaptureResult,
4686
- validateLlmTurnDefinition,
4687
- validatePiBuiltInToolArray,
4688
4878
  validateProcessGraphEntryTurns,
4689
4879
  validateProcessGraphProducts,
4690
4880
  validateProcessGraphTurnTransitions,
4691
- validateProcessLeafOutcomeDefinition,
4692
4881
  validateToolCallRendererDefinition,
4693
4882
  validateTurnDefinition
4694
4883
  };