/** * Session Manager — Copilot SDK Session Lifecycle * * Maps A2A contextId → Copilot session for multi-turn conversations. * Handles session creation, reuse, TTL-based cleanup, and task tracking. */ import type { CopilotClient } from "@github/copilot-sdk"; import type { AgentConfig } from "../config/types.js"; import type { McpEvidenceHooks } from "./mcp-hooks.js"; export interface CopilotSession { /** Unique identifier for this session, assigned by the Copilot SDK. */ readonly sessionId: string; /** * Subscribe to a session lifecycle or streaming event. * Returns an unsubscribe function — call it to remove the listener. */ on(event: string, handler: (event: unknown) => void): () => void; /** * Fire-and-forget send: dispatches the prompt and resolves immediately. * Listen to events (session.idle, assistant.message_delta, …) for results. */ send(params: { prompt: string; }): Promise; /** * Blocking send: dispatches the prompt and resolves with the complete * assistant response. Suitable for non-streaming, single-turn interactions. * * SDK 1.0.0: returns AssistantMessageEvent | undefined (was { data?: { content? } }) */ sendAndWait(params: { prompt: string; }, timeoutMs?: number): Promise<{ data?: { content?: string; }; } | undefined>; /** * Disconnect this session and release all SDK-side resources. * Session data on disk is preserved for later resumption. */ disconnect(): Promise; /** * @deprecated Use disconnect() instead. */ destroy(): Promise; } export declare class SessionManager { private readonly client; private readonly config; private readonly mcpHooks; /** A2A contextId → session entry */ private readonly contextSessions; /** taskId → sessionId for cancel support */ private readonly taskSessions; /** taskId → contextId for cancel support (allows publishStatus to emit correct contextId) */ private readonly taskContexts; private cleanupTimer; constructor(client: CopilotClient, config: Required, mcpHooks?: McpEvidenceHooks); /** * Build the session creation options from config. * Includes model, streaming, MCP servers, system message, and custom agents. */ private buildSessionOptions; /** * Get an existing session for the given contextId, or create a new one. * Returns the typed Copilot SDK session object. */ getOrCreate(contextId: string): Promise<{ sessionId: string; session: CopilotSession; isNew: boolean; }>; /** Track a task → session + context mapping for cancel support. */ trackTask(taskId: string, sessionId: string, contextId?: string): void; /** Remove task tracking. */ untrackTask(taskId: string): void; /** Get the sessionId for a tracked task. */ getSessionForTask(taskId: string): string | undefined; /** Get the A2A contextId for a tracked task. Used in cancelTask to emit the correct contextId. */ getContextForTask(taskId: string): string | undefined; /** Get the Copilot session object for a context. */ getSessionForContext(contextId: string): CopilotSession | undefined; /** Destroy a session by contextId. */ destroySession(contextId: string): Promise; /** Start periodic cleanup of expired sessions. */ startCleanup(): void; /** Shutdown: destroy all sessions and stop cleanup. */ shutdown(): Promise; } //# sourceMappingURL=session-manager.d.ts.map