/** * CustomToolAdapter wraps CustomTool instances into AgentTool for use with the agent. */ import type { AgentTool, AgentToolUpdateCallback } from "@gajae-code/agent-core"; import type { Static, TSchema } from "@gajae-code/ai/core"; import type { Theme } from "../../modes/theme/theme"; import { applyToolProxy } from "../tool-proxy"; import type { CustomTool, CustomToolContext } from "./types"; export class CustomToolAdapter implements AgentTool { declare name: string; declare label: string; declare description: string; declare parameters: TParams; readonly strict: boolean | undefined; readonly concurrency: "shared" | "exclusive" | undefined; constructor( private tool: CustomTool, private getContext: () => CustomToolContext, ) { applyToolProxy(tool, this); this.strict = tool.strict; this.concurrency = tool.concurrency; } execute( toolCallId: string, params: Static, signal?: AbortSignal, onUpdate?: AgentToolUpdateCallback, 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( tool: CustomTool, getContext: () => CustomToolContext, ): AgentTool { return new CustomToolAdapter(tool, getContext); } }