continue-custom/core/tools/implementations/createNewFile.ts
Dallin Romney f2237c0399 cleanup
2025-04-04 17:10:24 -07:00

34 lines
1 KiB
TypeScript

import { inferResolvedUriFromRelativePath } from "../../util/ideUtils";
import { ToolImpl } from ".";
import { getCleanUriPath, getUriPathBasename } from "../../util/uri";
export const createNewFileImpl: ToolImpl = async (args, extras) => {
const resolvedFileUri = await inferResolvedUriFromRelativePath(
args.filepath,
extras.ide,
);
if (resolvedFileUri) {
const exists = await extras.ide.fileExists(resolvedFileUri);
if (exists) {
throw new Error(
`File ${args.filepath} already exists. Use the edit tool to edit this file`,
);
}
await extras.ide.writeFile(resolvedFileUri, args.contents);
await extras.ide.openFile(resolvedFileUri);
return [
{
name: getUriPathBasename(resolvedFileUri),
description: getCleanUriPath(resolvedFileUri),
content: "File created successfuly",
uri: {
type: "file",
value: resolvedFileUri,
},
},
];
} else {
throw new Error("Failed to resolve path");
}
};