@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.
Files changed (78) hide show
  1. package/dist/{adapter-DN5AB4VU.js → adapter-CL-HUKgd.js} +1 -1
  2. package/dist/{admin-DOITMKnn.js → admin-C9urXVfi.js} +2 -1
  3. package/dist/{agent-runner-BsWhHe4N.js → agent-runner-Bfnw551N.js} +2174 -1323
  4. package/dist/api/schema.d.ts +2 -2
  5. package/dist/api/schema.js +7 -7
  6. package/dist/api.d.ts +1 -1
  7. package/dist/api.js +73 -112
  8. package/dist/{app-DyMs9330.d.ts → app-DBY5TnfY.d.ts} +2 -3
  9. package/dist/app.d.ts +1 -1
  10. package/dist/app.js +72 -42
  11. package/dist/{assistant-reply-9Jip5bsr.js → assistant-reply-u_PRYzuz.js} +1 -1
  12. package/dist/{automation-Mk8aaHzy.js → automation-DksGNDRO.js} +3 -6
  13. package/dist/{background-compaction-queue-DXkLsWoH.js → background-compaction-queue-CYI909P5.js} +137 -3
  14. package/dist/{briefs-Cl8-nK9B.js → briefs-DaXiMWzT.js} +6 -5
  15. package/dist/{catalog-runtime-Bte6jRB2.js → catalog-runtime-BCIuBe4d.js} +1 -1
  16. package/dist/cli/chat.js +14 -14
  17. package/dist/cli/check.js +3 -3
  18. package/dist/cli/main.js +3 -3
  19. package/dist/cli/plugins.js +4 -4
  20. package/dist/cli/snapshot-create.js +5 -6
  21. package/dist/cli/upgrade.d.ts +1 -1
  22. package/dist/cli/upgrade.js +3 -3
  23. package/dist/{client-DDbBucBw.js → config-CkHcUMN7.js} +580 -3
  24. package/dist/{connections-DA4LT9LL.js → connections-BnIj0wtx.js} +16 -50
  25. package/dist/{conversation-D8kVoCrP.js → conversation-E7ZPJx2H.js} +22 -6
  26. package/dist/{conversation-pending-messages-BvROq1bq.js → conversation-pending-messages-DVch6YQw.js} +2 -5
  27. package/dist/{conversation-privacy-D0j_h70R.js → conversation-privacy-DF1hW0ja.js} +1 -1
  28. package/dist/{credential-sync-hcsYatw-.js → credential-sync-CzMar9hq.js} +13 -13
  29. package/dist/{viewer-1Ea81s0b.js → db-DJ11eZqq.js} +64 -367
  30. package/dist/{db-BhHZSuFw.d.ts → db-YDKKDxlh.d.ts} +4 -4
  31. package/dist/{executor-BLEMIgIZ.js → executor-BY9TB31g.js} +20 -19
  32. package/dist/instrumentation.js +2 -2
  33. package/dist/{logging-BfORLKoq.js → logging-BO5zU6Mt.js} +1 -1
  34. package/dist/{media-Bu9C6lz0.js → media-Cz1ZiV1U.js} +16 -4
  35. package/dist/{message-DqjuKzUx.js → message-CsUbuEc8.js} +10 -10
  36. package/dist/nitro.d.ts +1 -1
  37. package/dist/nitro.js +2 -3
  38. package/dist/{oauth-callback-server-CFSRzu1n.js → oauth-callback-server-hiDKK0_n.js} +2 -2
  39. package/dist/{projection-DliWYrnT.js → projection-CL_YWeGf.js} +352 -356
  40. package/dist/{prompt-BvIUzY4y.js → prompt-BHOEQSmf.js} +182 -2
  41. package/dist/{registry-rC7MCxu8.js → registry-BriFLnaJ.js} +1 -1
  42. package/dist/{reporting-window-B4TwyuJo.js → reporting-window-B3Ze-Qnt.js} +4 -1
  43. package/dist/{resolve-Biu8Qw3u.js → resolve-Bt6GgAiA.js} +3 -3
  44. package/dist/{result-DxJMCX47.js → result-Bo1TZu0Q.js} +8 -8
  45. package/dist/{runner-BQJSFLKg.js → runner-D3YeCQgt.js} +16 -12
  46. package/dist/{sandbox-egress-signals-6aMxJSDn.js → sandbox-egress-signals-CcnSPP4S.js} +1 -1
  47. package/dist/{schema-BasXTvi2.js → schema-BWE3RJEB.js} +19 -7
  48. package/dist/{schema-BUviRAs8.d.ts → schema-C6fsEwjo.d.ts} +90 -8
  49. package/dist/{service-account-BI5Wgx22.js → service-account-DiQQuuw7.js} +3 -3
  50. package/dist/{service-account-CAE-_1dR.js → service-account-r6fl0b-9.js} +3 -3
  51. package/dist/{session-stop-CA-jOJ84.js → session-stop-B2Nut40V.js} +27 -25
  52. package/dist/{skills-B22duVJU.js → skills-CD5aJdzg.js} +2 -2
  53. package/dist/spawn-CalgZQiu.js +79 -0
  54. package/dist/{stop-DioIcEAu.js → stop-kujZLbi0.js} +233 -1127
  55. package/dist/{store-Dn4W7qgH.js → store-DdIEUL1q.js} +3 -3
  56. package/dist/{turn-session-routing-CGMKrYOj.js → task-runner-D_RDr2Hu.js} +1440 -993
  57. package/dist/{store-B26LV6UP.js → turn-failure-response-B5nV1Er-.js} +337 -6
  58. package/dist/{validation-TzhfQABF.js → validation-K4pqwoVZ.js} +1 -1
  59. package/dist/{version-DSk8CFvA.js → version-DBvhk1X9.js} +1 -1
  60. package/dist/version.js +1 -1
  61. package/dist/viewer-DrMmFUul.js +337 -0
  62. package/dist/{work-ybG4_q5C.js → work-ljRoODGu.js} +110 -94
  63. package/dist/{worker-ccSyZRNz.js → worker-CYO1Q0Js.js} +5 -6
  64. package/migrations/0086_shared_archive.sql +31 -0
  65. package/migrations/0087_child_location.sql +64 -0
  66. package/migrations/0088_conversation_unsubscribe.sql +1 -0
  67. package/migrations/meta/0086_snapshot.json +4366 -0
  68. package/migrations/meta/0087_snapshot.json +4366 -0
  69. package/migrations/meta/0088_snapshot.json +4372 -0
  70. package/migrations/meta/_journal.json +21 -0
  71. package/package.json +5 -4
  72. package/dist/config-DqFnykQT.js +0 -579
  73. package/dist/spawn-BB2_4VYn.js +0 -31
  74. package/dist/task-queue-Bt0IoR2i.js +0 -139
  75. package/dist/task-runner-D8lddjzp.js +0 -290
  76. package/dist/thread-state-CrFk3K_7.js +0 -173
  77. package/dist/turn-failure-response-DaJ04qVj.js +0 -224
  78. package/dist/turn-lifecycle-C2mXS7AZ.js +0 -58
