@sentry/junior 0.124.2 → 0.126.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/dist/{agent-hooks-HJQTURNC.js → agent-hooks-HDSNWDQM.js} +9 -10
- package/dist/api/conversations/auxiliary-costs.d.ts +6 -0
- package/dist/api/conversations/detail.d.ts +10 -0
- package/dist/api/conversations/list.d.ts +11 -0
- package/dist/api/conversations/projection.d.ts +2 -1
- package/dist/api/locations/detail.d.ts +20 -0
- package/dist/api/people/profile.d.ts +10 -0
- package/dist/api/people/shared.d.ts +36 -0
- package/dist/api/plugin-reports.d.ts +1 -0
- package/dist/api/schema/conversation.d.ts +40 -0
- package/dist/api/schema/location.d.ts +10 -0
- package/dist/api/schema/person.d.ts +10 -0
- package/dist/api/schema.d.ts +2 -2
- package/dist/api/schema.js +4 -2
- package/dist/api.js +339 -180
- package/dist/app.js +52 -41
- package/dist/{catalog-runtime-F356WNZS.js → catalog-runtime-BDC3UWPG.js} +5 -6
- package/dist/chat/agent/prompt.d.ts +1 -0
- package/dist/chat/agent/request.d.ts +2 -1
- package/dist/chat/agent/resume.d.ts +2 -0
- package/dist/chat/agent-dispatch/types.d.ts +2 -1
- package/dist/chat/conversation-privacy.d.ts +7 -12
- package/dist/chat/conversations/destination-visibility.d.ts +7 -0
- package/dist/chat/conversations/history.d.ts +4 -2
- package/dist/chat/conversations/sql/conversation-row.d.ts +7 -4
- package/dist/chat/conversations/sql/store.d.ts +2 -1
- package/dist/chat/conversations/store.d.ts +12 -4
- package/dist/chat/pi/client.d.ts +1 -0
- package/dist/chat/plugins/agent-hooks.d.ts +1 -0
- package/dist/chat/plugins/conversation-event-stats.d.ts +3 -0
- package/dist/chat/plugins/conversation-events.d.ts +1 -1
- package/dist/chat/services/turn-session-record.d.ts +4 -1
- package/dist/chat/slack/conversation-context.d.ts +4 -7
- package/dist/chat/slack/footer.d.ts +10 -1
- package/dist/chat/slack/reply.d.ts +9 -2
- package/dist/chat/slack/source-link.d.ts +5 -0
- package/dist/chat/source.d.ts +16 -0
- package/dist/chat/state/turn-session.d.ts +2 -6
- package/dist/{chunk-L7EZRQ2J.js → chunk-4PV73JHH.js} +11 -13
- package/dist/{chunk-IXTIJQ7Z.js → chunk-6KWO5DU3.js} +167 -20
- package/dist/{chunk-AYQZCJZJ.js → chunk-6ZBSTNYN.js} +14 -0
- package/dist/chunk-72SDEHFP.js +102 -0
- package/dist/{chunk-SMTAXLX4.js → chunk-ACJZZY5W.js} +2 -2
- package/dist/{chunk-KYKLQYSU.js → chunk-APYVVX2Y.js} +1 -1
- package/dist/{chunk-EOSC6JOC.js → chunk-EFQX6XBW.js} +1 -1
- package/dist/{chunk-IMLJE2NY.js → chunk-EQMSKORN.js} +2 -2
- package/dist/{chunk-ZO6E537B.js → chunk-GHNO2WUH.js} +1 -1
- package/dist/{chunk-WKBPFZ25.js → chunk-GK55KLEH.js} +1 -1
- package/dist/{chunk-PR3M62LK.js → chunk-HX236W2U.js} +6 -4
- package/dist/{chunk-7LDOW4QA.js → chunk-JFW62B3Y.js} +1 -1
- package/dist/{chunk-ASK74NM6.js → chunk-JP2ZOSQK.js} +15 -5
- package/dist/{chunk-NNKVDYXN.js → chunk-KISG7E24.js} +57 -36
- package/dist/{chunk-DW6SLS5F.js → chunk-KP7E267S.js} +83 -24
- package/dist/{chunk-VMRKIKGO.js → chunk-LCRWDMCH.js} +1 -1
- package/dist/{chunk-AQKVWIPR.js → chunk-LIDEU7QS.js} +4 -4
- package/dist/{chunk-GCGJGSQL.js → chunk-S4PUICSB.js} +2 -0
- package/dist/{chunk-SS7MAJF5.js → chunk-TUHUIBDX.js} +60 -40
- package/dist/{chunk-PE44LDDQ.js → chunk-UTL3MHPC.js} +1 -0
- package/dist/{chunk-S7G34U75.js → chunk-VUBUFT66.js} +5 -121
- package/dist/{chunk-CMYDYVOD.js → chunk-WRH7DWFO.js} +15 -12
- package/dist/{chunk-574YK7QW.js → chunk-XLIAQRDI.js} +25 -10
- package/dist/{chunk-7P7YVJKH.js → chunk-XVKJJXHF.js} +17 -15
- package/dist/{chunk-4JW3YNQZ.js → chunk-YMSVBWBY.js} +9 -11
- package/dist/cli/chat.js +25 -25
- package/dist/cli/check.js +6 -7
- package/dist/cli/plugins.js +12 -13
- package/dist/cli/snapshot-create.js +9 -10
- package/dist/cli/upgrade.js +7 -8
- package/dist/db/schema/conversations.d.ts +20 -0
- package/dist/db/schema.d.ts +19 -0
- package/dist/{db-4SU2HJSV.js → db-AZB6AGJL.js} +7 -8
- package/dist/instrumentation.js +4 -5
- package/dist/nitro.js +2 -2
- package/dist/{oauth-callback-server-MMCH5QV6.js → oauth-callback-server-XK4QJLPZ.js} +18 -19
- package/dist/reporting-schema.d.ts +2 -0
- package/dist/{runner-ZDSNVGYA.js → runner-DSGDSATN.js} +13 -15
- package/dist/{skills-7G7LBHLK.js → skills-CO6E3BQJ.js} +6 -7
- package/dist/{validation-2ETDADPB.js → validation-IHLISKM5.js} +6 -7
- package/dist/version.js +1 -1
- package/migrations/0013_conversation_session_source.sql +38 -0
- package/migrations/0014_source_visibility.sql +8 -0
- package/migrations/meta/0013_snapshot.json +1250 -0
- package/migrations/meta/0014_snapshot.json +1201 -0
- package/migrations/meta/_journal.json +14 -0
- package/package.json +6 -6
- package/dist/chunk-BA5KHLPQ.js +0 -55
- package/dist/chunk-OB42YVAE.js +0 -16
|
@@ -30,7 +30,7 @@ import {
|
|
|
30
30
|
toMcpProviderError,
|
|
31
31
|
toolInvocationDestination,
|
|
32
32
|
uploadFilesToConversation
|
|
33
|
-
} from "./chunk-
|
|
33
|
+
} from "./chunk-4PV73JHH.js";
|
|
34
34
|
import {
|
|
35
35
|
CooperativeTurnYieldError,
|
|
36
36
|
JUNIOR_THREAD_STATE_TTL_MS,
|
|
@@ -80,7 +80,7 @@ import {
|
|
|
80
80
|
stripRuntimeTurnContext,
|
|
81
81
|
trimTrailingAssistantMessages,
|
|
82
82
|
updateConversationStats
|
|
83
|
-
} from "./chunk-
|
|
83
|
+
} from "./chunk-WRH7DWFO.js";
|
|
84
84
|
import {
|
|
85
85
|
parseSandboxEgressAuthRequiredSignal,
|
|
86
86
|
parseSandboxEgressPermissionDeniedSignal,
|
|
@@ -104,14 +104,17 @@ import {
|
|
|
104
104
|
runNonInteractiveCommand,
|
|
105
105
|
throwSandboxOperationError,
|
|
106
106
|
wrapSandboxSetupError
|
|
107
|
-
} from "./chunk-
|
|
107
|
+
} from "./chunk-LIDEU7QS.js";
|
|
108
108
|
import {
|
|
109
109
|
incrementStat
|
|
110
|
-
} from "./chunk-
|
|
110
|
+
} from "./chunk-EQMSKORN.js";
|
|
111
|
+
import {
|
|
112
|
+
parseSlackThreadId
|
|
113
|
+
} from "./chunk-72SDEHFP.js";
|
|
111
114
|
import {
|
|
112
115
|
addAgentTurnUsage,
|
|
113
116
|
hasAgentTurnUsage
|
|
114
|
-
} from "./chunk-
|
|
117
|
+
} from "./chunk-HX236W2U.js";
|
|
115
118
|
import {
|
|
116
119
|
privateTraceResultAttributes
|
|
117
120
|
} from "./chunk-UIE3R5XU.js";
|
|
@@ -129,7 +132,7 @@ import {
|
|
|
129
132
|
normalizeSlackConversationId,
|
|
130
133
|
resolveChannelCapabilities,
|
|
131
134
|
withSlackRetries
|
|
132
|
-
} from "./chunk-
|
|
135
|
+
} from "./chunk-6KWO5DU3.js";
|
|
133
136
|
import {
|
|
134
137
|
KNOWN_CONVERSATION_EVENT_TYPES,
|
|
135
138
|
contextProvenance,
|
|
@@ -139,7 +142,7 @@ import {
|
|
|
139
142
|
instructionActors,
|
|
140
143
|
instructionProvenanceFor,
|
|
141
144
|
sameActorIdentity
|
|
142
|
-
} from "./chunk-
|
|
145
|
+
} from "./chunk-KP7E267S.js";
|
|
143
146
|
import {
|
|
144
147
|
SANDBOX_DATA_ROOT,
|
|
145
148
|
SANDBOX_SKILLS_ROOT,
|
|
@@ -149,7 +152,7 @@ import {
|
|
|
149
152
|
sandboxSkillFile,
|
|
150
153
|
sandboxSkillPathResolution,
|
|
151
154
|
sleep
|
|
152
|
-
} from "./chunk-
|
|
155
|
+
} from "./chunk-APYVVX2Y.js";
|
|
153
156
|
import {
|
|
154
157
|
ACTIVE_TURN_COMPACTION_SUMMARY_PREFIX,
|
|
155
158
|
COMPACTION_SUMMARY_PREFIX,
|
|
@@ -183,10 +186,9 @@ import {
|
|
|
183
186
|
renderCurrentInstruction,
|
|
184
187
|
resolveGatewayModel,
|
|
185
188
|
unwrapCurrentInstruction
|
|
186
|
-
} from "./chunk-
|
|
189
|
+
} from "./chunk-XLIAQRDI.js";
|
|
187
190
|
import {
|
|
188
191
|
canExposeConversationPayload,
|
|
189
|
-
parseSlackThreadId,
|
|
190
192
|
resolveConversationPrivacy,
|
|
191
193
|
runWithConversationPrivacy,
|
|
192
194
|
toCanonicalInputMessage,
|
|
@@ -194,16 +196,16 @@ import {
|
|
|
194
196
|
toGenAiMessagesTraceAttributes,
|
|
195
197
|
toGenAiPayloadMetadata,
|
|
196
198
|
toGenAiPayloadTraceAttributes
|
|
197
|
-
} from "./chunk-
|
|
199
|
+
} from "./chunk-VUBUFT66.js";
|
|
198
200
|
import {
|
|
199
201
|
discoverSkills,
|
|
200
202
|
findSkillByName,
|
|
201
203
|
loadSkillsByName,
|
|
202
204
|
parseSkillInvocation
|
|
203
|
-
} from "./chunk-
|
|
205
|
+
} from "./chunk-ACJZZY5W.js";
|
|
204
206
|
import {
|
|
205
207
|
pluginCatalogRuntime
|
|
206
|
-
} from "./chunk-
|
|
208
|
+
} from "./chunk-GHNO2WUH.js";
|
|
207
209
|
import {
|
|
208
210
|
CredentialUnavailableError,
|
|
209
211
|
OAuthProviderError,
|
|
@@ -211,13 +213,18 @@ import {
|
|
|
211
213
|
getOAuthProviderErrorAttributes,
|
|
212
214
|
resolveAuthTokenPlaceholder,
|
|
213
215
|
resolvePluginCommandEnv
|
|
214
|
-
} from "./chunk-
|
|
216
|
+
} from "./chunk-EFQX6XBW.js";
|
|
215
217
|
import {
|
|
216
218
|
credentialUserSubjectId
|
|
217
219
|
} from "./chunk-W3U3YQYI.js";
|
|
218
220
|
import {
|
|
219
221
|
isUserActor
|
|
220
222
|
} from "./chunk-HZF5P5UN.js";
|
|
223
|
+
import {
|
|
224
|
+
parseSlackChannelId,
|
|
225
|
+
parseSlackMessageTs,
|
|
226
|
+
parseSlackUserId
|
|
227
|
+
} from "./chunk-F3B2YJ76.js";
|
|
221
228
|
import {
|
|
222
229
|
extractGenAiUsageAttributes,
|
|
223
230
|
extractGenAiUsageSummary,
|
|
@@ -235,12 +242,7 @@ import {
|
|
|
235
242
|
summarizeMessageText,
|
|
236
243
|
withLogContext,
|
|
237
244
|
withSpan
|
|
238
|
-
} from "./chunk-
|
|
239
|
-
import {
|
|
240
|
-
parseSlackChannelId,
|
|
241
|
-
parseSlackMessageTs,
|
|
242
|
-
parseSlackUserId
|
|
243
|
-
} from "./chunk-F3B2YJ76.js";
|
|
245
|
+
} from "./chunk-JP2ZOSQK.js";
|
|
244
246
|
import {
|
|
245
247
|
startInactiveSpan,
|
|
246
248
|
withActiveSpan
|
|
@@ -1259,6 +1261,21 @@ var AuthorizationFlowDisabledError = class extends Error {
|
|
|
1259
1261
|
}
|
|
1260
1262
|
};
|
|
1261
1263
|
|
|
1264
|
+
// src/chat/conversations/destination-visibility.ts
|
|
1265
|
+
async function resolveDestinationVisibility(args) {
|
|
1266
|
+
if (args.visibility) {
|
|
1267
|
+
return args.visibility;
|
|
1268
|
+
}
|
|
1269
|
+
if (args.destination.platform === "local") {
|
|
1270
|
+
return "private";
|
|
1271
|
+
}
|
|
1272
|
+
return await getConversationStore().getDestinationVisibility({
|
|
1273
|
+
provider: "slack",
|
|
1274
|
+
providerDestinationId: args.destination.channelId,
|
|
1275
|
+
providerTenantId: args.destination.teamId
|
|
1276
|
+
});
|
|
1277
|
+
}
|
|
1278
|
+
|
|
1262
1279
|
// src/chat/tool-support/action-review-history.ts
|
|
1263
1280
|
import { z as z3 } from "zod";
|
|
1264
1281
|
var MAX_VISIBLE_HISTORY_CHARS = 12e3;
|
|
@@ -1693,10 +1710,7 @@ function formatAvailableSkillsForPrompt(skills) {
|
|
|
1693
1710
|
);
|
|
1694
1711
|
const sections = [];
|
|
1695
1712
|
if (autoSelectable.length > 0) {
|
|
1696
|
-
const available = [
|
|
1697
|
-
"<available-skills>",
|
|
1698
|
-
"Scan before answering. Load the most specific matching skill; do not answer from memory when a skill fits. A request that names a skill, plugin, provider, or account matching a skill name is a skill match. If none fits, do not load a skill."
|
|
1699
|
-
];
|
|
1713
|
+
const available = ["<available-skills>"];
|
|
1700
1714
|
for (const skill of autoSelectable) {
|
|
1701
1715
|
available.push(...formatSkillEntry(skill));
|
|
1702
1716
|
}
|
|
@@ -1817,7 +1831,7 @@ var TOOL_CALL_STYLE_RULES = [
|
|
|
1817
1831
|
];
|
|
1818
1832
|
var SKILL_POLICY_RULES = [
|
|
1819
1833
|
"- A `<skill>` block in the current user turn is already loaded. Follow its instructions directly and do not call `loadSkill` for that skill.",
|
|
1820
|
-
"- Otherwise,
|
|
1834
|
+
"- Otherwise, scan `<available-skills>` before acting. Load the most specific skill whose description matches the request; do not answer from memory when one fits. Only call `loadSkill` with an exact listed `<name>`; if none fits, do not load a skill.",
|
|
1821
1835
|
"- Load one skill at a time. After `loadSkill`, follow the instructions returned by that tool result."
|
|
1822
1836
|
];
|
|
1823
1837
|
var EXECUTION_CONTRACT_RULES = [
|
|
@@ -2374,7 +2388,8 @@ async function assemblePrompt(args) {
|
|
|
2374
2388
|
);
|
|
2375
2389
|
const baseInstructions = [buildSystemPrompt({ source }), pluginSystemPrompt].filter((section) => Boolean(section)).join("\n\n");
|
|
2376
2390
|
const pluginUserPromptContributions = !shouldPromptAgent || replayedPromptContent ? [] : await getPluginUserPromptContributions({
|
|
2377
|
-
context: args.toolRuntimeContext
|
|
2391
|
+
context: args.toolRuntimeContext,
|
|
2392
|
+
turnId: args.turnId
|
|
2378
2393
|
});
|
|
2379
2394
|
const turnContextPrompt = needsBootstrapContextForPrompt || pluginUserPromptContributions.length > 0 ? buildTurnContextPrompt({
|
|
2380
2395
|
availableSkills: args.availableSkills,
|
|
@@ -10774,11 +10789,9 @@ function assertCanQueryConversationEvents(args) {
|
|
|
10774
10789
|
if (targetConversationId === accessScope.currentConversationId || targetRootConversationId !== void 0 && targetRootConversationId === accessScope.currentRootConversationId) {
|
|
10775
10790
|
return;
|
|
10776
10791
|
}
|
|
10777
|
-
const publicPayloadAllowed = canExposeConversationPayload(
|
|
10778
|
-
|
|
10779
|
-
|
|
10780
|
-
...targetDestination?.platform === "slack" ? { channelId: targetDestination.channelId } : {}
|
|
10781
|
-
});
|
|
10792
|
+
const publicPayloadAllowed = canExposeConversationPayload(
|
|
10793
|
+
targetVisibility ? { visibility: targetVisibility } : {}
|
|
10794
|
+
);
|
|
10782
10795
|
if (!publicPayloadAllowed) {
|
|
10783
10796
|
throw new ToolInputError(
|
|
10784
10797
|
`Conversation events are not accessible: ${targetConversationId}`
|
|
@@ -11677,7 +11690,7 @@ function createTools(availableSkills, hooks = {}, context, options = {}) {
|
|
|
11677
11690
|
tools.slackCanvasEdit = createSlackCanvasEditTool(state);
|
|
11678
11691
|
tools.slackCanvasWrite = createSlackCanvasWriteTool(state);
|
|
11679
11692
|
tools.slackThreadRead = createSlackThreadReadTool(slackContext);
|
|
11680
|
-
if (context.conversationId && slackContext.source.
|
|
11693
|
+
if (context.conversationId && slackContext.source.visibility === "public") {
|
|
11681
11694
|
tools.searchConversationHistory = createSlackConversationSearchTool(
|
|
11682
11695
|
{
|
|
11683
11696
|
kind: "public_provider_tenant",
|
|
@@ -14721,6 +14734,7 @@ function createResumeState(args) {
|
|
|
14721
14734
|
channelName: args.channelName,
|
|
14722
14735
|
conversationId: args.conversationId,
|
|
14723
14736
|
destination: args.destination,
|
|
14737
|
+
...args.destinationVisibility ? { destinationVisibility: args.destinationVisibility } : {},
|
|
14724
14738
|
...args.dispatchId ? { dispatchId: args.dispatchId } : {},
|
|
14725
14739
|
source: args.runSource,
|
|
14726
14740
|
sessionId: args.turnId,
|
|
@@ -15408,14 +15422,17 @@ async function executeAgentRun(request, streamFn) {
|
|
|
15408
15422
|
if (!request.routing.destination) {
|
|
15409
15423
|
throw new TypeError("Assistant reply generation requires a destination");
|
|
15410
15424
|
}
|
|
15411
|
-
const
|
|
15425
|
+
const destinationVisibility = await resolveDestinationVisibility({
|
|
15426
|
+
destination: request.routing.destination,
|
|
15427
|
+
visibility: request.routing.destinationVisibility
|
|
15428
|
+
});
|
|
15412
15429
|
const conversationPrivacy = resolveConversationPrivacy({
|
|
15413
|
-
|
|
15414
|
-
conversationId: request.conversationId,
|
|
15415
|
-
// Destination visibility is provider-neutral. Slack event context remains
|
|
15416
|
-
// a compatibility fallback for callers that have not projected it yet.
|
|
15417
|
-
visibility: request.routing.destinationVisibility ?? request.routing.slackConversation?.visibility
|
|
15430
|
+
visibility: destinationVisibility
|
|
15418
15431
|
});
|
|
15432
|
+
const resolvedRequest = destinationVisibility ? {
|
|
15433
|
+
...request,
|
|
15434
|
+
routing: { ...request.routing, destinationVisibility }
|
|
15435
|
+
} : request;
|
|
15419
15436
|
const credentialActor = request.routing.credentialContext?.actor;
|
|
15420
15437
|
const actor = actorFromRouting(request.routing);
|
|
15421
15438
|
const userActor = actor && "userId" in actor ? actor : void 0;
|
|
@@ -15435,9 +15452,9 @@ async function executeAgentRun(request, streamFn) {
|
|
|
15435
15452
|
return withLogContext(
|
|
15436
15453
|
runLogContext,
|
|
15437
15454
|
() => runWithConversationPrivacy(
|
|
15438
|
-
conversationPrivacy
|
|
15455
|
+
conversationPrivacy,
|
|
15439
15456
|
() => executeAgentRunInPrivacyContext(
|
|
15440
|
-
|
|
15457
|
+
resolvedRequest,
|
|
15441
15458
|
conversationPrivacy,
|
|
15442
15459
|
runLogContext,
|
|
15443
15460
|
streamFn
|
|
@@ -15568,6 +15585,7 @@ async function executeAgentRunInPrivacyContext(request, conversationPrivacy, run
|
|
|
15568
15585
|
resume = createResumeState({
|
|
15569
15586
|
channelName: routing.slackConversation?.name,
|
|
15570
15587
|
destination: routing.destination,
|
|
15588
|
+
...routing.destinationVisibility ? { destinationVisibility: routing.destinationVisibility } : {},
|
|
15571
15589
|
...routing.dispatch?.id ? { dispatchId: routing.dispatch.id } : {},
|
|
15572
15590
|
durability,
|
|
15573
15591
|
getLoadedSkillNames: () => loadedSkillNamesForResume,
|
|
@@ -15881,6 +15899,7 @@ async function executeAgentRunInPrivacyContext(request, conversationPrivacy, run
|
|
|
15881
15899
|
resumedFromSessionRecord,
|
|
15882
15900
|
routing,
|
|
15883
15901
|
spanContext,
|
|
15902
|
+
turnId,
|
|
15884
15903
|
toolGuidance: wiring.toolGuidance,
|
|
15885
15904
|
toolRuntimeContext: wiring.toolRuntimeContext,
|
|
15886
15905
|
userContentParts
|
|
@@ -16509,6 +16528,7 @@ export {
|
|
|
16509
16528
|
getConfigDefaults,
|
|
16510
16529
|
shouldEmitDevAgentTrace,
|
|
16511
16530
|
AuthorizationFlowDisabledError,
|
|
16531
|
+
resolveDestinationVisibility,
|
|
16512
16532
|
buildSteeringPiMessage,
|
|
16513
16533
|
SANDBOX_EGRESS_PROXY_PATH,
|
|
16514
16534
|
parseSandboxEgressCredentialToken,
|
|
@@ -1,128 +1,16 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
} from "./chunk-
|
|
4
|
-
import {
|
|
5
|
-
parseSlackChannelId,
|
|
6
|
-
parseSlackMessageTs,
|
|
7
|
-
parseSlackTeamId
|
|
8
|
-
} from "./chunk-F3B2YJ76.js";
|
|
2
|
+
logWarn
|
|
3
|
+
} from "./chunk-JP2ZOSQK.js";
|
|
9
4
|
|
|
10
5
|
// src/chat/conversation-privacy.ts
|
|
11
6
|
import { AsyncLocalStorage } from "async_hooks";
|
|
12
|
-
|
|
13
|
-
// src/chat/slack/context.ts
|
|
14
|
-
import { z } from "zod";
|
|
15
|
-
function toTrimmedSlackString(value) {
|
|
16
|
-
const normalized = toOptionalString(value);
|
|
17
|
-
return normalized?.trim() || void 0;
|
|
18
|
-
}
|
|
19
|
-
var slackMessageEnvelopeSchema = z.object({
|
|
20
|
-
raw: z.unknown().optional()
|
|
21
|
-
});
|
|
22
|
-
var rawSlackMessageSchema = z.object({
|
|
23
|
-
channel: z.unknown().optional(),
|
|
24
|
-
message: z.unknown().optional(),
|
|
25
|
-
team: z.unknown().optional(),
|
|
26
|
-
team_id: z.unknown().optional(),
|
|
27
|
-
thread_ts: z.unknown().optional(),
|
|
28
|
-
ts: z.unknown().optional(),
|
|
29
|
-
user_team: z.unknown().optional()
|
|
30
|
-
});
|
|
31
|
-
var nestedRawSlackMessageSchema = z.object({
|
|
32
|
-
ts: z.unknown().optional()
|
|
33
|
-
});
|
|
34
|
-
function readSlackRawMessageContext(message) {
|
|
35
|
-
const envelope = slackMessageEnvelopeSchema.safeParse(message);
|
|
36
|
-
if (!envelope.success) {
|
|
37
|
-
return void 0;
|
|
38
|
-
}
|
|
39
|
-
const raw = rawSlackMessageSchema.safeParse(envelope.data.raw);
|
|
40
|
-
if (!raw.success) {
|
|
41
|
-
return void 0;
|
|
42
|
-
}
|
|
43
|
-
const nestedMessage = nestedRawSlackMessageSchema.safeParse(raw.data.message);
|
|
44
|
-
const channelId = parseSlackChannelId(raw.data.channel);
|
|
45
|
-
const threadTs = parseSlackMessageTs(raw.data.thread_ts);
|
|
46
|
-
const messageTs = parseSlackMessageTs(raw.data.ts);
|
|
47
|
-
const nestedMessageTs = nestedMessage.success && parseSlackMessageTs(nestedMessage.data.ts);
|
|
48
|
-
const teamId = parseSlackTeamId(raw.data.team_id) ?? parseSlackTeamId(raw.data.team);
|
|
49
|
-
const authorTeamId = parseSlackTeamId(raw.data.user_team);
|
|
50
|
-
return {
|
|
51
|
-
...channelId ? { channelId } : {},
|
|
52
|
-
...threadTs ? { threadTs } : {},
|
|
53
|
-
...messageTs ? { messageTs } : {},
|
|
54
|
-
...nestedMessageTs ? { nestedMessageTs } : {},
|
|
55
|
-
...teamId ? { teamId } : {},
|
|
56
|
-
...authorTeamId ? { authorTeamId } : {}
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
function parseSlackThreadId(threadId) {
|
|
60
|
-
const normalizedThreadId = toTrimmedSlackString(threadId);
|
|
61
|
-
if (!normalizedThreadId) {
|
|
62
|
-
return void 0;
|
|
63
|
-
}
|
|
64
|
-
const parts = normalizedThreadId.split(":");
|
|
65
|
-
if (parts.length !== 3 || parts[0] !== "slack") {
|
|
66
|
-
return void 0;
|
|
67
|
-
}
|
|
68
|
-
const channelId = parseSlackChannelId(parts[1]);
|
|
69
|
-
const threadTs = parseSlackMessageTs(parts[2]);
|
|
70
|
-
if (!channelId || !threadTs) {
|
|
71
|
-
return void 0;
|
|
72
|
-
}
|
|
73
|
-
return { channelId, threadTs };
|
|
74
|
-
}
|
|
75
|
-
function resolveSlackChannelIdFromThreadId(threadId) {
|
|
76
|
-
return parseSlackThreadId(threadId)?.channelId;
|
|
77
|
-
}
|
|
78
|
-
function resolveSlackChannelIdFromMessage(message) {
|
|
79
|
-
const messageChannelId = parseSlackChannelId(
|
|
80
|
-
message.channelId
|
|
81
|
-
);
|
|
82
|
-
if (messageChannelId) {
|
|
83
|
-
return messageChannelId;
|
|
84
|
-
}
|
|
85
|
-
const raw = message.raw;
|
|
86
|
-
if (raw && typeof raw === "object") {
|
|
87
|
-
const rawChannel = parseSlackChannelId(
|
|
88
|
-
raw.channel
|
|
89
|
-
);
|
|
90
|
-
if (rawChannel) {
|
|
91
|
-
return rawChannel;
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
const threadId = toTrimmedSlackString(
|
|
95
|
-
message.threadId
|
|
96
|
-
);
|
|
97
|
-
return resolveSlackChannelIdFromThreadId(threadId);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
// src/chat/conversation-privacy.ts
|
|
101
7
|
var SAFE_METADATA_KEY_LIMIT = 20;
|
|
102
8
|
var conversationPrivacyStorage = new AsyncLocalStorage();
|
|
103
|
-
function privateNarrowingFromChannelId(channelId) {
|
|
104
|
-
const normalized = channelId?.trim();
|
|
105
|
-
if (!normalized) return void 0;
|
|
106
|
-
return normalized.startsWith("D") || normalized.startsWith("G") ? "private" : void 0;
|
|
107
|
-
}
|
|
108
|
-
function privateNarrowingFromConversationId(conversationId) {
|
|
109
|
-
const normalized = conversationId?.trim();
|
|
110
|
-
if (!normalized) return void 0;
|
|
111
|
-
const slackThread = parseSlackThreadId(normalized);
|
|
112
|
-
if (slackThread) {
|
|
113
|
-
return privateNarrowingFromChannelId(slackThread.channelId);
|
|
114
|
-
}
|
|
115
|
-
if (normalized.startsWith("slack:")) {
|
|
116
|
-
return void 0;
|
|
117
|
-
}
|
|
118
|
-
return "private";
|
|
119
|
-
}
|
|
120
9
|
function resolveConversationPrivacy(input) {
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
return "private";
|
|
10
|
+
if (input.visibility === void 0) {
|
|
11
|
+
logWarn("conversation.visibility.defaulted");
|
|
124
12
|
}
|
|
125
|
-
return input.visibility;
|
|
13
|
+
return input.visibility === "public" ? "public" : "private";
|
|
126
14
|
}
|
|
127
15
|
function canExposeConversationPayload(input) {
|
|
128
16
|
return resolveConversationPrivacy(input) === "public";
|
|
@@ -298,10 +186,6 @@ function toGenAiMessagesTraceAttributes(prefix, messages) {
|
|
|
298
186
|
}
|
|
299
187
|
|
|
300
188
|
export {
|
|
301
|
-
readSlackRawMessageContext,
|
|
302
|
-
parseSlackThreadId,
|
|
303
|
-
resolveSlackChannelIdFromThreadId,
|
|
304
|
-
resolveSlackChannelIdFromMessage,
|
|
305
189
|
resolveConversationPrivacy,
|
|
306
190
|
canExposeConversationPayload,
|
|
307
191
|
getCurrentConversationPrivacy,
|
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
agentTurnUsageSchema,
|
|
5
5
|
authenticationLinkedEvent,
|
|
6
6
|
authenticationUnlinkedEvent
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-HX236W2U.js";
|
|
8
8
|
import {
|
|
9
9
|
agentHistoryItemSchema,
|
|
10
10
|
contextProvenance,
|
|
@@ -16,34 +16,32 @@ import {
|
|
|
16
16
|
instructionProvenanceFor,
|
|
17
17
|
sanitizePostgresJson,
|
|
18
18
|
withConversationEventLock
|
|
19
|
-
} from "./chunk-
|
|
19
|
+
} from "./chunk-KP7E267S.js";
|
|
20
20
|
import {
|
|
21
21
|
getStateAdapter,
|
|
22
22
|
sleep
|
|
23
|
-
} from "./chunk-
|
|
23
|
+
} from "./chunk-APYVVX2Y.js";
|
|
24
24
|
import {
|
|
25
25
|
botConfig,
|
|
26
26
|
escapeXml,
|
|
27
27
|
resolveGatewayModel,
|
|
28
28
|
unwrapCurrentInstruction
|
|
29
|
-
} from "./chunk-
|
|
29
|
+
} from "./chunk-XLIAQRDI.js";
|
|
30
30
|
import {
|
|
31
31
|
toStoredSlackActor
|
|
32
32
|
} from "./chunk-HZF5P5UN.js";
|
|
33
|
+
import {
|
|
34
|
+
parseSlackMessageTs
|
|
35
|
+
} from "./chunk-F3B2YJ76.js";
|
|
33
36
|
import {
|
|
34
37
|
getActiveTraceId,
|
|
38
|
+
isRecord,
|
|
35
39
|
logException,
|
|
36
40
|
logWarn,
|
|
37
|
-
setSpanAttributes
|
|
38
|
-
} from "./chunk-ASK74NM6.js";
|
|
39
|
-
import {
|
|
40
|
-
isRecord,
|
|
41
|
+
setSpanAttributes,
|
|
41
42
|
toOptionalNumber,
|
|
42
43
|
toOptionalString
|
|
43
|
-
} from "./chunk-
|
|
44
|
-
import {
|
|
45
|
-
parseSlackMessageTs
|
|
46
|
-
} from "./chunk-F3B2YJ76.js";
|
|
44
|
+
} from "./chunk-JP2ZOSQK.js";
|
|
47
45
|
|
|
48
46
|
// src/chat/turn-context-tag.ts
|
|
49
47
|
var TURN_CONTEXT_TAG = "runtime-turn-context";
|
|
@@ -1502,6 +1500,7 @@ async function recordConversationActivityMetadata(args) {
|
|
|
1502
1500
|
nowMs: args.nowMs,
|
|
1503
1501
|
actor: sessionLogActor(args.summary.actor),
|
|
1504
1502
|
source,
|
|
1503
|
+
...args.summary.source ? { sessionSource: args.summary.source } : {},
|
|
1505
1504
|
visibility: args.destinationVisibility
|
|
1506
1505
|
});
|
|
1507
1506
|
await conversationStore.recordExecution({
|
|
@@ -2012,6 +2011,7 @@ async function persistRunningSessionRecord(args) {
|
|
|
2012
2011
|
cumulativeDurationMs: latestSessionRecord?.cumulativeDurationMs,
|
|
2013
2012
|
cumulativeUsage: latestSessionRecord?.cumulativeUsage,
|
|
2014
2013
|
...args.destination ?? latestSessionRecord?.destination ? { destination: args.destination ?? latestSessionRecord?.destination } : {},
|
|
2014
|
+
destinationVisibility: args.destinationVisibility,
|
|
2015
2015
|
...args.dispatchId ?? latestSessionRecord?.dispatchId ? { dispatchId: args.dispatchId ?? latestSessionRecord?.dispatchId } : {},
|
|
2016
2016
|
...args.source ?? latestSessionRecord?.source ? { source: args.source ?? latestSessionRecord?.source } : {},
|
|
2017
2017
|
sessionId: args.sessionId,
|
|
@@ -2151,6 +2151,7 @@ async function persistAuthPauseSessionRecord(args) {
|
|
|
2151
2151
|
args.currentUsage
|
|
2152
2152
|
),
|
|
2153
2153
|
...args.destination ?? latestSessionRecord?.destination ? { destination: args.destination ?? latestSessionRecord?.destination } : {},
|
|
2154
|
+
destinationVisibility: args.destinationVisibility,
|
|
2154
2155
|
...args.dispatchId ?? latestSessionRecord?.dispatchId ? { dispatchId: args.dispatchId ?? latestSessionRecord?.dispatchId } : {},
|
|
2155
2156
|
...args.source ?? latestSessionRecord?.source ? { source: args.source ?? latestSessionRecord?.source } : {},
|
|
2156
2157
|
sessionId: args.sessionId,
|
|
@@ -2215,6 +2216,7 @@ async function persistContinuationSessionRecord(args) {
|
|
|
2215
2216
|
...args.destination ?? latestSessionRecord?.destination ? {
|
|
2216
2217
|
destination: args.destination ?? latestSessionRecord?.destination
|
|
2217
2218
|
} : {},
|
|
2219
|
+
destinationVisibility: args.destinationVisibility,
|
|
2218
2220
|
...args.dispatchId ?? latestSessionRecord?.dispatchId ? { dispatchId: args.dispatchId ?? latestSessionRecord?.dispatchId } : {},
|
|
2219
2221
|
...args.source ?? latestSessionRecord?.source ? { source: args.source ?? latestSessionRecord?.source } : {},
|
|
2220
2222
|
sessionId: args.sessionId,
|
|
@@ -2242,6 +2244,7 @@ async function persistContinuationSessionRecord(args) {
|
|
|
2242
2244
|
cumulativeDurationMs,
|
|
2243
2245
|
cumulativeUsage,
|
|
2244
2246
|
...args.destination ?? latestSessionRecord?.destination ? { destination: args.destination ?? latestSessionRecord?.destination } : {},
|
|
2247
|
+
destinationVisibility: args.destinationVisibility,
|
|
2245
2248
|
...args.dispatchId ?? latestSessionRecord?.dispatchId ? { dispatchId: args.dispatchId ?? latestSessionRecord?.dispatchId } : {},
|
|
2246
2249
|
...args.source ?? latestSessionRecord?.source ? { source: args.source ?? latestSessionRecord?.source } : {},
|
|
2247
2250
|
sessionId: args.sessionId,
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
getCurrentConversationPrivacy,
|
|
3
|
-
resolveConversationPrivacy,
|
|
4
3
|
toCanonicalInputMessage,
|
|
5
4
|
toCanonicalOutputMessage,
|
|
6
5
|
toGenAiMessagesTraceAttributes
|
|
7
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-VUBUFT66.js";
|
|
8
7
|
import {
|
|
9
8
|
extractGenAiUsageAttributes,
|
|
10
9
|
logException,
|
|
@@ -12,7 +11,7 @@ import {
|
|
|
12
11
|
normalizeGenAiFinishReason,
|
|
13
12
|
serializeGenAiAttribute,
|
|
14
13
|
withSpan
|
|
15
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-JP2ZOSQK.js";
|
|
16
15
|
|
|
17
16
|
// src/chat/config.ts
|
|
18
17
|
import { getModel as getModel2 } from "@earendil-works/pi-ai/compat";
|
|
@@ -322,7 +321,22 @@ var GEN_AI_SERVER_ADDRESS = "ai-gateway.vercel.sh";
|
|
|
322
321
|
var GEN_AI_SERVER_PORT = 443;
|
|
323
322
|
var GEN_AI_OPERATION_CHAT = "chat";
|
|
324
323
|
var GEN_AI_OPERATION_EMBEDDINGS = "embeddings";
|
|
324
|
+
var EMBEDDING_INPUT_COST_USD_PER_MILLION_TOKENS = {
|
|
325
|
+
"cohere/embed-v4.0": 0.12,
|
|
326
|
+
"google/gemini-embedding-001": 0.15,
|
|
327
|
+
"google/text-embedding-005": 0.025,
|
|
328
|
+
"mistral/mistral-embed": 0.1,
|
|
329
|
+
"openai/text-embedding-3-large": 0.13,
|
|
330
|
+
"openai/text-embedding-3-small": 0.02,
|
|
331
|
+
"openai/text-embedding-ada-002": 0.1,
|
|
332
|
+
"voyage/voyage-3.5": 0.06,
|
|
333
|
+
"voyage/voyage-3.5-lite": 0.02
|
|
334
|
+
};
|
|
325
335
|
var MISSING_GATEWAY_CREDENTIALS_ERROR = "Missing AI gateway credentials (AI_GATEWAY_API_KEY or VERCEL_OIDC_TOKEN)";
|
|
336
|
+
function embeddingCostUsd(modelId, inputTokens) {
|
|
337
|
+
const costPerMillionTokens = EMBEDDING_INPUT_COST_USD_PER_MILLION_TOKENS[modelId];
|
|
338
|
+
return costPerMillionTokens === void 0 ? void 0 : inputTokens * costPerMillionTokens / 1e6;
|
|
339
|
+
}
|
|
326
340
|
function getGatewayApiKey() {
|
|
327
341
|
return toOptionalTrimmed(getEnvApiKey("vercel-ai-gateway")) ?? toOptionalTrimmed(process.env.VERCEL_OIDC_TOKEN);
|
|
328
342
|
}
|
|
@@ -345,11 +359,7 @@ async function completeText(params) {
|
|
|
345
359
|
const model = resolveGatewayModel(params.modelId);
|
|
346
360
|
const apiKey = getPiGatewayApiKey();
|
|
347
361
|
const authMode = toOptionalTrimmed(process.env.AI_GATEWAY_API_KEY) ? "api_key" : toOptionalTrimmed(process.env.VERCEL_OIDC_TOKEN) ? "oidc" : "api_key";
|
|
348
|
-
const
|
|
349
|
-
channelId: typeof params.metadata?.channelId === "string" ? params.metadata.channelId : void 0,
|
|
350
|
-
conversationId: typeof params.metadata?.conversationId === "string" ? params.metadata.conversationId : typeof params.metadata?.threadId === "string" ? params.metadata.threadId : void 0
|
|
351
|
-
}) ?? getCurrentConversationPrivacy();
|
|
352
|
-
const effectivePrivacy = privacy ?? "private";
|
|
362
|
+
const effectivePrivacy = getCurrentConversationPrivacy() ?? "private";
|
|
353
363
|
const messageAttributeMode = params.messageAttributeMode ?? (effectivePrivacy === "public" ? "content" : "metadata");
|
|
354
364
|
const requestMessagesAttribute = messageAttributeMode === "content" ? serializeGenAiAttribute(params.messages.map(toCanonicalInputMessage)) : void 0;
|
|
355
365
|
const systemInstructionsAttribute = params.system && messageAttributeMode === "content" ? serializeGenAiAttribute([{ type: "text", content: params.system }]) : void 0;
|
|
@@ -566,11 +576,15 @@ async function embedTexts(params) {
|
|
|
566
576
|
}
|
|
567
577
|
);
|
|
568
578
|
}
|
|
579
|
+
const costUsd = embeddingCostUsd(params.modelId, result2.usage.tokens);
|
|
569
580
|
setSpanAttributes({
|
|
570
581
|
"gen_ai.embeddings.dimension.count": dimensions,
|
|
571
|
-
...extractGenAiUsageAttributes(
|
|
582
|
+
...extractGenAiUsageAttributes({
|
|
583
|
+
inputTokens: result2.usage.tokens,
|
|
584
|
+
...costUsd !== void 0 ? { cost: { input: costUsd, total: costUsd } } : {}
|
|
585
|
+
})
|
|
572
586
|
});
|
|
573
|
-
return { dimensions, result: result2 };
|
|
587
|
+
return { costUsd, dimensions, result: result2 };
|
|
574
588
|
},
|
|
575
589
|
{
|
|
576
590
|
"gen_ai.provider.name": GEN_AI_PROVIDER_NAME,
|
|
@@ -581,6 +595,7 @@ async function embedTexts(params) {
|
|
|
581
595
|
}
|
|
582
596
|
);
|
|
583
597
|
return {
|
|
598
|
+
...result.costUsd !== void 0 ? { costUsd: result.costUsd } : {},
|
|
584
599
|
dimensions: result.dimensions,
|
|
585
600
|
model: params.modelId,
|
|
586
601
|
provider: GEN_AI_PROVIDER_NAME,
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
2
|
healthReportSchema
|
|
3
|
-
} from "./chunk-
|
|
4
|
-
import {
|
|
5
|
-
normalizeSlackConversationId
|
|
6
|
-
} from "./chunk-IXTIJQ7Z.js";
|
|
3
|
+
} from "./chunk-UTL3MHPC.js";
|
|
7
4
|
import {
|
|
8
5
|
parseSlackThreadId
|
|
9
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-72SDEHFP.js";
|
|
7
|
+
import {
|
|
8
|
+
normalizeSlackConversationId
|
|
9
|
+
} from "./chunk-6KWO5DU3.js";
|
|
10
10
|
|
|
11
11
|
// src/handlers/health.ts
|
|
12
12
|
function readHealthReport() {
|
|
@@ -56,14 +56,6 @@ function conversationVisibilityFromSlackChannelType(channelType) {
|
|
|
56
56
|
if (!channelType) return void 0;
|
|
57
57
|
return channelType === "channel" ? "public" : "private";
|
|
58
58
|
}
|
|
59
|
-
function visibilityFromChannelIdPrefix(channelId) {
|
|
60
|
-
const normalized = normalizeSlackConversationId(channelId);
|
|
61
|
-
if (!normalized) return void 0;
|
|
62
|
-
if (normalized.startsWith("D") || normalized.startsWith("G")) {
|
|
63
|
-
return "private";
|
|
64
|
-
}
|
|
65
|
-
return void 0;
|
|
66
|
-
}
|
|
67
59
|
function resolveSlackChannelTypeFromMessage(message) {
|
|
68
60
|
const raw = message.raw;
|
|
69
61
|
if (!raw || typeof raw !== "object") {
|
|
@@ -76,7 +68,9 @@ function resolveSlackConversationContext(input) {
|
|
|
76
68
|
const type = typeFromSlackChannelType(input.channelType) ?? typeFromChannelId(input.channelId, input.channelName);
|
|
77
69
|
if (!type) return void 0;
|
|
78
70
|
const name = normalizeConversationName(type, input.channelName);
|
|
79
|
-
const visibility = conversationVisibilityFromSlackChannelType(
|
|
71
|
+
const visibility = conversationVisibilityFromSlackChannelType(
|
|
72
|
+
input.channelType
|
|
73
|
+
);
|
|
80
74
|
return {
|
|
81
75
|
type,
|
|
82
76
|
...name ? { name } : {},
|
|
@@ -85,10 +79,18 @@ function resolveSlackConversationContext(input) {
|
|
|
85
79
|
}
|
|
86
80
|
function resolveSlackConversationContextFromThreadId(input) {
|
|
87
81
|
const slackThread = parseSlackThreadId(input.threadId);
|
|
88
|
-
|
|
82
|
+
const context = resolveSlackConversationContext({
|
|
89
83
|
channelId: slackThread?.channelId,
|
|
90
84
|
channelName: input.channelName
|
|
91
85
|
});
|
|
86
|
+
if (!context || !input.visibility) {
|
|
87
|
+
return context;
|
|
88
|
+
}
|
|
89
|
+
return {
|
|
90
|
+
...context,
|
|
91
|
+
type: input.visibility === "private" && context.type === "public_channel" ? "private_channel" : context.type,
|
|
92
|
+
visibility: input.visibility
|
|
93
|
+
};
|
|
92
94
|
}
|
|
93
95
|
function formatSlackConversationTypeLabel(type) {
|
|
94
96
|
if (type === "public_channel") return "Public Channel";
|