@leitwerk-dev/process-sdk 0.2.0 → 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 (186) 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-TA4KO53Q.js → chunk-I7U6HCLN.js} +1 -7
  10. package/dist/chunk-I7U6HCLN.js.map +1 -0
  11. package/dist/{chunk-WFY2WWZE.js → chunk-TM2LTSW4.js} +1 -1
  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 +336 -20
  18. package/dist/core-capabilities.d.ts.map +1 -1
  19. package/dist/define-process.d.ts +195 -18
  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-CcqZCYJx.d.ts → extension-api-B4gG5w1K.d.ts} +1000 -108
  24. package/dist/extension-api.d.ts +385 -50
  25. package/dist/extension-api.d.ts.map +1 -1
  26. package/dist/external-action-source.d.ts +3 -1
  27. package/dist/external-action-source.d.ts.map +1 -1
  28. package/dist/external-source-poll.d.ts +8 -1
  29. package/dist/external-source-poll.d.ts.map +1 -1
  30. package/dist/flow.d.ts +308 -11
  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 +4 -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.map +1 -1
  39. package/dist/graph-fragments.d.ts +16 -0
  40. package/dist/graph-fragments.d.ts.map +1 -1
  41. package/dist/host-capabilities.d.ts +9 -3
  42. package/dist/host-capabilities.d.ts.map +1 -1
  43. package/dist/index.d.ts +24 -25
  44. package/dist/index.d.ts.map +1 -1
  45. package/dist/index.js +262 -80
  46. package/dist/index.js.map +1 -1
  47. package/dist/integration-http.d.ts +14 -3
  48. package/dist/integration-http.d.ts.map +1 -1
  49. package/dist/json-data.d.ts +1 -1
  50. package/dist/json-data.d.ts.map +1 -1
  51. package/dist/leaf-outcome-renderer.d.ts +35 -0
  52. package/dist/leaf-outcome-renderer.d.ts.map +1 -1
  53. package/dist/leaf-outcome-renderer.js +12 -0
  54. package/dist/leaf-outcome-renderer.js.map +1 -1
  55. package/dist/leaf-outcomes.d.ts +3 -0
  56. package/dist/leaf-outcomes.d.ts.map +1 -1
  57. package/dist/model-provider.d.ts +144 -12
  58. package/dist/model-provider.d.ts.map +1 -1
  59. package/dist/pi-config-public.d.ts +2 -0
  60. package/dist/pi-config-public.d.ts.map +1 -0
  61. package/dist/pi-config-public.js +15 -0
  62. package/dist/pi-config-public.js.map +1 -0
  63. package/dist/pi-config.d.ts +40 -0
  64. package/dist/pi-config.d.ts.map +1 -1
  65. package/dist/pi-config.js +1 -1
  66. package/dist/process-definition-internals.d.ts +4 -0
  67. package/dist/process-definition-internals.d.ts.map +1 -1
  68. package/dist/process-flow-view.d.ts +2 -0
  69. package/dist/process-flow-view.d.ts.map +1 -1
  70. package/dist/process-graph.d.ts +34 -0
  71. package/dist/process-graph.d.ts.map +1 -1
  72. package/dist/process-launcher-builder.d.ts +5 -0
  73. package/dist/process-launcher-builder.d.ts.map +1 -1
  74. package/dist/process-watcher-builder.d.ts +5 -0
  75. package/dist/process-watcher-builder.d.ts.map +1 -1
  76. package/dist/process-watcher-source.d.ts +3 -1
  77. package/dist/process-watcher-source.d.ts.map +1 -1
  78. package/dist/project-binding.d.ts +5 -1
  79. package/dist/project-binding.d.ts.map +1 -1
  80. package/dist/registry-utils.d.ts +6 -0
  81. package/dist/registry-utils.d.ts.map +1 -1
  82. package/dist/repository-feedback.d.ts +20 -2
  83. package/dist/repository-feedback.d.ts.map +1 -1
  84. package/dist/repository-git-env.d.ts +6 -2
  85. package/dist/repository-git-env.d.ts.map +1 -1
  86. package/dist/repository-http.d.ts +13 -1
  87. package/dist/repository-http.d.ts.map +1 -1
  88. package/dist/repository-https.d.ts +1 -1
  89. package/dist/repository-https.d.ts.map +1 -1
  90. package/dist/repository-issue-watcher.d.ts +21 -1
  91. package/dist/repository-issue-watcher.d.ts.map +1 -1
  92. package/dist/repository-reconciliation.d.ts +5 -0
  93. package/dist/repository-reconciliation.d.ts.map +1 -0
  94. package/dist/repository-source-config.d.ts +27 -1
  95. package/dist/repository-source-config.d.ts.map +1 -1
  96. package/dist/repository-types.d.ts +28 -1
  97. package/dist/repository-types.d.ts.map +1 -1
  98. package/dist/review-flow-public.d.ts +2 -0
  99. package/dist/review-flow-public.d.ts.map +1 -0
  100. package/dist/review-flow-public.js +11 -0
  101. package/dist/review-flow-public.js.map +1 -0
  102. package/dist/review-flow.d.ts +6 -0
  103. package/dist/review-flow.d.ts.map +1 -1
  104. package/dist/review-flow.js +1 -1
  105. package/dist/runtime-internals-public.d.ts +2 -0
  106. package/dist/runtime-internals-public.d.ts.map +1 -0
  107. package/dist/runtime-internals-public.js +16 -0
  108. package/dist/runtime-internals-public.js.map +1 -0
  109. package/dist/runtime-internals.js +2 -1
  110. package/dist/server-events.d.ts +67 -0
  111. package/dist/server-events.d.ts.map +1 -1
  112. package/dist/server-process-builder.d.ts +7 -0
  113. package/dist/server-process-builder.d.ts.map +1 -1
  114. package/dist/state-helpers.d.ts +6 -0
  115. package/dist/state-helpers.d.ts.map +1 -1
  116. package/dist/subprocess-env.d.ts +3 -0
  117. package/dist/subprocess-env.d.ts.map +1 -1
  118. package/dist/tool-arguments.d.ts +4 -2
  119. package/dist/tool-arguments.d.ts.map +1 -1
  120. package/dist/tool-renderers.d.ts +6 -0
  121. package/dist/tool-renderers.d.ts.map +1 -1
  122. package/dist/turn-semantics.d.ts +14 -1
  123. package/dist/turn-semantics.d.ts.map +1 -1
  124. package/dist/types.d.ts +205 -24
  125. package/dist/types.d.ts.map +1 -1
  126. package/dist/ui-process-builder.d.ts +5 -0
  127. package/dist/ui-process-builder.d.ts.map +1 -1
  128. package/dist/worker-process-builder.d.ts +5 -0
  129. package/dist/worker-process-builder.d.ts.map +1 -1
  130. package/package.json +16 -15
  131. package/src/browser-ui-extension.ts +20 -0
  132. package/src/capabilities.ts +9 -1
  133. package/src/codecs.ts +1 -0
  134. package/src/commit-message.ts +5 -0
  135. package/src/core-capabilities.ts +396 -35
  136. package/src/define-process.ts +198 -23
  137. package/src/event-bus.ts +1 -0
  138. package/src/extension-api.ts +399 -55
  139. package/src/external-action-source.ts +7 -2
  140. package/src/external-source-poll.ts +15 -3
  141. package/src/flow.ts +352 -23
  142. package/src/form-contract.ts +0 -4
  143. package/src/fs-utils.ts +4 -0
  144. package/src/git-binary.ts +2 -1
  145. package/src/graph-fragments.ts +16 -0
  146. package/src/host-capabilities.ts +9 -6
  147. package/src/index.ts +5 -201
  148. package/src/integration-http.ts +15 -3
  149. package/src/json-data.ts +1 -1
  150. package/src/leaf-outcome-renderer.ts +35 -0
  151. package/src/leaf-outcomes.ts +3 -0
  152. package/src/model-provider.ts +169 -20
  153. package/src/pi-config-public.ts +7 -0
  154. package/src/pi-config.ts +47 -2
  155. package/src/process-definition-internals.ts +4 -0
  156. package/src/process-flow-view.ts +2 -0
  157. package/src/process-graph.ts +34 -0
  158. package/src/process-launcher-builder.ts +5 -0
  159. package/src/process-watcher-builder.ts +5 -0
  160. package/src/process-watcher-source.ts +6 -4
  161. package/src/project-binding.ts +5 -1
  162. package/src/registry-utils.ts +6 -0
  163. package/src/repository-feedback.ts +30 -4
  164. package/src/repository-git-env.ts +6 -2
  165. package/src/repository-http.ts +19 -2
  166. package/src/repository-https.ts +1 -1
  167. package/src/repository-issue-watcher.ts +35 -5
  168. package/src/repository-reconciliation.ts +30 -0
  169. package/src/repository-source-config.ts +20 -1
  170. package/src/repository-types.ts +43 -5
  171. package/src/review-flow-public.ts +5 -0
  172. package/src/review-flow.ts +6 -0
  173. package/src/runtime-internals-public.ts +7 -0
  174. package/src/server-events.ts +67 -0
  175. package/src/server-process-builder.ts +10 -1
  176. package/src/state-helpers.ts +6 -0
  177. package/src/subprocess-env.ts +3 -0
  178. package/src/tool-arguments.ts +4 -2
  179. package/src/tool-renderers.ts +6 -0
  180. package/src/turn-semantics.ts +15 -2
  181. package/src/types.ts +212 -30
  182. package/src/ui-process-builder.ts +8 -1
  183. package/src/worker-process-builder.ts +8 -1
  184. package/dist/chunk-LIIP7FMU.js.map +0 -1
  185. package/dist/chunk-TA4KO53Q.js.map +0 -1
  186. package/dist/chunk-WFY2WWZE.js.map +0 -1
