@theia/ai-chat 1.60.2 → 1.61.0

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 (118) hide show
  1. package/lib/browser/ai-chat-frontend-contribution.d.ts +11 -0
  2. package/lib/browser/ai-chat-frontend-contribution.d.ts.map +1 -0
  3. package/lib/browser/ai-chat-frontend-contribution.js +56 -0
  4. package/lib/browser/ai-chat-frontend-contribution.js.map +1 -0
  5. package/lib/browser/ai-chat-frontend-module.d.ts.map +1 -1
  6. package/lib/browser/ai-chat-frontend-module.js +21 -3
  7. package/lib/browser/ai-chat-frontend-module.js.map +1 -1
  8. package/lib/browser/change-set-decorator-service.d.ts +24 -0
  9. package/lib/browser/change-set-decorator-service.d.ts.map +1 -0
  10. package/lib/browser/change-set-decorator-service.js +66 -0
  11. package/lib/browser/change-set-decorator-service.js.map +1 -0
  12. package/lib/browser/change-set-file-element.d.ts +7 -4
  13. package/lib/browser/change-set-file-element.d.ts.map +1 -1
  14. package/lib/browser/change-set-file-element.js +20 -12
  15. package/lib/browser/change-set-file-element.js.map +1 -1
  16. package/lib/browser/change-set-file-resource.d.ts +1 -42
  17. package/lib/browser/change-set-file-resource.d.ts.map +1 -1
  18. package/lib/browser/change-set-file-resource.js +1 -136
  19. package/lib/browser/change-set-file-resource.js.map +1 -1
  20. package/lib/browser/change-set-variable.d.ts.map +1 -1
  21. package/lib/browser/change-set-variable.js +13 -4
  22. package/lib/browser/change-set-variable.js.map +1 -1
  23. package/lib/browser/context-file-variable-label-provider.js +1 -1
  24. package/lib/browser/context-file-variable-label-provider.js.map +1 -1
  25. package/lib/browser/file-chat-variable-contribution.d.ts.map +1 -1
  26. package/lib/browser/file-chat-variable-contribution.js +29 -27
  27. package/lib/browser/file-chat-variable-contribution.js.map +1 -1
  28. package/lib/browser/task-context-service.d.ts +40 -0
  29. package/lib/browser/task-context-service.d.ts.map +1 -0
  30. package/lib/browser/task-context-service.js +148 -0
  31. package/lib/browser/task-context-service.js.map +1 -0
  32. package/lib/browser/task-context-storage-service.d.ts +18 -0
  33. package/lib/browser/task-context-storage-service.d.ts.map +1 -0
  34. package/lib/browser/task-context-storage-service.js +77 -0
  35. package/lib/browser/task-context-storage-service.js.map +1 -0
  36. package/lib/browser/task-context-variable-contribution.d.ts +20 -0
  37. package/lib/browser/task-context-variable-contribution.d.ts.map +1 -0
  38. package/lib/browser/task-context-variable-contribution.js +101 -0
  39. package/lib/browser/task-context-variable-contribution.js.map +1 -0
  40. package/lib/browser/task-context-variable-label-provider.d.ts +21 -0
  41. package/lib/browser/task-context-variable-label-provider.d.ts.map +1 -0
  42. package/lib/browser/task-context-variable-label-provider.js +83 -0
  43. package/lib/browser/task-context-variable-label-provider.js.map +1 -0
  44. package/lib/browser/task-context-variable.d.ts +3 -0
  45. package/lib/browser/task-context-variable.d.ts.map +1 -0
  46. package/lib/browser/task-context-variable.js +29 -0
  47. package/lib/browser/task-context-variable.js.map +1 -0
  48. package/lib/common/chat-agents.d.ts +2 -1
  49. package/lib/common/chat-agents.d.ts.map +1 -1
  50. package/lib/common/chat-agents.js +32 -20
  51. package/lib/common/chat-agents.js.map +1 -1
  52. package/lib/common/chat-model.d.ts +191 -8
  53. package/lib/common/chat-model.d.ts.map +1 -1
  54. package/lib/common/chat-model.js +369 -12
  55. package/lib/common/chat-model.js.map +1 -1
  56. package/lib/common/chat-request-parser.d.ts +1 -1
  57. package/lib/common/chat-request-parser.d.ts.map +1 -1
  58. package/lib/common/chat-request-parser.js +1 -1
  59. package/lib/common/chat-request-parser.js.map +1 -1
  60. package/lib/common/chat-service.d.ts +2 -0
  61. package/lib/common/chat-service.d.ts.map +1 -1
  62. package/lib/common/chat-service.js +18 -25
  63. package/lib/common/chat-service.js.map +1 -1
  64. package/lib/common/chat-session-naming-service.d.ts.map +1 -1
  65. package/lib/common/chat-session-naming-service.js +9 -11
  66. package/lib/common/chat-session-naming-service.js.map +1 -1
  67. package/lib/common/chat-session-summary-agent-prompt.d.ts +5 -0
  68. package/lib/common/chat-session-summary-agent-prompt.d.ts.map +1 -0
  69. package/lib/common/chat-session-summary-agent-prompt.js +30 -0
  70. package/lib/common/chat-session-summary-agent-prompt.js.map +1 -0
  71. package/lib/common/chat-session-summary-agent.d.ts +17 -0
  72. package/lib/common/chat-session-summary-agent.d.ts.map +1 -0
  73. package/lib/common/chat-session-summary-agent.js +48 -0
  74. package/lib/common/chat-session-summary-agent.js.map +1 -0
  75. package/lib/common/context-summary-variable.js +1 -1
  76. package/lib/common/context-summary-variable.js.map +1 -1
  77. package/lib/common/parse-contents-with-incomplete-parts.spec.d.ts +2 -0
  78. package/lib/common/parse-contents-with-incomplete-parts.spec.d.ts.map +1 -0
  79. package/lib/common/parse-contents-with-incomplete-parts.spec.js +103 -0
  80. package/lib/common/parse-contents-with-incomplete-parts.spec.js.map +1 -0
  81. package/lib/common/parse-contents.d.ts +1 -0
  82. package/lib/common/parse-contents.d.ts.map +1 -1
  83. package/lib/common/parse-contents.js +45 -5
  84. package/lib/common/parse-contents.js.map +1 -1
  85. package/lib/common/parse-contents.spec.d.ts +1 -0
  86. package/lib/common/parse-contents.spec.d.ts.map +1 -1
  87. package/lib/common/parse-contents.spec.js +25 -13
  88. package/lib/common/parse-contents.spec.js.map +1 -1
  89. package/lib/common/response-content-matcher.d.ts +6 -0
  90. package/lib/common/response-content-matcher.d.ts.map +1 -1
  91. package/lib/common/response-content-matcher.js +14 -3
  92. package/lib/common/response-content-matcher.js.map +1 -1
  93. package/package.json +11 -11
  94. package/src/browser/ai-chat-frontend-contribution.ts +49 -0
  95. package/src/browser/ai-chat-frontend-module.ts +25 -4
  96. package/src/browser/change-set-decorator-service.ts +72 -0
  97. package/src/browser/change-set-file-element.ts +18 -13
  98. package/src/browser/change-set-file-resource.ts +1 -138
  99. package/src/browser/change-set-variable.ts +14 -6
  100. package/src/browser/context-file-variable-label-provider.ts +1 -1
  101. package/src/browser/file-chat-variable-contribution.ts +26 -29
  102. package/src/browser/task-context-service.ts +144 -0
  103. package/src/browser/task-context-storage-service.ts +75 -0
  104. package/src/browser/task-context-variable-contribution.ts +93 -0
  105. package/src/browser/task-context-variable-label-provider.ts +67 -0
  106. package/src/browser/task-context-variable.ts +28 -0
  107. package/src/common/chat-agents.ts +38 -22
  108. package/src/common/chat-model.ts +566 -17
  109. package/src/common/chat-request-parser.ts +2 -2
  110. package/src/common/chat-service.ts +17 -26
  111. package/src/common/chat-session-naming-service.ts +13 -15
  112. package/src/common/chat-session-summary-agent-prompt.ts +28 -0
  113. package/src/common/chat-session-summary-agent.ts +42 -0
  114. package/src/common/context-summary-variable.ts +1 -1
  115. package/src/common/parse-contents-with-incomplete-parts.spec.ts +114 -0
  116. package/src/common/parse-contents.spec.ts +24 -12
  117. package/src/common/parse-contents.ts +52 -6
  118. package/src/common/response-content-matcher.ts +21 -3
