@sentry/junior 0.193.0 → 0.195.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 (99) hide show
  1. package/dist/{agent-hooks-DWY3MZZ7.js → agent-hooks-VIBTIP5F.js} +11 -11
  2. package/dist/api/activity.d.ts +9 -1
  3. package/dist/api/code/overview.d.ts +12 -0
  4. package/dist/api/conversations/aggregate.d.ts +2 -0
  5. package/dist/api/conversations/list.d.ts +1 -1
  6. package/dist/api/conversations/projection.d.ts +1 -1
  7. package/dist/api/locations/detail.d.ts +9 -1
  8. package/dist/api/locations/list.d.ts +5 -0
  9. package/dist/api/people/code.d.ts +6 -0
  10. package/dist/api/people/shared.d.ts +9 -1
  11. package/dist/api/reporting-window.d.ts +39 -1
  12. package/dist/api/schema/code.d.ts +12 -0
  13. package/dist/api/schema/conversation.d.ts +28 -3
  14. package/dist/api/schema/location.d.ts +14 -1
  15. package/dist/api/schema/person.d.ts +15 -1
  16. package/dist/api/schema/task.d.ts +83 -8
  17. package/dist/api/schema.d.ts +2 -2
  18. package/dist/api/schema.js +3 -1
  19. package/dist/api.js +320 -222
  20. package/dist/app.js +108 -39
  21. package/dist/{catalog-runtime-NAD44W5K.js → catalog-runtime-6E6SGRZK.js} +4 -4
  22. package/dist/chat/agent/resume.d.ts +2 -0
  23. package/dist/chat/config.d.ts +2 -0
  24. package/dist/chat/conversations/history.d.ts +4 -2
  25. package/dist/chat/event-tasks/store.d.ts +27 -17
  26. package/dist/chat/resource-events/notification.d.ts +2 -1
  27. package/dist/chat/services/automated-turn-limit.d.ts +110 -0
  28. package/dist/chat/services/turn-limit.d.ts +11 -1
  29. package/dist/chat/slack/automated-turn-limit-notice.d.ts +38 -0
  30. package/dist/chat/slack/{source-link.d.ts → location-url.d.ts} +1 -1
  31. package/dist/chat/task-execution/checkpoint.d.ts +2 -0
  32. package/dist/chat/task-execution/turn-cursor.d.ts +3 -0
  33. package/dist/chat/tasks/execution-stats.d.ts +15 -2
  34. package/dist/chat/tasks/read.d.ts +5 -2
  35. package/dist/chat/usage.d.ts +4 -0
  36. package/dist/{chunk-GUKGU6R7.js → chunk-3VWIZVK7.js} +1 -1
  37. package/dist/{chunk-THYNA2QN.js → chunk-5HNXLP4W.js} +1 -1
  38. package/dist/{chunk-GUMBIDDL.js → chunk-5NR7N567.js} +194 -43
  39. package/dist/{chunk-N6Q2PNSI.js → chunk-6GGDBXXP.js} +3 -3
  40. package/dist/{chunk-HMBTX5RK.js → chunk-6TRQLG3D.js} +1 -1
  41. package/dist/{chunk-IOUUS6H4.js → chunk-7MYXH5LA.js} +1 -1
  42. package/dist/{chunk-WH5VV2RW.js → chunk-7PQMTME5.js} +1 -1
  43. package/dist/{chunk-5E5SLAVD.js → chunk-7UED4D5T.js} +23 -25
  44. package/dist/{chunk-4UA5C7AM.js → chunk-BJZML4RT.js} +8 -8
  45. package/dist/{chunk-QDU5MW2R.js → chunk-C4NY6L7S.js} +1 -1
  46. package/dist/{chunk-DVU734PI.js → chunk-CE2P6TOV.js} +3 -3
  47. package/dist/{chunk-BFP3ZKG6.js → chunk-DTYOEHUP.js} +148 -19
  48. package/dist/{chunk-S5HS6WRH.js → chunk-FE3Y4KES.js} +5 -5
  49. package/dist/{chunk-PYBFVK6K.js → chunk-FEZIEEOP.js} +985 -569
  50. package/dist/{chunk-5S6AQFNG.js → chunk-FPQPYJEG.js} +23 -29
  51. package/dist/{chunk-42N6CDWF.js → chunk-HE5PZAPS.js} +4 -4
  52. package/dist/{chunk-QY2IU47O.js → chunk-HUQOXMDG.js} +1 -1
  53. package/dist/{chunk-IQCL5JGL.js → chunk-I4RH3KLJ.js} +1 -1
  54. package/dist/{chunk-LXRTHE43.js → chunk-JBSCMOLR.js} +5 -5
  55. package/dist/{chunk-OICYQPKP.js → chunk-KBPWC7NU.js} +1 -1
  56. package/dist/{chunk-2CYWEVOP.js → chunk-KQ3GZGBK.js} +88 -68
  57. package/dist/{chunk-GTXQHZ2O.js → chunk-KUQRWV53.js} +5 -5
  58. package/dist/{chunk-IBXXTO3J.js → chunk-L62JVQPL.js} +3 -3
  59. package/dist/{chunk-KWXZMHJS.js → chunk-LM7UE523.js} +3 -3
  60. package/dist/{chunk-WJJDQLVL.js → chunk-LMYRF6HX.js} +6 -2
  61. package/dist/{chunk-AZVDODSP.js → chunk-N67T4VY3.js} +9 -9
  62. package/dist/{chunk-D4XQZOHB.js → chunk-OQHO62VA.js} +8 -8
  63. package/dist/{chunk-FQ5HFSFR.js → chunk-PFQRZ4IB.js} +9 -6
  64. package/dist/{chunk-LG7Q4OW4.js → chunk-PYTRZZ4V.js} +8 -8
  65. package/dist/{chunk-THFNL3TL.js → chunk-QHJZSYKY.js} +2 -2
  66. package/dist/{chunk-5LEVZYXF.js → chunk-QKHZF2LH.js} +4 -4
  67. package/dist/{chunk-EYIMZY5O.js → chunk-QPZL2IYT.js} +100 -9
  68. package/dist/{chunk-D5YQPCEG.js → chunk-R5BGW4WR.js} +24 -2
  69. package/dist/{chunk-COCVPDWX.js → chunk-R5OHONYU.js} +6 -6
  70. package/dist/{chunk-DXFUYLHX.js → chunk-RKA22BQP.js} +1 -1
  71. package/dist/{chunk-3YZ2Q6AW.js → chunk-RQO67SAO.js} +2 -2
  72. package/dist/{chunk-ZFPEPWOO.js → chunk-RZ3PBNDV.js} +60 -29
  73. package/dist/{chunk-K47OVEO4.js → chunk-VYDIA2UL.js} +1 -1
  74. package/dist/{chunk-QWY4KI2V.js → chunk-X3PBQ4BK.js} +1 -1
  75. package/dist/cli/chat.js +33 -33
  76. package/dist/cli/check.js +5 -5
  77. package/dist/cli/plugins.js +12 -12
  78. package/dist/cli/snapshot-create.js +9 -9
  79. package/dist/cli/upgrade.js +6 -6
  80. package/dist/db/schema/event-tasks.d.ts +21 -0
  81. package/dist/db/schema.d.ts +19 -0
  82. package/dist/{db-H5MDRQEY.js → db-FVCSDROR.js} +6 -6
  83. package/dist/instrumentation.js +3 -3
  84. package/dist/nitro.js +6 -6
  85. package/dist/{oauth-callback-server-IOU3NUHT.js → oauth-callback-server-Z5PXTDOE.js} +29 -29
  86. package/dist/{runner-FZ5ZHLFG.js → runner-RHYU7OGV.js} +21 -21
  87. package/dist/{skills-AR3WD6BX.js → skills-QTN73DN5.js} +5 -5
  88. package/dist/spawn-R56OWLUH.js +42 -0
  89. package/dist/task-runner-LLJZTLRP.js +36 -0
  90. package/dist/{validation-VYE7TQY7.js → validation-2ZK7GA6N.js} +5 -5
  91. package/dist/version.js +1 -1
  92. package/dist/{work-CTQFWYKE.js → work-7IBKSZRU.js} +21 -21
  93. package/dist/{worker-6WQU3IT5.js → worker-RNVQVCO7.js} +10 -10
  94. package/migrations/0038_event_task_status.sql +5 -0
  95. package/migrations/meta/0038_snapshot.json +3323 -0
  96. package/migrations/meta/_journal.json +8 -1
  97. package/package.json +4 -4
  98. package/dist/spawn-ZU6JABR7.js +0 -42
  99. package/dist/task-runner-EEGGG2PM.js +0 -36
