Merge pull request #5673 from continuedev/dallin/hanging-tools
Fix: non-existent tool logic, better tool errors
This commit is contained in:
commit
34462703da
2 changed files with 50 additions and 44 deletions
|
|
@ -29,11 +29,12 @@ async function callHttpTool(
|
|||
}),
|
||||
});
|
||||
|
||||
const data = await response.json();
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`Failed to call tool: ${url}`);
|
||||
throw new Error(`Failed to call tool at ${url}:\n${JSON.stringify(data)}`);
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
return data.output;
|
||||
}
|
||||
|
||||
|
|
@ -84,7 +85,7 @@ async function callToolFromUri(
|
|||
});
|
||||
|
||||
if (response.isError === true) {
|
||||
throw new Error(`Failed to call tool: ${toolName}`);
|
||||
throw new Error(JSON.stringify(response.content));
|
||||
}
|
||||
|
||||
const contextItems: ContextItem[] = [];
|
||||
|
|
@ -130,6 +131,37 @@ async function callToolFromUri(
|
|||
}
|
||||
}
|
||||
|
||||
async function callBuiltInTool(
|
||||
functionName: string,
|
||||
args: any,
|
||||
extras: ToolExtras,
|
||||
): Promise<ContextItem[]> {
|
||||
switch (functionName) {
|
||||
case BuiltInToolNames.ReadFile:
|
||||
return await readFileImpl(args, extras);
|
||||
case BuiltInToolNames.CreateNewFile:
|
||||
return await createNewFileImpl(args, extras);
|
||||
case BuiltInToolNames.GrepSearch:
|
||||
return await grepSearchImpl(args, extras);
|
||||
case BuiltInToolNames.FileGlobSearch:
|
||||
return await fileGlobSearchImpl(args, extras);
|
||||
case BuiltInToolNames.RunTerminalCommand:
|
||||
return await runTerminalCommandImpl(args, extras);
|
||||
case BuiltInToolNames.SearchWeb:
|
||||
return await searchWebImpl(args, extras);
|
||||
case BuiltInToolNames.ViewDiff:
|
||||
return await viewDiffImpl(args, extras);
|
||||
case BuiltInToolNames.LSTool:
|
||||
return await lsToolImpl(args, extras);
|
||||
case BuiltInToolNames.ReadCurrentlyOpenFile:
|
||||
return await readCurrentlyOpenFileImpl(args, extras);
|
||||
case BuiltInToolNames.CreateRuleBlock:
|
||||
return await createRuleBlockImpl(args, extras);
|
||||
default:
|
||||
throw new Error(`Tool "${functionName}" not found`);
|
||||
}
|
||||
}
|
||||
|
||||
// Handles calls for core/non-client tools
|
||||
// Returns an error context item if the tool call fails
|
||||
// Note: Edit tool is handled on client
|
||||
|
|
@ -141,44 +173,11 @@ export async function callTool(
|
|||
contextItems: ContextItem[];
|
||||
errorMessage: string | undefined;
|
||||
}> {
|
||||
const args = JSON.parse(callArgs || "{}");
|
||||
const uri = tool.uri ?? tool.function.name;
|
||||
try {
|
||||
let contextItems: ContextItem[] = [];
|
||||
switch (uri) {
|
||||
case BuiltInToolNames.ReadFile:
|
||||
contextItems = await readFileImpl(args, extras);
|
||||
break;
|
||||
case BuiltInToolNames.CreateNewFile:
|
||||
contextItems = await createNewFileImpl(args, extras);
|
||||
break;
|
||||
case BuiltInToolNames.GrepSearch:
|
||||
contextItems = await grepSearchImpl(args, extras);
|
||||
break;
|
||||
case BuiltInToolNames.FileGlobSearch:
|
||||
contextItems = await fileGlobSearchImpl(args, extras);
|
||||
break;
|
||||
case BuiltInToolNames.RunTerminalCommand:
|
||||
contextItems = await runTerminalCommandImpl(args, extras);
|
||||
break;
|
||||
case BuiltInToolNames.SearchWeb:
|
||||
contextItems = await searchWebImpl(args, extras);
|
||||
break;
|
||||
case BuiltInToolNames.ViewDiff:
|
||||
contextItems = await viewDiffImpl(args, extras);
|
||||
break;
|
||||
case BuiltInToolNames.LSTool:
|
||||
contextItems = await lsToolImpl(args, extras);
|
||||
break;
|
||||
case BuiltInToolNames.ReadCurrentlyOpenFile:
|
||||
contextItems = await readCurrentlyOpenFileImpl(args, extras);
|
||||
break;
|
||||
case BuiltInToolNames.CreateRuleBlock:
|
||||
contextItems = await createRuleBlockImpl(args, extras);
|
||||
break;
|
||||
default:
|
||||
contextItems = await callToolFromUri(uri, args, extras);
|
||||
}
|
||||
const args = JSON.parse(callArgs || "{}");
|
||||
const contextItems = tool.uri
|
||||
? await callToolFromUri(tool.uri, args, extras)
|
||||
: await callBuiltInTool(tool.function.name, args, extras);
|
||||
if (tool.faviconUrl) {
|
||||
contextItems.forEach((item) => {
|
||||
item.icon = tool.faviconUrl;
|
||||
|
|
|
|||
|
|
@ -173,17 +173,24 @@ function ModeSelect() {
|
|||
{mode === "chat" && <CheckIcon className="ml-auto h-3 w-3" />}
|
||||
</ListboxOption>
|
||||
|
||||
<ListboxOption value="agent" disabled={!agentModeSupported}>
|
||||
<ListboxOption
|
||||
value="agent"
|
||||
disabled={!agentModeSupported}
|
||||
className={"gap-1"}
|
||||
>
|
||||
<div className="flex flex-row items-center gap-1.5">
|
||||
<SparklesIcon className="h-3 w-3" />
|
||||
<span className="">Agent</span>
|
||||
</div>
|
||||
{mode === "agent" && <CheckIcon className="ml-auto h-3 w-3" />}
|
||||
{!agentModeSupported && <span> (Not supported)</span>}
|
||||
{agentModeSupported ? (
|
||||
mode === "agent" && <CheckIcon className="ml-auto h-3 w-3" />
|
||||
) : (
|
||||
<span>(Not supported)</span>
|
||||
)}
|
||||
</ListboxOption>
|
||||
|
||||
<div className="text-lightgray px-2 py-1">
|
||||
{metaKeyLabel}. for next mode
|
||||
{`${metaKeyLabel} . for next mode`}
|
||||
</div>
|
||||
</ListboxOptions>
|
||||
</div>
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue