@leitwerk-dev/process-sdk 0.1.9 → 0.2.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 (169) hide show
  1. package/dist/{chunk-TRQJ5PRM.js → chunk-TA4KO53Q.js} +1 -5
  2. package/dist/chunk-TA4KO53Q.js.map +1 -0
  3. package/dist/{chunk-5RJZ2E7D.js → chunk-WFY2WWZE.js} +2 -6
  4. package/dist/{chunk-5RJZ2E7D.js.map → chunk-WFY2WWZE.js.map} +1 -1
  5. package/dist/core-capabilities.d.ts +70 -34
  6. package/dist/core-capabilities.d.ts.map +1 -1
  7. package/dist/define-process.d.ts +17 -49
  8. package/dist/define-process.d.ts.map +1 -1
  9. package/dist/{extension-api-BBcwktmc.d.ts → extension-api-CcqZCYJx.d.ts} +136 -70
  10. package/dist/extension-api.d.ts +115 -7
  11. package/dist/extension-api.d.ts.map +1 -1
  12. package/dist/external-action-source.d.ts +7 -0
  13. package/dist/external-action-source.d.ts.map +1 -0
  14. package/dist/external-source-poll.d.ts +15 -0
  15. package/dist/external-source-poll.d.ts.map +1 -0
  16. package/dist/flow.d.ts +80 -104
  17. package/dist/flow.d.ts.map +1 -1
  18. package/dist/fs-utils.d.ts +2 -0
  19. package/dist/fs-utils.d.ts.map +1 -1
  20. package/dist/git-binary.js +25 -33
  21. package/dist/git-binary.js.map +1 -1
  22. package/dist/index.d.ts +21 -9
  23. package/dist/index.d.ts.map +1 -1
  24. package/dist/index.js +4694 -29
  25. package/dist/index.js.map +1 -1
  26. package/dist/integration-http.d.ts +21 -0
  27. package/dist/integration-http.d.ts.map +1 -0
  28. package/dist/json-data.d.ts +3 -0
  29. package/dist/json-data.d.ts.map +1 -0
  30. package/dist/leaf-outcome-renderer.js +74 -64
  31. package/dist/leaf-outcome-renderer.js.map +1 -1
  32. package/dist/leaf-outcomes.d.ts.map +1 -1
  33. package/dist/model-provider.d.ts.map +1 -1
  34. package/dist/pi-config.d.ts +1 -5
  35. package/dist/pi-config.d.ts.map +1 -1
  36. package/dist/pi-config.js +20 -180
  37. package/dist/pi-config.js.map +1 -1
  38. package/dist/process-flow-view.d.ts.map +1 -1
  39. package/dist/process-graph.d.ts.map +1 -1
  40. package/dist/process-watcher-source.d.ts.map +1 -1
  41. package/dist/project-binding.d.ts +9 -0
  42. package/dist/project-binding.d.ts.map +1 -0
  43. package/dist/registry-utils.d.ts.map +1 -1
  44. package/dist/repository-feedback.d.ts +29 -0
  45. package/dist/repository-feedback.d.ts.map +1 -0
  46. package/dist/repository-git-env.d.ts +2 -0
  47. package/dist/repository-git-env.d.ts.map +1 -1
  48. package/dist/repository-http.d.ts +19 -0
  49. package/dist/repository-http.d.ts.map +1 -0
  50. package/dist/repository-https.d.ts +3 -0
  51. package/dist/repository-https.d.ts.map +1 -0
  52. package/dist/repository-issue-watcher.d.ts +31 -0
  53. package/dist/repository-issue-watcher.d.ts.map +1 -0
  54. package/dist/repository-source-config.d.ts +32 -0
  55. package/dist/repository-source-config.d.ts.map +1 -0
  56. package/dist/repository-types.d.ts +36 -0
  57. package/dist/repository-types.d.ts.map +1 -0
  58. package/dist/review-flow.js +12 -43
  59. package/dist/review-flow.js.map +1 -1
  60. package/dist/runtime-internals.js +18 -2
  61. package/dist/runtime-internals.js.map +1 -1
  62. package/dist/state-helpers.d.ts +2 -0
  63. package/dist/state-helpers.d.ts.map +1 -1
  64. package/dist/subprocess-env.d.ts +1 -0
  65. package/dist/subprocess-env.d.ts.map +1 -1
  66. package/dist/tool-arguments.d.ts +7 -0
  67. package/dist/tool-arguments.d.ts.map +1 -0
  68. package/dist/turn-semantics.d.ts +5 -6
  69. package/dist/turn-semantics.d.ts.map +1 -1
  70. package/dist/types.d.ts +5 -15
  71. package/dist/types.d.ts.map +1 -1
  72. package/package.json +6 -5
  73. package/src/core-capabilities.ts +81 -37
  74. package/src/define-process.ts +190 -313
  75. package/src/extension-api.ts +142 -6
  76. package/src/external-action-source.ts +12 -0
  77. package/src/external-source-poll.ts +49 -0
  78. package/src/flow.ts +332 -664
  79. package/src/fs-utils.ts +17 -2
  80. package/src/index.ts +54 -13
  81. package/src/integration-http.ts +58 -0
  82. package/src/json-data.ts +25 -0
  83. package/src/leaf-outcomes.ts +1 -9
  84. package/src/model-provider.ts +10 -23
  85. package/src/pi-config.ts +1 -6
  86. package/src/process-flow-view.ts +32 -88
  87. package/src/process-graph.ts +25 -51
  88. package/src/process-watcher-source.ts +3 -6
  89. package/src/project-binding.ts +36 -0
  90. package/src/registry-utils.ts +1 -5
  91. package/src/repository-feedback.ts +59 -0
  92. package/src/repository-git-env.ts +34 -0
  93. package/src/repository-http.ts +71 -0
  94. package/src/repository-https.ts +22 -0
  95. package/src/repository-issue-watcher.ts +92 -0
  96. package/src/repository-source-config.ts +60 -0
  97. package/src/repository-types.ts +25 -0
  98. package/src/state-helpers.ts +8 -4
  99. package/src/subprocess-env.ts +6 -0
  100. package/src/tool-arguments.ts +37 -0
  101. package/src/turn-semantics.ts +31 -75
  102. package/src/types.ts +5 -15
  103. package/dist/browser-ui-extension.js +0 -2
  104. package/dist/browser-ui-extension.js.map +0 -1
  105. package/dist/capabilities.js +0 -7
  106. package/dist/capabilities.js.map +0 -1
  107. package/dist/chunk-TRQJ5PRM.js.map +0 -1
  108. package/dist/codecs.js +0 -9
  109. package/dist/codecs.js.map +0 -1
  110. package/dist/commit-message.js +0 -3
  111. package/dist/commit-message.js.map +0 -1
  112. package/dist/core-capabilities.js +0 -6
  113. package/dist/core-capabilities.js.map +0 -1
  114. package/dist/define-process.js +0 -1078
  115. package/dist/define-process.js.map +0 -1
  116. package/dist/event-bus.js +0 -31
  117. package/dist/event-bus.js.map +0 -1
  118. package/dist/extension-api.js +0 -5
  119. package/dist/extension-api.js.map +0 -1
  120. package/dist/flow.js +0 -1645
  121. package/dist/flow.js.map +0 -1
  122. package/dist/form-contract.js +0 -2
  123. package/dist/form-contract.js.map +0 -1
  124. package/dist/fs-utils.js +0 -23
  125. package/dist/fs-utils.js.map +0 -1
  126. package/dist/graph-fragments.js +0 -57
  127. package/dist/graph-fragments.js.map +0 -1
  128. package/dist/host-capabilities.js +0 -42
  129. package/dist/host-capabilities.js.map +0 -1
  130. package/dist/launcher-contract.js +0 -2
  131. package/dist/launcher-contract.js.map +0 -1
  132. package/dist/leaf-outcomes.js +0 -52
  133. package/dist/leaf-outcomes.js.map +0 -1
  134. package/dist/model-provider.js +0 -171
  135. package/dist/model-provider.js.map +0 -1
  136. package/dist/process-definition-internals.js +0 -25
  137. package/dist/process-definition-internals.js.map +0 -1
  138. package/dist/process-flow-view.js +0 -418
  139. package/dist/process-flow-view.js.map +0 -1
  140. package/dist/process-graph.js +0 -212
  141. package/dist/process-graph.js.map +0 -1
  142. package/dist/process-launcher-builder.js +0 -43
  143. package/dist/process-launcher-builder.js.map +0 -1
  144. package/dist/process-watcher-builder.js +0 -40
  145. package/dist/process-watcher-builder.js.map +0 -1
  146. package/dist/process-watcher-source.js +0 -52
  147. package/dist/process-watcher-source.js.map +0 -1
  148. package/dist/registry-utils.js +0 -18
  149. package/dist/registry-utils.js.map +0 -1
  150. package/dist/repository-git-env.js +0 -26
  151. package/dist/repository-git-env.js.map +0 -1
  152. package/dist/server-events.js +0 -2
  153. package/dist/server-events.js.map +0 -1
  154. package/dist/server-process-builder.js +0 -52
  155. package/dist/server-process-builder.js.map +0 -1
  156. package/dist/state-helpers.js +0 -18
  157. package/dist/state-helpers.js.map +0 -1
  158. package/dist/subprocess-env.js +0 -34
  159. package/dist/subprocess-env.js.map +0 -1
  160. package/dist/tool-renderers.js +0 -63
  161. package/dist/tool-renderers.js.map +0 -1
  162. package/dist/turn-semantics.js +0 -365
  163. package/dist/turn-semantics.js.map +0 -1
  164. package/dist/types.js +0 -23
  165. package/dist/types.js.map +0 -1
  166. package/dist/ui-process-builder.js +0 -30
  167. package/dist/ui-process-builder.js.map +0 -1
  168. package/dist/worker-process-builder.js +0 -22
  169. 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,
