Path: blob/main/src/vs/workbench/contrib/chat/common/chatSessionsService.ts
3296 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import { CancellationToken } from '../../../../base/common/cancellation.js';6import { Event } from '../../../../base/common/event.js';7import { IMarkdownString } from '../../../../base/common/htmlContent.js';8import { IDisposable } from '../../../../base/common/lifecycle.js';9import { IObservable } from '../../../../base/common/observable.js';10import { ThemeIcon } from '../../../../base/common/themables.js';11import { IRelaxedExtensionDescription } from '../../../../platform/extensions/common/extensions.js';12import { createDecorator } from '../../../../platform/instantiation/common/instantiation.js';13import { IEditableData } from '../../../common/views.js';14import { IChatAgentRequest } from './chatAgents.js';15import { IChatProgress } from './chatService.js';1617export const enum ChatSessionStatus {18Failed = 0,19Completed = 1,20InProgress = 221}2223export interface IChatSessionsExtensionPoint {24readonly type: string;25readonly name: string;26readonly displayName: string;27readonly description: string;28readonly extensionDescription: IRelaxedExtensionDescription;29readonly when?: string;30readonly capabilities?: {31supportsFileAttachments?: boolean;32supportsToolAttachments?: boolean;33};34}35export interface IChatSessionItem {36id: string;37label: string;38iconPath?: ThemeIcon;39description?: string | IMarkdownString;40status?: ChatSessionStatus;41tooltip?: string | IMarkdownString;42timing?: {43startTime: number;44endTime?: number;45};46statistics?: {47insertions: number;48deletions: number;49};5051}5253export type IChatSessionHistoryItem = { type: 'request'; prompt: string; participant: string } | { type: 'response'; parts: IChatProgress[]; participant: string };5455export interface ChatSession extends IDisposable {56readonly sessionId: string;57readonly onWillDispose: Event<void>;58history: Array<IChatSessionHistoryItem>;59readonly progressObs?: IObservable<IChatProgress[]>;60readonly isCompleteObs?: IObservable<boolean>;61readonly interruptActiveResponseCallback?: () => Promise<boolean>;6263requestHandler?: (64request: IChatAgentRequest,65progress: (progress: IChatProgress[]) => void,66history: any[], // TODO: Nail down types67token: CancellationToken68) => Promise<void>;69}7071export interface IChatSessionItemProvider {72readonly chatSessionType: string;73readonly onDidChangeChatSessionItems: Event<void>;74provideChatSessionItems(token: CancellationToken): Promise<IChatSessionItem[]>;75provideNewChatSessionItem?(options: {76request: IChatAgentRequest;77prompt?: string;78history?: any[];79metadata?: any;80}, token: CancellationToken): Promise<IChatSessionItem>;81}8283export interface IChatSessionContentProvider {84provideChatSessionContent(sessionId: string, token: CancellationToken): Promise<ChatSession>;85}8687export interface IChatSessionsService {88readonly _serviceBrand: undefined;8990readonly onDidChangeItemsProviders: Event<IChatSessionItemProvider>;91readonly onDidChangeSessionItems: Event<string>;92readonly onDidChangeAvailability: Event<void>;93readonly onDidChangeInProgress: Event<void>;9495registerChatSessionItemProvider(provider: IChatSessionItemProvider): IDisposable;96getAllChatSessionContributions(): IChatSessionsExtensionPoint[];97canResolveItemProvider(chatSessionType: string): Promise<boolean>;98getAllChatSessionItemProviders(): IChatSessionItemProvider[];99provideNewChatSessionItem(chatSessionType: string, options: {100request: IChatAgentRequest;101prompt?: string;102history?: any[];103metadata?: any;104}, token: CancellationToken): Promise<IChatSessionItem>;105provideChatSessionItems(chatSessionType: string, token: CancellationToken): Promise<IChatSessionItem[]>;106reportInProgress(chatSessionType: string, count: number): void;107getInProgress(): { displayName: string; count: number }[];108109registerChatSessionContentProvider(chatSessionType: string, provider: IChatSessionContentProvider): IDisposable;110canResolveContentProvider(chatSessionType: string): Promise<boolean>;111provideChatSessionContent(chatSessionType: string, id: string, token: CancellationToken): Promise<ChatSession>;112113// Editable session support114setEditableSession(sessionId: string, data: IEditableData | null): Promise<void>;115getEditableData(sessionId: string): IEditableData | undefined;116isEditable(sessionId: string): boolean;117118// Notify providers about session items changes119notifySessionItemsChanged(chatSessionType: string): void;120}121122export const IChatSessionsService = createDecorator<IChatSessionsService>('chatSessionsService');123124125