@sentry/junior 0.137.0 → 0.138.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 (87) hide show
  1. package/dist/{agent-hooks-MZOKEP3J.js → agent-hooks-SCR74Q3E.js} +11 -9
  2. package/dist/api.js +21 -18
  3. package/dist/app.d.ts +7 -0
  4. package/dist/app.js +248 -689
  5. package/dist/{catalog-runtime-MD66YLFV.js → catalog-runtime-IU3QF4GG.js} +5 -5
  6. package/dist/chat/agent/request.d.ts +32 -2
  7. package/dist/chat/agent-dispatch/heartbeat.d.ts +5 -0
  8. package/dist/chat/agent-dispatch/types.d.ts +1 -1
  9. package/dist/chat/agent-invocations/errors.d.ts +8 -0
  10. package/dist/chat/agent-invocations/spawn.d.ts +12 -0
  11. package/dist/chat/agent-invocations/store.d.ts +44 -0
  12. package/dist/chat/agent-invocations/types.d.ts +449 -0
  13. package/dist/chat/agent-invocations/work.d.ts +31 -0
  14. package/dist/chat/config.d.ts +1 -0
  15. package/dist/chat/conversations/sql/store.d.ts +8 -0
  16. package/dist/chat/conversations/store.d.ts +7 -0
  17. package/dist/chat/experimental.d.ts +16 -0
  18. package/dist/chat/runtime/agent-runner.d.ts +2 -1
  19. package/dist/chat/services/auth-pause.d.ts +0 -1
  20. package/dist/chat/services/mcp-auth-orchestration.d.ts +3 -2
  21. package/dist/chat/services/plugin-auth-orchestration.d.ts +3 -2
  22. package/dist/chat/state/turn-session.d.ts +0 -2
  23. package/dist/chat/task-execution/state.d.ts +23 -11
  24. package/dist/chat/task-execution/store.d.ts +20 -11
  25. package/dist/chat/task-execution/worker.d.ts +2 -2
  26. package/dist/chat/tools/runtime/spawn-agent.d.ts +31 -0
  27. package/dist/chat/tools/types.d.ts +2 -0
  28. package/dist/chunk-3Y47VMHV.js +6 -0
  29. package/dist/chunk-5IDFPCON.js +46 -0
  30. package/dist/chunk-5LTJ4ITU.js +1523 -0
  31. package/dist/{chunk-WPPXIAFB.js → chunk-5MXWHTCK.js} +17 -434
  32. package/dist/{chunk-UOXATPSI.js → chunk-A7WCHXZV.js} +7 -5
  33. package/dist/{chunk-5G34IEK2.js → chunk-BOLJOV5T.js} +2 -56
  34. package/dist/{chunk-UG6ZYPBI.js → chunk-BYW4B4PR.js} +73 -60
  35. package/dist/{chunk-XZ7NPXAB.js → chunk-C7ZVPO4Z.js} +1 -1
  36. package/dist/{chunk-RB4NJKEX.js → chunk-DCLLQGS6.js} +119 -50
  37. package/dist/{chunk-DQXAAVTR.js → chunk-E5UYAIKJ.js} +44 -1467
  38. package/dist/{chunk-6QW2RRQT.js → chunk-ELKW5FIB.js} +5 -5
  39. package/dist/chunk-EM225ITJ.js +56 -0
  40. package/dist/{chunk-SYCX4DOK.js → chunk-FEUNPTGV.js} +7 -60
  41. package/dist/{chunk-YRPC6MJY.js → chunk-FNLBTB4K.js} +1 -1
  42. package/dist/chunk-HIWJWWMT.js +668 -0
  43. package/dist/chunk-IUFM5JWV.js +24 -0
  44. package/dist/{chunk-T6Z5S6PQ.js → chunk-JNNJZURV.js} +1 -1
  45. package/dist/{chunk-6ZK6FZIV.js → chunk-KCBZSJRU.js} +6 -27
  46. package/dist/{chunk-5PNJMOY5.js → chunk-KDCHVT25.js} +1 -1
  47. package/dist/{chunk-BZAMASJP.js → chunk-KFRHRSCJ.js} +1 -1
  48. package/dist/chunk-LPVUNO2W.js +320 -0
  49. package/dist/{chunk-EWDSB24B.js → chunk-N7WARMC6.js} +16 -776
  50. package/dist/chunk-PB3CXNVL.js +41 -0
  51. package/dist/chunk-Q6QZTTLS.js +55 -0
  52. package/dist/{chunk-36EG34YI.js → chunk-QS527AV5.js} +1 -1
  53. package/dist/chunk-R776HKPK.js +81 -0
  54. package/dist/{chunk-KJ4HGRHN.js → chunk-RZIBSCYC.js} +507 -596
  55. package/dist/chunk-SD3OFRWY.js +714 -0
  56. package/dist/{chunk-ZFS67WIR.js → chunk-SIPKWSXK.js} +57 -6
  57. package/dist/chunk-TCS76X5D.js +441 -0
  58. package/dist/{chunk-K2NCQJKH.js → chunk-TDJCLNDH.js} +3 -3
  59. package/dist/{chunk-POBSY47Q.js → chunk-TUUDXEXU.js} +336 -302
  60. package/dist/{chunk-YNFERGKP.js → chunk-VPZFVJND.js} +1 -1
  61. package/dist/{chunk-UZQ4VY3M.js → chunk-YU5QUF67.js} +1 -1
  62. package/dist/chunk-ZBSMCXKV.js +710 -0
  63. package/dist/{chunk-3Q342EJJ.js → chunk-ZXNTJJIE.js} +2 -2
  64. package/dist/cli/chat.js +65 -26
  65. package/dist/cli/check.js +6 -6
  66. package/dist/cli/plugins.js +14 -12
  67. package/dist/cli/snapshot-create.js +10 -9
  68. package/dist/cli/upgrade.js +7 -7
  69. package/dist/conversation-work-KATFHLG3.js +56 -0
  70. package/dist/db/schema/agent-invocations.d.ts +544 -0
  71. package/dist/db/schema.d.ts +543 -1
  72. package/dist/{db-66E7VDNC.js → db-UO2IWXGA.js} +7 -7
  73. package/dist/experimental-HH6OM6UH.js +13 -0
  74. package/dist/instrumentation.js +4 -4
  75. package/dist/nitro.js +4 -3
  76. package/dist/{oauth-callback-server-7QPD4Q7P.js → oauth-callback-server-MAQI43LX.js} +26 -18
  77. package/dist/{runner-L2BKJKOD.js → runner-PIUQEXKE.js} +26 -14
  78. package/dist/{skills-HOQ2NSPW.js → skills-4ARJADHQ.js} +6 -6
  79. package/dist/spawn-G2AWPMCT.js +38 -0
  80. package/dist/{validation-ENHI7S2C.js → validation-S3EE3HWL.js} +6 -6
  81. package/dist/version.js +1 -1
  82. package/dist/work-UARRUAW3.js +46 -0
  83. package/dist/worker-DOCIRVD3.js +24 -0
  84. package/migrations/0021_first_warhawk.sql +35 -0
  85. package/migrations/meta/0021_snapshot.json +2176 -0
  86. package/migrations/meta/_journal.json +8 -1
  87. package/package.json +5 -5