@@ -4,7 +4,7 @@ import {
4
4
  } from "./chunk-VFUK3X5B.js";
5
5
  import {
6
6
  DEFAULT_SQL_STATEMENT_TIMEOUT_MS
7
- } from "./chunk-WJJDQLVL.js";
7
+ } from "./chunk-LMYRF6HX.js";
8
8
 
9
9
  // src/db/neon.ts
10
10
  import { AsyncLocalStorage } from "async_hooks";
@@ -560,6 +560,7 @@ var juniorLocationConfigurations = pgTable13(
560
560
  );
561
561
 
562
562
  // src/db/schema/event-tasks.ts
563
+ import { sql as sql5 } from "drizzle-orm";
563
564
  import { bigint, index as index11, jsonb as jsonb6, pgTable as pgTable14, text as text14 } from "drizzle-orm/pg-core";
564
565
  var juniorEventTasks = pgTable14(
565
566
  "junior_event_tasks",
@@ -569,22 +570,15 @@ var juniorEventTasks = pgTable14(
569
570
  namespace: text14("namespace").notNull(),
570
571
  identifier: text14("identifier").notNull(),
571
572
  createdAtMs: bigint("created_at_ms", { mode: "number" }).notNull(),
573
+ /** Retained row status. Deleted tasks keep history but stop matching. */
574
+ status: text14("status").$type().notNull().default("active"),
572
575
  /** Short display title generated from the task instruction. */
573
576
  title: text14("title"),
574
577
  task: jsonb6("task_json").$type().notNull()
575
578
  },
576
579
  (table) => [
577
- index11("junior_event_tasks_team_idx").on(
578
- table.teamId,
579
- table.createdAtMs,
580
- table.id
581
- ),
582
- index11("junior_event_tasks_match_idx").on(
583
- table.namespace,
584
- table.identifier,
585
- table.createdAtMs,
586
- table.id
587
- )
580
+ index11("junior_event_tasks_team_idx").on(table.teamId, table.createdAtMs, table.id).where(sql5`${table.status} <> 'deleted'`),
581
+ index11("junior_event_tasks_match_idx").on(table.namespace, table.identifier, table.createdAtMs, table.id).where(sql5`${table.status} <> 'deleted'`)
588
582
  ]
589
583
  );
