refactor(agent): extract block chunker + tool adapter
This commit is contained in:
31
src/agents/pi-tool-definition-adapter.ts
Normal file
31
src/agents/pi-tool-definition-adapter.ts
Normal 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;
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user