@@ -1,38 +1,20 @@
1
+ import {
2
+ conversationQueueMessageSchema
3
+ } from "./chunk-IUFM5JWV.js";
1
4
  import {
2
5
  createVercelQueueClient
3
6
  } from "./chunk-5I6ORJUY.js";
4
7
 
5
8
  // src/chat/task-execution/queue-signing.ts
6
9
  import { createHmac, timingSafeEqual } from "crypto";
7
- import { z as z2 } from "zod";
8
-
9
- // src/chat/task-execution/queue.ts
10
10
  import { z } from "zod";
11
- var conversationQueueMessageSchema = z.object({
12
- conversationId: z.string().trim().min(1)
13
- }).strict();
14
- var ConversationQueueMessageRejectedError = class extends Error {
15
- conversationId;
16
- reason;
17
- constructor(reason, message, options = {}) {
18
- super(message);
19
- this.name = "ConversationQueueMessageRejectedError";
20
- this.reason = reason;
21
- this.conversationId = options.conversationId;
22
- }
23
- };
24
- function isConversationQueueMessageRejectedError(error) {
25
- return error instanceof ConversationQueueMessageRejectedError;
26
- }
27
-
28
- // src/chat/task-execution/queue-signing.ts
29
11
  var CONVERSATION_WORK_QUEUE_SIGNATURE_CONTEXT = "junior.conversation_work_queue.v2";
