@sentry/junior 0.88.0 → 0.90.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 (158) hide show
  1. package/README.md +16 -5
  2. package/dist/{agent-hooks-RIJ5TSWP.js → agent-hooks-MXAF7RQL.js} +10 -10
  3. package/dist/api/people/list.js +8 -8
  4. package/dist/api/people/profile.js +8 -8
  5. package/dist/api-reference.d.ts +1 -1
  6. package/dist/app.js +716 -732
  7. package/dist/{catalog-runtime-MW7XERSU.js → catalog-runtime-DXE6NXHT.js} +5 -5
  8. package/dist/chat/agent/index.d.ts +4 -0
  9. package/dist/chat/agent/prompt.d.ts +78 -0
  10. package/dist/chat/{respond.d.ts → agent/request.d.ts} +98 -55
  11. package/dist/chat/agent/resume.d.ts +65 -0
  12. package/dist/chat/agent/sandbox.d.ts +15 -0
  13. package/dist/chat/agent/session.d.ts +20 -0
  14. package/dist/chat/agent/skills.d.ts +26 -0
  15. package/dist/chat/agent/tools.d.ts +78 -0
  16. package/dist/chat/agent-dispatch/runner.d.ts +3 -5
  17. package/dist/chat/app/production.d.ts +3 -1
  18. package/dist/chat/app/services.d.ts +1 -4
  19. package/dist/chat/logging.d.ts +2 -0
  20. package/dist/chat/mcp/tool-manager.d.ts +1 -6
  21. package/dist/chat/pi/messages.d.ts +18 -2
  22. package/dist/chat/pi/transcript.d.ts +31 -0
  23. package/dist/chat/plugins/agent-hooks.d.ts +2 -2
  24. package/dist/chat/prompt.d.ts +1 -1
  25. package/dist/chat/runtime/agent-continue-runner.d.ts +5 -5
  26. package/dist/chat/runtime/agent-run-outcome.d.ts +21 -0
  27. package/dist/chat/runtime/agent-runner.d.ts +11 -0
  28. package/dist/chat/runtime/delivered-turn-state.d.ts +2 -2
  29. package/dist/chat/runtime/generated-artifacts.d.ts +16 -0
  30. package/dist/chat/runtime/reply-executor.d.ts +2 -2
  31. package/dist/chat/runtime/slack-resume.d.ts +21 -12
  32. package/dist/chat/runtime/turn.d.ts +5 -39
  33. package/dist/chat/services/reply-delivery-plan.d.ts +0 -8
  34. package/dist/chat/services/turn-failure-response.d.ts +4 -4
  35. package/dist/chat/services/turn-result.d.ts +4 -7
  36. package/dist/chat/slack/channel.d.ts +9 -5
  37. package/dist/chat/slack/client.d.ts +3 -1
  38. package/dist/chat/slack/context.d.ts +17 -5
  39. package/dist/chat/slack/id-param.d.ts +25 -0
  40. package/dist/chat/slack/ids.d.ts +18 -4
  41. package/dist/chat/slack/outbound.d.ts +16 -0
  42. package/dist/chat/slack/output.d.ts +3 -3
  43. package/dist/chat/slack/reply.d.ts +4 -7
  44. package/dist/chat/slack/timestamp-param.d.ts +25 -0
  45. package/dist/chat/slack/tools/canvas/context.d.ts +18 -0
  46. package/dist/chat/slack/tools/canvas/create.d.ts +4 -0
  47. package/dist/chat/slack/tools/canvas/edit.d.ts +3 -0
  48. package/dist/chat/slack/tools/canvas/read.d.ts +6 -0
  49. package/dist/chat/slack/tools/canvas/write.d.ts +3 -0
  50. package/dist/chat/{tools/slack → slack/tools}/channel-access.d.ts +4 -3
  51. package/dist/chat/{tools → slack/tools}/channel-capabilities.d.ts +2 -0
  52. package/dist/chat/slack/tools/channel-list-messages.d.ts +3 -0
  53. package/dist/chat/{tools/slack → slack/tools}/context.d.ts +5 -4
  54. package/dist/chat/slack/tools/list/add-items.d.ts +3 -0
  55. package/dist/chat/{tools/slack/lists.d.ts → slack/tools/list/api.d.ts} +2 -1
  56. package/dist/chat/slack/tools/list/create.d.ts +3 -0
  57. package/dist/chat/slack/tools/list/get-items.d.ts +3 -0
  58. package/dist/chat/slack/tools/list/update-item.d.ts +3 -0
  59. package/dist/chat/slack/tools/message-add-reaction.d.ts +4 -0
  60. package/dist/chat/slack/tools/send-message.d.ts +11 -0
  61. package/dist/chat/{tools/slack → slack/tools}/slack-message-url.d.ts +5 -5
  62. package/dist/chat/slack/tools/thread-read.d.ts +6 -0
  63. package/dist/chat/slack/tools/user-lookup.d.ts +2 -0
  64. package/dist/chat/slack/users.d.ts +2 -1
  65. package/dist/chat/{services → slack}/vision-context.d.ts +4 -2
  66. package/dist/chat/state/session-log.d.ts +1 -1
  67. package/dist/chat/tool-exposure.d.ts +10 -0
  68. package/dist/chat/tool-support/catalog-tool-call.d.ts +10 -0
  69. package/dist/chat/{tools/execution → tool-support}/normalize-result.d.ts +4 -1
  70. package/dist/chat/{tools/agent-tools.d.ts → tool-support/pi-tool-adapter.d.ts} +3 -9
  71. package/dist/chat/tool-support/schema-summary.d.ts +2 -0
  72. package/dist/chat/{tools → tool-support}/skill/mcp-tool-summary.d.ts +0 -6
  73. package/dist/chat/tool-support/structured-result.d.ts +73 -0
  74. package/dist/chat/tool-support/text-range-result.d.ts +58 -0
  75. package/dist/chat/tool-support/tool-execution-report.d.ts +7 -0
  76. package/dist/chat/tool-support/zod-tool.d.ts +27 -0
  77. package/dist/chat/tools/advisor/tool.d.ts +9 -18
  78. package/dist/chat/tools/definition.d.ts +56 -9
  79. package/dist/chat/tools/execute-tool.d.ts +3 -0
  80. package/dist/chat/tools/index.d.ts +3 -2
  81. package/dist/chat/tools/resource-events.d.ts +3 -13
  82. package/dist/chat/tools/runtime/report-progress.d.ts +1 -3
  83. package/dist/chat/tools/sandbox/bash.d.ts +1 -4
  84. package/dist/chat/tools/sandbox/edit-file.d.ts +25 -7
  85. package/dist/chat/tools/sandbox/file-uploads.d.ts +30 -0
  86. package/dist/chat/tools/sandbox/file-utils.d.ts +10 -1
  87. package/dist/chat/tools/sandbox/find-files.d.ts +12 -11
  88. package/dist/chat/tools/sandbox/grep.d.ts +18 -12
  89. package/dist/chat/tools/sandbox/list-dir.d.ts +15 -7
  90. package/dist/chat/tools/sandbox/read-file.d.ts +2 -31
  91. package/dist/chat/tools/sandbox/write-file.d.ts +1 -4
  92. package/dist/chat/tools/search-tools.d.ts +4 -0
  93. package/dist/chat/tools/skill/call-mcp-tool.d.ts +1 -4
  94. package/dist/chat/tools/skill/load-skill.d.ts +4 -5
  95. package/dist/chat/tools/skill/search-mcp-tools.d.ts +1 -5
  96. package/dist/chat/tools/system-time.d.ts +1 -1
  97. package/dist/chat/tools/types.d.ts +15 -5
  98. package/dist/chat/tools/web/fetch-content.d.ts +4 -2
  99. package/dist/chat/tools/web/fetch-tool.d.ts +4 -4
  100. package/dist/chat/tools/web/image-generate.d.ts +4 -3
  101. package/dist/chat/tools/web/search.d.ts +1 -4
  102. package/dist/{chunk-4IXHIV37.js → chunk-2S7M37HY.js} +6 -8
  103. package/dist/{chunk-L7OHKDOX.js → chunk-3MPOMK3K.js} +58 -7
  104. package/dist/{chunk-V6XDCS3X.js → chunk-5GBUZI6M.js} +4 -4
  105. package/dist/{chunk-7ES37H6U.js → chunk-AN2437E3.js} +4 -4
  106. package/dist/chunk-AOISHLSF.js +747 -0
  107. package/dist/{chunk-NYJLQI42.js → chunk-BKSZL4QO.js} +11257 -11957
  108. package/dist/{chunk-XS6NLQPA.js → chunk-DACFZ5CI.js} +474 -33
  109. package/dist/chunk-GCWD2VHP.js +1216 -0
  110. package/dist/chunk-GHGPTPBL.js +53 -0
  111. package/dist/{chunk-S35CPNPT.js → chunk-HXL2ZV74.js} +40 -216
  112. package/dist/{chunk-PBV4ZIVM.js → chunk-IRRMABQD.js} +1 -1
  113. package/dist/{chunk-2DPZRS3B.js → chunk-IX76WFJV.js} +8 -8
  114. package/dist/{chunk-66NX7MNW.js → chunk-KC42JAAQ.js} +1 -1
  115. package/dist/chunk-LFLTJQVR.js +90 -0
  116. package/dist/{chunk-IATAYWFU.js → chunk-NW7AXDA5.js} +2 -2
  117. package/dist/{chunk-F22AM3OW.js → chunk-NYWPISSO.js} +1 -1
  118. package/dist/chunk-OB42YVAE.js +16 -0
  119. package/dist/chunk-ONFOWI2D.js +955 -0
  120. package/dist/chunk-PHZHJTCK.js +1062 -0
  121. package/dist/{chunk-6UPQ5GTJ.js → chunk-QCKGI74V.js} +7 -7
  122. package/dist/{chunk-YPAE5RH3.js → chunk-RS6ANWVT.js} +1 -1
  123. package/dist/{chunk-C5NCV3OB.js → chunk-TYUXD3FN.js} +1 -1
  124. package/dist/{chunk-KBFQXJL4.js → chunk-XP7F4LYB.js} +5 -7
  125. package/dist/{chunk-VMBZFPZM.js → chunk-ZUK7BL63.js} +187 -9
  126. package/dist/cli/chat.js +55 -40
  127. package/dist/cli/check.js +6 -6
  128. package/dist/cli/init.js +30 -36
  129. package/dist/cli/plugins.js +16 -16
  130. package/dist/cli/snapshot-warmup.js +9 -9
  131. package/dist/cli/upgrade.js +21 -21
  132. package/dist/db-CXI7PR5U.js +18 -0
  133. package/dist/handlers/agent-dispatch.d.ts +3 -3
  134. package/dist/handlers/mcp-oauth-callback.d.ts +3 -3
  135. package/dist/handlers/oauth-callback.d.ts +3 -3
  136. package/dist/instrumentation.js +6 -5
  137. package/dist/nitro.js +3 -7
  138. package/dist/reporting.js +23 -25
  139. package/dist/{runner-BCRF2FCI.js → runner-FKL3RAHA.js} +89 -77
  140. package/dist/{validation-FMJO3L5P.js → validation-I7GD2YWS.js} +6 -6
  141. package/package.json +6 -6
  142. package/dist/chat/respond-helpers.d.ts +0 -82
  143. package/dist/chat/services/attachment-claims.d.ts +0 -2
  144. package/dist/chat/services/channel-intent.d.ts +0 -2
  145. package/dist/chat/tools/sandbox/attach-file.d.ts +0 -7
  146. package/dist/chat/tools/slack/canvas-tools.d.ts +0 -30
  147. package/dist/chat/tools/slack/channel-list-messages.d.ts +0 -9
  148. package/dist/chat/tools/slack/channel-post-message.d.ts +0 -5
  149. package/dist/chat/tools/slack/list-tools.d.ts +0 -21
  150. package/dist/chat/tools/slack/message-add-reaction.d.ts +0 -5
  151. package/dist/chat/tools/slack/thread-read.d.ts +0 -12
  152. package/dist/chat/tools/slack/user-lookup.d.ts +0 -8
  153. package/dist/chunk-AHLSXMOU.js +0 -506
  154. package/dist/chunk-FTMXFBDC.js +0 -49
  155. package/dist/chunk-KBSLCOGE.js +0 -2226
  156. package/dist/chunk-KQKIA4CU.js +0 -186
  157. package/dist/db-37HOGLI7.js +0 -18
  158. /package/dist/chat/{tools/slack/canvases.d.ts → slack/tools/canvas/api.d.ts} +0 -0
