@sentry/junior 0.150.1 → 0.151.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 (71) hide show
  1. package/dist/{agent-hooks-G4LEACQB.js → agent-hooks-EYUAEBMA.js} +10 -10
  2. package/dist/api/schema/conversation.d.ts +24 -4
  3. package/dist/api/schema.js +1 -1
  4. package/dist/api.js +63 -35
  5. package/dist/app.js +123 -200
  6. package/dist/{catalog-runtime-ZRSNE2MH.js → catalog-runtime-2LCLLOBI.js} +5 -5
  7. package/dist/chat/agent/skills.d.ts +5 -4
  8. package/dist/chat/agent/tools.d.ts +5 -5
  9. package/dist/chat/conversations/history.d.ts +12 -3
  10. package/dist/chat/conversations/projection.d.ts +7 -3
  11. package/dist/chat/mcp/tool-manager.d.ts +0 -4
  12. package/dist/chat/runtime/agent-run-outcome.d.ts +4 -0
  13. package/dist/chat/tools/search-conversation-events.d.ts +1 -1
  14. package/dist/chat/tools/skill/call-mcp-tool.d.ts +0 -1
  15. package/dist/chat/tools/skill/load-skill.d.ts +2 -5
  16. package/dist/chat/tools/types.d.ts +1 -2
  17. package/dist/{chunk-TZRYLW3R.js → chunk-2MGJ64SL.js} +1 -1
  18. package/dist/{chunk-IQW6RFXG.js → chunk-3WOK4ZLX.js} +72 -218
  19. package/dist/{chunk-XED3H34M.js → chunk-4ABTAQYC.js} +3 -3
  20. package/dist/{chunk-KFHJQYKQ.js → chunk-5N3XLYBW.js} +1 -1
  21. package/dist/{chunk-JVOLC6JZ.js → chunk-6A46QL4O.js} +4 -4
  22. package/dist/{chunk-2DIRU2C2.js → chunk-6DLWRSGV.js} +1 -1
  23. package/dist/{chunk-OWLJZ6I7.js → chunk-6PGJPCN2.js} +1 -1
  24. package/dist/{chunk-AD6N2KNE.js → chunk-6WNWM5JD.js} +5 -5
  25. package/dist/{chunk-D2PVJU5E.js → chunk-AGSUPAD5.js} +2 -2
  26. package/dist/{chunk-W3FQZAX5.js → chunk-B7KWBJAR.js} +6 -6
  27. package/dist/{chunk-QO3OSJDS.js → chunk-C7D2ONB5.js} +1 -1
  28. package/dist/{chunk-LSI3EKZQ.js → chunk-CL5DT6D2.js} +4 -4
  29. package/dist/{chunk-FGP5W3NS.js → chunk-D22FO4LW.js} +2 -2
  30. package/dist/{chunk-6IWDFUXW.js → chunk-DJAOSWB6.js} +1 -1
  31. package/dist/{chunk-JBYWR6FW.js → chunk-EMB4VY7H.js} +5 -5
  32. package/dist/{chunk-R53UTQ2Q.js → chunk-H7ZMEHAN.js} +1 -1
  33. package/dist/{chunk-N6QJAPZS.js → chunk-J5LAA2LI.js} +9 -9
  34. package/dist/{chunk-2AWDPNP7.js → chunk-JIJOPRD4.js} +16 -10
  35. package/dist/{chunk-6A24WEKX.js → chunk-JSKTDBSS.js} +4 -4
  36. package/dist/{chunk-GZ25ZSTX.js → chunk-K3QXMZDU.js} +11 -4
  37. package/dist/{chunk-IZE2EGCX.js → chunk-KPQBQRNM.js} +5 -5
  38. package/dist/{chunk-SZ74ECCC.js → chunk-M6KRPBXC.js} +6 -6
  39. package/dist/{chunk-3WIFZBJL.js → chunk-OAPPJ3TM.js} +1 -1
  40. package/dist/{chunk-LWFHRWJI.js → chunk-OFRJXFTH.js} +8 -8
  41. package/dist/{chunk-2Z7YX5PI.js → chunk-OYRFUQOV.js} +106 -16
  42. package/dist/{chunk-6ZYGORV4.js → chunk-PQUV3NA5.js} +2 -2
  43. package/dist/{chunk-5NOHC2Z4.js → chunk-PWMVR2MD.js} +1 -1
  44. package/dist/{chunk-QNSV46AW.js → chunk-QVQBWWXQ.js} +6 -6
  45. package/dist/{chunk-4JV7GUUH.js → chunk-UDDCHQN2.js} +1 -1
  46. package/dist/{chunk-JUBPTYNO.js → chunk-WVXFEQXE.js} +1 -1
  47. package/dist/{chunk-3JVUWLR7.js → chunk-XN3QKNQX.js} +8 -1
  48. package/dist/{chunk-B2YA2G26.js → chunk-YN4W5SRJ.js} +1 -1
  49. package/dist/{chunk-QZGYKKH6.js → chunk-ZGSL5ARH.js} +50 -22
  50. package/dist/cli/chat.js +30 -30
  51. package/dist/cli/check.js +6 -6
  52. package/dist/cli/plugins.js +13 -13
  53. package/dist/cli/snapshot-create.js +9 -9
  54. package/dist/cli/upgrade.js +7 -7
  55. package/dist/{db-WRA5ZHYE.js → db-ALCBI4JZ.js} +7 -7
  56. package/dist/instrumentation.js +4 -4
  57. package/dist/nitro.js +2 -2
  58. package/dist/{oauth-callback-server-QWAYG3MI.js → oauth-callback-server-3RRMG62B.js} +23 -23
  59. package/dist/{runner-5JQ54J6P.js → runner-V6C3EELU.js} +14 -14
  60. package/dist/{skills-3YD55WPO.js → skills-43PFYZIZ.js} +6 -6
  61. package/dist/spawn-UZNNTNFU.js +38 -0
  62. package/dist/{validation-ZXE3IRSB.js → validation-4MNN6QKE.js} +6 -6
  63. package/dist/version.js +1 -1
  64. package/dist/{work-7G2U64WI.js → work-YZO6XTEB.js} +17 -17
  65. package/dist/{worker-HJM2FZNI.js → worker-42AR7323.js} +11 -11
  66. package/migrations/0025_mcp_credential_subject.sql +8 -0
  67. package/migrations/meta/0025_snapshot.json +2275 -0
  68. package/migrations/meta/_journal.json +7 -0
  69. package/package.json +4 -4
  70. package/dist/chat/pi/derived-state.d.ts +0 -5
  71. package/dist/spawn-OOO26XDL.js +0 -38
