@sentry/junior 0.316.0 → 0.318.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 (124) hide show
  1. package/dist/{admin-QYiDMnsu.js → admin-UOHix_5P.js} +1 -1
  2. package/dist/{agent-runner-Cr5Fhjf-.js → agent-runner-DeYymwh2.js} +13494 -13135
  3. package/dist/{reporting-window-C4dbzDiR.js → agent-status-BA5x3Xtp.js} +33 -1
  4. package/dist/{agent-update-delivery-BY13DPSD.js → agent-update-delivery-DH8bx7jU.js} +5 -5
  5. package/dist/api/schema.d.ts +600 -130
  6. package/dist/api/schema.js +6 -6
  7. package/dist/api.js +228 -214
  8. package/dist/{app-BhvzRD__.d.ts → app-DKAOuaoC.d.ts} +33 -18
  9. package/dist/app.d.ts +1 -1
  10. package/dist/app.js +193 -177
  11. package/dist/{thread-context-fiMNylbg.js → auth-pause-state-f9hJM_zO.js} +6 -59
  12. package/dist/catalog-runtime-BfdAnztW.js +6 -0
  13. package/dist/{change-record-Bqsa5ZXE.d.ts → change-record-BzJgLsv7.d.ts} +60 -1
  14. package/dist/{adapter-context-Bref7aPI.js → channel-access-A0de5lRv.js} +2 -42
  15. package/dist/{chat-core-engine-3dtlMku3.js → chat-core-engine-D3Wd7f5n.js} +6 -5
  16. package/dist/{child-message--2G3Ft26.js → child-message-peFWLcCZ.js} +2 -6
  17. package/dist/cli/chat.js +38 -30
  18. package/dist/cli/check.js +5 -5
  19. package/dist/cli/main.js +2 -2
  20. package/dist/cli/plugins.js +5 -4
  21. package/dist/cli/snapshot-create.js +4 -2
  22. package/dist/cli/upgrade.js +5 -3
  23. package/dist/context-BKF_5zzI.js +1833 -0
  24. package/dist/{continue-in-slack-DbQUFe_F.js → continue-in-slack-YxwMQVeR.js} +3 -3
  25. package/dist/{conversation-feed-B84pMjHo.js → conversation-feed-Cj7IuBtM.js} +3 -3
  26. package/dist/{proxy-path-BTmXDjfx.js → conversation-privacy-Cr_dNW1p.js} +2 -16
  27. package/dist/{conversation-turn-DzEpTIaf.js → conversation-turn-Bru4w_FD.js} +196 -80
  28. package/dist/{create-DUJBXr6E.js → create-Btl1y1rq.js} +12 -11
  29. package/dist/{credential-sync-JH_K9Adg.js → credential-sync-DTarZ63K.js} +20 -15
  30. package/dist/{db-DhzvUY23.js → db-of6e3sGt.js} +20724 -27256
  31. package/dist/{deployment-BhvrhQeh.js → deployment-C0qXa0FD.js} +17 -15
  32. package/dist/{engine-context-C9Nal48K.js → engine-context-C_QL_bMQ.js} +304 -56
  33. package/dist/{html-B_12WjKT.js → html-9_pS9SjY.js} +6 -2
  34. package/dist/instrumentation.js +15 -7
  35. package/dist/{job-runner-DO8nslyY.js → job-runner-B2XEvpif.js} +392 -26
  36. package/dist/{lineage-D3AZAJVe.js → lineage-nh4z9iQN.js} +1 -1
  37. package/dist/{list-B0zsb5Cp.js → list-HRP3TIRl.js} +238 -550
  38. package/dist/{logging-B8KEJegM.js → logging-BnOG0qz2.js} +4 -50
  39. package/dist/{session-stop-DponjDUZ.js → mailbox-turn-Byrry9o1.js} +4807 -7102
  40. package/dist/{list-mkB_GU8R.js → markers-CTTtJqYn.js} +171 -124
  41. package/dist/{message-B5fKDYzz.js → message-BRUuLgrY.js} +13 -24
  42. package/dist/{model-input-CuMWy37l.js → model-input-CFC62mf-.js} +3 -3
  43. package/dist/nitro.d.ts +1 -1
  44. package/dist/nitro.js +21 -7
  45. package/dist/{oauth-callback-server-B3Vvlydo.js → oauth-callback-server-CjnnUr4o.js} +2 -2
  46. package/dist/{oauth-relay-6ERrGPbA.js → oauth-relay-BvHFH0fV.js} +2 -2
  47. package/dist/{package-discovery-BI6T_RkD.js → package-discovery-DD9vencX.js} +1 -50
  48. package/dist/{plugins-BXMdNdyA.js → plugins-D_Ru4CWc.js} +1 -1
  49. package/dist/profile-iHw1uu32.js +4657 -0
  50. package/dist/{transcript-CCi7323k.js → prompt-DEkStuxG.js} +92 -98
  51. package/dist/proxy-path-BHYoKZdq.js +15 -0
  52. package/dist/registry-Cl7Labpe.js +3279 -0
  53. package/dist/reports-C1d9azyV.js +195 -0
  54. package/dist/{resolve-D5JVvv6A.js → resolve-DC6zBuDV.js} +9 -29
  55. package/dist/{result-CS_7mo8a.js → result-DxewDuXb.js} +27 -118
  56. package/dist/run-conversation-Cz2ubZK-.js +337 -0
  57. package/dist/{runner-BzAES5W3.js → runner-99YxVN_r.js} +10 -18
  58. package/dist/{sandbox-egress-signals-Dwhk2Q5F.js → sandbox-egress-signals-CgoX5CTI.js} +1 -1
  59. package/dist/{schema-z5-wA6N4.js → schema-BTojNBr5.js} +48 -86
  60. package/dist/sender-actors-77zTQbSG.js +84 -0
  61. package/dist/{service-account-D6AsAtc1.js → service-account-YDCPSByj.js} +3 -1
  62. package/dist/{skills-DgJ9GBPR.js → skills-CleC0Hze.js} +6 -5
  63. package/dist/{slack-conversation-unfurl-Dq71EkhM.js → slack-conversation-unfurl-BNQLC12R.js} +7 -6
  64. package/dist/{spawn-BJWpdwhQ.js → spawn-DuZfodPa.js} +5 -5
  65. package/dist/{system-prompt-table-iIgpmslr.js → system-prompt-table-Ci6Ck4gk.js} +88 -69
  66. package/dist/{task-runner-BJae4JwE.js → task-runner-BJ9Up3bG.js} +30 -53
  67. package/dist/topics-BoCkoPJJ.js +21 -0
  68. package/dist/turn-membership-VT7XZh-L.js +856 -0
  69. package/dist/{turn-wake-BjDW7x-5.js → turn-wake-C7HeLHAM.js} +3 -4
  70. package/dist/{media-BebquhET.js → types-DCzTAA63.js} +629 -593
  71. package/dist/user-customization-CvfuY9Eo.js +93 -0
  72. package/dist/users-Cb9c1k9q.js +181 -0
  73. package/dist/{validation-D5WmmmhX.js → validation-BiUmWPhy.js} +1 -1
  74. package/dist/{version-CBQoanXb.js → version-VEXiEcZu.js} +1 -1
  75. package/dist/version.js +1 -1
  76. package/dist/{worker-Cyb4kF17.js → worker-ChWYQdhm.js} +5 -4
  77. package/migrations/20261126025226_drop_agent_invocations/migration.sql +6 -0
  78. package/migrations/20261126025226_drop_agent_invocations/snapshot.json +9 -0
  79. package/migrations/20261126033000_space_conversations_lead_children/migration.sql +155 -0
  80. package/migrations/20261126033000_space_conversations_lead_children/snapshot.json +9 -0
  81. package/migrations/20261126144620_drop_user_message_time_index/migration.sql +1 -0
  82. package/migrations/20261126144620_drop_user_message_time_index/snapshot.json +38 -0
  83. package/migrations/20261126153100_inbox_item_subjects/migration.sql +140 -0
  84. package/migrations/20261126153100_inbox_item_subjects/snapshot.json +9 -0
  85. package/migrations/20261126153103_inbox_item_subjects_not_null/migration.sql +12 -0
  86. package/migrations/20261126153103_inbox_item_subjects_not_null/snapshot.json +9 -0
  87. package/migrations/20261126153105_inbox_item_subject_indexes/migration.sql +1 -0
  88. package/migrations/20261126153105_inbox_item_subject_indexes/snapshot.json +9 -0
  89. package/migrations/20261126153108_automation_run_conversation_index/migration.sql +1 -0
  90. package/migrations/20261126153108_automation_run_conversation_index/snapshot.json +9 -0
  91. package/migrations/20261126153159_inbox_item_subjects_schema/migration.sql +4 -0
  92. package/migrations/20261126153159_inbox_item_subjects_schema/snapshot.json +437 -0
  93. package/migrations/20261126153259_inbox_questions/migration.sql +76 -0
  94. package/migrations/20261126153259_inbox_questions/snapshot.json +9 -0
  95. package/migrations/20261126153301_inbox_questions_valid/migration.sql +3 -0
  96. package/migrations/20261126153301_inbox_questions_valid/snapshot.json +9 -0
  97. package/migrations/20261126153343_inbox_questions_schema/migration.sql +5 -0
  98. package/migrations/20261126153343_inbox_questions_schema/snapshot.json +407 -0
  99. package/migrations/20261126154025_inbox_item_owners/migration.sql +74 -0
  100. package/migrations/20261126154025_inbox_item_owners/snapshot.json +9 -0
  101. package/migrations/20261126154048_inbox_item_open_subject_key_index/migration.sql +1 -0
  102. package/migrations/20261126154048_inbox_item_open_subject_key_index/snapshot.json +9 -0
  103. package/migrations/20261126154051_drop_inbox_item_owner_indexes/migration.sql +7 -0
  104. package/migrations/20261126154051_drop_inbox_item_owner_indexes/snapshot.json +9 -0
  105. package/migrations/20261126154121_inbox_item_owners_schema/migration.sql +8 -0
  106. package/migrations/20261126154121_inbox_item_owners_schema/snapshot.json +311 -0
  107. package/migrations/20261126175601_conversation_event_turn/migration.sql +5 -0
  108. package/migrations/20261126175601_conversation_event_turn/snapshot.json +103 -0
  109. package/migrations/20261126175614_conversation_event_turn_index/migration.sql +1 -0
  110. package/migrations/20261126175614_conversation_event_turn_index/snapshot.json +62 -0
  111. package/migrations/20261126230028_merge_leaves/migration.sql +2 -0
  112. package/migrations/20261126230028_merge_leaves/snapshot.json +12 -0
  113. package/migrations/20261126231932_space_lead_holds_name/migration.sql +46 -0
  114. package/migrations/20261126231932_space_lead_holds_name/snapshot.json +58 -0
  115. package/migrations/20261127001022_merge_leaves/migration.sql +2 -0
  116. package/migrations/20261127001022_merge_leaves/snapshot.json +12 -0
  117. package/migrations/20261127002500_turn_discarded_usage/migration.sql +2 -0
  118. package/migrations/20261127002500_turn_discarded_usage/snapshot.json +73 -0
  119. package/package.json +5 -5
  120. package/dist/people-CUtFApfL.js +0 -81
  121. package/dist/start-conversation-B-LIqqNi.js +0 -162
  122. package/dist/turn-session-routing-D15orfwy.js +0 -1309
  123. package/dist/user-customization-B27StpVQ.js +0 -9
  124. package/dist/web-message-id-C6P83ans.js +0 -10
