import { createDecorator, type ServiceIdentifier } from '#/_base/di/instantiation'; import type { Page } from '#/persistence/interface/queryStore'; export const PARENT_SESSION_ID_KEY = 'parent_session_id'; export const CHILD_SESSION_KIND_KEY = 'child_session_kind'; export const CHILD_SESSION_KIND = 'child'; export interface SessionSummary { readonly id: string; readonly workspaceId: string; readonly cwd?: string; readonly title?: string; readonly lastPrompt?: string; readonly createdAt: number; readonly updatedAt: number; readonly archived: boolean; readonly archivedAt?: number; readonly custom?: Record; readonly lastTurnReason?: 'completed' | 'cancelled' | 'failed'; } export interface SessionListQuery { readonly workspaceIds?: readonly string[]; readonly sessionId?: string; readonly includeArchived?: boolean; readonly limit?: number; readonly childOf?: string; readonly before?: string; readonly after?: string; } export interface SessionCountQuery { readonly workspaceIds?: readonly string[]; readonly includeArchived?: boolean; } export type SessionIndexState = 'uninitialized' | 'preparing' | 'ready' | 'degraded'; export interface SessionIndexStatus { readonly state: SessionIndexState; readonly generation?: number; readonly reason?: string; readonly degradedCount: number; } export interface ISessionIndex { readonly _serviceBrand: undefined; prepare(options?: { deadlineMs?: number }): Promise; status(): SessionIndexStatus; get(id: string): Promise; listRecent(query: SessionListQuery): Promise>; count(query: SessionCountQuery): Promise; remove(id: string): Promise; } export const ISessionIndex: ServiceIdentifier = createDecorator('sessionIndex'); export interface ISessionIndexMirror { readonly _serviceBrand: undefined; record(summary: SessionSummary): void; pending(): readonly SessionSummary[]; evict(id: string): Promise; drain(): Promise; } export const ISessionIndexMirror: ServiceIdentifier = createDecorator('sessionIndexMirror');