@sentry/junior 0.298.0 → 0.300.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 (95) hide show
  1. package/dist/{actor-6jsm_v96.js → actor-D2iXzvlN.js} +2 -1
  2. package/dist/{state-CSuA2J1V.js → adapter-S5UkjNK3.js} +53 -136
  3. package/dist/{admin-BF3DbYGf.js → admin-UrTniSPO.js} +2 -2
  4. package/dist/{agent-runner-Q9GkoerG.js → agent-runner-bY4_0UPm.js} +1444 -1478
  5. package/dist/api/schema.d.ts +2 -2
  6. package/dist/api/schema.js +7 -7
  7. package/dist/api.d.ts +1 -1
  8. package/dist/api.js +382 -68
  9. package/dist/{app-DOg_mCtV.d.ts → app-D-AcIcCV.d.ts} +17 -4
  10. package/dist/app.d.ts +1 -1
  11. package/dist/app.js +148 -483
  12. package/dist/{automation-Cn8qmbdr.js → automation-Dw82oQ-h.js} +2 -2
  13. package/dist/{background-compaction-queue-BZhGFOK6.js → background-compaction-queue-B6U3060-.js} +9 -5
  14. package/dist/{briefs-CQrCRF6-.js → briefs-DqiwWu-n.js} +4 -4
  15. package/dist/{catalog-runtime-DZeD2WbL.js → catalog-runtime-D1oYNv04.js} +1 -1
  16. package/dist/cli/chat.js +17 -17
  17. package/dist/cli/check.js +3 -3
  18. package/dist/cli/main.js +3 -3
  19. package/dist/cli/plugins.js +5 -5
  20. package/dist/cli/snapshot-create.js +4 -4
  21. package/dist/cli/upgrade.d.ts +1 -1
  22. package/dist/cli/upgrade.js +4 -4
  23. package/dist/{config-BOByVnxe.js → config-9nHoFiJP.js} +117 -12
  24. package/dist/{connections-BNN5cJam.js → connections-DZjTN3JC.js} +6 -6
  25. package/dist/continue-in-slack-Dtv7_U42.js +176 -0
  26. package/dist/{conversation-DCkzvxqB.js → conversation-Dyjq2CZ8.js} +36 -13
  27. package/dist/{conversation-feed-CMA12Rjs.js → conversation-feed-CcDxlrlQ.js} +109 -3
  28. package/dist/{conversation-privacy-C0eRxsgb.js → conversation-privacy-D-5HTXjS.js} +1 -1
  29. package/dist/{conversation-turn-D9qvcDX6.js → conversation-turn-Cxl8WZD7.js} +85 -68
  30. package/dist/{credential-sync-B_iUpxGL.js → credential-sync-C49ClwDX.js} +18 -18
  31. package/dist/{db-DoMcnYol.d.ts → db-2resqBh1.d.ts} +1 -1
  32. package/dist/{db-CoMNr2Zm.js → db-BJNo6fK5.js} +176 -12
  33. package/dist/{executor-C-m8VrzX.js → executor-DBIaOeJ_.js} +47 -13
  34. package/dist/{media-BepyEUNm.js → history-IjdmO_r6.js} +1 -85
  35. package/dist/instrumentation.js +14 -5
  36. package/dist/lineage-0dereG7H.js +37 -0
  37. package/dist/{logging-CJTi5niy.js → logging-BIclibct.js} +1 -1
  38. package/dist/{message-Q6_5DAWR.js → message-dkOl-Iii.js} +9 -10
  39. package/dist/model-input-CLo9TaUd.js +82 -0
  40. package/dist/nitro.d.ts +1 -1
  41. package/dist/nitro.js +17 -9
  42. package/dist/{oauth-callback-server-CH5XAyo-.js → oauth-callback-server-WmpjfJgQ.js} +2 -2
  43. package/dist/{plugins-HYh_JOdw.js → plugins-BBX07Jzt.js} +1 -1
  44. package/dist/{projection-BgwEE36_.js → projection-w_X-zi7v.js} +1035 -692
  45. package/dist/{prompt-DXc9DYT9.js → prompt-B1Xw46-S.js} +4 -4
  46. package/dist/{registry-9XwqSnM-.js → registry-BmP5vnlj.js} +4 -4
  47. package/dist/{resolve-DUIAbcRL.js → resolve-goo34bJK.js} +3 -3
  48. package/dist/{result-C2Vn8QGn.js → result-PVBeU0Wf.js} +158 -69
  49. package/dist/{runner-CXGtw-Mc.js → runner-DKrfvNV6.js} +9 -9
  50. package/dist/{sandbox-egress-signals-Di3S_dO7.js → sandbox-egress-signals-DsUcqrI0.js} +1 -1
  51. package/dist/{schema-Dyp7racy.js → schema-C9iNFz5n.js} +51 -7
  52. package/dist/{schema-BnbZ-rKv.d.ts → schema-Dns-sTas.d.ts} +1285 -761
  53. package/dist/{service-account-DM3KBBeG.js → service-account-CMAAloAL.js} +3 -3
  54. package/dist/{service-account-GzAMUQ8a.js → service-account-CmowamcB.js} +4 -4
  55. package/dist/session-stop-BcAXze8a.js +3330 -0
  56. package/dist/{skills-DCK9SD_l.js → skills-DfsazET6.js} +3 -3
  57. package/dist/slack-conversation-unfurl-CzQonuWz.js +370 -0
  58. package/dist/spawn-C7o0FDDp.js +73 -0
  59. package/dist/state-zSilNpbi.js +132 -0
  60. package/dist/{user-input-request-CXNIov9n.js → statuses-Hn-HsOph.js} +115 -26
  61. package/dist/{stop-Dh2DfwpK.js → stop-CFOujp8C.js} +9105 -6007
  62. package/dist/{store-DrA17Fbz.js → store-Dkeis_8o.js} +10 -10
  63. package/dist/{store-B1zepKG8.js → store-E3x2Fg_F.js} +24 -4
  64. package/dist/{task-queue-D1rXWfFN.js → task-queue-D-hCqdZW.js} +4 -4
  65. package/dist/{task-runner-CT4M8oDz.js → task-runner-vohUPLHe.js} +10 -10
  66. package/dist/{thread-context-DnqUkbzN.js → thread-context-BzvdkgI9.js} +18 -18
  67. package/dist/{turn-session-routing-VXDVXLRl.js → turn-session-routing-Bo_LxFum.js} +5 -5
  68. package/dist/turn-user-message-D5RnVmxQ.js +355 -0
  69. package/dist/users-2bggndVg.js +424 -0
  70. package/dist/{validation-zxAJBDDy.js → validation-BbWikeSa.js} +1 -1
  71. package/dist/{version-DcZ40a0g.js → version-GVBMW2jA.js} +1 -1
  72. package/dist/version.js +1 -1
  73. package/dist/{viewer-CgiGjW10.js → viewer-BpxRliyO.js} +36 -163
  74. package/dist/{warmup-CwKbxQLl.js → warmup-BW2qwnal.js} +1140 -145
  75. package/dist/{worker-CbDUzaBA.js → worker-Cbd-iuwZ.js} +25 -20
  76. package/migrations/0104_code_change_draft.sql +1 -0
  77. package/migrations/0105_attachment_uploads.sql +14 -0
  78. package/migrations/0106_conversation_agent_config.sql +1 -0
  79. package/migrations/0107_attachment_deferred_download.sql +2 -0
  80. package/migrations/meta/0104_snapshot.json +4516 -0
  81. package/migrations/meta/0105_snapshot.json +4611 -0
  82. package/migrations/meta/0106_snapshot.json +4617 -0
  83. package/migrations/meta/0107_snapshot.json +4617 -0
  84. package/migrations/meta/_journal.json +28 -0
  85. package/package.json +10 -8
  86. package/dist/attempt-selection-ClP3MMPr.js +0 -61
  87. package/dist/locks-D-0h111u.js +0 -48
  88. package/dist/notification-Bv25xbj0.js +0 -1284
  89. package/dist/prompt-input-BUr4J9RO.js +0 -1424
  90. package/dist/session-stop-D4i7e6iT.js +0 -181
  91. package/dist/spawn-6cX6xE9G.js +0 -80
  92. package/dist/turn-cancel-l460pfGW.js +0 -201
  93. package/dist/turn-user-message-BSPmkm7X.js +0 -608
  94. package/dist/turn-wake-DVFVXyhX.js +0 -161
  95. package/dist/{oauth-relay-CsfIazeF.js → oauth-relay-DRzq73b6.js} +1 -1
