@sentry/junior 0.185.0 → 0.186.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 (88) hide show
  1. package/dist/{agent-hooks-NGZQLL5O.js → agent-hooks-4B3Z4WRK.js} +11 -11
  2. package/dist/api/schema/conversation.d.ts +8 -0
  3. package/dist/api/schema.js +1 -1
  4. package/dist/api.js +43 -35
  5. package/dist/app.js +1061 -216
  6. package/dist/{catalog-runtime-AAEAO2RL.js → catalog-runtime-AFJCAOHC.js} +4 -4
  7. package/dist/chat/api-turns/mailbox-input.d.ts +7 -0
  8. package/dist/chat/api-turns/routing.d.ts +18 -3
  9. package/dist/chat/conversations/turn-lifecycle.d.ts +2 -0
  10. package/dist/chat/providers/slack/runtime.d.ts +0 -2
  11. package/dist/chat/providers/slack/turn.d.ts +0 -2
  12. package/dist/chat/resource-events/actor.d.ts +7 -2
  13. package/dist/chat/resource-events/app-publisher.d.ts +18 -0
  14. package/dist/chat/resource-events/catalog.d.ts +19 -0
  15. package/dist/chat/resource-events/ingest.d.ts +0 -1
  16. package/dist/chat/resource-events/notification.d.ts +28 -3
  17. package/dist/chat/resource-events/runtime-catalog.d.ts +7 -2
  18. package/dist/chat/resource-events/store.d.ts +1 -13
  19. package/dist/chat/resource-events/workspace.d.ts +7 -3
  20. package/dist/chat/sandbox/egress/credentials.d.ts +5 -4
  21. package/dist/chat/sandbox/egress/session.d.ts +9 -9
  22. package/dist/chat/sandbox/errors.d.ts +1 -1
  23. package/dist/chat/sandbox/ref.d.ts +1 -1
  24. package/dist/chat/sandbox/snapshot/events.d.ts +8 -1
  25. package/dist/chat/sandbox/snapshot/not-ready-error.d.ts +6 -1
  26. package/dist/chat/sentry-links.d.ts +2 -0
  27. package/dist/chat/services/turn-session-routing.d.ts +20 -5
  28. package/dist/chat/task-execution/slack-resource-event.d.ts +47 -0
  29. package/dist/chat/task-execution/slack-work.d.ts +0 -21
  30. package/dist/chat/tools/event-tasks.d.ts +1 -1
  31. package/dist/chat/tools/resource-events.d.ts +1 -1
  32. package/dist/{chunk-D63IUQQE.js → chunk-2IBDVE62.js} +12 -9
  33. package/dist/{chunk-C6TS47CQ.js → chunk-2U7EPTRZ.js} +11 -5
  34. package/dist/{chunk-OMQ2J6F6.js → chunk-3CVEE6LA.js} +1 -1
  35. package/dist/{chunk-ABAX75GG.js → chunk-43LODHJM.js} +17 -3
  36. package/dist/{chunk-7MHNIGHP.js → chunk-64WF2GQ3.js} +1 -1
  37. package/dist/{chunk-X7NCJQAA.js → chunk-7EOWT62G.js} +1 -1
  38. package/dist/{chunk-MWOH6CIK.js → chunk-7EU4YSZ4.js} +201 -57
  39. package/dist/{chunk-4S47VHJR.js → chunk-ACGWTJ74.js} +3 -3
  40. package/dist/{chunk-LRI5IRGY.js → chunk-AD64YMEC.js} +2 -2
  41. package/dist/{chunk-FTVMXDNN.js → chunk-BRKB5R7P.js} +1 -1
  42. package/dist/{chunk-Y5G23T2D.js → chunk-CM6RTYSO.js} +5 -5
  43. package/dist/{chunk-QCT4226Q.js → chunk-CV5CPRVG.js} +3 -3
  44. package/dist/{chunk-QZKHHG3B.js → chunk-DHYZ4VKG.js} +382 -279
  45. package/dist/{chunk-PNYJOEVV.js → chunk-DOP3FIQC.js} +1 -1
  46. package/dist/{chunk-HJPC32TQ.js → chunk-EWRPUXE3.js} +9 -9
  47. package/dist/{chunk-EIJCPJOY.js → chunk-FFYDRLXW.js} +1 -1
  48. package/dist/{chunk-W7GCLNIV.js → chunk-GQMQCY7H.js} +2 -2
  49. package/dist/{chunk-6DOAUXLD.js → chunk-GSB3NTNS.js} +744 -1707
  50. package/dist/{chunk-WLKWN4CD.js → chunk-H7X2G2KS.js} +8 -5
  51. package/dist/{chunk-ATUWN6Z3.js → chunk-HKFLRIBD.js} +2 -2
  52. package/dist/{chunk-EJYP3NQ4.js → chunk-HWXP6RHG.js} +37 -3
  53. package/dist/{chunk-VH4IU3UC.js → chunk-JFPY6XFF.js} +19 -45
  54. package/dist/{chunk-FFHXG2FX.js → chunk-MCLWOBPN.js} +76 -16
  55. package/dist/{chunk-GJTIZQGJ.js → chunk-NRMAOGRS.js} +1 -1
  56. package/dist/{chunk-X2SS6BF7.js → chunk-O6GQO7VP.js} +27 -33
  57. package/dist/{chunk-DAPC2HTM.js → chunk-OZG7E22Y.js} +5 -5
  58. package/dist/{chunk-4K25ODAO.js → chunk-PFAZSRGR.js} +3 -1
  59. package/dist/{chunk-UUULGCKK.js → chunk-PZZOGHVR.js} +14 -4
  60. package/dist/{chunk-TVVAMOLS.js → chunk-QBL2AVFF.js} +1 -1
  61. package/dist/{chunk-4HA36IWS.js → chunk-QU3URVWG.js} +8 -8
  62. package/dist/{chunk-6Q7YZLCL.js → chunk-STOCCPWH.js} +9 -1
  63. package/dist/{chunk-EWEH2PJW.js → chunk-TXLBLGNQ.js} +5 -5
  64. package/dist/{chunk-U4CTAVWN.js → chunk-VOGOTEW7.js} +1 -1
  65. package/dist/{chunk-ZIF2S464.js → chunk-VQIWBJOP.js} +1 -1
  66. package/dist/{chunk-ZKKGFUWM.js → chunk-VQZYIVYN.js} +6 -6
  67. package/dist/{chunk-LVK4WJKM.js → chunk-VXL2LBPK.js} +1 -1
  68. package/dist/{chunk-7GAP2XG4.js → chunk-YXSBZRP7.js} +1 -1
  69. package/dist/cli/chat.js +32 -32
  70. package/dist/cli/check.js +5 -5
  71. package/dist/cli/plugins.js +12 -12
  72. package/dist/cli/snapshot-create.js +9 -9
  73. package/dist/cli/upgrade.js +6 -6
  74. package/dist/{db-TRJ77FAU.js → db-7XL4UPAE.js} +6 -6
  75. package/dist/instrumentation.js +3 -3
  76. package/dist/nitro.js +6 -6
  77. package/dist/{oauth-callback-server-XD5SV3MS.js → oauth-callback-server-RAOYHWDI.js} +27 -27
  78. package/dist/{runner-KFX7NG6D.js → runner-KMPBWRPM.js} +19 -19
  79. package/dist/{skills-J2AH26CW.js → skills-IPCALGLQ.js} +5 -5
  80. package/dist/spawn-OSOWTMBG.js +41 -0
  81. package/dist/task-runner-IQNBA3RY.js +34 -0
  82. package/dist/{validation-O5J4VOPF.js → validation-BSRCCX6N.js} +5 -5
  83. package/dist/version.js +1 -1
  84. package/dist/{work-ECPQTG3U.js → work-T6UFTOJY.js} +20 -20
  85. package/dist/{worker-RS3DXUDO.js → worker-L35OG7VA.js} +10 -10
  86. package/package.json +5 -5
  87. package/dist/spawn-VU3CSRI6.js +0 -41
  88. package/dist/task-runner-5JG3VIIY.js +0 -34
