@sentry/junior 0.292.0 → 0.294.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-Cigb1MTr.js → adapter-DxLhJEnO.js} +1 -1
- package/dist/{admin-BO9V7vnn.js → admin-vt8aSiCD.js} +2 -2
- package/dist/{agent-runner-BuH7EHrX.js → agent-runner-DJu7w6mI.js} +318 -162
- package/dist/api/schema.d.ts +2 -2
- package/dist/api/schema.js +5 -5
- package/dist/api.d.ts +1 -1
- package/dist/api.js +65 -40
- package/dist/{app-C47PT68y.d.ts → app--a5RLOrr.d.ts} +4 -2
- package/dist/app.d.ts +1 -1
- package/dist/app.js +454 -435
- package/dist/{assistant-reply-ZjLRGHm2.js → assistant-reply-iTtEdDyc.js} +1 -1
- package/dist/{automation-CrsYnvdV.js → automation-BM-OBsKW.js} +72 -23
- package/dist/{background-compaction-queue-CqZBPe9g.js → background-compaction-queue-D2j-0XkH.js} +4 -4
- package/dist/{briefs-DZrhXJss.js → briefs-JOAoCb6d.js} +3 -3
- package/dist/{catalog-runtime-Cj9I0dco.js → catalog-runtime-CLMA9AXd.js} +1 -1
- package/dist/cli/chat.js +15 -15
- package/dist/cli/check.js +3 -3
- package/dist/cli/main.js +3 -3
- package/dist/cli/plugins.js +4 -4
- package/dist/cli/snapshot-create.js +4 -4
- package/dist/cli/upgrade.d.ts +1 -1
- package/dist/cli/upgrade.js +7 -74
- package/dist/{config-BerMjSVL.js → config-mIZeGEWv.js} +17 -7
- package/dist/{connections-BWmTOVPB.js → connections-XhdVg7OR.js} +6 -6
- package/dist/{conversation-CtjR1Zcx.js → conversation-CDWejM4R.js} +1 -0
- package/dist/{conversation-pending-messages-Cd7ShwBs.js → conversation-pending-messages-Dh2tfbaw.js} +5 -2
- package/dist/{conversation-privacy-BMfbOUCo.js → conversation-privacy-C6h-X2cZ.js} +1 -1
- package/dist/{credential-sync-DZDij2CU.js → credential-sync-zigBlXS3.js} +13 -13
- package/dist/{db-BlfjuqzW.js → db--xuNV7g6.js} +99 -6
- package/dist/{db-7glZCI18.d.ts → db-DV5AbcGM.d.ts} +8 -6
- package/dist/{executor-ikZvFaMD.js → executor-BItuRqAR.js} +87 -21
- package/dist/instrumentation.js +2 -2
- package/dist/{logging-CTCH5jOy.js → logging-Cb6MGvdt.js} +1 -1
- package/dist/{message-C1ID1tKi.js → message-BTGgSmaH.js} +9 -9
- package/dist/nitro.d.ts +1 -1
- package/dist/nitro.js +2 -2
- package/dist/{oauth-callback-server-CStBgDU7.js → oauth-callback-server-Dvh1aOIi.js} +2 -2
- package/dist/{projection-DY93nCfX.js → projection-DLQgfO5N.js} +61 -52
- package/dist/{prompt-exicBZeb.js → prompt-qp_LdxLX.js} +5 -6
- package/dist/{registry-X_xdFY9L.js → registry-MtwokaqW.js} +1 -1
- package/dist/{resolve-B9dYN-nS.js → resolve-BnJA0UNE.js} +3 -3
- package/dist/{result-CC8bV8Fl.js → result-ChL-1KyW.js} +8 -8
- package/dist/{runner-D44qp4rc.js → runner-BONN7Dp2.js} +8 -8
- package/dist/{sandbox-egress-signals-BrH6DWkt.js → sandbox-egress-signals-nmlmI5Ab.js} +1 -1
- package/dist/{schema-CC2RxDAV.d.ts → schema-DgvcyJ1y.d.ts} +283 -45
- package/dist/{schema-CVV5r-qP.js → schema-yr0ccDni.js} +29 -4
- package/dist/{service-account-DoNZuJb-.js → service-account-Bd0lBaGr.js} +3 -3
- package/dist/{service-account-89JZHWCE.js → service-account-kio5nXSD.js} +3 -3
- package/dist/{session-stop-DNucbmPf.js → session-stop-CeCXL3j9.js} +20 -41
- package/dist/{skills-BeUfmYXL.js → skills-e3DDNlKO.js} +10 -9
- package/dist/{spawn-CIAcfcvZ.js → spawn--cRxITWQ.js} +5 -5
- package/dist/{stop-Ckd3735h.js → stop-Iai5N2PU.js} +34 -29
- package/dist/{store-CS0xoqXW.js → store-C8LsaJwS.js} +3 -3
- package/dist/{task-runner-DjjHCX_m.js → task-runner-Dw7exu0-.js} +65 -90
- package/dist/{turn-failure-response-D0bwI462.js → turn-failure-response-BqTTx3XG.js} +8 -8
- package/dist/{validation-Cvx_AupF.js → validation-BrGahtnv.js} +1 -1
- package/dist/{version-BrDx4Fzc.js → version-Bdqhx8Qh.js} +1 -1
- package/dist/version.js +1 -1
- package/dist/{viewer-4CxdwLLQ.js → viewer-CjRFHR5U.js} +3 -3
- package/dist/{warmup-B62hd4lD.js → warmup-DuxCtzKC.js} +104 -26
- package/dist/{work-Cu315oJl.js → work-BWBG1EGV.js} +11 -11
- package/dist/{worker-4ClZu6ry.js → worker-DAnBIVMs.js} +6 -6
- package/migrations/0062_plugin_report_index.sql +1 -20
- package/migrations/0078_plugin_conversation_index.sql +1 -20
- package/migrations/0079_conversation_event_author_index.sql +1 -20
- package/migrations/0080_conversation_event_latest_message_indexes.sql +2 -27
- package/migrations/0090_guardian_review_time_index.sql +1 -20
- package/migrations/0091_conversation_participant_unsubscribed_index.sql +1 -20
- package/migrations/0096_automation_task_kind.sql +75 -0
- package/migrations/0097_conversation_kind_automation.sql +6 -0
- package/migrations/meta/0096_snapshot.json +4490 -0
- package/migrations/meta/0097_snapshot.json +4490 -0
- package/migrations/meta/_journal.json +14 -0
- package/package.json +5 -5
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import { An as resolvePluginOAuthAccount, En as createUserTokenStore,
|
|
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-
|
|
1
|
+
import { An as resolvePluginOAuthAccount, En as createUserTokenStore, Fi as resolveBaseUrl, Ni as formatProviderLabel, Pi as parseOAuthStatePayload, Yi as postSlackMessage, Z as getConversationPendingAuth, d as recordAuthorizationCompleted, oa as getSlackClient, ot as getTurnRecord, u as recordAuthenticationLinked } from "./projection-DLQgfO5N.js";
|
|
2
|
+
import { L as escapeXml, a as getRuntimeMetadata, n as botConfig } from "./config-mIZeGEWv.js";
|
|
3
|
+
import { U as isNativeIdentityProvider, _ as runBestEffort, h as logWarn, p as logException } from "./logging-Cb6MGvdt.js";
|
|
4
4
|
import { p as parseSlackUserId } from "./actor-6jsm_v96.js";
|
|
5
|
-
import {
|
|
5
|
+
import { B as upsertLinkedIdentity, I as findUserByVerifiedEmails, M as resolveActorIdentityId, s as getSqlExecutor } from "./db--xuNV7g6.js";
|
|
6
6
|
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 { It as wakeAuthorizedTurn, Lt as wakePausedTurn, Yt as deleteWebAuthorization, a as finalizeMcpAuthorization, d as getMcpStoredOAuthCredentials, f as putMcpStoredOAuthCredentials, o as deleteMcpAuthSession, u as getMcpAuthSession, y as lookupSlackUserProfile } from "./agent-runner-
|
|
7
|
+
import { n as buildOAuthTokenRequest, r as parseOAuthTokenResponse, u as hasRequiredOAuthScope } from "./registry-MtwokaqW.js";
|
|
8
|
+
import { n as pluginCatalogRuntime } from "./catalog-runtime-CLMA9AXd.js";
|
|
9
|
+
import { t as discoverSkills } from "./skills-e3DDNlKO.js";
|
|
10
|
+
import { It as wakeAuthorizedTurn, Lt as wakePausedTurn, Yt as deleteWebAuthorization, a as finalizeMcpAuthorization, d as getMcpStoredOAuthCredentials, f as putMcpStoredOAuthCredentials, o as deleteMcpAuthSession, u as getMcpAuthSession, y as lookupSlackUserProfile } from "./agent-runner-DJu7w6mI.js";
|
|
11
11
|
import { r as acquireActiveLock } from "./locks-D-0h111u.js";
|
|
12
|
-
import { o as readIdentityById } from "./viewer-
|
|
13
|
-
import { r as getStateAdapter } from "./adapter-
|
|
14
|
-
import {
|
|
15
|
-
import { _ as getMcpProviderErrorAttributes } from "./service-account-
|
|
16
|
-
import { i as readConnectedOAuthTokens, s as htmlCallbackResponse } from "./connections-
|
|
12
|
+
import { o as readIdentityById } from "./viewer-CjRFHR5U.js";
|
|
13
|
+
import { r as getStateAdapter } from "./adapter-DxLhJEnO.js";
|
|
14
|
+
import { gt as coerceThreadConversationState, pt as getPersistedThreadState } from "./task-runner-Dw7exu0-.js";
|
|
15
|
+
import { _ as getMcpProviderErrorAttributes } from "./service-account-kio5nXSD.js";
|
|
16
|
+
import { i as readConnectedOAuthTokens, s as htmlCallbackResponse } from "./connections-XhdVg7OR.js";
|
|
17
17
|
import { n as relayLocalOAuthCallback } from "./oauth-relay-D6xxVywK.js";
|
|
18
18
|
import path from "node:path";
|
|
19
19
|
import { createHmac, createSecretKey, timingSafeEqual } from "node:crypto";
|
|
@@ -1,8 +1,8 @@
|
|
|
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-
|
|
2
|
+
import { i as getChatConfig } from "./config-mIZeGEWv.js";
|
|
3
|
+
import { H as GOOGLE_IDENTITY_PROVIDER, W as normalizeIdentityEmail, h as logWarn } from "./logging-Cb6MGvdt.js";
|
|
4
4
|
import { a as isSlackUserId, d as parseSlackChannelReferenceId, f as parseSlackTeamId, s as parseActorUserId } from "./actor-6jsm_v96.js";
|
|
5
|
-
import { A as juniorConversations, E as juniorConversationAnnotations, M as juniorUsers, N as juniorDestinations, S as juniorConversationMetrics, j as juniorIdentities, t as createJuniorSqlExecutor, v as juniorConversationParticipants, w as juniorConversationEvents, x as CONVERSATION_METRICS, y as juniorConversationBindings } from "./executor-
|
|
5
|
+
import { A as juniorConversations, E as juniorConversationAnnotations, M as juniorUsers, N as juniorDestinations, S as juniorConversationMetrics, j as juniorIdentities, t as createJuniorSqlExecutor, v as juniorConversationParticipants, w as juniorConversationEvents, x as CONVERSATION_METRICS, y as juniorConversationBindings } from "./executor-BItuRqAR.js";
|
|
6
6
|
import { d as historyReplacementSchema, f as newConversationEventSchema, p as encodeHistoryPayload, s as conversationEventDataSchema, u as decodeStoredConversationEvent, y as usageSchema } from "./media-BepyEUNm.js";
|
|
7
7
|
import { randomUUID } from "node:crypto";
|
|
8
8
|
import { and, asc, desc, eq, gt, gte, inArray, isNull, lt, lte, ne, or, sql } from "drizzle-orm";
|
|
@@ -838,12 +838,105 @@ async function ensureConversationRow(executor, conversationId, atMs, options = {
|
|
|
838
838
|
}
|
|
839
839
|
});
|
|
840
840
|
}
|
|
841
|
+
const CONVERSATION_KINDS = /* @__PURE__ */ new Set([
|
|
842
|
+
"root",
|
|
843
|
+
"automation",
|
|
844
|
+
"thread",
|
|
845
|
+
"task"
|
|
846
|
+
]);
|
|
841
847
|
/** Decode a stored kind. A null kind comes from a writer of an older deploy. */
|
|
842
848
|
function conversationKindFromRow(row) {
|
|
843
849
|
const kind = row.kind ?? (row.parentConversationId ? "task" : "root");
|
|
844
|
-
if (kind
|
|
850
|
+
if (!CONVERSATION_KINDS.has(kind)) throw new Error("Conversation record kind is invalid");
|
|
845
851
|
return kind;
|
|
846
852
|
}
|
|
853
|
+
// src/chat/conversations/kind-behavior.ts
|
|
854
|
+
const ROOT = {
|
|
855
|
+
delivery: "location",
|
|
856
|
+
promptMode: "conversation",
|
|
857
|
+
gated: false,
|
|
858
|
+
tools: {
|
|
859
|
+
agents: "children",
|
|
860
|
+
reviewDesk: true,
|
|
861
|
+
subscriptions: true,
|
|
862
|
+
userCustomization: true,
|
|
863
|
+
reportBlocked: false,
|
|
864
|
+
noReply: true,
|
|
865
|
+
finishAutomationRun: false
|
|
866
|
+
}
|
|
867
|
+
};
|
|
868
|
+
const PERSON_IN_THREAD = {
|
|
869
|
+
...ROOT,
|
|
870
|
+
tools: {
|
|
871
|
+
...ROOT.tools,
|
|
872
|
+
agents: "none"
|
|
873
|
+
}
|
|
874
|
+
};
|
|
875
|
+
const AGENT_IN_CHILD = {
|
|
876
|
+
delivery: "conversation",
|
|
877
|
+
promptMode: "child_agent",
|
|
878
|
+
gated: false,
|
|
879
|
+
tools: {
|
|
880
|
+
agents: "children_and_parent",
|
|
881
|
+
reviewDesk: false,
|
|
882
|
+
subscriptions: false,
|
|
883
|
+
userCustomization: false,
|
|
884
|
+
reportBlocked: true,
|
|
885
|
+
noReply: true,
|
|
886
|
+
finishAutomationRun: false
|
|
887
|
+
}
|
|
888
|
+
};
|
|
889
|
+
const AUTOMATION_RUN = {
|
|
890
|
+
delivery: "conversation",
|
|
891
|
+
promptMode: "automation",
|
|
892
|
+
gated: true,
|
|
893
|
+
tools: {
|
|
894
|
+
...ROOT.tools,
|
|
895
|
+
noReply: false,
|
|
896
|
+
finishAutomationRun: true
|
|
897
|
+
}
|
|
898
|
+
};
|
|
899
|
+
/**
|
|
900
|
+
* Return the behavior of one Turn. `automationRun` marks a Scheduled or Event
|
|
901
|
+
* automation run. It is a temporary bridge until Conversation kind
|
|
902
|
+
* `automation` replaces it.
|
|
903
|
+
*
|
|
904
|
+
* TODO(dcramer): Remove `automationRun` when kind `automation` ships.
|
|
905
|
+
*/
|
|
906
|
+
function turnBehavior(args) {
|
|
907
|
+
if (args.automationRun) return AUTOMATION_RUN;
|
|
908
|
+
if (isTopLevelKind(args.kind)) return ROOT;
|
|
909
|
+
if (!args.personInput) return AGENT_IN_CHILD;
|
|
910
|
+
if (args.kind === "thread") return PERSON_IN_THREAD;
|
|
911
|
+
throw new Error("A task Conversation cannot have a person's input");
|
|
912
|
+
}
|
|
913
|
+
/** Return whether a Conversation of this kind has no parent. */
|
|
914
|
+
function isTopLevelKind(kind) {
|
|
915
|
+
return kind === "root" || kind === "automation";
|
|
916
|
+
}
|
|
917
|
+
/** Return whether a person sent input from this Source. */
|
|
918
|
+
function isPersonInput(source) {
|
|
919
|
+
return source === "web" || source === "slack";
|
|
920
|
+
}
|
|
921
|
+
/**
|
|
922
|
+
* Return whether the runtime delivers the final response of a Slack or
|
|
923
|
+
* dispatch run. Only root Conversations reach these paths, so only an
|
|
924
|
+
* Automation run keeps its final response in the Conversation. A dispatch
|
|
925
|
+
* with no outcomes delivers nothing.
|
|
926
|
+
*/
|
|
927
|
+
function deliversFinalText(dispatch) {
|
|
928
|
+
return dispatch?.outcomes?.length !== 0 && !dispatch?.declaresResult;
|
|
929
|
+
}
|
|
930
|
+
/**
|
|
931
|
+
* Return whether the runtime may post a failure reply or a status notice,
|
|
932
|
+
* such as an auth prompt, for a run outside `finishedRunReply`. The rule is
|
|
933
|
+
* the same as for a final response. A chat Turn may post, also in a thread
|
|
934
|
+
* that an Automation Conversation owns. An Automation run posts only a
|
|
935
|
+
* declared message; its failed execution shows on the Automation.
|
|
936
|
+
*/
|
|
937
|
+
function postsRunNotices(dispatch) {
|
|
938
|
+
return deliversFinalText(dispatch);
|
|
939
|
+
}
|
|
847
940
|
// src/chat/conversations/sql/store.ts
|
|
848
941
|
const CONVERSATION_MUTATION_LOCK_PREFIX = "junior_conversation";
|
|
849
942
|
/** Serialize one conversation's durable mutations inside a SQL transaction. */
|
|
@@ -1173,7 +1266,7 @@ var SqlStore = class {
|
|
|
1173
1266
|
/** Upsert the conversation row while preserving previously discovered nullable metadata fields. */
|
|
1174
1267
|
async upsertConversation(args) {
|
|
1175
1268
|
const { conversation } = args;
|
|
1176
|
-
if (conversation.kind
|
|
1269
|
+
if (isTopLevelKind(conversation.kind) !== !conversation.parentConversationId) throw new Error(`Conversation ${conversation.conversationId} kind does not match its parent`);
|
|
1177
1270
|
if (!conversation.parentConversationId && !conversation.destination) {
|
|
1178
1271
|
if (!await this.get({ conversationId: conversation.conversationId })) throw new Error(`Conversation ${conversation.conversationId} requires a destination at create`);
|
|
1179
1272
|
}
|
|
@@ -1941,4 +2034,4 @@ async function closeDb() {
|
|
|
1941
2034
|
current = void 0;
|
|
1942
2035
|
await previous?.db.close();
|
|
1943
2036
|
}
|
|
1944
|
-
export {
|
|
2037
|
+
export { nextDetailVersion as $, SYSTEM_IDENTITY_ID as A, upsertLinkedIdentity as B, isTopLevelKind as C, locationFromRow as D, conversationKindFromRow as E, deleteProviderIdentityForUser as F, addAgentTurnUsage as G, claimProviderConversation as H, findUserByVerifiedEmails as I, agentTurnUsageSchema as J, agentTurnCostUsd as K, readUserTimezone as L, resolveActorIdentityId as M, saveActorAvatar as N, setFirstConversationLocation as O, deleteProviderIdentityForSlackUser as P, conversationDetailTouch as Q, recordGoogleSignIn as R, isPersonInput as S, turnBehavior as T, getConversationIdByProviderConversation as U, bindProviderConversation as V, parseSessionSource as W, resolveRootConversationId as X, hasAgentTurnUsage as Y, rootConversationIsArchived as Z, setArchivedAt as _, getConversationStore as a, withConversationMutationLock as b, conversationIdsWithAnnotation as c, createSqlConversationEventStore as d, touchConversationDetail as et, eventFromRow as f, readConversationTrees as g, conversationDescendants as h, getConversationMessageSearchStore as i, sameDestination as it, findActorIdentityId as j, startLocationThread as k, hasAnnotationKey as l, conversationAncestors as m, db_exports as n, parseDestination as nt, getDb as o, withConversationEventLock as p, agentTurnTotalTokens as q, getConversationEventStore as r, requireSlackDestination as rt, getSqlExecutor as s, closeDb as t, createSlackDestination as tt, treeHasAnnotationKey as u, loadConversationSlackTenantIds as v, postsRunNotices as w, deliversFinalText as x, createSqlStore as y, saveUserTimezone as z };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import "./schema-
|
|
1
|
+
import "./schema-DgvcyJ1y.js";
|
|
2
2
|
import * as z from "zod";
|
|
3
3
|
import "drizzle-orm";
|
|
4
4
|
import { Destination, Source, locationSchema } from "@sentry/junior-plugin-api";
|
|
@@ -53,11 +53,13 @@ type Usage = z.output<typeof usageSchema>;
|
|
|
53
53
|
type AgentTurnUsage = Usage;
|
|
54
54
|
type ConversationSource = "api" | "internal" | "local" | "plugin" | "event" | "scheduler" | "slack" | "web";
|
|
55
55
|
/**
|
|
56
|
-
* Where a Conversation sits in its tree. A root
|
|
57
|
-
* child that people can message. A Task is a child that
|
|
58
|
-
* messages. A Conversation never changes kind.
|
|
56
|
+
* Where a Conversation sits in its tree. A root and an Automation run have no
|
|
57
|
+
* parent. A Thread is a child that people can message. A Task is a child that
|
|
58
|
+
* only its parent messages. A Conversation never changes kind.
|
|
59
59
|
*/
|
|
60
|
-
type ConversationKind = "root" | "thread" | "task";
|
|
60
|
+
type ConversationKind = "root" | "automation" | "thread" | "task";
|
|
61
|
+
/** The kind of a Conversation that has a parent. */
|
|
62
|
+
type ChildConversationKind = "thread" | "task";
|
|
61
63
|
type ConversationStatus = "paused" | "failed" | "idle" | "pending" | "running";
|
|
62
64
|
/** Cumulative duration and usage that one Run reported. */
|
|
63
65
|
interface ConversationRunMetrics {
|
|
@@ -137,7 +139,7 @@ interface ConversationStore {
|
|
|
137
139
|
*/
|
|
138
140
|
createChild(args: {
|
|
139
141
|
childConversationId: string;
|
|
140
|
-
kind:
|
|
142
|
+
kind: ChildConversationKind;
|
|
141
143
|
parentConversationId: string;
|
|
142
144
|
nowMs?: number;
|
|
143
145
|
source?: ConversationSource;
|
|
@@ -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-mIZeGEWv.js";
|
|
3
|
+
import { h as logWarn, p as logException } from "./logging-Cb6MGvdt.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";
|
|
@@ -140,8 +140,8 @@ const juniorConversations = pgTable("junior_conversations", {
|
|
|
140
140
|
metricRunId: text("metric_run_id"),
|
|
141
141
|
detailVersion: integer("detail_version").notNull().default(0)
|
|
142
142
|
}, (table) => [
|
|
143
|
-
check("junior_conversations_kind_check", sql`${table.kind} in ('root', 'thread', 'task')`),
|
|
144
|
-
check("junior_conversations_kind_parent_check", sql`${table.kind} is null or ((${table.kind}
|
|
143
|
+
check("junior_conversations_kind_check", sql`${table.kind} in ('root', 'automation', 'thread', 'task')`),
|
|
144
|
+
check("junior_conversations_kind_parent_check", sql`${table.kind} is null or ((${table.kind} in ('root', 'automation')) = (${table.parentConversationId} is null))`),
|
|
145
145
|
index("junior_conversations_last_activity_idx").on(table.lastActivityAt.desc(), table.conversationId),
|
|
146
146
|
index("junior_conversations_active_idx").using("btree", sql`coalesce(${table.executionUpdatedAt}, ${table.updatedAt})`, table.conversationId).where(sql`${table.executionStatus} <> 'idle'`),
|
|
147
147
|
index("junior_conversations_destination_activity_idx").on(table.destinationId, table.lastActivityAt.desc()),
|
|
@@ -503,10 +503,11 @@ const juniorStats = pgTable("junior_stats", {
|
|
|
503
503
|
* One row per Automation of either kind. `record` holds the fields that have
|
|
504
504
|
* no column. Each write also copies the nested fields that queries filter or
|
|
505
505
|
* search on into columns: `team_id`, `channel_id`, `creator_slack_user_id`,
|
|
506
|
-
* `instruction`, and the event trigger `namespace` and
|
|
507
|
-
*
|
|
508
|
-
*
|
|
509
|
-
* `identifier is
|
|
506
|
+
* the task `instruction` or `skill`, and the event trigger `namespace` and
|
|
507
|
+
* `identifier`. Exactly one of `instruction` and `skill` is set, by the task
|
|
508
|
+
* kind. A skill's context is only in `record`. An event trigger with no
|
|
509
|
+
* identifier runs for every resource of its namespace, so its `identifier` is
|
|
510
|
+
* null. The match index finds those rows with `identifier is null`.
|
|
510
511
|
*/
|
|
511
512
|
const juniorAutomations = pgTable("junior_automations", {
|
|
512
513
|
id: text("id").primaryKey(),
|
|
@@ -520,7 +521,10 @@ const juniorAutomations = pgTable("junior_automations", {
|
|
|
520
521
|
/** Why a run blocked this Automation, until its creator resumes it. */
|
|
521
522
|
statusReason: text("status_reason"),
|
|
522
523
|
title: text("title"),
|
|
523
|
-
instruction
|
|
524
|
+
/** The instruction of an instruction task. Null for a skill task. */
|
|
525
|
+
instruction: text("instruction"),
|
|
526
|
+
/** The skill of a skill task. Null for an instruction task. */
|
|
527
|
+
skill: text("skill"),
|
|
524
528
|
createdAtMs: bigint("created_at_ms", { mode: "number" }).notNull(),
|
|
525
529
|
nextRunAtMs: bigint("next_run_at_ms", { mode: "number" }),
|
|
526
530
|
runNowAtMs: bigint("run_now_at_ms", { mode: "number" }),
|
|
@@ -530,12 +534,14 @@ const juniorAutomations = pgTable("junior_automations", {
|
|
|
530
534
|
}, (table) => [
|
|
531
535
|
check("junior_automations_kind_check", sql`${table.kind} in ('scheduled', 'event')`),
|
|
532
536
|
check("junior_automations_status_check", sql`${table.status} in ('active', 'blocked', 'paused', 'completed', 'deleted')`),
|
|
537
|
+
check("junior_automations_task_check", sql`(${table.instruction} is null) <> (${table.skill} is null)`),
|
|
533
538
|
check("junior_automations_record_check", sql`jsonb_typeof(${table.record}) = 'object'`),
|
|
534
539
|
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')`),
|
|
535
540
|
index("junior_automations_team_idx").on(table.teamId, table.createdAtMs, table.id).where(sql`${table.status} <> 'deleted'`),
|
|
536
541
|
index("junior_automations_creator_identity_idx").on(table.creatorIdentityId, table.createdAtMs, table.id),
|
|
537
542
|
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`),
|
|
538
543
|
index("junior_automations_next_run_due_idx").on(table.nextRunAtMs, table.createdAtMs, table.id).where(sql`${table.status} = 'active' AND ${table.nextRunAtMs} IS NOT NULL`),
|
|
544
|
+
index("junior_automations_skill_idx").on(table.skill, table.createdAtMs, table.id).where(sql`${table.status} <> 'deleted' AND ${table.skill} IS NOT NULL`),
|
|
539
545
|
index("junior_automations_match_idx").on(table.namespace, table.identifier, table.createdAtMs, table.id).where(sql`${table.status} <> 'deleted'`)
|
|
540
546
|
]);
|
|
541
547
|
// src/db/schema/automation-versions.ts
|
|
@@ -789,6 +795,29 @@ const LOCK_TIMEOUT_MS = 5e3;
|
|
|
789
795
|
const LOCK_ATTEMPTS = 5;
|
|
790
796
|
const LOCK_RETRY_DELAY_MS = 5e3;
|
|
791
797
|
const LOCK_NOT_AVAILABLE = "55P03";
|
|
798
|
+
const MIGRATION_LOCK_POLL_MS = 1e3;
|
|
799
|
+
const CONCURRENT_STATEMENT = /^(?:CREATE (?:UNIQUE )?INDEX|DROP INDEX|REINDEX)\b[^;]*\bCONCURRENTLY\b/i;
|
|
800
|
+
const CONCURRENT_INDEX = /^CREATE (?:UNIQUE )?INDEX CONCURRENTLY IF NOT EXISTS "([a-z0-9_]+)" /i;
|
|
801
|
+
/** Statement text without its leading comment lines. */
|
|
802
|
+
function sqlOf(statement) {
|
|
803
|
+
return statement.split("\n").filter((line) => !line.trim().startsWith("--")).join("\n").trim();
|
|
804
|
+
}
|
|
805
|
+
/**
|
|
806
|
+
* Index builds of a migration that only builds indexes concurrently, or
|
|
807
|
+
* undefined for a migration that runs in a transaction.
|
|
808
|
+
*/
|
|
809
|
+
function concurrentIndexes(tag, statements) {
|
|
810
|
+
const sql = statements.map(sqlOf).filter(Boolean);
|
|
811
|
+
if (!sql.some((statement) => CONCURRENT_STATEMENT.test(statement))) return;
|
|
812
|
+
return sql.map((statement) => {
|
|
813
|
+
const name = CONCURRENT_INDEX.exec(statement)?.[1];
|
|
814
|
+
if (!name) throw new Error(`Migration ${tag}: a migration that uses CONCURRENTLY must contain only CREATE [UNIQUE] INDEX CONCURRENTLY IF NOT EXISTS "name" statements.`);
|
|
815
|
+
return {
|
|
816
|
+
name,
|
|
817
|
+
statement
|
|
818
|
+
};
|
|
819
|
+
});
|
|
820
|
+
}
|
|
792
821
|
function isLockTimeout(error) {
|
|
793
822
|
let current = error;
|
|
794
823
|
for (let depth = 0; current instanceof Error && depth < 5; depth += 1) {
|
|
@@ -797,6 +826,15 @@ function isLockTimeout(error) {
|
|
|
797
826
|
}
|
|
798
827
|
return false;
|
|
799
828
|
}
|
|
829
|
+
/**
|
|
830
|
+
* Wait for the migration lock by polling `pg_try_advisory_lock`. A session
|
|
831
|
+
* blocked in `pg_advisory_lock` holds a snapshot, and `CREATE INDEX
|
|
832
|
+
* CONCURRENTLY` waits for every older snapshot, so a second migrator that
|
|
833
|
+
* blocked there would deadlock with the build of the first.
|
|
834
|
+
*/
|
|
835
|
+
async function waitForMigrationLock(tryLock) {
|
|
836
|
+
while (!await tryLock()) await new Promise((resolve) => setTimeout(resolve, MIGRATION_LOCK_POLL_MS));
|
|
837
|
+
}
|
|
800
838
|
async function retryOnLockTimeout(tag, apply) {
|
|
801
839
|
for (let attempt = 1;; attempt += 1) try {
|
|
802
840
|
await apply();
|
|
@@ -817,7 +855,8 @@ async function retryOnLockTimeout(tag, apply) {
|
|
|
817
855
|
* (drizzle-orm#3249), so locks from earlier migrations stay held while later
|
|
818
856
|
* migrations wait for theirs. That can deadlock with live traffic. This keeps
|
|
819
857
|
* Drizzle's journal table and skip rule, so existing databases are unaffected.
|
|
820
|
-
* A migration that waits too long for a lock rolls back and runs again.
|
|
858
|
+
* A migration that waits too long for a lock rolls back and runs again. A
|
|
859
|
+
* migration that only builds indexes concurrently runs outside a transaction.
|
|
821
860
|
*/
|
|
822
861
|
async function applyMigrations(executor, config) {
|
|
823
862
|
const schema = config.migrationsSchema ?? "drizzle";
|
|
@@ -828,11 +867,23 @@ async function applyMigrations(executor, config) {
|
|
|
828
867
|
const appliedAt = Number(last?.createdAt ?? 0);
|
|
829
868
|
for (const migration of readMigrationFiles(config)) {
|
|
830
869
|
if (migration.folderMillis <= appliedAt) continue;
|
|
831
|
-
|
|
870
|
+
const tag = String(migration.folderMillis);
|
|
871
|
+
const recordApplied = () => executor.execute(`INSERT INTO ${table} (hash, created_at) VALUES ($1, $2)`, [migration.hash, migration.folderMillis]);
|
|
872
|
+
const indexes = concurrentIndexes(tag, migration.sql);
|
|
873
|
+
if (indexes) {
|
|
874
|
+
for (const { name, statement } of indexes) {
|
|
875
|
+
const [state] = await executor.query(`SELECT indisvalid AND indisready AS usable FROM pg_index WHERE indexrelid = to_regclass($1)`, [name]);
|
|
876
|
+
if (state && !state.usable) await executor.execute(`DROP INDEX CONCURRENTLY IF EXISTS "${name}"`);
|
|
877
|
+
await executor.execute(statement);
|
|
878
|
+
}
|
|
879
|
+
await recordApplied();
|
|
880
|
+
continue;
|
|
881
|
+
}
|
|
882
|
+
await retryOnLockTimeout(tag, async () => {
|
|
832
883
|
await executor.transaction(async () => {
|
|
833
884
|
await executor.execute(`SET LOCAL lock_timeout = ${LOCK_TIMEOUT_MS}`);
|
|
834
885
|
for (const statement of migration.sql) await executor.execute(statement);
|
|
835
|
-
await
|
|
886
|
+
await recordApplied();
|
|
836
887
|
});
|
|
837
888
|
});
|
|
838
889
|
}
|
|
@@ -860,11 +911,13 @@ var OverflowPool = class extends Pool {
|
|
|
860
911
|
connectionString: args.connectionString,
|
|
861
912
|
max: POOL_MAX,
|
|
862
913
|
idleTimeoutMillis: 6e4,
|
|
914
|
+
min: 1,
|
|
863
915
|
statement_timeout: args.statementTimeoutMs
|
|
864
916
|
});
|
|
865
917
|
this.sql = neon(args.connectionString, { fullResults: true });
|
|
866
918
|
this.dispatcher = args.dispatcher;
|
|
867
919
|
this.statementTimeoutMs = args.statementTimeoutMs;
|
|
920
|
+
this.on("remove", () => this.reconnectWhenEmpty());
|
|
868
921
|
}
|
|
869
922
|
query(input, values, callback) {
|
|
870
923
|
const query = typeof input === "string" ? { text: input } : input;
|
|
@@ -877,13 +930,22 @@ var OverflowPool = class extends Pool {
|
|
|
877
930
|
growInBackground() {
|
|
878
931
|
setImmediate(() => {
|
|
879
932
|
if (this.ending || this.idleCount > 0 || this.totalCount >= POOL_MAX) return;
|
|
880
|
-
this.
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
933
|
+
this.openClient();
|
|
934
|
+
});
|
|
935
|
+
}
|
|
936
|
+
reconnectWhenEmpty() {
|
|
937
|
+
setImmediate(() => {
|
|
938
|
+
if (this.ending || this.totalCount > 0) return;
|
|
939
|
+
this.openClient();
|
|
940
|
+
});
|
|
941
|
+
}
|
|
942
|
+
openClient() {
|
|
943
|
+
this.connect((error, client) => {
|
|
944
|
+
if (client) {
|
|
945
|
+
client.release();
|
|
946
|
+
return;
|
|
947
|
+
}
|
|
948
|
+
logException(error, "db.pool.client.connect_failed", { "app.db.driver": "neon" });
|
|
887
949
|
});
|
|
888
950
|
}
|
|
889
951
|
/** Keep every pool query in `callback` on WebSocket. */
|
|
@@ -1019,7 +1081,9 @@ var NeonExecutor = class {
|
|
|
1019
1081
|
const client = await this.pool.connect();
|
|
1020
1082
|
const lockName = `junior:migrate:${migrationTable}`;
|
|
1021
1083
|
try {
|
|
1022
|
-
await
|
|
1084
|
+
await waitForMigrationLock(async () => {
|
|
1085
|
+
return (await client.query("SELECT pg_try_advisory_lock(hashtext($1)) AS locked", [lockName])).rows[0]?.locked === true;
|
|
1086
|
+
});
|
|
1023
1087
|
return await this.pool.onWebSocket(callback);
|
|
1024
1088
|
} finally {
|
|
1025
1089
|
client.release(true);
|
|
@@ -1138,7 +1202,9 @@ var PostgresExecutor = class {
|
|
|
1138
1202
|
const client = await this.pool.connect();
|
|
1139
1203
|
const lockName = `junior:migrate:${migrationTable}`;
|
|
1140
1204
|
try {
|
|
1141
|
-
await
|
|
1205
|
+
await waitForMigrationLock(async () => {
|
|
1206
|
+
return (await client.query("SELECT pg_try_advisory_lock(hashtext($1)) AS locked", [lockName])).rows[0]?.locked === true;
|
|
1207
|
+
});
|
|
1142
1208
|
return await callback();
|
|
1143
1209
|
} finally {
|
|
1144
1210
|
client.release(true);
|
package/dist/instrumentation.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { a as getClient, c as init, i as getActiveSpan, o as getGlobalScope, p as spanToJSON, s as getTraceData } from "./sentry-BRTJqumy.js";
|
|
2
|
-
import { B as getDeploymentTelemetryAttributes, z as getDeploymentServiceVersion } from "./logging-
|
|
3
|
-
import { n as getCurrentConversationPrivacy } from "./conversation-privacy-
|
|
2
|
+
import { B as getDeploymentTelemetryAttributes, z as getDeploymentServiceVersion } from "./logging-Cb6MGvdt.js";
|
|
3
|
+
import { n as getCurrentConversationPrivacy } from "./conversation-privacy-C6h-X2cZ.js";
|
|
4
4
|
import { n as redactSandboxEgressProxyPath } from "./proxy-path-BHYoKZdq.js";
|
|
5
5
|
import { t as consumePrivateTraceResultMarker } from "./private-trace-result-CE7_lEdq.js";
|
|
6
6
|
import { n as promoteHttpRouteName, r as routeNameMiddleware, t as nameRequestRoute } from "./sentry-route-name-BhwWnfqj.js";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { _ as withScope, d as setTag, f as setUser, h as startSpan, i as getActiveSpan, l as logger, n as captureMessage, p as spanToJSON, s as getTraceData, t as captureException } from "./sentry-BRTJqumy.js";
|
|
2
|
-
import { t as JUNIOR_VERSION } from "./version-
|
|
2
|
+
import { t as JUNIOR_VERSION } from "./version-Bdqhx8Qh.js";
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import { styleText } from "node:util";
|
|
5
5
|
import { ConfigError, configureSync, getConfig, getLogger } from "@logtape/logtape";
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { v as __exportAll } from "./sentry-BRTJqumy.js";
|
|
2
|
-
import {
|
|
3
|
-
import { n as botConfig } from "./config-
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { I as PARENT_AGENT_TARGET, v as getActiveAgentInvocationForConversation } from "./turn-failure-response-
|
|
7
|
-
import { G as admitAutomatedTurn, S as EVENT_WAIT_MS, V as postAutomatedTurnLimitNoticeForConversation } from "./session-stop-
|
|
8
|
-
import { r as appendAndEnqueueInboundMessage } from "./store-
|
|
9
|
-
import { a as enqueueAgentInvocation, c as createAgentInvocationForMessage, u as findChildAgentConversationId } from "./work-
|
|
10
|
-
import { r as enqueueAgentMessageToParent } from "./result-
|
|
2
|
+
import { Cn as renderUntrustedTag, Za as canAccessConversation, eo as readConversationAccessFromSql } from "./projection-DLQgfO5N.js";
|
|
3
|
+
import { n as botConfig } from "./config-mIZeGEWv.js";
|
|
4
|
+
import { A as SYSTEM_IDENTITY_ID, a as getConversationStore, o as getDb } from "./db--xuNV7g6.js";
|
|
5
|
+
import { hn as toolInvocationDestination, in as AgentMessageTargetError, mn as actorFromRun, nn as AgentMessagePausedError } from "./agent-runner-DJu7w6mI.js";
|
|
6
|
+
import { I as PARENT_AGENT_TARGET, v as getActiveAgentInvocationForConversation } from "./turn-failure-response-BqTTx3XG.js";
|
|
7
|
+
import { G as admitAutomatedTurn, S as EVENT_WAIT_MS, V as postAutomatedTurnLimitNoticeForConversation } from "./session-stop-CeCXL3j9.js";
|
|
8
|
+
import { r as appendAndEnqueueInboundMessage } from "./store-C8LsaJwS.js";
|
|
9
|
+
import { a as enqueueAgentInvocation, c as createAgentInvocationForMessage, u as findChildAgentConversationId } from "./work-BWBG1EGV.js";
|
|
10
|
+
import { r as enqueueAgentMessageToParent } from "./result-ChL-1KyW.js";
|
|
11
11
|
// src/chat/agent-invocations/top-level-message.ts
|
|
12
12
|
const AGENT_MESSAGE_EVENT_NAMESPACE = "junior";
|
|
13
13
|
/** Event type of a message from another top-level agent. */
|
package/dist/nitro.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { i as JuniorDashboardOptions } from "./app
|
|
1
|
+
import { i as JuniorDashboardOptions } from "./app--a5RLOrr.js";
|
|
2
2
|
import { n as JuniorPluginSet } from "./plugins-DtmjkTza.js";
|
|
3
3
|
import { withSentryConfig as withSentryConfig$1 } from "@sentry/nitro";
|
|
4
4
|
type SentryNitroConfig = Parameters<typeof withSentryConfig$1>[0];
|
package/dist/nitro.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { A as JUNIOR_CONTEXT_COMPACTION_CALLBACK_ROUTE, D as JUNIOR_AUTO_ARCHIVE_CRON_SCHEDULE, F as JUNIOR_RETENTION_CRON_SCHEDULE, I as JUNIOR_RETENTION_ROUTE, L as JUNIOR_WORKSPACE_SNAPSHOT_JOB_CALLBACK_ROUTE, M as JUNIOR_HEARTBEAT_CRON_SCHEDULE, N as JUNIOR_HEARTBEAT_ROUTE, O as JUNIOR_AUTO_ARCHIVE_ROUTE, P as JUNIOR_PLUGIN_TASK_CALLBACK_ROUTE, j as JUNIOR_CONVERSATION_WORK_CALLBACK_ROUTE, k as JUNIOR_CACHE_WARMUP_CALLBACK_ROUTE, z as getDeploymentServiceVersion } from "./logging-
|
|
1
|
+
import { A as JUNIOR_CONTEXT_COMPACTION_CALLBACK_ROUTE, D as JUNIOR_AUTO_ARCHIVE_CRON_SCHEDULE, F as JUNIOR_RETENTION_CRON_SCHEDULE, I as JUNIOR_RETENTION_ROUTE, L as JUNIOR_WORKSPACE_SNAPSHOT_JOB_CALLBACK_ROUTE, M as JUNIOR_HEARTBEAT_CRON_SCHEDULE, N as JUNIOR_HEARTBEAT_ROUTE, O as JUNIOR_AUTO_ARCHIVE_ROUTE, P as JUNIOR_PLUGIN_TASK_CALLBACK_ROUTE, j as JUNIOR_CONVERSATION_WORK_CALLBACK_ROUTE, k as JUNIOR_CACHE_WARMUP_CALLBACK_ROUTE, z as getDeploymentServiceVersion } from "./logging-Cb6MGvdt.js";
|
|
2
2
|
import { d as resolvePackageDir, t as discoverInstalledPluginPackageContent, u as isValidPackageName } from "./package-discovery-DJhGdS4c.js";
|
|
3
|
-
import { S as CACHE_WARMUP_QUEUE_TOPIC, _ as resolveConversationWorkQueueTopic, a as PLUGIN_TASK_QUEUE_TOPIC, f as WORKSPACE_SNAPSHOT_JOB_QUEUE_TOPIC, t as BACKGROUND_COMPACTION_QUEUE_TOPIC } from "./background-compaction-queue-
|
|
3
|
+
import { S as CACHE_WARMUP_QUEUE_TOPIC, _ as resolveConversationWorkQueueTopic, a as PLUGIN_TASK_QUEUE_TOPIC, f as WORKSPACE_SNAPSHOT_JOB_QUEUE_TOPIC, t as BACKGROUND_COMPACTION_QUEUE_TOPIC } from "./background-compaction-queue-D2j-0XkH.js";
|
|
4
4
|
import { a as pluginRuntimeRegistrationsFromPluginSet, r as pluginCatalogConfigFromPluginSet } from "./plugins-HYh_JOdw.js";
|
|
5
5
|
import { n as loadPluginSetFromModule, r as resolvePluginModule } from "./plugin-module-Cf5gVPWP.js";
|
|
6
6
|
import path from "node:path";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { En as createUserTokenStore } from "./projection-
|
|
2
|
-
import { a as GET, n as syncLocalOAuthCredential, r as GET$1 } from "./credential-sync-
|
|
1
|
+
import { En as createUserTokenStore } from "./projection-DLQgfO5N.js";
|
|
2
|
+
import { a as GET, n as syncLocalOAuthCredential, r as GET$1 } from "./credential-sync-zigBlXS3.js";
|
|
3
3
|
import { createServer } from "node:http";
|
|
4
4
|
// src/chat/local/oauth-callback-server.ts
|
|
5
5
|
const LOCAL_OAUTH_TIMEOUT_MS = 6e5;
|