@sentry/junior 0.222.0 → 0.224.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 (61) hide show
  1. package/dist/{agent-hooks-DkriF84n.js → agent-hooks-DNLBwmsh.js} +60 -16
  2. package/dist/{agent-7kKtDe-6.js → agent-runner-9g6TQk9y.js} +879 -69
  3. package/dist/api/schema.d.ts +160 -11
  4. package/dist/api/schema.js +2 -2
  5. package/dist/api.js +16 -16
  6. package/dist/{app-C0zbsnr7.d.ts → app-BbSD6EtD.d.ts} +1 -1
  7. package/dist/app.d.ts +1 -1
  8. package/dist/app.js +1598 -69
  9. package/dist/{briefs-CNH1ztn5.js → briefs-CjXnGKzZ.js} +6 -6
  10. package/dist/{catalog-runtime-XH_LFA_7.js → catalog-runtime-CVZ9TEuK.js} +1 -1
  11. package/dist/{checkpoint-CRod8es5.js → checkpoint-Ceck_fLO.js} +12 -9
  12. package/dist/cli/chat.js +14 -15
  13. package/dist/cli/check.js +3 -3
  14. package/dist/cli/main.js +1 -1
  15. package/dist/cli/plugins.js +3 -3
  16. package/dist/cli/snapshot-create.js +3 -3
  17. package/dist/cli/upgrade.js +3 -3
  18. package/dist/{client-CcSboWx_.js → client-B27ufhzl.js} +56 -6
  19. package/dist/{config-CGYv-YPE.js → config-BAhl7-RC.js} +6 -7
  20. package/dist/{conversation-BBDt88di.js → conversation-1HUoZr2l.js} +33 -5
  21. package/dist/{conversation-privacy-BGjdDVWD.js → conversation-privacy-C-4JQzKD.js} +1 -1
  22. package/dist/credential-sync-BXHIxbtS.js +940 -0
  23. package/dist/{execution-stats-D97ePWuM.js → execution-stats-DikPOxJ1.js} +3 -3
  24. package/dist/{executor-BLBZ-UB8.js → executor-BG2Armby.js} +1 -1
  25. package/dist/{history-CaV8Ww7M.d.ts → history-yaSjGMD_.d.ts} +18 -0
  26. package/dist/instrumentation.js +2 -2
  27. package/dist/{job-queue-_8gxwDzt.js → job-queue-D4oAVrL9.js} +1 -1
  28. package/dist/{logging-qmsMdU0y.js → logging-iY0ssa2q.js} +1 -1
  29. package/dist/nitro.d.ts +1 -1
  30. package/dist/nitro.js +3 -3
  31. package/dist/{pending-auth-_1Ry-_Bw.js → oauth-authorization-BIijVS2N.js} +6 -48
  32. package/dist/{oauth-callback-server-Mjfm46A5.js → oauth-callback-server-DPkK3kzi.js} +4 -4
  33. package/dist/{profile-DbG8AlNd.js → profile-6KWhg_-U.js} +5 -9
  34. package/dist/{prompt-B8rCQI7K.js → prompt-90miy8VV.js} +1 -1
  35. package/dist/{registry-DGyQCsiy.js → registry-Ctgdjt-W.js} +1 -1
  36. package/dist/{resolve-D5SqDbCA.js → resolve-CB45ZukQ.js} +2 -2
  37. package/dist/{runner-BRAFjJhe.js → runner-BwKCqoF3.js} +9 -10
  38. package/dist/{sandbox-egress-signals-CdI1aVHT.js → sandbox-egress-signals-Cmy8ODat.js} +1 -1
  39. package/dist/{schema-CTOODa3L.js → schema-RpbW5Od2.js} +1 -1
  40. package/dist/{short-title-CB2fxEyx.js → short-title-xEkZwkcV.js} +2 -2
  41. package/dist/{skills-BoS3b8cg.js → skills-c2bMDVRS.js} +2 -2
  42. package/dist/{spawn-BXCU1udr.js → spawn-Cg6lyjE7.js} +2 -2
  43. package/dist/{stats-qUXQZq-w.js → stats-DP9zl3Jg.js} +19 -17
  44. package/dist/{task-queue-Di_q8922.js → task-queue-SL4uLfBB.js} +3 -3
  45. package/dist/{task-runner-4rCppQMo.js → task-runner-fntmnqzx.js} +9 -84
  46. package/dist/{thread-state-2Paza8DV.js → thread-state-Wfr0GdKS.js} +5 -5
  47. package/dist/{auth-pause-state-3OT67TA8.js → turn-failure-response-DLjSEm-R.js} +74 -84
  48. package/dist/{turn-lifecycle-f-y0Irpi.js → turn-lifecycle-5_jvLqRz.js} +1 -1
  49. package/dist/turn-session-routing-CQaysLoe.js +77 -0
  50. package/dist/{validation-Be9lSORU.js → validation-CnZkCN7o.js} +1 -1
  51. package/dist/{version-BydrOZMQ.js → version-C6lA-h_o.js} +1 -1
  52. package/dist/version.js +1 -1
  53. package/dist/{web-authorization-BdfOkTuG.js → web-authorization-Bbx999_q.js} +1 -1
  54. package/dist/{web-input-DegYUyKU.js → web-input-BoE1xE-K.js} +7 -7
  55. package/dist/{work-Citqpnfc.js → work-4Nhz9mVv.js} +52 -10
  56. package/dist/{worker-Bn_HFyvM.js → worker-CdWPsNL2.js} +5 -5
  57. package/package.json +4 -4
  58. package/dist/agent-runner-D0ImXS7U.js +0 -679
  59. package/dist/credential-sync-BfzGNruT.js +0 -2757
  60. package/dist/experimental-CIXf7Uye.js +0 -46
  61. package/dist/turn-execution--F7a9kEU.js +0 -47
