import { createHash, randomUUID } from "node:crypto";
import { mkdirSync, writeFileSync } from "node:fs";
import { join } from "node:path";
export class MemoryArtifactStore {
    artifactDir;
    constructor(options) {
        this.artifactDir = options.artifactDir;
    }
    writeTextArtifact(content, options) {
        mkdirSync(this.artifactDir, { recursive: true });
        const id = randomUUID();
        const extension = options?.extension ?? "txt";
        const path = join(this.artifactDir, `${id}.${extension}`);
        const bytes = Buffer.byteLength(content, "utf-8");
        const sha256 = createHash("sha256").update(content).digest("hex");
        writeFileSync(path, content, "utf-8");
        return {
            id,
            path,
            bytes,
            sha256,
            mimeType: options?.mimeType ?? "text/plain",
            createdAt: new Date().toISOString(),
        };
    }
}
export function shouldArtifactMemoryContent(content, thresholdBytes = 16 * 1024) {
    return Buffer.byteLength(content, "utf-8") > thresholdBytes;
}
export function summarizeArtifactedContent(content, ref) {
    const lineCount = content.split(/\r?\n/).length;
    return `[artifact ${ref.id}: ${ref.bytes} bytes, ${lineCount} lines, sha256 ${ref.sha256.slice(0, 12)}, path ${ref.path}]`;
}
//# sourceMappingURL=content-ref.js.map