@sentry/junior 0.312.0 → 0.314.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 (115) hide show
  1. package/dist/{adapter-iIq7ihf7.js → adapter-JARQvoLw.js} +1 -2
  2. package/dist/{adapter-context-BRjEWRy1.js → adapter-context-B4BrJZuS.js} +2 -2
  3. package/dist/{admin-DhInw5K9.js → admin-BXGAySz0.js} +1 -1
  4. package/dist/{agent-runner-C9iDurwX.js → agent-runner-qZU5TR8i.js} +865 -138
  5. package/dist/agent-update-cS7Z9mnG.js +26 -0
  6. package/dist/agent-update-delivery-CZ5M8RDa.js +85 -0
  7. package/dist/api/schema.d.ts +2 -2
  8. package/dist/api/schema.js +6 -6
  9. package/dist/api.d.ts +1 -1
  10. package/dist/api.js +340 -106
  11. package/dist/{app-DRFrC8Mw.d.ts → app-D7tKnw9a.d.ts} +4 -21
  12. package/dist/app.d.ts +2 -2
  13. package/dist/app.js +80 -171
  14. package/dist/{background-compaction-queue-DrKi7w3d.js → background-compaction-queue-C_uIBUvS.js} +6 -17
  15. package/dist/{callback-mFlTUWWx.js → callback-C8SdXCwr.js} +4 -11
  16. package/dist/{catalog-runtime-D7xapBAX.js → catalog-runtime-BLKtnUL3.js} +1 -1
  17. package/dist/{channel-access-CJGfNTdn.js → channel-access-BOL29BG3.js} +6 -6
  18. package/dist/child-message--2G3Ft26.js +19 -0
  19. package/dist/cli/chat.js +18 -21
  20. package/dist/cli/check.js +4 -4
  21. package/dist/cli/main.js +2 -2
  22. package/dist/cli/plugins.js +5 -5
  23. package/dist/cli/snapshot-create.js +5 -5
  24. package/dist/cli/upgrade.d.ts +1 -1
  25. package/dist/cli/upgrade.js +23 -4
  26. package/dist/{config-kXB2Y5tl.js → config-BIfHKNXN.js} +40 -35
  27. package/dist/{continue-in-slack-O6pV5004.js → continue-in-slack-fnmD2Ifb.js} +5 -7
  28. package/dist/{conversation-feed-uNOv_x68.js → conversation-feed-DdFQuQDR.js} +13 -2
  29. package/dist/{logging-dQ9ZRGQ8.js → conversation-privacy-DtZhI91r.js} +188 -2
  30. package/dist/{conversation-turn-CeLbHqdw.js → conversation-turn-DScuDYmN.js} +465 -62
  31. package/dist/create-CrNt4Ewu.js +212 -0
  32. package/dist/{credential-sync-I8VBGk05.js → credential-sync-CtqsGjj1.js} +14 -18
  33. package/dist/{credentialed-Cb6E2phL.js → credentialed-dWRA3-oJ.js} +911 -429
  34. package/dist/{db-LAyyX8tk.js → db-BTmLKZrp.js} +2245 -50
  35. package/dist/{db-BbC5stfa.d.ts → db-DcmzbA55.d.ts} +2 -2
  36. package/dist/{history-CYstOMKX.js → history-CneKY7_V.js} +19 -1
  37. package/dist/{html-BCZ3Xtb_.js → html-B8rBt7F4.js} +5 -7
  38. package/dist/{install-DCFJFkC0.js → install-OtFboxOM.js} +2 -2
  39. package/dist/instrumentation.js +2 -2
  40. package/dist/{lineage-B_m-4TJw.js → lineage-EULJkGO1.js} +1 -2
  41. package/dist/{list-CN2QA2R9.js → list-C5400AlJ.js} +284 -113
  42. package/dist/{thread-state-DhPndWi1.js → mailbox-turn-DL3Lvsm0.js} +4830 -485
  43. package/dist/markers-DUP8aBOp.js +323 -0
  44. package/dist/{media-CYm1QD8T.js → media-FYM-Bl3H.js} +42 -14
  45. package/dist/{message-DSXGj1hM.js → message-DuDelZFr.js} +16 -15
  46. package/dist/{model-input--TrP9hYV.js → model-input-0osF3pBS.js} +3 -3
  47. package/dist/nitro.d.ts +2 -4
  48. package/dist/nitro.js +340 -13
  49. package/dist/{oauth-callback-server-DHCZC6B4.js → oauth-callback-server-DX2fQ7Nq.js} +2 -2
  50. package/dist/{oauth-relay-pPMGnDZt.js → oauth-relay-PwPMdZJv.js} +1 -1
  51. package/dist/{plugins-Bkk0XRo2.js → plugins-BXMdNdyA.js} +1 -1
  52. package/dist/{registry-CZOzddwu.js → registry-D6kS6xYH.js} +1402 -64
  53. package/dist/{statuses-_cRJHXK7.js → reporting-window-C4dbzDiR.js} +1 -27
  54. package/dist/{resolve-cKOQ14Dh.js → resolve-D8CPJcNK.js} +3 -3
  55. package/dist/result-D090hxr5.js +402 -0
  56. package/dist/{runner-DBfUW44l.js → runner-BU7fgrm-.js} +7 -8
  57. package/dist/{sandbox-egress-signals-BVF_xAm1.js → sandbox-egress-signals-BUmVrsoG.js} +1 -1
  58. package/dist/{schema-Bk9Nm2E8.js → schema-7gW9vBpJ.js} +91 -10
  59. package/dist/{schema-BEHKxr4I.d.ts → schema-BB6E0wyV.d.ts} +2105 -2753
  60. package/dist/{service-account-CVYsFjty.js → service-account-plA-uzIB.js} +6 -5
  61. package/dist/{skills-VTnhAJWm.js → skills-CIosT6bS.js} +3 -3
  62. package/dist/{slack-conversation-unfurl-fuLnF1jE.js → slack-conversation-unfurl-CBgZqth6.js} +8 -10
  63. package/dist/spawn-DRjdzh3R.js +46 -0
  64. package/dist/{start-conversation-CEn2KH1A.js → start-conversation-a4NXH4X9.js} +13 -202
  65. package/dist/{store-DFZaN-Ix.js → store-BuhF1QDm.js} +2 -4
  66. package/dist/{task-queue-Cx4Lmjyk.js → task-queue-CrRjFzOh.js} +5 -16
  67. package/dist/{task-runner-CbTwFA6k.js → task-runner-C-pXsgHM.js} +105 -51
  68. package/dist/{thread-context-BkAZDTX2.js → thread-context-CDX4dSZd.js} +8 -10
  69. package/dist/turn-session-routing-CZTRU8IY.js +116 -0
  70. package/dist/turn-wake-Bzq1Efrm.js +154 -0
  71. package/dist/user-customization-B27StpVQ.js +9 -0
  72. package/dist/{validation-nIzMtAVJ.js → validation-bTq88sya.js} +1 -1
  73. package/dist/{vercel-queue-hW90XzbG.js → vercel-queue-nL0Hq3hr.js} +32 -147
  74. package/dist/{version-Brbtz4Qf.js → version-DGUa1dZK.js} +1 -1
  75. package/dist/version.js +1 -1
  76. package/dist/{warmup-BDA5myRK.js → warmup-CCOuIwAS.js} +831 -3254
  77. package/dist/{worker-D63RcaVD.js → worker-AkZg7Dg1.js} +5 -6
  78. package/migrations/0158_keep_legacy_archive_columns.sql +5 -0
  79. package/migrations/0159_conversation_embeddings_fk_validate.sql +5 -0
  80. package/migrations/0160_money_micro_usd_repair.sql +99 -0
  81. package/migrations/0161_agent_config_backfill.sql +34 -0
  82. package/migrations/0162_inbox_item_deliveries.sql +15 -0
  83. package/migrations/0163_pg_trgm.sql +2 -0
  84. package/migrations/0164_search_indexes.sql +4 -0
  85. package/migrations/0165_drop_legacy_archive_columns.sql +4 -0
  86. package/migrations/0166_memory_prefix_index.sql +1 -0
  87. package/migrations/0167_todo_search_indexes.sql +2 -0
  88. package/migrations/0168_todo_inbox_items.sql +4 -0
  89. package/migrations/0169_drop_code_urls.sql +2 -0
  90. package/migrations/meta/0158_snapshot.json +6515 -0
  91. package/migrations/meta/0159_snapshot.json +6515 -0
  92. package/migrations/meta/0160_snapshot.json +6515 -0
  93. package/migrations/meta/0161_snapshot.json +6278 -0
  94. package/migrations/meta/0162_snapshot.json +6404 -0
  95. package/migrations/meta/0163_snapshot.json +6404 -0
  96. package/migrations/meta/0164_snapshot.json +6466 -0
  97. package/migrations/meta/0165_snapshot.json +6466 -0
  98. package/migrations/meta/0166_snapshot.json +6494 -0
  99. package/migrations/meta/0167_snapshot.json +6525 -0
  100. package/migrations/meta/0168_snapshot.json +6525 -0
  101. package/migrations/meta/0169_snapshot.json +6513 -0
  102. package/migrations/meta/_journal.json +84 -0
  103. package/package.json +9 -18
  104. package/skills/design-automation-skill/SKILL.md +2 -3
  105. package/dist/actor-BsBdxDXQ.js +0 -208
  106. package/dist/child-message-DcsritGf.js +0 -179
  107. package/dist/conversation-privacy-L4ja1_W6.js +0 -189
  108. package/dist/executor-SCub-fAq.js +0 -1860
  109. package/dist/fan-out-Cod-yEHG.js +0 -10
  110. package/dist/ingest-BDf3D50j.js +0 -3836
  111. package/dist/result-DcvEOe1r.js +0 -574
  112. package/dist/result-event-type-BdIJuZxg.js +0 -48
  113. package/dist/service-account-Ts4ulcrV.js +0 -931
  114. package/dist/spawn-vxAarlX5.js +0 -73
  115. package/dist/state-C1P3_Ywk.js +0 -161