@@ -1,12 +1,12 @@
1
- import { Tu as juniorConversations, Wt as isPersonInput, cu as juniorAgentBindings, hu as juniorConversationEvents, i as getConversationStore, n as getConversationEventStore, o as getSqlExecutor, ws as conversationTurnFailedSql } from "./db-DhzvUY23.js";
2
- import { G as mapBounded } from "./transcript-CCi7323k.js";
3
- import { An as isAgentUpdateEventType } from "./media-BebquhET.js";
4
- import { E as readChildOfStoredParent, P as isPersonStopTurnId, Xt as getConversationWorkState, Zt as getConversationWorkStates, c as conversationSubtreeColumns, dn as isEventMailboxMetadata, et as buildDeterministicTurnId, f as listActiveMailboxTurnSources, gi as readInboundMessageSender, k as readAgentConfig, kr as EVENT_SYSTEM_ACTOR, n as getConversationStoppedAtMs, p as listActiveMailboxTurns, s as conversationSubtree, xi as readParentMessage } from "./session-stop-DponjDUZ.js";
1
+ import { Fn as readInboundMessageSender, In as isEventMailboxMetadata, Pn as readParentMessage, U as conversationLastTurnOutcomeSql, Zd as juniorAgentBindings, an as getConversationWorkState, cs as conversationSubtreeColumns, hf as juniorConversations, i as getConversationStore, if as juniorConversationEvents, jl as isPersonInput, n as getConversationEventStore, o as getSqlExecutor, on as getConversationWorkStates, ss as conversationSubtree } from "./db-of6e3sGt.js";
2
+ import { Hn as isAgentUpdateEventType } from "./types-DCzTAA63.js";
3
+ import { G as mapBounded } from "./prompt-DEkStuxG.js";
4
+ import { Er as TURN_OUTCOME_STATUSES, Vt as buildDeterministicTurnId, b as readAgentConfig, i as listActiveMailboxTurns, m as hasParentMessageAuthor, r as listActiveMailboxTurnSources } from "./mailbox-turn-Byrry9o1.js";
5
5
  import * as z from "zod";
6
- import pLimit from "p-limit";
7
6
  import { and, desc, eq, inArray, isNotNull, ne, sql } from "drizzle-orm";
8
7
  import { alias } from "drizzle-orm/pg-core";
9
- // src/chat/agent-invocations/child-input.ts
8
+ // src/chat/child-agents/child-input.ts
9
+ const parent = alias(juniorConversations, "parent");
10
10
  function childAgentInputKind(namespace, eventType, watchId) {
11
11
  if (namespace !== "junior" || !eventType) return;
12
12
  if (eventType === "agent.message") return "message";
@@ -23,6 +23,15 @@ function childAgentInput(message) {
23
23
  } : void 0;
24
24
  }
25
25
  /**
26
+ * Whether one input is the `stopped` result that the stop of its sender
27
+ * sends. Only a stop reports `stopped`, so the stored status tells this
28
+ * result from the reply of a Turn.
29
+ */
30
+ function isStopResult(message) {
31
+ const metadata = message.input.metadata;
32
+ return isEventMailboxMetadata(metadata) && metadata.event.namespace === "junior" && isAgentUpdateEventType(metadata.event.eventType) && metadata.event.status === "stopped";
33
+ }
34
+ /**
26
35
  * Whether the saved Event fields of a Turn's input Message name a child
27
36
  * agent's reply or message. A new and a resumed Turn read the same fields.
28
37
  */
