@leitwerk-dev/process-sdk 0.1.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 (199) hide show
  1. package/dist/LICENSE +13 -0
  2. package/dist/browser-ui-extension.d.ts +27 -0
  3. package/dist/browser-ui-extension.d.ts.map +1 -0
  4. package/dist/browser-ui-extension.js +2 -0
  5. package/dist/browser-ui-extension.js.map +1 -0
  6. package/dist/capabilities.d.ts +9 -0
  7. package/dist/capabilities.d.ts.map +1 -0
  8. package/dist/capabilities.js +7 -0
  9. package/dist/capabilities.js.map +1 -0
  10. package/dist/chunk-5RJZ2E7D.js +58 -0
  11. package/dist/chunk-5RJZ2E7D.js.map +1 -0
  12. package/dist/chunk-ITPH65G6.js +197 -0
  13. package/dist/chunk-ITPH65G6.js.map +1 -0
  14. package/dist/chunk-LIIP7FMU.js +48 -0
  15. package/dist/chunk-LIIP7FMU.js.map +1 -0
  16. package/dist/codecs.d.ts +3 -0
  17. package/dist/codecs.d.ts.map +1 -0
  18. package/dist/codecs.js +9 -0
  19. package/dist/codecs.js.map +1 -0
  20. package/dist/commit-message.d.ts +7 -0
  21. package/dist/commit-message.d.ts.map +1 -0
  22. package/dist/commit-message.js +3 -0
  23. package/dist/commit-message.js.map +1 -0
  24. package/dist/core-capabilities.d.ts +393 -0
  25. package/dist/core-capabilities.d.ts.map +1 -0
  26. package/dist/core-capabilities.js +6 -0
  27. package/dist/core-capabilities.js.map +1 -0
  28. package/dist/define-process.d.ts +269 -0
  29. package/dist/define-process.d.ts.map +1 -0
  30. package/dist/define-process.js +1040 -0
  31. package/dist/define-process.js.map +1 -0
  32. package/dist/event-bus.d.ts +3 -0
  33. package/dist/event-bus.d.ts.map +1 -0
  34. package/dist/event-bus.js +31 -0
  35. package/dist/event-bus.js.map +1 -0
  36. package/dist/extension-api-CnlL69Tu.d.ts +1281 -0
  37. package/dist/extension-api.d.ts +425 -0
  38. package/dist/extension-api.d.ts.map +1 -0
  39. package/dist/extension-api.js +5 -0
  40. package/dist/extension-api.js.map +1 -0
  41. package/dist/flow.d.ts +456 -0
  42. package/dist/flow.d.ts.map +1 -0
  43. package/dist/flow.js +1557 -0
  44. package/dist/flow.js.map +1 -0
  45. package/dist/form-contract.d.ts +2 -0
  46. package/dist/form-contract.d.ts.map +1 -0
  47. package/dist/form-contract.js +2 -0
  48. package/dist/form-contract.js.map +1 -0
  49. package/dist/fs-utils.d.ts +3 -0
  50. package/dist/fs-utils.d.ts.map +1 -0
  51. package/dist/fs-utils.js +23 -0
  52. package/dist/fs-utils.js.map +1 -0
  53. package/dist/git-binary.d.ts +11 -0
  54. package/dist/git-binary.d.ts.map +1 -0
  55. package/dist/git-binary.js +38 -0
  56. package/dist/git-binary.js.map +1 -0
  57. package/dist/graph-fragments.d.ts +23 -0
  58. package/dist/graph-fragments.d.ts.map +1 -0
  59. package/dist/graph-fragments.js +57 -0
  60. package/dist/graph-fragments.js.map +1 -0
  61. package/dist/host-capabilities.d.ts +12 -0
  62. package/dist/host-capabilities.d.ts.map +1 -0
  63. package/dist/host-capabilities.js +42 -0
  64. package/dist/host-capabilities.js.map +1 -0
  65. package/dist/index.d.ts +35 -0
  66. package/dist/index.d.ts.map +1 -0
  67. package/dist/index.js +29 -0
  68. package/dist/index.js.map +1 -0
  69. package/dist/launcher-contract.d.ts +2 -0
  70. package/dist/launcher-contract.d.ts.map +1 -0
  71. package/dist/launcher-contract.js +2 -0
  72. package/dist/launcher-contract.js.map +1 -0
  73. package/dist/leaf-outcome-renderer.d.ts +48 -0
  74. package/dist/leaf-outcome-renderer.d.ts.map +1 -0
  75. package/dist/leaf-outcome-renderer.js +69 -0
  76. package/dist/leaf-outcome-renderer.js.map +1 -0
  77. package/dist/leaf-outcomes.d.ts +5 -0
  78. package/dist/leaf-outcomes.d.ts.map +1 -0
  79. package/dist/leaf-outcomes.js +52 -0
  80. package/dist/leaf-outcomes.js.map +1 -0
  81. package/dist/model-provider.d.ts +210 -0
  82. package/dist/model-provider.d.ts.map +1 -0
  83. package/dist/model-provider.js +171 -0
  84. package/dist/model-provider.js.map +1 -0
  85. package/dist/pi-config.d.ts +59 -0
  86. package/dist/pi-config.d.ts.map +1 -0
  87. package/dist/pi-config.js +182 -0
  88. package/dist/pi-config.js.map +1 -0
  89. package/dist/process-definition-internals.d.ts +7 -0
  90. package/dist/process-definition-internals.d.ts.map +1 -0
  91. package/dist/process-definition-internals.js +25 -0
  92. package/dist/process-definition-internals.js.map +1 -0
  93. package/dist/process-flow-view.d.ts +20 -0
  94. package/dist/process-flow-view.d.ts.map +1 -0
  95. package/dist/process-flow-view.js +418 -0
  96. package/dist/process-flow-view.js.map +1 -0
  97. package/dist/process-graph.d.ts +45 -0
  98. package/dist/process-graph.d.ts.map +1 -0
  99. package/dist/process-graph.js +213 -0
  100. package/dist/process-graph.js.map +1 -0
  101. package/dist/process-launcher-builder.d.ts +9 -0
  102. package/dist/process-launcher-builder.d.ts.map +1 -0
  103. package/dist/process-launcher-builder.js +43 -0
  104. package/dist/process-launcher-builder.js.map +1 -0
  105. package/dist/process-watcher-builder.d.ts +10 -0
  106. package/dist/process-watcher-builder.d.ts.map +1 -0
  107. package/dist/process-watcher-builder.js +40 -0
  108. package/dist/process-watcher-builder.js.map +1 -0
  109. package/dist/registry-utils.d.ts +8 -0
  110. package/dist/registry-utils.d.ts.map +1 -0
  111. package/dist/registry-utils.js +18 -0
  112. package/dist/registry-utils.js.map +1 -0
  113. package/dist/repository-git-env.d.ts +8 -0
  114. package/dist/repository-git-env.d.ts.map +1 -0
  115. package/dist/repository-git-env.js +26 -0
  116. package/dist/repository-git-env.js.map +1 -0
  117. package/dist/review-flow.d.ts +10 -0
  118. package/dist/review-flow.d.ts.map +1 -0
  119. package/dist/review-flow.js +44 -0
  120. package/dist/review-flow.js.map +1 -0
  121. package/dist/runtime-internals.d.ts +3 -0
  122. package/dist/runtime-internals.d.ts.map +1 -0
  123. package/dist/runtime-internals.js +3 -0
  124. package/dist/runtime-internals.js.map +1 -0
  125. package/dist/server-events.d.ts +84 -0
  126. package/dist/server-events.d.ts.map +1 -0
  127. package/dist/server-events.js +2 -0
  128. package/dist/server-events.js.map +1 -0
  129. package/dist/server-process-builder.d.ts +11 -0
  130. package/dist/server-process-builder.d.ts.map +1 -0
  131. package/dist/server-process-builder.js +52 -0
  132. package/dist/server-process-builder.js.map +1 -0
  133. package/dist/state-helpers.d.ts +9 -0
  134. package/dist/state-helpers.d.ts.map +1 -0
  135. package/dist/state-helpers.js +20 -0
  136. package/dist/state-helpers.js.map +1 -0
  137. package/dist/subprocess-env.d.ts +12 -0
  138. package/dist/subprocess-env.d.ts.map +1 -0
  139. package/dist/subprocess-env.js +34 -0
  140. package/dist/subprocess-env.js.map +1 -0
  141. package/dist/tool-renderers.d.ts +10 -0
  142. package/dist/tool-renderers.d.ts.map +1 -0
  143. package/dist/tool-renderers.js +63 -0
  144. package/dist/tool-renderers.js.map +1 -0
  145. package/dist/turn-semantics.d.ts +22 -0
  146. package/dist/turn-semantics.d.ts.map +1 -0
  147. package/dist/turn-semantics.js +339 -0
  148. package/dist/turn-semantics.js.map +1 -0
  149. package/dist/types.d.ts +295 -0
  150. package/dist/types.d.ts.map +1 -0
  151. package/dist/types.js +12 -0
  152. package/dist/types.js.map +1 -0
  153. package/dist/ui-process-builder.d.ts +9 -0
  154. package/dist/ui-process-builder.d.ts.map +1 -0
  155. package/dist/ui-process-builder.js +30 -0
  156. package/dist/ui-process-builder.js.map +1 -0
  157. package/dist/worker-process-builder.d.ts +10 -0
  158. package/dist/worker-process-builder.d.ts.map +1 -0
  159. package/dist/worker-process-builder.js +22 -0
  160. package/dist/worker-process-builder.js.map +1 -0
  161. package/package.json +72 -0
  162. package/src/browser-ui-extension.ts +32 -0
  163. package/src/capabilities.ts +16 -0
  164. package/src/codecs.ts +10 -0
  165. package/src/commit-message.ts +9 -0
  166. package/src/core-capabilities.ts +526 -0
  167. package/src/define-process.ts +1879 -0
  168. package/src/event-bus.ts +35 -0
  169. package/src/extension-api.ts +600 -0
  170. package/src/flow.ts +2268 -0
  171. package/src/form-contract.ts +11 -0
  172. package/src/fs-utils.ts +28 -0
  173. package/src/git-binary.ts +40 -0
  174. package/src/graph-fragments.ts +110 -0
  175. package/src/host-capabilities.ts +60 -0
  176. package/src/index.ts +468 -0
  177. package/src/launcher-contract.ts +8 -0
  178. package/src/leaf-outcome-renderer.ts +112 -0
  179. package/src/leaf-outcomes.ts +74 -0
  180. package/src/model-provider.ts +461 -0
  181. package/src/pi-config.ts +268 -0
  182. package/src/process-definition-internals.ts +46 -0
  183. package/src/process-flow-view.ts +479 -0
  184. package/src/process-graph.ts +309 -0
  185. package/src/process-launcher-builder.ts +59 -0
  186. package/src/process-watcher-builder.ts +72 -0
  187. package/src/registry-utils.ts +31 -0
  188. package/src/repository-git-env.ts +35 -0
  189. package/src/review-flow.ts +66 -0
  190. package/src/runtime-internals.ts +7 -0
  191. package/src/server-events.ts +105 -0
  192. package/src/server-process-builder.ts +90 -0
  193. package/src/state-helpers.ts +36 -0
  194. package/src/subprocess-env.ts +48 -0
  195. package/src/tool-renderers.ts +92 -0
  196. package/src/turn-semantics.ts +554 -0
  197. package/src/types.ts +391 -0
  198. package/src/ui-process-builder.ts +46 -0
  199. package/src/worker-process-builder.ts +33 -0