@@ -1,12 +1,12 @@
1
1
  import {
2
2
  appendAndEnqueueInboundMessage
3
- } from "./chunk-JVOLC6JZ.js";
3
+ } from "./chunk-6A46QL4O.js";
4
4
  import {
5
5
  ConversationTurnLifecycleService,
6
6
  getPersistedSandboxState,
7
7
  getPersistedThreadState,
8
8
  persistThreadStateById
9
- } from "./chunk-JBYWR6FW.js";
9
+ } from "./chunk-EMB4VY7H.js";
10
10
  import {
11
11
  AgentInvocationBusyError,
12
12
  AgentInvocationLimitError,
@@ -15,7 +15,7 @@ import {
15
15
  agentBindingSchema,
16
16
  agentInvocationSchema,
17
17
  createAgentInvocationSchema
18
- } from "./chunk-IZE2EGCX.js";
18
+ } from "./chunk-KPQBQRNM.js";
19
19
  import {
20
20
  TurnInputCommitLostError,
21
21
  failTurnRecord,
@@ -26,16 +26,16 @@ import {
26
26
  isTurnInputCommitLostError,
27
27
  openConversationProjection,
28
28
  saveTurnCheckpoint
29
- } from "./chunk-2AWDPNP7.js";
29
+ } from "./chunk-JIJOPRD4.js";
30
30
  import {
31
31
  getConversationEventStore,
32
32
  getConversationStore,
33
33
  getSqlExecutor
34
- } from "./chunk-GZ25ZSTX.js";
34
+ } from "./chunk-K3QXMZDU.js";
35
35
  import {
36
36
  juniorAgentBindings,
37
37
  juniorAgentInvocations
38
- } from "./chunk-KFHJQYKQ.js";
38
+ } from "./chunk-5N3XLYBW.js";
39
39
 
40
40
  // src/chat/agent-invocations/work.ts
41
41
  import { z } from "zod";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  createAndEnqueueAgentInvocation