@@ -9,18 +9,18 @@ import {
9
9
  getSqlExecutor,
10
10
  sanitizePostgresJson,
11
11
  withConversationEventLock
12
- } from "./chunk-ABAX75GG.js";
12
+ } from "./chunk-43LODHJM.js";
13
13
  import {
14
14
  SANDBOX_REPOS_ROOT,
15
15
  SANDBOX_WORKSPACE_ROOT,
16
16
  sleep
17
- } from "./chunk-EJYP3NQ4.js";
17
+ } from "./chunk-HWXP6RHG.js";
18
18
  import {
19
19
  MUTATION_LOCK_TTL_MS,
20
20
  fenceLock,
21
21
  getStateAdapter,
22
22
  withLock
23
- } from "./chunk-PNYJOEVV.js";
23
+ } from "./chunk-DOP3FIQC.js";
24
24
  import {
25
25
  agentHistoryItemSchema,
26
26
  contextProvenance,
@@ -33,7 +33,7 @@ import {
33
33
  escapeXml,
34
34
  resolveGatewayModel,
35
35
  unwrapCurrentInstruction
36
- } from "./chunk-LRI5IRGY.js";
36
+ } from "./chunk-AD64YMEC.js";
37
37
  import {
38
38
  parseSlackMessageTs,
39
39
  toStoredSlackActor
@@ -43,7 +43,7 @@ import {
43
43
  logException,
44
44
  logWarn,
45
45
  setSpanAttributes
46
- } from "./chunk-OMQ2J6F6.js";
46
+ } from "./chunk-3CVEE6LA.js";
47
47
 