@@ -0,0 +1,28 @@
1
+ // *****************************************************************************
2
+ // Copyright (C) 2025 EclipseSource GmbH and others.
3
+ //
4
+ // This program and the accompanying materials are made available under the
5
+ // terms of the Eclipse Public License v. 2.0 which is available at
6
+ // http://www.eclipse.org/legal/epl-2.0.
7
+ //
8
+ // This Source Code may also be made available under the following Secondary
9
+ // Licenses when the conditions for such availability set forth in the Eclipse
10
+ // Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
+ // with the GNU Classpath Exception which is available at
12
+ // https://www.gnu.org/software/classpath/license.html.
13
+ //
14
+ // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
15
+ // *****************************************************************************
16
+
17
+ import { AIVariable } from '@theia/ai-core';
18
+ import { codiconArray } from '@theia/core/lib/browser';
19
+
20
+ export const TASK_CONTEXT_VARIABLE: AIVariable = {
21
+ id: 'taskContext',
22
+ description: 'Provides context information for a task, e.g. the plan for completing a task or a summary of a previous sessions',
23
+ name: 'taskContext',
24
+ label: 'Task Context',
25
+ iconClasses: codiconArray('clippy'),
26
+ isContextVariable: true,
27
+ args: [{ name: 'context-id', description: 'The ID of the task context to retrieve, or a chat session to summarize.' }]
28
+ };
@@ -22,11 +22,13 @@
22
22
  import {
23
23
  AgentSpecificVariables,
24
24
  AIVariableContext,
25
+ AIVariableResolutionRequest,
25
26
  CommunicationRecordingService,
26
27
  getTextOfResponse,
27
28
  isTextResponsePart,
28
29
  isThinkingResponsePart,
29
30
  isToolCallResponsePart,
31
+ isUsageResponsePart,
30
32
  LanguageModel,
31
33
  LanguageModelMessage,
32
34
  LanguageModelRequirement,
@@ -58,9 +60,9 @@ import {
58
60
  MarkdownChatResponseContentImpl,
59
61
  ToolCallChatResponseContentImpl,
60
62
  ChatRequestModel,
61
- ThinkingChatResponseContentImpl
63
+ ThinkingChatResponseContentImpl,
62
64
  } from './chat-model';
63
- import { findFirstMatch, parseContents } from './parse-contents';
65
+ import { parseContents } from './parse-contents';
64
66
  import { DefaultResponseContentFactory, ResponseContentMatcher, ResponseContentMatcherProvider } from './response-content-matcher';
65
67
  import { ChatToolRequest, ChatToolRequestService } from './chat-tool-request-service';
66
68
 
@@ -90,6 +92,10 @@ export namespace ChatSessionContext {
90
92
  export function is(candidate: unknown): candidate is ChatSessionContext {
91
93
  return typeof candidate === 'object' && !!candidate && 'model' in candidate;
92
94
  }
95
+
96
+ export function getVariables(context: ChatSessionContext): readonly AIVariableResolutionRequest[] {
97
+ return context.request?.context.variables.map(AIVariableResolutionRequest.fromResolved) ?? context.model.context.getVariables();
98
+ }
93
99
  }
94
100
 
95
101
  /**
@@ -389,28 +395,35 @@ export abstract class AbstractStreamParsingChatAgent extends AbstractChatAgent {
389
395
  }
390
396
 
391
397
  protected async addStreamResponse(languageModelResponse: LanguageModelStreamResponse, request: MutableChatRequestModel): Promise<void> {
392
- for await (const token of languageModelResponse.stream) {
393
- const newContents = this.parse(token, request);
394
- if (isArray(newContents)) {
395
- request.response.response.addContents(newContents);
396
- } else {
397
- request.response.response.addContent(newContents);
398
- }
398
+ let completeTextBuffer = '';
399
+ let startIndex = Math.max(0, request.response.response.content.length - 1);
399
400
 
400
- const lastContent = request.response.response.content.pop();
401
- if (lastContent === undefined) {
402
- return;
403
- }
404
- const text = lastContent.asString?.();
405
- if (text === undefined) {
406
- return;
407
- }
408
-
409
- const result: ChatResponseContent[] = findFirstMatch(this.contentMatchers, text) ? this.parseContents(text, request) : [];
410
- if (result.length > 0) {
411
- request.response.response.addContents(result);
401
+ for await (const token of languageModelResponse.stream) {
402
+ const newContent = this.parse(token, request);
403
+
404
+ if (!(isTextResponsePart(token) && token.content)) {
405
+ // For non-text tokens (like tool calls), add them directly
406
+ if (isArray(newContent)) {
407
+ request.response.response.addContents(newContent);
408
+ } else {
409
+ request.response.response.addContent(newContent);
410
+ }
411
+ // And reset the marker index and the text buffer as we skip matching across non-text tokens
412
+ startIndex = request.response.response.content.length - 1;
413
+ completeTextBuffer = '';
412
414
  } else {
413
- request.response.response.addContent(lastContent);
415
+ // parse the entire text so far (since beginning of the stream or last non-text token)
416
+ // and replace the entire content with the currently parsed content parts
417
+ completeTextBuffer += token.content;
418
+
419
+ const parsedContents = this.parseContents(completeTextBuffer, request);
420
+ const contentBeforeMarker = startIndex > 0
421
+ ? request.response.response.content.slice(0, startIndex)
422
+ : [];
423
+
424
+ request.response.response.clearContent();
425
+ request.response.response.addContents(contentBeforeMarker);
426
+ request.response.response.addContents(parsedContents);
414
427
  }
415
428
  }
416
429
  }
@@ -435,6 +448,9 @@ export abstract class AbstractStreamParsingChatAgent extends AbstractChatAgent {
435
448
  if (isThinkingResponsePart(token)) {
436
449
  return new ThinkingChatResponseContentImpl(token.thought, token.signature);
437
450
  }
451
+ if (isUsageResponsePart(token)) {
452
+ return [];
453
+ }
438
454
  return this.defaultContentFactory.create('', request);
439
455
  }
440
456