590
584
 
@@ -608,7 +602,7 @@ var juniorStats = pgTable15(
608
602
  );
609
603
 
610
604
  // src/db/schema/task-executions.ts
611
- import { sql as sql5 } from "drizzle-orm";
605
+ import { sql as sql6 } from "drizzle-orm";
612
606
  import {
613
607
  bigint as bigint2,
614
608
  check,
@@ -632,11 +626,11 @@ var juniorTaskExecutions = pgTable16(
632
626
  (table) => [
633
627
  check(
634
628
  "junior_task_executions_kind_check",
635
- sql5`${table.kind} in ('scheduled', 'event')`
629
+ sql6`${table.kind} in ('scheduled', 'event')`
636
630
  ),
637
631
  check(
638
632
  "junior_task_executions_status_check",
639
- sql5`${table.status} in ('blocked', 'completed', 'failed')`
633
+ sql6`${table.status} in ('blocked', 'completed', 'failed')`
640
634
  ),
641
635
  primaryKey8({
642
636
  name: "junior_task_executions_kind_namespace_execution_id_pk",
@@ -665,7 +659,7 @@ var juniorTaskExecutions = pgTable16(
665
659
  );
666
660
 
667
661
  // src/db/schema/scheduled-tasks.ts
668
- import { sql as sql6 } from "drizzle-orm";
662
+ import { sql as sql7 } from "drizzle-orm";
669
663
  import { bigint as bigint3, index as index13, jsonb as jsonb7, pgTable as pgTable17, text as text17 } from "drizzle-orm/pg-core";
670
664
  var juniorSchedulerTasks = pgTable17(
671
665
  "junior_scheduler_tasks",
@@ -687,16 +681,16 @@ var juniorSchedulerTasks = pgTable17(
687
681
  (table) => [
688
682
  // TODO(dcramer): Remove after no supported runtime reads or writes the
689
683
  // legacy creatorSlackUserId column.
690
- index13("junior_scheduler_tasks_creator_idx").on(table.teamId, table.creatorSlackUserId, table.createdAtMs, table.id).where(sql6`${table.status} <> 'deleted'`),
684
+ index13("junior_scheduler_tasks_creator_idx").on(table.teamId, table.creatorSlackUserId, table.createdAtMs, table.id).where(sql7`${table.status} <> 'deleted'`),
691
685
  index13("junior_scheduler_tasks_creator_identity_idx").on(table.creatorIdentityId, table.createdAtMs, table.id).where(
692
- sql6`${table.status} <> 'deleted' AND ${table.creatorIdentityId} IS NOT NULL`
686
+ sql7`${table.status} <> 'deleted' AND ${table.creatorIdentityId} IS NOT NULL`
693
687
  ),
694
- index13("junior_scheduler_tasks_team_status_idx").on(table.teamId, table.createdAtMs, table.id).where(sql6`${table.status} <> 'deleted'`),
688
+ index13("junior_scheduler_tasks_team_status_idx").on(table.teamId, table.createdAtMs, table.id).where(sql7`${table.status} <> 'deleted'`),
695
689
  index13("junior_scheduler_tasks_run_now_due_idx").on(table.runNowAtMs, table.createdAtMs, table.id).where(
696
- sql6`${table.status} = 'active' AND ${table.runNowAtMs} IS NOT NULL`
690
+ sql7`${table.status} = 'active' AND ${table.runNowAtMs} IS NOT NULL`
697
691
  ),
698
692
  index13("junior_scheduler_tasks_next_run_due_idx").on(table.nextRunAtMs, table.createdAtMs, table.id).where(
699
- sql6`${table.status} = 'active' AND ${table.nextRunAtMs} IS NOT NULL`
693
+ sql7`${table.status} = 'active' AND ${table.nextRunAtMs} IS NOT NULL`
700
694
  )
701
695
  ]
702
696
  );
@@ -723,7 +717,7 @@ var juniorSchedulerRuns = pgTable17(
723
717
  );
724
718
 
725
719
  // src/db/schema/snapshots.ts
726
- import { sql as sql7 } from "drizzle-orm";
720
+ import { sql as sql8 } from "drizzle-orm";
727
721
  import {
728
722
  bigint as bigint4,
729
723
  check as check2,
@@ -785,27 +779,27 @@ var juniorSnapshots = pgTable19(
785
779
  (table) => [
786
780
  check2(
787
781
  "junior_snapshots_status_check",
788
- sql7`${table.status} in ('building', 'failed', 'ready')`
782
+ sql8`${table.status} in ('building', 'failed', 'ready')`
789
783
  ),
790
784
  check2(
791
785
  "junior_snapshots_build_phase_check",
792
- sql7`${table.buildPhase} is null or ${table.buildPhase} in ('created', 'dependencies_installed', 'repositories_prepared')`
786
+ sql8`${table.buildPhase} is null or ${table.buildPhase} in ('created', 'dependencies_installed', 'repositories_prepared')`
793
787
  ),
794
788
  check2(
795
789
  "junior_snapshots_ready_fields_check",
796
- sql7`${table.status} <> 'ready' or (${table.snapshotId} is not null and ${table.buildDurationMs} is not null and ${table.generatedAt} is not null)`
790
+ sql8`${table.status} <> 'ready' or (${table.snapshotId} is not null and ${table.buildDurationMs} is not null and ${table.generatedAt} is not null)`
797
791
  ),
798
792
  check2(
799
793
  "junior_snapshots_build_fields_check",
800
- sql7`${table.status} = 'ready' or (${table.buildStartedAt} is not null and ${table.buildPhase} is not null)`
794
+ sql8`${table.status} = 'ready' or (${table.buildStartedAt} is not null and ${table.buildPhase} is not null)`
801
795
  ),
802
796
  check2(
803
797
  "junior_snapshots_build_duration_check",
804
- sql7`${table.buildDurationMs} is null or ${table.buildDurationMs} >= 0`
798
+ sql8`${table.buildDurationMs} is null or ${table.buildDurationMs} >= 0`
805
799
  ),
806
800
  check2(
807
801
  "junior_snapshots_size_bytes_check",
808
- sql7`${table.sizeBytes} is null or ${table.sizeBytes} >= 0`
802
+ sql8`${table.sizeBytes} is null or ${table.sizeBytes} >= 0`
809
803
  ),
810
804
  // Provider snapshot ids are unique. Nulls stay allowed for in-flight rows.
811
805
  uniqueIndex9("junior_snapshots_snapshot_id_uidx").on(table.snapshotId),
@@ -815,7 +809,7 @@ var juniorSnapshots = pgTable19(
815
809
  table.profileHash,
816
810
  table.status
817
811
  ),
818
- uniqueIndex9("junior_snapshots_active_build_uidx").on(table.workspaceId, table.profileHash).where(sql7`${table.status} = 'building'`),
812
+ uniqueIndex9("junior_snapshots_active_build_uidx").on(table.workspaceId, table.profileHash).where(sql8`${table.status} = 'building'`),
819
813
  index14("junior_snapshots_workspace_status_idx").on(
820
814
  table.workspaceId,
821
815
  table.status
@@ -19,23 +19,23 @@ import {
19
19
  releaseConversationWork,
20
20
  requestAnotherSlice,
21
21
  startConversationWork
22
- } from "./chunk-5LEVZYXF.js";
22
+ } from "./chunk-QKHZF2LH.js";
23
23
  import {
24
24
  getTurnRequestDeadline
25
- } from "./chunk-IQCL5JGL.js";
25
+ } from "./chunk-I4RH3KLJ.js";
26
26
  import {
27
27
  ConversationQueueMessageRejectedError
28
28
  } from "./chunk-JAL3CH4G.js";
29
29
  import {
30
30
  getChatConfig,
31
31
  isProviderRetryError
32
- } from "./chunk-WJJDQLVL.js";
32
+ } from "./chunk-LMYRF6HX.js";
33
33
  import {
34
34
  logException,
35
35
  logInfo,
36
36
  logWarn,
37
37
  withLogContext
38
- } from "./chunk-QY2IU47O.js";
38
+ } from "./chunk-HUQOXMDG.js";
39
39
 
40
40
  // src/chat/task-execution/worker.ts
41
41
  var CONVERSATION_WORK_DEFER_DELAY_MS = 15e3;
@@ -12,7 +12,7 @@ import {
12
12
  } from "./chunk-PEQXYSSE.js";
13
13
  import {
14
14
  JUNIOR_VERSION
15
- } from "./chunk-QDU5MW2R.js";
15
+ } from "./chunk-C4NY6L7S.js";
16
16
 
17
17
  // src/deployment.ts
18
18
  var JUNIOR_HEARTBEAT_ROUTE = "/api/internal/heartbeat";
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  FUNCTION_TIMEOUT_BUFFER_SECONDS,
3
3
  getChatConfig
4
- } from "./chunk-WJJDQLVL.js";
4
+ } from "./chunk-LMYRF6HX.js";
5
5
 
6
6
  // src/chat/runtime/request-deadline.ts
7
7
  import { AsyncLocalStorage } from "async_hooks";
@@ -7,23 +7,23 @@ import {
7
7
  import {
8
8
  formatProviderLabel,
9
9
  startOAuthFlow
10
- } from "./chunk-COCVPDWX.js";
10
+ } from "./chunk-R5OHONYU.js";
11
11
  import {
12
12
  abandonReplacedPendingAuth,
13
13
  canReusePendingAuthLink
14
- } from "./chunk-K47OVEO4.js";
14
+ } from "./chunk-VYDIA2UL.js";
15
15
  import {
16
16
  recordAuthorizationRequested
17
- } from "./chunk-ZFPEPWOO.js";
17
+ } from "./chunk-RZ3PBNDV.js";
18
18
  import {
19
19
  AGENT_INVOCATION_MAILBOX_STATUSES
20
- } from "./chunk-5S6AQFNG.js";
20
+ } from "./chunk-FPQPYJEG.js";
21
21
  import {
22
22
  TURN_REASONING_LEVELS
23
23
  } from "./chunk-D4YV5TDV.js";