3
- } from "./chunk-W3FQZAX5.js";
3
+ } from "./chunk-B7KWBJAR.js";
4
4
  import {
5
5
  actorFromRun,
6
6
  toolInvocationDestination
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  getTurnRequestDeadline
3
- } from "./chunk-R53UTQ2Q.js";
3
+ } from "./chunk-H7ZMEHAN.js";
4
4
  import {
5
5
  CONVERSATION_WORK_CHECK_IN_INTERVAL_MS,
6
6
  CONVERSATION_WORK_MAX_RETRIES,
@@ -21,20 +21,20 @@ import {
21
21
  releaseConversationWork,
22
22
  requestAnotherSlice,
23
23
  startConversationWork
24
- } from "./chunk-JVOLC6JZ.js";
24
+ } from "./chunk-6A46QL4O.js";
25
25
  import {
26
26
  ConversationQueueMessageRejectedError
27
27
  } from "./chunk-JAL3CH4G.js";
28
28
  import {
29
29
  getChatConfig,
30
30
  isProviderRetryError
31
- } from "./chunk-FGP5W3NS.js";
31
+ } from "./chunk-D22FO4LW.js";
32
32
  import {
33
33
  logException,
34
34
  logInfo,
35
35
  logWarn,
36
36
  withLogContext
37
- } from "./chunk-3WIFZBJL.js";
37
+ } from "./chunk-OAPPJ3TM.js";
38
38
 
39
39
  // src/chat/task-execution/worker.ts
40
40
  var CONVERSATION_WORK_DEFER_DELAY_MS = 15e3;
@@ -3,7 +3,7 @@ import {
3
3
  toCanonicalInputMessage,
4
4
  toCanonicalOutputMessage,
5
5
  toGenAiMessagesTraceAttributes
6
- } from "./chunk-5NOHC2Z4.js";
6
+ } from "./chunk-PWMVR2MD.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-3WIFZBJL.js";
14
+ } from "./chunk-OAPPJ3TM.js";
15
15
 
16
16
  // src/chat/services/provider-error.ts
17
17
  var ProviderError = class extends Error {
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  JUNIOR_VERSION
3
- } from "./chunk-JUBPTYNO.js";
3
+ } from "./chunk-WVXFEQXE.js";
4
4
 
5
5
  // src/deployment.ts
6
6
  var JUNIOR_HEARTBEAT_ROUTE = "/api/internal/heartbeat";
@@ -1,18 +1,18 @@
1
1
  import {
2
2
  persistConversationMessages
3
- } from "./chunk-2AWDPNP7.js";
3
+ } from "./chunk-JIJOPRD4.js";
4
4
  import {
5
5
  JUNIOR_THREAD_STATE_TTL_MS
6
6
  } from "./chunk-3Y47VMHV.js";
7
7
  import {
8
8
  getDb
9
- } from "./chunk-GZ25ZSTX.js";
9
+ } from "./chunk-K3QXMZDU.js";
10
10
  import {
11
11
  juniorLocationConfigurations
12
- } from "./chunk-KFHJQYKQ.js";
12
+ } from "./chunk-5N3XLYBW.js";
13
13
  import {
14
14
  getStateAdapter
15
- } from "./chunk-B2YA2G26.js";
15
+ } from "./chunk-YN4W5SRJ.js";
16
16
  import {
17
17
  juniorDestinations
18
18
  } from "./chunk-VFUK3X5B.js";
@@ -20,7 +20,7 @@ import {
20
20
  isRecord,
21
21
  toOptionalNumber,
22
22
  toOptionalString
23
- } from "./chunk-3WIFZBJL.js";
23
+ } from "./chunk-OAPPJ3TM.js";
24
24
 
25
25
  // src/chat/conversations/turn-lifecycle.ts
26
26
  var ConversationTurnLifecycleService = class {
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  FUNCTION_TIMEOUT_BUFFER_SECONDS,
3
3
  getChatConfig
4
- } from "./chunk-FGP5W3NS.js";
4
+ } from "./chunk-D22FO4LW.js";
5
5
 
6
6
  // src/chat/runtime/request-deadline.ts
7
7
  import { AsyncLocalStorage } from "async_hooks";
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  coerceThreadConversationState,
3
3
  getPersistedThreadState
4
- } from "./chunk-JBYWR6FW.js";
4
+ } from "./chunk-EMB4VY7H.js";
5
5
  import {
6
6
  pluginTaskId,
7
7
  pluginTaskParamsSchema,
@@ -20,7 +20,7 @@ import {
20
20
  markTurnCompleted,
21
21
  normalizeToolNameFromResult,
22
22
  stripRuntimeTurnContext
23
- } from "./chunk-2AWDPNP7.js";
23
+ } from "./chunk-JIJOPRD4.js";
24
24
  import {
25
25
  JUNIOR_THREAD_STATE_TTL_MS
26
26
  } from "./chunk-3Y47VMHV.js";