package/src/types.ts ADDED
@@ -0,0 +1,391 @@
1
+ import type {
2
+ ProcessSemanticEntryRefKey as DomainProcessSemanticEntryRefKey,
3
+ TurnAcceptanceState as DomainTurnAcceptanceState,
4
+ ProcessInstance,
5
+ ProcessProject,
6
+ ProcessTurnRecordPathType,
7
+ ProcessTurnTerminalLifecycleStatus,
8
+ TurnId,
9
+ } from "@leitwerk-dev/domain";
10
+
11
+ export interface ProcessContext {
12
+ readonly process: ProcessInstance;
13
+ readonly selectedTurnId: TurnId | null;
14
+ readonly isTerminal: boolean;
15
+ readonly projects: readonly ProcessProject[];
16
+ selectTurn(turnId: TurnId | null): void;
17
+ }
18
+
19
+ export interface TurnOptions {
20
+ reset?: boolean;
21
+ }
22
+
23
+ export interface TurnResult<T extends string = string> {
24
+ outcome: T;
25
+ params: Record<string, unknown>;
26
+ }
27
+
28
+ export const PI_BUILT_IN_TOOL_NAMES = [
29
+ "read",
30
+ "bash",
31
+ "edit",
32
+ "write",
33
+ "grep",
34
+ "find",
35
+ "ls",
36
+ ] as const;
37
+ export type PiBuiltInToolName = (typeof PI_BUILT_IN_TOOL_NAMES)[number];
38
+
39
+ export interface ProcessPiConfig {
40
+ /**
41
+ * System prompt template. Rendered with Mustache against runtime context.
42
+ * Use {{variableName}} for escaped values and {{{variableName}}} for raw values.
43
+ * When omitted, Pi's default system prompt is used.
44
+ */
45
+ systemPromptTemplate?: string;
46
+ /**
47
+ * Additional text appended after the base system prompt/resources. Rendered
48
+ * with Mustache against runtime context.
49
+ */
50
+ appendSystemPromptTemplate?: string;
51
+ /**
52
+ * Code-defined Pi session working directory template. Rendered with Mustache
53
+ * against runtime context. When omitted, the process workspace root is used.
54
+ */
55
+ sessionCwdTemplate?: string;
56
+ }
57
+
58
+ export interface ResolvedProcessPiConfig {
59
+ systemPrompt?: string;
60
+ appendSystemPrompt?: string;
61
+ sessionCwd?: string;
62
+ availableToolNames: string[];
63
+ }
64
+
65
+ export type OutcomeToolParameterType = "string" | "number" | "array" | "boolean" | "object";
66
+ export type OutcomeToolArrayItemType = Exclude<OutcomeToolParameterType, "array">;
67
+
68
+ export interface OutcomeToolArrayItemSpec {
69
+ type: OutcomeToolArrayItemType;
70
+ description?: string;
71
+ }
72
+
73
+ export interface OutcomeToolParameterSpec {
74
+ type: OutcomeToolParameterType;
75
+ description: string;
76
+ required?: boolean;
77
+ requiredErrorCode?: string;
78
+ invalidErrorCode?: string;
79
+ minItems?: number;
80
+ minItemsErrorCode?: string;
81
+ minimum?: number;
82
+ minimumErrorCode?: string;
83
+ items?: OutcomeToolArrayItemSpec;
84
+ enum?: readonly string[];
85
+ }
86
+
87
+ export interface OutcomeToolSpec {
88
+ description: string;
89
+ parameters: Record<string, OutcomeToolParameterSpec>;
90
+ /** Product published from this outcome's turn-result markdown, when selected. */
91
+ publishedProduct?: string;
92
+ /** Outcome parameter whose markdown value is captured as the turn result. */
93
+ turnResultMarkdownParameter?: string;
94
+ }
95
+
96
+ export interface ProcessToolResult {
97
+ status: string;
98
+ outcome?: string;
99
+ }
100
+
101
+ export interface PiTreeEntry {
102
+ readonly id: string;
103
+ readonly parentId: string | null;
104
+ readonly type: string;
105
+ readonly timestamp: string;
106
+ readonly message?: {
107
+ readonly role?: string;
108
+ readonly content?: unknown;
109
+ };
110
+ /** Pi custom-message fields. Details are intentionally excluded from model context. */
111
+ readonly customType?: string;
112
+ readonly content?: unknown;
113
+ readonly details?: unknown;
114
+ readonly targetId?: string;
115
+ readonly label?: string;
116
+ }
117
+
118
+ export interface PiTreeNode {
119
+ readonly entry: PiTreeEntry;
120
+ readonly children: readonly PiTreeNode[];
121
+ readonly label?: string;
122
+ readonly labelTimestamp?: string;
123
+ }
124
+
125
+ export interface PiTurnExecutionResult {
126
+ startLeafId: string | null;
127
+ endLeafId: string | null;
128
+ createdEntryIds: string[];
129
+ resultEntryId: string;
130
+ /** Final assistant markdown captured from the Pi assistant message for this turn, when available. */
131
+ assistantMarkdown?: string | null;
132
+ }
133
+
134
+ export type PiEventType =
135
+ | "turn.start"
136
+ | "turn.end"
137
+ | "stream.delta"
138
+ | "tool.call"
139
+ | "tool.update"
140
+ | "tool.result"
141
+ | "toolcall.start"
142
+ | "toolcall.delta"
143
+ | "toolcall.end"
144
+ | "compaction.start"
145
+ | "compaction.end"
146
+ | "label.changed"
147
+ | "error"
148
+ | "retry.start"
149
+ | "retry.end"
150
+ | "usage";
151
+
152
+ export interface PiEvent {
153
+ type: PiEventType;
154
+ turnId: string;
155
+ data: Record<string, unknown>;
156
+ timestamp: string;
157
+ }
158
+
159
+ export type PiEventHandler = (event: PiEvent) => void;
160
+
161
+ export type PiSessionDiagnosticLevel = "debug" | "info" | "warn" | "error";
162
+
163
+ export interface PiSessionDiagnostic {
164
+ level: PiSessionDiagnosticLevel;
165
+ code: string;
166
+ message: string;
167
+ timestamp: string;
168
+ turnId?: string;
169
+ details?: Record<string, unknown>;
170
+ }
171
+
172
+ export type PiSessionDiagnosticHandler = (diagnostic: PiSessionDiagnostic) => void;
173
+
174
+ export interface PiCustomToolExecutionContext {
175
+ /** Pi's identity for this exact invocation; stable across the paused call. */
176
+ toolCallId: string;
177
+ /** Aborted when the active turn is stopped or torn down. */
178
+ signal: AbortSignal;
179
+ /** Pause model-execution budgets while this custom tool awaits durable operator input. */
180
+ suspendPromptGuards?: () => () => void;
181
+ }
182
+
183
+ export interface PiCustomTool {
184
+ name: string;
185
+ description: string;
186
+ parameters: Record<string, unknown>;
187
+ executionMode?: "sequential" | "parallel";
188
+ execute(args: Record<string, unknown>, context?: PiCustomToolExecutionContext): Promise<unknown>;
189
+ }
190
+
191
+ export interface PiUsageData {
192
+ input: number;
193
+ output: number;
194
+ /** Provider-reported reasoning/thinking tokens. This is a subset of output tokens. */
195
+ reasoning?: number;
196
+ cacheRead: number;
197
+ cacheWrite: number;
198
+ totalTokens: number;
199
+ cost: {
200
+ input: number;
201
+ output: number;
202
+ cacheRead: number;
203
+ cacheWrite: number;
204
+ total: number;
205
+ };
206
+ cacheHitRate: number;
207
+ }
208
+
209
+ export interface PiRunDetails {
210
+ loadedAgentsFiles: Array<{ path: string; sizeBytes: number }>;
211
+ loadedSkills: Array<{ name: string; path: string }>;
212
+ availableToolNames: string[];
213
+ }
214
+
215
+ export type ProcessCustomTool = PiCustomTool;
216
+
217
+ export interface PiCustomMessageInput {
218
+ content: string;
219
+ details: unknown;
220
+ display?: boolean;
221
+ }
222
+
223
+ export type PiTerminalAcknowledgementState =
224
+ | "open"
225
+ | "outcome_accepted"
226
+ | "acknowledgement_succeeded"
227
+ | "acknowledgement_failed_ignored";
228
+
229
+ export interface PiTerminalAcknowledgementControl {
230
+ readonly timeoutMs: number;
231
+ state(): PiTerminalAcknowledgementState;
232
+ isOperatorAbortRequested(): boolean;
233
+ markSucceeded(): void;
234
+ markFailed(reason: string): void;
235
+ }
236
+
237
+ export interface PiPromptOptions {
238
+ tools?: readonly PiCustomTool[];
239
+ activeTools?: readonly string[];
240
+ /** @internal Runtime-only hook used by the worker Pi adapter before a tool executes. */
241
+ shouldBlockToolCall?: (toolName: string) => string | null;
242
+ /** @internal Guard suspension used by durable interactive tools. */
243
+ suspendPromptGuards?: () => () => void;
244
+ /** @internal Runtime-only terminal outcome acknowledgement state. */
245
+ terminalAcknowledgement?: PiTerminalAcknowledgementControl;
246
+ }
247
+
248
+ export interface PiTreeHandle {
249
+ readonly sessionId: string;
250
+ readonly treeFile: string;
251
+ readonly isResumed: boolean;
252
+
253
+ getRunDetails(): PiRunDetails;
254
+ getLeafId(): string | null;
255
+ getEntry(id: string): PiTreeEntry | undefined;
256
+ getBranch(fromId?: string): PiTreeEntry[];
257
+ getChildren(parentId: string): PiTreeEntry[];
258
+ getTree(): PiTreeNode[];
259
+ branch(entryId: string): void | Promise<void>;
260
+ branchFromRoot(): void | Promise<void>;
261
+ resetLeaf(): void | Promise<void>;
262
+ /**
263
+ * Compact the current Pi context. `details` is persisted with the resulting
264
+ * compaction entry, but deliberately remains outside model context.
265
+ */
266
+ compact?(customInstructions?: string, details?: unknown): Promise<unknown>;
267
+ prompt(text: string, options?: PiPromptOptions): Promise<PiTurnExecutionResult>;
268
+ promptLiteral(text: string, options?: PiPromptOptions): Promise<PiTurnExecutionResult>;
269
+ promptCustom(
270
+ input: PiCustomMessageInput,
271
+ options?: PiPromptOptions,
272
+ ): Promise<PiTurnExecutionResult>;
273
+ continueTurn(options?: PiPromptOptions): Promise<PiTurnExecutionResult>;
274
+ appendCustomMessage?(input: PiCustomMessageInput): Promise<string>;
275
+ steer(text: string): Promise<void>;
276
+ abortTurn(): Promise<void>;
277
+ subscribe(handler: PiEventHandler): () => void;
278
+ subscribeDiagnostics?(handler: PiSessionDiagnosticHandler): () => void;
279
+ close(): Promise<void>;
280
+ }
281
+
282
+ export const TURN_CONTEXT_MODES = ["full", "compacted", "fresh", "fresh_seeded"] as const;
283
+ export type TurnContextMode = (typeof TURN_CONTEXT_MODES)[number];
284
+
285
+ export const TURN_COMPLETION_MODES = ["turn_end"] as const;
286
+ export type TurnCompletionMode = (typeof TURN_COMPLETION_MODES)[number];
287
+
288
+ export type TurnBranchType = ProcessTurnRecordPathType;
289
+ export type TurnSemanticEntryRefKey = DomainProcessSemanticEntryRefKey;
290
+
291
+ export interface TurnResultMarkdownNoneBehavior {
292
+ mode: "none";
293
+ }
294
+
295
+ export interface TurnResultMarkdownAssistantOutputBehavior {
296
+ mode: "assistant_output";
297
+ required?: boolean;
298
+ }
299
+
300
+ export interface TurnResultMarkdownToolCallBehavior {
301
+ mode: "tool_call";
302
+ toolName: string;
303
+ source?: "arguments" | "result";
304
+ path: string;
305
+ required?: boolean;
306
+ }
307
+
308
+ export interface TurnResultMarkdownOutcomeToolArgumentBehavior {
309
+ mode: "outcome_tool_argument";
310
+ parameterName: string;
311
+ required?: boolean;
312
+ }
313
+
314
+ export type TurnResultMarkdownBehavior =
315
+ | TurnResultMarkdownNoneBehavior
316
+ | TurnResultMarkdownAssistantOutputBehavior
317
+ | TurnResultMarkdownToolCallBehavior
318
+ | TurnResultMarkdownOutcomeToolArgumentBehavior;
319
+
320
+ export type TurnAcceptanceState = DomainTurnAcceptanceState;
321
+
322
+ export interface ProcessActionSchedulingFixedTurnPreview {
323
+ kind: "fixed_turn";
324
+ turnId: TurnId | null;
325
+ }
326
+
327
+ export interface ProcessActionSchedulingTriggerPreview {
328
+ kind: "trigger";
329
+ trigger: string;
330
+ }
331
+
332
+ export interface ProcessActionSchedulingTerminalPreview {
333
+ kind: "terminal";
334
+ lifecycleStatus: ProcessTurnTerminalLifecycleStatus;
335
+ }
336
+
337
+ export type ProcessActionSchedulingPreview =
338
+ | ProcessActionSchedulingFixedTurnPreview
339
+ | ProcessActionSchedulingTriggerPreview
340
+ | ProcessActionSchedulingTerminalPreview;
341
+
342
+ export type ProcessActionPreviewDefinition = ProcessActionSchedulingPreview;
343
+
344
+ export interface ProcessActionSchedulingDefinition {
345
+ preview: ProcessActionSchedulingPreview;
346
+ }
347
+
348
+ export interface HumanTurnActionView {
349
+ actionId: string;
350
+ acceptanceState: TurnAcceptanceState;
351
+ label?: string;
352
+ description?: string;
353
+ preview?: ProcessActionPreviewDefinition;
354
+ scheduling?: ProcessActionSchedulingDefinition;
355
+ }
356
+
357
+ export interface HumanTurnNotesField {
358
+ id: string;
359
+ label: string;
360
+ description?: string;
361
+ placeholder?: string;
362
+ required?: boolean;
363
+ }
364
+
365
+ export interface HumanTurnExternalTrigger {
366
+ id: string;
367
+ actionId: string;
368
+ label: string;
369
+ description: string;
370
+ }
371
+
372
+ export interface HumanTurnExternalActionView {
373
+ /** Process-local arming id exposed to providers and UI. */
374
+ id: string;
375
+ externalActionId: string;
376
+ sourceKind: string;
377
+ label: string | null;
378
+ description: string | null;
379
+ }
380
+
381
+ export interface EventBus<TEventMap extends object = Record<string, unknown>> {
382
+ emit<K extends keyof TEventMap & string>(event: K, data: TEventMap[K]): void;
383
+ on<K extends keyof TEventMap & string>(
384
+ event: K,
385
+ handler: (data: TEventMap[K]) => void | Promise<void>,
386
+ ): void;
387
+ off<K extends keyof TEventMap & string>(
388
+ event: K,
389
+ handler: (data: TEventMap[K]) => void | Promise<void>,
390
+ ): void;
391
+ }
@@ -0,0 +1,46 @@
1
+ import type {
2
+ ExtensionProcessDefinition,
3
+ ProcessLeafOutcomeDefinition,
4
+ UiProcessAPI,
5
+ } from "./extension-api.js";
6
+ import { validateProcessLeafOutcomeDefinition } from "./leaf-outcomes.js";
7
+
8
+ export interface BuiltUiProcessDefinition<TParams = unknown, TState = unknown> {
9
+ leafOutcome: ProcessLeafOutcomeDefinition<TParams, TState> | null;
10
+ }
11
+
12
+ export function createUiProcessBuilder<TParams = unknown, TState = unknown>(): UiProcessAPI<
13
+ TParams,
14
+ TState
15
+ > & { getDefinition(): BuiltUiProcessDefinition<TParams, TState> } {
16
+ let leafOutcome: ProcessLeafOutcomeDefinition<TParams, TState> | null = null;
17
+
18
+ return {
19
+ leafOutcome(def) {
20
+ if (leafOutcome) {
21
+ throw new Error("Leaf outcome is already registered");
22
+ }
23
+ const validationErrors = validateProcessLeafOutcomeDefinition(def);
24
+ if (validationErrors.length > 0) {
25
+ throw new Error(validationErrors.join("; "));
26
+ }
27
+ leafOutcome = def;
28
+ },
29
+ getDefinition() {
30
+ return {
31
+ leafOutcome,
32
+ };
33
+ },
34
+ };
35
+ }
36
+
37
+ export function buildUiProcessDefinition<TParams = unknown, TState = unknown>(
38
+ process: ExtensionProcessDefinition<TParams, TState>,
39
+ ): BuiltUiProcessDefinition<TParams, TState> | undefined {
40
+ if (!process.ui) {
41
+ return undefined;
42
+ }
43
+ const builder = createUiProcessBuilder<TParams, TState>();
44
+ process.ui(builder);
45
+ return builder.getDefinition();
46
+ }
@@ -0,0 +1,33 @@
1
+ import type { TurnId } from "@leitwerk-dev/domain";
2
+ import type { WorkerProcessAPI, WorkerTurnHandler } from "./extension-api.js";
3
+ import { cloneMap, registerUnique } from "./registry-utils.js";
4
+
5
+ export interface BuiltWorkerProcessDefinition<TParams = unknown, TState = unknown> {
6
+ startTurnId: TurnId | null;
7
+ turns: ReadonlyMap<TurnId, WorkerTurnHandler<TParams, TState>>;
8
+ }
9
+
10
+ export function createWorkerProcessBuilder<TParams = unknown, TState = unknown>(): WorkerProcessAPI<
11
+ TParams,
12
+ TState
13
+ > & { getDefinition(): BuiltWorkerProcessDefinition<TParams, TState> } {
14
+ const turns = new Map<TurnId, WorkerTurnHandler<TParams, TState>>();
15
+ let startTurnId: TurnId | null = null;
16
+
17
+ return {
18
+ start(turnId: TurnId): void {
19
+ startTurnId = turnId;
20
+ },
21
+ turn(turnId: TurnId, handler: WorkerTurnHandler<TParams, TState>): void {
22
+ registerUnique(turns, turnId, handler, {
23
+ duplicateMessage: `Worker turn '${turnId}' is already registered`,
24
+ });
25
+ },
26
+ getDefinition(): BuiltWorkerProcessDefinition<TParams, TState> {
27
+ return {
28
+ startTurnId,
29
+ turns: cloneMap(turns),
30
+ };
31
+ },
32
+ };
33
+ }