@sentry/junior 0.132.0 → 0.133.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. package/dist/{agent-hooks-ONXOJDR6.js → agent-hooks-5BUIXVIX.js} +9 -9
  2. package/dist/api.js +16 -16
  3. package/dist/app.js +84 -37
  4. package/dist/{catalog-runtime-BATAY4R7.js → catalog-runtime-VGB3DWXZ.js} +5 -5
  5. package/dist/chat/config.d.ts +2 -0
  6. package/dist/chat/conversations/projection.d.ts +3 -1
  7. package/dist/chat/conversations/sql/bindings.d.ts +13 -0
  8. package/dist/chat/conversations/sql/store.d.ts +3 -0
  9. package/dist/chat/conversations/store.d.ts +15 -0
  10. package/dist/chat/runtime/reply-executor.d.ts +1 -0
  11. package/dist/chat/runtime/slack-runtime.d.ts +2 -0
  12. package/dist/chat/slack/dispatch-turn.d.ts +1 -0
  13. package/dist/chat/slack/reply.d.ts +1 -1
  14. package/dist/{chunk-JYQAE2ZU.js → chunk-5ZAZHLIW.js} +1 -1
  15. package/dist/{chunk-G3WYA2RS.js → chunk-AH5HTUYX.js} +1 -1
  16. package/dist/{chunk-GPXVDJML.js → chunk-ECUILEUX.js} +24 -15
  17. package/dist/{chunk-GOEZU33G.js → chunk-EJRJWBKG.js} +1 -1
  18. package/dist/{chunk-WEJIS7OC.js → chunk-FX6BLEDP.js} +1 -1
  19. package/dist/{chunk-V44FFBO3.js → chunk-HJ4KDO4N.js} +1 -1
  20. package/dist/{chunk-SKWIIUS7.js → chunk-HTGXUNEC.js} +7 -7
  21. package/dist/{chunk-2425Q4OR.js → chunk-IKO5LFIU.js} +1 -1
  22. package/dist/{chunk-BKE47OOW.js → chunk-IVTHTAVK.js} +2 -2
  23. package/dist/{chunk-B7IY6SVJ.js → chunk-JLN4XSPR.js} +1 -1
  24. package/dist/{chunk-NNHUGGO4.js → chunk-LDRO4OQ4.js} +19 -3
  25. package/dist/{chunk-WYQP7QSB.js → chunk-LNYNTR27.js} +101 -61
  26. package/dist/{chunk-KB2M27DL.js → chunk-QWGZ273D.js} +78 -36
  27. package/dist/{chunk-ZMV2YBT6.js → chunk-T5FPIBU2.js} +14 -14
  28. package/dist/{chunk-AW5Z3T7V.js → chunk-TBVS7GBE.js} +4 -4
  29. package/dist/{chunk-ODIP5CEM.js → chunk-TLN54TOQ.js} +1 -1
  30. package/dist/{chunk-GTKNPQNN.js → chunk-TU7P77FI.js} +36 -24
  31. package/dist/{chunk-U76PS7AT.js → chunk-V365UVCU.js} +2 -2
  32. package/dist/{chunk-ISNRPCPG.js → chunk-VL7OYSHD.js} +1 -1
  33. package/dist/{chunk-O2UXPUVQ.js → chunk-VQA25AL4.js} +6 -6
  34. package/dist/{chunk-ALDPUN3Z.js → chunk-WHEMUEXT.js} +5 -5
  35. package/dist/{chunk-XN656LB4.js → chunk-XTQGVNM3.js} +3 -3
  36. package/dist/cli/chat.js +24 -24
  37. package/dist/cli/check.js +6 -6
  38. package/dist/cli/init.js +1 -0
  39. package/dist/cli/plugins.js +12 -12
  40. package/dist/cli/snapshot-create.js +9 -9
  41. package/dist/cli/upgrade.js +9 -8
  42. package/dist/db/executor.d.ts +2 -1
  43. package/dist/db/neon.d.ts +1 -0
  44. package/dist/db/postgres.d.ts +1 -0
  45. package/dist/db/schema/conversation-bindings.d.ts +110 -0
  46. package/dist/db/schema.d.ts +111 -1
  47. package/dist/{db-QFFZACXF.js → db-RICMPUFT.js} +7 -7
  48. package/dist/instrumentation.js +4 -4
  49. package/dist/nitro.js +2 -2
  50. package/dist/{oauth-callback-server-5WXLD533.js → oauth-callback-server-YFVS4SAX.js} +17 -17
  51. package/dist/{runner-Y3LTUNAA.js → runner-A3LVGZR6.js} +11 -11
  52. package/dist/{skills-7M5C24GM.js → skills-P7Q6Z6PN.js} +6 -6
  53. package/dist/{validation-MRILMYDI.js → validation-RYHOWBET.js} +6 -6
  54. package/dist/version.js +1 -1
  55. package/migrations/0018_curvy_excalibur.sql +12 -0
  56. package/migrations/meta/0018_snapshot.json +1756 -0
  57. package/migrations/meta/_journal.json +8 -1
  58. package/package.json +5 -5