@@ -1,12 +1,52 @@
1
- import { _ as findProviderError, h as ProviderError, v as getProviderErrorAttributes, y as getProviderErrorUserMessage } from "./client-CcSboWx_.js";
2
- import { F as isRecord, t as buildTurnFailureResponse } from "./logging-qmsMdU0y.js";
1
+ import { y as clearPendingAuth } from "./agent-runner-9g6TQk9y.js";
2
+ import { _ as findProviderError, h as ProviderError, v as getProviderErrorAttributes, y as getProviderErrorUserMessage } from "./client-B27ufhzl.js";
3
+ import { F as isRecord, t as buildTurnFailureResponse } from "./logging-iY0ssa2q.js";
3
4
  import { _ as parseSlackMessageTs } from "./context-Bplcgypl.js";
4
- import { Ht as getConversationEventStore } from "./agent-hooks-DkriF84n.js";
5
- import { A as readMessageCards } from "./conversation-BBDt88di.js";
6
- import { Y as hydrateConversationMessages, ot as markConversationMessage } from "./checkpoint-CRod8es5.js";
7
- import { qt as buildDeterministicTurnId } from "./stats-qUXQZq-w.js";
8
- import { b as markTurnCompleted, r as clearPendingAuth, y as markTurnClosed } from "./pending-auth-_1Ry-_Bw.js";
9
- import { o as persistThreadStateById, r as getPersistedThreadState, s as coerceThreadConversationState } from "./thread-state-2Paza8DV.js";
5
+ import { Wt as getConversationEventStore } from "./agent-hooks-DNLBwmsh.js";
6
+ import { A as messageCardKey, N as readMessageCards, j as messageCardRefSchema } from "./conversation-1HUoZr2l.js";
7
+ import { J as hydrateConversationMessages, at as markConversationMessage } from "./checkpoint-Ceck_fLO.js";
8
+ import { qt as buildDeterministicTurnId } from "./stats-DP9zl3Jg.js";
9
+ import { g as markTurnCompleted, h as markTurnClosed } from "./oauth-authorization-BIijVS2N.js";
10
+ import { o as persistThreadStateById, r as getPersistedThreadState, s as coerceThreadConversationState } from "./thread-state-Wfr0GdKS.js";
11
+ //#region src/chat/conversations/pending-cards.ts
12
+ /** Read undelivered card snapshots across resume and history replacement. */
13
+ async function loadPendingMessageCards(conversationId) {
14
+ const cards = /* @__PURE__ */ new Map();
15
+ const deleted = /* @__PURE__ */ new Set();
16
+ let beforeSeq;
17
+ while (true) {
18
+ const page = await getConversationEventStore().query(conversationId, {
19
+ beforeSeq,
20
+ limit: 100,
21
+ types: [
22
+ "tool_result",
23
+ "message",
24
+ "turn_started"
25
+ ]
26
+ });
27
+ for (const event of [...page.events].reverse()) {
28
+ const data = event.data;
29
+ if (data.type === "turn_started" || data.type === "message" && data.role === "assistant") return [...cards.values()].reverse();
30
+ if (data.type !== "tool_result" || data.isError || typeof data.toolName !== "string" || !isRecord(data.details)) continue;
31
+ if (data.details.timed_out === true) continue;
32
+ if (Array.isArray(data.details.removedCards)) for (const ref of messageCardRefSchema.array().parse(data.details.removedCards)) deleted.add(JSON.stringify([ref.plugin, ref.key]));
33
+ for (const card of readMessageCards(data.details)) {
34
+ const key = messageCardKey(card);
35
+ if (!deleted.has(key) && !cards.has(key)) cards.set(key, card);
36
+ }
37
+ }
38
+ if (!page.hasOlder || page.events.length === 0) return [...cards.values()].reverse();
39
+ beforeSeq = page.events[0].seq;
40
+ }
41
+ }
42
+ //#endregion
43
+ //#region src/chat/interruption-marker.ts
44
+ const INTERRUPTED_MARKER = "\n\n[Response interrupted before completion]";
45
+ /** Return the marker added when a visible reply ended mid-execution. */
46
+ function getInterruptionMarker() {
47
+ return INTERRUPTED_MARKER;
48
+ }
49
+ //#endregion
10
50
  //#region src/chat/runtime/delivered-turn-state.ts
