import type { ByteRange, FileInfo, StoredFile } from "../index.js"; import { FilesError } from "../internal/errors.js"; import type { JsonObject, JsonValue } from "../internal/json.js"; import type { GlobalCliOptions } from "./loader.js"; export interface OutputOpts { json: boolean; pretty: boolean; verbose: boolean; } /** The JSON shape a {@link FilesError} serializes to on the CLI/MCP boundary. */ export interface FilesErrorJson { aborted: boolean; code: FilesError["code"]; message: string; timedOut: boolean; } /** * `JSON.stringify` replacer that makes a {@link FilesError} serialize * usefully. A bare stringify drops `message` (a non-enumerable `Error` * property) while leaking the enumerable `cause` — the raw provider error, * which can carry request ids and headers the docs on {@link FilesError} * explicitly warn against shipping across a trust boundary. Bulk partial * failures embed live `FilesError`s in their `errors` arrays, so every * outward serialization goes through this. Every other value passes through * untouched, whatever its type. */ export declare const filesErrorReplacer: (_key: string, value: T) => T | FilesErrorJson; /** Stringify for output, with {@link filesErrorReplacer} applied. */ export declare const toJson: (data: T, pretty: boolean) => string; export declare const exitCode: (code: string) => number; /** Print a command result to stdout in the user's chosen format. */ export declare const emit: (data: T, out: OutputOpts) => void; export declare const fail: (cause: unknown, out: OutputOpts) => never; export interface BodySource { file?: string; stdin?: boolean; } export interface ResolvedBody { body: ReadableStream; /** Where the bytes came from, for messages: the file path or ``. */ hint: string; /** Byte length when known (a file); `-1` for stdin. */ size: number; } /** * Resolve a body source from CLI flags as a web ReadableStream — the adapter * decides whether to buffer or stream. Both stdin and file paths are * streamed; size is unknown for stdin and reported as `-1`. */ export declare const readBody: (source: BodySource) => Promise; /** * Write a downloaded body to a destination file or stdout. When piping to * stdout, no JSON envelope is emitted on stdout — agents calling * `download --stdout` want the bytes, not a wrapper. */ export declare const writeBody: (file: StoredFile, dest: { out?: string; stdout?: boolean; }) => Promise; /** * A web `ReadableStream` over a local file that opens the descriptor lazily — * only on the first read, never at construction. The bulk-upload path builds * one of these per file and hands them all to `files.upload(items)`; deferring * the open (via a zero high-water-mark, so nothing is pre-buffered) keeps the * number of simultaneously-open descriptors bounded by the SDK's upload * concurrency rather than by the file count — a directory of thousands of * files won't exhaust the process's fd limit. */ export declare const fileBodyStream: (absPath: string) => ReadableStream; export interface WalkedFile { absPath: string; /** Path relative to the walk root, always with `/` separators (an object key). */ key: string; } /** * Recursively list every regular file under `root`, returning each file's * absolute path and its `/`-separated key relative to `root`. Directories are * descended; symlinks and other special entries are skipped. The result is * sorted by key so a directory upload produces deterministic output. */ export declare const walkDir: (root: string) => Promise; /** * Write a downloaded {@link StoredFile} into `dir`, at the path its key * implies (`dir/`), creating intermediate directories. Refuses keys that * would escape `dir` (`../`, absolute) so a hostile or malformed key can't * write outside the chosen output directory. Returns the path written. */ export declare const writeBodyToDir: (file: StoredFile, dir: string) => Promise; export declare const parseKeyValuePairs: (pairs?: readonly string[]) => Record | undefined; /** * Parse a `--range` flag into a {@link ByteRange}. Mirrors the HTTP `Range` * header's `start-end` form (both bounds 0-based and inclusive): * * - `"0-99"` → `{ start: 0, end: 99 }` (first 100 bytes) * - `"100-"` → `{ start: 100 }` (byte 100 to EOF) * * Only the numeric `start-end` / `start-` shapes are accepted — suffix ranges * (`-500`) have no {@link ByteRange} representation. The SDK does the final * `start`/`end` validation, so this just rejects unparseable input loudly. */ export declare const parseRange: (raw?: string) => ByteRange | undefined; /** * Decode a JSON-valued flag. Returns the raw decoded value — callers narrow it * (`isJsonObject`) to the shape their flag expects — or `undefined` when the * flag was not passed. */ export declare const parseJson: (raw?: string, flag?: string) => JsonValue | undefined; /** * Decode a flag that must carry a JSON *object* (`--config-json`, `--to`). * `undefined` when the flag was not passed; a `FilesError` naming the flag * for malformed JSON or a non-object value. */ export declare const parseJsonObject: (raw: string | undefined, flag: string) => JsonObject | undefined; /** * Decode a flag carrying a whole provider configuration as JSON (`--to` on * transfer/sync/mcp) — the same flat shape as the global flags. */ export declare const parseProviderOptions: (raw: string, flag: string) => GlobalCliOptions; /** * The JSON projection of a {@link FileInfo} — what `head`, `list`, `search` * and `download` print. Built field by field, so a downloaded * {@link StoredFile}'s body accessors and `name`/`type` aliases never leak in. */ export interface FileInfoJson { contentType: string; etag?: string; key: string; lastModified?: number; metadata?: Record; size: number; } export declare const fileInfoToJson: (f: FileInfo) => FileInfoJson; //# sourceMappingURL=io.d.ts.map