@@ -7,6 +7,7 @@ import {
7
7
  } from "./chunk-HX236W2U.js";
8
8
  import {
9
9
  agentHistoryItemSchema,
10
+ bindProviderConversation,
10
11
  contextProvenance,
11
12
  createSqlConversationEventStore,
12
13
  getConversationEventStore,
@@ -16,17 +17,17 @@ import {
16
17
  instructionProvenanceFor,
17
18
  sanitizePostgresJson,
18
19
  withConversationEventLock
19
- } from "./chunk-WYQP7QSB.js";
20
+ } from "./chunk-LNYNTR27.js";
20
21
  import {
21
22
  getStateAdapter,
22
23
  sleep
23
- } from "./chunk-ODIP5CEM.js";
24
+ } from "./chunk-TLN54TOQ.js";
24
25
  import {
25
26
  botConfig,
26
27
  escapeXml,
27
28
  resolveGatewayModel,
28
29
  unwrapCurrentInstruction
29
- } from "./chunk-NNHUGGO4.js";
30
+ } from "./chunk-LDRO4OQ4.js";
30
31
  import {
31
32
  toStoredSlackActor
32
33
  } from "./chunk-HZF5P5UN.js";
@@ -41,7 +42,7 @@ import {
41
42
  setSpanAttributes,
42
43
  toOptionalNumber,
43
44
  toOptionalString
44
- } from "./chunk-GOEZU33G.js";
45
+ } from "./chunk-EJRJWBKG.js";
45
46
 
46
47
  // src/chat/turn-context-tag.ts
47
48
  var TURN_CONTEXT_TAG = "runtime-turn-context";
@@ -997,17 +998,19 @@ async function commitAcceptedReply(args) {
997
998
  executor,
998
999
  args.conversationId,
999
1000
  async () => executor.transaction(async () => {
1000
- const agentMessage = normalizeDurableMessage(args.agentMessage);
1001
- await createSqlConversationEventStore(executor).append(
1002
- args.conversationId,
1003
- [
1004
- {
1005
- idempotencyKey: `message:${args.conversationMessageId}:agent`,
1006
- data: historyItemFromPiMessage(agentMessage, contextProvenance),
1007
- createdAtMs: messageTimestamp(agentMessage)
1008
- }
1009
- ]
1010
- );
1001
+ if (args.agentMessage) {
1002
+ const agentMessage = normalizeDurableMessage(args.agentMessage);
1003
+ await createSqlConversationEventStore(executor).append(
1004
+ args.conversationId,
1005
+ [
1006
+ {
1007
+ idempotencyKey: `message:${args.conversationMessageId}:agent`,
1008
+ data: historyItemFromPiMessage(agentMessage, contextProvenance),
1009
+ createdAtMs: messageTimestamp(agentMessage)
1010
+ }
1011
+ ]
1012
+ );
1013
+ }
1011
1014
  await appendConversationMessages(
1012
1015
  createSqlConversationEventStore(executor),
1013
1016
  {
@@ -1016,6 +1019,12 @@ async function commitAcceptedReply(args) {
1016
1019
  ...args.repliedAtMs === void 0 ? {} : { repliedAtMs: args.repliedAtMs }
1017
1020
  }
1018
1021
  );
1022
+ for (const binding of args.providerConversationBindings ?? []) {
1023
+ await bindProviderConversation(executor, {
1024
+ conversationId: args.conversationId,
1025
+ ...binding
1026
+ });
1027
+ }
1019
1028
  })
1020
1029
  );
1021
1030
  }
@@ -9,7 +9,7 @@ import {
9
9
  } from "./chunk-6GWA276C.js";
10
10
  import {
11
11
  getDeploymentTelemetryAttributes
12
- } from "./chunk-WEJIS7OC.js";
12
+ } from "./chunk-FX6BLEDP.js";
13
13
 
14
14
  // src/chat/logging.ts
15
15
  import path from "path";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  JUNIOR_VERSION
3
- } from "./chunk-2425Q4OR.js";
3
+ } from "./chunk-IKO5LFIU.js";
4
4
 
5
5
  // src/deployment.ts
6
6
  var JUNIOR_HEARTBEAT_ROUTE = "/api/internal/heartbeat";
