PAIPAI

createRedisThreadLiveProvider()

Cross-process live events for watch() when more than one Node process serves threads.

@pai/realtime is the provider contract. Production apps use @pai/realtime-redis. This is not durable storage and not the browser transport.

Pair with createPai({ live: { mode: "distributed" } }). Distributed mode requires a realtime provider: it is the only way watches learn about writes from other processes.

import { createRedisThreadLiveProvider } from "@pai/realtime-redis";

const realtime = createRedisThreadLiveProvider({
  url: process.env.REDIS_URL!,
  prefix: "pai:production",
});
await realtime.connect();

export const pai = createPai({
  agents: { main: assistantAgent },
  scopeKey: (identity) => identity.workspaceId,
  realtime,
  live: { mode: "distributed" },
});

Await connect() at startup before accepting traffic.

Import

import { createRedisThreadLiveProvider } from "@pai/realtime-redis";

Signature

function createRedisThreadLiveProvider(options: {
  url: string;
  prefix?: string;
  streamTtlSeconds?: number;
  streamTtlRefreshIntervalSeconds?: number;
}): ThreadLiveProvider & { connect(): Promise<void>; close(): Promise<void> };

Parameters

options: RedisThreadLiveProviderOptions

url: string

Redis connection URL. The provider owns its node-redis clients.

prefix?: string

Isolate environments.

Defaults to pai:realtime.

streamTtlSeconds?: number

Seconds to retain generation stream buffers after the last write.

Defaults to 1200.

streamTtlRefreshIntervalSeconds?: number

How often to refresh stream TTLs while a generation is live.

Returns

A ThreadLiveProvider & { connect(): Promise<void>; close(): Promise<void> }.

Await connect() at boot. createPai does not connect Redis for you.

createInMemoryThreadLiveProvider()

Tests. No options.

import { createInMemoryThreadLiveProvider } from "@pai/realtime-inmemory";

const realtime = createInMemoryThreadLiveProvider();

Learn more

On this page