@sentry/junior 0.147.0 → 0.148.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 (155) hide show
  1. package/dist/{agent-hooks-HS6VGUPM.js → agent-hooks-VAUYT6PD.js} +10 -10
  2. package/dist/api/conversations/access.d.ts +2 -1
  3. package/dist/api/conversations/archive.d.ts +3 -5
  4. package/dist/api/conversations/create.d.ts +6 -0
  5. package/dist/api/conversations/detail.d.ts +2 -296
  6. package/dist/api/conversations/event-list.d.ts +2 -193
  7. package/dist/api/conversations/list.d.ts +4 -66
  8. package/dist/api/conversations/routes.d.ts +1 -1
  9. package/dist/api/conversations/stats.d.ts +0 -54
  10. package/dist/api/http.d.ts +2 -6
  11. package/dist/api/locations/detail.d.ts +3 -111
  12. package/dist/api/locations/list.d.ts +0 -45
  13. package/dist/api/locations/query.d.ts +2 -1
  14. package/dist/api/locations/routes.d.ts +1 -1
  15. package/dist/api/people/list.d.ts +0 -29
  16. package/dist/api/people/profile.d.ts +2 -106
  17. package/dist/api/people/profile.query.d.ts +2 -1
  18. package/dist/api/people/routes.d.ts +1 -1
  19. package/dist/api/people/shared.d.ts +1 -1
  20. package/dist/api/people/spend.d.ts +3 -4
  21. package/dist/api/personal-tokens/routes.d.ts +2 -2
  22. package/dist/api/route.d.ts +8 -14
  23. package/dist/api/schema/conversation.d.ts +60 -29
  24. package/dist/api/schema/location.d.ts +4 -0
  25. package/dist/api/schema/person.d.ts +7 -3
  26. package/dist/api/schema.d.ts +2 -2
  27. package/dist/api/schema.js +7 -1
  28. package/dist/api/stats.d.ts +0 -13
  29. package/dist/api/validation.d.ts +7 -0
  30. package/dist/api/viewer.d.ts +3 -0
  31. package/dist/api.d.ts +2 -1
  32. package/dist/api.js +624 -562
  33. package/dist/app.js +183 -105
  34. package/dist/{catalog-runtime-M6ZTPYRV.js → catalog-runtime-WADOZVTB.js} +5 -5
  35. package/dist/chat/actor.d.ts +4 -1
  36. package/dist/chat/agent/request.d.ts +2 -0
  37. package/dist/chat/agent/resume.d.ts +1 -0
  38. package/dist/chat/agent-dispatch/context.d.ts +2 -2
  39. package/dist/chat/agent-invocations/types.d.ts +52 -0
  40. package/dist/chat/api-turns/work.d.ts +103 -0
  41. package/dist/chat/conversations/history.d.ts +60 -0
  42. package/dist/chat/conversations/provenance.d.ts +6 -0
  43. package/dist/chat/conversations/sql/actor-identity.d.ts +19 -0
  44. package/dist/chat/conversations/store.d.ts +1 -1
  45. package/dist/chat/resource-events/store.d.ts +1 -1
  46. package/dist/chat/runtime/reply-executor.d.ts +1 -1
  47. package/dist/chat/runtime/slack-runtime.d.ts +2 -1
  48. package/dist/chat/runtime/turn-preparation.d.ts +9 -0
  49. package/dist/chat/scheduled-tasks/tool-support.d.ts +5 -5
  50. package/dist/chat/scheduled-tasks/tools/create.d.ts +2 -2
  51. package/dist/chat/scheduled-tasks/tools/delete.d.ts +2 -2
  52. package/dist/chat/scheduled-tasks/tools/list.d.ts +2 -2
  53. package/dist/chat/scheduled-tasks/tools/run-now.d.ts +2 -2
  54. package/dist/chat/scheduled-tasks/tools/update.d.ts +2 -2
  55. package/dist/chat/slack/channel.d.ts +26 -0
  56. package/dist/chat/slack/dispatch-turn.d.ts +1 -0
  57. package/dist/chat/slack/timestamp-param.d.ts +0 -2
  58. package/dist/chat/slack/{tools → tool-support}/canvas/api.d.ts +1 -1
  59. package/dist/chat/slack/{tools → tool-support}/canvas/context.d.ts +3 -0
  60. package/dist/chat/slack/tool-support/channel-access.d.ts +42 -0
  61. package/dist/chat/slack/tool-support/channel-target.d.ts +27 -0
  62. package/dist/chat/slack/tool-support/list/params.d.ts +5 -0
  63. package/dist/chat/slack/tools/canvas/create.d.ts +1 -1
  64. package/dist/chat/slack/tools/channel-join.d.ts +28 -0
  65. package/dist/chat/slack/tools/channel-list-messages.d.ts +3 -2
  66. package/dist/chat/slack/tools/conversation-message-search.d.ts +2 -8
  67. package/dist/chat/slack/tools/message-add-reaction.d.ts +1 -1
  68. package/dist/chat/slack/tools/public-search.d.ts +63 -2
  69. package/dist/chat/slack/tools/send-files.d.ts +1 -1
  70. package/dist/chat/slack/tools/thread-read.d.ts +2 -5
  71. package/dist/chat/source.d.ts +2 -0
  72. package/dist/chat/task-execution/checkpoint.d.ts +1 -0
  73. package/dist/chat/task-execution/state.d.ts +9 -4
  74. package/dist/chat/task-execution/store.d.ts +3 -2
  75. package/dist/chat/task-execution/turn-cursor.d.ts +2 -0
  76. package/dist/chat/task-execution/worker.d.ts +2 -0
  77. package/dist/chat/tasks/read.d.ts +1 -1
  78. package/dist/chat/tools/search-conversation-events.d.ts +1 -1
  79. package/dist/chat/tools/types.d.ts +11 -4
  80. package/dist/chat/tools/watch-resource-events.d.ts +2 -2
  81. package/dist/{chunk-ORO3PWKQ.js → chunk-2B3PT3V2.js} +1 -1
  82. package/dist/{chunk-SVHUEHUL.js → chunk-45LOR4PU.js} +21 -4
  83. package/dist/{chunk-YBVXBNSV.js → chunk-4AQZYNHM.js} +2 -2
  84. package/dist/{chunk-Z4YU7Z4L.js → chunk-4EA2SFK2.js} +65 -4
  85. package/dist/{chunk-7NVJVJID.js → chunk-4GXJUYJV.js} +2 -2
  86. package/dist/{chunk-IIOOO4FQ.js → chunk-55F4QU2V.js} +2 -1
  87. package/dist/{chunk-745QJ3ZA.js → chunk-7OEIXFC3.js} +2 -2
  88. package/dist/{chunk-DU74WPIC.js → chunk-D3WPMGEX.js} +1 -1
  89. package/dist/{chunk-PVNG6UMU.js → chunk-D6YX4NNN.js} +22 -10
  90. package/dist/chunk-DUY5CDAM.js +36 -0
  91. package/dist/{chunk-4LJO56OJ.js → chunk-EAI67NTM.js} +1 -1
  92. package/dist/{chunk-X5UY34KT.js → chunk-EINWQFXI.js} +8 -8
  93. package/dist/chunk-GDFF3BQG.js +136 -0
  94. package/dist/{chunk-EFLJ2WJH.js → chunk-GXYDVZKM.js} +5 -5
  95. package/dist/{chunk-CWP5RHVX.js → chunk-HLPLT3NY.js} +8 -5
  96. package/dist/{chunk-JUUKWRBE.js → chunk-HWQGBIH7.js} +1 -1
  97. package/dist/{chunk-AZ7EAOBE.js → chunk-IL4EDBMV.js} +5 -5
  98. package/dist/{chunk-DLDRQHG5.js → chunk-LAZGHEYU.js} +1 -1
  99. package/dist/{chunk-RXBVB2JM.js → chunk-LE5H7LMT.js} +1 -1
  100. package/dist/chunk-LNVEIJ2L.js +48 -0
  101. package/dist/{chunk-YEO3VX72.js → chunk-OJCP3C3J.js} +8 -6
  102. package/dist/{chunk-GGB4WL5A.js → chunk-POSZWRGL.js} +1 -1
  103. package/dist/{chunk-YNTTROJT.js → chunk-QOWHHM3F.js} +1 -1
  104. package/dist/{chunk-6H5SZR24.js → chunk-RRJV5UR5.js} +302 -59
  105. package/dist/{chunk-AYU72WO7.js → chunk-ULAU5ZGU.js} +41 -64
  106. package/dist/{chunk-SGZO7UWH.js → chunk-V2FXMOEA.js} +2 -2
  107. package/dist/{chunk-AIOK6LAG.js → chunk-VCYSOXON.js} +272 -41
  108. package/dist/{chunk-7A4M7PCV.js → chunk-VMNRXKAH.js} +1166 -540
  109. package/dist/{chunk-YSB2N563.js → chunk-VRHTNBA6.js} +121 -87
  110. package/dist/{chunk-AVZDSUFB.js → chunk-VY6W3T43.js} +4 -4
  111. package/dist/{chunk-7UQIVT6G.js → chunk-WCN4YSH7.js} +6 -6
  112. package/dist/{chunk-CSZINQJ2.js → chunk-WOONT5ZP.js} +1 -1
  113. package/dist/{chunk-Q4R73I43.js → chunk-XJ42NBP5.js} +58 -28
  114. package/dist/{chunk-YHDERDRO.js → chunk-ZCHIC2GM.js} +91 -75
  115. package/dist/chunk-ZPL2RR7F.js +798 -0
  116. package/dist/cli/chat.js +33 -35
  117. package/dist/cli/check.js +6 -6
  118. package/dist/cli/plugins.js +13 -13
  119. package/dist/cli/snapshot-create.js +9 -9
  120. package/dist/cli/upgrade.js +7 -7
  121. package/dist/db/schema/agent-invocations.d.ts +20 -0
  122. package/dist/db/schema/conversation-annotations.d.ts +2 -2
  123. package/dist/db/schema.d.ts +22 -2
  124. package/dist/{db-CSEW4RII.js → db-XUKZRFFK.js} +7 -7
  125. package/dist/instrumentation.js +4 -4
  126. package/dist/nitro.js +2 -2
  127. package/dist/{oauth-callback-server-FUEV5HNG.js → oauth-callback-server-LPZMMGFI.js} +25 -26
  128. package/dist/{runner-U3XHSKSH.js → runner-DGKUTMPX.js} +17 -18
  129. package/dist/{skills-AKE6W3WI.js → skills-P7YUFSXM.js} +6 -6
  130. package/dist/spawn-DSK3ZEVD.js +38 -0
  131. package/dist/{validation-WDTAULUF.js → validation-S7U5M5NR.js} +6 -6
  132. package/dist/version.js +1 -1
  133. package/dist/{work-C3HAO2BG.js → work-GAA7TVAD.js} +18 -19
  134. package/dist/{worker-LNP4YKBM.js → worker-JXPJH3QB.js} +11 -10
  135. package/package.json +5 -4
  136. package/dist/api/health.d.ts +0 -7
  137. package/dist/api/personal-tokens/create.d.ts +0 -11
  138. package/dist/api/personal-tokens/list.d.ts +0 -12
  139. package/dist/api/personal-tokens/revoke.d.ts +0 -5
  140. package/dist/api/plugin-reports.d.ts +0 -63
  141. package/dist/api/plugins.d.ts +0 -8
  142. package/dist/api/runtime.d.ts +0 -24
  143. package/dist/api/skills.d.ts +0 -6
  144. package/dist/chat/slack/tools/channel-access.d.ts +0 -30
  145. package/dist/chunk-34GS7B6L.js +0 -115
  146. package/dist/chunk-AVOCH2Z5.js +0 -285
  147. package/dist/chunk-HLXXQI5Q.js +0 -238
  148. package/dist/chunk-K4SZAP3K.js +0 -67
  149. package/dist/chunk-R776HKPK.js +0 -81
  150. package/dist/spawn-B6GDTWJ4.js +0 -39
  151. /package/dist/chat/slack/{tools → tool-support}/canvas/markdown.d.ts +0 -0
  152. /package/dist/chat/slack/{tools → tool-support}/channel-capabilities.d.ts +0 -0
  153. /package/dist/chat/slack/{tools → tool-support}/context.d.ts +0 -0
  154. /package/dist/chat/slack/{tools → tool-support}/list/api.d.ts +0 -0
  155. /package/dist/chat/slack/{tools → tool-support}/slack-message-url.d.ts +0 -0
