import { AgentSpecificVariables, AIVariableContext, AIVariableResolutionRequest, CapabilityAwareContext, LanguageModel, TokenUsageService, UsageResponsePart, LanguageModelMessage, LanguageModelRequirement, LanguageModelResponse, LanguageModelService, LanguageModelStreamResponse, PromptService, ResolvedPromptFragment, PromptVariantSet, ServerToolCall, ToolCall, ToolRequest } from '@theia/ai-core'; import { Agent, LanguageModelRegistry, LanguageModelStreamResponsePart } from '@theia/ai-core/lib/common'; import { ContributionProvider, ILogger } from '@theia/core'; import { ChatAgentService } from './chat-agent-service'; import { FileReadTracker } from './file-read-tracker'; import { ChatModel, ChatRequestModel, ChatResponseContent, CommonChatSessionSettings, MutableChatRequestModel, ResponseTokenUsage } from './chat-model'; import { ChatToolRequestService } from './chat-tool-request-service'; import { DefaultResponseContentFactory, ResponseContentMatcher, ResponseContentMatcherProvider } from './response-content-matcher'; /** * System message content, enriched with function descriptions. */ export interface SystemMessageDescription { text: string; /** All functions references in the system message. */ functionDescriptions?: Map; /** * Ids of functions referenced in the system message that were marked as * deferred (`~{?functionId}`). Providers that support deferred tool * loading can use this to set the appropriate flag on the tool definition * and include the tool search tool in the request. */ deferredFunctionIds?: Set; /** The prompt variant ID used */ promptVariantId?: string; /** Whether the prompt variant is customized */ isPromptVariantCustomized?: boolean; } export declare namespace SystemMessageDescription { function fromResolvedPromptFragment(resolvedPrompt: ResolvedPromptFragment, promptVariantId?: string, isPromptVariantCustomized?: boolean): SystemMessageDescription; } export interface ChatSessionContext extends CapabilityAwareContext { request?: ChatRequestModel; model: ChatModel; } export declare namespace ChatSessionContext { function is(candidate: unknown): candidate is ChatSessionContext; function getVariables(context: ChatSessionContext): readonly AIVariableResolutionRequest[]; } /** * The location from where an chat agent may be invoked. * Based on the location, a different context may be available. */ export declare enum ChatAgentLocation { Panel = "panel", Terminal = "terminal", Notebook = "notebook", Editor = "editor" } export declare namespace ChatAgentLocation { const ALL: ChatAgentLocation[]; function fromRaw(value: string): ChatAgentLocation; } /** * Represents a mode that a chat agent can operate in. */ export interface ChatMode { readonly id: string; readonly name: string; readonly isDefault?: boolean; } export declare const ChatAgent: unique symbol; /** * A chat agent is a specialized agent with a common interface for its invocation. */ export interface ChatAgent extends Agent { locations: ChatAgentLocation[]; iconClass?: string; modes?: ChatMode[]; invoke(request: MutableChatRequestModel, chatAgentService?: ChatAgentService): Promise; } export declare function isChatAgent(agent: Agent): agent is ChatAgent; export declare abstract class AbstractChatAgent implements ChatAgent { protected languageModelRegistry: LanguageModelRegistry; protected readonly logger: ILogger; protected chatToolRequestService: ChatToolRequestService; protected languageModelService: LanguageModelService; protected promptService: PromptService; protected contentMatcherProviders: ContributionProvider; protected defaultContentFactory: DefaultResponseContentFactory; protected tokenUsageService: TokenUsageService | undefined; protected fileReadTracker: FileReadTracker | undefined; readonly abstract id: string; readonly abstract name: string; readonly abstract languageModelRequirements: LanguageModelRequirement[]; iconClass: string; locations: ChatAgentLocation[]; tags: string[]; description: string; variables: string[]; prompts: PromptVariantSet[]; agentSpecificVariables: AgentSpecificVariables[]; functions: string[]; protected readonly abstract defaultLanguageModelPurpose: string; protected systemPromptId: string | undefined; protected additionalToolRequests: ToolRequest[]; protected contentMatchers: ResponseContentMatcher[]; init(): void; protected initializeContentMatchers(): void; invoke(request: MutableChatRequestModel): Promise; /** * Tells the agent which files it read were meanwhile changed by somebody else. A trailing user message * rather than the cached system message; providers requiring alternating roles merge same-role runs. */ protected appendExternalFileChangeNotice(request: MutableChatRequestModel, messages: LanguageModelMessage[]): Promise; protected parseContents(text: string, request: MutableChatRequestModel): ChatResponseContent[]; protected handleError(request: MutableChatRequestModel, error: Error): void; protected getLanguageModelSelector(languageModelPurpose: string): LanguageModelRequirement; protected getLanguageModel(languageModelPurpose: string): Promise; /** * Resolves the language model for a request, honoring a per-session model override * ({@link CommonChatSessionSettings.modelId}) when set and resolvable, and otherwise falling * back to the agent's configured model for the given purpose. */ protected getLanguageModelForRequest(request: MutableChatRequestModel, languageModelPurpose: string): Promise; /** Resolves a concrete language model (or alias) id to a ready model, or `undefined` if none is ready. */ protected resolveModelById(modelId: string): Promise; protected selectLanguageModel(selector: LanguageModelRequirement): Promise; protected getSystemMessageDescription(context: AIVariableContext): Promise; /** * Appends resolved generic capability prompt fragments to the system message. * Only includes fragments for capability types that have selections. */ protected appendGenericCapabilities(systemMessage: SystemMessageDescription, context: CapabilityAwareContext): Promise; protected getMessages(model: ChatModel, includeResponseInProgress?: boolean): Promise; /** * Deduplicate tools by name (falling back to id) while preserving the first occurrence and order. */ protected deduplicateTools(toolRequests: ToolRequest[]): ToolRequest[]; /** * Extracts session settings from the request, separating Theia-specific common settings * from arbitrary provider settings. * * @param request The chat request model containing session settings * @returns An object with `commonSettings` (Theia-specific) and `providerSettings` (passed to LLM) */ protected getSessionSettings(request: MutableChatRequestModel): { commonSettings: CommonChatSessionSettings | undefined; providerSettings: Record; }; protected sendLlmRequest(request: MutableChatRequestModel, messages: LanguageModelMessage[], toolRequests: ToolRequest[], deferredToolIds: string[] | undefined, languageModel: LanguageModel, promptVariantId?: string, isPromptVariantCustomized?: boolean): Promise; /** * @returns the settings, such as `temperature`, to be used in all language model requests. Returns `undefined` by default. */ protected getLlmSettings(): { [key: string]: unknown; } | undefined; /** * Invoked after the response by the LLM completed successfully. * * The default implementation sets the state of the response to `complete`. * Subclasses may override this method to perform additional actions or keep the response open for processing further requests. */ protected onResponseComplete(request: MutableChatRequestModel): Promise; protected mapUsageResponsePart(usage: UsageResponsePart): ResponseTokenUsage; protected recordTokenUsageFromResponse(request: MutableChatRequestModel, languageModel: LanguageModel): Promise; protected abstract addContentsToResponse(languageModelResponse: LanguageModelResponse, request: MutableChatRequestModel): Promise; } export declare abstract class AbstractTextToModelParsingChatAgent extends AbstractChatAgent { protected addContentsToResponse(languageModelResponse: LanguageModelResponse, request: MutableChatRequestModel): Promise; protected abstract parseTextResponse(text: string): Promise; protected abstract createResponseContent(parsedModel: T, request: MutableChatRequestModel): ChatResponseContent; } /** * Factory for creating ToolCallChatResponseContent instances. */ export declare class ToolCallChatResponseContentFactory { create(toolCall: ToolCall): ChatResponseContent; } /** * Factory for creating ServerToolCallChatResponseContent instances (provider-executed server tools). */ export declare class ServerToolCallResponseContentFactory { create(serverToolCall: ServerToolCall): ChatResponseContent; } export declare abstract class AbstractStreamParsingChatAgent extends AbstractChatAgent { protected toolCallResponseContentFactory: ToolCallChatResponseContentFactory; protected serverToolCallResponseContentFactory: ServerToolCallResponseContentFactory; protected addContentsToResponse(languageModelResponse: LanguageModelResponse, request: MutableChatRequestModel): Promise; protected addStreamResponse(languageModelResponse: LanguageModelStreamResponse, request: MutableChatRequestModel): Promise; protected parse(token: LanguageModelStreamResponsePart, request: MutableChatRequestModel): ChatResponseContent | ChatResponseContent[]; /** * Creates a ToolCallChatResponseContent instance from the provided tool call data. * * This method is called when parsing stream response tokens that contain tool call data. * Subclasses can override this method to customize the creation of tool call response contents. * * @param toolCall The ToolCall. * @returns A ChatResponseContent representing the tool call. */ protected createToolCallResponseContent(toolCall: ToolCall): ChatResponseContent; /** * Creates a ServerToolCallChatResponseContent from the provided server tool call data. * Subclasses can override this to customize how provider-executed server tools are rendered. */ protected createServerToolCallResponseContent(serverToolCall: ServerToolCall): ChatResponseContent; } //# sourceMappingURL=chat-agents.d.ts.map