@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.
Files changed (128) hide show
  1. package/lib/browser/ai-chat-frontend-module.d.ts.map +1 -1
  2. package/lib/browser/ai-chat-frontend-module.js +16 -13
  3. package/lib/browser/ai-chat-frontend-module.js.map +1 -1
  4. package/lib/browser/ai-chat-preferences.d.ts +1 -0
  5. package/lib/browser/ai-chat-preferences.d.ts.map +1 -1
  6. package/lib/browser/ai-chat-preferences.js +12 -3
  7. package/lib/browser/ai-chat-preferences.js.map +1 -1
  8. package/lib/browser/change-set-file-element.d.ts +31 -6
  9. package/lib/browser/change-set-file-element.d.ts.map +1 -1
  10. package/lib/browser/change-set-file-element.js +108 -15
  11. package/lib/browser/change-set-file-element.js.map +1 -1
  12. package/lib/browser/change-set-file-resource.d.ts +40 -8
  13. package/lib/browser/change-set-file-resource.d.ts.map +1 -1
  14. package/lib/browser/change-set-file-resource.js +123 -37
  15. package/lib/browser/change-set-file-resource.js.map +1 -1
  16. package/lib/browser/change-set-file-service.d.ts +9 -3
  17. package/lib/browser/change-set-file-service.d.ts.map +1 -1
  18. package/lib/browser/change-set-file-service.js +35 -13
  19. package/lib/browser/change-set-file-service.js.map +1 -1
  20. package/lib/browser/change-set-variable.d.ts +11 -0
  21. package/lib/browser/change-set-variable.d.ts.map +1 -0
  22. package/lib/browser/change-set-variable.js +56 -0
  23. package/lib/browser/change-set-variable.js.map +1 -0
  24. package/lib/browser/context-file-variable-label-provider.d.ts +14 -0
  25. package/lib/browser/context-file-variable-label-provider.d.ts.map +1 -0
  26. package/lib/browser/context-file-variable-label-provider.js +63 -0
  27. package/lib/browser/context-file-variable-label-provider.js.map +1 -0
  28. package/lib/browser/context-variable-label-provider.d.ts +9 -0
  29. package/lib/browser/context-variable-label-provider.d.ts.map +1 -0
  30. package/lib/browser/context-variable-label-provider.js +55 -0
  31. package/lib/browser/context-variable-label-provider.js.map +1 -0
  32. package/lib/browser/file-chat-variable-contribution.d.ts +18 -0
  33. package/lib/browser/file-chat-variable-contribution.d.ts.map +1 -0
  34. package/lib/browser/file-chat-variable-contribution.js +135 -0
  35. package/lib/browser/file-chat-variable-contribution.js.map +1 -0
  36. package/lib/browser/frontend-chat-service.d.ts +10 -3
  37. package/lib/browser/frontend-chat-service.d.ts.map +1 -1
  38. package/lib/browser/frontend-chat-service.js +39 -19
  39. package/lib/browser/frontend-chat-service.js.map +1 -1
  40. package/lib/common/chat-agents.d.ts +54 -24
  41. package/lib/common/chat-agents.d.ts.map +1 -1
  42. package/lib/common/chat-agents.js +58 -20
  43. package/lib/common/chat-agents.js.map +1 -1
  44. package/lib/common/chat-history-entry.js +1 -1
  45. package/lib/common/chat-history-entry.js.map +1 -1
  46. package/lib/common/chat-model.d.ts +84 -36
  47. package/lib/common/chat-model.d.ts.map +1 -1
  48. package/lib/common/chat-model.js +142 -51
  49. package/lib/common/chat-model.js.map +1 -1
  50. package/lib/common/chat-service.d.ts +27 -10
  51. package/lib/common/chat-service.d.ts.map +1 -1
  52. package/lib/common/chat-service.js +80 -20
  53. package/lib/common/chat-service.js.map +1 -1
  54. package/lib/common/chat-string-utils.d.ts +3 -0
  55. package/lib/common/chat-string-utils.d.ts.map +1 -0
  56. package/lib/common/chat-string-utils.js +27 -0
  57. package/lib/common/chat-string-utils.js.map +1 -0
  58. package/lib/common/chat-tool-request-service.d.ts +5 -5
  59. package/lib/common/chat-tool-request-service.d.ts.map +1 -1
  60. package/lib/common/chat-tool-request-service.js.map +1 -1
  61. package/lib/common/context-details-variable.d.ts +9 -0
  62. package/lib/common/context-details-variable.d.ts.map +1 -0
  63. package/lib/common/context-details-variable.js +57 -0
  64. package/lib/common/context-details-variable.js.map +1 -0
  65. package/lib/common/context-summary-variable.d.ts +9 -0
  66. package/lib/common/context-summary-variable.d.ts.map +1 -0
  67. package/lib/common/context-summary-variable.js +57 -0
  68. package/lib/common/context-summary-variable.js.map +1 -0
  69. package/lib/common/context-variables.d.ts +4 -0
  70. package/lib/common/context-variables.d.ts.map +1 -0
  71. package/lib/common/context-variables.js +22 -0
  72. package/lib/common/context-variables.js.map +1 -0
  73. package/lib/common/custom-chat-agent.d.ts +6 -10
  74. package/lib/common/custom-chat-agent.d.ts.map +1 -1
  75. package/lib/common/custom-chat-agent.js +8 -11
  76. package/lib/common/custom-chat-agent.js.map +1 -1
  77. package/lib/common/index.d.ts +1 -3
  78. package/lib/common/index.d.ts.map +1 -1
  79. package/lib/common/index.js +1 -3
  80. package/lib/common/index.js.map +1 -1
  81. package/lib/common/parse-contents.d.ts +2 -2
  82. package/lib/common/parse-contents.d.ts.map +1 -1
  83. package/lib/common/parse-contents.js.map +1 -1
  84. package/lib/common/parse-contents.spec.d.ts.map +1 -1
  85. package/lib/common/parse-contents.spec.js.map +1 -1
  86. package/lib/common/response-content-matcher.d.ts +3 -3
  87. package/lib/common/response-content-matcher.d.ts.map +1 -1
  88. package/lib/common/response-content-matcher.js.map +1 -1
  89. package/package.json +12 -10
  90. package/src/browser/ai-chat-frontend-module.ts +20 -18
  91. package/src/browser/ai-chat-preferences.ts +13 -2
  92. package/src/browser/change-set-file-element.ts +109 -20
  93. package/src/browser/change-set-file-resource.ts +125 -39
  94. package/src/browser/change-set-file-service.ts +38 -16
  95. package/src/browser/change-set-variable.ts +54 -0
  96. package/src/browser/context-file-variable-label-provider.ts +62 -0
  97. package/src/browser/context-variable-label-provider.ts +56 -0
  98. package/src/browser/file-chat-variable-contribution.ts +143 -0
  99. package/src/browser/frontend-chat-service.ts +40 -26
  100. package/src/common/chat-agents.ts +87 -30
  101. package/src/common/chat-history-entry.ts +1 -1
  102. package/src/common/chat-model.ts +204 -70
  103. package/src/common/chat-service.ts +92 -24
  104. package/src/common/chat-string-utils.ts +23 -0
  105. package/src/common/chat-tool-request-service.ts +5 -5
  106. package/src/common/context-details-variable.ts +53 -0
  107. package/src/common/context-summary-variable.ts +53 -0
  108. package/src/common/context-variables.ts +19 -0
  109. package/src/common/custom-chat-agent.ts +9 -20
  110. package/src/common/index.ts +1 -3
  111. package/src/common/parse-contents.spec.ts +2 -2
  112. package/src/common/parse-contents.ts +2 -2
  113. package/src/common/response-content-matcher.ts +3 -3
  114. package/lib/common/command-chat-agents.d.ts +0 -33
  115. package/lib/common/command-chat-agents.d.ts.map +0 -1
  116. package/lib/common/command-chat-agents.js +0 -329
  117. package/lib/common/command-chat-agents.js.map +0 -1
  118. package/lib/common/orchestrator-chat-agent.d.ts +0 -22
  119. package/lib/common/orchestrator-chat-agent.d.ts.map +0 -1
  120. package/lib/common/orchestrator-chat-agent.js +0 -167
  121. package/lib/common/orchestrator-chat-agent.js.map +0 -1
  122. package/lib/common/universal-chat-agent.d.ts +0 -16
  123. package/lib/common/universal-chat-agent.d.ts.map +0 -1
  124. package/lib/common/universal-chat-agent.js +0 -109
  125. package/lib/common/universal-chat-agent.js.map +0 -1
  126. package/src/common/command-chat-agents.ts +0 -354
  127. package/src/common/orchestrator-chat-agent.ts +0 -179
  128. 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, unmanaged } from '@theia/core/shared/inversify';
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
- ChatRequestModelImpl,
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: ChatRequestModelImpl, chatAgentService?: ChatAgentService): Promise<void>;
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
- constructor(
138
- @unmanaged() public id: string,
139
- @unmanaged() public languageModelRequirements: LanguageModelRequirement[],
140
- @unmanaged() protected defaultLanguageModelPurpose: string,
141
- @unmanaged() public iconClass: string = 'codicon codicon-copilot',
142
- @unmanaged() public locations: ChatAgentLocation[] = ChatAgentLocation.ALL,
143
- @unmanaged() public tags: string[] = ['Chat'],
144
- @unmanaged() public defaultLogging: boolean = true) {
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: ChatRequestModelImpl): Promise<void> {
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: ChatRequestModelImpl): ChatResponseContent[] {
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: ChatRequestModelImpl, error: Error): void {
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 abstract getSystemMessageDescription(): Promise<SystemMessageDescription | undefined>;
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: ChatRequestModelImpl): Promise<void> {
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: ChatRequestModelImpl): Promise<void>;
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: ChatRequestModelImpl): Promise<void> {
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: ChatRequestModelImpl): ChatResponseContent;
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: ChatRequestModelImpl): Promise<void> {
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: ChatRequestModelImpl): Promise<void> {
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: ChatRequestModelImpl): ChatResponseContent | ChatResponseContent[] {
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
- new ToolCallChatResponseContentImpl(toolCall.id, toolCall.function?.name, toolCall.function?.arguments, toolCall.finished, toolCall.result));
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
  }
@@ -40,7 +40,7 @@ export namespace ChatHistoryEntry {
40
40
  agentId: agentId,
41
41
  sessionId: request.session.id,
42
42
  requestId: request.id,
43
- response: request.response.response.asString(),
43
+ response: request.response.response.asDisplayString(),
44
44
  ...args,
45
45
  };
46
46
  }