@pasko70/pibo 1.16.6 → 2.1.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 (156) hide show
  1. package/dist/agent-runtime/auth.js +28 -0
  2. package/dist/agent-runtime/capabilities.js +221 -0
  3. package/dist/agent-runtime/context-build.js +313 -0
  4. package/dist/agent-runtime/contract.js +45 -0
  5. package/dist/agent-runtime/errors.js +57 -0
  6. package/dist/agent-runtime/events.js +1 -0
  7. package/dist/agent-runtime/history.js +1 -0
  8. package/dist/agent-runtime/profile-validation.js +109 -0
  9. package/dist/agent-runtime/registry.js +608 -0
  10. package/dist/agent-runtime/resource-files.js +87 -0
  11. package/dist/agent-runtime/resource-service.js +635 -0
  12. package/dist/agent-runtime/resources.js +1 -0
  13. package/dist/agent-runtime/routed-session.js +931 -0
  14. package/dist/agent-runtime/testing/contract.js +51 -0
  15. package/dist/agent-runtime/testing/fake-adapter.js +192 -0
  16. package/dist/agent-runtime/types.js +3 -0
  17. package/dist/agent-runtimes/codex-native/adapter.js +905 -0
  18. package/dist/agent-runtimes/codex-native/auth.js +476 -0
  19. package/dist/agent-runtimes/codex-native/client.js +734 -0
  20. package/dist/agent-runtimes/codex-native/config.js +152 -0
  21. package/dist/agent-runtimes/codex-native/history.js +283 -0
  22. package/dist/agent-runtimes/codex-native/mcp-stdio-launcher.js +89 -0
  23. package/dist/agent-runtimes/codex-native/models.js +581 -0
  24. package/dist/agent-runtimes/codex-native/process.js +459 -0
  25. package/dist/agent-runtimes/codex-native/protocol-types.js +1 -0
  26. package/dist/agent-runtimes/codex-native/protocol-version.js +7 -0
  27. package/dist/agent-runtimes/codex-native/redaction.js +31 -0
  28. package/dist/agent-runtimes/codex-native/requests.js +378 -0
  29. package/dist/agent-runtimes/codex-native/resource-delivery.js +445 -0
  30. package/dist/agent-runtimes/codex-native/thread.js +388 -0
  31. package/dist/agent-runtimes/codex-native/turn.js +849 -0
  32. package/dist/agent-runtimes/omp/adapter.js +581 -0
  33. package/dist/agent-runtimes/omp/auth.js +109 -0
  34. package/dist/agent-runtimes/omp/client.js +460 -0
  35. package/dist/agent-runtimes/omp/config.js +188 -0
  36. package/dist/agent-runtimes/omp/history.js +108 -0
  37. package/dist/agent-runtimes/omp/host-tools.js +201 -0
  38. package/dist/agent-runtimes/omp/models.js +86 -0
  39. package/dist/agent-runtimes/omp/process.js +283 -0
  40. package/dist/agent-runtimes/omp/protocol-types.js +17 -0
  41. package/dist/agent-runtimes/omp/resource-delivery.js +162 -0
  42. package/dist/agent-runtimes/omp/thread.js +141 -0
  43. package/dist/agent-runtimes/omp/turn.js +325 -0
  44. package/dist/agent-runtimes/pi/adapter.js +653 -0
  45. package/dist/agent-runtimes/pi/auth.js +455 -0
  46. package/dist/agent-runtimes/pi/history.js +640 -0
  47. package/dist/agent-runtimes/pi/model-catalog.js +87 -0
  48. package/dist/agent-runtimes/pi/routed-session.js +1464 -0
  49. package/dist/agent-runtimes/pi/runtime.js +534 -0
  50. package/dist/agent-runtimes/pi/tool-compiler.js +69 -0
  51. package/dist/apps/chat/agent-profiles.js +40 -23
  52. package/dist/apps/chat/agent-store.js +111 -64
  53. package/dist/apps/chat/chat-api-routes.js +1 -1
  54. package/dist/apps/chat/chat-request-normalizers.js +47 -0
  55. package/dist/apps/chat/data/chat-data-mappers.js +25 -9
  56. package/dist/apps/chat/data/history-query-service.js +108 -0
  57. package/dist/apps/chat/data/session-query-service.js +24 -3
  58. package/dist/apps/chat/data/timeline-query-service.js +3 -3
  59. package/dist/apps/chat/model-catalog.js +1 -55
  60. package/dist/apps/chat/provider-auth-actions.js +171 -23
  61. package/dist/apps/chat/stream.js +12 -0
  62. package/dist/apps/chat/trace-v2.js +1 -0
  63. package/dist/apps/chat/trace.js +126 -415
  64. package/dist/apps/chat/web-app.js +582 -157
  65. package/dist/apps/chat-ui/assets/{dist-BTLtT_Vf.js → dist-9v2ZXT6V.js} +1 -1
  66. package/dist/apps/chat-ui/assets/{dist-CMk1aPug.js → dist-B1LVAytl.js} +1 -1
  67. package/dist/apps/chat-ui/assets/{dist-CcwA_IWN.js → dist-C6LPDFXU.js} +1 -1
  68. package/dist/apps/chat-ui/assets/{dist-DKOthbxr.js → dist-DVtXxfHc.js} +1 -1
  69. package/dist/apps/chat-ui/assets/{dist-ls2I6BIw.js → dist-DW4Qrfbd.js} +1 -1
  70. package/dist/apps/chat-ui/assets/{dist-D1rAtRWs.js → dist-DmbsHdMC.js} +1 -1
  71. package/dist/apps/chat-ui/assets/{dist-C1JQRskW.js → dist-DyvwuSFO.js} +1 -1
  72. package/dist/apps/chat-ui/assets/{dist-DfpaylQ-.js → dist-I26VB0QO.js} +1 -1
  73. package/dist/apps/chat-ui/assets/{dist-D10bTFD5.js → dist-RtHbJRPV.js} +1 -1
  74. package/dist/apps/chat-ui/assets/{dist-5KpmmBBZ.js → dist-sZgJkWZb.js} +1 -1
  75. package/dist/apps/chat-ui/assets/index-BPbNvcZe.css +1 -0
  76. package/dist/apps/chat-ui/assets/index-CIOf2uL2.js +237 -0
  77. package/dist/apps/chat-ui/index.html +2 -2
  78. package/dist/apps/chat-vscode-web/assets/index-1ivRyjFs.js +41 -0
  79. package/dist/apps/chat-vscode-web/index.html +1 -1
  80. package/dist/auth/login-actions.js +5 -251
  81. package/dist/cli-session/localSessionSource.js +8 -1
  82. package/dist/core/context-build.js +124 -20
  83. package/dist/core/default-profile.js +8 -0
  84. package/dist/core/profiles.js +30 -3
  85. package/dist/core/routed-session.js +5 -1446
  86. package/dist/core/runtime.js +5 -561
  87. package/dist/core/session-router.js +637 -83
  88. package/dist/data/cli.js +20 -3
  89. package/dist/data/schema.js +104 -1
  90. package/dist/data/session-store.js +24 -1
  91. package/dist/debug/events.js +25 -10
  92. package/dist/debug/failures.js +23 -3
  93. package/dist/debug/index.js +24 -6
  94. package/dist/debug/messages.js +87 -7
  95. package/dist/debug/persisted-payloads.js +31 -0
  96. package/dist/debug/pty.js +7 -6
  97. package/dist/debug/runtime-binding.js +29 -0
  98. package/dist/debug/session.js +137 -0
  99. package/dist/debug/summary.js +12 -0
  100. package/dist/debug/telemetry.js +28 -0
  101. package/dist/debug/tools.js +12 -2
  102. package/dist/debug/trace.js +154 -76
  103. package/dist/gateway/server.js +87 -2
  104. package/dist/gateway/tool.js +5 -5
  105. package/dist/index.js +21 -2
  106. package/dist/loops/tools.js +13 -12
  107. package/dist/mcp/agent-context.js +13 -4
  108. package/dist/mcp/client.js +10 -6
  109. package/dist/mcp/config.js +5 -2
  110. package/dist/mcp/runtime-session.js +166 -0
  111. package/dist/plugins/builtin.js +193 -53
  112. package/dist/plugins/codex-native.js +29 -0
  113. package/dist/plugins/omp.js +57 -0
  114. package/dist/plugins/registry.js +66 -2
  115. package/dist/runs/tools.js +26 -25
  116. package/dist/session-ui/terminalRows.js +2 -2
  117. package/dist/sessions/pibo-data-store.js +125 -16
  118. package/dist/sessions/runtime-binding.js +107 -0
  119. package/dist/sessions/sqlite-store.js +239 -18
  120. package/dist/sessions/store.js +86 -7
  121. package/dist/shared/trace-engine.js +18 -9
  122. package/dist/shared/trace-event-projection.js +29 -11
  123. package/dist/shared/{trace-transcript.js → trace-history.js} +193 -195
  124. package/dist/shared/trace-order.js +9 -4
  125. package/dist/shared/trace-page-merge.js +1 -1
  126. package/dist/signals/projector.js +20 -2
  127. package/dist/signals/registry.js +11 -0
  128. package/dist/subagents/tool.js +8 -6
  129. package/dist/tools/codex-browser.js +20 -19
  130. package/dist/tools/codex-compat.js +10 -9
  131. package/dist/tools/codex-image-generation.js +8 -6
  132. package/dist/tools/contract.js +45 -0
  133. package/dist/tools/credential-registry.js +182 -0
  134. package/dist/tools/mcp-bridge.js +511 -0
  135. package/dist/tools/payload-writer.js +17 -0
  136. package/dist/tools/runtime/tool.js +10 -9
  137. package/dist/tools/schema.js +9 -0
  138. package/dist/tools/session-service.js +193 -0
  139. package/dist/tools/session-tool-set.js +85 -0
  140. package/dist/web-annotations/tools.js +17 -16
  141. package/docs/README.md +11 -0
  142. package/package.json +3 -2
  143. package/skills/builtin/pibo-agent-runtime-adapter/SKILL.md +183 -0
  144. package/skills/builtin/pibo-agent-runtime-adapter/evals/README.md +10 -0
  145. package/skills/builtin/pibo-agent-runtime-adapter/evals/evals.json +45 -0
  146. package/skills/builtin/pibo-agent-runtime-adapter/evals/fixtures/orion-full-harness.md +60 -0
  147. package/skills/builtin/pibo-agent-runtime-adapter/evals/fixtures/relay-partial-harness.md +52 -0
  148. package/skills/builtin/pibo-agent-runtime-adapter/references/capabilities-and-designer.md +194 -0
  149. package/skills/builtin/pibo-agent-runtime-adapter/references/history-debug-and-security.md +213 -0
  150. package/skills/builtin/pibo-agent-runtime-adapter/references/interfaces-and-registration.md +214 -0
  151. package/skills/builtin/pibo-agent-runtime-adapter/references/lifecycle-bindings-and-events.md +193 -0
  152. package/skills/builtin/pibo-agent-runtime-adapter/references/portable-delivery-and-native-behavior.md +226 -0
  153. package/skills/builtin/pibo-agent-runtime-adapter/references/testing-migration-and-validation.md +256 -0
  154. package/dist/apps/chat-ui/assets/index-C2YI0xfw.js +0 -237
  155. package/dist/apps/chat-ui/assets/index-E0RmuCkY.css +0 -1
  156. package/dist/apps/chat-vscode-web/assets/index-D-tSsXLG.js +0 -41
