@sentry/junior 0.107.1 → 0.109.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 (68) hide show
  1. package/dist/{agent-hooks-ICPIJAFY.js → agent-hooks-FHHVLNPA.js} +12 -12
  2. package/dist/api/conversations/events.d.ts +1 -1
  3. package/dist/api/conversations/list.d.ts +1 -0
  4. package/dist/api/conversations/schema.d.ts +57 -6
  5. package/dist/api/schema.js +1 -1
  6. package/dist/api.js +116 -27
  7. package/dist/app.d.ts +1 -0
  8. package/dist/app.js +1741 -458
  9. package/dist/{catalog-runtime-FOFNPR3P.js → catalog-runtime-DMGJSLV2.js} +6 -4
  10. package/dist/chat/conversations/history.d.ts +16 -5
  11. package/dist/chat/conversations/message-projection.d.ts +3 -5
  12. package/dist/chat/conversations/sql/store.d.ts +0 -7
  13. package/dist/chat/log-context.d.ts +40 -0
  14. package/dist/chat/logging.d.ts +3 -26
  15. package/dist/chat/resource-events/store.d.ts +6 -0
  16. package/dist/chat/runtime/slack-resume.d.ts +2 -2
  17. package/dist/chat/runtime/slack-runtime.d.ts +3 -0
  18. package/dist/chat/services/turn-session-record.d.ts +0 -2
  19. package/dist/chat/slack/reply.d.ts +7 -19
  20. package/dist/chat/state/conversation.d.ts +1 -0
  21. package/dist/chat/task-execution/slack-work.d.ts +237 -10
  22. package/dist/chat/tool-support/turn-deadline-result.d.ts +3 -0
  23. package/dist/chunk-3SXUV423.js +10 -0
  24. package/dist/{chunk-YFQ7CQDE.js → chunk-72OMGPDS.js} +1017 -39
  25. package/dist/{chunk-2XXEKR44.js → chunk-7Q6WCISF.js} +1 -1
  26. package/dist/{chunk-NVOTGWYX.js → chunk-FENLIFJD.js} +97 -601
  27. package/dist/{chunk-IGHMVDWI.js → chunk-FWJRXN4F.js} +3 -3
  28. package/dist/{chunk-PUAMO4PI.js → chunk-HHVY4SMP.js} +41 -7
  29. package/dist/{chunk-SPUAJVVH.js → chunk-HO5NT6OE.js} +5 -7
  30. package/dist/{chunk-O24R4DCK.js → chunk-ISMWX44P.js} +93 -55
  31. package/dist/{chunk-7FBGKXPE.js → chunk-IVVGFRQQ.js} +5 -0
  32. package/dist/{chunk-EDLNHZH3.js → chunk-IXKSQGIO.js} +226 -191
  33. package/dist/{chunk-SS67LUOK.js → chunk-JNAVF45E.js} +6 -7
  34. package/dist/{chunk-DY7TRYB5.js → chunk-MGUMR35T.js} +1 -1
  35. package/dist/{chunk-CQ7KSO2B.js → chunk-MXW4GL53.js} +11 -15
  36. package/dist/{chunk-RT5BUHR5.js → chunk-O3JMSZLI.js} +1 -1
  37. package/dist/chunk-OCD3OZRK.js +125 -0
  38. package/dist/{chunk-B2Z2H66D.js → chunk-OUHNWH46.js} +60 -5
  39. package/dist/{chunk-VIXFG2VC.js → chunk-PLB7MRCQ.js} +1 -2
  40. package/dist/{chunk-RMVOAJRL.js → chunk-QY636HZU.js} +114 -12
  41. package/dist/{chunk-VH6KWKG2.js → chunk-RGX4V75M.js} +3 -3
  42. package/dist/{chunk-B7PUBQQM.js → chunk-SYAQIR5Z.js} +1 -1
  43. package/dist/chunk-TMBRFULF.js +471 -0
  44. package/dist/{chunk-YIPD3L6L.js → chunk-TT6GMXNA.js} +8 -10
  45. package/dist/{chunk-YT72TOEK.js → chunk-WHMOBKT7.js} +2 -2
  46. package/dist/cli/chat.js +23 -23
  47. package/dist/cli/check.js +8 -6
  48. package/dist/cli/plugins.js +16 -16
  49. package/dist/cli/snapshot-warmup.js +10 -9
  50. package/dist/cli/upgrade.js +314 -3505
  51. package/dist/db/db.d.ts +1 -1
  52. package/dist/{db-DIGO4TGW.js → db-V3NU72O2.js} +8 -6
  53. package/dist/instrumentation.js +3 -2
  54. package/dist/nitro.js +5 -4
  55. package/dist/{runner-ACR2HAIC.js → runner-JYBCQBLK.js} +17 -20
  56. package/dist/{skills-ITNHBARB.js → skills-U6MDAST7.js} +7 -5
  57. package/dist/{validation-AGQ46ZGV.js → validation-72N3JVRU.js} +7 -5
  58. package/dist/version.d.ts +2 -0
  59. package/dist/version.js +7 -0
  60. package/migrations/0006_drop_legacy_conversation_messages.sql +1 -0
  61. package/migrations/README.md +12 -9
  62. package/migrations/meta/0006_snapshot.json +948 -0
  63. package/migrations/meta/_journal.json +7 -0
  64. package/package.json +11 -7
  65. package/dist/chunk-4YF7Z6IA.js +0 -1061
  66. package/dist/chunk-AUUOHQAT.js +0 -115
  67. package/dist/chunk-G3E7SCME.js +0 -28
  68. package/dist/chunk-YNP2ATQX.js +0 -1282