@@ -1,21 +1,19 @@
1
1
  import { t as __exportAll } from "./rolldown-runtime-BKpuH2hG.js";
2
- import { Bn as readConversationMetadata, Fn as createPluginTurnEventReader, Hn as resolveRootVisibility, In as createPluginConversationEvents, Kn as storeConversationEmbedding, Ln as renderPluginConversationEvent, Mn as createPluginEmbedder, Nn as createPluginModel, Nr as getDispatchRecord, Pn as createPluginModelCostRecorder, Pt as createPluginState, Vn as writeConversationMetadata, Wn as createConversationEmbedder, Yn as listConversationAnnotations, _s as renderJuniorNativeConversationEvent, as as createPluginCache, at as getPiMessageRole, g as getRegistrations, gt as normalizeToolNameFromResult, ht as isToolResultMessage, mt as isToolResultError, ss as completeObject, st as getUserMessageInstructionText, ut as instructionTextForProjection, vt as stripRuntimeTurnContext, wr as createPluginLogger } from "./credentialed-Cb6E2phL.js";
3
- import { C as createSqlStore, D as hasConversationMetadata, Lt as readActorIdentity, Mn as hasAgentTurnUsage, a as getConversationStore, d as eventFromRow, o as getDb, s as getSqlExecutor } from "./db-LAyyX8tk.js";
4
- import { E as withSpan, U as buildSentryEventUrl, a as extractGenAiUsageSummary, m as logInfo } from "./logging-dQ9ZRGQ8.js";
5
- import { Ct as isEventAuthorId, Yt as getTurnRecord, gn as loadTurnStart, nt as hydrateConversationMessages, o as coerceThreadConversationState, r as getPersistedThreadState } from "./thread-state-DhPndWi1.js";
6
- import { O as matchSlackAttachments, T as isInheritedForkHistory, b as savedTurnMessages, n as startConversationToolDefinition, x as resolveConversationRouting } from "./start-conversation-CEn2KH1A.js";
7
- import { v as parseSlackMessageTs } from "./actor-BsBdxDXQ.js";
8
- import { m as sameActorIdentity } from "./history-CYstOMKX.js";
9
- import { H as juniorConversations, L as juniorCodeChanges, M as juniorConversationEvents, R as juniorCodeRepositories } from "./executor-SCub-fAq.js";
10
- import { n as botConfig, z as withLock } from "./config-kXB2Y5tl.js";
11
- import { i as getStateAdapter } from "./adapter-iIq7ihf7.js";
12
- import { Q as conversationReportMessageEventSchema, St as readMessageCardRefs, Z as conversationReportEventSchema, kt as readMessageAttachments, vt as inboxItemChangeRecordSchema } from "./media-CYm1QD8T.js";
2
+ import { $n as resolveRootVisibility, Ct as instructionTextForProjection, Dt as isToolResultError, Es as completeObject, Gn as createPluginModelCostRecorder, Gt as createPluginState, Is as renderJuniorNativeConversationEvent, Jn as renderPluginConversationEvent, Kn as createPluginTurnEventReader, Ot as isToolResultMessage, Qn as writeConversationMetadata, Rr as createPluginLogger, Un as createPluginEmbedder, Wn as createPluginModel, Zn as readConversationMetadata, bt as getUserMessageInstructionText, g as getRegistrations, h as getPlugins, jt as stripRuntimeTurnContext, kt as normalizeToolNameFromResult, lr as listConversationAnnotations, qn as createPluginConversationEvents, qr as getDispatchRecord, rr as storeConversationEmbedding, tr as createConversationEmbedder, vt as getPiMessageRole, ws as createPluginCache } from "./credentialed-dWRA3-oJ.js";
3
+ import { Ar as juniorConversationEvents, Br as juniorConversations, Fr as juniorCodeChanges, I as hasConversationMetadata, Ir as juniorCodeRepositories, Kn as hasAgentTurnUsage, M as createSqlStore, Xt as readActorIdentity, a as getDb, bi as parseSlackMessageTs, f as eventFromRow, i as getConversationStore, o as getSqlExecutor } from "./db-BTmLKZrp.js";
4
+ import { C as logInfo, F as withSpan, Q as buildSentryEventUrl, m as extractGenAiUsageSummary } from "./conversation-privacy-DtZhI91r.js";
5
+ import { D as isInheritedForkHistory, Si as loadTurnStart, dr as hydrateConversationMessages, ei as getTurnRecord, gt as getPersistedThreadState, kr as isEventAuthorId, m as isParentMessageAuthor, yt as coerceThreadConversationState } from "./mailbox-turn-DL3Lvsm0.js";
6
+ import { i as savedTurnMessages, t as resolveConversationRouting } from "./turn-session-routing-CZTRU8IY.js";
7
+ import { m as sameActorIdentity } from "./history-CneKY7_V.js";
8
+ import { gt as mapBounded, n as botConfig, z as withLock } from "./config-BIfHKNXN.js";
9
+ import { i as getStateAdapter } from "./adapter-JARQvoLw.js";
10
+ import { b as matchSlackAttachments, n as startConversationToolDefinition } from "./start-conversation-a4NXH4X9.js";
11
+ import { Q as conversationReportMessageEventSchema, St as readMessageCardRefs, Z as conversationReportEventSchema, kt as readMessageAttachments, vt as inboxItemChangeRecordSchema } from "./media-FYM-Bl3H.js";
13
12
  import { h as startSpan } from "./sentry-CPbZjomA.js";
