@sentry/junior 0.296.0 → 0.297.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-tmGIw4KS.js} +2 -2
  2. package/dist/{agent-runner-HoQiUKLL.js → agent-runner-CneTquAE.js} +378 -1919
  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-BJojZ7HL.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-BrP6ImrC.js} +1 -1
  12. package/dist/{background-compaction-queue-Cre1wFt9.js → background-compaction-queue-CwfJy3Cd.js} +4 -88
  13. package/dist/{briefs-BXECHduJ.js → briefs-uFTuhMqA.js} +3 -3
  14. package/dist/{catalog-runtime-CpCmlD9L.js → catalog-runtime-0kuQqYL4.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-Dj9M_nqB.js} +2 -2
  23. package/dist/{connections-B5pWh8e2.js → connections-B96JUM5o.js} +6 -6
  24. package/dist/{conversation-CMkSmi02.js → conversation-CvcBU1z2.js} +2 -16
  25. package/dist/{conversation-feed-BVAOga0H.js → conversation-feed-BSMlGZnS.js} +1 -1
  26. package/dist/{conversation-privacy-CZD5soDW.js → conversation-privacy-DI29jbZV.js} +1 -1
  27. package/dist/conversation-turn-CZWBr091.js +805 -0
  28. package/dist/{credential-sync-DwLkIvXI.js → credential-sync-Blhx4_xf.js} +14 -13
  29. package/dist/{db-C1M1y-bh.js → db-Br0tfAo7.js} +43 -15
  30. package/dist/{db-B3iyr_Or.d.ts → db-CrtyFRz7.d.ts} +13 -1
  31. package/dist/{executor-DUSEwXaO.js → executor-BMPipFVA.js} +14 -6
  32. package/dist/instrumentation.js +2 -2
  33. package/dist/{logging-D0svFM8r.js → logging-CQjlDQYX.js} +1 -1
  34. package/dist/{message-BFnIwKpx.js → message-BOZEIuxy.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-gusCgdQ6.js} +11 -930
  38. package/dist/{oauth-callback-server-BXRtD6Fk.js → oauth-callback-server-V_DuMuNX.js} +2 -2
  39. package/dist/{projection-B6VS7kbo.js → projection-B08mfi0u.js} +333 -106
  40. package/dist/{prompt-CD11tfG8.js → prompt-BlutWLNt.js} +4 -4
  41. package/dist/prompt-input-Dxn8cDC0.js +1424 -0
  42. package/dist/{registry-CHewwYEo.js → registry-BDWgCJDf.js} +1 -1
  43. package/dist/reporting-window-DopzcOHh.js +137 -0
  44. package/dist/{resolve-1owMH4qo.js → resolve-2Z_o_SsI.js} +3 -3
  45. package/dist/result-CAujiaci.js +463 -0
  46. package/dist/{runner-BtWvJslp.js → runner-D2Chc02N.js} +9 -8
  47. package/dist/{sandbox-egress-signals-ByftwJVt.js → sandbox-egress-signals-CFoJduFj.js} +1 -1
  48. package/dist/{schema-D2iGyYIp.js → schema-Bqa5NbcP.js} +11 -48
  49. package/dist/{schema-Ct1Zf2xy.d.ts → schema-Ce2XCS7O.d.ts} +8 -107
  50. package/dist/{service-account-DLoeoHww.js → service-account-C9kRQEb_.js} +3 -3
  51. package/dist/{service-account-BZEuMKdo.js → service-account-CERfXEVU.js} +3 -3
  52. package/dist/session-stop-B-I1rAS1.js +181 -0
  53. package/dist/{skills-DXgd5Inh.js → skills-B0m1nZ_j.js} +2 -2
  54. package/dist/{spawn-YeqlNDv8.js → spawn-CwMjRRtn.js} +6 -5
  55. package/dist/{state-C3CbtD_m.js → state-DFnmLmfn.js} +2 -2
  56. package/dist/{stop-Cze_pEL8.js → stop-BCH9VNGf.js} +63 -158
  57. package/dist/{store-CZ9vqR4P.js → store-B59rOYbS.js} +11 -4
  58. package/dist/{task-runner-CMiNGsER.js → store-m5bmdmsP.js} +939 -1593
  59. package/dist/task-queue-N0kuCknH.js +89 -0
  60. package/dist/task-runner-COOwR8qm.js +291 -0
  61. package/dist/thread-context-Cd44z_W5.js +248 -0
  62. package/dist/turn-cancel-DDu8TOwt.js +201 -0
  63. package/dist/turn-session-routing-BlCtVFRN.js +380 -0
  64. package/dist/{turn-failure-response-pXhZ2wMK.js → turn-user-message-ygLG3ylQ.js} +183 -361
  65. package/dist/turn-wake-DmQec4AG.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-Ba2OcUse.js} +1 -1
  68. package/dist/{version-EN3Wnq-R.js → version-KNDzIAh6.js} +1 -1
  69. package/dist/version.js +1 -1
  70. package/dist/{viewer-Agxi_o5c.js → viewer-BPpuN2f9.js} +3 -3
  71. package/dist/warmup-Bskrwmk1.js +2697 -0
  72. package/dist/{worker-BALVdWbv.js → worker-B1skZlit.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,11 @@
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-Dj9M_nqB.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-Br0tfAo7.js";
4
+ import { g as juniorAgentInvocations } from "./executor-BMPipFVA.js";
5
+ import { p as credentialContextSchema } from "./registry-BDWgCJDf.js";
6
+ import { i as isEventMailboxMetadata } from "./notification-gusCgdQ6.js";
7
+ import { _ as getConversationWorkState } from "./store-B59rOYbS.js";
8
+ import { d as AGENT_INVOCATION_MAILBOX_STATUSES, f as AGENT_INVOCATION_PARENT_MAILBOX_STATUSES } from "./user-input-request-CXNIov9n.js";
11
9
  import { createHash } from "node:crypto";
12
10
  import * as z from "zod";
13
11
  import { and, asc, desc, eq, inArray, or, sql } from "drizzle-orm";
@@ -21,97 +19,6 @@ function buildDeterministicTurnId(messageId) {
21
19
  function buildDeterministicAssistantMessageId(turnId) {
22
20
  return `${turnId}:assistant:1`;
23
21
  }
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
22
  // src/chat/agent-invocations/ids.ts
116
23
  const CREATE_LOCK_PREFIX = "junior:agent_invocation:create";
117
24
  /**
@@ -166,6 +73,35 @@ function getAgentInvocationTurnId(invocationId) {
166
73
  function getAgentInvocationMessageId(invocationId) {
167
74
  return `agent-invocation:${invocationId}:input`;
168
75
  }
76
+ const REPLY_MESSAGE_PREFIX = "agent-reply:";
77
+ /** Return the parent mailbox identity of one child agent `reply` call. */
78
+ function getAgentReplyMessageId(invocationId, toolCallId) {
79
+ return `${REPLY_MESSAGE_PREFIX}${invocationId}:${toolCallId}`;
80
+ }
81
+ /**
82
+ * Return the key of the `reply` of one Turn on a child's Conversation loop.
83
+ * It starts with the Turn id, so the parent can tell that the Turn replied.
84
+ */
85
+ function getTurnReplyKey(turnId, toolCallId) {
86
+ return `${turnId}:${toolCallId}`;
87
+ }
88
+ const REPLY_MESSAGE_ID = /^agent-reply:(agent-invocation:[0-9a-f]{32}):/;
89
+ /** Read the agent invocation identity from one parent `reply` mailbox identity. */
90
+ function parseAgentReplyMessageId(messageId) {
91
+ return REPLY_MESSAGE_ID.exec(messageId)?.[1];
92
+ }
93
+ const TURN_REPLY_MESSAGE_ID = /^agent-reply:agent-invocation:[0-9a-f]{32}:(turn_[A-Za-z0-9_-]+)(?::|$)/;
94
+ /**
95
+ * Read the Turn id from one parent mailbox identity that a Turn on a child's
96
+ * Conversation loop sent. A `reply` of an agent invocation has none.
97
+ */
98
+ function parseTurnReplyMessageId(messageId) {
99
+ return TURN_REPLY_MESSAGE_ID.exec(messageId)?.[1];
100
+ }
101
+ /** Return whether one parent mailbox identity is a `reply` of an agent invocation. */
102
+ function isAgentReplyMessageId(messageId, invocationId) {
103
+ return messageId.startsWith(`${REPLY_MESSAGE_PREFIX}${invocationId}:`);
104
+ }
169
105
  const RESULT_MESSAGE_PREFIX = "agent-invocation:";
170
106
  const RESULT_MESSAGE_SUFFIX = ":result";
171
107
  /** Return the stable parent mailbox identity for one terminal result. */
@@ -179,18 +115,15 @@ function parseAgentInvocationResultMessageId(messageId) {
179
115
  }
180
116
  // src/chat/agent-invocations/agent-types.ts
181
117
  /**
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.
118
+ * Child agent types. A type is plain data: when to pick it and what the child
119
+ * reads with its task. Runtime code reads only these fields, never a type
120
+ * name, so types can later come from configuration. Types do not limit tools:
121
+ * Guardian reviews each child action against the root user's messages, as for
122
+ * any child. A child keeps its type for later agent invocations. How a child
123
+ * starts, fresh or forked from its parent's history, is not a type: see
124
+ * `fork` on the agent invocation.
188
125
  */
189
- const AGENT_TYPES = [
190
- "fork",
191
- "explore",
192
- "reviewer"
193
- ];
126
+ const AGENT_TYPES = ["explore", "reviewer"];
194
127
  /**
195
128
  * Stored name of a child agent type. A stored name stays readable after its
196
129
  * type is removed; the runtime then treats the child as a
@@ -198,35 +131,21 @@ const AGENT_TYPES = [
198
131
  */
199
132
  const agentTypeSchema = z.string().regex(/^[a-z][a-z0-9_-]*$/);
200
133
  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
134
  explore: {
207
135
  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
136
  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
137
  },
211
138
  reviewer: {
212
139
  whenToUse: "An independent second opinion on a change, plan, or claim. Give it the evidence to judge, not your conclusion.",
213
- startsWithParentHistory: false,
214
140
  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
141
  }
216
142
  };
217
143
  function agentTypeDefinition(type) {
218
144
  return type && Object.hasOwn(AGENT_TYPE_DEFINITIONS, type) ? AGENT_TYPE_DEFINITIONS[type] : void 0;
219
145
  }
220
- /** Model-facing list of child agent types, with how each child starts. */
146
+ /** Model-facing list of child agent types. */
221
147
  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;
148
+ return AGENT_TYPES.map((type) => `- "${type}": ${AGENT_TYPE_DEFINITIONS[type].whenToUse}`).join("\n");
230
149
  }
