@sentry/junior 0.284.0 → 0.285.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 (79) hide show
  1. package/dist/{adapter-CW5UW7vL.js → adapter-DN5AB4VU.js} +37 -3
  2. package/dist/{admin-DUWN8zZX.js → admin-DOITMKnn.js} +1 -1
  3. package/dist/{agent-runner-Cqr21pOU.js → agent-runner-BsWhHe4N.js} +579 -1653
  4. package/dist/api/schema.d.ts +2 -2
  5. package/dist/api/schema.js +7 -6
  6. package/dist/api.d.ts +1 -1
  7. package/dist/api.js +141 -43
  8. package/dist/{app-CvGalMxi.d.ts → app-DyMs9330.d.ts} +2 -2
  9. package/dist/app.d.ts +1 -1
  10. package/dist/app.js +226 -186
  11. package/dist/{assistant-reply-CFE-OZMS.js → assistant-reply-9Jip5bsr.js} +1 -1
  12. package/dist/{automation-Zvx_I9Z5.js → automation-Mk8aaHzy.js} +1 -1
  13. package/dist/{background-compaction-queue-CHFzrQbS.js → background-compaction-queue-DXkLsWoH.js} +2 -2
  14. package/dist/{briefs-Cx7mkfSk.js → briefs-Cl8-nK9B.js} +5 -5
  15. package/dist/{catalog-runtime-dKOVbR7l.js → catalog-runtime-Bte6jRB2.js} +1 -1
  16. package/dist/cli/chat.js +19 -16
  17. package/dist/cli/check.js +3 -3
  18. package/dist/cli/init.js +3 -0
  19. package/dist/cli/main.js +3 -3
  20. package/dist/cli/plugins.js +4 -4
  21. package/dist/cli/snapshot-create.js +4 -4
  22. package/dist/cli/upgrade.d.ts +1 -1
  23. package/dist/cli/upgrade.js +12 -17
  24. package/dist/{client-CMyH5rDz.js → client-DDbBucBw.js} +2 -2
  25. package/dist/{config-Dt3CpG17.js → config-DqFnykQT.js} +1 -1
  26. package/dist/{connections-CCHPybZP.js → connections-DA4LT9LL.js} +10 -10
  27. package/dist/{conversation-DdT7SNar.js → conversation-D8kVoCrP.js} +58 -6
  28. package/dist/{conversation-pending-messages-Dct5pheX.js → conversation-pending-messages-BvROq1bq.js} +1 -1
  29. package/dist/{conversation-privacy-BpHHhEVp.js → conversation-privacy-D0j_h70R.js} +1 -1
  30. package/dist/{credential-sync-BBPw8dam.js → credential-sync-hcsYatw-.js} +13 -13
  31. package/dist/{db-D7CCwAo8.d.ts → db-BhHZSuFw.d.ts} +18 -2
  32. package/dist/{executor-CyIwHz9r.js → executor-BLEMIgIZ.js} +11 -3
  33. package/dist/instrumentation.js +2 -2
  34. package/dist/{logging-Qo-7xGp1.js → logging-BfORLKoq.js} +1 -1
  35. package/dist/{message-DFbtOWqv.js → message-DqjuKzUx.js} +13 -23
  36. package/dist/nitro.d.ts +1 -1
  37. package/dist/nitro.js +3 -3
  38. package/dist/{oauth-callback-server-BB1gixWo.js → oauth-callback-server-CFSRzu1n.js} +2 -2
  39. package/dist/{projection-0UcUeuzn.js → projection-DliWYrnT.js} +280 -71
  40. package/dist/{prompt-CCtaGgbI.js → prompt-BvIUzY4y.js} +8 -6
  41. package/dist/{registry-DOnPkI8g.js → registry-rC7MCxu8.js} +1 -1
  42. package/dist/{reporting-window-B-QP9zX1.js → reporting-window-B4TwyuJo.js} +14 -14
  43. package/dist/{resolve-Di3omymY.js → resolve-Biu8Qw3u.js} +3 -3
  44. package/dist/result-DxJMCX47.js +299 -0
  45. package/dist/result-event-type-DD6BAgT7.js +11 -0
  46. package/dist/{runner-CnX_dTKw.js → runner-BQJSFLKg.js} +11 -11
  47. package/dist/{sandbox-egress-signals-CtxLJmmg.js → sandbox-egress-signals-6aMxJSDn.js} +1 -1
  48. package/dist/{schema-B017enNE.d.ts → schema-BUviRAs8.d.ts} +157 -220
  49. package/dist/{schema-Bn3miEd_.js → schema-BasXTvi2.js} +63 -5
  50. package/dist/{service-account-KhZIqXRi.js → service-account-BI5Wgx22.js} +3 -3
  51. package/dist/{service-account-ewDAx4Mx.js → service-account-CAE-_1dR.js} +3 -3
  52. package/dist/session-stop-CA-jOJ84.js +2924 -0
  53. package/dist/{skills-CKyotM4g.js → skills-B22duVJU.js} +2 -2
  54. package/dist/{spawn-D5D2MQdz.js → spawn-BB2_4VYn.js} +2 -2
  55. package/dist/{stop-BSKRTaRS.js → stop-DioIcEAu.js} +4821 -4199
  56. package/dist/{store-G3S0kWSD.js → store-B26LV6UP.js} +78 -311
  57. package/dist/{store-ymkEUWe4.js → store-Dn4W7qgH.js} +30 -5
  58. package/dist/{task-queue-BcOHzXxe.js → task-queue-Bt0IoR2i.js} +3 -3
  59. package/dist/{task-runner-B65cDumh.js → task-runner-D8lddjzp.js} +7 -7
  60. package/dist/{thread-state-D6rNGQu9.js → thread-state-CrFk3K_7.js} +4 -4
  61. package/dist/{turn-failure-response-BlO4nuDJ.js → turn-failure-response-DaJ04qVj.js} +7 -7
  62. package/dist/{turn-lifecycle-BQ8ETk63.js → turn-lifecycle-C2mXS7AZ.js} +1 -1
  63. package/dist/{turn-session-routing-D_GXfcAG.js → turn-session-routing-CGMKrYOj.js} +10 -10
  64. package/dist/{validation-DJG_wrg2.js → validation-TzhfQABF.js} +1 -1
  65. package/dist/{version-i1An1eTS.js → version-DSk8CFvA.js} +1 -1
  66. package/dist/version.js +1 -1
  67. package/dist/{viewer-BlpnzZZa.js → viewer-1Ea81s0b.js} +190 -53
  68. package/dist/{work-BgCW3FDC.js → work-ybG4_q5C.js} +238 -32
  69. package/dist/{worker-BJz1mwYt.js → worker-ccSyZRNz.js} +6 -6
  70. package/migrations/0083_conversation_kind.sql +11 -0
  71. package/migrations/0084_read_position_backfill.sql +25 -0
  72. package/migrations/0085_child_archived_at.sql +1 -0
  73. package/migrations/meta/0083_snapshot.json +4388 -0
  74. package/migrations/meta/0084_snapshot.json +4388 -0
  75. package/migrations/meta/0085_snapshot.json +4394 -0
  76. package/migrations/meta/_journal.json +21 -0
  77. package/package.json +4 -4
  78. package/dist/result-NvndYzCb.js +0 -483
  79. package/dist/session-stop-D_1SysjC.js +0 -1438