@@ -5,7 +5,7 @@ import {
5
5
  logInfo,
6
6
  logWarn,
7
7
  setSpanAttributes
8
- } from "./chunk-GOEZU33G.js";
8
+ } from "./chunk-EJRJWBKG.js";
9
9
  import {
10
10
  discoverInstalledPluginPackageContent,
11
11
  normalizePluginPackageNames
@@ -6,25 +6,25 @@ import {
6
6
  isDmChannel,
7
7
  normalizeSlackConversationId,
8
8
  withSlackRetries
9
- } from "./chunk-ALDPUN3Z.js";
9
+ } from "./chunk-WHEMUEXT.js";
10
10
  import {
11
11
  getDb,
12
12
  parseDestination
13
- } from "./chunk-WYQP7QSB.js";
13
+ } from "./chunk-LNYNTR27.js";
14
14
  import {
15
15
  acquireActiveLock,
16
16
  getStateAdapter,
17
17
  sleep
18
- } from "./chunk-ODIP5CEM.js";
18
+ } from "./chunk-TLN54TOQ.js";
19
19
  import {
20
20
  normalizeSlackEmojiName
21
- } from "./chunk-NNHUGGO4.js";
21
+ } from "./chunk-LDRO4OQ4.js";
22
22
  import {
23
23
  pluginCatalogRuntime
24
- } from "./chunk-B7IY6SVJ.js";
24
+ } from "./chunk-JLN4XSPR.js";
25
25
  import {
26
26
  fetchWithBoundedOAuthErrorBodies
27
- } from "./chunk-V44FFBO3.js";
27
+ } from "./chunk-HJ4KDO4N.js";
28
28
  import {
29
29
  parseSlackMessageTs,
30
30
  parseSlackUserId
@@ -33,7 +33,7 @@ import {
33
33
  isRecord,
34
34
  logInfo,
35
35
  logWarn
36
- } from "./chunk-GOEZU33G.js";
36
+ } from "./chunk-EJRJWBKG.js";
37
37
 
38
38
  // src/chat/capabilities/router.ts
39
39
  var ProviderCredentialRouter = class {
@@ -1,7 +1,7 @@
1
1
  // package.json
2
2
  var package_default = {
3
3
  name: "@sentry/junior",
4
- version: "0.132.0",
4
+ version: "0.133.0",
5
5
  private: false,
6
6
  publishConfig: {
7
7
  access: "public"
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  pluginCatalogRuntime
3
- } from "./chunk-B7IY6SVJ.js";
3
+ } from "./chunk-JLN4XSPR.js";
4
4
  import {
5
5
  logWarn
6
- } from "./chunk-GOEZU33G.js";
6
+ } from "./chunk-EJRJWBKG.js";
7
7
  import {
8
8
  skillRoots
9
9
  } from "./chunk-H4HBKISO.js";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  createPluginCatalogRuntime
3
- } from "./chunk-V44FFBO3.js";
3
+ } from "./chunk-HJ4KDO4N.js";
4
4
 
5
5
  // src/chat/plugins/catalog-runtime.ts
6
6
  var pluginCatalogRuntime = createPluginCatalogRuntime();
@@ -3,7 +3,7 @@ import {
3
3
  toCanonicalInputMessage,
4
4
  toCanonicalOutputMessage,
5
5
  toGenAiMessagesTraceAttributes
6
- } from "./chunk-ISNRPCPG.js";
6
+ } from "./chunk-VL7OYSHD.js";
7
7
  import {
8
8
  extractGenAiUsageAttributes,
9
9
  logException,
@@ -11,7 +11,7 @@ import {
11
11
  normalizeGenAiFinishReason,
12
12
  serializeGenAiAttribute,
13
13
  withSpan
14
- } from "./chunk-GOEZU33G.js";
14
+ } from "./chunk-EJRJWBKG.js";
15
15
 
16
16
  // src/chat/config.ts
17
17
  import { getModel as getModel2 } from "@earendil-works/pi-ai/compat";
@@ -675,6 +675,7 @@ var DEFAULT_SLACK_SLASH_COMMAND = "/jr";
675
675
  var DEFAULT_PROCESSING_REACTION_EMOJI = "eyes";
676
676
  var DEFAULT_COMPLETED_REACTION_EMOJI = "white_check_mark";
677
677
  var DEFAULT_MODEL_CONTEXT_WINDOW_TOKENS = 4e5;
678
+ var DEFAULT_SQL_STATEMENT_TIMEOUT_MS = 3e4;
678
679
  var FUNCTION_TIMEOUT_BUFFER_SECONDS = 20;
679
680
  var CONVERSATION_WORK_SOFT_YIELD_BUFFER_SECONDS = 40;
680
681
  var DEFAULT_ASSISTANT_LOADING_MESSAGES = [
@@ -904,6 +905,19 @@ function readSqlDriver(env, databaseUrl) {
904
905
  }
905
906
  throw new Error("JUNIOR_DATABASE_DRIVER must be postgres or neon");
906
907
  }
