@sentry/junior 0.285.0 → 0.287.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/{adapter-DN5AB4VU.js → adapter-CL-HUKgd.js} +1 -1
- package/dist/{admin-DOITMKnn.js → admin-C9urXVfi.js} +2 -1
- package/dist/{agent-runner-BsWhHe4N.js → agent-runner-Bfnw551N.js} +2174 -1323
- package/dist/api/schema.d.ts +2 -2
- package/dist/api/schema.js +7 -7
- package/dist/api.d.ts +1 -1
- package/dist/api.js +73 -112
- package/dist/{app-DyMs9330.d.ts → app-DBY5TnfY.d.ts} +2 -3
- package/dist/app.d.ts +1 -1
- package/dist/app.js +72 -42
- package/dist/{assistant-reply-9Jip5bsr.js → assistant-reply-u_PRYzuz.js} +1 -1
- package/dist/{automation-Mk8aaHzy.js → automation-DksGNDRO.js} +3 -6
- package/dist/{background-compaction-queue-DXkLsWoH.js → background-compaction-queue-CYI909P5.js} +137 -3
- package/dist/{briefs-Cl8-nK9B.js → briefs-DaXiMWzT.js} +6 -5
- package/dist/{catalog-runtime-Bte6jRB2.js → catalog-runtime-BCIuBe4d.js} +1 -1
- package/dist/cli/chat.js +14 -14
- package/dist/cli/check.js +3 -3
- package/dist/cli/main.js +3 -3
- package/dist/cli/plugins.js +4 -4
- package/dist/cli/snapshot-create.js +5 -6
- package/dist/cli/upgrade.d.ts +1 -1
- package/dist/cli/upgrade.js +3 -3
- package/dist/{client-DDbBucBw.js → config-CkHcUMN7.js} +580 -3
- package/dist/{connections-DA4LT9LL.js → connections-BnIj0wtx.js} +16 -50
- package/dist/{conversation-D8kVoCrP.js → conversation-E7ZPJx2H.js} +22 -6
- package/dist/{conversation-pending-messages-BvROq1bq.js → conversation-pending-messages-DVch6YQw.js} +2 -5
- package/dist/{conversation-privacy-D0j_h70R.js → conversation-privacy-DF1hW0ja.js} +1 -1
- package/dist/{credential-sync-hcsYatw-.js → credential-sync-CzMar9hq.js} +13 -13
- package/dist/{viewer-1Ea81s0b.js → db-DJ11eZqq.js} +64 -367
- package/dist/{db-BhHZSuFw.d.ts → db-YDKKDxlh.d.ts} +4 -4
- package/dist/{executor-BLEMIgIZ.js → executor-BY9TB31g.js} +20 -19
- package/dist/instrumentation.js +2 -2
- package/dist/{logging-BfORLKoq.js → logging-BO5zU6Mt.js} +1 -1
- package/dist/{media-Bu9C6lz0.js → media-Cz1ZiV1U.js} +16 -4
- package/dist/{message-DqjuKzUx.js → message-CsUbuEc8.js} +10 -10
- package/dist/nitro.d.ts +1 -1
- package/dist/nitro.js +2 -3
- package/dist/{oauth-callback-server-CFSRzu1n.js → oauth-callback-server-hiDKK0_n.js} +2 -2
- package/dist/{projection-DliWYrnT.js → projection-CL_YWeGf.js} +352 -356
- package/dist/{prompt-BvIUzY4y.js → prompt-BHOEQSmf.js} +182 -2
- package/dist/{registry-rC7MCxu8.js → registry-BriFLnaJ.js} +1 -1
- package/dist/{reporting-window-B4TwyuJo.js → reporting-window-B3Ze-Qnt.js} +4 -1
- package/dist/{resolve-Biu8Qw3u.js → resolve-Bt6GgAiA.js} +3 -3
- package/dist/{result-DxJMCX47.js → result-Bo1TZu0Q.js} +8 -8
- package/dist/{runner-BQJSFLKg.js → runner-D3YeCQgt.js} +16 -12
- package/dist/{sandbox-egress-signals-6aMxJSDn.js → sandbox-egress-signals-CcnSPP4S.js} +1 -1
- package/dist/{schema-BasXTvi2.js → schema-BWE3RJEB.js} +19 -7
- package/dist/{schema-BUviRAs8.d.ts → schema-C6fsEwjo.d.ts} +90 -8
- package/dist/{service-account-BI5Wgx22.js → service-account-DiQQuuw7.js} +3 -3
- package/dist/{service-account-CAE-_1dR.js → service-account-r6fl0b-9.js} +3 -3
- package/dist/{session-stop-CA-jOJ84.js → session-stop-B2Nut40V.js} +27 -25
- package/dist/{skills-B22duVJU.js → skills-CD5aJdzg.js} +2 -2
- package/dist/spawn-CalgZQiu.js +79 -0
- package/dist/{stop-DioIcEAu.js → stop-kujZLbi0.js} +233 -1127
- package/dist/{store-Dn4W7qgH.js → store-DdIEUL1q.js} +3 -3
- package/dist/{turn-session-routing-CGMKrYOj.js → task-runner-D_RDr2Hu.js} +1440 -993
- package/dist/{store-B26LV6UP.js → turn-failure-response-B5nV1Er-.js} +337 -6
- package/dist/{validation-TzhfQABF.js → validation-K4pqwoVZ.js} +1 -1
- package/dist/{version-DSk8CFvA.js → version-DBvhk1X9.js} +1 -1
- package/dist/version.js +1 -1
- package/dist/viewer-DrMmFUul.js +337 -0
- package/dist/{work-ybG4_q5C.js → work-ljRoODGu.js} +110 -94
- package/dist/{worker-ccSyZRNz.js → worker-CYO1Q0Js.js} +5 -6
- package/migrations/0086_shared_archive.sql +31 -0
- package/migrations/0087_child_location.sql +64 -0
- package/migrations/0088_conversation_unsubscribe.sql +1 -0
- package/migrations/meta/0086_snapshot.json +4366 -0
- package/migrations/meta/0087_snapshot.json +4366 -0
- package/migrations/meta/0088_snapshot.json +4372 -0
- package/migrations/meta/_journal.json +21 -0
- package/package.json +5 -4
- package/dist/config-DqFnykQT.js +0 -579
- package/dist/spawn-BB2_4VYn.js +0 -31
- package/dist/task-queue-Bt0IoR2i.js +0 -139
- package/dist/task-runner-D8lddjzp.js +0 -290
- package/dist/thread-state-CrFk3K_7.js +0 -173
- package/dist/turn-failure-response-DaJ04qVj.js +0 -224
- package/dist/turn-lifecycle-C2mXS7AZ.js +0 -58
|
@@ -1,8 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
1
|
+
import { Cn as buildDeterministicTurnId, D as buildConversationContext, M as markConversationMessage, ko as listConversationAnnotations, q as clearPendingAuth, v as hydrateConversationMessages } from "./projection-CL_YWeGf.js";
|
|
2
|
+
import { I as findProviderError, L as getProviderErrorAttributes, P as ProviderError, R as getProviderErrorUserMessage, g as TURN_REASONING_LEVELS } from "./config-CkHcUMN7.js";
|
|
3
|
+
import { W as isRecord, b as setSpanAttributes, t as buildTurnFailureResponse } from "./logging-BO5zU6Mt.js";
|
|
4
|
+
import { h as parseSlackMessageTs } from "./actor-6jsm_v96.js";
|
|
5
|
+
import { o as getDb, r as getConversationEventStore, s as getSqlExecutor } from "./db-DJ11eZqq.js";
|
|
6
|
+
import { g as juniorAgentInvocations } from "./executor-BY9TB31g.js";
|
|
7
|
+
import { p as credentialContextSchema } from "./registry-BriFLnaJ.js";
|
|
8
|
+
import { F as removedCardSchema, I as resolveMessageCards, P as readMessageCardRefs } from "./conversation-E7ZPJx2H.js";
|
|
9
|
+
import { C as AGENT_INVOCATION_PARENT_MAILBOX_STATUSES, S as AGENT_INVOCATION_MAILBOX_STATUSES } from "./reporting-window-B3Ze-Qnt.js";
|
|
10
|
+
import { _t as getPersistedThreadState, bt as coerceThreadConversationState, yt as persistThreadStateById } from "./task-runner-D_RDr2Hu.js";
|
|
6
11
|
import { createHash } from "node:crypto";
|
|
7
12
|
import * as z from "zod";
|
|
8
13
|
import { and, asc, desc, eq, inArray, or, sql } from "drizzle-orm";
|
|
@@ -221,6 +226,11 @@ function agentTypeInstructions(type) {
|
|
|
221
226
|
// src/chat/agent-invocations/types.ts
|
|
222
227
|
const exactStringSchema = z.string().min(1).refine((value) => value === value.trim());
|
|
223
228
|
const agentNameSchema = exactStringSchema.max(64);
|
|
229
|
+
/**
|
|
230
|
+
* Kind of a new child Conversation. A Thread is a child that people can
|
|
231
|
+
* message; a Task is one that only its parent messages.
|
|
232
|
+
*/
|
|
233
|
+
const CHILD_AGENT_KINDS = ["thread", "task"];
|
|
224
234
|
/** `messageAgent` target for the parent of a child agent. */
|
|
225
235
|
const PARENT_AGENT_TARGET = "parent";
|
|
226
236
|
const agentInvocationMailboxStatusSchema = z.enum(AGENT_INVOCATION_MAILBOX_STATUSES);
|
|
@@ -278,6 +288,7 @@ const createAgentInvocationSchema = z.object({
|
|
|
278
288
|
destination: destinationSchema,
|
|
279
289
|
idempotencyKey: exactStringSchema,
|
|
280
290
|
input: exactStringSchema,
|
|
291
|
+
kind: z.enum(CHILD_AGENT_KINDS).default("task"),
|
|
281
292
|
parentConversationId: exactStringSchema,
|
|
282
293
|
parentToolCallId: exactStringSchema.optional(),
|
|
283
294
|
agentType: agentTypeSchema.optional(),
|
|
@@ -473,4 +484,324 @@ async function markAgentInvocationSteered(invocationId, nowMs = Date.now()) {
|
|
|
473
484
|
function isTerminalAgentInvocation(invocation) {
|
|
474
485
|
return TERMINAL_AGENT_INVOCATION_STATUSES.includes(invocation.status);
|
|
475
486
|
}
|
|
476
|
-
|
|
487
|
+
// src/chat/conversations/pending-cards.ts
|
|
488
|
+
/**
|
|
489
|
+
* Add the cards that tool results selected since the last visible assistant
|
|
490
|
+
* Message or Turn start, scanning back from `beforeSeq`. Returns the input
|
|
491
|
+
* message ids of the Turn start that ended the scan.
|
|
492
|
+
*/
|
|
493
|
+
async function selectTurnCards(conversationId, selection, beforeSeq) {
|
|
494
|
+
while (true) {
|
|
495
|
+
const page = await getConversationEventStore().query(conversationId, {
|
|
496
|
+
beforeSeq,
|
|
497
|
+
limit: 100,
|
|
498
|
+
types: [
|
|
499
|
+
"tool_result",
|
|
500
|
+
"message",
|
|
501
|
+
"turn_started"
|
|
502
|
+
]
|
|
503
|
+
});
|
|
504
|
+
for (const event of [...page.events].reverse()) {
|
|
505
|
+
const data = event.data;
|
|
506
|
+
if (data.type === "turn_started") return data.inputMessageIds;
|
|
507
|
+
if (data.type === "message" && data.role === "assistant") return [];
|
|
508
|
+
if (data.type !== "tool_result" || data.isError || typeof data.toolName !== "string" || !isRecord(data.details)) continue;
|
|
509
|
+
if (data.details.timed_out === true) continue;
|
|
510
|
+
if (Array.isArray(data.details.removedCards)) for (const ref of removedCardSchema.array().parse(data.details.removedCards)) selection.deleted.add(JSON.stringify([ref.plugin, ref.key]));
|
|
511
|
+
for (const card of readMessageCardRefs(data.details)) {
|
|
512
|
+
const key = JSON.stringify([card.plugin, card.key]);
|
|
513
|
+
if (!selection.deleted.has(key) && !selection.cards.has(key)) selection.cards.set(key, card);
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
if (!page.hasOlder || page.events.length === 0) return [];
|
|
517
|
+
beforeSeq = page.events[0].seq;
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
/**
|
|
521
|
+
* Add the cards of child agents whose results started this Turn. A child
|
|
522
|
+
* cannot reply to people, so its parent's reply delivers its cards.
|
|
523
|
+
*/
|
|
524
|
+
async function selectChildResultCards(inputMessageIds, selection) {
|
|
525
|
+
const events = getConversationEventStore();
|
|
526
|
+
for (const messageId of [...inputMessageIds].reverse()) {
|
|
527
|
+
const invocationId = parseAgentInvocationResultMessageId(messageId);
|
|
528
|
+
const invocation = invocationId ? await getAgentInvocation(invocationId) : void 0;
|
|
529
|
+
if (!invocation) continue;
|
|
530
|
+
const turnId = getAgentInvocationTurnId(invocation.invocationId);
|
|
531
|
+
const terminal = await events.loadByIdempotencyKey(invocation.childConversationId, `turn:${turnId}:terminal`);
|
|
532
|
+
if (!terminal) continue;
|
|
533
|
+
await selectTurnCards(invocation.childConversationId, selection, terminal.seq);
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
/** Select undelivered cards and load their latest saved facts. */
|
|
537
|
+
async function loadPendingMessageCards(conversationId) {
|
|
538
|
+
const selection = {
|
|
539
|
+
cards: /* @__PURE__ */ new Map(),
|
|
540
|
+
deleted: /* @__PURE__ */ new Set()
|
|
541
|
+
};
|
|
542
|
+
await selectChildResultCards(await selectTurnCards(conversationId, selection), selection);
|
|
543
|
+
if (selection.cards.size === 0) return [];
|
|
544
|
+
return resolveMessageCards([...selection.cards.values()].reverse(), await listConversationAnnotations(getDb(), conversationId));
|
|
545
|
+
}
|
|
546
|
+
// src/chat/conversations/turn-lifecycle.ts
|
|
547
|
+
/** Persist correlated turn lifecycle facts with retry-safe terminal exclusion. */
|
|
548
|
+
var ConversationTurnLifecycleService = class {
|
|
549
|
+
events;
|
|
550
|
+
constructor(events) {
|
|
551
|
+
this.events = events;
|
|
552
|
+
}
|
|
553
|
+
/** Record the turn start once after every input message is durable. */
|
|
554
|
+
async start(input) {
|
|
555
|
+
await this.events.append(input.conversationId, [{
|
|
556
|
+
idempotencyKey: `turn:${input.turnId}:started`,
|
|
557
|
+
createdAtMs: input.createdAtMs,
|
|
558
|
+
data: {
|
|
559
|
+
type: "turn_started",
|
|
560
|
+
turnId: input.turnId,
|
|
561
|
+
inputMessageIds: input.inputMessageIds,
|
|
562
|
+
surface: input.surface,
|
|
563
|
+
...input.threadContextThroughSeq === void 0 ? void 0 : { threadContextThroughSeq: input.threadContextThroughSeq }
|
|
564
|
+
}
|
|
565
|
+
}]);
|
|
566
|
+
}
|
|
567
|
+
/** Return the input message ids that started a Turn, when it started. */
|
|
568
|
+
async loadInputMessageIds(conversationId, turnId) {
|
|
569
|
+
const event = await this.events.loadByIdempotencyKey(conversationId, `turn:${turnId}:started`);
|
|
570
|
+
return event?.data.type === "turn_started" ? event.data.inputMessageIds : void 0;
|
|
571
|
+
}
|
|
572
|
+
/** Record a completion that is not a failure once. */
|
|
573
|
+
async complete(input) {
|
|
574
|
+
await this.events.append(input.conversationId, [{
|
|
575
|
+
idempotencyKey: `turn:${input.turnId}:terminal`,
|
|
576
|
+
createdAtMs: input.createdAtMs,
|
|
577
|
+
data: {
|
|
578
|
+
type: "turn_completed",
|
|
579
|
+
turnId: input.turnId,
|
|
580
|
+
outcome: input.outcome
|
|
581
|
+
}
|
|
582
|
+
}]);
|
|
583
|
+
}
|
|
584
|
+
/** Record a classified failure once. Do not store raw error text. */
|
|
585
|
+
async fail(input) {
|
|
586
|
+
await this.events.append(input.conversationId, [{
|
|
587
|
+
idempotencyKey: `turn:${input.turnId}:terminal`,
|
|
588
|
+
createdAtMs: input.createdAtMs,
|
|
589
|
+
data: {
|
|
590
|
+
type: "turn_failed",
|
|
591
|
+
turnId: input.turnId,
|
|
592
|
+
failureCode: input.failureCode,
|
|
593
|
+
...input.failureReason ? { failureReason: input.failureReason } : void 0,
|
|
594
|
+
...input.eventId ? { eventId: input.eventId } : void 0
|
|
595
|
+
}
|
|
596
|
+
}]);
|
|
597
|
+
}
|
|
598
|
+
};
|
|
599
|
+
/** Return the Turn lifecycle that records Conversation events. */
|
|
600
|
+
function getTurnLifecycle() {
|
|
601
|
+
return new ConversationTurnLifecycleService(getConversationEventStore());
|
|
602
|
+
}
|
|
603
|
+
// src/chat/conversations/thread-context.ts
|
|
604
|
+
const CURSOR_TURN_LOOKBACK = 10;
|
|
605
|
+
async function loadThreadContextCursor(args) {
|
|
606
|
+
const store = getConversationEventStore();
|
|
607
|
+
const [started, completed] = await Promise.all([store.query(args.conversationId, {
|
|
608
|
+
limit: CURSOR_TURN_LOOKBACK,
|
|
609
|
+
types: ["turn_started"]
|
|
610
|
+
}), store.query(args.conversationId, {
|
|
611
|
+
limit: CURSOR_TURN_LOOKBACK,
|
|
612
|
+
types: ["turn_completed"]
|
|
613
|
+
})]);
|
|
614
|
+
const finished = new Set(completed.events.flatMap((event) => event.data.type === "turn_completed" && event.data.outcome !== "cancelled" ? [event.data.turnId] : []));
|
|
615
|
+
const previous = [...started.events].reverse().find((event) => event.data.type === "turn_started" && event.data.turnId !== args.turnId && finished.has(event.data.turnId));
|
|
616
|
+
return previous?.data.type === "turn_started" ? previous.data.threadContextThroughSeq : void 0;
|
|
617
|
+
}
|
|
618
|
+
/**
|
|
619
|
+
* Return the oldest cursor of the Turns that the cursor lookup reads. Messages
|
|
620
|
+
* after it may still be in the thread context delta of the next Turn, also
|
|
621
|
+
* when the latest Turns failed or the next Turn retries.
|
|
622
|
+
*/
|
|
623
|
+
async function loadThreadContextTrimFloor(conversationId) {
|
|
624
|
+
const cursors = (await getConversationEventStore().query(conversationId, {
|
|
625
|
+
limit: CURSOR_TURN_LOOKBACK,
|
|
626
|
+
types: ["turn_started"]
|
|
627
|
+
})).events.flatMap((event) => event.data.type === "turn_started" && event.data.threadContextThroughSeq !== void 0 ? [event.data.threadContextThroughSeq] : []);
|
|
628
|
+
return cursors.length > 0 ? Math.min(...cursors) : void 0;
|
|
629
|
+
}
|
|
630
|
+
/**
|
|
631
|
+
* Build the thread context of one Turn prompt. With agent history, show only
|
|
632
|
+
* the thread Messages saved after the cursor of the previous Turn.
|
|
633
|
+
*/
|
|
634
|
+
async function buildTurnThreadContext(args) {
|
|
635
|
+
const afterSeq = args.hasHistory ? await loadThreadContextCursor({
|
|
636
|
+
conversationId: args.conversationId,
|
|
637
|
+
turnId: args.turnId
|
|
638
|
+
}) : void 0;
|
|
639
|
+
const block = buildConversationContext(args.conversation, {
|
|
640
|
+
excludeMessageIds: args.excludeMessageIds,
|
|
641
|
+
...args.hasHistory ? { history: { afterSeq } } : void 0
|
|
642
|
+
});
|
|
643
|
+
setSpanAttributes({
|
|
644
|
+
"app.thread_context.chars": block.text?.length ?? 0,
|
|
645
|
+
"app.thread_context.shown_messages": block.shownMessages,
|
|
646
|
+
"app.thread_context.omitted_messages": block.omittedMessages,
|
|
647
|
+
"app.thread_context.cursor": !args.hasHistory ? "no_history" : afterSeq === void 0 ? "missing" : "found"
|
|
648
|
+
});
|
|
649
|
+
return block.text;
|
|
650
|
+
}
|
|
651
|
+
// src/chat/runtime/delivered-turn-state.ts
|
|
652
|
+
/** Build state after destination delivery or intentional no-reply completion. */
|
|
653
|
+
function buildDeliveredTurnStatePatch(args) {
|
|
654
|
+
const conversation = structuredClone(args.conversation);
|
|
655
|
+
clearPendingAuth(conversation, args.sessionId);
|
|
656
|
+
markConversationMessage(conversation, args.userMessageId, {
|
|
657
|
+
replied: true,
|
|
658
|
+
skippedReason: void 0
|
|
659
|
+
});
|
|
660
|
+
markTurnCompleted({
|
|
661
|
+
conversation,
|
|
662
|
+
nowMs: Date.now(),
|
|
663
|
+
sessionId: args.sessionId
|
|
664
|
+
});
|
|
665
|
+
return {
|
|
666
|
+
conversation,
|
|
667
|
+
sandboxRef: args.reply.sandboxRef
|
|
668
|
+
};
|
|
669
|
+
}
|
|
670
|
+
// src/chat/runtime/turn-user-message.ts
|
|
671
|
+
/** Return the user message for a persisted turn/session, if one exists. */
|
|
672
|
+
function getTurnUserMessage(conversation, sessionId) {
|
|
673
|
+
for (let index = conversation.messages.length - 1; index >= 0; index -= 1) {
|
|
674
|
+
const message = conversation.messages[index];
|
|
675
|
+
if (message?.role !== "user") continue;
|
|
676
|
+
if (buildDeterministicTurnId(message.id) === sessionId) return message;
|
|
677
|
+
}
|
|
678
|
+
}
|
|
679
|
+
/** Return the persisted user-message id for a turn/session, if one exists. */
|
|
680
|
+
function getTurnUserMessageId(conversation, sessionId) {
|
|
681
|
+
return getTurnUserMessage(conversation, sessionId)?.id;
|
|
682
|
+
}
|
|
683
|
+
/** Return the Slack timestamp for the user message that a resumed turn acts on. */
|
|
684
|
+
function getTurnUserSlackMessageTs(message) {
|
|
685
|
+
return parseSlackMessageTs(message?.meta?.slackTs);
|
|
686
|
+
}
|
|
687
|
+
/** Rebuild attachment context for a resumed turn from the persisted user message. */
|
|
688
|
+
function getTurnUserReplyAttachmentContext(message) {
|
|
689
|
+
const inboundAttachmentCount = message?.meta?.attachmentCount ?? 0;
|
|
690
|
+
const imageAttachmentCount = message?.meta?.imageAttachmentCount ?? 0;
|
|
691
|
+
const imagesHydrated = message?.meta?.imagesHydrated === true;
|
|
692
|
+
return {
|
|
693
|
+
...inboundAttachmentCount > 0 ? { inboundAttachmentCount } : void 0,
|
|
694
|
+
...!imagesHydrated && imageAttachmentCount > 0 ? { omittedImageAttachmentCount: imageAttachmentCount } : void 0
|
|
695
|
+
};
|
|
696
|
+
}
|
|
697
|
+
// src/chat/runtime/auth-pause-state.ts
|
|
698
|
+
/** Mark an auth-paused turn complete after private authorization link delivery. */
|
|
699
|
+
function completeAuthPauseTurn(args) {
|
|
700
|
+
markConversationMessage(args.conversation, getTurnUserMessageId(args.conversation, args.sessionId), {
|
|
701
|
+
replied: true,
|
|
702
|
+
skippedReason: void 0
|
|
703
|
+
});
|
|
704
|
+
markTurnClosed({
|
|
705
|
+
conversation: args.conversation,
|
|
706
|
+
nowMs: Date.now(),
|
|
707
|
+
sessionId: args.sessionId
|
|
708
|
+
});
|
|
709
|
+
}
|
|
710
|
+
/** Reload thread state, mark the auth pause as parked, and persist it. */
|
|
711
|
+
async function persistAuthPauseTurnState(args) {
|
|
712
|
+
const currentState = await getPersistedThreadState(args.threadStateId);
|
|
713
|
+
const conversation = coerceThreadConversationState(currentState);
|
|
714
|
+
await hydrateConversationMessages({
|
|
715
|
+
conversation,
|
|
716
|
+
conversationId: args.threadStateId
|
|
717
|
+
});
|
|
718
|
+
completeAuthPauseTurn({
|
|
719
|
+
conversation,
|
|
720
|
+
sessionId: args.sessionId
|
|
721
|
+
});
|
|
722
|
+
await persistThreadStateById(args.threadStateId, { conversation });
|
|
723
|
+
}
|
|
724
|
+
// src/chat/interruption-marker.ts
|
|
725
|
+
const INTERRUPTED_MARKER = "\n\n[Response interrupted before completion]";
|
|
726
|
+
/** Return the marker added when a visible reply ended mid-execution. */
|
|
727
|
+
function getInterruptionMarker() {
|
|
728
|
+
return INTERRUPTED_MARKER;
|
|
729
|
+
}
|
|
730
|
+
// src/chat/services/turn-failure-response.ts
|
|
731
|
+
/** Require captured turn failures to carry a real Sentry event reference. */
|
|
732
|
+
function requireTurnFailureEventId(eventId, eventName) {
|
|
733
|
+
if (!eventId) throw new Error(`Sentry did not return an event ID for ${eventName}`);
|
|
734
|
+
return eventId;
|
|
735
|
+
}
|
|
736
|
+
function getExecutionFailureReason(reply) {
|
|
737
|
+
const errorMessage = reply.diagnostics.errorMessage?.trim();
|
|
738
|
+
if (errorMessage) return errorMessage;
|
|
739
|
+
if (reply.diagnostics.toolErrorCount > 0) return `${reply.diagnostics.toolErrorCount} tool result error(s)`;
|
|
740
|
+
if (reply.diagnostics.assistantMessageCount > 0) return "assistant returned no text";
|
|
741
|
+
return "empty assistant turn";
|
|
742
|
+
}
|
|
743
|
+
/** Return a fixed reason label for a failed model turn. */
|
|
744
|
+
function getTurnFailureReason(reply) {
|
|
745
|
+
if (reply.diagnostics.outcome === "success") return;
|
|
746
|
+
if (reply.diagnostics.outcome === "provider_error") return findProviderError(reply.diagnostics.providerError)?.kind ?? "unknown";
|
|
747
|
+
if (reply.diagnostics.toolErrorCount > 0) return "tool_errors";
|
|
748
|
+
if (reply.diagnostics.usedPrimaryText && reply.diagnostics.assistantMessageCount > 0) return "suppressed_output";
|
|
749
|
+
return "empty_output";
|
|
750
|
+
}
|
|
751
|
+
function getFailureCapture(reply) {
|
|
752
|
+
if (reply.diagnostics.outcome === "provider_error") {
|
|
753
|
+
const providerError = findProviderError(reply.diagnostics.providerError);
|
|
754
|
+
return {
|
|
755
|
+
eventName: "agent.turn.provider_error",
|
|
756
|
+
error: reply.diagnostics.providerError ?? new Error(reply.diagnostics.errorMessage ?? "Provider error without explicit message"),
|
|
757
|
+
attributes: providerError ? getProviderErrorAttributes(providerError) : {},
|
|
758
|
+
body: "Agent turn failed with provider error"
|
|
759
|
+
};
|
|
760
|
+
}
|
|
761
|
+
const failureReason = getExecutionFailureReason(reply);
|
|
762
|
+
return {
|
|
763
|
+
eventName: "agent.turn.execution.failed",
|
|
764
|
+
error: /* @__PURE__ */ new Error(`Agent turn execution failure: ${failureReason}`),
|
|
765
|
+
attributes: { "app.ai.execution_failure_reason": failureReason },
|
|
766
|
+
body: "Agent turn completed with execution failure"
|
|
767
|
+
};
|
|
768
|
+
}
|
|
769
|
+
/** Keep failed-turn Sentry captures and completion spans on the same keys. */
|
|
770
|
+
function getAgentTurnDiagnosticsAttributes(reply) {
|
|
771
|
+
return {
|
|
772
|
+
"app.ai.outcome": reply.diagnostics.outcome,
|
|
773
|
+
"app.ai.assistant_messages": reply.diagnostics.assistantMessageCount,
|
|
774
|
+
"app.ai.tool_results": reply.diagnostics.toolResultCount,
|
|
775
|
+
"app.ai.tool_error_results": reply.diagnostics.toolErrorCount,
|
|
776
|
+
"app.ai.tool_call_count": reply.diagnostics.toolCalls.length,
|
|
777
|
+
"app.ai.used_primary_text": reply.diagnostics.usedPrimaryText,
|
|
778
|
+
...reply.automation ? { "app.automation.result": reply.automation.result } : void 0,
|
|
779
|
+
...reply.diagnostics.reasoningLevel ? { "gen_ai.request.reasoning.level": reply.diagnostics.reasoningLevel } : void 0,
|
|
780
|
+
...reply.diagnostics.stopReason ? { "gen_ai.response.finish_reasons": [reply.diagnostics.stopReason] } : void 0,
|
|
781
|
+
...reply.diagnostics.errorMessage && reply.diagnostics.outcome !== "provider_error" ? { "exception.message": reply.diagnostics.errorMessage } : void 0
|
|
782
|
+
};
|
|
783
|
+
}
|
|
784
|
+
/** Enforce one captured failure response and return its structured correlation. */
|
|
785
|
+
function finalizeFailedTurnReplyWithEvent(args) {
|
|
786
|
+
if (args.reply.diagnostics.outcome === "success") return { reply: args.reply };
|
|
787
|
+
const failureReason = getTurnFailureReason(args.reply);
|
|
788
|
+
const capture = getFailureCapture(args.reply);
|
|
789
|
+
const eventId = requireTurnFailureEventId(args.logException(capture.error, capture.eventName, {
|
|
790
|
+
...getAgentTurnDiagnosticsAttributes(args.reply),
|
|
791
|
+
...args.attributes,
|
|
792
|
+
...capture.attributes,
|
|
793
|
+
...failureReason ? { "app.ai.failure_reason": failureReason } : void 0
|
|
794
|
+
}), capture.eventName);
|
|
795
|
+
const providerPartialText = args.reply.diagnostics.outcome === "provider_error" && args.reply.diagnostics.assistantMessageCount > 0 ? args.reply.text.trim() : "";
|
|
796
|
+
const providerUserMessage = args.reply.diagnostics.providerError instanceof ProviderError ? getProviderErrorUserMessage(args.reply.diagnostics.providerError) : "";
|
|
797
|
+
const failureText = providerUserMessage ? `${providerUserMessage} Reference: \`event_id=${eventId}\`.` : buildTurnFailureResponse(eventId);
|
|
798
|
+
return {
|
|
799
|
+
eventId,
|
|
800
|
+
...failureReason ? { failureReason } : void 0,
|
|
801
|
+
reply: {
|
|
802
|
+
...args.reply,
|
|
803
|
+
text: providerPartialText ? `${providerPartialText}${getInterruptionMarker()}` : failureText
|
|
804
|
+
}
|
|
805
|
+
};
|
|
806
|
+
}
|
|
807
|
+
export { getUnnamedAgentConversationId as $, markAgentInvocationPaused as A, AGENT_TYPES as B, isTerminalAgentInvocation as C, listPendingAgentInvocationResults as D, listPendingAgentInvocationMailboxAppends as E, CHILD_AGENT_RESULTS as F, getAgentInvocationIdForEvents as G, agentTypeStartsWithParentHistory as H, PARENT_AGENT_TARGET as I, getAgentInvocationMessageId as J, getAgentInvocationIdForMessage as K, agentBindingSchema as L, markAgentInvocationSteered as M, reportReplacedAgentInvocation as N, markAgentInvocationMailboxAppended as O, CHILD_AGENT_KINDS as P, getNamedAgentConversationId as Q, agentNameSchema as R, invocationFromRow as S, listOpenAgentInvocations as T, formatAgentTypes as U, agentTypeInstructions as V, getAgentInvocationId as W, getAgentInvocationTurnId as X, getAgentInvocationResultMessageId as Y, getChildAgentLockName as Z, completeAgentInvocation as _, persistAuthPauseTurnState as a, getConversationTurnBoundaryError as at, getChildAgentLabel as b, getTurnUserSlackMessageTs as c, isTurnInputDeferredError as ct, loadThreadContextTrimFloor as d, markTurnFailed as dt, parseAgentInvocationResultMessageId as et, ConversationTurnLifecycleService as f, startActiveTurn as ft, NON_TERMINAL_AGENT_INVOCATION_STATUSES as g, ACTIVE_AGENT_INVOCATION_STATUSES as h, completeAuthPauseTurn as i, TurnInputDeferredError as it, markAgentInvocationRunning as j, markAgentInvocationParentMailboxAppended as k, buildDeliveredTurnStatePatch as l, markTurnClosed as lt, loadPendingMessageCards as m, getAgentTurnDiagnosticsAttributes as n, CooperativeTurnYieldError as nt, getTurnUserMessage as o, isCooperativeTurnYieldError as ot, getTurnLifecycle as p, getAgentInvocationIdForResult as q, requireTurnFailureEventId as r, TurnInputCommitLostError as rt, getTurnUserReplyAttachmentContext as s, isTurnInputCommitLostError as st, finalizeFailedTurnReplyWithEvent as t, ConversationTurnBoundaryError as tt, buildTurnThreadContext as u, markTurnCompleted as ut, getActiveAgentInvocationForConversation as v, listAgentInvocationsForConversation as w, getLatestAgentInvocationForConversation as x, getAgentInvocation as y, createAgentInvocationSchema as z };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { v as __exportAll } from "./sentry-BRTJqumy.js";
|
|
2
|
-
import { n as pluginCatalogRuntime } from "./catalog-runtime-
|
|
2
|
+
import { n as pluginCatalogRuntime } from "./catalog-runtime-BCIuBe4d.js";
|
|
3
3
|
import { isDeepStrictEqual } from "node:util";
|
|
4
4
|
// src/chat/plugins/validation.ts
|
|
5
5
|
var validation_exports = /* @__PURE__ */ __exportAll({
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// package.json
|
|
2
|
-
var version = "0.
|
|
2
|
+
var version = "0.287.0";
|
|
3
3
|
// src/version.ts
|
|
4
4
|
/** Installed Junior package version, or `unknown` when package metadata is unavailable. */
|
|
5
5
|
const JUNIOR_VERSION = typeof version === "string" && version.trim() ? version : "unknown";
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { t as JUNIOR_VERSION } from "./version-
|
|
1
|
+
export { t as JUNIOR_VERSION } from "./version-DBvhk1X9.js";
|