import { type AccessContext } from "../sharing/access.js"; import { type ShareRole } from "../sharing/schema.js"; export declare function withThreadDataLock(threadId: string, fn: () => Promise): Promise; /** * A resource the chat is bound to, e.g. `{ type: "deck", id: "deck-abc" }`. * The framework is opaque to the type string — each template chooses what * its primary resource is and the surface it scopes to (deck, design, * dashboard, etc.). `label` is a denormalized snapshot for display when * the resource isn't on hand at render time; the live template can * overwrite it via the next createThread call. */ export interface ChatThreadScope { type: string; id: string; label?: string; } export interface ChatThread { id: string; ownerEmail: string; title: string; preview: string; threadData: string; messageCount: number; createdAt: number; updatedAt: number; scope: ChatThreadScope | null; pinnedAt: number | null; archivedAt: number | null; orgId: string | null; visibility: "private" | "org" | "public"; } export interface ChatThreadSummary { id: string; title: string; preview: string; messageCount: number; createdAt: number; updatedAt: number; scope: ChatThreadScope | null; pinnedAt: number | null; archivedAt: number | null; orgId: string | null; visibility: "private" | "org" | "public"; } export interface ForkThreadSourceSnapshot { threadData: string; title?: string; preview?: string; messageCount?: number; scope?: ChatThreadScope | null; } export declare function createThread(ownerEmail: string, opts?: { id?: string; title?: string; scope?: ChatThreadScope | null; }): Promise; export declare function registerChatThreadsShareable(): void; export declare function ensureChatThreadTables(): Promise; export declare function resolveThreadAccess(userEmail: string | null | undefined, threadId: string | null | undefined, minRole?: ShareRole | "owner", ctx?: Omit): Promise; export declare function getThread(id: string): Promise; export declare function forkThread(sourceId: string, ownerEmail: string, opts?: { id?: string; source?: ForkThreadSourceSnapshot | null; sourceAccessGranted?: boolean; }): Promise; export interface ListThreadsOptions { limit?: number; offset?: number; /** * Filter for chats bound to a specific resource. The default (undefined) * returns every thread the user owns. `{ type: "deck", id: "abc" }` * returns only that resource's threads. `{ type: "deck", id: null }` is * NOT supported — pass `unscopedOnly: true` to get only general chats. */ scope?: { type: string; id: string; }; /** When true, returns only threads with no scope (general chats). */ unscopedOnly?: boolean; orgId?: string | null; /** * Include archived threads in the results. Defaults to false: archived * threads (`archived_at` set via `setThreadArchived`) are hidden from the * ordinary chat list/search so archiving actually removes a thread from * view. Pass true for surfaces that explicitly need to see archived chats * (e.g. an "Archived" filter or restoring one via `setThreadArchived`). */ includeArchived?: boolean; } export declare function listThreads(ownerEmail: string, options?: ListThreadsOptions | number, legacyOffset?: number): Promise; export declare function searchThreads(ownerEmail: string, query: string, limit?: number, options?: { scope?: { type: string; id: string; }; orgId?: string | null; /** See `ListThreadsOptions.includeArchived` — defaults to false. */ includeArchived?: boolean; }): Promise; /** * Detach or rebind a chat's scope. Used by the UI's "Detach from " * action and by templates that need to retag a chat after a rename. Pass * `null` to clear the scope (chat becomes general). */ export declare function setThreadScope(id: string, scope: ChatThreadScope | null): Promise; export declare function renameThread(id: string, title: string, options?: { ownerEmail?: string; }): Promise; export declare function setThreadPinned(id: string, pinned: boolean, options?: { ownerEmail?: string; }): Promise; export declare function setThreadArchived(id: string, archived: boolean, options?: { ownerEmail?: string; }): Promise; export interface UpdateThreadDataOptions { preserveExistingQueuedMessages?: boolean; preserveExistingTopLevelKeys?: boolean; maxAttempts?: number; ignoreConflicts?: boolean; } export declare function updateThreadData(id: string, threadData: string, title: string, preview: string, messageCount: number, options?: UpdateThreadDataOptions): Promise; export interface ThreadEngineMeta { engineName: string; model: string; } /** * Read the engine pinned to a thread (stored in thread_data JSON). * Returns null if no engine is pinned. */ export declare function getThreadEngineMeta(threadId: string): Promise; /** * Pin an engine to a thread by storing engineMeta in thread_data JSON. * Does not change messages, title, or preview. */ export declare function setThreadEngineMeta(threadId: string, meta: ThreadEngineMeta): Promise; export interface QueuedMessage { id: string; text: string; images?: string[]; references?: unknown[]; } /** * Persist the user's queued (not-yet-sent) messages onto the thread. * Stored in thread_data JSON so it survives reloads without a schema * change. Safe to call often — the frontend debounces writes. * * Returns false when the thread is missing or `ownerEmail` doesn't match. * Callers that already need an ownership check should pass `ownerEmail` * here instead of doing their own getThread first — this path fires on * debounced composer writes, so a redundant pre-read of the full * thread_data blob is a real per-keystroke cost. */ export declare function setThreadQueuedMessages(threadId: string, queuedMessages: QueuedMessage[], options?: { ownerEmail?: string; }): Promise; export interface ChatThreadShareState { enabled: boolean; createdAt: number | null; updatedAt: number | null; revokedAt: number | null; } export interface ChatThreadShareLink extends ChatThreadShareState { enabled: true; token: string; } export declare function hashThreadShareToken(token: string): string; export declare function getThreadShareState(threadId: string, options?: { ownerEmail?: string; }): Promise; export declare function createThreadShareLink(threadId: string, options?: { ownerEmail?: string; }): Promise; export declare function revokeThreadShareLink(threadId: string, options?: { ownerEmail?: string; }): Promise; export declare function getThreadByShareToken(token: string): Promise; /** * Grant a user an explicit share on a thread they don't own. Used by the * messaging-integration path, where a channel conversation runs as the * integration service principal and so creates a thread owned by * `integration@` rather than the human who asked — without this the * "Open thread" deep link resolves to a 404 for them. * * Idempotent, and never downgrades an existing stronger role. */ export declare function grantThreadUserShare(threadId: string, userEmail: string, role: ShareRole, grantedBy: string): Promise; export declare function deleteThread(id: string): Promise; //# sourceMappingURL=store.d.ts.map