908
+ function readSqlStatementTimeoutMs(env) {
909
+ const rawValue = toOptionalTrimmed(env.JUNIOR_SQL_STATEMENT_TIMEOUT_MS);
910
+ if (rawValue === void 0) {
911
+ return DEFAULT_SQL_STATEMENT_TIMEOUT_MS;
912
+ }
913
+ const value = Number.parseInt(rawValue, 10);
914
+ if (!Number.isSafeInteger(value) || value < 0 || String(value) !== rawValue) {
915
+ throw new Error(
916
+ "JUNIOR_SQL_STATEMENT_TIMEOUT_MS must be a non-negative integer"
917
+ );
918
+ }
919
+ return value === 0 ? false : value;
920
+ }
907
921
  function readChatConfig(env = process.env, functionMaxDurationSeconds = DEFAULT_FUNCTION_MAX_DURATION_SECONDS) {
908
922
  const databaseUrl = readDatabaseUrl(env);
909
923
  const resolvedFunctionMaxDurationSeconds = resolveFunctionMaxDurationSeconds(
@@ -917,7 +931,8 @@ function readChatConfig(env = process.env, functionMaxDurationSeconds = DEFAULT_
917
931
  ),
918
932
  sql: {
919
933
  databaseUrl,
920
- driver: readSqlDriver(env, databaseUrl)
934
+ driver: readSqlDriver(env, databaseUrl),
935
+ statementTimeoutMs: readSqlStatementTimeoutMs(env)
921
936
  },
922
937
  slack: {
923
938
  botToken: toOptionalTrimmed(env.SLACK_BOT_TOKEN) ?? toOptionalTrimmed(env.SLACK_BOT_USER_TOKEN),
@@ -1027,6 +1042,7 @@ export {
1027
1042
  modelIdForProfile,
1028
1043
  standardModelId,
1029
1044
  profileConfig,
1045
+ DEFAULT_SQL_STATEMENT_TIMEOUT_MS,
1030
1046
  FUNCTION_TIMEOUT_BUFFER_SECONDS,
1031
1047
  configureFunctionMaxDurationSeconds,
1032
1048
  getChatConfig,
@@ -1,15 +1,16 @@
1
1
  import {
2
2
  createJuniorSqlExecutor,
3
+ juniorConversationBindings,
3
4
  juniorConversationEvents,
4
5
  juniorConversations,
5
6
  juniorIdentities,
6
7
  juniorUsers
7
- } from "./chunk-KB2M27DL.js";
8
+ } from "./chunk-QWGZ273D.js";
8
9
  import {
9
10
  TURN_REASONING_LEVELS,
10
11
  getChatConfig,
11
12
  modelProfileSchema
12
- } from "./chunk-NNHUGGO4.js";
13
+ } from "./chunk-LDRO4OQ4.js";
13
14
  import {
14
15
  juniorDestinations
15
16
  } from "./chunk-VFUK3X5B.js";
@@ -19,11 +20,11 @@ import {
19
20
  } from "./chunk-F3B2YJ76.js";
20
21
  import {
21
22
  normalizeIdentityEmail
22
- } from "./chunk-GOEZU33G.js";
23
+ } from "./chunk-EJRJWBKG.js";
23
24
 
24
25
  // src/chat/conversations/sql/store.ts
25
26
  import { randomUUID as randomUUID2 } from "crypto";
26
- import { and as and2, asc, desc, eq as eq2, isNull, sql as sql2 } from "drizzle-orm";
27
+ import { and as and3, asc, desc, eq as eq3, isNull, sql as sql2 } from "drizzle-orm";
27
28
 
28
29
  // src/chat/destination.ts
29
30
  import {
@@ -197,6 +198,35 @@ function parseSessionSource(value) {
197
198
  return parsed.success ? normalizeSessionSource(parsed.data) : void 0;
198
199
  }
199
200
 
201
+ // src/chat/conversations/sql/bindings.ts
202
+ import { and as and2, eq as eq2 } from "drizzle-orm";
203
+ async function getConversationIdByProviderConversation(executor, args) {
204
+ const rows = await executor.db().select({ conversationId: juniorConversationBindings.conversationId }).from(juniorConversationBindings).where(
205
+ and2(
206
+ eq2(juniorConversationBindings.provider, args.provider),
207
+ eq2(juniorConversationBindings.providerTenantId, args.providerTenantId),
208
+ eq2(
209
+ juniorConversationBindings.providerDestinationId,
210
+ args.providerDestinationId
211
+ ),
212
+ eq2(
213
+ juniorConversationBindings.providerConversationId,
214
+ args.providerConversationId
215
+ )
216
+ )
217
+ ).limit(1);
218
+ return rows[0]?.conversationId;
219
+ }
220
+ async function bindProviderConversation(executor, args) {
221
+ const rows = await executor.db().insert(juniorConversationBindings).values({ ...args, createdAt: /* @__PURE__ */ new Date() }).onConflictDoNothing().returning({ conversationId: juniorConversationBindings.conversationId });
222
+ const boundConversationId = rows[0]?.conversationId ?? await getConversationIdByProviderConversation(executor, args);
223
+ if (boundConversationId !== args.conversationId) {
224
+ throw new Error(
225
+ "Provider conversation is already bound to another conversation"
226
+ );
227
+ }
228
+ }
229
+
200
230
  // src/chat/conversations/location.ts
201
231
  import { nonBlankStringSchema } from "@sentry/junior-plugin-api";
202
232
  import { z } from "zod";
@@ -516,6 +546,12 @@ var SqlStore = class {
516
546
  this.executor = executor;
517
547
  }
518
548
  executor;
549
+ async getConversationIdByProviderConversation(args) {
550
+ return await getConversationIdByProviderConversation(this.executor, args);
551
+ }
552
+ async bindProviderConversation(args) {
553
+ await bindProviderConversation(this.executor, args);
554
+ }
519
555
  async get(args) {
520
556
  const row = await this.readConversationRow(args.conversationId);
521
557
  if (!row) {
@@ -609,7 +645,7 @@ var SqlStore = class {
609
645
  metricRunId: args.execution.runId ?? null,
610
646
  executionDurationMs: args.metrics.durationMs,
611
647
  executionUsage: args.metrics.usage ?? (sameRun ? row?.executionUsage ?? null : null)
612
- }).where(eq2(juniorConversations.conversationId, args.conversationId));
648
+ }).where(eq3(juniorConversations.conversationId, args.conversationId));
613
649
  }
