A11 TypeScript API - v0.7.0
    Preparing search index...

    Class AsyncNode

    One ordered, typed value sequence flowing through an A11 application.

    Action inputs and outputs are AsyncNodes. The writer serializes application values into sequenced chunks, persists them through a ChunkStore, and optionally tees stored fragments over a wire stream. The reader follows that same ordered log and deserializes values as they arrive, so an agent can expose tokens, audio frames, tool events, or a unary result through one protocol.

    End the sequence with finalize: it marks the logical end of the data and closes storage. Finality and closure remain two distinct facts -- see the AsyncNode lifecycle guide -- and close is the rarer half on its own, for a producer that cannot say which chunk was last. Failures should use abortWithStatus so local and remote readers see why the sequence ended.

    const node = valueOrThrow(await AsyncNode.create('tokens'));
    valueOrThrow(await node.put('Hello'));
    valueOrThrow(await node.finalize(' world'));
    for await (const token of node) console.log(token);
    Index
    chunkStore: ChunkStore

    Ordered storage shared by the node's reader and writer.

    nodeMap: NodeMap | null

    Owning node map, or null for a standalone node.

    • Iterate typed values until finality, closure, or failure.

      Returns AsyncGenerator<unknown, void, void>

    • Flush queued writes and close the writer, marking nothing final.

      The specialised half of finalize: closure without finality, for a producer that cannot say which chunk was the last one -- a log, say -- but can say that no more are coming. Closing always drains.

      Returns Promise<Status>

    • Consume and deserialize exactly one whole unary value.

      Type Parameters

      • T = unknown

      Parameters

      • options: {
            allowNone?: boolean;
            expectedTag?: string;
            mimetypePatterns?: string | readonly string[];
            raw?: "fragment" | "chunk";
            timeoutMs?: number;
        } = {}

      Returns Promise<StatusOr<Chunk | NodeFragment | T | null>>

    • Read one chunk and require the stream to contain no second value.

      Parameters

      • options: { allowNone?: boolean; timeoutMs?: number } = {}

      Returns Promise<StatusOr<Chunk | null>>

    • Consume exactly one whole value's fragment and validate its terminator. Use this for unary action ports; streaming ports should call next.

      Parameters

      • options: { allowNone?: boolean; timeoutMs?: number } = {}

      Returns Promise<StatusOr<NodeFragment | null>>

    • End the sequence: mark the logical end of the data, and close the writer.

      The one call an ordinary producer needs. value is written as the final fragment; omitting it (or passing null/undefined) writes a null terminator instead, which is the form to use once the last visible value has already gone out with put. Unless close is false the writer is closed too, so readers waiting for data that can no longer arrive are released and a peer's mirror of the node closes as well.

      It does not wait: the write and the close are carried out by the writer's own pump, so a producer can finalise and move on. Nothing is swallowed -- a failed write or close is reported through getWriterStatus. Pass wait: true to resolve only once the store has confirmed both.

      Parameters

      • Optionalvalue: unknown
      • options: { close?: boolean; mimetype?: string; seq?: number | null; wait?: boolean } = {}

      Returns Promise<Status>

    • Read one value, or null at finality, clean closure, or the reader limit.

      Type Parameters

      • T = unknown

      Parameters

      • optionsOrTimeout:
            | number
            | {
                expectedTag?: string;
                mimetypePatterns?: string
                | readonly string[];
                timeoutMs?: number;
            } = {}

      Returns Promise<StatusOr<T | null>>

    • Read the next inline chunk without deserializing its payload.

      Parameters

      • OptionaltimeoutMs: number

      Returns Promise<StatusOr<Chunk | null>>

    • Serialize and persist one application value, respecting writer backpressure.

      Parameters

      • value: unknown
      • options: { final?: boolean; mimetype?: string; seq?: number | null } = {}

      Returns Promise<StatusOr<number>>

    • Persist a raw chunk, optionally at an explicit sequence and/or as final.

      Parameters

      • chunk: Chunk
      • seq: number | null = null
      • final: boolean = false

      Returns Promise<StatusOr<number>>

    • Set default MIME/type constraints for subsequent typed reads.

      Parameters

      • mimetypePatterns: string | readonly string[] = ''
      • OptionalexpectedTag: string

      Returns Status

    • Iterate to the clean reader end, yielding at most one terminal error.

      Type Parameters

      • T = unknown

      Parameters

      • options: {
            expectedTag?: string;
            mimetypePatterns?: string | readonly string[];
            timeoutMs?: number;
        } = {}

      Returns AsyncGenerator<StatusOr<T>, void, void>