@@ -1,9 +1,10 @@
1
1
  import {
2
- botConfig
3
- } from "./chunk-7NVJVJID.js";
2
+ botConfig,
3
+ resolveGatewayModel
4
+ } from "./chunk-4GXJUYJV.js";
4
5
  import {
5
6
  logWarn
6
- } from "./chunk-4LJO56OJ.js";
7
+ } from "./chunk-EAI67NTM.js";
7
8
 
8
9
  // src/chat/services/short-title.ts
9
10
  var SHORT_TITLE_MAX_LENGTH = 60;
@@ -68,9 +69,69 @@ async function resolveTaskTitle(args) {
68
69
  });
69
70
  }
70
71
 
72
+ // src/chat/services/context-budget.ts
73
+ var COMPACTION_TRIGGER_RATIO = 0.9;
74
+ var CONTEXT_INPUT_LIMIT_RATIO = 0.95;
75
+ var COMPACTION_TARGET_RATIO = 0.8;
76
+ var FALLBACK_CONTEXT_WINDOW_TOKENS = 4e5;
77
+ function positiveInteger(value, fallback) {
78
+ return Number.isFinite(value) && value > 0 ? Math.floor(value) : fallback;
79
+ }
80
+ function estimateTextTokens(text) {
81
+ return Math.ceil(text.length / 4);
82
+ }
83
+ function calculateContextCompactionTriggerTokens(model) {
84
+ const contextWindow = positiveInteger(
85
+ model.contextWindow,
86
+ FALLBACK_CONTEXT_WINDOW_TOKENS
87
+ );
88
+ return Math.max(1, Math.floor(contextWindow * COMPACTION_TRIGGER_RATIO));
89
+ }
90
+ function calculateContextInputLimitTokens(model) {
91
+ const contextWindow = positiveInteger(
92
+ model.contextWindow,
93
+ FALLBACK_CONTEXT_WINDOW_TOKENS
94
+ );
95
+ return Math.max(1, Math.floor(contextWindow * CONTEXT_INPUT_LIMIT_RATIO));
96
+ }
97
+ function calculateContextCompactionTargetTokens(triggerTokens) {
98
+ return Math.max(1, Math.floor(triggerTokens * COMPACTION_TARGET_RATIO));
99
+ }
100
+ function getModelContextBudget(modelId) {
101
+ const model = resolveGatewayModel(modelId);
102
+ const advertisedContextWindow = positiveInteger(
103
+ model.contextWindow,
104
+ FALLBACK_CONTEXT_WINDOW_TOKENS
105
+ );
106
+ return {
107
+ contextWindow: Math.min(
108
+ botConfig.contextWindowTokens,
109
+ advertisedContextWindow
110
+ )
111
+ };
112
+ }
113
+ function getAgentContextCompactionTriggerTokens(modelId) {
114
+ return calculateContextCompactionTriggerTokens(
115
+ getModelContextBudget(modelId)
116
+ );
117
+ }
118
+ function getAgentContextInputLimitTokens(modelId) {
119
+ return calculateContextInputLimitTokens(getModelContextBudget(modelId));
120
+ }
121
+ function getConversationContextCompactionTriggerTokens() {
122
+ return calculateContextCompactionTriggerTokens(
123
+ getModelContextBudget(botConfig.fastModelId)
124
+ );
125
+ }
126
+
71
127
  export {
72
128
  SHORT_TITLE_MAX_LENGTH,
73
129
  fallbackShortTitle,
74
130
  generateShortTitle,
75
- resolveTaskTitle
131
+ resolveTaskTitle,
132
+ estimateTextTokens,
133
+ calculateContextCompactionTargetTokens,
134
+ getAgentContextCompactionTriggerTokens,
135
+ getAgentContextInputLimitTokens,
136
+ getConversationContextCompactionTriggerTokens
76
137
  };