@@ -21,38 +21,42 @@ import {
21
21
  RESERVED_INTEGRATION_TOOL_NAMES,
22
22
  } from "./types.js";
23
23
 
24
+ /** @internal */
24
25
  export function isLlmTurnDefinition<TParams = unknown, TState = unknown>(
25
26
  turnDef: TurnDefinition<TParams, TState>,
26
27
  ): turnDef is LlmTurnDefinition<string, TParams, TState> {
27
28
  return turnDef.kind === "llm";
28
29
  }
29
30
 
31
+ /** @internal */
30
32
  export function isAutomaticTurnDefinition<TParams = unknown, TState = unknown>(
31
33
  turnDef: TurnDefinition<TParams, TState>,
32
34
  ): turnDef is AutomaticTurnDefinition<string, TParams, TState> {
33
35
  return turnDef.kind === "automatic";
34
36
  }
35
37
 
38
+ /** @internal */
36
39
  export function isHumanTurnDefinition<TParams = unknown, TState = unknown>(
37
40
  turnDef: TurnDefinition<TParams, TState>,
38
41
  ): turnDef is HumanTurnDefinition<TParams, TState> {
39
42
  return turnDef.kind === "human";
40
43
  }
41
44
 
45
+ /** @internal */
42
46
  export function isExternalTurnDefinition<TParams = unknown, TState = unknown>(
43
47
  turnDef: TurnDefinition<TParams, TState>,
44
48
  ): turnDef is ExternalTurnDefinition<TParams, TState> {
45
49
  return turnDef.kind === "external";
46
50
  }
