Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

694 B
Raw Blame
import { FsSafeError } from "./errors.js";
export async function readOpenedFileSafely(params) {
    if (params.maxBytes !== undefined && params.opened.stat.size > params.maxBytes) {
        throw new FsSafeError("too-large", `file exceeds limit of ${params.maxBytes} bytes (got ${params.opened.stat.size})`);
    }
    const buffer = await params.opened.handle.readFile();
    if (params.maxBytes !== undefined && buffer.byteLength > params.maxBytes) {
        throw new FsSafeError("too-large", `file exceeds limit of ${params.maxBytes} bytes (got ${buffer.byteLength})`);
    }
    return {
        buffer,
        realPath: params.opened.realPath,
        stat: params.opened.stat,
    };
}