@theia/ai-chat 1.67.0-next.13 → 1.67.0-next.56

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 (254) hide show
  1. package/README.md +1 -0
  2. package/package.json +9 -9
  3. package/lib/browser/agent-delegation-tool.d.ts +0 -25
  4. package/lib/browser/agent-delegation-tool.d.ts.map +0 -1
  5. package/lib/browser/agent-delegation-tool.js +0 -196
  6. package/lib/browser/agent-delegation-tool.js.map +0 -1
  7. package/lib/browser/ai-chat-frontend-contribution.d.ts +0 -11
  8. package/lib/browser/ai-chat-frontend-contribution.d.ts.map +0 -1
  9. package/lib/browser/ai-chat-frontend-contribution.js +0 -56
  10. package/lib/browser/ai-chat-frontend-contribution.js.map +0 -1
  11. package/lib/browser/ai-chat-frontend-module.d.ts +0 -4
  12. package/lib/browser/ai-chat-frontend-module.d.ts.map +0 -1
  13. package/lib/browser/ai-chat-frontend-module.js +0 -143
  14. package/lib/browser/ai-chat-frontend-module.js.map +0 -1
  15. package/lib/browser/change-set-decorator-service.d.ts +0 -24
  16. package/lib/browser/change-set-decorator-service.d.ts.map +0 -1
  17. package/lib/browser/change-set-decorator-service.js +0 -66
  18. package/lib/browser/change-set-decorator-service.js.map +0 -1
  19. package/lib/browser/change-set-file-element-deserializer.d.ts +0 -7
  20. package/lib/browser/change-set-file-element-deserializer.d.ts.map +0 -1
  21. package/lib/browser/change-set-file-element-deserializer.js +0 -61
  22. package/lib/browser/change-set-file-element-deserializer.js.map +0 -1
  23. package/lib/browser/change-set-file-element.d.ts +0 -122
  24. package/lib/browser/change-set-file-element.d.ts.map +0 -1
  25. package/lib/browser/change-set-file-element.js +0 -435
  26. package/lib/browser/change-set-file-element.js.map +0 -1
  27. package/lib/browser/change-set-file-resource.d.ts +0 -4
  28. package/lib/browser/change-set-file-resource.d.ts.map +0 -1
  29. package/lib/browser/change-set-file-resource.js +0 -24
  30. package/lib/browser/change-set-file-resource.js.map +0 -1
  31. package/lib/browser/change-set-file-service.d.ts +0 -32
  32. package/lib/browser/change-set-file-service.d.ts.map +0 -1
  33. package/lib/browser/change-set-file-service.js +0 -161
  34. package/lib/browser/change-set-file-service.js.map +0 -1
  35. package/lib/browser/change-set-variable.d.ts +0 -11
  36. package/lib/browser/change-set-variable.d.ts.map +0 -1
  37. package/lib/browser/change-set-variable.js +0 -64
  38. package/lib/browser/change-set-variable.js.map +0 -1
  39. package/lib/browser/chat-session-store-impl.d.ts +0 -36
  40. package/lib/browser/chat-session-store-impl.d.ts.map +0 -1
  41. package/lib/browser/chat-session-store-impl.js +0 -287
  42. package/lib/browser/chat-session-store-impl.js.map +0 -1
  43. package/lib/browser/chat-tool-preference-bindings.d.ts +0 -34
  44. package/lib/browser/chat-tool-preference-bindings.d.ts.map +0 -1
  45. package/lib/browser/chat-tool-preference-bindings.js +0 -122
  46. package/lib/browser/chat-tool-preference-bindings.js.map +0 -1
  47. package/lib/browser/chat-tool-request-service.d.ts +0 -21
  48. package/lib/browser/chat-tool-request-service.d.ts.map +0 -1
  49. package/lib/browser/chat-tool-request-service.js +0 -90
  50. package/lib/browser/chat-tool-request-service.js.map +0 -1
  51. package/lib/browser/context-file-validation-service.d.ts +0 -15
  52. package/lib/browser/context-file-validation-service.d.ts.map +0 -1
  53. package/lib/browser/context-file-validation-service.js +0 -26
  54. package/lib/browser/context-file-validation-service.js.map +0 -1
  55. package/lib/browser/context-file-variable-label-provider.d.ts +0 -14
  56. package/lib/browser/context-file-variable-label-provider.d.ts.map +0 -1
  57. package/lib/browser/context-file-variable-label-provider.js +0 -63
  58. package/lib/browser/context-file-variable-label-provider.js.map +0 -1
  59. package/lib/browser/context-variable-label-provider.d.ts +0 -9
  60. package/lib/browser/context-variable-label-provider.d.ts.map +0 -1
  61. package/lib/browser/context-variable-label-provider.js +0 -55
  62. package/lib/browser/context-variable-label-provider.js.map +0 -1
  63. package/lib/browser/custom-agent-factory.d.ts +0 -4
  64. package/lib/browser/custom-agent-factory.d.ts.map +0 -1
  65. package/lib/browser/custom-agent-factory.js +0 -20
  66. package/lib/browser/custom-agent-factory.js.map +0 -1
  67. package/lib/browser/custom-agent-frontend-application-contribution.d.ts +0 -13
  68. package/lib/browser/custom-agent-frontend-application-contribution.d.ts.map +0 -1
  69. package/lib/browser/custom-agent-frontend-application-contribution.js +0 -83
  70. package/lib/browser/custom-agent-frontend-application-contribution.js.map +0 -1
  71. package/lib/browser/delegation-response-content.d.ts +0 -20
  72. package/lib/browser/delegation-response-content.d.ts.map +0 -1
  73. package/lib/browser/delegation-response-content.js +0 -47
  74. package/lib/browser/delegation-response-content.js.map +0 -1
  75. package/lib/browser/file-chat-variable-contribution.d.ts +0 -32
  76. package/lib/browser/file-chat-variable-contribution.d.ts.map +0 -1
  77. package/lib/browser/file-chat-variable-contribution.js +0 -241
  78. package/lib/browser/file-chat-variable-contribution.js.map +0 -1
  79. package/lib/browser/frontend-chat-service.d.ts +0 -15
  80. package/lib/browser/frontend-chat-service.d.ts.map +0 -1
  81. package/lib/browser/frontend-chat-service.js +0 -72
  82. package/lib/browser/frontend-chat-service.js.map +0 -1
  83. package/lib/browser/image-context-variable-contribution.d.ts +0 -27
  84. package/lib/browser/image-context-variable-contribution.d.ts.map +0 -1
  85. package/lib/browser/image-context-variable-contribution.js +0 -149
  86. package/lib/browser/image-context-variable-contribution.js.map +0 -1
  87. package/lib/browser/task-context-service.d.ts +0 -46
  88. package/lib/browser/task-context-service.d.ts.map +0 -1
  89. package/lib/browser/task-context-service.js +0 -256
  90. package/lib/browser/task-context-service.js.map +0 -1
  91. package/lib/browser/task-context-storage-service.d.ts +0 -19
  92. package/lib/browser/task-context-storage-service.d.ts.map +0 -1
  93. package/lib/browser/task-context-storage-service.js +0 -80
  94. package/lib/browser/task-context-storage-service.js.map +0 -1
  95. package/lib/browser/task-context-variable-contribution.d.ts +0 -20
  96. package/lib/browser/task-context-variable-contribution.d.ts.map +0 -1
  97. package/lib/browser/task-context-variable-contribution.js +0 -101
  98. package/lib/browser/task-context-variable-contribution.js.map +0 -1
  99. package/lib/browser/task-context-variable-label-provider.d.ts +0 -21
  100. package/lib/browser/task-context-variable-label-provider.d.ts.map +0 -1
  101. package/lib/browser/task-context-variable-label-provider.js +0 -83
  102. package/lib/browser/task-context-variable-label-provider.js.map +0 -1
  103. package/lib/browser/task-context-variable.d.ts +0 -3
  104. package/lib/browser/task-context-variable.d.ts.map +0 -1
  105. package/lib/browser/task-context-variable.js +0 -33
  106. package/lib/browser/task-context-variable.js.map +0 -1
  107. package/lib/common/ai-chat-preferences.d.ts +0 -5
  108. package/lib/common/ai-chat-preferences.d.ts.map +0 -1
  109. package/lib/common/ai-chat-preferences.js +0 -40
  110. package/lib/common/ai-chat-preferences.js.map +0 -1
  111. package/lib/common/change-set-element-deserializer.d.ts +0 -30
  112. package/lib/common/change-set-element-deserializer.d.ts.map +0 -1
  113. package/lib/common/change-set-element-deserializer.js +0 -81
  114. package/lib/common/change-set-element-deserializer.js.map +0 -1
  115. package/lib/common/change-set.d.ts +0 -85
  116. package/lib/common/change-set.d.ts.map +0 -1
  117. package/lib/common/change-set.js +0 -133
  118. package/lib/common/change-set.js.map +0 -1
  119. package/lib/common/chat-agent-service.d.ts +0 -46
  120. package/lib/common/chat-agent-service.d.ts.map +0 -1
  121. package/lib/common/chat-agent-service.js +0 -79
  122. package/lib/common/chat-agent-service.js.map +0 -1
  123. package/lib/common/chat-agents-variable-contribution.d.ts +0 -17
  124. package/lib/common/chat-agents-variable-contribution.d.ts.map +0 -1
  125. package/lib/common/chat-agents-variable-contribution.js +0 -67
  126. package/lib/common/chat-agents-variable-contribution.js.map +0 -1
  127. package/lib/common/chat-agents.d.ts +0 -138
  128. package/lib/common/chat-agents.d.ts.map +0 -1
  129. package/lib/common/chat-agents.js +0 -428
  130. package/lib/common/chat-agents.js.map +0 -1
  131. package/lib/common/chat-auto-save.spec.d.ts +0 -2
  132. package/lib/common/chat-auto-save.spec.d.ts.map +0 -1
  133. package/lib/common/chat-auto-save.spec.js +0 -304
  134. package/lib/common/chat-auto-save.spec.js.map +0 -1
  135. package/lib/common/chat-content-deserializer.d.ts +0 -161
  136. package/lib/common/chat-content-deserializer.d.ts.map +0 -1
  137. package/lib/common/chat-content-deserializer.js +0 -166
  138. package/lib/common/chat-content-deserializer.js.map +0 -1
  139. package/lib/common/chat-content-deserializer.spec.d.ts +0 -2
  140. package/lib/common/chat-content-deserializer.spec.d.ts.map +0 -1
  141. package/lib/common/chat-content-deserializer.spec.js +0 -307
  142. package/lib/common/chat-content-deserializer.spec.js.map +0 -1
  143. package/lib/common/chat-model-serialization.d.ts +0 -110
  144. package/lib/common/chat-model-serialization.d.ts.map +0 -1
  145. package/lib/common/chat-model-serialization.js +0 -20
  146. package/lib/common/chat-model-serialization.js.map +0 -1
  147. package/lib/common/chat-model-serialization.spec.d.ts +0 -2
  148. package/lib/common/chat-model-serialization.spec.d.ts.map +0 -1
  149. package/lib/common/chat-model-serialization.spec.js +0 -278
  150. package/lib/common/chat-model-serialization.spec.js.map +0 -1
  151. package/lib/common/chat-model-util.d.ts +0 -7
  152. package/lib/common/chat-model-util.d.ts.map +0 -1
  153. package/lib/common/chat-model-util.js +0 -50
  154. package/lib/common/chat-model-util.js.map +0 -1
  155. package/lib/common/chat-model.d.ts +0 -923
  156. package/lib/common/chat-model.d.ts.map +0 -1
  157. package/lib/common/chat-model.js +0 -1791
  158. package/lib/common/chat-model.js.map +0 -1
  159. package/lib/common/chat-request-parser.d.ts +0 -38
  160. package/lib/common/chat-request-parser.d.ts.map +0 -1
  161. package/lib/common/chat-request-parser.js +0 -230
  162. package/lib/common/chat-request-parser.js.map +0 -1
  163. package/lib/common/chat-request-parser.spec.d.ts +0 -2
  164. package/lib/common/chat-request-parser.spec.d.ts.map +0 -1
  165. package/lib/common/chat-request-parser.spec.js +0 -235
  166. package/lib/common/chat-request-parser.spec.js.map +0 -1
  167. package/lib/common/chat-service-deletion.spec.d.ts +0 -2
  168. package/lib/common/chat-service-deletion.spec.d.ts.map +0 -1
  169. package/lib/common/chat-service-deletion.spec.js +0 -221
  170. package/lib/common/chat-service-deletion.spec.js.map +0 -1
  171. package/lib/common/chat-service.d.ts +0 -153
  172. package/lib/common/chat-service.d.ts.map +0 -1
  173. package/lib/common/chat-service.js +0 -474
  174. package/lib/common/chat-service.js.map +0 -1
  175. package/lib/common/chat-session-naming-prompt-template.d.ts +0 -3
  176. package/lib/common/chat-session-naming-prompt-template.d.ts.map +0 -1
  177. package/lib/common/chat-session-naming-prompt-template.js +0 -31
  178. package/lib/common/chat-session-naming-prompt-template.js.map +0 -1
  179. package/lib/common/chat-session-naming-service.d.ts +0 -26
  180. package/lib/common/chat-session-naming-service.d.ts.map +0 -1
  181. package/lib/common/chat-session-naming-service.js +0 -119
  182. package/lib/common/chat-session-naming-service.js.map +0 -1
  183. package/lib/common/chat-session-store.d.ts +0 -43
  184. package/lib/common/chat-session-store.d.ts.map +0 -1
  185. package/lib/common/chat-session-store.js +0 -20
  186. package/lib/common/chat-session-store.js.map +0 -1
  187. package/lib/common/chat-session-summary-agent-prompt.d.ts +0 -8
  188. package/lib/common/chat-session-summary-agent-prompt.d.ts.map +0 -1
  189. package/lib/common/chat-session-summary-agent-prompt.js +0 -33
  190. package/lib/common/chat-session-summary-agent-prompt.js.map +0 -1
  191. package/lib/common/chat-session-summary-agent.d.ts +0 -16
  192. package/lib/common/chat-session-summary-agent.d.ts.map +0 -1
  193. package/lib/common/chat-session-summary-agent.js +0 -48
  194. package/lib/common/chat-session-summary-agent.js.map +0 -1
  195. package/lib/common/chat-string-utils.d.ts +0 -3
  196. package/lib/common/chat-string-utils.d.ts.map +0 -1
  197. package/lib/common/chat-string-utils.js +0 -27
  198. package/lib/common/chat-string-utils.js.map +0 -1
  199. package/lib/common/chat-tool-preferences.d.ts +0 -23
  200. package/lib/common/chat-tool-preferences.d.ts.map +0 -1
  201. package/lib/common/chat-tool-preferences.js +0 -68
  202. package/lib/common/chat-tool-preferences.js.map +0 -1
  203. package/lib/common/chat-tool-request-service.d.ts +0 -18
  204. package/lib/common/chat-tool-request-service.d.ts.map +0 -1
  205. package/lib/common/chat-tool-request-service.js +0 -52
  206. package/lib/common/chat-tool-request-service.js.map +0 -1
  207. package/lib/common/context-details-variable.d.ts +0 -9
  208. package/lib/common/context-details-variable.d.ts.map +0 -1
  209. package/lib/common/context-details-variable.js +0 -57
  210. package/lib/common/context-details-variable.js.map +0 -1
  211. package/lib/common/context-summary-variable.d.ts +0 -9
  212. package/lib/common/context-summary-variable.d.ts.map +0 -1
  213. package/lib/common/context-summary-variable.js +0 -57
  214. package/lib/common/context-summary-variable.js.map +0 -1
  215. package/lib/common/context-variables.d.ts +0 -4
  216. package/lib/common/context-variables.d.ts.map +0 -1
  217. package/lib/common/context-variables.js +0 -22
  218. package/lib/common/context-variables.js.map +0 -1
  219. package/lib/common/custom-chat-agent.d.ts +0 -10
  220. package/lib/common/custom-chat-agent.d.ts.map +0 -1
  221. package/lib/common/custom-chat-agent.js +0 -40
  222. package/lib/common/custom-chat-agent.js.map +0 -1
  223. package/lib/common/image-context-variable.d.ts +0 -29
  224. package/lib/common/image-context-variable.d.ts.map +0 -1
  225. package/lib/common/image-context-variable.js +0 -114
  226. package/lib/common/image-context-variable.js.map +0 -1
  227. package/lib/common/index.d.ts +0 -13
  228. package/lib/common/index.d.ts.map +0 -1
  229. package/lib/common/index.js +0 -31
  230. package/lib/common/index.js.map +0 -1
  231. package/lib/common/parse-contents-with-incomplete-parts.spec.d.ts +0 -2
  232. package/lib/common/parse-contents-with-incomplete-parts.spec.d.ts.map +0 -1
  233. package/lib/common/parse-contents-with-incomplete-parts.spec.js +0 -103
  234. package/lib/common/parse-contents-with-incomplete-parts.spec.js.map +0 -1
  235. package/lib/common/parse-contents.d.ts +0 -12
  236. package/lib/common/parse-contents.d.ts.map +0 -1
  237. package/lib/common/parse-contents.js +0 -107
  238. package/lib/common/parse-contents.js.map +0 -1
  239. package/lib/common/parse-contents.spec.d.ts +0 -10
  240. package/lib/common/parse-contents.spec.d.ts.map +0 -1
  241. package/lib/common/parse-contents.spec.js +0 -146
  242. package/lib/common/parse-contents.spec.js.map +0 -1
  243. package/lib/common/parsed-chat-request.d.ts +0 -66
  244. package/lib/common/parsed-chat-request.d.ts.map +0 -1
  245. package/lib/common/parsed-chat-request.js +0 -83
  246. package/lib/common/parsed-chat-request.js.map +0 -1
  247. package/lib/common/response-content-matcher.d.ts +0 -69
  248. package/lib/common/response-content-matcher.d.ts.map +0 -1
  249. package/lib/common/response-content-matcher.js +0 -97
  250. package/lib/common/response-content-matcher.js.map +0 -1
  251. package/lib/node/ai-chat-backend-module.d.ts +0 -4
  252. package/lib/node/ai-chat-backend-module.d.ts.map +0 -1
  253. package/lib/node/ai-chat-backend-module.js +0 -26
  254. package/lib/node/ai-chat-backend-module.js.map +0 -1