@@ -1,5 +1,6 @@
1
1
  import {
2
2
  CooperativeTurnYieldError,
3
+ JUNIOR_THREAD_STATE_TTL_MS,
3
4
  TurnInputCommitLostError,
4
5
  TurnSliceLimitExceededError,
5
6
  abandonReplacedPendingAuth,
@@ -8,23 +9,20 @@ import {
8
9
  getAgentContextCompactionTriggerTokens,
9
10
  getInterruptionMarker,
10
11
  isTurnInputCommitLostError,
12
+ loadConnectedMcpProviders,
13
+ loadConversationProjection,
11
14
  loadTurnSessionRecord,
12
15
  mergeArtifactsState,
16
+ openConversationProjection,
13
17
  persistAuthPauseSessionRecord,
14
18
  persistContinuationSessionRecord,
15
19
  persistRunningSessionRecord,
16
20
  persistYieldSessionRecord,
17
- updateConversationStats
18
- } from "./chunk-YFQ7CQDE.js";
19
- import {
20
- JUNIOR_THREAD_STATE_TTL_MS,
21
- loadConnectedMcpProviders,
22
- loadConversationProjection,
23
- openConversationProjection,
24
21
  recordAuthorizationRequested,
25
22
  recordMcpProviderConnected,
26
- recordToolExecutionStarted
27
- } from "./chunk-4YF7Z6IA.js";
23
+ recordToolExecutionStarted,
24
+ updateConversationStats
25
+ } from "./chunk-72OMGPDS.js";
28
26
  import {
29
27
  buildNonInteractiveShellScript,
30
28
  createSandboxInstance,
@@ -34,7 +32,7 @@ import {
34
32
  isSnapshotMissingError,
35
33
  resolveRuntimeDependencySnapshot,
36
34
  runNonInteractiveCommand
37
- } from "./chunk-SPUAJVVH.js";
35
+ } from "./chunk-HO5NT6OE.js";
38
36
  import {
39
37
  addAgentTurnUsage,
40
38
  hasAgentTurnUsage
@@ -44,27 +42,23 @@ import {
44
42
  } from "./chunk-UIE3R5XU.js";
45
43
  import {
46
44
  createPluginHookRunner,
45
+ createPluginLogger,
47
46
  getPluginSystemPromptContributions,
48
47
  getPluginTools,
49
48
  getPluginUserPromptContributions,
50
49
  getPlugins,
51
50
  getSlackToolContext,
52
51
  resolveChannelCapabilities
53
- } from "./chunk-RMVOAJRL.js";
54
- import {
55
- createPluginLogger
56
- } from "./chunk-AUUOHQAT.js";
52
+ } from "./chunk-QY636HZU.js";
57
53
  import {
58
54
  SANDBOX_DATA_ROOT,
59
55
  SANDBOX_SKILLS_ROOT,
60
56
  SANDBOX_WORKSPACE_ROOT,
57
+ acquireActiveLock,
58
+ getStateAdapter,
61
59
  sandboxSkillDir,
62
60
  sandboxSkillFile
63
- } from "./chunk-G3E7SCME.js";
64
- import {
65
- acquireActiveLock,
66
- getStateAdapter
67
- } from "./chunk-B2Z2H66D.js";
61
+ } from "./chunk-OUHNWH46.js";
68
62
  import {
69
63
  SlackActionError,
70
64
  downloadPrivateSlackFile,
@@ -74,7 +68,7 @@ import {
74
68
  isDmChannel,
75
69
  normalizeSlackConversationId,
76
70
  withSlackRetries
77
- } from "./chunk-VH6KWKG2.js";
71
+ } from "./chunk-RGX4V75M.js";
78
72
  import {
79
73
  contextProvenance,
80
74
  getConversationEventStore,
@@ -83,7 +77,7 @@ import {
83
77
  getDb,
84
78
  instructionActors,
85
79
  instructionProvenanceFor
86
- } from "./chunk-NVOTGWYX.js";
80
+ } from "./chunk-FENLIFJD.js";
87
81
  import {
88
82
  sleep
89
83
  } from "./chunk-4ZNGQH7C.js";
