mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-03 03:03:24 -04:00
fix: align tool execute arg parsing for hooks
This commit is contained in:
@@ -17,22 +17,21 @@ import {
|
||||
import { normalizeToolName } from "./tool-policy.js";
|
||||
import { jsonResult } from "./tools/common.js";
|
||||
|
||||
// oxlint-disable-next-line typescript/no-explicit-any
|
||||
type AnyAgentTool = AgentTool<any, unknown>;
|
||||
type AnyAgentTool = AgentTool;
|
||||
|
||||
type ToolExecuteArgsCurrent = [
|
||||
string,
|
||||
unknown,
|
||||
AbortSignal | undefined,
|
||||
AgentToolUpdateCallback<unknown> | undefined,
|
||||
unknown,
|
||||
AbortSignal | undefined,
|
||||
];
|
||||
type ToolExecuteArgsLegacy = [
|
||||
string,
|
||||
unknown,
|
||||
AbortSignal | undefined,
|
||||
AgentToolUpdateCallback<unknown> | undefined,
|
||||
unknown,
|
||||
AbortSignal | undefined,
|
||||
];
|
||||
type ToolExecuteArgs = ToolDefinition["execute"] extends (...args: infer P) => unknown
|
||||
? P
|
||||
@@ -45,8 +44,11 @@ function isAbortSignal(value: unknown): value is AbortSignal {
|
||||
|
||||
function isLegacyToolExecuteArgs(args: ToolExecuteArgsAny): args is ToolExecuteArgsLegacy {
|
||||
const third = args[2];
|
||||
const fourth = args[3];
|
||||
return isAbortSignal(third) || typeof fourth === "function";
|
||||
const fifth = args[4];
|
||||
if (typeof third === "function") {
|
||||
return true;
|
||||
}
|
||||
return isAbortSignal(fifth);
|
||||
}
|
||||
|
||||
function describeToolExecutionError(err: unknown): {
|
||||
@@ -67,7 +69,7 @@ function splitToolExecuteArgs(args: ToolExecuteArgsAny): {
|
||||
signal: AbortSignal | undefined;
|
||||
} {
|
||||
if (isLegacyToolExecuteArgs(args)) {
|
||||
const [toolCallId, params, signal, onUpdate] = args;
|
||||
const [toolCallId, params, onUpdate, _ctx, signal] = args;
|
||||
return {
|
||||
toolCallId,
|
||||
params,
|
||||
@@ -75,7 +77,7 @@ function splitToolExecuteArgs(args: ToolExecuteArgsAny): {
|
||||
signal,
|
||||
};
|
||||
}
|
||||
const [toolCallId, params, onUpdate, _ctx, signal] = args;
|
||||
const [toolCallId, params, signal, onUpdate] = args;
|
||||
return {
|
||||
toolCallId,
|
||||
params,
|
||||
@@ -199,8 +201,7 @@ export function toClientToolDefinitions(
|
||||
name: func.name,
|
||||
label: func.name,
|
||||
description: func.description ?? "",
|
||||
// oxlint-disable-next-line typescript/no-explicit-any
|
||||
parameters: func.parameters as any,
|
||||
parameters: func.parameters as ToolDefinition["parameters"],
|
||||
execute: async (...args: ToolExecuteArgs): Promise<AgentToolResult<unknown>> => {
|
||||
const { toolCallId, params } = splitToolExecuteArgs(args);
|
||||
const outcome = await runBeforeToolCallHook({
|
||||
|
||||
Reference in New Issue
Block a user