Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vscode-dts/vscode.proposed.chatSessionsProvider.d.ts
3290 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
declare module 'vscode' {
7
/**
8
* Represents the status of a chat session.
9
*/
10
export enum ChatSessionStatus {
11
/**
12
* The chat session failed to complete.
13
*/
14
Failed = 0,
15
16
/**
17
* The chat session completed successfully.
18
*/
19
Completed = 1,
20
21
/**
22
* The chat session is currently in progress.
23
*/
24
InProgress = 2
25
}
26
27
/**
28
* Provides a list of information about chat sessions.
29
*/
30
export interface ChatSessionItemProvider {
31
/**
32
* Event that the provider can fire to signal that chat sessions have changed.
33
*/
34
readonly onDidChangeChatSessionItems: Event<void>;
35
36
/**
37
* Creates a new chat session.
38
*
39
* @param options Options for the new session including an optional initial prompt and history
40
* @param token A cancellation token
41
* @returns Metadata for the chat session
42
*/
43
provideNewChatSessionItem?(options: {
44
/**
45
* The chat request that initiated the session creation
46
*/
47
readonly request: ChatRequest;
48
49
/**
50
* Initial prompt to initiate the session
51
*/
52
readonly prompt?: string;
53
54
/**
55
* History to initialize the session with
56
*/
57
readonly history?: ReadonlyArray<ChatRequestTurn | ChatResponseTurn>;
58
59
/**
60
* Additional metadata to use for session creation
61
*/
62
metadata?: any;
63
}, token: CancellationToken): ProviderResult<ChatSessionItem>;
64
65
/**
66
* Provides a list of chat sessions.
67
*/
68
// TODO: Do we need a flag to try auth if needed?
69
provideChatSessionItems(token: CancellationToken): ProviderResult<ChatSessionItem[]>;
70
}
71
72
export interface ChatSessionItem {
73
/**
74
* Unique identifier for the chat session.
75
*/
76
id: string;
77
78
/**
79
* Human readable name of the session shown in the UI
80
*/
81
label: string;
82
83
/**
84
* An icon for the participant shown in UI.
85
*/
86
iconPath?: IconPath;
87
88
/**
89
* An optional description that provides additional context about the chat session.
90
*/
91
description?: string | MarkdownString;
92
93
/**
94
* An optional status indicating the current state of the session.
95
*/
96
status?: ChatSessionStatus;
97
98
/**
99
* The tooltip text when you hover over this item.
100
*/
101
tooltip?: string | MarkdownString;
102
103
/**
104
* The times at which session started and ended
105
*/
106
timing?: {
107
/**
108
* Session start timestamp in milliseconds elapsed since January 1, 1970 00:00:00 UTC.
109
*/
110
startTime: number;
111
/**
112
* Session end timestamp in milliseconds elapsed since January 1, 1970 00:00:00 UTC.
113
*/
114
endTime?: number;
115
};
116
117
/**
118
* Statistics about the chat session.
119
*/
120
statistics?: {
121
/**
122
* Number of insertions made during the session.
123
*/
124
insertions: number;
125
126
/**
127
* Number of deletions made during the session.
128
*/
129
deletions: number;
130
};
131
}
132
133
export interface ChatSession {
134
/**
135
* The full history of the session
136
*
137
* This should not include any currently active responses
138
*/
139
// TODO: Are these the right types to use?
140
// TODO: link request + response to encourage correct usage?
141
readonly history: ReadonlyArray<ChatRequestTurn | ChatResponseTurn2>;
142
143
/**
144
* Callback invoked by the editor for a currently running response. This allows the session to push items for the
145
* current response and stream these in as them come in. The current response will be considered complete once the
146
* callback resolved.
147
*
148
* If not provided, the chat session is assumed to not currently be running.
149
*/
150
readonly activeResponseCallback?: (stream: ChatResponseStream, token: CancellationToken) => Thenable<void>;
151
152
/**
153
* Handles new request for the session.
154
*
155
* If not set, then the session will be considered read-only and no requests can be made.
156
*/
157
// TODO: Should we introduce our own type for `ChatRequestHandler` since not all field apply to chat sessions?
158
// TODO: Revisit this to align with code.
159
readonly requestHandler: ChatRequestHandler | undefined;
160
}
161
162
export interface ChatSessionContentProvider {
163
/**
164
* Resolves a chat session into a full `ChatSession` object.
165
*
166
* @param sessionId The id of the chat session to open.
167
* @param token A cancellation token that can be used to cancel the operation.
168
*/
169
provideChatSessionContent(sessionId: string, token: CancellationToken): Thenable<ChatSession> | ChatSession;
170
}
171
172
export namespace chat {
173
/**
174
* Registers a new {@link ChatSessionItemProvider chat session item provider}.
175
*
176
* To use this, also make sure to also add `chatSessions` contribution in the `package.json`.
177
*
178
* @param chatSessionType The type of chat session the provider is for.
179
* @param provider The provider to register.
180
*
181
* @returns A disposable that unregisters the provider when disposed.
182
*/
183
export function registerChatSessionItemProvider(chatSessionType: string, provider: ChatSessionItemProvider): Disposable;
184
185
/**
186
* Registers a new {@link ChatSessionContentProvider chat session content provider}.
187
*
188
* @param chatSessionType A unique identifier for the chat session type. This is used to differentiate between different chat session providers.
189
* @param provider The provider to register.
190
*
191
* @returns A disposable that unregisters the provider when disposed.
192
*/
193
export function registerChatSessionContentProvider(chatSessionType: string, provider: ChatSessionContentProvider, capabilities?: ChatSessionCapabilities): Disposable;
194
}
195
196
export interface ChatSessionCapabilities {
197
/**
198
* Whether sessions can be interrupted and resumed without side-effects.
199
*/
200
supportsInterruptions?: boolean;
201
}
202
203
export interface ChatSessionShowOptions {
204
/**
205
* The editor view column to show the chat session in.
206
*
207
* If not provided, the chat session will be shown in the chat panel instead.
208
*/
209
readonly viewColumn?: ViewColumn;
210
}
211
212
export namespace window {
213
/**
214
* Shows a chat session in the panel or editor.
215
*/
216
export function showChatSession(chatSessionType: string, sessionId: string, options: ChatSessionShowOptions): Thenable<void>;
217
}
218
}
219
220