feat: requestRule tool
This commit is contained in:
parent
1b59411ec1
commit
af30fbe360
11 changed files with 128 additions and 8 deletions
|
|
@ -51,7 +51,6 @@ import { LLMReranker } from "../llm/llms/llm";
|
|||
import TransformersJsEmbeddingsProvider from "../llm/llms/TransformersJsEmbeddingsProvider";
|
||||
import { slashCommandFromPromptFileV1 } from "../promptFiles/v1/slashCommandFromPromptFile";
|
||||
import { getAllPromptFiles } from "../promptFiles/v2/getPromptFiles";
|
||||
import { allTools } from "../tools";
|
||||
import { copyOf } from "../util";
|
||||
import { GlobalContext } from "../util/GlobalContext";
|
||||
import mergeJson from "../util/merge";
|
||||
|
|
@ -67,6 +66,7 @@ import {
|
|||
} from "../util/paths";
|
||||
import { localPathToUri } from "../util/pathToUri";
|
||||
|
||||
import { baseToolDefinitions } from "../tools";
|
||||
import { modifyAnyConfigWithSharedConfig } from "./sharedConfig";
|
||||
import {
|
||||
getModelByRole,
|
||||
|
|
@ -529,7 +529,7 @@ async function intermediateToFinalConfig({
|
|||
const continueConfig: ContinueConfig = {
|
||||
...config,
|
||||
contextProviders,
|
||||
tools: [...allTools],
|
||||
tools: baseToolDefinitions,
|
||||
mcpServerStatuses: [],
|
||||
slashCommands: config.slashCommands ?? [],
|
||||
modelsByRole: {
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ import { ControlPlaneClient } from "../../control-plane/client.js";
|
|||
import { getControlPlaneEnv } from "../../control-plane/env.js";
|
||||
import { TeamAnalytics } from "../../control-plane/TeamAnalytics.js";
|
||||
import ContinueProxy from "../../llm/llms/stubs/ContinueProxy";
|
||||
import { getConfigDependentToolDefinitions } from "../../tools";
|
||||
import { encodeMCPToolUri } from "../../tools/callTool";
|
||||
import { getConfigJsonPath, getConfigYamlPath } from "../../util/paths";
|
||||
import { localPathOrUriToPath } from "../../util/pathToUri";
|
||||
|
|
@ -193,6 +194,8 @@ export default async function doLoadConfig(options: {
|
|||
}
|
||||
}
|
||||
|
||||
newConfig.tools.push(...getConfigDependentTools(newConfig));
|
||||
|
||||
// Detect duplicate tool names
|
||||
const counts: Record<string, number> = {};
|
||||
newConfig.tools.forEach((tool) => {
|
||||
|
|
@ -202,6 +205,7 @@ export default async function doLoadConfig(options: {
|
|||
counts[tool.function.name] = 1;
|
||||
}
|
||||
});
|
||||
|
||||
Object.entries(counts).forEach(([toolName, count]) => {
|
||||
if (count > 1) {
|
||||
errors!.push({
|
||||
|
|
@ -309,3 +313,23 @@ async function getWorkspaceConfigs(ide: IDE): Promise<ContinueRcJson[]> {
|
|||
|
||||
return workspaceConfigs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of tools that depend on the configuration.
|
||||
* @param {ContinueConfig} config - The configuration object.
|
||||
* @returns {Tool[]} Array of tools
|
||||
* @todo Why is `doLoadConfig` getting called multiple times causing us to have duplicates here unless we filter
|
||||
*/
|
||||
function getConfigDependentTools(config: ContinueConfig): Tool[] {
|
||||
const configDependentTools = getConfigDependentToolDefinitions({
|
||||
rules: config.rules,
|
||||
});
|
||||
|
||||
return configDependentTools.filter(
|
||||
(configTool) =>
|
||||
!config.tools.some(
|
||||
(existingTool) =>
|
||||
existingTool.function.name === configTool.function.name,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,11 +36,11 @@ import FreeTrial from "../../llm/llms/FreeTrial";
|
|||
import TransformersJsEmbeddingsProvider from "../../llm/llms/TransformersJsEmbeddingsProvider";
|
||||
import { slashCommandFromPromptFileV1 } from "../../promptFiles/v1/slashCommandFromPromptFile";
|
||||
import { getAllPromptFiles } from "../../promptFiles/v2/getPromptFiles";
|
||||
import { allTools } from "../../tools";
|
||||
import { GlobalContext } from "../../util/GlobalContext";
|
||||
import { modifyAnyConfigWithSharedConfig } from "../sharedConfig";
|
||||
|
||||
import { getControlPlaneEnvSync } from "../../control-plane/env";
|
||||
import { baseToolDefinitions } from "../../tools";
|
||||
import { getCleanUriPath } from "../../util/uri";
|
||||
import { getAllDotContinueDefinitionFiles } from "../loadLocalAssistants";
|
||||
import { LocalPlatformClient } from "./LocalPlatformClient";
|
||||
|
|
@ -193,7 +193,7 @@ async function configYamlToContinueConfig(options: {
|
|||
|
||||
const continueConfig: ContinueConfig = {
|
||||
slashCommands: [],
|
||||
tools: [...allTools],
|
||||
tools: baseToolDefinitions,
|
||||
mcpServerStatuses: [],
|
||||
contextProviders: [],
|
||||
modelsByRole: {
|
||||
|
|
|
|||
6
core/index.d.ts
vendored
6
core/index.d.ts
vendored
|
|
@ -1003,6 +1003,12 @@ interface ToolChoice {
|
|||
};
|
||||
}
|
||||
|
||||
export interface ConfigDependentToolParams {
|
||||
rules: RuleWithSource[];
|
||||
}
|
||||
|
||||
export type GetTool = (params: ConfigDependentToolParams) => Tool;
|
||||
|
||||
export interface BaseCompletionOptions {
|
||||
temperature?: number;
|
||||
topP?: number;
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ export enum BuiltInToolNames {
|
|||
ViewDiff = "builtin_view_diff",
|
||||
LSTool = "builtin_ls",
|
||||
CreateRuleBlock = "builtin_create_rule_block",
|
||||
RequestRule = "builtin_request_rule",
|
||||
|
||||
// excluded from allTools for now
|
||||
ViewRepoMap = "builtin_view_repo_map",
|
||||
|
|
@ -18,4 +19,4 @@ export enum BuiltInToolNames {
|
|||
|
||||
export const BUILT_IN_GROUP_NAME = "Built-In";
|
||||
|
||||
export const CLIENT_TOOLS = [BuiltInToolNames.EditExistingFile];
|
||||
export const CLIENT_TOOLS_IMPLS = [BuiltInToolNames.EditExistingFile];
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ import { grepSearchImpl } from "./implementations/grepSearch";
|
|||
import { lsToolImpl } from "./implementations/lsTool";
|
||||
import { readCurrentlyOpenFileImpl } from "./implementations/readCurrentlyOpenFile";
|
||||
import { readFileImpl } from "./implementations/readFile";
|
||||
import { requestRuleImpl } from "./implementations/requestRule";
|
||||
import { runTerminalCommandImpl } from "./implementations/runTerminalCommand";
|
||||
import { searchWebImpl } from "./implementations/searchWeb";
|
||||
import { viewDiffImpl } from "./implementations/viewDiff";
|
||||
|
|
@ -157,6 +158,8 @@ async function callBuiltInTool(
|
|||
return await readCurrentlyOpenFileImpl(args, extras);
|
||||
case BuiltInToolNames.CreateRuleBlock:
|
||||
return await createRuleBlockImpl(args, extras);
|
||||
case BuiltInToolNames.RequestRule:
|
||||
return await requestRuleImpl(args, extras);
|
||||
default:
|
||||
throw new Error(`Tool "${functionName}" not found`);
|
||||
}
|
||||
|
|
|
|||
60
core/tools/definitions/requestRule.ts
Normal file
60
core/tools/definitions/requestRule.ts
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
import { ConfigDependentToolParams, GetTool } from "../..";
|
||||
import { BUILT_IN_GROUP_NAME, BuiltInToolNames } from "../builtIn";
|
||||
|
||||
export interface RequestRuleArgs {
|
||||
filepath: string;
|
||||
name: string;
|
||||
}
|
||||
|
||||
export function getRequestRuleDescription(
|
||||
rules: ConfigDependentToolParams["rules"],
|
||||
): string {
|
||||
// Must be explicitly false
|
||||
const agentRequestedRules = rules.filter(
|
||||
(rule) => rule.alwaysApply === false,
|
||||
);
|
||||
|
||||
const prefix =
|
||||
"Use this tool to select additional rules, specifically based on their descriptions. Available rules:\n";
|
||||
|
||||
const body = agentRequestedRules
|
||||
.map(
|
||||
(rule) =>
|
||||
`Rule: ${rule.name}\nDescription: ${rule.description}\nFilepath: ${rule.ruleFile}`,
|
||||
)
|
||||
.join("\n\n");
|
||||
|
||||
if (body.length === 0) {
|
||||
return prefix + "No rules available.";
|
||||
}
|
||||
|
||||
return prefix + body;
|
||||
}
|
||||
|
||||
export const requestRuleTool: GetTool = ({ rules }) => ({
|
||||
type: "function",
|
||||
displayTitle: "Request Rules",
|
||||
wouldLikeTo: "request rule {{{ name }}}",
|
||||
isCurrently: "reading rule {{{ name }}}",
|
||||
hasAlready: "read rule {{{ name }}}",
|
||||
group: BUILT_IN_GROUP_NAME,
|
||||
readonly: false,
|
||||
function: {
|
||||
name: BuiltInToolNames.RequestRule,
|
||||
description: getRequestRuleDescription(rules),
|
||||
parameters: {
|
||||
type: "object",
|
||||
required: ["name", "filepath"],
|
||||
properties: {
|
||||
filepath: {
|
||||
type: "string",
|
||||
description: "The path of the rule file",
|
||||
},
|
||||
name: {
|
||||
type: "string",
|
||||
description: "Name of the rule",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
19
core/tools/implementations/requestRule.ts
Normal file
19
core/tools/implementations/requestRule.ts
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
import { ToolImpl } from ".";
|
||||
import { parseMarkdownRule } from "../../config/markdown/parseMarkdownRule";
|
||||
|
||||
export const requestRuleImpl: ToolImpl = async (args, extras) => {
|
||||
const fileContent = await extras.ide.readFile(args.filepath);
|
||||
const { markdown, frontmatter } = parseMarkdownRule(fileContent);
|
||||
|
||||
return [
|
||||
{
|
||||
name: frontmatter.name ?? "",
|
||||
description: frontmatter.description ?? "",
|
||||
content: markdown,
|
||||
uri: {
|
||||
type: "file",
|
||||
value: args.filepath,
|
||||
},
|
||||
},
|
||||
];
|
||||
};
|
||||
|
|
@ -1,3 +1,4 @@
|
|||
import { ConfigDependentToolParams, Tool } from "..";
|
||||
import { createNewFileTool } from "./definitions/createNewFile";
|
||||
import { createRuleBlock } from "./definitions/createRuleBlock";
|
||||
import { editFileTool } from "./definitions/editFile";
|
||||
|
|
@ -6,11 +7,12 @@ import { grepSearchTool } from "./definitions/grepSearch";
|
|||
import { lsTool } from "./definitions/lsTool";
|
||||
import { readCurrentlyOpenFileTool } from "./definitions/readCurrentlyOpenFile";
|
||||
import { readFileTool } from "./definitions/readFile";
|
||||
import { requestRuleTool } from "./definitions/requestRule";
|
||||
import { runTerminalCommandTool } from "./definitions/runTerminalCommand";
|
||||
import { searchWebTool } from "./definitions/searchWeb";
|
||||
import { viewDiffTool } from "./definitions/viewDiff";
|
||||
|
||||
export const allTools = [
|
||||
export const baseToolDefinitions = [
|
||||
readFileTool,
|
||||
editFileTool,
|
||||
createNewFileTool,
|
||||
|
|
@ -26,3 +28,7 @@ export const allTools = [
|
|||
// viewSubdirectoryTool,
|
||||
// viewRepoMapTool,
|
||||
];
|
||||
|
||||
export const getConfigDependentToolDefinitions = (
|
||||
params: ConfigDependentToolParams,
|
||||
): Tool[] => [requestRuleTool(params)];
|
||||
|
|
|
|||
|
|
@ -56,6 +56,7 @@ export const uiSlice = createSlice({
|
|||
[BuiltInToolNames.ViewDiff]: "allowedWithoutPermission",
|
||||
[BuiltInToolNames.LSTool]: "allowedWithoutPermission",
|
||||
[BuiltInToolNames.CreateRuleBlock]: "allowedWithPermission",
|
||||
[BuiltInToolNames.RequestRule]: "allowedWithoutPermission",
|
||||
},
|
||||
toolGroupSettings: {
|
||||
[BUILT_IN_GROUP_NAME]: "include",
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { createAsyncThunk, unwrapResult } from "@reduxjs/toolkit";
|
||||
import { ContextItem } from "core";
|
||||
import { CLIENT_TOOLS } from "core/tools/builtIn";
|
||||
import { CLIENT_TOOLS_IMPLS } from "core/tools/builtIn";
|
||||
import { callClientTool } from "../../util/clientTools/callClientTool";
|
||||
import { selectCurrentToolCall } from "../selectors/selectCurrentToolCall";
|
||||
import { selectSelectedChatModel } from "../slices/configSlice";
|
||||
|
|
@ -51,7 +51,7 @@ export const callCurrentTool = createAsyncThunk<void, undefined, ThunkApiType>(
|
|||
// Errors that occur outside specifically calling the tool
|
||||
// Should not be caught here - should be handled as normal stream errors
|
||||
if (
|
||||
CLIENT_TOOLS.find(
|
||||
CLIENT_TOOLS_IMPLS.find(
|
||||
(toolName) => toolName === toolCallState.toolCall.function.name,
|
||||
)
|
||||
) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue