mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 18:18:28 +00:00
refactor: split agent tools
This commit is contained in:
44
src/agents/tools/gateway.ts
Normal file
44
src/agents/tools/gateway.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
import { callGateway } from "../../gateway/call.js";
|
||||
|
||||
export const DEFAULT_GATEWAY_URL = "ws://127.0.0.1:18789";
|
||||
|
||||
export type GatewayCallOptions = {
|
||||
gatewayUrl?: string;
|
||||
gatewayToken?: string;
|
||||
timeoutMs?: number;
|
||||
};
|
||||
|
||||
export function resolveGatewayOptions(opts?: GatewayCallOptions) {
|
||||
const url =
|
||||
typeof opts?.gatewayUrl === "string" && opts.gatewayUrl.trim()
|
||||
? opts.gatewayUrl.trim()
|
||||
: DEFAULT_GATEWAY_URL;
|
||||
const token =
|
||||
typeof opts?.gatewayToken === "string" && opts.gatewayToken.trim()
|
||||
? opts.gatewayToken.trim()
|
||||
: undefined;
|
||||
const timeoutMs =
|
||||
typeof opts?.timeoutMs === "number" && Number.isFinite(opts.timeoutMs)
|
||||
? Math.max(1, Math.floor(opts.timeoutMs))
|
||||
: 10_000;
|
||||
return { url, token, timeoutMs };
|
||||
}
|
||||
|
||||
export async function callGatewayTool<T = unknown>(
|
||||
method: string,
|
||||
opts: GatewayCallOptions,
|
||||
params?: unknown,
|
||||
extra?: { expectFinal?: boolean },
|
||||
) {
|
||||
const gateway = resolveGatewayOptions(opts);
|
||||
return await callGateway<T>({
|
||||
url: gateway.url,
|
||||
token: gateway.token,
|
||||
method,
|
||||
params,
|
||||
timeoutMs: gateway.timeoutMs,
|
||||
expectFinal: extra?.expectFinal,
|
||||
clientName: "agent",
|
||||
mode: "agent",
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user