47
51
 
48
- export { defaultProcessTurnStartSelection as defaultTurnStartSelection } from "@leitwerk-dev/domain";
49
-
52
+ /** @internal */
50
53
  export function resolveLlmTurnStartSelection<TOutcome extends string = string>(
51
54
  turnDef: Pick<LlmTurnDefinition<TOutcome>, "branchType" | "startFrom">,
52
55
  ): ProcessTurnStartSelection {
53
56
  return resolveProcessTurnStartSelection(turnDef);
54
57
  }
55
58
 
59
+ /** @internal */
56
60
  export function resolveLlmTurnRestorePrimaryLeafAfterTurn<TOutcome extends string = string>(
57
61
  turnDef: Pick<LlmTurnDefinition<TOutcome>, "branchType" | "restorePrimaryLeafAfterTurn">,
58
62
  ): boolean {
@@ -210,6 +214,7 @@ function validateTurnStartSelection(
210
214
  return errors;
211
215
  }
212
216
 
217
+ /** @internal */
213
218
  export function validateLlmTurnDefinition<
214
219
  TOutcome extends string = string,
215
220
  TParams = unknown,
@@ -320,6 +325,7 @@ export function validateLlmTurnDefinition<
320
325
  return errors;
321
326
  }
322
327
 
328
+ /** @internal */
323
329
  export function validateAutomaticTurnDefinition<
324
330
  TOutcome extends string = string,
325
331
  TParams = unknown,
@@ -331,6 +337,7 @@ export function validateAutomaticTurnDefinition<
331
337
  ];
332
338
  }
333
339
 
340
+ /** @internal */
334
341
  export function validateHumanTurnDefinition<TParams = unknown, TState = unknown>(
335
342
  turnId: string,
336
343
  turnDef: HumanTurnDefinition<TParams, TState>,
@@ -440,6 +447,7 @@ export function validateHumanTurnDefinition<TParams = unknown, TState = unknown>
440
447
  return errors;
441
448
  }
442
449
 
450
+ /** @internal */
443
451
  export function validateExternalTurnDefinition<TParams = unknown, TState = unknown>(
444
452
  turnId: string,
445
453
  turnDef: ExternalTurnDefinition<TParams, TState>,
@@ -467,13 +475,16 @@ export function validateExternalTurnDefinition<TParams = unknown, TState = unkno
467
475
  return errors;
468
476
  }
