refactor(agent): extract block chunker + tool adapter

This commit is contained in:
Peter Steinberger
2026-01-05 18:05:40 +00:00
parent 7c89ce93b5
commit 86ad703f53
4 changed files with 361 additions and 315 deletions

View File

@@ -0,0 +1,31 @@
import type {
AgentTool,
AgentToolResult,
AgentToolUpdateCallback,
} from "@mariozechner/pi-agent-core";
import type { ToolDefinition } from "@mariozechner/pi-coding-agent";
// biome-ignore lint/suspicious/noExplicitAny: TypeBox schema type from pi-agent-core uses a different module instance.
type AnyAgentTool = AgentTool<any, unknown>;
export function toToolDefinitions(tools: AnyAgentTool[]): ToolDefinition[] {
return tools.map((tool) => {
const name = tool.name || "tool";
return {
name,
label: tool.label ?? name,
description: tool.description ?? "",
// biome-ignore lint/suspicious/noExplicitAny: TypeBox schema from pi-agent-core uses a different module instance.
parameters: tool.parameters as any,
execute: async (
toolCallId,
params,
onUpdate: AgentToolUpdateCallback<unknown> | undefined,
_ctx,
signal,
): Promise<AgentToolResult<unknown>> => {
return tool.execute(toolCallId, params, signal, onUpdate);
},
} satisfies ToolDefinition;
});
}