@sentry/junior 0.265.0 → 0.267.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 (76) hide show
  1. package/dist/{actor-tlxzqaRe.js → actor-DZSokpwj.js} +8 -1
  2. package/dist/{adapter-cUkPH3Om.js → adapter-BybMEezj.js} +2 -2
  3. package/dist/{admin-Cf0rDmWV.js → admin-DOs1_EiW.js} +1 -1
  4. package/dist/{agent-runner-C6MwHJEs.js → agent-runner-DgNATN4D.js} +874 -228
  5. package/dist/api/schema.d.ts +202 -23
  6. package/dist/api/schema.js +6 -5
  7. package/dist/api.d.ts +6 -1
  8. package/dist/api.js +130 -1205
  9. package/dist/{app-Csbi9dW7.d.ts → app-DAB3fzyp.d.ts} +21 -3
  10. package/dist/app.d.ts +2 -2
  11. package/dist/app.js +1611 -353
  12. package/dist/{assistant-reply-UPA8vKlC.js → assistant-reply-CT7VcXQe.js} +1 -1
  13. package/dist/{automation-2RbKzpMT.js → automation-CmeFBSEh.js} +42 -14
  14. package/dist/{briefs-DRjx8kQ9.js → briefs-CWKjka7v.js} +5 -5
  15. package/dist/{catalog-runtime-D3qbJlYz.js → catalog-runtime-cMlAI5LY.js} +1 -1
  16. package/dist/cli/chat.js +15 -15
  17. package/dist/cli/check.js +3 -3
  18. package/dist/cli/init.js +0 -1
  19. package/dist/cli/main.js +3 -3
  20. package/dist/cli/plugins.js +4 -4
  21. package/dist/cli/snapshot-create.js +4 -4
  22. package/dist/cli/upgrade.d.ts +1 -1
  23. package/dist/cli/upgrade.js +3 -3
  24. package/dist/{client-DX34VNtH.js → client-BjgbMawj.js} +2 -2
  25. package/dist/{config-BayQ9hHH.js → config-CdB6yJj5.js} +32 -10
  26. package/dist/{connections-mpN5Lsnj.js → connections-RE_65jzK.js} +13 -12
  27. package/dist/{conversation-B0baEwoA.js → conversation-DSo310Ps.js} +14 -3
  28. package/dist/{conversation-privacy-frjQCJa9.js → conversation-privacy-BzgJC5k0.js} +1 -1
  29. package/dist/{credential-sync-CZmyDNdR.js → credential-sync-DhEGEpgq.js} +15 -15
  30. package/dist/{credentialed-C6pKlB1p.js → credentialed-CIGwoLU2.js} +2913 -1026
  31. package/dist/{db-BnRqQ7G5.d.ts → db-Bg-zC3r5.d.ts} +1 -1
  32. package/dist/{executor-CAr7xQr2.js → executor-VYrx_K4w.js} +7 -4
  33. package/dist/{history-AY8rs-FR.js → history-C84mlAwO.js} +2 -1
  34. package/dist/{images-B2yA3HWE.js → images-CecjXAAz.js} +3 -3
  35. package/dist/instrumentation.js +6 -2
  36. package/dist/{job-queue-Cjo6Yg_b.js → job-queue-C0BZSa7r.js} +128 -3
  37. package/dist/{web-input-Y6aXvmfa.js → list-1XQP-o6K.js} +1374 -71
  38. package/dist/{logging-D2QBriUo.js → logging-DuZ1A4ab.js} +11 -3
  39. package/dist/{message-C9ymnpBS.js → message-NKSbbnA6.js} +4 -4
  40. package/dist/nitro.d.ts +1 -1
  41. package/dist/nitro.js +3 -3
  42. package/dist/{oauth-callback-server-BtMf3TPZ.js → oauth-callback-server-qAHLPtml.js} +2 -2
  43. package/dist/{prompt-CvaDdSX3.js → prompt-BW9jFsqZ.js} +1 -1
  44. package/dist/{registry-COTeZ2cV.js → registry-FQutO926.js} +2 -2
  45. package/dist/{resolve-g9PKz9pH.js → resolve-Bk4yeuHy.js} +3 -3
  46. package/dist/{result-COnC42GR.js → result-B9e9ATOU.js} +9 -9
  47. package/dist/{runner-BnTNS7x_.js → runner-C3S2ObH-.js} +11 -11
  48. package/dist/{sandbox-egress-signals-C_IIdLFk.js → sandbox-egress-signals-DqpGzzMB.js} +1 -1
  49. package/dist/{schema-D5Amlzkp.js → schema-X7Fj4fv1.js} +3 -2
  50. package/dist/{service-account-CwvToidT.js → service-account-BQasl-qq.js} +3 -3
  51. package/dist/{service-account-YdYftwV2.js → service-account-Do30HUNv.js} +3 -3
  52. package/dist/{session-stop-CpCUy1ZJ.js → session-stop-DkOjt46_.js} +45 -128
  53. package/dist/{skills-Bb2KaJ3m.js → skills-CQHrwfOa.js} +2 -2
  54. package/dist/{spawn-mbTcrLb3.js → spawn-BHuqN14f.js} +2 -2
  55. package/dist/{store-CqRnaZSq.js → store-6EetVP-m.js} +3 -3
  56. package/dist/{store-CG0VJyye.d.ts → store-B8CABbmR.d.ts} +10 -2
  57. package/dist/store-DvNZIsCr.js +295 -0
  58. package/dist/{task-queue-8XjDIORF.js → task-queue-B0DLgd2P.js} +10 -5
  59. package/dist/{task-runner-6mLmG6g_.js → task-runner-B-PD_JOj.js} +26 -14
  60. package/dist/{tasks-DGbrur6x.js → tasks-0ilmuCux.js} +1440 -46
  61. package/dist/{thread-state-D45lz-oC.js → thread-state-DRmdJ2QN.js} +5 -5
  62. package/dist/{turn-failure-response-CaEPLSBn.js → turn-failure-response-G11cs2gE.js} +9 -9
  63. package/dist/{turn-lifecycle-C35IyRGp.js → turn-lifecycle-OzLIwvi1.js} +2 -2
  64. package/dist/{turn-session-routing-BKx6rfVd.js → turn-session-routing-Dyut9l7Y.js} +1 -1
  65. package/dist/user-input-request-BDFBdF8r.js +116 -0
  66. package/dist/{validation-C0X3CX51.js → validation-CxEmt1id.js} +1 -1
  67. package/dist/{version-BPHgJwnm.js → version-Bapedn4A.js} +1 -1
  68. package/dist/version.js +1 -1
  69. package/dist/{viewer-B2wXNspU.js → viewer-DrN3oC2X.js} +22 -11
  70. package/dist/{work-DMbqK0kT.js → work-DUQoNcqP.js} +52 -51
  71. package/dist/{worker-B-rDJ3XN.js → worker-D1l4Ugk0.js} +30 -19
  72. package/migrations/0064_any_resource_event_triggers.sql +2 -0
  73. package/migrations/meta/0064_snapshot.json +3505 -0
  74. package/migrations/meta/_journal.json +7 -0
  75. package/package.json +20 -5
  76. package/dist/store-DdT74Lvq.js +0 -1424
