@dexto/core 1.12.1 → 1.13.1

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 (152) hide show
  1. package/dist/agent/DextoAgent.cjs +7 -0
  2. package/dist/agent/DextoAgent.d.ts +2 -5
  3. package/dist/agent/DextoAgent.d.ts.map +1 -1
  4. package/dist/agent/DextoAgent.js +7 -0
  5. package/dist/approval/index.cjs +4 -2
  6. package/dist/approval/index.d.ts +1 -1
  7. package/dist/approval/index.d.ts.map +1 -1
  8. package/dist/approval/index.js +3 -2
  9. package/dist/approval/manager.cjs +23 -4
  10. package/dist/approval/manager.d.ts +3 -2
  11. package/dist/approval/manager.d.ts.map +1 -1
  12. package/dist/approval/manager.js +21 -3
  13. package/dist/approval/schemas.cjs +5 -0
  14. package/dist/approval/schemas.d.ts +8 -0
  15. package/dist/approval/schemas.d.ts.map +1 -1
  16. package/dist/approval/schemas.js +5 -0
  17. package/dist/approval/types.d.ts +2 -2
  18. package/dist/approval/types.d.ts.map +1 -1
  19. package/dist/context/manager.cjs +34 -31
  20. package/dist/context/manager.d.ts +5 -6
  21. package/dist/context/manager.d.ts.map +1 -1
  22. package/dist/context/manager.js +36 -32
  23. package/dist/context/utils.cjs +6 -17
  24. package/dist/context/utils.d.ts +2 -0
  25. package/dist/context/utils.d.ts.map +1 -1
  26. package/dist/context/utils.js +5 -17
  27. package/dist/events/index.cjs +8 -0
  28. package/dist/events/index.d.ts +18 -5
  29. package/dist/events/index.d.ts.map +1 -1
  30. package/dist/events/index.js +8 -0
  31. package/dist/llm/executor/repeated-pruned-tool-calls.cjs +69 -0
  32. package/dist/llm/executor/repeated-pruned-tool-calls.d.ts +17 -0
  33. package/dist/llm/executor/repeated-pruned-tool-calls.d.ts.map +1 -0
  34. package/dist/llm/executor/repeated-pruned-tool-calls.js +46 -0
  35. package/dist/llm/executor/tool-output-spill.cjs +92 -0
  36. package/dist/llm/executor/tool-output-spill.d.ts +24 -0
  37. package/dist/llm/executor/tool-output-spill.d.ts.map +1 -0
  38. package/dist/llm/executor/tool-output-spill.js +65 -0
  39. package/dist/llm/executor/turn-executor.cjs +116 -35
  40. package/dist/llm/executor/turn-executor.d.ts +21 -5
  41. package/dist/llm/executor/turn-executor.d.ts.map +1 -1
  42. package/dist/llm/executor/turn-executor.js +122 -35
  43. package/dist/llm/services/factory.cjs +2 -1
  44. package/dist/llm/services/factory.d.ts +2 -1
  45. package/dist/llm/services/factory.d.ts.map +1 -1
  46. package/dist/llm/services/factory.js +2 -1
  47. package/dist/llm/services/vercel.cjs +2 -1
  48. package/dist/llm/services/vercel.d.ts +2 -1
  49. package/dist/llm/services/vercel.d.ts.map +1 -1
  50. package/dist/llm/services/vercel.js +2 -1
  51. package/dist/mcp/errors.cjs +9 -0
  52. package/dist/mcp/errors.d.ts +4 -0
  53. package/dist/mcp/errors.d.ts.map +1 -1
  54. package/dist/mcp/errors.js +9 -0
  55. package/dist/mcp/manager.cjs +79 -3
  56. package/dist/mcp/manager.d.ts +14 -7
  57. package/dist/mcp/manager.d.ts.map +1 -1
  58. package/dist/mcp/manager.js +79 -3
  59. package/dist/mcp/mcp-client.cjs +52 -62
  60. package/dist/mcp/mcp-client.d.ts.map +1 -1
  61. package/dist/mcp/mcp-client.js +54 -63
  62. package/dist/session/chat-session.cjs +1 -0
  63. package/dist/session/chat-session.d.ts +2 -0
  64. package/dist/session/chat-session.d.ts.map +1 -1
  65. package/dist/session/chat-session.js +1 -0
  66. package/dist/session/session-manager.cjs +16 -2
  67. package/dist/session/session-manager.d.ts +2 -0
  68. package/dist/session/session-manager.d.ts.map +1 -1
  69. package/dist/session/session-manager.js +16 -2
  70. package/dist/storage/index.cjs +2 -0
  71. package/dist/storage/index.d.ts +2 -1
  72. package/dist/storage/index.d.ts.map +1 -1
  73. package/dist/storage/index.js +2 -0
  74. package/dist/storage/stores/backend.cjs +26 -0
  75. package/dist/storage/stores/backend.d.ts +20 -0
  76. package/dist/storage/stores/backend.d.ts.map +1 -1
  77. package/dist/storage/stores/backend.js +25 -0
  78. package/dist/storage/stores/in-memory.cjs +20 -3
  79. package/dist/storage/stores/in-memory.d.ts +16 -0
  80. package/dist/storage/stores/in-memory.d.ts.map +1 -1
  81. package/dist/storage/stores/in-memory.js +18 -2
  82. package/dist/storage/stores/types.d.ts +3 -0
  83. package/dist/storage/stores/types.d.ts.map +1 -1
  84. package/dist/storage/tool-executions/types.cjs +12 -8
  85. package/dist/storage/tool-executions/types.d.ts +11 -2
  86. package/dist/storage/tool-executions/types.d.ts.map +1 -1
  87. package/dist/storage/tool-executions/types.js +12 -8
  88. package/dist/storage/tool-outputs/types.cjs +16 -0
  89. package/dist/storage/tool-outputs/types.d.ts +19 -0
  90. package/dist/storage/tool-outputs/types.d.ts.map +1 -0
  91. package/dist/storage/tool-outputs/types.js +0 -0
  92. package/dist/telemetry/decorators.cjs +47 -23
  93. package/dist/telemetry/decorators.d.ts +6 -0
  94. package/dist/telemetry/decorators.d.ts.map +1 -1
  95. package/dist/telemetry/decorators.js +47 -23
  96. package/dist/telemetry/operation-span.cjs +5 -2
  97. package/dist/telemetry/operation-span.d.ts +3 -0
  98. package/dist/telemetry/operation-span.d.ts.map +1 -1
  99. package/dist/telemetry/operation-span.js +5 -2
  100. package/dist/tools/activity.cjs +8 -0
  101. package/dist/tools/activity.d.ts +1 -0
  102. package/dist/tools/activity.d.ts.map +1 -1
  103. package/dist/tools/activity.js +8 -0
  104. package/dist/tools/approval/tool-approval-policy.cjs +11 -1
  105. package/dist/tools/approval/tool-approval-policy.d.ts +2 -2
  106. package/dist/tools/approval/tool-approval-policy.d.ts.map +1 -1
  107. package/dist/tools/approval/tool-approval-policy.js +11 -1
  108. package/dist/tools/identity.cjs +36 -0
  109. package/dist/tools/identity.d.ts +6 -0
  110. package/dist/tools/identity.d.ts.map +1 -0
  111. package/dist/tools/identity.js +13 -0
  112. package/dist/tools/index.cjs +2 -0
  113. package/dist/tools/index.d.ts +2 -1
  114. package/dist/tools/index.d.ts.map +1 -1
  115. package/dist/tools/index.js +4 -1
  116. package/dist/tools/presentation/tool-presentation.d.ts +5 -0
  117. package/dist/tools/presentation/tool-presentation.d.ts.map +1 -1
  118. package/dist/tools/schema-fingerprint.cjs +48 -0
  119. package/dist/tools/schema-fingerprint.d.ts +4 -0
  120. package/dist/tools/schema-fingerprint.d.ts.map +1 -0
  121. package/dist/tools/schema-fingerprint.js +25 -0
  122. package/dist/tools/schemas.cjs +3 -0
  123. package/dist/tools/schemas.d.ts +1 -0
  124. package/dist/tools/schemas.d.ts.map +1 -1
  125. package/dist/tools/schemas.js +2 -0
  126. package/dist/tools/tool-manager.cjs +199 -48
  127. package/dist/tools/tool-manager.d.ts +25 -11
  128. package/dist/tools/tool-manager.d.ts.map +1 -1
  129. package/dist/tools/tool-manager.js +199 -48
  130. package/dist/tools/tool-output-read.cjs +129 -0
  131. package/dist/tools/tool-output-read.d.ts +19 -0
  132. package/dist/tools/tool-output-read.d.ts.map +1 -0
  133. package/dist/tools/tool-output-read.js +106 -0
  134. package/dist/tools/types.d.ts +55 -0
  135. package/dist/tools/types.d.ts.map +1 -1
  136. package/dist/utils/schema.cjs +2 -2
  137. package/dist/utils/schema.d.ts +1 -1
  138. package/dist/utils/schema.d.ts.map +1 -1
  139. package/dist/utils/schema.js +2 -2
  140. package/dist/utils/service-initializer.cjs +4 -0
  141. package/dist/utils/service-initializer.d.ts +2 -0
  142. package/dist/utils/service-initializer.d.ts.map +1 -1
  143. package/dist/utils/service-initializer.js +4 -0
  144. package/dist/utils/stable-fingerprint.cjs +32 -0
  145. package/dist/utils/stable-fingerprint.d.ts +3 -0
  146. package/dist/utils/stable-fingerprint.d.ts.map +1 -0
  147. package/dist/utils/stable-fingerprint.js +9 -0
  148. package/package.json +9 -2
  149. package/dist/llm/executor/tool-output-truncator.cjs +0 -75
  150. package/dist/llm/executor/tool-output-truncator.d.ts +0 -27
  151. package/dist/llm/executor/tool-output-truncator.d.ts.map +0 -1
  152. package/dist/llm/executor/tool-output-truncator.js +0 -48
