@sentry/junior 0.136.1 → 0.137.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-2KDSPPO4.js → agent-hooks-MZOKEP3J.js} +9 -9
- package/dist/api/conversations/projection.d.ts +1 -0
- package/dist/api/conversations/stats.d.ts +1 -0
- package/dist/api/schema/conversation.d.ts +2 -0
- package/dist/api/schema.js +1 -1
- package/dist/api.js +185 -47
- package/dist/app.d.ts +1 -1
- package/dist/app.js +293 -193
- package/dist/{catalog-runtime-WSZQGC4D.js → catalog-runtime-MD66YLFV.js} +5 -5
- package/dist/chat/configuration/defaults.d.ts +1 -1
- package/dist/chat/conversations/store.d.ts +2 -1
- package/dist/chat/pi/client.d.ts +1 -8
- package/dist/chat/pi/gateway-auth.d.ts +16 -0
- package/dist/chat/sandbox/docker.d.ts +17 -0
- package/dist/chat/services/agent-continue.d.ts +2 -0
- package/dist/chat/services/subscribed-reply-router-policy.d.ts +12 -0
- package/dist/chat/services/turn-session-routing.d.ts +17 -0
- package/dist/chat/slack/message.d.ts +6 -1
- package/dist/chat/slack/source-link.d.ts +8 -2
- package/dist/chat/slack/team-domain.d.ts +4 -0
- package/dist/chat/source.d.ts +5 -5
- package/dist/{chunk-3QNJOHKG.js → chunk-36EG34YI.js} +1 -1
- package/dist/{chunk-FSYXYBWU.js → chunk-3Q342EJJ.js} +2 -2
- package/dist/{chunk-4YQ6I6VF.js → chunk-5G34IEK2.js} +1 -1
- package/dist/{chunk-BG3KWWDJ.js → chunk-5PNJMOY5.js} +1 -1
- package/dist/{chunk-3SUK3UXX.js → chunk-6QW2RRQT.js} +5 -5
- package/dist/{chunk-VH6MI4L7.js → chunk-BZAMASJP.js} +1 -1
- package/dist/{chunk-CDVCCOMF.js → chunk-DQXAAVTR.js} +43 -20
- package/dist/{chunk-G66RYKRS.js → chunk-EWDSB24B.js} +7 -7
- package/dist/{chunk-TRZSM67C.js → chunk-HCIVH3JS.js} +1 -0
- package/dist/{chunk-UX2TNH5D.js → chunk-K2NCQJKH.js} +3 -3
- package/dist/{chunk-OTJMQYVP.js → chunk-KJ4HGRHN.js} +24 -26
- package/dist/{chunk-NVVBEJUB.js → chunk-POBSY47Q.js} +6 -4
- package/dist/{chunk-MW2QRPGW.js → chunk-RB4NJKEX.js} +1 -1
- package/dist/{chunk-Y6JNHTRD.js → chunk-SYCX4DOK.js} +34 -17
- package/dist/{chunk-XWPA5KZF.js → chunk-T6Z5S6PQ.js} +1 -1
- package/dist/{chunk-XCZ6COFO.js → chunk-UG6ZYPBI.js} +42 -19
- package/dist/{chunk-CZZDCH3Q.js → chunk-UOXATPSI.js} +203 -77
- package/dist/{chunk-RFDD3Z2I.js → chunk-UZQ4VY3M.js} +1 -1
- package/dist/{chunk-KLBYCSLJ.js → chunk-WPPXIAFB.js} +5 -5
- package/dist/{chunk-JQRTXJHD.js → chunk-XZ7NPXAB.js} +2 -1
- package/dist/{chunk-22Z6MGMK.js → chunk-YNFERGKP.js} +1 -1
- package/dist/{chunk-TYNMSQKA.js → chunk-YRPC6MJY.js} +1 -1
- package/dist/{chunk-HIRIWTWD.js → chunk-ZFS67WIR.js} +4 -7
- package/dist/cli/chat.js +24 -24
- package/dist/cli/check.js +7 -7
- package/dist/cli/plugins.js +12 -12
- package/dist/cli/snapshot-create.js +9 -9
- package/dist/cli/upgrade.js +7 -7
- package/dist/{db-Z2NNL2JC.js → db-66E7VDNC.js} +7 -7
- package/dist/instrumentation.js +4 -4
- package/dist/nitro.js +2 -2
- package/dist/{oauth-callback-server-PO3M5JMG.js → oauth-callback-server-7QPD4Q7P.js} +17 -17
- package/dist/{runner-QHQYZYJA.js → runner-L2BKJKOD.js} +11 -11
- package/dist/{skills-KXMT3DRA.js → skills-HOQ2NSPW.js} +6 -6
- package/dist/{validation-Y42ULTT6.js → validation-ENHI7S2C.js} +6 -6
- package/dist/version.js +1 -1
- package/package.json +5 -4
|
@@ -30,7 +30,7 @@ import {
|
|
|
30
30
|
toMcpProviderError,
|
|
31
31
|
toolInvocationDestination,
|
|
32
32
|
uploadFilesToConversation
|
|
33
|
-
} from "./chunk-
|
|
33
|
+
} from "./chunk-EWDSB24B.js";
|
|
34
34
|
import {
|
|
35
35
|
AGENTS_REMOVAL_NOTICE,
|
|
36
36
|
AGENTS_REPLACEMENT_NOTICE,
|
|
@@ -98,7 +98,7 @@ import {
|
|
|
98
98
|
trimTrailingAssistantMessages,
|
|
99
99
|
truncateText,
|
|
100
100
|
updateConversationStats
|
|
101
|
-
} from "./chunk-
|
|
101
|
+
} from "./chunk-POBSY47Q.js";
|
|
102
102
|
import {
|
|
103
103
|
parseSandboxEgressAuthRequiredSignal,
|
|
104
104
|
parseSandboxEgressPermissionDeniedSignal,
|
|
@@ -110,6 +110,7 @@ import {
|
|
|
110
110
|
buildCommandScript,
|
|
111
111
|
buildNonInteractiveShellScript,
|
|
112
112
|
createSandboxSession,
|
|
113
|
+
ensureDockerDaemon,
|
|
113
114
|
getSandboxResources,
|
|
114
115
|
getVercelSandboxCredentials,
|
|
115
116
|
hash,
|
|
@@ -123,7 +124,7 @@ import {
|
|
|
123
124
|
runNonInteractiveCommand,
|
|
124
125
|
throwSandboxOperationError,
|
|
125
126
|
wrapSandboxSetupError
|
|
126
|
-
} from "./chunk-
|
|
127
|
+
} from "./chunk-UOXATPSI.js";
|
|
127
128
|
import {
|
|
128
129
|
SCHEDULED_TASK_SYSTEM_ACTOR,
|
|
129
130
|
compactEventTask,
|
|
@@ -154,10 +155,10 @@ import {
|
|
|
154
155
|
resolveLocalScheduleAtMs,
|
|
155
156
|
saveEventTask,
|
|
156
157
|
writableEventTask
|
|
157
|
-
} from "./chunk-
|
|
158
|
+
} from "./chunk-K2NCQJKH.js";
|
|
158
159
|
import {
|
|
159
160
|
parseSlackThreadId
|
|
160
|
-
} from "./chunk-
|
|
161
|
+
} from "./chunk-YRPC6MJY.js";
|
|
161
162
|
import {
|
|
162
163
|
ToolInputError,
|
|
163
164
|
addAgentTurnUsage,
|
|
@@ -181,7 +182,7 @@ import {
|
|
|
181
182
|
readActorIdentity,
|
|
182
183
|
resolveChannelCapabilities,
|
|
183
184
|
withSlackRetries
|
|
184
|
-
} from "./chunk-
|
|
185
|
+
} from "./chunk-WPPXIAFB.js";
|
|
185
186
|
import {
|
|
186
187
|
KNOWN_CONVERSATION_EVENT_TYPES,
|
|
187
188
|
contextProvenance,
|
|
@@ -192,7 +193,7 @@ import {
|
|
|
192
193
|
instructionActors,
|
|
193
194
|
instructionProvenanceFor,
|
|
194
195
|
sameActorIdentity
|
|
195
|
-
} from "./chunk-
|
|
196
|
+
} from "./chunk-ZFS67WIR.js";
|
|
196
197
|
import {
|
|
197
198
|
SANDBOX_DATA_ROOT,
|
|
198
199
|
SANDBOX_SKILLS_ROOT,
|
|
@@ -202,7 +203,7 @@ import {
|
|
|
202
203
|
sandboxSkillFile,
|
|
203
204
|
sandboxSkillPathResolution,
|
|
204
205
|
sleep
|
|
205
|
-
} from "./chunk-
|
|
206
|
+
} from "./chunk-5G34IEK2.js";
|
|
206
207
|
import {
|
|
207
208
|
ACTIVE_TURN_COMPACTION_SUMMARY_PREFIX,
|
|
208
209
|
COMPACTION_SUMMARY_PREFIX,
|
|
@@ -223,7 +224,6 @@ import {
|
|
|
223
224
|
escapeXml,
|
|
224
225
|
findProviderError,
|
|
225
226
|
getGatewayApiKey,
|
|
226
|
-
getPiGatewayApiKey,
|
|
227
227
|
getProviderErrorAttributes,
|
|
228
228
|
hasCompactedConversationContext,
|
|
229
229
|
isCompactionSummaryText,
|
|
@@ -234,9 +234,10 @@ import {
|
|
|
234
234
|
parseTurnReasoningLevel,
|
|
235
235
|
profileConfig,
|
|
236
236
|
renderCurrentInstruction,
|
|
237
|
+
resolveGatewayCredential,
|
|
237
238
|
resolveGatewayModel,
|
|
238
239
|
unwrapCurrentInstruction
|
|
239
|
-
} from "./chunk-
|
|
240
|
+
} from "./chunk-UG6ZYPBI.js";
|
|
240
241
|
import {
|
|
241
242
|
canExposeConversationPayload,
|
|
242
243
|
resolveConversationPrivacy,
|
|
@@ -246,16 +247,16 @@ import {
|
|
|
246
247
|
toGenAiMessagesTraceAttributes,
|
|
247
248
|
toGenAiPayloadMetadata,
|
|
248
249
|
toGenAiPayloadTraceAttributes
|
|
249
|
-
} from "./chunk-
|
|
250
|
+
} from "./chunk-YNFERGKP.js";
|
|
250
251
|
import {
|
|
251
252
|
discoverSkills,
|
|
252
253
|
findSkillByName,
|
|
253
254
|
loadSkillsByName,
|
|
254
255
|
parseSkillInvocation
|
|
255
|
-
} from "./chunk-
|
|
256
|
+
} from "./chunk-3Q342EJJ.js";
|
|
256
257
|
import {
|
|
257
258
|
pluginCatalogRuntime
|
|
258
|
-
} from "./chunk-
|
|
259
|
+
} from "./chunk-36EG34YI.js";
|
|
259
260
|
import {
|
|
260
261
|
CredentialUnavailableError,
|
|
261
262
|
OAuthProviderError,
|
|
@@ -263,7 +264,7 @@ import {
|
|
|
263
264
|
getOAuthProviderErrorAttributes,
|
|
264
265
|
resolveAuthTokenPlaceholder,
|
|
265
266
|
resolvePluginCommandEnv
|
|
266
|
-
} from "./chunk-
|
|
267
|
+
} from "./chunk-BZAMASJP.js";
|
|
267
268
|
import {
|
|
268
269
|
credentialUserSubjectId
|
|
269
270
|
} from "./chunk-77VDLF3Z.js";
|
|
@@ -292,7 +293,7 @@ import {
|
|
|
292
293
|
summarizeMessageText,
|
|
293
294
|
withLogContext,
|
|
294
295
|
withSpan
|
|
295
|
-
} from "./chunk-
|
|
296
|
+
} from "./chunk-T6Z5S6PQ.js";
|
|
296
297
|
import {
|
|
297
298
|
startInactiveSpan,
|
|
298
299
|
withActiveSpan
|
|
@@ -321,13 +322,6 @@ function setConfigDefaults(defaults) {
|
|
|
321
322
|
"configDefaults must be an object keyed by plugin config key"
|
|
322
323
|
);
|
|
323
324
|
}
|
|
324
|
-
for (const key of Object.keys(defaults)) {
|
|
325
|
-
if (!pluginCatalogRuntime.isConfigKey(key)) {
|
|
326
|
-
throw new Error(
|
|
327
|
-
`configDefaults: "${key}" is not a registered plugin config key`
|
|
328
|
-
);
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
325
|
installDefaults = cloneDefaults(defaults);
|
|
332
326
|
}
|
|
333
327
|
function getConfigDefaults() {
|
|
@@ -3424,6 +3418,7 @@ function createSandboxRuntime(options) {
|
|
|
3424
3418
|
};
|
|
3425
3419
|
const prepareSandbox = async (targetSandbox) => {
|
|
3426
3420
|
await syncSkills(targetSandbox);
|
|
3421
|
+
await ensureDockerDaemon(targetSandbox);
|
|
3427
3422
|
await options.onSandboxPrepare?.(targetSandbox);
|
|
3428
3423
|
};
|
|
3429
3424
|
const applyNetworkPolicy = async (targetSandbox, traceHeaders) => {
|
|
@@ -7003,7 +6998,7 @@ function createImageGenerateTool(hooks, options, deps = {}) {
|
|
|
7003
6998
|
outputSchema: imageGenerateOutputSchema,
|
|
7004
6999
|
execute: async ({ prompt }) => {
|
|
7005
7000
|
const fetchImpl = deps.fetch ?? fetch;
|
|
7006
|
-
const apiKey = getGatewayApiKey();
|
|
7001
|
+
const apiKey = await getGatewayApiKey();
|
|
7007
7002
|
if (!apiKey) {
|
|
7008
7003
|
throw new Error(MISSING_GATEWAY_CREDENTIALS_ERROR);
|
|
7009
7004
|
}
|
|
@@ -12532,7 +12527,10 @@ function createWebSearchTool(modelId, override) {
|
|
|
12532
12527
|
}
|
|
12533
12528
|
const maxResults = max_results ?? 3;
|
|
12534
12529
|
const controller = new AbortController();
|
|
12535
|
-
const
|
|
12530
|
+
const credential = await resolveGatewayCredential();
|
|
12531
|
+
const provider = createGatewayProvider(
|
|
12532
|
+
credential ? { apiKey: credential.token } : {}
|
|
12533
|
+
);
|
|
12536
12534
|
const response = await withTimeout(
|
|
12537
12535
|
generateText({
|
|
12538
12536
|
model: provider.chat(modelId),
|
|
@@ -16948,9 +16946,9 @@ async function executeAgentRunInPrivacyContext(request, conversationPrivacy, run
|
|
|
16948
16946
|
}
|
|
16949
16947
|
return acceptedMessages;
|
|
16950
16948
|
};
|
|
16951
|
-
const apiKeyOverride = getPiGatewayApiKey();
|
|
16952
16949
|
agent = new Agent({
|
|
16953
|
-
|
|
16950
|
+
// Resolve on every provider call so runtime OIDC tokens stay fresh.
|
|
16951
|
+
getApiKey: getGatewayApiKey,
|
|
16954
16952
|
streamFn: createTracedStreamFn({
|
|
16955
16953
|
conversationPrivacy,
|
|
16956
16954
|
...streamFn ? { base: streamFn } : {}
|
|
@@ -18,18 +18,18 @@ import {
|
|
|
18
18
|
instructionProvenanceFor,
|
|
19
19
|
sanitizePostgresJson,
|
|
20
20
|
withConversationEventLock
|
|
21
|
-
} from "./chunk-
|
|
21
|
+
} from "./chunk-ZFS67WIR.js";
|
|
22
22
|
import {
|
|
23
23
|
SANDBOX_WORKSPACE_ROOT,
|
|
24
24
|
getStateAdapter,
|
|
25
25
|
sleep
|
|
26
|
-
} from "./chunk-
|
|
26
|
+
} from "./chunk-5G34IEK2.js";
|
|
27
27
|
import {
|
|
28
28
|
botConfig,
|
|
29
29
|
escapeXml,
|
|
30
30
|
resolveGatewayModel,
|
|
31
31
|
unwrapCurrentInstruction
|
|
32
|
-
} from "./chunk-
|
|
32
|
+
} from "./chunk-UG6ZYPBI.js";
|
|
33
33
|
import {
|
|
34
34
|
toStoredSlackActor
|
|
35
35
|
} from "./chunk-HZF5P5UN.js";
|
|
@@ -44,7 +44,7 @@ import {
|
|
|
44
44
|
setSpanAttributes,
|
|
45
45
|
toOptionalNumber,
|
|
46
46
|
toOptionalString
|
|
47
|
-
} from "./chunk-
|
|
47
|
+
} from "./chunk-T6Z5S6PQ.js";
|
|
48
48
|
|
|
49
49
|
// src/chat/turn-context-tag.ts
|
|
50
50
|
var TURN_CONTEXT_TAG = "runtime-turn-context";
|
|
@@ -1811,6 +1811,8 @@ var agentTurnSessionSummarySchema = z2.object({
|
|
|
1811
1811
|
conversationId: z2.string().min(1),
|
|
1812
1812
|
cumulativeDurationMs: nonNegativeNumberSchema,
|
|
1813
1813
|
cumulativeUsage: agentTurnUsageSchema.optional(),
|
|
1814
|
+
// TODO(#1267): Remove destination/source and their Redis write paths once
|
|
1815
|
+
// SQL-only readers are deployed; existing records do not need to expire.
|
|
1814
1816
|
destination: destinationSchema.optional(),
|
|
1815
1817
|
dispatchId: z2.string().min(1).optional(),
|
|
1816
1818
|
dispatchOutcome: z2.enum(["blocked", "completed", "failed"]).optional(),
|
|
@@ -22,7 +22,7 @@ import {
|
|
|
22
22
|
persistThreadStateById,
|
|
23
23
|
stripRuntimeTurnContext,
|
|
24
24
|
updateConversationStats
|
|
25
|
-
} from "./chunk-
|
|
25
|
+
} from "./chunk-POBSY47Q.js";
|
|
26
26
|
import {
|
|
27
27
|
createPluginConversationEvents,
|
|
28
28
|
createPluginEmbedder,
|
|
@@ -30,26 +30,26 @@ import {
|
|
|
30
30
|
createPluginModel,
|
|
31
31
|
createPluginState,
|
|
32
32
|
getPlugins
|
|
33
|
-
} from "./chunk-
|
|
33
|
+
} from "./chunk-WPPXIAFB.js";
|
|
34
34
|
import {
|
|
35
35
|
getDb,
|
|
36
36
|
sameActorIdentity
|
|
37
|
-
} from "./chunk-
|
|
37
|
+
} from "./chunk-ZFS67WIR.js";
|
|
38
38
|
import {
|
|
39
39
|
getStateAdapter
|
|
40
|
-
} from "./chunk-
|
|
40
|
+
} from "./chunk-5G34IEK2.js";
|
|
41
41
|
import {
|
|
42
42
|
ProviderError,
|
|
43
43
|
findProviderError,
|
|
44
44
|
getProviderErrorAttributes,
|
|
45
45
|
getProviderErrorUserMessage
|
|
46
|
-
} from "./chunk-
|
|
46
|
+
} from "./chunk-UG6ZYPBI.js";
|
|
47
47
|
import {
|
|
48
48
|
parseSlackMessageTs
|
|
49
49
|
} from "./chunk-F3B2YJ76.js";
|
|
50
50
|
import {
|
|
51
51
|
buildTurnFailureResponse
|
|
52
|
-
} from "./chunk-
|
|
52
|
+
} from "./chunk-T6Z5S6PQ.js";
|
|
53
53
|
|
|
54
54
|
// src/chat/runtime/delivered-turn-state.ts
|
|
55
55
|
function buildDeliveredTurnStatePatch(args) {
|
|
@@ -82,6 +82,25 @@ import {
|
|
|
82
82
|
isPrivateSource,
|
|
83
83
|
pluginRunContextSchema
|
|
84
84
|
} from "@sentry/junior-plugin-api";
|
|
85
|
+
|
|
86
|
+
// src/chat/services/turn-session-routing.ts
|
|
87
|
+
async function resolveTurnSessionRouting(args) {
|
|
88
|
+
const conversationStore = args.conversationStore ?? (await import("./db-66E7VDNC.js")).getConversationStore();
|
|
89
|
+
const conversation = await conversationStore.get({
|
|
90
|
+
conversationId: args.conversationId
|
|
91
|
+
});
|
|
92
|
+
if (!conversation?.destination || !conversation.sessionSource) {
|
|
93
|
+
throw new Error(
|
|
94
|
+
`Conversation ${args.conversationId} is missing durable routing metadata`
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
return {
|
|
98
|
+
destination: conversation.destination,
|
|
99
|
+
source: conversation.sessionSource
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// src/chat/plugins/task-runner.ts
|
|
85
104
|
var PLUGIN_TASK_LOCK_TTL_MS = 5 * 60 * 1e3;
|
|
86
105
|
function isRecord(value) {
|
|
87
106
|
return Boolean(value && typeof value === "object" && !Array.isArray(value));
|
|
@@ -210,9 +229,8 @@ function messageExistedAtRunCompletion(message, completedAtMs) {
|
|
|
210
229
|
const messageTimestampMs = conversationMessageTimestampMs(message);
|
|
211
230
|
return messageTimestampMs !== void 0 && messageTimestampMs <= completedAtMs;
|
|
212
231
|
}
|
|
213
|
-
async function loadConversationContextTranscriptEntries(record) {
|
|
214
|
-
|
|
215
|
-
if (source?.platform !== "slack" || isPrivateSource(source)) {
|
|
232
|
+
async function loadConversationContextTranscriptEntries(record, source) {
|
|
233
|
+
if (source.platform !== "slack" || isPrivateSource(source)) {
|
|
216
234
|
return [];
|
|
217
235
|
}
|
|
218
236
|
const state = await getPersistedThreadState(record.conversationId);
|
|
@@ -274,30 +292,28 @@ async function loadPluginRun(params) {
|
|
|
274
292
|
if (record.state !== "completed") {
|
|
275
293
|
throw new Error("Completed plugin task session record is not completed");
|
|
276
294
|
}
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
);
|
|
281
|
-
}
|
|
295
|
+
const routing = await resolveTurnSessionRouting({
|
|
296
|
+
conversationId: params.conversationId
|
|
297
|
+
});
|
|
282
298
|
const runEntries = turnMessagesWithProvenance(record).map(
|
|
283
299
|
({ message, provenance }) => runTranscriptEntry(message, provenance, record.actor)
|
|
284
300
|
).filter((entry) => Boolean(entry));
|
|
285
301
|
const runMessageTexts = new Set(
|
|
286
302
|
runEntries.filter((entry) => entry.type === "message").map((entry) => entry.text)
|
|
287
303
|
);
|
|
288
|
-
const contextEntries = (await loadConversationContextTranscriptEntries(record)).filter(
|
|
304
|
+
const contextEntries = (await loadConversationContextTranscriptEntries(record, routing.source)).filter(
|
|
289
305
|
(entry) => entry.type !== "message" || !runMessageTexts.has(entry.text)
|
|
290
306
|
);
|
|
291
307
|
return pluginRunContextSchema.parse({
|
|
292
308
|
completedAtMs: record.updatedAtMs,
|
|
293
309
|
conversationId: record.conversationId,
|
|
294
|
-
destination:
|
|
310
|
+
destination: routing.destination,
|
|
295
311
|
// Derived from the full run provenance on the record, not the sliced or
|
|
296
312
|
// stripped transcript, so it reflects every committed instruction actor.
|
|
297
313
|
actors: record.actors,
|
|
298
314
|
...record.actor ? { actor: record.actor } : {},
|
|
299
315
|
runId: record.sessionId,
|
|
300
|
-
source:
|
|
316
|
+
source: routing.source,
|
|
301
317
|
transcript: [...contextEntries, ...runEntries]
|
|
302
318
|
});
|
|
303
319
|
}
|
|
@@ -589,6 +605,7 @@ export {
|
|
|
589
605
|
getTurnUserMessageId,
|
|
590
606
|
getTurnUserSlackMessageTs,
|
|
591
607
|
getTurnUserReplyAttachmentContext,
|
|
608
|
+
resolveTurnSessionRouting,
|
|
592
609
|
scheduleSessionCompletedPluginTasks,
|
|
593
610
|
processPluginTask,
|
|
594
611
|
getInterruptionMarker,
|
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
toCanonicalInputMessage,
|
|
4
4
|
toCanonicalOutputMessage,
|
|
5
5
|
toGenAiMessagesTraceAttributes
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-YNFERGKP.js";
|
|
7
7
|
import {
|
|
8
8
|
extractGenAiUsageAttributes,
|
|
9
9
|
logException,
|
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
normalizeGenAiFinishReason,
|
|
12
12
|
serializeGenAiAttribute,
|
|
13
13
|
withSpan
|
|
14
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-T6Z5S6PQ.js";
|
|
15
15
|
|
|
16
16
|
// src/chat/config.ts
|
|
17
17
|
import { getModel as getModel2 } from "@earendil-works/pi-ai/compat";
|
|
@@ -42,6 +42,29 @@ import {
|
|
|
42
42
|
|
|
43
43
|
// src/chat/pi/client.ts
|
|
44
44
|
import { createGatewayProvider } from "@ai-sdk/gateway";
|
|
45
|
+
|
|
46
|
+
// src/chat/pi/gateway-auth.ts
|
|
47
|
+
import { getVercelOidcToken } from "@vercel/oidc";
|
|
48
|
+
var MISSING_GATEWAY_CREDENTIALS_ERROR = "Missing AI gateway credentials (enable Vercel OIDC or set AI_GATEWAY_API_KEY)";
|
|
49
|
+
async function resolveGatewayCredential() {
|
|
50
|
+
try {
|
|
51
|
+
const oidcToken = toOptionalTrimmed(await getVercelOidcToken());
|
|
52
|
+
if (oidcToken) {
|
|
53
|
+
return { mode: "oidc", token: oidcToken };
|
|
54
|
+
}
|
|
55
|
+
} catch {
|
|
56
|
+
}
|
|
57
|
+
const apiKey = toOptionalTrimmed(getEnvApiKey("vercel-ai-gateway"));
|
|
58
|
+
if (apiKey) {
|
|
59
|
+
return { mode: "api_key", token: apiKey };
|
|
60
|
+
}
|
|
61
|
+
return void 0;
|
|
62
|
+
}
|
|
63
|
+
async function getGatewayApiKey() {
|
|
64
|
+
return (await resolveGatewayCredential())?.token;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// src/chat/pi/client.ts
|
|
45
68
|
import {
|
|
46
69
|
embedMany,
|
|
47
70
|
generateObject,
|
|
@@ -332,17 +355,10 @@ var EMBEDDING_INPUT_COST_USD_PER_MILLION_TOKENS = {
|
|
|
332
355
|
"voyage/voyage-3.5": 0.06,
|
|
333
356
|
"voyage/voyage-3.5-lite": 0.02
|
|
334
357
|
};
|
|
335
|
-
var MISSING_GATEWAY_CREDENTIALS_ERROR = "Missing AI gateway credentials (AI_GATEWAY_API_KEY or VERCEL_OIDC_TOKEN)";
|
|
336
358
|
function embeddingCostUsd(modelId, inputTokens) {
|
|
337
359
|
const costPerMillionTokens = EMBEDDING_INPUT_COST_USD_PER_MILLION_TOKENS[modelId];
|
|
338
360
|
return costPerMillionTokens === void 0 ? void 0 : inputTokens * costPerMillionTokens / 1e6;
|
|
339
361
|
}
|
|
340
|
-
function getGatewayApiKey() {
|
|
341
|
-
return toOptionalTrimmed(getEnvApiKey("vercel-ai-gateway")) ?? toOptionalTrimmed(process.env.VERCEL_OIDC_TOKEN);
|
|
342
|
-
}
|
|
343
|
-
function getPiGatewayApiKey() {
|
|
344
|
-
return getGatewayApiKey();
|
|
345
|
-
}
|
|
346
362
|
function extractText(message) {
|
|
347
363
|
return (message.content ?? []).filter((part) => part.type === "text" && typeof part.text === "string").map((part) => part.text ?? "").join("").trim();
|
|
348
364
|
}
|
|
@@ -357,8 +373,9 @@ function resolveGatewayModel(modelId) {
|
|
|
357
373
|
}
|
|
358
374
|
async function completeText(params) {
|
|
359
375
|
const model = resolveGatewayModel(params.modelId);
|
|
360
|
-
const
|
|
361
|
-
const
|
|
376
|
+
const credential = await resolveGatewayCredential();
|
|
377
|
+
const apiKey = credential?.token;
|
|
378
|
+
const authMode = credential?.mode ?? "api_key";
|
|
362
379
|
const effectivePrivacy = getCurrentConversationPrivacy() ?? "private";
|
|
363
380
|
const messageAttributeMode = params.messageAttributeMode ?? (effectivePrivacy === "public" ? "content" : "metadata");
|
|
364
381
|
const requestMessagesAttribute = messageAttributeMode === "content" ? serializeGenAiAttribute(params.messages.map(toCanonicalInputMessage)) : void 0;
|
|
@@ -490,8 +507,10 @@ function bestEffortObjectCompletionCost(modelId, usage) {
|
|
|
490
507
|
}
|
|
491
508
|
}
|
|
492
509
|
async function completeObject(params) {
|
|
493
|
-
const
|
|
494
|
-
const provider = createGatewayProvider(
|
|
510
|
+
const credential = await resolveGatewayCredential();
|
|
511
|
+
const provider = createGatewayProvider(
|
|
512
|
+
credential ? { apiKey: credential.token } : {}
|
|
513
|
+
);
|
|
495
514
|
let result;
|
|
496
515
|
try {
|
|
497
516
|
result = await withSpan(
|
|
@@ -528,6 +547,7 @@ async function completeObject(params) {
|
|
|
528
547
|
"gen_ai.output.type": "json",
|
|
529
548
|
"server.address": GEN_AI_SERVER_ADDRESS,
|
|
530
549
|
"server.port": GEN_AI_SERVER_PORT,
|
|
550
|
+
"gen_ai.provider.auth_mode": credential?.mode ?? "api_key",
|
|
531
551
|
...params.thinkingLevel ? { "gen_ai.request.reasoning.level": params.thinkingLevel } : {},
|
|
532
552
|
...params.temperature !== void 0 ? { "gen_ai.request.temperature": params.temperature } : {},
|
|
533
553
|
...params.maxTokens !== void 0 ? { "gen_ai.request.max_tokens": params.maxTokens } : {}
|
|
@@ -551,8 +571,10 @@ async function embedTexts(params) {
|
|
|
551
571
|
if (texts.length === 0 || texts.some((text) => text.length === 0)) {
|
|
552
572
|
throw new Error("Embedding text is required.");
|
|
553
573
|
}
|
|
554
|
-
const
|
|
555
|
-
const provider = createGatewayProvider(
|
|
574
|
+
const credential = await resolveGatewayCredential();
|
|
575
|
+
const provider = createGatewayProvider(
|
|
576
|
+
credential ? { apiKey: credential.token } : {}
|
|
577
|
+
);
|
|
556
578
|
try {
|
|
557
579
|
const result = await withSpan(
|
|
558
580
|
`${GEN_AI_OPERATION_EMBEDDINGS} ${params.modelId}`,
|
|
@@ -591,7 +613,8 @@ async function embedTexts(params) {
|
|
|
591
613
|
"gen_ai.operation.name": GEN_AI_OPERATION_EMBEDDINGS,
|
|
592
614
|
"gen_ai.request.model": params.modelId,
|
|
593
615
|
"server.address": GEN_AI_SERVER_ADDRESS,
|
|
594
|
-
"server.port": GEN_AI_SERVER_PORT
|
|
616
|
+
"server.port": GEN_AI_SERVER_PORT,
|
|
617
|
+
"gen_ai.provider.auth_mode": credential?.mode ?? "api_key"
|
|
595
618
|
}
|
|
596
619
|
);
|
|
597
620
|
return {
|
|
@@ -1008,6 +1031,9 @@ function setSlackReactionConfig(overrides) {
|
|
|
1008
1031
|
|
|
1009
1032
|
export {
|
|
1010
1033
|
toOptionalTrimmed,
|
|
1034
|
+
MISSING_GATEWAY_CREDENTIALS_ERROR,
|
|
1035
|
+
resolveGatewayCredential,
|
|
1036
|
+
getGatewayApiKey,
|
|
1011
1037
|
ProviderError,
|
|
1012
1038
|
createProviderError,
|
|
1013
1039
|
isProviderRetryError,
|
|
@@ -1025,9 +1051,6 @@ export {
|
|
|
1025
1051
|
GEN_AI_PROVIDER_NAME,
|
|
1026
1052
|
GEN_AI_SERVER_ADDRESS,
|
|
1027
1053
|
GEN_AI_SERVER_PORT,
|
|
1028
|
-
MISSING_GATEWAY_CREDENTIALS_ERROR,
|
|
1029
|
-
getGatewayApiKey,
|
|
1030
|
-
getPiGatewayApiKey,
|
|
1031
1054
|
resolveGatewayModel,
|
|
1032
1055
|
completeText,
|
|
1033
1056
|
completeObject,
|