@sentry/junior 0.306.0 → 0.307.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{adapter-context-CnY-i32r.js → adapter-context-B69WPn6b.js} +2 -2
- package/dist/{admin-BLLdLnXh.js → admin-nCJXMgkp.js} +2 -2
- package/dist/{agent-runner-BaLjEjPR.js → agent-runner-DdFcxAxG.js} +226 -137
- package/dist/api/schema.d.ts +2 -2
- package/dist/api/schema.js +4 -4
- package/dist/api.d.ts +1 -1
- package/dist/api.js +328 -298
- package/dist/{app-DvYbM9UD.d.ts → app-EZur8cVC.d.ts} +12 -3
- package/dist/app.d.ts +2 -2
- package/dist/app.js +84 -44
- package/dist/background-compaction-queue-BhEe4UfU.js +231 -0
- package/dist/{briefs-DvyzXfrF.js → briefs-Dl9lxi7J.js} +2 -2
- package/dist/{catalog-runtime-B1R-nHd3.js → catalog-runtime-OXrv2Ewn.js} +1 -1
- package/dist/cli/chat.d.ts +1 -1
- package/dist/cli/chat.js +17 -16
- package/dist/cli/check.js +58 -48
- package/dist/cli/main.js +3 -3
- package/dist/cli/plugins.d.ts +1 -1
- package/dist/cli/plugins.js +4 -4
- package/dist/cli/snapshot-create.js +5 -5
- package/dist/cli/upgrade.d.ts +2 -2
- package/dist/cli/upgrade.js +3 -8
- package/dist/{config-DUD-zMvp.js → config-362yMSIz.js} +74 -38
- package/dist/{connections-CDhsqPcC.js → connections-BJv3EjmB.js} +10 -8
- package/dist/{continue-in-slack-BXQizz9o.js → continue-in-slack-CFEevC7z.js} +5 -5
- package/dist/{conversation-privacy-YE54gMN8.js → conversation-privacy-Tjj5P2W6.js} +1 -1
- package/dist/{conversation-turn-BzdmrHb0.js → conversation-turn-DU0_WDAr.js} +19 -47
- package/dist/{credential-sync-Cdm-e1vJ.js → credential-sync-D6aFARKE.js} +28 -28
- package/dist/{db-DV2ZUb1Y.js → db-Bcbd9zQc.js} +140 -11
- package/dist/{db-pH357Dkt.d.ts → db-C41UgdBj.d.ts} +1 -1
- package/dist/{executor-CjNhwwnj.js → executor-DBMBrpNV.js} +93 -32
- package/dist/{install-DbD7C5td.js → install-CgoAbzfF.js} +2 -2
- package/dist/instrumentation.js +2 -2
- package/dist/{lineage-BFdIPb3o.js → lineage-CsZDmz3e.js} +2 -2
- package/dist/{logging-oYpJYr-S.js → logging-CHCuQ5iz.js} +1 -1
- package/dist/{message-BBPcMKJY.js → message-B8vCbZZB.js} +8 -8
- package/dist/{model-input-DYYF3a8B.js → model-input-Xluiy-1W.js} +3 -3
- package/dist/nitro.d.ts +2 -2
- package/dist/nitro.js +3 -4
- package/dist/{oauth-callback-server-C7Q987su.js → oauth-callback-server-BUuNvfvu.js} +2 -2
- package/dist/{oauth-relay-DAmfVmJu.js → oauth-relay-DGAZzg9m.js} +1 -1
- package/dist/{plugins-B_0Cr0MO.d.ts → plugins-fBrz8PCV.d.ts} +2 -0
- package/dist/{projection-CWXDE0f6.js → projection-xPpvqexa.js} +1112 -693
- package/dist/{prompt-P3eRqO8C.js → prompt-D8u4jFs_.js} +3 -3
- package/dist/{registry-1pzXmplY.js → registry-D20hG3r6.js} +19 -9
- package/dist/{resolve-n87oXY-d.js → resolve-BhCySRCW.js} +3 -3
- package/dist/{result-BmF9v9bv.js → result-DddO63S9.js} +13 -11
- package/dist/{runner-4j7ZsxP5.js → runner-DQR9vYce.js} +9 -9
- package/dist/{sandbox-egress-signals-BRQI8HvT.js → sandbox-egress-signals-DFlNUOnK.js} +1 -1
- package/dist/{schedule-CHPWQn-x.js → schedule-BG1tEbRF.js} +34 -4
- package/dist/{schema-CVbIjrF3.d.ts → schema-CRXcj4fj.d.ts} +350 -143
- package/dist/{schema-D7iIEh6t.js → schema-D4jdesIu.js} +12 -4
- package/dist/{service-account-DzQiOmqa.js → service-account-Bv5QwrEq.js} +8 -6
- package/dist/{service-account-BDQ9xzta.js → service-account-CNfycv0z.js} +3 -3
- package/dist/{session-stop-BQxgHR4X.js → session-stop-BDdwyZaa.js} +36 -23
- package/dist/{skills-CPf4vNuC.js → skills-63i1Bcv1.js} +32 -28
- package/dist/{slack-conversation-unfurl-B1KEptUg.js → slack-conversation-unfurl-DtpBUlUu.js} +10 -10
- package/dist/{spawn-CjGddiAU.js → spawn-mwimEY9_.js} +6 -6
- package/dist/{state-9wfj6aSD.js → state-BBn9L6gC.js} +4 -4
- package/dist/{stop-CsQGuN5n.js → stop-Da-Ug7tg.js} +146 -158
- package/dist/{store-Dz3YZ7gQ.js → store-CdWg2r2L.js} +5 -5
- package/dist/{background-compaction-queue-D2wzxtGU.js → task-queue-BcjAYWyB.js} +164 -180
- package/dist/{task-runner-frzlUvFD.js → task-runner-CoXmMlsW.js} +11 -8
- package/dist/{thread-context-C4QuZlM8.js → thread-context-ZPGqOjW7.js} +6 -6
- package/dist/{turn-session-routing-BXaubz2w.js → turn-session-routing-DFYak28Q.js} +24 -5
- package/dist/{turn-user-message-DNC0eRZ7.js → turn-user-message-B1S8nOnG.js} +3 -3
- package/dist/{users-XCCKn3xW.js → users-DDbENg-I.js} +1 -1
- package/dist/{validation-L5fdjmFX.js → validation-fl21ps-k.js} +1 -1
- package/dist/{version-BFmuwgxP.js → version-DCdMMx_0.js} +1 -1
- package/dist/version.js +1 -1
- package/dist/{viewer-DKOeHpv3.js → viewer-DN_xzVKj.js} +3 -3
- package/dist/{warmup-mTMIatCV.js → warmup-CxhEhm71.js} +596 -281
- package/dist/{web-message-id-CUaSiGme.js → web-message-id-BT8Mg8LL.js} +1 -1
- package/dist/{worker-Bz4KNxjI.js → worker-Btb1SB5h.js} +8 -7
- package/migrations/0115_automation_creator_slack_index.sql +1 -0
- package/migrations/0116_conversation_event_search.sql +25 -0
- package/migrations/0117_automation_last_run.sql +46 -0
- package/migrations/0118_automation_last_run_index.sql +1 -0
- package/migrations/0119_money_micro_usd.sql +29 -0
- package/migrations/0120_conversation_cost_micro_usd.sql +8 -0
- package/migrations/meta/0115_snapshot.json +5225 -0
- package/migrations/meta/0116_snapshot.json +5388 -0
- package/migrations/meta/0117_snapshot.json +5413 -0
- package/migrations/meta/0118_snapshot.json +5428 -0
- package/migrations/meta/0119_snapshot.json +5441 -0
- package/migrations/meta/0120_snapshot.json +5441 -0
- package/migrations/meta/_journal.json +42 -0
- package/package.json +10 -9
- package/dist/queue-7FSijgqG.js +0 -115
- package/dist/secrets-DHaJ5TTn.js +0 -18
- package/dist/task-queue-CFlrJguF.js +0 -89
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { a as getConversationStore } from "./db-
|
|
2
|
-
import { p as logException } from "./logging-
|
|
3
|
-
import "./background-compaction-queue-
|
|
4
|
-
import { At as hasRunnableConversationWork, Bt as releaseInboundMessage, Dt as getConversationWorkState$1, Et as getConversation$1, Gt as stopConversationWork$1, Ht as requestConversationWork$1, Kt as takeDeferredConversationMove, Lt as recordAttemptFailure$1, Nt as listActiveConversationIds$1, Ot as getConversationWorkStates$1, Pt as markConversationWorkEnqueued$1, Rt as recordConversationRetry$1, St as deadLetterAttempt$1, Tt as dropPendingMessages$1, Ut as startConversationWork$1, Vt as requestAnotherSlice$1, Wt as steerWebPendingMessages$1, _t as clearConsumedConversationWake$1, bt as completeConversationWork$1, dt as appendExclusiveInboundMessage, ft as appendInboundMessage, gt as claimInboundMessage$1, ht as checkInConversationWork$1, mt as cancelHumanFacingPendingMessages$1, pt as beginConversationResume$1, ut as ackMessages$1, vt as clearExpiredConversationLease$1, wt as drainConversationMailbox$1, yt as completeConversationStop$1, zt as releaseConversationWork$1 } from "./projection-
|
|
1
|
+
import { a as getConversationStore } from "./db-Bcbd9zQc.js";
|
|
2
|
+
import { p as logException } from "./logging-CHCuQ5iz.js";
|
|
3
|
+
import "./background-compaction-queue-BhEe4UfU.js";
|
|
4
|
+
import { At as hasRunnableConversationWork, Bt as releaseInboundMessage, Dt as getConversationWorkState$1, Et as getConversation$1, Gt as stopConversationWork$1, Ht as requestConversationWork$1, Kt as takeDeferredConversationMove, Lt as recordAttemptFailure$1, Nt as listActiveConversationIds$1, Ot as getConversationWorkStates$1, Pt as markConversationWorkEnqueued$1, Rt as recordConversationRetry$1, St as deadLetterAttempt$1, Tt as dropPendingMessages$1, Ut as startConversationWork$1, Vt as requestAnotherSlice$1, Wt as steerWebPendingMessages$1, _t as clearConsumedConversationWake$1, bt as completeConversationWork$1, dt as appendExclusiveInboundMessage, ft as appendInboundMessage, gt as claimInboundMessage$1, ht as checkInConversationWork$1, mt as cancelHumanFacingPendingMessages$1, pt as beginConversationResume$1, ut as ackMessages$1, vt as clearExpiredConversationLease$1, wt as drainConversationMailbox$1, yt as completeConversationStop$1, zt as releaseConversationWork$1 } from "./projection-xPpvqexa.js";
|
|
5
5
|
// src/chat/task-execution/store.ts
|
|
6
6
|
function metadataStore(options) {
|
|
7
7
|
return options.conversationStore ?? getConversationStore();
|
|
@@ -304,7 +304,7 @@ async function runDeferredMove(args) {
|
|
|
304
304
|
const move = await takeDeferredConversationMove(args);
|
|
305
305
|
if (move === void 0) return;
|
|
306
306
|
try {
|
|
307
|
-
const { continueDeferredSlackClick } = await import("./slack-conversation-unfurl-
|
|
307
|
+
const { continueDeferredSlackClick } = await import("./slack-conversation-unfurl-DtpBUlUu.js").then((n) => n.r);
|
|
308
308
|
await continueDeferredSlackClick(move, args.getSlackAdapter);
|
|
309
309
|
} catch (error) {
|
|
310
310
|
logException(error, "slack.continue_here.deferred.failed", { "gen_ai.conversation.id": args.conversationId });
|
|
@@ -1,54 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { t as readJuniorSecret } from "./secrets-DHaJ5TTn.js";
|
|
1
|
+
import { h as logWarn, m as logInfo, p as logException } from "./logging-CHCuQ5iz.js";
|
|
2
|
+
import { i as getChatConfig } from "./config-362yMSIz.js";
|
|
4
3
|
import * as z from "zod";
|
|
5
4
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
6
5
|
import { createHash, createHmac, timingSafeEqual } from "node:crypto";
|
|
7
6
|
import { QueueClient, handleCallback, registerDevConsumer } from "@vercel/queue";
|
|
8
|
-
/** Validate the v2 conversation work hint sent through Vercel Queue. */
|
|
9
|
-
const conversationQueueMessageSchema = z.object({
|
|
10
|
-
schemaVersion: z.literal(2),
|
|
11
|
-
conversationId: z.string().trim().min(1)
|
|
12
|
-
}).strict();
|
|
13
|
-
var ConversationQueueMessageRejectedError = class extends Error {
|
|
14
|
-
conversationId;
|
|
15
|
-
reason;
|
|
16
|
-
constructor(reason, message, options = {}) {
|
|
17
|
-
super(message);
|
|
18
|
-
this.name = "ConversationQueueMessageRejectedError";
|
|
19
|
-
this.reason = reason;
|
|
20
|
-
this.conversationId = options.conversationId;
|
|
21
|
-
}
|
|
22
|
-
};
|
|
23
|
-
/** Return whether an error means the queue message was permanently rejected. */
|
|
24
|
-
function isConversationQueueMessageRejectedError(error) {
|
|
25
|
-
return error instanceof ConversationQueueMessageRejectedError;
|
|
26
|
-
}
|
|
27
|
-
/** Build the idempotency key of a wake that one worker event sends. */
|
|
28
|
-
function nudgeIdempotencyKey(reason, conversationId, nowMs) {
|
|
29
|
-
return `${reason}:${conversationId}:${nowMs}`;
|
|
30
|
-
}
|
|
31
|
-
// src/chat/runtime/request-deadline.ts
|
|
32
|
-
const requestDeadlineStorage = new AsyncLocalStorage();
|
|
33
|
-
function createTurnRequestDeadline(startedAtMs) {
|
|
34
|
-
return {
|
|
35
|
-
startedAtMs,
|
|
36
|
-
deadlineAtMs: startedAtMs + Math.max(1, getChatConfig().functionMaxDurationSeconds * 1e3 - 2e4)
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
/** Return the host request deadline inherited by the current async turn. */
|
|
40
|
-
function getTurnRequestDeadline() {
|
|
41
|
-
return requestDeadlineStorage.getStore();
|
|
42
|
-
}
|
|
43
|
-
/** Run work with one host request deadline shared by nested queued turns. */
|
|
44
|
-
function runWithTurnRequestDeadline(callback, startedAtMs = Date.now()) {
|
|
45
|
-
if (requestDeadlineStorage.getStore()) return callback();
|
|
46
|
-
return runWithNewTurnRequestDeadline(callback, startedAtMs);
|
|
47
|
-
}
|
|
48
|
-
/** Run work that a new host request owns, even inside another request. */
|
|
49
|
-
function runWithNewTurnRequestDeadline(callback, startedAtMs = Date.now()) {
|
|
50
|
-
return requestDeadlineStorage.run(createTurnRequestDeadline(startedAtMs), callback);
|
|
51
|
-
}
|
|
52
7
|
// src/chat/queue/bullmq.ts
|
|
53
8
|
const MAX_ATTEMPTS = 50;
|
|
54
9
|
const MAX_BACKOFF_MS = 3e4;
|
|
@@ -212,6 +167,94 @@ const vercelQueueProvider = {
|
|
|
212
167
|
function getQueueProvider() {
|
|
213
168
|
return getChatConfig().queue.provider === "bullmq" ? bullmqQueueProvider : vercelQueueProvider;
|
|
214
169
|
}
|
|
170
|
+
// src/chat/runtime/request-deadline.ts
|
|
171
|
+
const requestDeadlineStorage = new AsyncLocalStorage();
|
|
172
|
+
function createTurnRequestDeadline(startedAtMs) {
|
|
173
|
+
return {
|
|
174
|
+
startedAtMs,
|
|
175
|
+
deadlineAtMs: startedAtMs + Math.max(1, getChatConfig().functionMaxDurationSeconds * 1e3 - 2e4)
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
/** Return the host request deadline inherited by the current async turn. */
|
|
179
|
+
function getTurnRequestDeadline() {
|
|
180
|
+
return requestDeadlineStorage.getStore();
|
|
181
|
+
}
|
|
182
|
+
/** Run work under the current host request deadline, or start one. */
|
|
183
|
+
function runWithTurnRequestDeadline(callback, startedAtMs = Date.now()) {
|
|
184
|
+
if (requestDeadlineStorage.getStore()) return callback();
|
|
185
|
+
return runWithNewTurnRequestDeadline(callback, startedAtMs);
|
|
186
|
+
}
|
|
187
|
+
/** Run work that a new host request owns, even inside another request. */
|
|
188
|
+
function runWithNewTurnRequestDeadline(callback, startedAtMs = Date.now()) {
|
|
189
|
+
return requestDeadlineStorage.run(createTurnRequestDeadline(startedAtMs), callback);
|
|
190
|
+
}
|
|
191
|
+
// src/chat/queue/callback.ts
|
|
192
|
+
/** Shared queue callback wiring for signed messages. */
|
|
193
|
+
/** Build the HTTP callback and local-dev consumer for one signed queue. */
|
|
194
|
+
function queueCallback(options) {
|
|
195
|
+
const consume = async (message, metadata) => {
|
|
196
|
+
if (options.skip?.(metadata)) return;
|
|
197
|
+
try {
|
|
198
|
+
await runWithTurnRequestDeadline(() => options.run(message, metadata));
|
|
199
|
+
} catch (error) {
|
|
200
|
+
const reason = options.permanentError?.(error);
|
|
201
|
+
if (!reason) throw error;
|
|
202
|
+
options.onRejected(reason, metadata, error);
|
|
203
|
+
}
|
|
204
|
+
};
|
|
205
|
+
const handler = async (value, metadata) => {
|
|
206
|
+
if (options.skip?.(metadata)) return;
|
|
207
|
+
const checked = options.verify(value);
|
|
208
|
+
if (checked.status === "rejected") {
|
|
209
|
+
options.onRejected(checked.reason, metadata);
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
if (checked.status === "unavailable") throw new Error(`Queue message verification unavailable: ${checked.reason}`);
|
|
213
|
+
await runWithNewTurnRequestDeadline(() => consume(checked.message, metadata));
|
|
214
|
+
};
|
|
215
|
+
const retry = (error, metadata) => {
|
|
216
|
+
const reason = options.permanentError?.(error);
|
|
217
|
+
if (reason) {
|
|
218
|
+
options.onRejected(reason, metadata, error);
|
|
219
|
+
return { acknowledge: true };
|
|
220
|
+
}
|
|
221
|
+
if (options.maxDeliveries !== null && metadata.deliveryCount >= options.maxDeliveries) return { acknowledge: true };
|
|
222
|
+
};
|
|
223
|
+
const consumer = {
|
|
224
|
+
consumerGroup: options.consumerGroup,
|
|
225
|
+
handler,
|
|
226
|
+
retry,
|
|
227
|
+
topic: options.topic,
|
|
228
|
+
visibilityTimeoutSeconds: options.visibilityTimeoutSeconds
|
|
229
|
+
};
|
|
230
|
+
return {
|
|
231
|
+
/** Run a message that an in-process queue already trusts. */
|
|
232
|
+
consume,
|
|
233
|
+
consumer,
|
|
234
|
+
create: () => getQueueProvider().createCallback(consumer),
|
|
235
|
+
registerDev: () => {
|
|
236
|
+
if (process.env["NODE_ENV"] !== "development") return;
|
|
237
|
+
return getQueueProvider().registerDevConsumer?.(consumer);
|
|
238
|
+
}
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
// src/chat/secrets.ts
|
|
242
|
+
/** Read the server secret that signs internal tokens and payloads. */
|
|
243
|
+
function readJuniorSecret() {
|
|
244
|
+
return process.env["JUNIOR_SECRET"]?.trim() || void 0;
|
|
245
|
+
}
|
|
246
|
+
/** Read the raw dashboard session secret, with `JUNIOR_SECRET` as fallback. */
|
|
247
|
+
function readSignInSecret() {
|
|
248
|
+
return process.env["BETTER_AUTH_SECRET"] ?? process.env["JUNIOR_SECRET"];
|
|
249
|
+
}
|
|
250
|
+
/** Read the bearer secret that internal cron requests must send. */
|
|
251
|
+
function readSchedulerSecret() {
|
|
252
|
+
return process.env["JUNIOR_SCHEDULER_SECRET"]?.trim() || process.env["CRON_SECRET"]?.trim();
|
|
253
|
+
}
|
|
254
|
+
/** Read the VAPID private key that signs web push messages. */
|
|
255
|
+
function readWebPushPrivateKey() {
|
|
256
|
+
return process.env["JUNIOR_WEB_PUSH_PRIVATE_KEY"]?.trim();
|
|
257
|
+
}
|
|
215
258
|
// src/chat/queue/sign.ts
|
|
216
259
|
/** Sign and check queue messages before public callbacks run them. */
|
|
217
260
|
const QUEUE_SIGNATURE_MAX_AGE_MS = 36e5;
|
|
@@ -295,147 +338,88 @@ function verifyQueueMessage(config, value, nowMs = Date.now()) {
|
|
|
295
338
|
message: message.data
|
|
296
339
|
};
|
|
297
340
|
}
|
|
298
|
-
// src/chat/task-
|
|
299
|
-
const conversationQueueSign = {
|
|
300
|
-
context: "junior.conversation_work_queue.v2",
|
|
301
|
-
schema: conversationQueueMessageSchema,
|
|
302
|
-
separator: ":",
|
|
303
|
-
signatureVersion: "v2",
|
|
304
|
-
parts: (message) => [message.conversationId]
|
|
305
|
-
};
|
|
306
|
-
const CONVERSATION_WORK_QUEUE_SIGNATURE_MAX_SKEW_MS = QUEUE_SIGNATURE_MAX_AGE_MS;
|
|
307
|
-
/** Sign a conversation queue payload before it crosses the public callback route. */
|
|
308
|
-
function signConversationQueueMessage(message, nowMs = Date.now()) {
|
|
309
|
-
return signQueueMessage(conversationQueueSign, message, nowMs);
|
|
310
|
-
}
|
|
311
|
-
/** Explain whether a queue payload is verified, rejected, or unavailable. */
|
|
312
|
-
function verifyConversationQueueMessage(value, nowMs = Date.now()) {
|
|
313
|
-
return verifyQueueMessage(conversationQueueSign, value, nowMs);
|
|
314
|
-
}
|
|
315
|
-
const CONVERSATION_WORK_QUEUE_RETENTION_SECONDS = CONVERSATION_WORK_QUEUE_SIGNATURE_MAX_SKEW_MS / 1e3;
|
|
316
|
-
let defaultQueue;
|
|
317
|
-
/** Resolve the Vercel Queue topic used for conversation wake-up nudges. */
|
|
318
|
-
function resolveConversationWorkQueueTopic(options = {}) {
|
|
319
|
-
return options.topic?.trim() || process.env["JUNIOR_CONVERSATION_WORK_QUEUE_TOPIC"]?.trim() || "junior_conversation_work";
|
|
320
|
-
}
|
|
321
|
-
function toDelaySeconds(options) {
|
|
322
|
-
if (!options?.delayMs || options.delayMs <= 0) return;
|
|
323
|
-
return Math.ceil(options.delayMs / 1e3);
|
|
324
|
-
}
|
|
325
|
-
/** Create the Vercel Queue implementation for conversation wake-up nudges. */
|
|
326
|
-
function createVercelConversationWorkQueue(options = {}) {
|
|
327
|
-
const topic = resolveConversationWorkQueueTopic(options);
|
|
328
|
-
const client = options.client ?? getQueueProvider();
|
|
329
|
-
return { async send(message, sendOptions) {
|
|
330
|
-
const payload = signConversationQueueMessage(message);
|
|
331
|
-
return await withSpan("conversation.work.publish", "queue.publish", { conversationId: message.conversationId }, async (setSpanAttributes) => {
|
|
332
|
-
const result = await client.send(topic, payload, {
|
|
333
|
-
idempotencyKey: sendOptions?.idempotencyKey,
|
|
334
|
-
delaySeconds: toDelaySeconds(sendOptions),
|
|
335
|
-
retentionSeconds: options.retentionSeconds ?? CONVERSATION_WORK_QUEUE_RETENTION_SECONDS
|
|
336
|
-
});
|
|
337
|
-
if (!result.messageId) return {};
|
|
338
|
-
setSpanAttributes({ "messaging.message.id": result.messageId });
|
|
339
|
-
return { messageId: result.messageId };
|
|
340
|
-
}, {
|
|
341
|
-
"messaging.destination.name": topic,
|
|
342
|
-
"messaging.message.body.size": Buffer.byteLength(JSON.stringify(payload)),
|
|
343
|
-
"messaging.system": getQueueProvider().messagingSystem
|
|
344
|
-
});
|
|
345
|
-
} };
|
|
346
|
-
}
|
|
347
|
-
/** Return the default production conversation work queue. */
|
|
348
|
-
function getVercelConversationWorkQueue() {
|
|
349
|
-
defaultQueue ??= createVercelConversationWorkQueue();
|
|
350
|
-
return defaultQueue;
|
|
351
|
-
}
|
|
352
|
-
// src/chat/queue/callback.ts
|
|
353
|
-
/** Shared queue callback wiring for signed messages. */
|
|
354
|
-
/** Build the HTTP callback and local-dev consumer for one signed queue. */
|
|
355
|
-
function queueCallback(options) {
|
|
356
|
-
const consume = async (message, metadata) => {
|
|
357
|
-
if (options.skip?.(metadata)) return;
|
|
358
|
-
try {
|
|
359
|
-
await runWithTurnRequestDeadline(() => options.run(message, metadata));
|
|
360
|
-
} catch (error) {
|
|
361
|
-
const reason = options.permanentError?.(error);
|
|
362
|
-
if (!reason) throw error;
|
|
363
|
-
options.onRejected(reason, metadata, error);
|
|
364
|
-
}
|
|
365
|
-
};
|
|
366
|
-
const handler = async (value, metadata) => {
|
|
367
|
-
if (options.skip?.(metadata)) return;
|
|
368
|
-
const checked = options.verify(value);
|
|
369
|
-
if (checked.status === "rejected") {
|
|
370
|
-
options.onRejected(checked.reason, metadata);
|
|
371
|
-
return;
|
|
372
|
-
}
|
|
373
|
-
if (checked.status === "unavailable") throw new Error(`Queue message verification unavailable: ${checked.reason}`);
|
|
374
|
-
await runWithNewTurnRequestDeadline(() => consume(checked.message, metadata));
|
|
375
|
-
};
|
|
376
|
-
const retry = (error, metadata) => {
|
|
377
|
-
const reason = options.permanentError?.(error);
|
|
378
|
-
if (reason) {
|
|
379
|
-
options.onRejected(reason, metadata, error);
|
|
380
|
-
return { acknowledge: true };
|
|
381
|
-
}
|
|
382
|
-
if (options.maxDeliveries !== null && metadata.deliveryCount >= options.maxDeliveries) return { acknowledge: true };
|
|
383
|
-
};
|
|
384
|
-
const consumer = {
|
|
385
|
-
consumerGroup: options.consumerGroup,
|
|
386
|
-
handler,
|
|
387
|
-
retry,
|
|
388
|
-
topic: options.topic,
|
|
389
|
-
visibilityTimeoutSeconds: options.visibilityTimeoutSeconds
|
|
390
|
-
};
|
|
391
|
-
return {
|
|
392
|
-
/** Run a message that an in-process queue already trusts. */
|
|
393
|
-
consume,
|
|
394
|
-
consumer,
|
|
395
|
-
create: () => getQueueProvider().createCallback(consumer),
|
|
396
|
-
registerDev: () => {
|
|
397
|
-
if (process.env["NODE_ENV"] !== "development") return;
|
|
398
|
-
return getQueueProvider().registerDevConsumer?.(consumer);
|
|
399
|
-
}
|
|
400
|
-
};
|
|
401
|
-
}
|
|
402
|
-
// src/chat/services/background-compaction-queue.ts
|
|
341
|
+
// src/chat/plugins/task-queue.ts
|
|
403
342
|
/**
|
|
404
|
-
*
|
|
343
|
+
* Delivery for plugin-registered tasks.
|
|
405
344
|
*
|
|
406
|
-
*
|
|
407
|
-
*
|
|
408
|
-
* stays small.
|
|
345
|
+
* Plugins register named tasks. This module owns the shared signed message,
|
|
346
|
+
* send path, and HTTP/local callback. Core keeps one topic and one runner.
|
|
409
347
|
*/
|
|
410
348
|
/** Deploy topic name. Keep stable for Vercel queue wiring. */
|
|
411
|
-
const
|
|
412
|
-
const
|
|
413
|
-
|
|
349
|
+
const PLUGIN_TASK_QUEUE_TOPIC = "junior_plugin_tasks";
|
|
350
|
+
const PLUGIN_TASK_DEV_CONSUMER_GROUP = "junior_plugin_tasks_dev";
|
|
351
|
+
const PLUGIN_TASK_MAX_DELIVERIES = 5;
|
|
352
|
+
const PLUGIN_TASK_SIGN_CONTEXT = "junior.plugin_task_queue.v1";
|
|
353
|
+
const PLUGIN_TASK_SIGN_VERSION = "v1";
|
|
354
|
+
const pluginTaskParamsSchema = z.object({
|
|
355
|
+
conversationId: z.string().min(1),
|
|
356
|
+
sessionId: z.string().min(1)
|
|
357
|
+
}).strict();
|
|
358
|
+
const pluginTaskSign = {
|
|
359
|
+
context: PLUGIN_TASK_SIGN_CONTEXT,
|
|
414
360
|
schema: z.object({
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
361
|
+
name: z.string().min(1),
|
|
362
|
+
params: pluginTaskParamsSchema,
|
|
363
|
+
plugin: z.string().min(1)
|
|
418
364
|
}).strict(),
|
|
419
|
-
signatureVersion:
|
|
365
|
+
signatureVersion: PLUGIN_TASK_SIGN_VERSION,
|
|
420
366
|
parts: (message) => [
|
|
421
|
-
message.
|
|
422
|
-
|
|
423
|
-
|
|
367
|
+
message.plugin,
|
|
368
|
+
message.name,
|
|
369
|
+
message.params.conversationId,
|
|
370
|
+
message.params.sessionId
|
|
424
371
|
]
|
|
425
372
|
};
|
|
426
|
-
/**
|
|
427
|
-
function
|
|
428
|
-
return `
|
|
429
|
-
}
|
|
430
|
-
/**
|
|
431
|
-
function
|
|
432
|
-
return
|
|
433
|
-
}
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
373
|
+
/** Build the stable id used for delivery dedupe and tracing. */
|
|
374
|
+
function pluginTaskId(args) {
|
|
375
|
+
return `plugin-task_${createHash("sha256").update(args.plugin).update("\0").update(args.name).update("\0").update(args.params.conversationId).update("\0").update(args.params.sessionId).digest("hex").slice(0, 32)}`;
|
|
376
|
+
}
|
|
377
|
+
/** Sign a plugin task message for tests and local checks. */
|
|
378
|
+
function signPluginTaskQueueMessage(message, nowMs = Date.now()) {
|
|
379
|
+
return signQueueMessage(pluginTaskSign, message, nowMs);
|
|
380
|
+
}
|
|
381
|
+
function verifyPluginTaskQueueMessage(value, nowMs = Date.now()) {
|
|
382
|
+
return verifyQueueMessage(pluginTaskSign, value, nowMs);
|
|
383
|
+
}
|
|
384
|
+
function logPluginTaskQueueMessageRejected(reason, metadata) {
|
|
385
|
+
logWarn("plugin.task.queue_message.rejected", {
|
|
386
|
+
"app.queue.consumer_group": metadata.consumerGroup,
|
|
387
|
+
"app.queue.delivery_count": metadata.deliveryCount,
|
|
388
|
+
"app.queue.message_id": metadata.messageId,
|
|
389
|
+
"app.queue.reject_reason": reason,
|
|
390
|
+
"app.queue.topic_name": metadata.topicName
|
|
391
|
+
});
|
|
392
|
+
}
|
|
393
|
+
function pluginTaskCallback() {
|
|
394
|
+
return queueCallback({
|
|
395
|
+
consumerGroup: PLUGIN_TASK_DEV_CONSUMER_GROUP,
|
|
396
|
+
maxDeliveries: PLUGIN_TASK_MAX_DELIVERIES,
|
|
397
|
+
onRejected: logPluginTaskQueueMessageRejected,
|
|
398
|
+
run: async (message) => {
|
|
399
|
+
const { processPluginTask } = await import("./task-runner-CoXmMlsW.js").then((n) => n.r);
|
|
400
|
+
await processPluginTask(message);
|
|
401
|
+
},
|
|
402
|
+
topic: PLUGIN_TASK_QUEUE_TOPIC,
|
|
403
|
+
verify: verifyPluginTaskQueueMessage
|
|
404
|
+
});
|
|
405
|
+
}
|
|
406
|
+
/** Send one plugin task through the shared signed delivery path. */
|
|
407
|
+
async function sendVercelPluginTask(message) {
|
|
408
|
+
await getQueueProvider().send(PLUGIN_TASK_QUEUE_TOPIC, signPluginTaskQueueMessage(message), {
|
|
409
|
+
idempotencyKey: pluginTaskId(message),
|
|
438
410
|
retentionSeconds: QUEUE_SIGNATURE_MAX_AGE_MS / 1e3
|
|
439
411
|
});
|
|
440
|
-
}
|
|
441
|
-
|
|
412
|
+
}
|
|
413
|
+
/** Create the HTTP callback for plugin tasks. */
|
|
414
|
+
function createVercelPluginTaskCallback() {
|
|
415
|
+
return pluginTaskCallback().create();
|
|
416
|
+
}
|
|
417
|
+
/** Return the queue consumer for plugin tasks, for a pulling queue worker. */
|
|
418
|
+
function pluginTaskQueueConsumer() {
|
|
419
|
+
return pluginTaskCallback().consumer;
|
|
420
|
+
}
|
|
421
|
+
/** Register the local-dev consumer for plugin tasks. */
|
|
422
|
+
function registerVercelPluginTaskDevConsumer() {
|
|
423
|
+
return pluginTaskCallback().registerDev();
|
|
424
|
+
}
|
|
425
|
+
export { getQueueProvider as _, pluginTaskQueueConsumer as a, QUEUE_SIGNATURE_MAX_AGE_MS as c, readJuniorSecret as d, readSchedulerSecret as f, getTurnRequestDeadline as g, queueCallback as h, pluginTaskParamsSchema as i, signQueueMessage as l, readWebPushPrivateKey as m, createVercelPluginTaskCallback as n, registerVercelPluginTaskDevConsumer as o, readSignInSecret as p, pluginTaskId as r, sendVercelPluginTask as s, PLUGIN_TASK_QUEUE_TOPIC as t, verifyQueueMessage as u };
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { t as __exportAll } from "./rolldown-runtime-BKpuH2hG.js";
|
|
2
|
-
import {
|
|
3
|
-
import { $ as getStateAdapter, a as getConversationStore, o as getDb } from "./db-
|
|
4
|
-
import { E as withSpan } from "./logging-
|
|
5
|
-
import { a as getPersistedThreadState, c as coerceThreadConversationState, t as resolveConversationRouting } from "./turn-session-routing-
|
|
6
|
-
import { i as readActorIdentity } from "./viewer-
|
|
2
|
+
import { Ha as createPluginModelCostRecorder, Ln as coreTaskRegistrations, Mi as createPluginState, Nn as getPlugins, Oa as createPluginEmbedder, Qn as getPiMessageRole, Ua as createPluginLogger, Yo as getDispatchRecord, at as getTurnRecord, cr as isToolResultMessage, dr as stripRuntimeTurnContext, eo as createPluginConversationEvents, ka as createPluginModel, lr as normalizeToolNameFromResult, rr as instructionTextForProjection, sr as isToolResultError, ul as createPluginCache, v as hydrateConversationMessages } from "./projection-xPpvqexa.js";
|
|
3
|
+
import { $ as getStateAdapter, a as getConversationStore, o as getDb } from "./db-Bcbd9zQc.js";
|
|
4
|
+
import { E as withSpan } from "./logging-CHCuQ5iz.js";
|
|
5
|
+
import { a as getPersistedThreadState, c as coerceThreadConversationState, t as resolveConversationRouting } from "./turn-session-routing-DFYak28Q.js";
|
|
6
|
+
import { i as readActorIdentity } from "./viewer-DN_xzVKj.js";
|
|
7
7
|
import { v as parseSlackMessageTs } from "./actor-D2iXzvlN.js";
|
|
8
8
|
import { m as sameActorIdentity } from "./history-N7IVbUom.js";
|
|
9
|
-
import { i as pluginTaskParamsSchema, r as pluginTaskId } from "./task-queue-
|
|
9
|
+
import { i as pluginTaskParamsSchema, r as pluginTaskId } from "./task-queue-BcjAYWyB.js";
|
|
10
|
+
import pLimit from "p-limit";
|
|
10
11
|
import { pluginRunContextSchema } from "@sentry/junior-plugin-api";
|
|
11
12
|
// src/chat/plugins/task-runner.ts
|
|
12
13
|
/**
|
|
@@ -17,6 +18,7 @@ import { pluginRunContextSchema } from "@sentry/junior-plugin-api";
|
|
|
17
18
|
* payloads.
|
|
18
19
|
*/
|
|
19
20
|
var task_runner_exports = /* @__PURE__ */ __exportAll({ processPluginTask: () => processPluginTask });
|
|
21
|
+
const PLUGIN_MESSAGE_SEND_CONCURRENCY = 5;
|
|
20
22
|
const PLUGIN_TASK_LOCK_TTL_MS = 3e5;
|
|
21
23
|
function isRecord(value) {
|
|
22
24
|
return Boolean(value && typeof value === "object" && !Array.isArray(value));
|
|
@@ -262,9 +264,10 @@ async function scheduleSessionCompletedPluginTasks(params, send) {
|
|
|
262
264
|
params: coreParams,
|
|
263
265
|
plugin: plugin.manifest.name
|
|
264
266
|
}));
|
|
265
|
-
|
|
267
|
+
const limit = pLimit(PLUGIN_MESSAGE_SEND_CONCURRENCY);
|
|
268
|
+
await Promise.all(messages.map((message) => limit(async () => {
|
|
266
269
|
await send(message);
|
|
267
|
-
}));
|
|
270
|
+
})));
|
|
268
271
|
}
|
|
269
272
|
/**
|
|
270
273
|
* Execute one parsed plugin task request in a `plugin.task` span. The span
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { J as clearPendingAuth,
|
|
2
|
-
import { K as isRecord, b as setSpanAttributes } from "./logging-
|
|
3
|
-
import { o as getDb, r as getConversationEventStore } from "./db-
|
|
1
|
+
import { J as clearPendingAuth, Po as listConversationAnnotations, k as markConversationMessage, v as hydrateConversationMessages, w as buildConversationContext } from "./projection-xPpvqexa.js";
|
|
2
|
+
import { K as isRecord, b as setSpanAttributes } from "./logging-CHCuQ5iz.js";
|
|
3
|
+
import { o as getDb, r as getConversationEventStore } from "./db-Bcbd9zQc.js";
|
|
4
4
|
import { J as readMessageCardRefs, X as resolveMessageCards, Y as removedCardSchema } from "./conversation--f85g4zL.js";
|
|
5
|
-
import { S as listChildMessages, m as markTurnCompleted, n as getTurnUserMessageId, p as markTurnClosed, x as isAgentInvocationResult } from "./turn-user-message-
|
|
6
|
-
import { _ as getConversationWorkState } from "./store-
|
|
7
|
-
import { a as getPersistedThreadState, c as coerceThreadConversationState, s as persistThreadStateById } from "./turn-session-routing-
|
|
5
|
+
import { S as listChildMessages, m as markTurnCompleted, n as getTurnUserMessageId, p as markTurnClosed, x as isAgentInvocationResult } from "./turn-user-message-B1S8nOnG.js";
|
|
6
|
+
import { _ as getConversationWorkState } from "./store-CdWg2r2L.js";
|
|
7
|
+
import { a as getPersistedThreadState, c as coerceThreadConversationState, s as persistThreadStateById } from "./turn-session-routing-DFYak28Q.js";
|
|
8
8
|
// src/chat/conversations/pending-cards.ts
|
|
9
9
|
/**
|
|
10
10
|
* Add the cards that tool results selected since the last visible assistant
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { J as toOptionalString, K as isRecord, q as toOptionalNumber } from "./logging-
|
|
3
|
-
import { $ as getStateAdapter, o as getDb } from "./db-
|
|
1
|
+
import { Ko as getDispatchConversationId, Yo as getDispatchRecord, b as persistConversationMessages, dl as createDurableLocationConfigurationService, sl as JUNIOR_THREAD_STATE_TTL_MS } from "./projection-xPpvqexa.js";
|
|
2
|
+
import { J as toOptionalString, K as isRecord, q as toOptionalNumber } from "./logging-CHCuQ5iz.js";
|
|
3
|
+
import { $ as getStateAdapter, o as getDb } from "./db-Bcbd9zQc.js";
|
|
4
4
|
// src/chat/state/conversation.ts
|
|
5
5
|
function defaultConversationState() {
|
|
6
6
|
return {
|
|
@@ -202,7 +202,7 @@ function slackSourceForDestination(args) {
|
|
|
202
202
|
* Reads parent Conversations when this Conversation has no Destination.
|
|
203
203
|
*/
|
|
204
204
|
async function resolveConversationRouting(args) {
|
|
205
|
-
const conversationStore = args.conversationStore ?? (await import("./db-
|
|
205
|
+
const conversationStore = args.conversationStore ?? (await import("./db-Bcbd9zQc.js").then((n) => n.n)).getConversationStore();
|
|
206
206
|
const chain = await loadConversationChain(args.conversationId, conversationStore);
|
|
207
207
|
let destination;
|
|
208
208
|
let source;
|
|
@@ -241,4 +241,23 @@ async function resolveTurnSessionRouting(args) {
|
|
|
241
241
|
source: routing.source
|
|
242
242
|
};
|
|
243
243
|
}
|
|
244
|
-
|
|
244
|
+
/**
|
|
245
|
+
* Require the Destination and Source to resume a Turn.
|
|
246
|
+
*
|
|
247
|
+
* A dispatch Conversation stores the dispatch Source, which has no session
|
|
248
|
+
* Source. Its dispatch record owns the Destination and Source.
|
|
249
|
+
*/
|
|
250
|
+
async function resolveTurnResumeRouting(args) {
|
|
251
|
+
if (!args.dispatchId) return await resolveTurnSessionRouting(args);
|
|
252
|
+
const dispatch = await getDispatchRecord(args.dispatchId);
|
|
253
|
+
if (!dispatch) throw new Error(`Dispatch record is missing for ${args.dispatchId}`);
|
|
254
|
+
const dispatchConversationId = getDispatchConversationId(dispatch);
|
|
255
|
+
if (dispatchConversationId !== args.conversationId) throw new Error(`Dispatch ${dispatch.id} belongs to ${dispatchConversationId}, not ${args.conversationId}`);
|
|
256
|
+
const location = (await resolveConversationRouting(args))?.location;
|
|
257
|
+
return {
|
|
258
|
+
destination: dispatch.destination,
|
|
259
|
+
...location ? { location } : void 0,
|
|
260
|
+
source: dispatch.source
|
|
261
|
+
};
|
|
262
|
+
}
|
|
263
|
+
export { getPersistedThreadState as a, coerceThreadConversationState as c, getPersistedSandboxState as i, resolveTurnResumeRouting as n, persistThreadRuntimeState as o, getLocationConfigurationService as r, persistThreadStateById as s, resolveConversationRouting as t };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { qt as readInboundMessageSender } from "./projection-
|
|
1
|
+
import { qt as readInboundMessageSender } from "./projection-xPpvqexa.js";
|
|
2
2
|
import { v as parseSlackMessageTs } from "./actor-D2iXzvlN.js";
|
|
3
|
-
import { r as getConversationEventStore, s as getSqlExecutor } from "./db-
|
|
4
|
-
import {
|
|
3
|
+
import { r as getConversationEventStore, s as getSqlExecutor } from "./db-Bcbd9zQc.js";
|
|
4
|
+
import { y as juniorAgentInvocations } from "./executor-DBMBrpNV.js";
|
|
5
5
|
import { createHash } from "node:crypto";
|
|
6
6
|
import { inArray } from "drizzle-orm";
|
|
7
7
|
// src/chat/state/turn-id.ts
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { bs as SlackActionError, js as withSlackRetries, ws as getSlackClient } from "./projection-xPpvqexa.js";
|
|
2
2
|
import * as z from "zod";
|
|
3
3
|
// src/chat/slack/users.ts
|
|
4
4
|
const profileFieldsSchema = z.object({ fields: z.record(z.string(), z.object({
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { t as __exportAll } from "./rolldown-runtime-BKpuH2hG.js";
|
|
2
|
-
import { n as pluginCatalogRuntime } from "./catalog-runtime-
|
|
2
|
+
import { n as pluginCatalogRuntime } from "./catalog-runtime-OXrv2Ewn.js";
|
|
3
3
|
import { isDeepStrictEqual } from "node:util";
|
|
4
4
|
// src/chat/plugins/validation.ts
|
|
5
5
|
var validation_exports = /* @__PURE__ */ __exportAll({
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// package.json
|
|
2
|
-
var version = "0.
|
|
2
|
+
var version = "0.307.0";
|
|
3
3
|
// src/version.ts
|
|
4
4
|
/** Installed Junior package version, or `unknown` when package metadata is unavailable. */
|
|
5
5
|
const JUNIOR_VERSION = typeof version === "string" && version.trim() ? version : "unknown";
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { t as JUNIOR_VERSION } from "./version-
|
|
1
|
+
export { t as JUNIOR_VERSION } from "./version-DCdMMx_0.js";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { F as findActorIdentityId, J as clearCachedUser, Y as readCachedUserByEmail, o as getDb } from "./db-
|
|
2
|
-
import {
|
|
3
|
-
import { G as normalizeIdentityEmail, U as GOOGLE_IDENTITY_PROVIDER } from "./logging-
|
|
1
|
+
import { F as findActorIdentityId, J as clearCachedUser, Y as readCachedUserByEmail, o as getDb } from "./db-Bcbd9zQc.js";
|
|
2
|
+
import { B as juniorUsers, z as juniorIdentities } from "./executor-DBMBrpNV.js";
|
|
3
|
+
import { G as normalizeIdentityEmail, U as GOOGLE_IDENTITY_PROVIDER } from "./logging-CHCuQ5iz.js";
|
|
4
4
|
import { createHash, randomUUID } from "node:crypto";
|
|
5
5
|
import { and, asc, eq, inArray, isNotNull } from "drizzle-orm";
|
|
6
6
|
import { identitySchema, userSchema } from "@sentry/junior-plugin-api";
|