14
- import { i as pluginTaskParamsSchema, r as pluginTaskId } from "./task-queue-Cx4Lmjyk.js";
15
- import { t as mapBounded } from "./fan-out-Cod-yEHG.js";
13
+ import { i as pluginTaskParamsSchema, r as pluginTaskId } from "./task-queue-CrRjFzOh.js";
16
14
  import * as z from "zod";
17
15
  import { objectTypeSchema, pluginRunContextSchema, renderTag, tagJson } from "@sentry/junior-plugin-api";
18
- import { and, arrayContains, asc, desc, eq, getTableColumns, gt, inArray, isNotNull, lt, max, sql } from "drizzle-orm";
16
+ import { and, arrayContains, asc, desc, eq, getTableColumns, gt, inArray, lt, max, sql } from "drizzle-orm";
19
17
  import { alias } from "drizzle-orm/pg-core";
20
18
  // src/chat/conversations/metadata/generate.ts
21
19
  const MAX_INPUT_CHARS = 6e4;
@@ -60,8 +58,6 @@ function promptInput(args) {
60
58
  const entries = boundedEntries(args.input.entries);
61
59
  const messages = entries.filter((entry) => entry.role !== "tool");
62
60
  const tools = entries.filter((entry) => entry.role === "tool");
63
- const keptMessages = [...messages];
64
- const keptTools = [];
65
61
  const base = {
66
62
  conversation: {
67
63
  title: args.input.title,
@@ -72,29 +68,45 @@ function promptInput(args) {
72
68
  codeChanges: args.input.codeChanges,
73
69
  resources: args.input.resources
74
70
  };
75
- const serialize = () => {
76
- const kept = /* @__PURE__ */ new Set([...keptMessages, ...keptTools]);
77
- return tagJson({
78
- ...base,
79
- omitted: {
80
- messages: messages.length - keptMessages.length,
81
- toolResults: tools.length - keptTools.length
82
- },
83
- entries: entries.filter((entry) => kept.has(entry))
84
- });
85
- };
86
- let text = serialize();
87
- while (text.length > MAX_INPUT_CHARS && keptMessages.length > 0) {
88
- keptMessages.shift();
89
- text = serialize();
71
+ const emptyLength = tagJson({
72
+ ...base,
73
+ omitted: {
74
+ messages: 0,
75
+ toolResults: 0
76
+ },
77
+ entries: []
78
+ }).length;
79
+ const lengthOf = (keptMessages, keptTools, entryChars) => emptyLength - 2 + String(messages.length - keptMessages).length + String(tools.length - keptTools).length + entryChars + Math.max(0, keptMessages + keptTools - 1);
80
+ const entryLength = (entry) => tagJson(entry).length;
81
+ const messageLengths = messages.map(entryLength);
82
+ let messageChars = messageLengths.reduce((sum, length) => sum + length, 0);
83
+ let firstKeptMessage = 0;
84
+ while (firstKeptMessage < messages.length && lengthOf(messages.length - firstKeptMessage, 0, messageChars) > MAX_INPUT_CHARS) {
85
+ messageChars -= messageLengths[firstKeptMessage];
86
+ firstKeptMessage += 1;
90
87
  }
91
- if (text.length > MAX_INPUT_CHARS) throw new Error("Conversation metadata input exceeds the 60,000 character limit");
88
+ const keptMessageCount = messages.length - firstKeptMessage;
89
+ if (lengthOf(keptMessageCount, 0, messageChars) > MAX_INPUT_CHARS) throw new Error("Conversation metadata input exceeds the 60,000 character limit");
90
+ const kept = new Set(messages.slice(firstKeptMessage));
91
+ let keptToolCount = 0;
92
+ let entryChars = messageChars;
92
93
  for (let index = tools.length - 1; index >= 0; index -= 1) {
93
- keptTools.push(tools[index]);
94
- const candidate = serialize();
95
- if (candidate.length <= MAX_INPUT_CHARS) text = candidate;
96
- else keptTools.pop();
94
+ const tool = tools[index];
95
+ const length = entryLength(tool);
96
+ if (lengthOf(keptMessageCount, keptToolCount + 1, entryChars + length) <= MAX_INPUT_CHARS) {
97
+ kept.add(tool);
98
+ keptToolCount += 1;
99
+ entryChars += length;
100
+ }
97
101
  }
102
+ const text = tagJson({
103
+ ...base,
104
+ omitted: {
105
+ messages: messages.length - keptMessageCount,
106
+ toolResults: tools.length - keptToolCount
107
+ },
108
+ entries: entries.filter((entry) => kept.has(entry))
109
+ });
98
110
  return [renderTag("conversation-metadata-input", {}, [text]), "Return the next summary as structured data."].join("\n");
99
111
  }
100
112
  /** Generate the next summary of one Conversation. */
@@ -257,6 +269,16 @@ function reportMessageActorIdentity(data) {
257
269
  };
258
270
  return Object.keys(actorIdentity).length > 0 ? actorIdentity : void 0;
259
271
  }
272
+ /**
273
+ * Mark a child's input that its parent agent wrote, so the dashboard does not
274
+ * show the person who started the root as its author. Rows from before
275
+ * parent messages store the id of the work that wrote them. A parent message
276
+ * is named by its own id.
277
+ */
278
+ function reportParentAgentInput(message) {
279
+ if (typeof message.agentInvocationId === "string") return { agentInvocationId: message.agentInvocationId };
280
+ return isParentMessageAuthor({ userId: message.authorUserId }) ? { agentInvocationId: message.messageId } : void 0;
281
+ }
260
282
  /** Project native assistant tool calls through the existing reporting shape. */
261
283
  function reportToolCalls(args) {
262
284
  const message = reportingAssistantMessageSchema.safeParse(args.message);
@@ -395,11 +417,17 @@ function reportEventData(args) {
395
417
  ...data.meta?.["source"] === "web" || data.meta?.["source"] === "slack" ? { source: data.meta["source"] } : void 0,
396
418
  ...actorIdentity ? { actorIdentity } : void 0,
397
419
  ...args.canExposePayload && data.role === "user" && data.authorIdentityId && data.authorIdentityId !== "system" ? { actorIdentityId: data.authorIdentityId } : void 0,
398
- ...typeof data.meta?.["agentInvocationId"] === "string" ? { agentInvocationId: data.meta["agentInvocationId"] } : void 0,
420
+ ...reportParentAgentInput({
421
+ agentInvocationId: data.meta?.["agentInvocationId"],
422
+ authorUserId: reportingMessageAuthorSchema.safeParse(data.meta?.["author"]).data?.userId,
423
+ messageId: data.messageId
424
+ }),
399
425
  ...args.canExposePayload ? reportInboxItemChanges(data.meta) : void 0,
400
426
  eventObjectType: objectTypeSchema.safeParse(data.meta?.["eventObjectType"]).data,
401
427
  ...typeof data.meta?.["eventType"] === "string" ? { eventType: data.meta["eventType"] } : void 0,
402
428
  ...typeof data.meta?.["eventNamespace"] === "string" ? { eventNamespace: data.meta["eventNamespace"] } : void 0,
429
+ ...typeof data.meta?.["eventStatus"] === "string" ? { eventStatus: data.meta["eventStatus"] } : void 0,
430
+ ...typeof data.meta?.["eventWatchId"] === "string" ? { eventWatchId: data.meta["eventWatchId"] } : void 0,
403
431
  ...args.canExposePayload && typeof data.meta?.["eventIdentifier"] === "string" ? { eventIdentifier: data.meta["eventIdentifier"] } : void 0,
404
432
  ...typeof data.meta?.["explicitMention"] === "boolean" ? { explicitMention: data.meta["explicitMention"] } : void 0,
405
433
  ...data.meta?.["quiet"] === true ? { quiet: true } : void 0,
@@ -831,6 +859,28 @@ async function readConversationMessageEventSeq(executor, conversationId, message
831
859
  const [row] = await executor.db().select({ seq: juniorConversationEvents.seq }).from(juniorConversationEvents).where(and(eq(juniorConversationEvents.conversationId, conversationId), eq(juniorConversationEvents.type, "message"), sql`${juniorConversationEvents.payload}->>'messageId' = ${messageId}`)).orderBy(asc(juniorConversationEvents.seq)).limit(1);
832
860
  return row?.seq;
833
861
  }
862
+ // src/chat/code/links.ts
863
+ function codeLinks(provider) {
864
+ return getPlugins().find((plugin) => plugin.manifest.name === provider)?.codeLinks;
865
+ }
866
+ /** Providers whose installed plugin builds code links. */
867
+ function linkedCodeProviders() {
868
+ return getPlugins().flatMap((plugin) => plugin.codeLinks ? [plugin.manifest.name] : []);
869
+ }
870
+ /**
871
+ * Build the web page of one code change from its repository and number.
872
+ * Undefined when no installed plugin builds links for the provider.
873
+ */
874
+ function codeChangeUrl(change) {
875
+ return codeLinks(change.provider)?.change(change);
876
+ }
877
+ /**
878
+ * Build the web page of one repository from its name. Undefined when no
879
+ * installed plugin builds links for the provider.
880
+ */
881
+ function codeRepositoryUrl(repository) {
882
+ return codeLinks(repository.provider)?.repository(repository.name);
883
+ }
834
884
  // src/chat/conversations/transcript-entries.ts
835
885
  const TOOL_TEXT_LIMIT = 1500;
836
886
  function actorIdentityKey(actor) {
@@ -953,11 +1003,11 @@ async function conversationMetadataInputFromSql(executor, conversationId, throug
953
1003
  closedAt: juniorCodeChanges.closedAt,
954
1004
  mergedAt: juniorCodeChanges.mergedAt,
955
1005
  number: juniorCodeChanges.number,
1006
+ provider: juniorCodeChanges.provider,
956
1007
  repository: juniorCodeRepositories.name,
957
1008
  state: juniorCodeChanges.state,
958
- title: juniorCodeChanges.title,
959
- url: juniorCodeChanges.url
960
- }).from(juniorCodeChanges).innerJoin(juniorCodeRepositories, eq(juniorCodeRepositories.id, juniorCodeChanges.repositoryId)).where(and(arrayContains(juniorCodeChanges.conversationIds, [conversationId]), isNotNull(juniorCodeChanges.url)))
1009
+ title: juniorCodeChanges.title
1010
+ }).from(juniorCodeChanges).innerJoin(juniorCodeRepositories, eq(juniorCodeRepositories.id, juniorCodeChanges.repositoryId)).where(arrayContains(juniorCodeChanges.conversationIds, [conversationId]))
961
1011
  ]);