@@ -1,67 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ChatAgentsVariableContribution = exports.CHAT_AGENTS_VARIABLE = void 0;
4
- const tslib_1 = require("tslib");
5
- // *****************************************************************************
6
- // Copyright (C) 2024 EclipseSource GmbH.
7
- //
8
- // This program and the accompanying materials are made available under the
9
- // terms of the Eclipse Public License v. 2.0 which is available at
10
- // http://www.eclipse.org/legal/epl-2.0.
11
- //
12
- // This Source Code may also be made available under the following Secondary
13
- // Licenses when the conditions for such availability set forth in the Eclipse
14
- // Public License v. 2.0 are satisfied: GNU General Public License, version 2
15
- // with the GNU Classpath Exception which is available at
16
- // https://www.gnu.org/software/classpath/license.html.
17
- //
18
- // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
19
- // *****************************************************************************
20
- const core_1 = require("@theia/core");
21
- const inversify_1 = require("@theia/core/shared/inversify");
22
- const chat_agent_service_1 = require("./chat-agent-service");
23
- exports.CHAT_AGENTS_VARIABLE = {
24
- id: 'chatAgents',
25
- name: 'chatAgents',
26
- description: core_1.nls.localize('theia/ai/chat/chatAgentsVariable/description', 'Returns the list of chat agents available in the system')
27
- };
28
- let ChatAgentsVariableContribution = class ChatAgentsVariableContribution {
29
- registerVariables(service) {
30
- service.registerResolver(exports.CHAT_AGENTS_VARIABLE, this);
31
- }
32
- canResolve(request, _context) {
33
- if (request.variable.name === exports.CHAT_AGENTS_VARIABLE.name) {
34
- return 1;
35
- }
36
- return -1;
37
- }
38
- async resolve(request, context) {
39
- if (request.variable.name === exports.CHAT_AGENTS_VARIABLE.name) {
40
- return this.resolveAgentsVariable(request);
41
- }
42
- }
43
- resolveAgentsVariable(_request) {
44
- const agents = this.agents.getAgents().map(agent => ({
45
- id: agent.id,
46
- name: agent.name,
47
- description: agent.description
48
- }));
49
- const value = agents.map(agent => prettyPrintInMd(agent)).join('\n');
50
- return { variable: exports.CHAT_AGENTS_VARIABLE, value };
51
- }
52
- };
53
- exports.ChatAgentsVariableContribution = ChatAgentsVariableContribution;
54
- tslib_1.__decorate([
55
- (0, inversify_1.inject)(chat_agent_service_1.ChatAgentService),
56
- tslib_1.__metadata("design:type", Object)
57
- ], ChatAgentsVariableContribution.prototype, "agents", void 0);
58
- exports.ChatAgentsVariableContribution = ChatAgentsVariableContribution = tslib_1.__decorate([
59
- (0, inversify_1.injectable)()
60
- ], ChatAgentsVariableContribution);
61
- function prettyPrintInMd(agent) {
62
- return `- ${agent.id}
63
- - *ID*: ${agent.id}
64
- - *Name*: ${agent.name}
65
- - *Description*: ${agent.description.replace(/\n/g, ' ')}`;
66
- }
67
- //# sourceMappingURL=chat-agents-variable-contribution.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"chat-agents-variable-contribution.js","sourceRoot":"","sources":["../../src/common/chat-agents-variable-contribution.ts"],"names":[],"mappings":";;;;AAAA,gFAAgF;AAChF,yCAAyC;AACzC,EAAE;AACF,2EAA2E;AAC3E,mEAAmE;AACnE,wCAAwC;AACxC,EAAE;AACF,4EAA4E;AAC5E,8EAA8E;AAC9E,6EAA6E;AAC7E,yDAAyD;AACzD,uDAAuD;AACvD,EAAE;AACF,gFAAg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EAAE,CAAC;IACrD,CAAC;CACJ,CAAA;AA/BY,wEAA8B;AAGpB;IADlB,IAAA,kBAAM,EAAC,qCAAgB,CAAC;;8DACmB;yCAHnC,8BAA8B;IAD1C,IAAA,sBAAU,GAAE;GACA,8BAA8B,CA+B1C;AAED,SAAS,eAAe,CAAC,KAAyD;IAC9E,OAAO,KAAK,KAAK,CAAC,EAAE;YACZ,KAAK,CAAC,EAAE;cACN,KAAK,CAAC,IAAI;qBACH,KAAK,CAAC,WAAW,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,EAAE,CAAC;AAC7D,CAAC"}
@@ -1,138 +0,0 @@
1
- import { AgentSpecificVariables, AIVariableContext, AIVariableResolutionRequest, LanguageModel, LanguageModelMessage, LanguageModelRequirement, LanguageModelResponse, LanguageModelService, LanguageModelStreamResponse, PromptService, ResolvedPromptFragment, PromptVariantSet, ToolCall, ToolRequest } from '@theia/ai-core';
2
- import { Agent, LanguageModelRegistry, LanguageModelStreamResponsePart } from '@theia/ai-core/lib/common';
3
- import { ContributionProvider, ILogger } from '@theia/core';
4
- import { ChatAgentService } from './chat-agent-service';
5
- import { ChatModel, ChatRequestModel, ChatResponseContent, MutableChatRequestModel } from './chat-model';
6
- import { ChatToolRequest, ChatToolRequestService } from './chat-tool-request-service';
7
- import { DefaultResponseContentFactory, ResponseContentMatcher, ResponseContentMatcherProvider } from './response-content-matcher';
8
- /**
9
- * System message content, enriched with function descriptions.
10
- */
11
- export interface SystemMessageDescription {
12
- text: string;
13
- /** All functions references in the system message. */
14
- functionDescriptions?: Map<string, ToolRequest>;
15
- }
16
- export declare namespace SystemMessageDescription {
17
- function fromResolvedPromptFragment(resolvedPrompt: ResolvedPromptFragment): SystemMessageDescription;
18
- }
19
- export interface ChatSessionContext extends AIVariableContext {
20
- request?: ChatRequestModel;
21
- model: ChatModel;
22
- }
23
- export declare namespace ChatSessionContext {
24
- function is(candidate: unknown): candidate is ChatSessionContext;
25
- function getVariables(context: ChatSessionContext): readonly AIVariableResolutionRequest[];
26
- }
27
- /**
28
- * The location from where an chat agent may be invoked.
29
- * Based on the location, a different context may be available.
30
- */
31
- export declare enum ChatAgentLocation {
32
- Panel = "panel",
33
- Terminal = "terminal",
34
- Notebook = "notebook",
35
- Editor = "editor"
36
- }
37
- export declare namespace ChatAgentLocation {
38
- const ALL: ChatAgentLocation[];
39
- function fromRaw(value: string): ChatAgentLocation;
40
- }
41
- /**
42
- * Represents a mode that a chat agent can operate in.
43
- */
44
- export interface ChatMode {
45
- readonly id: string;
46
- readonly name: string;
47
- }
48
- export declare const ChatAgent: unique symbol;
49
- /**
50
- * A chat agent is a specialized agent with a common interface for its invocation.
51
- */
52
- export interface ChatAgent extends Agent {
53
- locations: ChatAgentLocation[];
54
- iconClass?: string;
55
- modes?: ChatMode[];
56
- invoke(request: MutableChatRequestModel, chatAgentService?: ChatAgentService): Promise<void>;
57
- }
58
- export declare abstract class AbstractChatAgent implements ChatAgent {
59
- protected languageModelRegistry: LanguageModelRegistry;
60
- protected logger: ILogger;
61
- protected chatToolRequestService: ChatToolRequestService;
62
- protected languageModelService: LanguageModelService;
63
- protected promptService: PromptService;
64
- protected contentMatcherProviders: ContributionProvider<ResponseContentMatcherProvider>;
65
- protected defaultContentFactory: DefaultResponseContentFactory;
66
- readonly abstract id: string;
67
- readonly abstract name: string;
68
- readonly abstract languageModelRequirements: LanguageModelRequirement[];
69
- iconClass: string;
70
- locations: ChatAgentLocation[];
71
- tags: string[];
72
- description: string;
73
- variables: string[];
74
- prompts: PromptVariantSet[];
75
- agentSpecificVariables: AgentSpecificVariables[];
76
- functions: string[];
77
- protected readonly abstract defaultLanguageModelPurpose: string;
78
- protected systemPromptId: string | undefined;
79
- protected additionalToolRequests: ToolRequest[];
80
- protected contentMatchers: ResponseContentMatcher[];
81
- init(): void;
82
- protected initializeContentMatchers(): void;
83
- invoke(request: MutableChatRequestModel): Promise<void>;
84
- protected parseContents(text: string, request: MutableChatRequestModel): ChatResponseContent[];
85
- protected handleError(request: MutableChatRequestModel, error: Error): void;
86
- protected getLanguageModelSelector(languageModelPurpose: string): LanguageModelRequirement;
87
- protected getLanguageModel(languageModelPurpose: string): Promise<LanguageModel>;
88
- protected selectLanguageModel(selector: LanguageModelRequirement): Promise<LanguageModel>;
89
- protected getSystemMessageDescription(context: AIVariableContext): Promise<SystemMessageDescription | undefined>;
90
- protected getMessages(model: ChatModel, includeResponseInProgress?: boolean): Promise<LanguageModelMessage[]>;
91
- /**
92
- * Deduplicate tools by name (falling back to id) while preserving the first occurrence and order.
93
- */
94
- protected deduplicateTools(toolRequests: ChatToolRequest[]): ChatToolRequest[];
95
- protected sendLlmRequest(request: MutableChatRequestModel, messages: LanguageModelMessage[], toolRequests: ChatToolRequest[], languageModel: LanguageModel): Promise<LanguageModelResponse>;
96
- /**
97
- * @returns the settings, such as `temperature`, to be used in all language model requests. Returns `undefined` by default.
98
- */
99
- protected getLlmSettings(): {
100
- [key: string]: unknown;
101
- } | undefined;
102
- /**
103
- * Invoked after the response by the LLM completed successfully.
104
- *
105
- * The default implementation sets the state of the response to `complete`.
106
- * Subclasses may override this method to perform additional actions or keep the response open for processing further requests.
107
- */
108
- protected onResponseComplete(request: MutableChatRequestModel): Promise<void>;
109
- protected abstract addContentsToResponse(languageModelResponse: LanguageModelResponse, request: MutableChatRequestModel): Promise<void>;
110
- }
111
- export declare abstract class AbstractTextToModelParsingChatAgent<T> extends AbstractChatAgent {
112
- protected addContentsToResponse(languageModelResponse: LanguageModelResponse, request: MutableChatRequestModel): Promise<void>;
113
- protected abstract parseTextResponse(text: string): Promise<T>;
114
- protected abstract createResponseContent(parsedModel: T, request: MutableChatRequestModel): ChatResponseContent;
115
- }
116
- /**
117
- * Factory for creating ToolCallChatResponseContent instances.
118
- */
119
- export declare class ToolCallChatResponseContentFactory {
120
- create(toolCall: ToolCall): ChatResponseContent;
121
- }
122
- export declare abstract class AbstractStreamParsingChatAgent extends AbstractChatAgent {
123
- protected toolCallResponseContentFactory: ToolCallChatResponseContentFactory;
124
- protected addContentsToResponse(languageModelResponse: LanguageModelResponse, request: MutableChatRequestModel): Promise<void>;
125
- protected addStreamResponse(languageModelResponse: LanguageModelStreamResponse, request: MutableChatRequestModel): Promise<void>;
126
- protected parse(token: LanguageModelStreamResponsePart, request: MutableChatRequestModel): ChatResponseContent | ChatResponseContent[];
127
- /**
128
- * Creates a ToolCallChatResponseContent instance from the provided tool call data.
129
- *
130
- * This method is called when parsing stream response tokens that contain tool call data.
131
- * Subclasses can override this method to customize the creation of tool call response contents.
132
- *
133
- * @param toolCall The ToolCall.
134
- * @returns A ChatResponseContent representing the tool call.
135
- */
136
- protected createToolCallResponseContent(toolCall: ToolCall): ChatResponseContent;
137
- }
138
- //# sourceMappingURL=chat-agents.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"chat-agents.d.ts","sourceRoot":"","sources":["../../src/common/chat-agents.ts"],"names":[],"mappings":"AAqBA,OAAO,EACH,sBAAsB,EACtB,iBAAiB,EACjB,2BAA2B,EAO3B,aAAa,EACb,oBAAoB,EACpB,wBAAwB,EACxB,qBAAqB,EACrB,oBAAoB,EACpB,2BAA2B,EAC3B,aAAa,EACb,sBAAsB,EACtB,gBAAgB,EAEhB,QAAQ,EACR,WAAW,EACd,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACH,KAAK,EAGL,qBAAqB,EACrB,+BAA+B,EAClC,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,oBAAoB,EAAE,OAAO,EAAgB,MAAM,aAAa,CAAC;AAE1E,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,EACH,SAAS,EACT,gBAAgB,EAChB,mBAAmB,EAGnB,uBAAuB,EAK1B,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,eAAe,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AAEtF,OAAO,EAAE,6BAA6B,EAAE,sBAAsB,EAAE,8BAA8B,EAAE,MAAM,4BAA4B,CAAC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AQ,iBAAiB;cAElE,qBAAqB,CAAC,qBAAqB,EAAE,qBAAqB,EAAE,OAAO,EAAE,uBAAuB,GAAG,OAAO,CAAC,IAAI,CAAC;IAOpI,SAAS,CAAC,QAAQ,CAAC,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC;IAE9D,SAAS,CAAC,QAAQ,CAAC,qBAAqB,CAAC,WAAW,EAAE,CAAC,EAAE,OAAO,EAAE,uBAAuB,GAAG,mBAAmB;CAClH;AAED;;GAEG;AACH,qBACa,kCAAkC;IAC3C,MAAM,CAAC,QAAQ,EAAE,QAAQ,GAAG,mBAAmB;CASlD;AAED,8BACsB,8BAA+B,SAAQ,iBAAiB;IAE1E,SAAS,CAAC,8BAA8B,EAAE,kCAAkC,CAAC;cAEpD,qBAAqB,CAAC,qBAAqB,EAAE,qBAAqB,EAAE,OAAO,EAAE,uBAAuB,GAAG,OAAO,CAAC,IAAI,CAAC;cAoB7H,iBAAiB,CAAC,qBAAqB,EAAE,2BAA2B,EAAE,OAAO,EAAE,uBAAuB,GAAG,OAAO,CAAC,IAAI,CAAC;IAqCtI,SAAS,CAAC,KAAK,CAAC,KAAK,EAAE,+BAA+B,EAAE,OAAO,EAAE,uBAAuB,GAAG,mBAAmB,GAAG,mBAAmB,EAAE;IA0BtI;;;;;;;;OAQG;IACH,SAAS,CAAC,6BAA6B,CAAC,QAAQ,EAAE,QAAQ,GAAG,mBAAmB;CAGnF"}
@@ -1,428 +0,0 @@
1
- "use strict";
2
- // *****************************************************************************
3
- // Copyright (C) 2024 EclipseSource GmbH.
4
- //
5
- // This program and the accompanying materials are made available under the
6
- // terms of the Eclipse Public License v. 2.0 which is available at
7
- // http://www.eclipse.org/legal/epl-2.0.
8
- //
9
- // This Source Code may also be made available under the following Secondary
10
- // Licenses when the conditions for such availability set forth in the Eclipse
11
- // Public License v. 2.0 are satisfied: GNU General Public License, version 2
12
- // with the GNU Classpath Exception which is available at
13
- // https://www.gnu.org/software/classpath/license.html.
14
- //
15
- // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
16
- // *****************************************************************************
17
- /*---------------------------------------------------------------------------------------------
18
- * Copyright (c) Microsoft Corporation. All rights reserved.
19
- * Licensed under the MIT License. See License.txt in the project root for license information.
20
- *--------------------------------------------------------------------------------------------*/
21
- // Partially copied from https://github.com/microsoft/vscode/blob/a2cab7255c0df424027be05d58e1b7b941f4ea60/src/vs/workbench/contrib/chat/common/chatAgents.ts
22
- Object.defineProperty(exports, "__esModule", { value: true });
23
- exports.AbstractStreamParsingChatAgent = exports.ToolCallChatResponseContentFactory = exports.AbstractTextToModelParsingChatAgent = exports.AbstractChatAgent = exports.ChatAgent = exports.ChatAgentLocation = exports.ChatSessionContext = exports.SystemMessageDescription = void 0;
24
- const tslib_1 = require("tslib");
25
- const ai_core_1 = require("@theia/ai-core");
26
- const common_1 = require("@theia/ai-core/lib/common");
27
- const core_1 = require("@theia/core");
28
- const inversify_1 = require("@theia/core/shared/inversify");
29
- const chat_model_1 = require("./chat-model");
30
- const chat_tool_request_service_1 = require("./chat-tool-request-service");
31
- const parse_contents_1 = require("./parse-contents");
32
- const response_content_matcher_1 = require("./response-content-matcher");
33
- const image_context_variable_1 = require("./image-context-variable");
34
- var SystemMessageDescription;
35
- (function (SystemMessageDescription) {
36
- function fromResolvedPromptFragment(resolvedPrompt) {
37
- return {
38
- text: resolvedPrompt.text,
39
- functionDescriptions: resolvedPrompt.functionDescriptions
40
- };
41
- }
42
- SystemMessageDescription.fromResolvedPromptFragment = fromResolvedPromptFragment;
43
- })(SystemMessageDescription || (exports.SystemMessageDescription = SystemMessageDescription = {}));
44
- var ChatSessionContext;
45
- (function (ChatSessionContext) {
46
- function is(candidate) {
47
- return typeof candidate === 'object' && !!candidate && 'model' in candidate;
48
- }
49
- ChatSessionContext.is = is;
50
- function getVariables(context) {
51
- var _a, _b;
52
- return (_b = (_a = context.request) === null || _a === void 0 ? void 0 : _a.context.variables.map(ai_core_1.AIVariableResolutionRequest.fromResolved)) !== null && _b !== void 0 ? _b : context.model.context.getVariables();
53
- }
54
- ChatSessionContext.getVariables = getVariables;
55
- })(ChatSessionContext || (exports.ChatSessionContext = ChatSessionContext = {}));
56
- /**
57
- * The location from where an chat agent may be invoked.
58
- * Based on the location, a different context may be available.
59
- */
60
- var ChatAgentLocation;
61
- (function (ChatAgentLocation) {
62
- ChatAgentLocation["Panel"] = "panel";
63
- ChatAgentLocation["Terminal"] = "terminal";
64
- ChatAgentLocation["Notebook"] = "notebook";
65
- ChatAgentLocation["Editor"] = "editor";
66
- })(ChatAgentLocation || (exports.ChatAgentLocation = ChatAgentLocation = {}));
67
- (function (ChatAgentLocation) {
68
- ChatAgentLocation.ALL = [ChatAgentLocation.Panel, ChatAgentLocation.Terminal, ChatAgentLocation.Notebook, ChatAgentLocation.Editor];
69
- function fromRaw(value) {
70
- switch (value) {
71
- case 'panel': return ChatAgentLocation.Panel;
72
- case 'terminal': return ChatAgentLocation.Terminal;
73
- case 'notebook': return ChatAgentLocation.Notebook;
74
- case 'editor': return ChatAgentLocation.Editor;
75
- }
76
- return ChatAgentLocation.Panel;
77
- }
78
- ChatAgentLocation.fromRaw = fromRaw;
79
- })(ChatAgentLocation || (exports.ChatAgentLocation = ChatAgentLocation = {}));
80
- exports.ChatAgent = Symbol('ChatAgent');
81
- let AbstractChatAgent = class AbstractChatAgent {
82
- constructor() {
83
- this.iconClass = 'codicon codicon-copilot';
84
- this.locations = ChatAgentLocation.ALL;
85
- this.tags = [core_1.nls.localizeByDefault('Chat')];
86
- this.description = '';
87
- this.variables = [];
88
- this.prompts = [];
89
- this.agentSpecificVariables = [];
90
- this.functions = [];
91
- this.systemPromptId = undefined;
92
- this.additionalToolRequests = [];
93
- this.contentMatchers = [];
94
- }
95
- init() {
96
- this.initializeContentMatchers();
97
- }
98
- initializeContentMatchers() {
99
- const contributedContentMatchers = this.contentMatcherProviders.getContributions().flatMap(provider => provider.matchers);
100
- this.contentMatchers.push(...contributedContentMatchers);
101
- }
102
- async invoke(request) {
103
- var _a;
104
- try {
105
- const languageModel = await this.getLanguageModel(this.defaultLanguageModelPurpose);
106
- if (!languageModel) {
107
- throw new Error(core_1.nls.localize('theia/ai/chat/couldNotFindMatchingLM', 'Couldn\'t find a matching language model. Please check your setup!'));
108
- }
109
- const systemMessageDescription = await this.getSystemMessageDescription({ model: request.session, request });
110
- const messages = await this.getMessages(request.session);
111
- if (systemMessageDescription) {
112
- const systemMsg = {
113
- actor: 'system',
114
- type: 'text',
115
- text: systemMessageDescription.text
116
- };
117
- // insert system message at the beginning of the request messages
118
- messages.unshift(systemMsg);
119
- }
120
- const systemMessageToolRequests = (_a = systemMessageDescription === null || systemMessageDescription === void 0 ? void 0 : systemMessageDescription.functionDescriptions) === null || _a === void 0 ? void 0 : _a.values();
121
- const tools = [
122
- ...this.chatToolRequestService.getChatToolRequests(request),
123
- ...this.chatToolRequestService.toChatToolRequests(systemMessageToolRequests ? Array.from(systemMessageToolRequests) : [], request),
124
- ...this.chatToolRequestService.toChatToolRequests(this.additionalToolRequests, request)
125
- ];
126
- const languageModelResponse = await this.sendLlmRequest(request, messages, tools, languageModel);
127
- await this.addContentsToResponse(languageModelResponse, request);
128
- await this.onResponseComplete(request);
129
- }
130
- catch (e) {
131
- this.handleError(request, e);
132
- }
133
- }
134
- parseContents(text, request) {
135
- var _a;
136
- return (0, parse_contents_1.parseContents)(text, request, this.contentMatchers, (_a = this.defaultContentFactory) === null || _a === void 0 ? void 0 : _a.create.bind(this.defaultContentFactory));
137
- }
138
- ;
139
- handleError(request, error) {
140
- console.error('Error handling chat interaction:', error);
141
- request.response.response.addContent(new chat_model_1.ErrorChatResponseContentImpl(error));
142
- request.response.error(error);
143
- }
144
- getLanguageModelSelector(languageModelPurpose) {
145
- return this.languageModelRequirements.find(req => req.purpose === languageModelPurpose);
146
- }
147
- async getLanguageModel(languageModelPurpose) {
148
- return this.selectLanguageModel(this.getLanguageModelSelector(languageModelPurpose));
149
- }
150
- async selectLanguageModel(selector) {
151
- const languageModel = await this.languageModelRegistry.selectLanguageModel({ agent: this.id, ...selector });
152
- if (!languageModel) {
153
- throw new Error(core_1.nls.localize('theia/ai/chat/couldNotFindReadyLMforAgent', 'Couldn\'t find a ready language model for agent {0}. Please check your setup!', this.id));
154
- }
155
- return languageModel;
156
- }
157
- async getSystemMessageDescription(context) {
158
- if (this.systemPromptId === undefined) {
159
- return undefined;
160
- }
161
- const resolvedPrompt = await this.promptService.getResolvedPromptFragment(this.systemPromptId, undefined, context);
162
- return resolvedPrompt ? SystemMessageDescription.fromResolvedPromptFragment(resolvedPrompt) : undefined;
163
- }
164
- async getMessages(model, includeResponseInProgress = false) {
165
- const requestMessages = model.getRequests().flatMap(request => {
166
- const messages = [];
167
- const text = request.message.parts.map(part => part.promptText).join('');
168
- if (text.length > 0) {
169
- messages.push({
170
- actor: 'user',
171
- type: 'text',
172
- text: text,
173
- });
174
- }
175
- const imageMessages = request.context.variables
176
- .filter(variable => image_context_variable_1.ImageContextVariable.isResolvedImageContext(variable))
177
- .map(variable => image_context_variable_1.ImageContextVariable.parseResolved(variable))
178
- .filter(content => content !== undefined)
179
- .map(content => ({
180
- actor: 'user',
181
- type: 'image',
182
- image: {
183
- base64data: content.data,
184
- mimeType: content.mimeType
185
- }
186
- }));
187
- messages.push(...imageMessages);
188
- if (request.response.isComplete || includeResponseInProgress) {
189
- const responseMessages = request.response.response.content
190
- .filter(c => {
191
- // we do not send errors or informational content
192
- if (chat_model_1.ErrorChatResponseContent.is(c) || chat_model_1.InformationalChatResponseContent.is(c)) {
193
- return false;
194
- }
195
- // content even has an own converter, definitely include it
196
- if (chat_model_1.ChatResponseContent.hasToLanguageModelMessage(c)) {
197
- return true;
198
- }
199
- // make sure content did not indicate to be excluded by returning undefined in asString
200
- if (chat_model_1.ChatResponseContent.hasAsString(c) && c.asString() === undefined) {
201
- return false;
202
- }
203
- // include the rest
204
- return true;
205
- })
206
- .flatMap(c => {
207
- var _a, _b;
208
- if (chat_model_1.ChatResponseContent.hasToLanguageModelMessage(c)) {
209
- return c.toLanguageModelMessage();
210
- }
211
- return {
212
- actor: 'ai',
213
- type: 'text',
214
- text: ((_a = c.asString) === null || _a === void 0 ? void 0 : _a.call(c)) || ((_b = c.asDisplayString) === null || _b === void 0 ? void 0 : _b.call(c)) || '',
215
- };
216
- });
217
- messages.push(...responseMessages);
218
- }
219
- return messages;
220
- });
221
- return requestMessages;
222
- }
223
- /**
224
- * Deduplicate tools by name (falling back to id) while preserving the first occurrence and order.
225
- */
226
- deduplicateTools(toolRequests) {
227
- var _a;
228
- const seen = new Set();
229
- const deduped = [];
230
- for (const tool of toolRequests) {
231
- const key = (_a = tool.name) !== null && _a !== void 0 ? _a : tool.id;
232
- if (!seen.has(key)) {
233
- seen.add(key);
234
- deduped.push(tool);
235
- }
236
- }
237
- return deduped;
238
- }
239
- async sendLlmRequest(request, messages, toolRequests, languageModel) {
240
- const agentSettings = this.getLlmSettings();
241
- const settings = { ...agentSettings, ...request.session.settings };
242
- const dedupedTools = this.deduplicateTools(toolRequests);
243
- const tools = dedupedTools.length > 0 ? dedupedTools : undefined;
244
- return this.languageModelService.sendRequest(languageModel, {
245
- messages,
246
- tools,
247
- settings,
248
- agentId: this.id,
249
- sessionId: request.session.id,
250
- requestId: request.id,
251
- cancellationToken: request.response.cancellationToken
252
- });
253
- }
254
- /**
255
- * @returns the settings, such as `temperature`, to be used in all language model requests. Returns `undefined` by default.
256
- */
257
- getLlmSettings() {
258
- return undefined;
259
- }
260
- /**
261
- * Invoked after the response by the LLM completed successfully.
262
- *
263
- * The default implementation sets the state of the response to `complete`.
264
- * Subclasses may override this method to perform additional actions or keep the response open for processing further requests.
265
- */
266
- async onResponseComplete(request) {
267
- return request.response.complete();
268
- }
269
- };
270
- exports.AbstractChatAgent = AbstractChatAgent;
271
- tslib_1.__decorate([
272
- (0, inversify_1.inject)(common_1.LanguageModelRegistry),
273
- tslib_1.__metadata("design:type", Object)
274
- ], AbstractChatAgent.prototype, "languageModelRegistry", void 0);
275
- tslib_1.__decorate([
276
- (0, inversify_1.inject)(core_1.ILogger),
277
- tslib_1.__metadata("design:type", Object)
278
- ], AbstractChatAgent.prototype, "logger", void 0);
279
- tslib_1.__decorate([
280
- (0, inversify_1.inject)(chat_tool_request_service_1.ChatToolRequestService),
281
- tslib_1.__metadata("design:type", chat_tool_request_service_1.ChatToolRequestService)
282
- ], AbstractChatAgent.prototype, "chatToolRequestService", void 0);
283
- tslib_1.__decorate([
284
- (0, inversify_1.inject)(ai_core_1.LanguageModelService),
285
- tslib_1.__metadata("design:type", Object)
286
- ], AbstractChatAgent.prototype, "languageModelService", void 0);
287
- tslib_1.__decorate([
288
- (0, inversify_1.inject)(ai_core_1.PromptService),
289
- tslib_1.__metadata("design:type", Object)
290
- ], AbstractChatAgent.prototype, "promptService", void 0);
291
- tslib_1.__decorate([
292
- (0, inversify_1.inject)(core_1.ContributionProvider),
293
- (0, inversify_1.named)(response_content_matcher_1.ResponseContentMatcherProvider),
294
- tslib_1.__metadata("design:type", Object)
295
- ], AbstractChatAgent.prototype, "contentMatcherProviders", void 0);
296
- tslib_1.__decorate([
297
- (0, inversify_1.inject)(response_content_matcher_1.DefaultResponseContentFactory),
298
- tslib_1.__metadata("design:type", response_content_matcher_1.DefaultResponseContentFactory)
299
- ], AbstractChatAgent.prototype, "defaultContentFactory", void 0);
300
- tslib_1.__decorate([
301
- (0, inversify_1.postConstruct)(),
302
- tslib_1.__metadata("design:type", Function),
303
- tslib_1.__metadata("design:paramtypes", []),
304
- tslib_1.__metadata("design:returntype", void 0)
305
- ], AbstractChatAgent.prototype, "init", null);
306
- exports.AbstractChatAgent = AbstractChatAgent = tslib_1.__decorate([
307
- (0, inversify_1.injectable)()
308
- ], AbstractChatAgent);
309
- let AbstractTextToModelParsingChatAgent = class AbstractTextToModelParsingChatAgent extends AbstractChatAgent {
310
- async addContentsToResponse(languageModelResponse, request) {
311
- const responseAsText = await (0, ai_core_1.getTextOfResponse)(languageModelResponse);
312
- const parsedCommand = await this.parseTextResponse(responseAsText);
313
- const content = this.createResponseContent(parsedCommand, request);
314
- request.response.response.addContent(content);
315
- }
316
- };
317
- exports.AbstractTextToModelParsingChatAgent = AbstractTextToModelParsingChatAgent;
318
- exports.AbstractTextToModelParsingChatAgent = AbstractTextToModelParsingChatAgent = tslib_1.__decorate([
319
- (0, inversify_1.injectable)()
320
- ], AbstractTextToModelParsingChatAgent);
321
- /**
322
- * Factory for creating ToolCallChatResponseContent instances.
323
- */
324
- let ToolCallChatResponseContentFactory = class ToolCallChatResponseContentFactory {
325
- create(toolCall) {
326
- var _a, _b;
327
- return new chat_model_1.ToolCallChatResponseContentImpl(toolCall.id, (_a = toolCall.function) === null || _a === void 0 ? void 0 : _a.name, (_b = toolCall.function) === null || _b === void 0 ? void 0 : _b.arguments, toolCall.finished, toolCall.result);
328
- }
329
- };
330
- exports.ToolCallChatResponseContentFactory = ToolCallChatResponseContentFactory;
331
- exports.ToolCallChatResponseContentFactory = ToolCallChatResponseContentFactory = tslib_1.__decorate([
332
- (0, inversify_1.injectable)()
333
- ], ToolCallChatResponseContentFactory);
334
- let AbstractStreamParsingChatAgent = class AbstractStreamParsingChatAgent extends AbstractChatAgent {
335
- async addContentsToResponse(languageModelResponse, request) {
336
- if ((0, common_1.isLanguageModelTextResponse)(languageModelResponse)) {
337
- const contents = this.parseContents(languageModelResponse.text, request);
338
- request.response.response.addContents(contents);
339
- return;
340
- }
341
- if ((0, common_1.isLanguageModelStreamResponse)(languageModelResponse)) {
342
- await this.addStreamResponse(languageModelResponse, request);
343
- return;
344
- }
345
- this.logger.error('Received unknown response in agent. Return response as text');
346
- request.response.response.addContent(new chat_model_1.MarkdownChatResponseContentImpl(JSON.stringify(languageModelResponse)));
347
- }
348
- async addStreamResponse(languageModelResponse, request) {
349
- let completeTextBuffer = '';
350
- let startIndex = request.response.response.content.length;
351
- for await (const token of languageModelResponse.stream) {
352
- // Skip unknown tokens. For example OpenAI sends empty tokens around tool calls
353
- if (!(0, ai_core_1.isLanguageModelStreamResponsePart)(token)) {
354
- console.debug(`Unknown token: '${JSON.stringify(token)}'. Skipping`);
355
- continue;
356
- }
357
- const newContent = this.parse(token, request);
358
- if (!(0, ai_core_1.isTextResponsePart)(token)) {
359
- // For non-text tokens (like tool calls), add them directly
360
- if ((0, core_1.isArray)(newContent)) {
361
- request.response.response.addContents(newContent);
362
- }
363
- else {
364
- request.response.response.addContent(newContent);
365
- }
366
- // And reset the marker index and the text buffer as we skip matching across non-text tokens
367
- startIndex = request.response.response.content.length;
368
- completeTextBuffer = '';
369
- }
370
- else {
371
- // parse the entire text so far (since beginning of the stream or last non-text token)
372
- // and replace the entire content with the currently parsed content parts
373
- completeTextBuffer += token.content;
374
- const parsedContents = this.parseContents(completeTextBuffer, request);
375
- const contentBeforeMarker = startIndex > 0
376
- ? request.response.response.content.slice(0, startIndex)
377
- : [];
378
- request.response.response.clearContent();
379
- request.response.response.addContents(contentBeforeMarker);
380
- request.response.response.addContents(parsedContents);
381
- }
382
- }
383
- }
384
- parse(token, request) {
385
- if ((0, ai_core_1.isTextResponsePart)(token)) {
386
- const content = token.content;
387
- // eslint-disable-next-line no-null/no-null
388
- if (content !== undefined && content !== null) {
389
- return this.defaultContentFactory.create(content, request);
390
- }
391
- }
392
- if ((0, ai_core_1.isToolCallResponsePart)(token)) {
393
- const toolCalls = token.tool_calls;
394
- if (toolCalls !== undefined) {
395
- const toolCallContents = toolCalls.map(toolCall => this.createToolCallResponseContent(toolCall));
396
- return toolCallContents;
397
- }
398
- }
399
- if ((0, ai_core_1.isThinkingResponsePart)(token)) {
400
- return new chat_model_1.ThinkingChatResponseContentImpl(token.thought, token.signature);
401
- }
402
- if ((0, ai_core_1.isUsageResponsePart)(token)) {
403
- return [];
404
- }
405
- return this.defaultContentFactory.create('', request);
406
- }
407
- /**
408
- * Creates a ToolCallChatResponseContent instance from the provided tool call data.
409
- *
410
- * This method is called when parsing stream response tokens that contain tool call data.
411
- * Subclasses can override this method to customize the creation of tool call response contents.
412
- *
413
- * @param toolCall The ToolCall.
414
- * @returns A ChatResponseContent representing the tool call.
415
- */
416
- createToolCallResponseContent(toolCall) {
417
- return this.toolCallResponseContentFactory.create(toolCall);
418
- }
419
- };
420
- exports.AbstractStreamParsingChatAgent = AbstractStreamParsingChatAgent;
421
- tslib_1.__decorate([
422
- (0, inversify_1.inject)(ToolCallChatResponseContentFactory),
423
- tslib_1.__metadata("design:type", ToolCallChatResponseContentFactory)
424
- ], AbstractStreamParsingChatAgent.prototype, "toolCallResponseContentFactory", void 0);
425
- exports.AbstractStreamParsingChatAgent = AbstractStreamParsingChatAgent = tslib_1.__decorate([
426
- (0, inversify_1.injectable)()
427
- ], AbstractStreamParsingChatAgent);
428
- //# sourceMappingURL=chat-agents.js.map