Skip to content

Interface: PubSubAdapter

@providerprotocol/ai


@providerprotocol/ai / middleware/pubsub / PubSubAdapter

Defined in: src/middleware/pubsub/types.ts:56

Storage adapter interface for pub-sub middleware.

Stores in-flight streams only. Completed streams are removed immediately. Apps should persist completed conversations via .then() and serve from their own storage on reconnect.

append(streamId, event): Promise<void>

Defined in: src/middleware/pubsub/types.ts:65

Appends an event to the stream (creates lazily if needed).

string

StreamEvent

Promise<void>


clear(streamId): Promise<void>

Defined in: src/middleware/pubsub/types.ts:104

Clears all events for a stream without removing it. Used during retry to reset accumulated state.

string

Promise<void>


exists(streamId): Promise<boolean>

Defined in: src/middleware/pubsub/types.ts:60

Checks if a stream exists.

string

Promise<boolean>


getCursorBase(streamId): number

Defined in: src/middleware/pubsub/types.ts:112

Gets the current cursor base for a stream. After a clear, cursor base increases so new events have higher cursors than any events sent before the clear.

string

number

Cursor base, or 0 if stream doesn’t exist or hasn’t been cleared


getEvents(streamId): Promise<StreamEvent[]>

Defined in: src/middleware/pubsub/types.ts:70

Fetches all events for replay.

string

Promise<StreamEvent[]>


publish(streamId, event): void

Defined in: src/middleware/pubsub/types.ts:87

Publishes event to all subscribers.

string

StreamEvent

void


remove(streamId): Promise<void>

Defined in: src/middleware/pubsub/types.ts:98

Notifies subscribers and removes stream from storage.

string

Promise<void>


setFinalData(streamId, data): void

Defined in: src/middleware/pubsub/types.ts:93

Sets final data to be sent to subscribers before completion. Typically used to send the serialized Turn.

string

unknown

void


subscribe(streamId, onEvent, onComplete, onFinalData?): Unsubscribe

Defined in: src/middleware/pubsub/types.ts:77

Subscribes to live events (creates lazily if needed).

string

SubscriptionCallback

CompletionCallback

FinalDataCallback

Optional callback for final data (Turn) before completion

Unsubscribe