@sentry/junior 0.296.0 → 0.298.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (82) hide show
  1. package/dist/{admin-z_lgDi-z.js → admin-BF3DbYGf.js} +2 -2
  2. package/dist/{agent-runner-HoQiUKLL.js → agent-runner-Q9GkoerG.js} +407 -1895
  3. package/dist/api/schema.d.ts +2 -2
  4. package/dist/api/schema.js +7 -7
  5. package/dist/api.d.ts +1 -1
  6. package/dist/api.js +38 -267
  7. package/dist/{app-C75Ft-A_.d.ts → app-DOg_mCtV.d.ts} +7 -2
  8. package/dist/app.d.ts +1 -1
  9. package/dist/app.js +64 -44
  10. package/dist/attempt-selection-ClP3MMPr.js +61 -0
  11. package/dist/{automation-yJX3C7i3.js → automation-Cn8qmbdr.js} +1 -1
  12. package/dist/{background-compaction-queue-Cre1wFt9.js → background-compaction-queue-BZhGFOK6.js} +4 -88
  13. package/dist/{briefs-BXECHduJ.js → briefs-CQrCRF6-.js} +3 -3
  14. package/dist/{catalog-runtime-CpCmlD9L.js → catalog-runtime-DZeD2WbL.js} +1 -1
  15. package/dist/cli/chat.js +19 -15
  16. package/dist/cli/check.js +3 -3
  17. package/dist/cli/main.js +3 -3
  18. package/dist/cli/plugins.js +4 -4
  19. package/dist/cli/snapshot-create.js +4 -4
  20. package/dist/cli/upgrade.d.ts +1 -1
  21. package/dist/cli/upgrade.js +3 -3
  22. package/dist/{config-CCPHvTqx.js → config-BOByVnxe.js} +2 -2
  23. package/dist/{connections-B5pWh8e2.js → connections-BNN5cJam.js} +6 -6
  24. package/dist/{conversation-CMkSmi02.js → conversation-DCkzvxqB.js} +51 -17
  25. package/dist/{conversation-feed-BVAOga0H.js → conversation-feed-CMA12Rjs.js} +1 -1
  26. package/dist/{conversation-privacy-CZD5soDW.js → conversation-privacy-C0eRxsgb.js} +1 -1
  27. package/dist/conversation-turn-D9qvcDX6.js +805 -0
  28. package/dist/{credential-sync-DwLkIvXI.js → credential-sync-B_iUpxGL.js} +14 -13
  29. package/dist/{db-C1M1y-bh.js → db-CoMNr2Zm.js} +43 -15
  30. package/dist/{db-B3iyr_Or.d.ts → db-DoMcnYol.d.ts} +13 -1
  31. package/dist/{executor-DUSEwXaO.js → executor-C-m8VrzX.js} +14 -6
  32. package/dist/instrumentation.js +2 -2
  33. package/dist/{logging-D0svFM8r.js → logging-CJTi5niy.js} +1 -1
  34. package/dist/{message-BFnIwKpx.js → message-Q6_5DAWR.js} +15 -13
  35. package/dist/nitro.d.ts +1 -1
  36. package/dist/nitro.js +3 -2
  37. package/dist/{session-stop-hYNTNpVf.js → notification-Bv25xbj0.js} +11 -930
  38. package/dist/{oauth-callback-server-BXRtD6Fk.js → oauth-callback-server-CH5XAyo-.js} +2 -2
  39. package/dist/{projection-B6VS7kbo.js → projection-BgwEE36_.js} +333 -106
  40. package/dist/{prompt-CD11tfG8.js → prompt-DXc9DYT9.js} +4 -4
  41. package/dist/prompt-input-BUr4J9RO.js +1424 -0
  42. package/dist/{registry-CHewwYEo.js → registry-9XwqSnM-.js} +1 -1
  43. package/dist/reporting-window-DopzcOHh.js +137 -0
  44. package/dist/{resolve-1owMH4qo.js → resolve-DUIAbcRL.js} +3 -3
  45. package/dist/result-C2Vn8QGn.js +463 -0
  46. package/dist/{runner-BtWvJslp.js → runner-CXGtw-Mc.js} +9 -8
  47. package/dist/{sandbox-egress-signals-ByftwJVt.js → sandbox-egress-signals-Di3S_dO7.js} +1 -1
  48. package/dist/{schema-Ct1Zf2xy.d.ts → schema-BnbZ-rKv.d.ts} +14 -107
  49. package/dist/{schema-D2iGyYIp.js → schema-Dyp7racy.js} +11 -48
  50. package/dist/{service-account-BZEuMKdo.js → service-account-DM3KBBeG.js} +3 -3
  51. package/dist/{service-account-DLoeoHww.js → service-account-GzAMUQ8a.js} +3 -3
  52. package/dist/session-stop-D4i7e6iT.js +181 -0
  53. package/dist/{skills-DXgd5Inh.js → skills-DCK9SD_l.js} +2 -2
  54. package/dist/{spawn-YeqlNDv8.js → spawn-6cX6xE9G.js} +6 -5
  55. package/dist/{state-C3CbtD_m.js → state-CSuA2J1V.js} +2 -2
  56. package/dist/{stop-Cze_pEL8.js → stop-Dh2DfwpK.js} +66 -159
  57. package/dist/{store-CZ9vqR4P.js → store-B1zepKG8.js} +11 -4
  58. package/dist/{task-runner-CMiNGsER.js → store-DrA17Fbz.js} +939 -1593
  59. package/dist/task-queue-D1rXWfFN.js +89 -0
  60. package/dist/task-runner-CT4M8oDz.js +291 -0
  61. package/dist/thread-context-DnqUkbzN.js +248 -0
  62. package/dist/turn-cancel-l460pfGW.js +201 -0
  63. package/dist/turn-session-routing-VXDVXLRl.js +380 -0
  64. package/dist/{turn-failure-response-pXhZ2wMK.js → turn-user-message-BSPmkm7X.js} +181 -392
  65. package/dist/turn-wake-DVFVXyhX.js +161 -0
  66. package/dist/{reporting-window-B3Ze-Qnt.js → user-input-request-CXNIov9n.js} +24 -143
  67. package/dist/{validation-Du7NdkOR.js → validation-zxAJBDDy.js} +1 -1
  68. package/dist/{version-EN3Wnq-R.js → version-DcZ40a0g.js} +1 -1
  69. package/dist/version.js +1 -1
  70. package/dist/{viewer-Agxi_o5c.js → viewer-CgiGjW10.js} +3 -3
  71. package/dist/warmup-CwKbxQLl.js +2698 -0
  72. package/dist/{worker-BALVdWbv.js → worker-CbDUzaBA.js} +20 -8
  73. package/migrations/0102_code_change_last_activity.sql +1 -0
  74. package/migrations/0103_agent_invocation_fork.sql +8 -0
  75. package/migrations/meta/0102_snapshot.json +4502 -0
  76. package/migrations/meta/0103_snapshot.json +4509 -0
  77. package/migrations/meta/_journal.json +14 -0
  78. package/package.json +4 -4
  79. package/dist/result-CEqQFrEf.js +0 -305
  80. package/dist/result-event-type-DD6BAgT7.js +0 -11
  81. package/dist/warmup-CY2ArYag.js +0 -2017
  82. package/dist/work-EA98F0ia.js +0 -768