@@ -32,15 +32,6 @@ const AGENT_INVOCATION_PARENT_MAILBOX_STATUSES = [
32
32
  "skipped",
33
33
  "steered"
34
34
  ];
35
- // src/chat/conversations/web-message-id.ts
36
- /**
37
- * Build the retry-stable Message id shared by web ingress and browser sends.
38
- * Keep the existing hash and prefix so retries still address stored Messages.
39
- */
40
- async function webMessageId(args) {
41
- const digest = await crypto.subtle.digest("SHA-256", new TextEncoder().encode(`${args.conversationId}\u0000${args.idempotencyKey}`));
42
- return `api-msg:${Array.from(new Uint8Array(digest), (byte) => byte.toString(16).padStart(2, "0")).join("").slice(0, 24)}`;
43
- }
44
35
  // src/chat/tools/runtime/user-input-request.ts
45
36
  const USER_INPUT_LIMITS = {
46
37
  maxButtonOptions: 5,
@@ -154,13 +145,13 @@ function answerLine(text) {
154
145
  return text.split("\n").map((line) => line.trim()).filter(Boolean).join("\n");
155
146
  }
156
147
  /**
157
- * Write an answer as the text of the person's message. Slack and the web
158
- * dashboard both send this text, so the model reads one format. The first
159
- * line names the request, and each field starts its own line.
148
+ * Write the fields of an answer, one `Label (field_id): value` line each.
149
+ * Slack, the web dashboard, and the prompt all use this text, so the model
150
+ * reads one format.
160
151
  */
161
152
  function formatUserInputAnswer(request, answer) {
162
153
  const normalized = normalizeUserInputAnswer(request, answer);
163
- const lines = [`Answer to request ${normalized.requestId}:`];
154
+ const lines = [];
164
155
  for (const field of request.fields) {
165
156
  const values = normalized.values[field.id];
166
157
  const value = values?.length ? values.join(", ") : "(no answer)";
@@ -169,6 +160,15 @@ function formatUserInputAnswer(request, answer) {
169
160
  if (normalized.other) lines.push(answerLine(`Other: ${normalized.other}`));
170
161
  return lines.join("\n");
171
162
  }
163
+ // src/chat/conversations/web-message-id.ts
164
+ /**
165
+ * Build the retry-stable Message id shared by web ingress and browser sends.
166
+ * Keep the existing hash and prefix so retries still address stored Messages.
167
+ */
168
+ async function webMessageId(args) {
169
+ const digest = await crypto.subtle.digest("SHA-256", new TextEncoder().encode(`${args.conversationId}\u0000${args.idempotencyKey}`));
170
+ return `api-msg:${Array.from(new Uint8Array(digest), (byte) => byte.toString(16).padStart(2, "0")).join("").slice(0, 24)}`;
171
+ }
172
172
  // src/api/reporting-window.ts
173
173
  /** Shared UTC day/hour/six-hour windows for dashboard activity series. */
174
174
  const HOUR_MS = 36e5;
@@ -292,4 +292,4 @@ function sumUtcHoursIntoSixHours(args) {
292
292
  rows: bySix
293
293
  });
294
294
  }
295
- export { AGENT_INVOCATION_STATUSES as C, userCustomizationTextSchema as E, AGENT_INVOCATION_PARENT_MAILBOX_STATUSES as S, userCustomizationSchema as T, isEmptyUserInputAnswer as _, fillUtcSixHours as a, webMessageId as b, trailingUtcDayWindow as c, utcDayKey as d, utcHourKey as f, formatUserInputAnswer as g, buttonUserInputField as h, fillUtcHours as i, trailingUtcHourWindow as l, USER_INPUT_NOTE as m, HOUR_MS as n, startOfUtcHour as o, USER_INPUT_LIMITS as p, fillUtcDays as r, sumUtcHoursIntoSixHours as s, DAY_MS as t, trailingUtcSixHourWindow as u, normalizeUserInputAnswer as v, USER_CUSTOMIZATION_MAX_CHARS as w, AGENT_INVOCATION_MAILBOX_STATUSES as x, userInputRequestSchema as y };
295
+ export { AGENT_INVOCATION_STATUSES as C, userCustomizationTextSchema as E, AGENT_INVOCATION_PARENT_MAILBOX_STATUSES as S, userCustomizationSchema as T, formatUserInputAnswer as _, fillUtcSixHours as a, userInputRequestSchema as b, trailingUtcDayWindow as c, utcDayKey as d, utcHourKey as f, buttonUserInputField as g, USER_INPUT_NOTE as h, fillUtcHours as i, trailingUtcHourWindow as l, USER_INPUT_LIMITS as m, HOUR_MS as n, startOfUtcHour as o, webMessageId as p, fillUtcDays as r, sumUtcHoursIntoSixHours as s, DAY_MS as t, trailingUtcSixHourWindow as u, isEmptyUserInputAnswer as v, USER_CUSTOMIZATION_MAX_CHARS as w, AGENT_INVOCATION_MAILBOX_STATUSES as x, normalizeUserInputAnswer as y };
@@ -1,6 +1,6 @@
1
- import { Ea as SANDBOX_COMMAND_PATH, La as runNonInteractiveCommand, ba as sleep, gi as isStale, ja as SANDBOX_WORKSPACE_ROOT, mi as create, vi as getSandboxProvider } from "./projection-0UcUeuzn.js";
2
- import { E as withSpan, b as setSpanAttributes } from "./logging-Qo-7xGp1.js";
3
- import { r as getStateAdapter } from "./adapter-CW5UW7vL.js";
1
+ import { Di as isStale, La as SANDBOX_COMMAND_PATH, Ti as create, Va as SANDBOX_WORKSPACE_ROOT, ja as sleep, ki as getSandboxProvider, qa as runNonInteractiveCommand } from "./projection-DliWYrnT.js";
2
+ import { E as withSpan, b as setSpanAttributes } from "./logging-BfORLKoq.js";
3
+ import { r as getStateAdapter } from "./adapter-DN5AB4VU.js";
4
4
  import * as z from "zod";
5
5
  // src/chat/sandbox/resources.ts
6
6
  let configuredResources;
@@ -0,0 +1,299 @@
1
+ import { v as __exportAll } from "./sentry-BRTJqumy.js";
2
+ import { _n as renderUntrustedTag } from "./projection-DliWYrnT.js";
3
+ import { H as SYSTEM_IDENTITY_ID } from "./viewer-1Ea81s0b.js";
4
+ import { f as credentialContextForActor } from "./registry-rC7MCxu8.js";
5
+ import { jt as listUnreportedSiblingAgents } from "./agent-runner-BsWhHe4N.js";
6
+ import { A as getAgentInvocationIdForEvents, M as getAgentInvocationIdForResult, P as getAgentInvocationResultMessageId, a as getAgentInvocation, h as markAgentInvocationParentMailboxAppended, j as getAgentInvocationIdForMessage, l as isTerminalAgentInvocation, s as getLatestAgentInvocationForConversation } from "./store-B26LV6UP.js";
7
+ import { C as isEventMailboxMetadata, T as timerWatchCredentialSubject, b as EVENT_WAIT_MS, d as getEventBatchDelayMs, n as isWatchEvent, p as parseEventMessages, s as eventReviewItemInputs, w as renderEventBatchInputs } from "./session-stop-CA-jOJ84.js";
8
+ import { r as appendAndEnqueueInboundMessage } from "./store-Dn4W7qgH.js";
9
+ import { a as resolveAgentInvocationId, i as enqueueAgentInvocation, l as createAgentInvocationFromLatest, t as createAgentInvocationWorker } from "./work-ybG4_q5C.js";
10
+ import { n as isAgentInvocationResultEventType, t as agentInvocationResultEventType } from "./result-event-type-DD6BAgT7.js";
11
+ // src/chat/agent-invocations/result.ts
12
+ var result_exports = /* @__PURE__ */ __exportAll({
13
+ createChildConversationWorker: () => createChildConversationWorker,
14
+ enqueueAgentInvocationResult: () => enqueueAgentInvocationResult,
15
+ enqueueAgentMessageToParent: () => enqueueAgentMessageToParent,
16
+ withAgentInvocationResultActors: () => withAgentInvocationResultActors
17
+ });
18
+ const AGENT_INVOCATION_EVENT_NAMESPACE = "junior";
19
+ const AGENT_INVOCATION_RESULT_MAX_LENGTH = 12e3;
20
+ /** Event type of a message that a child agent sends to its parent. */
21
+ const AGENT_MESSAGE_EVENT_TYPE = "agent.message";
22
+ /**
23
+ * Return the Inbound message author id for results sent by one Actor.
24
+ * `selectContiguousTurnBatch` in `task-execution/worker.ts` puts messages in
25
+ * one attempt only when their author ids and sources match. Mid-Turn drains
26
+ * take only `interrupt` messages, and results are `defer`. So results never
27
+ * share a Turn and its credentials with another Actor or with watch Events.
28
+ * Keep this id unique per Actor if either rule changes.
29
+ */
30
+ function resultAuthorId(actor) {
31
+ switch (actor.platform) {
32
+ case "system": return `agent-invocation:system:${actor.name}`;
33
+ case "slack": return `agent-invocation:slack:${actor.teamId}:${actor.userId}`;
34
+ default: return `agent-invocation:${actor.platform}:${actor.userId}`;
35
+ }
36
+ }
37
+ /**
38
+ * Error messages can contain text from tools or providers, so the trusted
39
+ * summary in the mailbox metadata has only the status.
40
+ */
41
+ function trustedSummary(invocation, agent) {
42
+ switch (invocation.status) {
43
+ case "completed": return `${agent} finished its task.`;
44
+ case "blocked": return `${agent} is blocked.`;
45
+ case "failed": return `${agent} failed.`;
46
+ case "stopped": return `${agent} was stopped.`;
47
+ }
48
+ }
49
+ /**
50
+ * Render the parent agent input for one terminal agent invocation as one
51
+ * `<agent-result>`. A child agent wrote the output, so it is escaped data.
52
+ * `status` and `waiting_on` are runtime facts. The system prompt says what to
53
+ * do for each status, so the input repeats no guidance.
54
+ */
55
+ function renderResultInput(invocation, openSiblings) {
56
+ const output = (invocation.status === "completed" ? invocation.result : invocation.errorMessage).trim().slice(0, AGENT_INVOCATION_RESULT_MAX_LENGTH);
57
+ return renderUntrustedTag("agent-result", {
58
+ conversation_id: invocation.childConversationId,
59
+ name: invocation.agentName,
60
+ source: "child_agent",
61
+ status: invocation.status,
62
+ title: invocation.title,
63
+ waiting_on: openSiblings.length ? openSiblings.map(siblingLabel).join(", ") : void 0
64
+ }, "A child agent that you started", output || "(empty)");
65
+ }
66
+ function siblingLabel(sibling) {
67
+ return sibling.agentName ?? sibling.title ?? sibling.childConversationId;
68
+ }
69
+ /** Build the parent Inbound message for one terminal agent invocation. */
70
+ function buildResultInboundMessage(invocation, nowMs, openSiblings) {
71
+ const summary = trustedSummary(invocation, childAgentLabel(invocation));
72
+ const metadata = {
73
+ kind: "event",
74
+ event: {
75
+ eventKey: invocation.invocationId,
76
+ eventType: agentInvocationResultEventType(invocation.status),
77
+ identifier: invocation.invocationId,
78
+ namespace: AGENT_INVOCATION_EVENT_NAMESPACE,
79
+ trustedSummary: summary
80
+ }
81
+ };
82
+ return {
83
+ conversationId: invocation.parentConversationId,
84
+ createdAtMs: invocation.terminalAtMs,
85
+ delivery: "defer",
86
+ inboundMessageId: getAgentInvocationResultMessageId(invocation.invocationId),
87
+ input: {
88
+ authorId: resultAuthorId(invocation.actor),
89
+ authorIdentityId: SYSTEM_IDENTITY_ID,
90
+ metadata,
91
+ text: renderResultInput(invocation, openSiblings)
92
+ },
93
+ receivedAtMs: nowMs,
94
+ source: "event"
95
+ };
96
+ }
97
+ /**
98
+ * Append one terminal agent invocation result to the parent mailbox and wake
99
+ * the parent. Repeat calls are safe.
100
+ *
101
+ * Results do not go through `admitAutomatedTurn`, so the automated-turn limit
102
+ * never drops them. Result Turns still count toward that limit.
103
+ * TODO(dcramer): Add a per-parent total invocation limit as the loop guard
104
+ * for spawn -> result -> spawn chains (#881).
105
+ */
106
+ async function enqueueAgentInvocationResult(invocation, options) {
107
+ if (invocation.parentMailboxStatus !== "pending") return;
108
+ const nowMs = options.nowMs ?? Date.now();
109
+ const openSiblings = await listUnreportedSiblingAgents(invocation.parentConversationId, invocation.childConversationId);
110
+ await appendAndEnqueueInboundMessage({
111
+ message: buildResultInboundMessage(invocation, nowMs, openSiblings),
112
+ queue: options.queue,
113
+ queueDelayMs: EVENT_WAIT_MS,
114
+ state: options.state
115
+ });
116
+ await markAgentInvocationParentMailboxAppended(invocation.invocationId, nowMs);
117
+ }
118
+ function childAgentLabel(invocation) {
119
+ return invocation.agentName ? `Child agent "${invocation.agentName}"` : "Child agent";
120
+ }
121
+ function renderMessageInput(sender, text) {
122
+ return renderUntrustedTag("agent-message", {
123
+ conversation_id: sender.childConversationId,
124
+ name: sender.agentName,
125
+ source: "child_agent",
126
+ title: sender.title
127
+ }, "A child agent that you started", text.trim());
128
+ }
129
+ /**
130
+ * Append one message from a child agent to its parent mailbox and wake the
131
+ * parent. `sender` is the open agent invocation of the child. The parent
132
+ * handles the message like a result: a root parent runs an Event Turn, and a
133
+ * child parent starts a new agent invocation. Repeat calls with the same
134
+ * `messageKey` are safe.
135
+ */
136
+ async function enqueueAgentMessageToParent(args) {
137
+ const nowMs = args.nowMs ?? Date.now();
138
+ const inboundMessageId = `agent-invocation:${args.sender.invocationId}:message:${args.messageKey}`;
139
+ const summary = `${childAgentLabel(args.sender)} sent a message.`;
140
+ const metadata = {
141
+ kind: "event",
142
+ event: {
143
+ eventKey: inboundMessageId,
144
+ eventType: AGENT_MESSAGE_EVENT_TYPE,
145
+ identifier: args.sender.invocationId,
146
+ namespace: AGENT_INVOCATION_EVENT_NAMESPACE,
147
+ trustedSummary: summary
148
+ }
149
+ };
150
+ await appendAndEnqueueInboundMessage({
151
+ message: {
152
+ conversationId: args.sender.parentConversationId,
153
+ createdAtMs: nowMs,
154
+ delivery: "defer",
155
+ inboundMessageId,
156
+ input: {
157
+ authorId: resultAuthorId(args.sender.actor),
158
+ authorIdentityId: SYSTEM_IDENTITY_ID,
159
+ metadata,
160
+ text: renderMessageInput(args.sender, args.text)
161
+ },
162
+ receivedAtMs: nowMs,
163
+ source: "event"
164
+ },
165
+ queue: args.queue,
166
+ queueDelayMs: EVENT_WAIT_MS,
167
+ state: args.state
168
+ });
169
+ }
170
+ /**
171
+ * Read the agent invocation that one result or message Event refers to: the
172
+ * finished child work for a result, or the open sender work for a message.
173
+ */
174
+ function childAgentInput(message) {
175
+ const metadata = message.input.metadata;
176
+ if (!isEventMailboxMetadata(metadata) || metadata.event.namespace !== AGENT_INVOCATION_EVENT_NAMESPACE) return;
177
+ if (metadata.event.eventType === AGENT_MESSAGE_EVENT_TYPE) return {
178
+ invocationId: metadata.event.identifier,
179
+ kind: "message"
180
+ };
181
+ return isAgentInvocationResultEventType(metadata.event.eventType) ? {
182
+ invocationId: metadata.event.identifier,
183
+ kind: "result"
184
+ } : void 0;
185
+ }
186
+ /**
187
+ * Return whether a stop after this result was sent skipped it, so it starts no
188
+ * work. A message that a child sent before its stop is still delivered.
189
+ */
190
+ function isSkippedAgentResult(input, invocation) {
191
+ return input.kind === "result" && isTerminalAgentInvocation(invocation) && invocation.parentMailboxStatus === "skipped";
192
+ }
193
+ /**
194
+ * Read the agent invocation of one result or message and check that it
195
+ * belongs to a child of the Conversation that received it.
196
+ */
197
+ async function getChildAgentInputInvocation(message, input) {
198
+ const invocation = await getAgentInvocation(input.invocationId);
199
+ if (!invocation || input.kind === "result" && !isTerminalAgentInvocation(invocation) || invocation.parentConversationId !== message.conversationId) throw new Error(`Agent invocation ${input.kind} ${input.invocationId} does not belong to ${message.conversationId}`);
200
+ return invocation;
201
+ }
202
+ /**
203
+ * Give mailbox input that reaches a child Conversation to that child: results
204
+ * and messages from its own child agents, and its own watch events. A child
205
+ * Conversation has no Location, so it cannot run an Event Turn. Each input
206
+ * starts a new agent invocation on the child instead, and that invocation
207
+ * reports to the child's parent. Returns undefined for work that is not
208
+ * mailbox input for a child Conversation.
209
+ */
210
+ async function startAgentInvocationsForChildInput(context, options) {
211
+ const messages = context.attempt.messages;
212
+ const inputs = messages.map(childAgentInput);
213
+ const isAgentInput = inputs.every((input) => input !== void 0);
214
+ const events = isAgentInput ? [] : parseEventMessages(messages);
215
+ if (messages.length === 0 || !isAgentInput && events.length === 0) return;
216
+ const latest = await getLatestAgentInvocationForConversation(context.conversationId);
217
+ if (!latest) return;
218
+ if ((latest.status === "stopped" || isTerminalAgentInvocation(latest) && latest.parentMailboxStatus === "skipped") && (isAgentInput || !messages.every(isWatchEvent))) {
219
+ await context.attempt.ack();
220
+ return { status: "completed" };
221
+ }
222
+ if (!isAgentInput) {
223
+ const delayMs = getEventBatchDelayMs(messages);
224
+ if (delayMs > 0) return {
225
+ status: "deferred",
226
+ delayMs
227
+ };
228
+ const { actor, source } = events[0];
229
+ const invocation = await createAgentInvocationFromLatest({
230
+ input: renderEventBatchInputs(messages, await eventReviewItemInputs(messages)).join("\n\n"),
231
+ invocationId: getAgentInvocationIdForEvents(messages[0].inboundMessageId),
232
+ latest,
233
+ runAs: {
234
+ actor,
235
+ credentialContext: credentialContextForActor(actor, timerWatchCredentialSubject(context.conversationId, messages)),
236
+ source
237
+ }
238
+ });
239
+ await enqueueAgentInvocation(invocation, options);
240
+ await context.attempt.ack();
241
+ return { status: "completed" };
242
+ }
243
+ for (const [index, message] of messages.entries()) {
244
+ const input = inputs[index];
245
+ const source = await getChildAgentInputInvocation(message, input);
246
+ if (isSkippedAgentResult(input, source)) continue;
247
+ const invocation = await createAgentInvocationFromLatest({
248
+ input: message.input.text.trim(),
249
+ invocationId: input.kind === "result" ? getAgentInvocationIdForResult(source.invocationId) : getAgentInvocationIdForMessage(message.inboundMessageId),
250
+ latest
251
+ });
252
+ await enqueueAgentInvocation(invocation, options);
253
+ }
254
+ await context.attempt.ack();
255
+ return { status: "completed" };
256
+ }
257
+ /**
258
+ * Build the worker for all work of a child Conversation. The caller selects
259
+ * it from the stored parent of the Conversation, never from a Turn Source. It
260
+ * starts agent invocations for child input, then runs the agent invocation
261
+ * that owns the work. Work that no agent invocation owns is an error.
262
+ */
263
+ function createChildConversationWorker(agentRunner, options) {
264
+ const invocationWorker = createAgentInvocationWorker(agentRunner, options);
265
+ return async (context) => {
266
+ const started = await startAgentInvocationsForChildInput(context, options);
267
+ if (started) return started;
268
+ const invocationId = await resolveAgentInvocationId(context);
269
+ if (!invocationId) throw new Error(`Child conversation ${context.conversationId} has no agent invocation for this work`);
270
+ return await invocationWorker(context, invocationId);
271
+ };
272
+ }
273
+ /**
274
+ * Run each agent invocation result or message as the Actor that triggered the
275
+ * child, user or system. This is on purpose: the result continues that
276
+ * Actor's work. The Actor comes from SQL, not from mailbox metadata, so the
277
+ * parent Turn has the same authority it had at spawn time. A result that a
278
+ * stop skipped is dropped. Returns undefined when no input is left.
279
+ *
280
+ * TODO(dcramer): Pass the delegated credential subject of a system Actor, such
281
+ * as a timer watch Turn, when system Turns can spawn children that need it.
282
+ */
283
+ async function withAgentInvocationResultActors(work) {
284
+ if (work.kind !== "mailbox") return work;
285
+ const kept = (await Promise.all(work.batch.map(async (entry) => {
286
+ const input = childAgentInput(entry.message);
287
+ if (!input) return entry;
288
+ const invocation = await getChildAgentInputInvocation(entry.message, input);
289
+ return isSkippedAgentResult(input, invocation) ? void 0 : {
290
+ ...entry,
291
+ actor: invocation.actor
292
+ };
293
+ }))).filter((entry) => entry !== void 0);
294
+ return kept.length > 0 ? {
295
+ kind: "mailbox",
296
+ batch: kept
297
+ } : void 0;
298
+ }
299
+ export { withAgentInvocationResultActors as a, result_exports as i, enqueueAgentInvocationResult as n, enqueueAgentMessageToParent as r, createChildConversationWorker as t };
@@ -0,0 +1,11 @@
1
+ // src/chat/agent-invocations/result-event-type.ts
2
+ const AGENT_INVOCATION_RESULT_EVENT_TYPE_PREFIX = "agent_invocation.";
3
+ /** Build the Event type of the parent message for one agent invocation result. */
4
+ function agentInvocationResultEventType(status) {
5
+ return `${AGENT_INVOCATION_RESULT_EVENT_TYPE_PREFIX}${status}`;
6
+ }
7
+ /** True when an Event type names an agent invocation result. */
8
+ function isAgentInvocationResultEventType(eventType) {
9
+ return eventType.startsWith(AGENT_INVOCATION_RESULT_EVENT_TYPE_PREFIX);
10
+ }
11
+ export { isAgentInvocationResultEventType as n, agentInvocationResultEventType as t };
@@ -1,14 +1,14 @@
1
- import { B as authorizationId, D as buildConversationContext, I as upsertConversationMessage, M as markConversationMessage, N as normalizeConversationText, P as recordDeliveredAssistantMessage, Ut as persistWithRetry, Z as saveTurnCheckpoint, a as loadProjection, d as recordAuthorizationCompleted, t as commitAcceptedReply, v as hydrateConversationMessages, y as persistConversationMessages } from "./projection-0UcUeuzn.js";
2
- import { S as setTags, T as withLogContext, p as logException } from "./logging-Qo-7xGp1.js";
3
- import { F as SYSTEM_IDENTITY_ID, x as getConversationStore, y as getConversationEventStore } from "./viewer-BlpnzZZa.js";
4
- import { f as credentialContextForActor } from "./registry-DOnPkI8g.js";
5
- import { j as messageCardText } from "./conversation-DdT7SNar.js";
6
- import { $ as markTurnFailed, et as startActiveTurn } from "./store-G3S0kWSD.js";
7
- import { n as getAssistantReplyText } from "./assistant-reply-CFE-OZMS.js";
8
- import { t as ConversationTurnLifecycleService } from "./turn-lifecycle-BQ8ETk63.js";
9
- import { a as persistThreadStateById, n as getPersistedSandboxState, o as coerceThreadConversationState, r as getPersistedThreadState } from "./thread-state-D6rNGQu9.js";
10
- import { n as scheduleSessionCompletedPluginTasks, t as processPluginTask } from "./task-runner-B65cDumh.js";
11
- import { i as completeAuthPauseTurn, l as buildDeliveredTurnStatePatch, t as finalizeFailedTurnReplyWithEvent, u as loadPendingMessageCards } from "./turn-failure-response-BlO4nuDJ.js";
1
+ import { F as recordDeliveredAssistantMessage, L as upsertConversationMessage, N as markConversationMessage, O as buildConversationContext, P as normalizeConversationText, Q as saveTurnCheckpoint, V as authorizationId, a as loadProjection, d as recordAuthorizationCompleted, qt as persistWithRetry, t as commitAcceptedReply, v as hydrateConversationMessages, y as persistConversationMessages } from "./projection-DliWYrnT.js";
2
+ import { S as setTags, T as withLogContext, p as logException } from "./logging-BfORLKoq.js";
3
+ import { H as SYSTEM_IDENTITY_ID, x as getConversationStore, y as getConversationEventStore } from "./viewer-1Ea81s0b.js";
4
+ import { f as credentialContextForActor } from "./registry-rC7MCxu8.js";
5
+ import { N as messageCardText } from "./conversation-D8kVoCrP.js";
6
+ import { X as markTurnFailed, Z as startActiveTurn } from "./store-B26LV6UP.js";
7
+ import { n as getAssistantReplyText } from "./assistant-reply-9Jip5bsr.js";
8
+ import { t as ConversationTurnLifecycleService } from "./turn-lifecycle-C2mXS7AZ.js";
9
+ import { a as persistThreadStateById, n as getPersistedSandboxState, o as coerceThreadConversationState, r as getPersistedThreadState } from "./thread-state-CrFk3K_7.js";
10
+ import { n as scheduleSessionCompletedPluginTasks, t as processPluginTask } from "./task-runner-D8lddjzp.js";
11
+ import { i as completeAuthPauseTurn, l as buildDeliveredTurnStatePatch, t as finalizeFailedTurnReplyWithEvent, u as loadPendingMessageCards } from "./turn-failure-response-DaJ04qVj.js";
12
12
  import { randomUUID } from "node:crypto";
13
13
  import { createLocalSource, localDestinationSchema } from "@sentry/junior-plugin-api";
14
14
  // src/chat/local/runner.ts
@@ -1,4 +1,4 @@
1
- import { ha as sandboxEgressSignalsResponseSchema } from "./projection-0UcUeuzn.js";
1
+ import { Ea as sandboxEgressSignalsResponseSchema } from "./projection-DliWYrnT.js";
2
2
  // src/chat/local/sandbox-egress-signals.ts
3
3
  const SANDBOX_EGRESS_SIGNALS_PATH = "/api/internal/sandbox-egress/signals";
4
4
  const LOCAL_DEV_SERVER_TIMEOUT_MS = 1e3;