231
150
  /** Return the instructions that a child of this type reads with its task. */
232
151
  function agentTypeInstructions(type) {
@@ -262,6 +181,8 @@ const agentInvocationBaseSchema = z.object({
262
181
  parentConversationId: exactStringSchema,
263
182
  parentToolCallId: exactStringSchema.optional(),
264
183
  agentType: agentTypeSchema.optional(),
184
+ /** The child starts with its parent's history. */
185
+ fork: z.literal(true).optional(),
265
186
  reasoningLevel: z.enum(TURN_REASONING_LEVELS).optional(),
266
187
  source: sourceSchema,
267
188
  title: exactStringSchema.optional(),
@@ -301,6 +222,7 @@ const createAgentInvocationSchema = z.object({
301
222
  parentConversationId: exactStringSchema,
302
223
  parentToolCallId: exactStringSchema.optional(),
303
224
  agentType: agentTypeSchema.optional(),
225
+ fork: z.literal(true).optional(),
304
226
  reasoningLevel: z.enum(TURN_REASONING_LEVELS).optional(),
305
227
  title: exactStringSchema.optional()
306
228
  }).strict();
@@ -311,6 +233,7 @@ const CHILD_AGENT_RESULTS = [
311
233
  "failed"
312
234
  ];
313
235
  // src/chat/agent-invocations/store.ts
236
+ /** Statuses of a finished agent invocation. */
314
237
  const TERMINAL_AGENT_INVOCATION_STATUSES = [
315
238
  "blocked",
316
239
  "completed",
@@ -342,6 +265,7 @@ function invocationFromRow(row) {
342
265
  ...row.parentMailboxStatus ? { parentMailboxStatus: row.parentMailboxStatus } : void 0,
343
266
  ...row.parentToolCallId ? { parentToolCallId: row.parentToolCallId } : void 0,
344
267
  ...row.agentType ? { agentType: row.agentType } : void 0,
268
+ ...row.fork ? { fork: true } : void 0,
345
269
  ...row.reasoningLevel ? { reasoningLevel: row.reasoningLevel } : void 0,
346
270
  ...row.result !== null ? { result: row.result } : void 0,
347
271
  source: row.source,
@@ -391,17 +315,38 @@ async function listOpenAgentInvocations(conversationId) {
391
315
  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
316
  }
393
317
  /**
318
+ * Return whether a terminal agent invocation sends its result to the parent.
319
+ * A child's final response stays in its Conversation, and a `reply` that
320
+ * reached the parent (its id is in `parentInboundMessageIds`) answered for
321
+ * the invocation. A failure after that, such as a lost worker before the
322
+ * Turn was saved, is not sent either.
323
+ */
324
+ function sendsResultToParent(invocation, parentInboundMessageIds) {
325
+ const replied = parentInboundMessageIds.some((messageId) => isAgentReplyMessageId(messageId, invocation.invocationId));
326
+ switch (invocation.status) {
327
+ case "completed": return !replied && Boolean(invocation.result?.trim());
328
+ case "failed": return !replied;
329
+ default: return true;
330
+ }
331
+ }
332
+ /**
394
333
  * Return whether a child Conversation has work that will start another agent
395
334
  * 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.
335
+ * child agent result that is sent but still waits in its mailbox.
397
336
  */
398
337
  async function hasOpenChildWork(invocation) {
399
338
  const conversationId = invocation.childConversationId;
400
339
  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;
340
+ const marked = await getSqlExecutor().db().select({
341
+ invocationId: juniorAgentInvocations.invocationId,
342
+ parentMailboxStatus: juniorAgentInvocations.parentMailboxStatus,
343
+ result: juniorAgentInvocations.result,
344
+ status: juniorAgentInvocations.status
345
+ }).from(juniorAgentInvocations).where(and(eq(juniorAgentInvocations.parentConversationId, conversationId), inArray(juniorAgentInvocations.parentMailboxStatus, ["pending", "appended"])));
346
+ if (marked.length === 0) return false;
347
+ const work = await getConversationWorkState({ conversationId });
348
+ const unread = new Set(work?.messages.map((message) => message.inboundMessageId));
349
+ return marked.some((row) => sendsResultToParent(row, work?.execution.inboundMessageIds ?? []) && (row.parentMailboxStatus === "pending" || unread.has(getAgentInvocationResultMessageId(row.invocationId))));
405
350
  }
406
351
  /** List bounded invocation records whose mailbox append still needs repair. */
407
352
  async function listPendingAgentInvocationMailboxAppends(limit = 100) {
@@ -422,6 +367,23 @@ async function reportReplacedAgentInvocation(invocationId, nowMs = Date.now()) {
422
367
  }).where(and(eq(juniorAgentInvocations.invocationId, invocationId), eq(juniorAgentInvocations.parentMailboxStatus, "replaced")));
423
368
  return await getAgentInvocation(invocationId);
424
369
  }
370
+ /**
371
+ * Send the `replaced` result of a child Conversation when its open child work
372
+ * ended and sent it nothing, such as a helper that ended with `noReply`. No
373
+ * later agent invocation of the child would send the report. Input from its
374
+ * own child agents that still waits in its mailbox starts one, so that one
375
+ * reports instead.
376
+ */
377
+ async function reportReplacedWithoutOpenWork(conversationId, nowMs = Date.now()) {
378
+ const latest = await getLatestAgentInvocationForConversation(conversationId);
379
+ if (!latest || !isTerminalAgentInvocation(latest) || latest.parentMailboxStatus !== "replaced" || await hasOpenChildWork(latest)) return;
380
+ if ((await getConversationWorkState({ conversationId }))?.messages.some(isChildAgentInputMessage)) return;
381
+ return await reportReplacedAgentInvocation(latest.invocationId, nowMs);
382
+ }
383
+ function isChildAgentInputMessage(message) {
384
+ const metadata = message.input.metadata;
385
+ return isEventMailboxMetadata(metadata) && metadata.event.namespace === "junior";
386
+ }
425
387
  /** Record that one terminal result is in its parent mailbox. */
426
388
  async function markAgentInvocationParentMailboxAppended(invocationId, nowMs = Date.now()) {
427
389
  await getSqlExecutor().db().update(juniorAgentInvocations).set({
@@ -493,64 +455,13 @@ async function markAgentInvocationSteered(invocationId, nowMs = Date.now()) {
493
455
  function isTerminalAgentInvocation(invocation) {
494
456
  return TERMINAL_AGENT_INVOCATION_STATUSES.includes(invocation.status);
495
457
  }
496
- // src/chat/conversations/pending-cards.ts
497
458
  /**
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.
459
+ * Return whether the newest agent invocation of a child shows a stop. A tree
460
+ * stop leaves a `replaced` agent invocation with its finished status and
461
+ * marks it `skipped`, so that also means stopped.
501
462
  */
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));
463
+ function isStoppedAgentInvocation(invocation) {
464
+ return invocation.status === "stopped" || isTerminalAgentInvocation(invocation) && invocation.parentMailboxStatus === "skipped";
554
465
  }
555
466
  // src/chat/conversations/turn-lifecycle.ts
556
467
  /** Persist correlated turn lifecycle facts with retry-safe terminal exclusion. */
@@ -609,76 +520,96 @@ var ConversationTurnLifecycleService = class {
609
520
  function getTurnLifecycle() {
610
521
  return new ConversationTurnLifecycleService(getConversationEventStore());
611
522
  }
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;
523
+ // src/chat/runtime/turn.ts
524
+ /** Classified Slack turn failure carrying the owning Sentry capture outward. */
525
+ var ConversationTurnBoundaryError = class extends Error {
526
+ eventId;
527
+ failureCode;
528
+ constructor(args) {
529
+ super(args.cause instanceof Error ? args.cause.message : String(args.cause), { cause: args.cause });
530
+ this.name = "ConversationTurnBoundaryError";
531
+ this.eventId = args.eventId;
532
+ this.failureCode = args.failureCode;
533
+ }
534
+ };
535
+ /** Return a classified Slack boundary failure without erasing its cause. */
536
+ function getConversationTurnBoundaryError(error) {
537
+ return error instanceof ConversationTurnBoundaryError ? error : void 0;
626
538
  }
627
539
  /**
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.
540
+ * Queue-worker yield routing: respond.ts returns a suspended AgentRunOutcome
541
+ * and the Slack executor raises this at the worker boundary so the lease owner
542
+ * requeues the conversation.
631
543
  */
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;
544
+ var CooperativeTurnYieldError = class extends Error {
545
+ code = "cooperative_turn_yield";
546
+ constructor(message = "Agent turn yielded at a safe boundary") {
547
+ super(message);
548
+ this.name = "CooperativeTurnYieldError";
549
+ }
550
+ };
551
+ function isCooperativeTurnYieldError(error) {
552
+ return error instanceof CooperativeTurnYieldError;
553
+ }
554
+ /** Error indicating durable turn input could not be committed by the worker owner. */
555
+ var TurnInputCommitLostError = class extends Error {
556
+ code = "turn_input_commit_lost";
557
+ constructor(message = "Turn input commit lost its durable owner") {
558
+ super(message);
559
+ this.name = "TurnInputCommitLostError";
560
+ }
561
+ };
562
+ /** Return whether an error means the durable worker lost input ownership. */
563
+ function isTurnInputCommitLostError(error) {
564
+ return error instanceof TurnInputCommitLostError;
565
+ }
566
+ /** Error indicating durable turn input should stay pending for a later worker. */
567
+ var TurnInputDeferredError = class extends Error {
568
+ code = "turn_input_deferred";
569
+ constructor(message = "Turn input is deferred until the active resume ends") {
570
+ super(message);
571
+ this.name = "TurnInputDeferredError";
572
+ }
573
+ };
574
+ /** Return whether an error means the durable worker should redeliver input later. */
575
+ function isTurnInputDeferredError(error) {
576
+ return error instanceof TurnInputDeferredError;
577
+ }
578
+ /** Mark a turn as the active turn in conversation state. */
579
+ function startActiveTurn(args) {
580
+ args.conversation.processing.activeTurnId = args.nextTurnId;
581
+ }
582
+ function clearActiveTurn(conversation, sessionId) {
583
+ if (!sessionId || conversation.processing.activeTurnId === sessionId) conversation.processing.activeTurnId = void 0;
638
584
  }
639
585
  /**
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.
586
+ * Close the active turn without marking a Pi session reusable for future
587
+ * history. Use this for auth handoffs and recovery replies that end the live
588
+ * turn but do not produce a completed Pi session.
646
589
  */
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
590
+ function markTurnClosed(args) {
591
+ clearActiveTurn(args.conversation, args.sessionId);
592
+ args.conversation.processing.lastCompletedAtMs = args.nowMs;
593
+ }
594
+ /**
595
+ * Mark a turn as completed after its assistant output has been handled.
596
+ */
597
+ function markTurnCompleted(args) {
598
+ clearActiveTurn(args.conversation, args.sessionId);
599
+ args.conversation.processing.lastCompletedAtMs = args.nowMs;
600
+ }
601
+ /**
602
+ * Mark a turn as failed when execution or final user-visible reply delivery
603
+ * cannot be completed. If `sessionId` is provided, `activeTurnId` is only
604
+ * cleared when it still matches the failing turn.
605
+ */
606
+ function markTurnFailed(args) {
607
+ clearActiveTurn(args.conversation, args.sessionId);
608
+ args.conversation.processing.lastCompletedAtMs = args.nowMs;
609
+ args.markConversationMessage(args.conversation, args.userMessageId, {
610
+ replied: false,
611
+ skippedReason: "reply failed"
677
612
  });
678
- return {
679
- conversation,
680
- sandboxRef: args.reply.sandboxRef
681
- };
682
613
  }
683
614
  // src/chat/runtime/turn-user-message.ts
684
615
  /** Return the user message for a persisted turn/session, if one exists. */
@@ -707,113 +638,4 @@ function getTurnUserReplyAttachmentContext(message) {
707
638
  ...!imagesHydrated && imageAttachmentCount > 0 ? { omittedImageAttachmentCount: imageAttachmentCount } : void 0
708
639
  };
709
640
  }
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 };
641
+ export { getAgentInvocationIdForMessage 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, AGENT_TYPES as J, agentNameSchema as K, markAgentInvocationRunning as L, listPendingAgentInvocationMailboxAppends as M, listPendingAgentInvocationResults as N, isStoppedAgentInvocation as O, markAgentInvocationMailboxAppended as P, getAgentInvocationIdForEvents as Q, markAgentInvocationSteered as R, completeAgentInvocation as S, getChildAgentLabel as T, CHILD_AGENT_RESULTS as U, sendsResultToParent as V, PARENT_AGENT_TARGET as W, formatAgentTypes as X, agentTypeInstructions as Y, getAgentInvocationId as Z, ConversationTurnLifecycleService as _, ConversationTurnBoundaryError as a, getChildAgentLockName as at, NON_TERMINAL_AGENT_INVOCATION_STATUSES as b, TurnInputDeferredError as c, getUnnamedAgentConversationId as ct, isTurnInputCommitLostError as d, parseAgentReplyMessageId as dt, getAgentInvocationIdForResult as et, isTurnInputDeferredError as f, parseTurnReplyMessageId as ft, startActiveTurn as g, markTurnFailed as h, getTurnUserSlackMessageTs as i, getAgentReplyMessageId as it, listOpenAgentInvocations as j, isTerminalAgentInvocation as k, getConversationTurnBoundaryError as l, isAgentReplyMessageId as lt, markTurnCompleted as m, buildDeterministicTurnId as mt, getTurnUserMessageId as n, getAgentInvocationResultMessageId as nt, CooperativeTurnYieldError as o, getNamedAgentConversationId as ot, markTurnClosed as p, buildDeterministicAssistantMessageId as pt, createAgentInvocationSchema as q, getTurnUserReplyAttachmentContext as r, getAgentInvocationTurnId as rt, TurnInputCommitLostError as s, getTurnReplyKey as st, getTurnUserMessage as t, getAgentInvocationMessageId as tt, isCooperativeTurnYieldError as u, parseAgentInvocationResultMessageId as ut, getTurnLifecycle as v, getAgentInvocation as w, TERMINAL_AGENT_INVOCATION_STATUSES as x, ACTIVE_AGENT_INVOCATION_STATUSES as y, reportReplacedAgentInvocation as z };