mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 05:51:24 +00:00
chore: Enable "curly" rule to avoid single-statement if confusion/errors.
This commit is contained in:
@@ -45,12 +45,16 @@ type ToolsInvokeBody = {
|
||||
};
|
||||
|
||||
function resolveSessionKeyFromBody(body: ToolsInvokeBody): string | undefined {
|
||||
if (typeof body.sessionKey === "string" && body.sessionKey.trim()) return body.sessionKey.trim();
|
||||
if (typeof body.sessionKey === "string" && body.sessionKey.trim()) {
|
||||
return body.sessionKey.trim();
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
function resolveMemoryToolDisableReasons(cfg: ReturnType<typeof loadConfig>): string[] {
|
||||
if (!process.env.VITEST) return [];
|
||||
if (!process.env.VITEST) {
|
||||
return [];
|
||||
}
|
||||
const reasons: string[] = [];
|
||||
const plugins = cfg.plugins;
|
||||
const slotRaw = plugins?.slots?.memory;
|
||||
@@ -59,7 +63,9 @@ function resolveMemoryToolDisableReasons(cfg: ReturnType<typeof loadConfig>): st
|
||||
const pluginsDisabled = plugins?.enabled === false;
|
||||
const defaultDisabled = isTestDefaultMemorySlotDisabled(cfg);
|
||||
|
||||
if (pluginsDisabled) reasons.push("plugins.enabled=false");
|
||||
if (pluginsDisabled) {
|
||||
reasons.push("plugins.enabled=false");
|
||||
}
|
||||
if (slotDisabled) {
|
||||
reasons.push(slotRaw === null ? "plugins.slots.memory=null" : 'plugins.slots.memory="none"');
|
||||
}
|
||||
@@ -75,8 +81,12 @@ function mergeActionIntoArgsIfSupported(params: {
|
||||
args: Record<string, unknown>;
|
||||
}): Record<string, unknown> {
|
||||
const { toolSchema, action, args } = params;
|
||||
if (!action) return args;
|
||||
if (args.action !== undefined) return args;
|
||||
if (!action) {
|
||||
return args;
|
||||
}
|
||||
if (args.action !== undefined) {
|
||||
return args;
|
||||
}
|
||||
// TypeBox schemas are plain objects; many tools define an `action` property.
|
||||
const schemaObj = toolSchema as { properties?: Record<string, unknown> } | null;
|
||||
const hasAction = Boolean(
|
||||
@@ -85,7 +95,9 @@ function mergeActionIntoArgsIfSupported(params: {
|
||||
schemaObj.properties &&
|
||||
"action" in schemaObj.properties,
|
||||
);
|
||||
if (!hasAction) return args;
|
||||
if (!hasAction) {
|
||||
return args;
|
||||
}
|
||||
return { ...args, action };
|
||||
}
|
||||
|
||||
@@ -95,7 +107,9 @@ export async function handleToolsInvokeHttpRequest(
|
||||
opts: { auth: ResolvedGatewayAuth; maxBodyBytes?: number; trustedProxies?: string[] },
|
||||
): Promise<boolean> {
|
||||
const url = new URL(req.url ?? "/", `http://${req.headers.host ?? "localhost"}`);
|
||||
if (url.pathname !== "/tools/invoke") return false;
|
||||
if (url.pathname !== "/tools/invoke") {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (req.method !== "POST") {
|
||||
sendMethodNotAllowed(res, "POST");
|
||||
@@ -116,7 +130,9 @@ export async function handleToolsInvokeHttpRequest(
|
||||
}
|
||||
|
||||
const bodyUnknown = await readJsonBodyOrError(req, res, opts.maxBodyBytes ?? DEFAULT_BODY_BYTES);
|
||||
if (bodyUnknown === undefined) return true;
|
||||
if (bodyUnknown === undefined) {
|
||||
return true;
|
||||
}
|
||||
const body = (bodyUnknown ?? {}) as ToolsInvokeBody;
|
||||
|
||||
const toolName = typeof body.tool === "string" ? body.tool.trim() : "";
|
||||
@@ -175,7 +191,9 @@ export async function handleToolsInvokeHttpRequest(
|
||||
const providerProfilePolicy = resolveToolProfilePolicy(providerProfile);
|
||||
|
||||
const mergeAlsoAllow = (policy: typeof profilePolicy, alsoAllow?: string[]) => {
|
||||
if (!policy?.allow || !Array.isArray(alsoAllow) || alsoAllow.length === 0) return policy;
|
||||
if (!policy?.allow || !Array.isArray(alsoAllow) || alsoAllow.length === 0) {
|
||||
return policy;
|
||||
}
|
||||
return { ...policy, allow: Array.from(new Set([...policy.allow, ...alsoAllow])) };
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user