@@ -3,7 +3,7 @@ import {
3
3
  toCanonicalInputMessage,
4
4
  toCanonicalOutputMessage,
5
5
  toGenAiMessagesTraceAttributes
6
- } from "./chunk-RXBVB2JM.js";
6
+ } from "./chunk-LE5H7LMT.js";
7
7
  import {
8
8
  extractGenAiUsageAttributes,
9
9
  logException,
@@ -11,7 +11,7 @@ import {
11
11
  normalizeGenAiFinishReason,
12
12
  serializeGenAiAttribute,
13
13
  withSpan
14
- } from "./chunk-4LJO56OJ.js";
14
+ } from "./chunk-EAI67NTM.js";
15
15
 
16
16
  // src/chat/services/provider-error.ts
17
17
  var ProviderError = class extends Error {
@@ -1,7 +1,7 @@
1
1
  // package.json
2
2
  var package_default = {
3
3
  name: "@sentry/junior",
4
- version: "0.147.0",
4
+ version: "0.148.0",
5
5
  private: false,
6
6
  publishConfig: {
7
7
  access: "public"
@@ -73,6 +73,7 @@ var package_default = {
73
73
  "@chat-adapter/state-redis": "4.29.0",
74
74
  "@earendil-works/pi-agent-core": "catalog:",
75
75
  "@earendil-works/pi-ai": "catalog:",
76
+ "@hono/zod-validator": "^0.9.0",
76
77
  "@logtape/logtape": "^2.1.1",
77
78
  "@modelcontextprotocol/sdk": "1.29.0",
78
79
  "@neondatabase/serverless": "^1.1.0",
@@ -1,10 +1,10 @@
1
1
  import {
2
2
  createAndEnqueueAgentInvocation
3
- } from "./chunk-YEO3VX72.js";
3
+ } from "./chunk-OJCP3C3J.js";
4
4
  import {
5
5
  actorFromRouting,
6
6
  toolInvocationDestination
7
- } from "./chunk-R776HKPK.js";
7
+ } from "./chunk-GDFF3BQG.js";
8
8
 
9
9
  // src/chat/agent-invocations/spawn.ts
10
10
  function bindSpawnAgent(request, options) {
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  DEFAULT_SQL_STATEMENT_TIMEOUT_MS
3
- } from "./chunk-7NVJVJID.js";
3
+ } from "./chunk-4GXJUYJV.js";
4
4
  import {
5
5
  juniorDestinations,
6
6
  timestamptz
@@ -1,3 +1,6 @@
1
+ import {
2
+ getTurnRequestDeadline
3
+ } from "./chunk-DUY5CDAM.js";
1
4
  import {
2
5
  CONVERSATION_WORK_CHECK_IN_INTERVAL_MS,
3
6
  CONVERSATION_WORK_MAX_RETRIES,
@@ -18,37 +21,37 @@ import {
18
21
  releaseConversationWork,
19
22
  requestAnotherSlice,
20
23
  startConversationWork
21
- } from "./chunk-CWP5RHVX.js";
24
+ } from "./chunk-HLPLT3NY.js";
22
25
  import {
23
26
  ConversationQueueMessageRejectedError
24
27
  } from "./chunk-JAL3CH4G.js";
25
28
  import {
26
29
  getChatConfig,
27
30
  isProviderRetryError
28
- } from "./chunk-7NVJVJID.js";
31
+ } from "./chunk-4GXJUYJV.js";
29
32
  import {
30
33
  logException,
31
34
  logInfo,
32
35
  logWarn,
33
36
  withLogContext
34
- } from "./chunk-4LJO56OJ.js";
37
+ } from "./chunk-EAI67NTM.js";
35
38
 