@@ -1,13 +1,12 @@
1
- import { E as buildConversationContext, Eo as listConversationAnnotations, X as clearPendingAuth, j as markConversationMessage, v as hydrateConversationMessages } from "./projection-B6VS7kbo.js";
2
- import { H as findProviderError, U as getProviderErrorAttributes, W as getProviderErrorUserMessage, g as TURN_REASONING_LEVELS, z as ProviderError } from "./config-CCPHvTqx.js";
3
- import { G as isRecord, b as setSpanAttributes, t as buildTurnFailureResponse } from "./logging-D0svFM8r.js";
1
+ import { g as TURN_REASONING_LEVELS } from "./config-BOByVnxe.js";
4
2
  import { h as parseSlackMessageTs } from "./actor-6jsm_v96.js";
5
- import { o as getDb, r as getConversationEventStore, s as getSqlExecutor } from "./db-C1M1y-bh.js";
6
- import { g as juniorAgentInvocations } from "./executor-DUSEwXaO.js";
7
- import { p as credentialContextSchema } from "./registry-CHewwYEo.js";
8
- import { L as readMessageCardRefs, R as removedCardSchema, z as resolveMessageCards } from "./conversation-CMkSmi02.js";
9
- import { C as AGENT_INVOCATION_PARENT_MAILBOX_STATUSES, S as AGENT_INVOCATION_MAILBOX_STATUSES } from "./reporting-window-B3Ze-Qnt.js";
10
- import { c as getPersistedThreadState, d as coerceThreadConversationState, u as persistThreadStateById } from "./task-runner-CMiNGsER.js";
3
+ import { r as getConversationEventStore, s as getSqlExecutor } from "./db-CoMNr2Zm.js";
4
+ import { g as juniorAgentInvocations } from "./executor-C-m8VrzX.js";
5
+ import { p as credentialContextSchema } from "./registry-9XwqSnM-.js";
6
+ import { k as agentTypeSchema } from "./conversation-DCkzvxqB.js";
7
+ import { i as isEventMailboxMetadata } from "./notification-Bv25xbj0.js";
8
+ import { _ as getConversationWorkState } from "./store-B1zepKG8.js";
9
+ import { d as AGENT_INVOCATION_MAILBOX_STATUSES, f as AGENT_INVOCATION_PARENT_MAILBOX_STATUSES } from "./user-input-request-CXNIov9n.js";
11
10
  import { createHash } from "node:crypto";
12
11
  import * as z from "zod";
13
12
  import { and, asc, desc, eq, inArray, or, sql } from "drizzle-orm";
