@leitwerk-dev/process-sdk 0.1.9 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (256) hide show
  1. package/dist/browser-ui-extension.d.ts +20 -0
  2. package/dist/browser-ui-extension.d.ts.map +1 -1
  3. package/dist/capabilities.d.ts +6 -0
  4. package/dist/capabilities.d.ts.map +1 -1
  5. package/dist/{chunk-LIIP7FMU.js → chunk-5R6MVLHC.js} +1 -1
  6. package/dist/chunk-5R6MVLHC.js.map +1 -0
  7. package/dist/chunk-DVXW2ZUV.js +1 -0
  8. package/dist/chunk-DVXW2ZUV.js.map +1 -0
  9. package/dist/{chunk-TRQJ5PRM.js → chunk-I7U6HCLN.js} +1 -11
  10. package/dist/chunk-I7U6HCLN.js.map +1 -0
  11. package/dist/{chunk-5RJZ2E7D.js → chunk-TM2LTSW4.js} +2 -6
  12. package/dist/chunk-TM2LTSW4.js.map +1 -0
  13. package/dist/codecs.d.ts +1 -0
  14. package/dist/codecs.d.ts.map +1 -1
  15. package/dist/commit-message.d.ts +5 -0
  16. package/dist/commit-message.d.ts.map +1 -1
  17. package/dist/core-capabilities.d.ts +396 -44
  18. package/dist/core-capabilities.d.ts.map +1 -1
  19. package/dist/define-process.d.ts +209 -64
  20. package/dist/define-process.d.ts.map +1 -1
  21. package/dist/event-bus.d.ts +1 -0
  22. package/dist/event-bus.d.ts.map +1 -1
  23. package/dist/{extension-api-BBcwktmc.d.ts → extension-api-B4gG5w1K.d.ts} +1111 -153
  24. package/dist/extension-api.d.ts +481 -38
  25. package/dist/extension-api.d.ts.map +1 -1
  26. package/dist/external-action-source.d.ts +9 -0
  27. package/dist/external-action-source.d.ts.map +1 -0
  28. package/dist/external-source-poll.d.ts +22 -0
  29. package/dist/external-source-poll.d.ts.map +1 -0
  30. package/dist/flow.d.ts +380 -107
  31. package/dist/flow.d.ts.map +1 -1
  32. package/dist/form-contract.d.ts +1 -1
  33. package/dist/form-contract.d.ts.map +1 -1
  34. package/dist/fs-utils.d.ts +6 -0
  35. package/dist/fs-utils.d.ts.map +1 -1
  36. package/dist/git-binary.d.ts +2 -1
  37. package/dist/git-binary.d.ts.map +1 -1
  38. package/dist/git-binary.js +25 -33
  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 +40 -29
  45. package/dist/index.d.ts.map +1 -1
  46. package/dist/index.js +4876 -29
  47. package/dist/index.js.map +1 -1
  48. package/dist/integration-http.d.ts +32 -0
  49. package/dist/integration-http.d.ts.map +1 -0
  50. package/dist/json-data.d.ts +3 -0
  51. package/dist/json-data.d.ts.map +1 -0
  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 +86 -64
  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 +41 -5
  65. package/dist/pi-config.d.ts.map +1 -1
  66. package/dist/pi-config.js +20 -180
  67. package/dist/pi-config.js.map +1 -1
  68. package/dist/process-definition-internals.d.ts +4 -0
  69. package/dist/process-definition-internals.d.ts.map +1 -1
  70. package/dist/process-flow-view.d.ts +2 -0
  71. package/dist/process-flow-view.d.ts.map +1 -1
  72. package/dist/process-graph.d.ts +34 -0
  73. package/dist/process-graph.d.ts.map +1 -1
  74. package/dist/process-launcher-builder.d.ts +5 -0
  75. package/dist/process-launcher-builder.d.ts.map +1 -1
  76. package/dist/process-watcher-builder.d.ts +5 -0
  77. package/dist/process-watcher-builder.d.ts.map +1 -1
  78. package/dist/process-watcher-source.d.ts +3 -1
  79. package/dist/process-watcher-source.d.ts.map +1 -1
  80. package/dist/project-binding.d.ts +13 -0
  81. package/dist/project-binding.d.ts.map +1 -0
  82. package/dist/registry-utils.d.ts +6 -0
  83. package/dist/registry-utils.d.ts.map +1 -1
  84. package/dist/repository-feedback.d.ts +47 -0
  85. package/dist/repository-feedback.d.ts.map +1 -0
  86. package/dist/repository-git-env.d.ts +8 -2
  87. package/dist/repository-git-env.d.ts.map +1 -1
  88. package/dist/repository-http.d.ts +31 -0
  89. package/dist/repository-http.d.ts.map +1 -0
  90. package/dist/repository-https.d.ts +3 -0
  91. package/dist/repository-https.d.ts.map +1 -0
  92. package/dist/repository-issue-watcher.d.ts +51 -0
  93. package/dist/repository-issue-watcher.d.ts.map +1 -0
  94. package/dist/repository-reconciliation.d.ts +5 -0
  95. package/dist/repository-reconciliation.d.ts.map +1 -0
  96. package/dist/repository-source-config.d.ts +58 -0
  97. package/dist/repository-source-config.d.ts.map +1 -0
  98. package/dist/repository-types.d.ts +63 -0
  99. package/dist/repository-types.d.ts.map +1 -0
  100. package/dist/review-flow-public.d.ts +2 -0
  101. package/dist/review-flow-public.d.ts.map +1 -0
  102. package/dist/review-flow-public.js +11 -0
  103. package/dist/review-flow-public.js.map +1 -0
  104. package/dist/review-flow.d.ts +6 -0
  105. package/dist/review-flow.d.ts.map +1 -1
  106. package/dist/review-flow.js +12 -43
  107. package/dist/review-flow.js.map +1 -1
  108. package/dist/runtime-internals-public.d.ts +2 -0
  109. package/dist/runtime-internals-public.d.ts.map +1 -0
  110. package/dist/runtime-internals-public.js +16 -0
  111. package/dist/runtime-internals-public.js.map +1 -0
  112. package/dist/runtime-internals.js +19 -2
  113. package/dist/runtime-internals.js.map +1 -1
  114. package/dist/server-events.d.ts +67 -0
  115. package/dist/server-events.d.ts.map +1 -1
  116. package/dist/server-process-builder.d.ts +7 -0
  117. package/dist/server-process-builder.d.ts.map +1 -1
  118. package/dist/state-helpers.d.ts +8 -0
  119. package/dist/state-helpers.d.ts.map +1 -1
  120. package/dist/subprocess-env.d.ts +4 -0
  121. package/dist/subprocess-env.d.ts.map +1 -1
  122. package/dist/tool-arguments.d.ts +9 -0
  123. package/dist/tool-arguments.d.ts.map +1 -0
  124. package/dist/tool-renderers.d.ts +6 -0
  125. package/dist/tool-renderers.d.ts.map +1 -1
  126. package/dist/turn-semantics.d.ts +18 -6
  127. package/dist/turn-semantics.d.ts.map +1 -1
  128. package/dist/types.d.ts +209 -38
  129. package/dist/types.d.ts.map +1 -1
  130. package/dist/ui-process-builder.d.ts +5 -0
  131. package/dist/ui-process-builder.d.ts.map +1 -1
  132. package/dist/worker-process-builder.d.ts +5 -0
  133. package/dist/worker-process-builder.d.ts.map +1 -1
  134. package/package.json +17 -15
  135. package/src/browser-ui-extension.ts +20 -0
  136. package/src/capabilities.ts +9 -1
  137. package/src/codecs.ts +1 -0
  138. package/src/commit-message.ts +5 -0
  139. package/src/core-capabilities.ts +464 -59
  140. package/src/define-process.ts +384 -332
  141. package/src/event-bus.ts +1 -0
  142. package/src/extension-api.ts +521 -41
  143. package/src/external-action-source.ts +17 -0
  144. package/src/external-source-poll.ts +61 -0
  145. package/src/flow.ts +674 -677
  146. package/src/form-contract.ts +0 -4
  147. package/src/fs-utils.ts +21 -2
  148. package/src/git-binary.ts +2 -1
  149. package/src/graph-fragments.ts +16 -0
  150. package/src/host-capabilities.ts +9 -6
  151. package/src/index.ts +51 -206
  152. package/src/integration-http.ts +70 -0
  153. package/src/json-data.ts +25 -0
  154. package/src/leaf-outcome-renderer.ts +35 -0
  155. package/src/leaf-outcomes.ts +4 -9
  156. package/src/model-provider.ts +179 -43
  157. package/src/pi-config-public.ts +7 -0
  158. package/src/pi-config.ts +48 -8
  159. package/src/process-definition-internals.ts +4 -0
  160. package/src/process-flow-view.ts +34 -88
  161. package/src/process-graph.ts +59 -51
  162. package/src/process-launcher-builder.ts +5 -0
  163. package/src/process-watcher-builder.ts +5 -0
  164. package/src/process-watcher-source.ts +9 -10
  165. package/src/project-binding.ts +40 -0
  166. package/src/registry-utils.ts +7 -5
  167. package/src/repository-feedback.ts +85 -0
  168. package/src/repository-git-env.ts +40 -2
  169. package/src/repository-http.ts +88 -0
  170. package/src/repository-https.ts +22 -0
  171. package/src/repository-issue-watcher.ts +122 -0
  172. package/src/repository-reconciliation.ts +30 -0
  173. package/src/repository-source-config.ts +79 -0
  174. package/src/repository-types.ts +63 -0
  175. package/src/review-flow-public.ts +5 -0
  176. package/src/review-flow.ts +6 -0
  177. package/src/runtime-internals-public.ts +7 -0
  178. package/src/server-events.ts +67 -0
  179. package/src/server-process-builder.ts +10 -1
  180. package/src/state-helpers.ts +14 -4
  181. package/src/subprocess-env.ts +9 -0
  182. package/src/tool-arguments.ts +39 -0
  183. package/src/tool-renderers.ts +6 -0
  184. package/src/turn-semantics.ts +45 -76
  185. package/src/types.ts +216 -44
  186. package/src/ui-process-builder.ts +8 -1
  187. package/src/worker-process-builder.ts +8 -1
  188. package/dist/browser-ui-extension.js +0 -2
  189. package/dist/browser-ui-extension.js.map +0 -1
  190. package/dist/capabilities.js +0 -7
  191. package/dist/capabilities.js.map +0 -1
  192. package/dist/chunk-5RJZ2E7D.js.map +0 -1
  193. package/dist/chunk-LIIP7FMU.js.map +0 -1
  194. package/dist/chunk-TRQJ5PRM.js.map +0 -1
  195. package/dist/codecs.js +0 -9
  196. package/dist/codecs.js.map +0 -1
  197. package/dist/commit-message.js +0 -3
  198. package/dist/commit-message.js.map +0 -1
  199. package/dist/core-capabilities.js +0 -6
  200. package/dist/core-capabilities.js.map +0 -1
  201. package/dist/define-process.js +0 -1078
  202. package/dist/define-process.js.map +0 -1
  203. package/dist/event-bus.js +0 -31
  204. package/dist/event-bus.js.map +0 -1
  205. package/dist/extension-api.js +0 -5
  206. package/dist/extension-api.js.map +0 -1
  207. package/dist/flow.js +0 -1645
  208. package/dist/flow.js.map +0 -1
  209. package/dist/form-contract.js +0 -2
  210. package/dist/form-contract.js.map +0 -1
  211. package/dist/fs-utils.js +0 -23
  212. package/dist/fs-utils.js.map +0 -1
  213. package/dist/graph-fragments.js +0 -57
  214. package/dist/graph-fragments.js.map +0 -1
  215. package/dist/host-capabilities.js +0 -42
  216. package/dist/host-capabilities.js.map +0 -1
  217. package/dist/launcher-contract.js +0 -2
  218. package/dist/launcher-contract.js.map +0 -1
  219. package/dist/leaf-outcomes.js +0 -52
  220. package/dist/leaf-outcomes.js.map +0 -1
  221. package/dist/model-provider.js +0 -171
  222. package/dist/model-provider.js.map +0 -1
  223. package/dist/process-definition-internals.js +0 -25
  224. package/dist/process-definition-internals.js.map +0 -1
  225. package/dist/process-flow-view.js +0 -418
  226. package/dist/process-flow-view.js.map +0 -1
  227. package/dist/process-graph.js +0 -212
  228. package/dist/process-graph.js.map +0 -1
  229. package/dist/process-launcher-builder.js +0 -43
  230. package/dist/process-launcher-builder.js.map +0 -1
  231. package/dist/process-watcher-builder.js +0 -40
  232. package/dist/process-watcher-builder.js.map +0 -1
  233. package/dist/process-watcher-source.js +0 -52
  234. package/dist/process-watcher-source.js.map +0 -1
  235. package/dist/registry-utils.js +0 -18
  236. package/dist/registry-utils.js.map +0 -1
  237. package/dist/repository-git-env.js +0 -26
  238. package/dist/repository-git-env.js.map +0 -1
  239. package/dist/server-events.js +0 -2
  240. package/dist/server-events.js.map +0 -1
  241. package/dist/server-process-builder.js +0 -52
  242. package/dist/server-process-builder.js.map +0 -1
  243. package/dist/state-helpers.js +0 -18
  244. package/dist/state-helpers.js.map +0 -1
  245. package/dist/subprocess-env.js +0 -34
  246. package/dist/subprocess-env.js.map +0 -1
  247. package/dist/tool-renderers.js +0 -63
  248. package/dist/tool-renderers.js.map +0 -1
  249. package/dist/turn-semantics.js +0 -365
  250. package/dist/turn-semantics.js.map +0 -1
  251. package/dist/types.js +0 -23
  252. package/dist/types.js.map +0 -1
  253. package/dist/ui-process-builder.js +0 -30
  254. package/dist/ui-process-builder.js.map +0 -1
  255. package/dist/worker-process-builder.js +0 -22
  256. package/dist/worker-process-builder.js.map +0 -1