@@ -0,0 +1,176 @@
1
+ import { Lt as moveIdleConversationDestination, Oi as getDashboardConversationLink, Oo as readLatestConversationBrief, Ta as postSlackMessage, ba as deleteSlackMessage, fa as escapeSlackMrkdwnText, pa as formatSlackLink, xa as getSlackMessagePermalink } from "./projection-w_X-zi7v.js";
2
+ import { u as parseSlackChannelId, v as parseSlackMessageTs } from "./actor-D2iXzvlN.js";
3
+ import { G as claimProviderConversation, K as getConversationIdByProviderConversation, a as getConversationStore, k as setFirstConversationLocation, o as getDb, s as getSqlExecutor, x as withConversationMutationLock } from "./db-BJNo6fK5.js";
4
+ import { P as juniorDestinations } from "./executor-DBIaOeJ_.js";
5
+ import { r as getStateAdapter } from "./adapter-S5UkjNK3.js";
6
+ import "./store-E3x2Fg_F.js";
7
+ import { c as joinPublicChannelForRead, s as checkSlackChannelReadAccess } from "./users-2bggndVg.js";
8
+ import { and, eq } from "drizzle-orm";
9
+ // src/chat/slack/continue-in-slack.ts
10
+ /** Refusal for a move that cannot wait for the active Run. */
11
+ const BUSY = "Wait for Junior to finish, then try again.";
12
+ const THREAD_TAKEN = "This thread already has a Junior conversation.";
13
+ const MOVED_ELSEWHERE = /* @__PURE__ */ new Error("Conversation already has a Location");
14
+ /**
15
+ * Return whether a Conversation can still move to a Slack thread.
16
+ *
17
+ * Only a dashboard root with no Location qualifies. The move is one-way, so
18
+ * a Conversation that has a Location never qualifies again.
19
+ */
20
+ function isMovableToSlack(conversation) {
21
+ return conversation.conversationId.startsWith("local:web:") && !conversation.location && !conversation.parentConversationId;
22
+ }
23
+ /** Return whether a viewer can move this public Conversation to Slack. */
24
+ function canContinueInSlack(conversation, access) {
25
+ return access?.isParticipant === true && access.visibility === "public" && isMovableToSlack(conversation);
26
+ }
27
+ /** Text for the first message of the Conversation in Slack. */
28
+ async function movedMessageText(conversation, actorName) {
29
+ const title = conversation.title ?? "Junior conversation";
30
+ const url = getDashboardConversationLink(conversation.conversationId);
31
+ const brief = await readLatestConversationBrief(getDb(), conversation.conversationId);
32
+ return [
33
+ `*${url ? formatSlackLink(url, title) : escapeSlackMrkdwnText(title)}*`,
34
+ ...brief ? [`> ${escapeSlackMrkdwnText(brief.content.summary)}`] : [],
35
+ `${escapeSlackMrkdwnText(actorName)} moved this conversation here from the dashboard. Mention me in this thread to continue.`
36
+ ].join("\n");
37
+ }
38
+ /** Make sure Junior can post in a public channel, then post there. */
39
+ async function postMovedMessage(channel, text, threadTs) {
40
+ const access = await checkSlackChannelReadAccess({
41
+ currentChannelIds: [],
42
+ targetChannelId: channel.channelId,
43
+ teamId: channel.teamId
44
+ });
45
+ if (!access.allowed) return { refused: access.reason === "private" ? "Only a public channel can be chosen." : access.error };
46
+ const channelName = access.channelName ?? channel.channelName;
47
+ if (access.isMember !== true) {
48
+ const joined = await joinPublicChannelForRead({
49
+ targetChannelId: channel.channelId,
50
+ ...channelName ? { channelName } : void 0
51
+ });
52
+ if (!joined.ok) return { refused: joined.error };
53
+ }
54
+ const posted = await postSlackMessage({
55
+ channelId: channel.channelId,
56
+ includePermalink: true,
57
+ text,
58
+ ...threadTs ? { threadTs } : void 0
59
+ });
60
+ return {
61
+ ...channelName ? { channelName } : void 0,
62
+ ...posted.permalink ? { permalink: posted.permalink } : void 0,
63
+ ts: posted.ts
64
+ };
65
+ }
66
+ async function readChannelLocationId(channel) {
67
+ const [row] = await getDb().select({ id: juniorDestinations.id }).from(juniorDestinations).where(and(eq(juniorDestinations.provider, "slack"), eq(juniorDestinations.providerTenantId, channel.teamId), eq(juniorDestinations.providerDestinationId, channel.channelId)));
68
+ if (!row) throw new Error("Slack channel Location was not stored");
69
+ return row.id;
70
+ }
71
+ /** Say which Slack thread a Conversation that already moved continues in. */
72
+ async function alreadyContinuesInSlackMessage(conversation) {
73
+ const { location } = conversation;
74
+ const channelId = location?.provider === "slack" ? parseSlackChannelId(location.channelId) : void 0;
75
+ const threadTs = parseSlackMessageTs(location?.provider === "slack" ? location.threadTs : void 0);
76
+ const url = channelId && threadTs ? await getSlackMessagePermalink({
77
+ channelId,
78
+ messageTs: threadTs
79
+ }) : void 0;
80
+ const place = conversation.channelName ? `#${conversation.channelName}` : "Slack";
81
+ return url ? `This conversation already continues in ${place}: ${url}` : `This conversation already continues in ${place}.`;
82
+ }
83
+ /**
84
+ * Move a qualifying dashboard Conversation to a public Slack channel thread.
85
+ *
86
+ * With `threadTs`, Junior replies in that existing thread. Without it, Junior
87
+ * starts a new thread. The thread then becomes the Conversation Location and
88
+ * its replies reach this Conversation. Dashboard Messages still get no Slack
89
+ * Delivery. The caller checks who may move it, and runs this inside the
90
+ * Slack installation of `channel.teamId`.
91
+ */
92
+ async function continueConversationInSlack(args) {
93
+ const { channel, conversation } = args;
94
+ const conversationId = conversation.conversationId;
95
+ if (conversation.execution.status === "running" || conversation.execution.status === "paused") return { status: "busy" };
96
+ const executor = getSqlExecutor();
97
+ const binding = (threadTs) => ({
98
+ provider: "slack",
99
+ providerDestinationId: channel.channelId,
100
+ providerTenantId: channel.teamId,
101
+ providerConversationId: threadTs
102
+ });
103
+ if (args.threadTs && await getConversationIdByProviderConversation(executor, binding(args.threadTs))) return {
104
+ message: THREAD_TAKEN,
105
+ status: "refused"
106
+ };
107
+ const posted = await postMovedMessage(channel, await movedMessageText(conversation, args.actorName), args.threadTs);
108
+ if ("refused" in posted) return {
109
+ message: posted.refused,
110
+ status: "refused"
111
+ };
112
+ const threadTs = args.threadTs ?? posted.ts;
113
+ const destination = {
114
+ platform: "slack",
115
+ teamId: channel.teamId,
116
+ channelId: channel.channelId
117
+ };
118
+ await getConversationStore().recordDestinationVisibility({
119
+ destination,
120
+ ...posted.channelName ? { channelName: posted.channelName } : void 0,
121
+ visibility: "public"
122
+ });
123
+ const locationId = await readChannelLocationId(channel);
124
+ let threadTaken = false;
125
+ const moved = await moveIdleConversationDestination({
126
+ conversationId,
127
+ destination,
128
+ move: async () => {
129
+ try {
130
+ return await withConversationMutationLock(executor, conversationId, async () => {
131
+ if (!await claimProviderConversation(executor, {
132
+ conversationId,
133
+ ...binding(threadTs)
134
+ })) {
135
+ threadTaken = true;
136
+ return false;
137
+ }
138
+ if (!await setFirstConversationLocation(executor, {
139
+ ...posted.channelName ? { channelName: posted.channelName } : void 0,
140
+ conversationId,
141
+ location: {
142
+ id: locationId,
143
+ provider: "slack",
144
+ teamId: channel.teamId,
145
+ channelId: channel.channelId,
146
+ threadTs
147
+ }
148
+ })) throw MOVED_ELSEWHERE;
149
+ return true;
150
+ });
151
+ } catch (error) {
152
+ if (error === MOVED_ELSEWHERE) return false;
153
+ throw error;
154
+ }
155
+ }
156
+ });
157
+ if (moved !== "moved") {
158
+ await deleteSlackMessage({
159
+ channelId: channel.channelId,
160
+ timestamp: posted.ts
161
+ });
162
+ if (moved === "busy") return { status: "busy" };
163
+ const current = await getConversationStore().get({ conversationId });
164
+ return {
165
+ message: threadTaken ? THREAD_TAKEN : await alreadyContinuesInSlackMessage(current ?? conversation),
166
+ status: "refused"
167
+ };
168
+ }
169
+ await getStateAdapter().subscribe(`slack:${channel.channelId}:${threadTs}`);
170
+ return {
171
+ ...posted.channelName ? { channelName: posted.channelName } : void 0,
172
+ ...posted.permalink ? { locationUrl: posted.permalink } : void 0,
173
+ status: "moved"
174
+ };
175
+ }
176
+ export { isMovableToSlack as a, continueConversationInSlack as i, alreadyContinuesInSlackMessage as n, canContinueInSlack as r, BUSY as t };
@@ -1,4 +1,4 @@
1
- import { c as conversationTurnFailureCodeSchema, l as conversationTurnFailureReasonSchema, n as INPUT_IMAGE_TYPES, y as usageSchema } from "./media-BepyEUNm.js";
1
+ import { a as conversationTurnFailureReasonSchema, h as usageSchema, i as conversationTurnFailureCodeSchema } from "./history-IjdmO_r6.js";
2
2
  import * as z from "zod";
