37 lines
915 B
TypeScript
37 lines
915 B
TypeScript
|
|
import fs from "fs";
|
||
|
|
import { RojoTool, RojoToolContext } from "./RojoTool.js";
|
||
|
|
import { resolveProjectPath } from "../../storage.js";
|
||
|
|
|
||
|
|
export class CreateDirectoryTool extends RojoTool
|
||
|
|
{
|
||
|
|
readonly Definition =
|
||
|
|
{
|
||
|
|
type: "function",
|
||
|
|
function:
|
||
|
|
{
|
||
|
|
name: "create_directory",
|
||
|
|
description: "Create a directory and any missing parent directories at the given path.",
|
||
|
|
parameters:
|
||
|
|
{
|
||
|
|
type: "object",
|
||
|
|
properties:
|
||
|
|
{
|
||
|
|
path: { type: "string", description: "Path relative to the project root." },
|
||
|
|
},
|
||
|
|
required: [ "path" ],
|
||
|
|
},
|
||
|
|
},
|
||
|
|
};
|
||
|
|
|
||
|
|
async execute( args: Record<string, unknown>, ctx: RojoToolContext ): Promise<unknown>
|
||
|
|
{
|
||
|
|
const full = resolveProjectPath( ctx.projectId, args.path as string );
|
||
|
|
|
||
|
|
if ( !full ) return { error: "Invalid path" };
|
||
|
|
|
||
|
|
fs.mkdirSync( full, { recursive: true } );
|
||
|
|
|
||
|
|
return { ok: true };
|
||
|
|
}
|
||
|
|
}
|