/** * Verbatim file bytes: from the session filesystem, in bounded windows, to * Harness's durable attachment store. * * The whole point of this module is the shape of the read. A generic file has * no size policy and no type policy — the adopted attachment contract says so * explicitly, because its storage is streamed and its content is consumed * lazily — so the one thing this frontend still had to decide was how to get * bytes into that stream without itself becoming a second file store. It reads * fixed-size windows through `FileSystem.readByteRange` and hands the store an * async iterable, which keeps the peak memory this process holds for a file * at one window rather than at the file's size. * * Everything the bytes pass through on the way is Harness's: the bytes are read * only through `ctx.fs`, so a remote or sandboxed backend is the one that * decides what the path means, and they are durably committed only through * `ctx.attachments`. `node:fs` is deliberately absent — its `createReadStream` * would bypass the filesystem seam entirely and work only for a host-local * profile, which is exactly the deployment this feature must not be limited to. * @module dshline/file-admission */ import type { AttachmentStore, FileAttachmentRef } from '@deepseek-ai/dsh-attachment'; import type { FileSystem } from '@deepseek-ai/dsh-fs'; import type { FileDraft } from './attachment-drafts.ts'; /** * Bytes requested per `readByteRange` window. * * A memory bound on THIS process, not a file-size policy: nothing is refused * for being larger, and the store still decides what it admits. 256 KiB is * chosen so a multi-megabyte log costs a few hundred windows rather than * hundreds of thousands, while the peak this process holds stays small next to * the provider's own staging buffer — a much larger window would buy nothing * once the copy inside `saveFileStream` is counted, and a much smaller one * turns a large upload into a round-trip storm against a remote filesystem. */ export declare const FILE_CHUNK_BYTES: number; /** * Refusals this module raises itself, in the vocabulary `FsError` already * established. * * They are a local class rather than `FsError` for the same reason the image * read path invents `IMAGE_BATCH_TOO_LARGE` rather than borrowing one: routing * reads `code`, and importing the filesystem package as a value would make a * profile that mounts no filesystem load it to read a draft. `FileSystem` is * still a type-only import here, so the module compiles to code that touches * only the two capability objects it is handed. */ export type FileDraftErrorCode = 'FS_NOT_FOUND' | 'FS_NOT_REGULAR_FILE' | 'FILE_CHANGED_DURING_ATTACHMENT'; /** One refusal raised by dshline's own file-admission path. */ export declare class FileDraftError extends Error { readonly code: FileDraftErrorCode; /** * @param code - the stable routing code, shared with `FsErrorCode` where one exists. * @param message - dshline's own description, never a provider or host path. */ constructor(code: FileDraftErrorCode, message: string); } /** * Read one staged file and durably commit it, byte for byte. * * The whole path is `resolve` → `stat` → streamed windows → `saveFileStream` → * `stat` again. The second `stat` is not optional bookkeeping: * `readByteRange` carries no version precondition, so nothing in the adopted * filesystem contract stops the file being rewritten between the first `stat` * and the last window. Comparing `FsInfo.version` around the stream is the only * evidence available that the bytes stored are the bytes that were there when * this submission started, and a mismatch is reported rather than sent — an * object may already have been published, and that is Harness's retention to * collect; there is no rollback to invent here. * @param draft - the staged path and its display name. * @param fs - the current session's filesystem authority. * @param attachments - the current session's durable attachment store. * @param cwd - the current session workspace, for relative paths. * @param signal - cancellation shared by resolution, reads, and the store. * @param chunkBytes - window size; {@link FILE_CHUNK_BYTES} is the default. * @returns the durable, content-addressed reference Harness recorded. * @throws FileDraftError when the path is absent, is not a regular file, or * changed while it was being attached. */ export declare function admitFileDraft(draft: FileDraft, fs: FileSystem, attachments: AttachmentStore, cwd: string, signal: AbortSignal, chunkBytes?: number): Promise; /** * A failure the attachment capability authored, and the words it used. * * The adopted attachment error class documents its message as carrying no raw * bytes and no host paths, so a failure it authored can be printed exactly as * written. That is how a storage fault has always been reported, and flattening * one into "could not be read" would throw away a diagnostic that names the * actual fault. * * Whether a failure IS an attachment failure is not decided here, and this * function used to be where it was: it kept a local copy of the whole published * `AttachmentErrorCode` union, which made a frontend the authority on a * vocabulary Harness owns and would have silently misclassified every code added * after the copy was taken — a new upstream code would have fallen through to * the filesystem wording, reporting a storage fault as an unreadable file. The * store's own `isAttachmentError` is asked instead, which is the same call * upstream's own `FileUploads.commit()` makes, and a failure it recognises is * shown whatever its code happens to be. * @param error - an admission failure. * @param attachments - the store that owns attachment-error identity. * @returns the authored message, or undefined when the failure is not one of ours. */ export declare function attachmentAuthoredMessage(error: unknown, attachments: AttachmentStore): string | undefined; /** * Path-free presentation for a failure raised while admitting a staged file. * * `FsError` messages may spell an absolute user path, and a file is far more * likely than an image to be named by one, so every branch here is a sentence * about the condition rather than about the path. * * `ATTACHMENT_FILES_UNSUPPORTED` is the one that matters most, because it is * not really a failure: it is the adopted base class answering a backend that * was never written to store files, and a profile without verbatim file * storage must still start, stage, and prompt normally. Its sentence is * specific rather than the class's own wording because the class describes * itself, and what a reader needs to know is which profile they are in. * * This switch names a handful of codes it can say something better about. It is * not the attachment-error test — {@link attachmentAuthoredMessage} is, and it * asks the store — so a code absent from this list is still classified * correctly upstream of here, it simply falls through to the store's own words. * * `undefined` means "no sentence here", which sends the caller on to * {@link attachmentAuthoredMessage} for a Harness-authored storage diagnostic. * @param error - an admission failure. * @returns a path-free sentence, or undefined when the failure is not one of ours. */ export declare function fileAttachmentFailure(error: unknown): string | undefined; //# sourceMappingURL=file-admission.d.ts.map