48
48
  // src/chat/turn-context-tag.ts
49
49
  var TURN_CONTEXT_TAG = "runtime-turn-context";
@@ -2308,6 +2308,9 @@ async function recordConversationActivityMetadata(args) {
2308
2308
  });
2309
2309
  const isChild = Boolean(conversation?.lineage);
2310
2310
  const destination = isChild ? void 0 : args.destination;
2311
+ if (!isChild && !destination && !conversation) {
2312
+ return;
2313
+ }
2311
2314
  const activitySource = isChild ? "internal" : args.source?.platform === "web" ? "web" : destination?.platform === "local" ? "local" : destination ? args.summary.surface : void 0;
2312
2315
  await conversationStore.recordActivity({
2313
2316
  activityAtMs: args.summary.updatedAtMs,
@@ -1,12 +1,12 @@
1
1
  import {
2
2
  pluginCatalogRuntime
3
- } from "./chunk-GJTIZQGJ.js";
3
+ } from "./chunk-NRMAOGRS.js";
4
4
  import {
5
5
  skillRoots
6
6
  } from "./chunk-TXKUKMVO.js";
7
7
  import {
8
8
  logWarn
9
- } from "./chunk-OMQ2J6F6.js";
9
+ } from "./chunk-3CVEE6LA.js";
10
10
 
11
11
  // src/chat/skills.ts
12
12
  import fs from "fs/promises";
@@ -1,13 +1,13 @@
1
1
  import {
2
2
  toOptionalTrimmed
3
- } from "./chunk-LRI5IRGY.js";
3
+ } from "./chunk-AD64YMEC.js";
4
4
  import {
5
5
  pluginCatalogRuntime
6
- } from "./chunk-GJTIZQGJ.js";
6
+ } from "./chunk-NRMAOGRS.js";
7
7
  import {
8
8
  setSpanAttributes,
9
9
  setSpanStatus
10
- } from "./chunk-OMQ2J6F6.js";
10
+ } from "./chunk-3CVEE6LA.js";
11
11
 
12
12
  // src/chat/sandbox/paths.ts
