mirror of
https://github.com/badlogic/pi-mono.git
synced 2026-11-05 23:37:25 +00:00
34 lines
1.3 KiB
TypeScript
34 lines
1.3 KiB
TypeScript
/**
|
|
* Tool wrappers for extension-registered tools.
|
|
*
|
|
* These wrappers only adapt tool execution so extension tools receive the runner context.
|
|
* Tool call and tool result interception is handled by AgentSession via agent-core hooks.
|
|
*/
|
|
|
|
import type { AgentTool } from "@mariozechner/pi-agent-core";
|
|
import type { ExtensionRunner } from "./runner.js";
|
|
import type { RegisteredTool } from "./types.js";
|
|
|
|
/**
|
|
* Wrap a RegisteredTool into an AgentTool.
|
|
* Uses the runner's createContext() for consistent context across tools and event handlers.
|
|
*/
|
|
export function wrapRegisteredTool(registeredTool: RegisteredTool, runner: ExtensionRunner): AgentTool {
|
|
const { definition } = registeredTool;
|
|
return {
|
|
name: definition.name,
|
|
label: definition.label,
|
|
description: definition.description,
|
|
parameters: definition.parameters,
|
|
execute: (toolCallId, params, signal, onUpdate) =>
|
|
definition.execute(toolCallId, params, signal, onUpdate, runner.createContext()),
|
|
};
|
|
}
|
|
|
|
/**
|
|
* Wrap all registered tools into AgentTools.
|
|
* Uses the runner's createContext() for consistent context across tools and event handlers.
|
|
*/
|
|
export function wrapRegisteredTools(registeredTools: RegisteredTool[], runner: ExtensionRunner): AgentTool[] {
|
|
return registeredTools.map((rt) => wrapRegisteredTool(rt, runner));
|
|
}
|