@sentry/junior 0.179.0 → 0.180.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-32IDCLMW.js → agent-hooks-DKDDRKZA.js} +16 -18
- package/dist/api/schema.js +0 -1
- package/dist/api.js +199 -197
- package/dist/app.d.ts +4 -0
- package/dist/app.js +300 -1259
- package/dist/catalog-runtime-WXKGUF3W.js +14 -0
- package/dist/chat/agent/sandbox.d.ts +0 -2
- package/dist/chat/api-turns/routing.d.ts +4 -0
- package/dist/chat/api-turns/work.d.ts +5 -0
- package/dist/chat/config.d.ts +5 -2
- package/dist/chat/configuration/defaults.d.ts +1 -1
- package/dist/chat/conversations/projection.d.ts +6 -4
- package/dist/chat/ingress/message-router.d.ts +3 -0
- package/dist/chat/model-profile.d.ts +8 -10
- package/dist/chat/pi/conversation-events.d.ts +3 -2
- package/dist/chat/plugins/task-queue.d.ts +40 -3
- package/dist/chat/plugins/task-runner.d.ts +1 -1
- package/dist/chat/queue/callback.d.ts +26 -0
- package/dist/chat/queue/sign.d.ts +30 -0
- package/dist/chat/sandbox/sandbox.d.ts +0 -2
- package/dist/chat/sandbox/session.d.ts +0 -2
- package/dist/chat/sandbox/skill-sync.d.ts +1 -1
- package/dist/chat/sandbox/snapshot/events.d.ts +23 -0
- package/dist/chat/sandbox/snapshot/job-callback.d.ts +5 -0
- package/dist/chat/sandbox/snapshot/job-queue.d.ts +26 -0
- package/dist/chat/sandbox/snapshot/job-runner.d.ts +11 -0
- package/dist/chat/sandbox/snapshot/not-ready-error.d.ts +6 -0
- package/dist/chat/sandbox/snapshot/workspace.d.ts +9 -3
- package/dist/chat/services/turn-router.d.ts +4 -3
- package/dist/chat/task-execution/queue-signing.d.ts +10 -21
- package/dist/chat/task-execution/state.d.ts +48 -0
- package/dist/chat/task-execution/store.d.ts +28 -2
- package/dist/chat/task-execution/worker.d.ts +4 -1
- package/dist/chat/tools/handoff/tool.d.ts +1 -1
- package/dist/{chunk-B6ECUSVX.js → chunk-2AYEVN7K.js} +8 -8
- package/dist/{chunk-SLGGOASN.js → chunk-2YIRH4E3.js} +46 -46
- package/dist/{chunk-KJLHIHFF.js → chunk-3ILJBWP7.js} +35 -227
- package/dist/{chunk-RZRYOLCE.js → chunk-5PUMIMNQ.js} +2292 -1147
- package/dist/{chunk-CJLBLELR.js → chunk-5TUR4M3M.js} +8 -61
- package/dist/{chunk-6ZWRNC4D.js → chunk-6Y5B5PEX.js} +1 -1
- package/dist/{chunk-XSPSCWLH.js → chunk-6YCEWOLO.js} +4 -4
- package/dist/chunk-7H2VZTWN.js +103 -0
- package/dist/{chunk-FAS6AIMF.js → chunk-CCDXTDSY.js} +8 -8
- package/dist/{chunk-CGA4ERJ5.js → chunk-CEMMLV5L.js} +1 -1
- package/dist/{chunk-XZY6G5YZ.js → chunk-CK6EINVZ.js} +180 -87
- package/dist/{chunk-FIANEE7Z.js → chunk-CM5HNV2W.js} +6 -6
- package/dist/{chunk-JT4WMD3C.js → chunk-CP73FKME.js} +144 -218
- package/dist/{chunk-3I7XE3PA.js → chunk-DHLOGWYH.js} +36 -36
- package/dist/chunk-DKIJ2RP5.js +68 -0
- package/dist/{chunk-YFNAMRGE.js → chunk-DRHEGXTZ.js} +1 -1
- package/dist/{chunk-OOUNJNMR.js → chunk-DWPN6SCH.js} +1 -1
- package/dist/chunk-EWHP2IRG.js +209 -0
- package/dist/{chunk-R6U7N4FS.js → chunk-FGC3PHNH.js} +3 -3
- package/dist/{chunk-3TM3FYLQ.js → chunk-GA5NS74S.js} +1 -1
- package/dist/{chunk-FIDMHAO6.js → chunk-GPXAHUQH.js} +84 -274
- package/dist/chunk-GUKXEPMX.js +218 -0
- package/dist/{chunk-GENV6KF2.js → chunk-I6IFTAPF.js} +108 -76
- package/dist/{chunk-R5NWWYIS.js → chunk-IANUX7HX.js} +5 -5
- package/dist/{chunk-G2CAC4CV.js → chunk-KCL6AWYW.js} +74 -68
- package/dist/{chunk-5IRROPA5.js → chunk-L7LTGN4Z.js} +129 -31
- package/dist/{chunk-Q5B3WTGG.js → chunk-LGVQLNLS.js} +42 -41
- package/dist/chunk-M3QYTBQ6.js +55 -0
- package/dist/{chunk-FTGD2FBP.js → chunk-MXEUIGHO.js} +2 -2
- package/dist/{chunk-M63DETLL.js → chunk-N7TMSOZH.js} +6 -6
- package/dist/{chunk-2HIPYNQI.js → chunk-O4QYZTDK.js} +33 -32
- package/dist/chunk-PEQXYSSE.js +45 -0
- package/dist/{chunk-RTRBYSF3.js → chunk-QSO7B5JO.js} +1 -1
- package/dist/{chunk-HQNE5APD.js → chunk-RAZG3YHC.js} +100 -79
- package/dist/{chunk-VP4OVRDD.js → chunk-S7YRTOSQ.js} +69 -73
- package/dist/{chunk-U4TKB6F6.js → chunk-SDBKZ5LV.js} +108 -5
- package/dist/{chunk-GPLAT6H7.js → chunk-TC5DE5KJ.js} +22 -18
- package/dist/{chunk-H4HBKISO.js → chunk-TXKUKMVO.js} +1 -1
- package/dist/chunk-U5EUCUBH.js +164 -0
- package/dist/{chunk-3AFVR5UC.js → chunk-VG722ONZ.js} +18 -16
- package/dist/{chunk-ZQMG3CL5.js → chunk-VGPPWWHF.js} +16 -16
- package/dist/{chunk-JMJNFEDC.js → chunk-WVAMRKYG.js} +9 -54
- package/dist/chunk-X6GDDWQH.js +60 -0
- package/dist/{chunk-4GWXAILB.js → chunk-ZE2KOV3G.js} +1 -1
- package/dist/{chunk-TIEKUH4Q.js → chunk-ZM7ZURJS.js} +4 -3
- package/dist/cli/chat.js +47 -43
- package/dist/cli/check.js +13 -15
- package/dist/cli/env.js +0 -1
- package/dist/cli/init.js +0 -1
- package/dist/cli/main.js +2 -3
- package/dist/cli/plugins.js +18 -20
- package/dist/cli/run.js +0 -1
- package/dist/cli/snapshot-create.js +14 -16
- package/dist/cli/upgrade.js +16 -18
- package/dist/{conversation-work-KATFHLG3.js → conversation-work-VIOQ5ZF3.js} +0 -2
- package/dist/{db-EJAV7JL6.js → db-6SBHIAJK.js} +8 -10
- package/dist/deployment.d.ts +1 -0
- package/dist/{discovery-GUFTFBTL.js → discovery-DWVDM7UK.js} +1 -2
- package/dist/{experimental-XVDOSRBS.js → experimental-SIJSRDJD.js} +0 -1
- package/dist/instrumentation.js +7 -9
- package/dist/nitro.js +39 -13
- package/dist/{oauth-callback-server-GAVSUBTQ.js → oauth-callback-server-WSDQPZZS.js} +34 -32
- package/dist/{oauth-relay-3ZU72UGL.js → oauth-relay-5XPVRPYB.js} +0 -1
- package/dist/{plugins-HW4VWW6G.js → plugins-YTYJMMJF.js} +1 -2
- package/dist/{runner-34JL64JF.js → runner-GWTSWESR.js} +39 -33
- package/dist/{sandbox-egress-signals-DXOOBSBI.js → sandbox-egress-signals-FIL7EGPR.js} +5 -6
- package/dist/{sentry-JMWTS32N.js → sentry-MB3NL3IR.js} +1 -2
- package/dist/skills-F32BPFYW.js +27 -0
- package/dist/spawn-X5BPP5OE.js +37 -0
- package/dist/task-runner-2FPBV5PP.js +32 -0
- package/dist/validation-62WO524A.js +17 -0
- package/dist/vercel.js +0 -1
- package/dist/version.js +1 -2
- package/dist/work-3C3CMZ24.js +45 -0
- package/dist/worker-MFAI6ZEK.js +22 -0
- package/package.json +8 -7
- package/dist/catalog-runtime-FBVA6WAQ.js +0 -16
- package/dist/chat/plugins/task-callback.d.ts +0 -5
- package/dist/chat/plugins/task-message.d.ts +0 -23
- package/dist/chat/plugins/task-signing.d.ts +0 -31
- package/dist/chat/sandbox/snapshot/waiting-error.d.ts +0 -15
- package/dist/chat/services/workspace-snapshot-wait.d.ts +0 -27
- package/dist/chunk-5I6ORJUY.js +0 -127
- package/dist/chunk-6GWA276C.js +0 -72
- package/dist/chunk-MLKGABMK.js +0 -9
- package/dist/chunk-UT6X7XN7.js +0 -51
- package/dist/chunk-WR76IVA5.js +0 -130
- package/dist/skills-U545HALM.js +0 -29
- package/dist/spawn-I2S4IDUQ.js +0 -37
- package/dist/validation-EVXVGA44.js +0 -19
- package/dist/work-QOAUPDBU.js +0 -45
- package/dist/worker-5GX2IKLZ.js +0 -24
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
getConversationEventStore,
|
|
6
6
|
getDb,
|
|
7
7
|
getSqlExecutor
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-S7YRTOSQ.js";
|
|
9
9
|
import {
|
|
10
10
|
juniorConversationAnnotations,
|
|
11
11
|
juniorConversationEvents,
|
|
@@ -14,7 +14,7 @@ import {
|
|
|
14
14
|
juniorUsers,
|
|
15
15
|
juniorWorkspaceRepos,
|
|
16
16
|
juniorWorkspaces
|
|
17
|
-
} from "./chunk-
|
|
17
|
+
} from "./chunk-FGC3PHNH.js";
|
|
18
18
|
import {
|
|
19
19
|
SANDBOX_WORKSPACE_ROOT,
|
|
20
20
|
getVercelSandboxCredentials,
|
|
@@ -22,24 +22,24 @@ import {
|
|
|
22
22
|
isSandboxMissingError,
|
|
23
23
|
runNonInteractiveCommand,
|
|
24
24
|
sleep
|
|
25
|
-
} from "./chunk-
|
|
25
|
+
} from "./chunk-WVAMRKYG.js";
|
|
26
26
|
import {
|
|
27
27
|
getStateAdapter
|
|
28
|
-
} from "./chunk-
|
|
28
|
+
} from "./chunk-GA5NS74S.js";
|
|
29
29
|
import {
|
|
30
30
|
botConfig,
|
|
31
31
|
completeObject,
|
|
32
|
+
defaultModelId,
|
|
32
33
|
embedTexts,
|
|
33
|
-
getSlackBotToken
|
|
34
|
-
|
|
35
|
-
} from "./chunk-GENV6KF2.js";
|
|
34
|
+
getSlackBotToken
|
|
35
|
+
} from "./chunk-I6IFTAPF.js";
|
|
36
36
|
import {
|
|
37
37
|
isActorUserId,
|
|
38
38
|
parseActorUserId,
|
|
39
39
|
parseSlackChannelReferenceId,
|
|
40
40
|
parseSlackMessageTs,
|
|
41
41
|
parseSlackTeamId
|
|
42
|
-
} from "./chunk-
|
|
42
|
+
} from "./chunk-N7TMSOZH.js";
|
|
43
43
|
import {
|
|
44
44
|
logException,
|
|
45
45
|
logInfo,
|
|
@@ -48,15 +48,15 @@ import {
|
|
|
48
48
|
setSpanAttributes,
|
|
49
49
|
setSpanStatus,
|
|
50
50
|
withSpan
|
|
51
|
-
} from "./chunk-
|
|
51
|
+
} from "./chunk-RAZG3YHC.js";
|
|
52
52
|
|
|
53
53
|
// src/chat/plugins/agent-hooks.ts
|
|
54
54
|
import {
|
|
55
55
|
missingToolAnnotationKeys,
|
|
56
56
|
normalizeResourceEventIdentifier,
|
|
57
|
+
pluginResourceEventsSchema,
|
|
57
58
|
promptContextSchema,
|
|
58
59
|
promptMessageSchema,
|
|
59
|
-
pluginResourceEventsSchema,
|
|
60
60
|
resourceEventInputSchema
|
|
61
61
|
} from "@sentry/junior-plugin-api";
|
|
62
62
|
|
|
@@ -300,13 +300,13 @@ function createPluginLogger(plugin) {
|
|
|
300
300
|
function createPluginModel(pluginName, options = {}, runtime = {}) {
|
|
301
301
|
return {
|
|
302
302
|
async completeObject(input) {
|
|
303
|
-
const modelId = options.structuredModelId ?? (options.structuredModel === "default" ?
|
|
303
|
+
const modelId = options.structuredModelId ?? (options.structuredModel === "default" ? defaultModelId(botConfig) : botConfig.fastModelId);
|
|
304
304
|
const result = await completeObject({
|
|
305
305
|
modelId,
|
|
306
306
|
schema: input.schema,
|
|
307
307
|
prompt: input.prompt,
|
|
308
|
-
...input.system !== void 0 ? { system: input.system } :
|
|
309
|
-
...input.maxTokens !== void 0 ? { maxTokens: input.maxTokens } :
|
|
308
|
+
...input.system !== void 0 ? { system: input.system } : void 0,
|
|
309
|
+
...input.maxTokens !== void 0 ? { maxTokens: input.maxTokens } : void 0,
|
|
310
310
|
signal: runtime.signal,
|
|
311
311
|
promptName: `${pluginName}.structured_completion`,
|
|
312
312
|
metadata: {
|
|
@@ -316,7 +316,7 @@ function createPluginModel(pluginName, options = {}, runtime = {}) {
|
|
|
316
316
|
});
|
|
317
317
|
return {
|
|
318
318
|
object: result.object,
|
|
319
|
-
...result.costUsd !== void 0 ? { costUsd: result.costUsd } :
|
|
319
|
+
...result.costUsd !== void 0 ? { costUsd: result.costUsd } : void 0
|
|
320
320
|
};
|
|
321
321
|
}
|
|
322
322
|
};
|
|
@@ -766,7 +766,7 @@ async function withSlackRetries(task, maxAttempts = 3, context = {}) {
|
|
|
766
766
|
"url.path": `/api/${action}`,
|
|
767
767
|
"app.slack.method": action,
|
|
768
768
|
"app.retry.max_attempts": maxAttempts,
|
|
769
|
-
...attemptNumber > 1 ? { "http.request.resend_count": attemptNumber - 1 } :
|
|
769
|
+
...attemptNumber > 1 ? { "http.request.resend_count": attemptNumber - 1 } : void 0,
|
|
770
770
|
...context.attributes ?? {},
|
|
771
771
|
...context.spanAttributes ?? {}
|
|
772
772
|
}
|
|
@@ -779,18 +779,18 @@ async function withSlackRetries(task, maxAttempts = 3, context = {}) {
|
|
|
779
779
|
const baseLogAttributes = {
|
|
780
780
|
"app.slack.action": action,
|
|
781
781
|
"app.slack.error_code": mapped.code,
|
|
782
|
-
...mapped.apiError ? { "app.slack.api_error": mapped.apiError } :
|
|
783
|
-
...mapped.detail ? { "app.slack.detail": mapped.detail } :
|
|
784
|
-
...mapped.detailLine !== void 0 ? { "app.slack.detail_line": mapped.detailLine } :
|
|
785
|
-
...mapped.detailRule ? { "app.slack.detail_rule": mapped.detailRule } :
|
|
786
|
-
...mapped.requestId ? { "app.slack.request_id": mapped.requestId } :
|
|
787
|
-
...mapped.statusCode !== void 0 ? { "http.response.status_code": mapped.statusCode } :
|
|
782
|
+
...mapped.apiError ? { "app.slack.api_error": mapped.apiError } : void 0,
|
|
783
|
+
...mapped.detail ? { "app.slack.detail": mapped.detail } : void 0,
|
|
784
|
+
...mapped.detailLine !== void 0 ? { "app.slack.detail_line": mapped.detailLine } : void 0,
|
|
785
|
+
...mapped.detailRule ? { "app.slack.detail_rule": mapped.detailRule } : void 0,
|
|
786
|
+
...mapped.requestId ? { "app.slack.request_id": mapped.requestId } : void 0,
|
|
787
|
+
...mapped.statusCode !== void 0 ? { "http.response.status_code": mapped.statusCode } : void 0,
|
|
788
788
|
...context.attributes ?? {}
|
|
789
789
|
};
|
|
790
790
|
if (!isRetryable || attempt >= maxAttempts || remainingDelayBudgetMs <= 0) {
|
|
791
791
|
logWarn("slack.action.failed", {
|
|
792
792
|
...baseLogAttributes,
|
|
793
|
-
...mapped.errorData ? { "app.slack.error_data": mapped.errorData } :
|
|
793
|
+
...mapped.errorData ? { "app.slack.error_data": mapped.errorData } : void 0
|
|
794
794
|
});
|
|
795
795
|
throw mapped;
|
|
796
796
|
}
|
|
@@ -1381,9 +1381,9 @@ function identityFromRow(row) {
|
|
|
1381
1381
|
id: row.id,
|
|
1382
1382
|
provider: row.provider,
|
|
1383
1383
|
providerSubjectId: row.providerSubjectId,
|
|
1384
|
-
...row.providerTenantId ? { providerTenantId: row.providerTenantId } :
|
|
1385
|
-
...row.displayName ? { displayName: row.displayName } :
|
|
1386
|
-
...row.handle ? { handle: row.handle } :
|
|
1384
|
+
...row.providerTenantId ? { providerTenantId: row.providerTenantId } : void 0,
|
|
1385
|
+
...row.displayName ? { displayName: row.displayName } : void 0,
|
|
1386
|
+
...row.handle ? { handle: row.handle } : void 0
|
|
1387
1387
|
});
|
|
1388
1388
|
}
|
|
1389
1389
|
async function readUserById(db, userRow) {
|
|
@@ -1401,7 +1401,7 @@ async function readUserById(db, userRow) {
|
|
|
1401
1401
|
email: userRow.primaryEmail,
|
|
1402
1402
|
id: userRow.id,
|
|
1403
1403
|
identities: identityRows.map(identityFromRow),
|
|
1404
|
-
...userRow.displayName ? { displayName: userRow.displayName } :
|
|
1404
|
+
...userRow.displayName ? { displayName: userRow.displayName } : void 0
|
|
1405
1405
|
});
|
|
1406
1406
|
}
|
|
1407
1407
|
async function resolveViewerUserFromSql(db, email) {
|
|
@@ -1457,7 +1457,7 @@ async function readActorIdentityFromSql(db, actor) {
|
|
|
1457
1457
|
if (!row) return void 0;
|
|
1458
1458
|
return {
|
|
1459
1459
|
identity: identityFromRow(row.identity),
|
|
1460
|
-
...row.user ? { user: await readUserById(db, row.user) } :
|
|
1460
|
+
...row.user ? { user: await readUserById(db, row.user) } : void 0
|
|
1461
1461
|
};
|
|
1462
1462
|
}
|
|
1463
1463
|
async function readActorIdentity(actor) {
|
|
@@ -2267,7 +2267,7 @@ function invocationPluginContext(plugin, context, turnId) {
|
|
|
2267
2267
|
plugin,
|
|
2268
2268
|
turnId
|
|
2269
2269
|
})
|
|
2270
|
-
} :
|
|
2270
|
+
} : void 0,
|
|
2271
2271
|
model: createPluginModel(plugin.manifest.name, plugin.model),
|
|
2272
2272
|
source: context.source,
|
|
2273
2273
|
text: context.userText ?? "",
|
|
@@ -2567,8 +2567,8 @@ function getPluginTools(context, sandbox = createSandboxCapability(context.works
|
|
|
2567
2567
|
channelCapabilities: resolveChannelCapabilities(
|
|
2568
2568
|
slackToolContext.sourceChannelId
|
|
2569
2569
|
),
|
|
2570
|
-
...dashboardConversationUrl ? { conversationLink: { url: dashboardConversationUrl } } :
|
|
2571
|
-
...credentialSubject ? { credentialSubject } :
|
|
2570
|
+
...dashboardConversationUrl ? { conversationLink: { url: dashboardConversationUrl } } : void 0,
|
|
2571
|
+
...credentialSubject ? { credentialSubject } : void 0
|
|
2572
2572
|
} : void 0;
|
|
2573
2573
|
const annotations = context.conversationId ? createPluginAnnotations({
|
|
2574
2574
|
conversationId: context.conversationId,
|
|
@@ -2619,12 +2619,12 @@ function getPluginTools(context, sandbox = createSandboxCapability(context.works
|
|
|
2619
2619
|
const resolveActor = context.resolveActorIdentity ?? (async () => void 0);
|
|
2620
2620
|
const common = {
|
|
2621
2621
|
...basePluginContext(plugin),
|
|
2622
|
-
...annotations ? { annotations } :
|
|
2622
|
+
...annotations ? { annotations } : void 0,
|
|
2623
2623
|
conversationId: context.conversationId,
|
|
2624
2624
|
userText: context.userText,
|
|
2625
2625
|
embedder: createPluginEmbedder(pluginName),
|
|
2626
2626
|
egress: context.egress,
|
|
2627
|
-
...mcp ? { mcp } :
|
|
2627
|
+
...mcp ? { mcp } : void 0,
|
|
2628
2628
|
model: createPluginModel(pluginName, plugin.model),
|
|
2629
2629
|
resourceEvents,
|
|
2630
2630
|
sandbox,
|
|
@@ -3213,7 +3213,7 @@ function createSandboxCapability(workspace, ownerSignal) {
|
|
|
3213
3213
|
const signal = preparationSignal(input.signal, ownerSignal);
|
|
3214
3214
|
const result = await runNonInteractiveCommand(workspace, {
|
|
3215
3215
|
...input,
|
|
3216
|
-
...signal ? { signal } :
|
|
3216
|
+
...signal ? { signal } : void 0
|
|
3217
3217
|
});
|
|
3218
3218
|
return {
|
|
3219
3219
|
exitCode: result.exitCode,
|
|
@@ -3226,7 +3226,7 @@ function createSandboxCapability(workspace, ownerSignal) {
|
|
|
3226
3226
|
{
|
|
3227
3227
|
path: input.path,
|
|
3228
3228
|
content: input.content,
|
|
3229
|
-
...input.mode !== void 0 ? { mode: input.mode } :
|
|
3229
|
+
...input.mode !== void 0 ? { mode: input.mode } : void 0
|
|
3230
3230
|
}
|
|
3231
3231
|
]);
|
|
3232
3232
|
}
|
|
@@ -3252,8 +3252,8 @@ function createPluginHookRunner(input = {}) {
|
|
|
3252
3252
|
try {
|
|
3253
3253
|
await hook({
|
|
3254
3254
|
...basePluginContext(plugin),
|
|
3255
|
-
...tool.conversationId ? { conversationId: tool.conversationId } :
|
|
3256
|
-
...annotations ? { annotations } :
|
|
3255
|
+
...tool.conversationId ? { conversationId: tool.conversationId } : void 0,
|
|
3256
|
+
...annotations ? { annotations } : void 0,
|
|
3257
3257
|
result: tool.structuredContent !== void 0 ? { structuredContent: tool.structuredContent } : {},
|
|
3258
3258
|
tool: {
|
|
3259
3259
|
arguments: tool.arguments,
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import {
|
|
2
|
+
conversationQueueMessageSchema
|
|
3
|
+
} from "./chunk-JAL3CH4G.js";
|
|
4
|
+
import {
|
|
5
|
+
QUEUE_SIGNATURE_MAX_AGE_MS,
|
|
6
|
+
createVercelQueueClient,
|
|
7
|
+
signQueueMessage,
|
|
8
|
+
verifyQueueMessage
|
|
9
|
+
} from "./chunk-7H2VZTWN.js";
|
|
10
|
+
|
|
11
|
+
// src/chat/task-execution/queue-signing.ts
|
|
12
|
+
var conversationQueueSign = {
|
|
13
|
+
context: "junior.conversation_work_queue.v2",
|
|
14
|
+
schema: conversationQueueMessageSchema,
|
|
15
|
+
separator: ":",
|
|
16
|
+
signatureVersion: "v2",
|
|
17
|
+
parts: (message) => [message.conversationId]
|
|
18
|
+
};
|
|
19
|
+
var CONVERSATION_WORK_QUEUE_SIGNATURE_MAX_SKEW_MS = QUEUE_SIGNATURE_MAX_AGE_MS;
|
|
20
|
+
function signConversationQueueMessage(message, nowMs = Date.now()) {
|
|
21
|
+
return signQueueMessage(conversationQueueSign, message, nowMs);
|
|
22
|
+
}
|
|
23
|
+
function verifyConversationQueueMessage(value, nowMs = Date.now()) {
|
|
24
|
+
return verifyQueueMessage(conversationQueueSign, value, nowMs);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// src/chat/task-execution/vercel-queue.ts
|
|
28
|
+
var DEFAULT_CONVERSATION_WORK_QUEUE_TOPIC = "junior_conversation_work";
|
|
29
|
+
var CONVERSATION_WORK_QUEUE_RETENTION_SECONDS = CONVERSATION_WORK_QUEUE_SIGNATURE_MAX_SKEW_MS / 1e3;
|
|
30
|
+
var defaultQueue;
|
|
31
|
+
function resolveConversationWorkQueueTopic(options = {}) {
|
|
32
|
+
const topic = options.topic?.trim();
|
|
33
|
+
return topic || process.env.JUNIOR_CONVERSATION_WORK_QUEUE_TOPIC?.trim() || DEFAULT_CONVERSATION_WORK_QUEUE_TOPIC;
|
|
34
|
+
}
|
|
35
|
+
function toDelaySeconds(options) {
|
|
36
|
+
if (!options?.delayMs || options.delayMs <= 0) {
|
|
37
|
+
return void 0;
|
|
38
|
+
}
|
|
39
|
+
return Math.ceil(options.delayMs / 1e3);
|
|
40
|
+
}
|
|
41
|
+
function createVercelConversationWorkQueue(options = {}) {
|
|
42
|
+
const topic = resolveConversationWorkQueueTopic(options);
|
|
43
|
+
const client = options.client ?? createVercelQueueClient();
|
|
44
|
+
return {
|
|
45
|
+
async send(message, sendOptions) {
|
|
46
|
+
const result = await client.send(
|
|
47
|
+
topic,
|
|
48
|
+
signConversationQueueMessage(message),
|
|
49
|
+
{
|
|
50
|
+
idempotencyKey: sendOptions?.idempotencyKey,
|
|
51
|
+
delaySeconds: toDelaySeconds(sendOptions),
|
|
52
|
+
retentionSeconds: options.retentionSeconds ?? CONVERSATION_WORK_QUEUE_RETENTION_SECONDS
|
|
53
|
+
}
|
|
54
|
+
);
|
|
55
|
+
return result.messageId ? { messageId: result.messageId } : {};
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
function getVercelConversationWorkQueue() {
|
|
60
|
+
defaultQueue ??= createVercelConversationWorkQueue();
|
|
61
|
+
return defaultQueue;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export {
|
|
65
|
+
verifyConversationQueueMessage,
|
|
66
|
+
resolveConversationWorkQueueTopic,
|
|
67
|
+
getVercelConversationWorkQueue
|
|
68
|
+
};
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
import {
|
|
2
|
+
coerceThreadConversationState,
|
|
3
|
+
getPersistedThreadState,
|
|
4
|
+
persistThreadStateById
|
|
5
|
+
} from "./chunk-5TUR4M3M.js";
|
|
6
|
+
import {
|
|
7
|
+
buildDeterministicTurnId,
|
|
8
|
+
clearPendingAuth,
|
|
9
|
+
markTurnClosed,
|
|
10
|
+
markTurnCompleted
|
|
11
|
+
} from "./chunk-GUKXEPMX.js";
|
|
12
|
+
import {
|
|
13
|
+
hydrateConversationMessages,
|
|
14
|
+
markConversationMessage
|
|
15
|
+
} from "./chunk-GPXAHUQH.js";
|
|
16
|
+
import {
|
|
17
|
+
ProviderError,
|
|
18
|
+
findProviderError,
|
|
19
|
+
getProviderErrorAttributes,
|
|
20
|
+
getProviderErrorUserMessage
|
|
21
|
+
} from "./chunk-I6IFTAPF.js";
|
|
22
|
+
import {
|
|
23
|
+
parseSlackMessageTs
|
|
24
|
+
} from "./chunk-N7TMSOZH.js";
|
|
25
|
+
import {
|
|
26
|
+
buildTurnFailureResponse
|
|
27
|
+
} from "./chunk-RAZG3YHC.js";
|
|
28
|
+
|
|
29
|
+
// src/chat/runtime/delivered-turn-state.ts
|
|
30
|
+
function buildDeliveredTurnStatePatch(args) {
|
|
31
|
+
const conversation = structuredClone(args.conversation);
|
|
32
|
+
clearPendingAuth(conversation, args.sessionId);
|
|
33
|
+
markConversationMessage(conversation, args.userMessageId, {
|
|
34
|
+
replied: true,
|
|
35
|
+
skippedReason: void 0
|
|
36
|
+
});
|
|
37
|
+
markTurnCompleted({
|
|
38
|
+
conversation,
|
|
39
|
+
nowMs: Date.now(),
|
|
40
|
+
sessionId: args.sessionId
|
|
41
|
+
});
|
|
42
|
+
return {
|
|
43
|
+
conversation,
|
|
44
|
+
sandboxRef: args.reply.sandboxRef
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// src/chat/interruption-marker.ts
|
|
49
|
+
var INTERRUPTED_MARKER = "\n\n[Response interrupted before completion]";
|
|
50
|
+
function getInterruptionMarker() {
|
|
51
|
+
return INTERRUPTED_MARKER;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// src/chat/services/turn-failure-response.ts
|
|
55
|
+
function requireTurnFailureEventId(eventId, eventName) {
|
|
56
|
+
if (!eventId) {
|
|
57
|
+
throw new Error(`Sentry did not return an event ID for ${eventName}`);
|
|
58
|
+
}
|
|
59
|
+
return eventId;
|
|
60
|
+
}
|
|
61
|
+
function getExecutionFailureReason(reply) {
|
|
62
|
+
const errorMessage = reply.diagnostics.errorMessage?.trim();
|
|
63
|
+
if (errorMessage) {
|
|
64
|
+
return errorMessage;
|
|
65
|
+
}
|
|
66
|
+
if (reply.diagnostics.toolErrorCount > 0) {
|
|
67
|
+
return `${reply.diagnostics.toolErrorCount} tool result error(s)`;
|
|
68
|
+
}
|
|
69
|
+
if (reply.diagnostics.assistantMessageCount > 0) {
|
|
70
|
+
return "assistant returned no text";
|
|
71
|
+
}
|
|
72
|
+
return "empty assistant turn";
|
|
73
|
+
}
|
|
74
|
+
function getFailureCapture(reply) {
|
|
75
|
+
if (reply.diagnostics.outcome === "provider_error") {
|
|
76
|
+
const providerError = findProviderError(reply.diagnostics.providerError);
|
|
77
|
+
return {
|
|
78
|
+
eventName: "agent.turn.provider_error",
|
|
79
|
+
error: reply.diagnostics.providerError ?? new Error(
|
|
80
|
+
reply.diagnostics.errorMessage ?? "Provider error without explicit message"
|
|
81
|
+
),
|
|
82
|
+
attributes: providerError ? getProviderErrorAttributes(providerError) : {},
|
|
83
|
+
body: "Agent turn failed with provider error"
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
const failureReason = getExecutionFailureReason(reply);
|
|
87
|
+
return {
|
|
88
|
+
eventName: "agent.turn.execution.failed",
|
|
89
|
+
error: new Error(`Agent turn execution failure: ${failureReason}`),
|
|
90
|
+
attributes: {
|
|
91
|
+
"app.ai.execution_failure_reason": failureReason
|
|
92
|
+
},
|
|
93
|
+
body: "Agent turn completed with execution failure"
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
function getAgentTurnDiagnosticsAttributes(reply) {
|
|
97
|
+
return {
|
|
98
|
+
"app.ai.outcome": reply.diagnostics.outcome,
|
|
99
|
+
"app.ai.assistant_messages": reply.diagnostics.assistantMessageCount,
|
|
100
|
+
"app.ai.tool_results": reply.diagnostics.toolResultCount,
|
|
101
|
+
"app.ai.tool_error_results": reply.diagnostics.toolErrorCount,
|
|
102
|
+
"app.ai.tool_call_count": reply.diagnostics.toolCalls.length,
|
|
103
|
+
"app.ai.used_primary_text": reply.diagnostics.usedPrimaryText,
|
|
104
|
+
...reply.diagnostics.reasoningLevel ? {
|
|
105
|
+
"gen_ai.request.reasoning.level": reply.diagnostics.reasoningLevel
|
|
106
|
+
} : void 0,
|
|
107
|
+
...reply.diagnostics.stopReason ? {
|
|
108
|
+
"gen_ai.response.finish_reasons": [reply.diagnostics.stopReason]
|
|
109
|
+
} : void 0,
|
|
110
|
+
...reply.diagnostics.errorMessage && reply.diagnostics.outcome !== "provider_error" ? { "exception.message": reply.diagnostics.errorMessage } : void 0
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
function finalizeFailedTurnReplyWithEvent(args) {
|
|
114
|
+
if (args.reply.diagnostics.outcome === "success") {
|
|
115
|
+
return { reply: args.reply };
|
|
116
|
+
}
|
|
117
|
+
const capture = getFailureCapture(args.reply);
|
|
118
|
+
const eventId = requireTurnFailureEventId(
|
|
119
|
+
args.logException(capture.error, capture.eventName, {
|
|
120
|
+
...getAgentTurnDiagnosticsAttributes(args.reply),
|
|
121
|
+
...args.attributes,
|
|
122
|
+
...capture.attributes
|
|
123
|
+
}),
|
|
124
|
+
capture.eventName
|
|
125
|
+
);
|
|
126
|
+
const providerPartialText = args.reply.diagnostics.outcome === "provider_error" && args.reply.diagnostics.assistantMessageCount > 0 ? args.reply.text.trim() : "";
|
|
127
|
+
const providerUserMessage = args.reply.diagnostics.providerError instanceof ProviderError ? getProviderErrorUserMessage(args.reply.diagnostics.providerError) : "";
|
|
128
|
+
const failureText = providerUserMessage ? `${providerUserMessage} Reference: \`event_id=${eventId}\`.` : buildTurnFailureResponse(eventId);
|
|
129
|
+
return {
|
|
130
|
+
eventId,
|
|
131
|
+
reply: {
|
|
132
|
+
...args.reply,
|
|
133
|
+
text: providerPartialText ? `${providerPartialText}${getInterruptionMarker()}` : failureText
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// src/chat/runtime/turn-user-message.ts
|
|
139
|
+
function getTurnUserMessage(conversation, sessionId) {
|
|
140
|
+
for (let index = conversation.messages.length - 1; index >= 0; index -= 1) {
|
|
141
|
+
const message = conversation.messages[index];
|
|
142
|
+
if (message?.role !== "user") {
|
|
143
|
+
continue;
|
|
144
|
+
}
|
|
145
|
+
if (buildDeterministicTurnId(message.id) === sessionId) {
|
|
146
|
+
return message;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
return void 0;
|
|
150
|
+
}
|
|
151
|
+
function getTurnUserMessageId(conversation, sessionId) {
|
|
152
|
+
return getTurnUserMessage(conversation, sessionId)?.id;
|
|
153
|
+
}
|
|
154
|
+
function getTurnUserSlackMessageTs(message) {
|
|
155
|
+
return parseSlackMessageTs(message?.meta?.slackTs);
|
|
156
|
+
}
|
|
157
|
+
function getTurnUserReplyAttachmentContext(message) {
|
|
158
|
+
const inboundAttachmentCount = message?.meta?.attachmentCount ?? 0;
|
|
159
|
+
const imageAttachmentCount = message?.meta?.imageAttachmentCount ?? 0;
|
|
160
|
+
const imagesHydrated = message?.meta?.imagesHydrated === true;
|
|
161
|
+
return {
|
|
162
|
+
...inboundAttachmentCount > 0 ? { inboundAttachmentCount } : void 0,
|
|
163
|
+
...!imagesHydrated && imageAttachmentCount > 0 ? { omittedImageAttachmentCount: imageAttachmentCount } : void 0
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// src/chat/runtime/auth-pause-state.ts
|
|
168
|
+
function completeAuthPauseTurn(args) {
|
|
169
|
+
markConversationMessage(
|
|
170
|
+
args.conversation,
|
|
171
|
+
getTurnUserMessageId(args.conversation, args.sessionId),
|
|
172
|
+
{
|
|
173
|
+
replied: true,
|
|
174
|
+
skippedReason: void 0
|
|
175
|
+
}
|
|
176
|
+
);
|
|
177
|
+
markTurnClosed({
|
|
178
|
+
conversation: args.conversation,
|
|
179
|
+
nowMs: Date.now(),
|
|
180
|
+
sessionId: args.sessionId
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
async function persistAuthPauseTurnState(args) {
|
|
184
|
+
const currentState = await getPersistedThreadState(args.threadStateId);
|
|
185
|
+
const conversation = coerceThreadConversationState(currentState);
|
|
186
|
+
await hydrateConversationMessages({
|
|
187
|
+
conversation,
|
|
188
|
+
conversationId: args.threadStateId
|
|
189
|
+
});
|
|
190
|
+
completeAuthPauseTurn({
|
|
191
|
+
conversation,
|
|
192
|
+
sessionId: args.sessionId
|
|
193
|
+
});
|
|
194
|
+
await persistThreadStateById(args.threadStateId, { conversation });
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
export {
|
|
198
|
+
buildDeliveredTurnStatePatch,
|
|
199
|
+
getTurnUserMessage,
|
|
200
|
+
getTurnUserMessageId,
|
|
201
|
+
getTurnUserSlackMessageTs,
|
|
202
|
+
getTurnUserReplyAttachmentContext,
|
|
203
|
+
getInterruptionMarker,
|
|
204
|
+
requireTurnFailureEventId,
|
|
205
|
+
getAgentTurnDiagnosticsAttributes,
|
|
206
|
+
finalizeFailedTurnReplyWithEvent,
|
|
207
|
+
completeAuthPauseTurn,
|
|
208
|
+
persistAuthPauseTurnState
|
|
209
|
+
};
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
DEFAULT_SQL_STATEMENT_TIMEOUT_MS
|
|
3
|
-
} from "./chunk-GENV6KF2.js";
|
|
4
1
|
import {
|
|
5
2
|
juniorDestinations,
|
|
6
3
|
timestamptz
|
|
7
4
|
} from "./chunk-VFUK3X5B.js";
|
|
5
|
+
import {
|
|
6
|
+
DEFAULT_SQL_STATEMENT_TIMEOUT_MS
|
|
7
|
+
} from "./chunk-I6IFTAPF.js";
|
|
8
8
|
|
|
9
9
|
// src/db/neon.ts
|
|
10
10
|
import { AsyncLocalStorage } from "async_hooks";
|