@@ -126,7 +120,7 @@ import {
126
120
  stripRuntimeTurnContext,
127
121
  trimTrailingAssistantMessages,
128
122
  unwrapCurrentInstruction
129
- } from "./chunk-SS67LUOK.js";
123
+ } from "./chunk-JNAVF45E.js";
130
124
  import {
131
125
  parseSlackThreadId,
132
126
  resolveConversationPrivacy,
@@ -136,26 +130,29 @@ import {
136
130
  toGenAiMessagesTraceAttributes,
137
131
  toGenAiPayloadMetadata,
138
132
  toGenAiPayloadTraceAttributes
139
- } from "./chunk-RT5BUHR5.js";
133
+ } from "./chunk-O3JMSZLI.js";
140
134
  import {
141
135
  parseDestination
142
- } from "./chunk-B7PUBQQM.js";
136
+ } from "./chunk-SYAQIR5Z.js";
143
137
  import {
144
138
  discoverSkills,
145
139
  findSkillByName,
146
140
  loadSkillsByName,
147
141
  parseSkillInvocation
148
- } from "./chunk-YT72TOEK.js";
142
+ } from "./chunk-WHMOBKT7.js";
143
+ import {
144
+ pluginCatalogRuntime
145
+ } from "./chunk-3SXUV423.js";
149
146
  import {
150
147
  CredentialUnavailableError,
151
148
  credentialContextSchema,
152
- pluginCatalogRuntime,
149
+ credentialUserSubjectId,
153
150
  resolveAuthTokenPlaceholder,
154
151
  resolvePluginCommandEnv
155
- } from "./chunk-YIPD3L6L.js";
152
+ } from "./chunk-TT6GMXNA.js";
156
153
  import {
157
154
  isUserActor
158
- } from "./chunk-VIXFG2VC.js";
155
+ } from "./chunk-PLB7MRCQ.js";
159
156
  import {
160
157
  extractGenAiUsageAttributes,
161
158
  extractGenAiUsageSummary,
@@ -171,8 +168,9 @@ import {
171
168
  setSpanStatus,
172
169
  setTags,
173
170
  summarizeMessageText,
171
+ withLogContext,
174
172
  withSpan
175
- } from "./chunk-O24R4DCK.js";
173
+ } from "./chunk-ISMWX44P.js";
176
174
  import {
177
175
  isRecord
178
176
  } from "./chunk-OB42YVAE.js";
@@ -180,16 +178,16 @@ import {
180
178
  startInactiveSpan,
181
179
  withActiveSpan
182
180
  } from "./chunk-6GWA276C.js";
183
- import {
184
- parseSlackChannelId,
185
- parseSlackMessageTs,
186
- parseSlackUserId
187
- } from "./chunk-7FBGKXPE.js";
188
181
  import {
189
182
  listReferenceFiles,
190
183
  soulPathCandidates,
191
184
  worldPathCandidates
192
185
  } from "./chunk-3V7OFJZC.js";
186
+ import {
187
+ parseSlackChannelId,
188
+ parseSlackMessageTs,
189
+ parseSlackUserId
190
+ } from "./chunk-IVVGFRQQ.js";
193
191
 
194
192
  // src/chat/configuration/defaults.ts
195
193
  var installDefaults = {};
@@ -839,8 +837,108 @@ function buildTurnResult(input) {
839
837
  };
840
838
  }
841
839
 
842
- // src/chat/services/turn-router.ts
840
+ // src/chat/tool-support/structured-result.ts
843
841
  import { z } from "zod";
