@struktoai/mirage-core
Version:
A Unified Virtual Filesystem For AI Agents
84 lines • 3.52 kB
TypeScript
import { Channel, type ConsoleChunk, type OwnedStream, type ReadResult } from './types.ts';
import type { ConsoleStore } from './store.ts';
/**
* Everything one job has printed, readable from any position.
*
* A job writes here as it runs, and any number of readers consume at
* their own pace. A reader's whole state is one number, so readers cost
* nothing, may join late, and may disappear without the console
* noticing.
*/
export declare class JobConsole {
private readonly backing;
private finishedFlag;
private execution;
get executionId(): string | null;
/** Associate this job's output with its one managed execution. */
bindExecution(executionId: string): void;
/**
* @param store where chunks live. Defaults to memory, which is the
* right home whenever the job and its readers share a process.
* @param finished whether the job has already ended, set when
* rebuilding a finished console from a snapshot.
*/
constructor(store?: ConsoleStore | null, finished?: boolean);
/**
* Where this console's chunks live. A job's console is the one its job
* store names, which every workspace on that store reads and ends.
*/
get store(): ConsoleStore;
/** Whether this process has seen the job end. */
get finished(): boolean;
/**
* Append output produced by the job.
*
* Ignored once the job has ended, so a runner still unwinding after a
* kill cannot append past the ending chunk and strand readers that
* already stopped following. Ignored too once the store is closed: the
* console was discarded, and a Redis store written after close would
* open a client that nothing quits.
*/
emit(channel: Channel, data: Uint8Array): Promise<void>;
/** Append output written to a stream a level owns; this console keeps it on its channel. */
emitTo(stream: OwnedStream, data: Uint8Array): Promise<void>;
/**
* Record how the job ended and release every waiting reader.
*
* Idempotent, so a job killed while it was already exiting does not
* get two endings.
*/
finish(outcome: string): Promise<void>;
/** Read chunks at or after a cursor. */
readFrom(seq: number, limit?: number): Promise<ReadResult>;
/** Yield chunks as they arrive, ending when the job does. */
follow(seq?: number): AsyncGenerator<ConsoleChunk>;
/**
* Resolve once the job has ended.
*
* Resolves on a closed store too, so a console discarded while someone
* was joining on it does not strand them, and once `signal` aborts, so
* an abandoned join stops reading.
*
* @param signal ends the wait early
*/
waitFinished(signal?: AbortSignal): Promise<void>;
/**
* How the job ended, or null while no ending is stored.
*
* Reads only the last chunk, wherever the store keeps it: a read past
* the end answers the console's length, and the ending is always the
* last chunk. This is how a workspace learns how another one's job
* ended.
*/
outcome(): Promise<string | null>;
/**
* Join everything the job has printed so far.
*
* With no channel, joins stdout and stderr in the order they were
* produced and omits the CONTROL chunk, which is status not output.
*/
snapshot(channel?: Channel | null): Promise<Uint8Array>;
/** Release the underlying store. */
close(): Promise<void>;
}
//# sourceMappingURL=job_console.d.ts.map