@@ -1,4 +1,4 @@
1
- import "./store-CG0VJyye.js";
1
+ import "./store-B8CABbmR.js";
2
2
  import { z } from "zod";
3
3
  import "drizzle-orm/pg-core";
4
4
  import "drizzle-orm/migrator";
@@ -1,5 +1,5 @@
1
- import "./config-BayQ9hHH.js";
2
- import { f as logException } from "./logging-D2QBriUo.js";
1
+ import "./config-CdB6yJj5.js";
2
+ import { p as logException } from "./logging-DuZ1A4ab.js";
3
3
  import { a as juniorAgentInvocations, c as juniorIdentities, d as juniorDestinations, f as timestamptz, i as juniorAgentBindings, l as juniorUsers, s as juniorConversations } from "./agent-invocations-CxKldAeB.js";
4
4
  import { AsyncLocalStorage } from "node:async_hooks";
5
5
  import { sql } from "drizzle-orm";
@@ -292,7 +292,10 @@ const juniorStats = pgTable("junior_stats", {
292
292
  * One row per Automation of either kind. `record` holds the fields that have
293
293
  * no column. Each write also copies the nested fields that queries filter or
294
294
  * search on into columns: `team_id`, `channel_id`, `creator_slack_user_id`,
295
- * `instruction`, and the event trigger `namespace` and `identifier`.
295
+ * `instruction`, and the event trigger `namespace` and `identifier`. An event
296
+ * trigger with no identifier runs for every resource of its namespace, so its
297
+ * `identifier` is null. The match index finds those rows with
298
+ * `identifier is null`.
296
299
  */
297
300
  const juniorAutomations = pgTable("junior_automations", {
298
301
  id: text("id").primaryKey(),
@@ -317,7 +320,7 @@ const juniorAutomations = pgTable("junior_automations", {
317
320
  check("junior_automations_kind_check", sql`${table.kind} in ('scheduled', 'event')`),
318
321
  check("junior_automations_status_check", sql`${table.status} in ('active', 'blocked', 'paused', 'completed', 'deleted')`),
319
322
  check("junior_automations_record_check", sql`jsonb_typeof(${table.record}) = 'object'`),
320
- check("junior_automations_trigger_check", sql`(${table.kind} = 'scheduled' and ${table.namespace} is null and ${table.identifier} is null) or (${table.kind} = 'event' and ${table.namespace} is not null and ${table.identifier} is not null and ${table.nextRunAtMs} is null and ${table.runNowAtMs} is null and ${table.status} <> 'completed')`),
323
+ check("junior_automations_trigger_check", sql`(${table.kind} = 'scheduled' and ${table.namespace} is null and ${table.identifier} is null) or (${table.kind} = 'event' and ${table.namespace} is not null and ${table.nextRunAtMs} is null and ${table.runNowAtMs} is null and ${table.status} <> 'completed')`),
321
324
  index("junior_automations_team_idx").on(table.teamId, table.createdAtMs, table.id).where(sql`${table.status} <> 'deleted'`),
322
325
  index("junior_automations_creator_identity_idx").on(table.creatorIdentityId, table.createdAtMs, table.id),
323
326
  index("junior_automations_run_now_due_idx").on(table.runNowAtMs, table.createdAtMs, table.id).where(sql`${table.status} = 'active' AND ${table.runNowAtMs} IS NOT NULL`),
@@ -366,7 +366,8 @@ const turnCompletedEventDataSchema = z.object({
366
366
  outcome: z.enum([
367
367
  "success",
368
368
  "no_reply",
369
- "cancelled"
369
+ "cancelled",
370
+ "blocked"
370
371
  ])
371
372
  }).strict();
372
373
  const turnFailedEventDataSchema = z.object({
@@ -1,7 +1,7 @@
1
1
  import { t as __exportAll } from "./rolldown-runtime-nwUcYXjP.js";
2
- import { p as getSqlExecutor } from "./viewer-B2wXNspU.js";
3
- import { S as readLiveAttachment, w as storeAttachment } from "./agent-runner-C6MwHJEs.js";
4
- import { H as detectImageMediaType } from "./conversation-B0baEwoA.js";
2
+ import { m as getSqlExecutor } from "./viewer-DrN3oC2X.js";
3
+ import { S as readLiveAttachment, w as storeAttachment } from "./agent-runner-DgNATN4D.js";
4
+ import { K as detectImageMediaType } from "./conversation-DSo310Ps.js";
5
5
  // src/chat/attachments/images.ts
6
6
  var images_exports = /* @__PURE__ */ __exportAll({
7
7
  decodeInputImages: () => decodeInputImages,
@@ -1,6 +1,6 @@
1
- import { F as getDeploymentTelemetryAttributes, P as getDeploymentServiceVersion } from "./logging-D2QBriUo.js";
1
+ import { F as getDeploymentServiceVersion, I as getDeploymentTelemetryAttributes } from "./logging-DuZ1A4ab.js";
2
2
  import { a as getClient, c as init, o as getGlobalScope } from "./sentry-MDkYAVPV.js";
3
- import { n as getCurrentConversationPrivacy } from "./conversation-privacy-frjQCJa9.js";
3
+ import { n as getCurrentConversationPrivacy } from "./conversation-privacy-BzgJC5k0.js";
4
4
  import { t as consumePrivateTraceResultMarker } from "./private-trace-result-CE7_lEdq.js";
5
5
  // src/chat/sentry-payload-filter.ts
6
6
  const PAYLOAD_ATTRIBUTE_KEYS = /* @__PURE__ */ new Set([
@@ -164,6 +164,10 @@ function initSentry() {
164
164
  environment: process.env.SENTRY_ENVIRONMENT ?? process.env.VERCEL_ENV ?? process.env.NODE_ENV,
165
165
  release: serviceVersion,
166
166
  tracesSampleRate: getSampleRate(process.env.SENTRY_TRACES_SAMPLE_RATE, 1),
167
+ ignoreSpans: [{
168
+ op: "http.server",
169
+ attributes: { "url.path": "/_vercel/ping" }
170
+ }],
167
171
  dataCollection: {
168
172
  httpBodies: ["incomingRequest"],
169
173
  databaseQueryData: false
@@ -1,5 +1,5 @@
1
- import { i as getChatConfig } from "./config-BayQ9hHH.js";
2
- import { T as withSpan } from "./logging-D2QBriUo.js";
1
+ import { i as getChatConfig } from "./config-CdB6yJj5.js";
2
+ import { E as withSpan, m as logInfo, p as logException } from "./logging-DuZ1A4ab.js";
3
3
  import { AsyncLocalStorage } from "node:async_hooks";
4
4
  import { z } from "zod";
5
5
  import { createHash, createHmac, timingSafeEqual } from "node:crypto";
@@ -40,6 +40,131 @@ function runWithTurnRequestDeadline(callback, startedAtMs = Date.now()) {
40
40
  if (requestDeadlineStorage.getStore()) return callback();
41
41
  return requestDeadlineStorage.run(createTurnRequestDeadline(startedAtMs), callback);
42
42
  }
43
+ // src/chat/queue/bullmq.ts
44
+ const MAX_ATTEMPTS = 50;
45
+ const MAX_BACKOFF_MS = 3e4;
46
+ const COMPLETED_JOB_AGE_SECONDS = 3600;
47
+ const FAILED_JOB_AGE_SECONDS = 86400;
48
+ /**
49
+ * Import a module by a name held in a variable.
50
+ *
51
+ * Bundlers follow a literal `import("bullmq")` and put BullMQ into the
52
+ * production server, even though production never selects this provider.
53
+ * Node resolves this import when the app runs instead.
54
+ */
55
+ function importAtRuntime(specifier) {
56
+ return import(
57
+ /* @vite-ignore */
58
+ specifier
59
+ );
60
+ }
61
+ function bullmqConfig() {
62
+ const config = getChatConfig().queue;
63
+ if (config.provider !== "bullmq") throw new Error("The BullMQ queue provider is not configured");
64
+ return config;
65
+ }
66
+ /** Load BullMQ and open a Redis client that the caller must close. */
67
+ async function connect() {
68
+ const [bullmq, redis] = await Promise.all([importAtRuntime("bullmq"), importAtRuntime("redis")]).catch((error) => {
69
+ throw new Error("JUNIOR_QUEUE_PROVIDER=bullmq needs the bullmq and redis packages installed", { cause: error });
70
+ });
71
+ const client = redis.createClient({ url: bullmqConfig().redisUrl });
72
+ try {
73
+ await client.connect();
74
+ return {
75
+ bullmq,
76
+ connection: bullmq.createNodeRedisClient(client)
77
+ };
78
+ } catch (error) {
79
+ client.destroy();
80
+ throw error;
81
+ }
82
+ }
83
+ /** BullMQ job ids must not contain ":", and Junior's keys do. */
84
+ function toJobId(idempotencyKey) {
85
+ return `k-${createHash("sha256").update(idempotencyKey).digest("base64url")}`;
86
+ }
87
+ function metadataFor(job, consumer) {
88
+ return {
89
+ consumerGroup: consumer.consumerGroup,
90
+ createdAt: new Date(job.timestamp),
91
+ deliveryCount: job.attemptsMade + 1,
92
+ messageId: job.id ?? "",
93
+ topicName: consumer.topic
94
+ };
95
+ }
96
+ async function processJob(job, consumer) {
97
+ const { payload, retentionSeconds } = job.data;
98
+ if (retentionSeconds !== void 0 && Date.now() - job.timestamp > retentionSeconds * 1e3) return;
99
+ const metadata = metadataFor(job, consumer);
100
+ try {
101
+ await consumer.handler(payload, metadata);
102
+ } catch (error) {
103
+ if (consumer.retry(error, metadata)?.acknowledge) return;
104
+ throw error;
105
+ }
106
+ }
107
+ /** Start one BullMQ worker for each consumer, on a Redis client it owns. */
108
+ async function startWorker(consumers) {
109
+ const { bullmq, connection } = await connect();
110
+ const concurrency = bullmqConfig().workerConcurrency;
111
+ const workers = consumers.map((consumer) => {
112
+ const worker = new bullmq.Worker(consumer.topic, (job) => processJob(job, consumer), {
113
+ concurrency,
114
+ connection,
115
+ ...consumer.visibilityTimeoutSeconds !== void 0 && { lockDuration: consumer.visibilityTimeoutSeconds * 1e3 },
116
+ settings: { backoffStrategy: (attemptsMade) => Math.min(1e3 * 2 ** (attemptsMade - 1), MAX_BACKOFF_MS) }
117
+ });
118
+ worker.on("error", (error) => {
119
+ logException(error, "queue.bullmq.worker.exception", { "messaging.destination.name": consumer.topic });
120
+ });
121
+ return worker;
122
+ });
123
+ logInfo("queue.bullmq.worker.started", {
124
+ "app.queue.worker_concurrency": concurrency,
125
+ "messaging.destination.names": consumers.map((consumer) => consumer.topic)
126
+ });
127
+ return { close: async () => {
128
+ try {
129
+ const failures = (await Promise.allSettled(workers.map((worker) => worker.close()))).flatMap((result) => result.status === "rejected" ? [result.reason] : []);
130
+ if (failures.length > 0) throw new AggregateError(failures, "BullMQ workers did not close");
131
+ } finally {
132
+ await connection.quit();
133
+ }
134
+ } };
135
+ }
136
+ /** Add one job on a Redis client that is open only for this send. */
137
+ async function send$1(topic, payload, options = {}) {
138
+ const { bullmq, connection } = await connect();
139
+ const queue = new bullmq.Queue(topic, { connection });
140
+ try {
141
+ const job = await queue.add(topic, {
142
+ payload,
143
+ retentionSeconds: options.retentionSeconds
144
+ }, {
145
+ attempts: MAX_ATTEMPTS,
146
+ backoff: { type: "custom" },
147
+ delay: options.delaySeconds ? options.delaySeconds * 1e3 : void 0,
148
+ jobId: options.idempotencyKey ? toJobId(options.idempotencyKey) : void 0,
149
+ removeOnComplete: { age: COMPLETED_JOB_AGE_SECONDS },
150
+ removeOnFail: { age: FAILED_JOB_AGE_SECONDS }
151
+ });
152
+ return job.id ? { messageId: job.id } : {};
153
+ } finally {
154
+ try {
155
+ await queue.close();
156
+ } finally {
157
+ await connection.quit();
158
+ }
159
+ }
160
+ }
161
+ /** Queue provider backed by BullMQ, for local development only. */
162
+ const bullmqQueueProvider = {
163
+ messagingSystem: "bullmq",
164
+ send: send$1,
165
+ createCallback: () => async () => new Response("This queue provider does not push messages", { status: 404 }),
166
+ startWorker
167
+ };
43
168
  // src/chat/queue/vercel.ts
44
169
  function defaultQueueClientOptions() {
45
170
  if (process.env.VERCEL_DEPLOYMENT_ID?.trim()) return {};
@@ -76,7 +201,7 @@ const vercelQueueProvider = {
76
201
  // src/chat/queue/provider.ts
77
202
  /** Return the queue provider for this deployment. */
78
203
  function getQueueProvider() {
79
- return vercelQueueProvider;
204
+ return getChatConfig().queue.provider === "bullmq" ? bullmqQueueProvider : vercelQueueProvider;
80
205
  }
81
206
  // src/chat/queue/sign.ts
82
207
  /** Sign and check queue messages before public callbacks run them. */