35 lines
1010 B
TypeScript
35 lines
1010 B
TypeScript
import { RojoTool, RojoToolContext } from "./RojoTool";
|
|
import { ReadPathMetaTool } from "./ReadPathMetaTool";
|
|
import { GetTextContentTool } from "./GetTextContentTool";
|
|
import { WriteTextContentTool } from "./WriteTextContentTool";
|
|
import { ListFilesTool } from "./ListFilesTool";
|
|
import { CreateDirectoryTool } from "./CreateDirectoryTool";
|
|
|
|
export class RojoToolRegistry
|
|
{
|
|
static readonly All: RojoTool[] =
|
|
[
|
|
new ReadPathMetaTool(),
|
|
new GetTextContentTool(),
|
|
new WriteTextContentTool(),
|
|
new ListFilesTool(),
|
|
new CreateDirectoryTool(),
|
|
];
|
|
|
|
static definitions(): object[]
|
|
{
|
|
return RojoToolRegistry.All.map( t => t.Definition );
|
|
}
|
|
|
|
static async execute( name: string, args: Record<string, unknown>, ctx: RojoToolContext ): Promise<unknown>
|
|
{
|
|
const tool = RojoToolRegistry.All.find(
|
|
t => ( t.Definition as any ).function?.name === name
|
|
);
|
|
|
|
if ( !tool ) return { error: `Unknown tool: ${ name }` };
|
|
|
|
return tool.execute( args, ctx );
|
|
}
|
|
}
|