@@ -31,25 +31,25 @@ import {
31
31
  createPluginModel,
32
32
  createPluginState,
33
33
  getPlugins
34
- } from "./chunk-QNSV46AW.js";
34
+ } from "./chunk-QVQBWWXQ.js";
35
35
  import {
36
36
  getConversationStore,
37
37
  getDb,
38
38
  sameActorIdentity
39
- } from "./chunk-GZ25ZSTX.js";
39
+ } from "./chunk-K3QXMZDU.js";
40
40
  import {
41
41
  juniorConversations,
42
42
  juniorTaskExecutions
43
- } from "./chunk-KFHJQYKQ.js";
43
+ } from "./chunk-5N3XLYBW.js";
44
44
  import {
45
45
  getStateAdapter
46
- } from "./chunk-B2YA2G26.js";
46
+ } from "./chunk-YN4W5SRJ.js";
47
47
  import {
48
48
  ProviderError,
49
49
  findProviderError,
50
50
  getProviderErrorAttributes,
51
51
  getProviderErrorUserMessage
52
- } from "./chunk-FGP5W3NS.js";
52
+ } from "./chunk-D22FO4LW.js";
53
53
  import {
54
54
  credentialSubjectSchema
55
55
  } from "./chunk-RUIXF3YQ.js";
@@ -59,7 +59,7 @@ import {
59
59
  import {
60
60
  buildTurnFailureResponse,
61
61
  logWarn
62
- } from "./chunk-3WIFZBJL.js";
62
+ } from "./chunk-OAPPJ3TM.js";
63
63
 
64
64
  // src/chat/runtime/delivered-turn-state.ts
65
65
  function buildDeliveredTurnStatePatch(args) {
@@ -85,7 +85,7 @@ import { pluginRunContextSchema } from "@sentry/junior-plugin-api";
85
85
 
86
86
  // src/chat/services/turn-session-routing.ts
87
87
  async function resolveTurnSessionRouting(args) {
88
- const conversationStore = args.conversationStore ?? (await import("./db-WRA5ZHYE.js")).getConversationStore();
88
+ const conversationStore = args.conversationStore ?? (await import("./db-ALCBI4JZ.js")).getConversationStore();
89
89
  const conversation = await conversationStore.get({
90
90
  conversationId: args.conversationId
91
91
  });
@@ -13,7 +13,7 @@ import {
13
13
  instructionProvenanceFor,
14
14
  sanitizePostgresJson,
15
15
  withConversationEventLock
16
- } from "./chunk-GZ25ZSTX.js";
16
+ } from "./chunk-K3QXMZDU.js";
17
17
  import {
18
18
  SANDBOX_WORKSPACE_ROOT,
19
19
  sleep
@@ -23,14 +23,14 @@ import {
23
23
  fenceLock,
24
24
  getStateAdapter,
25
25
  withLock
26
- } from "./chunk-B2YA2G26.js";
26
+ } from "./chunk-YN4W5SRJ.js";
27
27
  import {
28
28
  botConfig,
29
29
  completeText,
30
30
  escapeXml,
31
31
  resolveGatewayModel,
32
32
  unwrapCurrentInstruction
33
- } from "./chunk-FGP5W3NS.js";
33
+ } from "./chunk-D22FO4LW.js";
34
34
  import {
35
35
  toStoredSlackActor
36
36
  } from "./chunk-HZF5P5UN.js";
@@ -42,7 +42,7 @@ import {
42
42
  logException,
43
43
  logWarn,
44
44
  setSpanAttributes
45
- } from "./chunk-3WIFZBJL.js";
45
+ } from "./chunk-OAPPJ3TM.js";
46
46
 
47
47
  // src/chat/turn-context-tag.ts
48
48
  var TURN_CONTEXT_TAG = "runtime-turn-context";
@@ -1142,10 +1142,10 @@ function projectConversationEvents(events, options) {
1142
1142
  }
1143
1143
 
1144
1144
  // src/chat/conversations/projection.ts
