import type { Event } from '#/_base/event'; import { createDecorator, type ServiceIdentifier } from '#/_base/di/instantiation'; export interface AgentMeta { readonly homedir?: string; readonly type?: 'main' | 'sub' | 'independent'; readonly parentAgentId?: string | null; readonly forkedFrom?: string; readonly labels?: Readonly>; readonly swarmItem?: string; } export const SESSION_META_VERSION = 2; export type SessionTitleKind = 'replaceable' | 'generated' | 'custom'; export interface SessionMeta { readonly id: string; readonly version?: number; readonly title?: string; readonly titleKind?: SessionTitleKind; readonly lastPrompt?: string; readonly createdAt: number; readonly updatedAt: number; readonly archived: boolean; readonly archivedAt?: number; readonly cwd?: string; readonly forkedFrom?: string; readonly agents?: Readonly>; readonly custom?: Record; readonly lastTurnReason?: 'completed' | 'cancelled' | 'failed'; } export type SessionMetaPatch = Partial>; export interface SessionMetadataChangedEvent { readonly changed: readonly (keyof SessionMeta)[]; } export interface ISessionMetadata { readonly _serviceBrand: undefined; readonly ready: Promise; readonly onDidChangeMetadata: Event; read(): Promise; update(patch: SessionMetaPatch, opts?: { readonly touchUpdatedAt?: boolean }): Promise; setTitle(title: string): Promise; setGeneratedTitleIfUncustomized( title: string, opts?: { force?: boolean }, ): Promise; setArchived(archived: boolean): Promise; registerAgent(agentId: string, meta: AgentMeta): Promise; } export const ISessionMetadata: ServiceIdentifier = createDecorator('sessionMetadata');