24
24
  import {
25
25
  pluginCatalogRuntime
26
- } from "./chunk-DXFUYLHX.js";
26
+ } from "./chunk-RKA22BQP.js";
27
27
  import {
28
28
  credentialContextSchema
29
29
  } from "./chunk-CEMMLV5L.js";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  logWarn
3
- } from "./chunk-QY2IU47O.js";
3
+ } from "./chunk-HUQOXMDG.js";
4
4
 
5
5
  // src/chat/conversation-privacy.ts
6
6
  import { AsyncLocalStorage } from "async_hooks";
@@ -8,7 +8,7 @@ import {
8
8
  juniorConversations,
9
9
  juniorIdentities,
10
10
  juniorUsers
11
- } from "./chunk-5S6AQFNG.js";
11
+ } from "./chunk-FPQPYJEG.js";
12
12
  import {
13
13
  conversationEventDataSchema,
14
14
  decodeStoredConversationEvent,
@@ -20,7 +20,7 @@ import {
20
20
  } from "./chunk-VFUK3X5B.js";
21
21
  import {
22
22
  getChatConfig
23
- } from "./chunk-WJJDQLVL.js";
23
+ } from "./chunk-LMYRF6HX.js";
24
24
  import {
25
25
  parseActorUserId,
26
26
  parseSlackChannelReferenceId,
@@ -28,7 +28,7 @@ import {
28
28
  } from "./chunk-N7TMSOZH.js";
29
29
  import {
30
30
  normalizeIdentityEmail
31
- } from "./chunk-QY2IU47O.js";
31
+ } from "./chunk-HUQOXMDG.js";
32
32
 
