Files
oh-my-pi/packages/coding-agent/src/extensibility/custom-tools/wrapper.ts
T
can1357 2867e1f4e3 feat(deps): added pi.zod exports and removed TypeBox package exports
- Added canonical `pi.zod` schema API exports and removed TypeBox package exports/imports.
- Migrated Tool schema typing from TypeBox to shared `TSchema`/Zod flow with legacy TypeBox compatibility.
- Updated AI provider adapters and MCP/agent builders to convert tool params through `toolWireSchema()`.
- Reworked schema validation from AJV to Zod-safe parsing with `fromTypeBox`, `toolWireSchema`, and meta schema checks.
2026-05-15 14:46:54 +02:00

48 lines
1.5 KiB
TypeScript

/**
* CustomToolAdapter wraps CustomTool instances into AgentTool for use with the agent.
*/
import type { AgentTool, AgentToolUpdateCallback } from "@oh-my-pi/pi-agent-core";
import type { Static, TSchema } from "@oh-my-pi/pi-ai";
import type { Theme } from "../../modes/theme/theme";
import { applyToolProxy } from "../tool-proxy";
import type { CustomTool, CustomToolContext } from "./types";
export class CustomToolAdapter<TParams extends TSchema = TSchema, TDetails = any, TTheme extends Theme = Theme>
implements AgentTool<TParams, TDetails, TTheme>
{
declare name: string;
declare label: string;
declare description: string;
declare parameters: TParams;
readonly strict: boolean | undefined;
constructor(
private tool: CustomTool<TParams, TDetails>,
private getContext: () => CustomToolContext,
) {
applyToolProxy(tool, this);
this.strict = tool.strict;
}
execute(
toolCallId: string,
params: Static<TParams>,
signal?: AbortSignal,
onUpdate?: AgentToolUpdateCallback<TDetails, TParams>,
context?: CustomToolContext,
) {
return this.tool.execute(toolCallId, params, onUpdate, context ?? this.getContext(), signal);
}
/**
* Backward-compatible export of factory function for existing callers.
* Prefer CustomToolAdapter constructor directly.
*/
static wrap<TParams extends TSchema = TSchema, TDetails = any, TTheme extends Theme = Theme>(
tool: CustomTool<TParams, TDetails>,
getContext: () => CustomToolContext,
): AgentTool<TParams, TDetails, TTheme> {
return new CustomToolAdapter(tool, getContext);
}
}