842
+ var juniorToolContinuationSchema = z.object({
843
+ arguments: z.record(z.string(), z.unknown()),
844
+ reason: z.string().min(1).optional()
845
+ }).strict();
846
+ var juniorToolBoundContinuationSchema = juniorToolContinuationSchema.extend({
847
+ tool_name: z.string().min(1)
848
+ });
849
+ var juniorToolErrorSchema = z.object({
850
+ kind: z.string().min(1),
851
+ message: z.string().min(1),
852
+ retryable: z.boolean().optional()
853
+ }).strict();
854
+ var juniorToolResultSchema = z.object({
855
+ ok: z.boolean(),
856
+ status: z.enum(["success", "error"]),
857
+ target: z.string().min(1).optional(),
858
+ data: z.unknown().optional(),
859
+ truncated: z.boolean().optional(),
860
+ continuation: juniorToolContinuationSchema.optional(),
861
+ error: z.union([juniorToolErrorSchema, z.string()]).optional()
862
+ }).passthrough();
863
+ var juniorToolResultWithBoundContinuationSchema = juniorToolResultSchema.extend({
864
+ continuation: juniorToolBoundContinuationSchema.optional()
865
+ });
866
+ function sortJsonValue(value) {
867
+ if (Array.isArray(value)) {
868
+ return value.map(sortJsonValue);
869
+ }
870
+ if (!value || typeof value !== "object") {
871
+ return value;
872
+ }
873
+ return Object.fromEntries(
874
+ Object.entries(value).filter(([, item]) => item !== void 0).sort(([left], [right]) => left.localeCompare(right)).map(([key, item]) => [key, sortJsonValue(item)])
875
+ );
876
+ }
877
+ function isRecord2(value) {
878
+ return Boolean(value && typeof value === "object" && !Array.isArray(value));
879
+ }
880
+ function injectContinuationToolName(details, toolName) {
881
+ const parsed = juniorToolResultSchema.parse(details);
882
+ if (!isRecord2(parsed.continuation)) {
883
+ return parsed;
884
+ }
885
+ return juniorToolResultWithBoundContinuationSchema.parse({
886
+ ...parsed,
887
+ continuation: {
888
+ ...parsed.continuation,
889
+ tool_name: toolName
890
+ }
891
+ });
892
+ }
893
+ function makeStructuredToolResult(details, options = {}) {
894
+ const parsed = juniorToolResultSchema.parse(details);
895
+ return {
896
+ content: [
897
+ {
898
+ type: "text",
899
+ text: JSON.stringify(sortJsonValue(parsed))
900
+ },
901
+ ...options.content ?? []
902
+ ],
903
+ details: parsed
904
+ };
905
+ }
906
+
907
+ // src/chat/tool-support/turn-deadline-result.ts
908
+ var TURN_DEADLINE_INTERRUPTION = {
909
+ cause: "turn_deadline",
910
+ scope: "execution_slice",
911
+ task_status: "active"
912
+ };
913
+ function annotateTurnDeadlineToolResult(result) {
914
+ const parsed = juniorToolResultSchema.safeParse(result.details);
915
+ if (!parsed.success) {
916
+ return void 0;
917
+ }
918
+ const error = parsed.data.error;
919
+ if (!error || typeof error !== "object" || error.kind !== "outcome_unknown") {
920
+ return void 0;
921
+ }
922
+ const details = {
923
+ ...parsed.data,
924
+ interruption: TURN_DEADLINE_INTERRUPTION,
925
+ error: {
926
+ ...error,
927
+ message: "Tool execution was interrupted when the current execution slice reached its internal deadline. The original task remains active, but this tool call's outcome is unknown and may include side effects."
928
+ }
929
+ };
930
+ const envelope = makeStructuredToolResult(details, {
931
+ content: result.content.slice(1)
932
+ });
933
+ return {
934
+ content: envelope.content,
935
+ details: envelope.details,
936
+ isError: true
937
+ };
938
+ }
939
+
940
+ // src/chat/services/turn-router.ts
941
+ import { z as z2 } from "zod";
844
942
  var CLASSIFIER_CONFIDENCE_THRESHOLD = 0.75;
845
943
  var MAX_ROUTER_CONTEXT_CHARS = 8e3;
846
944
  var ROUTER_CONTEXT_HEAD_CHARS = 3e3;
@@ -866,17 +964,17 @@ function coerceClassifierConfidence(value) {
866
964
  return CONFIDENCE_LABELS[trimmed] ?? value;
867
965
  }