@@ -1,8 +1,7 @@
1
1
  import {
2
2
  assertValidProcessProductName,
3
- type InputKind,
4
- type InputSource,
5
- type ProcessInputTarget,
3
+ trimString as normalizeEffectString,
4
+ normalizeStringArray as normalizeEffectStringArray,
6
5
  type ProcessInstance,
7
6
  type ProcessSemanticEntryRefKey,
8
7
  type ProcessTurnStartSelection,
@@ -12,24 +11,16 @@ import {
12
11
  type TurnProgressReport,
13
12
  } from "@leitwerk-dev/domain";
14
13
  import type {
15
- Codec,
16
14
  ExtensionProcessDefinition,
17
15
  ExternalActionSource,
18
16
  ExternalSourceEffect,
19
17
  ExternalSourceResolveContext,
20
18
  FormDefinition,
21
- ProcessLauncherAPI,
22
19
  ProcessTurnBinding,
23
20
  ProcessTurnOutcomeEvent,
24
- ProcessWatcherAPI,
25
- RepositoryCredentialProject,
26
- RepositoryCredentialRequirement,
27
- ServerProcessAPI,
28
21
  ServerProcessContext,
29
22
  ServerTransitionRequest,
30
- UiProcessAPI,
31
23
  WorkerCompleteInput,
32
- WorkerProcessAPI,
33
24
  WorkerProcessContext,
34
25
  } from "./extension-api.js";
35
26
  import {
@@ -47,7 +38,6 @@ import type {
47
38
  PiBuiltInToolName,
48
39
  ProcessActionPreviewDefinition,
49
40
  ProcessActionSchedulingDefinition,
50
- ProcessPiConfig,
51
41
  TurnAcceptanceState,
52
42
  TurnBranchType,
53
43
  TurnCompletionMode,
@@ -55,25 +45,30 @@ import type {
55
45
  TurnResultMarkdownBehavior,
56
46
  } from "./types.js";
57
47
 
48
+ /** @internal */
58
49
  type ProcessEventName = keyof ServerExtensionEventMap & string;
59
50
 
51
+ /** @internal */
60
52
  type ProcessEmittedEvent = {
53
+ /** @internal */
61
54
  type: ProcessEventName;
55
+ /** @internal */
62
56
  data: unknown;
63
57
  };
64
58
 
65
- type ProcessQueuedInput = {
66
- source: InputSource;
67
- kind: InputKind;
68
- bodyMarkdown: string;
69
- target?: ProcessInputTarget;
70
- };
59
+ /** @public */
60
+ type ProcessQueuedInput = Parameters<ServerProcessContext["queueInput"]>[0];
71
61
 
62
+ /** @public */
72
63
  type MaybePromise<T> = T | Promise<T>;
73
64
 
65
+ /** @public */
74
66
  type StaticRouteTarget = {
67
+ /** @public */
75
68
  to?: TurnId;
69
+ /** @internal */
76
70
  complete?: boolean;
71
+ /** @public */
77
72
  lifecycleStatus?: ProcessTurnTerminalLifecycleStatus;
78
73
  };
79
74
 
@@ -86,24 +81,46 @@ type NormalizedActionRoute = NormalizedRouteTarget & {
86
81
  trigger: string;
87
82
  };
88
83
 
84
+ /** @public */
89
85
  export interface ProcessRuntimeTurnContext<TParams = unknown, TState = unknown>
90
86
  extends WorkerProcessContext<TParams, TState> {}
91
87
 
88
+ /** @internal */
89
+ export interface LlmTurnPreparationContext<TParams = unknown, TState = unknown>
90
+ extends ProcessRuntimeTurnContext<TParams, TState> {
91
+ /** @internal */
92
+ callIntegrationTool(name: string, args: Record<string, unknown>): Promise<unknown>;
93
+ /** @internal */
94
+ reportProgress(report: TurnProgressReport): void;
95
+ }
96
+
97
+ /** @public */
92
98
  export interface ProcessServerRuntimeContext<TParams = unknown, TState = unknown> {
99
+ /** @internal */
93
100
  readonly process: ServerProcessContext<TParams, TState>["process"];
101
+ /** @internal */
94
102
  readonly projects: ServerProcessContext<TParams, TState>["projects"];
103
+ /** @internal */
95
104
  readonly params: TParams;
105
+ /** @public */
96
106
  readonly state: TState;
107
+ /** @internal */
97
108
  readSemanticTurnResultMarkdown(ref: ProcessSemanticEntryRefKey): string | null;
109
+ /** @internal */
98
110
  readProductTurnResultMarkdown(productName: string): string | null;
111
+ /** @internal */
99
112
  reportProgress?(report: TurnProgressReport): void;
100
113
  }
101
114
 
115
+ /** @internal */
102
116
  export interface ProcessBroadcastEffect {
117
+ /** @internal */
103
118
  type: string;
119
+ /** @internal */
104
120
  payload: Record<string, unknown>;
105
121
  }
106
122
 
123
+ /** @public */
107
124
  export type ProcessPatchEffect = Partial<
108
125
  Pick<
109
126
  ProcessInstance,
@@ -118,137 +135,207 @@ export type ProcessPatchEffect = Partial<
118
135
  >
119
136
  >;
120
137
 
138
+ /** @public */
121
139
  export interface ProcessLifecycleEffects {
140
+ /** @public */
122
141
  processPatch?: ProcessPatchEffect;
142
+ /** @internal */
123
143
  broadcasts?: readonly ProcessBroadcastEffect[];
124
144
  }
125
145
 
146
+ /** @public */
126
147
  export interface ProcessEffectPlan<TState = unknown> extends ProcessLifecycleEffects {
148
+ /** @public */
127
149
  state?: TState;
150
+ /** @internal */
128
151
  emit?: readonly ProcessEmittedEvent[];
152
+ /** @public */
129
153
  queueInput?: readonly ProcessQueuedInput[];
130
154
  }
131
155
 
156
+ /** @internal */
132
157
  export interface SavePlanResultLifecycleIntent<TParams = unknown, TState = unknown> {
158
+ /** @internal */
133
159
  kind: "save_plan_result";
160
+ /** @internal */
134
161
  summaryParam: string;
162
+ /** @internal */
135
163
  acceptanceCriteriaParam: string;
164
+ /** @internal */
136
165
  planMarkdownParam: string;
166
+ /** @internal */
137
167
  emitEventType: ProcessEventName;
168
+ /** @internal */
138
169
  broadcastType: string;
170
+ /** @internal */
139
171
  state?: ProcessOutcomeEffect<TParams, TState>;
140
172
  }
141
173
 
174
+ /** @internal */
142
175
  export type ProcessOutcomeLifecycleIntent<
143
176
  TParams = unknown,
144
177
  TState = unknown,
145
178
  > = SavePlanResultLifecycleIntent<TParams, TState>;
146
179
 
180
+ /** @public */
147
181
  export interface ProcessActionExecution<TParams = unknown, TState = unknown> {
182
+ /** @public */
148
183
  readonly ctx: ProcessServerRuntimeContext<TParams, TState>;
184
+ /** @public */
149
185
  readonly input: Record<string, unknown>;
186
+ /** @internal */
150
187
  readonly turnId: TurnId;
188
+ /** @internal */
151
189
  readonly actionId: string;
190
+ /** @internal */
152
191
  readonly selectedBranchId?: string;
153
192
  }
154
193
 
194
+ /** @public */
155
195
  export interface ProcessOutcomeExecution<TParams = unknown, TState = unknown> {
196
+ /** @internal */
156
197
  readonly ctx: ProcessServerRuntimeContext<TParams, TState>;
198
+ /** @internal */
157
199
  readonly event: ProcessTurnOutcomeEvent;
200
+ /** @internal */
158
201
  readonly turnId: TurnId;
202
+ /** @internal */
159
203
  readonly outcome: string;
160
204
  }
161
205
 
206
+ /** @public */
162
207
  export type ProcessActionEffect<TParams = unknown, TState = unknown> = (
163
208
  input: ProcessActionExecution<TParams, TState>,
164
209
  ) => MaybePromise<ProcessEffectPlan<TState> | undefined>;
165
210
 
211
+ /** @public */
166
212
  export type ProcessActionBranchSelector<TParams = unknown, TState = unknown> = (
167
213
  input: Omit<ProcessActionExecution<TParams, TState>, "selectedBranchId">,
168
214
  ) => MaybePromise<string>;
169
215
 
216
+ /** @public */
170
217
  export type ProcessOutcomeEffect<TParams = unknown, TState = unknown> = (
171
218
  input: ProcessOutcomeExecution<TParams, TState>,
172
219
  ) => MaybePromise<ProcessEffectPlan<TState> | undefined>;
173
220
 
221
+ /** @internal */
174
222
  export type ProcessOutcomeBranchSelector<TParams = unknown, TState = unknown> = (
175
223
  input: ProcessOutcomeExecution<TParams, TState>,
176
224
  ) => MaybePromise<string>;
177
225
 
226
+ /** @internal */
178
227
  export interface ProcessOutcomeBranchSpec extends StaticRouteTarget {
228
+ /** @internal */
179
229
  trigger?: string;
180
230
  }
181
231
 
232
+ /** @internal */
182
233
  export interface ProcessActionExternalTrigger {
234
+ /** @internal */
183
235
  id: string;
236
+ /** @internal */
184
237
  label: string;
238
+ /** @internal */
185
239
  description: string;
186
240
  }
187
241
 
242
+ /** @internal */
188
243
  export interface ExternalActionInputPublication {
244
+ /** @internal */
189
245
  productName: string;
246
+ /** @internal */
190
247
  inputField: string;
191
248
  }
192
249
 
250
+ /** @public */
193
251
  export interface ProcessHumanTurnExternalActionSpec<
194
252
  TParams = unknown,
195
253
  TState = unknown,
196
254
  TEvent = unknown,
197
255
  TInput extends Record<string, unknown> = Record<string, unknown>,
198
256
  > extends StaticRouteTarget {
257
+ /** @internal */
199
258
  id: string;
259
+ /** @internal */
200
260
  source: ExternalActionSource<TParams, TState, TEvent, TInput>;
201
- /** Arms and exposes this action only when the current process snapshot matches. */
261
+ /** Arms and exposes this action only when the current process snapshot matches. @public */
202
262
  when?: (ctx: ExternalSourceResolveContext<TParams, TState>) => boolean;
263
+ /** @internal */
203
264
  label?: string;
265
+ /** @internal */
204
266
  description?: string;
267
+ /** @internal */
205
268
  publishInput?: ExternalActionInputPublication;
269
+ /** @public */
206
270
  effect?: ExternalSourceEffect<TParams, TState, TEvent, TInput>;
207
271
  }
208
272
 
273
+ /** @public */
209
274
  export interface ProcessActionBranchSpec extends StaticRouteTarget {
275
+ /** @internal */
210
276
  trigger?: string;
211
277
  }
212
278
 
279
+ /** @public */
213
280
  type StaticActionRouting = StaticRouteTarget & {
281
+ /** @internal */
214
282
  trigger?: string;
215
283
  };
216
284
 
285
+ /** @public */
217
286
  type BranchingActionRouting<TParams, TState> = {
287
+ /** @public */
218
288
  branches: Record<string, ProcessActionBranchSpec>;
289
+ /** @public */
219
290
  choose: ProcessActionBranchSelector<TParams, TState>;
220
291
  };
221
292
 
293
+ /** @public */
222
294
  interface BaseActionSpec<TParams, TState> {
295
+ /** @public */
223
296
  label: string;
297
+ /** @public */
224
298
  description?: string;
299
+ /** @internal */
225
300
  form?: FormDefinition;
301
+ /** @public */
226
302
  preview?: ProcessActionPreviewDefinition;
303
+ /** @public */
227
304
  schedulable?: boolean;
305
+ /** @public */
228
306
  effect?: ProcessActionEffect<TParams, TState>;
229
307
  }
230
308
 
309
+ /** @public */
231
310
  export type ProcessHumanTurnActionSpec<TParams = unknown, TState = unknown> = BaseActionSpec<
232
311
  TParams,
233
312
  TState
234
313
  > & {
314
+ /** @public */
235
315
  acceptanceState: TurnAcceptanceState;
316
+ /** @internal */
236
317
  externalTriggers?: readonly ProcessActionExternalTrigger[];
237
318
  } & (StaticActionRouting | BranchingActionRouting<TParams, TState>);
238
319
 
320
+ /** @public */
239
321
  interface ProcessToolOutcomeBaseSpec<TParams = unknown, TState = unknown> {
322
+ /** @internal */
240
323
  description: string;
324
+ /** @internal */
241
325
  parameters: Record<string, OutcomeToolParameterSpec>;
242
- /** Product published from this outcome's turn-result markdown, when this outcome is selected. */
326
+ /** Product published from this outcome's turn-result markdown, when this outcome is selected. @internal */
243
327
  publishedProduct?: string;
244
- /** Outcome parameter whose markdown value is captured as the turn result. */
328
+ /** Outcome parameter whose markdown value is captured as the turn result. @internal */
245
329
  turnResultMarkdownParameter?: string;
330
+ /** Outcome parameter containing a concise operator-facing summary. @internal */
331
+ resultSummaryParameter?: string;
332
+ /** @internal */
246
333
  effect?: ProcessOutcomeEffect<TParams, TState>;
247
- /** Parks the process on this turn after recording the outcome. */
248
- wait?: true;
334
+ /** @internal */
249
335
  lifecycleIntent?: ProcessOutcomeLifecycleIntent<TParams, TState>;
250
336
  }
251
337
 
338
+ /** @public */
252
339
  export type ProcessToolOutcomeSpec<
253
340
  TParams = unknown,
254
341
  TState = unknown,
@@ -256,183 +343,196 @@ export type ProcessToolOutcomeSpec<
256
343
  (
257
344
  | StaticRouteTarget
258
345
  | {
346
+ /** @internal */
259
347
  branches: Record<string, ProcessOutcomeBranchSpec>;
348
+ /** @internal */
260
349
  choose: ProcessOutcomeBranchSelector<TParams, TState>;
261
350
  }
262
351
  );
352
+ /** @public */
263
353
  export type HumanTurnOperatorAttention = "required" | "passive";
264
354
 
355
+ /** @public */
265
356
  export interface HumanTurnDefinition<TParams = unknown, TState = unknown> {
357
+ /** @public */
266
358
  kind: "human";
359
+ /** @public */
267
360
  description: string;
268
- /** Named product rendered as the subject of this human review turn. */
361
+ /** Named product rendered as the subject of this human review turn. @internal */
269
362
  reviewProduct?: string;
363
+ /** @internal */
270
364
  reviewSemanticRef?: ProcessSemanticEntryRefKey;
271
- /** Controls whether entering this turn should raise an action-required toast. */
365
+ /** Controls whether entering this turn should raise an action-required toast. @public */
272
366
  operatorAttention?: HumanTurnOperatorAttention;
367
+ /** @internal */
273
368
  notesFields?: readonly HumanTurnNotesField[];
369
+ /** @internal */
274
370
  commentary?: string;
371
+ /** @public */
275
372
  actions: Record<string, ProcessHumanTurnActionSpec<TParams, TState>>;
373
+ /** @internal */
276
374
  externalActions?: Record<string, ProcessHumanTurnExternalActionSpec<TParams, TState>>;
277
375
  }
278
376
 
377
+ /** @public */
279
378
  export interface ProcessTurnEndSpec<
280
379
  TParams = unknown,
281
380
  TState = unknown,
282
381
  TOutcome extends string = string,
283
382
  > extends StaticRouteTarget {
383
+ /** @public */
284
384
  outcome: TOutcome;
385
+ /** @public */
285
386
  params?: Record<string, unknown>;
387
+ /** @public */
286
388
  effect?: ProcessOutcomeEffect<TParams, TState>;
287
389
  }
288
390
 
391
+ /** @internal */
289
392
  export type OutcomeRouteSpec<TParams = unknown, TState = unknown> = StaticRouteTarget &
290
393
  Partial<Pick<ProcessToolOutcomeSpec<TParams, TState>, "description" | "parameters" | "effect">>;
291
394
 
395
+ /** @internal */
292
396
  export interface OutcomeRouteOptions {
397
+ /** @internal */
293
398
  strict?: boolean;
294
399
  }
295
400
 
401
+ /** @internal */
296
402
  export type LlmModelPurpose = "process_title_generation";
297
403
 
404
+ /** @public */
298
405
  export interface LlmTurnDefinition<
299
406
  TOutcome extends string = string,
300
407
  TParams = unknown,
301
408
  TState = unknown,
302
409
  > {
410
+ /** @public */
303
411
  kind: "llm";
412
+ /** @public */
304
413
  description: string;
305
- /** Code-defined model policy purpose. Purpose selections cannot be overridden per launch/action. */
414
+ /** Code-defined model policy purpose. Purpose selections cannot be overridden per launch/action. @internal */
306
415
  modelPurpose?: LlmModelPurpose;
307
- /** Built-in Pi tools active while this turn runs. */
416
+ /** Built-in Pi tools active while this turn runs. @public */
308
417
  availableTools: readonly PiBuiltInToolName[];
309
- /** Server-owned integration tools proxied over authenticated worker IPC. */
418
+ /** Server-owned integration tools proxied over authenticated worker IPC. @internal */
310
419
  integrationTools?: readonly string[];
311
- /** Opt in to the durable, operator-facing ask_questions custom tool. */
420
+ /** Resolve a constrained tool set from validated durable process data at turn start. @public */
421
+ resolveIntegrationTools?: (params: TParams, state: TState) => readonly string[];
422
+ /** Opt in to the durable, operator-facing ask_questions custom tool. @internal */
312
423
  askQuestions?: boolean;
424
+ /** Deterministic worker preparation that must complete before Pi is prompted. @internal */
425
+ prepare?(ctx: LlmTurnPreparationContext<TParams, TState>): MaybePromise<unknown>;
426
+ /** @public */
313
427
  completionMode?: TurnCompletionMode;
428
+ /** @public */
314
429
  branchType: TurnBranchType;
430
+ /** @public */
315
431
  context: TurnContextMode;
432
+ /** @internal */
316
433
  startFrom?: ProcessTurnStartSelection;
434
+ /** @internal */
317
435
  restorePrimaryLeafAfterTurn?: boolean;
436
+ /** @public */
318
437
  prompt(ctx: ProcessRuntimeTurnContext<TParams, TState>): string | Promise<string>;
438
+ /** @public */
319
439
  outcomes?: Partial<Record<TOutcome, ProcessToolOutcomeSpec<TParams, TState>>>;
440
+ /** @public */
320
441
  turnEnd?: ProcessTurnEndSpec<TParams, TState, TOutcome>;
442
+ /** @public */
321
443
  turnResultMarkdown?: TurnResultMarkdownBehavior;
444
+ /** @internal */
322
445
  reviewSemanticRef?: ProcessSemanticEntryRefKey;
446
+ /** @internal */
323
447
  resultSemanticRef?: ProcessSemanticEntryRefKey;
448
+ /** @internal */
324
449
  publishedProduct?: string;
450
+ /** @internal */
325
451
  consumedProducts?: readonly string[];
452
+ /** @internal */
326
453
  optionalConsumedProducts?: readonly string[];
454
+ /** @internal */
327
455
  requiredSemanticMarkdownRefs?: readonly ProcessSemanticEntryRefKey[];
456
+ /** @internal */
328
457
  optionalSemanticMarkdownRefs?: readonly ProcessSemanticEntryRefKey[];
329
458
  }
330
459
 
460
+ /** @public */
331
461
  export interface AutomaticTurnDefinition<
332
462
  TOutcome extends string = string,
333
463
  TParams = unknown,
334
464
  TState = unknown,
335
465
  > {
466
+ /** @public */
336
467
  kind: "automatic";
468
+ /** @public */
337
469
  description: string;
338
- /** Server-owned integration tools callable by this deterministic worker turn. */
470
+ /** Server-owned integration tools callable by this deterministic worker turn. @internal */
339
471
  integrationTools?: readonly string[];
340
- /** External events armed while this automatic turn is selected and waiting. */
472
+ /** External events armed while this automatic turn is selected and waiting. @public */
341
473
  externalActions?: Record<string, ProcessHumanTurnExternalActionSpec<TParams, TState>>;
474
+ /** @internal */
342
475
  outcomes?: Partial<Record<TOutcome, ProcessToolOutcomeSpec<TParams, TState>>>;
476
+ /** @internal */
343
477
  turnEnd?: ProcessTurnEndSpec<TParams, TState, TOutcome>;
478
+ /** @internal */
344
479
  reviewSemanticRef?: ProcessSemanticEntryRefKey;
480
+ /** @public */
345
481
  run(
346
482
  ctx: ProcessRuntimeTurnContext<TParams, TState>,
347
483
  ): Promise<WorkerCompleteInput<TOutcome>> | WorkerCompleteInput<TOutcome>;
348
484
  }
349
485
 
350
- export interface ServerAutomaticTurnRunResult<TOutcome extends string = string, TState = unknown>
351
- extends WorkerCompleteInput<TOutcome> {
352
- state?: TState;
353
- }
354
-
355
- export type ServerAutomaticTurnRestartBehavior = "rerun" | "fail_running";
356
-
357
- export interface ServerAutomaticTurnDefinition<
358
- TOutcome extends string = string,
359
- TParams = unknown,
360
- TState = unknown,
361
- > {
362
- kind: "server_automatic";
363
- description: string;
364
- outcomes?: Partial<Record<TOutcome, ProcessToolOutcomeSpec<TParams, TState>>>;
365
- turnEnd?: ProcessTurnEndSpec<TParams, TState, TOutcome>;
366
- reviewSemanticRef?: ProcessSemanticEntryRefKey;
367
- /**
368
- * Controls startup/drainer behavior when a durable running turn record already exists.
369
- * The default reruns the deterministic handler. Use fail_running for non-idempotent
370
- * host side effects that must not be replayed after a server crash/restart.
371
- */
372
- restartBehavior?: ServerAutomaticTurnRestartBehavior;
373
- run(
374
- ctx: ProcessServerRuntimeContext<TParams, TState>,
375
- ):
376
- | Promise<ServerAutomaticTurnRunResult<TOutcome, TState>>
377
- | ServerAutomaticTurnRunResult<TOutcome, TState>;
378
- }
379
-
486
+ /** @internal */
380
487
  export interface ExternalSourceTransition<
381
488
  TParams = unknown,
382
489
  TState = unknown,
383
490
  TEvent = unknown,
384
491
  TInput extends Record<string, unknown> = Record<string, unknown>,
385
492
  > extends StaticRouteTarget {
493
+ /** @internal */
386
494
  source: ExternalActionSource<TParams, TState, TEvent, TInput>;
495
+ /** @internal */
387
496
  effect?: ExternalSourceEffect<TParams, TState, TEvent, TInput>;
388
497
  }
389
498
 
499
+ /** @public */
390
500
  export interface ExternalTurnDefinition<TParams = unknown, TState = unknown> {
501
+ /** @public */
391
502
  kind: "external";
503
+ /** @public */
392
504
  description: string;
505
+ /** @internal */
393
506
  transitions: readonly ExternalSourceTransition<TParams, TState>[];
507
+ /** @internal */
394
508
  reviewSemanticRef?: ProcessSemanticEntryRefKey;
395
509
  }
396
510
 
511
+ /** @public */
397
512
  export type TurnDefinition<TParams = unknown, TState = unknown> =
398
513
  | LlmTurnDefinition<string, TParams, TState>
399
514
  | AutomaticTurnDefinition<string, TParams, TState>
400
- | ServerAutomaticTurnDefinition<string, TParams, TState>
401
515
  | HumanTurnDefinition<TParams, TState>
402
516
  | ExternalTurnDefinition<TParams, TState>;
403
517
 
518
+ /** @public */
404
519
  export type TurnDefinitionRecord<TParams = unknown, TState = unknown> = Record<
405
520
  TurnId,
406
521
  TurnDefinition<TParams, TState>
407
522
  >;
408
523
 
409
- export type ProcessDefinition<TParams = unknown, TState = unknown> = ExtensionProcessDefinition<
410
- TParams,
411
- TState
412
- >;
413
-
414
- export interface DefinedProcessInput<TParams = unknown, TState = unknown> {
415
- id: string;
416
- displayName: string;
417
- /** Primary entry used when a launch does not select a start turn explicitly. */
524
+ /** @public */
525
+ export interface DefinedProcessInput<TParams = unknown, TState = unknown>
526
+ extends Omit<
527
+ ExtensionProcessDefinition<TParams, TState>,
528
+ "entryTurnId" | "alternateEntryTurnIds" | "turns"
529
+ > {
530
+ /** Primary entry used when a launch does not select a start turn explicitly. @public */
418
531
  entry: TurnId;
419
- /** Additional entry turns that launchers may select explicitly. */
532
+ /** Additional entry turns that launchers may select explicitly. @public */
420
533
  alternateEntries?: readonly TurnId[];
421
- happyPath?: readonly TurnId[];
422
- paramsCodec: Codec<TParams>;
423
- stateCodec: Codec<TState>;
424
- initialState(params: TParams): TState;
425
- repositoryCredentials?(input: {
426
- params: TParams;
427
- projects: readonly RepositoryCredentialProject[];
428
- }): readonly RepositoryCredentialRequirement[];
429
- piConfig?: ProcessPiConfig;
534
+ /** @public */
430
535
  turns: TurnDefinitionRecord<TParams, TState>;
431
- worker?: (api: WorkerProcessAPI<TParams, TState>) => void;
432
- server?: (api: ServerProcessAPI<TParams, TState>) => void;
433
- ui?: (api: UiProcessAPI<TParams, TState>) => void;
434
- launchers?: (api: ProcessLauncherAPI<TParams>) => void;
435
- watchers?: (api: ProcessWatcherAPI<TParams>) => void;
436
536
  }
437
537
 
438
538
  type CompiledActionRouting<TParams, TState> =
@@ -454,20 +554,9 @@ type CompiledActionUse<TParams, TState> = {
454
554
  routing: CompiledActionRouting<TParams, TState>;
455
555
  };
456
556
 
457
- type CompiledExecutableTurn<TParams, TState> =
458
- | {
459
- kind: "llm";
460
- id: TurnId;
461
- spec: LlmTurnDefinition<string, TParams, TState>;
462
- }
463
- | {
464
- kind: "automatic";
465
- id: TurnId;
466
- spec: AutomaticTurnDefinition<string, TParams, TState>;
467
- };
468
-
469
- function createTransitionTargetError(context: string, detail: string): Error {
470
- return new Error(`${context} ${detail}`);
557
+ interface CompiledOutcomeHandlers<TParams, TState> {
558
+ effects: ReadonlyMap<string, ProcessOutcomeEffect<TParams, TState> | undefined>;
559
+ routings: ReadonlyMap<string, CompiledOutcomeRouting<TParams, TState>>;
471
560
  }
472
561
 
473
562
  function createProcessTurnBinding<TTurn>(
@@ -491,14 +580,13 @@ function normalizeStaticRouteTarget(
491
580
  (target.complete === true ? 1 : 0) +
492
581
  (target.lifecycleStatus !== undefined ? 1 : 0);
493
582
  if (declaredTargetCount !== 1) {
494
- throw createTransitionTargetError(
495
- context,
496
- "must declare exactly one target via 'to', 'complete', or 'lifecycleStatus'",
583
+ throw new Error(
584
+ `${context} must declare exactly one target via 'to', 'complete', or 'lifecycleStatus'`,
497
585
  );
498
586
  }
499
587
  if (target.to !== undefined) {
500
588
  if (knownTurnIds && !knownTurnIds.has(target.to)) {
501
- throw createTransitionTargetError(context, `references unknown turn '${target.to}'`);
589
+ throw new Error(`${context} references unknown turn '${target.to}'`);
502
590
  }
503
591
  return { nextTurnId: target.to };
504
592
  }
@@ -519,9 +607,6 @@ function buildOutcomeTransition<TParams, TState>(
519
607
  `Turn '${turnId}' outcome '${outcome}' must compile state routing before a static transition`,
520
608
  );
521
609
  }
522
- if ("wait" in target && target.wait && hasDeclaredStaticRouteTarget(target)) {
523
- throw new Error(`Turn '${turnId}' outcome '${outcome}' cannot wait and declare another route`);
524
- }
525
610
  if (!hasDeclaredStaticRouteTarget(target)) {
526
611
  return { nextTurnId: turnId };
527
612
  }
@@ -533,35 +618,30 @@ type CompiledOutcomeRouting<TParams, TState> = {
533
618
  choose: ProcessOutcomeBranchSelector<TParams, TState>;
534
619
  };
535
620
 
536
- type CompiledOutcome<TParams, TState> = {
537
- effect?: ProcessOutcomeEffect<TParams, TState>;
538
- routing?: CompiledOutcomeRouting<TParams, TState>;
539
- };
621
+ type BranchRouteSpec = StaticRouteTarget & { trigger?: string };
540
622
 
541
- function normalizeBranchRoutes(input: {
542
- subject: string;
543
- branches: Record<string, ProcessActionBranchSpec>;
623
+ function compileBranchRoutes(input: {
624
+ branches: Record<string, BranchRouteSpec>;
544
625
  knownTurnIds?: ReadonlySet<TurnId>;
626
+ targetContext(branchId: string): string;
627
+ emptyBranchError: string;
628
+ duplicateTriggerError(trigger: string): string;
545
629
  }): {
546
- routes: Readonly<Record<string, NormalizedActionRoute>>;
547
- transitions: readonly NormalizedActionRoute[];
630
+ routes: Record<string, NormalizedActionRoute>;
631
+ transitions: NormalizedActionRoute[];
548
632
  } {
549
- const entries = Object.entries(input.branches);
550
- if (entries.length === 0) throw new Error(`${input.subject} must declare at least one branch`);
551
633
  const routes: Record<string, NormalizedActionRoute> = {};
552
634
  const transitions: NormalizedActionRoute[] = [];
553
635
  const usedTriggers = new Set<string>();
554
- for (const [branchId, branchSpec] of entries) {
555
- if (branchId.trim() === "") throw new Error(`${input.subject} contains an empty branch id`);
636
+ for (const [branchId, branchSpec] of Object.entries(input.branches)) {
637
+ if (branchId.trim() === "") throw new Error(input.emptyBranchError);
556
638
  const target = normalizeStaticRouteTarget(
557
- `${input.subject} branch '${branchId}'`,
639
+ input.targetContext(branchId),
558
640
  branchSpec,
559
641
  input.knownTurnIds,
560
642
  );
561
643
  const trigger = branchSpec.trigger ?? branchId;
562
- if (usedTriggers.has(trigger)) {
563
- throw new Error(`${input.subject} contains duplicate branch trigger '${trigger}'`);
564
- }
644
+ if (usedTriggers.has(trigger)) throw new Error(input.duplicateTriggerError(trigger));
565
645
  usedTriggers.add(trigger);
566
646
  const route = { ...target, trigger };
567
647
  routes[branchId] = route;
@@ -579,10 +659,20 @@ function resolveOutcomeRouting<TParams, TState>(input: {
579
659
  if (!("branches" in input.spec)) {
580
660
  return null;
581
661
  }
582
- const { routes } = normalizeBranchRoutes({
583
- subject: `Turn '${input.turnId}' outcome '${input.outcome}'`,
662
+ const entries = Object.entries(input.spec.branches);
663
+ if (entries.length === 0) {
664
+ throw new Error(
665
+ `Turn '${input.turnId}' outcome '${input.outcome}' must declare at least one branch`,
666
+ );
667
+ }
668
+ const { routes } = compileBranchRoutes({
584
669
  branches: input.spec.branches,
585
670
  knownTurnIds: input.knownTurnIds,
671
+ targetContext: (branchId) =>
672
+ `Turn '${input.turnId}' outcome '${input.outcome}' branch '${branchId}'`,
673
+ emptyBranchError: `Turn '${input.turnId}' outcome '${input.outcome}' contains an empty branch id`,
674
+ duplicateTriggerError: (trigger) =>
675
+ `Turn '${input.turnId}' outcome '${input.outcome}' contains duplicate branch trigger '${trigger}'`,
586
676
  });
587
677
  return { routes, choose: input.spec.choose };
588
678
  }
@@ -597,13 +687,27 @@ function resolveActionRouting<TParams, TState>(input: {
597
687
  transitions: readonly NormalizedActionRoute[];
598
688
  } {
599
689
  if ("branches" in input.spec) {
600
- const { routes, transitions } = normalizeBranchRoutes({
601
- subject: `Action '${input.actionId}' on turn '${input.turnId}'`,
690
+ const entries = Object.entries(input.spec.branches) as Array<[string, ProcessActionBranchSpec]>;
691
+ if (entries.length === 0) {
692
+ throw new Error(
693
+ `Action '${input.actionId}' on turn '${input.turnId}' must declare at least one branch`,
694
+ );
695
+ }
696
+ const { routes, transitions } = compileBranchRoutes({
602
697
  branches: input.spec.branches,
603
698
  knownTurnIds: input.knownTurnIds,
699
+ targetContext: (branchId) =>
700
+ `Action '${input.actionId}' branch '${branchId}' on turn '${input.turnId}'`,
701
+ emptyBranchError: `Action '${input.actionId}' on turn '${input.turnId}' contains an empty branch id`,
702
+ duplicateTriggerError: (trigger) =>
703
+ `Action '${input.actionId}' on turn '${input.turnId}' contains duplicate branch trigger '${trigger}'`,
604
704
  });
605
705
  return {
606
- routing: { kind: "branches", routes, choose: input.spec.choose },
706
+ routing: {
707
+ kind: "branches",
708
+ routes,
709
+ choose: input.spec.choose,
710
+ },
607
711
  transitions,
608
712
  };
609
713
  }
@@ -626,19 +730,33 @@ function resolveActionRouting<TParams, TState>(input: {
626
730
  };
627
731
  }
628
732
 
629
- function externalSourceTransitionId(input: {
733
+ /** @internal */
734
+ export function getExternalSourceTransitionId(input: {
735
+ /** @internal */
630
736
  turnId: TurnId;
737
+ /** @internal */
631
738
  source: ExternalActionSource;
739
+ /** @internal */
632
740
  index: number;
633
741
  }): string {
634
742
  return `${input.turnId}:${input.source.kind}:${input.index}`;
635
743
  }
636
744
 
637
- function externalActionArmingId(input: { turnId: TurnId; externalActionId: string }): string {
745
+ /** @internal */
746
+ export function getExternalActionArmingId(input: {
747
+ /** @internal */
748
+ turnId: TurnId;
749
+ /** @internal */
750
+ externalActionId: string;
751
+ }): string {
638
752
  return `${input.turnId}:${input.externalActionId}`;
639
753
  }
640
754
 
641
- function externalActionTransitionTrigger(input: { externalActionId: string }): string {
755
+ /** @internal */
756
+ export function getExternalActionTransitionTrigger(input: {
757
+ /** @internal */
758
+ externalActionId: string;
759
+ }): string {
642
760
  return `external:${input.externalActionId}`;
643
761
  }
644
762
 
@@ -664,7 +782,7 @@ function compileExternalSourceTransitions<TParams, TState>(input: {
664
782
  return {
665
783
  ...(target.nextTurnId ? { nextTurnId: target.nextTurnId } : {}),
666
784
  ...(target.lifecycleStatus ? { lifecycleStatus: target.lifecycleStatus } : {}),
667
- trigger: externalSourceTransitionId({
785
+ trigger: getExternalSourceTransitionId({
668
786
  turnId: input.turnId,
669
787
  source: transition.source,
670
788
  index,
@@ -673,25 +791,6 @@ function compileExternalSourceTransitions<TParams, TState>(input: {
673
791
  });
674
792
  }
675
793
 
676
- export function getExternalSourceTransitionId(input: {
677
- turnId: TurnId;
678
- source: ExternalActionSource;
679
- index: number;
680
- }): string {
681
- return externalSourceTransitionId(input);
682
- }
683
-
684
- export function getExternalActionArmingId(input: {
685
- turnId: TurnId;
686
- externalActionId: string;
687
- }): string {
688
- return externalActionArmingId(input);
689
- }
690
-
691
- export function getExternalActionTransitionTrigger(input: { externalActionId: string }): string {
692
- return externalActionTransitionTrigger(input);
693
- }
694
-
695
794
  function previewMatchesTransition(
696
795
  preview: ProcessActionPreviewDefinition,
697
796
  transition: NormalizedActionRoute,
@@ -815,18 +914,6 @@ function mergeProcessEffectPlans<TState>(
815
914
  };
816
915
  }
817
916
 
818
- function normalizeEffectString(value: unknown): string {
819
- return typeof value === "string" ? value.trim() : "";
820
- }
821
-
822
- function normalizeEffectStringArray(value: unknown): string[] {
823
- return Array.isArray(value)
824
- ? value
825
- .map((entry) => (typeof entry === "string" ? entry.trim() : ""))
826
- .filter((entry) => entry !== "")
827
- : [];
828
- }
829
-
830
917
  async function buildSavePlanResultEffect<TParams, TState>(input: {
831
918
  intent: SavePlanResultLifecycleIntent<TParams, TState>;
832
919
  execution: ProcessOutcomeExecution<TParams, TState>;
@@ -873,25 +960,21 @@ function resolveOutcomeEffect<TParams, TState>(input: {
873
960
  spec: ProcessToolOutcomeSpec<TParams, TState> | ProcessTurnEndSpec<TParams, TState, string>;
874
961
  }): ProcessOutcomeEffect<TParams, TState> | undefined {
875
962
  const lifecycleIntent = "lifecycleIntent" in input.spec ? input.spec.lifecycleIntent : undefined;
876
- const waits = "wait" in input.spec && input.spec.wait === true;
877
- if (!lifecycleIntent && !waits) return input.spec.effect;
963
+ if (!lifecycleIntent) {
964
+ return input.spec.effect;
965
+ }
878
966
  return async (execution) => {
879
967
  const explicitPlan = input.spec.effect ? await input.spec.effect(execution) : undefined;
880
968
  let lifecyclePlan: ProcessEffectPlan<TState> | undefined;
881
- if (lifecycleIntent) {
882
- switch (lifecycleIntent.kind) {
883
- case "save_plan_result":
884
- lifecyclePlan = await buildSavePlanResultEffect({
885
- intent: lifecycleIntent,
886
- execution,
887
- });
888
- break;
889
- }
969
+ switch (lifecycleIntent.kind) {
970
+ case "save_plan_result":
971
+ lifecyclePlan = await buildSavePlanResultEffect({
972
+ intent: lifecycleIntent,
973
+ execution,
974
+ });
975
+ break;
890
976
  }
891
- const result = mergeProcessEffectPlans(explicitPlan, lifecyclePlan);
892
- return waits
893
- ? mergeProcessEffectPlans(result, { processPatch: { lifecycleStatus: "waiting" } })
894
- : result;
977
+ return mergeProcessEffectPlans(explicitPlan, lifecyclePlan);
895
978
  };
896
979
  }
897
980
 
@@ -1030,9 +1113,8 @@ function compileTurnOutcomeDefinitions<TParams, TState>(input: {
1030
1113
  outcomes?: Partial<Record<string, ProcessToolOutcomeSpec<TParams, TState>>>;
1031
1114
  turnEnd?: ProcessTurnEndSpec<TParams, TState, string>;
1032
1115
  knownTurnIds: ReadonlySet<TurnId>;
1033
- }): {
1116
+ }): CompiledOutcomeHandlers<TParams, TState> & {
1034
1117
  transitions: readonly ProcessTurnTransition[];
1035
- outcomes: ReadonlyMap<string, CompiledOutcome<TParams, TState>>;
1036
1118
  } {
1037
1119
  const outcomeEntries = Object.entries(input.outcomes ?? {}) as Array<
1038
1120
  [string, ProcessToolOutcomeSpec<TParams, TState>]
@@ -1049,7 +1131,8 @@ function compileTurnOutcomeDefinitions<TParams, TState>(input: {
1049
1131
  }
1050
1132
 
1051
1133
  const transitions: ProcessTurnTransition[] = [];
1052
- const outcomes = new Map<string, CompiledOutcome<TParams, TState>>();
1134
+ const effects = new Map<string, ProcessOutcomeEffect<TParams, TState> | undefined>();
1135
+ const routings = new Map<string, CompiledOutcomeRouting<TParams, TState>>();
1053
1136
  for (const [outcome, spec] of outcomeEntries) {
1054
1137
  if (outcome.trim() === "") {
1055
1138
  throw new Error(`Turn '${input.turnId}' declares an empty outcome id`);
@@ -1064,6 +1147,7 @@ function compileTurnOutcomeDefinitions<TParams, TState>(input: {
1064
1147
  ? null
1065
1148
  : buildOutcomeTransition(input.turnId, outcome, spec, input.knownTurnIds);
1066
1149
  if (routing) {
1150
+ routings.set(outcome, routing);
1067
1151
  for (const route of Object.values(routing.routes)) {
1068
1152
  transitions.push({
1069
1153
  ...(route.nextTurnId ? { nextTurnId: route.nextTurnId } : {}),
@@ -1079,10 +1163,7 @@ function compileTurnOutcomeDefinitions<TParams, TState>(input: {
1079
1163
  outcome,
1080
1164
  });
1081
1165
  }
1082
- outcomes.set(outcome, {
1083
- effect: resolveOutcomeEffect({ spec }),
1084
- ...(routing ? { routing } : {}),
1085
- });
1166
+ effects.set(outcome, resolveOutcomeEffect({ spec }));
1086
1167
  }
1087
1168
 
1088
1169
  if (input.turnEnd) {
@@ -1100,12 +1181,14 @@ function compileTurnOutcomeDefinitions<TParams, TState>(input: {
1100
1181
  ...(target.lifecycleStatus ? { lifecycleStatus: target.lifecycleStatus } : {}),
1101
1182
  outcome: input.turnEnd.outcome,
1102
1183
  });
1103
- outcomes.set(input.turnEnd.outcome, {
1104
- effect: resolveOutcomeEffect({ spec: input.turnEnd }),
1105
- });
1184
+ effects.set(input.turnEnd.outcome, resolveOutcomeEffect({ spec: input.turnEnd }));
1106
1185
  }
1107
1186
 
1108
- return { transitions, outcomes };
1187
+ return {
1188
+ transitions,
1189
+ effects,
1190
+ routings,
1191
+ };
1109
1192
  }
1110
1193
 
1111
1194
  function addActionUse<TParams, TState>(input: {
@@ -1172,7 +1255,7 @@ function resolveExternalActionRoute<TParams, TState>(input: {
1172
1255
  return {
1173
1256
  ...(target.nextTurnId ? { nextTurnId: target.nextTurnId } : {}),
1174
1257
  ...(target.lifecycleStatus ? { lifecycleStatus: target.lifecycleStatus } : {}),
1175
- trigger: externalActionTransitionTrigger({ externalActionId: input.externalActionId }),
1258
+ trigger: getExternalActionTransitionTrigger({ externalActionId: input.externalActionId }),
1176
1259
  };
1177
1260
  }
1178
1261
 
@@ -1235,73 +1318,12 @@ function validateActionPrimaryPrompt(
1235
1318
  }
1236
1319
  }
1237
1320
 
1238
- function deriveExternalActions<TParams, TState>(input: {
1239
- turnId: TurnId;
1240
- externalActions?: Record<string, ProcessHumanTurnExternalActionSpec<TParams, TState>>;
1241
- knownTurnIds?: ReadonlySet<TurnId>;
1242
- turnDefinitionsById?: ReadonlyMap<TurnId, TurnDefinition<unknown, unknown>>;
1243
- reservedTriggers?: ReadonlyMap<string, string>;
1244
- }): {
1245
- externalActions: readonly DerivedHumanTurnExternalAction<TParams, TState>[];
1246
- transitions: readonly ProcessTurnTransition[];
1247
- } {
1248
- const externalActions: DerivedHumanTurnExternalAction<TParams, TState>[] = [];
1249
- const transitions: ProcessTurnTransition[] = [];
1250
- const usedTriggers = new Map(input.reservedTriggers);
1251
- for (const [externalActionId, actionSpec] of Object.entries(input.externalActions ?? {})) {
1252
- if (actionSpec.publishInput) {
1253
- assertValidProcessProductName(actionSpec.publishInput.productName);
1254
- if (actionSpec.publishInput.inputField.trim() === "") {
1255
- throw new Error(
1256
- `Turn '${input.turnId}' external action '${externalActionId}' publishInput must declare a non-empty inputField`,
1257
- );
1258
- }
1259
- }
1260
- validateExternalActionPublishedInputTarget({
1261
- turnId: input.turnId,
1262
- externalActionId,
1263
- spec: actionSpec,
1264
- turnDefinitionsById: input.turnDefinitionsById,
1265
- });
1266
- const transition = resolveExternalActionRoute({
1267
- turnId: input.turnId,
1268
- externalActionId,
1269
- spec: actionSpec,
1270
- knownTurnIds: input.knownTurnIds,
1271
- });
1272
- const existingActionId = usedTriggers.get(transition.trigger);
1273
- if (existingActionId) {
1274
- throw new Error(
1275
- `Turn '${input.turnId}' contains duplicate trigger '${transition.trigger}' across action '${existingActionId}' and external action '${externalActionId}'`,
1276
- );
1277
- }
1278
- usedTriggers.set(transition.trigger, externalActionId);
1279
- transitions.push({
1280
- ...(transition.nextTurnId ? { nextTurnId: transition.nextTurnId } : {}),
1281
- ...(transition.lifecycleStatus ? { lifecycleStatus: transition.lifecycleStatus } : {}),
1282
- trigger: transition.trigger,
1283
- });
1284
- externalActions.push({
1285
- externalActionId,
1286
- actionSpec,
1287
- transition,
1288
- view: {
1289
- id: externalActionArmingId({ turnId: input.turnId, externalActionId }),
1290
- externalActionId,
1291
- sourceKind: actionSpec.source.kind,
1292
- label: actionSpec.label ?? actionSpec.source.label ?? null,
1293
- description: actionSpec.description ?? actionSpec.source.description ?? null,
1294
- },
1295
- });
1296
- }
1297
- return { externalActions, transitions };
1298
- }
1299
-
1300
1321
  function deriveHumanTurnActions<TParams, TState>(input: {
1301
1322
  turnId: TurnId;
1302
1323
  spec: HumanTurnDefinition<TParams, TState>;
1303
1324
  knownTurnIds?: ReadonlySet<TurnId>;
1304
1325
  turnDefinitionsById?: ReadonlyMap<TurnId, TurnDefinition<unknown, unknown>>;
1326
+ requireHumanActions?: boolean;
1305
1327
  }): {
1306
1328
  actions: readonly DerivedHumanTurnAction<TParams, TState>[];
1307
1329
  externalActions: readonly DerivedHumanTurnExternalAction<TParams, TState>[];
@@ -1310,7 +1332,7 @@ function deriveHumanTurnActions<TParams, TState>(input: {
1310
1332
  const actionEntries = Object.entries(input.spec.actions) as Array<
1311
1333
  [string, ProcessHumanTurnActionSpec<TParams, TState>]
1312
1334
  >;
1313
- if (actionEntries.length === 0 && input.knownTurnIds) {
1335
+ if (actionEntries.length === 0 && input.knownTurnIds && input.requireHumanActions !== false) {
1314
1336
  throw new Error(`Human turn '${input.turnId}' must declare at least one action`);
1315
1337
  }
1316
1338
 
@@ -1384,26 +1406,83 @@ function deriveHumanTurnActions<TParams, TState>(input: {
1384
1406
  });
1385
1407
  }
1386
1408
 
1387
- const derivedExternal = deriveExternalActions({
1388
- turnId: input.turnId,
1389
- externalActions: input.spec.externalActions,
1390
- knownTurnIds: input.knownTurnIds,
1391
- turnDefinitionsById: input.turnDefinitionsById,
1392
- reservedTriggers: actionIdByTrigger,
1393
- });
1409
+ const externalActionEntries = Object.entries(input.spec.externalActions ?? {}) as Array<
1410
+ [string, ProcessHumanTurnExternalActionSpec<TParams, TState>]
1411
+ >;
1412
+ const derivedExternalActions: DerivedHumanTurnExternalAction<TParams, TState>[] = [];
1413
+ const externalActionIds = new Set<string>();
1414
+ for (const [externalActionId, actionSpec] of externalActionEntries) {
1415
+ if (externalActionIds.has(externalActionId)) {
1416
+ throw new Error(
1417
+ `Human turn '${input.turnId}' declares duplicate external action '${externalActionId}'`,
1418
+ );
1419
+ }
1420
+ externalActionIds.add(externalActionId);
1421
+ if (actionSpec.publishInput) {
1422
+ assertValidProcessProductName(actionSpec.publishInput.productName);
1423
+ if (actionSpec.publishInput.inputField.trim() === "") {
1424
+ throw new Error(
1425
+ `Human turn '${input.turnId}' external action '${externalActionId}' publishInput must declare a non-empty inputField`,
1426
+ );
1427
+ }
1428
+ }
1429
+ validateExternalActionPublishedInputTarget({
1430
+ turnId: input.turnId,
1431
+ externalActionId,
1432
+ spec: actionSpec,
1433
+ turnDefinitionsById: input.turnDefinitionsById,
1434
+ });
1435
+ const transition = resolveExternalActionRoute({
1436
+ turnId: input.turnId,
1437
+ externalActionId,
1438
+ spec: actionSpec,
1439
+ knownTurnIds: input.knownTurnIds,
1440
+ });
1441
+ const existingActionId = actionIdByTrigger.get(transition.trigger);
1442
+ if (existingActionId) {
1443
+ throw new Error(
1444
+ `Human turn '${input.turnId}' contains duplicate trigger '${transition.trigger}' across action '${existingActionId}' and external action '${externalActionId}'`,
1445
+ );
1446
+ }
1447
+ actionIdByTrigger.set(transition.trigger, externalActionId);
1448
+ transitions.push({
1449
+ ...(transition.nextTurnId ? { nextTurnId: transition.nextTurnId } : {}),
1450
+ ...(transition.lifecycleStatus ? { lifecycleStatus: transition.lifecycleStatus } : {}),
1451
+ trigger: transition.trigger,
1452
+ });
1453
+ derivedExternalActions.push({
1454
+ externalActionId,
1455
+ actionSpec,
1456
+ transition,
1457
+ view: {
1458
+ id: getExternalActionArmingId({ turnId: input.turnId, externalActionId }),
1459
+ externalActionId,
1460
+ sourceKind: actionSpec.source.kind,
1461
+ label: actionSpec.label ?? actionSpec.source.label ?? null,
1462
+ description: actionSpec.description ?? actionSpec.source.description ?? null,
1463
+ },
1464
+ });
1465
+ }
1466
+
1394
1467
  return {
1395
1468
  actions: derivedActions,
1396
- externalActions: derivedExternal.externalActions,
1397
- transitions: [...transitions, ...derivedExternal.transitions],
1469
+ externalActions: derivedExternalActions,
1470
+ transitions,
1398
1471
  };
1399
1472
  }
1400
1473
 
1474
+ /** @internal */
1401
1475
  export function resolveHumanTurnView<TParams, TState>(input: {
1476
+ /** @internal */
1402
1477
  turnId: TurnId;
1478
+ /** @internal */
1403
1479
  turn: HumanTurnDefinition<TParams, TState>;
1404
1480
  }): {
1481
+ /** @internal */
1405
1482
  actions: readonly HumanTurnActionView[];
1483
+ /** @internal */
1406
1484
  externalTriggers: readonly HumanTurnExternalTrigger[];
1485
+ /** @internal */
1407
1486
  externalActions: readonly HumanTurnExternalActionView[];
1408
1487
  } {
1409
1488
  const derived = deriveHumanTurnActions({
@@ -1468,12 +1547,6 @@ function compileExternalTurn<TParams, TState>(input: {
1468
1547
  };
1469
1548
  }
1470
1549
 
1471
- function getTurnEntries<TParams, TState>(
1472
- turns: TurnDefinitionRecord<TParams, TState>,
1473
- ): Array<[TurnId, TurnDefinition<TParams, TState>]> {
1474
- return Object.entries(turns) as Array<[TurnId, TurnDefinition<TParams, TState>]>;
1475
- }
1476
-
1477
1550
  function resolveActionRouteForExecution<TParams, TState>(input: {
1478
1551
  use: CompiledActionUse<TParams, TState>;
1479
1552
  actionId: string;
@@ -1573,7 +1646,7 @@ function validateHappyPathConnectivity<TParams, TState>(input: {
1573
1646
  function buildDefinedProcess<TParams, TState>(
1574
1647
  input: DefinedProcessInput<TParams, TState>,
1575
1648
  ): Pick<ExtensionProcessDefinition<TParams, TState>, "turns" | "worker" | "server"> {
1576
- const turnEntries = getTurnEntries(input.turns);
1649
+ const turnEntries = Object.entries(input.turns);
1577
1650
  if (turnEntries.length === 0) {
1578
1651
  throw new Error(`Process '${input.id}' must declare at least one turn`);
1579
1652
  }
@@ -1618,61 +1691,41 @@ function buildDefinedProcess<TParams, TState>(
1618
1691
 
1619
1692
  const turns = new Map<TurnId, ProcessTurnBinding<TurnDefinition<TParams, TState>>>();
1620
1693
  const actionUses = new Map<string, CompiledActionUse<TParams, TState>[]>();
1621
- const compiledOutcomesByTurn = new Map<
1694
+ const executableTurns = new Map<
1622
1695
  TurnId,
1623
- ReadonlyMap<string, CompiledOutcome<TParams, TState>>
1696
+ CompiledOutcomeHandlers<TParams, TState> & {
1697
+ spec: RoutableTurnDefinition<string, TParams, TState>;
1698
+ }
1624
1699
  >();
1625
- const executableTurns = new Map<TurnId, CompiledExecutableTurn<TParams, TState>>();
1626
1700
 
1627
1701
  for (const [turnId, turnSpec] of turnEntries) {
1628
- if (turnSpec.kind === "llm") {
1629
- const compiledOutcomes = compileTurnOutcomeDefinitions({
1630
- turnId,
1631
- outcomes: turnSpec.outcomes,
1632
- turnEnd: turnSpec.turnEnd,
1633
- knownTurnIds,
1634
- });
1635
- turns.set(turnId, createProcessTurnBinding(turnSpec, compiledOutcomes.transitions));
1636
- compiledOutcomesByTurn.set(turnId, compiledOutcomes.outcomes);
1637
- executableTurns.set(turnId, {
1638
- kind: "llm",
1639
- id: turnId,
1640
- spec: turnSpec,
1641
- });
1642
- continue;
1643
- }
1644
-
1645
- if (turnSpec.kind === "automatic" || turnSpec.kind === "server_automatic") {
1646
- const compiledOutcomes = compileTurnOutcomeDefinitions({
1702
+ if (turnSpec.kind === "llm" || turnSpec.kind === "automatic") {
1703
+ const { transitions, effects, routings } = compileTurnOutcomeDefinitions({
1647
1704
  turnId,
1648
1705
  outcomes: turnSpec.outcomes,
1649
1706
  turnEnd: turnSpec.turnEnd,
1650
1707
  knownTurnIds,
1651
1708
  });
1652
1709
  const externalTransitions =
1653
- turnSpec.kind === "automatic"
1654
- ? deriveExternalActions({
1710
+ turnSpec.kind === "automatic" && turnSpec.externalActions
1711
+ ? deriveHumanTurnActions({
1655
1712
  turnId,
1656
- externalActions: turnSpec.externalActions,
1713
+ spec: {
1714
+ kind: "human",
1715
+ description: turnSpec.description,
1716
+ actions: {},
1717
+ externalActions: turnSpec.externalActions,
1718
+ },
1657
1719
  knownTurnIds,
1658
1720
  turnDefinitionsById,
1721
+ requireHumanActions: false,
1659
1722
  }).transitions
1660
1723
  : [];
1661
1724
  turns.set(
1662
1725
  turnId,
1663
- createProcessTurnBinding(turnSpec, [
1664
- ...compiledOutcomes.transitions,
1665
- ...externalTransitions,
1666
- ]),
1726
+ createProcessTurnBinding(turnSpec, [...transitions, ...externalTransitions]),
1667
1727
  );
1668
- compiledOutcomesByTurn.set(turnId, compiledOutcomes.outcomes);
1669
- if (turnSpec.kind === "automatic") {
1670
- executableTurns.set(turnId, {
1671
- kind: "automatic",
1672
- id: turnId,
1673
- spec: turnSpec,
1674
- });
1675
- }
1728
+ executableTurns.set(turnId, { spec: turnSpec, effects, routings });
1676
1729
  continue;
1677
1730
  }
1678
1731
 
@@ -1715,18 +1768,18 @@ function buildDefinedProcess<TParams, TState>(
1715
1768
  api.turn(turnId, handler);
1716
1769
  },
1717
1770
  });
1718
- for (const executable of executableTurns.values()) {
1719
- if (manuallyRegisteredTurns.has(executable.id)) {
1771
+ for (const [turnId, { spec }] of executableTurns) {
1772
+ if (manuallyRegisteredTurns.has(turnId)) {
1720
1773
  continue;
1721
1774
  }
1722
- if (executable.kind === "llm") {
1723
- api.turn(executable.id, async (run) => {
1724
- await run.turn(executable.spec);
1775
+ if (spec.kind === "llm") {
1776
+ api.turn(turnId, async (run) => {
1777
+ await run.turn(spec);
1725
1778
  });
1726
1779
  continue;
1727
1780
  }
1728
- api.turn(executable.id, async (run) => {
1729
- await run.complete(await executable.spec.run(run.ctx));
1781
+ api.turn(turnId, async (run) => {
1782
+ await run.complete(await spec.run(run.ctx));
1730
1783
  });
1731
1784
  }
1732
1785
  };
@@ -1788,9 +1841,10 @@ function buildDefinedProcess<TParams, TState>(
1788
1841
  });
1789
1842
  }
1790
1843
 
1791
- for (const [turnId, outcomes] of compiledOutcomesByTurn) {
1844
+ for (const [turnId, { effects, routings }] of executableTurns) {
1792
1845
  api.onTurnOutcome(turnId, async (event, ctx) => {
1793
- const { effect, routing } = outcomes.get(event.outcome) ?? {};
1846
+ const effect = effects.get(event.outcome);
1847
+ const routing = routings.get(event.outcome);
1794
1848
  if (!effect && !routing) {
1795
1849
  return;
1796
1850
  }
@@ -1826,9 +1880,10 @@ function buildDefinedProcess<TParams, TState>(
1826
1880
  };
1827
1881
  }
1828
1882
 
1883
+ /** @public */
1829
1884
  export function defineProcess<TParams = unknown, TState = unknown>(
1830
1885
  input: DefinedProcessInput<TParams, TState>,
1831
- ): ProcessDefinition<TParams, TState> {
1886
+ ): ExtensionProcessDefinition<TParams, TState> {
1832
1887
  const compiled = buildDefinedProcess(input);
1833
1888
  const process = {
1834
1889
  id: input.id,
@@ -1840,6 +1895,8 @@ export function defineProcess<TParams = unknown, TState = unknown>(
1840
1895
  paramsCodec: input.paramsCodec,
1841
1896
  stateCodec: input.stateCodec,
1842
1897
  initialState: input.initialState,
1898
+ ...(input.runtime ? { runtime: { ...input.runtime } } : {}),
1899
+ ...(input.resolveStorageSize ? { resolveStorageSize: input.resolveStorageSize } : {}),
1843
1900
  ...(input.repositoryCredentials ? { repositoryCredentials: input.repositoryCredentials } : {}),
1844
1901
  ...(input.piConfig ? { piConfig: input.piConfig } : {}),
1845
1902
  server: compiled.server,
@@ -1852,19 +1909,23 @@ export function defineProcess<TParams = unknown, TState = unknown>(
1852
1909
  return process;
1853
1910
  }
1854
1911
 
1912
+ /** @internal */
1855
1913
  type RoutableTurnDefinition<TOutcome extends string, TParams, TState> =
1856
1914
  | LlmTurnDefinition<TOutcome, TParams, TState>
1857
- | AutomaticTurnDefinition<TOutcome, TParams, TState>
1858
- | ServerAutomaticTurnDefinition<TOutcome, TParams, TState>;
1915
+ | AutomaticTurnDefinition<TOutcome, TParams, TState>;
1859
1916
 
1860
1917
  // biome-ignore-start lint/suspicious/noExplicitAny: conditional helper types must match and preserve any routable turn instantiation
1918
+ /** @internal */
1861
1919
  type RoutableOutcome<TTurn> =
1862
1920
  TTurn extends RoutableTurnDefinition<infer TOutcome, any, any> ? TOutcome : never;
1921
+ /** @internal */
1863
1922
  type RoutableParams<TTurn> =
1864
1923
  TTurn extends RoutableTurnDefinition<any, infer TParams, any> ? TParams : never;
1924
+ /** @internal */
1865
1925
  type RoutableState<TTurn> =
1866
1926
  TTurn extends RoutableTurnDefinition<any, any, infer TState> ? TState : never;
1867
1927
 
1928
+ /** @internal */
1868
1929
  export function routeTurnOutcomes<TTurn extends RoutableTurnDefinition<string, any, any>>(
1869
1930
  baseTurn: TTurn,
1870
1931
  routes: Partial<
@@ -1904,6 +1965,7 @@ export function routeTurnOutcomes<TTurn extends RoutableTurnDefinition<string, a
1904
1965
  }
1905
1966
  // biome-ignore-end lint/suspicious/noExplicitAny: end routable turn instantiation helper suppression
1906
1967
 
1968
+ /** @public */
1907
1969
  export function llmTurn<TParams = unknown, TState = unknown, TOutcome extends string = string>(
1908
1970
  input: Omit<LlmTurnDefinition<TOutcome, TParams, TState>, "kind">,
1909
1971
  ): LlmTurnDefinition<TOutcome, TParams, TState> {
@@ -1913,6 +1975,7 @@ export function llmTurn<TParams = unknown, TState = unknown, TOutcome extends st
1913
1975
  };
1914
1976
  }
1915
1977
 
1978
+ /** @internal */
1916
1979
  export function automaticTurn<
1917
1980
  TParams = unknown,
1918
1981
  TState = unknown,
@@ -1926,19 +1989,7 @@ export function automaticTurn<
1926
1989
  };
1927
1990
  }
1928
1991
 
1929
- export function serverAutomaticTurn<
1930
- TParams = unknown,
1931
- TState = unknown,
1932
- TOutcome extends string = string,
1933
- >(
1934
- input: Omit<ServerAutomaticTurnDefinition<TOutcome, TParams, TState>, "kind">,
1935
- ): ServerAutomaticTurnDefinition<TOutcome, TParams, TState> {
1936
- return {
1937
- ...input,
1938
- kind: "server_automatic",
1939
- };
1940
- }
1941
-
1992
+ /** @public */
1942
1993
  export function humanTurn<TParams = unknown, TState = unknown>(
1943
1994
  input: Omit<HumanTurnDefinition<TParams, TState>, "kind">,
1944
1995
  ): HumanTurnDefinition<TParams, TState> {
@@ -1948,6 +1999,7 @@ export function humanTurn<TParams = unknown, TState = unknown>(
1948
1999
  };
1949
2000
  }
1950
2001
 
2002
+ /** @internal */
1951
2003
  export function externalTurn<TParams = unknown, TState = unknown>(
1952
2004
  input: Omit<ExternalTurnDefinition<TParams, TState>, "kind">,
1953
2005
  ): ExternalTurnDefinition<TParams, TState> {