@dexto/core 1.12.1 → 1.13.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 (82) hide show
  1. package/dist/agent/DextoAgent.d.ts +2 -5
  2. package/dist/agent/DextoAgent.d.ts.map +1 -1
  3. package/dist/approval/index.cjs +4 -2
  4. package/dist/approval/index.d.ts +1 -1
  5. package/dist/approval/index.d.ts.map +1 -1
  6. package/dist/approval/index.js +3 -2
  7. package/dist/approval/manager.cjs +23 -4
  8. package/dist/approval/manager.d.ts +3 -2
  9. package/dist/approval/manager.d.ts.map +1 -1
  10. package/dist/approval/manager.js +21 -3
  11. package/dist/approval/schemas.cjs +5 -0
  12. package/dist/approval/schemas.d.ts +8 -0
  13. package/dist/approval/schemas.d.ts.map +1 -1
  14. package/dist/approval/schemas.js +5 -0
  15. package/dist/approval/types.d.ts +2 -2
  16. package/dist/approval/types.d.ts.map +1 -1
  17. package/dist/events/index.d.ts +2 -0
  18. package/dist/events/index.d.ts.map +1 -1
  19. package/dist/llm/executor/turn-executor.cjs +13 -20
  20. package/dist/llm/executor/turn-executor.d.ts +0 -1
  21. package/dist/llm/executor/turn-executor.d.ts.map +1 -1
  22. package/dist/llm/executor/turn-executor.js +13 -20
  23. package/dist/mcp/errors.cjs +9 -0
  24. package/dist/mcp/errors.d.ts +4 -0
  25. package/dist/mcp/errors.d.ts.map +1 -1
  26. package/dist/mcp/errors.js +9 -0
  27. package/dist/mcp/manager.cjs +79 -3
  28. package/dist/mcp/manager.d.ts +14 -7
  29. package/dist/mcp/manager.d.ts.map +1 -1
  30. package/dist/mcp/manager.js +79 -3
  31. package/dist/mcp/mcp-client.cjs +52 -62
  32. package/dist/mcp/mcp-client.d.ts.map +1 -1
  33. package/dist/mcp/mcp-client.js +54 -63
  34. package/dist/storage/tool-executions/types.cjs +12 -8
  35. package/dist/storage/tool-executions/types.d.ts +9 -0
  36. package/dist/storage/tool-executions/types.d.ts.map +1 -1
  37. package/dist/storage/tool-executions/types.js +12 -8
  38. package/dist/telemetry/decorators.cjs +47 -23
  39. package/dist/telemetry/decorators.d.ts +6 -0
  40. package/dist/telemetry/decorators.d.ts.map +1 -1
  41. package/dist/telemetry/decorators.js +47 -23
  42. package/dist/telemetry/operation-span.cjs +5 -2
  43. package/dist/telemetry/operation-span.d.ts +3 -0
  44. package/dist/telemetry/operation-span.d.ts.map +1 -1
  45. package/dist/telemetry/operation-span.js +5 -2
  46. package/dist/tools/approval/tool-approval-policy.cjs +11 -1
  47. package/dist/tools/approval/tool-approval-policy.d.ts +2 -2
  48. package/dist/tools/approval/tool-approval-policy.d.ts.map +1 -1
  49. package/dist/tools/approval/tool-approval-policy.js +11 -1
  50. package/dist/tools/identity.cjs +36 -0
  51. package/dist/tools/identity.d.ts +6 -0
  52. package/dist/tools/identity.d.ts.map +1 -0
  53. package/dist/tools/identity.js +13 -0
  54. package/dist/tools/index.cjs +2 -0
  55. package/dist/tools/index.d.ts +2 -1
  56. package/dist/tools/index.d.ts.map +1 -1
  57. package/dist/tools/index.js +4 -1
  58. package/dist/tools/presentation/tool-presentation.d.ts +5 -0
  59. package/dist/tools/presentation/tool-presentation.d.ts.map +1 -1
  60. package/dist/tools/schema-fingerprint.cjs +48 -0
  61. package/dist/tools/schema-fingerprint.d.ts +4 -0
  62. package/dist/tools/schema-fingerprint.d.ts.map +1 -0
  63. package/dist/tools/schema-fingerprint.js +25 -0
  64. package/dist/tools/schemas.cjs +3 -0
  65. package/dist/tools/schemas.d.ts +1 -0
  66. package/dist/tools/schemas.d.ts.map +1 -1
  67. package/dist/tools/schemas.js +2 -0
  68. package/dist/tools/tool-manager.cjs +160 -43
  69. package/dist/tools/tool-manager.d.ts +20 -11
  70. package/dist/tools/tool-manager.d.ts.map +1 -1
  71. package/dist/tools/tool-manager.js +160 -43
  72. package/dist/tools/types.d.ts +48 -0
  73. package/dist/tools/types.d.ts.map +1 -1
  74. package/dist/utils/schema.cjs +2 -2
  75. package/dist/utils/schema.d.ts +1 -1
  76. package/dist/utils/schema.d.ts.map +1 -1
  77. package/dist/utils/schema.js +2 -2
  78. package/dist/utils/stable-fingerprint.cjs +32 -0
  79. package/dist/utils/stable-fingerprint.d.ts +3 -0
  80. package/dist/utils/stable-fingerprint.d.ts.map +1 -0
  81. package/dist/utils/stable-fingerprint.js +9 -0
  82. package/package.json +9 -2