3
3
  import { codeChangeStateSchema, conversationAnnotationInputSchema, conversationEventPresentationSchema, conversationSidebarAnnotationSchema, objectFactFields, objectTypeSchema } from "@sentry/junior-plugin-api";
4
4
  // src/chat/briefs/schema.ts
@@ -132,21 +132,33 @@ function parseBriefInput(input) {
132
132
  };
133
133
  }
134
134
  // src/chat/attachments/input.ts
135
- /** Bound JSON image input below the hosting platform's request size limit. */
136
- const MAX_INPUT_IMAGE_BYTES = 3145728;
137
- const MAX_INPUT_IMAGES = 3;
138
- /** Image bytes accepted with a web message, never stored in its mailbox row. */
139
- const inputImageSchema = z.object({
135
+ /**
136
+ * Largest file that Junior stores from Slack or the web, or loads into the
137
+ * sandbox.
138
+ *
139
+ * Every path streams the bytes, so this cap does not depend on function
140
+ * memory. It bounds transfer time and sandbox disk use.
141
+ */
142
+ const MAX_ATTACHMENT_BYTES = 262144e3;
143
+ /** Most files on one web Message, as in one Slack message. */
144
+ const MAX_INPUT_ATTACHMENTS = 10;
145
+ /** File facts that a browser declares before it uploads the bytes. */
146
+ const inputFileSchema = z.object({
140
147
  filename: z.string().trim().min(1).max(255),
141
- contentType: z.enum(INPUT_IMAGE_TYPES),
142
- data: z.string().min(4).max(MAX_INPUT_IMAGE_BYTES * 4 / 3).regex(/^[A-Za-z0-9+/]*={0,2}$/).refine((data) => data.length % 4 === 0)
148
+ contentType: z.string().trim().toLowerCase().max(127).regex(/^[a-z0-9][\w.+-]*\/[a-z0-9][\w.+-]*$/),
149
+ bytes: z.number().int().min(1).max(MAX_ATTACHMENT_BYTES)
143
150
  }).strict();
144
151
  /** Safe attachment facts shared by mailbox input and transcript messages. */
145
152
  const messageAttachmentSchema = z.object({
146
153
  id: z.string().min(1),
147
154
  filename: z.string().min(1),
148
155
  contentType: z.string().min(1),
149
- bytes: z.number().int().nonnegative()
156
+ bytes: z.number().int().nonnegative(),
157
+ /**
158
+ * True for a large Slack file that Junior never stores. Each read
159
+ * downloads it from Slack, so it has no preview.
160
+ */
161
+ pending: z.literal(true).optional()
150
162
  }).strict();
151
163
  /** Read attachment metadata without exposing object storage keys or bytes. */
152
164
  function readMessageAttachments(value) {
@@ -352,6 +364,12 @@ const conversationAttachmentParamsSchema = z.object({
352
364
  attachmentId: z.string().min(1),
353
365
  conversationId: z.string().min(1)
354
366
  }).strict();
367
+ const conversationAttachmentQuerySchema = z.object({
368
+ /**
369
+ * Send `Content-Disposition: attachment` even for a type that previews
370
+ * inline, so a same-window download link saves the file.
371
+ */
372
+ download: z.stringbool().optional() }).strict();
355
373
  const conversationDetailQuerySchema = z.object({
356
374
  /** Omit to get the latest three Turns, up to the default page limit. */
357
375
  limit: z.coerce.number().int().min(1).max(1e3).optional(),
@@ -400,14 +418,19 @@ const conversationEventsQuerySchema = z.union([
400
418
  const conversationFeedQuerySchema = z.object({
401
419
  actorEmail: z.string().trim().email().transform((value) => value.toLowerCase()).optional(),
402
420
  codeRepositoryId: z.string().uuid().optional(),
421
+ /** `nextCursor` from the previous page of the same feed. */
422
+ cursor: z.string().min(1).max(500).optional(),
403
423
  q: z.string().trim().max(200).optional(),
404
424
  status: z.enum(["active", "archived"]).default("active")
405
425
  }).strict();
426
+ /** Client key that makes a retried send the same Message. */
427
+ const idempotencyKeySchema = z.string().trim().min(1).max(200);
406
428
  const createConversationMessageBodySchema = z.object({
407
- idempotencyKey: z.string().trim().min(1).max(200),
429
+ idempotencyKey: idempotencyKeySchema,
408
430
  message: z.string().trim().max(32e3),
409
- images: z.array(inputImageSchema).max(3).optional()
410
- }).strict().refine((body) => Boolean(body.message || body.images?.length), "Add a message or an image.").refine((body) => (body.images ?? []).reduce((sum, image) => sum + image.data.length, 0) <= MAX_INPUT_IMAGE_BYTES * 4 / 3, "Images must total 3 MB or less.");
431
+ /** Uploads from `POST /api/conversations/attachment-uploads`. */
432
+ uploadIds: z.array(z.string().min(1).max(64)).max(10).optional()
433
+ }).strict().refine((body) => Boolean(body.message || body.uploadIds?.length), "Add a message or a file.");
411
434
  const createConversationBodySchema = createConversationMessageBodySchema.safeExtend({
412
435
  /** Saved title. Title generation runs only when it is omitted. */
413
436
  title: conversationTitleSchema.optional(),
@@ -991,4 +1014,4 @@ const conversationDetailReportSchema = conversationSummaryReportSchema.extend({
991
1014
  sentryConversationUrl: z.string().optional(),
992
1015
  sourceTask: conversationSourceTaskSchema.optional()
993
1016
  }).strict().superRefine(validateConversationEvents);
994
- export { parseStoredBrief as $, formatAgentTypes as A, readMessageCardRefs as B, createConversationMessageBodySchema as C, AGENT_TYPES as D, conversationChildAgentTotalsSchema as E, conversationReadPositionSchema as F, messageAttachmentSchema as G, resolveMessageCards as H, reviewItemChangeRecordSchema as I, briefLinkSchema as J, readMessageAttachments as K, annotationCard as L, conversationTitleSchema as M, renameConversationBodySchema as N, agentTypeInstructions as O, renameConversationResponseSchema as P, parseBriefInput as Q, messageCardRef as R, createConversationBodySchema as S, forkConversationResponseSchema as T, MAX_INPUT_IMAGES as U, removedCardSchema as V, MAX_INPUT_IMAGE_BYTES as W, briefResourceLabel as X, briefOutcomeStatusSchema as Y, conversationBriefSchema as Z, conversationReportMessageEventSchema as _, conversationActivityPreviewSchema as a, conversationSurfaceSchema as b, conversationDetailQuerySchema as c, conversationEventPageSchema as d, conversationEventsQuerySchema as f, conversationReportEventSchema as g, conversationReportEventDataSchema as h, actorIdentitySchema as i, CONVERSATION_TITLE_MAX_LENGTH as j, agentTypeSchema as k, conversationDetailReportSchema as l, conversationParamsSchema as m, CONVERSATION_VERSION_HEADER as n, conversationAttachmentParamsSchema as o, conversationFeedQuerySchema as p, briefCodeChangeSchema as q, acceptedConversationMessageSchema as r, conversationAuxiliaryCostsSchema as s, CONVERSATION_DETAIL_VERSION_HEADER as t, conversationEventHistorySchema as u, conversationReportStatusSchema as v, forkConversationBodySchema as w, conversationUsageSchema as x, conversationSummaryReportSchema as y, messageCardText as z };
1017
+ export { briefResourceLabel as $, agentTypeInstructions as A, messageCardRef as B, createConversationBodySchema as C, idempotencyKeySchema as D, forkConversationResponseSchema as E, renameConversationBodySchema as F, MAX_ATTACHMENT_BYTES as G, readMessageCardRefs as H, renameConversationResponseSchema as I, messageAttachmentSchema as J, MAX_INPUT_ATTACHMENTS as K, conversationReadPositionSchema as L, formatAgentTypes as M, CONVERSATION_TITLE_MAX_LENGTH as N, conversationChildAgentTotalsSchema as O, conversationTitleSchema as P, briefOutcomeStatusSchema as Q, reviewItemChangeRecordSchema as R, conversationUsageSchema as S, forkConversationBodySchema as T, removedCardSchema as U, messageCardText as V, resolveMessageCards as W, briefCodeChangeSchema as X, readMessageAttachments as Y, briefLinkSchema as Z, conversationReportEventSchema as _, conversationActivityPreviewSchema as a, conversationSummaryReportSchema as b, conversationAuxiliaryCostsSchema as c, conversationEventHistorySchema as d, conversationBriefSchema as et, conversationEventPageSchema as f, conversationReportEventDataSchema as g, conversationParamsSchema as h, actorIdentitySchema as i, agentTypeSchema as j, AGENT_TYPES as k, conversationDetailQuerySchema as l, conversationFeedQuerySchema as m, CONVERSATION_VERSION_HEADER as n, parseStoredBrief as nt, conversationAttachmentParamsSchema as o, conversationEventsQuerySchema as p, inputFileSchema as q, acceptedConversationMessageSchema as r, conversationAttachmentQuerySchema as s, CONVERSATION_DETAIL_VERSION_HEADER as t, parseBriefInput as tt, conversationDetailReportSchema as u, conversationReportMessageEventSchema as v, createConversationMessageBodySchema as w, conversationSurfaceSchema as x, conversationReportStatusSchema as y, annotationCard as z };
@@ -1,5 +1,109 @@
1
- import { G as messageAttachmentSchema, I as reviewItemChangeRecordSchema, Y as briefOutcomeStatusSchema, i as actorIdentitySchema, l as conversationDetailReportSchema, y as conversationSummaryReportSchema } from "./conversation-DCkzvxqB.js";
1
+ import { J as messageAttachmentSchema, Q as briefOutcomeStatusSchema, R as reviewItemChangeRecordSchema, b as conversationSummaryReportSchema, i as actorIdentitySchema, u as conversationDetailReportSchema } from "./conversation-Dyjq2CZ8.js";
2
2
  import * as z from "zod";
3
+ // src/api/objects/cards.ts
4
+ const MAX_LABEL_CHARS = 256;
5
+ const MAX_FACT_CHARS = 160;
6
+ const conversationStates = {
7
+ active: "running",
8
+ completed: "idle",
9
+ failed: "failed",
10
+ stopped: "stopped"
11
+ };
12
+ function personName(person) {
13
+ return person.fullName ?? person.slackUserName ?? person.email;
14
+ }
15
+ /**
16
+ * Build the card of one Conversation that the viewer may read. Give `brief`
17
+ * only when the viewer may see the Brief.
18
+ */
19
+ function conversationObjectCard(args) {
20
+ const { summary } = args;
21
+ const participants = args.participants.flatMap((person) => personName(person)?.slice(0, MAX_FACT_CHARS) ?? []).slice(0, 5);
22
+ return {
23
+ kind: "object",
24
+ objectType: "conversation",
25
+ key: summary.conversationId.slice(0, 256),
26
+ label: summary.displayTitle.slice(0, MAX_LABEL_CHARS),
27
+ title: summary.displayTitle.slice(0, 512),
28
+ url: args.url,
29
+ status: summary.archivedAt ? "archived" : conversationStates[summary.status],
30
+ ...args.brief ? { description: args.brief.slice(0, 4e3) } : void 0,
31
+ facts: {
32
+ type: "conversation",
33
+ ...participants.length > 0 ? { participants } : void 0,
34
+ lastActivityAt: summary.lastSeenAt
35
+ }
36
+ };
37
+ }
38
+ /** Build the card of one known person from what the People pages show. */
39
+ function personObjectCard(args) {
40
+ const { person } = args;
41
+ const name = personName(person) ?? person.email;
42
+ return {
43
+ kind: "object",
44
+ objectType: "person",
45
+ key: person.email.toLowerCase().slice(0, 256),
46
+ label: name.slice(0, MAX_LABEL_CHARS),
47
+ title: name.slice(0, 512),
48
+ url: args.url,
49
+ facts: {
50
+ type: "person",
51
+ email: person.email.slice(0, MAX_FACT_CHARS),
52
+ ...person.slackUserName ? { slackHandle: person.slackUserName.slice(0, MAX_FACT_CHARS) } : void 0,
53
+ ...args.githubHandle ? { githubHandle: args.githubHandle } : void 0,
54
+ ...person.avatarUrl ? { avatarUrl: person.avatarUrl } : void 0
55
+ }
56
+ };
57
+ }
58
+ const MAX_SNIPPET_CHARS = 280;
59
+ const MAX_TITLE_CHARS = 100;
60
+ function truncate(text, max) {
61
+ return text.length > max ? `${text.slice(0, max - 1).trimEnd()}…` : text;
62
+ }
63
+ /**
64
+ * Build the card of one chat message. Give `text` only when the viewer may
65
+ * read the message: the card shows a short snippet of it, never all of it.
66
+ */
67
+ function messageObjectCard(args) {
68
+ const snippet = args.text?.replace(/\s+/g, " ").trim();
69
+ const title = snippet ? truncate(snippet, MAX_TITLE_CHARS) : `Message in ${args.channel}`;
70
+ return {
71
+ kind: "object",
72
+ objectType: "message",
73
+ key: args.key.slice(0, 256),
74
+ label: args.channel.slice(0, MAX_LABEL_CHARS),
75
+ title,
76
+ url: args.url,
77
+ ...snippet && snippet.length > title.length ? { description: truncate(snippet, MAX_SNIPPET_CHARS) } : void 0,
78
+ facts: {
79
+ type: "message",
80
+ channel: args.channel.slice(0, MAX_FACT_CHARS),
81
+ ...args.author ? { author: args.author.slice(0, MAX_FACT_CHARS) } : void 0,
82
+ ...args.sentAt ? { sentAt: args.sentAt } : void 0
83
+ }
84
+ };
85
+ }
86
+ /**
87
+ * Build the card of one public web page from its oEmbed fields or meta
88
+ * tags. `thumbnailUrl` must be a Junior image path.
89
+ */
90
+ function webPageObjectCard(args) {
91
+ return {
92
+ kind: "object",
93
+ objectType: "web_page",
94
+ key: args.url.slice(0, 256),
95
+ label: truncate(args.title, MAX_LABEL_CHARS),
96
+ title: truncate(args.title, 512),
97
+ url: args.url,
98
+ ...args.description ? { description: truncate(args.description, MAX_SNIPPET_CHARS) } : void 0,
99
+ facts: {
100
+ type: "web_page",
101
+ ...args.siteName ? { siteName: truncate(args.siteName, MAX_FACT_CHARS) } : void 0,
102
+ ...args.author ? { author: truncate(args.author, MAX_FACT_CHARS) } : void 0,
103
+ ...args.thumbnailUrl ? { thumbnailUrl: args.thumbnailUrl } : void 0
104
+ }
105
+ };
106
+ }
3
107
  // src/reporting-schema.ts
4
108
  const healthReportSchema = z.object({
5
109
  status: z.literal("ok"),
@@ -201,6 +305,8 @@ const conversationFeedItemSchema = conversationSummaryReportSchema.extend({
201
305
  const conversationFeedSchema = z.object({
202
306
  conversations: z.array(conversationFeedItemSchema),
203
307
  source: z.literal("conversation_index"),
204
- generatedAt: z.string()
308
+ generatedAt: z.string(),
309
+ /** Present when older conversations follow this page. */
310
+ nextCursor: z.string().optional()
205
311
  }).strict();
206
- export { skillReportsSchema as C, skillReportSchema as S, pluginPackageContentReportSchema as _, conversationDetailWithMailboxReportSchema as a, runtimeInfoReportSchema as b, conversationPendingMessageSchema as c, steerConversationPendingMessagesBodySchema as d, steerConversationPendingMessagesResponseSchema as f, pluginPackageContentItemReportSchema as g, pluginOperationalReportSchema as h, cancelConversationPendingMessagesResponseSchema as i, conversationPendingMessagesReportSchema as l, pluginOperationalReportFeedSchema as m, conversationFeedSchema as n, conversationPendingAuthorizationSchema as o, healthReportSchema as p, cancelConversationPendingMessagesBodySchema as r, conversationPendingMessageDeliverySchema as s, conversationFeedBriefSchema as t, conversationUnchangedDetailWithMailboxSchema as u, pluginSchema as v, skillDetailReportSchema as x, pluginsSchema as y };
312
+ export { skillReportsSchema as C, webPageObjectCard as D, personObjectCard as E, skillReportSchema as S, messageObjectCard as T, pluginPackageContentReportSchema as _, conversationDetailWithMailboxReportSchema as a, runtimeInfoReportSchema as b, conversationPendingMessageSchema as c, steerConversationPendingMessagesBodySchema as d, steerConversationPendingMessagesResponseSchema as f, pluginPackageContentItemReportSchema as g, pluginOperationalReportSchema as h, cancelConversationPendingMessagesResponseSchema as i, conversationPendingMessagesReportSchema as l, pluginOperationalReportFeedSchema as m, conversationFeedSchema as n, conversationPendingAuthorizationSchema as o, healthReportSchema as p, cancelConversationPendingMessagesBodySchema as r, conversationPendingMessageDeliverySchema as s, conversationFeedBriefSchema as t, conversationUnchangedDetailWithMailboxSchema as u, pluginSchema as v, conversationObjectCard as w, skillDetailReportSchema as x, pluginsSchema as y };
@@ -1,4 +1,4 @@
1
- import { h as logWarn } from "./logging-CJTi5niy.js";
1
+ import { h as logWarn } from "./logging-BIclibct.js";
2
2
  import { AsyncLocalStorage } from "node:async_hooks";
3
3
  // src/chat/conversation-privacy.ts
4
4
  const SAFE_METADATA_KEY_LIMIT = 20;
@@ -1,54 +1,25 @@
1
1
  import { i as getActiveSpan, r as continueTrace, v as __exportAll } from "./sentry-BRTJqumy.js";
2
- import { A as latestConversationMessageSeq, I as upsertConversationMessage, M as normalizeConversationText, N as recordDeliveredAssistantMessage, _i as verifyTimerWatchCredentialSubject, a as loadProjection, an as getAssistantReplyText, at as failTurnRecord, b as persistConversationMessages, j as markConversationMessage, mn as persistWithRetry, nt as saveTurnCheckpoint, ot as getTurnRecord, t as commitAcceptedReply, v as hydrateConversationMessages } from "./projection-BgwEE36_.js";
3
- import { n as botConfig } from "./config-BOByVnxe.js";
4
- import { E as withSpan, S as setTags, h as logWarn, p as logException } from "./logging-CJTi5niy.js";
5
- import { D as turnBehavior, T as isTopLevelKind, a as getConversationStore, et as nextDetailVersion, o as getDb, r as getConversationEventStore, s as getSqlExecutor, w as isPersonInput } from "./db-CoMNr2Zm.js";
6
- import { A as juniorConversations } from "./executor-C-m8VrzX.js";
7
- import { _ as instructionProvenanceFor } from "./media-BepyEUNm.js";
8
- import { f as credentialContextForActor } from "./registry-9XwqSnM-.js";
9
- import { gt as resolveConversationDestination, i as measureTurnCompactionWait } from "./agent-runner-Q9GkoerG.js";
10
- import { o as isEventConversationMessage } from "./prompt-DXc9DYT9.js";
11
- import { K as readMessageAttachments } from "./conversation-DCkzvxqB.js";
12
- import { C as legacyWebMailboxMetadataSchema, S as turnInputFactsFromConversationMessage, _ as getEventBatchDelayMs, l as withoutSavedSteeringMessages, n as loadReviewItemInput, o as buildSteeringPiMessage, s as instructionForInputs, t as eventReviewItemInputs, x as sourceFromTurnInput } from "./prompt-input-BUr4J9RO.js";
13
- import { _ as ConversationTurnLifecycleService, d as isTurnInputCommitLostError, dt as buildDeterministicTurnId, g as startActiveTurn, h as markTurnFailed, l as getConversationTurnBoundaryError, s as TurnInputCommitLostError, t as getTurnUserMessage } from "./turn-user-message-BSPmkm7X.js";
14
- import { T as recordFinishedTurnForAutomatedLimit, a as renderEventBatchInputs, i as isEventMailboxMetadata, o as timerWatchCredentialSubject, r as eventBatchMessageMeta, y as maybePostAutomatedTurnLimitNotice } from "./notification-Bv25xbj0.js";
15
- import { a as getPersistedThreadState, c as coerceThreadConversationState, i as getPersistedSandboxState, s as persistThreadStateById } from "./turn-session-routing-VXDVXLRl.js";
16
- import { a as AgentRunError, n as completeCancelledConversationTurn, o as executeTurn, r as supersedeOpenMailboxTurns } from "./turn-cancel-l460pfGW.js";
17
- import { o as createWebAuthorization } from "./turn-wake-DVFVXyhX.js";
18
- import { H as blockEventAutomation, M as blockScheduledAutomation, c as getDispatchRecord, o as getDispatchIdForConversation, v as notifyAutomationBlocked, x as readAutomationExecutionByConversationId } from "./store-DrA17Fbz.js";
19
- import { n as scheduleSessionCompletedPluginTasks, t as processPluginTask } from "./task-runner-CT4M8oDz.js";
20
- import { c as buildDeliveredTurnStatePatch, l as loadPendingMessageCards, o as completeAuthPauseTurn, r as finalizeFailedTurnReplyWithEvent, t as buildTurnThreadContext } from "./thread-context-DnqUkbzN.js";
2
+ import { A as latestConversationMessageSeq, Ei as verifyTimerWatchCredentialSubject, I as upsertConversationMessage, M as normalizeConversationText, N as recordDeliveredAssistantMessage, a as loadProjection, at as failTurnRecord, b as persistConversationMessages, bn as persistWithRetry, j as markConversationMessage, nt as saveTurnCheckpoint, st as getTurnRecord, t as commitAcceptedReply, un as getAssistantReplyText, v as hydrateConversationMessages } from "./projection-w_X-zi7v.js";
3
+ import { n as botConfig } from "./config-9nHoFiJP.js";
4
+ import { E as withSpan, S as setTags, h as logWarn, p as logException } from "./logging-BIclibct.js";
5
+ import { C as isPersonInput, E as turnBehavior, a as getConversationStore, nt as nextDetailVersion, o as getDb, r as getConversationEventStore, s as getSqlExecutor, w as isTopLevelKind } from "./db-BJNo6fK5.js";
6
+ import { j as juniorConversations } from "./executor-DBIaOeJ_.js";
7
+ import { p as instructionProvenanceFor } from "./history-IjdmO_r6.js";
8
+ import { f as credentialContextForActor } from "./registry-BmP5vnlj.js";
9
+ import { dt as resolveConversationDestination, i as measureTurnCompactionWait } from "./agent-runner-bY4_0UPm.js";
10
+ import { o as isEventConversationMessage } from "./prompt-B1Xw46-S.js";
11
+ import { Y as readMessageAttachments } from "./conversation-Dyjq2CZ8.js";
12
+ import { A as turnInputFactsFromConversationMessage, F as isEventMailboxMetadata, I as renderEventBatchInputs, L as timerWatchCredentialSubject, P as eventBatchMessageMeta, X as maybePostAutomatedTurnLimitNotice, c as loadReviewItemInput, f as buildSteeringPiMessage, g as withoutSavedSteeringMessages, j as legacyWebMailboxMetadataSchema, k as sourceFromTurnInput, m as instructionForInputs, nt as recordFinishedTurnForAutomatedLimit, p as instructionActorFor, s as eventReviewItemInputs, w as getEventBatchDelayMs } from "./session-stop-BcAXze8a.js";
13
+ import { Et as executeTurn, L as readParentMessage, M as childAgentTurnOptions, N as isParentMessageMeta, St as createWebAuthorization, Tt as AgentRunError, Y as completeCancelledConversationTurn, dt as supersedeOpenMailboxTurns } from "./warmup-BW2qwnal.js";
14
+ import { R as buildDeterministicTurnId, _ as ConversationTurnLifecycleService, d as isTurnInputCommitLostError, g as startActiveTurn, h as markTurnFailed, l as getConversationTurnBoundaryError, s as TurnInputCommitLostError, t as getTurnUserMessage } from "./turn-user-message-D5RnVmxQ.js";
15
+ import { a as getPersistedThreadState, c as coerceThreadConversationState, i as getPersistedSandboxState, s as persistThreadStateById } from "./turn-session-routing-Bo_LxFum.js";
16
+ import { H as blockEventAutomation, M as blockScheduledAutomation, c as getDispatchRecord, o as getDispatchIdForConversation, v as notifyAutomationBlocked, x as readAutomationExecutionByConversationId } from "./store-Dkeis_8o.js";
17
+ import { t as readConversationLineage } from "./lineage-0dereG7H.js";
18
+ import { c as buildDeliveredTurnStatePatch, l as loadPendingMessageCards, o as completeAuthPauseTurn, r as finalizeFailedTurnReplyWithEvent, t as buildTurnThreadContext } from "./thread-context-BzvdkgI9.js";
19
+ import { n as scheduleSessionCompletedPluginTasks, t as processPluginTask } from "./task-runner-vohUPLHe.js";
21
20
  import { isDeepStrictEqual } from "node:util";
22
21
  import { createHash } from "node:crypto";
23
22
  import { and, eq, isNotNull, isNull } from "drizzle-orm";
24
- // src/chat/conversations/delivery-pause.ts
25
- /** True when the Conversation is a root that delivers to a Location. */
26
- function canPauseConversationDelivery(conversation) {
27
- return isTopLevelKind(conversation.kind) && conversation.location !== void 0;
28
- }
29
- const rootConversation = (conversationId) => and(eq(juniorConversations.conversationId, conversationId), isNull(juniorConversations.parentConversationId));
30
- /**
31
- * Stop Delivery of a root's Event Turn replies to its Location. Returns false
32
- * when Delivery was already paused or the root does not exist.
33
- */
34
- async function pauseConversationDelivery(conversationId) {
35
- return (await getSqlExecutor().db().update(juniorConversations).set({
36
- deliveryPausedAt: /* @__PURE__ */ new Date(),
37
- detailVersion: nextDetailVersion
38
- }).where(and(rootConversation(conversationId), isNull(juniorConversations.deliveryPausedAt))).returning({ conversationId: juniorConversations.conversationId })).length > 0;
39
- }
40
- /** Deliver a root's Event Turn replies to its Location again. */
41
- async function resumeConversationDelivery(conversationId) {
42
- await getSqlExecutor().db().update(juniorConversations).set({
43
- deliveryPausedAt: null,
44
- detailVersion: nextDetailVersion
45
- }).where(and(rootConversation(conversationId), isNotNull(juniorConversations.deliveryPausedAt)));
46
- }
47
- /** True while a root's Event Turn replies stay out of its Location. */
48
- async function isConversationDeliveryPaused(conversationId) {
49
- const [row] = await getSqlExecutor().db().select({ pausedAt: juniorConversations.deliveryPausedAt }).from(juniorConversations).where(eq(juniorConversations.conversationId, conversationId)).limit(1);
50
- return Boolean(row?.pausedAt);
51
- }
52
23
  // src/chat/task-execution/turn-telemetry.ts
53
24
  /** Read the turn input timing facts from a mailbox batch, oldest first. */
54
25
  function turnInputTelemetry(messages) {
@@ -142,6 +113,34 @@ async function blockRunAutomation(conversationId, blocked) {
142
113
  reason: blocked.missing
143
114
  });
144
115
  }
116
+ // src/chat/conversations/delivery-pause.ts
117
+ /** True when the Conversation is a root that delivers to a Location. */
118
+ function canPauseConversationDelivery(conversation) {
119
+ return isTopLevelKind(conversation.kind) && conversation.location !== void 0;
120
+ }
121
+ const rootConversation = (conversationId) => and(eq(juniorConversations.conversationId, conversationId), isNull(juniorConversations.parentConversationId));
122
+ /**
123
+ * Stop Delivery of a root's Event Turn replies to its Location. Returns false
124
+ * when Delivery was already paused or the root does not exist.
125
+ */
126
+ async function pauseConversationDelivery(conversationId) {
127
+ return (await getSqlExecutor().db().update(juniorConversations).set({
128
+ deliveryPausedAt: /* @__PURE__ */ new Date(),
129
+ detailVersion: nextDetailVersion
130
+ }).where(and(rootConversation(conversationId), isNull(juniorConversations.deliveryPausedAt))).returning({ conversationId: juniorConversations.conversationId })).length > 0;
131
+ }
132
+ /** Deliver a root's Event Turn replies to its Location again. */
133
+ async function resumeConversationDelivery(conversationId) {
134
+ await getSqlExecutor().db().update(juniorConversations).set({
135
+ deliveryPausedAt: null,
136
+ detailVersion: nextDetailVersion
137
+ }).where(and(rootConversation(conversationId), isNotNull(juniorConversations.deliveryPausedAt)));
138
+ }
139
+ /** True while a root's Event Turn replies stay out of its Location. */
140
+ async function isConversationDeliveryPaused(conversationId) {
141
+ const [row] = await getSqlExecutor().db().select({ pausedAt: juniorConversations.deliveryPausedAt }).from(juniorConversations).where(eq(juniorConversations.conversationId, conversationId)).limit(1);
142
+ return Boolean(row?.pausedAt);
143
+ }
145
144
  // src/chat/task-execution/assistant-message.ts
146
145
  /** Store one assistant Message and its Agent history. */
147
146
  async function commitAssistantMessage(args) {
@@ -229,10 +228,7 @@ async function steeringMessageFromWeb(message, actor) {
229
228
  const storedAttachments = readMessageAttachments(message.input.attachments);
230
229
  const reviewItemInput = await loadReviewItemInput(message.input.reviewItemChange);
231
230
  return {
232
- actor: {
233
- authorId: actor.userId,
234
- ...actor.fullName ? { authorName: actor.fullName } : void 0
235
- },
231
+ actor: instructionActorFor(actor),
236
232
  ...reviewItemInput ? { kind: "runtime" } : void 0,
237
233
  provenance: instructionProvenanceFor(actor),
238
234
  text: reviewItemInput ?? message.input.text.trim(),
@@ -270,6 +266,29 @@ function createWebSteeringDrain(args) {
270
266
  return accepted;
271
267
  };
272
268
  }
269
+ // src/chat/task-execution/turn-credentials.ts
270
+ /**
271
+ * Return a saved timer creator subject when it is still valid here. The
272
+ * timer's Watch belongs to this Conversation. It may also belong to an
273
+ * ancestor when `fromParent`: the input is a parent message that passed its
274
+ * sender check, so the child continues the work of the parent's timer Turn.
275
+ */
276
+ async function verifiedTimerWatchSubject(conversationId, subject, fromParent) {
277
+ if (subject?.binding.type !== "timer-watch") return void 0;
278
+ const watchConversationId = subject.binding.conversationId;
279
+ if (watchConversationId !== conversationId && !(fromParent && (await readConversationLineage(conversationId)).some((entry) => entry.conversationId === watchConversationId))) return;
280
+ return verifyTimerWatchCredentialSubject({
281
+ conversationId: watchConversationId,
282
+ subject,
283
+ watchId: subject.binding.watchId
284
+ }) ? subject : void 0;
285
+ }
286
+ /** Return the delegated subject that every input of a batch carries, if any. */
287
+ function sharedDelegatedSubject(batch) {
288
+ const subjects = batch.map((entry) => entry.credentialContext && "subject" in entry.credentialContext ? entry.credentialContext.subject : void 0);
289
+ const first = subjects[0];
290
+ return first && subjects.every((subject) => isDeepStrictEqual(subject, first)) ? first : void 0;
291
+ }
273
292
  // src/chat/task-execution/conversation-turn.ts
274
293
  /** Run a mailbox Turn and store its assistant Messages. */
275
294
  var conversation_turn_exports = /* @__PURE__ */ __exportAll({ createConversationTurnWorker: () => createConversationTurnWorker });
@@ -284,20 +303,6 @@ function captureConversationTurnFailure(args) {
284
303
  });
285
304
  return typeof eventId === "string" ? eventId : void 0;
286
305
  }
287
- /** Return the saved timer creator subject when it is still valid here. */
288
- function resumedTimerWatchCredentialSubject(conversationId, subject) {
289
- if (subject?.binding.type !== "timer-watch") return void 0;
290
- return verifyTimerWatchCredentialSubject({
291
- conversationId,
292
- subject,
293
- watchId: subject.binding.watchId
294
- }) ? subject : void 0;
295
- }
296
- function sharedDelegatedSubject(batch) {
297
- const subjects = batch.map((entry) => entry.credentialContext && "subject" in entry.credentialContext ? entry.credentialContext.subject : void 0);
298
- const first = subjects[0];
299
- return first && subjects.every((subject) => isDeepStrictEqual(subject, first)) ? first : void 0;
300
- }
301
306
  function hasLostTurnInputCommit(error) {
302
307
  const cause = getConversationTurnBoundaryError(error)?.cause ?? error;
303
308
  return isTurnInputCommitLostError(error) || isTurnInputCommitLostError(cause);
@@ -374,10 +379,12 @@ function createConversationTurnWorker(agentRunner, deliverMessage, deliverToPare
374
379
  });
375
380
  const savedTurn = isResume ? await getTurnRecord(context.conversationId, turnId) : void 0;
376
381
  let savedMessageIsEvent = false;
382
+ let savedParentMessage = false;
377
383
  if (isResume) {
378
384
  const userMessage = getTurnUserMessage(conversation, turnId);
379
385
  if (!userMessage) throw new Error(`Unable to locate the persisted user message for Turn "${turnId}"`);
380
386
  savedMessageIsEvent = isEventConversationMessage(userMessage);
387
+ savedParentMessage = isParentMessageMeta(userMessage.meta);
381
388
  turnInputFacts = turnInputFactsFromConversationMessage(userMessage, {
382
389
  conversationId: context.conversationId,
383
390
  location: storedConversation?.location,
@@ -402,8 +409,9 @@ function createConversationTurnWorker(agentRunner, deliverMessage, deliverToPare
402
409
  const { actor, author } = turnInputFacts;
403
410
  const instructionInputs = instructionForInputs(inputs);
404
411
  const { text } = instructionInputs;
412
+ const instructionActor = instructionActorFor(actor);
405
413
  let credentialSubject;
406
- if (actor.platform === "system") credentialSubject = resolved.kind === "mailbox" ? timerWatchCredentialSubject(context.conversationId, resolved.batch.map((entry) => entry.message)) ?? resumedTimerWatchCredentialSubject(context.conversationId, sharedDelegatedSubject(resolved.batch)) : resumedTimerWatchCredentialSubject(context.conversationId, savedTurn?.credentialSubject);
414
+ if (actor.platform === "system") credentialSubject = resolved.kind === "mailbox" ? timerWatchCredentialSubject(context.conversationId, resolved.batch.map((entry) => entry.message)) ?? await verifiedTimerWatchSubject(context.conversationId, sharedDelegatedSubject(resolved.batch), resolved.batch.every((entry) => readParentMessage(entry.message))) : await verifiedTimerWatchSubject(context.conversationId, savedTurn?.credentialSubject, savedParentMessage);
407
415
  const source = sourceFromTurnInput({
408
416
  conversationId: context.conversationId,
409
417
  source: turnInputFacts.source,
@@ -560,7 +568,13 @@ function createConversationTurnWorker(agentRunner, deliverMessage, deliverToPare
560
568
  })) return await completeCancelledTurn();
561
569
  await persistThreadStateById(context.conversationId, { conversation });
562
570
  if (stopSignal?.aborted) return await completeCancelledTurn();
563
- const piMessages = await loadProjection({ conversationId: context.conversationId });
571
+ const childTurn = await childAgentTurnOptions({
572
+ conversationId: context.conversationId,
573
+ history: await loadProjection({ conversationId: context.conversationId }),
574
+ inputs: resolved.kind === "mailbox" ? resolved.batch.map((entry) => entry.message) : [],
575
+ savedParentMessage
576
+ });
577
+ const piMessages = childTurn.history;
564
578
  failureCode = "agent_run_failed";
565
579
  currentRunId = `conversation-run:${stableHex(turnId, String(startedAtMs))}`;
566
580
  setTags({ runId: currentRunId });
@@ -571,6 +585,8 @@ function createConversationTurnWorker(agentRunner, deliverMessage, deliverToPare
571
585
  runId: currentRunId,
572
586
  instruction: {
573
587
  ...instructionInputs,
588
+ ...instructionActor ? { actor: instructionActor } : void 0,
589
+ ...childTurn.instruction,
574
590
  storedAttachments: attachments,
575
591
  context: await buildTurnThreadContext({
576
592
  conversation,
@@ -581,6 +597,7 @@ function createConversationTurnWorker(agentRunner, deliverMessage, deliverToPare
581
597
  })
582
598
  },
583
599
  history: piMessages,
600
+ ...childTurn.run,
584
601
  actor,
585
602
  credentialContext: credentialContextForActor(actor, credentialSubject),
586
603
  destination,
@@ -802,4 +819,4 @@ function createConversationTurnWorker(agentRunner, deliverMessage, deliverToPare
802
819
  });
803
820
  };
804
821
  }
805
- export { withTurnSpan as a, resumeConversationDelivery as c, turnInputTelemetry as i, createConversationTurnWorker as n, canPauseConversationDelivery as o, getTurnInputSpanAttributes as r, pauseConversationDelivery as s, conversation_turn_exports as t };
822
+ export { resumeConversationDelivery as a, withTurnSpan as c, pauseConversationDelivery as i, createConversationTurnWorker as n, getTurnInputSpanAttributes as o, canPauseConversationDelivery as r, turnInputTelemetry as s, conversation_turn_exports as t };