bothy-sdk
    Preparing search index...

    Class Gateway

    One agent's gateway session with reconnects, as an async iterator of server frames.

    Nothing connects before Gateway.frames is iterated. Control frames (hello, heartbeat_ack) are handled when they arrive; the other frames wait for the consumer in arrival order.

    Index

    Constructors

    • Creates the gateway; nothing connects before Gateway.frames is iterated.

      Parameters

      • url: string

        The WebSocket URL (gatewayUrl).

      • credentials: Credentials

        The agent's API token and optional DPoP key.

      • options: GatewayOptions

        Consumer, agent ID, settings, clock, random, heartbeat source, User-Agent, nonce sink, WebSocket constructor and logger.

      Returns Gateway

      TypeError when url uses clear text off the loopback host.

    Properties

    agentId: string

    The agent's principal ID.

    clock: Clock

    The time source.

    closeReason: CloseReason | undefined

    Why the gateway stopped, once it has.

    connects: number = 0

    The number of opened connections.

    consumer: string

    The consumer name.

    settings: SdkSettings

    The resolved SDK settings.

    url: string

    The WebSocket URL (gatewayUrl).

    Accessors

    • get lastSeq(): number

      The highest acknowledged seq (the cursor of a resume).

      Returns number

    • get sessionId(): string | undefined

      The gateway session of the last ready, if any.

      Returns string | undefined

    Methods

    • Acknowledges every event up to seq (op ack, cumulative); without a connection the acknowledgement is dropped, the next one covers it.

      Parameters

      • seq: number

        The highest settled seq.

      Returns Promise<void>

      A promise that resolves once the frame is handed to the socket.

    • Returns the wait before reconnect attempt attempt: uniform in [0, min(sync.reconnect_backoff_cap, sync.reconnect_backoff_base * 2^attempt)].

      Parameters

      • attempt: number

        The attempt, from zero; ready and resumed reset it.

      Returns number

      The wait in milliseconds.

    • Closes with 1000; Gateway.frames ends without reconnecting.

      Returns Promise<void>

      A promise that resolves once the close is started.

    • Connects, keeps the session alive and yields every relevant server frame.

      The iterator reconnects after every close code that allows it and ends when the gateway stops; Gateway.closeReason then tells why. Breaking out of the loop closes the gateway.

      Returns AsyncGenerator<GatewayEvent, void, undefined>

      The server frames ready, resumed, dispatch, cursor, resync_required and error (with a GatewayOpError as model).

    • Sends the op command.autocomplete_result.

      Parameters

      • requestId: string

        The request of the command.autocomplete_requested event.

      • choices: readonly {}[]

        The choices.

      • Optionalref: string

        A reference the error frame repeats.

      Returns Promise<void>

      A promise that resolves once the frame is handed to the socket.

      TransportError when the gateway is not connected.

    • Sends the op run.update (no success reply; a failure comes as an error frame).

      Parameters

      • runId: string

        The run.

      • baseVersion: number

        The version the patch is based on.

      • ops: readonly {}[]

        The RFC 6902 operations.

      • Optionalref: string

        A reference the error frame repeats.

      Returns Promise<void>

      A promise that resolves once the frame is handed to the socket.

      TransportError when the gateway is not connected.