rojects/source/server/rojos/tools/WriteTextContentTool.ts

35 lines
977 B
TypeScript

import { RojoTool, RojoToolContext } from "./RojoTool.js";
import { writeProjectFile } from "../../storage.js";
export class WriteTextContentTool extends RojoTool
{
readonly Definition =
{
type: "function",
function:
{
name: "write_text_content",
description: "Write text content to a file, creating it if it does not exist or overwriting it if it does.",
parameters:
{
type: "object",
properties:
{
path: { type: "string", description: "Path relative to the project root." },
text: { type: "string", description: "The text content to write." },
},
required: [ "path", "text" ],
},
},
};
async execute( args: Record<string, unknown>, ctx: RojoToolContext ): Promise<unknown>
{
const ok = writeProjectFile( ctx.projectId, args.path as string, args.text as string );
if ( !ok ) return { error: "Could not write file" };
return { ok: true };
}
}