@@ -62,12 +52,7 @@ type ProcessEmittedEvent = {
62
52
  data: unknown;
63
53
  };
64
54
 
65
- type ProcessQueuedInput = {
66
- source: InputSource;
67
- kind: InputKind;
68
- bodyMarkdown: string;
69
- target?: ProcessInputTarget;
70
- };
55
+ type ProcessQueuedInput = Parameters<ServerProcessContext["queueInput"]>[0];
71
56
 
72
57
  type MaybePromise<T> = T | Promise<T>;
73
58
 
@@ -89,6 +74,12 @@ type NormalizedActionRoute = NormalizedRouteTarget & {
89
74
  export interface ProcessRuntimeTurnContext<TParams = unknown, TState = unknown>
90
75
  extends WorkerProcessContext<TParams, TState> {}
91
76
 
77
+ export interface LlmTurnPreparationContext<TParams = unknown, TState = unknown>
78
+ extends ProcessRuntimeTurnContext<TParams, TState> {
79
+ callIntegrationTool(name: string, args: Record<string, unknown>): Promise<unknown>;
80
+ reportProgress(report: TurnProgressReport): void;
81
+ }
82
+
92
83
  export interface ProcessServerRuntimeContext<TParams = unknown, TState = unknown> {
93
84
  readonly process: ServerProcessContext<TParams, TState>["process"];
94
85
  readonly projects: ServerProcessContext<TParams, TState>["projects"];
@@ -243,9 +234,9 @@ interface ProcessToolOutcomeBaseSpec<TParams = unknown, TState = unknown> {
243
234
  publishedProduct?: string;
244
235
  /** Outcome parameter whose markdown value is captured as the turn result. */
245
236
  turnResultMarkdownParameter?: string;
237
+ /** Outcome parameter containing a concise operator-facing summary. */
238
+ resultSummaryParameter?: string;
246
239
  effect?: ProcessOutcomeEffect<TParams, TState>;
247
- /** Parks the process on this turn after recording the outcome. */
248
- wait?: true;
249
240
  lifecycleIntent?: ProcessOutcomeLifecycleIntent<TParams, TState>;
250
241
  }
251
242
 
@@ -308,8 +299,12 @@ export interface LlmTurnDefinition<
308
299
  availableTools: readonly PiBuiltInToolName[];
309
300
  /** Server-owned integration tools proxied over authenticated worker IPC. */
310
301
  integrationTools?: readonly string[];
302
+ /** Resolve a constrained tool set from validated durable process data at turn start. */
303
+ resolveIntegrationTools?: (params: TParams, state: TState) => readonly string[];
311
304
  /** Opt in to the durable, operator-facing ask_questions custom tool. */
312
305
  askQuestions?: boolean;
306
+ /** Deterministic worker preparation that must complete before Pi is prompted. */
307
+ prepare?(ctx: LlmTurnPreparationContext<TParams, TState>): MaybePromise<unknown>;
313
308
  completionMode?: TurnCompletionMode;
314
309
  branchType: TurnBranchType;
315
310
  context: TurnContextMode;
@@ -347,36 +342,6 @@ export interface AutomaticTurnDefinition<
347
342
  ): Promise<WorkerCompleteInput<TOutcome>> | WorkerCompleteInput<TOutcome>;
348
343
  }