@@ -1,8 +1,13 @@
1
- import { g as TURN_REASONING_LEVELS } from "./config-DqFnykQT.js";
2
- import { C as getSqlExecutor } from "./viewer-1Ea81s0b.js";
3
- import { g as juniorAgentInvocations } from "./executor-BLEMIgIZ.js";
4
- import { p as credentialContextSchema } from "./registry-rC7MCxu8.js";
5
- import { S as AGENT_INVOCATION_PARENT_MAILBOX_STATUSES, x as AGENT_INVOCATION_MAILBOX_STATUSES } from "./reporting-window-B4TwyuJo.js";
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
- export { getAgentInvocationIdForEvents as A, ConversationTurnBoundaryError as B, agentNameSchema as C, agentTypeStartsWithParentHistory as D, agentTypeInstructions as E, getAgentInvocationTurnId as F, isCooperativeTurnYieldError as G, TurnInputCommitLostError as H, getChildAgentLockName as I, markTurnClosed as J, isTurnInputCommitLostError as K, getNamedAgentConversationId as L, getAgentInvocationIdForResult as M, getAgentInvocationMessageId as N, formatAgentTypes as O, getAgentInvocationResultMessageId as P, getUnnamedAgentConversationId as R, agentBindingSchema as S, AGENT_TYPES as T, TurnInputDeferredError as U, CooperativeTurnYieldError as V, getConversationTurnBoundaryError as W, markTurnFailed as X, markTurnCompleted as Y, startActiveTurn as Z, markAgentInvocationRunning as _, getAgentInvocation as a, CHILD_AGENT_RESULTS as b, invocationFromRow as c, listOpenAgentInvocations as d, listPendingAgentInvocationMailboxAppends as f, markAgentInvocationPaused as g, markAgentInvocationParentMailboxAppended as h, getActiveAgentInvocationForConversation as i, getAgentInvocationIdForMessage as j, getAgentInvocationId as k, isTerminalAgentInvocation as l, markAgentInvocationMailboxAppended as m, NON_TERMINAL_AGENT_INVOCATION_STATUSES as n, getChildAgentLabel as o, listPendingAgentInvocationResults as p, isTurnInputDeferredError as q, completeAgentInvocation as r, getLatestAgentInvocationForConversation as s, ACTIVE_AGENT_INVOCATION_STATUSES as t, listAgentInvocationsForConversation as u, markAgentInvocationSteered as v, createAgentInvocationSchema as w, PARENT_AGENT_TARGET as x, reportReplacedAgentInvocation as y, parseAgentInvocationResultMessageId as z };
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-Bte6jRB2.js";
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.285.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-DSk8CFvA.js";
1
+ export { t as JUNIOR_VERSION } from "./version-DBvhk1X9.js";