@@ -0,0 +1,931 @@
1
+ import { PiboSteeringUnavailableError, } from "../core/events.js";
2
+ import { runtimeSessionErrorDetails } from "../core/session-errors.js";
3
+ import { isPiboThinkingLevel } from "../core/thinking.js";
4
+ import { AgentRuntimeCapabilityUnavailableError } from "./errors.js";
5
+ const RUN_REMINDER_CAPABILITY_TOOLS = new Set([
6
+ "pibo_run_status",
7
+ "pibo_run_wait",
8
+ "pibo_run_read",
9
+ "pibo_run_cancel",
10
+ "pibo_run_ack",
11
+ ]);
12
+ function errorMessage(error) {
13
+ return error instanceof Error ? error.message : String(error);
14
+ }
15
+ function promptSource(source) {
16
+ return source === "user" || source === "ui" ? "interactive" : "rpc";
17
+ }
18
+ function runtimeCapabilityError(session, capability) {
19
+ return new AgentRuntimeCapabilityUnavailableError(capability, session.runtimeInstanceId, `Runtime instance "${session.runtimeInstanceId}" does not support ${capability}.`);
20
+ }
21
+ function nativeSnapshotToPiCompatibility(session, snapshot) {
22
+ const nativeSessionId = snapshot.nativeSessionId;
23
+ if (!nativeSessionId)
24
+ throw runtimeCapabilityError(session, "a native session identifier");
25
+ return {
26
+ piSessionId: nativeSessionId,
27
+ sessionFile: snapshot.locator?.kind === "local-file" ? snapshot.locator.value : undefined,
28
+ leafId: snapshot.leafId ?? null,
29
+ cwd: snapshot.cwd,
30
+ sessionName: snapshot.name,
31
+ parentSessionFile: snapshot.parentLocator?.kind === "local-file"
32
+ ? snapshot.parentLocator.value
33
+ : undefined,
34
+ };
35
+ }
36
+ function nativeOperationToPiCompatibility(session, piboSessionId, result) {
37
+ return {
38
+ piboSessionId,
39
+ previous: nativeSnapshotToPiCompatibility(session, result.previous),
40
+ current: nativeSnapshotToPiCompatibility(session, result.current),
41
+ cancelled: result.cancelled,
42
+ selectedText: result.selectedText,
43
+ editorText: result.editorText,
44
+ summaryEntryId: result.summaryEntryId,
45
+ };
46
+ }
47
+ function nativeSessionInfoToPiCompatibility(session, info) {
48
+ if (!info.nativeSessionId)
49
+ throw runtimeCapabilityError(session, "native session listing identifiers");
50
+ return {
51
+ path: info.locator?.value ?? info.nativeSessionId,
52
+ id: info.nativeSessionId,
53
+ cwd: info.cwd,
54
+ name: info.name,
55
+ parentSessionPath: info.parentLocator?.value,
56
+ created: info.createdAt ?? "",
57
+ modified: info.updatedAt ?? info.createdAt ?? "",
58
+ messageCount: info.messageCount ?? 0,
59
+ firstMessage: info.firstMessage ?? "",
60
+ };
61
+ }
62
+ function isSessionOperationResult(value) {
63
+ if (!value || typeof value !== "object")
64
+ return false;
65
+ const candidate = value;
66
+ return typeof candidate.piboSessionId === "string"
67
+ && Boolean(candidate.current)
68
+ && typeof candidate.current?.piSessionId === "string";
69
+ }
70
+ export class RuntimeRoutedSession {
71
+ piboSessionId;
72
+ runtimeSession;
73
+ emit;
74
+ pluginRegistry;
75
+ options;
76
+ /** @deprecated Pi compatibility handle for existing direct test/TUI consumers. */
77
+ runtime;
78
+ queue = [];
79
+ processing = false;
80
+ disposed = false;
81
+ disposePromise;
82
+ runtimeDisposePromise;
83
+ forceDisposalStarted = false;
84
+ drainPromise;
85
+ activeMessage;
86
+ activeExecutionEvent;
87
+ activeMessageFailed = false;
88
+ activeAssistantIndex;
89
+ nextAssistantIndex = 0;
90
+ activeThinkingIndex;
91
+ nextThinkingIndex = 0;
92
+ unsubscribe;
93
+ constructor(piboSessionId, runtimeSession, emit, pluginRegistry, options = {}) {
94
+ this.piboSessionId = piboSessionId;
95
+ this.runtimeSession = runtimeSession;
96
+ this.emit = emit;
97
+ this.pluginRegistry = pluginRegistry;
98
+ this.options = options;
99
+ this.runtime = runtimeSession.getNativeCompatibilityHandle?.() ?? runtimeSession;
100
+ this.unsubscribe = runtimeSession.subscribe((event) => this.handleRuntimeEvent(event));
101
+ }
102
+ enqueueMessage(event) {
103
+ this.assertActive();
104
+ this.queue.push({ kind: "message", event });
105
+ const output = {
106
+ type: "message_queued",
107
+ piboSessionId: this.piboSessionId,
108
+ eventId: event.id,
109
+ queuedMessages: this.queue.length,
110
+ text: event.text,
111
+ source: event.source,
112
+ provenance: event.provenance,
113
+ };
114
+ this.emit(output);
115
+ this.notifyState();
116
+ this.startDrain();
117
+ return output;
118
+ }
119
+ async steerMessage(event) {
120
+ this.assertActive();
121
+ const activeMessage = this.activeMessage;
122
+ if (!activeMessage || !this.processing || !this.runtimeSession.getStatus().streaming || !this.runtimeSession.steer) {
123
+ throw new PiboSteeringUnavailableError();
124
+ }
125
+ try {
126
+ await this.runtimeSession.steer({
127
+ text: event.text,
128
+ source: promptSource(event.source),
129
+ capabilityScope: event.capabilityScope,
130
+ });
131
+ }
132
+ catch (error) {
133
+ throw new PiboSteeringUnavailableError(`The active session could not accept steering: ${errorMessage(error)}`, { cause: error });
134
+ }
135
+ const output = {
136
+ type: "message_steered",
137
+ piboSessionId: this.piboSessionId,
138
+ eventId: event.id,
139
+ activeEventId: activeMessage.id,
140
+ text: event.text,
141
+ source: event.source,
142
+ };
143
+ this.emit(output);
144
+ return output;
145
+ }
146
+ async executeAction(event) {
147
+ this.assertActive();
148
+ if (event.action === "compact")
149
+ return this.enqueueCompactAction(event);
150
+ const result = await this.runAction(event);
151
+ if (isSessionOperationResult(result))
152
+ await this.options.onSessionOperation?.(result, event);
153
+ const output = {
154
+ type: "execution_result",
155
+ piboSessionId: this.piboSessionId,
156
+ eventId: event.id,
157
+ action: event.action,
158
+ result,
159
+ };
160
+ this.emit(output);
161
+ return output;
162
+ }
163
+ getActiveMessage() {
164
+ if (!this.activeMessage)
165
+ return undefined;
166
+ return {
167
+ id: this.activeMessage.id,
168
+ source: this.activeMessage.source,
169
+ provenance: this.activeMessage.provenance,
170
+ };
171
+ }
172
+ getStatus() {
173
+ const status = this.runtimeSession.getStatus();
174
+ const binding = this.runtimeSession.getBinding();
175
+ const pendingApprovals = this.runtimeSession.pendingApprovals
176
+ ?? (this.runtimeSession.pendingApproval ? [this.runtimeSession.pendingApproval] : []);
177
+ const pendingUserInputs = this.runtimeSession.pendingUserInputs
178
+ ?? (this.runtimeSession.pendingUserInput ? [this.runtimeSession.pendingUserInput] : []);
179
+ const thinkingLevel = status.reasoning?.value && isPiboThinkingLevel(status.reasoning.value)
180
+ ? status.reasoning.value
181
+ : undefined;
182
+ return {
183
+ piboSessionId: this.piboSessionId,
184
+ runtimeBinding: {
185
+ runtimeInstanceId: binding.runtimeInstanceId,
186
+ adapterId: binding.adapterId,
187
+ nativeSessionId: binding.nativeSessionId,
188
+ state: binding.state,
189
+ protocol: binding.protocol,
190
+ protocolVersion: binding.protocolVersion,
191
+ adapterVersion: binding.adapterVersion,
192
+ revision: binding.revision,
193
+ },
194
+ queuedMessages: this.queue.length,
195
+ processing: this.disposed ? false : this.processing,
196
+ streaming: this.disposed ? false : status.streaming,
197
+ activeTools: [...status.enabledTools],
198
+ enabledTools: [...status.enabledTools],
199
+ cwd: status.cwd,
200
+ disposed: this.disposed,
201
+ thinkingLevel,
202
+ fastMode: status.fastMode?.mode === "fast",
203
+ retry: status.retry,
204
+ warnings: status.warnings,
205
+ errors: status.errors,
206
+ ...(pendingApprovals.length > 0
207
+ ? { pendingApprovals: pendingApprovals.map((request) => structuredClone(request)) }
208
+ : {}),
209
+ ...(pendingUserInputs.length > 0
210
+ ? { pendingUserInputs: pendingUserInputs.map((request) => structuredClone(request)) }
211
+ : {}),
212
+ };
213
+ }
214
+ async getStatusSnapshot() {
215
+ const status = this.runtimeSession.getStatusSnapshot
216
+ ? await this.runtimeSession.getStatusSnapshot()
217
+ : this.runtimeSession.getStatus();
218
+ return {
219
+ ...this.getStatus(),
220
+ activeModel: status.activeModel,
221
+ contextUsage: status.contextUsage,
222
+ providerUsage: status.providerUsage,
223
+ warnings: status.warnings,
224
+ errors: status.errors,
225
+ };
226
+ }
227
+ getContextUsage() {
228
+ return this.runtimeSession.getStatus().contextUsage;
229
+ }
230
+ getActiveModel() {
231
+ return this.runtimeSession.getStatus().activeModel;
232
+ }
233
+ getRuntimeBinding() {
234
+ return this.runtimeSession.getBinding();
235
+ }
236
+ async getProviderUsage() {
237
+ const status = this.runtimeSession.getStatusSnapshot
238
+ ? await this.runtimeSession.getStatusSnapshot()
239
+ : this.runtimeSession.getStatus();
240
+ return status.providerUsage;
241
+ }
242
+ getActionContextUsage() {
243
+ const usage = this.getContextUsage();
244
+ if (!usage)
245
+ return undefined;
246
+ return {
247
+ tokens: usage.tokens ?? null,
248
+ contextWindow: usage.contextWindow ?? null,
249
+ percent: usage.percent ?? null,
250
+ };
251
+ }
252
+ async getActionProviderUsage() {
253
+ const usage = await this.getProviderUsage();
254
+ if (!usage || typeof usage.fetchedAt !== "string")
255
+ return undefined;
256
+ return usage;
257
+ }
258
+ removeQueuedMessages(predicate) {
259
+ this.assertActive();
260
+ const removedMessages = [];
261
+ for (let index = this.queue.length - 1; index >= 0; index -= 1) {
262
+ const item = this.queue[index];
263
+ if (item.kind !== "message" || !predicate(item.event))
264
+ continue;
265
+ this.queue.splice(index, 1);
266
+ removedMessages.push(item.event);
267
+ }
268
+ removedMessages.reverse();
269
+ this.notifyMessagesInterrupted(removedMessages, "queued message removed");
270
+ return removedMessages.length;
271
+ }
272
+ getCurrentSession() {
273
+ const getCurrentSession = this.runtimeSession.controls?.getCurrentSession;
274
+ if (!getCurrentSession)
275
+ throw runtimeCapabilityError(this.runtimeSession, "native session inspection");
276
+ return nativeSnapshotToPiCompatibility(this.runtimeSession, getCurrentSession());
277
+ }
278
+ async listSessions() {
279
+ const listSessions = this.runtimeSession.controls?.listSessions;
280
+ if (!listSessions)
281
+ throw runtimeCapabilityError(this.runtimeSession, "native session listing");
282
+ return (await listSessions()).map((info) => nativeSessionInfoToPiCompatibility(this.runtimeSession, info));
283
+ }
284
+ getForkCandidates() {
285
+ const getForkCandidates = this.runtimeSession.controls?.getForkCandidates;
286
+ if (!getForkCandidates)
287
+ throw runtimeCapabilityError(this.runtimeSession, "native session fork candidates");
288
+ return getForkCandidates();
289
+ }
290
+ async forkSession(entryId) {
291
+ const forkSession = this.runtimeSession.controls?.forkSession;
292
+ if (!forkSession)
293
+ throw runtimeCapabilityError(this.runtimeSession, "native session fork");
294
+ return nativeOperationToPiCompatibility(this.runtimeSession, this.piboSessionId, await forkSession(entryId));
295
+ }
296
+ async cloneSession() {
297
+ const cloneSession = this.runtimeSession.controls?.cloneSession;
298
+ if (!cloneSession)
299
+ throw runtimeCapabilityError(this.runtimeSession, "native session clone");
300
+ return nativeOperationToPiCompatibility(this.runtimeSession, this.piboSessionId, await cloneSession());
301
+ }
302
+ getSessionTree() {
303
+ const getSessionTree = this.runtimeSession.controls?.getSessionTree;
304
+ if (!getSessionTree)
305
+ throw runtimeCapabilityError(this.runtimeSession, "native session tree");
306
+ const result = getSessionTree();
307
+ return {
308
+ current: nativeSnapshotToPiCompatibility(this.runtimeSession, result.current),
309
+ tree: result.tree,
310
+ };
311
+ }
312
+ async navigateSessionTree(params) {
313
+ const navigate = this.runtimeSession.controls?.navigateSessionTree;
314
+ if (!navigate)
315
+ throw runtimeCapabilityError(this.runtimeSession, "native session tree navigation");
316
+ return nativeOperationToPiCompatibility(this.runtimeSession, this.piboSessionId, await navigate(params));
317
+ }
318
+ async switchSession(params) {
319
+ const switchSession = this.runtimeSession.controls?.switchSession;
320
+ if (!switchSession)
321
+ throw runtimeCapabilityError(this.runtimeSession, "native session switching");
322
+ return nativeOperationToPiCompatibility(this.runtimeSession, this.piboSessionId, await switchSession(params));
323
+ }
324
+ async setModel(model) {
325
+ const setModel = this.runtimeSession.controls?.setModel;
326
+ if (!setModel)
327
+ throw runtimeCapabilityError(this.runtimeSession, "in-session model switching");
328
+ return await setModel(model);
329
+ }
330
+ setThinkingLevel(level) {
331
+ const setReasoning = this.runtimeSession.controls?.setReasoning;
332
+ if (!setReasoning)
333
+ throw runtimeCapabilityError(this.runtimeSession, "reasoning-level selection");
334
+ const result = setReasoning(level);
335
+ return {
336
+ level: typeof result.value === "string" && isPiboThinkingLevel(result.value) ? result.value : "off",
337
+ availableLevels: result.availableValues.filter(isPiboThinkingLevel),
338
+ supported: result.supported,
339
+ };
340
+ }
341
+ cycleThinkingLevel() {
342
+ const cycleReasoning = this.runtimeSession.controls?.cycleReasoning;
343
+ if (!cycleReasoning)
344
+ throw runtimeCapabilityError(this.runtimeSession, "reasoning-level cycling");
345
+ const result = cycleReasoning();
346
+ return {
347
+ level: typeof result.value === "string" && isPiboThinkingLevel(result.value) ? result.value : "off",
348
+ availableLevels: result.availableValues.filter(isPiboThinkingLevel),
349
+ supported: result.supported,
350
+ };
351
+ }
352
+ getFastMode() {
353
+ const getFastMode = this.runtimeSession.controls?.getFastMode;
354
+ return getFastMode ? getFastMode() : { mode: "normal", supported: false };
355
+ }
356
+ setFastMode(enabled) {
357
+ const setFastMode = this.runtimeSession.controls?.setFastMode;
358
+ if (!setFastMode)
359
+ return { mode: "normal", supported: false, changed: false };
360
+ const result = setFastMode(enabled);
361
+ return { ...result, changed: result.changed ?? false };
362
+ }
363
+ async compact(customInstructions) {
364
+ const compact = this.runtimeSession.controls?.compact;
365
+ if (!compact)
366
+ throw runtimeCapabilityError(this.runtimeSession, "compaction");
367
+ return await compact(customInstructions);
368
+ }
369
+ async respondToApproval(requestId, decision) {
370
+ const respond = this.runtimeSession.controls?.respondToApproval;
371
+ if (!respond)
372
+ throw runtimeCapabilityError(this.runtimeSession, "approval responses");
373
+ await respond(requestId, decision);
374
+ }
375
+ async respondToUserInput(requestId, answers) {
376
+ const respond = this.runtimeSession.controls?.respondToUserInput;
377
+ if (!respond)
378
+ throw runtimeCapabilityError(this.runtimeSession, "structured user-input responses");
379
+ await respond(requestId, answers);
380
+ }
381
+ async dispose() {
382
+ if (this.disposePromise)
383
+ return this.disposePromise;
384
+ this.disposePromise = this.disposeUnsafe();
385
+ return this.disposePromise;
386
+ }
387
+ forceDispose(reason = "session disposal timed out") {
388
+ this.transitionToDisposed(reason);
389
+ if (this.forceDisposalStarted)
390
+ return;
391
+ this.forceDisposalStarted = true;
392
+ void this.runtimeSession.abort().catch(() => { });
393
+ void this.disposeRuntime().catch(() => { });
394
+ }
395
+ async kill() {
396
+ this.notifyMessagesInterrupted(this.activeAndQueuedMessages(), "session killed");
397
+ this.queue.length = 0;
398
+ this.notifyState();
399
+ await this.runtimeSession.abort();
400
+ return this.piboSessionId;
401
+ }
402
+ async cancelMessage(eventId) {
403
+ this.assertActive();
404
+ const queuedIndex = this.queue.findIndex((item) => item.event.id === eventId);
405
+ if (queuedIndex >= 0) {
406
+ const [removed] = this.queue.splice(queuedIndex, 1);
407
+ if (removed?.kind === "message")
408
+ this.notifyMessagesInterrupted([removed.event], "message cancelled");
409
+ this.notifyState();
410
+ return true;
411
+ }
412
+ if (this.activeMessage?.id === eventId) {
413
+ this.notifyMessagesInterrupted([this.activeMessage], "message cancelled");
414
+ await this.runtimeSession.abort();
415
+ return true;
416
+ }
417
+ return false;
418
+ }
419
+ handleRuntimeEvent(event) {
420
+ switch (event.type) {
421
+ case "assistant_delta":
422
+ this.emit(this.withActiveMessage({
423
+ type: "assistant_delta",
424
+ piboSessionId: this.piboSessionId,
425
+ text: event.text,
426
+ contentIndex: event.contentIndex,
427
+ }));
428
+ return;
429
+ case "assistant_message":
430
+ this.emit(this.withActiveMessage({
431
+ type: "assistant_message",
432
+ piboSessionId: this.piboSessionId,
433
+ text: event.text,
434
+ contentIndex: event.contentIndex,
435
+ }));
436
+ return;
437
+ case "reasoning_started":
438
+ this.emit(this.withActiveMessage({
439
+ type: "thinking_started",
440
+ piboSessionId: this.piboSessionId,
441
+ contentIndex: event.contentIndex,
442
+ }));
443
+ return;
444
+ case "reasoning_delta":
445
+ this.emit(this.withActiveMessage({
446
+ type: "thinking_delta",
447
+ piboSessionId: this.piboSessionId,
448
+ text: event.text,
449
+ contentIndex: event.contentIndex,
450
+ }));
451
+ return;
452
+ case "reasoning_finished":
453
+ this.emit(this.withActiveMessage({
454
+ type: "thinking_finished",
455
+ piboSessionId: this.piboSessionId,
456
+ text: event.text,
457
+ contentIndex: event.contentIndex,
458
+ }));
459
+ return;
460
+ case "tool_call":
461
+ this.emit(this.withActiveMessage({ ...event, type: "tool_call", piboSessionId: this.piboSessionId }));
462
+ return;
463
+ case "tool_execution_started":
464
+ this.emit(this.withActiveMessage({ ...event, type: "tool_execution_started", piboSessionId: this.piboSessionId }));
465
+ return;
466
+ case "tool_execution_updated":
467
+ this.emit(this.withActiveMessage({ ...event, type: "tool_execution_updated", piboSessionId: this.piboSessionId }));
468
+ return;
469
+ case "tool_execution_finished":
470
+ this.emit(this.withActiveMessage({ ...event, type: "tool_execution_finished", piboSessionId: this.piboSessionId }));
471
+ return;
472
+ case "usage":
473
+ this.emit(this.withActiveMessage({
474
+ type: "assistant_usage",
475
+ piboSessionId: this.piboSessionId,
476
+ inputTokens: event.usage.inputTokens,
477
+ outputTokens: event.usage.outputTokens,
478
+ cacheReadTokens: event.usage.cacheReadTokens,
479
+ cacheWriteTokens: event.usage.cacheWriteTokens,
480
+ totalTokens: event.usage.totalTokens,
481
+ }));
482
+ return;
483
+ case "compaction_start":
484
+ this.emit(this.withActiveMessage({
485
+ type: "compaction_start",
486
+ piboSessionId: this.piboSessionId,
487
+ reason: event.reason,
488
+ }));
489
+ return;
490
+ case "compaction_end":
491
+ if (event.result && !event.aborted)
492
+ this.resetContentIndices();
493
+ this.emit(this.withActiveMessage({
494
+ type: "compaction_end",
495
+ piboSessionId: this.piboSessionId,
496
+ reason: event.reason,
497
+ result: event.result,
498
+ aborted: event.aborted,
499
+ errorMessage: event.errorMessage,
500
+ }));
501
+ return;
502
+ case "approval_requested":
503
+ this.emit(this.withActiveMessage({
504
+ type: "approval_requested",
505
+ piboSessionId: this.piboSessionId,
506
+ request: structuredClone(event.request),
507
+ }));
508
+ return;
509
+ case "approval_resolved":
510
+ this.emit(this.withActiveMessage({
511
+ type: "approval_resolved",
512
+ piboSessionId: this.piboSessionId,
513
+ requestId: event.requestId,
514
+ resolution: event.resolution,
515
+ }));
516
+ return;
517
+ case "user_input_requested":
518
+ this.emit(this.withActiveMessage({
519
+ type: "user_input_requested",
520
+ piboSessionId: this.piboSessionId,
521
+ request: structuredClone(event.request),
522
+ }));
523
+ return;
524
+ case "user_input_resolved":
525
+ this.emit(this.withActiveMessage({
526
+ type: "user_input_resolved",
527
+ piboSessionId: this.piboSessionId,
528
+ requestId: event.requestId,
529
+ resolution: event.resolution,
530
+ }));
531
+ return;
532
+ case "error":
533
+ this.emitRuntimeError(event.message, event.details);
534
+ return;
535
+ case "turn_failed":
536
+ this.emitRuntimeError(event.message, event.details);
537
+ return;
538
+ case "native_event":
539
+ this.options.onNativeEventTelemetry?.(this.piboSessionId, event.event, {
540
+ status: this.getStatus(),
541
+ activeEventId: this.activeMessage?.id ?? this.activeExecutionEvent?.id,
542
+ });
543
+ if (this.options.forwardLegacyPiEvents
544
+ && this.runtimeSession.compatibility?.productRawEventType === "pi_event") {
545
+ this.emit({ type: "pi_event", piboSessionId: this.piboSessionId, event: event.event });
546
+ }
547
+ return;
548
+ default:
549
+ return;
550
+ }
551
+ }
552
+ emitRuntimeError(message, details) {
553
+ if (this.activeMessageFailed)
554
+ return;
555
+ this.activeMessageFailed = true;
556
+ this.emit(this.withActiveMessage({
557
+ type: "session_error",
558
+ piboSessionId: this.piboSessionId,
559
+ error: message,
560
+ errorDetails: details ?? runtimeSessionErrorDetails(message),
561
+ provenance: this.activeMessage?.provenance,
562
+ }));
563
+ }
564
+ startDrain() {
565
+ if (this.drainPromise)
566
+ return;
567
+ const drain = this.drain();
568
+ this.drainPromise = drain;
569
+ void drain.finally(() => {
570
+ if (this.drainPromise === drain)
571
+ this.drainPromise = undefined;
572
+ });
573
+ }
574
+ async drain() {
575
+ if (this.processing || this.disposed)
576
+ return;
577
+ this.processing = true;
578
+ this.notifyState();
579
+ try {
580
+ while (this.queue.length > 0 && !this.disposed) {
581
+ const item = this.queue.shift();
582
+ this.notifyState();
583
+ if (item.kind === "compact")
584
+ await this.processQueuedCompact(item.event);
585
+ else
586
+ await this.processQueuedMessage(item.event);
587
+ }
588
+ }
589
+ finally {
590
+ this.processing = false;
591
+ this.notifyState();
592
+ }
593
+ }
594
+ async processQueuedMessage(event) {
595
+ try {
596
+ const preflight = await this.options.messagePreflight?.(event);
597
+ if (this.disposed)
598
+ return;
599
+ if (preflight && !preflight.allowed) {
600
+ this.emit({
601
+ type: "session_error",
602
+ piboSessionId: this.piboSessionId,
603
+ eventId: event.id,
604
+ error: preflight.reason ?? "Queued message is no longer authorized",
605
+ errorDetails: {
606
+ category: "loop_lifecycle",
607
+ errorClass: "runtime_abort",
608
+ code: preflight.code ?? "message_preflight_rejected",
609
+ origin: "runtime",
610
+ retryable: false,
611
+ },
612
+ provenance: event.provenance,
613
+ });
614
+ return;
615
+ }
616
+ this.emit({
617
+ type: "message_started",
618
+ piboSessionId: this.piboSessionId,
619
+ eventId: event.id,
620
+ text: event.text,
621
+ source: event.source,
622
+ provenance: event.provenance,
623
+ });
624
+ this.activeMessage = event;
625
+ this.activeMessageFailed = false;
626
+ this.resetContentIndices();
627
+ await this.runtimeSession.prompt({
628
+ text: event.text,
629
+ source: promptSource(event.source),
630
+ capabilityScope: event.capabilityScope,
631
+ });
632
+ if (this.disposed)
633
+ return;
634
+ if (!this.activeMessageFailed) {
635
+ this.emit({
636
+ type: "message_finished",
637
+ piboSessionId: this.piboSessionId,
638
+ eventId: event.id,
639
+ source: event.source,
640
+ provenance: event.provenance,
641
+ });
642
+ }
643
+ }
644
+ catch (error) {
645
+ if (this.disposed)
646
+ return;
647
+ if (!this.activeMessageFailed) {
648
+ const message = errorMessage(error);
649
+ this.emit({
650
+ type: "session_error",
651
+ piboSessionId: this.piboSessionId,
652
+ eventId: event.id,
653
+ error: message,
654
+ errorDetails: runtimeSessionErrorDetails(message),
655
+ provenance: event.provenance,
656
+ });
657
+ }
658
+ }
659
+ finally {
660
+ this.activeMessage = undefined;
661
+ this.activeMessageFailed = false;
662
+ this.resetContentIndices();
663
+ }
664
+ }
665
+ async processQueuedCompact(event) {
666
+ this.activeExecutionEvent = event;
667
+ try {
668
+ const result = await this.runAction(event);
669
+ if (this.disposed)
670
+ return;
671
+ this.emit({
672
+ type: "execution_result",
673
+ piboSessionId: this.piboSessionId,
674
+ eventId: event.id,
675
+ action: event.action,
676
+ result,
677
+ });
678
+ }
679
+ catch (error) {
680
+ if (this.disposed)
681
+ return;
682
+ const message = errorMessage(error);
683
+ this.emit({
684
+ type: "session_error",
685
+ piboSessionId: this.piboSessionId,
686
+ eventId: event.id,
687
+ error: message,
688
+ errorDetails: runtimeSessionErrorDetails(message),
689
+ });
690
+ }
691
+ finally {
692
+ this.activeExecutionEvent = undefined;
693
+ }
694
+ }
695
+ enqueueCompactAction(event) {
696
+ this.queue.push({ kind: "compact", event });
697
+ const output = {
698
+ type: "execution_result",
699
+ piboSessionId: this.piboSessionId,
700
+ eventId: event.id,
701
+ action: event.action,
702
+ result: { queued: true, queuedMessages: this.queue.length },
703
+ };
704
+ this.emit(output);
705
+ this.notifyState();
706
+ this.startDrain();
707
+ return output;
708
+ }
709
+ async runAction(event) {
710
+ const gatewayAction = this.pluginRegistry.getGatewayAction(event.action);
711
+ if (!gatewayAction)
712
+ throw new Error(`Unknown execution action "${event.action}"`);
713
+ return await gatewayAction.execute({
714
+ piboSessionId: this.piboSessionId,
715
+ runtimeInstanceId: this.runtimeSession.runtimeInstanceId,
716
+ runtimeAuthRequired: this.runtimeSession.capabilities.auth.status
717
+ && this.runtimeSession.capabilities.auth.methods.length > 0,
718
+ getStatus: () => this.getStatus(),
719
+ getStatusSnapshot: () => this.getStatusSnapshot(),
720
+ getContextUsage: () => this.getActionContextUsage(),
721
+ getActiveModel: () => this.getActiveModel(),
722
+ getModelCatalog: async () => {
723
+ const adapter = this.pluginRegistry.getAgentRuntimeAdapter(this.runtimeSession.runtimeInstanceId);
724
+ return adapter?.listModels
725
+ ? await adapter.listModels()
726
+ : { runtimeInstanceId: this.runtimeSession.runtimeInstanceId, models: [] };
727
+ },
728
+ getRuntimeAuthStatus: async () => this.options.getRuntimeAuthStatus
729
+ ? await this.options.getRuntimeAuthStatus()
730
+ : await this.pluginRegistry.getAgentRuntimeAuthStatus(this.runtimeSession.runtimeInstanceId),
731
+ startRuntimeAuth: async (input) => this.options.startRuntimeAuth
732
+ ? await this.options.startRuntimeAuth(input)
733
+ : await this.pluginRegistry.startAgentRuntimeAuth(this.runtimeSession.runtimeInstanceId, input),
734
+ completeRuntimeAuth: async (input) => this.options.completeRuntimeAuth
735
+ ? await this.options.completeRuntimeAuth(input)
736
+ : await this.pluginRegistry.completeAgentRuntimeAuth(this.runtimeSession.runtimeInstanceId, input),
737
+ cancelRuntimeAuth: async (input) => this.options.cancelRuntimeAuth
738
+ ? await this.options.cancelRuntimeAuth(input)
739
+ : await this.pluginRegistry.cancelAgentRuntimeAuth(this.runtimeSession.runtimeInstanceId, input),
740
+ logoutRuntimeAuth: async (input) => this.options.logoutRuntimeAuth
741
+ ? await this.options.logoutRuntimeAuth(input)
742
+ : await this.pluginRegistry.logoutAgentRuntimeAuth(this.runtimeSession.runtimeInstanceId, input),
743
+ getProviderUsage: () => this.getActionProviderUsage(),
744
+ clearQueue: () => this.clearQueue(),
745
+ abort: async () => {
746
+ if (this.activeMessage)
747
+ this.notifyMessagesInterrupted([this.activeMessage], "abort requested");
748
+ await this.runtimeSession.abort();
749
+ },
750
+ dispose: () => this.dispose(),
751
+ getCurrentSession: () => this.getCurrentSession(),
752
+ listSessions: () => this.listSessions(),
753
+ getForkCandidates: () => this.getForkCandidates(),
754
+ forkSession: (entryId) => this.forkSession(entryId),
755
+ cloneSession: () => this.cloneSession(),
756
+ getSessionTree: () => this.getSessionTree(),
757
+ navigateSessionTree: (params) => this.navigateSessionTree(params),
758
+ switchSession: (params) => this.switchSession(params),
759
+ getThinkingLevel: () => this.getThinkingResult(),
760
+ setThinkingLevel: (level) => this.setThinkingLevel(level),
761
+ cycleThinkingLevel: () => this.cycleThinkingLevel(),
762
+ getFastMode: () => this.getFastMode(),
763
+ setFastMode: (enabled) => this.setFastMode(enabled),
764
+ setModel: (model) => this.setModel(model),
765
+ compact: (customInstructions) => this.compact(customInstructions),
766
+ respondToApproval: (requestId, decision) => this.respondToApproval(requestId, decision),
767
+ respondToUserInput: (requestId, answers) => this.respondToUserInput(requestId, answers),
768
+ kill: async () => {
769
+ const killed = [await this.kill()];
770
+ let cancelledRuns = [];
771
+ if (this.options.onKillChildren) {
772
+ const children = await this.options.onKillChildren(this.piboSessionId);
773
+ killed.push(...children.killed);
774
+ cancelledRuns = children.cancelledRuns;
775
+ }
776
+ return { killed, cancelledRuns };
777
+ },
778
+ killAll: async () => {
779
+ const killed = [await this.kill()];
780
+ let cancelledRuns = [];
781
+ if (this.options.onKillChildren) {
782
+ const children = await this.options.onKillChildren(this.piboSessionId, { includeRuns: true });
783
+ killed.push(...children.killed);
784
+ cancelledRuns = children.cancelledRuns;
785
+ }
786
+ return { killed, cancelledRuns };
787
+ },
788
+ }, event);
789
+ }
790
+ getThinkingResult() {
791
+ const result = this.runtimeSession.controls?.getReasoning?.();
792
+ return {
793
+ level: result?.value && isPiboThinkingLevel(result.value) ? result.value : "off",
794
+ availableLevels: result?.availableValues.filter(isPiboThinkingLevel) ?? [],
795
+ supported: result?.supported ?? false,
796
+ };
797
+ }
798
+ transitionToDisposed(reason) {
799
+ if (this.disposed)
800
+ return false;
801
+ const activeMessage = this.activeMessage;
802
+ this.notifyMessagesInterrupted(this.activeAndQueuedMessages(), reason);
803
+ if (activeMessage) {
804
+ const error = `Session disposed while a message was active: ${reason}`;
805
+ this.emit({
806
+ type: "session_error",
807
+ piboSessionId: this.piboSessionId,
808
+ eventId: activeMessage.id,
809
+ error,
810
+ errorDetails: runtimeSessionErrorDetails(error),
811
+ });
812
+ }
813
+ this.queue.length = 0;
814
+ this.unsubscribe?.();
815
+ this.unsubscribe = undefined;
816
+ this.disposed = true;
817
+ this.processing = false;
818
+ this.notifyState();
819
+ return true;
820
+ }
821
+ disposeRuntime() {
822
+ if (!this.runtimeDisposePromise) {
823
+ try {
824
+ this.runtimeDisposePromise = Promise.resolve(this.runtimeSession.dispose());
825
+ }
826
+ catch (error) {
827
+ this.runtimeDisposePromise = Promise.reject(error);
828
+ }
829
+ }
830
+ return this.runtimeDisposePromise;
831
+ }
832
+ async disposeUnsafe() {
833
+ if (!this.transitionToDisposed("session disposed"))
834
+ return;
835
+ try {
836
+ await Promise.allSettled([this.runtimeSession.abort()]);
837
+ await this.drainPromise;
838
+ }
839
+ finally {
840
+ await this.disposeRuntime();
841
+ }
842
+ }
843
+ clearQueue() {
844
+ const cleared = this.queue.length;
845
+ const removedMessages = this.queue.flatMap((item) => item.kind === "message" ? [item.event] : []);
846
+ this.queue.length = 0;
847
+ this.notifyMessagesInterrupted(removedMessages, "queue cleared");
848
+ this.notifyState();
849
+ return cleared;
850
+ }
851
+ activeAndQueuedMessages() {
852
+ const messages = this.queue.flatMap((item) => item.kind === "message" ? [item.event] : []);
853
+ return this.activeMessage ? [this.activeMessage, ...messages] : messages;
854
+ }
855
+ notifyMessagesInterrupted(messages, reason) {
856
+ if (messages.length === 0)
857
+ return;
858
+ this.options.onMessagesInterrupted?.(messages, reason);
859
+ }
860
+ notifyState() {
861
+ this.options.onStateChange?.({
862
+ processing: this.processing,
863
+ queuedMessages: this.queue.length,
864
+ disposed: this.disposed,
865
+ });
866
+ }
867
+ resetContentIndices() {
868
+ this.activeAssistantIndex = undefined;
869
+ this.nextAssistantIndex = 0;
870
+ this.activeThinkingIndex = undefined;
871
+ this.nextThinkingIndex = 0;
872
+ }
873
+ withActiveMessage(event) {
874
+ if (this.activeMessage?.id && event.type === "assistant_delta") {
875
+ const assistantIndex = this.activeAssistantIndex ?? this.nextAssistantIndex;
876
+ if (this.activeAssistantIndex === undefined) {
877
+ this.nextAssistantIndex += 1;
878
+ this.activeAssistantIndex = assistantIndex;
879
+ }
880
+ return { ...event, eventId: this.activeMessage.id, assistantIndex };
881
+ }
882
+ if (this.activeMessage?.id && event.type === "assistant_message") {
883
+ const assistantIndex = this.activeAssistantIndex ?? this.nextAssistantIndex;
884
+ if (this.activeAssistantIndex === undefined)
885
+ this.nextAssistantIndex += 1;
886
+ this.activeAssistantIndex = undefined;
887
+ return { ...event, eventId: this.activeMessage.id, assistantIndex };
888
+ }
889
+ if (this.activeMessage?.id && event.type === "thinking_started") {
890
+ const thinkingIndex = this.nextThinkingIndex;
891
+ this.nextThinkingIndex += 1;
892
+ this.activeThinkingIndex = thinkingIndex;
893
+ return { ...event, eventId: this.activeMessage.id, thinkingIndex };
894
+ }
895
+ if (this.activeMessage?.id && (event.type === "thinking_delta" || event.type === "thinking_finished")) {
896
+ const thinkingIndex = this.activeThinkingIndex ?? this.nextThinkingIndex;
897
+ if (this.activeThinkingIndex === undefined) {
898
+ this.nextThinkingIndex += 1;
899
+ this.activeThinkingIndex = thinkingIndex;
900
+ }
901
+ const output = { ...event, eventId: this.activeMessage.id, thinkingIndex };
902
+ if (event.type === "thinking_finished")
903
+ this.activeThinkingIndex = undefined;
904
+ return output;
905
+ }
906
+ if (this.activeMessage?.id
907
+ && (event.type === "assistant_usage"
908
+ || event.type === "compaction_start"
909
+ || event.type === "compaction_end"
910
+ || event.type === "tool_call"
911
+ || event.type === "tool_execution_started"
912
+ || event.type === "tool_execution_updated"
913
+ || event.type === "tool_execution_finished"
914
+ || event.type === "approval_requested"
915
+ || event.type === "approval_resolved"
916
+ || event.type === "user_input_requested"
917
+ || event.type === "user_input_resolved"
918
+ || event.type === "session_error"
919
+ || event.type === "execution_result")) {
920
+ return { ...event, eventId: this.activeMessage.id };
921
+ }
922
+ return event;
923
+ }
924
+ assertActive() {
925
+ if (this.disposed)
926
+ throw new Error(`Session "${this.piboSessionId}" has been disposed`);
927
+ }
928
+ }
929
+ export function runtimeReminderToolNames(toolNames) {
930
+ return toolNames.filter((name) => RUN_REMINDER_CAPABILITY_TOOLS.has(name));
931
+ }