614
650
  });
615
651
  }
@@ -621,11 +657,11 @@ var SqlStore = class {
621
657
  actorUserDisplayName: juniorUsers.displayName
622
658
  }).from(juniorConversations).leftJoin(
623
659
  juniorDestinations,
624
- eq2(juniorDestinations.id, juniorConversations.destinationId)
660
+ eq3(juniorDestinations.id, juniorConversations.destinationId)
625
661
  ).leftJoin(
626
662
  juniorIdentities,
627
- eq2(juniorIdentities.id, juniorConversations.actorIdentityId)
628
- ).leftJoin(juniorUsers, eq2(juniorUsers.id, juniorIdentities.userId)).where(isNull(juniorConversations.parentConversationId)).orderBy(
663
+ eq3(juniorIdentities.id, juniorConversations.actorIdentityId)
664
+ ).leftJoin(juniorUsers, eq3(juniorUsers.id, juniorIdentities.userId)).where(isNull(juniorConversations.parentConversationId)).orderBy(
629
665
  desc(juniorConversations.lastActivityAt),
630
666
  asc(juniorConversations.conversationId)
631
667
  ).limit(Math.max(0, args.limit ?? 1e4)).offset(Math.max(0, args.offset ?? 0));
@@ -639,13 +675,13 @@ var SqlStore = class {
639
675
  const rows = await this.executor.db().select({
640
676
  visibility: juniorDestinations.visibility
641
677
  }).from(juniorDestinations).where(
642
- and2(
643
- eq2(juniorDestinations.provider, args.provider),
644
- eq2(
678
+ and3(
679
+ eq3(juniorDestinations.provider, args.provider),
680
+ eq3(
645
681
  juniorDestinations.providerTenantId,
646
682
  tenantId2(args.providerTenantId)
647
683
  ),
648
- eq2(
684
+ eq3(
649
685
  juniorDestinations.providerDestinationId,
650
686
  args.providerDestinationId
651
687
  )
@@ -675,11 +711,11 @@ var SqlStore = class {
675
711
  actorUserDisplayName: juniorUsers.displayName
676
712
  }).from(juniorConversations).leftJoin(
677
713
  juniorDestinations,
678
- eq2(juniorDestinations.id, juniorConversations.destinationId)
714
+ eq3(juniorDestinations.id, juniorConversations.destinationId)
679
715
  ).leftJoin(
680
716
  juniorIdentities,
681
- eq2(juniorIdentities.id, juniorConversations.actorIdentityId)
682
- ).leftJoin(juniorUsers, eq2(juniorUsers.id, juniorIdentities.userId)).where(eq2(juniorConversations.conversationId, conversationId));
717
+ eq3(juniorIdentities.id, juniorConversations.actorIdentityId)
718
+ ).leftJoin(juniorUsers, eq3(juniorUsers.id, juniorIdentities.userId)).where(eq3(juniorConversations.conversationId, conversationId));
683
719
  return rows[0];
684
720
  }
685
721
  /** Upsert the conversation row while preserving previously discovered nullable metadata fields. */
@@ -808,10 +844,10 @@ function createSqlStore(executor) {
808
844
 
809
845
  // src/chat/conversations/sql/history.ts
810
846
  import {
811
- and as and3,
847
+ and as and4,
812
848
  asc as asc2,
813
849
  desc as desc2,
814
- eq as eq3,
850
+ eq as eq4,
815
851
  gt,
816
852
  gte,
817
853
  inArray,
@@ -1287,8 +1323,8 @@ var SqlConversationEventStore = class {
1287
1323
  const existingKeys = parsed.map((event) => event.idempotencyKey).filter((key) => key !== void 0);
1288
1324
  const persistedKeys = existingKeys.length === 0 ? /* @__PURE__ */ new Set() : new Set(
1289
1325
  (await this.executor.db().select({ key: juniorConversationEvents.idempotencyKey }).from(juniorConversationEvents).where(
1290
- and3(
1291
- eq3(
1326
+ and4(
1327
+ eq4(
1292
1328
  juniorConversationEvents.conversationId,
1293
1329
  conversationId
1294
1330
  ),
@@ -1320,8 +1356,8 @@ var SqlConversationEventStore = class {
1320
1356
  );
1321
1357
  if (options.activity !== "preserve") {
1322
1358
  await this.executor.db().update(juniorConversations).set({ archivedAt: null }).where(
1323
- and3(
1324
- eq3(juniorConversations.conversationId, conversationId),
1359
+ and4(
1360
+ eq4(juniorConversations.conversationId, conversationId),
1325
1361
  isNotNull(juniorConversations.archivedAt)
1326
1362
  )
1327
1363
  );
@@ -1340,8 +1376,8 @@ var SqlConversationEventStore = class {
1340
1376
  await withConversationEventLock(this.executor, conversationId, async () => {
1341
1377
  await ensureConversationRow(this.executor, conversationId, Date.now());
1342
1378
  await this.executor.db().update(juniorConversations).set({ archivedAt: null }).where(
1343
- and3(
1344
- eq3(juniorConversations.conversationId, conversationId),
1379
+ and4(
1380
+ eq4(juniorConversations.conversationId, conversationId),
1345
1381
  isNotNull(juniorConversations.archivedAt)
1346
1382
  )
1347
1383
  );
@@ -1363,34 +1399,34 @@ var SqlConversationEventStore = class {
1363
1399
  return [];
1364
1400
  }
1365
1401
  const rows = await this.executor.db().select().from(juniorConversationEvents).where(
1366
- and3(
1367
- eq3(juniorConversationEvents.conversationId, conversationId),
1368
- eq3(juniorConversationEvents.historyVersion, cursor.maxHistoryVersion)
1402
+ and4(
1403
+ eq4(juniorConversationEvents.conversationId, conversationId),
1404
+ eq4(juniorConversationEvents.historyVersion, cursor.maxHistoryVersion)
1369
1405
  )
1370
1406
  ).orderBy(asc2(juniorConversationEvents.seq));
1371
1407
  return rows.map(eventFromRow);
1372
1408
  }
1373
1409
  async loadByIdempotencyKey(conversationId, idempotencyKey) {
1374
1410
  const [row] = await this.executor.db().select().from(juniorConversationEvents).where(
1375
- and3(
1376
- eq3(juniorConversationEvents.conversationId, conversationId),
1377
- eq3(juniorConversationEvents.idempotencyKey, idempotencyKey)
1411
+ and4(
1412
+ eq4(juniorConversationEvents.conversationId, conversationId),
1413
+ eq4(juniorConversationEvents.idempotencyKey, idempotencyKey)
1378
1414
  )
1379
1415
  ).limit(1);
1380
1416
  return row ? eventFromRow(row) : void 0;
1381
1417
  }
1382
1418
  async loadHistoryContaining(conversationId, seq, throughSeq) {
1383
1419
  const [boundary] = await this.executor.db().select({ historyVersion: juniorConversationEvents.historyVersion }).from(juniorConversationEvents).where(
1384
- and3(
1385
- eq3(juniorConversationEvents.conversationId, conversationId),
1386
- eq3(juniorConversationEvents.seq, seq)
1420
+ and4(
1421
+ eq4(juniorConversationEvents.conversationId, conversationId),
1422
+ eq4(juniorConversationEvents.seq, seq)
1387
1423
  )
1388
1424
  ).limit(1);
1389
1425
  if (!boundary) return void 0;
1390
1426
  const rows = await this.executor.db().select().from(juniorConversationEvents).where(
1391
- and3(
1392
- eq3(juniorConversationEvents.conversationId, conversationId),
1393
- eq3(juniorConversationEvents.historyVersion, boundary.historyVersion),
1427
+ and4(
1428
+ eq4(juniorConversationEvents.conversationId, conversationId),
1429
+ eq4(juniorConversationEvents.historyVersion, boundary.historyVersion),
1394
1430
  throughSeq === void 0 ? void 0 : lte(juniorConversationEvents.seq, throughSeq)
1395
1431
  )
1396
1432
  ).orderBy(asc2(juniorConversationEvents.seq));
@@ -1398,9 +1434,9 @@ var SqlConversationEventStore = class {
1398
1434
  }
1399
1435
  async loadLatestInstruction(conversationId) {
1400
1436
  const [row] = await this.executor.db().select().from(juniorConversationEvents).where(
1401
- and3(
1402
- eq3(juniorConversationEvents.conversationId, conversationId),
1403
- eq3(juniorConversationEvents.type, "user_message"),
1437
+ and4(
1438
+ eq4(juniorConversationEvents.conversationId, conversationId),
1439
+ eq4(juniorConversationEvents.type, "user_message"),
1404
1440
  sql4`${juniorConversationEvents.payload}->'provenance'->>'authority' = 'instruction'`
1405
1441
  )
1406
1442
  ).orderBy(desc2(juniorConversationEvents.seq)).limit(1);
@@ -1408,16 +1444,16 @@ var SqlConversationEventStore = class {
1408
1444
  }
1409
1445
  async loadMessageHistory(conversationId) {
1410
1446
  const [compactionRow] = await this.executor.db().select().from(juniorConversationEvents).where(
1411
- and3(
1412
- eq3(juniorConversationEvents.conversationId, conversationId),
1413
- eq3(juniorConversationEvents.type, "messages_summarized")
1447
+ and4(
1448
+ eq4(juniorConversationEvents.conversationId, conversationId),
1449
+ eq4(juniorConversationEvents.type, "messages_summarized")
1414
1450
  )
1415
1451
  ).orderBy(desc2(juniorConversationEvents.seq)).limit(1);
1416
1452
  const compaction = compactionRow ? messagesSummarizedEventFromRow(compactionRow) : void 0;
1417
1453
  const historyFromSeq = compaction?.data.historyFromSeq ?? 0;
1418
1454
  const rows = await this.executor.db().select().from(juniorConversationEvents).where(
1419
- and3(
1420
- eq3(juniorConversationEvents.conversationId, conversationId),
1455
+ and4(
1456
+ eq4(juniorConversationEvents.conversationId, conversationId),
1421
1457
  inArray(juniorConversationEvents.type, messageHistoryEventTypes),
1422
1458
  gte(juniorConversationEvents.seq, historyFromSeq)
1423
1459
  )
@@ -1425,7 +1461,7 @@ var SqlConversationEventStore = class {
1425
1461
  return { events: rows.map(eventFromRow), compaction, historyFromSeq };
1426
1462
  }
1427
1463
  async loadHistory(conversationId) {
1428
- const rows = await this.executor.db().select().from(juniorConversationEvents).where(eq3(juniorConversationEvents.conversationId, conversationId)).orderBy(asc2(juniorConversationEvents.seq));
1464
+ const rows = await this.executor.db().select().from(juniorConversationEvents).where(eq4(juniorConversationEvents.conversationId, conversationId)).orderBy(asc2(juniorConversationEvents.seq));
1429
1465
  return rows.map(eventFromRow);
1430
1466
  }
1431
1467
  async query(conversationId, query) {
@@ -1436,8 +1472,8 @@ var SqlConversationEventStore = class {
1436
1472
  return { events: [], hasOlder: false, hasNewer: false };
1437
1473
  }
1438
1474
  const typeFilter = query.types && query.types.length > 0 ? inArray(juniorConversationEvents.type, [...query.types]) : void 0;
1439
- const bounds = and3(
1440
- eq3(juniorConversationEvents.conversationId, conversationId),
1475
+ const bounds = and4(
1476
+ eq4(juniorConversationEvents.conversationId, conversationId),
1441
1477
  query.afterSeq === void 0 ? void 0 : gt(juniorConversationEvents.seq, query.afterSeq),
1442
1478
  query.beforeSeq === void 0 ? void 0 : lt(juniorConversationEvents.seq, query.beforeSeq),
1443
1479
  typeFilter
@@ -1474,8 +1510,8 @@ var SqlConversationEventStore = class {
1474
1510
  return false;
1475
1511
  }
1476
1512
  const [row] = await this.executor.db().select({ seq: juniorConversationEvents.seq }).from(juniorConversationEvents).where(
1477
- and3(
1478
- eq3(juniorConversationEvents.conversationId, args.conversationId),
1513
+ and4(
1514
+ eq4(juniorConversationEvents.conversationId, args.conversationId),
1479
1515
  args.afterSeq === void 0 ? void 0 : gt(juniorConversationEvents.seq, args.afterSeq),
1480
1516
  args.beforeSeq === void 0 ? void 0 : lt(juniorConversationEvents.seq, args.beforeSeq),
1481
1517
  args.typeFilter
@@ -1488,7 +1524,7 @@ var SqlConversationEventStore = class {
1488
1524
  const rows = await this.executor.db().select({
1489
1525
  maxSeq: sql4`max(${juniorConversationEvents.seq})`,
1490
1526
  maxHistoryVersion: sql4`max(${juniorConversationEvents.historyVersion})`
1491
- }).from(juniorConversationEvents).where(eq3(juniorConversationEvents.conversationId, conversationId));
1527
+ }).from(juniorConversationEvents).where(eq4(juniorConversationEvents.conversationId, conversationId));
1492
1528
  const maxSeq = rows[0]?.maxSeq;
1493
1529
  const maxHistoryVersion = rows[0]?.maxHistoryVersion;
1494
1530
  return {
@@ -1502,7 +1538,7 @@ function createSqlConversationEventStore(executor) {
1502
1538
  }
1503
1539
 
1504
1540
  // src/chat/conversations/sql/search.ts
1505
- import { and as and4, desc as desc3, eq as eq4, isNull as isNull2, ne, sql as sql5 } from "drizzle-orm";
1541
+ import { and as and5, desc as desc3, eq as eq5, isNull as isNull2, ne, sql as sql5 } from "drizzle-orm";
1506
1542
  var SqlConversationSearchStore = class {
1507
1543
  constructor(executor) {
1508
1544
  this.executor = executor;
@@ -1527,23 +1563,23 @@ var SqlConversationSearchStore = class {
1527
1563
  role: role.as("role")
1528
1564
  }).from(juniorConversationEvents).innerJoin(
1529
1565
  juniorConversations,
1530
- eq4(
1566
+ eq5(
1531
1567
  juniorConversations.conversationId,
1532
1568
  juniorConversationEvents.conversationId
1533
1569
  )
1534
1570
  ).innerJoin(
1535
1571
  juniorDestinations,
1536
- eq4(juniorDestinations.id, juniorConversations.destinationId)
1572
+ eq5(juniorDestinations.id, juniorConversations.destinationId)
1537
1573
  ).where(
1538
- and4(
1539
- eq4(juniorConversations.source, "slack"),
1574
+ and5(
1575
+ eq5(juniorConversations.source, "slack"),
1540
1576
  isNull2(juniorConversations.parentConversationId),
1541
1577
  isNull2(juniorConversations.transcriptPurgedAt),
1542
1578
  ne(juniorConversations.conversationId, args.currentConversationId),
1543
- eq4(juniorDestinations.provider, args.scope.provider),
1544
- eq4(juniorDestinations.providerTenantId, args.scope.providerTenantId),
1545
- eq4(juniorDestinations.visibility, "public"),
1546
- eq4(juniorConversationEvents.type, "message"),
1579
+ eq5(juniorDestinations.provider, args.scope.provider),
1580
+ eq5(juniorDestinations.providerTenantId, args.scope.providerTenantId),
1581
+ eq5(juniorDestinations.visibility, "public"),
1582
+ eq5(juniorConversationEvents.type, "message"),
1547
1583
  sql5`${role} in ('user', 'assistant')`,
1548
1584
  sql5`to_tsvector('english', ${text}) @@ ${tsquery}`
1549
1585
  )
@@ -1575,12 +1611,13 @@ var current;
1575
1611
  function createDb(args) {
1576
1612
  return createJuniorSqlExecutor({
1577
1613
  connectionString: args.databaseUrl,
1578
- driver: args.driver
1614
+ driver: args.driver,
1615
+ statementTimeoutMs: args.statementTimeoutMs
1579
1616
  });
1580
1617
  }
1581
1618
  function getSqlExecutor() {
1582
1619
  const { sql: sql6 } = getChatConfig();
1583
- if (current?.databaseUrl !== sql6.databaseUrl || current.driver !== sql6.driver) {
1620
+ if (current?.databaseUrl !== sql6.databaseUrl || current.driver !== sql6.driver || current.statementTimeoutMs !== sql6.statementTimeoutMs) {
1584
1621
  if (current) {
1585
1622
  const previous = current;
1586
1623
  current = void 0;
@@ -1588,11 +1625,13 @@ function getSqlExecutor() {
1588
1625
  }
1589
1626
  const db = createDb({
1590
1627
  databaseUrl: sql6.databaseUrl,
1591
- driver: sql6.driver
1628
+ driver: sql6.driver,
1629
+ statementTimeoutMs: sql6.statementTimeoutMs
1592
1630
  });
1593
1631
  current = {
1594
1632
  databaseUrl: sql6.databaseUrl,
1595
1633
  driver: sql6.driver,
1634
+ statementTimeoutMs: sql6.statementTimeoutMs,
1596
1635
  db,
1597
1636
  store: createSqlStore(db),
1598
1637
  eventStore: createSqlConversationEventStore(db),
@@ -1628,6 +1667,7 @@ export {
1628
1667
  requireSlackDestination,
1629
1668
  sameDestination,
1630
1669
  parseSessionSource,
1670
+ bindProviderConversation,
1631
1671
  locationFromRow,
1632
1672
  instructionProvenanceFor,
1633
1673
  contextProvenance,