469
477
 
478
+ /** @internal */
470
479
  export function validateTurnDefinition<TParams = unknown, TState = unknown>(
471
480
  turnId: string,
472
481
  turnDef: TurnDefinition<TParams, TState>,
473
482
  ): string[];
483
+ /** @internal */
474
484
  export function validateTurnDefinition<TParams = unknown, TState = unknown>(
475
485
  turnDef: TurnDefinition<TParams, TState>,
476
486
  ): string[];
487
+ /** @internal */
477
488
  export function validateTurnDefinition<TParams = unknown, TState = unknown>(
478
489
  turnIdOrDef: string | TurnDefinition<TParams, TState>,
479
490
  turnDef?: TurnDefinition<TParams, TState>,
@@ -495,6 +506,7 @@ export function validateTurnDefinition<TParams = unknown, TState = unknown>(
495
506
  : validateExternalTurnDefinition(effectiveTurnId, effectiveTurnDef);
496
507
  }
497
508
 
509
+ /** @internal */
498
510
  export function assertValidLlmTurnDefinition<
499
511
  TOutcome extends string = string,
500
512
  TParams = unknown,
@@ -503,6 +515,7 @@ export function assertValidLlmTurnDefinition<
503
515
  assertNoValidationErrors(validateLlmTurnDefinition(turnId, turnDef));
504
516
  }
505
517
 
518
+ /** @internal */
506
519
  export function createRootBranchReviewTurn<
507
520
  TOutcome extends string,
508
521
  TParams = unknown,
package/src/types.ts CHANGED
@@ -1,31 +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";
10
7
  import type { UsageCostSnapshot, UsageTokenCounts } from "@leitwerk-dev/protocol";
11
8
 
12
- export interface ProcessContext {
13
- readonly process: ProcessInstance;
14
- readonly selectedTurnId: TurnId | null;
15
- readonly isTerminal: boolean;
16
- readonly projects: readonly ProcessProject[];
17
- selectTurn(turnId: TurnId | null): void;
18
- }
19
-
9
+ /** @internal */
20
10
  export interface TurnOptions {
11
+ /** @internal */
21
12
  reset?: boolean;
22
13
  }
23
14
 
15
+ /** @internal */
24
16
  export interface TurnResult<T extends string = string> {
17
+ /** @internal */
25
18
  outcome: T;
19
+ /** @internal */
26
20
  params: Record<string, unknown>;
27
21
  }
28
22
 
