import type { Lock, Logger, QueueEntry, StateAdapter } from "chat"; import type { ConvexClient, ConvexHttpClient } from "convex/browser"; import type { FunctionReference } from "convex/server"; /** * Supported Convex clients. Both ship with `.mutation(ref, args, opts?)` and * `.query(ref, args)` signatures that the adapter relies on. The union is * strict — we don't accept just any shape-compatible object, so breaking * changes in Convex's client API surface here at compile time. */ export type ConvexClientLike = ConvexClient | ConvexHttpClient; type Ref, Ret> = FunctionReference; type KP = { keyPrefix: string; }; type WithThread = KP & { threadId: string; }; type WithKey = KP & { cacheKey: string; }; /** * Shape of the wrapper mutations/queries the user exports from their * `convex/chatState.ts`. Pass `api.chatState` as `api` to the adapter. * See `convex-chatState.template.ts` in this package for the exact file. */ export interface ChatStateApi { subscribe: Ref<"mutation", WithThread, null>; unsubscribe: Ref<"mutation", WithThread, null>; isSubscribed: Ref<"query", WithThread, boolean>; acquireLock: Ref<"mutation", WithThread & { ttlMs: number; token: string; }, { threadId: string; token: string; expiresAt: number; } | null>; releaseLock: Ref<"mutation", WithThread & { token: string; }, null>; forceReleaseLock: Ref<"mutation", WithThread, null>; extendLock: Ref<"mutation", WithThread & { token: string; ttlMs: number; }, boolean>; kvGet: Ref<"query", WithKey, string | null>; kvSet: Ref<"mutation", WithKey & { value: string; ttlMs?: number; }, null>; kvSetIfNotExists: Ref<"mutation", WithKey & { value: string; ttlMs?: number; }, boolean>; kvDelete: Ref<"mutation", WithKey, null>; appendToList: Ref<"mutation", KP & { listKey: string; value: string; maxLength?: number; ttlMs?: number; }, null>; getList: Ref<"query", KP & { listKey: string; }, string[]>; enqueue: Ref<"mutation", WithThread & { value: string; expiresAt: number; maxSize: number; }, number>; dequeue: Ref<"mutation", WithThread, { value: string; expiresAt: number; } | null>; queueDepth: Ref<"query", WithThread, number>; } export interface ConvexStateAdapterOptions { /** Convex client (ConvexHttpClient or ConvexClient). */ client: ConvexClientLike; /** Reference to your exported wrapper functions, typically `api.chatState`. */ api: ChatStateApi; /** Namespace for all rows. Default: `"chat-sdk"`. */ keyPrefix?: string; /** Logger instance for error reporting. */ logger?: Logger; } export declare class ConvexStateAdapter implements StateAdapter { private readonly client; private readonly api; private readonly keyPrefix; private readonly logger; private connected; constructor(options: ConvexStateAdapterOptions); connect(): Promise; disconnect(): Promise; subscribe(threadId: string): Promise; unsubscribe(threadId: string): Promise; isSubscribed(threadId: string): Promise; acquireLock(threadId: string, ttlMs: number): Promise; releaseLock(lock: Lock): Promise; forceReleaseLock(threadId: string): Promise; extendLock(lock: Lock, ttlMs: number): Promise; get(key: string): Promise; set(key: string, value: T, ttlMs?: number): Promise; setIfNotExists(key: string, value: unknown, ttlMs?: number): Promise; delete(key: string): Promise; appendToList(key: string, value: unknown, options?: { maxLength?: number; ttlMs?: number; }): Promise; getList(key: string): Promise; enqueue(threadId: string, entry: QueueEntry, maxSize: number): Promise; dequeue(threadId: string): Promise; queueDepth(threadId: string): Promise; private ensureConnected; } export declare function createConvexState(options: ConvexStateAdapterOptions): ConvexStateAdapter; /** * Convenient alias for consumers who want a named type for an adapter * instance without importing the implementation class. * * ```ts * import type { ChatStateAdapter } from "chat-state-convex-adapter"; * let state: ChatStateAdapter; * ``` */ export type ChatStateAdapter = ConvexStateAdapter; export { ConvexCtxStateAdapter, createConvexStateFromCtx, } from "./ctx.js"; export type { ConvexCtxStateAdapterOptions, RunComponentCtx, } from "./ctx.js"; //# sourceMappingURL=index.d.ts.map