@@ -10,7 +10,14 @@ import { z } from "zod";
10
10
  import { trace } from "@opentelemetry/api";
11
11
  import { sanitizeToolResult } from "../../context/utils.js";
12
12
  import { StreamProcessor } from "./stream-processor.js";
13
- import { truncateToolResult } from "./tool-output-truncator.js";
13
+ import {
14
+ planToolOutputSpills,
15
+ toolOutputBudget,
16
+ toolResultText,
17
+ TOOL_OUTPUT_READ_TOOL_NAME,
18
+ withToolOutputPreview
19
+ } from "./tool-output-spill.js";
20
+ import { findRepeatedPrunedToolCalls } from "./repeated-pruned-tool-calls.js";
14
21
  import { buildProviderOptions, getEffectiveReasoningBudgetTokens } from "./provider-options.js";
15
22
  import { DextoLogComponent } from "../../logger/v2/types.js";
16
23
  import { recordOperationSpan } from "../../telemetry/operation-span.js";
@@ -25,7 +32,7 @@ import {
25
32
  createModelRequestDiagnostics,
26
33
  modelRequestDiagnosticAttributes
27
34
  } from "./model-request-diagnostics.js";
28
- import { ApprovalStatus } from "../../approval/types.js";
35
+ import { approvalResponseToDecisionInput } from "../../approval/manager.js";
29
36
  import {
30
37
  describeContentPartsForAudit,
31
38
  describeInternalMessageTailForAudit
@@ -81,15 +88,26 @@ const ProviderOptionsStateSchema = z.record(
81
88
  const JsonSchemaStateSchema = z.custom(
82
89
  (value) => typeof value === "object" && value !== null && !Array.isArray(value)
83
90
  );
91
+ const ToolAnnotationsStateSchema = z.object({
92
+ title: z.string().optional(),
93
+ readOnlyHint: z.boolean().optional(),
94
+ destructiveHint: z.boolean().optional(),
95
+ idempotentHint: z.boolean().optional(),
96
+ openWorldHint: z.boolean().optional()
97
+ }).catchall(JsonValueSchema);
84
98
  const ToolSetEntryStateSchema = z.object({
85
99
  name: z.string().optional(),
86
100
  description: z.string().optional(),
87
101
  parameters: JsonSchemaStateSchema,
102
+ outputSchema: JsonSchemaStateSchema.optional(),
103
+ annotations: ToolAnnotationsStateSchema.optional(),
88
104
  _meta: z.record(z.string(), JsonValueSchema).optional()
89
105
  }).strict().transform((parsed) => {
90
106
  const tool = { parameters: parsed.parameters };
91
107
  if (parsed.name !== void 0) tool.name = parsed.name;
92
108
  if (parsed.description !== void 0) tool.description = parsed.description;
109
+ if (parsed.outputSchema !== void 0) tool.outputSchema = parsed.outputSchema;
110
+ if (parsed.annotations !== void 0) tool.annotations = parsed.annotations;
93
111
  if (parsed._meta !== void 0) tool._meta = parsed._meta;
94
112
  return tool;
95
113
  });
@@ -937,7 +955,10 @@ class TurnExecutor {
937
955
  await this.injectQueuedMessages(coalesced);
938
956
  }
939
957
  }
940
- await this.pruneOldToolOutputs();
958
+ const modelHistory = await this.contextManager.getModelHistory();
959
+ this.reportRepeatedPrunedToolCalls(modelHistory);
960
+ const { preparedHistory: visibleHistory } = await this.contextManager.prepareModelHistory();
961
+ await this.pruneOldToolOutputs(visibleHistory);
941
962
  let systemPrompt = await recordOperationSpan(
942
963
  {
943
964
  name: "system_prompt.build",
@@ -1344,10 +1365,21 @@ class TurnExecutor {
1344
1365
  )
1345
1366
  )
1346
1367
  );
1368
+ const sanitizedResults = await Promise.all(
1369
+ toolCalls.map((toolCall, index) => {
1370
+ const executionResult = executionResults[index];
1371
+ if (executionResult === void 0) {
1372
+ throw new Error("Tool call result count must match emitted tool call count");
1373
+ }
1374
+ return this.sanitizeModelToolResult(toolCall, executionResult);
1375
+ })
1376
+ );
1377
+ const modelResults = await this.storeOversizedToolOutputs(toolCalls, sanitizedResults);
1347
1378
  for (let index = 0; index < toolCalls.length; index += 1) {
1348
1379
  const toolCall = toolCalls[index];
1349
1380
  const executionResult = executionResults[index];
1350
- if (toolCall === void 0 || executionResult === void 0) {
1381
+ const modelResult = modelResults[index];
1382
+ if (toolCall === void 0 || executionResult === void 0 || modelResult === void 0) {
1351
1383
  throw new Error("Tool call result count must match emitted tool call count");
1352
1384
  }
1353
1385
  await recordOperationSpan(
@@ -1360,7 +1392,7 @@ class TurnExecutor {
1360
1392
  "tool.success": this.isToolExecutionSuccessful(executionResult)
1361
1393
  }
1362
1394
  },
1363
- () => this.persistModelToolResult(toolCall, executionResult),
1395
+ () => this.persistModelToolResult(toolCall, executionResult, modelResult),
1364
1396
  this.logger
1365
1397
  );
1366
1398
  }
@@ -1429,7 +1461,7 @@ class TurnExecutor {
1429
1461
  if (approval.kind === "terminal") {
1430
1462
  return approval.modelVisibleResult;
1431
1463
  }
1432
- const decision = this.toApprovalDecisionInput(approval.response);
1464
+ const decision = approvalResponseToDecisionInput(approval.response);
1433
1465
  const applied = await this.toolManager.applyApprovalDecision(recorded, decision);
1434
1466
  if (applied.kind === "terminal") {
1435
1467
  return applied.modelVisibleResult;
@@ -1544,9 +1576,9 @@ class TurnExecutor {
1544
1576
  }
1545
1577
  return preparedCall.prepared.modelVisibleResult.presentationSnapshot ?? this.buildToolCallFallbackSnapshot(preparedCall.toolCall.toolName);
1546
1578
  }
1547
- async persistModelToolResult(toolCall, executionResult) {
1579
+ async sanitizeModelToolResult(toolCall, executionResult) {
1548
1580
  const success = this.isToolExecutionSuccessful(executionResult);
1549
- const sanitized = await sanitizeToolResult(
1581
+ return await sanitizeToolResult(
1550
1582
  executionResult.result,
1551
1583
  {
1552
1584
  artifactStore: this.resourceManager.getArtifactStore(),
@@ -1558,7 +1590,47 @@ class TurnExecutor {
1558
1590
  },
1559
1591
  this.logger
1560
1592
  );
1561
- const truncated = truncateToolResult(sanitized);
1593
+ }
1594
+ /**
1595
+ * Keeps oversized tool output out of model history: the full text goes to the session's tool
1596
+ * output store and history keeps a head and tail preview that names `tool_output_read`. If
1597
+ * storing fails, the full text stays inline so nothing is lost.
1598
+ */
1599
+ async storeOversizedToolOutputs(toolCalls, results) {
1600
+ const texts = results.map(toolResultText);
1601
+ const previewChars = planToolOutputSpills(
1602
+ results.flatMap(
1603
+ (result, index) => (
1604
+ // A read of stored output is already bounded; storing it again could loop.
1605
+ toolCalls[index]?.toolName === TOOL_OUTPUT_READ_TOOL_NAME ? [] : [
1606
+ {
1607
+ toolCallId: result.meta.toolCallId,
1608
+ textLength: texts[index]?.length ?? 0
1609
+ }
1610
+ ]
1611
+ )
1612
+ ),
1613
+ toolOutputBudget(this.contextManager.getMaxInputTokens())
1614
+ );
1615
+ return await Promise.all(
1616
+ results.map(async (result, index) => {
1617
+ const chars = previewChars.get(result.meta.toolCallId);
1618
+ const text = texts[index];
1619
+ if (chars === void 0 || text === void 0) return result;
1620
+ try {
1621
+ await this.contextManager.saveToolOutput(result.meta.toolCallId, text);
1622
+ } catch (error) {
1623
+ this.logger.warn(
1624
+ `Failed to store tool output for ${result.meta.toolCallId}; keeping it inline: ${error instanceof Error ? error.message : String(error)}`
1625
+ );
1626
+ return result;
1627
+ }
1628
+ return withToolOutputPreview(result, text, chars);
1629
+ })
1630
+ );
1631
+ }
1632
+ async persistModelToolResult(toolCall, executionResult, truncated) {
1633
+ const success = this.isToolExecutionSuccessful(executionResult);
1562
1634
  const metadata = this.getToolExecutionMetadata(executionResult);
1563
1635
  const errorMessage = this.getToolExecutionErrorMessage(executionResult.result);
1564
1636
  await this.contextManager.addToolResult(
@@ -1619,24 +1691,6 @@ class TurnExecutor {
1619
1691
  toolCallId
1620
1692
  };
1621
1693
  }
1622
- toApprovalDecisionInput(response) {
1623
- if (response.status === ApprovalStatus.APPROVED) {
1624
- return {
1625
- approvalId: response.approvalId,
1626
- status: ApprovalStatus.APPROVED,
1627
- ...response.data !== void 0 ? { data: response.data } : {}
1628
- };
1629
- }
1630
- const status = response.status === ApprovalStatus.DENIED ? ApprovalStatus.DENIED : ApprovalStatus.CANCELLED;
1631
- return {
1632
- approvalId: response.approvalId,
1633
- status,
1634
- ...response.reason !== void 0 ? { reason: response.reason } : {},
1635
- ...response.message !== void 0 ? { message: response.message } : {},
1636
- ...response.timeoutMs !== void 0 ? { timeoutMs: response.timeoutMs } : {},
1637
- ...response.data !== void 0 ? { data: response.data } : {}
1638
- };
1639
- }
1640
1694
  getToolExecutionMetadata(executionResult) {
1641
1695
  const metadata = {};
1642
1696
  if (executionResult.presentationSnapshot !== void 0) {
@@ -1678,12 +1732,42 @@ class TurnExecutor {
1678
1732
  };
1679
1733
  }
1680
1734
  /**
1681
- * Constants for pruning thresholds
1735
+ * Constants for pruning thresholds. The protected budget scales with the model's input
1736
+ * window so large-window models keep more recent tool output visible.
1682
1737
  */
1683
- static PRUNE_PROTECT = 4e4;
1684
- // Keep last 40K tokens of tool outputs
1738
+ static PRUNE_PROTECT_MIN = 4e4;
1739
+ // Always keep at least 40K tokens of tool outputs
1740
+ static PRUNE_PROTECT_WINDOW_RATIO = 0.3;
1741
+ // Or 30% of the input window, if larger
1685
1742
  static PRUNE_MINIMUM = 2e4;
1686
1743
  // Only prune if we can save 20K+
1744
+ getPruneProtectTokens() {
1745
+ return Math.max(
1746
+ TurnExecutor.PRUNE_PROTECT_MIN,
1747
+ Math.floor(
1748
+ this.contextManager.getMaxInputTokens() * TurnExecutor.PRUNE_PROTECT_WINDOW_RATIO
1749
+ )
1750
+ );
1751
+ }
1752
+ /**
1753
+ * Emits `context:pruned-tool-call-repeated` for each call in the latest assistant message that
1754
+ * repeats a call whose result was already pruned. This is a no-progress signal for hosts;
1755
+ * the executor never stops the run because of it.
1756
+ */
1757
+ reportRepeatedPrunedToolCalls(history) {
1758
+ for (const repeat of findRepeatedPrunedToolCalls(history)) {
1759
+ this.logger.warn(
1760
+ `Model repeated ${repeat.toolName} after its earlier result was pruned (${repeat.repeatCount}x)`
1761
+ );
1762
+ try {
1763
+ this.eventBus.emit("context:pruned-tool-call-repeated", repeat);
1764
+ } catch (error) {
1765
+ this.logger.warn(
1766
+ `A context:pruned-tool-call-repeated listener failed: ${error instanceof Error ? error.message : String(error)}`
1767
+ );
1768
+ }
1769
+ }
1770
+ }
1687
1771
  /**
1688
1772
  * Prunes old tool outputs by marking them with compactedAt timestamp.
1689
1773
  * Does NOT modify content - transformation happens at format time in
@@ -1693,24 +1777,27 @@ class TurnExecutor {
1693
1777
  * 1. Go backwards through history (most recent first)
1694
1778
  * 2. Stop at summary message (only process post-summary messages)
1695
1779
  * 3. Count tool message tokens
1696
- * 4. If total exceeds PRUNE_PROTECT, mark older ones for pruning
1697
- * 5. Only prune if savings exceed PRUNE_MINIMUM
1780
+ * 4. If total exceeds the protected budget, mark older ones for pruning
1781
+ * 5. Never prune results the model has not seen yet
1782
+ * 6. Only prune if savings exceed PRUNE_MINIMUM
1698
1783
  */
1699
- async pruneOldToolOutputs() {
1700
- const history = await this.contextManager.getModelHistory();
1784
+ async pruneOldToolOutputs(history) {
1785
+ const protectTokens = this.getPruneProtectTokens();
1701
1786
  let totalToolTokens = 0;
1702
1787
  let prunedTokens = 0;
1703
1788
  const toPrune = [];
1789
+ let seenByModel = false;
1704
1790
  for (let i = history.length - 1; i >= 0; i--) {
1705
1791
  const msg = history[i];
1706
1792
  if (!msg) continue;
1707
1793
  if (msg.metadata?.isSummary === true) break;
1794
+ if (msg.role === "assistant") seenByModel = true;
1708
1795
  if (msg.role !== "tool") continue;
1709
1796
  if (msg.compactedAt) continue;
1710
1797
  if (!Array.isArray(msg.content)) continue;
1711
1798
  const tokens = this.estimateToolTokens(msg.content);
1712
1799
  totalToolTokens += tokens;
1713
- if (totalToolTokens > TurnExecutor.PRUNE_PROTECT && msg.id) {
1800
+ if (seenByModel && totalToolTokens > protectTokens && msg.id) {
1714
1801
  prunedTokens += tokens;
1715
1802
  toPrune.push(msg.id);
1716
1803
  }
@@ -354,7 +354,7 @@ async function createVercelModel(llmConfig, context) {
354
354
  throw import_errors.LLMError.unsupportedProvider(provider);
355
355
  }
356
356
  }
357
- async function createLLMService(config, toolManager, systemPromptManager, conversationStore, sessionEventBus, sessionId, resourceManager, logger, options, languageModelFactory) {
357
+ async function createLLMService(config, toolManager, systemPromptManager, conversationStore, toolOutputStore, sessionEventBus, sessionId, resourceManager, logger, options, languageModelFactory) {
358
358
  const { usageScopeId, compactionStrategy, executionControl, steerQueue, followUpQueue } = options;
359
359
  const providerContext = {
360
360
  sessionId,
@@ -380,6 +380,7 @@ async function createLLMService(config, toolManager, systemPromptManager, conver
380
380
  model,
381
381
  systemPromptManager,
382
382
  conversationStore,
383
+ toolOutputStore,
383
384
  sessionEventBus,
384
385
  config,
385
386
  sessionId,
@@ -1,3 +1,4 @@
1
+ import type { ToolOutputStore } from '../../storage/tool-outputs/types.js';
1
2
  import { ToolManager } from '../../tools/tool-manager.js';
2
3
  import { ValidatedLLMConfig } from '../schemas.js';
3
4
  import { VercelLLMService } from './vercel.js';
@@ -33,5 +34,5 @@ export declare function createVercelModel(llmConfig: ValidatedLLMConfig, context
33
34
  * @param options Session-scoped runtime options
34
35
  * @returns Promise resolving to a VercelLLMService instance
35
36
  */
36
- export declare function createLLMService(config: ValidatedLLMConfig, toolManager: ToolManager, systemPromptManager: SystemPromptManager, conversationStore: ConversationStore, sessionEventBus: SessionEventBus, sessionId: string, resourceManager: import('../../resources/index.js').ResourceManager, logger: Logger, options: CreateLLMServiceOptions, languageModelFactory?: LanguageModelFactory): Promise<VercelLLMService>;
37
+ export declare function createLLMService(config: ValidatedLLMConfig, toolManager: ToolManager, systemPromptManager: SystemPromptManager, conversationStore: ConversationStore, toolOutputStore: ToolOutputStore, sessionEventBus: SessionEventBus, sessionId: string, resourceManager: import('../../resources/index.js').ResourceManager, logger: Logger, options: CreateLLMServiceOptions, languageModelFactory?: LanguageModelFactory): Promise<VercelLLMService>;
37
38
  //# sourceMappingURL=factory.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../../../src/llm/services/factory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAC1D,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAEnD,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,IAAI,CAAC;AACxC,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,qCAA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+BAA+B,CAAC;AACzE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,KAAK,EACR,uBAAuB,EACvB,oBAAoB,EACpB,oBAAoB,EACvB,MAAM,YAAY,CAAC;AAoHpB;;;;;;;;;GASG;AACH,wBAAsB,iBAAiB,CACnC,SAAS,EAAE,kBAAkB,EAC7B,OAAO,CAAC,EAAE,oBAAoB,GAC/B,OAAO,CAAC,aAAa,CAAC,CAyUxB;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAsB,gBAAgB,CAClC,MAAM,EAAE,kBAAkB,EAC1B,WAAW,EAAE,WAAW,EACxB,mBAAmB,EAAE,mBAAmB,EACxC,iBAAiB,EAAE,iBAAiB,EACpC,eAAe,EAAE,eAAe,EAChC,eAAe,EAAE,eAAe,EAChC,SAAS,EAAE,MAAM,EACjB,eAAe,EAAE,OAAO,0BAA0B,EAAE,eAAe,EACnE,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,uBAAuB,EAChC,oBAAoB,CAAC,EAAE,oBAAoB,GAC5C,OAAO,CAAC,gBAAgB,CAAC,CA2C3B"}
@@ -326,7 +326,7 @@ async function createVercelModel(llmConfig, context) {
326
326
  throw LLMError.unsupportedProvider(provider);
327
327
  }
328
328
  }
329
- async function createLLMService(config, toolManager, systemPromptManager, conversationStore, sessionEventBus, sessionId, resourceManager, logger, options, languageModelFactory) {
329
+ async function createLLMService(config, toolManager, systemPromptManager, conversationStore, toolOutputStore, sessionEventBus, sessionId, resourceManager, logger, options, languageModelFactory) {
330
330
  const { usageScopeId, compactionStrategy, executionControl, steerQueue, followUpQueue } = options;
331
331
  const providerContext = {
332
332
  sessionId,
@@ -352,6 +352,7 @@ async function createLLMService(config, toolManager, systemPromptManager, conver
352
352
  model,
353
353
  systemPromptManager,
354
354
  conversationStore,
355
+ toolOutputStore,
355
356
  sessionEventBus,
356
357
  config,
357
358
  sessionId,
@@ -121,7 +121,7 @@ class VercelLLMService {
121
121
  getModelId() {
122
122
  return typeof this.model === "string" ? this.model : this.model.modelId;
123
123
  }
124
- constructor(toolManager, model, systemPromptManager, conversationStore, sessionEventBus, config, sessionId, resourceManager, logger, steerQueue, followUpQueue, usageScopeId, executionControl, compactionStrategy, llmRegistry = import_llm.DEFAULT_MODEL_REGISTRY) {
124
+ constructor(toolManager, model, systemPromptManager, conversationStore, toolOutputStore, sessionEventBus, config, sessionId, resourceManager, logger, steerQueue, followUpQueue, usageScopeId, executionControl, compactionStrategy, llmRegistry = import_llm.DEFAULT_MODEL_REGISTRY) {
125
125
  this.logger = logger.createChild(import_types.DextoLogComponent.LLM);
126
126
  this.model = model;
127
127
  this.config = config;
@@ -149,6 +149,7 @@ class VercelLLMService {
149
149
  sessionId,
150
150
  resourceManager,
151
151
  this.logger,
152
+ toolOutputStore,
152
153
  this.llmRegistry
153
154
  );
154
155
  this.logger.debug(
@@ -1,3 +1,4 @@
1
+ import type { ToolOutputStore } from '../../storage/tool-outputs/types.js';
1
2
  import { LanguageModel } from 'ai';
2
3
  import { ToolManager } from '../../tools/tool-manager.js';
3
4
  import type { CreateTurnDriverOptions, LLMExecutionControl, LLMServiceConfig } from './types.js';
@@ -49,7 +50,7 @@ export declare class VercelLLMService {
49
50
  * Helper to extract model ID from LanguageModel union type (string | LanguageModelV2)
50
51
  */
51
52
  private getModelId;
52
- constructor(toolManager: ToolManager, model: LanguageModel, systemPromptManager: SystemPromptManager, conversationStore: ConversationStore, sessionEventBus: SessionEventBus, config: ValidatedLLMConfig, sessionId: string, resourceManager: ResourceManager, logger: Logger, steerQueue: MessageQueueService, followUpQueue: MessageQueueService, usageScopeId?: string, executionControl?: LLMExecutionControl, compactionStrategy?: import('../../context/compaction/types.js').CompactionStrategy | null, llmRegistry?: ModelRegistry);
53
+ constructor(toolManager: ToolManager, model: LanguageModel, systemPromptManager: SystemPromptManager, conversationStore: ConversationStore, toolOutputStore: ToolOutputStore, sessionEventBus: SessionEventBus, config: ValidatedLLMConfig, sessionId: string, resourceManager: ResourceManager, logger: Logger, steerQueue: MessageQueueService, followUpQueue: MessageQueueService, usageScopeId?: string, executionControl?: LLMExecutionControl, compactionStrategy?: import('../../context/compaction/types.js').CompactionStrategy | null, llmRegistry?: ModelRegistry);
53
54
  getAllTools(): Promise<ToolSet>;
54
55
  getEnabledTools(): Promise<ToolSet>;
55
56
  createTurnDriver(options?: CreateTurnDriverOptions): Promise<TurnDriver>;
@@ -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,uBAAuB,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AACjG,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AAEvD,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAC/C,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAI1D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,qCAAqC,CAAC;AAC7E,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAC;AAEzE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAGxD,OAAO,EAAgB,KAAK,UAAU,EAAE,MAAM,8BAA8B,CAAC;AAC7E,OAAO,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AACrE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAIhE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAEpE,OAAO,EAA0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kB,GAAG,IAAI;IAI9F,gBAAgB,IAAI,aAAa;CAGpC"}
@@ -57,7 +57,7 @@ class VercelLLMService {
57
57
  getModelId() {
58
58
  return typeof this.model === "string" ? this.model : this.model.modelId;
59
59
  }
60
- constructor(toolManager, model, systemPromptManager, conversationStore, sessionEventBus, config, sessionId, resourceManager, logger, steerQueue, followUpQueue, usageScopeId, executionControl, compactionStrategy, llmRegistry = DEFAULT_MODEL_REGISTRY) {
60
+ constructor(toolManager, model, systemPromptManager, conversationStore, toolOutputStore, sessionEventBus, config, sessionId, resourceManager, logger, steerQueue, followUpQueue, usageScopeId, executionControl, compactionStrategy, llmRegistry = DEFAULT_MODEL_REGISTRY) {
61
61
  this.logger = logger.createChild(DextoLogComponent.LLM);
62
62
  this.model = model;
63
63
  this.config = config;
@@ -85,6 +85,7 @@ class VercelLLMService {
85
85
  sessionId,
86
86
  resourceManager,
87
87
  this.logger,
88
+ toolOutputStore,
88
89
  this.llmRegistry
89
90
  );
90
91
  this.logger.debug(
@@ -162,6 +162,15 @@ class MCPError {
162
162
  { toolName, reason }
163
163
  );
164
164
  }
165
+ static invalidToolArguments(toolName, reason) {
166
+ return new import_DextoRuntimeError.DextoRuntimeError(
167
+ import_error_codes.MCPErrorCode.PROTOCOL_ERROR,
168
+ import_types.ErrorScope.MCP,
169
+ import_types.ErrorType.USER,
170
+ `MCP tool '${toolName}' received invalid arguments: ${reason}`,
171
+ { toolName, reason }
172
+ );
173
+ }
165
174
  }
166
175
  // Annotate the CommonJS export names for ESM import in node:
167
176
  0 && (module.exports = {
@@ -74,5 +74,9 @@ export declare class MCPError {
74
74
  toolName: string;
75
75
  reason: string;
76
76
  }>;
77
+ static invalidToolArguments(toolName: string, reason: string): DextoRuntimeError<{
78
+ toolName: string;
79
+ reason: string;
80
+ }>;
77
81
  }
78
82
  //# sourceMappingURL=errors.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/mcp/errors.ts"],"names":[],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E,MAAM,EAAE,MAAM,EAAE,MAAM;;;;IAW1D;;OAEG;IACH,MAAM,CAAC,mBAAmB,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;;;;IAW7D;;OAEG;IACH,MAAM,CAAC,aAAa,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO;IAWvD;;OAEG;IACH,MAAM,CAAC,sBAAsB,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM;;;;IAWjE;;OAEG;IACH,MAAM,CAAC,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM;;;;IAWvD;;OAEG;IACH,MAAM,CAAC,cAAc,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM;;;;IAUzD;;OAEG;IACH,MAAM,CAAC,YAAY,CAAC,QAAQ,EAAE,MAAM;;;IAUpC;;OAEG;IACH,MAAM,CAAC,cAAc,CAAC,UAAU,EAAE,MAAM;;;IAUxC;;OAEG;IACH,MAAM,CAAC,gBAAgB,CAAC,WAAW,EAAE,MAAM;;;IAU3C;;OAEG;IACH,MAAM,CAAC,kBAAkB,CAAC,OAAO,CAAC,EAAE,MAAM;;;IAU1C;;OAEG;IACH,MAAM,CAAC,iBAAiB,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;;;;IAUzD,MAAM,CAAC,oBAAoB,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;;;;CAS/D"}
@@ -140,6 +140,15 @@ class MCPError {
140
140
  { toolName, reason }
141
141
  );
142
142
  }
143
+ static invalidToolArguments(toolName, reason) {
144
+ return new DextoRuntimeError(
145
+ MCPErrorCode.PROTOCOL_ERROR,
146
+ ErrorScope.MCP,
147
+ ErrorType.USER,
148
+ `MCP tool '${toolName}' received invalid arguments: ${reason}`,
149
+ { toolName, reason }
150
+ );
151
+ }
143
152
  }
144
153
  export {
145
154
  MCPError
@@ -25,12 +25,19 @@ var import_mcp_client = require("./mcp-client.js");
25
25
  var import_types = require("../logger/v2/types.js");
26
26
  var import_errors = require("./errors.js");
27
27
  var import_events = require("../events/index.js");
28
+ var import_schema_fingerprint = require("../tools/schema-fingerprint.js");
29
+ var import_cfworker = require("@modelcontextprotocol/sdk/validation/cfworker");
30
+ function isJsonSchemaObject(value) {
31
+ return typeof value === "object" && value !== null && !Array.isArray(value);
32
+ }
28
33
  class MCPManager {
29
34
  clients = /* @__PURE__ */ new Map();
30
35
  connectionErrors = {};
31
36
  configCache = /* @__PURE__ */ new Map();
32
37
  // Store original configs for restart
33
38
  toolCache = /* @__PURE__ */ new Map();
39
+ toolInputValidators = /* @__PURE__ */ new Map();
40
+ jsonSchemaValidator = new import_cfworker.CfWorkerJsonSchemaValidator();
34
41
  toolConflicts = /* @__PURE__ */ new Set();
35
42
  // Track which tool names have conflicts
36
43
  promptCache = /* @__PURE__ */ new Map();
@@ -245,6 +252,7 @@ class MCPManager {
245
252
  this.toolCache.set(newQualified, {
246
253
  serverName: clientName,
247
254
  client,
255
+ upstreamToolName: toolName,
248
256
  definition: toolDef
249
257
  });
250
258
  this.logger.warn(
@@ -256,6 +264,7 @@ class MCPManager {
256
264
  this.toolCache.set(qualifiedName, {
257
265
  serverName: clientName,
258
266
  client,
267
+ upstreamToolName: toolName,
259
268
  definition: toolDef
260
269
  });
261
270
  this.logger.debug(`\u2705 Tool '${qualifiedName}' cached (known conflict)`);
@@ -263,6 +272,7 @@ class MCPManager {
263
272
  this.toolCache.set(toolName, {
264
273
  serverName: clientName,
265
274
  client,
275
+ upstreamToolName: toolName,
266
276
  definition: toolDef
267
277
  });
268
278
  this.logger.debug(`\u2705 Tool '${toolName}' mapped to ${clientName}`);
@@ -346,6 +356,70 @@ class MCPManager {
346
356
  this.logger.silly(`MCP tools: ${JSON.stringify(allTools, null, 2)}`);
347
357
  return allTools;
348
358
  }
359
+ /**
360
+ * Describe cached MCP tools without provider-specific schema wrapping.
361
+ * The callable name may change when conflicts appear, while identity remains connection-based.
362
+ */
363
+ getToolDescriptors() {
364
+ return Array.from(
365
+ this.toolCache.entries(),
366
+ ([name, entry]) => this.buildToolDescriptor(name, entry)
367
+ );
368
+ }
369
+ getToolDescriptor(name) {
370
+ const entry = this.toolCache.get(name);
371
+ return entry === void 0 ? void 0 : this.buildToolDescriptor(name, entry);
372
+ }
373
+ /** Validate arguments against the tool's advertised input schema before calling the server. */
374
+ validateToolInput(toolName, input) {
375
+ const entry = this.toolCache.get(toolName);
376
+ if (entry === void 0) {
377
+ throw import_errors.MCPError.toolNotFound(toolName);
378
+ }
379
+ const schemaFingerprint = (0, import_schema_fingerprint.toolSchemaFingerprint)(entry.definition.parameters);
380
+ let cached = this.toolInputValidators.get(toolName);
381
+ if (cached?.schemaFingerprint !== schemaFingerprint) {
382
+ const inputSchema = entry.definition.parameters;
383
+ if (!isJsonSchemaObject(inputSchema)) {
384
+ throw import_errors.MCPError.invalidToolSchema(entry.upstreamToolName, "expected an object");
385
+ }
386
+ try {
387
+ cached = {
388
+ schemaFingerprint,
389
+ validate: this.jsonSchemaValidator.getValidator(inputSchema)
390
+ };
391
+ } catch (error) {
392
+ throw import_errors.MCPError.invalidToolSchema(
393
+ entry.upstreamToolName,
394
+ error instanceof Error ? error.message : String(error)
395
+ );
396
+ }
397
+ this.toolInputValidators.set(toolName, cached);
398
+ }
399
+ const result = cached.validate(input);
400
+ if (!result.valid) {
401
+ throw import_errors.MCPError.invalidToolArguments(entry.upstreamToolName, result.errorMessage);
402
+ }
403
+ return result.data;
404
+ }
405
+ buildToolDescriptor(name, entry) {
406
+ return {
407
+ name,
408
+ description: entry.definition.description ?? "",
409
+ identity: {
410
+ type: "mcp",
411
+ connectionId: entry.serverName,
412
+ toolName: entry.upstreamToolName
413
+ },
414
+ inputSchema: entry.definition.parameters,
415
+ ...entry.definition.outputSchema !== void 0 ? { outputSchema: entry.definition.outputSchema } : {},
416
+ ...entry.definition.annotations !== void 0 ? { annotations: entry.definition.annotations } : {},
417
+ schemaFingerprint: (0, import_schema_fingerprint.toolSchemaFingerprint)(
418
+ entry.definition.parameters,
419
+ entry.definition.outputSchema
420
+ )
421
+ };
422
+ }
349
423
  /**
350
424
  * Get all MCP tools with their server metadata.
351
425
  * This returns the internal tool cache entries which include server names.
@@ -414,9 +488,7 @@ class MCPManager {
414
488
  const result = await client.callTool(actualToolName, args, invocation);
415
489
  return result;
416
490
  } catch (error) {
417
- this.logger.error(
418
- `\u274C MCP tool execution failed: '${actualToolName}' - ${error instanceof Error ? error.message : String(error)}`
419
- );
491
+ this.logger.error(`MCP tool execution failed: '${actualToolName}'`);
420
492
  throw error;
421
493
  }
422
494
  }
@@ -739,6 +811,7 @@ class MCPManager {
739
811
  this.connectionErrors = {};
740
812
  this.configCache.clear();
741
813
  this.toolCache.clear();
814
+ this.toolInputValidators.clear();
742
815
  this.toolConflicts.clear();
743
816
  this.promptCache.clear();
744
817
  this.resourceCache.clear();
@@ -876,6 +949,7 @@ class MCPManager {
876
949
  this.toolCache.set(newQualified, {
877
950
  serverName,
878
951
  client,
952
+ upstreamToolName: toolName,
879
953
  definition: toolDef
880
954
  });
881
955
  this.logger.warn(
@@ -887,6 +961,7 @@ class MCPManager {
887
961
  this.toolCache.set(qualifiedName, {
888
962
  serverName,
889
963
  client,
964
+ upstreamToolName: toolName,
890
965
  definition: toolDef
891
966
  });
892
967
  this.logger.debug(`\u2705 Tool '${qualifiedName}' cached (known conflict)`);
@@ -894,6 +969,7 @@ class MCPManager {
894
969
  this.toolCache.set(toolName, {
895
970
  serverName,
896
971
  client,
972
+ upstreamToolName: toolName,
897
973
  definition: toolDef
898
974
  });
899
975
  this.logger.debug(`\u2705 Tool '${toolName}' mapped to ${serverName}`);
@@ -2,26 +2,24 @@ import type { ValidatedServersConfig, ValidatedMcpServerConfig } from './schemas
2
2
  import type { Logger } from '../logger/v2/types.js';
3
3
  import type { GetPromptResult, ReadResourceResult } from '@modelcontextprotocol/sdk/types.js';
4
4
  import type { McpClient, MCPResolvedResource, McpAuthProviderFactory } from './types.js';
5
- import type { ToolSet } from '../tools/types.js';
5
+ import type { MCPToolDescriptor, ToolSet } from '../tools/types.js';
6
6
  import { type AgentEventBus } from '../events/index.js';
7
7
  import type { PromptDefinition } from '../prompts/types.js';
8
- import type { JSONSchema7 } from 'json-schema';
9
8
  import type { ApprovalManager } from '../approval/manager.js';
10
9
  import type { AgentRunContext } from '../runtime/run-context.js';
11
10
  type ToolCacheEntry = {
12
11
  serverName: string;
13
12
  client: McpClient;
14
- definition: {
15
- name?: string;
16
- description?: string;
17
- parameters: JSONSchema7;
18
- };
13
+ upstreamToolName: string;
14
+ definition: ToolSet[string];
19
15
  };
20
16
  export declare class MCPManager {
21
17
  private clients;
22
18
  private connectionErrors;
23
19
  private configCache;
24
20
  private toolCache;
21
+ private toolInputValidators;
22
+ private readonly jsonSchemaValidator;
25
23
  private toolConflicts;
26
24
  private promptCache;
27
25
  private resourceCache;
@@ -108,6 +106,15 @@ export declare class MCPManager {
108
106
  * @returns Promise resolving to a ToolSet mapping tool names to Tool definitions
109
107
  */
110
108
  getAllTools(): Promise<ToolSet>;
109
+ /**
110
+ * Describe cached MCP tools without provider-specific schema wrapping.
111
+ * The callable name may change when conflicts appear, while identity remains connection-based.
112
+ */
113
+ getToolDescriptors(): MCPToolDescriptor[];
114
+ getToolDescriptor(name: string): MCPToolDescriptor | undefined;
115
+ /** Validate arguments against the tool's advertised input schema before calling the server. */
116
+ validateToolInput(toolName: string, input: Record<string, unknown>): Record<string, unknown>;
117
+ private buildToolDescriptor;
111
118
  /**
112
119
  * Get all MCP tools with their server metadata.
113
120
  * This returns the internal tool cache entries which include server names.