23
+ /** @public */
29
24
  export const PI_BUILT_IN_TOOL_NAMES = [
30
25
  "read",
31
26
  "bash",
@@ -35,118 +30,166 @@ export const PI_BUILT_IN_TOOL_NAMES = [
35
30
  "find",
36
31
  "ls",
37
32
  ] as const;
33
+ /** @public */
38
34
  export type PiBuiltInToolName = (typeof PI_BUILT_IN_TOOL_NAMES)[number];
39
35
 
40
- /** 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 */
41
37
  export const FRAMEWORK_LLM_TOOL_NAMES = [
42
38
  "ask_questions",
43
39
  "markdown_result",
44
40
  "upload_result_images",
45
41
  ] as const;
46
42
 
47
- /** 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 */
48
44
  export const RESERVED_INTEGRATION_TOOL_NAMES = [
49
45
  ...PI_BUILT_IN_TOOL_NAMES,
50
46
  ...FRAMEWORK_LLM_TOOL_NAMES,
51
47
  ] as const;
52
48
 
49
+ /** @public */
53
50
  export interface ProcessPiConfig {
54
51
  /**
55
52
  * System prompt template. Rendered with Mustache against runtime context.
56
53
  * Use {{variableName}} for escaped values and {{{variableName}}} for raw values.
57
54
  * When omitted, Pi's default system prompt is used.
58
55
  */
56
+ /** @internal */
59
57
  systemPromptTemplate?: string;
60
58
  /**
61
59
  * Additional text appended after the base system prompt/resources. Rendered
62
60
  * with Mustache against runtime context.
63
61
  */
62
+ /** @public */
64
63
  appendSystemPromptTemplate?: string;
65
64
  /**
66
65
  * Code-defined Pi session working directory template. Rendered with Mustache
67
66
  * against runtime context. When omitted, the process workspace root is used.
68
67
  */
68
+ /** @public */
69
69
  sessionCwdTemplate?: string;
70
70
  }
71
71
 
72
+ /** @internal */
72
73
  export interface ResolvedProcessPiConfig {
74
+ /** @internal */
73
75
  systemPrompt?: string;
76
+ /** @internal */
74
77
  appendSystemPrompt?: string;
78
+ /** @internal */
75
79
  sessionCwd?: string;
80
+ /** @internal */
76
81
  availableToolNames: string[];
77
82
  }
78
83
 
84
+ /** @internal */
79
85
  export type OutcomeToolParameterType = "string" | "number" | "array" | "boolean" | "object";
86
+ /** @internal */
80
87
  export type OutcomeToolArrayItemType = Exclude<OutcomeToolParameterType, "array">;
81
88
 
89
+ /** @internal */
82
90
  export interface OutcomeToolArrayItemSpec {
91
+ /** @internal */
83
92
  type: OutcomeToolArrayItemType;
93
+ /** @internal */
84
94
  description?: string;
85
95
  }
86
96
 
97
+ /** @public */
87
98
  export interface OutcomeToolParameterSpec {
99
+ /** @internal */
88
100
  type: OutcomeToolParameterType;
101
+ /** @internal */
89
102
  description: string;
103
+ /** @internal */
90
104
  required?: boolean;
105
+ /** @internal */
91
106
  requiredErrorCode?: string;
107
+ /** @internal */
92
108
  invalidErrorCode?: string;
109
+ /** @internal */
93
110
  minItems?: number;
111
+ /** @internal */
94
112
  minItemsErrorCode?: string;
113
+ /** @internal */
95
114
  minimum?: number;
115
+ /** @internal */
96
116
  minimumErrorCode?: string;
117
+ /** @internal */
97
118
  items?: OutcomeToolArrayItemSpec;
119
+ /** @internal */
98
120
  enum?: readonly string[];
99
121
  }
100
122
 
123
+ /** @internal */
101
124
  export interface OutcomeToolSpec {
125
+ /** @internal */
102
126
  description: string;
127
+ /** @internal */
103
128
  parameters: Record<string, OutcomeToolParameterSpec>;
104
- /** Product published from this outcome's turn-result markdown, when selected. */
129
+ /** Product published from this outcome's turn-result markdown, when selected. @internal */
105
130
  publishedProduct?: string;
106
- /** Outcome parameter whose markdown value is captured as the turn result. */
131
+ /** Outcome parameter whose markdown value is captured as the turn result. @internal */
107
132
  turnResultMarkdownParameter?: string;
108
- /** Outcome parameter containing a concise operator-facing summary. */
133
+ /** Outcome parameter containing a concise operator-facing summary. @internal */
109
134
  resultSummaryParameter?: string;
110
135
  }
111
136
 
112
- export interface ProcessToolResult {
113
- status: string;
114
- outcome?: string;
115
- }
116
-
137
+ /** @public */
117
138
  export interface PiTreeEntry {
139
+ /** @internal */
118
140
  readonly id: string;
141
+ /** @internal */
119
142
  readonly parentId: string | null;
143
+ /** @public */
120
144
  readonly type: string;
145
+ /** @internal */
121
146
  readonly timestamp: string;
147
+ /** @public */
122
148
  readonly message?: {
149
+ /** @internal */
123
150
  readonly role?: string;
151
+ /** @public */
124
152
  readonly content?: unknown;
125
153
  };
126
- /** Pi custom-message fields. Details are intentionally excluded from model context. */
154
+ /** Pi custom-message fields. Details are intentionally excluded from model context. @internal */
127
155
  readonly customType?: string;
156
+ /** @public */
128
157
  readonly content?: unknown;
158
+ /** @internal */
129
159
  readonly details?: unknown;
160
+ /** @internal */
130
161
  readonly targetId?: string;
162
+ /** @internal */
131
163
  readonly label?: string;
132
164
  }
133
165
 
166
+ /** @internal */
134
167
  export interface PiTreeNode {
168
+ /** @internal */
135
169
  readonly entry: PiTreeEntry;
170
+ /** @internal */
136
171
  readonly children: readonly PiTreeNode[];
172
+ /** @internal */
137
173
  readonly label?: string;
174
+ /** @internal */
138
175
  readonly labelTimestamp?: string;
139
176
  }
140
177
 
178
+ /** @public */
141
179
  export interface PiTurnExecutionResult {
180
+ /** @internal */
142
181
  startLeafId: string | null;
182
+ /** @internal */
143
183
  endLeafId: string | null;
184
+ /** @internal */
144
185
  createdEntryIds: string[];
186
+ /** @internal */
145
187
  resultEntryId: string;
146
- /** 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 */
147
189
  assistantMarkdown?: string | null;
148
190
  }
149
191
 
192
+ /** @internal */
150
193
  export type PiEventType =
151
194
  | "turn.start"
152
195
  | "turn.end"
@@ -165,80 +208,134 @@ export type PiEventType =
165
208
  | "retry.end"
166
209
  | "usage";
167
210
 
211
+ /** @internal */
168
212
  export interface PiEvent {
213
+ /** @internal */
169
214
  type: PiEventType;
215
+ /** @internal */
170
216
  turnId: string;
217
+ /** @internal */
171
218
  data: Record<string, unknown>;
219
+ /** @internal */
172
220
  timestamp: string;
173
221
  }
174
222
 
223
+ /** @internal */
175
224
  export type PiEventHandler = (event: PiEvent) => void;
176
225
 
226
+ /** @internal */
177
227
  export type PiSessionDiagnosticLevel = "debug" | "info" | "warn" | "error";
178
228
 
229
+ /** @internal */
179
230
  export interface PiSessionDiagnostic {
231
+ /** @internal */
180
232
  level: PiSessionDiagnosticLevel;
233
+ /** @internal */
181
234
  code: string;
235
+ /** @internal */
182
236
  message: string;
237
+ /** @internal */
183
238
  timestamp: string;
239
+ /** @internal */
184
240
  turnId?: string;
241
+ /** @internal */
185
242
  details?: Record<string, unknown>;
186
243
  }
187
244
 
245
+ /** @internal */
188
246
  export type PiSessionDiagnosticHandler = (diagnostic: PiSessionDiagnostic) => void;
189
247
 
248
+ /** @public */
190
249
  export interface PiCustomToolExecutionContext {
191
- /** 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 */
192
251
  toolCallId: string;
193
- /** Aborted when the active turn is stopped or torn down. */
252
+ /** Aborted when the active turn is stopped or torn down. @public */
194
253
  signal: AbortSignal;
195
- /** 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 */
196
255
  suspendPromptGuards?: () => () => void;
197
256
  }
198
257
 
258
+ /** @public */
199
259
  export interface PiCustomTool {
260
+ /** @public */
200
261
  name: string;
262
+ /** @internal */
201
263
  description: string;
264
+ /** @internal */
202
265
  parameters: Record<string, unknown>;
266
+ /** @internal */
203
267
  executionMode?: "sequential" | "parallel";
268
+ /** @public */
204
269
  execute(args: Record<string, unknown>, context?: PiCustomToolExecutionContext): Promise<unknown>;
205
270
  }
206
271
 
272
+ /** @internal */
207
273
  export interface PiUsageData extends UsageTokenCounts {
274
+ /** @internal */
208
275
  cost: UsageCostSnapshot;
276
+ /** @internal */
209
277
  cacheHitRate: number;
210
278
  }
211
279
 
280
+ /** @internal */
212
281
  export interface PiRunDetails {
213
- loadedAgentsFiles: Array<{ path: string; sizeBytes: number }>;
214
- 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 */
215
297
  availableToolNames: string[];
216
298
  }
217
299
 
300
+ /** @internal */
218
301
  export type ProcessCustomTool = PiCustomTool;
219
302
 
303
+ /** @public */
220
304
  export interface PiCustomMessageInput {
305
+ /** @internal */
221
306
  content: string;
307
+ /** @internal */
222
308
  details: unknown;
309
+ /** @internal */
223
310
  display?: boolean;
224
311
  }
225
312
 
313
+ /** @internal */
226
314
  export type PiTerminalAcknowledgementState =
227
315
  | "open"
228
316
  | "outcome_accepted"
229
317
  | "acknowledgement_succeeded"
230
318
  | "acknowledgement_failed_ignored";
231
319
 
320
+ /** @internal */
232
321
  export interface PiTerminalAcknowledgementControl {
322
+ /** @internal */
233
323
  readonly timeoutMs: number;
324
+ /** @internal */
234
325
  state(): PiTerminalAcknowledgementState;
326
+ /** @internal */
235
327
  isOperatorAbortRequested(): boolean;
328
+ /** @internal */
236
329
  markSucceeded(): void;
330
+ /** @internal */
237
331
  markFailed(reason: string): void;
238
332
  }
239
333
 
334
+ /** @public */
240
335
  export interface PiPromptOptions {
336
+ /** @public */
241
337
  tools?: readonly PiCustomTool[];
338
+ /** @internal */
242
339
  activeTools?: readonly string[];
243
340
  /** @internal Runtime-only hook used by the worker Pi adapter before a tool executes. */
244
341
  shouldBlockToolCall?: (toolName: string) => string | null;
@@ -248,145 +345,230 @@ export interface PiPromptOptions {
248
345
  terminalAcknowledgement?: PiTerminalAcknowledgementControl;
249
346
  }
250
347
 
348
+ /** @public */
251
349
  export interface PiTreeHandle {
350
+ /** @internal */
252
351
  readonly sessionId: string;
352
+ /** @internal */
253
353
  readonly treeFile: string;
354
+ /** @internal */
254
355
  readonly isResumed: boolean;
255
356
 
357
+ /** @internal */
256
358
  getRunDetails(): PiRunDetails;
359
+ /** @internal */
257
360
  getLeafId(): string | null;
361
+ /** @internal */
258
362
  getEntry(id: string): PiTreeEntry | undefined;
363
+ /** @internal */
259
364
  getBranch(fromId?: string): PiTreeEntry[];
365
+ /** @internal */
260
366
  getChildren(parentId: string): PiTreeEntry[];
367
+ /** @internal */
261
368
  getTree(): PiTreeNode[];
369
+ /** @internal */
262
370
  branch(entryId: string): void | Promise<void>;
371
+ /** @internal */
263
372
  branchFromRoot(): void | Promise<void>;
373
+ /** @internal */
264
374
  resetLeaf(): void | Promise<void>;
265
375
  /**
266
376
  * Compact the current Pi context. `details` is persisted with the resulting
267
377
  * compaction entry, but deliberately remains outside model context.
268
378
  */
379
+ /** @internal */
269
380
  compact?(customInstructions?: string, details?: unknown): Promise<unknown>;
381
+ /** @public */
270
382
  prompt(text: string, options?: PiPromptOptions): Promise<PiTurnExecutionResult>;
383
+ /** @public */
271
384
  promptLiteral(text: string, options?: PiPromptOptions): Promise<PiTurnExecutionResult>;
385
+ /** @public */
272
386
  promptCustom(
273
387
  input: PiCustomMessageInput,
274
388
  options?: PiPromptOptions,
275
389
  ): Promise<PiTurnExecutionResult>;
390
+ /** @public */
276
391
  continueTurn(options?: PiPromptOptions): Promise<PiTurnExecutionResult>;
392
+ /** @internal */
277
393
  appendCustomMessage?(input: PiCustomMessageInput): Promise<string>;
394
+ /** @internal */
278
395
  steer(text: string): Promise<void>;
396
+ /** @internal */
279
397
  abortTurn(): Promise<void>;
398
+ /** @internal */
280
399
  subscribe(handler: PiEventHandler): () => void;
400
+ /** @internal */
281
401
  subscribeDiagnostics?(handler: PiSessionDiagnosticHandler): () => void;
402
+ /** @internal */
282
403
  close(): Promise<void>;
283
404
  }
284
405
 
406
+ /** @public */
285
407
  export const TURN_CONTEXT_MODES = ["full", "compacted", "fresh", "fresh_seeded"] as const;
408
+ /** @public */
286
409
  export type TurnContextMode = (typeof TURN_CONTEXT_MODES)[number];
287
410
 
411
+ /** @public */
288
412
  export const TURN_COMPLETION_MODES = ["turn_end"] as const;
413
+ /** @public */
289
414
  export type TurnCompletionMode = (typeof TURN_COMPLETION_MODES)[number];
290
415
 
416
+ /** @public */
291
417
  export type TurnBranchType = ProcessTurnRecordPathType;
292
- export type TurnSemanticEntryRefKey = DomainProcessSemanticEntryRefKey;
293
418
 
419
+ /** @public */
294
420
  export interface TurnResultMarkdownNoneBehavior {
421
+ /** @internal */
295
422
  mode: "none";
296
423
  }
297
424
 
425
+ /** @public */
298
426
  export interface TurnResultMarkdownAssistantOutputBehavior {
427
+ /** @internal */
299
428
  mode: "assistant_output";
429
+ /** @internal */
300
430
  required?: boolean;
301
431
  }
302
432
 
433
+ /** @public */
303
434
  export interface TurnResultMarkdownToolCallBehavior {
435
+ /** @internal */
304
436
  mode: "tool_call";
437
+ /** @internal */
305
438
  toolName: string;
439
+ /** @internal */
306
440
  source?: "arguments" | "result";
441
+ /** @internal */
307
442
  path: string;
443
+ /** @internal */
308
444
  required?: boolean;
309
445
  }
310
446
 
447
+ /** @public */
311
448
  export interface TurnResultMarkdownOutcomeToolArgumentBehavior {
449
+ /** @internal */
312
450
  mode: "outcome_tool_argument";
451
+ /** @internal */
313
452
  parameterName: string;
453
+ /** @internal */
314
454
  required?: boolean;
315
455
  }
316
456
 
457
+ /** @public */
317
458
  export type TurnResultMarkdownBehavior =
318
459
  | TurnResultMarkdownNoneBehavior
319
460
  | TurnResultMarkdownAssistantOutputBehavior
320
461
  | TurnResultMarkdownToolCallBehavior
321
462
  | TurnResultMarkdownOutcomeToolArgumentBehavior;
322
463
 
464
+ /** @public */
323
465
  export type TurnAcceptanceState = DomainTurnAcceptanceState;
324
466
 
467
+ /** @public */
325
468
  export interface ProcessActionSchedulingFixedTurnPreview {
469
+ /** @public */
326
470
  kind: "fixed_turn";
471
+ /** @public */
327
472
  turnId: TurnId | null;
328
473
  }
329
474
 
475
+ /** @public */
330
476
  export interface ProcessActionSchedulingTriggerPreview {
477
+ /** @public */
331
478
  kind: "trigger";
479
+ /** @internal */
332
480
  trigger: string;
333
481
  }
334
482
 
483
+ /** @public */
335
484
  export interface ProcessActionSchedulingTerminalPreview {
485
+ /** @public */
336
486
  kind: "terminal";
487
+ /** @internal */
337
488
  lifecycleStatus: ProcessTurnTerminalLifecycleStatus;
338
489
  }
339
490
 
491
+ /** @public */
340
492
  export type ProcessActionSchedulingPreview =
341
493
  | ProcessActionSchedulingFixedTurnPreview
342
494
  | ProcessActionSchedulingTriggerPreview
343
495
  | ProcessActionSchedulingTerminalPreview;
344
496
 
497
+ /** @public */
345
498
  export type ProcessActionPreviewDefinition = ProcessActionSchedulingPreview;
346
499
 
500
+ /** @internal */
347
501
  export interface ProcessActionSchedulingDefinition {
502
+ /** @internal */
348
503
  preview: ProcessActionSchedulingPreview;
349
504
  }
350
505
 
506
+ /** @internal */
351
507
  export interface HumanTurnActionView {
508
+ /** @internal */
352
509
  actionId: string;
510
+ /** @internal */
353
511
  acceptanceState: TurnAcceptanceState;
512
+ /** @internal */
354
513
  label?: string;
514
+ /** @internal */
355
515
  description?: string;
516
+ /** @internal */
356
517
  preview?: ProcessActionPreviewDefinition;
518
+ /** @internal */
357
519
  scheduling?: ProcessActionSchedulingDefinition;
358
520
  }
359
521
 
522
+ /** @internal */
360
523
  export interface HumanTurnNotesField {
524
+ /** @internal */
361
525
  id: string;
526
+ /** @internal */
362
527
  label: string;
528
+ /** @internal */
363
529
  description?: string;
530
+ /** @internal */
364
531
  placeholder?: string;
532
+ /** @internal */
365
533
  required?: boolean;
366
534
  }
367
535
 
536
+ /** @internal */
368
537
  export interface HumanTurnExternalTrigger {
538
+ /** @internal */
369
539
  id: string;
540
+ /** @internal */
370
541
  actionId: string;
542
+ /** @internal */
371
543
  label: string;
544
+ /** @internal */
372
545
  description: string;
373
546
  }
374
547
 
548
+ /** @internal */
375
549
  export interface HumanTurnExternalActionView {
376
- /** Process-local arming id exposed to providers and UI. */
550
+ /** Process-local arming id exposed to providers and UI. @internal */
377
551
  id: string;
552
+ /** @internal */
378
553
  externalActionId: string;
554
+ /** @internal */
379
555
  sourceKind: string;
556
+ /** @internal */
380
557
  label: string | null;
558
+ /** @internal */
381
559
  description: string | null;
382
560
  }
383
561
 
562
+ /** @internal */
384
563
  export interface EventBus<TEventMap extends object = Record<string, unknown>> {
564
+ /** @internal */
385
565
  emit<K extends keyof TEventMap & string>(event: K, data: TEventMap[K]): void;
566
+ /** @internal */
386
567
  on<K extends keyof TEventMap & string>(
387
568
  event: K,
388
569
  handler: (data: TEventMap[K]) => void | Promise<void>,
389
570
  ): void;
571
+ /** @internal */
390
572
  off<K extends keyof TEventMap & string>(
391
573
  event: K,
392
574
  handler: (data: TEventMap[K]) => void | Promise<void>,