@@ -0,0 +1,53 @@
1
+ import {
2
+ parseSlackChannelReferenceId,
3
+ parseSlackTeamId
4
+ } from "./chunk-LFLTJQVR.js";
5
+
6
+ // src/chat/destination.ts
7
+ import {
8
+ destinationSchema
9
+ } from "@sentry/junior-plugin-api";
10
+ function createSlackDestination(input) {
11
+ const channelId = parseSlackChannelReferenceId(input.channelId);
12
+ const teamId = parseSlackTeamId(input.teamId);
13
+ if (!channelId || !teamId) {
14
+ return void 0;
15
+ }
16
+ return { platform: "slack", teamId, channelId };
17
+ }
18
+ function parseDestination(value) {
19
+ const parsed = destinationSchema.safeParse(value);
20
+ return parsed.success ? parsed.data : void 0;
21
+ }
22
+ function requireSlackDestination(destination, action) {
23
+ if (destination?.platform === "slack") {
24
+ return destination;
25
+ }
26
+ throw new Error(`${action} requires a Slack destination`);
27
+ }
28
+ function sameDestination(left, right) {
29
+ if (left.platform !== right.platform) {
30
+ return false;
31
+ }
32
+ if (left.platform === "local" && right.platform === "local") {
33
+ return left.conversationId === right.conversationId;
34
+ }
35
+ if (left.platform === "slack" && right.platform === "slack") {
36
+ return left.teamId === right.teamId && left.channelId === right.channelId;
37
+ }
38
+ return false;
39
+ }
40
+ function destinationKey(destination) {
41
+ if (destination.platform === "local") {
42
+ return destination.conversationId;
43
+ }
44
+ return `slack:${destination.teamId}:${destination.channelId}`;
45
+ }
46
+
47
+ export {
48
+ createSlackDestination,
49
+ parseDestination,
50
+ requireSlackDestination,
51
+ sameDestination,
52
+ destinationKey
53
+ };
@@ -4,7 +4,7 @@ import {
4
4
  toGenAiMessageMetadata,
5
5
  toGenAiMessagesTraceAttributes,
6
6
  toGenAiTextMetadata
7
- } from "./chunk-L7OHKDOX.js";
7
+ } from "./chunk-3MPOMK3K.js";
8
8
  import {
9
9
  extractGenAiUsageAttributes,
10
10
  logException,
@@ -12,168 +12,23 @@ import {
12
12
  serializeGenAiAttribute,
13
13
  setSpanAttributes,
14
14
  withSpan
15
- } from "./chunk-VMBZFPZM.js";
16
-
17
- // src/chat/xml.ts
18
- function escapeXml(value) {
19
- return value.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;").replaceAll('"', "&quot;").replaceAll("'", "&apos;");
20
- }
21
-
22
- // src/chat/current-instruction.ts
23
- var CURRENT_INSTRUCTION_TAG = "current-instruction";
24
- var CURRENT_INSTRUCTION_PATTERN = new RegExp(
25
- `<${CURRENT_INSTRUCTION_TAG}>\\n([\\s\\S]*?)\\n</${CURRENT_INSTRUCTION_TAG}>`
26
- );
27
- var STANDALONE_CURRENT_INSTRUCTION_PATTERN = new RegExp(
28
- `^<${CURRENT_INSTRUCTION_TAG}>\\n([\\s\\S]*?)\\n</${CURRENT_INSTRUCTION_TAG}>$`
29
- );
30
- function unescapeXml(value) {
31
- return value.replaceAll("&quot;", '"').replaceAll("&apos;", "'").replaceAll("&gt;", ">").replaceAll("&lt;", "<").replaceAll("&amp;", "&");
32
- }
33
- function renderCurrentInstruction(instruction) {
34
- return [
35
- `<${CURRENT_INSTRUCTION_TAG}>`,
36
- escapeXml(instruction),
37
- `</${CURRENT_INSTRUCTION_TAG}>`
38
- ].join("\n");
39
- }
40
- function extractCurrentInstructionBody(text) {
41
- const match = text.match(STANDALONE_CURRENT_INSTRUCTION_PATTERN);
42
- return match?.[1];
43
- }
44
- function unwrapCurrentInstruction(text) {
45
- const match = text.match(CURRENT_INSTRUCTION_PATTERN);
46
- if (!match) {
47
- return void 0;
48
- }
49
- return unescapeXml(match[1]);
50
- }
15
+ } from "./chunk-ZUK7BL63.js";
51
16
 
