@dexto/core 1.6.26 → 1.6.27

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 (103) hide show
  1. package/dist/agent/DextoAgent.cjs +75 -90
  2. package/dist/agent/DextoAgent.d.ts +4 -4
  3. package/dist/agent/DextoAgent.d.ts.map +1 -1
  4. package/dist/agent/DextoAgent.js +76 -91
  5. package/dist/agent/error-codes.cjs +1 -0
  6. package/dist/agent/error-codes.d.ts +1 -0
  7. package/dist/agent/error-codes.d.ts.map +1 -1
  8. package/dist/agent/error-codes.js +1 -0
  9. package/dist/agent/errors.cjs +13 -0
  10. package/dist/agent/errors.d.ts +6 -0
  11. package/dist/agent/errors.d.ts.map +1 -1
  12. package/dist/agent/errors.js +13 -0
  13. package/dist/agent/index.d.ts +1 -0
  14. package/dist/agent/index.d.ts.map +1 -1
  15. package/dist/agent/schemas.d.ts +2 -2
  16. package/dist/agent/types.d.ts +11 -0
  17. package/dist/agent/types.d.ts.map +1 -1
  18. package/dist/approval/factory.cjs +1 -0
  19. package/dist/approval/factory.d.ts.map +1 -1
  20. package/dist/approval/factory.js +1 -0
  21. package/dist/approval/manager.cjs +19 -6
  22. package/dist/approval/manager.d.ts +6 -0
  23. package/dist/approval/manager.d.ts.map +1 -1
  24. package/dist/approval/manager.js +19 -6
  25. package/dist/approval/schemas.cjs +10 -0
  26. package/dist/approval/schemas.d.ts +305 -0
  27. package/dist/approval/schemas.d.ts.map +1 -1
  28. package/dist/approval/schemas.js +10 -0
  29. package/dist/events/index.cjs +210 -75
  30. package/dist/events/index.d.ts +44 -181
  31. package/dist/events/index.d.ts.map +1 -1
  32. package/dist/events/index.js +206 -74
  33. package/dist/hooks/manager.cjs +5 -2
  34. package/dist/hooks/manager.d.ts +2 -0
  35. package/dist/hooks/manager.d.ts.map +1 -1
  36. package/dist/hooks/manager.js +5 -2
  37. package/dist/hooks/types.d.ts +3 -0
  38. package/dist/hooks/types.d.ts.map +1 -1
  39. package/dist/index.browser.d.ts +1 -0
  40. package/dist/index.browser.d.ts.map +1 -1
  41. package/dist/index.cjs +3 -1
  42. package/dist/index.d.ts +1 -0
  43. package/dist/index.d.ts.map +1 -1
  44. package/dist/index.js +1 -0
  45. package/dist/llm/executor/turn-executor.cjs +8 -4
  46. package/dist/llm/executor/turn-executor.d.ts +3 -1
  47. package/dist/llm/executor/turn-executor.d.ts.map +1 -1
  48. package/dist/llm/executor/turn-executor.js +8 -4
  49. package/dist/llm/services/vercel.cjs +29 -6
  50. package/dist/llm/services/vercel.d.ts +3 -0
  51. package/dist/llm/services/vercel.d.ts.map +1 -1
  52. package/dist/llm/services/vercel.js +27 -5
  53. package/dist/mcp/manager.cjs +7 -2
  54. package/dist/mcp/manager.d.ts +3 -1
  55. package/dist/mcp/manager.d.ts.map +1 -1
  56. package/dist/mcp/manager.js +7 -2
  57. package/dist/mcp/mcp-client.cjs +71 -62
  58. package/dist/mcp/mcp-client.d.ts +3 -2
  59. package/dist/mcp/mcp-client.d.ts.map +1 -1
  60. package/dist/mcp/mcp-client.js +71 -62
  61. package/dist/mcp/schemas.d.ts +10 -10
  62. package/dist/resources/handlers/filesystem-handler.cjs +22 -3
  63. package/dist/resources/handlers/filesystem-handler.d.ts.map +1 -1
  64. package/dist/resources/handlers/filesystem-handler.js +22 -3
  65. package/dist/runtime/host-runtime.cjs +163 -0
  66. package/dist/runtime/host-runtime.d.ts +23 -0
  67. package/dist/runtime/host-runtime.d.ts.map +1 -0
  68. package/dist/runtime/host-runtime.js +133 -0
  69. package/dist/runtime/index.cjs +42 -0
  70. package/dist/runtime/index.d.ts +2 -0
  71. package/dist/runtime/index.d.ts.map +1 -0
  72. package/dist/runtime/index.js +21 -0
  73. package/dist/runtime/run-context.cjs +53 -0
  74. package/dist/runtime/run-context.d.ts +13 -0
  75. package/dist/runtime/run-context.d.ts.map +1 -0
  76. package/dist/runtime/run-context.js +34 -0
  77. package/dist/session/chat-session.cjs +30 -32
  78. package/dist/session/chat-session.d.ts +5 -15
  79. package/dist/session/chat-session.d.ts.map +1 -1
  80. package/dist/session/chat-session.js +31 -33
  81. package/dist/session/error-codes.cjs +1 -0
  82. package/dist/session/error-codes.d.ts +2 -1
  83. package/dist/session/error-codes.d.ts.map +1 -1
  84. package/dist/session/error-codes.js +1 -0
  85. package/dist/session/errors.cjs +13 -0
  86. package/dist/session/errors.d.ts +6 -0
  87. package/dist/session/errors.d.ts.map +1 -1
  88. package/dist/session/errors.js +13 -0
  89. package/dist/telemetry/decorators.cjs +75 -57
  90. package/dist/telemetry/decorators.d.ts +2 -0
  91. package/dist/telemetry/decorators.d.ts.map +1 -1
  92. package/dist/telemetry/decorators.js +75 -57
  93. package/dist/telemetry/utils.cjs +9 -6
  94. package/dist/telemetry/utils.d.ts +3 -0
  95. package/dist/telemetry/utils.d.ts.map +1 -1
  96. package/dist/telemetry/utils.js +9 -6
  97. package/dist/tools/tool-manager.cjs +92 -36
  98. package/dist/tools/tool-manager.d.ts +12 -3
  99. package/dist/tools/tool-manager.d.ts.map +1 -1
  100. package/dist/tools/tool-manager.js +92 -36
  101. package/dist/tools/types.d.ts +7 -1
  102. package/dist/tools/types.d.ts.map +1 -1
  103. package/package.json +1 -1