@@ -30,38 +39,83 @@ function isChildAgentEvent(meta) {
30
39
  return Boolean(childAgentInputKind(meta?.eventNamespace, meta?.eventType, meta?.eventWatchId));
31
40
  }
32
41
  /**
42
+ * Return the stored parent edge that a parent message claims, or undefined
43
+ * when its author id is not that parent's, so it is dropped with no read.
44
+ */
45
+ function claimedParentEdge(message, parentMessage) {
46
+ return hasParentMessageAuthor(message, parentMessage) ? parentEdgeKey(message.conversationId, parentMessage.parentConversationId) : void 0;
47
+ }
48
+ function parentEdgeKey(childConversationId, parentConversationId) {
49
+ return JSON.stringify([childConversationId, parentConversationId]);
50
+ }
51
+ /**
52
+ * Return the child that sent a reply that a stop can skip. A message that a
53
+ * child sent is still delivered, and so is the `stopped` result that a
54
+ * person's stop sends.
55
+ */
56
+ function skippableReplySender(message) {
57
+ if (childAgentInput(message)?.kind !== "reply" || isStopResult(message)) return;
58
+ return readInboundMessageSender(message)?.conversationId;
59
+ }
60
+ /**
61
+ * Read the stops that `isDroppedChildInput` needs for many inputs, with one
62
+ * query for the receiving children and one for the reply senders.
63
+ */
64
+ async function readChildInputDropFacts(messages) {
65
+ const childIds = /* @__PURE__ */ new Set();
66
+ const parentIds = /* @__PURE__ */ new Set();
67
+ const senderIds = /* @__PURE__ */ new Set();
68
+ for (const message of messages) {
69
+ const parentMessage = readParentMessage(message);
70
+ if (parentMessage) {
71
+ if (claimedParentEdge(message, parentMessage)) {
72
+ childIds.add(message.conversationId);
73
+ parentIds.add(parentMessage.parentConversationId);
74
+ }
75
+ continue;
76
+ }
77
+ const sender = skippableReplySender(message);
78
+ if (sender) senderIds.add(sender);
79
+ }
80
+ const db = getSqlExecutor().db();
81
+ const [children, senders] = await Promise.all([childIds.size > 0 ? db.select({
82
+ conversationId: juniorConversations.conversationId,
83
+ parentConversationId: parent.conversationId,
84
+ stoppedAt: juniorConversations.stoppedAt
85
+ }).from(juniorConversations).innerJoin(parent, eq(parent.conversationId, juniorConversations.parentConversationId)).where(and(inArray(juniorConversations.conversationId, [...childIds]), inArray(parent.conversationId, [...parentIds]))) : [], senderIds.size > 0 ? db.select({
86
+ conversationId: juniorConversations.conversationId,
87
+ stoppedAt: juniorConversations.stoppedAt
88
+ }).from(juniorConversations).where(inArray(juniorConversations.conversationId, [...senderIds])) : []]);
89
+ return {
90
+ childStops: new Map(children.map((row) => [parentEdgeKey(row.conversationId, row.parentConversationId), row.stoppedAt])),
91
+ senderStops: new Map(senders.flatMap((row) => row.stoppedAt ? [[row.conversationId, row.stoppedAt]] : []))
92
+ };
93
+ }
94
+ /**
33
95
  * Return whether a Conversation drops one input, so it starts no work.
34
- * Routing, the stop skips, and the child agent status all read this, so they
35
- * agree on which input starts work.
96
+ * Routing and the child agent status both read this, so they agree on which
97
+ * input starts work. `facts` must come from `readChildInputDropFacts` for
98
+ * this input.
36
99
  *
37
100
  * A parent message is dropped when it does not come from the stored parent,
38
- * or when it was sent before the child's stop. A child reply that a stop
39
- * skips is dropped too. A stopped Conversation never reads other automated
40
- * input: `enqueueAutomatedInput` and the stop hold it first.
101
+ * or when it was sent before the child's stop. A stop drops a child's unread
102
+ * replies from the parent's mailbox. One sent before the stop can reach the
103
+ * mailbox after that drop, so while the sending child is stopped, a reply
104
+ * that it sent after the stop is dropped too. A stopped Conversation never
105
+ * reads other automated input: `enqueueAutomatedInput` and the stop hold it
106
+ * first.
41
107
  */