52
17
  // src/chat/turn-context-tag.ts
53
18
  var TURN_CONTEXT_TAG = "runtime-turn-context";
54
19
 
55
- // src/chat/respond-helpers.ts
56
- var MAX_INLINE_ATTACHMENT_BASE64_CHARS = 12e4;
20
+ // src/chat/pi/transcript.ts
57
21
  var RUNTIME_TURN_CONTEXT_START = `<${TURN_CONTEXT_TAG}>`;
58
- function getSessionIdentifiers(context) {
59
- return {
60
- conversationId: context.correlation?.conversationId ?? context.correlation?.threadId ?? context.correlation?.runId,
61
- sessionId: context.correlation?.turnId
62
- };
63
- }
64
- function isExecutionDeferralResponse(text) {
65
- return /\b(want me to proceed|do you want me to proceed|shall i proceed|can i proceed|should i proceed|let me do that now|give me a moment|tag me again|fresh invocation)\b/i.test(
66
- text
67
- );
68
- }
69
- function isToolAccessDisclaimerResponse(text) {
70
- return /\b(i (don't|do not) have access to (active )?tool|tool results came back empty|prior results .* empty|cannot access .*tool|need to (run|load) .*tool .* first)\b/i.test(
71
- text
72
- );
73
- }
74
- function isExecutionEscapeResponse(text) {
75
- const trimmed = text.trim();
76
- if (!trimmed) return false;
77
- return isExecutionDeferralResponse(trimmed) || isToolAccessDisclaimerResponse(trimmed);
78
- }
79
- function parseJsonCandidate(text) {
80
- const trimmed = text.trim();
81
- if (!trimmed) return void 0;
82
- try {
83
- return JSON.parse(trimmed);
84
- } catch {
85
- const fenced = trimmed.match(/^```(?:json)?\s*([\s\S]*?)\s*```$/i);
86
- if (!fenced) return void 0;
87
- try {
88
- return JSON.parse(fenced[1]);
89
- } catch {
90
- return void 0;
91
- }
92
- }
93
- }
94
- function isToolPayloadShape(payload) {
95
- if (!payload || typeof payload !== "object") return false;
96
- const record = payload;
97
- const type = typeof record.type === "string" ? record.type.toLowerCase() : "";
98
- if (type.startsWith("tool-")) return true;
99
- if (type === "tool_use" || type === "tool_call" || type === "tool_result" || type === "tool_error")
100
- return true;
101
- const hasToolName = typeof record.toolName === "string" || typeof record.name === "string";
102
- const hasToolInput = Object.prototype.hasOwnProperty.call(record, "input") || Object.prototype.hasOwnProperty.call(record, "args");
103
- if (hasToolName && hasToolInput) return true;
104
- return false;
105
- }
106
- function isRawToolPayloadResponse(text) {
107
- const parsed = parseJsonCandidate(text);
108
- if (Array.isArray(parsed)) {
109
- return parsed.some((entry) => isToolPayloadShape(entry));
110
- }
111
- if (isToolPayloadShape(parsed)) {
112
- return true;
113
- }
114
- const compact = text.replace(/\s+/g, " ");
115
- return /"type"\s*:\s*"tool[-_](use|call|result|error)"/i.test(compact);
116
- }
117
- function toObservablePromptPart(part) {
118
- if (part.type === "text") {
119
- return {
120
- type: "text",
121
- text: part.text
122
- };
123
- }
124
- return {
125
- type: "image",
126
- mimeType: part.mimeType,
127
- data: `[omitted:${part.data.length}]`
128
- };
129
- }
130
- function summarizeMessageText(text) {
131
- const normalized = text.trim().replace(/\s+/g, " ");
132
- if (!normalized) {
133
- return "[empty]";
134
- }
135
- return normalized.length > 1200 ? `${normalized.slice(0, 1200)}...` : normalized;
136
- }
137
- function isStructuredThreadContext(context) {
138
- return /^<thread-(compactions|transcript)>/.test(context);
139
- }
140
- function renderThreadContextForPrompt(context) {
141
- if (isStructuredThreadContext(context)) {
142
- return context;
143
- }
144
- return ["<thread-background>", context, "</thread-background>"].join("\n");
145
- }
146
- function buildUserTurnText(userInput, conversationContext) {
147
- const trimmedContext = conversationContext?.trim();
148
- const currentInstruction = renderCurrentInstruction(userInput);
149
- if (!trimmedContext) {
150
- return currentInstruction;
151
- }
152
- return [
153
- renderThreadContextForPrompt(trimmedContext),
154
- "",
155
- currentInstruction
156
- ].join("\n");
157
- }
158
- function encodeNonImageAttachmentForPrompt(attachment) {
159
- const base64 = attachment.data.toString("base64");
160
- const wasTruncated = base64.length > MAX_INLINE_ATTACHMENT_BASE64_CHARS;
161
- const encodedPayload = wasTruncated ? `${base64.slice(0, MAX_INLINE_ATTACHMENT_BASE64_CHARS)}...` : base64;
162
- return [
163
- "<attachment>",
164
- `filename: ${attachment.filename ?? "unnamed"}`,
165
- `media_type: ${attachment.mediaType}`,
166
- "encoding: base64",
167
- `truncated: ${wasTruncated ? "true" : "false"}`,
168
- "<data_base64>",
169
- encodedPayload,
170
- "</data_base64>",
171
- "</attachment>"
172
- ].join("\n");
22
+ function isAssistantMessage(value) {
23
+ return typeof value === "object" && value !== null && value.role === "assistant";
173
24
  }
174
25
  function isToolResultMessage(value) {
175
26
  return typeof value === "object" && value !== null && value.role === "toolResult";
176
27
  }
28
+ function isToolResultError(result) {
29
+ if (!result || typeof result !== "object") return false;
30
+ return Boolean(result.isError);
31
+ }
177
32
  function normalizeToolNameFromResult(result) {
178
33
  if (!result || typeof result !== "object") return void 0;
179
34
  const record = result;
@@ -185,13 +40,6 @@ function normalizeToolNameFromResult(result) {
185
40
  }
186
41
  return void 0;
187
42
  }
188
- function isToolResultError(result) {
189
- if (!result || typeof result !== "object") return false;
190
- return Boolean(result.isError);
191
- }
192
- function isAssistantMessage(value) {
193
- return typeof value === "object" && value !== null && value.role === "assistant";
194
- }
195
43
  function getPiMessageRole(value) {
196
44
  if (!value || typeof value !== "object") {
197
45
  return void 0;
@@ -199,17 +47,40 @@ function getPiMessageRole(value) {
199
47
  const role = value.role;
200
48
  return typeof role === "string" ? role : void 0;
201
49
  }
50
+ function extractAssistantText(message) {
51
+ const content = message.content ?? [];
52
+ return content.filter(
53
+ (part) => part.type === "text" && typeof part.text === "string"
54
+ ).map((part) => part.text).join("\n");
55
+ }
56
+ function getTerminalAssistantMessages(messages) {
57
+ let lastToolResultIndex = -1;
58
+ for (let index = messages.length - 1; index >= 0; index -= 1) {
59
+ if (isToolResultMessage(messages[index])) {
60
+ lastToolResultIndex = index;
61
+ break;
62
+ }
63
+ }
64
+ return messages.slice(lastToolResultIndex + 1).filter(isAssistantMessage);
65
+ }
66
+ function trimTrailingAssistantMessages(messages) {
67
+ let end = messages.length;
68
+ while (end > 0 && getPiMessageRole(messages[end - 1]) === "assistant") {
69
+ end -= 1;
70
+ }
71
+ return end === messages.length ? [...messages] : messages.slice(0, end);
72
+ }
202
73
  function getUserMessageContent(message) {
203
74
  const record = message;
204
75
  return record.role === "user" && Array.isArray(record.content) ? record.content : void 0;
205
76
  }
206
- function isRuntimeTurnContextPart(part, marker) {
207
- return part !== null && typeof part === "object" && part.type === "text" && typeof part.text === "string" && part.text.startsWith(marker);
77
+ function isRuntimeTurnContextPart(part) {
78
+ return part !== null && typeof part === "object" && part.type === "text" && typeof part.text === "string" && part.text.startsWith(RUNTIME_TURN_CONTEXT_START);
208
79
  }
209
80
  function hasRuntimeTurnContext(messages) {
210
81
  return messages.some(
211
82
  (message) => getUserMessageContent(message)?.some(
212
- (part) => isRuntimeTurnContextPart(part, RUNTIME_TURN_CONTEXT_START)
83
+ (part) => isRuntimeTurnContextPart(part)
213
84
  )
214
85
  );
215
86
  }
@@ -220,7 +91,7 @@ function stripRuntimeTurnContext(messages) {
220
91
  return [message];
221
92
  }
222
93
  const nextContent = content.filter(
223
- (part) => !isRuntimeTurnContextPart(part, RUNTIME_TURN_CONTEXT_START)
94
+ (part) => !isRuntimeTurnContextPart(part)
224
95
  );
225
96
  if (nextContent.length === content.length) {
226
97
  return [message];
@@ -231,41 +102,6 @@ function stripRuntimeTurnContext(messages) {
231
102
  return [{ ...message, content: nextContent }];
232
103
  });
233
104
  }
234
- function extractAssistantText(message) {
235
- const content = message.content ?? [];
236
- return content.filter(
237
- (part) => part.type === "text" && typeof part.text === "string"
238
- ).map((part) => part.text).join("\n");
239
- }
240
- function getTerminalAssistantMessages(messages) {
241
- let lastToolResultIndex = -1;
242
- for (let index = messages.length - 1; index >= 0; index -= 1) {
243
- if (isToolResultMessage(messages[index])) {
244
- lastToolResultIndex = index;
245
- break;
246
- }
247
- }
248
- return messages.slice(lastToolResultIndex + 1).filter(isAssistantMessage);
249
- }
250
- function upsertActiveSkill(activeSkills, next) {
251
- const existing = activeSkills.find((skill) => skill.name === next.name);
252
- if (existing) {
253
- existing.body = next.body;
254
- existing.description = next.description;
255
- existing.skillPath = next.skillPath;
256
- existing.allowedTools = next.allowedTools;
257
- existing.pluginProvider = next.pluginProvider;
258
- return;
259
- }
260
- activeSkills.push(next);
261
- }
262
- function trimTrailingAssistantMessages(messages) {
263
- let end = messages.length;
264
- while (end > 0 && getPiMessageRole(messages[end - 1]) === "assistant") {
265
- end -= 1;
266
- }
267
- return end === messages.length ? [...messages] : messages.slice(0, end);
268
- }
269
105
 
270
106
  // src/chat/config.ts
271
107
  import { getModel } from "@earendil-works/pi-ai";
@@ -892,29 +728,17 @@ function setSlackReactionConfig(overrides) {
892
728
 
893
729
  export {
894
730
  toOptionalTrimmed,
895
- escapeXml,
896
- renderCurrentInstruction,
897
- extractCurrentInstructionBody,
898
- unwrapCurrentInstruction,
899
731
  TURN_CONTEXT_TAG,
900
- getSessionIdentifiers,
901
- isExecutionEscapeResponse,
902
- isRawToolPayloadResponse,
903
- toObservablePromptPart,
904
- summarizeMessageText,
905
- buildUserTurnText,
906
- encodeNonImageAttachmentForPrompt,
732
+ isAssistantMessage,
907
733
  isToolResultMessage,
908
- normalizeToolNameFromResult,
909
734
  isToolResultError,
910
- isAssistantMessage,
735
+ normalizeToolNameFromResult,
911
736
  getPiMessageRole,
912
- hasRuntimeTurnContext,
913
- stripRuntimeTurnContext,
914
737
  extractAssistantText,
915
738
  getTerminalAssistantMessages,
916
- upsertActiveSkill,
917
739
  trimTrailingAssistantMessages,
740
+ hasRuntimeTurnContext,
741
+ stripRuntimeTurnContext,
918
742
  isProviderRetryError,
919
743
  nextProviderRetry,
920
744
  GEN_AI_PROVIDER_NAME,
@@ -4,7 +4,7 @@ import {
4
4
  juniorDestinations,
5
5
  juniorIdentities,
6
6
  juniorUsers
7
- } from "./chunk-4IXHIV37.js";
7
+ } from "./chunk-2S7M37HY.js";
8
8
 
9
9
  // src/api/people/shared.ts
10
10
  import { and, asc, desc, eq, sql } from "drizzle-orm";
@@ -1,25 +1,25 @@
1
1
  import {
2
2
  JUNIOR_THREAD_STATE_TTL_MS
3
- } from "./chunk-66NX7MNW.js";
3
+ } from "./chunk-KC42JAAQ.js";
4
4
  import {
5
5
  getDefaultRedisStateAdapterFor,
6
6
  getStateAdapter
7
- } from "./chunk-YPAE5RH3.js";
7
+ } from "./chunk-RS6ANWVT.js";
8
+ import {
9
+ getChatConfig
10
+ } from "./chunk-HXL2ZV74.js";
8
11
  import {
9
12
  parseDestination,
10
13
  sameDestination
11
- } from "./chunk-AHLSXMOU.js";
12
- import {
13
- getChatConfig
14
- } from "./chunk-S35CPNPT.js";
14
+ } from "./chunk-GHGPTPBL.js";
15
15
  import {
16
16
  parseStoredSlackRequester
17
- } from "./chunk-KQKIA4CU.js";
17
+ } from "./chunk-ZUK7BL63.js";
18
18
  import {
19
19
  isRecord,
20
20
  toOptionalNumber,
21
21
  toOptionalString
22
- } from "./chunk-FTMXFBDC.js";
22
+ } from "./chunk-OB42YVAE.js";
23
23
 