1145
- function connectedMcpProvidersFromEvents(events) {
1145
+ function connectedMcpProvidersFromEvents(events, credentialSubjectId) {
1146
1146
  const providers = /* @__PURE__ */ new Set();
1147
1147
  for (const event of events) {
1148
- if (event.data.type === "mcp_provider_connected") {
1148
+ if (event.data.type === "mcp_provider_connected" && event.data.credentialSubjectId === credentialSubjectId) {
1149
1149
  providers.add(event.data.provider);
1150
1150
  }
1151
1151
  }
@@ -1285,10 +1285,10 @@ async function loadTurnProjection(args) {
1285
1285
  return projectConversationEvents(historyEvents);
1286
1286
  }
1287
1287
  async function loadConnectedMcpProviders(args) {
1288
- const events = await getConversationEventStore().loadCurrentHistory(
1288
+ const events = await getConversationEventStore().loadHistory(
1289
1289
  args.conversationId
1290
1290
  );
1291
- return connectedMcpProvidersFromEvents(events);
1291
+ return connectedMcpProvidersFromEvents(events, args.credentialSubjectId);
1292
1292
  }
1293
1293
  function messageTimestamp2(message) {
1294
1294
  const timestamp = message.timestamp;
@@ -1404,12 +1404,18 @@ async function commitMessagesLocked(args, executor) {
1404
1404
  async function recordMcpProviderConnected(args) {
1405
1405
  const eventStore = getConversationEventStore();
1406
1406
  const events = await eventStore.loadCurrentHistory(args.conversationId);
1407
- if (connectedMcpProvidersFromEvents(events).includes(args.provider)) {
1407
+ if (connectedMcpProvidersFromEvents(events, args.credentialSubjectId).includes(
1408
+ args.provider
1409
+ )) {
1408
1410
  return;
1409
1411
  }
1410
1412
  await eventStore.append(args.conversationId, [
1411
1413
  {
1412
- data: { type: "mcp_provider_connected", provider: args.provider },
1414
+ data: {
1415
+ type: "mcp_provider_connected",
1416
+ provider: args.provider,
1417
+ credentialSubjectId: args.credentialSubjectId
1418
+ },
1413
1419
  createdAtMs: Date.now()
1414
1420
  }
1415
1421
  ]);
@@ -4,18 +4,18 @@ import {
4
4
  } from "./chunk-EM225ITJ.js";
5
5
  import {
6
6
  getStateAdapter
7
- } from "./chunk-B2YA2G26.js";
7
+ } from "./chunk-YN4W5SRJ.js";
8
8
  import {
9
9
  toOptionalTrimmed
10
- } from "./chunk-FGP5W3NS.js";
10
+ } from "./chunk-D22FO4LW.js";
11
11
  import {
12
12
  pluginCatalogRuntime
13
- } from "./chunk-2DIRU2C2.js";
13
+ } from "./chunk-6DLWRSGV.js";
14
14
  import {
15
15
  setSpanAttributes,
16
16
  setSpanStatus,
17
17
  withSpan
18
- } from "./chunk-3WIFZBJL.js";
18
+ } from "./chunk-OAPPJ3TM.js";
19
19
 
20
20
  // src/chat/sandbox/resources.ts
21
21
  var configuredResources;
@@ -5,12 +5,12 @@ import {
5
5
  juniorConversations,
6
6
  juniorIdentities,
7
7
  juniorUsers
8
- } from "./chunk-KFHJQYKQ.js";
8
+ } from "./chunk-5N3XLYBW.js";
9
9
  import {
10
10
  TURN_REASONING_LEVELS,
11
11
  getChatConfig,
12
12
  modelProfileSchema
13
- } from "./chunk-FGP5W3NS.js";
13
+ } from "./chunk-D22FO4LW.js";
14
14
  import {
15
15
  juniorDestinations
16
16
  } from "./chunk-VFUK3X5B.js";
@@ -20,7 +20,7 @@ import {
20
20
  } from "./chunk-F3B2YJ76.js";
21
21
  import {
22
22
  normalizeIdentityEmail
23
- } from "./chunk-3WIFZBJL.js";
23
+ } from "./chunk-OAPPJ3TM.js";
24
24
 
25
25
  // src/chat/conversations/sql/store.ts
26
26
  import { randomUUID as randomUUID2 } from "crypto";
@@ -1095,6 +1095,11 @@ var historyReplacementSchema = z3.object({
1095
1095
  }).strict();
1096
1096
  var mcpProviderConnectedEventDataSchema = z3.object({
1097
1097
  type: z3.literal("mcp_provider_connected"),
1098
+ provider: z3.string().min(1),
1099
+ credentialSubjectId: z3.string().min(1)
1100
+ }).strict();
1101
+ var unownedMcpProviderConnectedEventDataSchema = z3.object({
1102
+ type: z3.literal("mcp_provider_connected_unowned"),
1098
1103
  provider: z3.string().min(1)
1099
1104
  }).strict();
1100
1105
  var authorizationKindSchema = z3.union([
@@ -1265,7 +1270,8 @@ var appendableConversationEventDataSchema = z3.union([
1265
1270
  ]);
1266
1271
  var conversationEventDataSchema = z3.union([
1267
1272
  appendableConversationEventDataSchema,
1268
- historyReplacementEventDataSchema
1273
+ historyReplacementEventDataSchema,
1274
+ unownedMcpProviderConnectedEventDataSchema
1269
1275
  ]);
1270
1276
  var KNOWN_CONVERSATION_EVENT_TYPES = [
1271
1277
  "message",
@@ -1274,6 +1280,7 @@ var KNOWN_CONVERSATION_EVENT_TYPES = [
1274
1280
  "assistant_message",
1275
1281
  "tool_result",
1276
1282
  "mcp_provider_connected",
1283
+ "mcp_provider_connected_unowned",
1277
1284
  "authorization_requested",
1278
1285
  "authorization_completed",
1279
1286
  "tool_execution_started",
@@ -4,7 +4,7 @@ import {
4
4
  import {
5
5
  formatProviderLabel,
6
6
  startOAuthFlow
7
- } from "./chunk-SZ74ECCC.js";
7
+ } from "./chunk-M6KRPBXC.js";
8
8
  import {
9
9
  parseSandboxEgressAuthRequiredSignal
10
10
  } from "./chunk-HUO3UTAQ.js";
@@ -12,16 +12,16 @@ import {
12
12
  abandonReplacedPendingAuth,
13
13
  canReusePendingAuthLink,
14
14
  recordAuthorizationRequested
15
- } from "./chunk-2AWDPNP7.js";
15
+ } from "./chunk-JIJOPRD4.js";
16
16
  import {
17
17
  AGENT_INVOCATION_MAILBOX_STATUSES
18
- } from "./chunk-KFHJQYKQ.js";
18
+ } from "./chunk-5N3XLYBW.js";
19
19
  import {
20
20
  TURN_REASONING_LEVELS
21
- } from "./chunk-FGP5W3NS.js";
21
+ } from "./chunk-D22FO4LW.js";
22
22
  import {
23
23
  pluginCatalogRuntime
24
- } from "./chunk-2DIRU2C2.js";
24
+ } from "./chunk-6DLWRSGV.js";
25
25
  import {
26
26
  credentialContextSchema
27
27
  } from "./chunk-RUIXF3YQ.js";
@@ -4,19 +4,19 @@ import {
4
4
  isDmChannel,
5
5
  normalizeSlackConversationId,
6
6
  withSlackRetries
7
- } from "./chunk-D2PVJU5E.js";
7
+ } from "./chunk-AGSUPAD5.js";
8
8
  import {
9
9
  parseDestination
10
- } from "./chunk-GZ25ZSTX.js";
10
+ } from "./chunk-K3QXMZDU.js";
11
11
  import {
12
12
  getStateAdapter
13
- } from "./chunk-B2YA2G26.js";
13
+ } from "./chunk-YN4W5SRJ.js";
14
14
  import {
15
15
  normalizeSlackEmojiName
16
- } from "./chunk-FGP5W3NS.js";
16
+ } from "./chunk-D22FO4LW.js";
17
17
  import {
18
18
  pluginCatalogRuntime
19
- } from "./chunk-2DIRU2C2.js";
19
+ } from "./chunk-6DLWRSGV.js";
20
20
  import {
21
21
  parseSlackMessageTs,
22
22
  parseSlackUserId
@@ -25,7 +25,7 @@ import {
25
25
  isRecord,
26
26
  logInfo,
27
27
  logWarn
28
- } from "./chunk-3WIFZBJL.js";
28
+ } from "./chunk-OAPPJ3TM.js";
29
29
 
