@sentry/junior 0.149.0 → 0.150.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-CWMCXAMT.js → agent-hooks-SEOGOGKX.js} +10 -10
  2. package/dist/api.d.ts +1 -1
  3. package/dist/api.js +25 -23
  4. package/dist/app.js +92 -85
  5. package/dist/{catalog-runtime-GAW5APVI.js → catalog-runtime-HA7RIWYT.js} +5 -5
  6. package/dist/chat/agent/index.d.ts +5 -4
  7. package/dist/chat/agent/prompt.d.ts +8 -5
  8. package/dist/chat/agent/resume.d.ts +2 -2
  9. package/dist/chat/agent/tools.d.ts +4 -7
  10. package/dist/chat/agent/{request.d.ts → types.d.ts} +138 -129
  11. package/dist/chat/agent-dispatch/types.d.ts +2 -2
  12. package/dist/chat/agent-invocations/spawn.d.ts +2 -2
  13. package/dist/chat/plugins/viewer.d.ts +4 -0
  14. package/dist/chat/runtime/agent-runner.d.ts +7 -5
  15. package/dist/chat/runtime/slack-resume.d.ts +3 -3
  16. package/dist/chat/task-execution/paused-turn.d.ts +2 -2
  17. package/dist/chat/tools/types.d.ts +1 -1
  18. package/dist/{chunk-QIW7OQEO.js → chunk-3GL327SC.js} +1 -1
  19. package/dist/{chunk-32CXPIZE.js → chunk-3ZMKDHCT.js} +2 -2
  20. package/dist/{chunk-EXW76GW4.js → chunk-4KAYAIBV.js} +1 -1
  21. package/dist/{chunk-75DSYFFB.js → chunk-4VH7KLGC.js} +100 -107
  22. package/dist/{chunk-SWHPVZBV.js → chunk-64K7GKRW.js} +2 -2
  23. package/dist/{chunk-25SC7D6Z.js → chunk-6PFDWAK2.js} +1 -1
  24. package/dist/{chunk-ART7P442.js → chunk-7D4GNUV2.js} +3 -3
  25. package/dist/{chunk-5CWUQXXT.js → chunk-7GOP6VFJ.js} +20 -24
  26. package/dist/{chunk-X22XXSZA.js → chunk-7NLW2NF5.js} +1 -1
  27. package/dist/{chunk-ZYMYLLWG.js → chunk-7QB2CKCW.js} +1 -1
  28. package/dist/{chunk-JMH3DBM5.js → chunk-DWETNV66.js} +6 -6
  29. package/dist/{chunk-3I2IVWSZ.js → chunk-F5NMSEBL.js} +1 -1
  30. package/dist/{chunk-4YKPOYRV.js → chunk-FEFEIA3Z.js} +5 -5
  31. package/dist/{chunk-MEMURSBG.js → chunk-H2RLIJ7G.js} +1 -1
  32. package/dist/{chunk-3GYZ5YEH.js → chunk-ILYL6YFD.js} +3 -3
  33. package/dist/{chunk-EW2LNCRL.js → chunk-IPGNWXA3.js} +4 -4
  34. package/dist/{chunk-6G5RCDKP.js → chunk-IZRSLANA.js} +1 -1
  35. package/dist/{chunk-RLVZIWNQ.js → chunk-JQXJ2E53.js} +1 -1
  36. package/dist/{chunk-JMSMXXED.js → chunk-M5OZSVJI.js} +4 -4
  37. package/dist/{chunk-RB26T3LU.js → chunk-MCNP7A7T.js} +8 -8
  38. package/dist/{chunk-W7UONUIZ.js → chunk-NCGVQXX5.js} +22 -26
  39. package/dist/{chunk-4JGM7FXO.js → chunk-NNOCRVQO.js} +2 -2
  40. package/dist/{chunk-URDCZAL4.js → chunk-P43QM7JY.js} +5 -5
  41. package/dist/{chunk-XPYWWMHR.js → chunk-QPIPYVGE.js} +5 -5
  42. package/dist/{chunk-GDFF3BQG.js → chunk-RF6J3DIO.js} +34 -36
  43. package/dist/{chunk-TFBNBXPU.js → chunk-SH6ZKJFZ.js} +4 -4
  44. package/dist/{chunk-3KGQOKIG.js → chunk-SHDREBGC.js} +1 -1
  45. package/dist/{chunk-DK5UT6PQ.js → chunk-TZLYAO2J.js} +185 -126
  46. package/dist/{chunk-UZGASGOD.js → chunk-UIMBNY6O.js} +9 -9
  47. package/dist/{chunk-7BH46NB4.js → chunk-UOFQEVR5.js} +15 -6
  48. package/dist/{chunk-ALJG73MQ.js → chunk-Y2VZ54CQ.js} +12 -12
  49. package/dist/{chunk-2P6BQQER.js → chunk-ZBOGYZ53.js} +4 -4
  50. package/dist/{chunk-2JHKISQA.js → chunk-ZUQT35YC.js} +1 -1
  51. package/dist/cli/chat.js +31 -31
  52. package/dist/cli/check.js +6 -6
  53. package/dist/cli/plugins.js +13 -13
  54. package/dist/cli/snapshot-create.js +9 -9
  55. package/dist/cli/upgrade.js +7 -7
  56. package/dist/{db-JBZLRIVY.js → db-HUW75QG7.js} +7 -7
  57. package/dist/instrumentation.js +4 -4
  58. package/dist/nitro.js +2 -2
  59. package/dist/{oauth-callback-server-MNTVYY2I.js → oauth-callback-server-DP7NIZPQ.js} +24 -24
  60. package/dist/{runner-K24BWZSZ.js → runner-AINV7K3M.js} +40 -37
  61. package/dist/{skills-AU5ST2CG.js → skills-PKS37E6B.js} +6 -6
  62. package/dist/spawn-NJCDEPPL.js +38 -0
  63. package/dist/{validation-IXGZCFRO.js → validation-PDC3MVMM.js} +6 -6
  64. package/dist/version.js +1 -1
  65. package/dist/{work-WCZIYILX.js → work-KJLJRPXS.js} +17 -17
  66. package/dist/{worker-U2AACBEY.js → worker-TYQ7YVIR.js} +11 -11
  67. package/package.json +4 -4
  68. package/dist/spawn-6PO7CVJ6.js +0 -38