33
33
  // src/chat/conversations/sql/store.ts
34
34
  import { randomUUID as randomUUID2 } from "crypto";
@@ -68,6 +68,12 @@ function sameDestination(left, right) {
68
68
  }
69
69
  return false;
70
70
  }
71
+ function destinationKey(destination) {
72
+ if (destination.platform === "local") {
73
+ return destination.conversationId;
74
+ }
75
+ return `slack:${destination.teamId}:${destination.channelId}`;
76
+ }
71
77
 
72
78
  // src/chat/identities/sql.ts
73
79
  import { randomUUID } from "crypto";
@@ -450,7 +456,9 @@ function locationForWrite(args) {
450
456
  }
451
457
  function locationFromRow(value, row, sessionSource) {
452
458
  if (value !== void 0 && value !== null) {
453
- return locationSchema.parse(value);
459
+ const location = locationSchema.parse(value);
460
+ const slackSource2 = !location.threadTs && sessionSource?.kind === "slack" && sessionSource.teamId === location.teamId && sessionSource.channelId === location.channelId ? sessionSource : void 0;
461
+ return slackSource2?.threadTs ? { ...location, threadTs: slackSource2.threadTs } : location;
454
462
  }
455
463
  if (!row || row.provider === "local") {
456
464
  return void 0;
@@ -1397,76 +1405,84 @@ var SqlConversationEventStore = class {
1397
1405
  (event) => newConversationEventSchema.parse(event)
1398
1406
  );
1399
1407
  if (parsed.length === 0) {
1400
- return;
1408
+ return [];
1401
1409
  }
1402
- await withConversationEventLock(this.executor, conversationId, async () => {
1403
- const existingKeys = parsed.map((event) => event.idempotencyKey).filter((key) => key !== void 0);
1404
- const persistedKeys = existingKeys.length === 0 ? /* @__PURE__ */ new Set() : new Set(
1405
- (await this.executor.db().select({ key: juniorConversationEvents.idempotencyKey }).from(juniorConversationEvents).where(
1406
- and6(
1407
- eq6(
1408
- juniorConversationEvents.conversationId,
1409
- conversationId
1410
- ),
1411
- inArray2(
1412
- juniorConversationEvents.idempotencyKey,
1413
- existingKeys
1410
+ return withConversationEventLock(
1411
+ this.executor,
1412
+ conversationId,
1413
+ async () => {
1414
+ const existingKeys = parsed.map((event) => event.idempotencyKey).filter((key) => key !== void 0);
1415
+ const persistedKeys = existingKeys.length === 0 ? /* @__PURE__ */ new Set() : new Set(
1416
+ (await this.executor.db().select({ key: juniorConversationEvents.idempotencyKey }).from(juniorConversationEvents).where(
1417
+ and6(
1418
+ eq6(
1419
+ juniorConversationEvents.conversationId,
1420
+ conversationId
1421
+ ),
1422
+ inArray2(
1423
+ juniorConversationEvents.idempotencyKey,
1424
+ existingKeys
1425
+ )
1414
1426
  )
1415
- )
1416
- )).flatMap((row) => row.key ? [row.key] : [])
1417
- );
1418
- const acceptedKeys = new Set(persistedKeys);
1419
- const pending = parsed.filter((event) => {
1420
- if (event.idempotencyKey === void 0) return true;
1421
- if (acceptedKeys.has(event.idempotencyKey)) return false;
1422
- acceptedKeys.add(event.idempotencyKey);
1423
- return true;
1424
- });
1425
- if (pending.length === 0) {
1426
- return;
1427
- }
1428
- const newestCreatedAtMs = Math.max(
1429
- ...pending.map((event) => event.createdAtMs)
1430
- );
1431
- await ensureConversationRow(
1432
- this.executor,
1433
- conversationId,
1434
- newestCreatedAtMs,
1435
- options
1436
- );
1437
- const cursor = await this.readCursor(conversationId);
1438
- const historyVersion = cursor.maxHistoryVersion ?? 0;
1439
- let seq = cursor.nextSeq;
1440
- const rows = [];
1441
- for (const event of pending) {
1442
- const actorIdentityId = await resolveEventActorIdentityId(
1443
- this.executor,
1444
- {
1445
- conversationId,
1446
- data: event.data,
1447
- nowMs: event.createdAtMs
1448
- }
1427
+ )).flatMap((row) => row.key ? [row.key] : [])
1449
1428
  );
1450
- rows.push(
1451
- insertFromEvent(
1452
- conversationId,
1453
- seq++,
1454
- historyVersion,
1455
- event,
1456
- actorIdentityId
1457
- )
1429
+ const acceptedKeys = new Set(persistedKeys);
1430
+ const pending = parsed.filter((event) => {
1431
+ if (event.idempotencyKey === void 0) return true;
1432
+ if (acceptedKeys.has(event.idempotencyKey)) return false;
1433
+ acceptedKeys.add(event.idempotencyKey);
1434
+ return true;
1435
+ });
1436
+ if (pending.length === 0) {
1437
+ return [];
1438
+ }
1439
+ const newestCreatedAtMs = Math.max(
1440
+ ...pending.map((event) => event.createdAtMs)
1458
1441
  );
1459
- if (actorIdentityId) {
1460
- await recordConversationParticipant(this.executor, {
1461
- actorIdentityId,
1462
- conversationId,
1463
- atMs: event.createdAtMs,
1464
- restoreArchive: eventUnarchivesConversation(event.data)
1465
- });
1442
+ await ensureConversationRow(
1443
+ this.executor,
1444
+ conversationId,
1445
+ newestCreatedAtMs,
1446
+ options
1447
+ );
1448
+ const cursor = await this.readCursor(conversationId);
1449
+ const historyVersion = cursor.maxHistoryVersion ?? 0;
1450
+ let seq = cursor.nextSeq;
1451
+ const rows = [];
1452
+ for (const event of pending) {
1453
+ const actorIdentityId = await resolveEventActorIdentityId(
1454
+ this.executor,
1455
+ {
1456
+ conversationId,
1457
+ data: event.data,
1458
+ nowMs: event.createdAtMs
1459
+ }
1460
+ );
1461
+ rows.push(
1462
+ insertFromEvent(
1463
+ conversationId,
1464
+ seq++,
1465
+ historyVersion,
1466
+ event,
1467
+ actorIdentityId
1468
+ )
1469
+ );
1470
+ if (actorIdentityId) {
1471
+ await recordConversationParticipant(this.executor, {
1472
+ actorIdentityId,
1473
+ conversationId,
1474
+ atMs: event.createdAtMs,
1475
+ restoreArchive: eventUnarchivesConversation(event.data)
1476
+ });
1477
+ }
1466
1478
  }
1479
+ await this.executor.db().insert(juniorConversationEvents).values(rows);
1480
+ return rows.map((row) => ({
1481
+ seq: row.seq,
1482
+ historyVersion: row.historyVersion
1483
+ }));
1467
1484
  }
1468
- await this.executor.db().insert(juniorConversationEvents).values(rows);
1469
- });
1485
+ );
1470
1486
  }
1471
1487
  async replaceHistory(conversationId, replacement) {
1472
1488
  const parsed = historyReplacementSchema.parse(replacement);
@@ -1484,6 +1500,9 @@ var SqlConversationEventStore = class {
1484
1500
  );
1485
1501
  });
1486
1502
  }
1503
+ async loadCurrentHistoryVersion(conversationId) {
1504
+ return (await this.readCursor(conversationId)).maxHistoryVersion ?? 0;
1505
+ }
1487
1506
  async loadCurrentHistory(conversationId) {
1488
1507
  const cursor = await this.readCursor(conversationId);
1489
1508
  if (cursor.maxHistoryVersion === null) {
@@ -1823,6 +1842,7 @@ export {
1823
1842
  parseDestination,
1824
1843
  requireSlackDestination,
1825
1844
  sameDestination,
1845
+ destinationKey,
1826
1846
  upsertIdentity,
1827
1847
  upsertLinkedIdentity,
1828
1848
  deleteProviderIdentityForSlackUser,
@@ -2,16 +2,16 @@ import {
2
2
  coerceThreadConversationState,
3
3
  getPersistedThreadState,
4
4
  persistThreadStateById
5
- } from "./chunk-S5HS6WRH.js";
5
+ } from "./chunk-FE3Y4KES.js";
6
6
  import {
7
7
  clearPendingAuth,
8
8
  markTurnClosed,
9
9
  markTurnCompleted
10
- } from "./chunk-K47OVEO4.js";
10
+ } from "./chunk-VYDIA2UL.js";
11
11
  import {
12
12
  hydrateConversationMessages,
13
13
  markConversationMessage
14
- } from "./chunk-ZFPEPWOO.js";
14
+ } from "./chunk-RZ3PBNDV.js";
15
15
  import {
16
16
  buildDeterministicTurnId
17
17
  } from "./chunk-DA2KGZZI.js";
@@ -20,13 +20,13 @@ import {
20
20
  findProviderError,
21
21
  getProviderErrorAttributes,
22
22
  getProviderErrorUserMessage
23
- } from "./chunk-WJJDQLVL.js";
23
+ } from "./chunk-LMYRF6HX.js";
24
24
  import {
25
25
  parseSlackMessageTs
26
26
  } from "./chunk-N7TMSOZH.js";
27
27
  import {
28
28
  buildTurnFailureResponse
29
- } from "./chunk-QY2IU47O.js";
29
+ } from "./chunk-HUQOXMDG.js";
30
30
 
31
31
  // src/chat/runtime/delivered-turn-state.ts
32
32
  function buildDeliveredTurnStatePatch(args) {
@@ -6,14 +6,14 @@ import {
6
6
  isStale,
7
7
  runNonInteractiveCommand,
8
8
  sleep
9
- } from "./chunk-KWXZMHJS.js";
9
+ } from "./chunk-LM7UE523.js";
10
10
  import {
11
11
  getStateAdapter
12
- } from "./chunk-IOUUS6H4.js";
12
+ } from "./chunk-7MYXH5LA.js";
13
13
  import {
14
14
  setSpanAttributes,
15
15
  withSpan
16
- } from "./chunk-QY2IU47O.js";
16
+ } from "./chunk-HUQOXMDG.js";
17
17
 
