@sentry/junior 0.72.0 → 0.73.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/bin/junior.mjs +12 -10
- package/dist/app.d.ts +11 -2
- package/dist/app.js +936 -13042
- package/dist/chat/agent-dispatch/runner.d.ts +2 -0
- package/dist/chat/agent-dispatch/store.d.ts +2 -2
- package/dist/chat/agent-dispatch/types.d.ts +6 -3
- package/dist/chat/agent-dispatch/validation.d.ts +2 -3
- package/dist/chat/app/production.d.ts +8 -1
- package/dist/chat/app/services.d.ts +7 -0
- package/dist/chat/destination.d.ts +3 -1
- package/dist/chat/logging.d.ts +3 -0
- package/dist/chat/oauth-flow.d.ts +1 -1
- package/dist/chat/plugins/registry.d.ts +2 -0
- package/dist/chat/plugins/types.d.ts +2 -0
- package/dist/chat/prompt.d.ts +4 -1
- package/dist/chat/requester.d.ts +19 -12
- package/dist/chat/respond.d.ts +6 -2
- package/dist/chat/runtime/agent-continue-runner.d.ts +1 -1
- package/dist/chat/runtime/reply-executor.d.ts +3 -1
- package/dist/chat/runtime/slack-resume.d.ts +3 -3
- package/dist/chat/runtime/slack-runtime.d.ts +13 -3
- package/dist/chat/runtime/turn.d.ts +15 -1
- package/dist/chat/sandbox/egress-credentials.d.ts +5 -2
- package/dist/chat/sandbox/egress-policy.d.ts +5 -1
- package/dist/chat/sandbox/egress-proxy.d.ts +2 -0
- package/dist/chat/sandbox/egress-schemas.d.ts +4 -0
- package/dist/chat/sandbox/egress-session.d.ts +3 -1
- package/dist/chat/sandbox/egress-tracing.d.ts +7 -0
- package/dist/chat/sandbox/sandbox.d.ts +2 -0
- package/dist/chat/sandbox/session.d.ts +3 -2
- package/dist/chat/services/auth-pause-response.d.ts +1 -1
- package/dist/chat/services/auth-pause.d.ts +2 -1
- package/dist/chat/services/mcp-auth-orchestration.d.ts +1 -1
- package/dist/chat/services/message-actor-identity.d.ts +2 -2
- package/dist/chat/services/plugin-auth-orchestration.d.ts +9 -8
- package/dist/chat/services/turn-result.d.ts +3 -0
- package/dist/chat/slack/user.d.ts +2 -2
- package/dist/chat/task-execution/store.d.ts +1 -1
- package/dist/chat/tools/slack/canvas-tools.d.ts +3 -2
- package/dist/chat/tools/slack/channel-list-messages.d.ts +2 -2
- package/dist/chat/tools/slack/channel-post-message.d.ts +3 -2
- package/dist/chat/tools/slack/context.d.ts +15 -2
- package/dist/chat/tools/slack/message-add-reaction.d.ts +3 -2
- package/dist/chat/tools/slack/thread-read.d.ts +2 -2
- package/dist/chat/tools/types.d.ts +19 -19
- package/dist/{chunk-6GEYPE6T.js → chunk-3BYAPS6B.js} +30 -6
- package/dist/{chunk-GB3AL54K.js → chunk-7Q5YOUUT.js} +10 -2
- package/dist/{chunk-HNMUVGSR.js → chunk-AL5T52ZD.js} +6 -6
- package/dist/{chunk-PP7AGSBU.js → chunk-CYUI7JU5.js} +18 -8
- package/dist/{chunk-3FYPXHPL.js → chunk-DIMX5F3T.js} +1 -1
- package/dist/{chunk-4JXCSGSA.js → chunk-M4FLLXXD.js} +1 -1
- package/dist/chunk-OQSYYOLM.js +12787 -0
- package/dist/{chunk-55XEZFGD.js → chunk-OR6NQJ5E.js} +2 -2
- package/dist/{chunk-VLIO6RQR.js → chunk-RY6AL5C7.js} +4 -4
- package/dist/chunk-SJHUF3DP.js +43 -0
- package/dist/{chunk-ICKIDP7G.js → chunk-UOTZ3EEQ.js} +1 -1
- package/dist/{chunk-VSNA5KAB.js → chunk-UZVHXZ7V.js} +1276 -1481
- package/dist/{chunk-XC33FJZN.js → chunk-V4VYUY4A.js} +25 -4
- package/dist/{chunk-ZJQPA67D.js → chunk-WS2EG3GW.js} +224 -224
- package/dist/chunk-ZDA2HYX5.js +275 -0
- package/dist/cli/chat.js +205 -0
- package/dist/cli/check.js +9 -10
- package/dist/cli/run.js +10 -2
- package/dist/cli/snapshot-warmup.js +7 -7
- package/dist/cli/upgrade.js +8 -8
- package/dist/deployment.d.ts +4 -0
- package/dist/handlers/agent-dispatch.d.ts +6 -1
- package/dist/handlers/mcp-oauth-callback.d.ts +6 -1
- package/dist/handlers/oauth-callback.d.ts +6 -1
- package/dist/handlers/sandbox-egress-proxy.d.ts +2 -0
- package/dist/handlers/webhooks.d.ts +4 -2
- package/dist/instrumentation.js +17 -2
- package/dist/nitro.js +9 -10
- package/dist/reporting.js +19 -17
- package/dist/runner-LMAM4OGD.js +259 -0
- package/package.json +3 -3
- package/dist/chunk-6YY4Q3D4.js +0 -12
- package/dist/chunk-Z3YD6NHK.js +0 -12
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
2
|
getSlackBotToken
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-WS2EG3GW.js";
|
|
4
4
|
import {
|
|
5
5
|
isSlackConversationId,
|
|
6
6
|
isSlackTeamId,
|
|
7
7
|
logWarn
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-3BYAPS6B.js";
|
|
9
9
|
|
|
10
10
|
// src/chat/slack/client.ts
|
|
11
11
|
import { WebClient } from "@slack/web-api";
|
|
@@ -277,7 +277,9 @@ async function downloadPrivateSlackFile(url) {
|
|
|
277
277
|
}
|
|
278
278
|
|
|
279
279
|
// src/chat/destination.ts
|
|
280
|
-
import {
|
|
280
|
+
import {
|
|
281
|
+
destinationSchema
|
|
282
|
+
} from "@sentry/junior-plugin-api";
|
|
281
283
|
function createSlackDestination(input) {
|
|
282
284
|
const channelId = normalizeSlackConversationId(input.channelId);
|
|
283
285
|
const teamId = input.teamId?.trim();
|
|
@@ -293,10 +295,28 @@ function parseDestination(value) {
|
|
|
293
295
|
const parsed = destinationSchema.safeParse(value);
|
|
294
296
|
return parsed.success ? parsed.data : void 0;
|
|
295
297
|
}
|
|
298
|
+
function requireSlackDestination(destination, action) {
|
|
299
|
+
if (destination?.platform === "slack") {
|
|
300
|
+
return destination;
|
|
301
|
+
}
|
|
302
|
+
throw new Error(`${action} requires a Slack destination`);
|
|
303
|
+
}
|
|
296
304
|
function sameDestination(left, right) {
|
|
297
|
-
|
|
305
|
+
if (left.platform !== right.platform) {
|
|
306
|
+
return false;
|
|
307
|
+
}
|
|
308
|
+
if (left.platform === "local" && right.platform === "local") {
|
|
309
|
+
return left.conversationId === right.conversationId;
|
|
310
|
+
}
|
|
311
|
+
if (left.platform === "slack" && right.platform === "slack") {
|
|
312
|
+
return left.teamId === right.teamId && left.channelId === right.channelId;
|
|
313
|
+
}
|
|
314
|
+
return false;
|
|
298
315
|
}
|
|
299
316
|
function destinationKey(destination) {
|
|
317
|
+
if (destination.platform === "local") {
|
|
318
|
+
return destination.conversationId;
|
|
319
|
+
}
|
|
300
320
|
return `slack:${destination.teamId}:${destination.channelId}`;
|
|
301
321
|
}
|
|
302
322
|
|
|
@@ -313,6 +333,7 @@ export {
|
|
|
313
333
|
downloadPrivateSlackFile,
|
|
314
334
|
createSlackDestination,
|
|
315
335
|
parseDestination,
|
|
336
|
+
requireSlackDestination,
|
|
316
337
|
sameDestination,
|
|
317
338
|
destinationKey
|
|
318
339
|
};
|
|
@@ -6,230 +6,7 @@ import {
|
|
|
6
6
|
setSpanAttributes,
|
|
7
7
|
toOptionalString,
|
|
8
8
|
withSpan
|
|
9
|
-
} from "./chunk-
|
|
10
|
-
|
|
11
|
-
// src/chat/config.ts
|
|
12
|
-
import { getModel } from "@earendil-works/pi-ai";
|
|
13
|
-
|
|
14
|
-
// src/chat/optional-string.ts
|
|
15
|
-
function toOptionalTrimmed(value) {
|
|
16
|
-
if (!value) {
|
|
17
|
-
return void 0;
|
|
18
|
-
}
|
|
19
|
-
const trimmed = value.trim();
|
|
20
|
-
return trimmed.length > 0 ? trimmed : void 0;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
// src/chat/pi/client.ts
|
|
24
|
-
import {
|
|
25
|
-
completeSimple,
|
|
26
|
-
getEnvApiKey,
|
|
27
|
-
getModels,
|
|
28
|
-
registerApiProvider
|
|
29
|
-
} from "@earendil-works/pi-ai";
|
|
30
|
-
import {
|
|
31
|
-
streamAnthropic,
|
|
32
|
-
streamSimpleAnthropic
|
|
33
|
-
} from "@earendil-works/pi-ai/anthropic";
|
|
34
|
-
|
|
35
|
-
// src/chat/slack/context.ts
|
|
36
|
-
function toTrimmedSlackString(value) {
|
|
37
|
-
const normalized = toOptionalString(value);
|
|
38
|
-
return normalized?.trim() || void 0;
|
|
39
|
-
}
|
|
40
|
-
function parseSlackThreadId(threadId) {
|
|
41
|
-
const normalizedThreadId = toTrimmedSlackString(threadId);
|
|
42
|
-
if (!normalizedThreadId) {
|
|
43
|
-
return void 0;
|
|
44
|
-
}
|
|
45
|
-
const parts = normalizedThreadId.split(":");
|
|
46
|
-
if (parts.length !== 3 || parts[0] !== "slack") {
|
|
47
|
-
return void 0;
|
|
48
|
-
}
|
|
49
|
-
const channelId = toTrimmedSlackString(parts[1]);
|
|
50
|
-
const threadTs = toTrimmedSlackString(parts[2]);
|
|
51
|
-
if (!channelId || !threadTs) {
|
|
52
|
-
return void 0;
|
|
53
|
-
}
|
|
54
|
-
return { channelId, threadTs };
|
|
55
|
-
}
|
|
56
|
-
function resolveSlackChannelIdFromThreadId(threadId) {
|
|
57
|
-
return parseSlackThreadId(threadId)?.channelId;
|
|
58
|
-
}
|
|
59
|
-
function resolveSlackChannelIdFromMessage(message) {
|
|
60
|
-
const messageChannelId = toTrimmedSlackString(
|
|
61
|
-
message.channelId
|
|
62
|
-
);
|
|
63
|
-
if (messageChannelId) {
|
|
64
|
-
return messageChannelId;
|
|
65
|
-
}
|
|
66
|
-
const raw = message.raw;
|
|
67
|
-
if (raw && typeof raw === "object") {
|
|
68
|
-
const rawChannel = toTrimmedSlackString(
|
|
69
|
-
raw.channel
|
|
70
|
-
);
|
|
71
|
-
if (rawChannel) {
|
|
72
|
-
return rawChannel;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
const threadId = toTrimmedSlackString(
|
|
76
|
-
message.threadId
|
|
77
|
-
);
|
|
78
|
-
return resolveSlackChannelIdFromThreadId(threadId);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
// src/chat/conversation-privacy.ts
|
|
82
|
-
var SAFE_METADATA_KEY_LIMIT = 20;
|
|
83
|
-
function conversationPrivacyFromChannelId(channelId) {
|
|
84
|
-
const normalized = channelId?.trim();
|
|
85
|
-
if (!normalized) return void 0;
|
|
86
|
-
return normalized.startsWith("C") ? "public" : "private";
|
|
87
|
-
}
|
|
88
|
-
function conversationPrivacyFromConversationId(conversationId) {
|
|
89
|
-
if (!conversationId?.trim()) return void 0;
|
|
90
|
-
const slackThread = parseSlackThreadId(conversationId);
|
|
91
|
-
if (slackThread) {
|
|
92
|
-
return conversationPrivacyFromChannelId(slackThread.channelId);
|
|
93
|
-
}
|
|
94
|
-
return "private";
|
|
95
|
-
}
|
|
96
|
-
function resolveConversationPrivacy(input) {
|
|
97
|
-
return conversationPrivacyFromChannelId(input.channelId) ?? conversationPrivacyFromConversationId(input.conversationId);
|
|
98
|
-
}
|
|
99
|
-
function canExposeConversationPayload(input) {
|
|
100
|
-
return resolveConversationPrivacy(input) === "public";
|
|
101
|
-
}
|
|
102
|
-
function contentMetadata(content) {
|
|
103
|
-
if (typeof content === "string") {
|
|
104
|
-
return [{ type: "text", chars: content.length }];
|
|
105
|
-
}
|
|
106
|
-
if (!Array.isArray(content)) {
|
|
107
|
-
return { type: typeof content };
|
|
108
|
-
}
|
|
109
|
-
return content.map((part) => {
|
|
110
|
-
if (!part || typeof part !== "object") {
|
|
111
|
-
return { type: typeof part };
|
|
112
|
-
}
|
|
113
|
-
const record = part;
|
|
114
|
-
const type = typeof record.type === "string" ? record.type : "unknown";
|
|
115
|
-
return {
|
|
116
|
-
type,
|
|
117
|
-
...typeof record.text === "string" ? { chars: record.text.length } : {},
|
|
118
|
-
...typeof record.mimeType === "string" ? { mimeType: record.mimeType } : {},
|
|
119
|
-
...typeof record.mediaType === "string" ? { mediaType: record.mediaType } : {},
|
|
120
|
-
...typeof record.data === "string" ? { dataChars: record.data.length } : {}
|
|
121
|
-
};
|
|
122
|
-
});
|
|
123
|
-
}
|
|
124
|
-
function toGenAiMessageMetadata(message) {
|
|
125
|
-
const record = message && typeof message === "object" ? message : {};
|
|
126
|
-
return {
|
|
127
|
-
role: record.role,
|
|
128
|
-
content: contentMetadata(record.content)
|
|
129
|
-
};
|
|
130
|
-
}
|
|
131
|
-
function toGenAiTextMetadata(text) {
|
|
132
|
-
return { type: "text", chars: text.length };
|
|
133
|
-
}
|
|
134
|
-
function payloadType(payload) {
|
|
135
|
-
return Array.isArray(payload) ? "array" : typeof payload;
|
|
136
|
-
}
|
|
137
|
-
function payloadKeys(payload) {
|
|
138
|
-
if (!payload || typeof payload !== "object" || Array.isArray(payload)) {
|
|
139
|
-
return void 0;
|
|
140
|
-
}
|
|
141
|
-
const keys = Object.keys(payload).slice(
|
|
142
|
-
0,
|
|
143
|
-
SAFE_METADATA_KEY_LIMIT
|
|
144
|
-
);
|
|
145
|
-
return keys.length > 0 ? keys : void 0;
|
|
146
|
-
}
|
|
147
|
-
function serializedLength(payload) {
|
|
148
|
-
const serialized = typeof payload === "string" ? payload : JSON.stringify(payload);
|
|
149
|
-
return serialized?.length ?? 0;
|
|
150
|
-
}
|
|
151
|
-
function toGenAiPayloadMetadata(payload) {
|
|
152
|
-
const base = {
|
|
153
|
-
type: payloadType(payload),
|
|
154
|
-
chars: serializedLength(payload)
|
|
155
|
-
};
|
|
156
|
-
if (!payload || typeof payload !== "object" || Array.isArray(payload)) {
|
|
157
|
-
return base;
|
|
158
|
-
}
|
|
159
|
-
const keys = payloadKeys(payload);
|
|
160
|
-
return {
|
|
161
|
-
...base,
|
|
162
|
-
...keys ? { keys } : {}
|
|
163
|
-
};
|
|
164
|
-
}
|
|
165
|
-
function toGenAiPayloadTraceAttributes(prefix, payload) {
|
|
166
|
-
const attributes = {
|
|
167
|
-
[`${prefix}.type`]: payloadType(payload),
|
|
168
|
-
[`${prefix}.size_chars`]: serializedLength(payload)
|
|
169
|
-
};
|
|
170
|
-
const keys = payloadKeys(payload);
|
|
171
|
-
if (keys) {
|
|
172
|
-
attributes[`${prefix}.keys`] = keys;
|
|
173
|
-
}
|
|
174
|
-
return attributes;
|
|
175
|
-
}
|
|
176
|
-
function summarizeContent(content) {
|
|
177
|
-
if (typeof content === "string") {
|
|
178
|
-
return { chars: content.length, partTypes: ["text"] };
|
|
179
|
-
}
|
|
180
|
-
if (!Array.isArray(content)) {
|
|
181
|
-
return {
|
|
182
|
-
chars: serializedLength(content),
|
|
183
|
-
partTypes: [payloadType(content)]
|
|
184
|
-
};
|
|
185
|
-
}
|
|
186
|
-
let chars = 0;
|
|
187
|
-
const partTypes = /* @__PURE__ */ new Set();
|
|
188
|
-
for (const part of content) {
|
|
189
|
-
if (!part || typeof part !== "object") {
|
|
190
|
-
chars += serializedLength(part);
|
|
191
|
-
partTypes.add(payloadType(part));
|
|
192
|
-
continue;
|
|
193
|
-
}
|
|
194
|
-
const record = part;
|
|
195
|
-
const type = typeof record.type === "string" ? record.type : "unknown";
|
|
196
|
-
partTypes.add(type);
|
|
197
|
-
if (typeof record.text === "string") {
|
|
198
|
-
chars += record.text.length;
|
|
199
|
-
} else if (typeof record.data === "string") {
|
|
200
|
-
chars += record.data.length;
|
|
201
|
-
} else {
|
|
202
|
-
chars += serializedLength(part);
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
return { chars, partTypes: [...partTypes] };
|
|
206
|
-
}
|
|
207
|
-
function toGenAiMessagesTraceAttributes(prefix, messages) {
|
|
208
|
-
let contentChars = 0;
|
|
209
|
-
const roles = /* @__PURE__ */ new Set();
|
|
210
|
-
const partTypes = /* @__PURE__ */ new Set();
|
|
211
|
-
for (const message of messages) {
|
|
212
|
-
if (!message || typeof message !== "object") {
|
|
213
|
-
contentChars += serializedLength(message);
|
|
214
|
-
continue;
|
|
215
|
-
}
|
|
216
|
-
const record = message;
|
|
217
|
-
if (typeof record.role === "string") {
|
|
218
|
-
roles.add(record.role);
|
|
219
|
-
}
|
|
220
|
-
const summary = summarizeContent(record.content);
|
|
221
|
-
contentChars += summary.chars;
|
|
222
|
-
for (const partType of summary.partTypes) {
|
|
223
|
-
partTypes.add(partType);
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
return {
|
|
227
|
-
[`${prefix}.message_count`]: messages.length,
|
|
228
|
-
[`${prefix}.content_chars`]: contentChars,
|
|
229
|
-
...roles.size > 0 ? { [`${prefix}.roles`]: [...roles] } : {},
|
|
230
|
-
...partTypes.size > 0 ? { [`${prefix}.part_types`]: [...partTypes] } : {}
|
|
231
|
-
};
|
|
232
|
-
}
|
|
9
|
+
} from "./chunk-3BYAPS6B.js";
|
|
233
10
|
|
|
234
11
|
// src/chat/turn-context-tag.ts
|
|
235
12
|
var TURN_CONTEXT_TAG = "runtime-turn-context";
|
|
@@ -491,6 +268,229 @@ function trimTrailingAssistantMessages(messages) {
|
|
|
491
268
|
return end === messages.length ? [...messages] : messages.slice(0, end);
|
|
492
269
|
}
|
|
493
270
|
|
|
271
|
+
// src/chat/config.ts
|
|
272
|
+
import { getModel } from "@earendil-works/pi-ai";
|
|
273
|
+
|
|
274
|
+
// src/chat/optional-string.ts
|
|
275
|
+
function toOptionalTrimmed(value) {
|
|
276
|
+
if (!value) {
|
|
277
|
+
return void 0;
|
|
278
|
+
}
|
|
279
|
+
const trimmed = value.trim();
|
|
280
|
+
return trimmed.length > 0 ? trimmed : void 0;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
// src/chat/pi/client.ts
|
|
284
|
+
import {
|
|
285
|
+
completeSimple,
|
|
286
|
+
getEnvApiKey,
|
|
287
|
+
getModels,
|
|
288
|
+
registerApiProvider
|
|
289
|
+
} from "@earendil-works/pi-ai";
|
|
290
|
+
import {
|
|
291
|
+
streamAnthropic,
|
|
292
|
+
streamSimpleAnthropic
|
|
293
|
+
} from "@earendil-works/pi-ai/anthropic";
|
|
294
|
+
|
|
295
|
+
// src/chat/slack/context.ts
|
|
296
|
+
function toTrimmedSlackString(value) {
|
|
297
|
+
const normalized = toOptionalString(value);
|
|
298
|
+
return normalized?.trim() || void 0;
|
|
299
|
+
}
|
|
300
|
+
function parseSlackThreadId(threadId) {
|
|
301
|
+
const normalizedThreadId = toTrimmedSlackString(threadId);
|
|
302
|
+
if (!normalizedThreadId) {
|
|
303
|
+
return void 0;
|
|
304
|
+
}
|
|
305
|
+
const parts = normalizedThreadId.split(":");
|
|
306
|
+
if (parts.length !== 3 || parts[0] !== "slack") {
|
|
307
|
+
return void 0;
|
|
308
|
+
}
|
|
309
|
+
const channelId = toTrimmedSlackString(parts[1]);
|
|
310
|
+
const threadTs = toTrimmedSlackString(parts[2]);
|
|
311
|
+
if (!channelId || !threadTs) {
|
|
312
|
+
return void 0;
|
|
313
|
+
}
|
|
314
|
+
return { channelId, threadTs };
|
|
315
|
+
}
|
|
316
|
+
function resolveSlackChannelIdFromThreadId(threadId) {
|
|
317
|
+
return parseSlackThreadId(threadId)?.channelId;
|
|
318
|
+
}
|
|
319
|
+
function resolveSlackChannelIdFromMessage(message) {
|
|
320
|
+
const messageChannelId = toTrimmedSlackString(
|
|
321
|
+
message.channelId
|
|
322
|
+
);
|
|
323
|
+
if (messageChannelId) {
|
|
324
|
+
return messageChannelId;
|
|
325
|
+
}
|
|
326
|
+
const raw = message.raw;
|
|
327
|
+
if (raw && typeof raw === "object") {
|
|
328
|
+
const rawChannel = toTrimmedSlackString(
|
|
329
|
+
raw.channel
|
|
330
|
+
);
|
|
331
|
+
if (rawChannel) {
|
|
332
|
+
return rawChannel;
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
const threadId = toTrimmedSlackString(
|
|
336
|
+
message.threadId
|
|
337
|
+
);
|
|
338
|
+
return resolveSlackChannelIdFromThreadId(threadId);
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
// src/chat/conversation-privacy.ts
|
|
342
|
+
var SAFE_METADATA_KEY_LIMIT = 20;
|
|
343
|
+
function conversationPrivacyFromChannelId(channelId) {
|
|
344
|
+
const normalized = channelId?.trim();
|
|
345
|
+
if (!normalized) return void 0;
|
|
346
|
+
return normalized.startsWith("C") ? "public" : "private";
|
|
347
|
+
}
|
|
348
|
+
function conversationPrivacyFromConversationId(conversationId) {
|
|
349
|
+
if (!conversationId?.trim()) return void 0;
|
|
350
|
+
const slackThread = parseSlackThreadId(conversationId);
|
|
351
|
+
if (slackThread) {
|
|
352
|
+
return conversationPrivacyFromChannelId(slackThread.channelId);
|
|
353
|
+
}
|
|
354
|
+
return "private";
|
|
355
|
+
}
|
|
356
|
+
function resolveConversationPrivacy(input) {
|
|
357
|
+
return conversationPrivacyFromChannelId(input.channelId) ?? conversationPrivacyFromConversationId(input.conversationId);
|
|
358
|
+
}
|
|
359
|
+
function canExposeConversationPayload(input) {
|
|
360
|
+
return resolveConversationPrivacy(input) === "public";
|
|
361
|
+
}
|
|
362
|
+
function contentMetadata(content) {
|
|
363
|
+
if (typeof content === "string") {
|
|
364
|
+
return [{ type: "text", chars: content.length }];
|
|
365
|
+
}
|
|
366
|
+
if (!Array.isArray(content)) {
|
|
367
|
+
return { type: typeof content };
|
|
368
|
+
}
|
|
369
|
+
return content.map((part) => {
|
|
370
|
+
if (!part || typeof part !== "object") {
|
|
371
|
+
return { type: typeof part };
|
|
372
|
+
}
|
|
373
|
+
const record = part;
|
|
374
|
+
const type = typeof record.type === "string" ? record.type : "unknown";
|
|
375
|
+
return {
|
|
376
|
+
type,
|
|
377
|
+
...typeof record.text === "string" ? { chars: record.text.length } : {},
|
|
378
|
+
...typeof record.mimeType === "string" ? { mimeType: record.mimeType } : {},
|
|
379
|
+
...typeof record.mediaType === "string" ? { mediaType: record.mediaType } : {},
|
|
380
|
+
...typeof record.data === "string" ? { dataChars: record.data.length } : {}
|
|
381
|
+
};
|
|
382
|
+
});
|
|
383
|
+
}
|
|
384
|
+
function toGenAiMessageMetadata(message) {
|
|
385
|
+
const record = message && typeof message === "object" ? message : {};
|
|
386
|
+
return {
|
|
387
|
+
role: record.role,
|
|
388
|
+
content: contentMetadata(record.content)
|
|
389
|
+
};
|
|
390
|
+
}
|
|
391
|
+
function toGenAiTextMetadata(text) {
|
|
392
|
+
return { type: "text", chars: text.length };
|
|
393
|
+
}
|
|
394
|
+
function payloadType(payload) {
|
|
395
|
+
return Array.isArray(payload) ? "array" : typeof payload;
|
|
396
|
+
}
|
|
397
|
+
function payloadKeys(payload) {
|
|
398
|
+
if (!payload || typeof payload !== "object" || Array.isArray(payload)) {
|
|
399
|
+
return void 0;
|
|
400
|
+
}
|
|
401
|
+
const keys = Object.keys(payload).slice(
|
|
402
|
+
0,
|
|
403
|
+
SAFE_METADATA_KEY_LIMIT
|
|
404
|
+
);
|
|
405
|
+
return keys.length > 0 ? keys : void 0;
|
|
406
|
+
}
|
|
407
|
+
function serializedLength(payload) {
|
|
408
|
+
const serialized = typeof payload === "string" ? payload : JSON.stringify(payload);
|
|
409
|
+
return serialized?.length ?? 0;
|
|
410
|
+
}
|
|
411
|
+
function toGenAiPayloadMetadata(payload) {
|
|
412
|
+
const base = {
|
|
413
|
+
type: payloadType(payload),
|
|
414
|
+
chars: serializedLength(payload)
|
|
415
|
+
};
|
|
416
|
+
if (!payload || typeof payload !== "object" || Array.isArray(payload)) {
|
|
417
|
+
return base;
|
|
418
|
+
}
|
|
419
|
+
const keys = payloadKeys(payload);
|
|
420
|
+
return {
|
|
421
|
+
...base,
|
|
422
|
+
...keys ? { keys } : {}
|
|
423
|
+
};
|
|
424
|
+
}
|
|
425
|
+
function toGenAiPayloadTraceAttributes(prefix, payload) {
|
|
426
|
+
const attributes = {
|
|
427
|
+
[`${prefix}.type`]: payloadType(payload),
|
|
428
|
+
[`${prefix}.size_chars`]: serializedLength(payload)
|
|
429
|
+
};
|
|
430
|
+
const keys = payloadKeys(payload);
|
|
431
|
+
if (keys) {
|
|
432
|
+
attributes[`${prefix}.keys`] = keys;
|
|
433
|
+
}
|
|
434
|
+
return attributes;
|
|
435
|
+
}
|
|
436
|
+
function summarizeContent(content) {
|
|
437
|
+
if (typeof content === "string") {
|
|
438
|
+
return { chars: content.length, partTypes: ["text"] };
|
|
439
|
+
}
|
|
440
|
+
if (!Array.isArray(content)) {
|
|
441
|
+
return {
|
|
442
|
+
chars: serializedLength(content),
|
|
443
|
+
partTypes: [payloadType(content)]
|
|
444
|
+
};
|
|
445
|
+
}
|
|
446
|
+
let chars = 0;
|
|
447
|
+
const partTypes = /* @__PURE__ */ new Set();
|
|
448
|
+
for (const part of content) {
|
|
449
|
+
if (!part || typeof part !== "object") {
|
|
450
|
+
chars += serializedLength(part);
|
|
451
|
+
partTypes.add(payloadType(part));
|
|
452
|
+
continue;
|
|
453
|
+
}
|
|
454
|
+
const record = part;
|
|
455
|
+
const type = typeof record.type === "string" ? record.type : "unknown";
|
|
456
|
+
partTypes.add(type);
|
|
457
|
+
if (typeof record.text === "string") {
|
|
458
|
+
chars += record.text.length;
|
|
459
|
+
} else if (typeof record.data === "string") {
|
|
460
|
+
chars += record.data.length;
|
|
461
|
+
} else {
|
|
462
|
+
chars += serializedLength(part);
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
return { chars, partTypes: [...partTypes] };
|
|
466
|
+
}
|
|
467
|
+
function toGenAiMessagesTraceAttributes(prefix, messages) {
|
|
468
|
+
let contentChars = 0;
|
|
469
|
+
const roles = /* @__PURE__ */ new Set();
|
|
470
|
+
const partTypes = /* @__PURE__ */ new Set();
|
|
471
|
+
for (const message of messages) {
|
|
472
|
+
if (!message || typeof message !== "object") {
|
|
473
|
+
contentChars += serializedLength(message);
|
|
474
|
+
continue;
|
|
475
|
+
}
|
|
476
|
+
const record = message;
|
|
477
|
+
if (typeof record.role === "string") {
|
|
478
|
+
roles.add(record.role);
|
|
479
|
+
}
|
|
480
|
+
const summary = summarizeContent(record.content);
|
|
481
|
+
contentChars += summary.chars;
|
|
482
|
+
for (const partType of summary.partTypes) {
|
|
483
|
+
partTypes.add(partType);
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
return {
|
|
487
|
+
[`${prefix}.message_count`]: messages.length,
|
|
488
|
+
[`${prefix}.content_chars`]: contentChars,
|
|
489
|
+
...roles.size > 0 ? { [`${prefix}.roles`]: [...roles] } : {},
|
|
490
|
+
...partTypes.size > 0 ? { [`${prefix}.part_types`]: [...partTypes] } : {}
|
|
491
|
+
};
|
|
492
|
+
}
|
|
493
|
+
|
|
494
494
|
// src/chat/services/provider-retry.ts
|
|
495
495
|
var PROVIDER_RETRY_DELAYS_MS = [2e3, 4e3, 8e3];
|
|
496
496
|
var PROVIDER_ERROR_PREFIX = "AI provider error:";
|