@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.
- package/README.md +16 -5
- package/dist/{agent-hooks-RIJ5TSWP.js → agent-hooks-MXAF7RQL.js} +10 -10
- package/dist/api/people/list.js +8 -8
- package/dist/api/people/profile.js +8 -8
- package/dist/api-reference.d.ts +1 -1
- package/dist/app.js +716 -732
- package/dist/{catalog-runtime-MW7XERSU.js → catalog-runtime-DXE6NXHT.js} +5 -5
- package/dist/chat/agent/index.d.ts +4 -0
- package/dist/chat/agent/prompt.d.ts +78 -0
- package/dist/chat/{respond.d.ts → agent/request.d.ts} +98 -55
- package/dist/chat/agent/resume.d.ts +65 -0
- package/dist/chat/agent/sandbox.d.ts +15 -0
- package/dist/chat/agent/session.d.ts +20 -0
- package/dist/chat/agent/skills.d.ts +26 -0
- package/dist/chat/agent/tools.d.ts +78 -0
- package/dist/chat/agent-dispatch/runner.d.ts +3 -5
- package/dist/chat/app/production.d.ts +3 -1
- package/dist/chat/app/services.d.ts +1 -4
- package/dist/chat/logging.d.ts +2 -0
- package/dist/chat/mcp/tool-manager.d.ts +1 -6
- package/dist/chat/pi/messages.d.ts +18 -2
- package/dist/chat/pi/transcript.d.ts +31 -0
- package/dist/chat/plugins/agent-hooks.d.ts +2 -2
- package/dist/chat/prompt.d.ts +1 -1
- package/dist/chat/runtime/agent-continue-runner.d.ts +5 -5
- package/dist/chat/runtime/agent-run-outcome.d.ts +21 -0
- package/dist/chat/runtime/agent-runner.d.ts +11 -0
- package/dist/chat/runtime/delivered-turn-state.d.ts +2 -2
- package/dist/chat/runtime/generated-artifacts.d.ts +16 -0
- package/dist/chat/runtime/reply-executor.d.ts +2 -2
- package/dist/chat/runtime/slack-resume.d.ts +21 -12
- package/dist/chat/runtime/turn.d.ts +5 -39
- package/dist/chat/services/reply-delivery-plan.d.ts +0 -8
- package/dist/chat/services/turn-failure-response.d.ts +4 -4
- package/dist/chat/services/turn-result.d.ts +4 -7
- package/dist/chat/slack/channel.d.ts +9 -5
- package/dist/chat/slack/client.d.ts +3 -1
- package/dist/chat/slack/context.d.ts +17 -5
- package/dist/chat/slack/id-param.d.ts +25 -0
- package/dist/chat/slack/ids.d.ts +18 -4
- package/dist/chat/slack/outbound.d.ts +16 -0
- package/dist/chat/slack/output.d.ts +3 -3
- package/dist/chat/slack/reply.d.ts +4 -7
- package/dist/chat/slack/timestamp-param.d.ts +25 -0
- package/dist/chat/slack/tools/canvas/context.d.ts +18 -0
- package/dist/chat/slack/tools/canvas/create.d.ts +4 -0
- package/dist/chat/slack/tools/canvas/edit.d.ts +3 -0
- package/dist/chat/slack/tools/canvas/read.d.ts +6 -0
- package/dist/chat/slack/tools/canvas/write.d.ts +3 -0
- package/dist/chat/{tools/slack → slack/tools}/channel-access.d.ts +4 -3
- package/dist/chat/{tools → slack/tools}/channel-capabilities.d.ts +2 -0
- package/dist/chat/slack/tools/channel-list-messages.d.ts +3 -0
- package/dist/chat/{tools/slack → slack/tools}/context.d.ts +5 -4
- package/dist/chat/slack/tools/list/add-items.d.ts +3 -0
- package/dist/chat/{tools/slack/lists.d.ts → slack/tools/list/api.d.ts} +2 -1
- package/dist/chat/slack/tools/list/create.d.ts +3 -0
- package/dist/chat/slack/tools/list/get-items.d.ts +3 -0
- package/dist/chat/slack/tools/list/update-item.d.ts +3 -0
- package/dist/chat/slack/tools/message-add-reaction.d.ts +4 -0
- package/dist/chat/slack/tools/send-message.d.ts +11 -0
- package/dist/chat/{tools/slack → slack/tools}/slack-message-url.d.ts +5 -5
- package/dist/chat/slack/tools/thread-read.d.ts +6 -0
- package/dist/chat/slack/tools/user-lookup.d.ts +2 -0
- package/dist/chat/slack/users.d.ts +2 -1
- package/dist/chat/{services → slack}/vision-context.d.ts +4 -2
- package/dist/chat/state/session-log.d.ts +1 -1
- package/dist/chat/tool-exposure.d.ts +10 -0
- package/dist/chat/tool-support/catalog-tool-call.d.ts +10 -0
- package/dist/chat/{tools/execution → tool-support}/normalize-result.d.ts +4 -1
- package/dist/chat/{tools/agent-tools.d.ts → tool-support/pi-tool-adapter.d.ts} +3 -9
- package/dist/chat/tool-support/schema-summary.d.ts +2 -0
- package/dist/chat/{tools → tool-support}/skill/mcp-tool-summary.d.ts +0 -6
- package/dist/chat/tool-support/structured-result.d.ts +73 -0
- package/dist/chat/tool-support/text-range-result.d.ts +58 -0
- package/dist/chat/tool-support/tool-execution-report.d.ts +7 -0
- package/dist/chat/tool-support/zod-tool.d.ts +27 -0
- package/dist/chat/tools/advisor/tool.d.ts +9 -18
- package/dist/chat/tools/definition.d.ts +56 -9
- package/dist/chat/tools/execute-tool.d.ts +3 -0
- package/dist/chat/tools/index.d.ts +3 -2
- package/dist/chat/tools/resource-events.d.ts +3 -13
- package/dist/chat/tools/runtime/report-progress.d.ts +1 -3
- package/dist/chat/tools/sandbox/bash.d.ts +1 -4
- package/dist/chat/tools/sandbox/edit-file.d.ts +25 -7
- package/dist/chat/tools/sandbox/file-uploads.d.ts +30 -0
- package/dist/chat/tools/sandbox/file-utils.d.ts +10 -1
- package/dist/chat/tools/sandbox/find-files.d.ts +12 -11
- package/dist/chat/tools/sandbox/grep.d.ts +18 -12
- package/dist/chat/tools/sandbox/list-dir.d.ts +15 -7
- package/dist/chat/tools/sandbox/read-file.d.ts +2 -31
- package/dist/chat/tools/sandbox/write-file.d.ts +1 -4
- package/dist/chat/tools/search-tools.d.ts +4 -0
- package/dist/chat/tools/skill/call-mcp-tool.d.ts +1 -4
- package/dist/chat/tools/skill/load-skill.d.ts +4 -5
- package/dist/chat/tools/skill/search-mcp-tools.d.ts +1 -5
- package/dist/chat/tools/system-time.d.ts +1 -1
- package/dist/chat/tools/types.d.ts +15 -5
- package/dist/chat/tools/web/fetch-content.d.ts +4 -2
- package/dist/chat/tools/web/fetch-tool.d.ts +4 -4
- package/dist/chat/tools/web/image-generate.d.ts +4 -3
- package/dist/chat/tools/web/search.d.ts +1 -4
- package/dist/{chunk-4IXHIV37.js → chunk-2S7M37HY.js} +6 -8
- package/dist/{chunk-L7OHKDOX.js → chunk-3MPOMK3K.js} +58 -7
- package/dist/{chunk-V6XDCS3X.js → chunk-5GBUZI6M.js} +4 -4
- package/dist/{chunk-7ES37H6U.js → chunk-AN2437E3.js} +4 -4
- package/dist/chunk-AOISHLSF.js +747 -0
- package/dist/{chunk-NYJLQI42.js → chunk-BKSZL4QO.js} +11257 -11957
- package/dist/{chunk-XS6NLQPA.js → chunk-DACFZ5CI.js} +474 -33
- package/dist/chunk-GCWD2VHP.js +1216 -0
- package/dist/chunk-GHGPTPBL.js +53 -0
- package/dist/{chunk-S35CPNPT.js → chunk-HXL2ZV74.js} +40 -216
- package/dist/{chunk-PBV4ZIVM.js → chunk-IRRMABQD.js} +1 -1
- package/dist/{chunk-2DPZRS3B.js → chunk-IX76WFJV.js} +8 -8
- package/dist/{chunk-66NX7MNW.js → chunk-KC42JAAQ.js} +1 -1
- package/dist/chunk-LFLTJQVR.js +90 -0
- package/dist/{chunk-IATAYWFU.js → chunk-NW7AXDA5.js} +2 -2
- package/dist/{chunk-F22AM3OW.js → chunk-NYWPISSO.js} +1 -1
- package/dist/chunk-OB42YVAE.js +16 -0
- package/dist/chunk-ONFOWI2D.js +955 -0
- package/dist/chunk-PHZHJTCK.js +1062 -0
- package/dist/{chunk-6UPQ5GTJ.js → chunk-QCKGI74V.js} +7 -7
- package/dist/{chunk-YPAE5RH3.js → chunk-RS6ANWVT.js} +1 -1
- package/dist/{chunk-C5NCV3OB.js → chunk-TYUXD3FN.js} +1 -1
- package/dist/{chunk-KBFQXJL4.js → chunk-XP7F4LYB.js} +5 -7
- package/dist/{chunk-VMBZFPZM.js → chunk-ZUK7BL63.js} +187 -9
- package/dist/cli/chat.js +55 -40
- package/dist/cli/check.js +6 -6
- package/dist/cli/init.js +30 -36
- package/dist/cli/plugins.js +16 -16
- package/dist/cli/snapshot-warmup.js +9 -9
- package/dist/cli/upgrade.js +21 -21
- package/dist/db-CXI7PR5U.js +18 -0
- package/dist/handlers/agent-dispatch.d.ts +3 -3
- package/dist/handlers/mcp-oauth-callback.d.ts +3 -3
- package/dist/handlers/oauth-callback.d.ts +3 -3
- package/dist/instrumentation.js +6 -5
- package/dist/nitro.js +3 -7
- package/dist/reporting.js +23 -25
- package/dist/{runner-BCRF2FCI.js → runner-FKL3RAHA.js} +89 -77
- package/dist/{validation-FMJO3L5P.js → validation-I7GD2YWS.js} +6 -6
- package/package.json +6 -6
- package/dist/chat/respond-helpers.d.ts +0 -82
- package/dist/chat/services/attachment-claims.d.ts +0 -2
- package/dist/chat/services/channel-intent.d.ts +0 -2
- package/dist/chat/tools/sandbox/attach-file.d.ts +0 -7
- package/dist/chat/tools/slack/canvas-tools.d.ts +0 -30
- package/dist/chat/tools/slack/channel-list-messages.d.ts +0 -9
- package/dist/chat/tools/slack/channel-post-message.d.ts +0 -5
- package/dist/chat/tools/slack/list-tools.d.ts +0 -21
- package/dist/chat/tools/slack/message-add-reaction.d.ts +0 -5
- package/dist/chat/tools/slack/thread-read.d.ts +0 -12
- package/dist/chat/tools/slack/user-lookup.d.ts +0 -8
- package/dist/chunk-AHLSXMOU.js +0 -506
- package/dist/chunk-FTMXFBDC.js +0 -49
- package/dist/chunk-KBSLCOGE.js +0 -2226
- package/dist/chunk-KQKIA4CU.js +0 -186
- package/dist/db-37HOGLI7.js +0 -18
- /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-
|
|
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-
|
|
16
|
-
|
|
17
|
-
// src/chat/xml.ts
|
|
18
|
-
function escapeXml(value) {
|
|
19
|
-
return value.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">").replaceAll('"', """).replaceAll("'", "'");
|
|
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(""", '"').replaceAll("'", "'").replaceAll(">", ">").replaceAll("<", "<").replaceAll("&", "&");
|
|
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/
|
|
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
|
|
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
|
|
207
|
-
return part !== null && typeof part === "object" && part.type === "text" && typeof part.text === "string" && part.text.startsWith(
|
|
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
|
|
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
|
|
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
|
-
|
|
901
|
-
isExecutionEscapeResponse,
|
|
902
|
-
isRawToolPayloadResponse,
|
|
903
|
-
toObservablePromptPart,
|
|
904
|
-
summarizeMessageText,
|
|
905
|
-
buildUserTurnText,
|
|
906
|
-
encodeNonImageAttachmentForPrompt,
|
|
732
|
+
isAssistantMessage,
|
|
907
733
|
isToolResultMessage,
|
|
908
|
-
normalizeToolNameFromResult,
|
|
909
734
|
isToolResultError,
|
|
910
|
-
|
|
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,
|
|
@@ -1,25 +1,25 @@
|
|
|
1
1
|
import {
|
|
2
2
|
JUNIOR_THREAD_STATE_TTL_MS
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-KC42JAAQ.js";
|
|
4
4
|
import {
|
|
5
5
|
getDefaultRedisStateAdapterFor,
|
|
6
6
|
getStateAdapter
|
|
7
|
-
} from "./chunk-
|
|
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-
|
|
12
|
-
import {
|
|
13
|
-
getChatConfig
|
|
14
|
-
} from "./chunk-S35CPNPT.js";
|
|
14
|
+
} from "./chunk-GHGPTPBL.js";
|
|
15
15
|
import {
|
|
16
16
|
parseStoredSlackRequester
|
|
17
|
-
} from "./chunk-
|
|
17
|
+
} from "./chunk-ZUK7BL63.js";
|
|
18
18
|
import {
|
|
19
19
|
isRecord,
|
|
20
20
|
toOptionalNumber,
|
|
21
21
|
toOptionalString
|
|
22
|
-
} from "./chunk-
|
|
22
|
+
} from "./chunk-OB42YVAE.js";
|
|
23
23
|
|
|
24
24
|
// src/chat/task-execution/state.ts
|
|
25
25
|
import { randomUUID } from "crypto";
|
|
@@ -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-
|
|
3
|
+
} from "./chunk-RS6ANWVT.js";
|
|
4
4
|
import {
|
|
5
5
|
logException,
|
|
6
6
|
logInfo,
|
|
7
7
|
logWarn
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-ZUK7BL63.js";
|
|
9
9
|
|
|
10
10
|
// src/chat/plugins/logging.ts
|
|
11
11
|
function createPluginLogger(plugin) {
|
|
@@ -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
|
+
};
|