13
13
  function normalizeWorkspaceRoot(input) {
@@ -399,6 +399,32 @@ function getVercelSandboxCredentials() {
399
399
  return void 0;
400
400
  }
401
401
 
402
+ // src/chat/sandbox/snapshot/not-ready-error.ts
403
+ var WorkspaceSnapshotNotReadyError = class extends Error {
404
+ workspaceName;
405
+ constructor(workspaceName) {
406
+ super(`Workspace ${workspaceName} snapshot is not ready`);
407
+ this.name = "WorkspaceSnapshotNotReadyError";
408
+ this.workspaceName = workspaceName;
409
+ }
410
+ };
411
+ function getWorkspaceSnapshotNotReadyError(error) {
412
+ const seen = /* @__PURE__ */ new Set();
413
+ let current = error;
414
+ while (current instanceof Error && !seen.has(current)) {
415
+ if (current instanceof WorkspaceSnapshotNotReadyError) return current;
416
+ seen.add(current);
417
+ current = current.cause;
418
+ }
419
+ return void 0;
420
+ }
421
+ function isWorkspaceSnapshotNotReadyError(error) {
422
+ return getWorkspaceSnapshotNotReadyError(error) !== void 0;
423
+ }
424
+ function workspaceSnapshotNotReadyUserMessage(error) {
425
+ return `The ${error.workspaceName} workspace is still preparing its sandbox. Wait for that preparation to finish, then try again.`;
426
+ }
427
+
402
428
  // src/chat/sandbox/http-error-details.ts
403
429
  var DEFAULT_PREVIEW_LIMIT = 512;
404
430
  function toTrimmedString(value, maxChars) {
@@ -615,6 +641,10 @@ function isSandboxCommandStreamInterruptedError(error) {
615
641
  });
616
642
  }
617
643
  function wrapSandboxSetupError(error) {
644
+ const notReady = getWorkspaceSnapshotNotReadyError(error);
645
+ if (notReady) {
646
+ return notReady;
647
+ }
618
648
  try {
619
649
  const details = getSandboxErrorDetails(error);
620
650
  if (details.summary) {
@@ -667,6 +697,10 @@ export {
667
697
  buildNonInteractiveShellScript,
668
698
  runNonInteractiveCommand,
669
699
  getVercelSandboxCredentials,
700
+ WorkspaceSnapshotNotReadyError,
701
+ getWorkspaceSnapshotNotReadyError,
702
+ isWorkspaceSnapshotNotReadyError,
703
+ workspaceSnapshotNotReadyUserMessage,
670
704
  isAlreadyExistsError,
671
705
  isSandboxUnavailableError,
672
706
  isSandboxMissingError,
@@ -5,7 +5,7 @@ import {
5
5
  getConversationEventStore,
6
6
  getDb,
7
7
  getSqlExecutor
8
- } from "./chunk-ABAX75GG.js";
8
+ } from "./chunk-43LODHJM.js";
9
9
  import {
10
10
  juniorCodeChanges,
11
11
  juniorCodeRepositories,
@@ -16,7 +16,7 @@ import {
16
16
  juniorUsers,
17
17
  juniorWorkspaceRepos,
18
18
  juniorWorkspaces
19
- } from "./chunk-LVK4WJKM.js";
19
+ } from "./chunk-VXL2LBPK.js";
20
20
  import {
21
21
  SANDBOX_WORKSPACE_ROOT,
22
22
  getVercelSandboxCredentials,
@@ -24,16 +24,16 @@ import {
24
24
  isSandboxMissingError,
25
25
  runNonInteractiveCommand,
26
26
  sleep
27
- } from "./chunk-EJYP3NQ4.js";
27
+ } from "./chunk-HWXP6RHG.js";
28
28
  import {
29
29
  getStateAdapter
30
- } from "./chunk-PNYJOEVV.js";
30
+ } from "./chunk-DOP3FIQC.js";
31
31
  import {
32
32
  botConfig,
33
33
  completeObject,
34
34
  embedTexts,
35
35
  getSlackBotToken
36
- } from "./chunk-LRI5IRGY.js";
36
+ } from "./chunk-AD64YMEC.js";
37
37
  import {
38
38
  defaultModelId
39
39
  } from "./chunk-D4YV5TDV.js";
@@ -52,7 +52,7 @@ import {
52
52
  setSpanAttributes,
53
53
  setSpanStatus,
54
54
  withSpan
55
- } from "./chunk-OMQ2J6F6.js";
55
+ } from "./chunk-3CVEE6LA.js";
56
56
 
