Agents: validate persisted tool-call names

This commit is contained in:
Vignesh Natarajan
2026-02-21 23:06:44 -08:00
parent 29a782b9cd
commit cdfe45eeb8
11 changed files with 248 additions and 8 deletions

View 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;
}