Class StreamingManager

Implements

Manages real-time data streams for AgentOS, handling client subscriptions and chunk distribution.

Implements

Constructors

Methods

  • Async

    Initializes the StreamingManager with its configuration. This method must be called successfully before any other operations.

    Parameters

    Returns Promise<void>

    A promise that resolves upon successful initialization.

    Throws

    If configuration is invalid or initialization fails.

  • Creates a new data stream and returns its unique ID.

    Parameters

    • Optional requestedStreamId: string

      Optional. If provided, attempts to use this ID. If not provided or if the ID already exists, a new unique ID will be generated.

    Returns Promise<string>

    A promise resolving to the unique ID of the created stream.

    Throws

    If the maximum number of concurrent streams is reached, or if a requestedStreamId is provided but already in use (and regeneration is not supported/fails).

  • Async

    Registers a client to a specific stream to receive data chunks.

    Parameters

    • streamId: string

      The ID of the stream to subscribe to.

    • client: IStreamClient

      The client instance that implements IStreamClient.

    Returns Promise<void>

    A promise that resolves when the client is successfully registered.

    Throws

    If the stream does not exist, if the client is already registered, or if the maximum number of clients for the stream is reached.

  • Async

    Deregisters a client from a specific stream. The client will no longer receive data chunks for this stream.

    Parameters

    • streamId: string

      The ID of the stream to unsubscribe from.

    • clientId: string

      The ID of the client to deregister.

    Returns Promise<void>

    A promise that resolves when the client is successfully deregistered.

    Throws

    If the stream or client does not exist within that stream.

  • Async

    Pushes a data chunk to all clients currently subscribed to the specified stream.

    Parameters

    • streamId: string

      The ID of the stream to push data to.

    • chunk: AgentOSResponse

      The data chunk to distribute.

    Returns Promise<void>

    A promise that resolves when the chunk has been pushed to all active clients of the stream (or attempted, based on onClientSendErrorBehavior).

    Throws

    If the stream does not exist, or if onClientSendErrorBehavior is 'throw' and a client send fails.

  • Async

    Closes a specific stream. All subscribed clients will be notified and subsequently deregistered. No further data can be pushed to a closed stream.

    Parameters

    • streamId: string

      The ID of the stream to close.

    • Optional reason: string

      An optional reason for closing the stream.

    Returns Promise<void>

    A promise that resolves when the stream is closed and clients are notified.

    Throws

    If the stream does not exist.

  • Async

    Handles an error that occurred on a specific stream. This might involve notifying clients with an error chunk and/or closing the stream.

    Parameters

    • streamId: string

      The ID of the stream where the error occurred.

    • error: Error

      The error object.

    • terminateStream: boolean = true

      If true, the stream will be closed after processing the error.

    Returns Promise<void>

    A promise that resolves when the error has been handled.

    Throws

    If the stream does not exist.

  • Async

    Gracefully shuts down the StreamingManager, closing all active streams and releasing any resources.

    Parameters

    • isReinitializing: boolean = false

    Returns Promise<void>

    A promise that resolves when shutdown is complete.

Properties

managerId: string