diff options
Diffstat (limited to 'src/domains/files.ts')
| -rw-r--r-- | src/domains/files.ts | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/src/domains/files.ts b/src/domains/files.ts index f0cb6b0..91f8761 100644 --- a/src/domains/files.ts +++ b/src/domains/files.ts @@ -1,4 +1,4 @@ -import { access, constants, stat, readFile, writeFile } from "node:fs/promises"; +import { mkdir, access, constants, stat, readFile, writeFile } from "node:fs/promises"; import { basename } from "node:path"; import { Type } from "typebox"; import type { BrowserClient } from "../client"; @@ -136,6 +136,14 @@ export const downloadTool = defineBrowserTool({ parameters: DownloadArgs, async handler(args, { client }): Promise<Result<ToolOk, ToolErr>> { try { + await mkdir(args.downloadPath, { recursive: true }); + } catch (e) { + return err({ + kind: "io_error", + message: `Cannot create download directory: ${args.downloadPath} (${e instanceof Error ? e.message : String(e)})`, + }); + } + try { const s = await stat(args.downloadPath); if (!s.isDirectory()) { return err({ kind: "io_error", message: `Not a directory: ${args.downloadPath}` }); |
