fix: tool outcome errors for preprocessing failures

This commit is contained in:
Dallin Romney 2025-10-02 10:18:01 -07:00
parent 89826f0fea
commit 7036ece762
3 changed files with 58 additions and 24 deletions

View file

@ -83,6 +83,7 @@ import { NextEditProvider } from "./nextEdit/NextEditProvider";
import type { FromCoreProtocol, ToCoreProtocol } from "./protocol";
import { OnboardingModes } from "./protocol/core";
import type { IMessenger, Message } from "./protocol/messenger";
import { ContinueError, ContinueErrorReason } from "./util/errors";
import { shareSession } from "./util/historyUtils";
import { Logger } from "./util/Logger.js";
@ -1131,12 +1132,27 @@ export class Core {
if (!tool) {
throw new Error(`Tool ${toolName} not found`);
}
const preprocessedArgs = await tool.preprocessArgs?.(args, {
ide: this.ide,
});
return {
preprocessedArgs,
};
try {
const preprocessedArgs = await tool.preprocessArgs?.(args, {
ide: this.ide,
});
return {
preprocessedArgs,
};
} catch (e) {
let errorReason =
e instanceof ContinueError ? e.reason : ContinueErrorReason.Unknown;
let errorMessage =
e instanceof Error
? e.message
: `Error preprocessing tool call args for ${toolName}\n${JSON.stringify(args)}`;
return {
preprocessedArgs: undefined,
errorReason,
errorMessage,
};
}
});
on("isItemTooBig", async ({ data: { item } }) => {

View file

@ -54,6 +54,7 @@ import {
} from "../control-plane/client";
import { ProcessedItem } from "../nextEdit/NextEditPrefetchQueue";
import { NextEditOutcome } from "../nextEdit/types";
import { ContinueErrorReason } from "../util/errors";
export enum OnboardingModes {
API_KEY = "API Key",
@ -317,7 +318,11 @@ export type ToCoreFromIdeOrWebviewProtocol = {
];
"tools/preprocessArgs": [
{ toolName: string; args: Record<string, unknown> },
{ preprocessedArgs?: Record<string, unknown> },
{
preprocessedArgs?: Record<string, unknown>;
errorReason?: ContinueErrorReason;
errorMessage?: string;
},
];
"clipboardCache/add": [{ content: string }, void];
"controlPlane/openUrl": [{ path: string; orgSlug?: string }, void];

View file

@ -1,4 +1,6 @@
import { ToolCallState } from "core";
import { ContinueErrorReason } from "core/util/errors";
import posthog from "posthog-js";
import { IIdeMessenger } from "../../context/IdeMessenger";
import {
errorToolCall,
@ -15,25 +17,29 @@ export async function preprocessToolCalls(
// Tool call pre-processing
await Promise.all(
generatedToolCalls.map(async (tcState) => {
try {
const result = await ideMessenger.request("tools/preprocessArgs", {
let errorReason: ContinueErrorReason | undefined = undefined;
let errorMessage: string | undefined = undefined;
let preprocessedArgs: Record<string, unknown> | undefined = undefined;
const result = await ideMessenger.request("tools/preprocessArgs", {
toolName: tcState.toolCall.function.name,
args: tcState.parsedArgs,
});
if (result.status === "success") {
preprocessedArgs = result.content.preprocessedArgs;
errorMessage = result.content.errorMessage;
errorReason = result.content.errorReason;
} else {
errorMessage = result.error;
errorReason = ContinueErrorReason.Unknown;
}
if (errorReason) {
posthog.capture("tool_call_outcome", {
// model: , TODO
succeeded: false,
toolName: tcState.toolCall.function.name,
args: tcState.parsedArgs,
errorReason,
duration_ms: 0, // preprocessing is more or less instantaneous
});
if (result.status === "success") {
if (result.content.preprocessedArgs) {
dispatch(
setToolCallArgs({
toolCallId: tcState.toolCallId,
newArgs: result.content.preprocessedArgs,
}),
);
}
} else {
throw new Error(result.error);
}
} catch (e) {
let errorMessage = e instanceof Error ? e.message : `Unknown error`;
dispatch(
errorToolCall({
toolCallId: tcState.toolCallId,
@ -53,6 +59,13 @@ export async function preprocessToolCalls(
],
}),
);
} else if (preprocessedArgs) {
dispatch(
setToolCallArgs({
toolCallId: tcState.toolCallId,
newArgs: preprocessedArgs,
}),
);
}
}),
);