349
344
 
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
-
380
345
  export interface ExternalSourceTransition<
381
346
  TParams = unknown,
382
347
  TState = unknown,
@@ -397,7 +362,6 @@ export interface ExternalTurnDefinition<TParams = unknown, TState = unknown> {
397
362
  export type TurnDefinition<TParams = unknown, TState = unknown> =
398
363
  | LlmTurnDefinition<string, TParams, TState>
399
364
  | AutomaticTurnDefinition<string, TParams, TState>
400
- | ServerAutomaticTurnDefinition<string, TParams, TState>
401
365
  | HumanTurnDefinition<TParams, TState>
402
366
  | ExternalTurnDefinition<TParams, TState>;
403
367
 
@@ -411,28 +375,16 @@ export type ProcessDefinition<TParams = unknown, TState = unknown> = ExtensionPr
411
375
  TState
412
376
  >;
413
377
 
414
- export interface DefinedProcessInput<TParams = unknown, TState = unknown> {
415
- id: string;
416
- displayName: string;
378
+ export interface DefinedProcessInput<TParams = unknown, TState = unknown>
379
+ extends Omit<
380
+ ExtensionProcessDefinition<TParams, TState>,
381
+ "entryTurnId" | "alternateEntryTurnIds" | "turns"
382
+ > {
417
383
  /** Primary entry used when a launch does not select a start turn explicitly. */
418
384
  entry: TurnId;
419
385
  /** Additional entry turns that launchers may select explicitly. */
420
386
  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;
430
387
  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
388
  }
437
389
 
438
390
  type CompiledActionRouting<TParams, TState> =
@@ -454,20 +406,9 @@ type CompiledActionUse<TParams, TState> = {
454
406
  routing: CompiledActionRouting<TParams, TState>;
455
407
  };
456
408
 
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}`);
409
+ interface CompiledOutcomeHandlers<TParams, TState> {
410
+ effects: ReadonlyMap<string, ProcessOutcomeEffect<TParams, TState> | undefined>;
411
+ routings: ReadonlyMap<string, CompiledOutcomeRouting<TParams, TState>>;
471
412
  }
472
413
 
473
414
  function createProcessTurnBinding<TTurn>(
@@ -491,14 +432,13 @@ function normalizeStaticRouteTarget(
491
432
  (target.complete === true ? 1 : 0) +
492
433
  (target.lifecycleStatus !== undefined ? 1 : 0);
493
434
  if (declaredTargetCount !== 1) {
494
- throw createTransitionTargetError(
495
- context,
496
- "must declare exactly one target via 'to', 'complete', or 'lifecycleStatus'",
435
+ throw new Error(
436
+ `${context} must declare exactly one target via 'to', 'complete', or 'lifecycleStatus'`,
497
437
  );
498
438
  }
499
439
  if (target.to !== undefined) {
500
440
  if (knownTurnIds && !knownTurnIds.has(target.to)) {
501
- throw createTransitionTargetError(context, `references unknown turn '${target.to}'`);
441
+ throw new Error(`${context} references unknown turn '${target.to}'`);
502
442
  }
503
443
  return { nextTurnId: target.to };
504
444
  }
@@ -519,9 +459,6 @@ function buildOutcomeTransition<TParams, TState>(
519
459
  `Turn '${turnId}' outcome '${outcome}' must compile state routing before a static transition`,
520
460
  );
521
461
  }
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
462
  if (!hasDeclaredStaticRouteTarget(target)) {
526
463
  return { nextTurnId: turnId };
527
464
  }
@@ -533,35 +470,30 @@ type CompiledOutcomeRouting<TParams, TState> = {
533
470
  choose: ProcessOutcomeBranchSelector<TParams, TState>;
534
471
  };
535
472
 
536
- type CompiledOutcome<TParams, TState> = {
537
- effect?: ProcessOutcomeEffect<TParams, TState>;
538
- routing?: CompiledOutcomeRouting<TParams, TState>;
539
- };
473
+ type BranchRouteSpec = StaticRouteTarget & { trigger?: string };
540
474
 
541
- function normalizeBranchRoutes(input: {
542
- subject: string;
543
- branches: Record<string, ProcessActionBranchSpec>;
475
+ function compileBranchRoutes(input: {
476
+ branches: Record<string, BranchRouteSpec>;
544
477
  knownTurnIds?: ReadonlySet<TurnId>;
478
+ targetContext(branchId: string): string;
479
+ emptyBranchError: string;
480
+ duplicateTriggerError(trigger: string): string;
545
481
  }): {
546
- routes: Readonly<Record<string, NormalizedActionRoute>>;
547
- transitions: readonly NormalizedActionRoute[];
482
+ routes: Record<string, NormalizedActionRoute>;
483
+ transitions: NormalizedActionRoute[];
548
484
  } {
549
- const entries = Object.entries(input.branches);
550
- if (entries.length === 0) throw new Error(`${input.subject} must declare at least one branch`);
551
485
  const routes: Record<string, NormalizedActionRoute> = {};
552
486
  const transitions: NormalizedActionRoute[] = [];
553
487
  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`);
488
+ for (const [branchId, branchSpec] of Object.entries(input.branches)) {
489
+ if (branchId.trim() === "") throw new Error(input.emptyBranchError);
556
490
  const target = normalizeStaticRouteTarget(
557
- `${input.subject} branch '${branchId}'`,
491
+ input.targetContext(branchId),
558
492
  branchSpec,
559
493
  input.knownTurnIds,
560
494
  );
561
495
  const trigger = branchSpec.trigger ?? branchId;
562
- if (usedTriggers.has(trigger)) {
563
- throw new Error(`${input.subject} contains duplicate branch trigger '${trigger}'`);
564
- }
496
+ if (usedTriggers.has(trigger)) throw new Error(input.duplicateTriggerError(trigger));
565
497
  usedTriggers.add(trigger);
566
498
  const route = { ...target, trigger };
567
499
  routes[branchId] = route;
@@ -579,10 +511,20 @@ function resolveOutcomeRouting<TParams, TState>(input: {
579
511
  if (!("branches" in input.spec)) {
580
512
  return null;
581
513
  }
582
- const { routes } = normalizeBranchRoutes({
583
- subject: `Turn '${input.turnId}' outcome '${input.outcome}'`,
514
+ const entries = Object.entries(input.spec.branches);
515
+ if (entries.length === 0) {
516
+ throw new Error(
517
+ `Turn '${input.turnId}' outcome '${input.outcome}' must declare at least one branch`,
518
+ );
519
+ }
520
+ const { routes } = compileBranchRoutes({
584
521
  branches: input.spec.branches,
585
522
  knownTurnIds: input.knownTurnIds,
523
+ targetContext: (branchId) =>
524
+ `Turn '${input.turnId}' outcome '${input.outcome}' branch '${branchId}'`,
525
+ emptyBranchError: `Turn '${input.turnId}' outcome '${input.outcome}' contains an empty branch id`,
526
+ duplicateTriggerError: (trigger) =>
527
+ `Turn '${input.turnId}' outcome '${input.outcome}' contains duplicate branch trigger '${trigger}'`,
586
528
  });
587
529
  return { routes, choose: input.spec.choose };
588
530
  }
@@ -597,13 +539,27 @@ function resolveActionRouting<TParams, TState>(input: {
597
539
  transitions: readonly NormalizedActionRoute[];
598
540
  } {
599
541
  if ("branches" in input.spec) {
600
- const { routes, transitions } = normalizeBranchRoutes({
601
- subject: `Action '${input.actionId}' on turn '${input.turnId}'`,
542
+ const entries = Object.entries(input.spec.branches) as Array<[string, ProcessActionBranchSpec]>;
543
+ if (entries.length === 0) {
544
+ throw new Error(
545
+ `Action '${input.actionId}' on turn '${input.turnId}' must declare at least one branch`,
546
+ );
547
+ }
548
+ const { routes, transitions } = compileBranchRoutes({
602
549
  branches: input.spec.branches,
603
550
  knownTurnIds: input.knownTurnIds,
551
+ targetContext: (branchId) =>
552
+ `Action '${input.actionId}' branch '${branchId}' on turn '${input.turnId}'`,
553
+ emptyBranchError: `Action '${input.actionId}' on turn '${input.turnId}' contains an empty branch id`,
554
+ duplicateTriggerError: (trigger) =>
555
+ `Action '${input.actionId}' on turn '${input.turnId}' contains duplicate branch trigger '${trigger}'`,
604
556
  });
605
557
  return {
606
- routing: { kind: "branches", routes, choose: input.spec.choose },
558
+ routing: {
559
+ kind: "branches",
560
+ routes,
561
+ choose: input.spec.choose,
562
+ },
607
563
  transitions,
608
564
  };
609
565
  }
@@ -626,7 +582,7 @@ function resolveActionRouting<TParams, TState>(input: {
626
582
  };
627
583
  }
628
584
 
629
- function externalSourceTransitionId(input: {
585
+ export function getExternalSourceTransitionId(input: {
630
586
  turnId: TurnId;
631
587
  source: ExternalActionSource;
632
588
  index: number;
@@ -634,11 +590,14 @@ function externalSourceTransitionId(input: {
634
590
  return `${input.turnId}:${input.source.kind}:${input.index}`;
635
591
  }
636
592
 
637
- function externalActionArmingId(input: { turnId: TurnId; externalActionId: string }): string {
593
+ export function getExternalActionArmingId(input: {
594
+ turnId: TurnId;
595
+ externalActionId: string;
596
+ }): string {
638
597
  return `${input.turnId}:${input.externalActionId}`;
639
598
  }
640
599
 
641
- function externalActionTransitionTrigger(input: { externalActionId: string }): string {
600
+ export function getExternalActionTransitionTrigger(input: { externalActionId: string }): string {
642
601
  return `external:${input.externalActionId}`;
643
602
  }
644
603
 
@@ -664,7 +623,7 @@ function compileExternalSourceTransitions<TParams, TState>(input: {
664
623
  return {
665
624
  ...(target.nextTurnId ? { nextTurnId: target.nextTurnId } : {}),
666
625
  ...(target.lifecycleStatus ? { lifecycleStatus: target.lifecycleStatus } : {}),
667
- trigger: externalSourceTransitionId({
626
+ trigger: getExternalSourceTransitionId({
668
627
  turnId: input.turnId,
669
628
  source: transition.source,
670
629
  index,
@@ -673,25 +632,6 @@ function compileExternalSourceTransitions<TParams, TState>(input: {
673
632
  });
674
633
  }
675
634
 
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
635
  function previewMatchesTransition(
696
636
  preview: ProcessActionPreviewDefinition,
697
637
  transition: NormalizedActionRoute,
@@ -815,18 +755,6 @@ function mergeProcessEffectPlans<TState>(
815
755
  };
816
756
  }
817
757
 
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
758
  async function buildSavePlanResultEffect<TParams, TState>(input: {
831
759
  intent: SavePlanResultLifecycleIntent<TParams, TState>;
832
760
  execution: ProcessOutcomeExecution<TParams, TState>;
@@ -873,25 +801,21 @@ function resolveOutcomeEffect<TParams, TState>(input: {
873
801
  spec: ProcessToolOutcomeSpec<TParams, TState> | ProcessTurnEndSpec<TParams, TState, string>;
874
802
  }): ProcessOutcomeEffect<TParams, TState> | undefined {
875
803
  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;
804
+ if (!lifecycleIntent) {
805
+ return input.spec.effect;
806
+ }
878
807
  return async (execution) => {
879
808
  const explicitPlan = input.spec.effect ? await input.spec.effect(execution) : undefined;
880
809
  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
- }
810
+ switch (lifecycleIntent.kind) {
811
+ case "save_plan_result":
812
+ lifecyclePlan = await buildSavePlanResultEffect({
813
+ intent: lifecycleIntent,
814
+ execution,
815
+ });
816
+ break;
890
817
  }
891
- const result = mergeProcessEffectPlans(explicitPlan, lifecyclePlan);
892
- return waits
893
- ? mergeProcessEffectPlans(result, { processPatch: { lifecycleStatus: "waiting" } })
894
- : result;
818
+ return mergeProcessEffectPlans(explicitPlan, lifecyclePlan);
895
819
  };
896
820
  }
897
821
 
@@ -1030,9 +954,8 @@ function compileTurnOutcomeDefinitions<TParams, TState>(input: {
1030
954
  outcomes?: Partial<Record<string, ProcessToolOutcomeSpec<TParams, TState>>>;
1031
955
  turnEnd?: ProcessTurnEndSpec<TParams, TState, string>;
1032
956
  knownTurnIds: ReadonlySet<TurnId>;
1033
- }): {
957
+ }): CompiledOutcomeHandlers<TParams, TState> & {
1034
958
  transitions: readonly ProcessTurnTransition[];
1035
- outcomes: ReadonlyMap<string, CompiledOutcome<TParams, TState>>;
1036
959
  } {
1037
960
  const outcomeEntries = Object.entries(input.outcomes ?? {}) as Array<
1038
961
  [string, ProcessToolOutcomeSpec<TParams, TState>]
@@ -1049,7 +972,8 @@ function compileTurnOutcomeDefinitions<TParams, TState>(input: {
1049
972
  }
1050
973
 
1051
974
  const transitions: ProcessTurnTransition[] = [];
1052
- const outcomes = new Map<string, CompiledOutcome<TParams, TState>>();
975
+ const effects = new Map<string, ProcessOutcomeEffect<TParams, TState> | undefined>();
976
+ const routings = new Map<string, CompiledOutcomeRouting<TParams, TState>>();
1053
977
  for (const [outcome, spec] of outcomeEntries) {
1054
978
  if (outcome.trim() === "") {
1055
979
  throw new Error(`Turn '${input.turnId}' declares an empty outcome id`);
@@ -1064,6 +988,7 @@ function compileTurnOutcomeDefinitions<TParams, TState>(input: {
1064
988
  ? null
1065
989
  : buildOutcomeTransition(input.turnId, outcome, spec, input.knownTurnIds);
1066
990
  if (routing) {
991
+ routings.set(outcome, routing);
1067
992
  for (const route of Object.values(routing.routes)) {
1068
993
  transitions.push({
1069
994
  ...(route.nextTurnId ? { nextTurnId: route.nextTurnId } : {}),
@@ -1079,10 +1004,7 @@ function compileTurnOutcomeDefinitions<TParams, TState>(input: {
1079
1004
  outcome,
1080
1005
  });
1081
1006
  }
1082
- outcomes.set(outcome, {
1083
- effect: resolveOutcomeEffect({ spec }),
1084
- ...(routing ? { routing } : {}),
1085
- });
1007
+ effects.set(outcome, resolveOutcomeEffect({ spec }));
1086
1008
  }
1087
1009
 
1088
1010
  if (input.turnEnd) {
@@ -1100,12 +1022,14 @@ function compileTurnOutcomeDefinitions<TParams, TState>(input: {
1100
1022
  ...(target.lifecycleStatus ? { lifecycleStatus: target.lifecycleStatus } : {}),
1101
1023
  outcome: input.turnEnd.outcome,
1102
1024
  });
1103
- outcomes.set(input.turnEnd.outcome, {
1104
- effect: resolveOutcomeEffect({ spec: input.turnEnd }),
1105
- });
1025
+ effects.set(input.turnEnd.outcome, resolveOutcomeEffect({ spec: input.turnEnd }));
1106
1026
  }
1107
1027
 
1108
- return { transitions, outcomes };
1028
+ return {
1029
+ transitions,
1030
+ effects,
1031
+ routings,
1032
+ };
1109
1033
  }
1110
1034
 
1111
1035
  function addActionUse<TParams, TState>(input: {
@@ -1172,7 +1096,7 @@ function resolveExternalActionRoute<TParams, TState>(input: {
1172
1096
  return {
1173
1097
  ...(target.nextTurnId ? { nextTurnId: target.nextTurnId } : {}),
1174
1098
  ...(target.lifecycleStatus ? { lifecycleStatus: target.lifecycleStatus } : {}),
1175
- trigger: externalActionTransitionTrigger({ externalActionId: input.externalActionId }),
1099
+ trigger: getExternalActionTransitionTrigger({ externalActionId: input.externalActionId }),
1176
1100
  };
1177
1101
  }
1178
1102
 
@@ -1235,73 +1159,12 @@ function validateActionPrimaryPrompt(
1235
1159
  }
1236
1160
  }
1237
1161
 
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
1162
  function deriveHumanTurnActions<TParams, TState>(input: {
1301
1163
  turnId: TurnId;
1302
1164
  spec: HumanTurnDefinition<TParams, TState>;
1303
1165
  knownTurnIds?: ReadonlySet<TurnId>;
1304
1166
  turnDefinitionsById?: ReadonlyMap<TurnId, TurnDefinition<unknown, unknown>>;
1167
+ requireHumanActions?: boolean;
1305
1168
  }): {
1306
1169
  actions: readonly DerivedHumanTurnAction<TParams, TState>[];
1307
1170
  externalActions: readonly DerivedHumanTurnExternalAction<TParams, TState>[];
@@ -1310,7 +1173,7 @@ function deriveHumanTurnActions<TParams, TState>(input: {
1310
1173
  const actionEntries = Object.entries(input.spec.actions) as Array<
1311
1174
  [string, ProcessHumanTurnActionSpec<TParams, TState>]
1312
1175
  >;
1313
- if (actionEntries.length === 0 && input.knownTurnIds) {
1176
+ if (actionEntries.length === 0 && input.knownTurnIds && input.requireHumanActions !== false) {
1314
1177
  throw new Error(`Human turn '${input.turnId}' must declare at least one action`);
1315
1178
  }
1316
1179
 
@@ -1384,17 +1247,68 @@ function deriveHumanTurnActions<TParams, TState>(input: {
1384
1247
  });
1385
1248
  }
1386
1249
 
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
- });
1250
+ const externalActionEntries = Object.entries(input.spec.externalActions ?? {}) as Array<
1251
+ [string, ProcessHumanTurnExternalActionSpec<TParams, TState>]
1252
+ >;
1253
+ const derivedExternalActions: DerivedHumanTurnExternalAction<TParams, TState>[] = [];
1254
+ const externalActionIds = new Set<string>();
1255
+ for (const [externalActionId, actionSpec] of externalActionEntries) {
1256
+ if (externalActionIds.has(externalActionId)) {
1257
+ throw new Error(
1258
+ `Human turn '${input.turnId}' declares duplicate external action '${externalActionId}'`,
1259
+ );
1260
+ }
1261
+ externalActionIds.add(externalActionId);
1262
+ if (actionSpec.publishInput) {
1263
+ assertValidProcessProductName(actionSpec.publishInput.productName);
1264
+ if (actionSpec.publishInput.inputField.trim() === "") {
1265
+ throw new Error(
1266
+ `Human turn '${input.turnId}' external action '${externalActionId}' publishInput must declare a non-empty inputField`,
1267
+ );
1268
+ }
1269
+ }
1270
+ validateExternalActionPublishedInputTarget({
1271
+ turnId: input.turnId,
1272
+ externalActionId,
1273
+ spec: actionSpec,
1274
+ turnDefinitionsById: input.turnDefinitionsById,
1275
+ });
1276
+ const transition = resolveExternalActionRoute({
1277
+ turnId: input.turnId,
1278
+ externalActionId,
1279
+ spec: actionSpec,
1280
+ knownTurnIds: input.knownTurnIds,
1281
+ });
1282
+ const existingActionId = actionIdByTrigger.get(transition.trigger);
1283
+ if (existingActionId) {
1284
+ throw new Error(
1285
+ `Human turn '${input.turnId}' contains duplicate trigger '${transition.trigger}' across action '${existingActionId}' and external action '${externalActionId}'`,
1286
+ );
1287
+ }
1288
+ actionIdByTrigger.set(transition.trigger, externalActionId);
1289
+ transitions.push({
1290
+ ...(transition.nextTurnId ? { nextTurnId: transition.nextTurnId } : {}),
1291
+ ...(transition.lifecycleStatus ? { lifecycleStatus: transition.lifecycleStatus } : {}),
1292
+ trigger: transition.trigger,
1293
+ });
1294
+ derivedExternalActions.push({
1295
+ externalActionId,
1296
+ actionSpec,
1297
+ transition,
1298
+ view: {
1299
+ id: getExternalActionArmingId({ turnId: input.turnId, externalActionId }),
1300
+ externalActionId,
1301
+ sourceKind: actionSpec.source.kind,
1302
+ label: actionSpec.label ?? actionSpec.source.label ?? null,
1303
+ description: actionSpec.description ?? actionSpec.source.description ?? null,
1304
+ },
1305
+ });
1306
+ }
1307
+
1394
1308
  return {
1395
1309
  actions: derivedActions,
1396
- externalActions: derivedExternal.externalActions,
1397
- transitions: [...transitions, ...derivedExternal.transitions],
1310
+ externalActions: derivedExternalActions,
1311
+ transitions,
1398
1312
  };
1399
1313
  }
1400
1314
 
@@ -1468,12 +1382,6 @@ function compileExternalTurn<TParams, TState>(input: {
1468
1382
  };
1469
1383
  }
1470
1384
 
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
1385
  function resolveActionRouteForExecution<TParams, TState>(input: {
1478
1386
  use: CompiledActionUse<TParams, TState>;
1479
1387
  actionId: string;
@@ -1573,7 +1481,7 @@ function validateHappyPathConnectivity<TParams, TState>(input: {
1573
1481
  function buildDefinedProcess<TParams, TState>(
1574
1482
  input: DefinedProcessInput<TParams, TState>,
1575
1483
  ): Pick<ExtensionProcessDefinition<TParams, TState>, "turns" | "worker" | "server"> {
1576
- const turnEntries = getTurnEntries(input.turns);
1484
+ const turnEntries = Object.entries(input.turns);
1577
1485
  if (turnEntries.length === 0) {
1578
1486
  throw new Error(`Process '${input.id}' must declare at least one turn`);
1579
1487
  }
@@ -1618,61 +1526,41 @@ function buildDefinedProcess<TParams, TState>(
1618
1526
 
1619
1527
  const turns = new Map<TurnId, ProcessTurnBinding<TurnDefinition<TParams, TState>>>();
1620
1528
  const actionUses = new Map<string, CompiledActionUse<TParams, TState>[]>();
1621
- const compiledOutcomesByTurn = new Map<
1529
+ const executableTurns = new Map<
1622
1530
  TurnId,
1623
- ReadonlyMap<string, CompiledOutcome<TParams, TState>>
1531
+ CompiledOutcomeHandlers<TParams, TState> & {
1532
+ spec: RoutableTurnDefinition<string, TParams, TState>;
1533
+ }
1624
1534
  >();
1625
- const executableTurns = new Map<TurnId, CompiledExecutableTurn<TParams, TState>>();
1626
1535
 
1627
1536
  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({
1537
+ if (turnSpec.kind === "llm" || turnSpec.kind === "automatic") {
1538
+ const { transitions, effects, routings } = compileTurnOutcomeDefinitions({
1647
1539
  turnId,
1648
1540
  outcomes: turnSpec.outcomes,
1649
1541
  turnEnd: turnSpec.turnEnd,
1650
1542
  knownTurnIds,
1651
1543
  });
1652
1544
  const externalTransitions =
1653
- turnSpec.kind === "automatic"
1654
- ? deriveExternalActions({
1545
+ turnSpec.kind === "automatic" && turnSpec.externalActions
1546
+ ? deriveHumanTurnActions({
1655
1547
  turnId,
1656
- externalActions: turnSpec.externalActions,
1548
+ spec: {
1549
+ kind: "human",
1550
+ description: turnSpec.description,
1551
+ actions: {},
1552
+ externalActions: turnSpec.externalActions,
1553
+ },
1657
1554
  knownTurnIds,
1658
1555
  turnDefinitionsById,
1556
+ requireHumanActions: false,
1659
1557
  }).transitions
1660
1558
  : [];
1661
1559
  turns.set(
1662
1560
  turnId,
1663
- createProcessTurnBinding(turnSpec, [
1664
- ...compiledOutcomes.transitions,
1665
- ...externalTransitions,
1666
- ]),
1561
+ createProcessTurnBinding(turnSpec, [...transitions, ...externalTransitions]),
1667
1562
  );
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
- }
1563
+ executableTurns.set(turnId, { spec: turnSpec, effects, routings });
1676
1564
  continue;
1677
1565
  }
1678
1566
 
@@ -1715,18 +1603,18 @@ function buildDefinedProcess<TParams, TState>(
1715
1603
  api.turn(turnId, handler);
1716
1604
  },
1717
1605
  });
1718
- for (const executable of executableTurns.values()) {
1719
- if (manuallyRegisteredTurns.has(executable.id)) {
1606
+ for (const [turnId, { spec }] of executableTurns) {
1607
+ if (manuallyRegisteredTurns.has(turnId)) {
1720
1608
  continue;
1721
1609
  }
1722
- if (executable.kind === "llm") {
1723
- api.turn(executable.id, async (run) => {
1724
- await run.turn(executable.spec);
1610
+ if (spec.kind === "llm") {
1611
+ api.turn(turnId, async (run) => {
1612
+ await run.turn(spec);
1725
1613
  });
1726
1614
  continue;
1727
1615
  }
1728
- api.turn(executable.id, async (run) => {
1729
- await run.complete(await executable.spec.run(run.ctx));
1616
+ api.turn(turnId, async (run) => {
1617
+ await run.complete(await spec.run(run.ctx));
1730
1618
  });
1731
1619
  }
1732
1620
  };
@@ -1788,9 +1676,10 @@ function buildDefinedProcess<TParams, TState>(
1788
1676
  });
1789
1677
  }
1790
1678
 
1791
- for (const [turnId, outcomes] of compiledOutcomesByTurn) {
1679
+ for (const [turnId, { effects, routings }] of executableTurns) {
1792
1680
  api.onTurnOutcome(turnId, async (event, ctx) => {
1793
- const { effect, routing } = outcomes.get(event.outcome) ?? {};
1681
+ const effect = effects.get(event.outcome);
1682
+ const routing = routings.get(event.outcome);
1794
1683
  if (!effect && !routing) {
1795
1684
  return;
1796
1685
  }
@@ -1840,6 +1729,8 @@ export function defineProcess<TParams = unknown, TState = unknown>(
1840
1729
  paramsCodec: input.paramsCodec,
1841
1730
  stateCodec: input.stateCodec,
1842
1731
  initialState: input.initialState,
1732
+ ...(input.runtime ? { runtime: { ...input.runtime } } : {}),
1733
+ ...(input.resolveStorageSize ? { resolveStorageSize: input.resolveStorageSize } : {}),
1843
1734
  ...(input.repositoryCredentials ? { repositoryCredentials: input.repositoryCredentials } : {}),
1844
1735
  ...(input.piConfig ? { piConfig: input.piConfig } : {}),
1845
1736
  server: compiled.server,
@@ -1854,8 +1745,7 @@ export function defineProcess<TParams = unknown, TState = unknown>(
1854
1745
 
1855
1746
  type RoutableTurnDefinition<TOutcome extends string, TParams, TState> =
1856
1747
  | LlmTurnDefinition<TOutcome, TParams, TState>
1857
- | AutomaticTurnDefinition<TOutcome, TParams, TState>
1858
- | ServerAutomaticTurnDefinition<TOutcome, TParams, TState>;
1748
+ | AutomaticTurnDefinition<TOutcome, TParams, TState>;
1859
1749
 
1860
1750
  // biome-ignore-start lint/suspicious/noExplicitAny: conditional helper types must match and preserve any routable turn instantiation
1861
1751
  type RoutableOutcome<TTurn> =
@@ -1926,19 +1816,6 @@ export function automaticTurn<
1926
1816
  };
1927
1817
  }
1928
1818
 
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
-
1942
1819
  export function humanTurn<TParams = unknown, TState = unknown>(
1943
1820
  input: Omit<HumanTurnDefinition<TParams, TState>, "kind">,
1944
1821
  ): HumanTurnDefinition<TParams, TState> {