import { AIVariableResolutionRequest, AIVariableService, ToolInvocationRegistry, ToolRequest } from '@theia/ai-core'; import { Emitter, Event, ILogger, URI } from '@theia/core'; import { ChatAgentService, DefaultChatAgentId, FallbackChatAgentId } from './chat-agent-service'; import { ChatAgent, ChatAgentLocation, ChatSessionContext } from './chat-agents'; import { ChatContext, ChatModel, ChatRequest, ChatRequestModel, ChatResponseModel, MutableChatModel, MutableChatRequestModel } from './chat-model'; import { ChatRequestParser } from './chat-request-parser'; import { ChatSessionNamingService } from './chat-session-naming-service'; import { ParsedChatRequest, ParsedChatRequestAgentPart } from './parsed-chat-request'; import { ChatSessionIndex, ChatSessionStore } from './chat-session-store'; import { ChatContentDeserializerRegistry } from './chat-content-deserializer'; import { ChangeSetElementDeserializerRegistry } from './change-set-element-deserializer'; import { SerializableChangeSetElement, SerializedChatModel, SerializableParsedRequest } from './chat-model-serialization'; export { DefaultChatAgentId, FallbackChatAgentId }; /** * Error with which {@link ChatRequestInvocation.requestCompleted} and * {@link ChatRequestInvocation.responseCreated} are rejected when no chat agent is available * to handle the request. */ export declare class NoChatAgentError extends Error { constructor(message: string); static is(error: unknown): error is NoChatAgentError; } export interface ChatRequestInvocation { /** * Promise which completes once the request preprocessing is complete. * Rejected with a {@link NoChatAgentError} when no agent is available to handle the request. */ requestCompleted: Promise; /** * Promise which completes once a response is expected to arrive. * Rejected with a {@link NoChatAgentError} when no agent is available to handle the request. */ responseCreated: Promise; /** * Promise which completes once the response is complete. * In the no-agent case it resolves with the error response model instead of rejecting. */ responseCompleted: Promise; } export interface ChatSession { id: string; title?: string; lastInteraction?: Date; model: ChatModel; isActive: boolean; pinnedAgent?: ChatAgent; /** ID of the root session in the delegation chain. For delegated sessions, this points to the topmost session where task contexts are stored. */ rootSessionId?: string; /** ID of the immediate parent session that delegated this one. Undefined for top-level sessions. */ parentSessionId?: string; } export interface ActiveSessionChangedEvent { type: 'activeChange'; sessionId: string | undefined; focus?: boolean; } export declare function isActiveSessionChangedEvent(obj: unknown): obj is ActiveSessionChangedEvent; export interface SessionCreatedEvent { type: 'created'; sessionId: string; } export declare function isSessionCreatedEvent(obj: unknown): obj is SessionCreatedEvent; export interface SessionDeletedEvent { type: 'deleted'; sessionId: string; } export declare function isSessionDeletedEvent(obj: unknown): obj is SessionDeletedEvent; export interface SessionRenamedEvent { type: 'renamed'; sessionId: string; } export interface SessionOptions { focus?: boolean; } export declare const PinChatAgent: unique symbol; export type PinChatAgent = boolean; export declare const ChatService: unique symbol; export declare const ChatServiceFactory: unique symbol; export interface ChatService { onSessionEvent: Event; getSession(id: string): ChatSession | undefined; getSessions(): ChatSession[]; createSession(location?: ChatAgentLocation, options?: SessionOptions, pinnedAgent?: ChatAgent): ChatSession; deleteSession(sessionId: string): Promise; renameSession(sessionId: string, title: string): Promise; getActiveSession(): ChatSession | undefined; setActiveSession(sessionId: string, options?: SessionOptions): void; sendRequest(sessionId: string, request: ChatRequest): Promise; deleteChangeSet(sessionId: string): void; deleteChangeSetElement(sessionId: string, uri: URI): void; cancelRequest(sessionId: string, requestId: string): Promise; getAgent(parsedRequest: ParsedChatRequest, session: ChatSession): ChatAgent | undefined; /** * Get an existing session or restore from storage */ getOrRestoreSession(sessionId: string): Promise; /** * Get all persisted session metadata. * Note: This may trigger storage initialization if not already initialized. */ getPersistedSessions(): Promise; /** * Check if there are persisted sessions available. */ hasPersistedSessions(): Promise; } interface ChatSessionInternal extends ChatSession { model: MutableChatModel; } export declare class ChatServiceImpl implements ChatService { protected readonly onSessionEventEmitter: Emitter; onSessionEvent: Event; protected chatAgentService: ChatAgentService; protected chatSessionNamingService: ChatSessionNamingService | undefined; protected pinChatAgent: boolean | undefined; protected chatRequestParser: ChatRequestParser; protected variableService: AIVariableService; protected readonly logger: ILogger; protected sessionStore: ChatSessionStore | undefined; protected deserializerRegistry: ChatContentDeserializerRegistry; protected changeSetElementDeserializerRegistry: ChangeSetElementDeserializerRegistry; protected toolInvocationRegistry: ToolInvocationRegistry; protected _sessions: ChatSessionInternal[]; /** In-flight session restores by id, so concurrent requests for the same session share one restore. */ protected readonly pendingSessionRestores: Map>; getSessions(): ChatSessionInternal[]; getSession(id: string): ChatSessionInternal | undefined; createSession(location?: ChatAgentLocation, options?: SessionOptions, pinnedAgent?: ChatAgent): ChatSession; deleteSession(sessionId: string): Promise; protected deleteSessionAndChildren(sessionId: string, visited: Set): Promise; renameSession(sessionId: string, title: string): Promise; getActiveSession(): ChatSession | undefined; setActiveSession(sessionId: string | undefined, options?: SessionOptions): void; sendRequest(sessionId: string, request: ChatRequest): Promise; protected cancelIncompleteRequests(session: ChatSessionInternal): void; protected updateSessionMetadata(session: ChatSessionInternal, request: MutableChatRequestModel): void; protected resolveChatContext(resolutionRequests: readonly AIVariableResolutionRequest[], context: ChatSessionContext): Promise; cancelRequest(sessionId: string, requestId: string): Promise; getAgent(parsedRequest: ParsedChatRequest, session: ChatSession): ChatAgent | undefined; /** * Determines if chat agent pinning is enabled. * Can be overridden by subclasses to provide different logic (e.g., using preferences). */ protected isPinChatAgentEnabled(): boolean; /** * Check if an agent is pinned, and use it if no other agent is mentioned. */ protected getPinnedAgent(parsedRequest: ParsedChatRequest, session: ChatSession, agent: ChatAgent | undefined): ChatAgent | undefined; protected initialAgentSelection(parsedRequest: ParsedChatRequest): ChatAgent | undefined; protected getMentionedAgent(parsedRequest: ParsedChatRequest): ParsedChatRequestAgentPart | undefined; deleteChangeSet(sessionId: string): void; deleteChangeSetElement(sessionId: string, uri: URI): void; protected saveSession(sessionId: string): Promise; /** * Set up auto-save for a session by listening to model changes. */ protected setupAutoSaveForSession(session: ChatSessionInternal): void; getOrRestoreSession(sessionId: string): Promise; protected restoreSession(sessionId: string): Promise; getPersistedSessions(): Promise; hasPersistedSessions(): Promise; /** * Deserialize response content and restore changesets. * Called after basic chat model structure was created. */ protected restoreSessionData(model: MutableChatModel, data: SerializedChatModel): Promise; /** * Extracts and resolves tool requests from serialized data. * Looks up actual ToolRequest objects from the registry, or creates fallbacks if not found. */ protected restoreToolRequests(data: SerializableParsedRequest): Map; /** * Loads a tool request from the registry or creates a fallback if not found. */ protected loadToolRequestOrFallback(toolId: string): ToolRequest; protected restoreChangeSetElements(requestModel: MutableChatRequestModel, elements: SerializableChangeSetElement[], sessionId: string): Promise; } //# sourceMappingURL=chat-service.d.ts.map