42
- async function isDroppedChildInput(message) {
108
+ function isDroppedChildInput(message, facts) {
43
109
  if (isPersonInput(message.source)) return false;
44
110
  const parentMessage = readParentMessage(message);
45
111
  if (parentMessage) {
46
- const child = await readChildOfStoredParent(message, parentMessage);
47
- if (!child) return true;
48
- const stoppedAtMs = child.stoppedAt?.getTime();
112
+ const edge = claimedParentEdge(message, parentMessage);
113
+ if (!edge || !facts.childStops.has(edge)) return true;
114
+ const stoppedAtMs = facts.childStops.get(edge)?.getTime();
49
115
  return stoppedAtMs !== void 0 && message.receivedAtMs <= stoppedAtMs;
50
116
  }
51
- return childAgentInput(message)?.kind === "reply" && await isSkippedReply(message);
52
- }
53
- /**
54
- * Return whether a stop skipped this reply. A stop drops a child's unread
55
- * replies from the parent's mailbox. One sent before the stop can reach the
56
- * mailbox after that drop, so while the sending child is stopped, a reply
57
- * that it sent after the stop is dropped too, except the `stopped` result
58
- * that a person's stop sends. A message that a child sent is still
59
- * delivered.
60
- */
61
- async function isSkippedReply(message) {
62
- const sender = readInboundMessageSender(message);
63
- if (!sender || isPersonStopTurnId(sender.turnId)) return false;
64
- const senderStoppedAtMs = await getConversationStoppedAtMs(sender.conversationId);
117
+ const sender = skippableReplySender(message);
118
+ const senderStoppedAtMs = sender ? facts.senderStops.get(sender)?.getTime() : void 0;
65
119
  return senderStoppedAtMs !== void 0 && message.createdAtMs >= senderStoppedAtMs;
66
120
  }
67
121
  /**
@@ -69,103 +123,31 @@ async function isSkippedReply(message) {
69
123
  * binding. A Conversation without a parent has none.
70
124
  */
71
125
  async function readChildConversationSender(childConversationId) {
72
- const parent = alias(juniorConversations, "parent");
73
126
  const [row] = await getSqlExecutor().db().select({
74
127
  agentName: juniorAgentBindings.name,
75
128
  parentConversationId: parent.conversationId,
129
+ parentKind: parent.kind,
76
130
  title: juniorConversations.title
77
131
  }).from(juniorConversations).innerJoin(parent, eq(parent.conversationId, juniorConversations.parentConversationId)).leftJoin(juniorAgentBindings, eq(juniorAgentBindings.childConversationId, juniorConversations.conversationId)).where(eq(juniorConversations.conversationId, childConversationId));
78
132
  return row ? {
79
133
  ...row.agentName ? { agentName: row.agentName } : void 0,
80
134
  childConversationId,
81
135
  parentConversationId: row.parentConversationId,
136
+ ...row.parentKind ? { parentKind: row.parentKind } : void 0,
82
137
  ...row.title ? { title: row.title } : void 0
83
138
  } : void 0;
84
139
  }
85
140
  /**
86
141
  * Read the sender of one reply or message, when it is a child of the
87
- * Conversation that received it. Otherwise the input has no child sender,
88
- * such as one that an Agent invocation of an earlier release sent.
142
+ * Conversation that received it. Input that names no child of this
143
+ * Conversation has no sender, so `withSenderActors` runs it as the Event
144
+ * system Actor and it gets no child's authority.
89
145
  */
90
146
  async function getChildAgentInputSender(message, input) {
91
147
  const sender = await readChildConversationSender(input.senderId);
92
148
  return sender?.parentConversationId === message.conversationId ? sender : void 0;
93
149
  }
94
- // src/chat/agent-invocations/markers.ts
95
- const SUBAGENT_KIND = "agent";
96
- const SUBAGENT_STARTED_KEY_PREFIX = "subagent_started:";
97
- const SUBAGENT_ENDED_KEY_PREFIX = "subagent_ended:";
98
- /**
99
- * Record in the parent Conversation that a child agent got one task or
100
- * message. Write it before the input reaches the child's mailbox, so the
101
- * child cannot end first.
102
- */
103
- async function recordSubagentStartedMarker(start) {
104
- await getConversationEventStore().append(start.parentConversationId, [{
105
- idempotencyKey: `${SUBAGENT_STARTED_KEY_PREFIX}${start.markerId}`,
106
- data: {
107
- type: "subagent_started",
108
- subagentInvocationId: start.markerId,
109
- subagentKind: SUBAGENT_KIND,
110
- childConversationId: start.childConversationId,
111
- ...start.agentName ? { agentName: start.agentName } : void 0,
112
- parentToolCallId: start.parentToolCallId,
113
- task: start.input,
114
- ...start.title ? { title: start.title } : void 0,
115
- ...start.reasoningLevel ? { reasoningLevel: start.reasoningLevel } : void 0
116
- },
117
- createdAtMs: start.createdAtMs
118
- }]);
119
- }
120
- /**
121
- * Record in the parent Conversation how the work of a child agent ended.
122
- * Each parent message has its own `subagent_started` marker, named by the
123
- * message id, and each one that the child already took ends with `outcome`.
124
- * A parent message that still waits in the child's mailbox stays open,
125
- * because later work reads it, unless `includeWaiting` is set, as for a stop
126
- * that skips it. Write it before the child's result reaches the parent.
127
- */
128
- async function recordChildAgentEnded(childConversationId, outcome, options = {}) {
129
- if (!await readAgentConfig(childConversationId)) return;
130
- const work = await getConversationWorkState({
131
- conversationId: childConversationId,
132
- state: options.state
133
- });
134
- const running = new Set(work?.runningInboundMessageIds);
135
- const waiting = new Set(options.includeWaiting ? [] : (work?.messages ?? []).map((message) => message.inboundMessageId).filter((id) => !running.has(id)));
136
- const taken = (work?.execution.inboundMessageIds ?? []).filter((id) => !waiting.has(id));
137
- if (taken.length === 0) return;
138
- const sender = await readChildConversationSender(childConversationId);
139
- if (!sender) return;
140
- const keys = await getSqlExecutor().db().select({ idempotencyKey: juniorConversationEvents.idempotencyKey }).from(juniorConversationEvents).where(and(eq(juniorConversationEvents.conversationId, sender.parentConversationId), inArray(juniorConversationEvents.idempotencyKey, taken.flatMap((id) => [`${SUBAGENT_STARTED_KEY_PREFIX}${id}`, `${SUBAGENT_ENDED_KEY_PREFIX}${id}`]))));
141
- const found = new Set(keys.map((row) => row.idempotencyKey));
142
- const open = taken.filter((id) => found.has(`${SUBAGENT_STARTED_KEY_PREFIX}${id}`) && !found.has(`${SUBAGENT_ENDED_KEY_PREFIX}${id}`));
143
- if (open.length > 0) await appendSubagentEnded(sender.parentConversationId, open, outcome, options.nowMs ?? Date.now());
144
- }
145
- async function appendSubagentEnded(parentConversationId, markerIds, outcome, createdAtMs) {
146
- await getConversationEventStore().append(parentConversationId, markerIds.map((id) => ({
147
- idempotencyKey: `${SUBAGENT_ENDED_KEY_PREFIX}${id}`,
148
- data: {
149
- type: "subagent_ended",
150
- subagentInvocationId: id,
151
- outcome
152
- },
153
- createdAtMs
154
- })));
155
- }
156
- // src/chat/agent-invocations/parent-result.ts
157
- /**
158
- * Return the Actor that a child Turn's update carries to its parent, whose
159
- * Turn for it runs as that Actor. Only a Turn that agent work started, a
160
- * parent message or an Event such as a child result, keeps its Actor. Any
161
- * other Turn, such as a person's Turn in a Thread or a saved Turn with no
162
- * Source, reports as the Event system Actor, so the parent never gets a
163
- * person's access.
164
- */
165
- function parentResultActor(actor, source) {
166
- return source === "parent_message" || source === "event" ? actor : EVENT_SYSTEM_ACTOR;
167
- }
168
- // src/chat/agent-invocations/list.ts
150
+ // src/chat/child-agents/list.ts
169
151
  const childConversationKindSchema = z.enum(["thread", "task"]);
170
152
  /** Bound the child agents that one listing reads. */
171
153
  const CHILD_AGENT_LIST_LIMIT = 200;
@@ -174,42 +156,47 @@ const CHILD_AGENT_LIST_LIMIT = 200;
174
156
  * activity first. The state comes from each child's Turns and mailbox, not
175
157
  * from model output. Each child agent stores its agent config, so older
176
158
  * children of a parent, such as ones that a removed feature created, are not
177
- * listed. A child is `running` while a Turn or mailbox input that answers its
178
- * parent is open, and is `failed` when its last Turn failed, also when the
179
- * Turn ended with a model error and execution went back to idle. Turns do
180
- * not store a blocked result, so only a failure sets `lastResult`.
159
+ * listed. A child is `stopped` while stopped, `running` while a Turn or
160
+ * mailbox input that answers its parent is open, `failed` when its stored
161
+ * execution failed, such as when its worker gave up and no Turn ended, and
162
+ * else `idle`.
163
+ * `lastResult` is how its newest finished Turn that was not stopped ended:
164
+ * the status that `readTurnUpdate` gives it, or `failed`.
181
165
  */
182
166
  async function listChildAgents(parentConversationId) {
183
167
  const rows = await getSqlExecutor().db().select({
184
168
  agentName: juniorAgentBindings.name,
185
169
  archivedAt: juniorConversations.archivedAt,
186
170
  conversationId: juniorConversations.conversationId,
171
+ executionStatus: juniorConversations.executionStatus,
187
172
  executionUpdatedAt: juniorConversations.executionUpdatedAt,
188
173
  kind: juniorConversations.kind,
174
+ lastTurnOutcome: conversationLastTurnOutcomeSql(juniorConversations),
189
175
  stoppedAt: juniorConversations.stoppedAt,
190
176
  title: juniorConversations.title,
191
- turnFailed: conversationTurnFailedSql(juniorConversations),
192
177
  updatedAt: juniorConversations.updatedAt
193
178
  }).from(juniorConversations).leftJoin(juniorAgentBindings, eq(juniorAgentBindings.childConversationId, juniorConversations.conversationId)).where(and(eq(juniorConversations.parentConversationId, parentConversationId), isNotNull(juniorConversations.agentConfig))).orderBy(desc(sql`coalesce(${juniorConversations.executionUpdatedAt}, ${juniorConversations.updatedAt})`)).limit(CHILD_AGENT_LIST_LIMIT);
194
179
  const ids = rows.map((row) => row.conversationId);
195
180
  const [workStates, mailboxTurnSources] = await Promise.all([getConversationWorkStates(ids), listActiveMailboxTurnSources(ids)]);
196
- const limit = pLimit(8);
197
- return (await Promise.all(rows.map(async (row) => {
181
+ const pendingInput = (conversationId) => workStates.get(conversationId)?.execution.pendingMessages ?? [];
182
+ const dropFacts = await readChildInputDropFacts(rows.flatMap((row) => row.stoppedAt ? [] : pendingInput(row.conversationId)));
183
+ return rows.map((row) => {
198
184
  const kind = childConversationKindSchema.parse(row.kind);
199
185
  const stoppedAtMs = row.stoppedAt?.getTime();
200
- const running = stoppedAtMs === void 0 && await limit(() => runsOnConversationLoop(workStates.get(row.conversationId)?.execution.pendingMessages ?? [], mailboxTurnSources.get(row.conversationId) ?? []));
186
+ const running = stoppedAtMs === void 0 && runsOnConversationLoop(pendingInput(row.conversationId), mailboxTurnSources.get(row.conversationId) ?? [], dropFacts);
187
+ const outcome = row.lastTurnOutcome;
188
+ const lastResult = outcome === "failed" ? "failed" : outcome ? TURN_OUTCOME_STATUSES[outcome] : void 0;
201
189
  return {
202
190
  ...row.agentName ? { agentName: row.agentName } : void 0,
203
191
  ...row.archivedAt ? { archivedAtMs: row.archivedAt.getTime() } : void 0,
204
192
  childConversationId: row.conversationId,
205
193
  kind,
206
- ...row.turnFailed && !running ? { lastResult: "failed" } : void 0,
207
- status: stoppedAtMs !== void 0 ? "stopped" : running ? "running" : row.turnFailed ? "failed" : "completed",
208
- task: row.title ?? "",
194
+ ...lastResult ? { lastResult } : void 0,
195
+ status: stoppedAtMs !== void 0 ? "stopped" : running ? "running" : row.executionStatus === "failed" ? "failed" : "idle",
209
196
  ...row.title ? { title: row.title } : void 0,
210
197
  updatedAtMs: (row.executionUpdatedAt ?? row.updatedAt).getTime()
211
198
  };
212
- }))).sort((left, right) => right.updatedAtMs - left.updatedAtMs);
199
+ }).sort((left, right) => right.updatedAtMs - left.updatedAtMs);
213
200
  }
214
201
  /** List the ids of the child agents of one parent that have open work. */
215
202
  async function listOpenChildAgents(parentConversationId) {
@@ -221,10 +208,8 @@ async function listOpenChildAgents(parentConversationId) {
221
208
  * Event in its debounce window, or an open mailbox Turn. Every Turn of a
222
209
  * child answers its parent, whoever started it.
223
210
  */
224
- async function runsOnConversationLoop(pending, mailboxTurnSources) {
225
- if (mailboxTurnSources.length > 0) return true;
226
- for (const message of pending) if (!await isDroppedChildInput(message)) return true;
227
- return false;
211
+ function runsOnConversationLoop(pending, mailboxTurnSources, dropFacts) {
212
+ return mailboxTurnSources.length > 0 || pending.some((message) => !isDroppedChildInput(message, dropFacts));
228
213
  }
229
214
  /**
230
215
  * List the ids of a child's open Turns on the Conversation loop. A Turn keeps
@@ -292,4 +277,66 @@ async function listAgentRelatives(input) {
292
277
  siblings: family.filter((agent) => agent.childConversationId !== conversationId)
293
278
  };
294
279
  }
295
- export { listUnreportedSiblingAgents as a, recordSubagentStartedMarker as c, isChildAgentEvent as d, isDroppedChildInput as f, listOpenChildAgents as i, childAgentInput as l, listChildAgents as n, parentResultActor as o, readChildConversationSender as p, listDescendantAgents as r, recordChildAgentEnded as s, listAgentRelatives as t, getChildAgentInputSender as u };
280
+ // src/chat/child-agents/markers.ts
281
+ const SUBAGENT_KIND = "agent";
282
+ const SUBAGENT_STARTED_KEY_PREFIX = "subagent_started:";
283
+ const SUBAGENT_ENDED_KEY_PREFIX = "subagent_ended:";
284
+ /**
285
+ * Record in the parent Conversation that a child agent got one task or
286
+ * message. Write it before the input reaches the child's mailbox, so the
287
+ * child cannot end first.
288
+ */
289
+ async function recordSubagentStartedMarker(start) {
290
+ await getConversationEventStore().append(start.parentConversationId, [{
291
+ idempotencyKey: `${SUBAGENT_STARTED_KEY_PREFIX}${start.markerId}`,
292
+ data: {
293
+ type: "subagent_started",
294
+ subagentInvocationId: start.markerId,
295
+ subagentKind: SUBAGENT_KIND,
296
+ childConversationId: start.childConversationId,
297
+ ...start.agentName ? { agentName: start.agentName } : void 0,
298
+ parentToolCallId: start.parentToolCallId,
299
+ task: start.input,
300
+ ...start.title ? { title: start.title } : void 0,
301
+ ...start.reasoningLevel ? { reasoningLevel: start.reasoningLevel } : void 0
302
+ },
303
+ createdAtMs: start.createdAtMs
304
+ }]);
305
+ }
306
+ /**
307
+ * Record in the parent Conversation how the work of a child agent ended.
308
+ * Each parent message has its own `subagent_started` marker, named by the
309
+ * message id, and each one that the child already took ends with `outcome`.
310
+ * A parent message that still waits in the child's mailbox stays open,
311
+ * because later work reads it, unless `includeWaiting` is set, as for a stop
312
+ * that skips it. Write it before the child's result reaches the parent.
313
+ */
314
+ async function recordChildAgentEnded(childConversationId, outcome, options = {}) {
315
+ if (!await readAgentConfig(childConversationId)) return;
316
+ const work = await getConversationWorkState({
317
+ conversationId: childConversationId,
318
+ state: options.state
319
+ });
320
+ const running = new Set(work?.runningInboundMessageIds);
321
+ const waiting = new Set(options.includeWaiting ? [] : (work?.messages ?? []).map((message) => message.inboundMessageId).filter((id) => !running.has(id)));
322
+ const taken = (work?.execution.inboundMessageIds ?? []).filter((id) => !waiting.has(id));
323
+ if (taken.length === 0) return;
324
+ const sender = await readChildConversationSender(childConversationId);
325
+ if (!sender) return;
326
+ const keys = await getSqlExecutor().db().select({ idempotencyKey: juniorConversationEvents.idempotencyKey }).from(juniorConversationEvents).where(and(eq(juniorConversationEvents.conversationId, sender.parentConversationId), inArray(juniorConversationEvents.idempotencyKey, taken.flatMap((id) => [`${SUBAGENT_STARTED_KEY_PREFIX}${id}`, `${SUBAGENT_ENDED_KEY_PREFIX}${id}`]))));
327
+ const found = new Set(keys.map((row) => row.idempotencyKey));
328
+ const open = taken.filter((id) => found.has(`${SUBAGENT_STARTED_KEY_PREFIX}${id}`) && !found.has(`${SUBAGENT_ENDED_KEY_PREFIX}${id}`));
329
+ if (open.length > 0) await appendSubagentEnded(sender.parentConversationId, open, outcome, options.nowMs ?? Date.now());
330
+ }
331
+ async function appendSubagentEnded(parentConversationId, markerIds, outcome, createdAtMs) {
332
+ await getConversationEventStore().append(parentConversationId, markerIds.map((id) => ({
333
+ idempotencyKey: `${SUBAGENT_ENDED_KEY_PREFIX}${id}`,
334
+ data: {
335
+ type: "subagent_ended",
336
+ subagentInvocationId: id,
337
+ outcome
338
+ },
339
+ createdAtMs
340
+ })));
341
+ }
342
+ export { listDescendantAgents as a, childAgentInput as c, isDroppedChildInput as d, isStopResult as f, listChildAgents as i, getChildAgentInputSender as l, readChildInputDropFacts as m, recordSubagentStartedMarker as n, listOpenChildAgents as o, readChildConversationSender as p, listAgentRelatives as r, listUnreportedSiblingAgents as s, recordChildAgentEnded as t, isChildAgentEvent as u };
@@ -1,23 +1,18 @@
1
1
  import { t as __exportAll } from "./rolldown-runtime-BKpuH2hG.js";
2
- import { Q as findChildAgentConversationId, R as actorFromRun, et as PARENT_AGENT_TARGET, it as AgentMessageTargetError } from "./agent-runner-Cr5Fhjf-.js";
3
- import { Tl as readConversationAccessFromSql, Wt as isPersonInput, a as getDb, i as getConversationStore, qc as readActorIdentity, sl as SYSTEM_IDENTITY_ID, vl as canAccessConversation } from "./db-DhzvUY23.js";
4
- import { p as readChildConversationSender } from "./list-mkB_GU8R.js";
5
- import { r as enqueueAgentMessageToParent } from "./result-CS_7mo8a.js";
6
- import { t as messageChildAgent } from "./create-DUJBXr6E.js";
7
- import { on as EVENT_WAIT_MS, t as enqueueAutomatedInput } from "./session-stop-DponjDUZ.js";
8
- import { H as renderDataTag } from "./transcript-CCi7323k.js";
9
- import { o as readLeadSpace } from "./turn-session-routing-D15orfwy.js";
10
- // src/chat/agent-invocations/top-level-message.ts
11
- const AGENT_MESSAGE_EVENT_NAMESPACE = "junior";
12
- /** Event type of a message from another top-level agent. */
13
- const TOP_LEVEL_AGENT_MESSAGE_EVENT_TYPE = "agent.top_level_message";
2
+ import { F as AgentMessageTargetError, b as actorFromRun } from "./agent-runner-DeYymwh2.js";
3
+ import { $s as SYSTEM_IDENTITY_ID, It as PARENT_AGENT_TARGET, Kl as CORE_EVENT_NAMESPACE, Nt as findChildAgentConversationId, _r as canAccessConversation, a as getDb, i as getConversationStore, wr as readConversationAccessFromSql } from "./db-of6e3sGt.js";
4
+ import { p as readChildConversationSender } from "./markers-CTTtJqYn.js";
5
+ import { n as enqueueAgentMessageToParent } from "./result-DxewDuXb.js";
6
+ import { t as messageChildAgent } from "./create-Btl1y1rq.js";
7
+ import { H as enqueueAutomatedInput, O as EVENT_WAIT_MS } from "./mailbox-turn-Byrry9o1.js";
8
+ import { H as renderDataTag } from "./prompt-DEkStuxG.js";
9
+ import { Bn as TOP_LEVEL_AGENT_MESSAGE_EVENT_TYPE } from "./types-DCzTAA63.js";
10
+ // src/chat/child-agents/top-level-message.ts
14
11
  /**
15
12
  * Check that a top-level agent can message another top-level agent under
16
13
  * `policies/conversation-access.md`. Public agents can message each other.
17
14
  * A private agent can message only agents at its own Destination, such as
18
- * another thread in the same private Slack channel, or in its own private
19
- * Space. A Space's Lead messages a root outside its Space only when the
20
- * member who asked is a Participant of that root.
15
+ * another thread in the same private Slack channel.
21
16
  * Every target that the sender cannot reach gets the same error, so the
22
17
  * error does not show that a private Conversation exists.
23
18
  */
@@ -35,12 +30,7 @@ async function requireTopLevelAgentAccess(args) {
35
30
  requester: sender,
36
31
  target: receiver
37
32
  })) throw notReachable;
38
- if (receiver.visibility === "public" && sender.visibility !== "public") throw new AgentMessageTargetError(`"${args.to}" is a public conversation and this conversation is private. A private conversation can message only conversations in its own channel, DM, or private Space`);
39
- const leadSpaceId = (await readLeadSpace(args.senderConversationId))?.id;
40
- if (leadSpaceId && target.spaceId !== leadSpaceId) {
41
- const person = args.askingActor ? (await readActorIdentity(args.askingActor))?.user : void 0;
42
- if (!(person ? (await readConversationAccessFromSql(getDb(), [args.to], person)).get(args.to) : void 0)?.isParticipant) throw new AgentMessageTargetError(`"${args.to}" is outside this Space. You can message a conversation outside this Space only for a member who takes part in it and asked for this Turn`);
43
- }
33
+ if (receiver.visibility === "public" && sender.visibility !== "public") throw new AgentMessageTargetError(`"${args.to}" is a public conversation and this conversation is private. A private conversation can message only conversations in its own channel or DM`);
44
34
  }
45
35
  function renderTopLevelMessageInput(args) {
46
36
  return renderDataTag("agent-message", {
@@ -66,7 +56,7 @@ async function enqueueTopLevelAgentMessage(args) {
66
56
  eventKey: inboundMessageId,
67
57
  eventType: TOP_LEVEL_AGENT_MESSAGE_EVENT_TYPE,
68
58
  identifier: args.senderConversationId,
69
- namespace: AGENT_MESSAGE_EVENT_NAMESPACE,
59
+ namespace: CORE_EVENT_NAMESPACE,
70
60
  trustedSummary: summary
71
61
  }
72
62
  };
@@ -93,7 +83,7 @@ async function enqueueTopLevelAgentMessage(args) {
93
83
  state: args.state
94
84
  });
95
85
  }
96
- // src/chat/agent-invocations/message.ts
86
+ // src/chat/child-agents/message.ts
97
87
  var message_exports = /* @__PURE__ */ __exportAll({ bindMessageAgent: () => bindMessageAgent });
98
88
  /**
99
89
  * Bind a Run's Actor and credentials to messages for its parent and child
@@ -129,7 +119,6 @@ function bindMessageAgent(run, options) {
129
119
  });
130
120
  if (!childConversationId) {
131
121
  await enqueueTopLevelAgentMessage({
132
- askingActor: isPersonInput(run.source.kind) ? actor : void 0,
133
122
  messageKey: `${run.turnId}:${call.toolCallId}`,
134
123
  queue,
135
124
  senderConversationId: run.conversationId,
@@ -1,7 +1,7 @@
1
1
  import { t as __exportAll } from "./rolldown-runtime-BKpuH2hG.js";
2
- import { o as getSqlExecutor } from "./db-DhzvUY23.js";
3
- import { i as isVisionImageMediaType, r as detectImageMediaType } from "./media-BebquhET.js";
4
- import { M as readLiveAttachment } from "./turn-session-routing-D15orfwy.js";
2
+ import { o as getSqlExecutor } from "./db-of6e3sGt.js";
3
+ import { o as detectImageMediaType, s as isVisionImageMediaType } from "./user-customization-CvfuY9Eo.js";
4
+ import { d as readLiveAttachment } from "./turn-membership-VT7XZh-L.js";
5
5
  import { escapeTagText, renderTag } from "@sentry/junior-plugin-api";
6
6
  // src/chat/attachments/model-input.ts
7
7
  var model_input_exports = /* @__PURE__ */ __exportAll({ loadInputAttachments: () => loadInputAttachments });
package/dist/nitro.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { n as JuniorPluginSet } from "./plugins-fBrz8PCV.js";
2
- import { r as JuniorDashboardOptions } from "./app-BhvzRD__.js";
2
+ import { r as JuniorDashboardOptions } from "./app-DKAOuaoC.js";
3
3
  import { withSentryConfig as withSentryConfig$1 } from "@sentry/nitro";
4
4
  type SentryNitroConfig = Parameters<typeof withSentryConfig$1>[0];
5
5
  type SentryNitroOptions = NonNullable<Parameters<typeof withSentryConfig$1>[1]>;
package/dist/nitro.js CHANGED
@@ -1,8 +1,9 @@
1
- import { _ as readQueueConfig, d as resolvePackageDir, f as BACKGROUND_COMPACTION_QUEUE_TOPIC, g as resolveConversationWorkQueueTopic, h as WORKSPACE_SNAPSHOT_JOB_QUEUE_TOPIC, m as PLUGIN_TASK_QUEUE_TOPIC, p as CACHE_WARMUP_QUEUE_TOPIC, t as discoverInstalledPluginPackageContent, u as isValidPackageName, v as resolveBotName } from "./package-discovery-BI6T_RkD.js";
1
+ import { a as WORKSPACE_SNAPSHOT_JOB_QUEUE_TOPIC, i as PLUGIN_TASK_QUEUE_TOPIC, n as CACHE_WARMUP_QUEUE_TOPIC, o as toOptionalTrimmed, t as BACKGROUND_COMPACTION_QUEUE_TOPIC } from "./topics-BoCkoPJJ.js";
2
2
  import { t as startLocalVercelQueueServer } from "./local-server-CpnGhYml.js";
3
3
  import { n as TURN_STEP_TOPIC, t as DELIVERY_TOPIC } from "./topic-CRYYBYp-.js";
4
- import { _ as getDeploymentServiceVersion, a as JUNIOR_CONVERSATION_WORK_CALLBACK_ROUTE, c as JUNIOR_HEARTBEAT_ROUTE, d as JUNIOR_RETENTION_ROUTE, f as JUNIOR_TURN_STEP_CALLBACK_ROUTE, i as JUNIOR_CONTEXT_COMPACTION_CALLBACK_ROUTE, l as JUNIOR_PLUGIN_TASK_CALLBACK_ROUTE, n as JUNIOR_AUTO_ARCHIVE_ROUTE, o as JUNIOR_DELIVERY_CALLBACK_ROUTE, p as JUNIOR_WORKSPACE_SNAPSHOT_JOB_CALLBACK_ROUTE, r as JUNIOR_CACHE_WARMUP_CALLBACK_ROUTE, s as JUNIOR_HEARTBEAT_CRON_SCHEDULE, t as JUNIOR_AUTO_ARCHIVE_CRON_SCHEDULE, u as JUNIOR_RETENTION_CRON_SCHEDULE } from "./deployment-BhvrhQeh.js";
5
- import { a as pluginRuntimeRegistrationsFromPluginSet, r as pluginCatalogConfigFromPluginSet } from "./plugins-BXMdNdyA.js";
4
+ import { a as JUNIOR_CONVERSATION_WORK_CALLBACK_ROUTE, c as JUNIOR_HEARTBEAT_ROUTE, d as JUNIOR_RETENTION_ROUTE, f as JUNIOR_TURN_STEP_CALLBACK_ROUTE, g as getDeploymentServiceVersion, i as JUNIOR_CONTEXT_COMPACTION_CALLBACK_ROUTE, l as JUNIOR_PLUGIN_TASK_CALLBACK_ROUTE, n as JUNIOR_AUTO_ARCHIVE_ROUTE, o as JUNIOR_DELIVERY_CALLBACK_ROUTE, p as JUNIOR_WORKSPACE_SNAPSHOT_JOB_CALLBACK_ROUTE, r as JUNIOR_CACHE_WARMUP_CALLBACK_ROUTE, s as JUNIOR_HEARTBEAT_CRON_SCHEDULE, t as JUNIOR_AUTO_ARCHIVE_CRON_SCHEDULE, u as JUNIOR_RETENTION_CRON_SCHEDULE } from "./deployment-C0qXa0FD.js";
5
+ import { d as resolvePackageDir, t as discoverInstalledPluginPackageContent, u as isValidPackageName } from "./package-discovery-DD9vencX.js";
6
+ import { a as pluginRuntimeRegistrationsFromPluginSet, r as pluginCatalogConfigFromPluginSet } from "./plugins-D_Ru4CWc.js";
6
7
  import { n as loadPluginSetFromModule, r as resolvePluginModule } from "./plugin-module-Cv2ETe8Y.js";
7
8
  import path from "node:path";
8
9
  import { cpSync, existsSync, mkdirSync, readdirSync, statSync } from "node:fs";
@@ -17,7 +18,7 @@ function queueCallbackRoutes() {
17
18
  return [
18
19
  {
19
20
  route: JUNIOR_CONVERSATION_WORK_CALLBACK_ROUTE,
20
- topic: resolveConversationWorkQueueTopic()
21
+ topic: process.env["JUNIOR_CONVERSATION_WORK_QUEUE_TOPIC"]?.trim() || "junior_conversation_work"
21
22
  },
22
23
  {
23
24
  route: JUNIOR_PLUGIN_TASK_CALLBACK_ROUTE,
@@ -58,7 +59,7 @@ const LOCAL_CONSUMER_GROUP = "local";
58
59
  * server.
59
60
  */
60
61
  async function startDevQueue(nitro) {
61
- if (readQueueConfig(process.env).apiUrl) return;
62
+ if (toOptionalTrimmed(process.env["JUNIOR_QUEUE_API_URL"])) return;
62
63
  const appUrl = `http://localhost:${nitro.options.devServer.port ?? (process.env["PORT"]?.trim() || 3e3)}`;
63
64
  const server = await startLocalVercelQueueServer({ consumers: queueCallbackRoutes().map(({ route, topic }) => ({
64
65
  consumerGroup: LOCAL_CONSUMER_GROUP,
@@ -252,11 +253,24 @@ function injectVirtualConfig(nitro, options) {
252
253
  */
253
254
  function injectVirtualSystemPrompts(nitro, options) {
254
255
  nitro.options.virtual["#junior/system-prompts"] = async () => {
255
- const { buildSystemPromptTable } = await import("./system-prompt-table-iIgpmslr.js").then((n) => n.r);
256
+ const { buildSystemPromptTable } = await import("./system-prompt-table-Ci6Ck4gk.js").then((n) => n.r);
256
257
  const table = await buildSystemPromptTable(await options.loadPlugins(), options.botName);
257
258
  return `export const systemPrompts = ${JSON.stringify(table)};`;
258
259
  };
259
260
  }
261
+ // src/chat/bot-name.ts
262
+ /**
263
+ * Resolve the name Junior uses for itself: `name`, then `JUNIOR_BOT_NAME`,
264
+ * then `junior`. A build passes `juniorNitro({ botName })` as `name`.
265
+ */
266
+ function resolveBotName(name, env) {
267
+ if (name !== void 0) {
268
+ const trimmed = toOptionalTrimmed(name);
269
+ if (!trimmed) throw new Error("botName must not be empty");
270
+ return trimmed;
271
+ }
272
+ return toOptionalTrimmed(env["JUNIOR_BOT_NAME"]) ?? "junior";
273
+ }
260
274
  // src/nitro.ts
261
275
  /**
262
276
  * Sentry's Nitro config wrapper: source map upload and Nitro request hooks.
@@ -272,7 +286,7 @@ function withSentryConfig(config, options = {}) {
272
286
  return withSentryConfig$1(config, {
273
287
  ...options,
274
288
  release: {
275
- name: getDeploymentServiceVersion(),
289
+ name: getDeploymentServiceVersion(process.env),
276
290
  ...options.release
277
291
  }
278
292
  });
@@ -1,5 +1,5 @@
1
- import { a as GET, n as syncLocalOAuthCredential, r as GET$1 } from "./credential-sync-JH_K9Adg.js";
2
- import { wr as createUserTokenStore } from "./db-DhzvUY23.js";
1
+ import { a as GET, n as syncLocalOAuthCredential, r as GET$1 } from "./credential-sync-DTarZ63K.js";
2
+ import { A as createUserTokenStore } from "./profile-iHw1uu32.js";
3
3
  import { createServer } from "node:http";
4
4
  // src/chat/local/oauth-callback-server.ts
5
5
  const LOCAL_OAUTH_TIMEOUT_MS = 6e5;
@@ -1,5 +1,5 @@
1
1
  import { t as __exportAll } from "./rolldown-runtime-BKpuH2hG.js";
2
- import { vd as readJuniorSecret } from "./db-DhzvUY23.js";
2
+ import { R as getChatConfig } from "./context-BKF_5zzI.js";
3
3
  import * as z from "zod";
4
4
  import { randomBytes } from "node:crypto";
5
5
  import { SignJWT, jwtVerify } from "jose";
@@ -17,7 +17,7 @@ const localOAuthRelayPayloadSchema = z.object({
17
17
  }).strict();
18
18
  /** Derive the HMAC key used only for signed local OAuth relay state. */
19
19
  function relayKey() {
20
- const secret = readJuniorSecret();
20
+ const secret = getChatConfig().secrets.juniorSecret;
21
21
  if (!secret) throw new Error("Local OAuth requires JUNIOR_SECRET");
22
22
  return new TextEncoder().encode(secret);
23
23
  }
@@ -3,55 +3,6 @@ import { createRequire } from "node:module";
3
3
  import path from "node:path";
4
4
  import fs, { statSync } from "node:fs";
5
5
  import { fileURLToPath } from "node:url";
6
- // src/chat/optional-string.ts
7
- /**
8
- * Normalize optional env-style strings so blank values do not masquerade as
9
- * configured inputs.
10
- */
11
- function toOptionalTrimmed(value) {
12
- if (!value) return;
13
- const trimmed = value.trim();
14
- return trimmed.length > 0 ? trimmed : void 0;
15
- }
16
- // src/chat/bot-name.ts
17
- /**
18
- * Resolve the name Junior uses for itself: `name`, then `JUNIOR_BOT_NAME`,
19
- * then `junior`. A build passes `juniorNitro({ botName })` as `name`.
20
- */
21
- function resolveBotName(name, env) {
22
- if (name !== void 0) {
23
- const trimmed = toOptionalTrimmed(name);
24
- if (!trimmed) throw new Error("botName must not be empty");
25
- return trimmed;
26
- }
27
- return toOptionalTrimmed(env["JUNIOR_BOT_NAME"]) ?? "junior";
28
- }
29
- // src/chat/queue/config.ts
30
- function readApiUrl(value) {
31
- const raw = toOptionalTrimmed(value);
32
- if (raw === void 0) return;
33
- const protocol = URL.parse(raw)?.protocol;
34
- if (protocol !== "http:" && protocol !== "https:") throw new Error("JUNIOR_QUEUE_API_URL must be an http or https URL");
35
- return raw;
36
- }
37
- /** Read queue settings from environment variables. */
38
- function readQueueConfig(env) {
39
- const apiUrl = readApiUrl(env["JUNIOR_QUEUE_API_URL"]);
40
- return apiUrl ? { apiUrl } : {};
41
- }
42
- // src/chat/queue/topics.ts
43
- /**
44
- * Queue topic names. Vercel queue wiring uses them at build, so keep them
45
- * stable, and keep this module free of runtime configuration.
46
- */
47
- const CACHE_WARMUP_QUEUE_TOPIC = "junior_cache_warmups";
48
- const PLUGIN_TASK_QUEUE_TOPIC = "junior_plugin_tasks";
49
- const WORKSPACE_SNAPSHOT_JOB_QUEUE_TOPIC = "junior_workspace_snapshots";
50
- const BACKGROUND_COMPACTION_QUEUE_TOPIC = "junior_context_compaction";
51
- /** Resolve the Vercel Queue topic used for conversation wake-up nudges. */
52
- function resolveConversationWorkQueueTopic(options = {}) {
53
- return options.topic?.trim() || process.env["JUNIOR_CONVERSATION_WORK_QUEUE_TOPIC"]?.trim() || "junior_conversation_work";
54
- }
55
6
  // src/package-resolution.ts
56
7
  function isDirectory$1(targetPath) {
57
8
  try {
@@ -496,4 +447,4 @@ function discoverInstalledPluginPackageContent(cwd = process.cwd(), options) {
496
447
  tracingIncludes: uniqueStringsInOrder(tracingIncludes)
497
448
  };
498
449
  }
499
- export { readQueueConfig as _, listReferenceFiles as a, soulPathCandidates as c, resolvePackageDir as d, BACKGROUND_COMPACTION_QUEUE_TOPIC as f, resolveConversationWorkQueueTopic as g, WORKSPACE_SNAPSHOT_JOB_QUEUE_TOPIC as h, homeDir as i, worldPathCandidates as l, PLUGIN_TASK_QUEUE_TOPIC as m, normalizePluginPackageNames as n, pluginRoots as o, CACHE_WARMUP_QUEUE_TOPIC as p, discovery_exports as r, skillRoots as s, discoverInstalledPluginPackageContent as t, isValidPackageName as u, resolveBotName as v, toOptionalTrimmed as y };
450
+ export { listReferenceFiles as a, soulPathCandidates as c, resolvePackageDir as d, homeDir as i, worldPathCandidates as l, normalizePluginPackageNames as n, pluginRoots as o, discovery_exports as r, skillRoots as s, discoverInstalledPluginPackageContent as t, isValidPackageName as u };