mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 05:27:39 +00:00
Agents: validate persisted tool-call names
This commit is contained in:
26
src/agents/pi-embedded-runner/tool-name-allowlist.ts
Normal file
26
src/agents/pi-embedded-runner/tool-name-allowlist.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import type { AgentTool } from "@mariozechner/pi-agent-core";
|
||||
import type { ClientToolDefinition } from "./run/params.js";
|
||||
|
||||
function addName(names: Set<string>, value: unknown): void {
|
||||
if (typeof value !== "string") {
|
||||
return;
|
||||
}
|
||||
const trimmed = value.trim();
|
||||
if (trimmed) {
|
||||
names.add(trimmed);
|
||||
}
|
||||
}
|
||||
|
||||
export function collectAllowedToolNames(params: {
|
||||
tools: AgentTool[];
|
||||
clientTools?: ClientToolDefinition[];
|
||||
}): Set<string> {
|
||||
const names = new Set<string>();
|
||||
for (const tool of params.tools) {
|
||||
addName(names, tool.name);
|
||||
}
|
||||
for (const tool of params.clientTools ?? []) {
|
||||
addName(names, tool.function?.name);
|
||||
}
|
||||
return names;
|
||||
}
|
||||
Reference in New Issue
Block a user