@@ -7,7 +7,7 @@ import {
7
7
  PluginCredentialFailureError,
8
8
  agentNameSchema,
9
9
  createPluginAuthOrchestration
10
- } from "./chunk-XPYWWMHR.js";
10
+ } from "./chunk-QPIPYVGE.js";
11
11
  import {
12
12
  authorizationId
13
13
  } from "./chunk-DIB4GX3G.js";
@@ -32,15 +32,15 @@ import {
32
32
  searchSlackUsers,
33
33
  selectPluginGrant,
34
34
  toMcpProviderError
35
- } from "./chunk-RB26T3LU.js";
35
+ } from "./chunk-MCNP7A7T.js";
36
36
  import {
37
37
  RetryableDeliveryError,
38
- actorFromRouting,
39
- assertRunRoutingConsistency,
38
+ actorFromRun,
39
+ assertRunConsistency,
40
40
  isAgentRunFeatureDisabled,
41
- surfaceFromRouting,
41
+ surfaceFromRun,
42
42
  toolInvocationDestination
43
- } from "./chunk-GDFF3BQG.js";
43
+ } from "./chunk-RF6J3DIO.js";
44
44
  import {
45
45
  addReactionToMessage,
46
46
  deliverOAuthAuthorization,
@@ -48,7 +48,7 @@ import {
48
48
  getSlackMessagePermalink,
49
49
  resolveBaseUrl,
50
50
  uploadFilesToConversation
51
- } from "./chunk-JMH3DBM5.js";
51
+ } from "./chunk-DWETNV66.js";
52
52
  import {
53
53
  parseSandboxEgressAuthRequiredSignal,
54
54
  parseSandboxEgressPermissionDeniedSignal,
@@ -77,7 +77,7 @@ import {
77
77
  runNonInteractiveCommand,
78
78
  throwSandboxOperationError,
79
79
  wrapSandboxSetupError
80
- } from "./chunk-2P6BQQER.js";
80
+ } from "./chunk-ZBOGYZ53.js";
81
81
  import {
82
82
  SCHEDULED_TASK_SYSTEM_ACTOR,
83
83
  compactEventTask,
@@ -109,10 +109,10 @@ import {
109
109
  saveEventTask,
110
110
  scheduledTaskAttributes,
111
111
  writableEventTask
112
- } from "./chunk-URDCZAL4.js";
112
+ } from "./chunk-P43QM7JY.js";
113
113
  import {
114
114
  parseSlackThreadId
115
- } from "./chunk-MEMURSBG.js";
115
+ } from "./chunk-H2RLIJ7G.js";
116
116
  import {
117
117
  AGENTS_REMOVAL_NOTICE,
118
118
  AGENTS_REPLACEMENT_NOTICE,
@@ -182,7 +182,7 @@ import {
182
182
  stripRuntimeTurnContext,
183
183
  trimTrailingAssistantMessages,
184
184
  truncateText
185
- } from "./chunk-EW2LNCRL.js";
185
+ } from "./chunk-IPGNWXA3.js";
186
186
  import {
187
187
  JUNIOR_THREAD_STATE_TTL_MS
188
188
  } from "./chunk-3Y47VMHV.js";
@@ -198,7 +198,7 @@ import {
198
198
  getSlackToolContext,
199
199
  readActorIdentity,
200
200
  resolveChannelCapabilities
201
- } from "./chunk-7BH46NB4.js";
201
+ } from "./chunk-UOFQEVR5.js";
202
202
  import {
203
203
  SlackActionError,
204
204
  downloadPrivateSlackFile,
@@ -207,7 +207,7 @@ import {
207
207
  isConversationScopedChannel,
208
208
  normalizeSlackConversationId,
209
209
  withSlackRetries
210
- } from "./chunk-SWHPVZBV.js";
210
+ } from "./chunk-64K7GKRW.js";
211
211
  import {
212
212
  KNOWN_CONVERSATION_EVENT_TYPES,
213
213
  contextProvenance,
@@ -219,10 +219,10 @@ import {
219
219
  instructionActors,
220
220
  instructionProvenanceFor,
221
221
  sameActorIdentity
222
- } from "./chunk-3GYZ5YEH.js";
222
+ } from "./chunk-ILYL6YFD.js";
223
223
  import {
224
224
  juniorIdentities
225
- } from "./chunk-3I2IVWSZ.js";
225
+ } from "./chunk-F5NMSEBL.js";
226
226
  import {
227
227
  SANDBOX_DATA_ROOT,
228
228
  SANDBOX_SKILLS_ROOT,
@@ -234,7 +234,7 @@ import {
234
234
  } from "./chunk-EM225ITJ.js";
235
235
  import {
236
236
  getStateAdapter
237
- } from "./chunk-25SC7D6Z.js";
237
+ } from "./chunk-6PFDWAK2.js";
238
238
  import {
239
239
  ACTIVE_TURN_COMPACTION_SUMMARY_PREFIX,
240
240
  COMPACTION_SUMMARY_PREFIX,
@@ -267,7 +267,7 @@ import {
267
267
  resolveGatewayCredential,
268
268
  resolveGatewayModel,
269
269
  unwrapCurrentInstruction
270
- } from "./chunk-32CXPIZE.js";
270
+ } from "./chunk-3ZMKDHCT.js";
271
271
  import {
272
272
  canExposeConversationPayload,
273
273
  resolveConversationPrivacy,
@@ -277,16 +277,16 @@ import {
277
277
  toGenAiMessagesTraceAttributes,
278
278
  toGenAiPayloadMetadata,
279
279
  toGenAiPayloadTraceAttributes
280
- } from "./chunk-3KGQOKIG.js";
280
+ } from "./chunk-SHDREBGC.js";
281
281
  import {
282
282
  discoverSkills,
283
283
  findSkillByName,
284
284
  loadSkillsByName,
285
285
  parseSkillInvocation
286
- } from "./chunk-4JGM7FXO.js";
286
+ } from "./chunk-NNOCRVQO.js";
287
287
  import {
288
288
  pluginCatalogRuntime
289
- } from "./chunk-X22XXSZA.js";
289
+ } from "./chunk-7NLW2NF5.js";
290
290
  import {
291
291
  CredentialUnavailableError,
292
292
  OAuthProviderError,
@@ -294,7 +294,7 @@ import {
294
294
  getOAuthProviderErrorAttributes,
295
295
  resolveAuthTokenPlaceholder,
296
296
  resolvePluginCommandEnv
297
- } from "./chunk-2JHKISQA.js";
297
+ } from "./chunk-ZUQT35YC.js";
298
298
  import {
299
299
  credentialUserSubjectId
300
300
  } from "./chunk-RUIXF3YQ.js";