18
18
  // src/chat/sandbox/resources.ts
19
19
  var configuredResources;
@@ -1,13 +1,13 @@
1
1
  import {
2
2
  toOptionalTrimmed
3
- } from "./chunk-WJJDQLVL.js";
3
+ } from "./chunk-LMYRF6HX.js";
4
4
  import {
5
5
  pluginCatalogRuntime
6
- } from "./chunk-DXFUYLHX.js";
6
+ } from "./chunk-RKA22BQP.js";
7
7
  import {
8
8
  setSpanAttributes,
9
9
  setSpanStatus
10
- } from "./chunk-QY2IU47O.js";
10
+ } from "./chunk-HUQOXMDG.js";
11
11
 
12
12
  // src/chat/sandbox/paths.ts
13
13
  function normalizeWorkspaceRoot(input) {
@@ -7,7 +7,7 @@ import {
7
7
  toCanonicalInputMessage,
8
8
  toCanonicalOutputMessage,
9
9
  toGenAiMessagesTraceAttributes
10
- } from "./chunk-OICYQPKP.js";
10
+ } from "./chunk-KBPWC7NU.js";
11
11
  import {
12
12
  extractGenAiUsageAttributes,
13
13
  logException,
@@ -15,7 +15,7 @@ import {
15
15
  normalizeGenAiFinishReason,
16
16
  serializeGenAiAttribute,
17
17
  withSpan
18
- } from "./chunk-QY2IU47O.js";
18
+ } from "./chunk-HUQOXMDG.js";
19
19
 