30
30
  // src/chat/slack/outbound.ts
31
31
  var MAX_SLACK_MESSAGE_TEXT_CHARS = 4e4;
@@ -9,7 +9,7 @@ import {
9
9
  } from "./chunk-6GWA276C.js";
10
10
  import {
11
11
  getDeploymentTelemetryAttributes
12
- } from "./chunk-6IWDFUXW.js";
12
+ } from "./chunk-DJAOSWB6.js";
13
13
 
14
14
  // src/chat/logging.ts
15
15
  import path from "path";
@@ -1,34 +1,34 @@
1
1
  import {
2
2
  resolveBaseUrl
3
- } from "./chunk-SZ74ECCC.js";
3
+ } from "./chunk-M6KRPBXC.js";
4
4
  import {
5
5
  createPluginLogger,
6
6
  getPlugins
7
- } from "./chunk-QNSV46AW.js";
7
+ } from "./chunk-QVQBWWXQ.js";
8
8
  import {
9
9
  getSlackClient,
10
10
  withSlackRetries
11
- } from "./chunk-D2PVJU5E.js";
11
+ } from "./chunk-AGSUPAD5.js";
12
12
  import {
13
13
  getDb,
14
14
  parseDestination
15
- } from "./chunk-GZ25ZSTX.js";
15
+ } from "./chunk-K3QXMZDU.js";
16
16
  import {
17
17
  sleep
18
18
  } from "./chunk-EM225ITJ.js";