962
1012
  const location = conversation.location;
963
1013
  return {
@@ -968,15 +1018,19 @@ async function conversationMetadataInputFromSql(executor, conversationId, throug
968
1018
  ...conversation.channelName ? { channelName: conversation.channelName } : void 0
969
1019
  } } : void 0,
970
1020
  entries: transcriptEntriesFromReportEvents(events),
971
- codeChanges: codeChanges.map((change) => ({
972
- repository: change.repository,
973
- number: change.number,
974
- ...change.title ? { title: change.title } : void 0,
975
- url: change.url,
976
- state: change.state,
977
- ...change.mergedAt ? { mergedAt: change.mergedAt.toISOString() } : void 0,
978
- ...change.closedAt ? { closedAt: change.closedAt.toISOString() } : void 0
979
- })),
1021
+ codeChanges: codeChanges.flatMap((change) => {
1022
+ const url = codeChangeUrl(change);
1023
+ if (!url) return [];
1024
+ return [{
1025
+ repository: change.repository,
1026
+ number: change.number,
1027
+ ...change.title ? { title: change.title } : void 0,
1028
+ url,
1029
+ state: change.state,
1030
+ ...change.mergedAt ? { mergedAt: change.mergedAt.toISOString() } : void 0,
1031
+ ...change.closedAt ? { closedAt: change.closedAt.toISOString() } : void 0
1032
+ }];
1033
+ }),
980
1034
  resources: annotations.flatMap((annotation) => annotation.url ? [{
981
1035
  label: annotation.kind === "object" && annotation.title !== annotation.label ? `${annotation.label} · ${annotation.title}` : annotation.label,
982
1036
  url: annotation.url,
@@ -1375,7 +1429,7 @@ function taskPluginContext(plugin, message, options = {}) {
1375
1429
  };
1376
1430
  }
1377
1431
  function isConversationMetadataTask(message) {
1378
- return message.plugin === CONVERSATION_METADATA_TASK.plugin && message.name === CONVERSATION_METADATA_TASK.name || message.plugin === "briefs" && message.name === "updateBrief";
1432
+ return message.plugin === CONVERSATION_METADATA_TASK.plugin && message.name === CONVERSATION_METADATA_TASK.name;
1379
1433
  }
1380
1434
  function findPluginTask(message) {
1381
1435
  const plugin = getRegistrations().find((candidate) => candidate.manifest.name === message.plugin);
@@ -1429,4 +1483,4 @@ async function processPluginTask(message, options = {}) {
1429
1483
  "app.plugin.task": message.name
1430
1484
  });
1431
1485
  }
1432
- export { readConversationEventPage as a, readConversationLastEventSeq as c, transcriptEntriesFromReportEvents as i, readConversationMessageEventSeq as l, scheduleSessionCompletedPluginTasks as n, readConversationEventPageAfter as o, task_runner_exports as r, readConversationEventPageAround as s, processPluginTask as t };
1486
+ export { codeChangeUrl as a, readConversationEventPage as c, readConversationLastEventSeq as d, readConversationMessageEventSeq as f, transcriptEntriesFromReportEvents as i, readConversationEventPageAfter as l, scheduleSessionCompletedPluginTasks as n, codeRepositoryUrl as o, reportParentAgentInput as p, task_runner_exports as r, linkedCodeProviders as s, processPluginTask as t, readConversationEventPageAround as u };
@@ -1,11 +1,10 @@
1
- import { Yn as listConversationAnnotations } from "./credentialed-Cb6E2phL.js";
2
- import { t as mapBounded } from "./fan-out-Cod-yEHG.js";
3
- import { b as setSpanAttributes } from "./logging-dQ9ZRGQ8.js";
4
- import { o as getDb, r as getConversationEventStore } from "./db-LAyyX8tk.js";
5
- import { Rt as clearPendingAuth, a as persistThreadStateById, ct as buildConversationContext, nt as hydrateConversationMessages, o as coerceThreadConversationState, pt as markConversationMessage, r as getPersistedThreadState, w as getConversationWorkState } from "./thread-state-DhPndWi1.js";
6
- import { Ct as removedCardSchema, St as readMessageCardRefs, wt as resolveMessageCards } from "./media-CYm1QD8T.js";
7
- import { F as getTurnUserMessageId, K as markTurnClosed, q as markTurnCompleted } from "./ingest-BDf3D50j.js";
8
- import { i as listChildMessages, r as isAgentInvocationResult } from "./child-message-DcsritGf.js";
1
+ import { lr as listConversationAnnotations } from "./credentialed-dWRA3-oJ.js";
2
+ import { gt as mapBounded } from "./config-BIfHKNXN.js";
3
+ import { k as setSpanAttributes } from "./conversation-privacy-DtZhI91r.js";
4
+ import { a as getDb, n as getConversationEventStore } from "./db-BTmLKZrp.js";
5
+ import { $ as getTurnUserMessageId, Bt as getConversationWorkState, Wr as clearPendingAuth, dr as hydrateConversationMessages, dt as markTurnCompleted, gr as buildConversationContext, gt as getPersistedThreadState, ut as markTurnClosed, vt as persistThreadStateById, xr as markConversationMessage, yt as coerceThreadConversationState } from "./mailbox-turn-DL3Lvsm0.js";
6
+ import { Ct as removedCardSchema, St as readMessageCardRefs, wt as resolveMessageCards } from "./media-FYM-Bl3H.js";
7
+ import { n as listChildMessages } from "./child-message--2G3Ft26.js";
9
8
  // src/chat/conversations/pending-cards.ts
10
9
  /**
11
10
  * Add the cards that tool results selected since the last visible assistant
@@ -49,12 +48,11 @@ async function selectChildResultCards(conversationId, inputMessageIds, selection
49
48
  if (inputMessageIds.length === 0) return;
50
49
  const events = getConversationEventStore();
51
50
  const execution = (await getConversationWorkState({ conversationId }))?.execution;
52
- const messages = await listChildMessages(inputMessageIds, execution?.messageSenders ?? {});
51
+ const messages = listChildMessages(inputMessageIds, execution?.messageSenders ?? {});
53
52
  messages.reverse();
54
53
  const terminals = await mapBounded(messages, ({ sender }) => events.loadByIdempotencyKey(sender.conversationId, `turn:${sender.turnId}:terminal`));
55
54
  for (const [index, message] of messages.entries()) {
56
55
  const terminal = terminals[index];
57
- if (!terminal && isAgentInvocationResult(message)) continue;
58
56
  await selectTurnCards(message.sender.conversationId, selection, terminal?.seq);
59
57
  }
60
58
  }
@@ -0,0 +1,116 @@
1
+ import { Wr as getDispatchConversationId, qr as getDispatchRecord } from "./credentialed-dWRA3-oJ.js";
2
+ // src/chat/task-execution/turn-membership.ts
3
+ /** True when the committed message at `seq` belongs to the Turn. */
4
+ function isTurnMessage(start, seq, message) {
5
+ return seq > start.seq && message.role !== "system";
6
+ }
7
+ /**
8
+ * The messages of a saved Turn with their provenance. Without a
9
+ * `turn_started` event, nothing tells this Turn from earlier history, so it
10
+ * has no messages.
11
+ */
12
+ function savedTurnMessages(record, start) {
13
+ if (!start) return [];
14
+ return record.piMessages.flatMap((message, index) => {
15
+ const seq = record.piMessageSeqs[index];
16
+ return seq !== void 0 && isTurnMessage(start, seq, message) ? [{
17
+ message,
18
+ provenance: record.piMessageProvenance[index] ?? { authority: "context" }
19
+ }] : [];
20
+ });
21
+ }
22
+ // src/chat/services/turn-session-routing.ts
23
+ async function loadConversationChain(conversationId, conversationStore) {
24
+ const chain = [];
25
+ const seen = /* @__PURE__ */ new Set();
26
+ let cursor = conversationId;
27
+ while (cursor && !seen.has(cursor)) {
28
+ seen.add(cursor);
29
+ const conversation = await conversationStore.get({ conversationId: cursor });
30
+ if (!conversation) break;
31
+ chain.push(conversation);
32
+ cursor = conversation.parentConversationId;
33
+ }
34
+ return chain;
35
+ }
36
+ /**
37
+ * Normalize a stored Slack session source against the conversation destination.
38
+ *
39
+ * Does not create channel or thread values from the conversation id.
40
+ */
41
+ function slackSourceForDestination(args) {
42
+ if (args.source?.kind !== "slack" || args.source.channelId !== args.destination.channelId) return;
43
+ const threadTs = args.source.threadTs?.trim();
44
+ return {
45
+ kind: "slack",
46
+ visibility: args.source.visibility ?? "public",
47
+ teamId: args.source.teamId?.trim() || args.destination.teamId,
48
+ channelId: args.source.channelId,
49
+ ...threadTs ? { threadTs } : void 0
50
+ };
51
+ }
52
+ /**
53
+ * Resolve the Conversation Location, Destination, and session Source.
54
+ *
55
+ * Reads parent Conversations when this Conversation has no Destination.
56
+ */
57
+ async function resolveConversationRouting(args) {
58
+ const conversationStore = args.conversationStore ?? (await import("./db-BTmLKZrp.js").then((n) => n.t)).getConversationStore();
59
+ const chain = await loadConversationChain(args.conversationId, conversationStore);
60
+ let destination;
61
+ let source;
62
+ let location;
63
+ for (const conversation of chain) {
64
+ destination ??= conversation.destination;
65
+ source ??= conversation.sessionSource;
66
+ location ??= conversation.location;
67
+ if (destination && source) break;
68
+ }
69
+ if (!destination) return;
70
+ if (destination.platform === "slack") {
71
+ const slackSource = slackSourceForDestination({
72
+ destination,
73
+ source
74
+ });
75
+ return {
76
+ destination,
77
+ ...location ? { location } : void 0,
78
+ ...slackSource ? { source: slackSource } : void 0
79
+ };
80
+ }
81
+ return {
82
+ destination,
83
+ ...location ? { location } : void 0,
84
+ ...source ? { source } : void 0
85
+ };
86
+ }
87
+ /** Require the Conversation Destination and Source from SQL. */
88
+ async function resolveTurnSessionRouting(args) {
89
+ const routing = await resolveConversationRouting(args);
90
+ if (!routing?.destination || !routing.source) throw new Error(`Conversation ${args.conversationId} is missing durable routing metadata`);
91
+ return {
92
+ destination: routing.destination,
93
+ ...routing.location ? { location: routing.location } : void 0,
94
+ source: routing.source
95
+ };
96
+ }
97
+ /**
98
+ * Require the Destination and Source to resume a Turn.
99
+ *
100
+ * A dispatch Conversation stores the dispatch Source, which has no session
101
+ * Source. Its dispatch record owns the Destination and Source.
102
+ */
103
+ async function resolveTurnResumeRouting(args) {
104
+ if (!args.dispatchId) return await resolveTurnSessionRouting(args);
105
+ const dispatch = await getDispatchRecord(args.dispatchId);
106
+ if (!dispatch) throw new Error(`Dispatch record is missing for ${args.dispatchId}`);
107
+ const dispatchConversationId = getDispatchConversationId(dispatch);
108
+ if (dispatchConversationId !== args.conversationId) throw new Error(`Dispatch ${dispatch.id} belongs to ${dispatchConversationId}, not ${args.conversationId}`);
109
+ const location = (await resolveConversationRouting(args))?.location;
110
+ return {
111
+ destination: dispatch.destination,
112
+ ...location ? { location } : void 0,
113
+ source: dispatch.source
114
+ };
115
+ }
116
+ export { savedTurnMessages as i, resolveTurnResumeRouting as n, isTurnMessage as r, resolveConversationRouting as t };
@@ -0,0 +1,154 @@
1
+ import { i as getConversationStore, n as getConversationEventStore, z as isTopLevelKind } from "./db-BTmLKZrp.js";
2
+ import { $r as failTurnRecord, Rt as ensureConversationWake, ei as getTurnRecord, ni as recordTurnSummary, qr as loadTurnCheckpoint, qt as requestConversationWork } from "./mailbox-turn-DL3Lvsm0.js";
3
+ import { n as resolveTurnResumeRouting } from "./turn-session-routing-CZTRU8IY.js";
4
+ import { qr as getDispatchRecord } from "./credentialed-dWRA3-oJ.js";
5
+ import { S as logException } from "./conversation-privacy-DtZhI91r.js";
6
+ import { t as getVercelConversationWorkQueue } from "./vercel-queue-nL0Hq3hr.js";
7
+ import * as z from "zod";
8
+ // src/chat/task-execution/authorized-turn.ts
9
+ /**
10
+ * OAuth callbacks save readiness, not agent history. The conversation worker
11
+ * consumes this event under its lease before it resumes the paused Turn.
12
+ */
13
+ const authorizationSchema = z.object({
14
+ kind: z.enum(["mcp", "plugin"]),
15
+ provider: z.string().min(1),
16
+ actorId: z.string().min(1),
17
+ authorizationId: z.string().min(1),
18
+ authSessionId: z.string().optional(),
19
+ scope: z.string().optional(),
20
+ configuration: z.record(z.string(), z.unknown()).optional(),
21
+ toolChannelId: z.string().optional()
22
+ });
23
+ function authorizationKey(turn) {
24
+ return `turn:${turn.turnId}:authorization:${turn.version}`;
25
+ }
26
+ /** Save authorization for this parked boundary without changing model history. */
27
+ async function recordTurnAuthorization(args) {
28
+ const turn = await getTurnRecord(args.conversationId, args.turnId);
29
+ if (!turn || turn.state !== "paused" || turn.resumeReason !== "auth") return;
30
+ await getConversationEventStore().append(args.conversationId, [{
31
+ idempotencyKey: authorizationKey(turn),
32
+ createdAtMs: Date.now(),
33
+ data: {
34
+ type: "structured_event",
35
+ namespace: "junior",
36
+ name: "turn_authorized",
37
+ version: 1,
38
+ turnId: turn.turnId,
39
+ content: authorizationSchema.parse(args)
40
+ }
41
+ }], { activity: "preserve" });
42
+ return {
43
+ conversationId: args.conversationId,
44
+ destination: args.destination,
45
+ turnId: turn.turnId,
46
+ expectedVersion: turn.version
47
+ };
48
+ }
49
+ /** Read authorization for the exact pause; a later auth pause needs its own callback. */
50
+ async function getTurnAuthorization(turn) {
51
+ const event = await getConversationEventStore().loadByIdempotencyKey(turn.conversationId, authorizationKey(turn));
52
+ if (event?.data.type !== "structured_event") return void 0;
53
+ return authorizationSchema.parse(event.data.content);
54
+ }
55
+ // src/chat/task-execution/turn-wake.ts
56
+ /** Build the worker input for a paused turn. */
57
+ async function getPausedTurnRequest(args) {
58
+ const turn = (await loadTurnCheckpoint({
59
+ conversationId: args.conversationId,
60
+ turnId: args.turnId
61
+ })).record;
62
+ if (!turn || turn.state !== "paused" || turn.resumeReason !== "timeout" && turn.resumeReason !== "yield" && turn.resumeReason !== "retry" && !(turn.resumeReason === "auth" && await getTurnAuthorization(turn)) || turn.resumeReason === "timeout" && turn.sliceId < 2) return;
63
+ let routing;
64
+ try {
65
+ routing = await resolveTurnResumeRouting({
66
+ conversationId: args.conversationId,
67
+ conversationStore: args.conversationStore,
68
+ dispatchId: turn.dispatchId
69
+ });
70
+ } catch (error) {
71
+ const failed = await failTurnRecord({
72
+ conversationId: args.conversationId,
73
+ expectedVersion: turn.version,
74
+ turnId: args.turnId,
75
+ errorMessage: error instanceof Error ? error.message : String(error)
76
+ });
77
+ if (failed) await recordFailedDispatchTurn(failed);
78
+ return;
79
+ }
80
+ return {
81
+ conversationId: args.conversationId,
82
+ destination: routing.destination,
83
+ turnId: args.turnId,
84
+ expectedVersion: turn.version,
85
+ traceContext: turn.traceContext
86
+ };
87
+ }
88
+ /**
89
+ * Record that a resume failed a dispatch turn for good. Without this outcome,
90
+ * the dispatch runs the turn again, so a failed write is only logged.
91
+ */
92
+ async function recordFailedDispatchTurn(turn) {
93
+ if (!turn.dispatchId) return;
94
+ try {
95
+ const dispatch = await getDispatchRecord(turn.dispatchId);
96
+ await recordTurnSummary({
97
+ conversationId: turn.conversationId,
98
+ destination: dispatch?.destination,
99
+ dispatchId: turn.dispatchId,
100
+ dispatchOutcome: "failed",
101
+ turnId: turn.turnId,
102
+ sliceId: turn.sliceId,
103
+ source: dispatch?.source,
104
+ state: "failed",
105
+ surface: turn.surface
106
+ });
107
+ } catch (error) {
108
+ logException(error, "agent.continue.dispatch_failure_summary.failed", {
109
+ "app.ai.conversation_id": turn.conversationId,
110
+ "app.ai.session_id": turn.turnId
111
+ });
112
+ }
113
+ }
114
+ /** Wake the conversation worker for a paused turn. */
115
+ async function wakePausedTurn(request, options = {}) {
116
+ const nowMs = options.nowMs ?? Date.now();
117
+ const conversation = await (options.conversationStore ?? getConversationStore()).get({ conversationId: request.conversationId });
118
+ await requestConversationWork({
119
+ conversationId: request.conversationId,
120
+ destination: conversation && !isTopLevelKind(conversation.kind) ? void 0 : request.destination,
121
+ nowMs,
122
+ state: options.state
123
+ });
124
+ const queue = options.queue ?? getVercelConversationWorkQueue();
125
+ await ensureConversationWake({
126
+ conversationId: request.conversationId,
127
+ idempotencyKey: [
128
+ "agent-continue",
129
+ request.conversationId,
130
+ request.turnId,
131
+ request.expectedVersion,
132
+ nowMs
133
+ ].join(":"),
134
+ nowMs,
135
+ queue,
136
+ state: options.state
137
+ });
138
+ }
139
+ /** Create paused Turn operations for one app. */
140
+ function createPausedTurns(options = {}) {
141
+ return {
142
+ get: (args) => getPausedTurnRequest({
143
+ ...args,
144
+ conversationStore: options.conversationStore
145
+ }),
146
+ wake: (request) => wakePausedTurn(request, options)
147
+ };
148
+ }
149
+ /** Record completed authorization and wake the sole execution owner. */
150
+ async function wakeAuthorizedTurn(args, queue) {
151
+ const request = await recordTurnAuthorization(args);
152
+ if (request) await wakePausedTurn(request, { queue });
153
+ }
154
+ export { wakePausedTurn as a, wakeAuthorizedTurn as i, getPausedTurnRequest as n, getTurnAuthorization as o, recordFailedDispatchTurn as r, createPausedTurns as t };
@@ -0,0 +1,9 @@
1
+ import * as z from "zod";
2
+ // src/api/schema/user-customization.ts
3
+ /** Longest customization text one user can save. */
4
+ const USER_CUSTOMIZATION_MAX_CHARS = 1e3;
5
+ /** Saved customization text. An empty string means none. */
6
+ const userCustomizationTextSchema = z.string().trim().max(USER_CUSTOMIZATION_MAX_CHARS);
7
+ /** Request and response body for the viewer's customization. */
8
+ const userCustomizationSchema = z.object({ customization: userCustomizationTextSchema }).strict();
9
+ export { userCustomizationSchema as n, userCustomizationTextSchema as r, USER_CUSTOMIZATION_MAX_CHARS as t };
@@ -1,5 +1,5 @@
1
1
  import { t as __exportAll } from "./rolldown-runtime-BKpuH2hG.js";
2
- import { n as pluginCatalogRuntime } from "./catalog-runtime-D7xapBAX.js";
2
+ import { n as pluginCatalogRuntime } from "./catalog-runtime-BLKtnUL3.js";
3
3
  import { isDeepStrictEqual } from "node:util";
4
4
  // src/chat/plugins/validation.ts
5
5
  var validation_exports = /* @__PURE__ */ __exportAll({