@@ -63,7 +63,8 @@ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "
63
63
  var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
64
64
  var vercel_exports = {};
65
65
  __export(vercel_exports, {
66
- VercelLLMService: () => VercelLLMService
66
+ VercelLLMService: () => VercelLLMService,
67
+ ensureRunContextMatchesServiceSession: () => ensureRunContextMatchesServiceSession
67
68
  });
68
69
  module.exports = __toCommonJS(vercel_exports);
69
70
  var import_types = require("../../logger/v2/types.js");
@@ -74,8 +75,24 @@ var import_decorators = require("../../telemetry/decorators.js");
74
75
  var import_api = require("@opentelemetry/api");
75
76
  var import_turn_executor = require("../executor/turn-executor.js");
76
77
  var import_DextoRuntimeError = require("../../errors/DextoRuntimeError.js");
78
+ var import_types4 = require("../../errors/types.js");
77
79
  var import_error_codes = require("../error-codes.js");
78
80
  var _VercelLLMService_decorators, _init;
81
+ function ensureRunContextMatchesServiceSession(serviceSessionId, runContext) {
82
+ if (runContext !== void 0 && runContext.sessionId !== serviceSessionId) {
83
+ throw new import_DextoRuntimeError.DextoRuntimeError(
84
+ import_error_codes.LLMErrorCode.GENERATION_FAILED,
85
+ import_types4.ErrorScope.LLM,
86
+ import_types4.ErrorType.SYSTEM,
87
+ `Run context session '${runContext.sessionId}' does not match LLM service session '${serviceSessionId}'`,
88
+ {
89
+ serviceSessionId,
90
+ runContextSessionId: runContext.sessionId
91
+ }
92
+ );
93
+ }
94
+ return serviceSessionId;
95
+ }
79
96
  _VercelLLMService_decorators = [(0, import_decorators.InstrumentClass)({
80
97
  prefix: "llm.vercel",
81
98
  excludeMethods: ["getModelId", "getAllTools", "createTurnExecutor"]
@@ -138,7 +155,7 @@ class VercelLLMService {
138
155
  /**
139
156
  * Create a TurnExecutor instance for executing the agent loop.
140
157
  */
141
- createTurnExecutor(externalSignal) {
158
+ createTurnExecutor(externalSignal, runContext) {
142
159
  return new import_turn_executor.TurnExecutor(
143
160
  this.model,
144
161
  this.toolManager,
@@ -160,7 +177,8 @@ class VercelLLMService {
160
177
  this.messageQueue,
161
178
  this.modelLimits,
162
179
  externalSignal,
163
- this.compactionStrategy
180
+ this.compactionStrategy,
181
+ runContext
164
182
  );
165
183
  }
166
184
  /**
@@ -176,6 +194,10 @@ class VercelLLMService {
176
194
  * @returns Object with text response
177
195
  */
178
196
  async stream(content, options) {
197
+ const sessionId = ensureRunContextMatchesServiceSession(
198
+ this.sessionId,
199
+ options?.runContext
200
+ );
179
201
  const activeSpan = import_api.trace.getActiveSpan();
180
202
  const currentContext = import_api.context.active();
181
203
  const provider = this.config.provider;
@@ -200,9 +222,9 @@ class VercelLLMService {
200
222
  return await import_api.context.with(updatedContext, async () => {
201
223
  const parts = typeof content === "string" ? [{ type: "text", text: content }] : content;
202
224
  await this.contextManager.addUserMessage(parts);
203
- const executor = this.createTurnExecutor(options?.signal);
225
+ const executor = this.createTurnExecutor(options?.signal, options?.runContext);
204
226
  const contributorContext = await this.toolManager.buildContributorContext({
205
- sessionId: this.sessionId
227
+ sessionId
206
228
  });
207
229
  const result = await executor.execute(contributorContext, true);
208
230
  return {
@@ -267,5 +289,6 @@ VercelLLMService = __decorateElement(_init, 0, "VercelLLMService", _VercelLLMSer
267
289
  __runInitializers(_init, 1, VercelLLMService);
268
290
  // Annotate the CommonJS export names for ESM import in node:
269
291
  0 && (module.exports = {
270
- VercelLLMService
292
+ VercelLLMService,
293
+ ensureRunContextMatchesServiceSession
271
294
  });
@@ -11,6 +11,8 @@ import type { ValidatedLLMConfig } from '../schemas.js';
11
11
  import { MessageQueueService } from '../../session/message-queue.js';
12
12
  import type { ResourceManager } from '../../resources/index.js';
13
13
  import type { ContentInput } from '../../agent/types.js';
14
+ import type { AgentRunContext } from '../../runtime/run-context.js';
15
+ export declare function ensureRunContextMatchesServiceSession(serviceSessionId: string, runContext?: AgentRunContext): string;
14
16
  /**
15
17
  * Vercel AI SDK implementation of the core session LLM runtime
16
18
  *
@@ -65,6 +67,7 @@ export declare class VercelLLMService {
65
67
  */
66
68
  stream(content: ContentInput, options?: {
67
69
  signal?: AbortSignal;
70
+ runContext?: AgentRunContext;
68
71
  }): Promise<{
69
72
  text: string;
70
73
  }>;
@@ -1 +1 @@
1
- {"version":3,"file":"vercel.d.ts","sourceRoot":"","sources":["../../../src/llm/services/vercel.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAqB,MAAM,IAAI,CAAC;AACtD,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAC1D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AACnD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AAEvD,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAC/C,O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,EAAE,kBAAkB,GAAG,IAAI;IAuC9F,WAAW,IAAI,OAAO,CAAC,OAAO,CAAC;IAI/B,eAAe,IAAI,OAAO,CAAC,OAAO,CAAC;IAMnC;;OAEG;IACH,OAAO,CAAC,kBAAkB;IA8B1B;;OAEG;IACH,OAAc,YAAY,EAAE;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;IAE7C;;;;;;;OAOG;IACG,MAAM,CACR,OAAO,EAAE,YAAY,EACrB,OAAO,CAAC,EAAE;QACN,MAAM,CAAC,EAAE,WAAW,CAAC;QACrB,UAAU,CAAC,EAAE,eAAe,CAAC;KAChC,GACF,OAAO,CAAC;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;IA+D5B;;;OAGG;IACH,SAAS,IAAI,gBAAgB;IA+B7B;;OAEG;IACH,iBAAiB,IAAI,cAAc,CAAC,OAAO,CAAC;IAI5C;;OAEG;IACH,eAAe,IAAI,mBAAmB;IAItC;;OAEG;IACH,qBAAqB,IAAI,OAAO,mCAAmC,EAAE,kBAAkB,GAAG,IAAI;IAI9F,gBAAgB,IAAI,aAAa;CAGpC"}
@@ -12,7 +12,23 @@ import { InstrumentClass } from "../../telemetry/decorators.js";
12
12
  import { trace, context, propagation } from "@opentelemetry/api";
13
13
  import { TurnExecutor } from "../executor/turn-executor.js";
14
14
  import { DextoRuntimeError } from "../../errors/DextoRuntimeError.js";
15
+ import { ErrorScope, ErrorType } from "../../errors/types.js";
15
16
  import { LLMErrorCode } from "../error-codes.js";
17
+ function ensureRunContextMatchesServiceSession(serviceSessionId, runContext) {
18
+ if (runContext !== void 0 && runContext.sessionId !== serviceSessionId) {
19
+ throw new DextoRuntimeError(
20
+ LLMErrorCode.GENERATION_FAILED,
21
+ ErrorScope.LLM,
22
+ ErrorType.SYSTEM,
23
+ `Run context session '${runContext.sessionId}' does not match LLM service session '${serviceSessionId}'`,
24
+ {
25
+ serviceSessionId,
26
+ runContextSessionId: runContext.sessionId
27
+ }
28
+ );
29
+ }
30
+ return serviceSessionId;
31
+ }
16
32
  _VercelLLMService_decorators = [InstrumentClass({
17
33
  prefix: "llm.vercel",
18
34
  excludeMethods: ["getModelId", "getAllTools", "createTurnExecutor"]
@@ -75,7 +91,7 @@ class VercelLLMService {
75
91
  /**
76
92
  * Create a TurnExecutor instance for executing the agent loop.
77
93
  */
78
- createTurnExecutor(externalSignal) {
94
+ createTurnExecutor(externalSignal, runContext) {
79
95
  return new TurnExecutor(
80
96
  this.model,
81
97
  this.toolManager,
@@ -97,7 +113,8 @@ class VercelLLMService {
97
113
  this.messageQueue,
98
114
  this.modelLimits,
99
115
  externalSignal,
100
- this.compactionStrategy
116
+ this.compactionStrategy,
117
+ runContext
101
118
  );
102
119
  }
103
120
  /**
@@ -113,6 +130,10 @@ class VercelLLMService {
113
130
  * @returns Object with text response
114
131
  */
115
132
  async stream(content, options) {
133
+ const sessionId = ensureRunContextMatchesServiceSession(
134
+ this.sessionId,
135
+ options?.runContext
136
+ );
116
137
  const activeSpan = trace.getActiveSpan();
117
138
  const currentContext = context.active();
118
139
  const provider = this.config.provider;
@@ -137,9 +158,9 @@ class VercelLLMService {
137
158
  return await context.with(updatedContext, async () => {
138
159
  const parts = typeof content === "string" ? [{ type: "text", text: content }] : content;
139
160
  await this.contextManager.addUserMessage(parts);
140
- const executor = this.createTurnExecutor(options?.signal);
161
+ const executor = this.createTurnExecutor(options?.signal, options?.runContext);
141
162
  const contributorContext = await this.toolManager.buildContributorContext({
142
- sessionId: this.sessionId
163
+ sessionId
143
164
  });
144
165
  const result = await executor.execute(contributorContext, true);
145
166
  return {
@@ -203,5 +224,6 @@ _init = __decoratorStart(null);
203
224
  VercelLLMService = __decorateElement(_init, 0, "VercelLLMService", _VercelLLMService_decorators, VercelLLMService);
204
225
  __runInitializers(_init, 1, VercelLLMService);
205
226
  export {
206
- VercelLLMService
227
+ VercelLLMService,
228
+ ensureRunContextMatchesServiceSession
207
229
  };
@@ -387,9 +387,10 @@ class MCPManager {
387
387
  * @param toolName Name of the MCP tool to execute (may include server prefix)
388
388
  * @param args Arguments to pass to the tool
389
389
  * @param sessionId Optional session ID
390
+ * @param runContext Optional execution-scoped context for this tool call
390
391
  * @returns Promise resolving to the tool execution result
391
392
  */
392
- async executeTool(toolName, args, _sessionId) {
393
+ async executeTool(toolName, args, sessionId, runContext) {
393
394
  const client = this.getToolClient(toolName);
394
395
  if (!client) {
395
396
  this.logger.error(`\u274C No MCP tool found: ${toolName}`);
@@ -406,7 +407,11 @@ class MCPManager {
406
407
  `\u25B6\uFE0F Executing MCP tool '${actualToolName}' on server '${serverName}'...`
407
408
  );
408
409
  try {
409
- const result = await client.callTool(actualToolName, args);
410
+ const invocation = sessionId !== void 0 || runContext !== void 0 ? {
411
+ ...sessionId !== void 0 ? { sessionId } : {},
412
+ ...runContext !== void 0 ? { runContext } : {}
413
+ } : void 0;
414
+ const result = await client.callTool(actualToolName, args, invocation);
410
415
  return result;
411
416
  } catch (error) {
412
417
  this.logger.error(
@@ -7,6 +7,7 @@ import { type AgentEventBus } from '../events/index.js';
7
7
  import type { PromptDefinition } from '../prompts/types.js';
8
8
  import type { JSONSchema7 } from 'json-schema';
9
9
  import type { ApprovalManager } from '../approval/manager.js';
10
+ import type { AgentRunContext } from '../runtime/run-context.js';
10
11
  type ToolCacheEntry = {
11
12
  serverName: string;
12
13
  client: McpClient;
@@ -130,9 +131,10 @@ export declare class MCPManager {
130
131
  * @param toolName Name of the MCP tool to execute (may include server prefix)
131
132
  * @param args Arguments to pass to the tool
132
133
  * @param sessionId Optional session ID
134
+ * @param runContext Optional execution-scoped context for this tool call
133
135
  * @returns Promise resolving to the tool execution result
134
136
  */
135
- executeTool(toolName: string, args: any, _sessionId?: string): Promise<any>;
137
+ executeTool(toolName: string, args: any, sessionId?: string, runContext?: AgentRunContext): Promise<any>;
136
138
  /**
137
139
  * Get all available prompt names from all connected clients, updating the cache.
138
140
  * @returns Promise resolving to an array of unique prompt names.
@@ -1 +1 @@
1
- {"version":3,"file":"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AMG;IACG,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,wBAAwB,GAAG,OAAO,CAAC,IAAI,CAAC;IAwClF;;;OAGG;IACH,UAAU,IAAI,GAAG,CAAC,MAAM,EAAE,SAAS,CAAC;IAIpC;;;OAGG;IACH,oBAAoB,IAAI;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG;YAAE,OAAO,EAAE,MAAM,CAAC;YAAC,IAAI,CAAC,EAAE,MAAM,CAAA;SAAE,CAAA;KAAE;IAI7E,wBAAwB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS;IAI1D,4BAA4B,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS;IAI9D,eAAe,CAAC,IAAI,EAAE,MAAM;IAQ5B,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,wBAAwB,GAAG,SAAS;IAInE;;;;OAIG;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAc9B;;;OAGG;IACG,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IA0B/C;;;;OAIG;IACG,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAuEhD;;OAEG;IACG,aAAa,IAAI,OAAO,CAAC,IAAI,CAAC;IAyBpC;;OAEG;IACH,OAAO,CAAC,wBAAwB;IA4BhC;;OAEG;YACW,qBAAqB;IAuCnC;;OAEG;YACW,wBAAwB;IAkDtC;;OAEG;YACW,sBAAsB;CA4HvC"}
@@ -365,9 +365,10 @@ class MCPManager {
365
365
  * @param toolName Name of the MCP tool to execute (may include server prefix)
366
366
  * @param args Arguments to pass to the tool
367
367
  * @param sessionId Optional session ID
368
+ * @param runContext Optional execution-scoped context for this tool call
368
369
  * @returns Promise resolving to the tool execution result
369
370
  */
370
- async executeTool(toolName, args, _sessionId) {
371
+ async executeTool(toolName, args, sessionId, runContext) {
371
372
  const client = this.getToolClient(toolName);
372
373
  if (!client) {
373
374
  this.logger.error(`\u274C No MCP tool found: ${toolName}`);
@@ -384,7 +385,11 @@ class MCPManager {
384
385
  `\u25B6\uFE0F Executing MCP tool '${actualToolName}' on server '${serverName}'...`
385
386
  );
386
387
  try {
387
- const result = await client.callTool(actualToolName, args);
388
+ const invocation = sessionId !== void 0 || runContext !== void 0 ? {
389
+ ...sessionId !== void 0 ? { sessionId } : {},
390
+ ...runContext !== void 0 ? { runContext } : {}
391
+ } : void 0;
392
+ const result = await client.callTool(actualToolName, args, invocation);
388
393
  return result;
389
394
  } catch (error) {
390
395
  this.logger.error(
@@ -22,6 +22,7 @@ __export(mcp_client_exports, {
22
22
  });
23
23
  module.exports = __toCommonJS(mcp_client_exports);
24
24
  var import_client = require("@modelcontextprotocol/sdk/client/index.js");
25
+ var import_async_hooks = require("async_hooks");
25
26
  var import_stdio = require("@modelcontextprotocol/sdk/client/stdio.js");
26
27
  var import_sse = require("@modelcontextprotocol/sdk/client/sse.js");
27
28
  var import_streamableHttp = require("@modelcontextprotocol/sdk/client/streamableHttp.js");
@@ -49,6 +50,7 @@ function buildClientCapabilities() {
49
50
  };
50
51
  }
51
52
  class DextoMcpClient extends import_events.EventEmitter {
53
+ toolInvocationContext = new import_async_hooks.AsyncLocalStorage();
52
54
  client = null;
53
55
  transport = null;
54
56
  isConnected = false;
@@ -322,71 +324,75 @@ class DextoMcpClient extends import_events.EventEmitter {
322
324
  * @param args Tool arguments
323
325
  * @returns Result of the tool execution
324
326
  */
325
- async callTool(name, args) {
327
+ async callTool(name, args, invocation) {
326
328
  this.ensureConnected();
327
- const shouldTrace = (0, import_utils.hasActiveTelemetry)();
328
- const tracer = shouldTrace ? import_api.trace.getTracer("dexto") : null;
329
- const span = tracer?.startSpan(`mcp.tool.${name}`, {
330
- kind: import_api.SpanKind.CLIENT
331
- });
332
- try {
333
- if (span) {
334
- const ctx = import_api.trace.setSpan(import_api.context.active(), span);
335
- (0, import_utils.addBaggageAttributesToSpan)(span, ctx, this.logger);
336
- span.setAttribute("tool.name", name);
337
- span.setAttribute("tool.server", this.serverAlias || "unknown");
338
- span.setAttribute("tool.timeout", this.timeout);
339
- span.setAttribute("tool.arguments", (0, import_safe_stringify.safeStringify)(args, 4096));
340
- }
341
- this.logger.debug(`Calling tool '${name}' with args: ${JSON.stringify(args, null, 2)}`);
342
- let toolArgs = args;
343
- if (typeof args === "string") {
344
- try {
345
- toolArgs = JSON.parse(args);
346
- } catch {
347
- toolArgs = { input: args };
329
+ return await this.toolInvocationContext.run(invocation, async () => {
330
+ const shouldTrace = (0, import_utils.hasActiveTelemetry)();
331
+ const tracer = shouldTrace ? import_api.trace.getTracer("dexto") : null;
332
+ const span = tracer?.startSpan(`mcp.tool.${name}`, {
333
+ kind: import_api.SpanKind.CLIENT
334
+ });
335
+ try {
336
+ if (span) {
337
+ const ctx = import_api.trace.setSpan(import_api.context.active(), span);
338
+ (0, import_utils.addBaggageAttributesToSpan)(span, ctx, this.logger);
339
+ span.setAttribute("tool.name", name);
340
+ span.setAttribute("tool.server", this.serverAlias || "unknown");
341
+ span.setAttribute("tool.timeout", this.timeout);
342
+ span.setAttribute("tool.arguments", (0, import_safe_stringify.safeStringify)(args, 4096));
348
343
  }
349
- }
350
- this.logger.debug(`Using timeout: ${this.timeout}`);
351
- const result = await this.client.callTool(
352
- { name, arguments: toolArgs },
353
- void 0,
354
- // resultSchema (optional)
355
- { timeout: this.timeout }
356
- // Use server-specific timeout, default 1 minute
357
- );
358
- const logResult = JSON.stringify(
359
- result,
360
- (key, value) => {
361
- if (key === "data" && typeof value === "string" && value.length > 100) {
362
- return `[Base64 data: ${value.length} chars]`;
344
+ this.logger.debug(
345
+ `Calling tool '${name}' with args: ${JSON.stringify(args, null, 2)}`
346
+ );
347
+ let toolArgs = args;
348
+ if (typeof args === "string") {
349
+ try {
350
+ toolArgs = JSON.parse(args);
351
+ } catch {
352
+ toolArgs = { input: args };
363
353
  }
364
- return value;
365
- },
366
- 2
367
- );
368
- this.logger.debug(`Tool '${name}' result: ${logResult}`);
369
- if (span) {
370
- span.setAttribute("tool.result", (0, import_safe_stringify.safeStringify)(result, 4096));
371
- span.setStatus({ code: import_api.SpanStatusCode.OK });
372
- }
373
- if (result === null || result === void 0) {
374
- return "Tool executed successfully with no result data.";
375
- }
376
- return result;
377
- } catch (error) {
378
- this.logger.error(`Tool call '${name}' failed: ${JSON.stringify(error, null, 2)}`);
379
- if (span) {
380
- span.recordException(error);
381
- span.setStatus({
382
- code: import_api.SpanStatusCode.ERROR,
383
- message: error instanceof Error ? error.message : String(error)
384
- });
354
+ }
355
+ this.logger.debug(`Using timeout: ${this.timeout}`);
356
+ const result = await this.client.callTool(
357
+ { name, arguments: toolArgs },
358
+ void 0,
359
+ // resultSchema (optional)
360
+ { timeout: this.timeout }
361
+ // Use server-specific timeout, default 1 minute
362
+ );
363
+ const logResult = JSON.stringify(
364
+ result,
365
+ (key, value) => {
366
+ if (key === "data" && typeof value === "string" && value.length > 100) {
367
+ return `[Base64 data: ${value.length} chars]`;
368
+ }
369
+ return value;
370
+ },
371
+ 2
372
+ );
373
+ this.logger.debug(`Tool '${name}' result: ${logResult}`);
374
+ if (span) {
375
+ span.setAttribute("tool.result", (0, import_safe_stringify.safeStringify)(result, 4096));
376
+ span.setStatus({ code: import_api.SpanStatusCode.OK });
377
+ }
378
+ if (result === null || result === void 0) {
379
+ return "Tool executed successfully with no result data.";
380
+ }
381
+ return result;
382
+ } catch (error) {
383
+ this.logger.error(`Tool call '${name}' failed: ${JSON.stringify(error, null, 2)}`);
384
+ if (span) {
385
+ span.recordException(error);
386
+ span.setStatus({
387
+ code: import_api.SpanStatusCode.ERROR,
388
+ message: error instanceof Error ? error.message : String(error)
389
+ });
390
+ }
391
+ return `Error executing tool '${name}': ${error instanceof Error ? error.message : String(error)}`;
392
+ } finally {
393
+ span?.end();
385
394
  }
386
- return `Error executing tool '${name}': ${error instanceof Error ? error.message : String(error)}`;
387
- } finally {
388
- span?.end();
389
- }
395
+ });
390
396
  }
391
397
  /**
392
398
  * Get the list of tools provided by this client
@@ -657,10 +663,13 @@ class DextoMcpClient extends import_events.EventEmitter {
657
663
  );
658
664
  return { action: "decline" };
659
665
  }
666
+ const invocation = this.toolInvocationContext.getStore();
660
667
  const response = await this.approvalManager.requestElicitation({
661
668
  schema: params.requestedSchema,
662
669
  prompt: params.message,
663
- serverName: this.serverAlias || "unknown"
670
+ serverName: this.serverAlias || "unknown",
671
+ ...invocation?.sessionId !== void 0 ? { sessionId: invocation.sessionId } : {},
672
+ ...invocation?.runContext?.hostRuntime !== void 0 ? { hostRuntime: invocation.runContext.hostRuntime } : {}
664
673
  });
665
674
  if (response.status === import_types2.ApprovalStatus.APPROVED && response.data) {
666
675
  const formData = response.data && typeof response.data === "object" && "formData" in response.data ? response.data.formData : {};
@@ -3,13 +3,14 @@ import { EventEmitter } from 'events';
3
3
  import type { Logger } from '../logger/v2/types.js';
4
4
  import type { ApprovalManager } from '../approval/manager.js';
5
5
  import type { ValidatedMcpServerConfig } from './schemas.js';
6
- import type { ToolSet } from '../tools/types.js';
6
+ import type { ToolExecutionContextBase, ToolSet } from '../tools/types.js';
7
7
  import type { McpClient, MCPResourceSummary, McpAuthProviderFactory } from './types.js';
8
8
  import type { GetPromptResult, ReadResourceResult, Prompt } from '@modelcontextprotocol/sdk/types.js';
9
9
  /**
10
10
  * Wrapper on top of Client class provided in model context protocol SDK, to add additional metadata about the server
11
11
  */
12
12
  export declare class DextoMcpClient extends EventEmitter implements McpClient {
13
+ private readonly toolInvocationContext;
13
14
  private client;
14
15
  private transport;
15
16
  private isConnected;
@@ -52,7 +53,7 @@ export declare class DextoMcpClient extends EventEmitter implements McpClient {
52
53
  * @param args Tool arguments
53
54
  * @returns Result of the tool execution
54
55
  */
55
- callTool(name: string, args: any): Promise<any>;
56
+ callTool(name: string, args: any, invocation?: Pick<ToolExecutionContextBase, 'sessionId' | 'runContext'>): Promise<any>;
56
57
  /**
57
58
  * Get the list of tools provided by this client
58
59
  * @returns Array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