19
19
  import {
20
20
  acquireActiveLock,
21
21
  getStateAdapter
22
- } from "./chunk-B2YA2G26.js";
22
+ } from "./chunk-YN4W5SRJ.js";
23
23
  import {
24
24
  pluginCatalogRuntime
25
- } from "./chunk-2DIRU2C2.js";
25
+ } from "./chunk-6DLWRSGV.js";
26
26
  import {
27
27
  fetchWithBoundedOAuthErrorBodies
28
- } from "./chunk-TZRYLW3R.js";
28
+ } from "./chunk-2MGJ64SL.js";
29
29
  import {
30
30
  isRecord
31
- } from "./chunk-3WIFZBJL.js";
31
+ } from "./chunk-OAPPJ3TM.js";
32
32
 
33
33
  // src/chat/capabilities/router.ts
34
34
  var ProviderCredentialRouter = class {
@@ -1,26 +1,26 @@
1
1
  import {
2
2
  appendAndEnqueueInboundMessage
3
- } from "./chunk-JVOLC6JZ.js";
3
+ } from "./chunk-6A46QL4O.js";
4
4
  import {
5
5
  buildDeliveredTurnStatePatch,
6
6
  finalizeFailedTurnReplyWithEvent,
7
7
  getTurnUserMessage,
8
8
  processPluginTask,
9
9
  scheduleSessionCompletedPluginTasks
10
- } from "./chunk-N6QJAPZS.js";
10
+ } from "./chunk-J5LAA2LI.js";
11
11
  import {
12
12
  ConversationTurnLifecycleService,
13
13
  coerceThreadConversationState,
14
14
  getPersistedSandboxState,
15
15
  getPersistedThreadState,
16
16
  persistThreadStateById
17
- } from "./chunk-JBYWR6FW.js";
17
+ } from "./chunk-EMB4VY7H.js";
18
18
  import {
19
19
  healthReportSchema
20
20
  } from "./chunk-UTL3MHPC.js";
21
21
  import {
22
22
  parseSlackThreadId
23
- } from "./chunk-4JV7GUUH.js";
23
+ } from "./chunk-UDDCHQN2.js";
24
24
  import {
25
25
  TurnInputCommitLostError,
26
26
  buildConversationContext,
@@ -41,22 +41,26 @@ import {
41
41
  saveTurnCheckpoint,
42
42
  startActiveTurn,
43
43
  upsertConversationMessage
44
- } from "./chunk-2AWDPNP7.js";
44
+ } from "./chunk-JIJOPRD4.js";
45
45
  import {
46
46
  normalizeSlackConversationId
47
- } from "./chunk-D2PVJU5E.js";
47
+ } from "./chunk-AGSUPAD5.js";
48
48
  import {
49
49
  getConversationEventStore,
50
50
  getConversationStore
51
- } from "./chunk-GZ25ZSTX.js";
51
+ } from "./chunk-K3QXMZDU.js";
52
+ import {
53
+ getSlackBotToken
54
+ } from "./chunk-D22FO4LW.js";
52
55
  import {
53
56
  credentialContextForActor
54
57
  } from "./chunk-RUIXF3YQ.js";
55
58
  import {
56
59
  logException,
60
+ logWarn,
57
61
  setTags,
58
62
  withLogContext
59
- } from "./chunk-3WIFZBJL.js";
63
+ } from "./chunk-OAPPJ3TM.js";
60
64
 
61
65
  // src/handlers/health.ts