57
57
  // src/chat/plugins/agent-hooks.ts
58
58
  import {
@@ -473,14 +473,13 @@ function getDashboardTaskLink(taskId) {
473
473
  // src/chat/resource-events/store.ts
474
474
  import { createHash as createHash2 } from "crypto";
475
475
  import {
476
- destinationSchema,
477
476
  resourceEventMatchSchema,
478
477
  resourceEventMatches,
479
478
  resourceEventTypeSchema,
480
479
  stableResourceEventMatchKey
481
480
  } from "@sentry/junior-plugin-api";
482
481
  import { z as z2 } from "zod";
483
- var RESOURCE_EVENT_PREFIX = "junior:resource_event_subscription:v3";
482
+ var RESOURCE_EVENT_PREFIX = "junior:resource_event_subscription:v5";
484
483
  var INDEX_LOCK_TTL_MS = 1e4;
485
484
  var SUBSCRIPTION_LOCK_TTL_MS = 1e4;
486
485
  var SUBSCRIPTION_LOCK_WAIT_MS = 1e4;
@@ -491,7 +490,6 @@ var subscriptionIdIndexSchema = z2.array(z2.string().min(1));
491
490
  var subscriptionSchema = z2.object({
492
491
  conversationId: z2.string().min(1),
493
492
  createdAtMs: z2.number().finite(),
494
- destination: destinationSchema,
495
493
  events: z2.array(resourceEventTypeSchema).min(1),
496
494
  expiresAtMs: z2.number().finite(),
497
495
  id: z2.string().min(1),
@@ -513,14 +511,8 @@ function subscriptionKey(id) {
513
511
  function subscriptionLockKey(id) {
514
512
  return `${RESOURCE_EVENT_PREFIX}:lock:${id}`;
515
513
  }
516
- function resourceIndexKey(teamId, namespace, identifier) {
517
- return `${RESOURCE_EVENT_PREFIX}:resource:${digest(`${teamId}\0${namespace}\0${identifier}`)}`;
518
- }
519
- function subscriptionTeamId(destination) {
520
- if (destination.platform !== "slack") {
521
- throw new Error("Resource event subscriptions require a Slack destination");
522
- }
523
- return destination.teamId;
514
+ function resourceIndexKey(namespace, identifier) {
515
+ return `${RESOURCE_EVENT_PREFIX}:resource:${digest(`${namespace}\0${identifier}`)}`;
524
516
  }
525
517
  function conversationIndexKey(conversationId) {
526
518
  return `${RESOURCE_EVENT_PREFIX}:conversation:${digest(conversationId)}`;
@@ -606,7 +598,7 @@ async function readSubscriptionIdIndex(state, key) {
606
598
  function buildSubscriptionId(input) {
607
599
  const eventKey = [...new Set(input.events)].sort().join("\0");
608
600
  const matchKey = stableResourceEventMatchKey(input.match);
609
- const material = matchKey ? `${input.teamId}\0${input.namespace}\0${input.identifier}\0${input.conversationId}\0${eventKey}\0${matchKey}` : `${input.teamId}\0${input.namespace}\0${input.identifier}\0${input.conversationId}\0${eventKey}`;
601
+ const material = matchKey ? `${input.namespace}\0${input.identifier}\0${input.conversationId}\0${eventKey}\0${matchKey}` : `${input.namespace}\0${input.identifier}\0${input.conversationId}\0${eventKey}`;
610
602
  return `resub_${digest(material)}`;
611
603
  }
612
604
  async function withIndexLock(state, key, callback) {
@@ -658,7 +650,7 @@ function activeAt(subscription, nowMs) {
658
650
  return subscription.status === "active" && subscription.expiresAtMs > nowMs;
659
651
  }
660
652
  function matchesEvent(subscription, input) {
661
- return subscription.namespace === input.namespace && subscription.identifier === input.identifier && subscriptionTeamId(subscription.destination) === input.teamId && subscription.events.includes(input.eventType) && activeAt(subscription, input.nowMs) && resourceEventMatches(subscription.match, input.data);
653
+ return subscription.namespace === input.namespace && subscription.identifier === input.identifier && subscription.events.includes(input.eventType) && activeAt(subscription, input.nowMs) && resourceEventMatches(subscription.match, input.data);
662
654
  }
663
655
  async function createResourceEventSubscription(input, options = {}) {
664
656
  const state = options.state ?? getStateAdapter();
@@ -679,13 +671,11 @@ async function createResourceEventSubscription(input, options = {}) {
679
671
  events,
680
672
  match,
681
673
  namespace: input.namespace,
682
- identifier: input.identifier,
683
- teamId: subscriptionTeamId(input.destination)
674
+ identifier: input.identifier
684
675
  });
685
676
  const record = {
686
677
  conversationId: input.conversationId,
687
678
  createdAtMs: nowMs,
688
- destination: input.destination,
689
679
  events,
690
680
  expiresAtMs: input.expiresAtMs,
691
681
  id,
@@ -706,11 +696,7 @@ async function createResourceEventSubscription(input, options = {}) {
706
696
  );
707
697
  await addToIndex(
708
698
  state,
709
- resourceIndexKey(
710
- subscriptionTeamId(parsed.destination),
711
- input.namespace,
712
- input.identifier
713
- ),
699
+ resourceIndexKey(input.namespace, input.identifier),
714
700
  id,
715
701
  nowMs
716
702
  );
@@ -762,11 +748,7 @@ async function cancelResourceEventSubscription(input) {
762
748
  );
763
749
  await removeFromIndex(
764
750
  state,
765
- resourceIndexKey(
766
- subscriptionTeamId(current.destination),
767
- current.namespace,
768
- current.identifier
769
- ),
751
+ resourceIndexKey(current.namespace, current.identifier),
770
752
  input.id,
771
753
  nowMs
772
754
  );
@@ -805,7 +787,7 @@ async function collectResourceEventMatchKeys(input) {
805
787
  for (const identifier of identifiers) {
806
788
  const ids = await readSubscriptionIdIndex(
807
789
  state,
808
- resourceIndexKey(input.teamId, input.namespace, identifier)
790
+ resourceIndexKey(input.namespace, identifier)
809
791
  );
810
792
  const records = await Promise.all(
811
793
  ids.map(
@@ -816,7 +798,6 @@ async function collectResourceEventMatchKeys(input) {
816
798
  if (!record) continue;
817
799
  if (record.namespace !== input.namespace) continue;
818
800
  if (record.identifier !== identifier) continue;
819
- if (subscriptionTeamId(record.destination) !== input.teamId) continue;
820
801
  if (!activeAt(record, nowMs)) continue;
821
802
  if (!record.events.some((eventType) => eventTypes.has(eventType))) continue;
822
803
  for (const key of Object.keys(record.match ?? {})) {
@@ -832,7 +813,7 @@ async function findMatchingResourceEventSubscriptions(input) {
832
813
  const nowMs = input.nowMs ?? Date.now();
833
814
  const ids = await readSubscriptionIdIndex(
834
815
  state,
835
- resourceIndexKey(input.teamId, input.namespace, input.identifier)
816
+ resourceIndexKey(input.namespace, input.identifier)
836
817
  );
837
818
  const records = await Promise.all(
838
819
  ids.map(
@@ -845,8 +826,7 @@ async function findMatchingResourceEventSubscriptions(input) {
845
826
  eventType: input.eventType,
846
827
  nowMs,
847
828
  namespace: input.namespace,
848
- identifier: input.identifier,
849
- teamId: input.teamId
829
+ identifier: input.identifier
850
830
  })
851
831
  );
852
832
  }
@@ -866,8 +846,7 @@ async function deliverResourceEventSubscription(input) {
866
846
  eventType: input.eventType,
867
847
  nowMs,
868
848
  namespace: input.namespace,
869
- identifier: input.identifier,
870
- teamId: input.teamId
849
+ identifier: input.identifier
871
850
  })) {
872
851
  return false;
873
852
  }
@@ -891,11 +870,7 @@ async function deliverResourceEventSubscription(input) {
891
870
  );
892
871
  await removeFromIndex(
893
872
  state,
894
- resourceIndexKey(
895
- subscriptionTeamId(current.destination),
896
- current.namespace,
897
- current.identifier
898
- ),
873
+ resourceIndexKey(current.namespace, current.identifier),
899
874
  current.id,
900
875
  nowMs
901
876
  );
@@ -2711,7 +2686,6 @@ function getPluginTools(context, sandbox = createSandboxCapability(context.works
2711
2686
  }
2712
2687
  const subscription = await createResourceEventSubscription({
2713
2688
  conversationId: context.conversationId,
2714
- destination: context.destination,
2715
2689
  events: input.events,
2716
2690
  expiresAtMs: Date.now() + RESOURCE_SUBSCRIPTION_DEFAULT_TTL_MS,
2717
2691
  intent: input.intent,
@@ -1,12 +1,12 @@
1
1
  import {
2
2
  coerceThreadConversationState,
3
3
  getPersistedThreadState
4
- } from "./chunk-Y5G23T2D.js";
4
+ } from "./chunk-CM6RTYSO.js";
5
5
  import {
6
6
  pluginTaskId,
7
7
  pluginTaskParamsSchema,
8
8
  sendVercelPluginTask
9
- } from "./chunk-4S47VHJR.js";
9
+ } from "./chunk-ACGWTJ74.js";
10
10
  import {
11
11
  getPiMessageRole,
12
12
  getTurnRecord,
@@ -16,7 +16,7 @@ import {
16
16
  isToolResultMessage,
17
17
  normalizeToolNameFromResult,
18
18
  stripRuntimeTurnContext
19
- } from "./chunk-WLKWN4CD.js";
19
+ } from "./chunk-H7X2G2KS.js";
20
20
  import {
21
21
  createPluginConversationEvents,
22
22
  createPluginEmbedder,
@@ -25,21 +25,21 @@ import {
25
25
  createPluginState,
26
26
  getPlugins,
27
27
  readActorIdentity
28
- } from "./chunk-VH4IU3UC.js";
28
+ } from "./chunk-JFPY6XFF.js";
29
29
  import {
30
30
  JUNIOR_THREAD_STATE_TTL_MS
31
31
  } from "./chunk-3Y47VMHV.js";
32
32
  import {
33
33
  getConversationStore,
34
34
  getDb
35
- } from "./chunk-ABAX75GG.js";
35
+ } from "./chunk-43LODHJM.js";
36
36
  import {
37
37
  juniorConversations,
38
38
  juniorTaskExecutions
39
- } from "./chunk-LVK4WJKM.js";
39
+ } from "./chunk-VXL2LBPK.js";
40
40
  import {
41
41
  getStateAdapter
42
- } from "./chunk-PNYJOEVV.js";
42
+ } from "./chunk-DOP3FIQC.js";
43
43
  import {
44
44
  sameActorIdentity
45
45
  } from "./chunk-GFBR4S3Q.js";
@@ -51,26 +51,85 @@ import {
51
51
  } from "./chunk-N7TMSOZH.js";
52
52
  import {
53
53
  logWarn
54
- } from "./chunk-OMQ2J6F6.js";
54
+ } from "./chunk-3CVEE6LA.js";
55
55
 
56
56
  // src/chat/plugins/task-runner.ts
57
57
  import { pluginRunContextSchema } from "@sentry/junior-plugin-api";
58
58
 
59
59
  // src/chat/services/turn-session-routing.ts
60
+ async function loadConversationChain(conversationId, conversationStore) {
61
+ const chain = [];
62
+ const seen = /* @__PURE__ */ new Set();
63
+ let cursor = conversationId;
64
+ while (cursor && !seen.has(cursor)) {
65
+ seen.add(cursor);
66
+ const conversation = await conversationStore.get({ conversationId: cursor });
67
+ if (!conversation) {
68
+ break;
69
+ }
70
+ chain.push(conversation);
71
+ cursor = conversation.lineage?.parentConversationId;
72
+ }
73
+ return chain;
74
+ }
75
+ function slackSourceForDestination(args) {
76
+ if (args.source?.platform !== "slack" || args.source.channelId !== args.destination.channelId) {
77
+ return void 0;
78
+ }
79
+ const threadTs = args.source.threadTs?.trim();
80
+ return {
81
+ platform: "slack",
82
+ visibility: args.source.visibility ?? "public",
83
+ teamId: args.source.teamId?.trim() || args.destination.teamId,
84
+ channelId: args.source.channelId,
85
+ ...threadTs ? { threadTs } : void 0
86
+ };
87
+ }
88
+ async function resolveConversationRouting(args) {
89
+ const conversationStore = args.conversationStore ?? (await import("./db-7XL4UPAE.js")).getConversationStore();
90
+ const chain = await loadConversationChain(
91
+ args.conversationId,
92
+ conversationStore
93
+ );
94
+ let destination;
95
+ let source;
96
+ let locationId;
97
+ for (const conversation of chain) {
98
+ destination ??= conversation.destination;
99
+ source ??= conversation.sessionSource;
100
+ locationId ??= conversation.location?.id;
101
+ if (destination && source) {
102
+ break;
103
+ }
104
+ }
105
+ if (!destination) {
106
+ return void 0;
107
+ }
108
+ if (destination.platform === "slack") {
109
+ const slackSource = slackSourceForDestination({ destination, source });
110
+ return {
111
+ destination,
112
+ ...locationId ? { locationId } : void 0,
113
+ ...slackSource ? { source: slackSource } : void 0
114
+ };
115
+ }
116
+ return {
117
+ destination,
118
+ ...locationId ? { locationId } : void 0,
119
+ ...source ? { source } : void 0
120
+ };
121
+ }
60
122
  async function resolveTurnSessionRouting(args) {
61
- const conversationStore = args.conversationStore ?? (await import("./db-TRJ77FAU.js")).getConversationStore();
62
- const conversation = await conversationStore.get({
63
- conversationId: args.conversationId
64
- });
65
- if (!conversation?.destination || !conversation.sessionSource) {
123
+ const routing = await resolveConversationRouting(args);
124
+ if (!routing?.destination || !routing.source) {
66
125
  throw new Error(
67
126
  `Conversation ${args.conversationId} is missing durable routing metadata`
68
127
  );
69
128
  }
70
129
  return {
71
- destination: conversation.destination,
72
- ...conversation.location ? { locationId: conversation.location.id } : void 0,
73
- source: conversation.sessionSource
130
+ destination: routing.destination,
131
+ source: routing.source,
132
+ ...routing.locationId ? { locationId: routing.locationId } : void 0
74
133
  };
75
134
  }
76
135
 
@@ -1023,6 +1082,7 @@ export {
1023
1082
  listPendingDispatchMailboxAppends,
1024
1083
  claimDispatchMailboxAppend,
1025
1084
  getPluginDispatchProjection,
1085
+ resolveConversationRouting,
1026
1086
  resolveTurnSessionRouting,
1027
1087
  scheduleSessionCompletedPluginTasks,
1028
1088
  processPluginTask
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  createPluginCatalogRuntime
3
- } from "./chunk-7MHNIGHP.js";
3
+ } from "./chunk-64WF2GQ3.js";
4
4
 
5
5
  // src/chat/plugins/catalog-runtime.ts
6
6
  var pluginCatalogRuntime = createPluginCatalogRuntime();