36
39
  // src/chat/task-execution/worker.ts
37
40
  var CONVERSATION_WORK_DEFER_DELAY_MS = 15e3;
38
41
  function now(options) {
39
42
  return options.nowMs?.() ?? Date.now();
40
43
  }
41
- function selectContiguousActorBatch(messages) {
44
+ function selectContiguousTurnBatch(messages) {
42
45
  const first = messages[0];
43
46
  if (!first) {
44
47
  return [];
45
48
  }
46
- const nextActorIndex = messages.findIndex(
47
- (message) => message.input.authorId !== first.input.authorId
49
+ const nextTurnIndex = messages.findIndex(
50
+ (message) => message.input.authorId !== first.input.authorId || message.publishExternally !== first.publishExternally
48
51
  );
49
52
  return messages.slice(
50
53
  0,
51
- nextActorIndex === -1 ? messages.length : nextActorIndex
54
+ nextTurnIndex === -1 ? messages.length : nextTurnIndex
52
55
  );
53
56
  }
54
57
  function selectAttemptMessages(work) {
@@ -57,9 +60,9 @@ function selectAttemptMessages(work) {
57
60
  (message) => message.delivery === "interrupt"
58
61
  );
59
62
  if (interrupts.length > 0) {
60
- return selectContiguousActorBatch(interrupts);
63
+ return selectContiguousTurnBatch(interrupts);
61
64
  }
62
- return work.execution.status === "paused" ? [] : selectContiguousActorBatch(messages);
65
+ return work.execution.status === "paused" ? [] : selectContiguousTurnBatch(messages);
63
66
  }
64
67
  function nudgeIdempotencyKey(reason, conversationId, nowMs) {
65
68
  return `${reason}:${conversationId}:${nowMs}`;
@@ -283,7 +286,14 @@ async function processConversationWorkInContext(message, options) {
283
286
  nowMs: now(options),
284
287
  state: options.state
285
288
  });
286
- const shouldYield = () => leaseLost || now(options) >= softYieldDeadlineMs;
289
+ const requestDeadlineAtMs = getTurnRequestDeadline()?.deadlineAtMs;
290
+ const shouldYield = () => (
291
+ // Lease ownership is no longer confirmed, so this worker must stop.
292
+ leaseLost || // The worker soft limit reserves time to persist state and release the lease.
293
+ now(options) >= softYieldDeadlineMs || // Nested work can inherit an older host request deadline. Stop after that
294
+ // absolute deadline, even if this worker acquired its lease later.
295
+ requestDeadlineAtMs !== void 0 && Date.now() >= requestDeadlineAtMs
296
+ );
287
297
  const checkIn = async () => {
288
298
  const checkedIn = await checkInConversationWork({
289
299
  conversationId,
@@ -377,6 +387,7 @@ async function processConversationWorkInContext(message, options) {
377
387
  attemptMessageIds = attemptMessages.map(
378
388
  (message2) => message2.inboundMessageId
379
389
  );
390
+ const publishExternally = attemptMessages[0]?.publishExternally ?? false;
380
391
  attemptSelectedMessageIds = new Set(attemptMessageIds);
381
392
  const ack = async () => {
382
393
  const acknowledged = await ackMessages({
@@ -407,6 +418,7 @@ async function processConversationWorkInContext(message, options) {
407
418
  },
408
419
  conversationId,
409
420
  destination,
421
+ publishExternally,
410
422
  shouldYield,
411
423
  checkIn
412
424
  };
@@ -0,0 +1,36 @@
1
+ import {
2
+ FUNCTION_TIMEOUT_BUFFER_SECONDS,
3
+ getChatConfig
4
+ } from "./chunk-4GXJUYJV.js";
5
+
6
+ // src/chat/runtime/request-deadline.ts
7
+ import { AsyncLocalStorage } from "async_hooks";
8
+ var requestDeadlineStorage = new AsyncLocalStorage();
9
+ function createTurnRequestDeadline(startedAtMs) {
10
+ const requestBudgetMs = Math.max(
11
+ 1,
12
+ getChatConfig().functionMaxDurationSeconds * 1e3 - FUNCTION_TIMEOUT_BUFFER_SECONDS * 1e3
13
+ );
14
+ return {
15
+ startedAtMs,
16
+ deadlineAtMs: startedAtMs + requestBudgetMs
17
+ };
18
+ }
19
+ function getTurnRequestDeadline() {
20
+ return requestDeadlineStorage.getStore();
21
+ }
22
+ function runWithTurnRequestDeadline(callback, startedAtMs = Date.now()) {
23
+ const existingDeadline = requestDeadlineStorage.getStore();
24
+ if (existingDeadline) {
25
+ return callback();
26
+ }
27
+ return requestDeadlineStorage.run(
28
+ createTurnRequestDeadline(startedAtMs),
29
+ callback
30
+ );
31
+ }
32
+
33
+ export {
34
+ getTurnRequestDeadline,
35
+ runWithTurnRequestDeadline
36
+ };
@@ -9,7 +9,7 @@ import {
9
9
  } from "./chunk-6GWA276C.js";
10
10
  import {
11
11
  getDeploymentTelemetryAttributes
12
- } from "./chunk-DLDRQHG5.js";
12
+ } from "./chunk-LAZGHEYU.js";
13
13
 
14
14
  // src/chat/logging.ts
15
15
  import path from "path";
@@ -4,24 +4,24 @@ import {
4
4
  import {
5
5
  formatProviderLabel,
6
6
  startOAuthFlow
7
- } from "./chunk-7UQIVT6G.js";
7
+ } from "./chunk-WCN4YSH7.js";
8
+ import {
9
+ parseSandboxEgressAuthRequiredSignal
10
+ } from "./chunk-HUO3UTAQ.js";
8
11
  import {
9
12
  abandonReplacedPendingAuth,
10
13
  canReusePendingAuthLink,
11
14
  recordAuthorizationRequested
12
- } from "./chunk-AIOK6LAG.js";
13
- import {
14
- parseSandboxEgressAuthRequiredSignal
15
- } from "./chunk-HUO3UTAQ.js";
15
+ } from "./chunk-VCYSOXON.js";
16
16
  import {
17
17
  AGENT_INVOCATION_MAILBOX_STATUSES
18
- } from "./chunk-DU74WPIC.js";
18
+ } from "./chunk-D3WPMGEX.js";
19
19
  import {
20
20
  TURN_REASONING_LEVELS
21
- } from "./chunk-7NVJVJID.js";
21
+ } from "./chunk-4GXJUYJV.js";
22
22
  import {
23
23
  pluginCatalogRuntime
24
- } from "./chunk-JUUKWRBE.js";
24
+ } from "./chunk-HWQGBIH7.js";
25
25
  import {
26
26
  credentialContextSchema
27
27
  } from "./chunk-RUIXF3YQ.js";
@@ -0,0 +1,136 @@
1
+ // src/chat/agent/request.ts
2
+ function isAgentRunFeatureDisabled(policy, feature) {
3
+ return policy?.disabledFeatures?.includes(feature) ?? false;
4
+ }
5
+ var RetryableDeliveryError = class extends Error {
6
+ constructor(cause) {
7
+ super("Assistant delivery was transient or ambiguous", { cause });
8
+ this.name = "RetryableDeliveryError";
9
+ }
10
+ };
11
+ function actorFromRouting(routing) {
12
+ if (routing.dispatch?.actor) {
13
+ return routing.dispatch.actor;
14
+ }
15
+ if (routing.actor) {
16
+ return routing.actor;
17
+ }
18
+ if (routing.credentialContext && !("type" in routing.credentialContext.actor)) {
19
+ return routing.credentialContext.actor;
20
+ }
21
+ return void 0;
22
+ }
23
+ function assertRunRoutingConsistency(request) {
24
+ const { destination, source } = request.routing;
25
+ switch (source.platform) {
26
+ case "slack": {
27
+ if (destination.platform !== "slack") {
28
+ throw new TypeError("Run source and destination platforms do not match");
29
+ }
30
+ if (source.teamId !== destination.teamId) {
31
+ throw new TypeError("Slack source and destination teams do not match");
32
+ }
33
+ break;
34
+ }
35
+ case "local": {
36
+ if (destination.platform !== "local") {
37
+ throw new TypeError("Run source and destination platforms do not match");
38
+ }
39
+ if (source.conversationId !== destination.conversationId) {
40
+ throw new TypeError(
41
+ "Source and destination conversation IDs do not match"
42
+ );
43
+ }
44
+ if (request.routing.surface !== "internal" && destination.conversationId !== request.conversationId) {
45
+ throw new TypeError(
46
+ "Source, destination, and run conversation IDs do not match"
47
+ );
48
+ }
49
+ break;
50
+ }
51
+ case "web": {
52
+ if (request.routing.surface !== "internal" && source.conversationId !== request.conversationId) {
53
+ throw new TypeError(
54
+ "Web source and run conversation IDs do not match"
55
+ );
56
+ }
57
+ switch (destination.platform) {
58
+ case "local": {
59
+ if (source.conversationId !== destination.conversationId) {
60
+ throw new TypeError(
61
+ "Source and destination conversation IDs do not match"
62
+ );
63
+ }
64
+ if (request.routing.surface !== "internal" && destination.conversationId !== request.conversationId) {
65
+ throw new TypeError(
66
+ "Source, destination, and run conversation IDs do not match"
67
+ );
68
+ }
69
+ break;
70
+ }
71
+ case "slack": {
72
+ if (request.routing.publishExternally) {
73
+ throw new TypeError(
74
+ "Web turns on Slack destinations must not publish externally"
75
+ );
76
+ }
77
+ break;
78
+ }
79
+ }
80
+ break;
81
+ }
82
+ }
83
+ const actor = request.routing.dispatch?.actor ?? request.routing.actor;
84
+ if (!actor || actor.platform === "system") {
85
+ return;
86
+ }
87
+ const actorMatchesDestination = (() => {
88
+ switch (actor.platform) {
89
+ case "slack":
90
+ return destination.platform === "slack";
91
+ case "local":
92
+ return destination.platform === "local";
93
+ case "web":
94
+ return destination.platform === "local" || destination.platform === "slack" && request.routing.publishExternally !== true;
95
+ }
96
+ })();
97
+ if (!actorMatchesDestination) {
98
+ throw new TypeError(
99
+ `Actor platform "${actor.platform}" does not match destination platform "${destination.platform}"`
100
+ );
101
+ }
102
+ if (actor.platform === "slack" && destination.platform === "slack" && actor.teamId !== destination.teamId) {
103
+ throw new TypeError("Slack actor team does not match destination team");
104
+ }
105
+ }
106
+ function toolInvocationDestination(routing) {
107
+ if (routing.destination.platform !== "slack" || !routing.toolChannelId) {
108
+ return routing.destination;
109
+ }
110
+ return {
111
+ platform: "slack",
112
+ teamId: routing.destination.teamId,
113
+ channelId: routing.toolChannelId
114
+ };
115
+ }
116
+ function surfaceFromRouting(routing) {
117
+ if (routing.surface) {
118
+ return routing.surface;
119
+ }
120
+ if (routing.source.platform === "slack") {
121
+ return "slack";
122
+ }
123
+ if (routing.source.platform === "web") {
124
+ return "api";
125
+ }
126
+ return "internal";
127
+ }
128
+
129
+ export {
130
+ isAgentRunFeatureDisabled,
131
+ RetryableDeliveryError,
132
+ actorFromRouting,
133
+ assertRunRoutingConsistency,
134
+ toolInvocationDestination,
135
+ surfaceFromRouting
136
+ };
@@ -1,25 +1,25 @@
1
1
  import {
2
2
  ToolInputError
3
- } from "./chunk-HLXXQI5Q.js";
3
+ } from "./chunk-VCYSOXON.js";
4
4
  import {
5
5
  canRouteResourceEvents,
6
6
  getPlugins
7
- } from "./chunk-YHDERDRO.js";
7
+ } from "./chunk-ZCHIC2GM.js";
8
8
  import {
9
9
  getDb
10
- } from "./chunk-YSB2N563.js";
10
+ } from "./chunk-VRHTNBA6.js";
11
11
  import {
12
12
  juniorEventTasks,
13
13
  juniorSchedulerRuns,
14
14
  juniorSchedulerTasks,
15
15
  juniorStats
16
- } from "./chunk-DU74WPIC.js";
16
+ } from "./chunk-D3WPMGEX.js";
17
17
  import {
18
18
  juniorDestinations
19
19
  } from "./chunk-VFUK3X5B.js";