62
66
  function readHealthReport() {
@@ -70,20 +74,105 @@ function GET() {
70
74
  return Response.json(readHealthReport());
71
75
  }
72
76
 
77
+ // src/chat/slack/user.ts
78
+ import { z } from "zod";
79
+ var slackUserInfoSchema = z.object({
80
+ ok: z.literal(true),
81
+ user: z.object({
82
+ name: z.string().nullish(),
83
+ profile: z.object({
84
+ email: z.string().nullish(),
85
+ real_name: z.string().nullish()
86
+ }).optional()
87
+ })
88
+ });
89
+ var USER_CACHE_TTL_MS = 5 * 60 * 1e3;
90
+ var userCache = /* @__PURE__ */ new Map();
91
+ function userCacheKey(teamId, userId) {
92
+ return `${teamId}:${userId}`;
93
+ }
94
+ function readFromCache(teamId, userId) {
95
+ const hit = userCache.get(userCacheKey(teamId, userId));
96
+ if (!hit) return null;
97
+ if (hit.expiresAt < Date.now()) {
98
+ userCache.delete(userCacheKey(teamId, userId));
99
+ return null;
100
+ }
101
+ return hit.value;
102
+ }
103
+ function writeToCache(teamId, userId, value) {
104
+ userCache.set(userCacheKey(teamId, userId), {
105
+ value,
106
+ expiresAt: Date.now() + USER_CACHE_TTL_MS
107
+ });
108
+ }
109
+ async function lookupSlackUser(teamId, userId) {
110
+ if (!teamId || !userId) {
111
+ return null;
112
+ }
113
+ const cached = readFromCache(teamId, userId);
114
+ if (cached) {
115
+ return cached;
116
+ }
117
+ const token = getSlackBotToken();
118
+ if (!token) {
119
+ return null;
120
+ }
121
+ try {
122
+ const response = await fetch(
123
+ `https://slack.com/api/users.info?user=${encodeURIComponent(userId)}`,
124
+ {
125
+ headers: {
126
+ authorization: `Bearer ${token}`
127
+ }
128
+ }
129
+ );
130
+ if (!response.ok) {
131
+ logWarn("slack.user.lookup.failed", {
132
+ "enduser.id": userId,
133
+ "app.slack.team_id": teamId,
134
+ "http.response.status_code": response.status
135
+ });
136
+ return null;
137
+ }
138
+ const parsed = slackUserInfoSchema.safeParse(await response.json());
139
+ if (!parsed.success) {
140
+ return null;
141
+ }
142
+ const payload = parsed.data;
143
+ const userName = payload.user.name?.trim() || void 0;
144
+ const fullName = payload.user.profile?.real_name?.trim() || void 0;
145
+ const result = {
146
+ userName,
147
+ fullName,
148
+ email: payload.user.profile?.email?.trim() || void 0
149
+ };
150
+ writeToCache(teamId, userId, result);
151
+ return result;
152
+ } catch (error) {
153
+ logWarn("slack.user.lookup.failed", {
154
+ "enduser.id": userId,
155
+ "app.slack.team_id": teamId,
156
+ "exception.message": error instanceof Error ? error.message : String(error)
157
+ });
158
+ return null;
159
+ }
160
+ }
161
+
73
162
  // src/chat/api-turns/work.ts
74
163
  import { createHash } from "crypto";
75
- import { z } from "zod";
164
+ import { z as z2 } from "zod";
76
165
  import {
77
166
  createWebSource,
78
167
  localDestinationSchema
79
168
  } from "@sentry/junior-plugin-api";
80
- var apiTurnMailboxMetadataSchema = z.object({
81
- authorEmail: z.string().email(),
82
- authorFullName: z.string().min(1).optional(),
83
- authorUserId: z.string().min(1),
84
- authorUserName: z.string().min(1).optional(),
85
- kind: z.literal("api_turn"),
86
- messageId: z.string().min(1)
169
+ var apiTurnMailboxMetadataSchema = z2.object({
170
+ authorEmail: z2.string().email(),
171
+ authorFullName: z2.string().min(1).optional(),
172
+ authorUserId: z2.string().min(1),
173
+ authorUserName: z2.string().min(1).optional(),
174
+ kind: z2.literal("api_turn"),
175
+ messageId: z2.string().min(1)
87
176
  }).strict();
88
177
  function normalizeEmail(email) {
89
178
  return email.trim().toLowerCase();
@@ -789,6 +878,7 @@ function formatSlackConversationRedactedLabel(context) {
789
878
  export {
790
879
  readHealthReport,
791
880
  GET,
881
+ lookupSlackUser,
792
882
  conversationVisibilityFromSlackChannelType,
793
883
  resolveSlackChannelTypeFromMessage,
794
884
  resolveSlackConversationContext,