fix(coding-agent): built-in tools work like extension tools
Export readToolDefinition / createReadToolDefinition and the equivalent built-in ToolDefinition APIs from @mariozechner/pi-coding-agent.
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
import type { AgentTool } from "@mariozechner/pi-agent-core";
|
||||
import type { ExtensionContext, ToolDefinition } from "../extensions/types.js";
|
||||
|
||||
/** Wrap a ToolDefinition into an AgentTool for the core runtime. */
|
||||
export function wrapToolDefinition<TDetails = unknown>(
|
||||
definition: ToolDefinition<any, TDetails>,
|
||||
ctxFactory?: () => ExtensionContext,
|
||||
): AgentTool<any, TDetails> {
|
||||
return {
|
||||
name: definition.name,
|
||||
label: definition.label,
|
||||
description: definition.description,
|
||||
parameters: definition.parameters,
|
||||
execute: (toolCallId, params, signal, onUpdate) =>
|
||||
definition.execute(toolCallId, params, signal, onUpdate, ctxFactory?.() as ExtensionContext),
|
||||
};
|
||||
}
|
||||
|
||||
/** Wrap multiple ToolDefinitions into AgentTools for the core runtime. */
|
||||
export function wrapToolDefinitions(
|
||||
definitions: ToolDefinition<any, any>[],
|
||||
ctxFactory?: () => ExtensionContext,
|
||||
): AgentTool<any>[] {
|
||||
return definitions.map((definition) => wrapToolDefinition(definition, ctxFactory));
|
||||
}
|
||||
|
||||
/**
|
||||
* Synthesize a minimal ToolDefinition from an AgentTool.
|
||||
*
|
||||
* This keeps AgentSession's internal registry definition-first even when a caller
|
||||
* provides plain AgentTool overrides that do not include prompt metadata or renderers.
|
||||
*/
|
||||
export function createToolDefinitionFromAgentTool(tool: AgentTool<any>): ToolDefinition<any, unknown> {
|
||||
return {
|
||||
name: tool.name,
|
||||
label: tool.label,
|
||||
description: tool.description,
|
||||
parameters: tool.parameters as any,
|
||||
execute: async (toolCallId, params, signal, onUpdate) => tool.execute(toolCallId, params, signal, onUpdate),
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user