export interface ChatThreadScope { type: string; id: string; label?: string; contextKey?: string; context?: string; contextVersion?: string; } /** Which of the caller's lists a thread belongs to; `mine` is ownership alone. */ export type ChatThreadOwnership = "all" | "mine" | "shared"; /** * Why the caller can see a thread. A direct per-user grant outranks * organization access when both apply. */ export type ChatThreadAccessBasis = "owner" | "direct" | "organization"; export type ChatThreadVisibility = "private" | "org" | "public"; export interface ChatThreadSummary { id: string; title: string; preview: string; messageCount: number; createdAt: number; updatedAt: number; scope: ChatThreadScope | null; source?: ChatThreadSource | null; pinnedAt?: number | null; hiddenAt?: number | null; archivedAt?: number | null; /** * Server-supplied on listed threads. Absent on optimistic local drafts, * which the caller owns by definition. */ ownerEmail?: string; accessBasis?: ChatThreadAccessBasis; visibility?: ChatThreadVisibility; orgId?: string | null; } export interface ChatThreadSource { platform?: string; appId?: string; url?: string; } export interface ChatThreadData { id: string; ownerEmail: string; title: string; preview: string; threadData: string; messageCount: number; createdAt: number; updatedAt: number; scope: ChatThreadScope | null; source?: ChatThreadSource | null; pinnedAt?: number | null; hiddenAt?: number | null; archivedAt?: number | null; } export interface ChatThreadSnapshot { threadData: string; title: string; preview: string; messageCount: number; } export interface ChatThreadShareState { enabled: boolean; createdAt: number | null; updatedAt: number | null; revokedAt: number | null; } export interface ChatThreadShareLink extends ChatThreadShareState { token?: string; url: string; } type ThreadTitleSource = "fallback" | "generated" | "extracted"; export interface UseChatThreadsOptions { autoCreate?: boolean; restoreActiveThread?: boolean; browserTabId?: string; routeThreadId?: string | null; includeExternal?: boolean; includeHidden?: boolean; isolateHistoryByScope?: boolean; /** Narrows the history list and search. Defaults to `all`. */ ownership?: ChatThreadOwnership; } export declare const CHAT_THREADS_UPDATED_EVENT = "agent-chat:threads-updated"; /** The server caps one page here; larger requests are silently shortened. */ export declare const CHAT_THREADS_MAX_PAGE_SIZE = 200; /** * True while a thread id was created on this client and the server has not * listed it yet. Routes use it to show a new chat instead of a missing thread. */ export declare function isClientDraftThread(id: string): boolean; export declare function markClientDraftThread(id: string): void; /** The thread list endpoint answered with a failure status or a malformed body. */ export declare class ChatThreadListError extends Error { readonly status: number | null; constructor(message: string, status?: number | null); } export interface ChatThreadListPageRequest { apiUrl?: string; /** Non-negative safe integer. Undefined uses the server default. */ offset?: number; /** Positive safe integer. Undefined uses the server default. The server caps pages at 200 rows. */ limit?: number; /** Switches the endpoint to search; ownership still narrows before paging. */ query?: string; ownership?: ChatThreadOwnership; includeExternal?: boolean; includeArchived?: boolean; includeHidden?: boolean; scope?: ChatThreadScope | null; } /** A listed thread as the server returns it: ownership metadata always present. */ export type ChatThreadListRow = ChatThreadSummary & { ownerEmail: string; accessBasis: ChatThreadAccessBasis; visibility: ChatThreadVisibility; }; export interface ChatThreadListPage { threads: ChatThreadListRow[]; /** `undefined` when the server did not report it. */ hasMore: boolean | undefined; } /** * One page of the thread list or search, for the ownership-aware lists. Throws * `ChatThreadListError` for a non-2xx response, a body that is not a thread * list, or a row missing `ownerEmail` / `accessBasis` / `visibility` or sitting * on the wrong side of `ownership`, so callers cannot mistake a failed page * for an empty one. Invalid explicit pagination arguments reject with * `TypeError` before a request is sent. * * The server caps each page at 200 rows. Advance offsets by the actual number * of returned rows and use `hasMore`, rather than the requested limit. */ export declare function fetchChatThreadListPage(request?: ChatThreadListPageRequest): Promise; export declare class ChatThreadMutationError extends Error { readonly status: number; constructor(status: number); } export declare function hideChatThread(threadId: string, hidden: boolean, options?: { apiUrl?: string; scope?: ChatThreadScope | null; }): Promise; export declare function appendChatThreadScopeParams(params: URLSearchParams, scope?: ChatThreadScope | null): void; /** * Tell every mounted chat history list the thread set or its sharing changed, * so they refetch. Anything that mutates a thread outside `useChatThreads` * (a share grant, a visibility change) must call this. */ export declare function notifyChatThreadsUpdated(): void; export declare function useChatThreads(apiUrl?: string, storageKey?: string, scope?: ChatThreadScope | null, options?: UseChatThreadsOptions): { threads: ChatThreadSummary[]; activeThreadId: string | null; isLoading: boolean; createThread: (preferredId?: string) => Promise; openThread: (id: string) => Promise<"opened" | "missing" | "unavailable">; switchThread: (id: string) => void; deleteThread: (id: string) => Promise; detachThread: (threadId: string) => Promise; pinThread: (threadId: string, pinned: boolean) => Promise; hideThread: (threadId: string, hidden: boolean) => Promise; archiveThread: (threadId: string) => Promise; renameThread: (threadId: string, title: string) => Promise; forkThread: (sourceId: string, sourceSnapshot?: ChatThreadSnapshot | null) => Promise; saveThreadData: (id: string, data: { threadData: string; title: string; preview: string; messageCount?: number; titleSource?: ThreadTitleSource; }, context?: { signal?: AbortSignal; }) => Promise; generateTitle: (threadId: string, message: string, selection?: { engine?: string; model?: string; }) => Promise; searchThreads: (query: string) => Promise; loadMoreThreads: () => Promise; getThreadShareState: (threadId: string) => Promise; createThreadShareLink: (threadId: string) => Promise; revokeThreadShareLink: (threadId: string) => Promise; refreshThreads: () => void; hasMoreThreads: boolean; isLoadingMoreThreads: boolean; threadsLoadError: string | null; restoredThreadIdOnListFailure: string | null; evictedThreadIds: string[]; isNewThread: (id: string) => boolean; isThreadPersisted: (id: string) => boolean; confirmThreadSnapshotPersisted: (id: string) => void; }; export {};