30
12
  var CONVERSATION_WORK_QUEUE_SIGNATURE_VERSION = "v2";
31
13
  var CONVERSATION_WORK_QUEUE_SIGNATURE_MAX_SKEW_MS = 60 * 60 * 1e3;
32
14
  var signedConversationQueueMessageSchema = conversationQueueMessageSchema.extend({
33
- signature: z2.string().trim().min(1),
34
- signatureVersion: z2.literal(CONVERSATION_WORK_QUEUE_SIGNATURE_VERSION),
35
- signedAtMs: z2.number().finite()
15
+ signature: z.string().trim().min(1),
16
+ signatureVersion: z.literal(CONVERSATION_WORK_QUEUE_SIGNATURE_VERSION),
17
+ signedAtMs: z.number().finite()
36
18
  }).strict();
37
19
  function getConversationWorkQueueSecret() {
38
20
  return process.env.JUNIOR_SECRET?.trim() || void 0;
@@ -139,9 +121,6 @@ function getVercelConversationWorkQueue() {
139
121
  }
140
122
 
141
123
  export {
142
- conversationQueueMessageSchema,
143
- ConversationQueueMessageRejectedError,
144
- isConversationQueueMessageRejectedError,
145
124
  verifyConversationQueueMessage,
146
125
  resolveConversationWorkQueueTopic,
147
126
  getVercelConversationWorkQueue
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  JUNIOR_VERSION
3
- } from "./chunk-XZ7NPXAB.js";
3
+ } from "./chunk-C7ZVPO4Z.js";
4
4
 
5
5
  // src/deployment.ts
6
6
  var JUNIOR_HEARTBEAT_ROUTE = "/api/internal/heartbeat";
