import { ApiCaller } from '../api/api-caller'; import { Dto } from '../api/client'; import { SessionDto } from '../types/dtos'; import { WidgetConfig } from '../types/widget-config'; import { PrimitiveState } from '../utils/PrimitiveState'; import { ContactCtx } from './contact.ctx'; import { StorageCtx } from './storage.ctx'; type SessionState = { /** * The currently selected session. * Can be null if no session is selected, or if in chat screen and the session is not created yet. */ session: SessionDto | null; isCreatingSession: boolean; isResolvingSession: boolean; }; export type SessionsState = { /** List of all user sessions */ data: SessionDto[]; /** A cursor to get the next page of sessions */ cursor: string | undefined; /** Indicates if no more pages are left */ isLastPage: boolean; /** Did fetch for the first time */ didStartInitialFetch: boolean; isInitialFetchLoading: boolean; }; export declare class SessionCtx { private config; private api; private contactCtx; private storageCtx?; private sessionsPollingIntervalSeconds; private sessionsRefresher; /** The session id currently written to storage (null = none written). */ private persistedSessionId; private stopPersistingSession?; private stopWaitingForContact?; private sessionAbortController; sessionState: PrimitiveState; sessionsState: PrimitiveState; constructor({ config, api, contactCtx, storageCtx, sessionsPollingIntervalSeconds, sharedSessions, }: { config: WidgetConfig; api: ApiCaller; contactCtx: ContactCtx; storageCtx?: StorageCtx; sessionsPollingIntervalSeconds: number; sharedSessions?: PrimitiveState; }); /** * Remember which conversation the visitor is in, so a page reload can put * them back into it (`RouterCtx` does the restoring). Only OPEN sessions are * remembered — a closed one would reopen as a dead transcript — and the * pointer is dropped the moment the visitor leaves for a new chat. * * The boot value is deliberately NOT written: `subscribe` fires on changes * only, and clearing on a null we never set would wipe the pointer the * restore is about to read. */ private registerActiveSessionPersistence; /** Return persistence to the owning widget without overwriting its saved selection. */ restoreActiveSessionTracking: () => void; /** Persistence belongs to the selected conversation, never a background response. */ trackActiveSession: (active: SessionCtx) => void; private persistSession; /** The conversation the visitor was last in, from a previous page load. */ getLastActiveSessionId: () => Promise; /** Clears the session and stops polling */ reset: () => Promise; private registerSessionsRefresherWrapper; private registerSessionsRefresher; /** Permanently stop work owned by this runtime. */ dispose: ({ clearActiveSession }?: { clearActiveSession?: boolean | undefined; }) => Promise | undefined; private getParsedCustomData; createSession: () => Promise; /** One create-session request; on success the session is stored and the hook fires. */ private requestSession; loadMoreSessions: () => Promise; private getSessions; setSessions: (data: SessionDto[]) => void; refreshSessions: () => Promise; resolveSession: () => Promise<{ readonly success: false; readonly error: "Session is not opened"; readonly data?: undefined; } | { readonly success: false; readonly error: "Session was reset"; readonly data?: undefined; } | { readonly success: true; readonly data: { id: string; ticketNumber: number; title: string | null; createdAt: string; updatedAt: string; isHandedOff: boolean; isOpened: boolean; assignee: { kind: import('../api/schema').components["schemas"]["AssigneeKindEnum"]; name: string | null; avatarUrl: string | null; }; channel: string; isVerified: boolean; lastMessage: string | null; unread?: boolean; modeId: string | null; latestStateCheckpointPayload: { [key: string]: unknown; } | null; sessionAttributes: { [key: string]: string | number | boolean; }; customStatus: { id: string; name: string; description: string | null; color: string | null; icon: string | null; } | null; }; readonly error?: undefined; } | { readonly success: false; readonly error: { statusCode?: number; message?: string; error?: string; }; readonly data?: undefined; }>; createStateCheckpoint: (payload: Dto["WidgetCreateStateCheckpointInputDto"]["payload"]) => Promise<{ readonly success: true; } | { readonly success: false; } | undefined>; } export {}; //# sourceMappingURL=session.ctx.d.ts.map