11
51
  /** Build state after destination delivery or intentional no-reply completion. */
12
52
  function buildDeliveredTurnStatePatch(args) {
@@ -55,54 +95,32 @@ function getTurnUserReplyAttachmentContext(message) {
55
95
  };
56
96
  }
57
97
  //#endregion
58
- //#region src/chat/conversations/pending-cards.ts
59
- const CARD_TOOLS = /* @__PURE__ */ new Set([
60
- "createEventAutomation",
61
- "updateEventAutomation",
62
- "deleteEventAutomation",
63
- "slackScheduleCreateAutomation",
64
- "slackScheduleUpdateAutomation",
65
- "slackScheduleDeleteAutomation"
66
- ]);
67
- /** Read undelivered card snapshots across resume and history replacement. */
68
- async function loadPendingMessageCards(conversationId) {
69
- const cards = /* @__PURE__ */ new Map();
70
- const deleted = /* @__PURE__ */ new Set();
71
- let beforeSeq;
72
- while (true) {
73
- const page = await getConversationEventStore().query(conversationId, {
74
- beforeSeq,
75
- limit: 100,
76
- types: [
77
- "tool_result",
78
- "message",
79
- "turn_started"
80
- ]
81
- });
82
- for (const event of [...page.events].reverse()) {
83
- const data = event.data;
84
- if (data.type === "turn_started" || data.type === "message" && data.role === "assistant") return [...cards.values()].reverse();
85
- if (data.type !== "tool_result" || data.isError || typeof data.toolName !== "string" || !CARD_TOOLS.has(data.toolName) || !isRecord(data.details)) continue;
86
- if (data.toolName === "deleteEventAutomation" || data.toolName === "slackScheduleDeleteAutomation") {
87
- if (isRecord(data.details.automation) && typeof data.details.automation.id === "string") deleted.add(data.details.automation.id);
88
- continue;
89
- }
90
- if (!Array.isArray(data.details.cards)) continue;
91
- for (const card of readMessageCards(data.details.cards)) {
92
- const key = `${card.kind}:${card.id}`;
93
- if (!deleted.has(card.id) && !cards.has(key)) cards.set(key, card);
94
- }
95
- }
96
- if (!page.hasOlder || page.events.length === 0) return [...cards.values()].reverse();
97
- beforeSeq = page.events[0].seq;
98
- }
98
+ //#region src/chat/runtime/auth-pause-state.ts
99
+ /** Mark an auth-paused turn complete after private authorization link delivery. */
100
+ function completeAuthPauseTurn(args) {
101
+ markConversationMessage(args.conversation, getTurnUserMessageId(args.conversation, args.sessionId), {
102
+ replied: true,
103
+ skippedReason: void 0
104
+ });
105
+ markTurnClosed({
106
+ conversation: args.conversation,
107
+ nowMs: Date.now(),
108
+ sessionId: args.sessionId
109
+ });
99
110
  }
100
- //#endregion
101
- //#region src/chat/interruption-marker.ts
102
- const INTERRUPTED_MARKER = "\n\n[Response interrupted before completion]";
103
- /** Return the marker added when a visible reply ended mid-execution. */
104
- function getInterruptionMarker() {
105
- return INTERRUPTED_MARKER;
111
+ /** Reload thread state, mark the auth pause as parked, and persist it. */
112
+ async function persistAuthPauseTurnState(args) {
113
+ const currentState = await getPersistedThreadState(args.threadStateId);
114
+ const conversation = coerceThreadConversationState(currentState);
115
+ await hydrateConversationMessages({
116
+ conversation,
117
+ conversationId: args.threadStateId
118
+ });
119
+ completeAuthPauseTurn({
120
+ conversation,
121
+ sessionId: args.sessionId
122
+ });
123
+ await persistThreadStateById(args.threadStateId, { conversation });
106
124
  }
107
125
  //#endregion
108
126
  //#region src/chat/services/turn-failure-response.ts
@@ -182,32 +200,4 @@ function finalizeFailedTurnReplyWithEvent(args) {
182
200
  };
183
201
  }
184
202
  //#endregion
185
- //#region src/chat/runtime/auth-pause-state.ts
186
- /** Mark an auth-paused turn complete after private authorization link delivery. */
187
- function completeAuthPauseTurn(args) {
188
- markConversationMessage(args.conversation, getTurnUserMessageId(args.conversation, args.sessionId), {
189
- replied: true,
190
- skippedReason: void 0
191
- });
192
- markTurnClosed({
193
- conversation: args.conversation,
194
- nowMs: Date.now(),
195
- sessionId: args.sessionId
196
- });
197
- }
198
- /** Reload thread state, mark the auth pause as parked, and persist it. */
199
- async function persistAuthPauseTurnState(args) {
200
- const currentState = await getPersistedThreadState(args.threadStateId);
201
- const conversation = coerceThreadConversationState(currentState);
202
- await hydrateConversationMessages({
203
- conversation,
204
- conversationId: args.threadStateId
205
- });
206
- completeAuthPauseTurn({
207
- conversation,
208
- sessionId: args.sessionId
209
- });
210
- await persistThreadStateById(args.threadStateId, { conversation });
211
- }
212
- //#endregion
213
- export { requireTurnFailureEventId as a, getTurnUserMessage as c, getTurnUserSlackMessageTs as d, buildDeliveredTurnStatePatch as f, getAgentTurnDiagnosticsAttributes as i, getTurnUserMessageId as l, persistAuthPauseTurnState as n, getInterruptionMarker as o, finalizeFailedTurnReplyWithEvent as r, loadPendingMessageCards as s, completeAuthPauseTurn as t, getTurnUserReplyAttachmentContext as u };
203
+ export { persistAuthPauseTurnState as a, getTurnUserSlackMessageTs as c, loadPendingMessageCards as d, completeAuthPauseTurn as i, buildDeliveredTurnStatePatch as l, getAgentTurnDiagnosticsAttributes as n, getTurnUserMessage as o, requireTurnFailureEventId as r, getTurnUserReplyAttachmentContext as s, finalizeFailedTurnReplyWithEvent as t, getInterruptionMarker as u };
@@ -1,4 +1,4 @@
1
- import { Ht as getConversationEventStore } from "./agent-hooks-DkriF84n.js";
1
+ import { Wt as getConversationEventStore } from "./agent-hooks-DNLBwmsh.js";
2
2
  //#region src/chat/conversations/turn-lifecycle.ts
3
3
  /** Persist correlated turn lifecycle facts with retry-safe terminal exclusion. */
4
4
  var ConversationTurnLifecycleService = class {
@@ -0,0 +1,77 @@
1
+ //#region src/chat/services/turn-session-routing.ts
2
+ async function loadConversationChain(conversationId, conversationStore) {
3
+ const chain = [];
4
+ const seen = /* @__PURE__ */ new Set();
5
+ let cursor = conversationId;
6
+ while (cursor && !seen.has(cursor)) {
7
+ seen.add(cursor);
8
+ const conversation = await conversationStore.get({ conversationId: cursor });
9
+ if (!conversation) break;
10
+ chain.push(conversation);
11
+ cursor = conversation.parentConversationId;
12
+ }
13
+ return chain;
14
+ }
15
+ /**
16
+ * Normalize a stored Slack session source against the conversation destination.
17
+ *
18
+ * Does not create channel or thread values from the conversation id.
19
+ */
20
+ function slackSourceForDestination(args) {
21
+ if (args.source?.kind !== "slack" || args.source.channelId !== args.destination.channelId) return;
22
+ const threadTs = args.source.threadTs?.trim();
23
+ return {
24
+ kind: "slack",
25
+ visibility: args.source.visibility ?? "public",
26
+ teamId: args.source.teamId?.trim() || args.destination.teamId,
27
+ channelId: args.source.channelId,
28
+ ...threadTs ? { threadTs } : void 0
29
+ };
30
+ }
31
+ /**
32
+ * Resolve the Conversation Location, Destination, and session Source.
33
+ *
34
+ * Reads parent Conversations when this Conversation has no Destination.
35
+ */
36
+ async function resolveConversationRouting(args) {
37
+ const conversationStore = args.conversationStore ?? (await import("./agent-hooks-DNLBwmsh.js").then((n) => n.Ut)).getConversationStore();
38
+ const chain = await loadConversationChain(args.conversationId, conversationStore);
39
+ let destination;
40
+ let source;
41
+ let location;
42
+ for (const conversation of chain) {
43
+ destination ??= conversation.destination;
44
+ source ??= conversation.sessionSource;
45
+ location ??= conversation.location;
46
+ if (destination && source) break;
47
+ }
48
+ if (!destination) return;
49
+ if (destination.platform === "slack") {
50
+ const slackSource = slackSourceForDestination({
51
+ destination,
52
+ source
53
+ });
54
+ return {
55
+ destination,
56
+ ...location ? { location } : void 0,
57
+ ...slackSource ? { source: slackSource } : void 0
58
+ };
59
+ }
60
+ return {
61
+ destination,
62
+ ...location ? { location } : void 0,
63
+ ...source ? { source } : void 0
64
+ };
65
+ }
66
+ /** Require the Conversation Destination and Source from SQL. */
67
+ async function resolveTurnSessionRouting(args) {
68
+ const routing = await resolveConversationRouting(args);
69
+ if (!routing?.destination || !routing.source) throw new Error(`Conversation ${args.conversationId} is missing durable routing metadata`);
70
+ return {
71
+ destination: routing.destination,
72
+ ...routing.location ? { location: routing.location } : void 0,
73
+ source: routing.source
74
+ };
75
+ }
76
+ //#endregion
77
+ export { resolveTurnSessionRouting as n, resolveConversationRouting as t };
@@ -1,5 +1,5 @@
1
1
  import { t as __exportAll } from "./rolldown-runtime-B4FMCO8f.js";
2
- import { n as pluginCatalogRuntime } from "./catalog-runtime-XH_LFA_7.js";
2
+ import { n as pluginCatalogRuntime } from "./catalog-runtime-CVZ9TEuK.js";
3
3
  import { isDeepStrictEqual } from "node:util";
4
4
  //#region src/chat/plugins/validation.ts
5
5
  var validation_exports = /* @__PURE__ */ __exportAll({
@@ -1,5 +1,5 @@
1
1
  //#region package.json
2
- var version = "0.222.0";
2
+ var version = "0.224.0";
3
3
  //#endregion
4
4
  //#region src/version.ts
5
5
  /** Installed Junior package version, or `unknown` when package metadata is unavailable. */
package/dist/version.js CHANGED
@@ -1,2 +1,2 @@
1
- import { t as JUNIOR_VERSION } from "./version-BydrOZMQ.js";
1
+ import { t as JUNIOR_VERSION } from "./version-C6lA-h_o.js";
2
2
  export { JUNIOR_VERSION };
@@ -1,4 +1,4 @@
1
- import { w as getStateAdapter } from "./profile-DbG8AlNd.js";
1
+ import { w as getStateAdapter } from "./profile-6KWhg_-U.js";
2
2
  import { randomUUID } from "node:crypto";
3
3
  //#region src/chat/conversations/web-authorization.ts
4
4
  const WEB_AUTHORIZATION_PREFIX = "junior:web_authorization:v1";
@@ -1,13 +1,13 @@
1
- import { f as logWarn } from "./logging-qmsMdU0y.js";
2
- import { s as getSlackBotToken } from "./config-CGYv-YPE.js";
1
+ import { f as logWarn } from "./logging-iY0ssa2q.js";
2
+ import { s as getSlackBotToken } from "./config-BAhl7-RC.js";
3
3
  import "./context-Bplcgypl.js";
4
- import { Gt as getDb, K as normalizeSlackConversationId, Wt as getConversationStore } from "./agent-hooks-DkriF84n.js";
4
+ import { K as normalizeSlackConversationId, Kt as getConversationStore, qt as getDb } from "./agent-hooks-DNLBwmsh.js";
5
5
  import { n as juniorDestinations } from "./destinations-BeBiJeEM.js";
6
- import { D as juniorIdentities, O as juniorUsers, o as juniorSchedulerTasks } from "./executor-BLBZ-UB8.js";
7
- import { t as fallbackShortTitle } from "./short-title-CB2fxEyx.js";
8
- import { A as eventAutomationTriggerAvailable, F as effectiveTaskOutcomes, G as listDeletedEventAutomationsCreatedBy, H as eventAutomationBelongsToUser, J as listPublicEventAutomationsForTeams, K as listEventAutomationsCreatedBy, V as deleteEventAutomation, W as getEventAutomation, X as getEventCatalog, _ as parseScheduledAutomationRow, c as parseSlackThreadId, ft as appendAndEnqueueExclusiveInboundMessage, m as listPublicScheduledAutomationsForTeams, p as isListedScheduledAutomation, pt as appendAndEnqueueInboundMessage, qt as buildDeterministicTurnId, v as readScheduledAutomation, y as saveScheduledAutomation } from "./stats-qUXQZq-w.js";
6
+ import { D as juniorIdentities, O as juniorUsers, o as juniorSchedulerTasks } from "./executor-BG2Armby.js";
7
+ import { t as fallbackShortTitle } from "./short-title-xEkZwkcV.js";
8
+ import { A as eventAutomationTriggerAvailable, F as effectiveTaskOutcomes, G as listDeletedEventAutomationsCreatedBy, H as eventAutomationBelongsToUser, J as listPublicEventAutomationsForTeams, K as listEventAutomationsCreatedBy, V as deleteEventAutomation, W as getEventAutomation, X as getEventCatalog, _ as parseScheduledAutomationRow, c as parseSlackThreadId, ft as appendAndEnqueueExclusiveInboundMessage, m as listPublicScheduledAutomationsForTeams, p as isListedScheduledAutomation, pt as appendAndEnqueueInboundMessage, qt as buildDeterministicTurnId, v as readScheduledAutomation, y as saveScheduledAutomation } from "./stats-DP9zl3Jg.js";
9
9
  import { p as healthReportSchema, s as sumUtcHoursIntoSixHours } from "./reporting-window-DbUqng0P.js";
10
- import { a as readAutomationExecutionStatusDays, c as readAutomationExecutions, i as readAutomationExecutionHours, l as readAutomationRuns, n as readAutomationExecutionByConversationId, o as readAutomationExecutionStatusHours, r as readAutomationExecutionDays, s as readAutomationExecutionSummaries, t as emptyAutomationRunWindows } from "./execution-stats-D97ePWuM.js";
10
+ import { a as readAutomationExecutionStatusDays, c as readAutomationExecutions, i as readAutomationExecutionHours, l as readAutomationRuns, n as readAutomationExecutionByConversationId, o as readAutomationExecutionStatusHours, r as readAutomationExecutionDays, s as readAutomationExecutionSummaries, t as emptyAutomationRunWindows } from "./execution-stats-DikPOxJ1.js";
11
11
  import { z } from "zod";
12
12
  import { createHash } from "node:crypto";
13
13
  import { and, desc, eq, inArray, lt, notInArray, or, sql } from "drizzle-orm";
@@ -1,13 +1,12 @@
1
1
  import { t as __exportAll } from "./rolldown-runtime-B4FMCO8f.js";
2
- import { $ as AuthorizationFlowDisabledError, A as createAgentInvocationSchema, M as AgentInvocationLimitError, O as agentBindingSchema, f as PluginCredentialFailureError, j as AgentInvocationBusyError, k as agentInvocationSchema } from "./agent-7kKtDe-6.js";
3
- import { Ht as getConversationEventStore, Kt as getSqlExecutor, Wt as getConversationStore } from "./agent-hooks-DkriF84n.js";
4
- import { f as juniorAgentBindings, p as juniorAgentInvocations } from "./executor-BLBZ-UB8.js";
5
- import { L as openConversationProjection, o as failTurnRecord, r as saveTurnCheckpoint, s as getTurnRecord, v as getTerminalAssistantMessages } from "./checkpoint-CRod8es5.js";
6
- import { pt as appendAndEnqueueInboundMessage } from "./stats-qUXQZq-w.js";
7
- import { _ as isTurnInputCommitLostError, h as getConversationTurnBoundaryError, p as TurnInputCommitLostError, s as getAssistantReplyText } from "./pending-auth-_1Ry-_Bw.js";
8
- import { t as ConversationTurnLifecycleService } from "./turn-lifecycle-f-y0Irpi.js";
9
- import { n as executeTurn, t as AgentRunError } from "./turn-execution--F7a9kEU.js";
10
- import { n as getPersistedSandboxState, o as persistThreadStateById, r as getPersistedThreadState } from "./thread-state-2Paza8DV.js";
2
+ import { B as AgentInvocationLimitError, I as agentBindingSchema, L as agentInvocationSchema, R as createAgentInvocationSchema, St as AuthorizationFlowDisabledError, n as runAgentWithTimeout, v as PluginCredentialFailureError, z as AgentInvocationBusyError } from "./agent-runner-9g6TQk9y.js";
3
+ import { Jt as getSqlExecutor, Kt as getConversationStore, Wt as getConversationEventStore } from "./agent-hooks-DNLBwmsh.js";
4
+ import { f as juniorAgentBindings, p as juniorAgentInvocations } from "./executor-BG2Armby.js";
5
+ import { I as openConversationProjection, _ as getTerminalAssistantMessages, o as failTurnRecord, r as saveTurnCheckpoint, s as getTurnRecord } from "./checkpoint-Ceck_fLO.js";
6
+ import { pt as appendAndEnqueueInboundMessage } from "./stats-DP9zl3Jg.js";
7
+ import { d as getConversationTurnBoundaryError, l as TurnInputCommitLostError, p as isTurnInputCommitLostError, r as getAssistantReplyText } from "./oauth-authorization-BIijVS2N.js";
8
+ import { t as ConversationTurnLifecycleService } from "./turn-lifecycle-5_jvLqRz.js";
9
+ import { n as getPersistedSandboxState, o as persistThreadStateById, r as getPersistedThreadState } from "./thread-state-Wfr0GdKS.js";
11
10
  import { z } from "zod";
12
11
  import { createHash } from "node:crypto";
13
12
  import { and, asc, count, eq, inArray } from "drizzle-orm";
@@ -201,6 +200,49 @@ function isTerminalAgentInvocation(invocation) {
201
200
  return TERMINAL_AGENT_INVOCATION_STATUSES.includes(invocation.status);
202
201
  }
203
202
  //#endregion
203
+ //#region src/chat/runtime/turn-execution.ts
204
+ /** An error thrown while the agent advances a Run. */
205
+ var AgentRunError = class extends Error {
206
+ constructor(cause) {
207
+ super(cause instanceof Error ? cause.message : "Agent Run failed", { cause });
208
+ this.name = "AgentRunError";
209
+ }
210
+ };
211
+ /**
212
+ * Run the agent and finish the Turn after the caller saves its result.
213
+ *
214
+ * A paused Run, or a Run waiting for authorization, leaves the Turn open. A
215
+ * save error also leaves the Turn open so the worker can retry or recover it.
216
+ * A timeout aborts the Run before this function reports the failure.
217
+ */
218
+ async function executeTurn(agentRunner, run, saveResult, timeoutMs) {
219
+ let outcome;
220
+ try {
221
+ outcome = await runAgentWithTimeout(agentRunner, run, timeoutMs);
222
+ } catch (error) {
223
+ throw new AgentRunError(error);
224
+ }
225
+ if (outcome.status !== "completed") return outcome;
226
+ const saved = await saveResult(outcome.result);
227
+ const lifecycle = new ConversationTurnLifecycleService(getConversationEventStore());
228
+ const common = {
229
+ conversationId: run.conversationId,
230
+ createdAtMs: saved.finishedAtMs ?? Date.now(),
231
+ turnId: run.turnId
232
+ };
233
+ if (saved.outcome === "failed") await lifecycle.fail({
234
+ ...common,
235
+ ...saved.eventId ? { eventId: saved.eventId } : void 0,
236
+ failureCode: saved.failureCode,
237
+ ...saved.failureReason ? { failureReason: saved.failureReason } : void 0
238
+ });
239
+ else await lifecycle.complete({
240
+ ...common,
241
+ outcome: saved.outcome
242
+ });
243
+ return { status: "completed" };
244
+ }
245
+ //#endregion
204
246
  //#region src/chat/agent-invocations/work.ts
205
247
  var work_exports = /* @__PURE__ */ __exportAll({
206
248
  buildAgentInvocationInboundMessage: () => buildAgentInvocationInboundMessage,
@@ -506,4 +548,4 @@ function routeAgentInvocationWork(options) {
506
548
  };
507
549
  }
508
550
  //#endregion
509
- export { work_exports as a, resolveAgentInvocationId as i, createAndEnqueueAgentInvocation as n, listPendingAgentInvocationMailboxAppends as o, enqueueAgentInvocation as r, createAgentInvocationWorker as t };
551
+ export { work_exports as a, listPendingAgentInvocationMailboxAppends as c, resolveAgentInvocationId as i, createAndEnqueueAgentInvocation as n, AgentRunError as o, enqueueAgentInvocation as r, executeTurn as s, createAgentInvocationWorker as t };
@@ -1,10 +1,10 @@
1
1
  import { t as __exportAll } from "./rolldown-runtime-B4FMCO8f.js";
2
- import { b as isProviderRetryError } from "./client-CcSboWx_.js";
3
- import { S as withLogContext, d as logInfo, f as logWarn, u as logException } from "./logging-qmsMdU0y.js";
4
- import { a as getChatConfig } from "./config-CGYv-YPE.js";
5
- import { At as recordConversationRetry, Ct as drainConversationMailbox, Et as getConversationWorkState, Ft as startConversationWork, Ht as isInvalidConversationRecordError, Nt as requestAnotherSlice, St as deadLetterAttempt, Vt as isFinalAttempt, _t as clearConsumedConversationWake, bt as completeConversationWork, dt as ackMessages, gt as checkInConversationWork, jt as releaseConversationWork, kt as recordAttemptFailure, mt as beginConversationResume, wt as ensureConversationWake, xt as countPendingConversationMessages, yt as completeConversationStop, zt as hasConversationStop } from "./stats-qUXQZq-w.js";
2
+ import { b as isProviderRetryError } from "./client-B27ufhzl.js";
3
+ import { S as withLogContext, d as logInfo, f as logWarn, u as logException } from "./logging-iY0ssa2q.js";
4
+ import { a as getChatConfig } from "./config-BAhl7-RC.js";
5
+ import { At as recordConversationRetry, Ct as drainConversationMailbox, Et as getConversationWorkState, Ft as startConversationWork, Ht as isInvalidConversationRecordError, Nt as requestAnotherSlice, St as deadLetterAttempt, Vt as isFinalAttempt, _t as clearConsumedConversationWake, bt as completeConversationWork, dt as ackMessages, gt as checkInConversationWork, jt as releaseConversationWork, kt as recordAttemptFailure, mt as beginConversationResume, wt as ensureConversationWake, xt as countPendingConversationMessages, yt as completeConversationStop, zt as hasConversationStop } from "./stats-DP9zl3Jg.js";
6
6
  import { c as ConversationQueueMessageRejectedError } from "./vercel-queue-DIkVcfK4.js";
7
- import { a as getTurnRequestDeadline } from "./job-queue-_8gxwDzt.js";
7
+ import { a as getTurnRequestDeadline } from "./job-queue-D4oAVrL9.js";
8
8
  //#region src/chat/task-execution/worker.ts
9
9
  var worker_exports = /* @__PURE__ */ __exportAll({
10
10
  CONVERSATION_WORK_DEFER_DELAY_MS: () => CONVERSATION_WORK_DEFER_DELAY_MS,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sentry/junior",
3
- "version": "0.222.0",
3
+ "version": "0.224.0",
4
4
  "private": false,
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -85,7 +85,7 @@
85
85
  "pg": "^8.16.3",
86
86
  "yaml": "^2.9.0",
87
87
  "zod": "^4.5.4",
88
- "@sentry/junior-plugin-api": "0.222.0"
88
+ "@sentry/junior-plugin-api": "0.224.0"
89
89
  },
90
90
  "devDependencies": {
91
91
  "@emnapi/core": "^1.10.0",
@@ -104,9 +104,9 @@
104
104
  "typescript": "^6.0.3",
105
105
  "vercel": "^54.4.0",
106
106
  "vitest": "^4.1.7",
107
- "@sentry/junior-github": "0.222.0",
107
+ "@sentry/junior-memory": "0.224.0",
108
108
  "@sentry/junior-testing": "0.0.0",
109
- "@sentry/junior-memory": "0.222.0"
109
+ "@sentry/junior-github": "0.224.0"
110
110
  },
111
111
  "scripts": {
112
112
  "build": "tsdown",