/** * Session API — Safe API for agents */ interface SessionEvent { id: string; sessionId: string; timestamp: string; type: string; content?: string; role?: string; metadata?: Record; } interface Decision { id: string; sessionId: string; timestamp: string; text: string; confidence: number; sources: string[]; } interface TaskState { id: string; sessionId: string; status: string; createdAt: string; } interface AgentTimeline { agentId: string; events: Array<{ timestamp: string; type: string; message: string }>; } interface SessionSummary { sessionId: string; durationMs: number; messageCount: number; toolCount: number; decisionCount: number; taskCount: number; topics: string[]; } interface WorkflowState { id: string; status: string; tasks: string[]; blockers: string[]; } interface ArchitectureDecision { id: string; decision: string; timestamp: string; } export interface SessionService { getLatestDecision(): Promise; getLatestTask(): Promise; getRecentFailures(limit?: number): Promise; getArchitectureHistory(): Promise; getWorkflowState(): Promise; getLatestSummary(): Promise; search(query: string): Promise; getAgentTimeline(agentId: string): Promise; getSessionTimeline(limit?: number): Promise; } export class SessionServiceImpl implements SessionService { private events: SessionEvent[] = []; private decisions: Decision[] = []; private tasks: TaskState[] = []; private summary: SessionSummary = { sessionId: "", durationMs: 0, messageCount: 0, toolCount: 0, decisionCount: 0, taskCount: 0, topics: [], }; loadEvents(events: SessionEvent[]): void { this.events = events; } async getLatestDecision(): Promise { return this.decisions[this.decisions.length - 1] ?? null; } async getLatestTask(): Promise { return this.tasks[this.tasks.length - 1] ?? null; } async getRecentFailures(limit = 10): Promise { return this.events.filter((e) => e.type === "tool_error").slice(-limit); } async getArchitectureHistory(): Promise { return []; } async getWorkflowState(): Promise { return { id: "main", status: "running", tasks: [], blockers: [] }; } async getLatestSummary(): Promise { return this.summary; } async search(query: string): Promise { const q = query.toLowerCase(); return this.events.filter((e) => e.content?.toLowerCase().includes(q)); } async getAgentTimeline(agentId: string): Promise { return { agentId, events: [] }; } async getSessionTimeline(limit = 100): Promise { return this.events.slice(-limit); } }