@theia/ai-chat 1.58.3 → 1.59.0-next.72
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/browser/ai-chat-frontend-module.d.ts.map +1 -1
- package/lib/browser/ai-chat-frontend-module.js +16 -13
- package/lib/browser/ai-chat-frontend-module.js.map +1 -1
- package/lib/browser/ai-chat-preferences.d.ts +1 -0
- package/lib/browser/ai-chat-preferences.d.ts.map +1 -1
- package/lib/browser/ai-chat-preferences.js +12 -3
- package/lib/browser/ai-chat-preferences.js.map +1 -1
- package/lib/browser/change-set-file-element.d.ts +31 -6
- package/lib/browser/change-set-file-element.d.ts.map +1 -1
- package/lib/browser/change-set-file-element.js +108 -15
- package/lib/browser/change-set-file-element.js.map +1 -1
- package/lib/browser/change-set-file-resource.d.ts +40 -8
- package/lib/browser/change-set-file-resource.d.ts.map +1 -1
- package/lib/browser/change-set-file-resource.js +123 -37
- package/lib/browser/change-set-file-resource.js.map +1 -1
- package/lib/browser/change-set-file-service.d.ts +9 -3
- package/lib/browser/change-set-file-service.d.ts.map +1 -1
- package/lib/browser/change-set-file-service.js +35 -13
- package/lib/browser/change-set-file-service.js.map +1 -1
- package/lib/browser/change-set-variable.d.ts +11 -0
- package/lib/browser/change-set-variable.d.ts.map +1 -0
- package/lib/browser/change-set-variable.js +56 -0
- package/lib/browser/change-set-variable.js.map +1 -0
- package/lib/browser/context-file-variable-label-provider.d.ts +14 -0
- package/lib/browser/context-file-variable-label-provider.d.ts.map +1 -0
- package/lib/browser/context-file-variable-label-provider.js +63 -0
- package/lib/browser/context-file-variable-label-provider.js.map +1 -0
- package/lib/browser/context-variable-label-provider.d.ts +9 -0
- package/lib/browser/context-variable-label-provider.d.ts.map +1 -0
- package/lib/browser/context-variable-label-provider.js +55 -0
- package/lib/browser/context-variable-label-provider.js.map +1 -0
- package/lib/browser/file-chat-variable-contribution.d.ts +18 -0
- package/lib/browser/file-chat-variable-contribution.d.ts.map +1 -0
- package/lib/browser/file-chat-variable-contribution.js +135 -0
- package/lib/browser/file-chat-variable-contribution.js.map +1 -0
- package/lib/browser/frontend-chat-service.d.ts +10 -3
- package/lib/browser/frontend-chat-service.d.ts.map +1 -1
- package/lib/browser/frontend-chat-service.js +39 -19
- package/lib/browser/frontend-chat-service.js.map +1 -1
- package/lib/common/chat-agents.d.ts +54 -24
- package/lib/common/chat-agents.d.ts.map +1 -1
- package/lib/common/chat-agents.js +58 -20
- package/lib/common/chat-agents.js.map +1 -1
- package/lib/common/chat-history-entry.js +1 -1
- package/lib/common/chat-history-entry.js.map +1 -1
- package/lib/common/chat-model.d.ts +84 -36
- package/lib/common/chat-model.d.ts.map +1 -1
- package/lib/common/chat-model.js +142 -51
- package/lib/common/chat-model.js.map +1 -1
- package/lib/common/chat-service.d.ts +27 -10
- package/lib/common/chat-service.d.ts.map +1 -1
- package/lib/common/chat-service.js +80 -20
- package/lib/common/chat-service.js.map +1 -1
- package/lib/common/chat-string-utils.d.ts +3 -0
- package/lib/common/chat-string-utils.d.ts.map +1 -0
- package/lib/common/chat-string-utils.js +27 -0
- package/lib/common/chat-string-utils.js.map +1 -0
- package/lib/common/chat-tool-request-service.d.ts +5 -5
- package/lib/common/chat-tool-request-service.d.ts.map +1 -1
- package/lib/common/chat-tool-request-service.js.map +1 -1
- package/lib/common/context-details-variable.d.ts +9 -0
- package/lib/common/context-details-variable.d.ts.map +1 -0
- package/lib/common/context-details-variable.js +57 -0
- package/lib/common/context-details-variable.js.map +1 -0
- package/lib/common/context-summary-variable.d.ts +9 -0
- package/lib/common/context-summary-variable.d.ts.map +1 -0
- package/lib/common/context-summary-variable.js +57 -0
- package/lib/common/context-summary-variable.js.map +1 -0
- package/lib/common/context-variables.d.ts +4 -0
- package/lib/common/context-variables.d.ts.map +1 -0
- package/lib/common/context-variables.js +22 -0
- package/lib/common/context-variables.js.map +1 -0
- package/lib/common/custom-chat-agent.d.ts +6 -10
- package/lib/common/custom-chat-agent.d.ts.map +1 -1
- package/lib/common/custom-chat-agent.js +8 -11
- package/lib/common/custom-chat-agent.js.map +1 -1
- package/lib/common/index.d.ts +1 -3
- package/lib/common/index.d.ts.map +1 -1
- package/lib/common/index.js +1 -3
- package/lib/common/index.js.map +1 -1
- package/lib/common/parse-contents.d.ts +2 -2
- package/lib/common/parse-contents.d.ts.map +1 -1
- package/lib/common/parse-contents.js.map +1 -1
- package/lib/common/parse-contents.spec.d.ts.map +1 -1
- package/lib/common/parse-contents.spec.js.map +1 -1
- package/lib/common/response-content-matcher.d.ts +3 -3
- package/lib/common/response-content-matcher.d.ts.map +1 -1
- package/lib/common/response-content-matcher.js.map +1 -1
- package/package.json +12 -10
- package/src/browser/ai-chat-frontend-module.ts +20 -18
- package/src/browser/ai-chat-preferences.ts +13 -2
- package/src/browser/change-set-file-element.ts +109 -20
- package/src/browser/change-set-file-resource.ts +125 -39
- package/src/browser/change-set-file-service.ts +38 -16
- package/src/browser/change-set-variable.ts +54 -0
- package/src/browser/context-file-variable-label-provider.ts +62 -0
- package/src/browser/context-variable-label-provider.ts +56 -0
- package/src/browser/file-chat-variable-contribution.ts +143 -0
- package/src/browser/frontend-chat-service.ts +40 -26
- package/src/common/chat-agents.ts +87 -30
- package/src/common/chat-history-entry.ts +1 -1
- package/src/common/chat-model.ts +204 -70
- package/src/common/chat-service.ts +92 -24
- package/src/common/chat-string-utils.ts +23 -0
- package/src/common/chat-tool-request-service.ts +5 -5
- package/src/common/context-details-variable.ts +53 -0
- package/src/common/context-summary-variable.ts +53 -0
- package/src/common/context-variables.ts +19 -0
- package/src/common/custom-chat-agent.ts +9 -20
- package/src/common/index.ts +1 -3
- package/src/common/parse-contents.spec.ts +2 -2
- package/src/common/parse-contents.ts +2 -2
- package/src/common/response-content-matcher.ts +3 -3
- package/lib/common/command-chat-agents.d.ts +0 -33
- package/lib/common/command-chat-agents.d.ts.map +0 -1
- package/lib/common/command-chat-agents.js +0 -329
- package/lib/common/command-chat-agents.js.map +0 -1
- package/lib/common/orchestrator-chat-agent.d.ts +0 -22
- package/lib/common/orchestrator-chat-agent.d.ts.map +0 -1
- package/lib/common/orchestrator-chat-agent.js +0 -167
- package/lib/common/orchestrator-chat-agent.js.map +0 -1
- package/lib/common/universal-chat-agent.d.ts +0 -16
- package/lib/common/universal-chat-agent.d.ts.map +0 -1
- package/lib/common/universal-chat-agent.js +0 -109
- package/lib/common/universal-chat-agent.js.map +0 -1
- package/src/common/command-chat-agents.ts +0 -354
- package/src/common/orchestrator-chat-agent.ts +0 -179
- package/src/common/universal-chat-agent.ts +0 -117
|
@@ -20,6 +20,8 @@
|
|
|
20
20
|
// Partially copied from https://github.com/microsoft/vscode/blob/a2cab7255c0df424027be05d58e1b7b941f4ea60/src/vs/workbench/contrib/chat/common/chatAgents.ts
|
|
21
21
|
|
|
22
22
|
import {
|
|
23
|
+
AgentSpecificVariables,
|
|
24
|
+
AIVariableContext,
|
|
23
25
|
CommunicationRecordingService,
|
|
24
26
|
getTextOfResponse,
|
|
25
27
|
LanguageModel,
|
|
@@ -27,7 +29,9 @@ import {
|
|
|
27
29
|
LanguageModelResponse,
|
|
28
30
|
LanguageModelStreamResponse,
|
|
29
31
|
PromptService,
|
|
32
|
+
PromptTemplate,
|
|
30
33
|
ResolvedPromptTemplate,
|
|
34
|
+
ToolCall,
|
|
31
35
|
ToolRequest,
|
|
32
36
|
} from '@theia/ai-core';
|
|
33
37
|
import {
|
|
@@ -39,15 +43,16 @@ import {
|
|
|
39
43
|
MessageActor,
|
|
40
44
|
} from '@theia/ai-core/lib/common';
|
|
41
45
|
import { CancellationToken, ContributionProvider, ILogger, isArray } from '@theia/core';
|
|
42
|
-
import { inject, injectable, named, postConstruct
|
|
46
|
+
import { inject, injectable, named, postConstruct } from '@theia/core/shared/inversify';
|
|
43
47
|
import { ChatAgentService } from './chat-agent-service';
|
|
44
48
|
import {
|
|
45
49
|
ChatModel,
|
|
46
|
-
|
|
50
|
+
MutableChatRequestModel,
|
|
47
51
|
ChatResponseContent,
|
|
48
52
|
ErrorChatResponseContentImpl,
|
|
49
53
|
MarkdownChatResponseContentImpl,
|
|
50
|
-
ToolCallChatResponseContentImpl
|
|
54
|
+
ToolCallChatResponseContentImpl,
|
|
55
|
+
ChatRequestModel
|
|
51
56
|
} from './chat-model';
|
|
52
57
|
import { findFirstMatch, parseContents } from './parse-contents';
|
|
53
58
|
import { DefaultResponseContentFactory, ResponseContentMatcher, ResponseContentMatcherProvider } from './response-content-matcher';
|
|
@@ -83,6 +88,17 @@ export namespace SystemMessageDescription {
|
|
|
83
88
|
}
|
|
84
89
|
}
|
|
85
90
|
|
|
91
|
+
export interface ChatSessionContext extends AIVariableContext {
|
|
92
|
+
request?: ChatRequestModel;
|
|
93
|
+
model: ChatModel;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export namespace ChatSessionContext {
|
|
97
|
+
export function is(candidate: unknown): candidate is ChatSessionContext {
|
|
98
|
+
return typeof candidate === 'object' && !!candidate && 'model' in candidate;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
86
102
|
/**
|
|
87
103
|
* The location from where an chat agent may be invoked.
|
|
88
104
|
* Based on the location, a different context may be available.
|
|
@@ -115,11 +131,11 @@ export const ChatAgent = Symbol('ChatAgent');
|
|
|
115
131
|
export interface ChatAgent extends Agent {
|
|
116
132
|
locations: ChatAgentLocation[];
|
|
117
133
|
iconClass?: string;
|
|
118
|
-
invoke(request:
|
|
134
|
+
invoke(request: MutableChatRequestModel, chatAgentService?: ChatAgentService): Promise<void>;
|
|
119
135
|
}
|
|
120
136
|
|
|
121
137
|
@injectable()
|
|
122
|
-
export abstract class AbstractChatAgent {
|
|
138
|
+
export abstract class AbstractChatAgent implements ChatAgent {
|
|
123
139
|
@inject(LanguageModelRegistry) protected languageModelRegistry: LanguageModelRegistry;
|
|
124
140
|
@inject(ILogger) protected logger: ILogger;
|
|
125
141
|
@inject(CommunicationRecordingService) protected recordingService: CommunicationRecordingService;
|
|
@@ -128,21 +144,26 @@ export abstract class AbstractChatAgent {
|
|
|
128
144
|
|
|
129
145
|
@inject(ContributionProvider) @named(ResponseContentMatcherProvider)
|
|
130
146
|
protected contentMatcherProviders: ContributionProvider<ResponseContentMatcherProvider>;
|
|
131
|
-
protected additionalToolRequests: ToolRequest[] = [];
|
|
132
|
-
protected contentMatchers: ResponseContentMatcher[] = [];
|
|
133
147
|
|
|
134
148
|
@inject(DefaultResponseContentFactory)
|
|
135
149
|
protected defaultContentFactory: DefaultResponseContentFactory;
|
|
136
150
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
151
|
+
readonly abstract id: string;
|
|
152
|
+
readonly abstract name: string;
|
|
153
|
+
readonly abstract languageModelRequirements: LanguageModelRequirement[];
|
|
154
|
+
iconClass: string = 'codicon codicon-copilot';
|
|
155
|
+
locations: ChatAgentLocation[] = ChatAgentLocation.ALL;
|
|
156
|
+
tags: string[] = ['Chat'];
|
|
157
|
+
description: string = '';
|
|
158
|
+
variables: string[] = [];
|
|
159
|
+
promptTemplates: PromptTemplate[] = [];
|
|
160
|
+
agentSpecificVariables: AgentSpecificVariables[] = [];
|
|
161
|
+
functions: string[] = [];
|
|
162
|
+
protected readonly abstract defaultLanguageModelPurpose: string;
|
|
163
|
+
protected defaultLogging: boolean = true;
|
|
164
|
+
protected systemPromptId: string | undefined = undefined;
|
|
165
|
+
protected additionalToolRequests: ToolRequest[] = [];
|
|
166
|
+
protected contentMatchers: ResponseContentMatcher[] = [];
|
|
146
167
|
|
|
147
168
|
@postConstruct()
|
|
148
169
|
init(): void {
|
|
@@ -154,14 +175,13 @@ export abstract class AbstractChatAgent {
|
|
|
154
175
|
this.contentMatchers.push(...contributedContentMatchers);
|
|
155
176
|
}
|
|
156
177
|
|
|
157
|
-
async invoke(request:
|
|
178
|
+
async invoke(request: MutableChatRequestModel): Promise<void> {
|
|
158
179
|
try {
|
|
159
180
|
const languageModel = await this.getLanguageModel(this.defaultLanguageModelPurpose);
|
|
160
181
|
if (!languageModel) {
|
|
161
182
|
throw new Error('Couldn\'t find a matching language model. Please check your setup!');
|
|
162
183
|
}
|
|
163
|
-
|
|
164
|
-
const systemMessageDescription = await this.getSystemMessageDescription();
|
|
184
|
+
const systemMessageDescription = await this.getSystemMessageDescription({ model: request.session, request } satisfies ChatSessionContext);
|
|
165
185
|
const messages = await this.getMessages(request.session);
|
|
166
186
|
if (this.defaultLogging) {
|
|
167
187
|
this.recordingService.recordRequest(
|
|
@@ -206,7 +226,7 @@ export abstract class AbstractChatAgent {
|
|
|
206
226
|
}
|
|
207
227
|
}
|
|
208
228
|
|
|
209
|
-
protected parseContents(text: string, request:
|
|
229
|
+
protected parseContents(text: string, request: MutableChatRequestModel): ChatResponseContent[] {
|
|
210
230
|
return parseContents(
|
|
211
231
|
text,
|
|
212
232
|
request,
|
|
@@ -215,7 +235,7 @@ export abstract class AbstractChatAgent {
|
|
|
215
235
|
);
|
|
216
236
|
};
|
|
217
237
|
|
|
218
|
-
protected handleError(request:
|
|
238
|
+
protected handleError(request: MutableChatRequestModel, error: Error): void {
|
|
219
239
|
request.response.response.addContent(new ErrorChatResponseContentImpl(error));
|
|
220
240
|
request.response.error(error);
|
|
221
241
|
}
|
|
@@ -236,7 +256,13 @@ export abstract class AbstractChatAgent {
|
|
|
236
256
|
return languageModel;
|
|
237
257
|
}
|
|
238
258
|
|
|
239
|
-
protected
|
|
259
|
+
protected async getSystemMessageDescription(context: AIVariableContext): Promise<SystemMessageDescription | undefined> {
|
|
260
|
+
if (this.systemPromptId === undefined) {
|
|
261
|
+
return undefined;
|
|
262
|
+
}
|
|
263
|
+
const resolvedPrompt = await this.promptService.getPrompt(this.systemPromptId, undefined, context);
|
|
264
|
+
return resolvedPrompt ? SystemMessageDescription.fromResolvedPromptTemplate(resolvedPrompt) : undefined;
|
|
265
|
+
}
|
|
240
266
|
|
|
241
267
|
protected async getMessages(
|
|
242
268
|
model: ChatModel, includeResponseInProgress = false
|
|
@@ -290,17 +316,17 @@ export abstract class AbstractChatAgent {
|
|
|
290
316
|
* The default implementation sets the state of the response to `complete`.
|
|
291
317
|
* Subclasses may override this method to perform additional actions or keep the response open for processing further requests.
|
|
292
318
|
*/
|
|
293
|
-
protected async onResponseComplete(request:
|
|
319
|
+
protected async onResponseComplete(request: MutableChatRequestModel): Promise<void> {
|
|
294
320
|
return request.response.complete();
|
|
295
321
|
}
|
|
296
322
|
|
|
297
|
-
protected abstract addContentsToResponse(languageModelResponse: LanguageModelResponse, request:
|
|
323
|
+
protected abstract addContentsToResponse(languageModelResponse: LanguageModelResponse, request: MutableChatRequestModel): Promise<void>;
|
|
298
324
|
}
|
|
299
325
|
|
|
300
326
|
@injectable()
|
|
301
327
|
export abstract class AbstractTextToModelParsingChatAgent<T> extends AbstractChatAgent {
|
|
302
328
|
|
|
303
|
-
protected async addContentsToResponse(languageModelResponse: LanguageModelResponse, request:
|
|
329
|
+
protected async addContentsToResponse(languageModelResponse: LanguageModelResponse, request: MutableChatRequestModel): Promise<void> {
|
|
304
330
|
const responseAsText = await getTextOfResponse(languageModelResponse);
|
|
305
331
|
const parsedCommand = await this.parseTextResponse(responseAsText);
|
|
306
332
|
const content = this.createResponseContent(parsedCommand, request);
|
|
@@ -309,13 +335,31 @@ export abstract class AbstractTextToModelParsingChatAgent<T> extends AbstractCha
|
|
|
309
335
|
|
|
310
336
|
protected abstract parseTextResponse(text: string): Promise<T>;
|
|
311
337
|
|
|
312
|
-
protected abstract createResponseContent(parsedModel: T, request:
|
|
338
|
+
protected abstract createResponseContent(parsedModel: T, request: MutableChatRequestModel): ChatResponseContent;
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
/**
|
|
342
|
+
* Factory for creating ToolCallChatResponseContent instances.
|
|
343
|
+
*/
|
|
344
|
+
@injectable()
|
|
345
|
+
export class ToolCallChatResponseContentFactory {
|
|
346
|
+
create(toolCall: ToolCall): ChatResponseContent {
|
|
347
|
+
return new ToolCallChatResponseContentImpl(
|
|
348
|
+
toolCall.id,
|
|
349
|
+
toolCall.function?.name,
|
|
350
|
+
toolCall.function?.arguments,
|
|
351
|
+
toolCall.finished,
|
|
352
|
+
toolCall.result
|
|
353
|
+
);
|
|
354
|
+
}
|
|
313
355
|
}
|
|
314
356
|
|
|
315
357
|
@injectable()
|
|
316
358
|
export abstract class AbstractStreamParsingChatAgent extends AbstractChatAgent {
|
|
359
|
+
@inject(ToolCallChatResponseContentFactory)
|
|
360
|
+
protected toolCallResponseContentFactory: ToolCallChatResponseContentFactory;
|
|
317
361
|
|
|
318
|
-
protected override async addContentsToResponse(languageModelResponse: LanguageModelResponse, request:
|
|
362
|
+
protected override async addContentsToResponse(languageModelResponse: LanguageModelResponse, request: MutableChatRequestModel): Promise<void> {
|
|
319
363
|
if (isLanguageModelTextResponse(languageModelResponse)) {
|
|
320
364
|
const contents = this.parseContents(languageModelResponse.text, request);
|
|
321
365
|
request.response.response.addContents(contents);
|
|
@@ -335,7 +379,7 @@ export abstract class AbstractStreamParsingChatAgent extends AbstractChatAgent {
|
|
|
335
379
|
);
|
|
336
380
|
}
|
|
337
381
|
|
|
338
|
-
protected async addStreamResponse(languageModelResponse: LanguageModelStreamResponse, request:
|
|
382
|
+
protected async addStreamResponse(languageModelResponse: LanguageModelStreamResponse, request: MutableChatRequestModel): Promise<void> {
|
|
339
383
|
for await (const token of languageModelResponse.stream) {
|
|
340
384
|
const newContents = this.parse(token, request);
|
|
341
385
|
if (isArray(newContents)) {
|
|
@@ -362,7 +406,7 @@ export abstract class AbstractStreamParsingChatAgent extends AbstractChatAgent {
|
|
|
362
406
|
}
|
|
363
407
|
}
|
|
364
408
|
|
|
365
|
-
protected parse(token: LanguageModelStreamResponsePart, request:
|
|
409
|
+
protected parse(token: LanguageModelStreamResponsePart, request: MutableChatRequestModel): ChatResponseContent | ChatResponseContent[] {
|
|
366
410
|
const content = token.content;
|
|
367
411
|
// eslint-disable-next-line no-null/no-null
|
|
368
412
|
if (content !== undefined && content !== null) {
|
|
@@ -371,10 +415,23 @@ export abstract class AbstractStreamParsingChatAgent extends AbstractChatAgent {
|
|
|
371
415
|
const toolCalls = token.tool_calls;
|
|
372
416
|
if (toolCalls !== undefined) {
|
|
373
417
|
const toolCallContents = toolCalls.map(toolCall =>
|
|
374
|
-
|
|
418
|
+
this.createToolCallResponseContent(toolCall)
|
|
419
|
+
);
|
|
375
420
|
return toolCallContents;
|
|
376
421
|
}
|
|
377
422
|
return this.defaultContentFactory.create('', request);
|
|
378
423
|
}
|
|
379
424
|
|
|
425
|
+
/**
|
|
426
|
+
* Creates a ToolCallChatResponseContent instance from the provided tool call data.
|
|
427
|
+
*
|
|
428
|
+
* This method is called when parsing stream response tokens that contain tool call data.
|
|
429
|
+
* Subclasses can override this method to customize the creation of tool call response contents.
|
|
430
|
+
*
|
|
431
|
+
* @param toolCall The ToolCall.
|
|
432
|
+
* @returns A ChatResponseContent representing the tool call.
|
|
433
|
+
*/
|
|
434
|
+
protected createToolCallResponseContent(toolCall: ToolCall): ChatResponseContent {
|
|
435
|
+
return this.toolCallResponseContentFactory.create(toolCall);
|
|
436
|
+
}
|
|
380
437
|
}
|