continue-custom/core/tools/index.ts
Dallin Romney fac7f5c449
feat: tool call args preprocessing (#7992)
* feat: preprocess tool call args

* fix: broken multi edit impl

* fix: preprocess test failures

* fix: preprocessing tests

* fix: tool calls test progress

* fix: tests using mock store

* fix: thunk tests working

* fix: mock ide messenger tests
2025-09-30 18:49:29 -07:00

58 lines
1.8 KiB
TypeScript

import { ConfigDependentToolParams, Tool } from "..";
import { isRecommendedAgentModel } from "../llm/toolSupport";
import * as toolDefinitions from "./definitions";
// I'm writing these as functions because we've messed up 3 TIMES by pushing to const, causing duplicate tool definitions on subsequent config loads.
export const getBaseToolDefinitions = () => [
toolDefinitions.readFileTool,
toolDefinitions.createNewFileTool,
toolDefinitions.runTerminalCommandTool,
toolDefinitions.globSearchTool,
toolDefinitions.viewDiffTool,
toolDefinitions.readCurrentlyOpenFileTool,
toolDefinitions.lsTool,
toolDefinitions.createRuleBlock,
toolDefinitions.fetchUrlContentTool,
];
export const getConfigDependentToolDefinitions = (
params: ConfigDependentToolParams,
): Tool[] => {
const { modelName, isSignedIn, enableExperimentalTools, isRemote } = params;
const tools: Tool[] = [];
tools.push(toolDefinitions.requestRuleTool(params));
if (isSignedIn) {
// Web search is only available for signed-in users
tools.push(toolDefinitions.searchWebTool);
}
if (enableExperimentalTools) {
tools.push(
toolDefinitions.viewRepoMapTool,
toolDefinitions.viewSubdirectoryTool,
toolDefinitions.codebaseTool,
toolDefinitions.readFileRangeTool,
);
}
if (modelName && isRecommendedAgentModel(modelName)) {
tools.push(toolDefinitions.multiEditTool);
} else {
tools.push(toolDefinitions.editFileTool);
tools.push(toolDefinitions.singleFindAndReplaceTool);
}
// missing support for remote os calls: https://github.com/microsoft/vscode/issues/252269
if (!isRemote) {
tools.push(toolDefinitions.grepSearchTool);
}
return tools;
};
export function serializeTool(tool: Tool) {
const { preprocessArgs, evaluateToolCallPolicy, ...rest } = tool;
return rest;
}