@@ -34,8 +34,7 @@ var import_types2 = require("../approval/types.js");
34
34
  var import_errors = require("./errors.js");
35
35
  var import_types3 = require("@modelcontextprotocol/sdk/types.js");
36
36
  var import_api = require("@opentelemetry/api");
37
- var import_utils = require("../telemetry/utils.js");
38
- var import_safe_stringify = require("../utils/safe-stringify.js");
37
+ var import_operation_span = require("../telemetry/operation-span.js");
39
38
  const UI_EXTENSION_NAME = "io.modelcontextprotocol/ui";
40
39
  const UI_EXTENSION_MIME_TYPE = "text/html;profile=mcp-app";
41
40
  function buildClientCapabilities() {
@@ -49,6 +48,19 @@ function buildClientCapabilities() {
49
48
  }
50
49
  };
51
50
  }
51
+ function mcpToolFailureMessage(name, result) {
52
+ const parsed = import_types3.CallToolResultSchema.safeParse(result);
53
+ if (!parsed.success) {
54
+ return `MCP tool '${name}' failed.`;
55
+ }
56
+ const messages = [];
57
+ for (const content of parsed.data.content) {
58
+ if (content.type === "text") {
59
+ messages.push(content.text);
60
+ }
61
+ }
62
+ return messages.join("\n") || `MCP tool '${name}' failed.`;
63
+ }
52
64
  class DextoMcpClient extends import_events.EventEmitter {
53
65
  toolInvocationContext = new import_async_hooks.AsyncLocalStorage();
54
66
  client = null;
@@ -327,70 +339,46 @@ class DextoMcpClient extends import_events.EventEmitter {
327
339
  async callTool(name, args, invocation) {
328
340
  this.ensureConnected();
329
341
  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
342
  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));
343
- }
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 };
353
- }
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]`;
343
+ return await (0, import_operation_span.recordOperationSpan)(
344
+ {
345
+ attributes: {
346
+ "tool.name": name,
347
+ "tool.server": this.serverAlias || "unknown",
348
+ "tool.timeout": this.timeout
349
+ },
350
+ captureErrors: false,
351
+ componentName: "DextoMcpClient",
352
+ name: `mcp.tool.${name}`,
353
+ spanKind: import_api.SpanKind.CLIENT
354
+ },
355
+ async () => {
356
+ this.logger.debug(`Calling tool '${name}'`);
357
+ let toolArgs = args;
358
+ if (typeof args === "string") {
359
+ try {
360
+ toolArgs = JSON.parse(args);
361
+ } catch {
362
+ toolArgs = { input: args };
363
+ }
364
+ }
365
+ this.logger.debug(`Using timeout: ${this.timeout}`);
366
+ const result = await this.client.callTool(
367
+ { name, arguments: toolArgs },
368
+ void 0,
369
+ { timeout: this.timeout }
370
+ );
371
+ if (result.isError === true) {
372
+ throw new Error(mcpToolFailureMessage(name, result));
368
373
  }
369
- return value;
374
+ this.logger.debug(`Tool '${name}' completed`);
375
+ return result ?? "Tool executed successfully with no result data.";
370
376
  },
371
- 2
377
+ this.logger
372
378
  );
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
379
  } 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();
380
+ this.logger.error(`Tool call '${name}' failed`);
381
+ throw error;
394
382
  }
395
383
  });
396
384
  }
@@ -415,7 +403,9 @@ class DextoMcpClient extends import_events.EventEmitter {
415
403
  tools[tool.name] = {
416
404
  description: tool.description ?? "",
417
405
  parameters: tool.inputSchema,
418
- _meta: tool._meta
406
+ ...tool.outputSchema !== void 0 ? { outputSchema: tool.outputSchema } : {},
407
+ ...tool.annotations !== void 0 ? { annotations: tool.annotations } : {},
408
+ ...tool._meta !== void 0 ? { _meta: tool._meta } : {}
419
409
  };
420
410
  });
421
411
  } else {
@@ -1 +1 @@
1
- {"version":3,"file":"mcp-client.d.ts","sourceRoot":"","sources":["../../src/mcp/mcp-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AAMnE,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAGtC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAEpD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAE9D,OA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"}
@@ -11,13 +11,13 @@ import { DextoLogComponent } from "../logger/v2/types.js";
11
11
  import { ApprovalStatus } from "../approval/types.js";
12
12
  import { MCPError } from "./errors.js";
13
13
  import {
14
+ CallToolResultSchema,
14
15
  ResourceUpdatedNotificationSchema,
15
16
  PromptListChangedNotificationSchema,
16
17
  ToolListChangedNotificationSchema
17
18
  } from "@modelcontextprotocol/sdk/types.js";
18
- import { trace, context, SpanStatusCode, SpanKind } from "@opentelemetry/api";
19
- import { hasActiveTelemetry, addBaggageAttributesToSpan } from "../telemetry/utils.js";
20
- import { safeStringify } from "../utils/safe-stringify.js";
19
+ import { SpanKind } from "@opentelemetry/api";
20
+ import { recordOperationSpan } from "../telemetry/operation-span.js";
21
21
  const UI_EXTENSION_NAME = "io.modelcontextprotocol/ui";
22
22
  const UI_EXTENSION_MIME_TYPE = "text/html;profile=mcp-app";
23
23
  function buildClientCapabilities() {
@@ -31,6 +31,19 @@ function buildClientCapabilities() {
31
31
  }
32
32
  };
33
33
  }
34
+ function mcpToolFailureMessage(name, result) {
35
+ const parsed = CallToolResultSchema.safeParse(result);
36
+ if (!parsed.success) {
37
+ return `MCP tool '${name}' failed.`;
38
+ }
39
+ const messages = [];
40
+ for (const content of parsed.data.content) {
41
+ if (content.type === "text") {
42
+ messages.push(content.text);
43
+ }
44
+ }
45
+ return messages.join("\n") || `MCP tool '${name}' failed.`;
46
+ }
34
47
  class DextoMcpClient extends EventEmitter {
35
48
  toolInvocationContext = new AsyncLocalStorage();
36
49
  client = null;
@@ -309,70 +322,46 @@ class DextoMcpClient extends EventEmitter {
309
322
  async callTool(name, args, invocation) {
310
323
  this.ensureConnected();
311
324
  return await this.toolInvocationContext.run(invocation, async () => {
312
- const shouldTrace = hasActiveTelemetry();
313
- const tracer = shouldTrace ? trace.getTracer("dexto") : null;
314
- const span = tracer?.startSpan(`mcp.tool.${name}`, {
315
- kind: SpanKind.CLIENT
316
- });
317
325
  try {
318
- if (span) {
319
- const ctx = trace.setSpan(context.active(), span);
320
- addBaggageAttributesToSpan(span, ctx, this.logger);
321
- span.setAttribute("tool.name", name);
322
- span.setAttribute("tool.server", this.serverAlias || "unknown");
323
- span.setAttribute("tool.timeout", this.timeout);
324
- span.setAttribute("tool.arguments", safeStringify(args, 4096));
325
- }
326
- this.logger.debug(
327
- `Calling tool '${name}' with args: ${JSON.stringify(args, null, 2)}`
328
- );
329
- let toolArgs = args;
330
- if (typeof args === "string") {
331
- try {
332
- toolArgs = JSON.parse(args);
333
- } catch {
334
- toolArgs = { input: args };
335
- }
336
- }
337
- this.logger.debug(`Using timeout: ${this.timeout}`);
338
- const result = await this.client.callTool(
339
- { name, arguments: toolArgs },
340
- void 0,
341
- // resultSchema (optional)
342
- { timeout: this.timeout }
343
- // Use server-specific timeout, default 1 minute
344
- );
345
- const logResult = JSON.stringify(
346
- result,
347
- (key, value) => {
348
- if (key === "data" && typeof value === "string" && value.length > 100) {
349
- return `[Base64 data: ${value.length} chars]`;
326
+ return await recordOperationSpan(
327
+ {
328
+ attributes: {
329
+ "tool.name": name,
330
+ "tool.server": this.serverAlias || "unknown",
331
+ "tool.timeout": this.timeout
332
+ },
333
+ captureErrors: false,
334
+ componentName: "DextoMcpClient",
335
+ name: `mcp.tool.${name}`,
336
+ spanKind: SpanKind.CLIENT
337
+ },
338
+ async () => {
339
+ this.logger.debug(`Calling tool '${name}'`);
340
+ let toolArgs = args;
341
+ if (typeof args === "string") {
342
+ try {
343
+ toolArgs = JSON.parse(args);
344
+ } catch {
345
+ toolArgs = { input: args };
346
+ }
347
+ }
348
+ this.logger.debug(`Using timeout: ${this.timeout}`);
349
+ const result = await this.client.callTool(
350
+ { name, arguments: toolArgs },
351
+ void 0,
352
+ { timeout: this.timeout }
353
+ );
354
+ if (result.isError === true) {
355
+ throw new Error(mcpToolFailureMessage(name, result));
350
356
  }
351
- return value;
357
+ this.logger.debug(`Tool '${name}' completed`);
358
+ return result ?? "Tool executed successfully with no result data.";
352
359
  },
353
- 2
360
+ this.logger
354
361
  );
355
- this.logger.debug(`Tool '${name}' result: ${logResult}`);
356
- if (span) {
357
- span.setAttribute("tool.result", safeStringify(result, 4096));
358
- span.setStatus({ code: SpanStatusCode.OK });
359
- }
360
- if (result === null || result === void 0) {
361
- return "Tool executed successfully with no result data.";
362
- }
363
- return result;
364
362
  } catch (error) {
365
- this.logger.error(`Tool call '${name}' failed: ${JSON.stringify(error, null, 2)}`);
366
- if (span) {
367
- span.recordException(error);
368
- span.setStatus({
369
- code: SpanStatusCode.ERROR,
370
- message: error instanceof Error ? error.message : String(error)
371
- });
372
- }
373
- return `Error executing tool '${name}': ${error instanceof Error ? error.message : String(error)}`;
374
- } finally {
375
- span?.end();
363
+ this.logger.error(`Tool call '${name}' failed`);
364
+ throw error;
376
365
  }
377
366
  });
378
367
  }
@@ -397,7 +386,9 @@ class DextoMcpClient extends EventEmitter {
397
386
  tools[tool.name] = {
398
387
  description: tool.description ?? "",
399
388
  parameters: tool.inputSchema,
400
- _meta: tool._meta
389
+ ...tool.outputSchema !== void 0 ? { outputSchema: tool.outputSchema } : {},
390
+ ...tool.annotations !== void 0 ? { annotations: tool.annotations } : {},
391
+ ...tool._meta !== void 0 ? { _meta: tool._meta } : {}
401
392
  };
402
393
  });
403
394
  } else {
@@ -29,14 +29,15 @@ __export(types_exports, {
29
29
  splitToolExecutionResult: () => splitToolExecutionResult
30
30
  });
31
31
  module.exports = __toCommonJS(types_exports);
32
- var import_crypto = require("crypto");
33
32
  var import_zod = require("zod");
34
33
  var import_display_types = require("../../tools/display-types.js");
35
34
  var import_presentation_schema = require("../../tools/presentation-schema.js");
35
+ var import_stable_fingerprint = require("../../utils/stable-fingerprint.js");
36
36
  const ToolExecutionIdentitySchema = import_zod.z.object({
37
37
  runId: import_zod.z.string().min(1),
38
38
  turnId: import_zod.z.string().min(1),
39
39
  modelStepId: import_zod.z.string().min(1),
40
+ parentToolCallId: import_zod.z.string().min(1).optional(),
40
41
  toolCallId: import_zod.z.string().min(1)
41
42
  }).strict();
42
43
  const ToolExecutionResultMetadataSchema = import_zod.z.object({
@@ -86,13 +87,16 @@ const ToolExecutionRecordSchema = import_zod.z.discriminatedUnion("status", [
86
87
  ToolExecutionCancelledRecordSchema
87
88
  ]);
88
89
  function createToolExecutionId(identity) {
89
- const key = JSON.stringify([
90
- identity.runId,
91
- identity.turnId,
92
- identity.modelStepId,
93
- identity.toolCallId
94
- ]);
95
- return `tool-exec-${(0, import_crypto.createHash)("sha256").update(key).digest("hex")}`;
90
+ const key = JSON.stringify(
91
+ identity.parentToolCallId === void 0 ? [identity.runId, identity.turnId, identity.modelStepId, identity.toolCallId] : [
92
+ identity.runId,
93
+ identity.turnId,
94
+ identity.modelStepId,
95
+ identity.parentToolCallId,
96
+ identity.toolCallId
97
+ ]
98
+ );
99
+ return `tool-exec-${(0, import_stable_fingerprint.stableFingerprint)(key)}`;
96
100
  }
97
101
  function splitToolExecutionResult(result) {
98
102
  const resultMetadata = {};
@@ -6,6 +6,7 @@ export declare const ToolExecutionIdentitySchema: z.ZodObject<{
6
6
  runId: z.ZodString;
7
7
  turnId: z.ZodString;
8
8
  modelStepId: z.ZodString;
9
+ parentToolCallId: z.ZodOptional<z.ZodString>;
9
10
  toolCallId: z.ZodString;
10
11
  }, z.core.$strict>;
11
12
  export declare const ToolExecutionRunningRecordSchema: z.ZodObject<{
@@ -14,6 +15,7 @@ export declare const ToolExecutionRunningRecordSchema: z.ZodObject<{
14
15
  runId: z.ZodString;
15
16
  turnId: z.ZodString;
16
17
  modelStepId: z.ZodString;
18
+ parentToolCallId: z.ZodOptional<z.ZodString>;
17
19
  toolCallId: z.ZodString;
18
20
  }, z.core.$strict>;
19
21
  input: z.ZodRecord<z.ZodString, z.ZodUnknown>;
@@ -28,6 +30,7 @@ export declare const ToolExecutionCompletedRecordSchema: z.ZodObject<{
28
30
  runId: z.ZodString;
29
31
  turnId: z.ZodString;
30
32
  modelStepId: z.ZodString;
33
+ parentToolCallId: z.ZodOptional<z.ZodString>;
31
34
  toolCallId: z.ZodString;
32
35
  }, z.core.$strict>;
33
36
  input: z.ZodRecord<z.ZodString, z.ZodUnknown>;
@@ -186,6 +189,7 @@ export declare const ToolExecutionFailedRecordSchema: z.ZodObject<{
186
189
  runId: z.ZodString;
187
190
  turnId: z.ZodString;
188
191
  modelStepId: z.ZodString;
192
+ parentToolCallId: z.ZodOptional<z.ZodString>;
189
193
  toolCallId: z.ZodString;
190
194
  }, z.core.$strict>;
191
195
  input: z.ZodRecord<z.ZodString, z.ZodUnknown>;
@@ -202,6 +206,7 @@ export declare const ToolExecutionCancelledRecordSchema: z.ZodObject<{
202
206
  runId: z.ZodString;
203
207
  turnId: z.ZodString;
204
208
  modelStepId: z.ZodString;
209
+ parentToolCallId: z.ZodOptional<z.ZodString>;
205
210
  toolCallId: z.ZodString;
206
211
  }, z.core.$strict>;
207
212
  input: z.ZodRecord<z.ZodString, z.ZodUnknown>;
@@ -218,6 +223,7 @@ export declare const ToolExecutionRecordSchema: z.ZodDiscriminatedUnion<[z.ZodOb
218
223
  runId: z.ZodString;
219
224
  turnId: z.ZodString;
220
225
  modelStepId: z.ZodString;
226
+ parentToolCallId: z.ZodOptional<z.ZodString>;
221
227
  toolCallId: z.ZodString;
222
228
  }, z.core.$strict>;
223
229
  input: z.ZodRecord<z.ZodString, z.ZodUnknown>;
@@ -231,6 +237,7 @@ export declare const ToolExecutionRecordSchema: z.ZodDiscriminatedUnion<[z.ZodOb
231
237
  runId: z.ZodString;
232
238
  turnId: z.ZodString;
233
239
  modelStepId: z.ZodString;
240
+ parentToolCallId: z.ZodOptional<z.ZodString>;
234
241
  toolCallId: z.ZodString;
235
242
  }, z.core.$strict>;
236
243
  input: z.ZodRecord<z.ZodString, z.ZodUnknown>;
@@ -388,6 +395,7 @@ export declare const ToolExecutionRecordSchema: z.ZodDiscriminatedUnion<[z.ZodOb
388
395
  runId: z.ZodString;
389
396
  turnId: z.ZodString;
390
397
  modelStepId: z.ZodString;
398
+ parentToolCallId: z.ZodOptional<z.ZodString>;
391
399
  toolCallId: z.ZodString;
392
400
  }, z.core.$strict>;
393
401
  input: z.ZodRecord<z.ZodString, z.ZodUnknown>;
@@ -403,6 +411,7 @@ export declare const ToolExecutionRecordSchema: z.ZodDiscriminatedUnion<[z.ZodOb
403
411
  runId: z.ZodString;
404
412
  turnId: z.ZodString;
405
413
  modelStepId: z.ZodString;
414
+ parentToolCallId: z.ZodOptional<z.ZodString>;
406
415
  toolCallId: z.ZodString;
407
416
  }, z.core.$strict>;
408
417
  input: z.ZodRecord<z.ZodString, z.ZodUnknown>;
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/storage/tool-executions/types.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAAE,mBAAmB,EAA8B,MAAM,sBAAsB,CAAC;AAC5F,OAAO,EAAsB,KAAK,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAExF,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAC;AAE1E,eAAO,MAAM,2BAA2B;;;;;kBAO3B,CAAC;AA+Bd,eAAO,MAAM,gCAAgC;;;;;;;;;;;;;kBAElC,CAAC;AAEZ,eAAO,MAAM,kCAAkC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;kBAKpC,CAAC;AAEZ,eAAO,MAAM,+BAA+B;;;;;;;;;;;;;;;kBAIjC,CAAC;AAEZ,eAAO,MAAM,kCAAkC;;;;;;;;;;;;;;;kBAIpC,CAAC;AAEZ,eAAO,MAAM,yBAAyB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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
3
  import { isValidDisplayData } from "../../tools/display-types.js";
5
4
  import { ToolPresentationSnapshotV1Schema } from "../../tools/presentation-schema.js";
5
+ import { stableFingerprint } from "../../utils/stable-fingerprint.js";
6
6
  const ToolExecutionIdentitySchema = z.object({
7
7
  runId: z.string().min(1),
8
8
  turnId: z.string().min(1),
9
9
  modelStepId: z.string().min(1),
10
+ parentToolCallId: z.string().min(1).optional(),
10
11
  toolCallId: z.string().min(1)
11
12
  }).strict();
12
13
  const ToolExecutionResultMetadataSchema = z.object({
@@ -56,13 +57,16 @@ const ToolExecutionRecordSchema = z.discriminatedUnion("status", [
56
57
  ToolExecutionCancelledRecordSchema
57
58
  ]);
58
59
  function createToolExecutionId(identity) {
59
- const key = JSON.stringify([
60
- identity.runId,
61
- identity.turnId,
62
- identity.modelStepId,
63
- identity.toolCallId
64
- ]);
65
- return `tool-exec-${createHash("sha256").update(key).digest("hex")}`;
60
+ const key = JSON.stringify(
61
+ identity.parentToolCallId === void 0 ? [identity.runId, identity.turnId, identity.modelStepId, identity.toolCallId] : [
62
+ identity.runId,
63
+ identity.turnId,
64
+ identity.modelStepId,
65
+ identity.parentToolCallId,
66
+ identity.toolCallId
67
+ ]
68
+ );
69
+ return `tool-exec-${stableFingerprint(key)}`;
66
70
  }
67
71
  function splitToolExecutionResult(result) {
68
72
  const resultMetadata = {};
@@ -27,6 +27,9 @@ var import_utils = require("./utils.js");
27
27
  var import_safe_stringify = require("../utils/safe-stringify.js");
28
28
  var import_runtime = require("../runtime/index.js");
29
29
  function withSpan(options) {
30
+ const captureArguments = options.captureArguments ?? true;
31
+ const captureErrors = options.captureErrors ?? true;
32
+ const captureResult = options.captureResult ?? true;
30
33
  return function(_target, propertyKey, descriptor) {
31
34
  if (!descriptor || typeof descriptor === "number") return;
32
35
  const originalMethod = descriptor.value;
@@ -63,9 +66,14 @@ function withSpan(options) {
63
66
  const effectiveHostRuntime = hostRuntime;
64
67
  const effectiveRunId = effectiveHostRuntime?.ids?.runId ?? runId;
65
68
  const applySpanAttributes = (span) => {
66
- args.forEach((arg, index) => {
67
- span.setAttribute(`${spanName}.argument.${index}`, (0, import_safe_stringify.safeStringify)(arg, 8192));
68
- });
69
+ if (captureArguments) {
70
+ args.forEach((arg, index) => {
71
+ span.setAttribute(
72
+ `${spanName}.argument.${index}`,
73
+ (0, import_safe_stringify.safeStringify)(arg, 8192)
74
+ );
75
+ });
76
+ }
69
77
  if (sessionId) {
70
78
  span.setAttribute("sessionId", sessionId);
71
79
  span.setAttribute("baggage.sessionId", sessionId);
@@ -159,36 +167,49 @@ function withSpan(options) {
159
167
  result = originalMethod.apply(this, args);
160
168
  if (result instanceof Promise) {
161
169
  return result.then((resolvedValue) => {
162
- span.setAttribute(
163
- `${spanName}.result`,
164
- (0, import_safe_stringify.safeStringify)(resolvedValue, 8192)
165
- );
170
+ if (captureResult) {
171
+ span.setAttribute(
172
+ `${spanName}.result`,
173
+ (0, import_safe_stringify.safeStringify)(resolvedValue, 8192)
174
+ );
175
+ }
166
176
  return resolvedValue;
167
177
  }).catch((error) => {
168
- span.recordException(error);
169
- span.setStatus({
170
- code: import_api.SpanStatusCode.ERROR,
171
- message: error?.toString()
172
- });
178
+ if (captureErrors) {
179
+ span.recordException(error);
180
+ span.setStatus({
181
+ code: import_api.SpanStatusCode.ERROR,
182
+ message: error?.toString()
183
+ });
184
+ } else {
185
+ span.setStatus({ code: import_api.SpanStatusCode.ERROR });
186
+ }
173
187
  throw error;
174
188
  }).finally(() => {
175
189
  span.end();
176
190
  });
177
191
  }
178
- span.setAttribute(`${spanName}.result`, (0, import_safe_stringify.safeStringify)(result, 8192));
192
+ if (captureResult) {
193
+ span.setAttribute(`${spanName}.result`, (0, import_safe_stringify.safeStringify)(result, 8192));
194
+ }
179
195
  return result;
180
196
  } catch (error) {
181
197
  const logger2 = this?.logger;
182
- logger2?.error(
183
- `withSpan: Error in method '${methodName}': ${error instanceof Error ? error.message : String(error)}`,
184
- { error }
185
- );
186
- span.setStatus({
187
- code: import_api.SpanStatusCode.ERROR,
188
- message: error instanceof Error ? error.message : "Unknown error"
189
- });
190
- if (error instanceof Error) {
191
- span.recordException(error);
198
+ if (captureErrors) {
199
+ logger2?.error(
200
+ `withSpan: Error in method '${methodName}': ${error instanceof Error ? error.message : String(error)}`,
201
+ { error }
202
+ );
203
+ span.setStatus({
204
+ code: import_api.SpanStatusCode.ERROR,
205
+ message: error instanceof Error ? error.message : "Unknown error"
206
+ });
207
+ if (error instanceof Error) {
208
+ span.recordException(error);
209
+ }
210
+ } else {
211
+ logger2?.error(`withSpan: Error in method '${methodName}'`);
212
+ span.setStatus({ code: import_api.SpanStatusCode.ERROR });
192
213
  }
193
214
  throw error;
194
215
  } finally {
@@ -215,6 +236,9 @@ function InstrumentClass(options) {
215
236
  target.prototype,
216
237
  method,
217
238
  withSpan({
239
+ captureArguments: options?.captureArguments ?? true,
240
+ captureErrors: options?.captureErrors ?? true,
241
+ captureResult: options?.captureResult ?? true,
218
242
  spanName: options?.prefix ? `${options.prefix}.${method}` : method,
219
243
  skipIfNoTelemetry: true,
220
244
  spanKind: options?.spanKind || import_api.SpanKind.INTERNAL,
@@ -1,5 +1,8 @@
1
1
  import { SpanKind } from '@opentelemetry/api';
2
2
  export declare function withSpan(options: {
3
+ captureArguments?: boolean;
4
+ captureErrors?: boolean;
5
+ captureResult?: boolean;
3
6
  spanName?: string;
4
7
  componentName?: string;
5
8
  skipIfNoTelemetry?: boolean;
@@ -7,6 +10,9 @@ export declare function withSpan(options: {
7
10
  tracerName?: string;
8
11
  }): any;
9
12
  export declare function InstrumentClass(options?: {
13
+ captureArguments?: boolean;
14
+ captureErrors?: boolean;
15
+ captureResult?: boolean;
10
16
  prefix?: string;
11
17
  componentName?: string;
12
18
  spanKind?: SpanKind;
@@ -1 +1 @@
1
- {"version":3,"file":"decorators.d.ts","sourceRoot":"","sources":["../../src/telemetry/decorators.ts"],"names":[],"mappings":"AAAA,OAAO,EAIH,QAAQ,EAKX,MAAM,oBAAoB,CAAC;AAO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