@@ -21,97 +20,6 @@ function buildDeterministicTurnId(messageId) {
21
20
  function buildDeterministicAssistantMessageId(turnId) {
22
21
  return `${turnId}:assistant:1`;
23
22
  }
24
- // src/chat/runtime/turn.ts
25
- /** Classified Slack turn failure carrying the owning Sentry capture outward. */
26
- var ConversationTurnBoundaryError = class extends Error {
27
- eventId;
28
- failureCode;
29
- constructor(args) {
30
- super(args.cause instanceof Error ? args.cause.message : String(args.cause), { cause: args.cause });
31
- this.name = "ConversationTurnBoundaryError";
32
- this.eventId = args.eventId;
33
- this.failureCode = args.failureCode;
34
- }
35
- };
36
- /** Return a classified Slack boundary failure without erasing its cause. */
37
- function getConversationTurnBoundaryError(error) {
38
- return error instanceof ConversationTurnBoundaryError ? error : void 0;
39
- }
40
- /**
41
- * Queue-worker yield routing: respond.ts returns a suspended AgentRunOutcome
42
- * and the Slack executor raises this at the worker boundary so the lease owner
43
- * requeues the conversation.
44
- */
45
- var CooperativeTurnYieldError = class extends Error {
46
- code = "cooperative_turn_yield";
47
- constructor(message = "Agent turn yielded at a safe boundary") {
48
- super(message);
49
- this.name = "CooperativeTurnYieldError";
50
- }
51
- };
52
- function isCooperativeTurnYieldError(error) {
53
- return error instanceof CooperativeTurnYieldError;
54
- }
55
- /** Error indicating durable turn input could not be committed by the worker owner. */
56
- var TurnInputCommitLostError = class extends Error {
57
- code = "turn_input_commit_lost";
58
- constructor(message = "Turn input commit lost its durable owner") {
59
- super(message);
60
- this.name = "TurnInputCommitLostError";
61
- }
62
- };
63
- /** Return whether an error means the durable worker lost input ownership. */
64
- function isTurnInputCommitLostError(error) {
65
- return error instanceof TurnInputCommitLostError;
66
- }
67
- /** Error indicating durable turn input should stay pending for a later worker. */
68
- var TurnInputDeferredError = class extends Error {
69
- code = "turn_input_deferred";
70
- constructor(message = "Turn input is deferred until the active resume ends") {
71
- super(message);
72
- this.name = "TurnInputDeferredError";
73
- }
74
- };
75
- /** Return whether an error means the durable worker should redeliver input later. */
76
- function isTurnInputDeferredError(error) {
77
- return error instanceof TurnInputDeferredError;
78
- }
79
- /** Mark a turn as the active turn in conversation state. */
80
- function startActiveTurn(args) {
81
- args.conversation.processing.activeTurnId = args.nextTurnId;
82
- }
83
- function clearActiveTurn(conversation, sessionId) {
84
- if (!sessionId || conversation.processing.activeTurnId === sessionId) conversation.processing.activeTurnId = void 0;
85
- }
86
- /**
87
- * Close the active turn without marking a Pi session reusable for future
88
- * history. Use this for auth handoffs and recovery replies that end the live
89
- * turn but do not produce a completed Pi session.
90
- */
91
- function markTurnClosed(args) {
92
- clearActiveTurn(args.conversation, args.sessionId);
93
- args.conversation.processing.lastCompletedAtMs = args.nowMs;
94
- }
95
- /**
96
- * Mark a turn as completed after its assistant output has been handled.
97
- */
98
- function markTurnCompleted(args) {
99
- clearActiveTurn(args.conversation, args.sessionId);
100
- args.conversation.processing.lastCompletedAtMs = args.nowMs;
101
- }
102
- /**
103
- * Mark a turn as failed when execution or final user-visible reply delivery
104
- * cannot be completed. If `sessionId` is provided, `activeTurnId` is only
105
- * cleared when it still matches the failing turn.
106
- */
107
- function markTurnFailed(args) {
108
- clearActiveTurn(args.conversation, args.sessionId);
109
- args.conversation.processing.lastCompletedAtMs = args.nowMs;
110
- args.markConversationMessage(args.conversation, args.userMessageId, {
111
- replied: false,
112
- skippedReason: "reply failed"
113
- });
114
- }
115
23
  // src/chat/agent-invocations/ids.ts
116
24
  const CREATE_LOCK_PREFIX = "junior:agent_invocation:create";
117
25
  /**
@@ -166,6 +74,35 @@ function getAgentInvocationTurnId(invocationId) {
166
74
  function getAgentInvocationMessageId(invocationId) {
167
75
  return `agent-invocation:${invocationId}:input`;
168
76
  }
77
+ const REPLY_MESSAGE_PREFIX = "agent-reply:";
78
+ /** Return the parent mailbox identity of one child agent `reply` call. */
79
+ function getAgentReplyMessageId(invocationId, toolCallId) {
80
+ return `${REPLY_MESSAGE_PREFIX}${invocationId}:${toolCallId}`;
81
+ }
82
+ /**
83
+ * Return the key of the `reply` of one Turn on a child's Conversation loop.
84
+ * It starts with the Turn id, so the parent can tell that the Turn replied.
85
+ */
86
+ function getTurnReplyKey(turnId, toolCallId) {
87
+ return `${turnId}:${toolCallId}`;
88
+ }
89
+ const REPLY_MESSAGE_ID = /^agent-reply:(agent-invocation:[0-9a-f]{32}):/;
90
+ /** Read the agent invocation identity from one parent `reply` mailbox identity. */
91
+ function parseAgentReplyMessageId(messageId) {
92
+ return REPLY_MESSAGE_ID.exec(messageId)?.[1];
93
+ }
94
+ const TURN_REPLY_MESSAGE_ID = /^agent-reply:agent-invocation:[0-9a-f]{32}:(turn_[A-Za-z0-9_-]+)(?::|$)/;
95
+ /**
96
+ * Read the Turn id from one parent mailbox identity that a Turn on a child's
97
+ * Conversation loop sent. A `reply` of an agent invocation has none.
98
+ */
99
+ function parseTurnReplyMessageId(messageId) {
100
+ return TURN_REPLY_MESSAGE_ID.exec(messageId)?.[1];
101
+ }
102
+ /** Return whether one parent mailbox identity is a `reply` of an agent invocation. */
103
+ function isAgentReplyMessageId(messageId, invocationId) {
104
+ return messageId.startsWith(`${REPLY_MESSAGE_PREFIX}${invocationId}:`);
105
+ }
169
106
  const RESULT_MESSAGE_PREFIX = "agent-invocation:";
170
107
  const RESULT_MESSAGE_SUFFIX = ":result";
171
108
  /** Return the stable parent mailbox identity for one terminal result. */
@@ -177,61 +114,6 @@ function parseAgentInvocationResultMessageId(messageId) {
177
114
  if (!messageId.startsWith(RESULT_MESSAGE_PREFIX) || !messageId.endsWith(RESULT_MESSAGE_SUFFIX)) return;
178
115
  return messageId.slice(17, -7) || void 0;
179
116
  }
180
- // src/chat/agent-invocations/agent-types.ts
181
- /**
182
- * Child agent types. A type is plain data: when to pick it, whether the child
183
- * starts with its parent's history, and what it reads with its task. Runtime
184
- * code reads only these fields, never a type name, so types can later come
185
- * from configuration. Types do not limit tools: Guardian reviews each child
186
- * action against the root user's messages, as for any child. A child keeps its
187
- * type for later agent invocations. A child without a type starts fresh.
188
- */
189
- const AGENT_TYPES = [
190
- "fork",
191
- "explore",
192
- "reviewer"
193
- ];
194
- /**
195
- * Stored name of a child agent type. A stored name stays readable after its
196
- * type is removed; the runtime then treats the child as a
197
- * child without a type.
198
- */
199
- const agentTypeSchema = z.string().regex(/^[a-z][a-z0-9_-]*$/);
200
- const AGENT_TYPE_DEFINITIONS = {
201
- fork: {
202
- whenToUse: "A copy of you. Use it when the brief would need most of what you already know, or when the intermediate tool output is not worth keeping in your context. The task is a directive: say what to do and what is in or out of scope; do not re-explain the background.",
203
- startsWithParentHistory: true,
204
- instructions: "You are a fork of your parent agent. The messages before your first parent task are copied from the parent's conversation so you have its context. They are not your job: your job is the parent task below. Sandbox files, approvals, and credentials of the parent were not copied, and your sandbox is separate. Verify files in your own sandbox before you use them."
205
- },
206
- explore: {
207
- whenToUse: "Investigation across code, docs, logs, telemetry, or the web. Use it when an answer needs reading across many files or sources and you need the conclusion with evidence, not the raw output.",
208
- startsWithParentHistory: false,
209
- instructions: "You are an explore agent. Your job is to investigate and report, so do not change anything outside your sandbox unless the task asks for it. Report what you found with exact evidence, such as paths, lines, links, and ids, and say what you could not verify."
210
- },
211
- reviewer: {
212
- whenToUse: "An independent second opinion on a change, plan, or claim. Give it the evidence to judge, not your conclusion.",
213
- startsWithParentHistory: false,
214
- instructions: "You are a reviewer agent. Give an independent assessment. Do not assume that the parent's framing is correct: verify each claim against the evidence. Do not change anything outside your own sandbox. Report concrete problems ranked by severity, each with its evidence, and say clearly when you found none."
215
- }
216
- };
217
- function agentTypeDefinition(type) {
218
- return type && Object.hasOwn(AGENT_TYPE_DEFINITIONS, type) ? AGENT_TYPE_DEFINITIONS[type] : void 0;
219
- }
220
- /** Model-facing list of child agent types, with how each child starts. */
221
- function formatAgentTypes() {
222
- return AGENT_TYPES.map((type) => {
223
- const definition = AGENT_TYPE_DEFINITIONS[type];
224
- return `- "${type}"${definition.startsWithParentHistory ? " (starts with this conversation's history)" : ""}: ${definition.whenToUse}`;
225
- }).join("\n");
226
- }
227
- /** Return whether a child of this type starts with its parent's history. */
228
- function agentTypeStartsWithParentHistory(type) {
229
- return agentTypeDefinition(type)?.startsWithParentHistory ?? false;
230
- }
231
- /** Return the instructions that a child of this type reads with its task. */
232
- function agentTypeInstructions(type) {
233
- return agentTypeDefinition(type)?.instructions;
234
- }
235
117
  // src/chat/agent-invocations/types.ts
236
118
  const exactStringSchema = z.string().min(1).refine((value) => value === value.trim());
237
119
  const agentNameSchema = exactStringSchema.max(64);
@@ -262,6 +144,8 @@ const agentInvocationBaseSchema = z.object({
262
144
  parentConversationId: exactStringSchema,
263
145
  parentToolCallId: exactStringSchema.optional(),
264
146
  agentType: agentTypeSchema.optional(),
147
+ /** The child starts with its parent's history. */
148
+ fork: z.literal(true).optional(),
265
149
  reasoningLevel: z.enum(TURN_REASONING_LEVELS).optional(),
266
150
  source: sourceSchema,
267
151
  title: exactStringSchema.optional(),
@@ -301,6 +185,7 @@ const createAgentInvocationSchema = z.object({
301
185
  parentConversationId: exactStringSchema,
302
186
  parentToolCallId: exactStringSchema.optional(),
303
187
  agentType: agentTypeSchema.optional(),
188
+ fork: z.literal(true).optional(),
304
189
  reasoningLevel: z.enum(TURN_REASONING_LEVELS).optional(),
305
190
  title: exactStringSchema.optional()
306
191
  }).strict();
@@ -311,6 +196,7 @@ const CHILD_AGENT_RESULTS = [
311
196
  "failed"
312
197
  ];
313
198
  // src/chat/agent-invocations/store.ts
199
+ /** Statuses of a finished agent invocation. */
314
200
  const TERMINAL_AGENT_INVOCATION_STATUSES = [
315
201
  "blocked",
316
202
  "completed",
@@ -342,6 +228,7 @@ function invocationFromRow(row) {
342
228
  ...row.parentMailboxStatus ? { parentMailboxStatus: row.parentMailboxStatus } : void 0,
343
229
  ...row.parentToolCallId ? { parentToolCallId: row.parentToolCallId } : void 0,
344
230
  ...row.agentType ? { agentType: row.agentType } : void 0,
231
+ ...row.fork ? { fork: true } : void 0,
345
232
  ...row.reasoningLevel ? { reasoningLevel: row.reasoningLevel } : void 0,
346
233
  ...row.result !== null ? { result: row.result } : void 0,
347
234
  source: row.source,
@@ -372,13 +259,17 @@ async function getLatestAgentInvocationForConversation(childConversationId) {
372
259
  return rows[0] ? invocationFromRow(rows[0]) : void 0;
373
260
  }
374
261
  /**
375
- * Read the name and the newest task title of one child Conversation, for
376
- * labels. Agent invocations that give a nested result to the child have no
377
- * title, so an agent invocation with a title comes first.
262
+ * Read the name, agent type, fork flag, and newest task title of one child
263
+ * Conversation, for labels. Agent invocations that give a nested result to
264
+ * the child have no title, so an agent invocation with a title comes first.
265
+ * Each agent invocation keeps the child's agent type, but only the one that
266
+ * started a fork has `fork` set, so the flag reads every agent invocation.
378
267
  */
379
268
  async function getChildAgentLabel(childConversationId) {
380
269
  const [row] = await getSqlExecutor().db().select({
381
270
  agentName: juniorAgentInvocations.agentName,
271
+ agentType: juniorAgentInvocations.agentType,
272
+ fork: sql`bool_or(${juniorAgentInvocations.fork}) over ()`,
382
273
  title: juniorAgentInvocations.title
383
274
  }).from(juniorAgentInvocations).where(eq(juniorAgentInvocations.childConversationId, childConversationId)).orderBy(sql`${juniorAgentInvocations.title} is null`, desc(juniorAgentInvocations.createdAt)).limit(1);
384
275
  return row;
@@ -391,17 +282,38 @@ async function listOpenAgentInvocations(conversationId) {
391
282
  return (await getSqlExecutor().db().select().from(juniorAgentInvocations).where(and(or(eq(juniorAgentInvocations.childConversationId, conversationId), eq(juniorAgentInvocations.parentConversationId, conversationId)), inArray(juniorAgentInvocations.status, NON_TERMINAL_AGENT_INVOCATION_STATUSES))).orderBy(asc(juniorAgentInvocations.createdAt))).map(invocationFromRow);
392
283
  }
393
284
  /**
285
+ * Return whether a terminal agent invocation sends its result to the parent.
286
+ * A child's final response stays in its Conversation, and a `reply` that
287
+ * reached the parent (its id is in `parentInboundMessageIds`) answered for
288
+ * the invocation. A failure after that, such as a lost worker before the
289
+ * Turn was saved, is not sent either.
290
+ */
291
+ function sendsResultToParent(invocation, parentInboundMessageIds) {
292
+ const replied = parentInboundMessageIds.some((messageId) => isAgentReplyMessageId(messageId, invocation.invocationId));
293
+ switch (invocation.status) {
294
+ case "completed": return !replied && Boolean(invocation.result?.trim());
295
+ case "failed": return !replied;
296
+ default: return true;
297
+ }
298
+ }
299
+ /**
394
300
  * Return whether a child Conversation has work that will start another agent
395
301
  * invocation on it: another open agent invocation, an open child agent, or a
396
- * sent child agent result that no agent invocation has received yet.
302
+ * child agent result that is sent but still waits in its mailbox.
397
303
  */
398
304
  async function hasOpenChildWork(invocation) {
399
305
  const conversationId = invocation.childConversationId;
400
306
  if ((await listOpenAgentInvocations(conversationId)).some((row) => row.invocationId !== invocation.invocationId)) return true;
401
- const db = getSqlExecutor().db();
402
- const sent = await db.select({ invocationId: juniorAgentInvocations.invocationId }).from(juniorAgentInvocations).where(and(eq(juniorAgentInvocations.parentConversationId, conversationId), inArray(juniorAgentInvocations.parentMailboxStatus, ["pending", "appended"])));
403
- if (sent.length === 0) return false;
404
- return (await db.select({ invocationId: juniorAgentInvocations.invocationId }).from(juniorAgentInvocations).where(inArray(juniorAgentInvocations.invocationId, sent.map((row) => getAgentInvocationIdForResult(row.invocationId))))).length < sent.length;
307
+ const marked = await getSqlExecutor().db().select({
308
+ invocationId: juniorAgentInvocations.invocationId,
309
+ parentMailboxStatus: juniorAgentInvocations.parentMailboxStatus,
310
+ result: juniorAgentInvocations.result,
311
+ status: juniorAgentInvocations.status
312
+ }).from(juniorAgentInvocations).where(and(eq(juniorAgentInvocations.parentConversationId, conversationId), inArray(juniorAgentInvocations.parentMailboxStatus, ["pending", "appended"])));
313
+ if (marked.length === 0) return false;
314
+ const work = await getConversationWorkState({ conversationId });
315
+ const unread = new Set(work?.messages.map((message) => message.inboundMessageId));
316
+ return marked.some((row) => sendsResultToParent(row, work?.execution.inboundMessageIds ?? []) && (row.parentMailboxStatus === "pending" || unread.has(getAgentInvocationResultMessageId(row.invocationId))));
405
317
  }
406
318
  /** List bounded invocation records whose mailbox append still needs repair. */
407
319
  async function listPendingAgentInvocationMailboxAppends(limit = 100) {
@@ -422,6 +334,23 @@ async function reportReplacedAgentInvocation(invocationId, nowMs = Date.now()) {
422
334
  }).where(and(eq(juniorAgentInvocations.invocationId, invocationId), eq(juniorAgentInvocations.parentMailboxStatus, "replaced")));
423
335
  return await getAgentInvocation(invocationId);
424
336
  }
337
+ /**
338
+ * Send the `replaced` result of a child Conversation when its open child work
339
+ * ended and sent it nothing, such as a helper that ended with `noReply`. No
340
+ * later agent invocation of the child would send the report. Input from its
341
+ * own child agents that still waits in its mailbox starts one, so that one
342
+ * reports instead.
343
+ */
344
+ async function reportReplacedWithoutOpenWork(conversationId, nowMs = Date.now()) {
345
+ const latest = await getLatestAgentInvocationForConversation(conversationId);
346
+ if (!latest || !isTerminalAgentInvocation(latest) || latest.parentMailboxStatus !== "replaced" || await hasOpenChildWork(latest)) return;
347
+ if ((await getConversationWorkState({ conversationId }))?.messages.some(isChildAgentInputMessage)) return;
348
+ return await reportReplacedAgentInvocation(latest.invocationId, nowMs);
349
+ }
350
+ function isChildAgentInputMessage(message) {
351
+ const metadata = message.input.metadata;
352
+ return isEventMailboxMetadata(metadata) && metadata.event.namespace === "junior";
353
+ }
425
354
  /** Record that one terminal result is in its parent mailbox. */
426
355
  async function markAgentInvocationParentMailboxAppended(invocationId, nowMs = Date.now()) {
427
356
  await getSqlExecutor().db().update(juniorAgentInvocations).set({
@@ -493,64 +422,13 @@ async function markAgentInvocationSteered(invocationId, nowMs = Date.now()) {
493
422
  function isTerminalAgentInvocation(invocation) {
494
423
  return TERMINAL_AGENT_INVOCATION_STATUSES.includes(invocation.status);
495
424
  }
496
- // src/chat/conversations/pending-cards.ts
497
425
  /**
498
- * Add the cards that tool results selected since the last visible assistant
499
- * Message or Turn start, scanning back from `beforeSeq`. Returns the input
500
- * message ids of the Turn start that ended the scan.
426
+ * Return whether the newest agent invocation of a child shows a stop. A tree
427
+ * stop leaves a `replaced` agent invocation with its finished status and
428
+ * marks it `skipped`, so that also means stopped.
501
429
  */
502
- async function selectTurnCards(conversationId, selection, beforeSeq) {
503
- while (true) {
504
- const page = await getConversationEventStore().query(conversationId, {
505
- beforeSeq,
506
- limit: 100,
507
- types: [
508
- "tool_result",
509
- "message",
510
- "turn_started"
511
- ]
512
- });
513
- for (const event of [...page.events].reverse()) {
514
- const data = event.data;
515
- if (data.type === "turn_started") return data.inputMessageIds;
516
- if (data.type === "message" && data.role === "assistant") return [];
517
- if (data.type !== "tool_result" || data.isError || typeof data.toolName !== "string" || !isRecord(data.details)) continue;
518
- if (data.details.timed_out === true) continue;
519
- if (Array.isArray(data.details.removedCards)) for (const ref of removedCardSchema.array().parse(data.details.removedCards)) selection.deleted.add(JSON.stringify([ref.plugin, ref.key]));
520
- for (const card of readMessageCardRefs(data.details)) {
521
- const key = JSON.stringify([card.plugin, card.key]);
522
- if (!selection.deleted.has(key) && !selection.cards.has(key)) selection.cards.set(key, card);
523
- }
524
- }
525
- if (!page.hasOlder || page.events.length === 0) return [];
526
- beforeSeq = page.events[0].seq;
527
- }
528
- }
529
- /**
530
- * Add the cards of child agents whose results started this Turn. A child
531
- * cannot reply to people, so its parent's reply delivers its cards.
532
- */
533
- async function selectChildResultCards(inputMessageIds, selection) {
534
- const events = getConversationEventStore();
535
- for (const messageId of [...inputMessageIds].reverse()) {
536
- const invocationId = parseAgentInvocationResultMessageId(messageId);
537
- const invocation = invocationId ? await getAgentInvocation(invocationId) : void 0;
538
- if (!invocation) continue;
539
- const turnId = getAgentInvocationTurnId(invocation.invocationId);
540
- const terminal = await events.loadByIdempotencyKey(invocation.childConversationId, `turn:${turnId}:terminal`);
541
- if (!terminal) continue;
542
- await selectTurnCards(invocation.childConversationId, selection, terminal.seq);
543
- }
544
- }
545
- /** Select undelivered cards and load their latest saved facts. */
546
- async function loadPendingMessageCards(conversationId) {
547
- const selection = {
548
- cards: /* @__PURE__ */ new Map(),
549
- deleted: /* @__PURE__ */ new Set()
550
- };
551
- await selectChildResultCards(await selectTurnCards(conversationId, selection), selection);
552
- if (selection.cards.size === 0) return [];
553
- return resolveMessageCards([...selection.cards.values()].reverse(), await listConversationAnnotations(getDb(), conversationId));
430
+ function isStoppedAgentInvocation(invocation) {
431
+ return invocation.status === "stopped" || isTerminalAgentInvocation(invocation) && invocation.parentMailboxStatus === "skipped";
554
432
  }
555
433
  // src/chat/conversations/turn-lifecycle.ts
556
434
  /** Persist correlated turn lifecycle facts with retry-safe terminal exclusion. */
@@ -609,76 +487,96 @@ var ConversationTurnLifecycleService = class {
609
487
  function getTurnLifecycle() {
610
488
  return new ConversationTurnLifecycleService(getConversationEventStore());
611
489
  }
612
- // src/chat/conversations/thread-context.ts
613
- const CURSOR_TURN_LOOKBACK = 10;
614
- async function loadThreadContextCursor(args) {
615
- const store = getConversationEventStore();
616
- const [started, completed] = await Promise.all([store.query(args.conversationId, {
617
- limit: CURSOR_TURN_LOOKBACK,
618
- types: ["turn_started"]
619
- }), store.query(args.conversationId, {
620
- limit: CURSOR_TURN_LOOKBACK,
621
- types: ["turn_completed"]
622
- })]);
623
- const finished = new Set(completed.events.flatMap((event) => event.data.type === "turn_completed" && event.data.outcome !== "cancelled" ? [event.data.turnId] : []));
624
- const previous = [...started.events].reverse().find((event) => event.data.type === "turn_started" && event.data.turnId !== args.turnId && finished.has(event.data.turnId));
625
- return previous?.data.type === "turn_started" ? previous.data.threadContextThroughSeq : void 0;
490
+ // src/chat/runtime/turn.ts
491
+ /** Classified Slack turn failure carrying the owning Sentry capture outward. */
492
+ var ConversationTurnBoundaryError = class extends Error {
493
+ eventId;
494
+ failureCode;
495
+ constructor(args) {
496
+ super(args.cause instanceof Error ? args.cause.message : String(args.cause), { cause: args.cause });
497
+ this.name = "ConversationTurnBoundaryError";
498
+ this.eventId = args.eventId;
499
+ this.failureCode = args.failureCode;
500
+ }
501
+ };
502
+ /** Return a classified Slack boundary failure without erasing its cause. */
503
+ function getConversationTurnBoundaryError(error) {
504
+ return error instanceof ConversationTurnBoundaryError ? error : void 0;
626
505
  }
627
506
  /**
628
- * Return the oldest cursor of the Turns that the cursor lookup reads. Messages
629
- * after it may still be in the thread context delta of the next Turn, also
630
- * when the latest Turns failed or the next Turn retries.
507
+ * Queue-worker yield routing: respond.ts returns a suspended AgentRunOutcome
508
+ * and the Slack executor raises this at the worker boundary so the lease owner
509
+ * requeues the conversation.
631
510
  */
632
- async function loadThreadContextTrimFloor(conversationId) {
633
- const cursors = (await getConversationEventStore().query(conversationId, {
634
- limit: CURSOR_TURN_LOOKBACK,
635
- types: ["turn_started"]
636
- })).events.flatMap((event) => event.data.type === "turn_started" && event.data.threadContextThroughSeq !== void 0 ? [event.data.threadContextThroughSeq] : []);
637
- return cursors.length > 0 ? Math.min(...cursors) : void 0;
511
+ var CooperativeTurnYieldError = class extends Error {
512
+ code = "cooperative_turn_yield";
513
+ constructor(message = "Agent turn yielded at a safe boundary") {
514
+ super(message);
515
+ this.name = "CooperativeTurnYieldError";
516
+ }
517
+ };
518
+ function isCooperativeTurnYieldError(error) {
519
+ return error instanceof CooperativeTurnYieldError;
520
+ }
521
+ /** Error indicating durable turn input could not be committed by the worker owner. */
522
+ var TurnInputCommitLostError = class extends Error {
523
+ code = "turn_input_commit_lost";
524
+ constructor(message = "Turn input commit lost its durable owner") {
525
+ super(message);
526
+ this.name = "TurnInputCommitLostError";
527
+ }
528
+ };
529
+ /** Return whether an error means the durable worker lost input ownership. */
530
+ function isTurnInputCommitLostError(error) {
531
+ return error instanceof TurnInputCommitLostError;
532
+ }
533
+ /** Error indicating durable turn input should stay pending for a later worker. */
534
+ var TurnInputDeferredError = class extends Error {
535
+ code = "turn_input_deferred";
536
+ constructor(message = "Turn input is deferred until the active resume ends") {
537
+ super(message);
538
+ this.name = "TurnInputDeferredError";
539
+ }
540
+ };
541
+ /** Return whether an error means the durable worker should redeliver input later. */
542
+ function isTurnInputDeferredError(error) {
543
+ return error instanceof TurnInputDeferredError;
544
+ }
545
+ /** Mark a turn as the active turn in conversation state. */
546
+ function startActiveTurn(args) {
547
+ args.conversation.processing.activeTurnId = args.nextTurnId;
548
+ }
549
+ function clearActiveTurn(conversation, sessionId) {
550
+ if (!sessionId || conversation.processing.activeTurnId === sessionId) conversation.processing.activeTurnId = void 0;
638
551
  }
639
552
  /**
640
- * Build the thread context of one Turn prompt. With agent history, show only
641
- * the thread Messages saved after the cursor of the previous Turn.
642
- *
643
- * Sets `app.thread_context.*` on the active span: `chat.reply` in a Slack
644
- * Turn, `chat.turn` in a web or Event Turn. Cursor `missing` means that the
645
- * previous Turn ran before cursors existed.
553
+ * Close the active turn without marking a Pi session reusable for future
554
+ * history. Use this for auth handoffs and recovery replies that end the live
555
+ * turn but do not produce a completed Pi session.
646
556
  */
647
- async function buildTurnThreadContext(args) {
648
- const afterSeq = args.hasHistory ? await loadThreadContextCursor({
649
- conversationId: args.conversationId,
650
- turnId: args.turnId
651
- }) : void 0;
652
- const block = buildConversationContext(args.conversation, {
653
- excludeMessageIds: args.excludeMessageIds,
654
- ...args.hasHistory ? { history: { afterSeq } } : void 0
655
- });
656
- setSpanAttributes({
657
- "app.thread_context.chars": block.text?.length ?? 0,
658
- "app.thread_context.shown_messages": block.shownMessages,
659
- "app.thread_context.omitted_messages": block.omittedMessages,
660
- "app.thread_context.cursor": !args.hasHistory ? "no_history" : afterSeq === void 0 ? "missing" : "found"
661
- });
662
- return block.text;
663
- }
664
- // src/chat/runtime/delivered-turn-state.ts
665
- /** Build state after destination delivery or intentional no-reply completion. */
666
- function buildDeliveredTurnStatePatch(args) {
667
- const conversation = structuredClone(args.conversation);
668
- clearPendingAuth(conversation, args.sessionId);
669
- markConversationMessage(conversation, args.userMessageId, {
670
- replied: true,
671
- skippedReason: void 0
672
- });
673
- markTurnCompleted({
674
- conversation,
675
- nowMs: Date.now(),
676
- sessionId: args.sessionId
557
+ function markTurnClosed(args) {
558
+ clearActiveTurn(args.conversation, args.sessionId);
559
+ args.conversation.processing.lastCompletedAtMs = args.nowMs;
560
+ }
561
+ /**
562
+ * Mark a turn as completed after its assistant output has been handled.
563
+ */
564
+ function markTurnCompleted(args) {
565
+ clearActiveTurn(args.conversation, args.sessionId);
566
+ args.conversation.processing.lastCompletedAtMs = args.nowMs;
567
+ }
568
+ /**
569
+ * Mark a turn as failed when execution or final user-visible reply delivery
570
+ * cannot be completed. If `sessionId` is provided, `activeTurnId` is only
571
+ * cleared when it still matches the failing turn.
572
+ */
573
+ function markTurnFailed(args) {
574
+ clearActiveTurn(args.conversation, args.sessionId);
575
+ args.conversation.processing.lastCompletedAtMs = args.nowMs;
576
+ args.markConversationMessage(args.conversation, args.userMessageId, {
577
+ replied: false,
578
+ skippedReason: "reply failed"
677
579
  });
678
- return {
679
- conversation,
680
- sandboxRef: args.reply.sandboxRef
681
- };
682
580
  }
683
581
  // src/chat/runtime/turn-user-message.ts
684
582
  /** Return the user message for a persisted turn/session, if one exists. */
@@ -707,113 +605,4 @@ function getTurnUserReplyAttachmentContext(message) {
707
605
  ...!imagesHydrated && imageAttachmentCount > 0 ? { omittedImageAttachmentCount: imageAttachmentCount } : void 0
708
606
  };
709
607
  }
710
- // src/chat/runtime/auth-pause-state.ts
711
- /** Mark an auth-paused turn complete after private authorization link delivery. */
712
- function completeAuthPauseTurn(args) {
713
- markConversationMessage(args.conversation, getTurnUserMessageId(args.conversation, args.sessionId), {
714
- replied: true,
715
- skippedReason: void 0
716
- });
717
- markTurnClosed({
718
- conversation: args.conversation,
719
- nowMs: Date.now(),
720
- sessionId: args.sessionId
721
- });
722
- }
723
- /** Reload thread state, mark the auth pause as parked, and persist it. */
724
- async function persistAuthPauseTurnState(args) {
725
- const currentState = await getPersistedThreadState(args.threadStateId);
726
- const conversation = coerceThreadConversationState(currentState);
727
- await hydrateConversationMessages({
728
- conversation,
729
- conversationId: args.threadStateId
730
- });
731
- completeAuthPauseTurn({
732
- conversation,
733
- sessionId: args.sessionId
734
- });
735
- await persistThreadStateById(args.threadStateId, { conversation });
736
- }
737
- // src/chat/interruption-marker.ts
738
- const INTERRUPTED_MARKER = "\n\n[Response interrupted before completion]";
739
- /** Return the marker added when a visible reply ended mid-execution. */
740
- function getInterruptionMarker() {
741
- return INTERRUPTED_MARKER;
742
- }
743
- // src/chat/services/turn-failure-response.ts
744
- /** Require captured turn failures to carry a real Sentry event reference. */
745
- function requireTurnFailureEventId(eventId, eventName) {
746
- if (!eventId) throw new Error(`Sentry did not return an event ID for ${eventName}`);
747
- return eventId;
748
- }
749
- function getExecutionFailureReason(reply) {
750
- const errorMessage = reply.diagnostics.errorMessage?.trim();
751
- if (errorMessage) return errorMessage;
752
- if (reply.diagnostics.toolErrorCount > 0) return `${reply.diagnostics.toolErrorCount} tool result error(s)`;
753
- if (reply.diagnostics.assistantMessageCount > 0) return "assistant returned no text";
754
- return "empty assistant turn";
755
- }
756
- /** Return a fixed reason label for a failed model turn. */
757
- function getTurnFailureReason(reply) {
758
- if (reply.diagnostics.outcome === "success") return;
759
- if (reply.diagnostics.outcome === "provider_error") return findProviderError(reply.diagnostics.providerError)?.kind ?? "unknown";
760
- if (reply.diagnostics.toolErrorCount > 0) return "tool_errors";
761
- if (reply.diagnostics.usedPrimaryText && reply.diagnostics.assistantMessageCount > 0) return "suppressed_output";
762
- return "empty_output";
763
- }
764
- function getFailureCapture(reply) {
765
- if (reply.diagnostics.outcome === "provider_error") {
766
- const providerError = findProviderError(reply.diagnostics.providerError);
767
- return {
768
- eventName: "agent.turn.provider_error",
769
- error: reply.diagnostics.providerError ?? new Error(reply.diagnostics.errorMessage ?? "Provider error without explicit message"),
770
- attributes: providerError ? getProviderErrorAttributes(providerError) : {},
771
- body: "Agent turn failed with provider error"
772
- };
773
- }
774
- const failureReason = getExecutionFailureReason(reply);
775
- return {
776
- eventName: "agent.turn.execution.failed",
777
- error: /* @__PURE__ */ new Error(`Agent turn execution failure: ${failureReason}`),
778
- attributes: { "app.ai.execution_failure_reason": failureReason },
779
- body: "Agent turn completed with execution failure"
780
- };
781
- }
782
- /** Keep failed-turn Sentry captures and completion spans on the same keys. */
783
- function getAgentTurnDiagnosticsAttributes(reply) {
784
- return {
785
- "app.ai.outcome": reply.diagnostics.outcome,
786
- "app.ai.assistant_messages": reply.diagnostics.assistantMessageCount,
787
- "app.ai.tool_results": reply.diagnostics.toolResultCount,
788
- "app.ai.tool_error_results": reply.diagnostics.toolErrorCount,
789
- "app.ai.tool_call_count": reply.diagnostics.toolCalls.length,
790
- "app.ai.used_primary_text": reply.diagnostics.usedPrimaryText,
791
- ...reply.diagnostics.reasoningLevel ? { "gen_ai.request.reasoning.level": reply.diagnostics.reasoningLevel } : void 0,
792
- ...reply.diagnostics.stopReason ? { "gen_ai.response.finish_reasons": [reply.diagnostics.stopReason] } : void 0,
793
- ...reply.diagnostics.errorMessage && reply.diagnostics.outcome !== "provider_error" ? { "exception.message": reply.diagnostics.errorMessage } : void 0
794
- };
795
- }
796
- /** Enforce one captured failure response and return its structured correlation. */
797
- function finalizeFailedTurnReplyWithEvent(args) {
798
- if (args.reply.diagnostics.outcome === "success") return { reply: args.reply };
799
- const failureReason = getTurnFailureReason(args.reply);
800
- const capture = getFailureCapture(args.reply);
801
- const eventId = requireTurnFailureEventId(args.logException(capture.error, capture.eventName, {
802
- ...getAgentTurnDiagnosticsAttributes(args.reply),
803
- ...args.attributes,
804
- ...capture.attributes,
805
- ...failureReason ? { "app.ai.failure_reason": failureReason } : void 0
806
- }), capture.eventName);
807
- const providerPartialText = args.reply.diagnostics.outcome === "provider_error" && args.reply.diagnostics.assistantMessageCount > 0 ? args.reply.text.trim() : "";
808
- const providerUserMessage = args.reply.diagnostics.providerError instanceof ProviderError ? getProviderErrorUserMessage(args.reply.diagnostics.providerError) : "";
809
- const failureText = providerUserMessage ? `${providerUserMessage} Reference: \`event_id=${eventId}\`.` : buildTurnFailureResponse(eventId);
810
- return {
811
- eventId,
812
- ...failureReason ? { failureReason } : void 0,
813
- reply: {
814
- ...args.reply,
815
- text: providerPartialText ? `${providerPartialText}${getInterruptionMarker()}` : failureText
816
- }
817
- };
818
- }
819
- export { getUnnamedAgentConversationId as $, markAgentInvocationPaused as A, AGENT_TYPES as B, isTerminalAgentInvocation as C, listPendingAgentInvocationResults as D, listPendingAgentInvocationMailboxAppends as E, CHILD_AGENT_RESULTS as F, getAgentInvocationIdForEvents as G, agentTypeStartsWithParentHistory as H, PARENT_AGENT_TARGET as I, getAgentInvocationMessageId as J, getAgentInvocationIdForMessage as K, agentBindingSchema as L, markAgentInvocationSteered as M, reportReplacedAgentInvocation as N, markAgentInvocationMailboxAppended as O, CHILD_AGENT_KINDS as P, getNamedAgentConversationId as Q, agentNameSchema as R, invocationFromRow as S, listOpenAgentInvocations as T, formatAgentTypes as U, agentTypeInstructions as V, getAgentInvocationId as W, getAgentInvocationTurnId as X, getAgentInvocationResultMessageId as Y, getChildAgentLockName as Z, completeAgentInvocation as _, persistAuthPauseTurnState as a, getConversationTurnBoundaryError as at, getChildAgentLabel as b, getTurnUserSlackMessageTs as c, isTurnInputDeferredError as ct, loadThreadContextTrimFloor as d, markTurnFailed as dt, parseAgentInvocationResultMessageId as et, ConversationTurnLifecycleService as f, startActiveTurn as ft, NON_TERMINAL_AGENT_INVOCATION_STATUSES as g, ACTIVE_AGENT_INVOCATION_STATUSES as h, completeAuthPauseTurn as i, TurnInputDeferredError as it, markAgentInvocationRunning as j, markAgentInvocationParentMailboxAppended as k, buildDeliveredTurnStatePatch as l, markTurnClosed as lt, loadPendingMessageCards as m, buildDeterministicTurnId as mt, getAgentTurnDiagnosticsAttributes as n, CooperativeTurnYieldError as nt, getTurnUserMessage as o, isCooperativeTurnYieldError as ot, getTurnLifecycle as p, buildDeterministicAssistantMessageId as pt, getAgentInvocationIdForResult as q, requireTurnFailureEventId as r, TurnInputCommitLostError as rt, getTurnUserReplyAttachmentContext as s, isTurnInputCommitLostError as st, finalizeFailedTurnReplyWithEvent as t, ConversationTurnBoundaryError as tt, buildTurnThreadContext as u, markTurnCompleted as ut, getActiveAgentInvocationForConversation as v, listAgentInvocationsForConversation as w, getLatestAgentInvocationForConversation as x, getAgentInvocation as y, createAgentInvocationSchema as z };
608
+ export { getAgentInvocationResultMessageId as $, listAgentInvocationsForConversation as A, reportReplacedWithoutOpenWork as B, getActiveAgentInvocationForConversation as C, invocationFromRow as D, getLatestAgentInvocationForConversation as E, markAgentInvocationParentMailboxAppended as F, agentBindingSchema as G, CHILD_AGENT_KINDS as H, markAgentInvocationPaused as I, getAgentInvocationId as J, agentNameSchema as K, markAgentInvocationRunning as L, listPendingAgentInvocationMailboxAppends as M, listPendingAgentInvocationResults as N, isStoppedAgentInvocation as O, markAgentInvocationMailboxAppended as P, getAgentInvocationMessageId as Q, markAgentInvocationSteered as R, completeAgentInvocation as S, getChildAgentLabel as T, CHILD_AGENT_RESULTS as U, sendsResultToParent as V, PARENT_AGENT_TARGET as W, getAgentInvocationIdForMessage as X, getAgentInvocationIdForEvents as Y, getAgentInvocationIdForResult as Z, ConversationTurnLifecycleService as _, ConversationTurnBoundaryError as a, getUnnamedAgentConversationId as at, NON_TERMINAL_AGENT_INVOCATION_STATUSES as b, TurnInputDeferredError as c, parseAgentReplyMessageId as ct, isTurnInputCommitLostError as d, buildDeterministicTurnId as dt, getAgentInvocationTurnId as et, isTurnInputDeferredError as f, startActiveTurn as g, markTurnFailed as h, getTurnUserSlackMessageTs as i, getTurnReplyKey as it, listOpenAgentInvocations as j, isTerminalAgentInvocation as k, getConversationTurnBoundaryError as l, parseTurnReplyMessageId as lt, markTurnCompleted as m, getTurnUserMessageId as n, getChildAgentLockName as nt, CooperativeTurnYieldError as o, isAgentReplyMessageId as ot, markTurnClosed as p, createAgentInvocationSchema as q, getTurnUserReplyAttachmentContext as r, getNamedAgentConversationId as rt, TurnInputCommitLostError as s, parseAgentInvocationResultMessageId as st, getTurnUserMessage as t, getAgentReplyMessageId as tt, isCooperativeTurnYieldError as u, buildDeterministicAssistantMessageId as ut, getTurnLifecycle as v, getAgentInvocation as w, TERMINAL_AGENT_INVOCATION_STATUSES as x, ACTIVE_AGENT_INVOCATION_STATUSES as y, reportReplacedAgentInvocation as z };