20
20
  import {
21
21
  logInfo
22
- } from "./chunk-4LJO56OJ.js";
22
+ } from "./chunk-EAI67NTM.js";
23
23
 
24
24
  // src/chat/event-tasks/store.ts
25
25
  import { and, asc, desc, eq, inArray, or, sql } from "drizzle-orm";
@@ -8,14 +8,14 @@ import {
8
8
  getConversationStore,
9
9
  parseDestination,
10
10
  sameDestination
11
- } from "./chunk-YSB2N563.js";
11
+ } from "./chunk-VRHTNBA6.js";
12
12
  import {
13
13
  getDefaultRedisStateAdapterFor,
14
14
  getStateAdapter
15
- } from "./chunk-ORO3PWKQ.js";
15
+ } from "./chunk-2B3PT3V2.js";
16
16
  import {
17
17
  getChatConfig
18
- } from "./chunk-7NVJVJID.js";
18
+ } from "./chunk-4GXJUYJV.js";
19
19
  import {
20
20
  parseStoredSlackActor
21
21
  } from "./chunk-HZF5P5UN.js";
@@ -23,7 +23,7 @@ import {
23
23
  isRecord,
24
24
  toOptionalNumber,
25
25
  toOptionalString
26
- } from "./chunk-4LJO56OJ.js";
26
+ } from "./chunk-EAI67NTM.js";
27
27
 