20
20
  // src/chat/services/provider-error.ts
21
21
  var ProviderError = class extends Error {
@@ -674,6 +674,8 @@ function normalizeSlackEmojiName(value) {
674
674
  var MIN_AGENT_TURN_TIMEOUT_MS = 10 * 1e3;
675
675
  var DEFAULT_AGENT_TURN_TIMEOUT_MS = 12 * 60 * 1e3;
676
676
  var MAX_SLICES_PER_TURN = 100;
677
+ var MAX_TOOL_CALLS_PER_TURN = 150;
678
+ var MAX_CONSECUTIVE_AUTOMATED_TURNS = 10;
677
679
  var DEFAULT_FUNCTION_MAX_DURATION_SECONDS = 300;
678
680
  var DEFAULT_SLACK_SLASH_COMMAND = "/jr";
679
681
  var DEFAULT_PROCESSING_REACTION_EMOJI = "eyes";
@@ -902,6 +904,8 @@ function readBotConfig(env, functionMaxDurationSeconds) {
902
904
  loadingMessages: parseLoadingMessages(env.JUNIOR_LOADING_MESSAGES),
903
905
  visionModelId: validateGatewayModelId(env.AI_VISION_MODEL),
904
906
  maxSlicesPerTurn: MAX_SLICES_PER_TURN,
907
+ maxToolCallsPerTurn: MAX_TOOL_CALLS_PER_TURN,
908
+ maxConsecutiveAutomatedTurns: MAX_CONSECUTIVE_AUTOMATED_TURNS,
905
909
  turnTimeoutMs: parseAgentTurnTimeoutMs(
906
910
  env.AGENT_TURN_TIMEOUT_MS,
907
911
  maxTurnTimeoutMs
@@ -1,15 +1,15 @@
1
1
  import {
2
2
  AgentRunError,
3
3
  executeTurn
4
- } from "./chunk-DVU734PI.js";
4
+ } from "./chunk-CE2P6TOV.js";
5
5
  import {
6
6
  ConversationTurnLifecycleService
7
- } from "./chunk-WH5VV2RW.js";
7
+ } from "./chunk-7PQMTME5.js";
8
8
  import {
9
9
  getPersistedSandboxState,
10
10
  getPersistedThreadState,
11
11
  persistThreadStateById
12
- } from "./chunk-S5HS6WRH.js";
12
+ } from "./chunk-FE3Y4KES.js";
13
13
  import {
14
14
  AgentInvocationBusyError,
15
15
  AgentInvocationLimitError,
@@ -18,32 +18,32 @@ import {
18
18
  agentBindingSchema,
19
19
  agentInvocationSchema,
20
20
  createAgentInvocationSchema
21
- } from "./chunk-LXRTHE43.js";
21
+ } from "./chunk-JBSCMOLR.js";
22
22
  import {
23
23
  TurnInputCommitLostError,
24
24
  getAssistantReplyText,
25
25
  getConversationTurnBoundaryError,
26
26
  isTurnInputCommitLostError
27
- } from "./chunk-K47OVEO4.js";
27
+ } from "./chunk-VYDIA2UL.js";
28
28
  import {
29
29
  failTurnRecord,
30
30
  getTerminalAssistantMessages,
31
31
  getTurnRecord,
32
32
  openConversationProjection,
33
33
  saveTurnCheckpoint
34
- } from "./chunk-ZFPEPWOO.js";
34
+ } from "./chunk-RZ3PBNDV.js";
35
35
  import {
36
36
  appendAndEnqueueInboundMessage
37
- } from "./chunk-5LEVZYXF.js";
37
+ } from "./chunk-QKHZF2LH.js";
38
38
  import {
39
39
  getConversationEventStore,
40
40
  getConversationStore,
41
41
  getSqlExecutor
42
- } from "./chunk-2CYWEVOP.js";
42
+ } from "./chunk-KQ3GZGBK.js";
43
43
  import {
44
44
  juniorAgentBindings,
45
45
  juniorAgentInvocations
46
- } from "./chunk-5S6AQFNG.js";
46
+ } from "./chunk-FPQPYJEG.js";
47
47
 
