import type { Lock, Logger, QueueEntry, StateAdapter } from "chat"; import type { FunctionArgs, FunctionReference, FunctionReturnType } from "convex/server"; import type { ComponentApi } from "../component/_generated/component.js"; /** * The subset of a Convex action/mutation `ctx` we need. Any `ActionCtx` or * `MutationCtx` from the installing app satisfies this shape. * * The component's functions are `"internal"` from the app's perspective, so * we constrain to that visibility. */ export type RunComponentCtx = { runMutation: >(mutation: Mutation, args: FunctionArgs) => Promise>; runQuery: >(query: Query, args: FunctionArgs) => Promise>; }; export interface ConvexCtxStateAdapterOptions { /** A Convex action or mutation `ctx` with `runMutation`/`runQuery`. */ ctx: RunComponentCtx; /** The mounted component reference, typically `components.chatState`. */ component: ComponentApi; /** Namespace for all rows. Default: `"chat-sdk"`. */ keyPrefix?: string; /** Logger instance for error reporting. */ logger?: Logger; } /** * Chat SDK state adapter that runs inside a Convex action or httpAction. * * Unlike `ConvexStateAdapter` (which uses a `ConvexHttpClient` from an * external process), this variant calls the component directly via * `ctx.runMutation` / `ctx.runQuery`. No wrapper file is needed — the * calls go straight to `components.chatState.*`. * * Use this when your Chat SDK webhook handler lives inside a Convex * `httpAction`. Use `ConvexStateAdapter` when the handler lives in an * external runtime (Next.js route, Cloudflare Worker, etc.). */ export declare class ConvexCtxStateAdapter implements StateAdapter { private readonly ctx; private readonly component; private readonly keyPrefix; private readonly logger; private connected; constructor(options: ConvexCtxStateAdapterOptions); 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 createConvexStateFromCtx(options: ConvexCtxStateAdapterOptions): ConvexCtxStateAdapter; //# sourceMappingURL=ctx.d.ts.map