28
28
  // src/chat/task-execution/state.ts
29
29
  import { randomUUID } from "crypto";
@@ -69,7 +69,8 @@ var inboundMessageSourceSchema = z.enum([
69
69
  "plugin",
70
70
  "resource_event",
71
71
  "scheduler",
72
- "slack"
72
+ "slack",
73
+ "web"
73
74
  ]);
74
75
  var agentInputSchema = z.object({
75
76
  attachments: z.array(z.unknown()).optional(),
@@ -80,6 +81,7 @@ var agentInputSchema = z.object({
80
81
  message: "agent input requires text or attachments"
81
82
  });
82
83
  var inboundMessageDeliverySchema = z.enum(["defer", "interrupt"]);
84
+ var publishExternallySchema = z.boolean();
83
85
  var inboundMessageSchema = z.object({
84
86
  attemptCount: z.number().finite().optional(),
85
87
  conversationId: z.string().refine((value) => value.trim().length > 0),
@@ -90,6 +92,7 @@ var inboundMessageSchema = z.object({
90
92
  injectedAtMs: z.number().finite().optional(),
91
93
  input: agentInputSchema,
92
94
  receivedAtMs: z.number().finite(),
95
+ publishExternally: publishExternallySchema,
93
96
  source: inboundMessageSourceSchema
94
97
  }).strict();
95
98
  function conversationKey(conversationId) {
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  createPluginCatalogRuntime
3
- } from "./chunk-GGB4WL5A.js";
3
+ } from "./chunk-POSZWRGL.js";
4
4
 
5
5
  // src/chat/plugins/catalog-runtime.ts
6
6
  var pluginCatalogRuntime = createPluginCatalogRuntime();
@@ -1,18 +1,18 @@
1
1
  import {
2
2
  persistConversationMessages
3
- } from "./chunk-AIOK6LAG.js";
3
+ } from "./chunk-VCYSOXON.js";
4
4
  import {
5
5
  JUNIOR_THREAD_STATE_TTL_MS
6
6
  } from "./chunk-3Y47VMHV.js";
7
7
  import {
8
8
  getDb
9
- } from "./chunk-YSB2N563.js";
9
+ } from "./chunk-VRHTNBA6.js";
10
10
  import {
11
11
  juniorLocationConfigurations
12
- } from "./chunk-DU74WPIC.js";
12
+ } from "./chunk-D3WPMGEX.js";
13
13
  import {
14
14
  getStateAdapter
15
- } from "./chunk-ORO3PWKQ.js";
15
+ } from "./chunk-2B3PT3V2.js";
16
16
  import {
17
17
  juniorDestinations
18
18
  } from "./chunk-VFUK3X5B.js";
