@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
package/src/types.ts CHANGED
@@ -1,30 +1,26 @@
1
1
  import type {
2
- ProcessSemanticEntryRefKey as DomainProcessSemanticEntryRefKey,
3
2
  TurnAcceptanceState as DomainTurnAcceptanceState,
4
- ProcessInstance,
5
- ProcessProject,
6
3
  ProcessTurnRecordPathType,
7
4
  ProcessTurnTerminalLifecycleStatus,
8
5
  TurnId,
9
6
  } from "@leitwerk-dev/domain";
7
+ import type { UsageCostSnapshot, UsageTokenCounts } from "@leitwerk-dev/protocol";
10
8
 
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
-
9
+ /** @internal */
19
10
  export interface TurnOptions {
11
+ /** @internal */
20
12
  reset?: boolean;
21
13
  }
22
14
 
15
+ /** @internal */
23
16
  export interface TurnResult<T extends string = string> {
17
+ /** @internal */
24
18
  outcome: T;
19
+ /** @internal */
25
20
  params: Record<string, unknown>;
26
21
  }
27
22
 
23
+ /** @public */
28
24
  export const PI_BUILT_IN_TOOL_NAMES = [
29
25
  "read",
30
26
  "bash",
@@ -34,116 +30,166 @@ export const PI_BUILT_IN_TOOL_NAMES = [
34
30
  "find",
35
31
  "ls",
36
32
  ] as const;
33
+ /** @public */
37
34
  export type PiBuiltInToolName = (typeof PI_BUILT_IN_TOOL_NAMES)[number];
38
35
 
39
- /** Tool names owned by the worker runtime rather than an integration extension. */
36
+ /** Tool names owned by the worker runtime rather than an integration extension. @internal */
40
37
  export const FRAMEWORK_LLM_TOOL_NAMES = [
41
38
  "ask_questions",
42
39
  "markdown_result",
43
40
  "upload_result_images",
44
41
  ] as const;
45
42
 
46
- /** Names integration tools cannot use because Pi or the worker runtime owns them. */
43
+ /** Names integration tools cannot use because Pi or the worker runtime owns them. @internal */
47
44
  export const RESERVED_INTEGRATION_TOOL_NAMES = [
48
45
  ...PI_BUILT_IN_TOOL_NAMES,
49
46
  ...FRAMEWORK_LLM_TOOL_NAMES,
50
47
  ] as const;
51
48
 
49
+ /** @public */
52
50
  export interface ProcessPiConfig {
53
51
  /**
54
52
  * System prompt template. Rendered with Mustache against runtime context.
55
53
  * Use {{variableName}} for escaped values and {{{variableName}}} for raw values.
56
54
  * When omitted, Pi's default system prompt is used.
57
55
  */
56
+ /** @internal */
58
57
  systemPromptTemplate?: string;
59
58
  /**
60
59
  * Additional text appended after the base system prompt/resources. Rendered
61
60
  * with Mustache against runtime context.
62
61
  */
62
+ /** @public */
63
63
  appendSystemPromptTemplate?: string;
64
64
  /**
65
65
  * Code-defined Pi session working directory template. Rendered with Mustache
66
66
  * against runtime context. When omitted, the process workspace root is used.
67
67
  */
68
+ /** @public */
68
69
  sessionCwdTemplate?: string;
69
70
  }
70
71
 
72
+ /** @internal */
71
73
  export interface ResolvedProcessPiConfig {
74
+ /** @internal */
72
75
  systemPrompt?: string;
76
+ /** @internal */
73
77
  appendSystemPrompt?: string;
78
+ /** @internal */
74
79
  sessionCwd?: string;
80
+ /** @internal */
75
81
  availableToolNames: string[];
76
82
  }
77
83
 
84
+ /** @internal */
78
85
  export type OutcomeToolParameterType = "string" | "number" | "array" | "boolean" | "object";
86
+ /** @internal */
79
87
  export type OutcomeToolArrayItemType = Exclude<OutcomeToolParameterType, "array">;
80
88
 
89
+ /** @internal */
81
90
  export interface OutcomeToolArrayItemSpec {
91
+ /** @internal */
82
92
  type: OutcomeToolArrayItemType;
93
+ /** @internal */
83
94
  description?: string;
84
95
  }
85
96
 
97
+ /** @public */
86
98
  export interface OutcomeToolParameterSpec {
99
+ /** @internal */
87
100
  type: OutcomeToolParameterType;
101
+ /** @internal */
88
102
  description: string;
103
+ /** @internal */
89
104
  required?: boolean;
105
+ /** @internal */
90
106
  requiredErrorCode?: string;
107
+ /** @internal */
91
108
  invalidErrorCode?: string;
109
+ /** @internal */
92
110
  minItems?: number;
111
+ /** @internal */
93
112
  minItemsErrorCode?: string;
113
+ /** @internal */
94
114
  minimum?: number;
115
+ /** @internal */
95
116
  minimumErrorCode?: string;
117
+ /** @internal */
96
118
  items?: OutcomeToolArrayItemSpec;
119
+ /** @internal */
97
120
  enum?: readonly string[];
98
121
  }
99
122
 
123
+ /** @internal */
100
124
  export interface OutcomeToolSpec {
125
+ /** @internal */
101
126
  description: string;
127
+ /** @internal */
102
128
  parameters: Record<string, OutcomeToolParameterSpec>;
103
- /** Product published from this outcome's turn-result markdown, when selected. */
129
+ /** Product published from this outcome's turn-result markdown, when selected. @internal */
104
130
  publishedProduct?: string;
105
- /** Outcome parameter whose markdown value is captured as the turn result. */
131
+ /** Outcome parameter whose markdown value is captured as the turn result. @internal */
106
132
  turnResultMarkdownParameter?: string;
133
+ /** Outcome parameter containing a concise operator-facing summary. @internal */
134
+ resultSummaryParameter?: string;
107
135
  }
108
136
 
109
- export interface ProcessToolResult {
110
- status: string;
111
- outcome?: string;
112
- }
113
-
137
+ /** @public */
114
138
  export interface PiTreeEntry {
139
+ /** @internal */
115
140
  readonly id: string;
141
+ /** @internal */
116
142
  readonly parentId: string | null;
143
+ /** @public */
117
144
  readonly type: string;
145
+ /** @internal */
118
146
  readonly timestamp: string;
147
+ /** @public */
119
148
  readonly message?: {
149
+ /** @internal */
120
150
  readonly role?: string;
151
+ /** @public */
121
152
  readonly content?: unknown;
122
153
  };
123
- /** Pi custom-message fields. Details are intentionally excluded from model context. */
154
+ /** Pi custom-message fields. Details are intentionally excluded from model context. @internal */
124
155
  readonly customType?: string;
156
+ /** @public */
125
157
  readonly content?: unknown;
158
+ /** @internal */
126
159
  readonly details?: unknown;
160
+ /** @internal */
127
161
  readonly targetId?: string;
162
+ /** @internal */
128
163
  readonly label?: string;
129
164
  }
130
165
 
166
+ /** @internal */
131
167
  export interface PiTreeNode {
168
+ /** @internal */
132
169
  readonly entry: PiTreeEntry;
170
+ /** @internal */
133
171
  readonly children: readonly PiTreeNode[];
172
+ /** @internal */
134
173
  readonly label?: string;
174
+ /** @internal */
135
175
  readonly labelTimestamp?: string;
136
176
  }
137
177
 
178
+ /** @public */
138
179
  export interface PiTurnExecutionResult {
180
+ /** @internal */
139
181
  startLeafId: string | null;
182
+ /** @internal */
140
183
  endLeafId: string | null;
184
+ /** @internal */
141
185
  createdEntryIds: string[];
186
+ /** @internal */
142
187
  resultEntryId: string;
143
- /** Final assistant markdown captured from the Pi assistant message for this turn, when available. */
188
+ /** Final assistant markdown captured from the Pi assistant message for this turn, when available. @internal */
144
189
  assistantMarkdown?: string | null;
145
190
  }
146
191
 
192
+ /** @internal */
147
193
  export type PiEventType =
148
194
  | "turn.start"
149
195
  | "turn.end"
@@ -162,93 +208,134 @@ export type PiEventType =
162
208
  | "retry.end"
163
209
  | "usage";
164
210
 
211
+ /** @internal */
165
212
  export interface PiEvent {
213
+ /** @internal */
166
214
  type: PiEventType;
215
+ /** @internal */
167
216
  turnId: string;
217
+ /** @internal */
168
218
  data: Record<string, unknown>;
219
+ /** @internal */
169
220
  timestamp: string;
170
221
  }
171
222
 
223
+ /** @internal */
172
224
  export type PiEventHandler = (event: PiEvent) => void;
173
225
 
226
+ /** @internal */
174
227
  export type PiSessionDiagnosticLevel = "debug" | "info" | "warn" | "error";
175
228
 
229
+ /** @internal */
176
230
  export interface PiSessionDiagnostic {
231
+ /** @internal */
177
232
  level: PiSessionDiagnosticLevel;
233
+ /** @internal */
178
234
  code: string;
235
+ /** @internal */
179
236
  message: string;
237
+ /** @internal */
180
238
  timestamp: string;
239
+ /** @internal */
181
240
  turnId?: string;
241
+ /** @internal */
182
242
  details?: Record<string, unknown>;
183
243
  }
184
244
 
245
+ /** @internal */
185
246
  export type PiSessionDiagnosticHandler = (diagnostic: PiSessionDiagnostic) => void;
186
247
 
248
+ /** @public */
187
249
  export interface PiCustomToolExecutionContext {
188
- /** Pi's identity for this exact invocation; stable across the paused call. */
250
+ /** Pi's identity for this exact invocation; stable across the paused call. @public */
189
251
  toolCallId: string;
190
- /** Aborted when the active turn is stopped or torn down. */
252
+ /** Aborted when the active turn is stopped or torn down. @public */
191
253
  signal: AbortSignal;
192
- /** Pause model-execution budgets while this custom tool awaits durable operator input. */
254
+ /** Pause model-execution budgets while this custom tool awaits durable operator input. @internal */
193
255
  suspendPromptGuards?: () => () => void;
194
256
  }
195
257
 
258
+ /** @public */
196
259
  export interface PiCustomTool {
260
+ /** @public */
197
261
  name: string;
262
+ /** @internal */
198
263
  description: string;
264
+ /** @internal */
199
265
  parameters: Record<string, unknown>;
266
+ /** @internal */
200
267
  executionMode?: "sequential" | "parallel";
268
+ /** @public */
201
269
  execute(args: Record<string, unknown>, context?: PiCustomToolExecutionContext): Promise<unknown>;
202
270
  }
203
271
 
204
- export interface PiUsageData {
205
- input: number;
206
- output: number;
207
- /** Provider-reported reasoning/thinking tokens. This is a subset of output tokens. */
208
- reasoning?: number;
209
- cacheRead: number;
210
- cacheWrite: number;
211
- totalTokens: number;
212
- cost: {
213
- input: number;
214
- output: number;
215
- cacheRead: number;
216
- cacheWrite: number;
217
- total: number;
218
- };
272
+ /** @internal */
273
+ export interface PiUsageData extends UsageTokenCounts {
274
+ /** @internal */
275
+ cost: UsageCostSnapshot;
276
+ /** @internal */
219
277
  cacheHitRate: number;
220
278
  }
221
279
 
280
+ /** @internal */
222
281
  export interface PiRunDetails {
223
- loadedAgentsFiles: Array<{ path: string; sizeBytes: number }>;
224
- loadedSkills: Array<{ name: string; path: string }>;
282
+ /** @internal */
283
+ loadedAgentsFiles: Array<{
284
+ /** @internal */
285
+ path: string;
286
+ /** @internal */
287
+ sizeBytes: number;
288
+ }>;
289
+ /** @internal */
290
+ loadedSkills: Array<{
291
+ /** @internal */
292
+ name: string;
293
+ /** @internal */
294
+ path: string;
295
+ }>;
296
+ /** @internal */
225
297
  availableToolNames: string[];
226
298
  }
227
299
 
300
+ /** @internal */
228
301
  export type ProcessCustomTool = PiCustomTool;
229
302
 
303
+ /** @public */
230
304
  export interface PiCustomMessageInput {
305
+ /** @internal */
231
306
  content: string;
307
+ /** @internal */
232
308
  details: unknown;
309
+ /** @internal */
233
310
  display?: boolean;
234
311
  }
235
312
 
313
+ /** @internal */
236
314
  export type PiTerminalAcknowledgementState =
237
315
  | "open"
238
316
  | "outcome_accepted"
239
317
  | "acknowledgement_succeeded"
240
318
  | "acknowledgement_failed_ignored";
241
319
 
320
+ /** @internal */
242
321
  export interface PiTerminalAcknowledgementControl {
322
+ /** @internal */
243
323
  readonly timeoutMs: number;
324
+ /** @internal */
244
325
  state(): PiTerminalAcknowledgementState;
326
+ /** @internal */
245
327
  isOperatorAbortRequested(): boolean;
328
+ /** @internal */
246
329
  markSucceeded(): void;
330
+ /** @internal */
247
331
  markFailed(reason: string): void;
248
332
  }
249
333
 
334
+ /** @public */
250
335
  export interface PiPromptOptions {
336
+ /** @public */
251
337
  tools?: readonly PiCustomTool[];
338
+ /** @internal */
252
339
  activeTools?: readonly string[];
253
340
  /** @internal Runtime-only hook used by the worker Pi adapter before a tool executes. */
254
341
  shouldBlockToolCall?: (toolName: string) => string | null;
@@ -258,145 +345,230 @@ export interface PiPromptOptions {
258
345
  terminalAcknowledgement?: PiTerminalAcknowledgementControl;
259
346
  }
260
347
 
348
+ /** @public */
261
349
  export interface PiTreeHandle {
350
+ /** @internal */
262
351
  readonly sessionId: string;
352
+ /** @internal */
263
353
  readonly treeFile: string;
354
+ /** @internal */
264
355
  readonly isResumed: boolean;
265
356
 
357
+ /** @internal */
266
358
  getRunDetails(): PiRunDetails;
359
+ /** @internal */
267
360
  getLeafId(): string | null;
361
+ /** @internal */
268
362
  getEntry(id: string): PiTreeEntry | undefined;
363
+ /** @internal */
269
364
  getBranch(fromId?: string): PiTreeEntry[];
365
+ /** @internal */
270
366
  getChildren(parentId: string): PiTreeEntry[];
367
+ /** @internal */
271
368
  getTree(): PiTreeNode[];
369
+ /** @internal */
272
370
  branch(entryId: string): void | Promise<void>;
371
+ /** @internal */
273
372
  branchFromRoot(): void | Promise<void>;
373
+ /** @internal */
274
374
  resetLeaf(): void | Promise<void>;
275
375
  /**
276
376
  * Compact the current Pi context. `details` is persisted with the resulting
277
377
  * compaction entry, but deliberately remains outside model context.
278
378
  */
379
+ /** @internal */
279
380
  compact?(customInstructions?: string, details?: unknown): Promise<unknown>;
381
+ /** @public */
280
382
  prompt(text: string, options?: PiPromptOptions): Promise<PiTurnExecutionResult>;
383
+ /** @public */
281
384
  promptLiteral(text: string, options?: PiPromptOptions): Promise<PiTurnExecutionResult>;
385
+ /** @public */
282
386
  promptCustom(
283
387
  input: PiCustomMessageInput,
284
388
  options?: PiPromptOptions,
285
389
  ): Promise<PiTurnExecutionResult>;
390
+ /** @public */
286
391
  continueTurn(options?: PiPromptOptions): Promise<PiTurnExecutionResult>;
392
+ /** @internal */
287
393
  appendCustomMessage?(input: PiCustomMessageInput): Promise<string>;
394
+ /** @internal */
288
395
  steer(text: string): Promise<void>;
396
+ /** @internal */
289
397
  abortTurn(): Promise<void>;
398
+ /** @internal */
290
399
  subscribe(handler: PiEventHandler): () => void;
400
+ /** @internal */
291
401
  subscribeDiagnostics?(handler: PiSessionDiagnosticHandler): () => void;
402
+ /** @internal */
292
403
  close(): Promise<void>;
293
404
  }
294
405
 
406
+ /** @public */
295
407
  export const TURN_CONTEXT_MODES = ["full", "compacted", "fresh", "fresh_seeded"] as const;
408
+ /** @public */
296
409
  export type TurnContextMode = (typeof TURN_CONTEXT_MODES)[number];
297
410
 
411
+ /** @public */
298
412
  export const TURN_COMPLETION_MODES = ["turn_end"] as const;
413
+ /** @public */
299
414
  export type TurnCompletionMode = (typeof TURN_COMPLETION_MODES)[number];
300
415
 
416
+ /** @public */
301
417
  export type TurnBranchType = ProcessTurnRecordPathType;
302
- export type TurnSemanticEntryRefKey = DomainProcessSemanticEntryRefKey;
303
418
 
419
+ /** @public */
304
420
  export interface TurnResultMarkdownNoneBehavior {
421
+ /** @internal */
305
422
  mode: "none";
306
423
  }
307
424
 
425
+ /** @public */
308
426
  export interface TurnResultMarkdownAssistantOutputBehavior {
427
+ /** @internal */
309
428
  mode: "assistant_output";
429
+ /** @internal */
310
430
  required?: boolean;
311
431
  }
312
432
 
433
+ /** @public */
313
434
  export interface TurnResultMarkdownToolCallBehavior {
435
+ /** @internal */
314
436
  mode: "tool_call";
437
+ /** @internal */
315
438
  toolName: string;
439
+ /** @internal */
316
440
  source?: "arguments" | "result";
441
+ /** @internal */
317
442
  path: string;
443
+ /** @internal */
318
444
  required?: boolean;
319
445
  }
320
446
 
447
+ /** @public */
321
448
  export interface TurnResultMarkdownOutcomeToolArgumentBehavior {
449
+ /** @internal */
322
450
  mode: "outcome_tool_argument";
451
+ /** @internal */
323
452
  parameterName: string;
453
+ /** @internal */
324
454
  required?: boolean;
325
455
  }
326
456
 
457
+ /** @public */
327
458
  export type TurnResultMarkdownBehavior =
328
459
  | TurnResultMarkdownNoneBehavior
329
460
  | TurnResultMarkdownAssistantOutputBehavior
330
461
  | TurnResultMarkdownToolCallBehavior
331
462
  | TurnResultMarkdownOutcomeToolArgumentBehavior;
332
463
 
464
+ /** @public */
333
465
  export type TurnAcceptanceState = DomainTurnAcceptanceState;
334
466
 
467
+ /** @public */
335
468
  export interface ProcessActionSchedulingFixedTurnPreview {
469
+ /** @public */
336
470
  kind: "fixed_turn";
471
+ /** @public */
337
472
  turnId: TurnId | null;
338
473
  }
339
474
 
475
+ /** @public */
340
476
  export interface ProcessActionSchedulingTriggerPreview {
477
+ /** @public */
341
478
  kind: "trigger";
479
+ /** @internal */
342
480
  trigger: string;
343
481
  }
344
482
 
483
+ /** @public */
345
484
  export interface ProcessActionSchedulingTerminalPreview {
485
+ /** @public */
346
486
  kind: "terminal";
487
+ /** @internal */
347
488
  lifecycleStatus: ProcessTurnTerminalLifecycleStatus;
348
489
  }
349
490
 
491
+ /** @public */
350
492
  export type ProcessActionSchedulingPreview =
351
493
  | ProcessActionSchedulingFixedTurnPreview
352
494
  | ProcessActionSchedulingTriggerPreview
353
495
  | ProcessActionSchedulingTerminalPreview;
354
496
 
497
+ /** @public */
355
498
  export type ProcessActionPreviewDefinition = ProcessActionSchedulingPreview;
356
499
 
500
+ /** @internal */
357
501
  export interface ProcessActionSchedulingDefinition {
502
+ /** @internal */
358
503
  preview: ProcessActionSchedulingPreview;
359
504
  }
360
505
 
506
+ /** @internal */
361
507
  export interface HumanTurnActionView {
508
+ /** @internal */
362
509
  actionId: string;
510
+ /** @internal */
363
511
  acceptanceState: TurnAcceptanceState;
512
+ /** @internal */
364
513
  label?: string;
514
+ /** @internal */
365
515
  description?: string;
516
+ /** @internal */
366
517
  preview?: ProcessActionPreviewDefinition;
518
+ /** @internal */
367
519
  scheduling?: ProcessActionSchedulingDefinition;
368
520
  }
369
521
 
522
+ /** @internal */
370
523
  export interface HumanTurnNotesField {
524
+ /** @internal */
371
525
  id: string;
526
+ /** @internal */
372
527
  label: string;
528
+ /** @internal */
373
529
  description?: string;
530
+ /** @internal */
374
531
  placeholder?: string;
532
+ /** @internal */
375
533
  required?: boolean;
376
534
  }
377
535
 
536
+ /** @internal */
378
537
  export interface HumanTurnExternalTrigger {
538
+ /** @internal */
379
539
  id: string;
540
+ /** @internal */
380
541
  actionId: string;
542
+ /** @internal */
381
543
  label: string;
544
+ /** @internal */
382
545
  description: string;
383
546
  }
384
547
 
548
+ /** @internal */
385
549
  export interface HumanTurnExternalActionView {
386
- /** Process-local arming id exposed to providers and UI. */
550
+ /** Process-local arming id exposed to providers and UI. @internal */
387
551
  id: string;
552
+ /** @internal */
388
553
  externalActionId: string;
554
+ /** @internal */
389
555
  sourceKind: string;
556
+ /** @internal */
390
557
  label: string | null;
558
+ /** @internal */
391
559
  description: string | null;
392
560
  }
393
561
 
562
+ /** @internal */
394
563
  export interface EventBus<TEventMap extends object = Record<string, unknown>> {
564
+ /** @internal */
395
565
  emit<K extends keyof TEventMap & string>(event: K, data: TEventMap[K]): void;
566
+ /** @internal */
396
567
  on<K extends keyof TEventMap & string>(
397
568
  event: K,
398
569
  handler: (data: TEventMap[K]) => void | Promise<void>,
399
570
  ): void;
571
+ /** @internal */
400
572
  off<K extends keyof TEventMap & string>(
401
573
  event: K,
402
574
  handler: (data: TEventMap[K]) => void | Promise<void>,
@@ -5,14 +5,20 @@ import type {
5
5
  } from "./extension-api.js";
6
6
  import { validateProcessLeafOutcomeDefinition } from "./leaf-outcomes.js";
7
7
 
8
+ /** @internal */
8
9
  export interface BuiltUiProcessDefinition<TParams = unknown, TState = unknown> {
10
+ /** @internal */
9
11
  leafOutcome: ProcessLeafOutcomeDefinition<TParams, TState> | null;
10
12
  }
11
13
 
14
+ /** @internal */
12
15
  export function createUiProcessBuilder<TParams = unknown, TState = unknown>(): UiProcessAPI<
13
16
  TParams,
14
17
  TState
15
- > & { getDefinition(): BuiltUiProcessDefinition<TParams, TState> } {
18
+ > & {
19
+ /** @internal */
20
+ getDefinition(): BuiltUiProcessDefinition<TParams, TState>;
21
+ } {
16
22
  let leafOutcome: ProcessLeafOutcomeDefinition<TParams, TState> | null = null;
17
23
 
18
24
  return {
@@ -34,6 +40,7 @@ export function createUiProcessBuilder<TParams = unknown, TState = unknown>(): U
34
40
  };
35
41
  }
36
42
 
43
+ /** @internal */
37
44
  export function buildUiProcessDefinition<TParams = unknown, TState = unknown>(
38
45
  process: ExtensionProcessDefinition<TParams, TState>,
39
46
  ): BuiltUiProcessDefinition<TParams, TState> | undefined {
@@ -2,15 +2,22 @@ import type { TurnId } from "@leitwerk-dev/domain";
2
2
  import type { WorkerProcessAPI, WorkerTurnHandler } from "./extension-api.js";
3
3
  import { cloneMap, registerUnique } from "./registry-utils.js";
4
4
 
5
+ /** @internal */
5
6
  export interface BuiltWorkerProcessDefinition<TParams = unknown, TState = unknown> {
7
+ /** @internal */
6
8
  startTurnId: TurnId | null;
9
+ /** @internal */
7
10
  turns: ReadonlyMap<TurnId, WorkerTurnHandler<TParams, TState>>;
8
11
  }
9
12
 
13
+ /** @internal */
10
14
  export function createWorkerProcessBuilder<TParams = unknown, TState = unknown>(): WorkerProcessAPI<
11
15
  TParams,
12
16
  TState
13
- > & { getDefinition(): BuiltWorkerProcessDefinition<TParams, TState> } {
17
+ > & {
18
+ /** @internal */
19
+ getDefinition(): BuiltWorkerProcessDefinition<TParams, TState>;
20
+ } {
14
21
  const turns = new Map<TurnId, WorkerTurnHandler<TParams, TState>>();
15
22
  let startTurnId: TurnId | null = null;
16
23
 
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=browser-ui-extension.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"browser-ui-extension.js","sourceRoot":"","sources":["../src/browser-ui-extension.ts"],"names":[],"mappings":""}
@@ -1,7 +0,0 @@
1
- export function createCapabilityToken(id, options = {}) {
2
- return {
3
- id,
4
- cardinality: options.cardinality ?? "single",
5
- };
6
- }
7
- //# sourceMappingURL=capabilities.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"capabilities.js","sourceRoot":"","sources":["../src/capabilities.ts"],"names":[],"mappings":"AAOA,MAAM,UAAU,qBAAqB,CACpC,EAAU,EACV,UAAmD,EAAE;IAErD,OAAO;QACN,EAAE;QACF,WAAW,EAAE,OAAO,CAAC,WAAW,IAAI,QAAQ;KAC5C,CAAC;AACH,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/process-definition-internals.ts","../src/registry-utils.ts"],"sourcesContent":["import type { ProcessTurnTransition } from \"@leitwerk-dev/domain\";\nimport type { ProcessTurnBinding } from \"./extension-api.js\";\n\ninterface ProcessDefinitionInternalRegistry {\n\tdefinedProcesses: WeakSet<object>;\n\tturnTransitions: WeakMap<object, readonly ProcessTurnTransition[]>;\n}\n\nconst registryKey = Symbol.for(\"@leitwerk-dev/process-sdk/internal-registry\");\nconst registryHolder = globalThis as typeof globalThis & {\n\t[registryKey]?: ProcessDefinitionInternalRegistry;\n};\nif (!registryHolder[registryKey]) {\n\tregistryHolder[registryKey] = {\n\t\tdefinedProcesses: new WeakSet<object>(),\n\t\tturnTransitions: new WeakMap<object, readonly ProcessTurnTransition[]>(),\n\t};\n}\nconst registry = registryHolder[registryKey];\n\nexport function markDefinedProcess(value: object): void {\n\tregistry.definedProcesses.add(value);\n}\n\nexport function isDefinedProcess(value: unknown): boolean {\n\treturn typeof value === \"object\" && value !== null && registry.definedProcesses.has(value);\n}\n\nexport function setProcessTurnTransitions(\n\tbinding: object,\n\ttransitions: readonly ProcessTurnTransition[],\n): void {\n\tregistry.turnTransitions.set(\n\t\tbinding,\n\t\ttransitions.map((transition) => ({ ...transition })),\n\t);\n}\n\nexport function getProcessTurnTransitions(\n\tbinding: ProcessTurnBinding<unknown> | undefined,\n): readonly ProcessTurnTransition[] {\n\tif (!binding) {\n\t\treturn [];\n\t}\n\treturn registry.turnTransitions.get(binding)?.map((transition) => ({ ...transition })) ?? [];\n}\n","export interface UniqueRegistrationOptions<TValue> {\n\tduplicateMessage: string;\n\tvalidate?: (value: TValue) => void;\n}\n\nexport function registerUnique<TKey, TValue>(\n\tregistry: Map<TKey, TValue>,\n\tkey: TKey,\n\tvalue: TValue,\n\toptions: UniqueRegistrationOptions<TValue>,\n): void {\n\tif (registry.has(key)) {\n\t\tthrow new Error(options.duplicateMessage);\n\t}\n\toptions.validate?.(value);\n\tregistry.set(key, value);\n}\n\nexport function cloneMap<TKey, TValue>(registry: ReadonlyMap<TKey, TValue>): Map<TKey, TValue> {\n\treturn new Map(registry);\n}\n\nexport function cloneArrayValueMap<TKey, TValue>(\n\tregistry: ReadonlyMap<TKey, readonly TValue[]>,\n): Map<TKey, readonly TValue[]> {\n\tconst cloned = new Map<TKey, readonly TValue[]>();\n\tfor (const [key, values] of registry) {\n\t\tcloned.set(key, [...values]);\n\t}\n\treturn cloned;\n}\n"],"mappings":";AAQA,IAAM,cAAc,uBAAO,IAAI,6CAA6C;AAC5E,IAAM,iBAAiB;AAGvB,IAAI,CAAC,eAAe,WAAW,GAAG;AACjC,iBAAe,WAAW,IAAI;AAAA,IAC7B,kBAAkB,oBAAI,QAAgB;AAAA,IACtC,iBAAiB,oBAAI,QAAkD;AAAA,EACxE;AACD;AACA,IAAM,WAAW,eAAe,WAAW;AAEpC,SAAS,mBAAmB,OAAqB;AACvD,WAAS,iBAAiB,IAAI,KAAK;AACpC;AAEO,SAAS,iBAAiB,OAAyB;AACzD,SAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,SAAS,iBAAiB,IAAI,KAAK;AAC1F;AAEO,SAAS,0BACf,SACA,aACO;AACP,WAAS,gBAAgB;AAAA,IACxB;AAAA,IACA,YAAY,IAAI,CAAC,gBAAgB,EAAE,GAAG,WAAW,EAAE;AAAA,EACpD;AACD;AAEO,SAAS,0BACf,SACmC;AACnC,MAAI,CAAC,SAAS;AACb,WAAO,CAAC;AAAA,EACT;AACA,SAAO,SAAS,gBAAgB,IAAI,OAAO,GAAG,IAAI,CAAC,gBAAgB,EAAE,GAAG,WAAW,EAAE,KAAK,CAAC;AAC5F;;;ACxCO,SAAS,eACfA,WACA,KACA,OACA,SACO;AACP,MAAIA,UAAS,IAAI,GAAG,GAAG;AACtB,UAAM,IAAI,MAAM,QAAQ,gBAAgB;AAAA,EACzC;AACA,UAAQ,WAAW,KAAK;AACxB,EAAAA,UAAS,IAAI,KAAK,KAAK;AACxB;AAEO,SAAS,SAAuBA,WAAwD;AAC9F,SAAO,IAAI,IAAIA,SAAQ;AACxB;AAEO,SAAS,mBACfA,WAC+B;AAC/B,QAAM,SAAS,oBAAI,IAA6B;AAChD,aAAW,CAAC,KAAK,MAAM,KAAKA,WAAU;AACrC,WAAO,IAAI,KAAK,CAAC,GAAG,MAAM,CAAC;AAAA,EAC5B;AACA,SAAO;AACR;","names":["registry"]}