@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.
- package/dist/agent/DextoAgent.cjs +7 -0
- package/dist/agent/DextoAgent.d.ts +2 -5
- package/dist/agent/DextoAgent.d.ts.map +1 -1
- package/dist/agent/DextoAgent.js +7 -0
- package/dist/approval/index.cjs +4 -2
- package/dist/approval/index.d.ts +1 -1
- package/dist/approval/index.d.ts.map +1 -1
- package/dist/approval/index.js +3 -2
- package/dist/approval/manager.cjs +23 -4
- package/dist/approval/manager.d.ts +3 -2
- package/dist/approval/manager.d.ts.map +1 -1
- package/dist/approval/manager.js +21 -3
- package/dist/approval/schemas.cjs +5 -0
- package/dist/approval/schemas.d.ts +8 -0
- package/dist/approval/schemas.d.ts.map +1 -1
- package/dist/approval/schemas.js +5 -0
- package/dist/approval/types.d.ts +2 -2
- package/dist/approval/types.d.ts.map +1 -1
- package/dist/context/manager.cjs +34 -31
- package/dist/context/manager.d.ts +5 -6
- package/dist/context/manager.d.ts.map +1 -1
- package/dist/context/manager.js +36 -32
- package/dist/context/utils.cjs +6 -17
- package/dist/context/utils.d.ts +2 -0
- package/dist/context/utils.d.ts.map +1 -1
- package/dist/context/utils.js +5 -17
- package/dist/events/index.cjs +8 -0
- package/dist/events/index.d.ts +18 -5
- package/dist/events/index.d.ts.map +1 -1
- package/dist/events/index.js +8 -0
- package/dist/llm/executor/repeated-pruned-tool-calls.cjs +69 -0
- package/dist/llm/executor/repeated-pruned-tool-calls.d.ts +17 -0
- package/dist/llm/executor/repeated-pruned-tool-calls.d.ts.map +1 -0
- package/dist/llm/executor/repeated-pruned-tool-calls.js +46 -0
- package/dist/llm/executor/tool-output-spill.cjs +92 -0
- package/dist/llm/executor/tool-output-spill.d.ts +24 -0
- package/dist/llm/executor/tool-output-spill.d.ts.map +1 -0
- package/dist/llm/executor/tool-output-spill.js +65 -0
- package/dist/llm/executor/turn-executor.cjs +116 -35
- package/dist/llm/executor/turn-executor.d.ts +21 -5
- package/dist/llm/executor/turn-executor.d.ts.map +1 -1
- package/dist/llm/executor/turn-executor.js +122 -35
- package/dist/llm/services/factory.cjs +2 -1
- package/dist/llm/services/factory.d.ts +2 -1
- package/dist/llm/services/factory.d.ts.map +1 -1
- package/dist/llm/services/factory.js +2 -1
- package/dist/llm/services/vercel.cjs +2 -1
- package/dist/llm/services/vercel.d.ts +2 -1
- package/dist/llm/services/vercel.d.ts.map +1 -1
- package/dist/llm/services/vercel.js +2 -1
- package/dist/mcp/errors.cjs +9 -0
- package/dist/mcp/errors.d.ts +4 -0
- package/dist/mcp/errors.d.ts.map +1 -1
- package/dist/mcp/errors.js +9 -0
- package/dist/mcp/manager.cjs +79 -3
- package/dist/mcp/manager.d.ts +14 -7
- package/dist/mcp/manager.d.ts.map +1 -1
- package/dist/mcp/manager.js +79 -3
- package/dist/mcp/mcp-client.cjs +52 -62
- package/dist/mcp/mcp-client.d.ts.map +1 -1
- package/dist/mcp/mcp-client.js +54 -63
- package/dist/session/chat-session.cjs +1 -0
- package/dist/session/chat-session.d.ts +2 -0
- package/dist/session/chat-session.d.ts.map +1 -1
- package/dist/session/chat-session.js +1 -0
- package/dist/session/session-manager.cjs +16 -2
- package/dist/session/session-manager.d.ts +2 -0
- package/dist/session/session-manager.d.ts.map +1 -1
- package/dist/session/session-manager.js +16 -2
- package/dist/storage/index.cjs +2 -0
- package/dist/storage/index.d.ts +2 -1
- package/dist/storage/index.d.ts.map +1 -1
- package/dist/storage/index.js +2 -0
- package/dist/storage/stores/backend.cjs +26 -0
- package/dist/storage/stores/backend.d.ts +20 -0
- package/dist/storage/stores/backend.d.ts.map +1 -1
- package/dist/storage/stores/backend.js +25 -0
- package/dist/storage/stores/in-memory.cjs +20 -3
- package/dist/storage/stores/in-memory.d.ts +16 -0
- package/dist/storage/stores/in-memory.d.ts.map +1 -1
- package/dist/storage/stores/in-memory.js +18 -2
- package/dist/storage/stores/types.d.ts +3 -0
- package/dist/storage/stores/types.d.ts.map +1 -1
- package/dist/storage/tool-executions/types.cjs +12 -8
- package/dist/storage/tool-executions/types.d.ts +11 -2
- package/dist/storage/tool-executions/types.d.ts.map +1 -1
- package/dist/storage/tool-executions/types.js +12 -8
- package/dist/storage/tool-outputs/types.cjs +16 -0
- package/dist/storage/tool-outputs/types.d.ts +19 -0
- package/dist/storage/tool-outputs/types.d.ts.map +1 -0
- package/dist/storage/tool-outputs/types.js +0 -0
- package/dist/telemetry/decorators.cjs +47 -23
- package/dist/telemetry/decorators.d.ts +6 -0
- package/dist/telemetry/decorators.d.ts.map +1 -1
- package/dist/telemetry/decorators.js +47 -23
- package/dist/telemetry/operation-span.cjs +5 -2
- package/dist/telemetry/operation-span.d.ts +3 -0
- package/dist/telemetry/operation-span.d.ts.map +1 -1
- package/dist/telemetry/operation-span.js +5 -2
- package/dist/tools/activity.cjs +8 -0
- package/dist/tools/activity.d.ts +1 -0
- package/dist/tools/activity.d.ts.map +1 -1
- package/dist/tools/activity.js +8 -0
- package/dist/tools/approval/tool-approval-policy.cjs +11 -1
- package/dist/tools/approval/tool-approval-policy.d.ts +2 -2
- package/dist/tools/approval/tool-approval-policy.d.ts.map +1 -1
- package/dist/tools/approval/tool-approval-policy.js +11 -1
- package/dist/tools/identity.cjs +36 -0
- package/dist/tools/identity.d.ts +6 -0
- package/dist/tools/identity.d.ts.map +1 -0
- package/dist/tools/identity.js +13 -0
- package/dist/tools/index.cjs +2 -0
- package/dist/tools/index.d.ts +2 -1
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/index.js +4 -1
- package/dist/tools/presentation/tool-presentation.d.ts +5 -0
- package/dist/tools/presentation/tool-presentation.d.ts.map +1 -1
- package/dist/tools/schema-fingerprint.cjs +48 -0
- package/dist/tools/schema-fingerprint.d.ts +4 -0
- package/dist/tools/schema-fingerprint.d.ts.map +1 -0
- package/dist/tools/schema-fingerprint.js +25 -0
- package/dist/tools/schemas.cjs +3 -0
- package/dist/tools/schemas.d.ts +1 -0
- package/dist/tools/schemas.d.ts.map +1 -1
- package/dist/tools/schemas.js +2 -0
- package/dist/tools/tool-manager.cjs +199 -48
- package/dist/tools/tool-manager.d.ts +25 -11
- package/dist/tools/tool-manager.d.ts.map +1 -1
- package/dist/tools/tool-manager.js +199 -48
- package/dist/tools/tool-output-read.cjs +129 -0
- package/dist/tools/tool-output-read.d.ts +19 -0
- package/dist/tools/tool-output-read.d.ts.map +1 -0
- package/dist/tools/tool-output-read.js +106 -0
- package/dist/tools/types.d.ts +55 -0
- package/dist/tools/types.d.ts.map +1 -1
- package/dist/utils/schema.cjs +2 -2
- package/dist/utils/schema.d.ts +1 -1
- package/dist/utils/schema.d.ts.map +1 -1
- package/dist/utils/schema.js +2 -2
- package/dist/utils/service-initializer.cjs +4 -0
- package/dist/utils/service-initializer.d.ts +2 -0
- package/dist/utils/service-initializer.d.ts.map +1 -1
- package/dist/utils/service-initializer.js +4 -0
- package/dist/utils/stable-fingerprint.cjs +32 -0
- package/dist/utils/stable-fingerprint.d.ts +3 -0
- package/dist/utils/stable-fingerprint.d.ts.map +1 -0
- package/dist/utils/stable-fingerprint.js +9 -0
- package/package.json +9 -2
- package/dist/llm/executor/tool-output-truncator.cjs +0 -75
- package/dist/llm/executor/tool-output-truncator.d.ts +0 -27
- package/dist/llm/executor/tool-output-truncator.d.ts.map +0 -1
- package/dist/llm/executor/tool-output-truncator.js +0 -48
|
@@ -9,6 +9,7 @@ import { ToolError } from "./errors.js";
|
|
|
9
9
|
import { DextoRuntimeError, ErrorScope, ErrorType } from "../errors/index.js";
|
|
10
10
|
import { DextoLogComponent } from "../logger/v2/types.js";
|
|
11
11
|
import { convertZodSchemaToJsonSchema } from "../utils/schema.js";
|
|
12
|
+
import { toolSchemaFingerprint } from "./schema-fingerprint.js";
|
|
12
13
|
import { ApprovalStatus, ApprovalType, DenialReason } from "../approval/types.js";
|
|
13
14
|
import { ToolApprovalMetadataSchema, ToolApprovalResponseDataSchema } from "../approval/schemas.js";
|
|
14
15
|
import { matchesToolPolicyPattern, SessionToolPolicy } from "./approval/session-tool-policy.js";
|
|
@@ -28,6 +29,9 @@ function isRecord(value) {
|
|
|
28
29
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
29
30
|
}
|
|
30
31
|
_ToolManager_decorators = [InstrumentClass({
|
|
32
|
+
captureArguments: false,
|
|
33
|
+
captureErrors: false,
|
|
34
|
+
captureResult: false,
|
|
31
35
|
prefix: "tool",
|
|
32
36
|
excludeMethods: ["setHookSupport", "getApprovalManager", "getAllowedToolsProvider"]
|
|
33
37
|
})];
|
|
@@ -78,6 +82,8 @@ let _ToolManager = class _ToolManager {
|
|
|
78
82
|
}
|
|
79
83
|
mcpManager;
|
|
80
84
|
agentTools = /* @__PURE__ */ new Map();
|
|
85
|
+
/** Core-owned tools: always registered, never replaced by host tools or filtered per session. */
|
|
86
|
+
coreTools = [];
|
|
81
87
|
approvalManager;
|
|
82
88
|
allowedToolsProvider;
|
|
83
89
|
approvalMode;
|
|
@@ -141,9 +147,23 @@ let _ToolManager = class _ToolManager {
|
|
|
141
147
|
async initialize() {
|
|
142
148
|
this.logger.debug("ToolManager initialization complete");
|
|
143
149
|
}
|
|
150
|
+
registerCoreTools(tools) {
|
|
151
|
+
this.coreTools = tools;
|
|
152
|
+
for (const tool of tools) {
|
|
153
|
+
this.agentTools.set(tool.id, tool);
|
|
154
|
+
}
|
|
155
|
+
this.invalidateCache();
|
|
156
|
+
}
|
|
144
157
|
setTools(tools) {
|
|
145
158
|
this.agentTools.clear();
|
|
159
|
+
for (const tool of this.coreTools) {
|
|
160
|
+
this.agentTools.set(tool.id, tool);
|
|
161
|
+
}
|
|
146
162
|
for (const tool of tools) {
|
|
163
|
+
if (this.coreTools.some((coreTool) => coreTool.id === tool.id)) {
|
|
164
|
+
this.logger.warn(`Ignoring host tool '${tool.id}': the id belongs to a core tool`);
|
|
165
|
+
continue;
|
|
166
|
+
}
|
|
147
167
|
this.agentTools.set(tool.id, tool);
|
|
148
168
|
}
|
|
149
169
|
this.invalidateCache();
|
|
@@ -320,7 +340,12 @@ let _ToolManager = class _ToolManager {
|
|
|
320
340
|
* Filter a tool set based on disabled tools for a session.
|
|
321
341
|
*/
|
|
322
342
|
filterToolsForSession(toolSet, sessionId) {
|
|
323
|
-
|
|
343
|
+
const filtered = this.sessionToolPolicy.filterToolsForSession(toolSet, sessionId);
|
|
344
|
+
for (const tool of this.coreTools) {
|
|
345
|
+
const definition = toolSet[tool.id];
|
|
346
|
+
if (definition !== void 0) filtered[tool.id] = definition;
|
|
347
|
+
}
|
|
348
|
+
return filtered;
|
|
324
349
|
}
|
|
325
350
|
/**
|
|
326
351
|
* Check if a session has auto-approve tools set.
|
|
@@ -538,15 +563,77 @@ let _ToolManager = class _ToolManager {
|
|
|
538
563
|
async getMcpTools() {
|
|
539
564
|
return await this.mcpManager.getAllTools();
|
|
540
565
|
}
|
|
566
|
+
/**
|
|
567
|
+
* Return canonical tool descriptions for host-owned discovery and type generation.
|
|
568
|
+
* Unlike getAllTools(), schemas are not rewritten for model-provider compatibility.
|
|
569
|
+
*/
|
|
570
|
+
async getToolDescriptors() {
|
|
571
|
+
const descriptors = [];
|
|
572
|
+
for (const tool of this.agentTools.values()) {
|
|
573
|
+
descriptors.push(await this.buildLocalToolDescriptor(tool));
|
|
574
|
+
}
|
|
575
|
+
for (const descriptor of this.mcpManager.getToolDescriptors()) {
|
|
576
|
+
descriptors.push(this.prefixMcpToolDescriptor(descriptor));
|
|
577
|
+
}
|
|
578
|
+
return descriptors;
|
|
579
|
+
}
|
|
580
|
+
async getToolDescriptor(toolName) {
|
|
581
|
+
const localTool = this.agentTools.get(toolName);
|
|
582
|
+
if (localTool !== void 0) {
|
|
583
|
+
return await this.buildLocalToolDescriptor(localTool);
|
|
584
|
+
}
|
|
585
|
+
if (!toolName.startsWith(_ToolManager.MCP_TOOL_PREFIX)) {
|
|
586
|
+
return void 0;
|
|
587
|
+
}
|
|
588
|
+
const mcpName = toolName.substring(_ToolManager.MCP_TOOL_PREFIX.length);
|
|
589
|
+
if (mcpName.length === 0) {
|
|
590
|
+
return void 0;
|
|
591
|
+
}
|
|
592
|
+
const descriptor = this.mcpManager.getToolDescriptor(mcpName);
|
|
593
|
+
return descriptor === void 0 ? void 0 : this.prefixMcpToolDescriptor(descriptor);
|
|
594
|
+
}
|
|
595
|
+
resolveToolIdentity(toolName) {
|
|
596
|
+
if (this.agentTools.has(toolName)) {
|
|
597
|
+
return { type: "local", toolId: toolName };
|
|
598
|
+
}
|
|
599
|
+
if (!toolName.startsWith(_ToolManager.MCP_TOOL_PREFIX)) {
|
|
600
|
+
return void 0;
|
|
601
|
+
}
|
|
602
|
+
const mcpName = toolName.substring(_ToolManager.MCP_TOOL_PREFIX.length);
|
|
603
|
+
return this.mcpManager.getToolDescriptor(mcpName)?.identity;
|
|
604
|
+
}
|
|
605
|
+
async buildLocalToolDescriptor(tool) {
|
|
606
|
+
const inputSchema = convertZodSchemaToJsonSchema(tool.inputSchema, this.logger);
|
|
607
|
+
const outputSchema = tool.outputSchema === void 0 ? void 0 : convertZodSchemaToJsonSchema(tool.outputSchema, this.logger, "output");
|
|
608
|
+
return {
|
|
609
|
+
name: tool.id,
|
|
610
|
+
description: await this.getLocalToolDescription(tool),
|
|
611
|
+
approval: this.approvalMode === "auto-approve" || tool.needsApproval === false || tool.needsApproval === null ? "never" : "possible",
|
|
612
|
+
identity: { type: "local", toolId: tool.id },
|
|
613
|
+
inputSchema,
|
|
614
|
+
...outputSchema === void 0 ? {} : { outputSchema },
|
|
615
|
+
schemaFingerprint: toolSchemaFingerprint(inputSchema, outputSchema)
|
|
616
|
+
};
|
|
617
|
+
}
|
|
618
|
+
prefixMcpToolDescriptor(descriptor) {
|
|
619
|
+
return {
|
|
620
|
+
...descriptor,
|
|
621
|
+
approval: this.approvalMode === "auto-approve" ? "never" : "possible",
|
|
622
|
+
name: `${_ToolManager.MCP_TOOL_PREFIX}${descriptor.name}`,
|
|
623
|
+
description: `${descriptor.description || "No description provided"} (via MCP servers)`
|
|
624
|
+
};
|
|
625
|
+
}
|
|
541
626
|
buildToolExecutionContext(options) {
|
|
542
627
|
const workspace = this.currentWorkspace;
|
|
543
628
|
const baseContext = {
|
|
544
629
|
sessionId: options.sessionId,
|
|
545
630
|
runContext: options.runContext,
|
|
631
|
+
executionIdentity: options.executionIdentity,
|
|
546
632
|
workspaceId: workspace?.id,
|
|
547
633
|
workspace,
|
|
548
634
|
abortSignal: options.abortSignal,
|
|
549
635
|
toolCallId: options.toolCallId,
|
|
636
|
+
parentToolCallId: options.parentToolCallId,
|
|
550
637
|
hostRuntime: options.runContext?.hostRuntime,
|
|
551
638
|
logger: this.logger
|
|
552
639
|
};
|
|
@@ -560,8 +647,14 @@ let _ToolManager = class _ToolManager {
|
|
|
560
647
|
const sessionId = options.runContext?.sessionId ?? options.sessionId;
|
|
561
648
|
return { ...options, sessionId, hostRuntime: options.runContext?.hostRuntime };
|
|
562
649
|
}
|
|
563
|
-
resolveToolExecutionIdentity(invocation, toolCallId) {
|
|
650
|
+
resolveToolExecutionIdentity(invocation, toolCallId, parentToolCallId) {
|
|
564
651
|
if (invocation.executionIdentity !== void 0) {
|
|
652
|
+
if (invocation.executionIdentity.toolCallId !== toolCallId || invocation.executionIdentity.parentToolCallId !== parentToolCallId) {
|
|
653
|
+
throw ToolError.executionFailed(
|
|
654
|
+
toolCallId,
|
|
655
|
+
"Tool execution identity does not match the prepared call"
|
|
656
|
+
);
|
|
657
|
+
}
|
|
565
658
|
return invocation.executionIdentity;
|
|
566
659
|
}
|
|
567
660
|
const ids = invocation.runContext?.hostRuntime?.ids;
|
|
@@ -578,6 +671,7 @@ let _ToolManager = class _ToolManager {
|
|
|
578
671
|
runId,
|
|
579
672
|
turnId,
|
|
580
673
|
modelStepId,
|
|
674
|
+
...parentToolCallId === void 0 ? {} : { parentToolCallId },
|
|
581
675
|
toolCallId
|
|
582
676
|
};
|
|
583
677
|
}
|
|
@@ -623,6 +717,16 @@ let _ToolManager = class _ToolManager {
|
|
|
623
717
|
}
|
|
624
718
|
return validated;
|
|
625
719
|
}
|
|
720
|
+
validateToolArgs(toolName, args) {
|
|
721
|
+
if (!toolName.startsWith(_ToolManager.MCP_TOOL_PREFIX)) {
|
|
722
|
+
return this.validateLocalToolArgs(toolName, args);
|
|
723
|
+
}
|
|
724
|
+
const mcpName = toolName.substring(_ToolManager.MCP_TOOL_PREFIX.length);
|
|
725
|
+
if (mcpName.length === 0) {
|
|
726
|
+
throw ToolError.invalidName(toolName, "tool name cannot be empty after prefix");
|
|
727
|
+
}
|
|
728
|
+
return this.mcpManager.validateToolInput(mcpName, args);
|
|
729
|
+
}
|
|
626
730
|
async executeLocalTool(toolName, args, options) {
|
|
627
731
|
const tool = this.agentTools.get(toolName);
|
|
628
732
|
if (!tool) {
|
|
@@ -636,15 +740,15 @@ let _ToolManager = class _ToolManager {
|
|
|
636
740
|
const context = this.buildToolExecutionContext({
|
|
637
741
|
sessionId: options?.sessionId,
|
|
638
742
|
abortSignal: options?.abortSignal,
|
|
743
|
+
executionIdentity: options?.executionIdentity,
|
|
639
744
|
toolCallId: options?.toolCallId,
|
|
745
|
+
parentToolCallId: options?.parentToolCallId,
|
|
640
746
|
runContext: options?.runContext
|
|
641
747
|
});
|
|
642
748
|
const result = await tool.execute(args, context);
|
|
643
749
|
return result;
|
|
644
750
|
} catch (error) {
|
|
645
|
-
this.logger.error(
|
|
646
|
-
error: error instanceof Error ? error.message : String(error)
|
|
647
|
-
});
|
|
751
|
+
this.logger.error(`Local tool execution failed: ${toolName}`);
|
|
648
752
|
throw error;
|
|
649
753
|
}
|
|
650
754
|
}
|
|
@@ -673,21 +777,7 @@ let _ToolManager = class _ToolManager {
|
|
|
673
777
|
mcpTools = {};
|
|
674
778
|
}
|
|
675
779
|
for (const [toolName, tool] of this.agentTools) {
|
|
676
|
-
|
|
677
|
-
if (tool.getDescription) {
|
|
678
|
-
try {
|
|
679
|
-
const dynamicDescription = await tool.getDescription(
|
|
680
|
-
this.buildToolExecutionContext({})
|
|
681
|
-
);
|
|
682
|
-
if (dynamicDescription.trim()) {
|
|
683
|
-
description = dynamicDescription;
|
|
684
|
-
}
|
|
685
|
-
} catch (error) {
|
|
686
|
-
this.logger.warn(
|
|
687
|
-
`Failed to build dynamic description for '${toolName}': ${error instanceof Error ? error.message : String(error)}`
|
|
688
|
-
);
|
|
689
|
-
}
|
|
690
|
-
}
|
|
780
|
+
const description = await this.getLocalToolDescription(tool);
|
|
691
781
|
allTools[toolName] = {
|
|
692
782
|
name: toolName,
|
|
693
783
|
description,
|
|
@@ -713,6 +803,21 @@ let _ToolManager = class _ToolManager {
|
|
|
713
803
|
);
|
|
714
804
|
return allTools;
|
|
715
805
|
}
|
|
806
|
+
async getLocalToolDescription(tool) {
|
|
807
|
+
const fallback = tool.description || "No description provided";
|
|
808
|
+
if (!tool.getDescription) {
|
|
809
|
+
return fallback;
|
|
810
|
+
}
|
|
811
|
+
try {
|
|
812
|
+
const description = await tool.getDescription(this.buildToolExecutionContext({}));
|
|
813
|
+
return description.trim() ? description : fallback;
|
|
814
|
+
} catch (error) {
|
|
815
|
+
this.logger.warn(
|
|
816
|
+
`Failed to build dynamic description for '${tool.id}': ${error instanceof Error ? error.message : String(error)}`
|
|
817
|
+
);
|
|
818
|
+
return fallback;
|
|
819
|
+
}
|
|
820
|
+
}
|
|
716
821
|
/**
|
|
717
822
|
* Get all available tools from all sources with conflict resolution
|
|
718
823
|
* This is the single interface the LLM uses to discover tools
|
|
@@ -729,8 +834,8 @@ let _ToolManager = class _ToolManager {
|
|
|
729
834
|
}
|
|
730
835
|
async prepareToolCall(input) {
|
|
731
836
|
const sessionId = input.runContext?.sessionId ?? input.sessionId;
|
|
732
|
-
const
|
|
733
|
-
if (
|
|
837
|
+
const identity = this.resolveToolIdentity(input.toolName);
|
|
838
|
+
if (identity === void 0) {
|
|
734
839
|
return this.createPreparedToolError(
|
|
735
840
|
"unknown-tool",
|
|
736
841
|
input.toolName,
|
|
@@ -749,7 +854,7 @@ let _ToolManager = class _ToolManager {
|
|
|
749
854
|
const approvalDescription = typeof meta.callActivity?.running === "string" ? meta.callActivity.running : typeof rawToolArgs.description === "string" ? rawToolArgs.description : void 0;
|
|
750
855
|
let validatedArgs;
|
|
751
856
|
try {
|
|
752
|
-
validatedArgs = this.
|
|
857
|
+
validatedArgs = this.validateToolArgs(input.toolName, rawToolArgs);
|
|
753
858
|
} catch (error) {
|
|
754
859
|
return this.createPreparedToolError(
|
|
755
860
|
"invalid-input",
|
|
@@ -761,13 +866,15 @@ let _ToolManager = class _ToolManager {
|
|
|
761
866
|
toolName: input.toolName,
|
|
762
867
|
args: validatedArgs,
|
|
763
868
|
toolCallId: input.toolCallId,
|
|
869
|
+
...input.parentToolCallId === void 0 ? {} : { parentToolCallId: input.parentToolCallId },
|
|
764
870
|
...sessionId !== void 0 ? { sessionId } : {},
|
|
765
871
|
...input.runContext !== void 0 ? { runContext: input.runContext } : {}
|
|
766
872
|
});
|
|
767
873
|
const call = {
|
|
874
|
+
identity,
|
|
768
875
|
input: validatedArgs,
|
|
876
|
+
...input.parentToolCallId === void 0 ? {} : { parentToolCallId: input.parentToolCallId },
|
|
769
877
|
presentationSnapshot,
|
|
770
|
-
source,
|
|
771
878
|
toolCallId: input.toolCallId,
|
|
772
879
|
toolName: input.toolName,
|
|
773
880
|
...eventMeta !== void 0 ? { meta: eventMeta } : {}
|
|
@@ -777,10 +884,11 @@ let _ToolManager = class _ToolManager {
|
|
|
777
884
|
getContext: () => this.buildToolExecutionContext({
|
|
778
885
|
sessionId,
|
|
779
886
|
toolCallId: input.toolCallId,
|
|
887
|
+
parentToolCallId: input.parentToolCallId,
|
|
780
888
|
runContext: input.runContext
|
|
781
889
|
}),
|
|
782
890
|
...sessionId !== void 0 ? { sessionId } : {},
|
|
783
|
-
|
|
891
|
+
identity,
|
|
784
892
|
toolName: input.toolName
|
|
785
893
|
});
|
|
786
894
|
if (approvalGate.kind === "ready") {
|
|
@@ -803,6 +911,7 @@ let _ToolManager = class _ToolManager {
|
|
|
803
911
|
...input.runContext !== void 0 ? { runContext: input.runContext } : {},
|
|
804
912
|
...input.sessionId !== void 0 ? { sessionId: input.sessionId } : {},
|
|
805
913
|
toolCallId: input.toolCallId,
|
|
914
|
+
...input.call.parentToolCallId === void 0 ? {} : { parentToolCallId: input.call.parentToolCallId },
|
|
806
915
|
toolName: input.toolName
|
|
807
916
|
});
|
|
808
917
|
const hostRuntime = input.runContext?.hostRuntime;
|
|
@@ -812,9 +921,11 @@ let _ToolManager = class _ToolManager {
|
|
|
812
921
|
...hostRuntime !== void 0 ? { hostRuntime } : {},
|
|
813
922
|
metadata: {
|
|
814
923
|
toolName: input.toolName,
|
|
924
|
+
toolIdentity: input.call.identity,
|
|
815
925
|
...input.approvalGate.approvalKey !== void 0 ? { approvalKey: input.approvalGate.approvalKey } : {},
|
|
816
926
|
presentationSnapshot: input.call.presentationSnapshot,
|
|
817
927
|
toolCallId: input.toolCallId,
|
|
928
|
+
...input.call.parentToolCallId === void 0 ? {} : { parentToolCallId: input.call.parentToolCallId },
|
|
818
929
|
args: input.args,
|
|
819
930
|
...input.approvalDescription !== void 0 ? { description: input.approvalDescription } : {},
|
|
820
931
|
...displayPreview !== void 0 ? { displayPreview } : {}
|
|
@@ -875,6 +986,14 @@ let _ToolManager = class _ToolManager {
|
|
|
875
986
|
async requestApprovalDecision(recorded) {
|
|
876
987
|
return this.approvalManager.requestApprovalDecision(recorded.request);
|
|
877
988
|
}
|
|
989
|
+
async cancelApprovalRequest(recorded) {
|
|
990
|
+
await this.approvalManager.cancelApproval(recorded.request.approvalId);
|
|
991
|
+
await this.applyApprovalDecision(recorded, {
|
|
992
|
+
approvalId: recorded.request.approvalId,
|
|
993
|
+
reason: "system_cancelled",
|
|
994
|
+
status: ApprovalStatus.CANCELLED
|
|
995
|
+
});
|
|
996
|
+
}
|
|
878
997
|
assertRecordedApprovalMatchesPreparedCall(prepared, request) {
|
|
879
998
|
const expected = {
|
|
880
999
|
type: prepared.requestDetails.type,
|
|
@@ -951,15 +1070,6 @@ let _ToolManager = class _ToolManager {
|
|
|
951
1070
|
const outcome = response.status === ApprovalStatus.DENIED ? "approval was denied" : "approval was cancelled";
|
|
952
1071
|
return `Tool '${toolName}' was not executed because ${outcome}${response.message ? `: ${response.message}` : ""}.`;
|
|
953
1072
|
}
|
|
954
|
-
async resolveExecutableToolSource(toolName) {
|
|
955
|
-
if (this.agentTools.has(toolName)) {
|
|
956
|
-
return "local";
|
|
957
|
-
}
|
|
958
|
-
if (toolName.startsWith(_ToolManager.MCP_TOOL_PREFIX) && toolName.length > _ToolManager.MCP_TOOL_PREFIX.length) {
|
|
959
|
-
return "mcp";
|
|
960
|
-
}
|
|
961
|
-
return "unknown";
|
|
962
|
-
}
|
|
963
1073
|
createPreparedToolError(kind, toolName, error) {
|
|
964
1074
|
return {
|
|
965
1075
|
kind: "terminal",
|
|
@@ -987,7 +1097,6 @@ let _ToolManager = class _ToolManager {
|
|
|
987
1097
|
async executeTool(toolName, args, toolCallId, invocation) {
|
|
988
1098
|
const { sessionId, runContext, hostRuntime } = this.resolveToolExecutionInvocation(invocation);
|
|
989
1099
|
this.logger.debug(`\u{1F527} Tool execution requested: '${toolName}' (toolCallId: ${toolCallId})`);
|
|
990
|
-
this.logger.debug(`Tool args: ${JSON.stringify(args, null, 2)}`);
|
|
991
1100
|
if (toolName === _ToolManager.MCP_TOOL_PREFIX) {
|
|
992
1101
|
throw ToolError.invalidName(toolName, "tool name cannot be empty after prefix");
|
|
993
1102
|
}
|
|
@@ -995,6 +1104,7 @@ let _ToolManager = class _ToolManager {
|
|
|
995
1104
|
toolName,
|
|
996
1105
|
input: args,
|
|
997
1106
|
toolCallId,
|
|
1107
|
+
...invocation?.executionIdentity?.parentToolCallId === void 0 ? {} : { parentToolCallId: invocation.executionIdentity.parentToolCallId },
|
|
998
1108
|
...sessionId !== void 0 ? { sessionId } : {},
|
|
999
1109
|
...runContext !== void 0 ? { runContext } : {}
|
|
1000
1110
|
});
|
|
@@ -1013,7 +1123,11 @@ let _ToolManager = class _ToolManager {
|
|
|
1013
1123
|
try {
|
|
1014
1124
|
const recorded = await this.recordApprovalRequest(
|
|
1015
1125
|
prepared,
|
|
1016
|
-
this.resolveDirectApprovalIdentity(
|
|
1126
|
+
this.resolveDirectApprovalIdentity(
|
|
1127
|
+
invocation,
|
|
1128
|
+
toolCallId,
|
|
1129
|
+
prepared.call.parentToolCallId
|
|
1130
|
+
)
|
|
1017
1131
|
);
|
|
1018
1132
|
const response = await this.requestApprovalDecision(recorded);
|
|
1019
1133
|
applied = await this.applyApprovalDecision(recorded, {
|
|
@@ -1042,6 +1156,9 @@ let _ToolManager = class _ToolManager {
|
|
|
1042
1156
|
if (!sessionId) {
|
|
1043
1157
|
return;
|
|
1044
1158
|
}
|
|
1159
|
+
if (call.parentToolCallId !== void 0) {
|
|
1160
|
+
return;
|
|
1161
|
+
}
|
|
1045
1162
|
this.agentEventBus.emit("llm:tool-call", {
|
|
1046
1163
|
toolName: call.toolName,
|
|
1047
1164
|
presentationSnapshot: this.toolPresentation.snapshotForToolCallEvent({
|
|
@@ -1063,7 +1180,11 @@ let _ToolManager = class _ToolManager {
|
|
|
1063
1180
|
if (isBackgroundTasksEnabled() && call.meta?.runInBackground === true && sessionId !== void 0) {
|
|
1064
1181
|
return void 0;
|
|
1065
1182
|
}
|
|
1066
|
-
const identity = this.resolveToolExecutionIdentity(
|
|
1183
|
+
const identity = this.resolveToolExecutionIdentity(
|
|
1184
|
+
invocation ?? {},
|
|
1185
|
+
call.toolCallId,
|
|
1186
|
+
call.parentToolCallId
|
|
1187
|
+
);
|
|
1067
1188
|
if (identity === void 0) {
|
|
1068
1189
|
return void 0;
|
|
1069
1190
|
}
|
|
@@ -1091,13 +1212,24 @@ let _ToolManager = class _ToolManager {
|
|
|
1091
1212
|
`Tool execution already failed: ${executionId}`
|
|
1092
1213
|
);
|
|
1093
1214
|
}
|
|
1215
|
+
if (this.resumesRunningExecution(call, record.status)) {
|
|
1216
|
+
return void 0;
|
|
1217
|
+
}
|
|
1094
1218
|
throw ToolError.executionFailed(
|
|
1095
1219
|
call.toolName,
|
|
1096
1220
|
`Tool execution already ${record.status}: ${executionId}`
|
|
1097
1221
|
);
|
|
1098
1222
|
}
|
|
1223
|
+
/** A `resumable` local tool re-enters its own matching record that is still running. */
|
|
1224
|
+
resumesRunningExecution(call, status) {
|
|
1225
|
+
return status === "running" && call.identity.type === "local" && this.agentTools.get(call.identity.toolId)?.resumable === true;
|
|
1226
|
+
}
|
|
1099
1227
|
async recordDirectToolExecutionFailure(call, invocation, error) {
|
|
1100
|
-
const identity = this.resolveToolExecutionIdentity(
|
|
1228
|
+
const identity = this.resolveToolExecutionIdentity(
|
|
1229
|
+
invocation ?? {},
|
|
1230
|
+
call.toolCallId,
|
|
1231
|
+
call.parentToolCallId
|
|
1232
|
+
);
|
|
1101
1233
|
if (identity === void 0) {
|
|
1102
1234
|
return;
|
|
1103
1235
|
}
|
|
@@ -1130,8 +1262,12 @@ let _ToolManager = class _ToolManager {
|
|
|
1130
1262
|
error: error instanceof Error ? error.message : String(error)
|
|
1131
1263
|
});
|
|
1132
1264
|
}
|
|
1133
|
-
resolveDirectApprovalIdentity(invocation, toolCallId) {
|
|
1134
|
-
const executionIdentity = this.resolveToolExecutionIdentity(
|
|
1265
|
+
resolveDirectApprovalIdentity(invocation, toolCallId, parentToolCallId) {
|
|
1266
|
+
const executionIdentity = this.resolveToolExecutionIdentity(
|
|
1267
|
+
invocation ?? {},
|
|
1268
|
+
toolCallId,
|
|
1269
|
+
parentToolCallId
|
|
1270
|
+
);
|
|
1135
1271
|
if (executionIdentity !== void 0) {
|
|
1136
1272
|
return {
|
|
1137
1273
|
runId: executionIdentity.runId,
|
|
@@ -1182,7 +1318,8 @@ let _ToolManager = class _ToolManager {
|
|
|
1182
1318
|
const { sessionId, abortSignal, runContext, hostRuntime } = this.resolveToolExecutionInvocation(invocation);
|
|
1183
1319
|
const durableIdentity = this.resolveToolExecutionIdentity(
|
|
1184
1320
|
invocation ?? {},
|
|
1185
|
-
call.toolCallId
|
|
1321
|
+
call.toolCallId,
|
|
1322
|
+
call.parentToolCallId
|
|
1186
1323
|
);
|
|
1187
1324
|
const backgroundTasksEnabled = isBackgroundTasksEnabled();
|
|
1188
1325
|
const willRunInBackground = backgroundTasksEnabled && call.meta?.runInBackground === true && sessionId !== void 0;
|
|
@@ -1231,10 +1368,16 @@ let _ToolManager = class _ToolManager {
|
|
|
1231
1368
|
}
|
|
1232
1369
|
return this.createFailedPreparedToolResult(call, started.record.error);
|
|
1233
1370
|
}
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1371
|
+
if (!this.resumesRunningExecution(call, started.record.status)) {
|
|
1372
|
+
throw ToolError.executionFailed(
|
|
1373
|
+
call.toolName,
|
|
1374
|
+
`Tool execution already ${started.record.status}: ${executionId}`
|
|
1375
|
+
);
|
|
1376
|
+
}
|
|
1377
|
+
this.logger.info("Resuming running prepared tool execution", {
|
|
1378
|
+
executionId,
|
|
1379
|
+
toolName: call.toolName
|
|
1380
|
+
});
|
|
1238
1381
|
}
|
|
1239
1382
|
}
|
|
1240
1383
|
const startTime = Date.now();
|
|
@@ -1246,6 +1389,9 @@ let _ToolManager = class _ToolManager {
|
|
|
1246
1389
|
this.agentEventBus.emit("tool:running", {
|
|
1247
1390
|
toolName: call.toolName,
|
|
1248
1391
|
toolCallId: call.toolCallId,
|
|
1392
|
+
...call.parentToolCallId !== void 0 && {
|
|
1393
|
+
parentToolCallId: call.parentToolCallId
|
|
1394
|
+
},
|
|
1249
1395
|
sessionId,
|
|
1250
1396
|
...hostRuntime !== void 0 && { hostRuntime }
|
|
1251
1397
|
});
|
|
@@ -1270,7 +1416,7 @@ let _ToolManager = class _ToolManager {
|
|
|
1270
1416
|
);
|
|
1271
1417
|
toolArgs = modifiedPayload.args;
|
|
1272
1418
|
try {
|
|
1273
|
-
toolArgs = this.
|
|
1419
|
+
toolArgs = this.validateToolArgs(call.toolName, toolArgs);
|
|
1274
1420
|
} catch (error) {
|
|
1275
1421
|
this.logger.error(
|
|
1276
1422
|
`Post-hook validation failed for tool '${call.toolName}': a beforeToolCall hook may have set invalid args`
|
|
@@ -1289,7 +1435,7 @@ let _ToolManager = class _ToolManager {
|
|
|
1289
1435
|
promise
|
|
1290
1436
|
};
|
|
1291
1437
|
};
|
|
1292
|
-
if (call.
|
|
1438
|
+
if (call.identity.type === "mcp") {
|
|
1293
1439
|
const actualToolName = call.toolName.substring(_ToolManager.MCP_TOOL_PREFIX.length);
|
|
1294
1440
|
if (actualToolName.length === 0) {
|
|
1295
1441
|
throw ToolError.invalidName(
|
|
@@ -1346,7 +1492,9 @@ let _ToolManager = class _ToolManager {
|
|
|
1346
1492
|
this.executeLocalTool(call.toolName, toolArgs, {
|
|
1347
1493
|
sessionId: backgroundSessionId,
|
|
1348
1494
|
abortSignal,
|
|
1495
|
+
executionIdentity,
|
|
1349
1496
|
toolCallId: call.toolCallId,
|
|
1497
|
+
parentToolCallId: call.parentToolCallId,
|
|
1350
1498
|
runContext
|
|
1351
1499
|
}),
|
|
1352
1500
|
`Tool ${call.toolName}`
|
|
@@ -1370,7 +1518,9 @@ let _ToolManager = class _ToolManager {
|
|
|
1370
1518
|
result = await this.executeLocalTool(call.toolName, toolArgs, {
|
|
1371
1519
|
sessionId,
|
|
1372
1520
|
abortSignal,
|
|
1521
|
+
executionIdentity,
|
|
1373
1522
|
toolCallId: call.toolCallId,
|
|
1523
|
+
parentToolCallId: call.parentToolCallId,
|
|
1374
1524
|
runContext
|
|
1375
1525
|
});
|
|
1376
1526
|
}
|
|
@@ -1406,6 +1556,7 @@ let _ToolManager = class _ToolManager {
|
|
|
1406
1556
|
result,
|
|
1407
1557
|
args: toolArgs,
|
|
1408
1558
|
toolCallId: call.toolCallId,
|
|
1559
|
+
...call.parentToolCallId === void 0 ? {} : { parentToolCallId: call.parentToolCallId },
|
|
1409
1560
|
...sessionId !== void 0 ? { sessionId } : {},
|
|
1410
1561
|
...runContext !== void 0 ? { runContext } : {}
|
|
1411
1562
|
});
|
|
@@ -1437,7 +1588,7 @@ let _ToolManager = class _ToolManager {
|
|
|
1437
1588
|
} catch (error) {
|
|
1438
1589
|
const duration = Date.now() - startTime;
|
|
1439
1590
|
this.logger.error(
|
|
1440
|
-
|
|
1591
|
+
`Prepared tool execution failed for ${call.toolName} after ${duration}ms, sessionId: ${sessionId ?? "global"}`
|
|
1441
1592
|
);
|
|
1442
1593
|
const message = error instanceof Error ? error.message : String(error);
|
|
1443
1594
|
if (executionId !== void 0) {
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var tool_output_read_exports = {};
|
|
20
|
+
__export(tool_output_read_exports, {
|
|
21
|
+
createToolOutputReadTool: () => createToolOutputReadTool
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(tool_output_read_exports);
|
|
24
|
+
var import_zod = require("zod");
|
|
25
|
+
var import_tool_output_spill = require("../llm/executor/tool-output-spill.js");
|
|
26
|
+
var import_activity = require("./activity.js");
|
|
27
|
+
var import_errors = require("./errors.js");
|
|
28
|
+
var import_define_tool = require("./define-tool.js");
|
|
29
|
+
var import_presentation = require("./presentation.js");
|
|
30
|
+
const MAX_READ_LINES = 2e3;
|
|
31
|
+
const MAX_READ_CHARS = 5e4;
|
|
32
|
+
const DEFAULT_MAX_MATCHES = 100;
|
|
33
|
+
const MAX_MATCHES = 500;
|
|
34
|
+
const MAX_MATCH_LINE_CHARS = 500;
|
|
35
|
+
const ToolOutputReadInputSchema = import_zod.z.object({
|
|
36
|
+
id: import_zod.z.string().min(1).describe("The tool call id named in a truncated or cleared tool result."),
|
|
37
|
+
offset: import_zod.z.number().int().min(1).optional().describe("1-based line to start reading from. Defaults to 1."),
|
|
38
|
+
charOffset: import_zod.z.number().int().min(0).optional().describe(
|
|
39
|
+
"0-based character to start from within the offset line, for lines too long to read at once."
|
|
40
|
+
),
|
|
41
|
+
limit: import_zod.z.number().int().min(1).max(MAX_READ_LINES).optional().describe(`Number of lines to read, up to ${MAX_READ_LINES}.`),
|
|
42
|
+
pattern: import_zod.z.string().min(1).optional().describe(
|
|
43
|
+
"Search instead of reading a range: returns lines containing this text (case-insensitive) with their line numbers."
|
|
44
|
+
),
|
|
45
|
+
maxMatches: import_zod.z.number().int().min(1).max(MAX_MATCHES).optional().describe(`Most matching lines to return with pattern, up to ${MAX_MATCHES}.`)
|
|
46
|
+
}).strict();
|
|
47
|
+
function createToolOutputReadTool(stores) {
|
|
48
|
+
return (0, import_define_tool.defineTool)({
|
|
49
|
+
id: import_tool_output_spill.TOOL_OUTPUT_READ_TOOL_NAME,
|
|
50
|
+
description: "Read a tool result that was truncated or cleared from this conversation, by the id named in its marker. Read a line range with offset and limit, or search it with pattern. Use this instead of re-running the tool.",
|
|
51
|
+
inputSchema: ToolOutputReadInputSchema,
|
|
52
|
+
needsApproval: false,
|
|
53
|
+
presentation: {
|
|
54
|
+
activity: import_activity.TOOL_ACTIVITY.readToolOutput,
|
|
55
|
+
describeHeader: (input) => (0, import_presentation.createLocalToolCallHeader)({
|
|
56
|
+
title: "Read earlier output",
|
|
57
|
+
argsText: input.pattern === void 0 ? input.id : `${input.id} "${input.pattern}"`
|
|
58
|
+
})
|
|
59
|
+
},
|
|
60
|
+
async execute(input, context) {
|
|
61
|
+
const sessionId = context.sessionId;
|
|
62
|
+
if (sessionId === void 0) {
|
|
63
|
+
throw import_errors.ToolError.executionFailed(import_tool_output_spill.TOOL_OUTPUT_READ_TOOL_NAME, "it needs a session");
|
|
64
|
+
}
|
|
65
|
+
const text = await loadToolOutput(stores, sessionId, input.id);
|
|
66
|
+
if (text === void 0) {
|
|
67
|
+
return `No stored output with id "${input.id}" in this conversation. It may have expired. Re-run the tool if it only reads data, or narrow the request.`;
|
|
68
|
+
}
|
|
69
|
+
return input.pattern === void 0 ? readLines(text, input) : searchLines(text, input.pattern, input.maxMatches ?? DEFAULT_MAX_MATCHES);
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
async function loadToolOutput(stores, sessionId, toolCallId) {
|
|
74
|
+
const stored = await stores.toolOutputs.load({ sessionId, toolCallId });
|
|
75
|
+
if (stored !== void 0) return stored;
|
|
76
|
+
const messages = await stores.conversation.listMessages({ sessionId });
|
|
77
|
+
const message = messages.find(
|
|
78
|
+
(candidate) => candidate.role === "tool" && candidate.toolCallId === toolCallId
|
|
79
|
+
);
|
|
80
|
+
if (message?.role !== "tool") return void 0;
|
|
81
|
+
return message.content.flatMap((part) => part.type === "text" ? [part.text] : []).join("\n");
|
|
82
|
+
}
|
|
83
|
+
function readLines(text, input) {
|
|
84
|
+
const lines = text.split("\n");
|
|
85
|
+
const start = Math.min(input.offset ?? 1, lines.length);
|
|
86
|
+
const end = Math.min(start - 1 + (input.limit ?? MAX_READ_LINES), lines.length);
|
|
87
|
+
const selected = [];
|
|
88
|
+
let chars = 0;
|
|
89
|
+
for (let line = start; line <= end && chars < MAX_READ_CHARS; line += 1) {
|
|
90
|
+
const full = lines[line - 1] ?? "";
|
|
91
|
+
const from = line === start ? Math.min(input.charOffset ?? 0, full.length) : 0;
|
|
92
|
+
const piece = full.slice(from, from + MAX_READ_CHARS - chars);
|
|
93
|
+
selected.push(`${line}: ${piece}`);
|
|
94
|
+
chars += piece.length + 1;
|
|
95
|
+
if (from + piece.length < full.length) {
|
|
96
|
+
const next = from + piece.length;
|
|
97
|
+
return `${selected.join("\n")}
|
|
98
|
+
|
|
99
|
+
[Line ${line} continues (${full.length} characters). Use offset=${line} charOffset=${next} to continue.]`;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
const last = start + selected.length - 1;
|
|
103
|
+
const hint = last < lines.length ? `Showing lines ${start}-${last} of ${lines.length}. Use offset=${last + 1} to continue.` : `Showing lines ${start}-${last} of ${lines.length}.`;
|
|
104
|
+
return `${selected.join("\n")}
|
|
105
|
+
|
|
106
|
+
[${hint}]`;
|
|
107
|
+
}
|
|
108
|
+
function searchLines(text, pattern, maxMatches) {
|
|
109
|
+
const needle = pattern.toLowerCase();
|
|
110
|
+
const lines = text.split("\n");
|
|
111
|
+
const found = [];
|
|
112
|
+
let total = 0;
|
|
113
|
+
lines.forEach((line, index) => {
|
|
114
|
+
if (!line.toLowerCase().includes(needle)) return;
|
|
115
|
+
total += 1;
|
|
116
|
+
if (found.length < maxMatches) {
|
|
117
|
+
found.push(`${index + 1}: ${line.slice(0, MAX_MATCH_LINE_CHARS)}`);
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
if (total === 0) return `[No lines contain "${pattern}" in ${lines.length} lines.]`;
|
|
121
|
+
const shown = total > found.length ? `Showing ${found.length} of ${total} matching lines; raise maxMatches or narrow the pattern.` : `${total} matching lines of ${lines.length}.`;
|
|
122
|
+
return `${found.join("\n")}
|
|
123
|
+
|
|
124
|
+
[${shown} Read around a match with offset.]`;
|
|
125
|
+
}
|
|
126
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
127
|
+
0 && (module.exports = {
|
|
128
|
+
createToolOutputReadTool
|
|
129
|
+
});
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/** Core `tool_output_read`: pages through or searches a tool result stored for this session. */
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import type { ConversationStore } from '../storage/conversation/types.js';
|
|
4
|
+
import type { ToolOutputStore } from '../storage/tool-outputs/types.js';
|
|
5
|
+
import type { Tool } from './types.js';
|
|
6
|
+
declare const ToolOutputReadInputSchema: z.ZodObject<{
|
|
7
|
+
id: z.ZodString;
|
|
8
|
+
offset: z.ZodOptional<z.ZodNumber>;
|
|
9
|
+
charOffset: z.ZodOptional<z.ZodNumber>;
|
|
10
|
+
limit: z.ZodOptional<z.ZodNumber>;
|
|
11
|
+
pattern: z.ZodOptional<z.ZodString>;
|
|
12
|
+
maxMatches: z.ZodOptional<z.ZodNumber>;
|
|
13
|
+
}, z.core.$strict>;
|
|
14
|
+
export declare function createToolOutputReadTool(stores: {
|
|
15
|
+
conversation: ConversationStore;
|
|
16
|
+
toolOutputs: ToolOutputStore;
|
|
17
|
+
}): Tool<typeof ToolOutputReadInputSchema>;
|
|
18
|
+
export {};
|
|
19
|
+
//# sourceMappingURL=tool-output-read.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-output-read.d.ts","sourceRoot":"","sources":["../../src/tools/tool-output-read.ts"],"names":[],"mappings":"AAAA,gGAAgG;AAChG,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAC;AAC1E,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AAMxE,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAQvC,QAAA,MAAM,yBAAyB;;;;;;;kBA0ClB,CAAC;AAId,wBAAgB,wBAAwB,CAAC,MAAM,EAAE;IAC7C,YAAY,EAAE,iBAAiB,CAAC;IAChC,WAAW,EAAE,eAAe,CAAC;CAChC,GAAG,IAAI,CAAC,OAAO,yBAAyB,CAAC,CAkCzC"}
|