@@ -20,7 +20,7 @@ import {
20
20
  isRecord,
21
21
  toOptionalNumber,
22
22
  toOptionalString
23
- } from "./chunk-4LJO56OJ.js";
23
+ } from "./chunk-EAI67NTM.js";
24
24
 
25
25
  // src/chat/conversations/turn-lifecycle.ts
26
26
  var ConversationTurnLifecycleService = class {
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  JUNIOR_VERSION
3
- } from "./chunk-IIOOO4FQ.js";
3
+ } from "./chunk-55F4QU2V.js";
4
4
 
5
5
  // src/deployment.ts
6
6
  var JUNIOR_HEARTBEAT_ROUTE = "/api/internal/heartbeat";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  logWarn
3
- } from "./chunk-4LJO56OJ.js";
3
+ } from "./chunk-EAI67NTM.js";
4
4
 
5
5
  // src/chat/conversation-privacy.ts
6
6
  import { AsyncLocalStorage } from "async_hooks";
@@ -0,0 +1,48 @@
1
+ import {
2
+ getTurnUserMessageId,
3
+ markConversationMessage
4
+ } from "./chunk-RRJV5UR5.js";
5
+ import {
6
+ coerceThreadConversationState,
7
+ getPersistedThreadState,
8
+ persistThreadStateById
9
+ } from "./chunk-IL4EDBMV.js";
10
+ import {
11
+ hydrateConversationMessages,
12
+ markTurnClosed
13
+ } from "./chunk-VCYSOXON.js";
14
+
15
+ // src/chat/runtime/auth-pause-state.ts
16
+ function completeAuthPauseTurn(args) {
17
+ markConversationMessage(
18
+ args.conversation,
19
+ getTurnUserMessageId(args.conversation, args.sessionId),
20
+ {
21
+ replied: true,
22
+ skippedReason: void 0
23
+ }
24
+ );
25
+ markTurnClosed({
26
+ conversation: args.conversation,
27
+ nowMs: Date.now(),
28
+ sessionId: args.sessionId
29
+ });
30
+ }
31
+ async function persistAuthPauseTurnState(args) {
32
+ const currentState = await getPersistedThreadState(args.threadStateId);
33
+ const conversation = coerceThreadConversationState(currentState);
34
+ await hydrateConversationMessages({
35
+ conversation,
36
+ conversationId: args.threadStateId
37
+ });
38
+ completeAuthPauseTurn({
39
+ conversation,
40
+ sessionId: args.sessionId
41
+ });
42
+ await persistThreadStateById(args.threadStateId, { conversation });
43
+ }
44
+
45
+ export {
46
+ completeAuthPauseTurn,
47
+ persistAuthPauseTurnState
48
+ };