@@ -324,7 +324,7 @@ import {
324
324
  summarizeMessageText,
325
325
  withLogContext,
326
326
  withSpan
327
- } from "./chunk-RLVZIWNQ.js";
327
+ } from "./chunk-JQXJ2E53.js";
328
328
  import {
329
329
  startInactiveSpan,
330
330
  withActiveSpan
@@ -2243,12 +2243,13 @@ function buildUserTurnInput(args) {
2243
2243
  }
2244
2244
  return { contextContentParts: [], routerBlocks, userContentParts };
2245
2245
  }
2246
- function buildPromptInput(input) {
2247
- const promptConversationContext = input.piMessages && input.piMessages.length > 0 && !input.includeConversationContextWithPiMessages ? void 0 : input.conversationContext;
2246
+ function buildPromptInput(args) {
2247
+ const { instruction, history } = args;
2248
+ const promptConversationContext = history && history.length > 0 && !instruction.includeConversationContextWithHistory ? void 0 : instruction.context;
2248
2249
  const promptInput = buildUserTurnInput({
2249
- omittedImageAttachmentCount: input.omittedImageAttachmentCount ?? 0,
2250
- userAttachments: input.userAttachments,
2251
- userTurnText: buildUserTurnText(input.messageText, input.actor)
2250
+ omittedImageAttachmentCount: instruction.omittedImageAttachmentCount ?? 0,
2251
+ userAttachments: instruction.attachments ? [...instruction.attachments] : void 0,
2252
+ userTurnText: buildUserTurnText(instruction.text, instruction.actor)
2252
2253
  });
2253
2254
  const trimmedContext = promptConversationContext?.trim();
2254
2255
  return {
@@ -2259,7 +2260,7 @@ function buildPromptInput(input) {
2259
2260
  function buildSteeringPiMessage(message) {
2260
2261
  const { userContentParts } = buildUserTurnInput({
2261
2262
  userTurnText: buildUserTurnText(message.text, message.actor),
2262
- userAttachments: message.userAttachments,
2263
+ userAttachments: message.attachments ? [...message.attachments] : void 0,
2263
2264
  omittedImageAttachmentCount: message.omittedImageAttachmentCount ?? 0
2264
2265
  });
2265
2266
  return {
@@ -2333,7 +2334,7 @@ function checkpointedPrompt(args) {
2333
2334
  };
2334
2335
  }
2335
2336
  async function assemblePrompt(args) {
2336
- const source = args.routing.source;
2337
+ const source = args.run.source;
2337
2338
  const hasPromptCheckpoint = args.resumedFromSessionRecord && args.existingTurnStartMessageIndex !== void 0;
2338
2339
  const shouldPromptAgent = !args.resumedFromSessionRecord || !hasPromptCheckpoint;
2339
2340
  const requestContentParts = args.userContentParts;
@@ -2365,11 +2366,11 @@ async function assemblePrompt(args) {
2365
2366
  toolGuidance: args.toolGuidance,
2366
2367
  runtime: {
2367
2368
  conversationId: args.spanContext.conversationId,
2368
- slackConversation: args.routing.slackConversation
2369
+ slackConversation: args.run.slackConversation
2369
2370
  },
2370
- dispatch: args.routing.dispatch ? {
2371
- ...args.routing.dispatch,
2372
- destination: args.routing.destination,
2371
+ dispatch: args.run.dispatch ? {
2372
+ ...args.run.dispatch,
2373
+ destination: args.run.destination,
2373
2374
  source
2374
2375
  } : void 0,
2375
2376
  actor: isUserActor(args.currentActor) ? args.currentActor : void 0,
@@ -15918,8 +15919,8 @@ async function tryRecordSkillLoadStat(skill) {
15918
15919
  }
15919
15920
  }
15920
15921
  function resolveToolRuntimeRoute(args) {
15921
- const destination = toolInvocationDestination(args.routing);
15922
- switch (args.routing.source.platform) {
15922
+ const destination = toolInvocationDestination(args.run);
15923
+ switch (args.run.source.platform) {
15923
15924
  case "slack": {
15924
15925
  if (destination.platform !== "slack") {
15925
15926
  throw new TypeError("Slack tool runtime requires a Slack destination");
@@ -15927,8 +15928,8 @@ function resolveToolRuntimeRoute(args) {
15927
15928
  return {
15928
15929
  destination,
15929
15930
  actor: args.actor?.platform === "slack" ? args.actor : void 0,
15930
- source: args.routing.source,
15931
- slackActionToken: args.routing.slackActionToken
15931
+ source: args.run.source,
15932
+ slackActionToken: args.run.slackActionToken
15932
15933
  };
15933
15934
  }
15934
15935
  case "local": {
@@ -15938,20 +15939,20 @@ function resolveToolRuntimeRoute(args) {
15938
15939
  return {
15939
15940
  destination,
15940
15941
  actor: args.actor?.platform === "local" ? args.actor : void 0,
15941
- source: args.routing.source
15942
+ source: args.run.source
15942
15943
  };
15943
15944
  }
15944
15945
  case "web":
15945
15946
  return {
15946
15947
  destination,
15947
15948
  actor: args.actor?.platform === "web" ? args.actor : void 0,
15948
- source: args.routing.source
15949
+ source: args.run.source
15949
15950
  };
15950
15951
  }
15951
15952
  }
15952
15953
  async function wireAgentTools(args) {
15953
- const runSource = args.routing.source;
15954
- const credentialUserId = args.routing.credentialContext ? credentialUserSubjectId(args.routing.credentialContext) : void 0;
15954
+ const runSource = args.run.source;
15955
+ const credentialUserId = args.run.credentialContext ? credentialUserSubjectId(args.run.credentialContext) : void 0;
15955
15956
  const userTokenStore = createUserTokenStore();
15956
15957
  const pluginHooks = createPluginHookRunner({
15957
15958
  actor: args.currentActor,
@@ -15961,54 +15962,54 @@ async function wireAgentTools(args) {
15961
15962
  sandboxRef: args.state.sandboxRef,
15962
15963
  skills: args.availableSkills,
15963
15964
  traceContext: args.spanContext,
15964
- tracePropagation: args.policy.sandboxTracePropagation,
15965
- egressSignals: args.policy.sandboxEgressSignals,
15966
- credentialEgress: args.routing.credentialContext,
15965
+ tracePropagation: args.run.environment?.sandboxTracePropagation,
15966
+ egressSignals: args.run.environment?.sandboxEgressSignals,
15967
+ credentialEgress: args.run.credentialContext,
15967
15968
  actor: args.currentActor,
15968
- locationConfiguration: args.policy.locationConfiguration,
15969
+ locationConfiguration: args.run.environment?.locationConfiguration,
15969
15970
  configurationValues: args.configurationValues,
15970
15971
  getActiveSkill: () => args.skillSandbox.getActiveSkill(),
15971
15972
  prepareSandbox: pluginHooks.prepareSandbox,
15972
15973
  onSandboxRefChanged: args.onSandboxRefChanged,
15973
15974
  persistSandboxRef: args.durability.onSandboxRefChanged
15974
15975
  });
15975
- const slackDestination = args.routing.destination.platform === "slack" ? args.routing.destination : void 0;
15976
+ const slackDestination = args.run.destination.platform === "slack" ? args.run.destination : void 0;
15976
15977
  const slackChannelId = slackDestination?.channelId;
15977
15978
  const mcpAuth = createMcpAuthOrchestration({
15978
15979
  abortAgent: args.abortAgent,
15979
- conversationId: args.conversationId,
15980
- sessionId: args.turnId,
15980
+ conversationId: args.run.conversationId,
15981
+ sessionId: args.run.turnId,
15981
15982
  actorId: credentialUserId,
15982
15983
  channelId: slackChannelId,
15983
- destination: args.routing.destination,
15984
+ destination: args.run.destination,
15984
15985
  source: runSource,
15985
- threadTs: args.routing.source.platform === "slack" ? args.routing.source.threadTs : void 0,
15986
- toolChannelId: args.routing.toolChannelId,
15986
+ threadTs: args.run.source.platform === "slack" ? args.run.source.threadTs : void 0,
15987
+ toolChannelId: args.run.toolChannelId,
15987
15988
  userMessage: args.userInput,
15988
15989
  pendingAuth: args.state.pendingAuth,
15989
15990
  getConfiguration: () => args.configurationValues,
15990
15991
  recordPendingAuth: args.durability.recordPendingAuth,
15991
15992
  interactiveAuthEnabled: !isAgentRunFeatureDisabled(
15992
- args.policy,
15993
+ args.run.disabledFeatures,
15993
15994
  "interactive-auth"
15994
15995
  ),
15995
15996
  authorization: args.authorization
15996
15997
  });
15997
15998
  const pluginAuth = createPluginAuthOrchestration({
15998
15999
  abortAgent: args.abortAgent,
15999
- conversationId: args.conversationId,
16000
- sessionId: args.turnId,
16000
+ conversationId: args.run.conversationId,
16001
+ sessionId: args.run.turnId,
16001
16002
  actorId: credentialUserId,
16002
16003
  actor: args.currentActor,
16003
16004
  channelId: slackChannelId,
16004
- destination: args.routing.destination,
16005
+ destination: args.run.destination,
16005
16006
  source: runSource,
16006
- threadTs: args.routing.source.platform === "slack" ? args.routing.source.threadTs : void 0,
16007
+ threadTs: args.run.source.platform === "slack" ? args.run.source.threadTs : void 0,
16007
16008
  userMessage: args.userInput,
16008
16009
  pendingAuth: args.state.pendingAuth,
16009
16010
  recordPendingAuth: args.durability.recordPendingAuth,
16010
16011
  interactiveAuthEnabled: !isAgentRunFeatureDisabled(
16011
- args.policy,
16012
+ args.run.disabledFeatures,
16012
16013
  "interactive-auth"
16013
16014
  ),
16014
16015
  userTokenStore,
@@ -16022,7 +16023,7 @@ async function wireAgentTools(args) {
16022
16023
  onToolSuccess: async (input) => {
16023
16024
  await pluginHooks.afterMcpTool({
16024
16025
  ...input,
16025
- conversationId: args.conversationId
16026
+ conversationId: args.run.conversationId
16026
16027
  });
16027
16028
  }
16028
16029
  }
@@ -16035,11 +16036,11 @@ async function wireAgentTools(args) {
16035
16036
  args.invokedSkill && args.activeSkills.some((skill) => skill.name === args.invokedSkill?.name)
16036
16037
  );
16037
16038
  const commonToolRuntimeContext = {
16038
- conversationId: args.conversationId,
16039
+ conversationId: args.run.conversationId,
16039
16040
  userText: args.userInput,
16040
16041
  configuration: args.configurationValues,
16041
16042
  egress: createPluginEgress({
16042
- credentialContext: args.routing.credentialContext,
16043
+ credentialContext: args.run.credentialContext,
16043
16044
  pluginAuth: {
16044
16045
  async handleAuthRequired(signal) {
16045
16046
  await pluginAuth.maybeHandleAuthSignal({
@@ -16067,7 +16068,7 @@ async function wireAgentTools(args) {
16067
16068
  };
16068
16069
  const toolRoute = resolveToolRuntimeRoute({
16069
16070
  actor: args.currentActor,
16070
- routing: args.routing
16071
+ run: args.run
16071
16072
  });
16072
16073
  const toolRuntimeContext = {
16073
16074
  ...commonToolRuntimeContext,
@@ -16076,16 +16077,16 @@ async function wireAgentTools(args) {
16076
16077
  const actionReview = createToolActionReview({
16077
16078
  context: {
16078
16079
  actor: args.currentActor,
16079
- conversationId: args.conversationId,
16080
- credentialContext: args.routing.credentialContext,
16080
+ conversationId: args.run.conversationId,
16081
+ credentialContext: args.run.credentialContext,
16081
16082
  destination: toolRoute.destination,
16082
16083
  source: runSource,
16083
16084
  userIntent: args.currentUserIntent,
16084
16085
  evidence: () => buildToolActionEvidence(args.currentAgentMessages())
16085
16086
  },
16086
16087
  onDecision: ({ toolCallId, toolName, decision }) => recordGuardianActionReviewed({
16087
- conversationId: args.conversationId,
16088
- turnId: args.turnId,
16088
+ conversationId: args.run.conversationId,
16089
+ turnId: args.run.turnId,
16089
16090
  toolCallId,
16090
16091
  toolName,
16091
16092
  costUsd: decision.costUsd,
@@ -16108,7 +16109,7 @@ async function wireAgentTools(args) {
16108
16109
  args.generatedFiles.push(...files);
16109
16110
  return refs;
16110
16111
  },
16111
- toolOverrides: args.policy.toolOverrides,
16112
+ toolOverrides: args.run.environment?.toolOverrides,
16112
16113
  onSkillLoaded: async (loadedSkill) => {
16113
16114
  const resolvedSkill = await args.skillSandbox.loadSkill(
16114
16115
  loadedSkill.name
@@ -16180,10 +16181,12 @@ async function wireAgentTools(args) {
16180
16181
  const activeMcpCatalogs = toActiveMcpCatalogSummaries(
16181
16182
  mcpToolManager.getActiveToolCatalog()
16182
16183
  );
16184
+ const emitEvent = args.onEvent;
16183
16185
  const onToolCall = async (toolCallId, toolName, params) => {
16184
16186
  args.toolCalls.push(toolName);
16185
16187
  try {
16186
- await args.observers.onToolInvocation?.({
16188
+ await emitEvent?.({
16189
+ type: "tool_started",
16187
16190
  params,
16188
16191
  toolCallId,
16189
16192
  toolName
@@ -16195,17 +16198,23 @@ async function wireAgentTools(args) {
16195
16198
  });
16196
16199
  }
16197
16200
  };
16201
+ const onStatus = emitEvent ? async (status) => {
16202
+ await emitEvent({ type: "status", text: status.text });
16203
+ } : void 0;
16204
+ const onToolResult = emitEvent ? async (report) => {
16205
+ await emitEvent({ type: "tool_finished", report });
16206
+ } : void 0;
16198
16207
  const agentTools = createPiAgentTools(
16199
16208
  tools,
16200
16209
  args.skillSandbox,
16201
16210
  args.spanContext,
16202
- args.observers.onStatus,
16211
+ onStatus,
16203
16212
  agentSandbox.tools,
16204
16213
  pluginAuth,
16205
16214
  onToolCall,
16206
16215
  pluginHooks,
16207
16216
  args.conversationPrivacy,
16208
- args.observers.onToolResult,
16217
+ onToolResult,
16209
16218
  actionReview
16210
16219
  );
16211
16220
  return {
@@ -17026,33 +17035,33 @@ function waitForAbortSettlement(promise, timeoutMs) {
17026
17035
  );
17027
17036
  });
17028
17037
  }
17029
- async function executeAgentRun(request, streamFn) {
17030
- if (!request.routing.destination) {
17038
+ async function executeAgentRun(run, streamFn) {
17039
+ if (!run.destination) {
17031
17040
  throw new TypeError("Assistant reply generation requires a destination");
17032
17041
  }
17033
17042
  const destinationVisibility = await resolveDestinationVisibility({
17034
- destination: request.routing.destination,
17035
- visibility: request.routing.destinationVisibility
17043
+ destination: run.destination,
17044
+ visibility: run.destinationVisibility
17036
17045
  });
17037
17046
  const conversationPrivacy = resolveConversationPrivacy({
17038
17047
  visibility: destinationVisibility
17039
17048
  });
17040
- const resolvedRequest = destinationVisibility ? {
17041
- ...request,
17042
- routing: { ...request.routing, destinationVisibility }
17043
- } : request;
17044
- const credentialActor = request.routing.credentialContext?.actor;
17045
- const actor = actorFromRouting(request.routing);
17049
+ const resolvedRun = destinationVisibility ? {
17050
+ ...run,
17051
+ destinationVisibility
17052
+ } : run;
17053
+ const credentialActor = run.credentialContext?.actor;
17054
+ const actor = actorFromRun(run);
17046
17055
  const userActor = actor && "userId" in actor ? actor : void 0;
17047
17056
  const runLogContext = {
17048
- conversationId: request.conversationId,
17049
- platform: request.routing.source.platform,
17050
- messageConversationId: request.routing.source.platform === "slack" ? request.conversationId : request.routing.source.conversationId,
17051
- destinationName: request.routing.destination.platform === "slack" ? request.routing.destination.channelId : request.routing.destination.conversationId,
17057
+ conversationId: run.conversationId,
17058
+ platform: run.source.platform,
17059
+ messageConversationId: run.source.platform === "slack" ? run.conversationId : run.source.conversationId,
17060
+ destinationName: run.destination.platform === "slack" ? run.destination.channelId : run.destination.conversationId,
17052
17061
  userId: userActor?.userId,
17053
17062
  userName: userActor?.userName,
17054
17063
  userEmail: userActor?.email,
17055
- runId: request.runId,
17064
+ runId: run.runId,
17056
17065
  actorType: credentialActor ? "type" in credentialActor ? credentialActor.type : "system" : void 0,
17057
17066
  actorId: credentialActor ? "type" in credentialActor ? credentialActor.userId : credentialActor.name : void 0,
17058
17067
  assistantUserName: botConfig.userName
@@ -17062,7 +17071,7 @@ async function executeAgentRun(request, streamFn) {
17062
17071
  () => runWithConversationPrivacy(
17063
17072
  conversationPrivacy,
17064
17073
  () => executeAgentRunInPrivacyContext(
17065
- resolvedRequest,
17074
+ resolvedRun,
17066
17075
  conversationPrivacy,
17067
17076
  runLogContext,
17068
17077
  streamFn
@@ -17070,17 +17079,68 @@ async function executeAgentRun(request, streamFn) {
17070
17079
  )
17071
17080
  );
17072
17081
  }
17073
- async function executeAgentRunInPrivacyContext(request, conversationPrivacy, runLogContext, streamFn) {
17074
- const { conversationId, input, routing, runId, turnId } = request;
17075
- const policy = request.policy ?? {};
17082
+ async function executeAgentRunInPrivacyContext(run, conversationPrivacy, runLogContext, streamFn) {
17083
+ const conversationId = run.conversationId;
17084
+ const turnId = run.turnId;
17085
+ const runId = run.runId;
17086
+ const input = {
17087
+ actor: run.instruction.actor,
17088
+ includeConversationContextWithPiMessages: run.instruction.includeConversationContextWithHistory,
17089
+ messageText: run.instruction.text,
17090
+ userAttachments: run.instruction.attachments ? [...run.instruction.attachments] : void 0,
17091
+ inboundAttachmentCount: run.instruction.inboundAttachmentCount,
17092
+ omittedImageAttachmentCount: run.instruction.omittedImageAttachmentCount,
17093
+ piMessages: run.history ? [...run.history] : void 0,
17094
+ conversationContext: run.instruction.context
17095
+ };
17096
+ const routing = {
17097
+ actor: run.actor,
17098
+ credentialContext: run.credentialContext,
17099
+ source: run.source,
17100
+ slackConversation: run.slackConversation,
17101
+ slackActionToken: run.slackActionToken,
17102
+ destination: run.destination,
17103
+ publishExternally: run.publishExternally,
17104
+ destinationVisibility: run.destinationVisibility,
17105
+ surface: run.surface,
17106
+ dispatch: run.dispatch,
17107
+ toolChannelId: run.toolChannelId
17108
+ };
17109
+ const policy = {
17110
+ disabledFeatures: run.disabledFeatures,
17111
+ turnDeadlineAtMs: run.deadlineAtMs,
17112
+ signal: run.signal,
17113
+ reasoningLevel: run.reasoning,
17114
+ configuration: run.environment?.configuration,
17115
+ locationConfiguration: run.environment?.locationConfiguration,
17116
+ skillDirs: run.environment?.skillDirs,
17117
+ sandboxTracePropagation: run.environment?.sandboxTracePropagation,
17118
+ sandboxEgressSignals: run.environment?.sandboxEgressSignals,
17119
+ toolOverrides: run.environment?.toolOverrides
17120
+ };
17076
17121
  const signal = policy.signal;
17077
- const state = request.state ?? {};
17078
- const observers = request.observers ?? {};
17079
- const delivery = request.delivery;
17080
- const authorization = request.authorization;
17081
- const durability = request.durability ?? {};
17122
+ const state = run.state ?? {};
17123
+ const observers = {
17124
+ onStatus: run.onEvent ? async (status) => {
17125
+ await run.onEvent?.({ type: "status", text: status.text });
17126
+ } : void 0,
17127
+ onToolInvocation: run.onEvent ? async (invocation) => {
17128
+ await run.onEvent?.({
17129
+ type: "tool_started",
17130
+ params: invocation.params,
17131
+ toolCallId: invocation.toolCallId,
17132
+ toolName: invocation.toolName
17133
+ });
17134
+ } : void 0,
17135
+ onToolResult: run.onEvent ? async (report) => {
17136
+ await run.onEvent?.({ type: "tool_finished", report });
17137
+ } : void 0
17138
+ };
17139
+ const delivery = run.delivery;
17140
+ const authorization = run.authorization;
17141
+ const durability = run.durability ?? {};
17082
17142
  signal?.throwIfAborted();
17083
- assertRunRoutingConsistency(request);
17143
+ assertRunConsistency(run);
17084
17144
  const replyStartedAtMs = Date.now();
17085
17145
  const configuredTurnDeadlineAtMs = replyStartedAtMs + botConfig.turnTimeoutMs;
17086
17146
  const policyTurnDeadlineAtMs = typeof policy.turnDeadlineAtMs === "number" && Number.isFinite(policy.turnDeadlineAtMs) ? Math.floor(policy.turnDeadlineAtMs) : void 0;
@@ -17107,8 +17167,8 @@ async function executeAgentRunInPrivacyContext(request, conversationPrivacy, run
17107
17167
  ) : void 0;
17108
17168
  let activeModelProfile = STANDARD_MODEL_PROFILE;
17109
17169
  let activeModelId = modelIdForProfile(botConfig, activeModelProfile);
17110
- const actor = actorFromRouting(routing);
17111
- const surface = surfaceFromRouting(routing);
17170
+ const actor = actorFromRun(run);
17171
+ const surface = surfaceFromRun(run);
17112
17172
  const runSource = routing.source;
17113
17173
  const slackSource = runSource.platform === "slack" ? runSource : void 0;
17114
17174
  const slackDestination = routing.destination.platform === "slack" ? routing.destination : void 0;
@@ -17234,9 +17294,12 @@ async function executeAgentRunInPrivacyContext(request, conversationPrivacy, run
17234
17294
  skillSandbox
17235
17295
  });
17236
17296
  const explicitSkill = invokedSkill ? activeSkills.find((skill) => skill.name === invokedSkill.name) ?? null : null;
17237
- const { contextContentParts, routerBlocks, userContentParts } = buildPromptInput(input);
17297
+ const { contextContentParts, routerBlocks, userContentParts } = buildPromptInput({
17298
+ instruction: run.instruction,
17299
+ history: run.history
17300
+ });
17238
17301
  const preAgentPromptMessages = () => existingSessionRecord?.piMessages ?? [...input.piMessages ?? []];
17239
- const handoffEnabled = !isAgentRunFeatureDisabled(policy, "handoff");
17302
+ const handoffEnabled = !isAgentRunFeatureDisabled(policy.disabledFeatures, "handoff");
17240
17303
  const storedTurnRoute = await loadTurnRoute({ conversationId, turnId });
17241
17304
  if (storedTurnRoute) {
17242
17305
  const resumedAfterHandoff = handoffEnabled && activeModelProfile !== STANDARD_MODEL_PROFILE && activeModelProfile !== storedTurnRoute.modelProfile;
@@ -17431,7 +17494,7 @@ async function executeAgentRunInPrivacyContext(request, conversationPrivacy, run
17431
17494
  authorization,
17432
17495
  generatedFiles,
17433
17496
  invokedSkill,
17434
- observers,
17497
+ onEvent: run.onEvent,
17435
17498
  onFatalToolError(error) {
17436
17499
  pendingPiHookError = error;
17437
17500
  agent?.abort();
@@ -17439,15 +17502,12 @@ async function executeAgentRunInPrivacyContext(request, conversationPrivacy, run
17439
17502
  onSandboxRefChanged: (sandboxRef) => {
17440
17503
  lastKnownSandboxRef = sandboxRef;
17441
17504
  },
17442
- policy,
17443
17505
  preAgentPromptMessages,
17444
17506
  priorPiMessages,
17445
17507
  recordConnectedMcpProvider,
17446
17508
  requestHandoff,
17447
17509
  resume: runResume,
17448
- routing,
17449
- conversationId,
17450
- turnId,
17510
+ run,
17451
17511
  skillSandbox,
17452
17512
  spanContext,
17453
17513
  state,
@@ -17529,7 +17589,7 @@ async function executeAgentRunInPrivacyContext(request, conversationPrivacy, run
17529
17589
  explicitSkill,
17530
17590
  priorPiMessages,
17531
17591
  resumedFromSessionRecord,
17532
- routing,
17592
+ run,
17533
17593
  spanContext,
17534
17594
  turnId,
17535
17595
  toolGuidance: wiring.toolGuidance,
@@ -17838,7 +17898,7 @@ async function executeAgentRunInPrivacyContext(request, conversationPrivacy, run
17838
17898
  tools: agent.state.tools
17839
17899
  });
17840
17900
  }
17841
- const runAgentStep = async (run2, abortRun = () => agent.abort()) => {
17901
+ const runAgentStep = async (run3, abortRun = () => agent.abort()) => {
17842
17902
  let timeoutId;
17843
17903
  let removeAbortListener;
17844
17904
  const timeoutPromise = new Promise((_, reject) => {
@@ -17875,7 +17935,7 @@ async function executeAgentRunInPrivacyContext(request, conversationPrivacy, run
17875
17935
  let result2;
17876
17936
  try {
17877
17937
  result2 = await Promise.race(
17878
- abortPromise ? [run2, timeoutPromise, abortPromise] : [run2, timeoutPromise]
17938
+ abortPromise ? [run3, timeoutPromise, abortPromise] : [run3, timeoutPromise]
17879
17939
  );
17880
17940
  } catch (error) {
17881
17941
  if (runResume.timedOut) {
@@ -17893,7 +17953,7 @@ async function executeAgentRunInPrivacyContext(request, conversationPrivacy, run
17893
17953
  )
17894
17954
  });
17895
17955
  const settled = await waitForAbortSettlement(
17896
- run2,
17956
+ run3,
17897
17957
  AGENT_ABORT_SETTLE_GRACE_MS
17898
17958
  );
17899
17959
  if (!settled) {
@@ -17927,7 +17987,7 @@ async function executeAgentRunInPrivacyContext(request, conversationPrivacy, run
17927
17987
  return result2;
17928
17988
  };
17929
17989
  const requestedProfile = activeModelProfile === STANDARD_MODEL_PROFILE ? turnRoute.profile : void 0;
17930
- let run;
17990
+ let run2;
17931
17991
  let handoffApplied = false;
17932
17992
  if (requestedProfile && requestedProfile !== STANDARD_MODEL_PROFILE) {
17933
17993
  const handoffAbortController = new AbortController();
@@ -17967,7 +18027,7 @@ async function executeAgentRunInPrivacyContext(request, conversationPrivacy, run
17967
18027
  freshPromptMessage
17968
18028
  ]);
17969
18029
  }
17970
- run = shouldPromptAgent && !capacityUpdate ? agent.prompt(freshPromptMessage) : agent.continue();
18030
+ run2 = shouldPromptAgent && !capacityUpdate ? agent.prompt(freshPromptMessage) : agent.continue();
17971
18031
  let discardedRetryUsage;
17972
18032
  let actionConfirmationRetryUsed = false;
17973
18033
  let providerRetryAttempt = 0;
@@ -17983,7 +18043,7 @@ async function executeAgentRunInPrivacyContext(request, conversationPrivacy, run
17983
18043
  };
17984
18044
  try {
17985
18045
  for (; ; ) {
17986
- await runAgentStep(run);
18046
+ await runAgentStep(run2);
17987
18047
  if (assistantMessageDeliveryError) {
17988
18048
  throw assistantMessageDeliveryError;
17989
18049
  }
@@ -18027,7 +18087,7 @@ async function executeAgentRunInPrivacyContext(request, conversationPrivacy, run
18027
18087
  if (confirmationRetry) {
18028
18088
  actionConfirmationRetryUsed = true;
18029
18089
  await prepareRetry(confirmationRetry);
18030
- run = agent.continue();
18090
+ run2 = agent.continue();
18031
18091
  continue;
18032
18092
  }
18033
18093
  const emptyOutputContinuation = nextEmptyOutputContinuation({
@@ -18041,7 +18101,7 @@ async function executeAgentRunInPrivacyContext(request, conversationPrivacy, run
18041
18101
  logWarn("agent.turn.empty_output.retrying", {
18042
18102
  "app.ai.empty_output.attempt": emptyOutputAttempt
18043
18103
  });
18044
- run = agent.continue();
18104
+ run2 = agent.continue();
18045
18105
  continue;
18046
18106
  }
18047
18107
  if (emptyOutputContinuation.kind === "exhausted") {
@@ -18061,7 +18121,7 @@ async function executeAgentRunInPrivacyContext(request, conversationPrivacy, run
18061
18121
  await prepareRetry(providerRetry.messages);
18062
18122
  logWarn("agent.turn.provider.retrying");
18063
18123
  await sleep(providerRetry.delayMs, signal);
18064
- run = agent.continue();
18124
+ run2 = agent.continue();
18065
18125
  }
18066
18126
  } catch (error) {
18067
18127
  if (error instanceof AuthorizationPauseError) {
@@ -18207,29 +18267,28 @@ async function executeAgentRunInPrivacyContext(request, conversationPrivacy, run
18207
18267
  }
18208
18268
 
18209
18269
  // src/chat/runtime/agent-runner.ts
18210
- function createAgentRunner(run, options) {
18270
+ function createAgentRunner(execute, options) {
18271
+ const streamFn = options?.streamFn;
18211
18272
  const tracePropagation = options?.tracePropagation;
18212
18273
  const bindSpawnAgent = options?.bindSpawnAgent;
18213
18274
  const canBindSpawn = Boolean(bindSpawnAgent) && isExperimentalFeatureEnabled("subagents");
18214
- if (!tracePropagation && !canBindSpawn) {
18215
- return { run };
18216
- }
18217
18275
  return {
18218
- run: async (request) => {
18219
- const spawnAgent = bindSpawnAgent && canBindSpawn && !isAgentRunFeatureDisabled(request.policy, "subagents") ? bindSpawnAgent(request) : void 0;
18220
- return await run({
18221
- ...request,
18222
- policy: {
18223
- ...request.policy,
18224
- sandboxTracePropagation: request.policy?.sandboxTracePropagation ?? tracePropagation
18276
+ run: async (run) => {
18277
+ const spawnAgent = bindSpawnAgent && canBindSpawn && !isAgentRunFeatureDisabled(run.disabledFeatures, "subagents") ? bindSpawnAgent(run) : void 0;
18278
+ const nextRun = {
18279
+ ...run,
18280
+ environment: {
18281
+ ...run.environment,
18282
+ sandboxTracePropagation: run.environment?.sandboxTracePropagation ?? tracePropagation
18225
18283
  },
18226
18284
  ...spawnAgent ? {
18227
18285
  durability: {
18228
- ...request.durability,
18286
+ ...run.durability,
18229
18287
  spawnAgent
18230
18288
  }
18231
18289
  } : {}
18232
- });
18290
+ };
18291
+ return await execute(nextRun, streamFn);
18233
18292
  }
18234
18293
  };
18235
18294
  }