24
24
  // src/chat/task-execution/state.ts
25
25
  import { randomUUID } from "crypto";
@@ -2,7 +2,7 @@ import {
2
2
  isRecord,
3
3
  toOptionalNumber,
4
4
  toOptionalString
5
- } from "./chunk-FTMXFBDC.js";
5
+ } from "./chunk-OB42YVAE.js";
6
6
 
7
7
  // src/chat/state/conversation.ts
8
8
  function coerceRole(value) {
@@ -0,0 +1,90 @@
1
+ // src/deployment.ts
2
+ var JUNIOR_HEARTBEAT_ROUTE = "/api/internal/heartbeat";
3
+ var JUNIOR_HEARTBEAT_CRON_SCHEDULE = "* * * * *";
4
+ var JUNIOR_CONVERSATION_WORK_CALLBACK_ROUTE = "/api/internal/agent/continue";
5
+ var JUNIOR_PLUGIN_TASK_CALLBACK_ROUTE = "/api/internal/plugin/tasks";
6
+ var LEGACY_JUNIOR_CONVERSATION_WORK_FUNCTION = "api/internal/agent/continue.ts";
7
+ function toOptionalTrimmed(value) {
8
+ const trimmed = value?.trim();
9
+ return trimmed ? trimmed : void 0;
10
+ }
11
+ function getDeploymentServiceVersion() {
12
+ return toOptionalTrimmed(process.env.SENTRY_RELEASE) ?? toOptionalTrimmed(process.env.VERCEL_GIT_COMMIT_SHA);
13
+ }
14
+ function getDeploymentTelemetryAttributes() {
15
+ const attributes = {};
16
+ const serviceVersion = getDeploymentServiceVersion();
17
+ const deploymentId = toOptionalTrimmed(process.env.VERCEL_DEPLOYMENT_ID);
18
+ if (serviceVersion) {
19
+ attributes["service.version"] = serviceVersion;
20
+ }
21
+ if (deploymentId) {
22
+ attributes["deployment.id"] = deploymentId;
23
+ }
24
+ return attributes;
25
+ }
26
+
27
+ // src/chat/slack/timestamp.ts
28
+ import { z } from "zod";
29
+ var slackMessageTsSchema = z.string().trim().regex(/^\d+(?:\.\d+)?$/).brand();
30
+ function parseSlackMessageTs(value) {
31
+ const parsed = slackMessageTsSchema.safeParse(value);
32
+ return parsed.success ? parsed.data : void 0;
33
+ }
34
+
35
+ // src/chat/slack/ids.ts
36
+ import { z as z2 } from "zod";
37
+ var slackChannelIdSchema = z2.string().regex(/^[CDG][A-Z0-9]+$/).brand();
38
+ var slackTeamIdSchema = z2.string().regex(/^T[A-Z0-9]+$/).brand();
39
+ var slackUserIdSchema = z2.string().regex(/^[UW][A-Z0-9]+$/).brand();
40
+ function slackChannelReferenceCandidate(value) {
41
+ const trimmed = value.trim();
42
+ if (!trimmed.startsWith("slack:")) {
43
+ return trimmed;
44
+ }
45
+ const parts = trimmed.split(":");
46
+ if (parts.length === 2) {
47
+ return parts[1]?.trim() ?? "";
48
+ }
49
+ if (parts.length === 3 && parseSlackMessageTs(parts[2])) {
50
+ return parts[1]?.trim() ?? "";
51
+ }
52
+ return "";
53
+ }
54
+ function parseSlackChannelId(value) {
55
+ if (typeof value !== "string") return void 0;
56
+ const parsed = slackChannelIdSchema.safeParse(value.trim());
57
+ return parsed.success ? parsed.data : void 0;
58
+ }
59
+ function parseSlackChannelReferenceId(value) {
60
+ if (typeof value !== "string") return void 0;
61
+ const parsed = slackChannelIdSchema.safeParse(
62
+ slackChannelReferenceCandidate(value)
63
+ );
64
+ return parsed.success ? parsed.data : void 0;
65
+ }
66
+ function parseSlackTeamId(value) {
67
+ if (typeof value !== "string") return void 0;
68
+ const parsed = slackTeamIdSchema.safeParse(value.trim());
69
+ return parsed.success ? parsed.data : void 0;
70
+ }
71
+ function parseSlackUserId(value) {
72
+ if (typeof value !== "string") return void 0;
73
+ const parsed = slackUserIdSchema.safeParse(value.trim());
74
+ return parsed.success ? parsed.data : void 0;
75
+ }
76
+
77
+ export {
78
+ JUNIOR_HEARTBEAT_ROUTE,
79
+ JUNIOR_HEARTBEAT_CRON_SCHEDULE,
80
+ JUNIOR_CONVERSATION_WORK_CALLBACK_ROUTE,
81
+ JUNIOR_PLUGIN_TASK_CALLBACK_ROUTE,
82
+ LEGACY_JUNIOR_CONVERSATION_WORK_FUNCTION,
83
+ getDeploymentServiceVersion,
84
+ getDeploymentTelemetryAttributes,
85
+ parseSlackMessageTs,
86
+ parseSlackChannelId,
87
+ parseSlackChannelReferenceId,
88
+ parseSlackTeamId,
89
+ parseSlackUserId
90
+ };
@@ -1,11 +1,11 @@
1
1
  import {
2
2
  getStateAdapter
3
- } from "./chunk-YPAE5RH3.js";
3
+ } from "./chunk-RS6ANWVT.js";
4
4
  import {
5
5
  logException,
6
6
  logInfo,
7
7
  logWarn
8
- } from "./chunk-VMBZFPZM.js";
8
+ } from "./chunk-ZUK7BL63.js";
9
9
 
10
10
  // src/chat/plugins/logging.ts
11
11
  function createPluginLogger(plugin) {
@@ -4,7 +4,7 @@ import {
4
4
  import {
5
5
  destinationKey,
6
6
  parseDestination
7
- } from "./chunk-AHLSXMOU.js";
7
+ } from "./chunk-GHGPTPBL.js";
8
8
 
9
9
  // src/chat/task-execution/queue-signing.ts
10
10
  import { createHmac, timingSafeEqual } from "crypto";
@@ -0,0 +1,16 @@
1
+ // src/chat/coerce.ts
2
+ function toOptionalString(value) {
3
+ return typeof value === "string" && value.trim() ? value : void 0;
4
+ }
5
+ function toOptionalNumber(value) {
6
+ return typeof value === "number" && Number.isFinite(value) ? value : void 0;
7
+ }
8
+ function isRecord(value) {
9
+ return typeof value === "object" && value !== null;
10
+ }
11
+
12
+ export {
13
+ toOptionalString,
14
+ toOptionalNumber,
15
+ isRecord
16
+ };