UNPKG

@struktoai/mirage-core

Version:

A Unified Virtual Filesystem For AI Agents

93 lines • 4.68 kB
import type { util } from 'zod'; import { ByteSpool } from '../../../io/spool.ts'; import type { IOResult } from '../../../io/types.ts'; import { type Served } from '../../../rs/stream.ts'; import { PathSpec } from '../../../types.ts'; import type { Context } from '../../config.ts'; /** * The files and commands a mirage-rs stream reaches, through the workspace. * An input opens on its first read. An operand still holding its * command-line spelling reads through the mount's own reader, the way it * was resolved, unless another mount serves it; every other name reads * through the dispatcher, as writes go through it. Every stdin reader (`-`, * `/dev/stdin` and a command run without input of its own) shares one * cursor, so none replays what another read. A write is held until the * stream flushes it. `dash`: an operand `-` names stdin (see `isStdin`); * `command`: the command a failed operand's line names, worded as * `fsErrorLine` words it, and that may create no file one of its operands * names, empty leaving both to the stream; * `local`: whether the mount serves an operand, every one by default, as it * resolved them. Mirrors Python's StreamHost. */ export declare class StreamHost { private readonly operands; private readonly stream; private readonly ctx; private readonly dash; private readonly command; private readonly local; readonly errors: ByteSpool; private readonly stdin; private readonly caller; private readonly inputs; private readonly named; private readonly spools; private readonly outputs; constructor(operands: readonly PathSpec[], stream: (p: PathSpec) => AsyncIterable<Uint8Array>, ctx: Context, dash?: boolean, command?: string, local?: (path: PathSpec) => boolean); stdinView(): AsyncIterable<Uint8Array>; /** Read a file; `local`: an operand this mount's backend serves. */ private readPath; /** * Open an input by name: `-` or `/dev/stdin` is stdin; `operand` is the * operand, from 1, the name came from; `file` is a file a script names, * which no spelling of stdin stands for; `asOperand` is a name standing in * for an operand (unzip's `X.zip` for `X`), read as an operand is. */ openInput(name: string, operand: number | null, file?: boolean, asOperand?: boolean): AsyncIterable<Uint8Array>; /** The operand a name is, when it still holds its spelling. */ private operand; /** Commit one file's writes, or every file's; the first failure stops it, and its reply, naming the file, is returned. */ flushOutput(name?: string): Promise<Record<string, util.JSONType> | null>; /** Do one request a stream makes. */ serve(request: Readonly<Record<string, util.JSONType>>, data: Uint8Array): Promise<Served>; /** * The input a read or a fill opens: an operand, a name, or a spool past its * first `skip` bytes, where nothing spooled reads as empty. */ private open; /** * A failed input's reply, or a throw for what is not the file's own: the * failure's words, and the line the command words for an operand. */ private failed; /** Read an input whole into spool `into` and answer its length. */ private fill; private read; /** * Write to a file: `append` adds to it, otherwise it is emptied first, * every held write committed before; `atomic` replaces it whole, once * flushed, with what this and later writes carry, and `create` writes it * whole as they carry it, `whole` from this write's bytes alone; `spool` * writes that spool's bytes past its first `skip` and drops it, or, with * `size`, that many of them and keeps it, with `create` the file whole * from them. */ private write; /** Unlink, make (one level) or stat a path; a stat answers what stands there, `dir` or `file`, or why it found nothing. */ private pathOp; /** * Run a command line in a subshell of the session, as sh -c would; `eval` * takes the line whole, so an empty one, a comment or a line ending in a * backslash runs as `sh -c` would run it. */ private run; /** Let go of every input, spool and uncommitted write. */ close(): Promise<void>; } /** * Run a stream that reaches files through `host`, yielding its output as it * settles; output closed early still lets what it wrote to its files land. * Mirrors Python's `hosted_stream`. */ export declare function hostedStream(kind: string, config: Readonly<Record<string, util.JSONType>>, host: StreamHost, io: IOResult, signal?: AbortSignal): AsyncIterable<Uint8Array>; //# sourceMappingURL=stream_host.d.ts.map