@@ -5,7 +5,7 @@ import {
5
5
  logInfo,
6
6
  logWarn,
7
7
  setSpanAttributes
8
- } from "./chunk-T6Z5S6PQ.js";
8
+ } from "./chunk-JNNJZURV.js";
9
9
  import {
10
10
  discoverInstalledPluginPackageContent,
11
11
  normalizePluginPackageNames
@@ -0,0 +1,320 @@
1
+ import {
2
+ authorizationId
3
+ } from "./chunk-DIB4GX3G.js";
4
+ import {
5
+ formatProviderLabel,
6
+ startOAuthFlow
7
+ } from "./chunk-SD3OFRWY.js";
8
+ import {
9
+ abandonReplacedPendingAuth,
10
+ canReusePendingAuthLink,
11
+ recordAuthorizationRequested
12
+ } from "./chunk-TUUDXEXU.js";
13
+ import {
14
+ parseSandboxEgressAuthRequiredSignal
15
+ } from "./chunk-EPBBYMNE.js";
16
+ import {
17
+ AGENT_INVOCATION_MAILBOX_STATUSES
18
+ } from "./chunk-DCLLQGS6.js";
19
+ import {
20
+ TURN_REASONING_LEVELS
21
+ } from "./chunk-BYW4B4PR.js";
22
+ import {
23
+ pluginCatalogRuntime
24
+ } from "./chunk-QS527AV5.js";
25
+ import {
26
+ credentialContextSchema
27
+ } from "./chunk-77VDLF3Z.js";
28
+
29
+ // src/chat/services/auth-pause.ts
30
+ var AuthorizationPauseError = class extends Error {
31
+ disposition;
32
+ kind;
33
+ provider;
34
+ providerDisplayName;
35
+ requestText;
36
+ constructor(kind, provider, providerDisplayName, disposition, requestText) {
37
+ super(
38
+ kind === "mcp" ? `MCP authorization started for ${provider}` : `Plugin authorization started for ${provider}`
39
+ );
40
+ this.name = kind === "mcp" ? "McpAuthorizationPauseError" : "PluginAuthorizationPauseError";
41
+ this.disposition = disposition;
42
+ this.kind = kind;
43
+ this.provider = provider;
44
+ this.providerDisplayName = providerDisplayName;
45
+ this.requestText = requestText;
46
+ }
47
+ };
48
+ var AuthPausePersistenceError = class extends Error {
49
+ constructor(conversationId, turnId, cause) {
50
+ super(
51
+ `Failed to persist auth pause for conversation=${conversationId} turn=${turnId}`,
52
+ cause === void 0 ? void 0 : { cause }
53
+ );
54
+ this.name = "AuthPausePersistenceError";
55
+ }
56
+ };
57
+ var AuthorizationFlowDisabledError = class extends Error {
58
+ kind;
59
+ provider;
60
+ constructor(kind, provider) {
61
+ super(
62
+ `Authorization is required for ${provider}, but this turn cannot start an authorization flow.`
63
+ );
64
+ this.name = "AuthorizationFlowDisabledError";
65
+ this.kind = kind;
66
+ this.provider = provider;
67
+ }
68
+ };
69
+
70
+ // src/chat/services/plugin-auth-orchestration.ts
71
+ var PluginAuthorizationPauseError = class extends AuthorizationPauseError {
72
+ constructor(provider, providerDisplayName, disposition, requestText) {
73
+ super("plugin", provider, providerDisplayName, disposition, requestText);
74
+ }
75
+ };
76
+ var PluginCredentialFailureError = class extends Error {
77
+ provider;
78
+ constructor(provider, message) {
79
+ super(message);
80
+ this.name = "PluginCredentialFailureError";
81
+ this.provider = provider;
82
+ }
83
+ };
84
+ function pluginAuthRequiredSignal(details) {
85
+ if (!details || typeof details !== "object") {
86
+ return void 0;
87
+ }
88
+ const signal = details.auth_required;
89
+ const parsedSignal = parseSandboxEgressAuthRequiredSignal(signal);
90
+ if (!parsedSignal) {
91
+ return void 0;
92
+ }
93
+ return {
94
+ provider: parsedSignal.provider,
95
+ grant: parsedSignal.grant,
96
+ kind: parsedSignal.kind,
97
+ ...parsedSignal.message ? { message: parsedSignal.message } : {},
98
+ ...parsedSignal.authorization ? { authorization: parsedSignal.authorization } : {}
99
+ };
100
+ }
101
+ function createPluginAuthOrchestration(input) {
102
+ let pendingPause;
103
+ const startAuthorizationPause = async (provider, options) => {
104
+ if (pendingPause) {
105
+ throw pendingPause;
106
+ }
107
+ if (!input.actorId || !pluginCatalogRuntime.getOAuthConfig(provider)) {
108
+ throw new Error(`Cannot start plugin authorization for ${provider}`);
109
+ }
110
+ if (input.interactiveAuthEnabled === false) {
111
+ throw new AuthorizationFlowDisabledError("plugin", provider);
112
+ }
113
+ const recordPendingAuth = input.sessionId ? input.recordPendingAuth : void 0;
114
+ if (input.sessionId && !recordPendingAuth) {
115
+ throw new Error(
116
+ `Missing pending auth recorder for plugin authorization pause "${provider}"`
117
+ );
118
+ }
119
+ const providerLabel = formatProviderLabel(provider);
120
+ const reusingPendingLink = input.sessionId ? canReusePendingAuthLink({
121
+ pendingAuth: input.pendingAuth,
122
+ kind: "plugin",
123
+ provider,
124
+ actorId: input.actorId,
125
+ sessionId: input.sessionId,
126
+ ...options?.scope ? { scope: options.scope } : {}
127
+ }) : false;
128
+ if (!reusingPendingLink) {
129
+ const oauthResult = await startOAuthFlow(provider, {
130
+ actorId: input.actorId,
131
+ channelId: input.channelId,
132
+ destination: input.destination,
133
+ source: input.source,
134
+ threadTs: input.threadTs,
135
+ ...options?.scope ? { scope: options.scope } : {},
136
+ resumeConversationId: input.conversationId,
137
+ resumeSessionId: input.sessionId,
138
+ authorization: input.authorization
139
+ });
140
+ if (!oauthResult.ok) {
141
+ throw new Error(oauthResult.error);
142
+ }
143
+ if (!oauthResult.delivery) {
144
+ throw new Error(
145
+ `I need to connect your ${providerLabel} account first, but I wasn't able to send you a private authorization link. Please send me a direct message and try again.`
146
+ );
147
+ }
148
+ }
149
+ if (input.sessionId && recordPendingAuth) {
150
+ const nextPendingAuth = {
151
+ kind: "plugin",
152
+ provider,
153
+ actorId: input.actorId,
154
+ ...options?.scope ? { scope: options.scope } : {},
155
+ sessionId: input.sessionId,
156
+ linkSentAtMs: reusingPendingLink ? input.pendingAuth.linkSentAtMs : Date.now()
157
+ };
158
+ await recordPendingAuth(nextPendingAuth);
159
+ await abandonReplacedPendingAuth({
160
+ conversationId: input.conversationId,
161
+ previousPendingAuth: input.pendingAuth,
162
+ nextPendingAuth
163
+ });
164
+ }
165
+ if (input.conversationId && input.sessionId) {
166
+ await recordAuthorizationRequested({
167
+ conversationId: input.conversationId,
168
+ kind: "plugin",
169
+ provider,
170
+ actorId: input.actorId,
171
+ authorizationId: authorizationId({
172
+ kind: "plugin",
173
+ provider,
174
+ sessionId: input.sessionId
175
+ }),
176
+ delivery: reusingPendingLink ? "private_link_reused" : "private_link_sent"
177
+ });
178
+ }
179
+ pendingPause = new PluginAuthorizationPauseError(
180
+ provider,
181
+ providerLabel,
182
+ reusingPendingLink ? "link_already_sent" : "link_sent",
183
+ input.userMessage
184
+ );
185
+ input.abortAgent();
186
+ throw pendingPause;
187
+ };
188
+ return {
189
+ maybeHandleAuthSignal: async (details) => {
190
+ const signal = pluginAuthRequiredSignal(details);
191
+ if (!signal) {
192
+ return;
193
+ }
194
+ const { provider, authorization } = signal;
195
+ if (signal.kind === "unavailable") {
196
+ throw new PluginCredentialFailureError(
197
+ provider,
198
+ signal.message ?? `${formatProviderLabel(provider)} credentials are unavailable.`
199
+ );
200
+ }
201
+ if (!authorization) {
202
+ throw new PluginCredentialFailureError(
203
+ provider,
204
+ signal.message ?? `${formatProviderLabel(provider)} credentials are required but no OAuth flow is available for this provider.`
205
+ );
206
+ }
207
+ if (!input.actorId || !input.userTokenStore) {
208
+ if (input.interactiveAuthEnabled === false) {
209
+ throw new AuthorizationFlowDisabledError("plugin", provider);
210
+ }
211
+ throw new PluginCredentialFailureError(
212
+ provider,
213
+ signal.message ?? `${formatProviderLabel(provider)} credentials are required. Please connect your ${formatProviderLabel(provider)} account and try again.`
214
+ );
215
+ }
216
+ if (!pluginCatalogRuntime.getOAuthConfig(authorization.provider)) {
217
+ throw new PluginCredentialFailureError(
218
+ provider,
219
+ signal.message ?? `${formatProviderLabel(provider)} credentials are required but the provider is not configured for OAuth.`
220
+ );
221
+ }
222
+ await startAuthorizationPause(
223
+ authorization.provider,
224
+ authorization.scope ? { scope: authorization.scope } : void 0
225
+ );
226
+ },
227
+ getPendingPause: () => pendingPause
228
+ };
229
+ }
230
+
231
+ // src/chat/agent-invocations/errors.ts
232
+ var AgentInvocationBusyError = class extends Error {
233
+ constructor(name) {
234
+ super(`Named agent "${name}" already has active work`);
235
+ this.name = "AgentInvocationBusyError";
236
+ }
237
+ };
238
+ var AgentInvocationLimitError = class extends Error {
239
+ constructor(limit) {
240
+ super(
241
+ `Parent already has ${limit} active child agent invocations (limit ${limit})`
242
+ );
243
+ this.name = "AgentInvocationLimitError";
244
+ }
245
+ };
246
+
247
+ // src/chat/agent-invocations/types.ts
248
+ import {
249
+ actorSchema,
250
+ destinationSchema,
251
+ sourceSchema
252
+ } from "@sentry/junior-plugin-api";
253
+ import { z } from "zod";
254
+ var exactStringSchema = z.string().min(1).refine((value) => value === value.trim());
255
+ var agentNameSchema = exactStringSchema.max(64);
256
+ var agentInvocationMailboxStatusSchema = z.enum(
257
+ AGENT_INVOCATION_MAILBOX_STATUSES
258
+ );
259
+ var agentBindingSchema = z.object({
260
+ childConversationId: exactStringSchema,
261
+ name: agentNameSchema,
262
+ parentConversationId: exactStringSchema
263
+ }).strict();
264
+ var agentInvocationBaseSchema = z.object({
265
+ actor: actorSchema,
266
+ agentName: agentNameSchema.optional(),
267
+ childConversationId: exactStringSchema,
268
+ createdAtMs: z.number().finite(),
269
+ credentialContext: credentialContextSchema.optional(),
270
+ destination: destinationSchema,
271
+ destinationVisibility: z.enum(["public", "private"]).optional(),
272
+ input: exactStringSchema,
273
+ invocationId: exactStringSchema,
274
+ mailboxStatus: agentInvocationMailboxStatusSchema,
275
+ parentConversationId: exactStringSchema,
276
+ reasoningLevel: z.enum(TURN_REASONING_LEVELS).optional(),
277
+ source: sourceSchema,
278
+ updatedAtMs: z.number().finite()
279
+ }).strict();
280
+ var agentInvocationSchema = z.discriminatedUnion("status", [
281
+ agentInvocationBaseSchema.extend({
282
+ status: z.enum(["pending", "running", "awaiting_resume"])
283
+ }),
284
+ agentInvocationBaseSchema.extend({
285
+ result: z.string(),
286
+ status: z.literal("completed"),
287
+ terminalAtMs: z.number().finite()
288
+ }),
289
+ agentInvocationBaseSchema.extend({
290
+ errorMessage: z.string(),
291
+ status: z.enum(["blocked", "failed"]),
292
+ terminalAtMs: z.number().finite()
293
+ })
294
+ ]);
295
+ var createAgentInvocationSchema = z.object({
296
+ actor: actorSchema,
297
+ agentName: agentNameSchema.optional(),
298
+ credentialContext: credentialContextSchema.optional(),
299
+ destination: destinationSchema,
300
+ destinationVisibility: z.enum(["public", "private"]).optional(),
301
+ idempotencyKey: exactStringSchema,
302
+ input: exactStringSchema,
303
+ parentConversationId: exactStringSchema,
304
+ reasoningLevel: z.enum(TURN_REASONING_LEVELS).optional(),
305
+ source: sourceSchema
306
+ }).strict();
307
+
308
+ export {
309
+ AuthorizationPauseError,
310
+ AuthPausePersistenceError,
311
+ AuthorizationFlowDisabledError,
312
+ AgentInvocationBusyError,
313
+ AgentInvocationLimitError,
314
+ agentNameSchema,
315
+ agentBindingSchema,
316
+ agentInvocationSchema,
317
+ createAgentInvocationSchema,
318
+ PluginCredentialFailureError,
319
+ createPluginAuthOrchestration
320
+ };