@sentry/junior 0.298.0 → 0.299.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/{actor-6jsm_v96.js → actor-D2iXzvlN.js} +2 -1
- package/dist/{state-CSuA2J1V.js → adapter-AgCNqqsG.js} +49 -133
- package/dist/{admin-BF3DbYGf.js → admin-1VwEXztm.js} +2 -2
- package/dist/{agent-runner-Q9GkoerG.js → agent-runner-Ciet8_nn.js} +977 -1316
- package/dist/api/schema.d.ts +2 -2
- package/dist/api/schema.js +8 -7
- package/dist/api.d.ts +1 -1
- package/dist/api.js +125 -43
- package/dist/{app-DOg_mCtV.d.ts → app--ky-Eu33.d.ts} +6 -4
- package/dist/app.d.ts +1 -1
- package/dist/app.js +126 -299
- package/dist/{automation-Cn8qmbdr.js → automation-M3RFJUBf.js} +1 -1
- package/dist/{background-compaction-queue-BZhGFOK6.js → background-compaction-queue-CnimvRdk.js} +4 -4
- package/dist/{briefs-CQrCRF6-.js → briefs-CwzvgdCa.js} +4 -4
- package/dist/{catalog-runtime-DZeD2WbL.js → catalog-runtime-DaBaHY7u.js} +1 -1
- package/dist/cli/chat.js +17 -17
- package/dist/cli/check.js +3 -3
- package/dist/cli/main.js +3 -3
- package/dist/cli/plugins.js +5 -5
- package/dist/cli/snapshot-create.js +4 -4
- package/dist/cli/upgrade.d.ts +1 -1
- package/dist/cli/upgrade.js +4 -4
- package/dist/{config-BOByVnxe.js → config-CAXIpWQb.js} +80 -6
- package/dist/{connections-BNN5cJam.js → connections-Dy0hPdUq.js} +6 -6
- package/dist/continue-in-slack-DIOjFj76.js +176 -0
- package/dist/{conversation-DCkzvxqB.js → conversation-fCWD9Az3.js} +24 -12
- package/dist/{conversation-feed-CMA12Rjs.js → conversation-feed-BPK8vkkZ.js} +88 -3
- package/dist/{conversation-privacy-C0eRxsgb.js → conversation-privacy-DUgtRkf8.js} +1 -1
- package/dist/{conversation-turn-D9qvcDX6.js → conversation-turn-DkJB6yMF.js} +85 -68
- package/dist/{credential-sync-B_iUpxGL.js → credential-sync-RX24Y8aY.js} +18 -18
- package/dist/{db-DoMcnYol.d.ts → db-B07FtU9g.d.ts} +1 -1
- package/dist/{db-CoMNr2Zm.js → db-COYOGzYS.js} +171 -12
- package/dist/{executor-C-m8VrzX.js → executor-BWmAgSyi.js} +40 -11
- package/dist/{media-BepyEUNm.js → history-IjdmO_r6.js} +1 -85
- package/dist/instrumentation.js +2 -2
- package/dist/lineage-D-5jm_oj.js +37 -0
- package/dist/{logging-CJTi5niy.js → logging-DPLEa8Bn.js} +1 -1
- package/dist/media-BAHvgkok.js +85 -0
- package/dist/{message-Q6_5DAWR.js → message-BIHR1yRk.js} +9 -10
- package/dist/model-input-BPZYH8Nd.js +82 -0
- package/dist/nitro.d.ts +1 -1
- package/dist/nitro.js +17 -9
- package/dist/{oauth-callback-server-CH5XAyo-.js → oauth-callback-server-R7qvSzFG.js} +2 -2
- package/dist/{plugins-HYh_JOdw.js → plugins-CBW2Prb_.js} +1 -1
- package/dist/{projection-BgwEE36_.js → projection-DEdP1q6f.js} +261 -36
- package/dist/{prompt-DXc9DYT9.js → prompt-4M98h_tC.js} +4 -4
- package/dist/{registry-9XwqSnM-.js → registry-BTKmKM-r.js} +3 -3
- package/dist/{resolve-DUIAbcRL.js → resolve-B8hXNVZ3.js} +3 -3
- package/dist/{result-C2Vn8QGn.js → result-g-XAaOj6.js} +158 -69
- package/dist/{runner-CXGtw-Mc.js → runner-BlPSA5A8.js} +9 -9
- package/dist/{sandbox-egress-signals-Di3S_dO7.js → sandbox-egress-signals-Pai-MzEY.js} +1 -1
- package/dist/{schema-Dyp7racy.js → schema-BNnY_trV.js} +47 -7
- package/dist/{schema-BnbZ-rKv.d.ts → schema-DbuWR-DN.d.ts} +657 -346
- package/dist/{service-account-GzAMUQ8a.js → service-account-9OLNQMyz.js} +4 -4
- package/dist/{service-account-DM3KBBeG.js → service-account-BYGZ08DQ.js} +3 -3
- package/dist/session-stop-2XJrcNCy.js +3356 -0
- package/dist/{skills-DCK9SD_l.js → skills-DpBQoeHV.js} +3 -3
- package/dist/slack-conversation-unfurl-BcDIWo67.js +370 -0
- package/dist/spawn-09GssFod.js +73 -0
- package/dist/state-Cufq0_rH.js +132 -0
- package/dist/{user-input-request-CXNIov9n.js → statuses-B8mUfghF.js} +30 -25
- package/dist/{stop-Dh2DfwpK.js → stop-U7iUrR1g.js} +6008 -5772
- package/dist/{store-B1zepKG8.js → store-BHiaHCQu.js} +24 -4
- package/dist/{store-DrA17Fbz.js → store-CSgUTMdv.js} +10 -10
- package/dist/{task-queue-D1rXWfFN.js → task-queue-bMNq0clp.js} +4 -4
- package/dist/{task-runner-CT4M8oDz.js → task-runner-B__rxwxU.js} +10 -10
- package/dist/{thread-context-DnqUkbzN.js → thread-context-d0ceWbVT.js} +18 -18
- package/dist/{turn-session-routing-VXDVXLRl.js → turn-session-routing-BVZHBFCF.js} +5 -5
- package/dist/turn-user-message-BEw7acTP.js +355 -0
- package/dist/users-BK3dbxZL.js +424 -0
- package/dist/{validation-zxAJBDDy.js → validation-BDVJjO2E.js} +1 -1
- package/dist/{version-DcZ40a0g.js → version-DQgZoQ3D.js} +1 -1
- package/dist/version.js +1 -1
- package/dist/{viewer-CgiGjW10.js → viewer-CAWfFo29.js} +25 -54
- package/dist/{warmup-CwKbxQLl.js → warmup-9ySPacF9.js} +1137 -144
- package/dist/{worker-CbDUzaBA.js → worker-D8jJO-WO.js} +8 -7
- package/migrations/0104_code_change_draft.sql +1 -0
- package/migrations/0105_attachment_uploads.sql +14 -0
- package/migrations/0106_conversation_agent_config.sql +1 -0
- package/migrations/meta/0104_snapshot.json +4516 -0
- package/migrations/meta/0105_snapshot.json +4611 -0
- package/migrations/meta/0106_snapshot.json +4617 -0
- package/migrations/meta/_journal.json +21 -0
- package/package.json +4 -4
- package/dist/attempt-selection-ClP3MMPr.js +0 -61
- package/dist/locks-D-0h111u.js +0 -48
- package/dist/notification-Bv25xbj0.js +0 -1284
- package/dist/prompt-input-BUr4J9RO.js +0 -1424
- package/dist/session-stop-D4i7e6iT.js +0 -181
- package/dist/spawn-6cX6xE9G.js +0 -80
- package/dist/turn-cancel-l460pfGW.js +0 -201
- package/dist/turn-user-message-BSPmkm7X.js +0 -608
- package/dist/turn-wake-DVFVXyhX.js +0 -161
- package/dist/{oauth-relay-CsfIazeF.js → oauth-relay-DRzq73b6.js} +1 -1
|
@@ -1,54 +1,25 @@
|
|
|
1
1
|
import { i as getActiveSpan, r as continueTrace, v as __exportAll } from "./sentry-BRTJqumy.js";
|
|
2
|
-
import { A as latestConversationMessageSeq, I as upsertConversationMessage, M as normalizeConversationText, N as recordDeliveredAssistantMessage,
|
|
3
|
-
import { n as botConfig } from "./config-
|
|
4
|
-
import { E as withSpan, S as setTags, h as logWarn, p as logException } from "./logging-
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import { f as credentialContextForActor } from "./registry-
|
|
9
|
-
import {
|
|
10
|
-
import { o as isEventConversationMessage } from "./prompt-
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import { a as getPersistedThreadState, c as coerceThreadConversationState, i as getPersistedSandboxState, s as persistThreadStateById } from "./turn-session-routing-
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
19
|
-
import { n as scheduleSessionCompletedPluginTasks, t as processPluginTask } from "./task-runner-
|
|
20
|
-
import { c as buildDeliveredTurnStatePatch, l as loadPendingMessageCards, o as completeAuthPauseTurn, r as finalizeFailedTurnReplyWithEvent, t as buildTurnThreadContext } from "./thread-context-DnqUkbzN.js";
|
|
2
|
+
import { A as latestConversationMessageSeq, Ei as verifyTimerWatchCredentialSubject, I as upsertConversationMessage, M as normalizeConversationText, N as recordDeliveredAssistantMessage, a as loadProjection, at as failTurnRecord, b as persistConversationMessages, bn as persistWithRetry, j as markConversationMessage, nt as saveTurnCheckpoint, st as getTurnRecord, t as commitAcceptedReply, un as getAssistantReplyText, v as hydrateConversationMessages } from "./projection-DEdP1q6f.js";
|
|
3
|
+
import { n as botConfig } from "./config-CAXIpWQb.js";
|
|
4
|
+
import { E as withSpan, S as setTags, h as logWarn, p as logException } from "./logging-DPLEa8Bn.js";
|
|
5
|
+
import { C as isPersonInput, E as turnBehavior, a as getConversationStore, nt as nextDetailVersion, o as getDb, r as getConversationEventStore, s as getSqlExecutor, w as isTopLevelKind } from "./db-COYOGzYS.js";
|
|
6
|
+
import { j as juniorConversations } from "./executor-BWmAgSyi.js";
|
|
7
|
+
import { p as instructionProvenanceFor } from "./history-IjdmO_r6.js";
|
|
8
|
+
import { f as credentialContextForActor } from "./registry-BTKmKM-r.js";
|
|
9
|
+
import { i as measureTurnCompactionWait, lt as resolveConversationDestination } from "./agent-runner-Ciet8_nn.js";
|
|
10
|
+
import { o as isEventConversationMessage } from "./prompt-4M98h_tC.js";
|
|
11
|
+
import { J as readMessageAttachments } from "./conversation-fCWD9Az3.js";
|
|
12
|
+
import { A as turnInputFactsFromConversationMessage, F as isEventMailboxMetadata, I as renderEventBatchInputs, L as timerWatchCredentialSubject, P as eventBatchMessageMeta, X as maybePostAutomatedTurnLimitNotice, c as loadReviewItemInput, f as buildSteeringPiMessage, g as withoutSavedSteeringMessages, j as legacyWebMailboxMetadataSchema, k as sourceFromTurnInput, m as instructionForInputs, nt as recordFinishedTurnForAutomatedLimit, p as instructionActorFor, s as eventReviewItemInputs, w as getEventBatchDelayMs } from "./session-stop-2XJrcNCy.js";
|
|
13
|
+
import { Et as executeTurn, L as readParentMessage, M as childAgentTurnOptions, N as isParentMessageMeta, St as createWebAuthorization, Tt as AgentRunError, Y as completeCancelledConversationTurn, dt as supersedeOpenMailboxTurns } from "./warmup-9ySPacF9.js";
|
|
14
|
+
import { R as buildDeterministicTurnId, _ as ConversationTurnLifecycleService, d as isTurnInputCommitLostError, g as startActiveTurn, h as markTurnFailed, l as getConversationTurnBoundaryError, s as TurnInputCommitLostError, t as getTurnUserMessage } from "./turn-user-message-BEw7acTP.js";
|
|
15
|
+
import { a as getPersistedThreadState, c as coerceThreadConversationState, i as getPersistedSandboxState, s as persistThreadStateById } from "./turn-session-routing-BVZHBFCF.js";
|
|
16
|
+
import { H as blockEventAutomation, M as blockScheduledAutomation, c as getDispatchRecord, o as getDispatchIdForConversation, v as notifyAutomationBlocked, x as readAutomationExecutionByConversationId } from "./store-CSgUTMdv.js";
|
|
17
|
+
import { t as readConversationLineage } from "./lineage-D-5jm_oj.js";
|
|
18
|
+
import { c as buildDeliveredTurnStatePatch, l as loadPendingMessageCards, o as completeAuthPauseTurn, r as finalizeFailedTurnReplyWithEvent, t as buildTurnThreadContext } from "./thread-context-d0ceWbVT.js";
|
|
19
|
+
import { n as scheduleSessionCompletedPluginTasks, t as processPluginTask } from "./task-runner-B__rxwxU.js";
|
|
21
20
|
import { isDeepStrictEqual } from "node:util";
|
|
22
21
|
import { createHash } from "node:crypto";
|
|
23
22
|
import { and, eq, isNotNull, isNull } from "drizzle-orm";
|
|
24
|
-
// src/chat/conversations/delivery-pause.ts
|
|
25
|
-
/** True when the Conversation is a root that delivers to a Location. */
|
|
26
|
-
function canPauseConversationDelivery(conversation) {
|
|
27
|
-
return isTopLevelKind(conversation.kind) && conversation.location !== void 0;
|
|
28
|
-
}
|
|
29
|
-
const rootConversation = (conversationId) => and(eq(juniorConversations.conversationId, conversationId), isNull(juniorConversations.parentConversationId));
|
|
30
|
-
/**
|
|
31
|
-
* Stop Delivery of a root's Event Turn replies to its Location. Returns false
|
|
32
|
-
* when Delivery was already paused or the root does not exist.
|
|
33
|
-
*/
|
|
34
|
-
async function pauseConversationDelivery(conversationId) {
|
|
35
|
-
return (await getSqlExecutor().db().update(juniorConversations).set({
|
|
36
|
-
deliveryPausedAt: /* @__PURE__ */ new Date(),
|
|
37
|
-
detailVersion: nextDetailVersion
|
|
38
|
-
}).where(and(rootConversation(conversationId), isNull(juniorConversations.deliveryPausedAt))).returning({ conversationId: juniorConversations.conversationId })).length > 0;
|
|
39
|
-
}
|
|
40
|
-
/** Deliver a root's Event Turn replies to its Location again. */
|
|
41
|
-
async function resumeConversationDelivery(conversationId) {
|
|
42
|
-
await getSqlExecutor().db().update(juniorConversations).set({
|
|
43
|
-
deliveryPausedAt: null,
|
|
44
|
-
detailVersion: nextDetailVersion
|
|
45
|
-
}).where(and(rootConversation(conversationId), isNotNull(juniorConversations.deliveryPausedAt)));
|
|
46
|
-
}
|
|
47
|
-
/** True while a root's Event Turn replies stay out of its Location. */
|
|
48
|
-
async function isConversationDeliveryPaused(conversationId) {
|
|
49
|
-
const [row] = await getSqlExecutor().db().select({ pausedAt: juniorConversations.deliveryPausedAt }).from(juniorConversations).where(eq(juniorConversations.conversationId, conversationId)).limit(1);
|
|
50
|
-
return Boolean(row?.pausedAt);
|
|
51
|
-
}
|
|
52
23
|
// src/chat/task-execution/turn-telemetry.ts
|
|
53
24
|
/** Read the turn input timing facts from a mailbox batch, oldest first. */
|
|
54
25
|
function turnInputTelemetry(messages) {
|
|
@@ -142,6 +113,34 @@ async function blockRunAutomation(conversationId, blocked) {
|
|
|
142
113
|
reason: blocked.missing
|
|
143
114
|
});
|
|
144
115
|
}
|
|
116
|
+
// src/chat/conversations/delivery-pause.ts
|
|
117
|
+
/** True when the Conversation is a root that delivers to a Location. */
|
|
118
|
+
function canPauseConversationDelivery(conversation) {
|
|
119
|
+
return isTopLevelKind(conversation.kind) && conversation.location !== void 0;
|
|
120
|
+
}
|
|
121
|
+
const rootConversation = (conversationId) => and(eq(juniorConversations.conversationId, conversationId), isNull(juniorConversations.parentConversationId));
|
|
122
|
+
/**
|
|
123
|
+
* Stop Delivery of a root's Event Turn replies to its Location. Returns false
|
|
124
|
+
* when Delivery was already paused or the root does not exist.
|
|
125
|
+
*/
|
|
126
|
+
async function pauseConversationDelivery(conversationId) {
|
|
127
|
+
return (await getSqlExecutor().db().update(juniorConversations).set({
|
|
128
|
+
deliveryPausedAt: /* @__PURE__ */ new Date(),
|
|
129
|
+
detailVersion: nextDetailVersion
|
|
130
|
+
}).where(and(rootConversation(conversationId), isNull(juniorConversations.deliveryPausedAt))).returning({ conversationId: juniorConversations.conversationId })).length > 0;
|
|
131
|
+
}
|
|
132
|
+
/** Deliver a root's Event Turn replies to its Location again. */
|
|
133
|
+
async function resumeConversationDelivery(conversationId) {
|
|
134
|
+
await getSqlExecutor().db().update(juniorConversations).set({
|
|
135
|
+
deliveryPausedAt: null,
|
|
136
|
+
detailVersion: nextDetailVersion
|
|
137
|
+
}).where(and(rootConversation(conversationId), isNotNull(juniorConversations.deliveryPausedAt)));
|
|
138
|
+
}
|
|
139
|
+
/** True while a root's Event Turn replies stay out of its Location. */
|
|
140
|
+
async function isConversationDeliveryPaused(conversationId) {
|
|
141
|
+
const [row] = await getSqlExecutor().db().select({ pausedAt: juniorConversations.deliveryPausedAt }).from(juniorConversations).where(eq(juniorConversations.conversationId, conversationId)).limit(1);
|
|
142
|
+
return Boolean(row?.pausedAt);
|
|
143
|
+
}
|
|
145
144
|
// src/chat/task-execution/assistant-message.ts
|
|
146
145
|
/** Store one assistant Message and its Agent history. */
|
|
147
146
|
async function commitAssistantMessage(args) {
|
|
@@ -229,10 +228,7 @@ async function steeringMessageFromWeb(message, actor) {
|
|
|
229
228
|
const storedAttachments = readMessageAttachments(message.input.attachments);
|
|
230
229
|
const reviewItemInput = await loadReviewItemInput(message.input.reviewItemChange);
|
|
231
230
|
return {
|
|
232
|
-
actor:
|
|
233
|
-
authorId: actor.userId,
|
|
234
|
-
...actor.fullName ? { authorName: actor.fullName } : void 0
|
|
235
|
-
},
|
|
231
|
+
actor: instructionActorFor(actor),
|
|
236
232
|
...reviewItemInput ? { kind: "runtime" } : void 0,
|
|
237
233
|
provenance: instructionProvenanceFor(actor),
|
|
238
234
|
text: reviewItemInput ?? message.input.text.trim(),
|
|
@@ -270,6 +266,29 @@ function createWebSteeringDrain(args) {
|
|
|
270
266
|
return accepted;
|
|
271
267
|
};
|
|
272
268
|
}
|
|
269
|
+
// src/chat/task-execution/turn-credentials.ts
|
|
270
|
+
/**
|
|
271
|
+
* Return a saved timer creator subject when it is still valid here. The
|
|
272
|
+
* timer's Watch belongs to this Conversation. It may also belong to an
|
|
273
|
+
* ancestor when `fromParent`: the input is a parent message that passed its
|
|
274
|
+
* sender check, so the child continues the work of the parent's timer Turn.
|
|
275
|
+
*/
|
|
276
|
+
async function verifiedTimerWatchSubject(conversationId, subject, fromParent) {
|
|
277
|
+
if (subject?.binding.type !== "timer-watch") return void 0;
|
|
278
|
+
const watchConversationId = subject.binding.conversationId;
|
|
279
|
+
if (watchConversationId !== conversationId && !(fromParent && (await readConversationLineage(conversationId)).some((entry) => entry.conversationId === watchConversationId))) return;
|
|
280
|
+
return verifyTimerWatchCredentialSubject({
|
|
281
|
+
conversationId: watchConversationId,
|
|
282
|
+
subject,
|
|
283
|
+
watchId: subject.binding.watchId
|
|
284
|
+
}) ? subject : void 0;
|
|
285
|
+
}
|
|
286
|
+
/** Return the delegated subject that every input of a batch carries, if any. */
|
|
287
|
+
function sharedDelegatedSubject(batch) {
|
|
288
|
+
const subjects = batch.map((entry) => entry.credentialContext && "subject" in entry.credentialContext ? entry.credentialContext.subject : void 0);
|
|
289
|
+
const first = subjects[0];
|
|
290
|
+
return first && subjects.every((subject) => isDeepStrictEqual(subject, first)) ? first : void 0;
|
|
291
|
+
}
|
|
273
292
|
// src/chat/task-execution/conversation-turn.ts
|
|
274
293
|
/** Run a mailbox Turn and store its assistant Messages. */
|
|
275
294
|
var conversation_turn_exports = /* @__PURE__ */ __exportAll({ createConversationTurnWorker: () => createConversationTurnWorker });
|
|
@@ -284,20 +303,6 @@ function captureConversationTurnFailure(args) {
|
|
|
284
303
|
});
|
|
285
304
|
return typeof eventId === "string" ? eventId : void 0;
|
|
286
305
|
}
|
|
287
|
-
/** Return the saved timer creator subject when it is still valid here. */
|
|
288
|
-
function resumedTimerWatchCredentialSubject(conversationId, subject) {
|
|
289
|
-
if (subject?.binding.type !== "timer-watch") return void 0;
|
|
290
|
-
return verifyTimerWatchCredentialSubject({
|
|
291
|
-
conversationId,
|
|
292
|
-
subject,
|
|
293
|
-
watchId: subject.binding.watchId
|
|
294
|
-
}) ? subject : void 0;
|
|
295
|
-
}
|
|
296
|
-
function sharedDelegatedSubject(batch) {
|
|
297
|
-
const subjects = batch.map((entry) => entry.credentialContext && "subject" in entry.credentialContext ? entry.credentialContext.subject : void 0);
|
|
298
|
-
const first = subjects[0];
|
|
299
|
-
return first && subjects.every((subject) => isDeepStrictEqual(subject, first)) ? first : void 0;
|
|
300
|
-
}
|
|
301
306
|
function hasLostTurnInputCommit(error) {
|
|
302
307
|
const cause = getConversationTurnBoundaryError(error)?.cause ?? error;
|
|
303
308
|
return isTurnInputCommitLostError(error) || isTurnInputCommitLostError(cause);
|
|
@@ -374,10 +379,12 @@ function createConversationTurnWorker(agentRunner, deliverMessage, deliverToPare
|
|
|
374
379
|
});
|
|
375
380
|
const savedTurn = isResume ? await getTurnRecord(context.conversationId, turnId) : void 0;
|
|
376
381
|
let savedMessageIsEvent = false;
|
|
382
|
+
let savedParentMessage = false;
|
|
377
383
|
if (isResume) {
|
|
378
384
|
const userMessage = getTurnUserMessage(conversation, turnId);
|
|
379
385
|
if (!userMessage) throw new Error(`Unable to locate the persisted user message for Turn "${turnId}"`);
|
|
380
386
|
savedMessageIsEvent = isEventConversationMessage(userMessage);
|
|
387
|
+
savedParentMessage = isParentMessageMeta(userMessage.meta);
|
|
381
388
|
turnInputFacts = turnInputFactsFromConversationMessage(userMessage, {
|
|
382
389
|
conversationId: context.conversationId,
|
|
383
390
|
location: storedConversation?.location,
|
|
@@ -402,8 +409,9 @@ function createConversationTurnWorker(agentRunner, deliverMessage, deliverToPare
|
|
|
402
409
|
const { actor, author } = turnInputFacts;
|
|
403
410
|
const instructionInputs = instructionForInputs(inputs);
|
|
404
411
|
const { text } = instructionInputs;
|
|
412
|
+
const instructionActor = instructionActorFor(actor);
|
|
405
413
|
let credentialSubject;
|
|
406
|
-
if (actor.platform === "system") credentialSubject = resolved.kind === "mailbox" ? timerWatchCredentialSubject(context.conversationId, resolved.batch.map((entry) => entry.message)) ??
|
|
414
|
+
if (actor.platform === "system") credentialSubject = resolved.kind === "mailbox" ? timerWatchCredentialSubject(context.conversationId, resolved.batch.map((entry) => entry.message)) ?? await verifiedTimerWatchSubject(context.conversationId, sharedDelegatedSubject(resolved.batch), resolved.batch.every((entry) => readParentMessage(entry.message))) : await verifiedTimerWatchSubject(context.conversationId, savedTurn?.credentialSubject, savedParentMessage);
|
|
407
415
|
const source = sourceFromTurnInput({
|
|
408
416
|
conversationId: context.conversationId,
|
|
409
417
|
source: turnInputFacts.source,
|
|
@@ -560,7 +568,13 @@ function createConversationTurnWorker(agentRunner, deliverMessage, deliverToPare
|
|
|
560
568
|
})) return await completeCancelledTurn();
|
|
561
569
|
await persistThreadStateById(context.conversationId, { conversation });
|
|
562
570
|
if (stopSignal?.aborted) return await completeCancelledTurn();
|
|
563
|
-
const
|
|
571
|
+
const childTurn = await childAgentTurnOptions({
|
|
572
|
+
conversationId: context.conversationId,
|
|
573
|
+
history: await loadProjection({ conversationId: context.conversationId }),
|
|
574
|
+
inputs: resolved.kind === "mailbox" ? resolved.batch.map((entry) => entry.message) : [],
|
|
575
|
+
savedParentMessage
|
|
576
|
+
});
|
|
577
|
+
const piMessages = childTurn.history;
|
|
564
578
|
failureCode = "agent_run_failed";
|
|
565
579
|
currentRunId = `conversation-run:${stableHex(turnId, String(startedAtMs))}`;
|
|
566
580
|
setTags({ runId: currentRunId });
|
|
@@ -571,6 +585,8 @@ function createConversationTurnWorker(agentRunner, deliverMessage, deliverToPare
|
|
|
571
585
|
runId: currentRunId,
|
|
572
586
|
instruction: {
|
|
573
587
|
...instructionInputs,
|
|
588
|
+
...instructionActor ? { actor: instructionActor } : void 0,
|
|
589
|
+
...childTurn.instruction,
|
|
574
590
|
storedAttachments: attachments,
|
|
575
591
|
context: await buildTurnThreadContext({
|
|
576
592
|
conversation,
|
|
@@ -581,6 +597,7 @@ function createConversationTurnWorker(agentRunner, deliverMessage, deliverToPare
|
|
|
581
597
|
})
|
|
582
598
|
},
|
|
583
599
|
history: piMessages,
|
|
600
|
+
...childTurn.run,
|
|
584
601
|
actor,
|
|
585
602
|
credentialContext: credentialContextForActor(actor, credentialSubject),
|
|
586
603
|
destination,
|
|
@@ -802,4 +819,4 @@ function createConversationTurnWorker(agentRunner, deliverMessage, deliverToPare
|
|
|
802
819
|
});
|
|
803
820
|
};
|
|
804
821
|
}
|
|
805
|
-
export {
|
|
822
|
+
export { resumeConversationDelivery as a, withTurnSpan as c, pauseConversationDelivery as i, createConversationTurnWorker as n, getTurnInputSpanAttributes as o, canPauseConversationDelivery as r, turnInputTelemetry as s, conversation_turn_exports as t };
|
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { L as escapeXml, a as getRuntimeMetadata, n as botConfig } from "./config-
|
|
3
|
-
import { U as isNativeIdentityProvider, _ as runBestEffort, h as logWarn, p as logException } from "./logging-
|
|
4
|
-
import { p as parseSlackUserId } from "./actor-
|
|
5
|
-
import {
|
|
1
|
+
import { Fa as getSlackClient, Z as getConversationPendingAuth, Zn as createUserTokenStore, ca as resolveBaseUrl, d as recordAuthorizationCompleted, oa as formatProviderLabel, sa as parseOAuthStatePayload, st as getTurnRecord, tr as resolvePluginOAuthAccount, u as recordAuthenticationLinked, wa as postSlackMessage } from "./projection-DEdP1q6f.js";
|
|
2
|
+
import { L as escapeXml, a as getRuntimeMetadata, n as botConfig } from "./config-CAXIpWQb.js";
|
|
3
|
+
import { U as isNativeIdentityProvider, _ as runBestEffort, h as logWarn, p as logException } from "./logging-DPLEa8Bn.js";
|
|
4
|
+
import { p as parseSlackUserId } from "./actor-D2iXzvlN.js";
|
|
5
|
+
import { L as findUserByVerifiedEmails, N as resolveActorIdentityId, V as upsertLinkedIdentity, s as getSqlExecutor } from "./db-COYOGzYS.js";
|
|
6
|
+
import { r as getStateAdapter, s as acquireActiveLock } from "./adapter-AgCNqqsG.js";
|
|
6
7
|
import { i as homeDir } from "./package-discovery-DJhGdS4c.js";
|
|
7
|
-
import { n as buildOAuthTokenRequest, r as parseOAuthTokenResponse, u as hasRequiredOAuthScope } from "./registry-
|
|
8
|
-
import { n as pluginCatalogRuntime } from "./catalog-runtime-
|
|
9
|
-
import { t as discoverSkills } from "./skills-
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import { o as readIdentityById } from "./viewer-CgiGjW10.js";
|
|
13
|
-
import { a as getStateAdapter } from "./state-CSuA2J1V.js";
|
|
8
|
+
import { n as buildOAuthTokenRequest, r as parseOAuthTokenResponse, u as hasRequiredOAuthScope } from "./registry-BTKmKM-r.js";
|
|
9
|
+
import { n as pluginCatalogRuntime } from "./catalog-runtime-DaBaHY7u.js";
|
|
10
|
+
import { t as discoverSkills } from "./skills-DpBQoeHV.js";
|
|
11
|
+
import { d as getMcpAuthSession, f as getMcpStoredOAuthCredentials, o as finalizeMcpAuthorization, p as putMcpStoredOAuthCredentials, s as deleteMcpAuthSession } from "./agent-runner-Ciet8_nn.js";
|
|
12
|
+
import { o as readIdentityById } from "./viewer-CAWfFo29.js";
|
|
14
13
|
import { t as readJuniorSecret } from "./secrets-DebYU866.js";
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
import { _ as getMcpProviderErrorAttributes } from "./service-account-
|
|
18
|
-
import {
|
|
19
|
-
import {
|
|
14
|
+
import { Ct as deleteWebAuthorization, gt as wakePausedTurn, ht as wakeAuthorizedTurn } from "./warmup-9ySPacF9.js";
|
|
15
|
+
import { a as getPersistedThreadState, c as coerceThreadConversationState } from "./turn-session-routing-BVZHBFCF.js";
|
|
16
|
+
import { _ as getMcpProviderErrorAttributes } from "./service-account-9OLNQMyz.js";
|
|
17
|
+
import { r as lookupSlackUserProfile } from "./users-BK3dbxZL.js";
|
|
18
|
+
import { i as readConnectedOAuthTokens, s as htmlCallbackResponse } from "./connections-Dy0hPdUq.js";
|
|
19
|
+
import { n as relayLocalOAuthCallback } from "./oauth-relay-DRzq73b6.js";
|
|
20
|
+
import * as z from "zod";
|
|
20
21
|
import path from "node:path";
|
|
21
22
|
import { createHmac, createSecretKey, timingSafeEqual } from "node:crypto";
|
|
22
|
-
import * as z from "zod";
|
|
23
23
|
import { pluginStoredTokensSchema } from "@sentry/junior-plugin-api";
|
|
24
24
|
import fs from "node:fs";
|
|
25
25
|
// src/handlers/mcp-oauth-callback.ts
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { v as __exportAll } from "./sentry-BRTJqumy.js";
|
|
2
|
-
import { i as getChatConfig } from "./config-
|
|
3
|
-
import { H as GOOGLE_IDENTITY_PROVIDER, W as normalizeIdentityEmail, h as logWarn } from "./logging-
|
|
4
|
-
import { a as isSlackUserId, d as parseSlackChannelReferenceId, f as parseSlackTeamId, s as parseActorUserId } from "./actor-
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
2
|
+
import { i as getChatConfig } from "./config-CAXIpWQb.js";
|
|
3
|
+
import { H as GOOGLE_IDENTITY_PROVIDER, W as normalizeIdentityEmail, h as logWarn } from "./logging-DPLEa8Bn.js";
|
|
4
|
+
import { a as isSlackUserId, d as parseSlackChannelReferenceId, f as parseSlackTeamId, s as parseActorUserId } from "./actor-D2iXzvlN.js";
|
|
5
|
+
import { C as isUserInstruction, E as juniorConversationAnnotations, M as juniorIdentities, N as juniorUsers, P as juniorDestinations, S as juniorConversationMetrics, j as juniorConversations, t as createJuniorSqlExecutor, v as juniorConversationParticipants, w as juniorConversationEvents, x as CONVERSATION_METRICS, y as juniorConversationBindings } from "./executor-BWmAgSyi.js";
|
|
6
|
+
import { c as newConversationEventSchema, h as usageSchema, l as encodeHistoryPayload, o as decodeStoredConversationEvent, r as conversationEventDataSchema, s as historyReplacementSchema } from "./history-IjdmO_r6.js";
|
|
7
|
+
import { l as withLock, r as getStateAdapter } from "./adapter-AgCNqqsG.js";
|
|
8
|
+
import * as z from "zod";
|
|
7
9
|
import { randomUUID } from "node:crypto";
|
|
8
10
|
import { and, asc, desc, eq, gt, gte, inArray, isNull, lt, lte, ne, or, sql } from "drizzle-orm";
|
|
9
11
|
import { destinationSchema, locationSchema, sourceSchema } from "@sentry/junior-plugin-api";
|
|
@@ -395,6 +397,167 @@ async function claimProviderConversation(executor, args) {
|
|
|
395
397
|
async function bindProviderConversation(executor, args) {
|
|
396
398
|
if (!await claimProviderConversation(executor, args)) throw new Error("Provider conversation is already bound to another conversation");
|
|
397
399
|
}
|
|
400
|
+
// src/chat/state/cache.ts
|
|
401
|
+
const MAX_CACHE_KEY_LENGTH = 512;
|
|
402
|
+
const LOAD_WAIT_MS = 1e4;
|
|
403
|
+
/**
|
|
404
|
+
* Create a cache in the state adapter under `junior:cache:{namespace}:`.
|
|
405
|
+
* Entries are wrapped, so `null` and `false` values are cache hits.
|
|
406
|
+
*/
|
|
407
|
+
function createCache(state, namespace) {
|
|
408
|
+
return { async getOrLoad(key, load, options) {
|
|
409
|
+
if (!key.trim()) throw new Error("Cache key is required");
|
|
410
|
+
if (key.length > MAX_CACHE_KEY_LENGTH) throw new Error("Cache key exceeds the maximum length");
|
|
411
|
+
const cacheKey = `junior:cache:${namespace}:${key}`;
|
|
412
|
+
const cached = async () => options?.refresh ? void 0 : await state.get(cacheKey) ?? void 0;
|
|
413
|
+
await state.connect();
|
|
414
|
+
const hit = await cached();
|
|
415
|
+
if (hit) return hit.value;
|
|
416
|
+
const attempt = await withLock(state, `${cacheKey}:load`, async () => {
|
|
417
|
+
const loadedMeanwhile = await cached();
|
|
418
|
+
if (loadedMeanwhile) return loadedMeanwhile.value;
|
|
419
|
+
const entry = await load();
|
|
420
|
+
if (entry.ttlMs !== void 0) {
|
|
421
|
+
if (!(entry.ttlMs > 0)) throw new Error("Cache ttlMs must be positive");
|
|
422
|
+
await state.set(cacheKey, { value: entry.value }, entry.ttlMs);
|
|
423
|
+
}
|
|
424
|
+
return entry.value;
|
|
425
|
+
}, {
|
|
426
|
+
keepAlive: true,
|
|
427
|
+
waitMs: LOAD_WAIT_MS
|
|
428
|
+
});
|
|
429
|
+
if (attempt.acquired) return attempt.value;
|
|
430
|
+
return (await load()).value;
|
|
431
|
+
} };
|
|
432
|
+
}
|
|
433
|
+
// src/chat/identities/user-cache.ts
|
|
434
|
+
/**
|
|
435
|
+
* Cache of each User and their user Identities. Every signed-in request
|
|
436
|
+
* resolves its viewer, and person cards read the people that a message
|
|
437
|
+
* links to, so these reads go to the state cache instead of the database.
|
|
438
|
+
*
|
|
439
|
+
* Every write to a cached column or to a user Identity must call
|
|
440
|
+
* `clearCachedUser`. The other columns of a User, such as the timezone or
|
|
441
|
+
* the customization, are not in the cache.
|
|
442
|
+
*/
|
|
443
|
+
const USER_TTL_MS = 864e5;
|
|
444
|
+
const MISSING_TTL_MS = 6e4;
|
|
445
|
+
const SETTLE_MS = 1e4;
|
|
446
|
+
const CACHE_NAMESPACE = "identities";
|
|
447
|
+
const cachedUserSchema = z.object({
|
|
448
|
+
identities: z.array(z.object({
|
|
449
|
+
avatarUrl: z.string().nullable(),
|
|
450
|
+
displayName: z.string().nullable(),
|
|
451
|
+
handle: z.string().nullable(),
|
|
452
|
+
id: z.string(),
|
|
453
|
+
provider: z.string(),
|
|
454
|
+
providerSubjectId: z.string(),
|
|
455
|
+
providerTenantId: z.string(),
|
|
456
|
+
updatedAt: z.coerce.date()
|
|
457
|
+
})),
|
|
458
|
+
user: z.object({
|
|
459
|
+
displayName: z.string().nullable(),
|
|
460
|
+
id: z.string(),
|
|
461
|
+
isAdmin: z.boolean(),
|
|
462
|
+
primaryEmail: z.string()
|
|
463
|
+
})
|
|
464
|
+
});
|
|
465
|
+
const versionSchema = z.object({
|
|
466
|
+
token: z.string(),
|
|
467
|
+
writtenAtMs: z.number()
|
|
468
|
+
});
|
|
469
|
+
function versionKey(userId) {
|
|
470
|
+
return `junior:cache:${CACHE_NAMESPACE}:version:${userId}`;
|
|
471
|
+
}
|
|
472
|
+
function cache() {
|
|
473
|
+
return createCache(getStateAdapter(), CACHE_NAMESPACE);
|
|
474
|
+
}
|
|
475
|
+
async function readVersion(userId) {
|
|
476
|
+
const state = getStateAdapter();
|
|
477
|
+
const stored = versionSchema.safeParse(await state.get(versionKey(userId)));
|
|
478
|
+
if (stored.success) return stored.data;
|
|
479
|
+
const created = {
|
|
480
|
+
token: randomUUID(),
|
|
481
|
+
writtenAtMs: 0
|
|
482
|
+
};
|
|
483
|
+
if (await state.setIfNotExists(versionKey(userId), created, 2 * USER_TTL_MS)) return created;
|
|
484
|
+
return versionSchema.parse(await state.get(versionKey(userId)));
|
|
485
|
+
}
|
|
486
|
+
async function loadUser(db, userId) {
|
|
487
|
+
const rows = await db.select({
|
|
488
|
+
avatarUrl: juniorIdentities.avatarUrl,
|
|
489
|
+
displayName: juniorIdentities.displayName,
|
|
490
|
+
handle: juniorIdentities.handle,
|
|
491
|
+
identityId: juniorIdentities.id,
|
|
492
|
+
provider: juniorIdentities.provider,
|
|
493
|
+
providerSubjectId: juniorIdentities.providerSubjectId,
|
|
494
|
+
providerTenantId: juniorIdentities.providerTenantId,
|
|
495
|
+
updatedAt: juniorIdentities.updatedAt,
|
|
496
|
+
userDisplayName: juniorUsers.displayName,
|
|
497
|
+
userId: juniorUsers.id,
|
|
498
|
+
userIsAdmin: juniorUsers.isAdmin,
|
|
499
|
+
userPrimaryEmail: juniorUsers.primaryEmail
|
|
500
|
+
}).from(juniorUsers).leftJoin(juniorIdentities, and(eq(juniorIdentities.userId, juniorUsers.id), eq(juniorIdentities.kind, "user"))).where(eq(juniorUsers.id, userId)).orderBy(asc(juniorIdentities.provider), asc(juniorIdentities.providerTenantId), asc(juniorIdentities.providerSubjectId));
|
|
501
|
+
const first = rows[0];
|
|
502
|
+
if (!first) return null;
|
|
503
|
+
return {
|
|
504
|
+
identities: rows.flatMap((row) => row.identityId && row.provider && row.providerSubjectId && row.providerTenantId !== null && row.updatedAt ? [{
|
|
505
|
+
avatarUrl: row.avatarUrl,
|
|
506
|
+
displayName: row.displayName,
|
|
507
|
+
handle: row.handle,
|
|
508
|
+
id: row.identityId,
|
|
509
|
+
provider: row.provider,
|
|
510
|
+
providerSubjectId: row.providerSubjectId,
|
|
511
|
+
providerTenantId: row.providerTenantId,
|
|
512
|
+
updatedAt: row.updatedAt
|
|
513
|
+
}] : []),
|
|
514
|
+
user: {
|
|
515
|
+
displayName: first.userDisplayName,
|
|
516
|
+
id: first.userId,
|
|
517
|
+
isAdmin: first.userIsAdmin,
|
|
518
|
+
primaryEmail: first.userPrimaryEmail
|
|
519
|
+
}
|
|
520
|
+
};
|
|
521
|
+
}
|
|
522
|
+
/** Read one User and their user Identities by User id. */
|
|
523
|
+
async function readCachedUser(db, userId) {
|
|
524
|
+
const version = await readVersion(userId);
|
|
525
|
+
const settled = Date.now() - version.writtenAtMs >= SETTLE_MS;
|
|
526
|
+
const cached = await cache().getOrLoad(`user:${userId}:${version.token}`, async () => {
|
|
527
|
+
const value = await loadUser(db, userId);
|
|
528
|
+
if (!settled) return { value };
|
|
529
|
+
return {
|
|
530
|
+
value,
|
|
531
|
+
ttlMs: value ? USER_TTL_MS : MISSING_TTL_MS
|
|
532
|
+
};
|
|
533
|
+
});
|
|
534
|
+
return cached ? cachedUserSchema.parse(cached) : void 0;
|
|
535
|
+
}
|
|
536
|
+
/**
|
|
537
|
+
* Read one User and their user Identities by normalized primary email. A
|
|
538
|
+
* primary email never changes, so the email to User id entry stays valid.
|
|
539
|
+
* A missing User is not cached: a first sign-in can create it at any time.
|
|
540
|
+
*/
|
|
541
|
+
async function readCachedUserByEmail(db, normalizedEmail) {
|
|
542
|
+
const userId = await cache().getOrLoad(emailKey(normalizedEmail), async () => {
|
|
543
|
+
const id = (await db.select({ id: juniorUsers.id }).from(juniorUsers).where(eq(juniorUsers.primaryEmailNormalized, normalizedEmail)).limit(1))[0]?.id ?? null;
|
|
544
|
+
return id ? {
|
|
545
|
+
value: id,
|
|
546
|
+
ttlMs: USER_TTL_MS
|
|
547
|
+
} : { value: null };
|
|
548
|
+
});
|
|
549
|
+
return userId ? await readCachedUser(db, userId) : void 0;
|
|
550
|
+
}
|
|
551
|
+
function emailKey(normalizedEmail) {
|
|
552
|
+
return `email:${normalizedEmail}`;
|
|
553
|
+
}
|
|
554
|
+
/** Clear the cached User after a write to their row or user Identities. */
|
|
555
|
+
async function clearCachedUser(userId) {
|
|
556
|
+
await getStateAdapter().set(versionKey(userId), {
|
|
557
|
+
token: randomUUID(),
|
|
558
|
+
writtenAtMs: Date.now()
|
|
559
|
+
}, 2 * USER_TTL_MS);
|
|
560
|
+
}
|
|
398
561
|
// src/chat/identities/sql.ts
|
|
399
562
|
function dateFromMs$1(ms) {
|
|
400
563
|
return new Date(ms);
|
|
@@ -482,6 +645,7 @@ async function upsertIdentityRecord(executor, identity, linkedUserId, nowMs) {
|
|
|
482
645
|
if (linkedUserId) throw new Error("Identity conflicts with linked user");
|
|
483
646
|
throw new Error("Identity upsert returned no row");
|
|
484
647
|
}
|
|
648
|
+
for (const changedUserId of /* @__PURE__ */ new Set([existing?.userId, row.userId])) if (changedUserId) await clearCachedUser(changedUserId);
|
|
485
649
|
if (!existing?.userId && row.userId && identity.kind === "user") await recordStartedConversationParticipants(executor, {
|
|
486
650
|
identityId: row.id,
|
|
487
651
|
userId: row.userId
|
|
@@ -537,6 +701,7 @@ async function deleteProviderIdentityForSlackUser(executor, slackTeamId, slackUs
|
|
|
537
701
|
/** Remove one exact provider identity owned by a user. */
|
|
538
702
|
async function deleteProviderIdentityForUser(executor, userId, provider, providerSubjectId) {
|
|
539
703
|
await executor.db().delete(juniorIdentities).where(and(eq(juniorIdentities.userId, userId), eq(juniorIdentities.provider, provider), eq(juniorIdentities.providerTenantId, ""), eq(juniorIdentities.providerSubjectId, providerSubjectId)));
|
|
704
|
+
await clearCachedUser(userId);
|
|
540
705
|
}
|
|
541
706
|
/**
|
|
542
707
|
* Save one Google sign-in. Link the Google identity to the user of its
|
|
@@ -1970,12 +2135,6 @@ function treeHasAnnotationKey(rootConversationId, key) {
|
|
|
1970
2135
|
where ${and(eq(annotated.rootConversationId, rootConversationId), annotationKeyMatches(key))}
|
|
1971
2136
|
)`;
|
|
1972
2137
|
}
|
|
1973
|
-
/** Return the IDs in `conversationIds` that have an Annotation with `key`. */
|
|
1974
|
-
async function conversationIdsWithAnnotation(db, conversationIds, key) {
|
|
1975
|
-
if (conversationIds.length === 0) return /* @__PURE__ */ new Set();
|
|
1976
|
-
const rows = await db.selectDistinct({ conversationId: juniorConversationAnnotations.conversationId }).from(juniorConversationAnnotations).where(and(inArray(juniorConversationAnnotations.conversationId, [...conversationIds]), annotationKeyMatches(key)));
|
|
1977
|
-
return new Set(rows.map((row) => row.conversationId));
|
|
1978
|
-
}
|
|
1979
2138
|
// src/chat/conversations/sql/message-search.ts
|
|
1980
2139
|
const EXCERPT_WITHOUT_QUERY_CHARS = 240;
|
|
1981
2140
|
var SqlConversationMessageSearchStore = class {
|
|
@@ -2100,4 +2259,4 @@ async function closeDb() {
|
|
|
2100
2259
|
current = void 0;
|
|
2101
2260
|
await previous?.db.close();
|
|
2102
2261
|
}
|
|
2103
|
-
export {
|
|
2262
|
+
export { resolveRootConversationId as $, startLocationThread as A, saveUserTimezone as B, isPersonInput as C, conversationKindFromRow as D, turnBehavior as E, deleteProviderIdentityForSlackUser as F, claimProviderConversation as G, clearCachedUser as H, deleteProviderIdentityForUser as I, addAgentTurnUsage as J, getConversationIdByProviderConversation as K, findUserByVerifiedEmails as L, findActorIdentityId as M, resolveActorIdentityId as N, locationFromRow as O, saveActorAvatar as P, hasAgentTurnUsage as Q, readUserTimezone as R, deliversFinalText as S, postsRunNotices as T, readCachedUserByEmail as U, upsertLinkedIdentity as V, createCache as W, agentTurnTotalTokens as X, agentTurnCostUsd as Y, agentTurnUsageSchema as Z, loadConversationSlackTenantIds as _, getConversationStore as a, parseDestination as at, createSqlStore as b, hasAnnotationKey as c, eventFromRow as d, rootConversationIsArchived as et, withConversationEventLock as f, setArchivedAt as g, readConversationTrees as h, getConversationMessageSearchStore as i, createSlackDestination as it, SYSTEM_IDENTITY_ID as j, setFirstConversationLocation as k, treeHasAnnotationKey as l, conversationDescendants as m, db_exports as n, nextDetailVersion as nt, getDb as o, requireSlackDestination as ot, conversationAncestors as p, parseSessionSource as q, getConversationEventStore as r, touchConversationDetail as rt, getSqlExecutor as s, sameDestination as st, closeDb as t, conversationDetailTouch as tt, createSqlConversationEventStore as u, lastMessageAtSql as v, isTopLevelKind as w, withConversationMutationLock as x, userMessageQueries as y, recordGoogleSignIn as z };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { _ as withScope } from "./sentry-BRTJqumy.js";
|
|
2
|
-
import "./config-
|
|
3
|
-
import { h as logWarn, p as logException } from "./logging-
|
|
2
|
+
import "./config-CAXIpWQb.js";
|
|
3
|
+
import { h as logWarn, p as logException } from "./logging-DPLEa8Bn.js";
|
|
4
4
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
5
5
|
import { sql } from "drizzle-orm";
|
|
6
6
|
import { bigint, boolean, check, date, doublePrecision, foreignKey, index, integer, jsonb, pgTable, primaryKey, text, timestamp, uniqueIndex, uuid } from "drizzle-orm/pg-core";
|
|
@@ -121,6 +121,7 @@ const juniorConversations = pgTable("junior_conversations", {
|
|
|
121
121
|
lastEnqueuedAt: timestamptz("last_enqueued_at"),
|
|
122
122
|
parentConversationId: text("parent_conversation_id").references(() => juniorConversations.conversationId),
|
|
123
123
|
kind: text("kind").$type(),
|
|
124
|
+
agentConfig: jsonb("agent_config_json").$type(),
|
|
124
125
|
archivedAt: timestamptz("archived_at"),
|
|
125
126
|
legacyChildArchivedAt: timestamptz("child_archived_at"),
|
|
126
127
|
forkedFromConversationId: text("forked_from_conversation_id").references(() => juniorConversations.conversationId, { onDelete: "set null" }),
|
|
@@ -180,6 +181,28 @@ const juniorAttachments = pgTable("junior_attachments", {
|
|
|
180
181
|
index("junior_attachments_provider_idx").on(table.conversationId, table.provider, table.providerId),
|
|
181
182
|
index("junior_attachments_gc_idx").on(table.storageProvider, table.deleteRequestedAt, table.createdAt)
|
|
182
183
|
]);
|
|
184
|
+
/**
|
|
185
|
+
* Browser uploads that wait for a web Message.
|
|
186
|
+
*
|
|
187
|
+
* A row binds one object key to the viewer, Conversation, and Message
|
|
188
|
+
* idempotency key that asked for it. A Message turns the upload into a
|
|
189
|
+
* `junior_attachments` row with the same id. Cleanup deletes the object of an
|
|
190
|
+
* upload that no Message used.
|
|
191
|
+
*/
|
|
192
|
+
const juniorAttachmentUploads = pgTable("junior_attachment_uploads", {
|
|
193
|
+
id: text("id").primaryKey(),
|
|
194
|
+
/** No foreign key: a new Conversation has no row until its first send. */
|
|
195
|
+
conversationId: text("conversation_id").notNull(),
|
|
196
|
+
userId: text("user_id").notNull(),
|
|
197
|
+
idempotencyKey: text("idempotency_key").notNull(),
|
|
198
|
+
storageProvider: text("storage_provider").notNull(),
|
|
199
|
+
storageKey: text("storage_key").notNull(),
|
|
200
|
+
filename: text("filename").notNull(),
|
|
201
|
+
contentType: text("content_type").notNull(),
|
|
202
|
+
/** Size that the browser declared and the upload target allows. */
|
|
203
|
+
bytes: integer("bytes").notNull(),
|
|
204
|
+
createdAt: timestamptz("created_at").notNull()
|
|
205
|
+
}, (table) => [index("junior_attachment_uploads_gc_idx").on(table.storageProvider, table.createdAt)]);
|
|
183
206
|
// src/db/schema/code.ts
|
|
184
207
|
/** Repository known to Junior through an installed code plugin. */
|
|
185
208
|
const juniorCodeRepositories = pgTable("junior_code_repositories", {
|
|
@@ -195,6 +218,7 @@ const juniorCodeChanges = pgTable("junior_code_changes", {
|
|
|
195
218
|
id: uuid("id").primaryKey(),
|
|
196
219
|
closedAt: timestamptz("closed_at"),
|
|
197
220
|
conversationIds: text("conversation_ids").array().notNull().default(sql`ARRAY[]::text[]`),
|
|
221
|
+
draft: boolean("draft").notNull().default(false),
|
|
198
222
|
/** Latest push, review, or comment by a person, from the code plugin. */
|
|
199
223
|
lastActivityAt: timestamptz("last_activity_at"),
|
|
200
224
|
mergedAt: timestamptz("merged_at"),
|
|
@@ -753,6 +777,7 @@ const juniorSnapshots = pgTable("junior_snapshots", {
|
|
|
753
777
|
// src/db/schema.ts
|
|
754
778
|
const juniorSqlSchema = {
|
|
755
779
|
juniorArtifacts,
|
|
780
|
+
juniorAttachmentUploads,
|
|
756
781
|
juniorAttachments,
|
|
757
782
|
juniorCodeChanges,
|
|
758
783
|
juniorCodeRepositories,
|
|
@@ -901,9 +926,18 @@ const POOL_MAX = 10;
|
|
|
901
926
|
function toWebSocketError(error, failure) {
|
|
902
927
|
if (error instanceof Error) return error;
|
|
903
928
|
const event = error ?? {};
|
|
904
|
-
const
|
|
929
|
+
const cause = event.error instanceof Error ? event.error : void 0;
|
|
930
|
+
const reason = typeof event.message === "string" && event.message || cause?.message || cause && `${cause.name} (no message)` || typeof event.type === "string" && event.type || String(error);
|
|
905
931
|
return new Error(`WebSocket ${failure}: ${reason}`, event.error === void 0 ? void 0 : { cause: event.error });
|
|
906
932
|
}
|
|
933
|
+
function warnWebSocketFailure(name, error, failure) {
|
|
934
|
+
const reported = toWebSocketError(error, failure);
|
|
935
|
+
logWarn(name, {
|
|
936
|
+
"app.db.driver": "neon",
|
|
937
|
+
"error.type": reported.name,
|
|
938
|
+
"exception.message": reported.message
|
|
939
|
+
});
|
|
940
|
+
}
|
|
907
941
|
/**
|
|
908
942
|
* Sends a pool query over Neon's SQL-over-HTTP endpoint when no idle
|
|
909
943
|
* WebSocket client is free.
|
|
@@ -959,7 +993,7 @@ var OverflowPool = class extends Pool {
|
|
|
959
993
|
client.release();
|
|
960
994
|
return;
|
|
961
995
|
}
|
|
962
|
-
|
|
996
|
+
warnWebSocketFailure("db.pool.client.connect_failed", error, "connect failed");
|
|
963
997
|
});
|
|
964
998
|
}
|
|
965
999
|
/** Keep every pool query in `callback` on WebSocket. */
|
|
@@ -1120,12 +1154,7 @@ function createNeonJuniorSqlExecutor(args) {
|
|
|
1120
1154
|
dispatcher
|
|
1121
1155
|
});
|
|
1122
1156
|
pool.on("error", (error) => {
|
|
1123
|
-
|
|
1124
|
-
logWarn("db.pool.client.failed", {
|
|
1125
|
-
"app.db.driver": "neon",
|
|
1126
|
-
"error.type": failure.name,
|
|
1127
|
-
"exception.message": failure.message
|
|
1128
|
-
});
|
|
1157
|
+
warnWebSocketFailure("db.pool.client.failed", error, "idle client failed");
|
|
1129
1158
|
});
|
|
1130
1159
|
if (onInfo) forwardInfoMessages(pool, onInfo);
|
|
1131
1160
|
return new NeonExecutor(pool, dispatcher);
|
|
@@ -1265,4 +1294,4 @@ function createJuniorSqlExecutor(args) {
|
|
|
1265
1294
|
statementTimeoutMs
|
|
1266
1295
|
});
|
|
1267
1296
|
}
|
|
1268
|
-
export {
|
|
1297
|
+
export { juniorAttachments as A, isUserInstruction as C, juniorCodeChanges as D, juniorConversationAnnotations as E, juniorArtifacts as F, juniorIdentities as M, juniorUsers as N, juniorCodeRepositories as O, juniorDestinations as P, juniorConversationMetrics as S, juniorApiTokens as T, juniorConversationReadPositions as _, juniorPushSubscriptions as a, juniorConversationBriefs as b, juniorReviewItemSlackCards as c, juniorAutomationVersions as d, juniorAutomations as f, juniorAgentInvocations as g, juniorAgentBindings as h, juniorWorkspaces as i, juniorConversations as j, juniorAttachmentUploads as k, juniorReviewItems as l, juniorLocationConfigurations as m, juniorSnapshots as n, juniorReviewItemAssignees as o, juniorStats as p, juniorWorkspaceRepos as r, juniorReviewItemConversations as s, createJuniorSqlExecutor as t, juniorAutomationRuns as u, juniorConversationParticipants as v, juniorConversationEvents as w, CONVERSATION_METRICS as x, juniorConversationBindings as y };
|