868
966
  function createTurnRouteSchema(profiles) {
869
- return z.object({
870
- reasoning_level: z.enum(TURN_REASONING_LEVELS),
967
+ return z2.object({
968
+ reasoning_level: z2.enum(TURN_REASONING_LEVELS),
871
969
  profile: modelProfileSchema.refine(
872
970
  (profile) => Object.hasOwn(profiles, profile),
873
971
  "Profile is not configured"
874
972
  ),
875
- confidence: z.preprocess(
973
+ confidence: z2.preprocess(
876
974
  coerceClassifierConfidence,
877
- z.number().min(0).max(1)
975
+ z2.number().min(0).max(1)
878
976
  ),
879
- reason: z.string().min(1)
977
+ reason: z2.string().min(1)
880
978
  });
881
979
  }
882
980
  var CLASSIFIER_FALLBACK_REASONING_LEVEL = "medium";
@@ -973,9 +1071,9 @@ async function selectTurnRoute(args) {
973
1071
  messageText: args.messageText
974
1072
  });
975
1073
  const logContext = {
976
- slackThreadId: args.context?.threadId,
977
- slackChannelId: args.context?.channelId,
978
- slackUserId: args.context?.actorId,
1074
+ messageConversationId: args.context?.threadId,
1075
+ destinationName: args.context?.channelId,
1076
+ userId: args.context?.actorId,
979
1077
  runId: args.context?.runId,
980
1078
  modelId: args.fastModelId
981
1079
  };
@@ -1214,7 +1312,7 @@ function parseMcpProviderFromToolName(toolName) {
1214
1312
 
1215
1313
  // src/chat/pi/derived-state.ts
1216
1314
  var MCP_BRIDGE_TOOLS = /* @__PURE__ */ new Set(["callMcpTool", "searchMcpTools"]);
1217
- function isRecord2(value) {
1315
+ function isRecord3(value) {
1218
1316
  return Boolean(value && typeof value === "object" && !Array.isArray(value));
1219
1317
  }
1220
1318
  function providerFromToolName(value) {
@@ -1236,7 +1334,7 @@ function addBridgeToolProvider(toolName, value, providers) {
1236
1334
  if (bridgeTool === "searchMcpTools") {
1237
1335
  for (const argsKey of ["input", "args", "arguments", "params"]) {
1238
1336
  const args = value[argsKey];
1239
- if (isRecord2(args)) {
1337
+ if (isRecord3(args)) {
1240
1338
  addString(providers, args.provider);
1241
1339
  }
1242
1340
  }
@@ -1245,7 +1343,7 @@ function addBridgeToolProvider(toolName, value, providers) {
1245
1343
  if (bridgeTool === "callMcpTool") {
1246
1344
  for (const argsKey of ["input", "args", "arguments", "params"]) {
1247
1345
  const args = value[argsKey];
1248
- if (isRecord2(args)) {
1346
+ if (isRecord3(args)) {
1249
1347
  addString(providers, providerFromToolName(args.tool_name));
1250
1348
  }
1251
1349
  }
@@ -1258,18 +1356,18 @@ function addMcpResultProvider(message, providers) {
1258
1356
  return;
1259
1357
  }
1260
1358
  if (toolName === "loadSkill") {
1261
- if (isRecord2(message.details)) {
1359
+ if (isRecord3(message.details)) {
1262
1360
  addString(providers, message.details.mcp_provider);
1263
1361
  }
1264
1362
  addString(providers, message.mcp_provider);
1265
1363
  return;
1266
1364
  }
1267
1365
  if (toolName === "searchMcpTools") {
1268
- if (isRecord2(message.details)) {
1366
+ if (isRecord3(message.details)) {
1269
1367
  addString(providers, message.details.provider);
1270
1368
  if (Array.isArray(message.details.tools)) {
1271
1369
  for (const tool of message.details.tools) {
1272
- if (isRecord2(tool)) {
1370
+ if (isRecord3(tool)) {
1273
1371
  addString(providers, providerFromToolName(tool.tool_name));
1274
1372
  }
1275
1373
  }
@@ -1281,11 +1379,11 @@ function addMcpResultProvider(message, providers) {
1281
1379
  if (toolName === "callMcpTool") {
1282
1380
  for (const argsKey of ["input", "args", "arguments", "params"]) {
1283
1381
  const args = message[argsKey];
1284
- if (isRecord2(args)) {
1382
+ if (isRecord3(args)) {
1285
1383
  addString(providers, providerFromToolName(args.tool_name));
1286
1384
  }
1287
1385
  }
1288
- if (isRecord2(message.details)) {
1386
+ if (isRecord3(message.details)) {
1289
1387
  addString(providers, message.details.provider);
1290
1388
  addString(providers, providerFromToolName(message.details.tool_name));
1291
1389
  }
@@ -1293,7 +1391,7 @@ function addMcpResultProvider(message, providers) {
1293
1391
  }
1294
1392
  }
1295
1393
  function scanMcpProviders(message, providers) {
1296
- if (!isRecord2(message)) {
1394
+ if (!isRecord3(message)) {
1297
1395
  return;
1298
1396
  }
1299
1397
  if (message.role === "toolResult") {
@@ -1305,15 +1403,15 @@ function scanMcpProviders(message, providers) {
1305
1403
  return;
1306
1404
  }
1307
1405
  for (const part of content) {
1308
- if (!isRecord2(part)) {
1406
+ if (!isRecord3(part)) {
1309
1407
  continue;
1310
1408
  }
1311
1409
  addBridgeToolProvider(getToolName(part), part, providers);
1312
1410
  }
1313
1411
  }
1314
1412
  function scanLoadedSkills(message, skills) {
1315
- if (isRecord2(message) && message.role === "toolResult" && message.toolName === "loadSkill" && message.isError !== true) {
1316
- if (isRecord2(message.details)) {
1413
+ if (isRecord3(message) && message.role === "toolResult" && message.toolName === "loadSkill" && message.isError !== true) {
1414
+ if (isRecord3(message.details)) {
1317
1415
  addString(skills, message.details.skill_name);
1318
1416
  }
1319
1417
  addString(skills, message.skill_name);
@@ -3817,73 +3915,6 @@ function serializeMcpPayload(payload, privacy, options = {}) {
3817
3915
  // src/chat/tools/sandbox/bash.ts
3818
3916
  import { z as z4 } from "zod";
3819
3917
 
3820
- // src/chat/tool-support/structured-result.ts
3821
- import { z as z2 } from "zod";
3822
- var juniorToolContinuationSchema = z2.object({
3823
- arguments: z2.record(z2.string(), z2.unknown()),
3824
- reason: z2.string().min(1).optional()
3825
- }).strict();
3826
- var juniorToolBoundContinuationSchema = juniorToolContinuationSchema.extend({
3827
- tool_name: z2.string().min(1)
3828
- });
3829
- var juniorToolErrorSchema = z2.object({
3830
- kind: z2.string().min(1),
3831
- message: z2.string().min(1),
3832
- retryable: z2.boolean().optional()
3833
- }).strict();
3834
- var juniorToolResultSchema = z2.object({
3835
- ok: z2.boolean(),
3836
- status: z2.enum(["success", "error"]),
3837
- target: z2.string().min(1).optional(),
3838
- data: z2.unknown().optional(),
3839
- truncated: z2.boolean().optional(),
3840
- continuation: juniorToolContinuationSchema.optional(),
3841
- error: z2.union([juniorToolErrorSchema, z2.string()]).optional()
3842
- }).passthrough();
3843
- var juniorToolResultWithBoundContinuationSchema = juniorToolResultSchema.extend({
3844
- continuation: juniorToolBoundContinuationSchema.optional()
3845
- });
3846
- function sortJsonValue(value) {
3847
- if (Array.isArray(value)) {
3848
- return value.map(sortJsonValue);
3849
- }
3850
- if (!value || typeof value !== "object") {
3851
- return value;
3852
- }
3853
- return Object.fromEntries(
3854
- Object.entries(value).filter(([, item]) => item !== void 0).sort(([left], [right]) => left.localeCompare(right)).map(([key, item]) => [key, sortJsonValue(item)])
3855
- );
3856
- }
3857
- function isRecord3(value) {
3858
- return Boolean(value && typeof value === "object" && !Array.isArray(value));
3859
- }
3860
- function injectContinuationToolName(details, toolName) {
3861
- const parsed = juniorToolResultSchema.parse(details);
3862
- if (!isRecord3(parsed.continuation)) {
3863
- return parsed;
3864
- }
3865
- return juniorToolResultWithBoundContinuationSchema.parse({
3866
- ...parsed,
3867
- continuation: {
3868
- ...parsed.continuation,
3869
- tool_name: toolName
3870
- }
3871
- });
3872
- }
3873
- function makeStructuredToolResult(details, options = {}) {
3874
- const parsed = juniorToolResultSchema.parse(details);
3875
- return {
3876
- content: [
3877
- {
3878
- type: "text",
3879
- text: JSON.stringify(sortJsonValue(parsed))
3880
- },
3881
- ...options.content ?? []
3882
- ],
3883
- details: parsed
3884
- };
3885
- }
3886
-
3887
3918
  // src/chat/tool-support/zod-tool.ts
3888
3919
  import { z as z3 } from "zod";
3889
3920
 
@@ -5990,6 +6021,17 @@ async function cancelResourceEventSubscription(input) {
5990
6021
  return next;
5991
6022
  });
5992
6023
  }
6024
+ async function cancelSubscriptions(input) {
6025
+ const subscriptions = await listResourceEventSubscriptions(input);
6026
+ for (const subscription of subscriptions) {
6027
+ await cancelResourceEventSubscription({
6028
+ conversationId: input.conversationId,
6029
+ id: subscription.id,
6030
+ nowMs: input.nowMs,
6031
+ state: input.state
6032
+ });
6033
+ }
6034
+ }
5993
6035
  async function findMatchingResourceEventSubscriptions(input) {
5994
6036
  const state = input.state ?? getStateAdapter();
5995
6037
  await state.connect();
@@ -11216,12 +11258,11 @@ function buildSandboxEgressNetworkPolicy(input) {
11216
11258
  domain,
11217
11259
  input?.traceConfig
11218
11260
  );
11219
- allow[domain] = [
11220
- {
11221
- ...shouldPropagateTrace && hasTraceHeaders ? { transform: [{ headers: traceHeaders }] } : {},
11222
- ...policy.forward && forwardURL ? { forwardURL } : {}
11223
- }
11224
- ];
11261
+ if (policy.forward && forwardURL) {
11262
+ allow[domain] = [{ forwardURL }];
11263
+ } else if (shouldPropagateTrace && hasTraceHeaders) {
11264
+ allow[domain] = [{ transform: [{ headers: traceHeaders }] }];
11265
+ }
11225
11266
  }
11226
11267
  return { allow };
11227
11268
  }
@@ -14590,7 +14631,7 @@ async function writeSandboxGeneratedArtifacts(sandbox, files) {
14590
14631
  // src/chat/agent/tools.ts
14591
14632
  async function wireAgentTools(args) {
14592
14633
  const runSource = args.routing.source;
14593
- const authActorId = args.routing.credentialContext && "type" in args.routing.credentialContext.actor ? args.routing.credentialContext.actor.userId : void 0;
14634
+ const credentialUserId = args.routing.credentialContext ? credentialUserSubjectId(args.routing.credentialContext) : void 0;
14594
14635
  const userTokenStore = createUserTokenStore();
14595
14636
  const pluginHooks = createPluginHookRunner({
14596
14637
  actor: args.currentActor,
@@ -14638,7 +14679,7 @@ async function wireAgentTools(args) {
14638
14679
  abortAgent: args.abortAgent,
14639
14680
  conversationId: args.conversationId,
14640
14681
  sessionId: args.turnId,
14641
- actorId: authActorId,
14682
+ actorId: credentialUserId,
14642
14683
  channelId: slackChannelId,
14643
14684
  destination: args.routing.destination,
14644
14685
  source: runSource,
@@ -14659,7 +14700,7 @@ async function wireAgentTools(args) {
14659
14700
  abortAgent: args.abortAgent,
14660
14701
  conversationId: args.conversationId,
14661
14702
  sessionId: args.turnId,
14662
- actorId: authActorId,
14703
+ actorId: credentialUserId,
14663
14704
  channelId: slackChannelId,
14664
14705
  destination: args.routing.destination,
14665
14706
  source: runSource,
@@ -14793,32 +14834,25 @@ async function wireAgentTools(args) {
14793
14834
  })
14794
14835
  );
14795
14836
  const pendingMcpProvider = args.state.pendingAuth?.kind === "mcp" ? args.state.pendingAuth.provider : void 0;
14796
- const providersToRestore = /* @__PURE__ */ new Set([
14797
- ...args.connectedMcpProviders,
14798
- ...inferActiveMcpProvidersFromPiMessages(args.priorPiMessages)
14799
- ]);
14800
- for (const provider of providersToRestore) {
14801
- if (provider === pendingMcpProvider) {
14802
- continue;
14803
- }
14804
- if (await mcpToolManager.activateProvider(provider)) {
14805
- await args.recordConnectedMcpProvider(provider);
14806
- }
14807
- if (mcpAuth.getPendingPause()) {
14808
- args.resume.captureResumeSnapshot(args.preAgentPromptMessages());
14809
- throw mcpAuth.getPendingPause();
14810
- }
14811
- }
14812
- for (const skill of args.activeSkills) {
14813
- if (skill.pluginProvider === pendingMcpProvider) {
14814
- continue;
14815
- }
14816
- if (await mcpToolManager.activateForSkill(skill)) {
14817
- await args.recordConnectedMcpProvider(skill.pluginProvider);
14818
- }
14819
- if (mcpAuth.getPendingPause()) {
14820
- args.resume.captureResumeSnapshot(args.preAgentPromptMessages());
14821
- throw mcpAuth.getPendingPause();
14837
+ if (credentialUserId) {
14838
+ const providersToRestore = /* @__PURE__ */ new Set([
14839
+ ...args.connectedMcpProviders,
14840
+ ...inferActiveMcpProvidersFromPiMessages(args.priorPiMessages),
14841
+ ...args.activeSkills.flatMap(
14842
+ (skill) => skill.pluginProvider ? [skill.pluginProvider] : []
14843
+ )
14844
+ ]);
14845
+ for (const provider of providersToRestore) {
14846
+ if (provider === pendingMcpProvider) {
14847
+ continue;
14848
+ }
14849
+ if (await mcpToolManager.activateProvider(provider)) {
14850
+ await args.recordConnectedMcpProvider(provider);
14851
+ }
14852
+ if (mcpAuth.getPendingPause()) {
14853
+ args.resume.captureResumeSnapshot(args.preAgentPromptMessages());
14854
+ throw mcpAuth.getPendingPause();
14855
+ }
14822
14856
  }
14823
14857
  }
14824
14858
  const activeMcpCatalogs = toActiveMcpCatalogSummaries(
@@ -15283,9 +15317,9 @@ async function maybeCompactWithDeps(args, deps) {
15283
15317
  logWarn(
15284
15318
  "context_compaction_summary_failed",
15285
15319
  {
15286
- slackThreadId: args.metadata?.threadId,
15287
- slackUserId: args.metadata?.actorId,
15288
- slackChannelId: args.metadata?.channelId,
15320
+ messageConversationId: args.metadata?.threadId,
15321
+ userId: args.metadata?.actorId,
15322
+ destinationName: args.metadata?.channelId,
15289
15323
  runId: args.metadata?.runId,
15290
15324
  assistantUserName: botConfig.userName,
15291
15325
  modelId: botConfig.fastModelId
@@ -15435,12 +15469,35 @@ async function executeAgentRun(request) {
15435
15469
  // a compatibility fallback for callers that have not projected it yet.
15436
15470
  visibility: request.routing.destinationVisibility ?? request.routing.slackConversation?.visibility
15437
15471
  });
15438
- return runWithConversationPrivacy(
15439
- conversationPrivacy ?? "private",
15440
- () => executeAgentRunInPrivacyContext(request, conversationPrivacy)
15472
+ const credentialActor = request.routing.credentialContext?.actor;
15473
+ const actor = actorFromRouting(request.routing);
15474
+ const userActor = actor && "userId" in actor ? actor : void 0;
15475
+ const runLogContext = {
15476
+ conversationId: request.conversationId,
15477
+ platform: request.routing.source.platform,
15478
+ messageConversationId: request.routing.source.platform === "slack" ? request.conversationId : request.routing.source.conversationId,
15479
+ destinationName: request.routing.destination.platform === "slack" ? request.routing.destination.channelId : request.routing.destination.conversationId,
15480
+ userId: userActor?.userId,
15481
+ userName: userActor?.userName,
15482
+ userEmail: userActor?.email,
15483
+ runId: request.runId,
15484
+ actorType: credentialActor ? "type" in credentialActor ? credentialActor.type : "system" : void 0,
15485
+ actorId: credentialActor ? "type" in credentialActor ? credentialActor.userId : credentialActor.name : void 0,
15486
+ assistantUserName: botConfig.userName
15487
+ };
15488
+ return withLogContext(
15489
+ runLogContext,
15490
+ () => runWithConversationPrivacy(
15491
+ conversationPrivacy ?? "private",
15492
+ () => executeAgentRunInPrivacyContext(
15493
+ request,
15494
+ conversationPrivacy,
15495
+ runLogContext
15496
+ )
15497
+ )
15441
15498
  );
15442
15499
  }
15443
- async function executeAgentRunInPrivacyContext(request, conversationPrivacy) {
15500
+ async function executeAgentRunInPrivacyContext(request, conversationPrivacy, runLogContext) {
15444
15501
  const { conversationId, input, routing, runId, turnId } = request;
15445
15502
  const policy = request.policy ?? {};
15446
15503
  const signal = policy.signal;
@@ -15517,16 +15574,7 @@ async function executeAgentRunInPrivacyContext(request, conversationPrivacy) {
15517
15574
  activeModelProfile = projection.modelProfile;
15518
15575
  activeModelId = modelIdForProfile(botConfig, activeModelProfile);
15519
15576
  const shouldTrace = shouldEmitDevAgentTrace();
15520
- const spanContext = {
15521
- conversationId,
15522
- slackThreadId: slackSource ? conversationId : void 0,
15523
- slackUserId: slackActor?.userId,
15524
- slackChannelId: slackDestination?.channelId,
15525
- runId,
15526
- ...credentialActorLogContext,
15527
- assistantUserName: botConfig.userName,
15528
- modelId: activeModelId
15529
- };
15577
+ const spanContext = { modelId: activeModelId };
15530
15578
  const availableSkills = await discoverRunSkills({
15531
15579
  skillDirs: policy.skillDirs,
15532
15580
  spanContext
@@ -15746,13 +15794,7 @@ async function executeAgentRunInPrivacyContext(request, conversationPrivacy) {
15746
15794
  })
15747
15795
  };
15748
15796
  setTags({
15749
- conversationId: spanContext.conversationId,
15750
- slackThreadId: slackSource ? conversationId : void 0,
15751
- slackUserId: slackActor?.userId,
15752
- slackChannelId: slackDestination?.channelId,
15753
- runId,
15754
- ...credentialActorLogContext,
15755
- assistantUserName: botConfig.userName,
15797
+ ...runLogContext,
15756
15798
  modelId: activeModelId
15757
15799
  });
15758
15800
  const wiring = await wireAgentTools({
@@ -15930,6 +15972,7 @@ async function executeAgentRunInPrivacyContext(request, conversationPrivacy) {
15930
15972
  }
15931
15973
  return void 0;
15932
15974
  },
15975
+ afterToolCall: async ({ result: result2 }, signal2) => runResume.timedOut && signal2?.aborted ? annotateTurnDeadlineToolResult(result2) : void 0,
15933
15976
  prepareNextTurn: async () => {
15934
15977
  const update = applyPendingHandoff();
15935
15978
  await drainSteeringMessages();
@@ -16259,16 +16302,7 @@ async function executeAgentRunInPrivacyContext(request, conversationPrivacy) {
16259
16302
  logException(
16260
16303
  error,
16261
16304
  "assistant_reply_generation_failed",
16262
- {
16263
- conversationId,
16264
- slackThreadId: slackSource ? conversationId : void 0,
16265
- slackUserId: slackActor?.userId,
16266
- slackChannelId: slackDestination?.channelId,
16267
- runId,
16268
- ...credentialActorLogContext,
16269
- assistantUserName: botConfig.userName,
16270
- modelId: activeModelId
16271
- },
16305
+ { modelId: activeModelId },
16272
16306
  {},
16273
16307
  "executeAgentRun failed"
16274
16308
  );
@@ -16342,6 +16376,7 @@ export {
16342
16376
  buildSlackOutputMessage,
16343
16377
  buildSteeringPiMessage,
16344
16378
  createUserTokenStore,
16379
+ cancelSubscriptions,
16345
16380
  findMatchingResourceEventSubscriptions,
16346
16381
  deliverResourceEventSubscription,
16347
16382
  listThreadReplies,