48
48
  // src/chat/agent-invocations/work.ts
49
49
  import { z } from "zod";
@@ -1,32 +1,32 @@
1
1
  import {
2
2
  resolveBaseUrl
3
- } from "./chunk-COCVPDWX.js";
3
+ } from "./chunk-R5OHONYU.js";
4
4
  import {
5
5
  createPluginLogger,
6
6
  getPlugins,
7
7
  getSlackClient,
8
8
  withSlackRetries
9
- } from "./chunk-FQ5HFSFR.js";
9
+ } from "./chunk-PFQRZ4IB.js";
10
10
  import {
11
11
  getDb,
12
12
  parseDestination
13
- } from "./chunk-2CYWEVOP.js";
13
+ } from "./chunk-KQ3GZGBK.js";
14
14
  import {
15
15
  sleep
16
- } from "./chunk-KWXZMHJS.js";
16
+ } from "./chunk-LM7UE523.js";
17
17
  import {
18
18
  acquireActiveLock,
19
19
  getStateAdapter
20
- } from "./chunk-IOUUS6H4.js";
20
+ } from "./chunk-7MYXH5LA.js";
21
21
  import {
22
22
  pluginCatalogRuntime
23
- } from "./chunk-DXFUYLHX.js";
23
+ } from "./chunk-RKA22BQP.js";
24
24
  import {
25
25
  fetchWithBoundedOAuthErrorBodies
26
- } from "./chunk-QWY4KI2V.js";
26
+ } from "./chunk-X3PBQ4BK.js";
27
27
  import {
28
28
  isRecord
29
- } from "./chunk-QY2IU47O.js";
29
+ } from "./chunk-HUQOXMDG.js";
30
30
 
31
31
  // src/chat/capabilities/router.ts
32
32
  var ProviderCredentialRouter = class {