@theia/ai-chat 1.67.0-next.3 → 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 (250) hide show
  1. package/README.md +1 -0
  2. package/package.json +9 -9
  3. package/{lib/common/context-variables.js → src/browser/context-file-validation-service.ts} +19 -7
  4. package/lib/browser/agent-delegation-tool.d.ts +0 -25
  5. package/lib/browser/agent-delegation-tool.d.ts.map +0 -1
  6. package/lib/browser/agent-delegation-tool.js +0 -196
  7. package/lib/browser/agent-delegation-tool.js.map +0 -1
  8. package/lib/browser/ai-chat-frontend-contribution.d.ts +0 -11
  9. package/lib/browser/ai-chat-frontend-contribution.d.ts.map +0 -1
  10. package/lib/browser/ai-chat-frontend-contribution.js +0 -56
  11. package/lib/browser/ai-chat-frontend-contribution.js.map +0 -1
  12. package/lib/browser/ai-chat-frontend-module.d.ts +0 -4
  13. package/lib/browser/ai-chat-frontend-module.d.ts.map +0 -1
  14. package/lib/browser/ai-chat-frontend-module.js +0 -143
  15. package/lib/browser/ai-chat-frontend-module.js.map +0 -1
  16. package/lib/browser/change-set-decorator-service.d.ts +0 -24
  17. package/lib/browser/change-set-decorator-service.d.ts.map +0 -1
  18. package/lib/browser/change-set-decorator-service.js +0 -66
  19. package/lib/browser/change-set-decorator-service.js.map +0 -1
  20. package/lib/browser/change-set-file-element-deserializer.d.ts +0 -7
  21. package/lib/browser/change-set-file-element-deserializer.d.ts.map +0 -1
  22. package/lib/browser/change-set-file-element-deserializer.js +0 -61
  23. package/lib/browser/change-set-file-element-deserializer.js.map +0 -1
  24. package/lib/browser/change-set-file-element.d.ts +0 -122
  25. package/lib/browser/change-set-file-element.d.ts.map +0 -1
  26. package/lib/browser/change-set-file-element.js +0 -435
  27. package/lib/browser/change-set-file-element.js.map +0 -1
  28. package/lib/browser/change-set-file-resource.d.ts +0 -4
  29. package/lib/browser/change-set-file-resource.d.ts.map +0 -1
  30. package/lib/browser/change-set-file-resource.js +0 -24
  31. package/lib/browser/change-set-file-resource.js.map +0 -1
  32. package/lib/browser/change-set-file-service.d.ts +0 -32
  33. package/lib/browser/change-set-file-service.d.ts.map +0 -1
  34. package/lib/browser/change-set-file-service.js +0 -161
  35. package/lib/browser/change-set-file-service.js.map +0 -1
  36. package/lib/browser/change-set-variable.d.ts +0 -11
  37. package/lib/browser/change-set-variable.d.ts.map +0 -1
  38. package/lib/browser/change-set-variable.js +0 -64
  39. package/lib/browser/change-set-variable.js.map +0 -1
  40. package/lib/browser/chat-session-store-impl.d.ts +0 -36
  41. package/lib/browser/chat-session-store-impl.d.ts.map +0 -1
  42. package/lib/browser/chat-session-store-impl.js +0 -287
  43. package/lib/browser/chat-session-store-impl.js.map +0 -1
  44. package/lib/browser/chat-tool-preference-bindings.d.ts +0 -34
  45. package/lib/browser/chat-tool-preference-bindings.d.ts.map +0 -1
  46. package/lib/browser/chat-tool-preference-bindings.js +0 -122
  47. package/lib/browser/chat-tool-preference-bindings.js.map +0 -1
  48. package/lib/browser/chat-tool-request-service.d.ts +0 -21
  49. package/lib/browser/chat-tool-request-service.d.ts.map +0 -1
  50. package/lib/browser/chat-tool-request-service.js +0 -90
  51. package/lib/browser/chat-tool-request-service.js.map +0 -1
  52. package/lib/browser/context-file-variable-label-provider.d.ts +0 -14
  53. package/lib/browser/context-file-variable-label-provider.d.ts.map +0 -1
  54. package/lib/browser/context-file-variable-label-provider.js +0 -63
  55. package/lib/browser/context-file-variable-label-provider.js.map +0 -1
  56. package/lib/browser/context-variable-label-provider.d.ts +0 -9
  57. package/lib/browser/context-variable-label-provider.d.ts.map +0 -1
  58. package/lib/browser/context-variable-label-provider.js +0 -55
  59. package/lib/browser/context-variable-label-provider.js.map +0 -1
  60. package/lib/browser/custom-agent-factory.d.ts +0 -4
  61. package/lib/browser/custom-agent-factory.d.ts.map +0 -1
  62. package/lib/browser/custom-agent-factory.js +0 -20
  63. package/lib/browser/custom-agent-factory.js.map +0 -1
  64. package/lib/browser/custom-agent-frontend-application-contribution.d.ts +0 -13
  65. package/lib/browser/custom-agent-frontend-application-contribution.d.ts.map +0 -1
  66. package/lib/browser/custom-agent-frontend-application-contribution.js +0 -83
  67. package/lib/browser/custom-agent-frontend-application-contribution.js.map +0 -1
  68. package/lib/browser/delegation-response-content.d.ts +0 -20
  69. package/lib/browser/delegation-response-content.d.ts.map +0 -1
  70. package/lib/browser/delegation-response-content.js +0 -47
  71. package/lib/browser/delegation-response-content.js.map +0 -1
  72. package/lib/browser/file-chat-variable-contribution.d.ts +0 -32
  73. package/lib/browser/file-chat-variable-contribution.d.ts.map +0 -1
  74. package/lib/browser/file-chat-variable-contribution.js +0 -241
  75. package/lib/browser/file-chat-variable-contribution.js.map +0 -1
  76. package/lib/browser/frontend-chat-service.d.ts +0 -15
  77. package/lib/browser/frontend-chat-service.d.ts.map +0 -1
  78. package/lib/browser/frontend-chat-service.js +0 -72
  79. package/lib/browser/frontend-chat-service.js.map +0 -1
  80. package/lib/browser/image-context-variable-contribution.d.ts +0 -27
  81. package/lib/browser/image-context-variable-contribution.d.ts.map +0 -1
  82. package/lib/browser/image-context-variable-contribution.js +0 -149
  83. package/lib/browser/image-context-variable-contribution.js.map +0 -1
  84. package/lib/browser/task-context-service.d.ts +0 -46
  85. package/lib/browser/task-context-service.d.ts.map +0 -1
  86. package/lib/browser/task-context-service.js +0 -256
  87. package/lib/browser/task-context-service.js.map +0 -1
  88. package/lib/browser/task-context-storage-service.d.ts +0 -19
  89. package/lib/browser/task-context-storage-service.d.ts.map +0 -1
  90. package/lib/browser/task-context-storage-service.js +0 -80
  91. package/lib/browser/task-context-storage-service.js.map +0 -1
  92. package/lib/browser/task-context-variable-contribution.d.ts +0 -20
  93. package/lib/browser/task-context-variable-contribution.d.ts.map +0 -1
  94. package/lib/browser/task-context-variable-contribution.js +0 -101
  95. package/lib/browser/task-context-variable-contribution.js.map +0 -1
  96. package/lib/browser/task-context-variable-label-provider.d.ts +0 -21
  97. package/lib/browser/task-context-variable-label-provider.d.ts.map +0 -1
  98. package/lib/browser/task-context-variable-label-provider.js +0 -83
  99. package/lib/browser/task-context-variable-label-provider.js.map +0 -1
  100. package/lib/browser/task-context-variable.d.ts +0 -3
  101. package/lib/browser/task-context-variable.d.ts.map +0 -1
  102. package/lib/browser/task-context-variable.js +0 -33
  103. package/lib/browser/task-context-variable.js.map +0 -1
  104. package/lib/common/ai-chat-preferences.d.ts +0 -5
  105. package/lib/common/ai-chat-preferences.d.ts.map +0 -1
  106. package/lib/common/ai-chat-preferences.js +0 -40
  107. package/lib/common/ai-chat-preferences.js.map +0 -1
  108. package/lib/common/change-set-element-deserializer.d.ts +0 -30
  109. package/lib/common/change-set-element-deserializer.d.ts.map +0 -1
  110. package/lib/common/change-set-element-deserializer.js +0 -81
  111. package/lib/common/change-set-element-deserializer.js.map +0 -1
  112. package/lib/common/change-set.d.ts +0 -85
  113. package/lib/common/change-set.d.ts.map +0 -1
  114. package/lib/common/change-set.js +0 -133
  115. package/lib/common/change-set.js.map +0 -1
  116. package/lib/common/chat-agent-service.d.ts +0 -46
  117. package/lib/common/chat-agent-service.d.ts.map +0 -1
  118. package/lib/common/chat-agent-service.js +0 -79
  119. package/lib/common/chat-agent-service.js.map +0 -1
  120. package/lib/common/chat-agents-variable-contribution.d.ts +0 -17
  121. package/lib/common/chat-agents-variable-contribution.d.ts.map +0 -1
  122. package/lib/common/chat-agents-variable-contribution.js +0 -67
  123. package/lib/common/chat-agents-variable-contribution.js.map +0 -1
  124. package/lib/common/chat-agents.d.ts +0 -138
  125. package/lib/common/chat-agents.d.ts.map +0 -1
  126. package/lib/common/chat-agents.js +0 -428
  127. package/lib/common/chat-agents.js.map +0 -1
  128. package/lib/common/chat-auto-save.spec.d.ts +0 -2
  129. package/lib/common/chat-auto-save.spec.d.ts.map +0 -1
  130. package/lib/common/chat-auto-save.spec.js +0 -304
  131. package/lib/common/chat-auto-save.spec.js.map +0 -1
  132. package/lib/common/chat-content-deserializer.d.ts +0 -161
  133. package/lib/common/chat-content-deserializer.d.ts.map +0 -1
  134. package/lib/common/chat-content-deserializer.js +0 -166
  135. package/lib/common/chat-content-deserializer.js.map +0 -1
  136. package/lib/common/chat-content-deserializer.spec.d.ts +0 -2
  137. package/lib/common/chat-content-deserializer.spec.d.ts.map +0 -1
  138. package/lib/common/chat-content-deserializer.spec.js +0 -307
  139. package/lib/common/chat-content-deserializer.spec.js.map +0 -1
  140. package/lib/common/chat-model-serialization.d.ts +0 -110
  141. package/lib/common/chat-model-serialization.d.ts.map +0 -1
  142. package/lib/common/chat-model-serialization.js +0 -20
  143. package/lib/common/chat-model-serialization.js.map +0 -1
  144. package/lib/common/chat-model-serialization.spec.d.ts +0 -2
  145. package/lib/common/chat-model-serialization.spec.d.ts.map +0 -1
  146. package/lib/common/chat-model-serialization.spec.js +0 -278
  147. package/lib/common/chat-model-serialization.spec.js.map +0 -1
  148. package/lib/common/chat-model-util.d.ts +0 -7
  149. package/lib/common/chat-model-util.d.ts.map +0 -1
  150. package/lib/common/chat-model-util.js +0 -50
  151. package/lib/common/chat-model-util.js.map +0 -1
  152. package/lib/common/chat-model.d.ts +0 -923
  153. package/lib/common/chat-model.d.ts.map +0 -1
  154. package/lib/common/chat-model.js +0 -1791
  155. package/lib/common/chat-model.js.map +0 -1
  156. package/lib/common/chat-request-parser.d.ts +0 -38
  157. package/lib/common/chat-request-parser.d.ts.map +0 -1
  158. package/lib/common/chat-request-parser.js +0 -230
  159. package/lib/common/chat-request-parser.js.map +0 -1
  160. package/lib/common/chat-request-parser.spec.d.ts +0 -2
  161. package/lib/common/chat-request-parser.spec.d.ts.map +0 -1
  162. package/lib/common/chat-request-parser.spec.js +0 -235
  163. package/lib/common/chat-request-parser.spec.js.map +0 -1
  164. package/lib/common/chat-service-deletion.spec.d.ts +0 -2
  165. package/lib/common/chat-service-deletion.spec.d.ts.map +0 -1
  166. package/lib/common/chat-service-deletion.spec.js +0 -221
  167. package/lib/common/chat-service-deletion.spec.js.map +0 -1
  168. package/lib/common/chat-service.d.ts +0 -153
  169. package/lib/common/chat-service.d.ts.map +0 -1
  170. package/lib/common/chat-service.js +0 -474
  171. package/lib/common/chat-service.js.map +0 -1
  172. package/lib/common/chat-session-naming-prompt-template.d.ts +0 -3
  173. package/lib/common/chat-session-naming-prompt-template.d.ts.map +0 -1
  174. package/lib/common/chat-session-naming-prompt-template.js +0 -31
  175. package/lib/common/chat-session-naming-prompt-template.js.map +0 -1
  176. package/lib/common/chat-session-naming-service.d.ts +0 -26
  177. package/lib/common/chat-session-naming-service.d.ts.map +0 -1
  178. package/lib/common/chat-session-naming-service.js +0 -119
  179. package/lib/common/chat-session-naming-service.js.map +0 -1
  180. package/lib/common/chat-session-store.d.ts +0 -43
  181. package/lib/common/chat-session-store.d.ts.map +0 -1
  182. package/lib/common/chat-session-store.js +0 -20
  183. package/lib/common/chat-session-store.js.map +0 -1
  184. package/lib/common/chat-session-summary-agent-prompt.d.ts +0 -8
  185. package/lib/common/chat-session-summary-agent-prompt.d.ts.map +0 -1
  186. package/lib/common/chat-session-summary-agent-prompt.js +0 -33
  187. package/lib/common/chat-session-summary-agent-prompt.js.map +0 -1
  188. package/lib/common/chat-session-summary-agent.d.ts +0 -16
  189. package/lib/common/chat-session-summary-agent.d.ts.map +0 -1
  190. package/lib/common/chat-session-summary-agent.js +0 -48
  191. package/lib/common/chat-session-summary-agent.js.map +0 -1
  192. package/lib/common/chat-string-utils.d.ts +0 -3
  193. package/lib/common/chat-string-utils.d.ts.map +0 -1
  194. package/lib/common/chat-string-utils.js +0 -27
  195. package/lib/common/chat-string-utils.js.map +0 -1
  196. package/lib/common/chat-tool-preferences.d.ts +0 -23
  197. package/lib/common/chat-tool-preferences.d.ts.map +0 -1
  198. package/lib/common/chat-tool-preferences.js +0 -68
  199. package/lib/common/chat-tool-preferences.js.map +0 -1
  200. package/lib/common/chat-tool-request-service.d.ts +0 -18
  201. package/lib/common/chat-tool-request-service.d.ts.map +0 -1
  202. package/lib/common/chat-tool-request-service.js +0 -52
  203. package/lib/common/chat-tool-request-service.js.map +0 -1
  204. package/lib/common/context-details-variable.d.ts +0 -9
  205. package/lib/common/context-details-variable.d.ts.map +0 -1
  206. package/lib/common/context-details-variable.js +0 -57
  207. package/lib/common/context-details-variable.js.map +0 -1
  208. package/lib/common/context-summary-variable.d.ts +0 -9
  209. package/lib/common/context-summary-variable.d.ts.map +0 -1
  210. package/lib/common/context-summary-variable.js +0 -57
  211. package/lib/common/context-summary-variable.js.map +0 -1
  212. package/lib/common/context-variables.d.ts +0 -4
  213. package/lib/common/context-variables.d.ts.map +0 -1
  214. package/lib/common/context-variables.js.map +0 -1
  215. package/lib/common/custom-chat-agent.d.ts +0 -10
  216. package/lib/common/custom-chat-agent.d.ts.map +0 -1
  217. package/lib/common/custom-chat-agent.js +0 -40
  218. package/lib/common/custom-chat-agent.js.map +0 -1
  219. package/lib/common/image-context-variable.d.ts +0 -29
  220. package/lib/common/image-context-variable.d.ts.map +0 -1
  221. package/lib/common/image-context-variable.js +0 -114
  222. package/lib/common/image-context-variable.js.map +0 -1
  223. package/lib/common/index.d.ts +0 -13
  224. package/lib/common/index.d.ts.map +0 -1
  225. package/lib/common/index.js +0 -31
  226. package/lib/common/index.js.map +0 -1
  227. package/lib/common/parse-contents-with-incomplete-parts.spec.d.ts +0 -2
  228. package/lib/common/parse-contents-with-incomplete-parts.spec.d.ts.map +0 -1
  229. package/lib/common/parse-contents-with-incomplete-parts.spec.js +0 -103
  230. package/lib/common/parse-contents-with-incomplete-parts.spec.js.map +0 -1
  231. package/lib/common/parse-contents.d.ts +0 -12
  232. package/lib/common/parse-contents.d.ts.map +0 -1
  233. package/lib/common/parse-contents.js +0 -107
  234. package/lib/common/parse-contents.js.map +0 -1
  235. package/lib/common/parse-contents.spec.d.ts +0 -10
  236. package/lib/common/parse-contents.spec.d.ts.map +0 -1
  237. package/lib/common/parse-contents.spec.js +0 -146
  238. package/lib/common/parse-contents.spec.js.map +0 -1
  239. package/lib/common/parsed-chat-request.d.ts +0 -66
  240. package/lib/common/parsed-chat-request.d.ts.map +0 -1
  241. package/lib/common/parsed-chat-request.js +0 -83
  242. package/lib/common/parsed-chat-request.js.map +0 -1
  243. package/lib/common/response-content-matcher.d.ts +0 -69
  244. package/lib/common/response-content-matcher.d.ts.map +0 -1
  245. package/lib/common/response-content-matcher.js +0 -97
  246. package/lib/common/response-content-matcher.js.map +0 -1
  247. package/lib/node/ai-chat-backend-module.d.ts +0 -4
  248. package/lib/node/ai-chat-backend-module.d.ts.map +0 -1
  249. package/lib/node/ai-chat-backend-module.js +0 -26
  250. package/lib/node/ai-chat-backend-module.js.map +0 -1
@@ -1,1791 +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/chatModel.ts
22
- Object.defineProperty(exports, "__esModule", { value: true });
23
- exports.UnknownChatResponseContentImpl = exports.ProgressChatResponseContentImpl = exports.ErrorChatResponseModel = exports.MutableChatResponseModel = exports.QuestionResponseContentImpl = exports.HorizontalLayoutChatResponseContentImpl = exports.CommandChatResponseContentImpl = exports.COMMAND_CHAT_RESPONSE_COMMAND = exports.ToolCallChatResponseContentImpl = exports.CodeChatResponseContentImpl = exports.InformationalChatResponseContentImpl = exports.MarkdownChatResponseContentImpl = exports.ThinkingChatResponseContentImpl = exports.TextChatResponseContentImpl = exports.ErrorChatResponseContentImpl = exports.MutableChatRequestModel = exports.ChatContextManagerImpl = exports.ChatRequestHierarchyBranchImpl = exports.ChatRequestHierarchyImpl = exports.ChatTreeChangeSet = exports.MutableChatModel = exports.QuestionResponseContent = exports.ProgressChatResponseContent = exports.ThinkingChatResponseContent = exports.ErrorChatResponseContent = exports.ToolCallChatResponseContent = exports.HorizontalLayoutChatResponseContent = exports.CodeChatResponseContent = exports.CommandChatResponseContent = exports.InformationalChatResponseContent = exports.MarkdownChatResponseContent = exports.TextChatResponseContent = exports.Location = exports.ChatResponseContent = exports.EditableChatRequestModel = exports.ChatRequestModel = exports.ChatSuggestionCallback = exports.ChatChangeEvent = exports.ChangeSetImpl = void 0;
24
- const ai_core_1 = require("@theia/ai-core");
25
- const core_1 = require("@theia/core");
26
- const markdown_rendering_1 = require("@theia/core/lib/common/markdown-rendering");
27
- const vscode_languageserver_protocol_1 = require("@theia/core/shared/vscode-languageserver-protocol");
28
- const change_set_1 = require("./change-set");
29
- Object.defineProperty(exports, "ChangeSetImpl", { enumerable: true, get: function () { return change_set_1.ChangeSetImpl; } });
30
- const chat_agents_1 = require("./chat-agents");
31
- const debounce = require("@theia/core/shared/lodash.debounce");
32
- var ChatChangeEvent;
33
- (function (ChatChangeEvent) {
34
- function isChangeSetEvent(event) {
35
- return event.kind === 'updateChangeSet';
36
- }
37
- ChatChangeEvent.isChangeSetEvent = isChangeSetEvent;
38
- })(ChatChangeEvent || (exports.ChatChangeEvent = ChatChangeEvent = {}));
39
- var ChatSuggestionCallback;
40
- (function (ChatSuggestionCallback) {
41
- function is(candidate) {
42
- return typeof candidate === 'object' && 'callback' in candidate;
43
- }
44
- ChatSuggestionCallback.is = is;
45
- function containsCallbackLink(candidate) {
46
- if (!is(candidate)) {
47
- return false;
48
- }
49
- const text = typeof candidate.content === 'string' ? candidate.content : candidate.content.value;
50
- return text.includes('](_callback)');
51
- }
52
- ChatSuggestionCallback.containsCallbackLink = containsCallbackLink;
53
- })(ChatSuggestionCallback || (exports.ChatSuggestionCallback = ChatSuggestionCallback = {}));
54
- var ChatRequestModel;
55
- (function (ChatRequestModel) {
56
- function is(request) {
57
- return !!(request &&
58
- typeof request === 'object' &&
59
- 'id' in request &&
60
- typeof request.id === 'string' &&
61
- 'session' in request &&
62
- 'request' in request &&
63
- 'response' in request &&
64
- 'message' in request);
65
- }
66
- ChatRequestModel.is = is;
67
- function isInProgress(request) {
68
- if (!request) {
69
- return false;
70
- }
71
- const response = request.response;
72
- return !(response.isComplete ||
73
- response.isCanceled ||
74
- response.isError);
75
- }
76
- ChatRequestModel.isInProgress = isInProgress;
77
- })(ChatRequestModel || (exports.ChatRequestModel = ChatRequestModel = {}));
78
- var EditableChatRequestModel;
79
- (function (EditableChatRequestModel) {
80
- function is(request) {
81
- return !!(ChatRequestModel.is(request) &&
82
- 'enableEdit' in request &&
83
- 'cancelEdit' in request &&
84
- 'submitEdit' in request);
85
- }
86
- EditableChatRequestModel.is = is;
87
- function isEditing(request) {
88
- return is(request) && request.isEditing;
89
- }
90
- EditableChatRequestModel.isEditing = isEditing;
91
- })(EditableChatRequestModel || (exports.EditableChatRequestModel = EditableChatRequestModel = {}));
92
- var ChatResponseContent;
93
- (function (ChatResponseContent) {
94
- function is(obj) {
95
- return !!(obj &&
96
- typeof obj === 'object' &&
97
- 'kind' in obj &&
98
- typeof obj.kind === 'string');
99
- }
100
- ChatResponseContent.is = is;
101
- function hasAsString(obj) {
102
- return typeof obj.asString === 'function';
103
- }
104
- ChatResponseContent.hasAsString = hasAsString;
105
- function hasDisplayString(obj) {
106
- return typeof obj.asDisplayString === 'function';
107
- }
108
- ChatResponseContent.hasDisplayString = hasDisplayString;
109
- function hasMerge(obj) {
110
- return typeof obj.merge === 'function';
111
- }
112
- ChatResponseContent.hasMerge = hasMerge;
113
- function hasToLanguageModelMessage(obj) {
114
- return typeof obj.toLanguageModelMessage === 'function';
115
- }
116
- ChatResponseContent.hasToLanguageModelMessage = hasToLanguageModelMessage;
117
- })(ChatResponseContent || (exports.ChatResponseContent = ChatResponseContent = {}));
118
- var Location;
119
- (function (Location) {
120
- function is(obj) {
121
- return !!obj && typeof obj === 'object' &&
122
- 'uri' in obj && obj.uri instanceof core_1.URI &&
123
- 'position' in obj && vscode_languageserver_protocol_1.Position.is(obj.position);
124
- }
125
- Location.is = is;
126
- })(Location || (exports.Location = Location = {}));
127
- var TextChatResponseContent;
128
- (function (TextChatResponseContent) {
129
- function is(obj) {
130
- return (ChatResponseContent.is(obj) &&
131
- obj.kind === 'text' &&
132
- 'content' in obj &&
133
- typeof obj.content === 'string');
134
- }
135
- TextChatResponseContent.is = is;
136
- })(TextChatResponseContent || (exports.TextChatResponseContent = TextChatResponseContent = {}));
137
- var MarkdownChatResponseContent;
138
- (function (MarkdownChatResponseContent) {
139
- function is(obj) {
140
- return (ChatResponseContent.is(obj) &&
141
- obj.kind === 'markdownContent' &&
142
- 'content' in obj &&
143
- markdown_rendering_1.MarkdownString.is(obj.content));
144
- }
145
- MarkdownChatResponseContent.is = is;
146
- })(MarkdownChatResponseContent || (exports.MarkdownChatResponseContent = MarkdownChatResponseContent = {}));
147
- var InformationalChatResponseContent;
148
- (function (InformationalChatResponseContent) {
149
- function is(obj) {
150
- return (ChatResponseContent.is(obj) &&
151
- obj.kind === 'informational' &&
152
- 'content' in obj &&
153
- markdown_rendering_1.MarkdownString.is(obj.content));
154
- }
155
- InformationalChatResponseContent.is = is;
156
- })(InformationalChatResponseContent || (exports.InformationalChatResponseContent = InformationalChatResponseContent = {}));
157
- var CommandChatResponseContent;
158
- (function (CommandChatResponseContent) {
159
- function is(obj) {
160
- return (ChatResponseContent.is(obj) &&
161
- obj.kind === 'command' &&
162
- 'command' in obj &&
163
- core_1.Command.is(obj.command));
164
- }
165
- CommandChatResponseContent.is = is;
166
- })(CommandChatResponseContent || (exports.CommandChatResponseContent = CommandChatResponseContent = {}));
167
- var CodeChatResponseContent;
168
- (function (CodeChatResponseContent) {
169
- function is(obj) {
170
- return (ChatResponseContent.is(obj) &&
171
- obj.kind === 'code' &&
172
- 'code' in obj &&
173
- typeof obj.code === 'string');
174
- }
175
- CodeChatResponseContent.is = is;
176
- })(CodeChatResponseContent || (exports.CodeChatResponseContent = CodeChatResponseContent = {}));
177
- var HorizontalLayoutChatResponseContent;
178
- (function (HorizontalLayoutChatResponseContent) {
179
- function is(obj) {
180
- return (ChatResponseContent.is(obj) &&
181
- obj.kind === 'horizontal' &&
182
- 'content' in obj &&
183
- Array.isArray(obj.content) &&
184
- obj.content.every(ChatResponseContent.is));
185
- }
186
- HorizontalLayoutChatResponseContent.is = is;
187
- })(HorizontalLayoutChatResponseContent || (exports.HorizontalLayoutChatResponseContent = HorizontalLayoutChatResponseContent = {}));
188
- var ToolCallChatResponseContent;
189
- (function (ToolCallChatResponseContent) {
190
- function is(obj) {
191
- return ChatResponseContent.is(obj) && obj.kind === 'toolCall';
192
- }
193
- ToolCallChatResponseContent.is = is;
194
- })(ToolCallChatResponseContent || (exports.ToolCallChatResponseContent = ToolCallChatResponseContent = {}));
195
- var ErrorChatResponseContent;
196
- (function (ErrorChatResponseContent) {
197
- function is(obj) {
198
- return (ChatResponseContent.is(obj) &&
199
- obj.kind === 'error' &&
200
- 'error' in obj &&
201
- obj.error instanceof Error);
202
- }
203
- ErrorChatResponseContent.is = is;
204
- })(ErrorChatResponseContent || (exports.ErrorChatResponseContent = ErrorChatResponseContent = {}));
205
- var ThinkingChatResponseContent;
206
- (function (ThinkingChatResponseContent) {
207
- function is(obj) {
208
- return (ChatResponseContent.is(obj) &&
209
- obj.kind === 'thinking' &&
210
- 'content' in obj &&
211
- typeof obj.content === 'string');
212
- }
213
- ThinkingChatResponseContent.is = is;
214
- })(ThinkingChatResponseContent || (exports.ThinkingChatResponseContent = ThinkingChatResponseContent = {}));
215
- var ProgressChatResponseContent;
216
- (function (ProgressChatResponseContent) {
217
- function is(obj) {
218
- return (ChatResponseContent.is(obj) &&
219
- obj.kind === 'progress' &&
220
- 'message' in obj &&
221
- typeof obj.message === 'string');
222
- }
223
- ProgressChatResponseContent.is = is;
224
- })(ProgressChatResponseContent || (exports.ProgressChatResponseContent = ProgressChatResponseContent = {}));
225
- var QuestionResponseContent;
226
- (function (QuestionResponseContent) {
227
- function is(obj) {
228
- return (ChatResponseContent.is(obj) &&
229
- obj.kind === 'question' &&
230
- 'question' in obj &&
231
- typeof obj.question === 'string' &&
232
- 'options' in obj &&
233
- Array.isArray(obj.options) &&
234
- obj.options.every(option => typeof option === 'object' &&
235
- option && 'text' in option &&
236
- typeof option.text === 'string' &&
237
- ('value' in option ? typeof option.value === 'string' || typeof option.value === 'undefined' : true)) &&
238
- // handler and request are optional (undefined for restored/read-only questions)
239
- ('handler' in obj ? obj.handler === undefined || typeof obj.handler === 'function' : true) &&
240
- ('request' in obj ? obj.request === undefined || obj.request instanceof MutableChatRequestModel : true));
241
- }
242
- QuestionResponseContent.is = is;
243
- })(QuestionResponseContent || (exports.QuestionResponseContent = QuestionResponseContent = {}));
244
- /**********************
245
- * Implementations
246
- **********************/
247
- class MutableChatModel {
248
- get location() {
249
- return this._location;
250
- }
251
- constructor(locationOrSerializedData = chat_agents_1.ChatAgentLocation.Panel) {
252
- this._onDidChangeEmitter = new core_1.Emitter();
253
- this.onDidChange = this._onDidChangeEmitter.event;
254
- this.toDispose = new core_1.DisposableCollection();
255
- this._suggestions = [];
256
- this._contextManager = new ChatContextManagerImpl();
257
- // Check if we're restoring from serialized data
258
- if (this.isSerializedChatModel(locationOrSerializedData)) {
259
- this.restoreFromSerializedData(locationOrSerializedData);
260
- }
261
- else {
262
- // Normal creation path
263
- this._location = locationOrSerializedData;
264
- this._id = (0, core_1.generateUuid)();
265
- this._hierarchy = new ChatRequestHierarchyImpl();
266
- this._changeSet = new ChatTreeChangeSet(this._hierarchy);
267
- this.toDispose.push(this._changeSet);
268
- this._changeSet.onDidChange(this._onDidChangeEmitter.fire, this._onDidChangeEmitter, this.toDispose);
269
- }
270
- this.toDispose.pushAll([
271
- this._onDidChangeEmitter,
272
- this._contextManager.onDidChange(this._onDidChangeEmitter.fire, this._onDidChangeEmitter),
273
- this._hierarchy.onDidChange(event => {
274
- this._onDidChangeEmitter.fire({
275
- kind: 'changeHierarchyBranch',
276
- branch: event.branch,
277
- });
278
- }),
279
- ]);
280
- }
281
- /**
282
- * Type guard to determine if we're receiving serialized data
283
- */
284
- isSerializedChatModel(data) {
285
- return typeof data === 'object' && 'sessionId' in data && 'requests' in data && 'responses' in data;
286
- }
287
- /**
288
- * Restore this chat model from serialized data
289
- *
290
- * Does not restore response content or changesets.
291
- * This handled by the chat service using the deserializer registries.
292
- */
293
- restoreFromSerializedData(data) {
294
- this._id = data.sessionId;
295
- this._location = data.location;
296
- // First, create all request models and build a map
297
- const requestMap = new Map();
298
- for (const reqData of data.requests) {
299
- const respData = data.responses.find(r => r.requestId === reqData.id);
300
- const requestModel = new MutableChatRequestModel(this, reqData, respData);
301
- requestMap.set(requestModel.id, requestModel);
302
- }
303
- // Restore the hierarchy structure with all alternatives
304
- this._hierarchy = new ChatRequestHierarchyImpl(data.hierarchy, requestMap);
305
- // Register all requests with changeset
306
- this._changeSet = new ChatTreeChangeSet(this._hierarchy);
307
- this.toDispose.push(this._changeSet);
308
- this._changeSet.onDidChange(this._onDidChangeEmitter.fire, this._onDidChangeEmitter, this.toDispose);
309
- for (const requestModel of requestMap.values()) {
310
- this._changeSet.registerRequest(requestModel);
311
- }
312
- }
313
- get id() {
314
- return this._id;
315
- }
316
- get changeSet() {
317
- return this._changeSet;
318
- }
319
- getBranches() {
320
- return this._hierarchy.activeBranches();
321
- }
322
- getBranch(requestId) {
323
- return this._hierarchy.findBranch(requestId);
324
- }
325
- getRequests() {
326
- return this._hierarchy.activeRequests();
327
- }
328
- getRequest(id) {
329
- return this.getRequests().find(request => request.id === id);
330
- }
331
- get suggestions() {
332
- return this._suggestions;
333
- }
334
- get context() {
335
- return this._contextManager;
336
- }
337
- get settings() {
338
- return this._settings;
339
- }
340
- setSettings(settings) {
341
- this._settings = settings;
342
- }
343
- addRequest(parsedChatRequest, agentId, context = { variables: [] }) {
344
- const add = this.getTargetForRequestAddition(parsedChatRequest);
345
- const requestModel = new MutableChatRequestModel(this, parsedChatRequest, agentId, context);
346
- requestModel.onDidChange(event => {
347
- if (!ChatChangeEvent.isChangeSetEvent(event)) {
348
- this._onDidChangeEmitter.fire(event);
349
- }
350
- }, this, this.toDispose);
351
- add(requestModel);
352
- this._changeSet.registerRequest(requestModel);
353
- this._onDidChangeEmitter.fire({
354
- kind: 'addRequest',
355
- request: requestModel,
356
- });
357
- return requestModel;
358
- }
359
- getTargetForRequestAddition(request) {
360
- const requestId = request.request.referencedRequestId;
361
- const branch = requestId !== undefined && this._hierarchy.findBranch(requestId);
362
- if (requestId !== undefined && !branch) {
363
- throw new Error(`Cannot find branch for requestId: ${requestId}`);
364
- }
365
- return branch ? branch.add.bind(branch) : this._hierarchy.append.bind(this._hierarchy);
366
- }
367
- setSuggestions(suggestions) {
368
- this._suggestions = Object.freeze(suggestions);
369
- this._onDidChangeEmitter.fire({
370
- kind: 'suggestionsChanged',
371
- suggestions
372
- });
373
- }
374
- isEmpty() {
375
- return this.getRequests().length === 0;
376
- }
377
- toSerializable() {
378
- const hierarchy = this._hierarchy.toSerializable();
379
- const allRequests = this.getAllRequests();
380
- const serializedRequests = allRequests.map(req => req.toSerializable());
381
- const serializedResponses = allRequests
382
- .filter(req => req.response)
383
- .map(req => req.response.toSerializable());
384
- return {
385
- sessionId: this._id,
386
- location: this.location,
387
- hierarchy,
388
- requests: serializedRequests,
389
- responses: serializedResponses
390
- };
391
- }
392
- /**
393
- * Get all requests from the hierarchy.
394
- * This is used for operations that need to process all requests, such as serialization.
395
- */
396
- getAllRequests() {
397
- const allRequests = [];
398
- const visited = new Set();
399
- const collectFromBranch = (branch) => {
400
- for (const item of branch.items) {
401
- // Avoid duplicates
402
- if (!visited.has(item.element.id)) {
403
- visited.add(item.element.id);
404
- allRequests.push(item.element);
405
- }
406
- // Recursively collect from next branches
407
- if (item.next) {
408
- collectFromBranch(item.next);
409
- }
410
- }
411
- };
412
- collectFromBranch(this._hierarchy.branch);
413
- return allRequests;
414
- }
415
- dispose() {
416
- this.toDispose.dispose();
417
- }
418
- }
419
- exports.MutableChatModel = MutableChatModel;
420
- class ChatTreeChangeSet {
421
- get onDidChange() {
422
- return this.onDidChangeEmitter.event;
423
- }
424
- constructor(hierarchy) {
425
- this.hierarchy = hierarchy;
426
- this.onDidChangeEmitter = new core_1.Emitter();
427
- this.toDispose = new core_1.DisposableCollection();
428
- this.currentElements = [];
429
- this.handleChangeSetChange = debounce(this.doHandleChangeSetChange.bind(this), 100, { leading: false, trailing: true });
430
- this.toDisposeOnRequestAdded = new core_1.DisposableCollection();
431
- hierarchy.onDidChange(this.handleChangeSetChange, this, this.toDispose);
432
- }
433
- get title() {
434
- var _a, _b;
435
- return (_b = (_a = this.getCurrentChangeSet()) === null || _a === void 0 ? void 0 : _a.title) !== null && _b !== void 0 ? _b : '';
436
- }
437
- removeElements(...uris) {
438
- return this.getMutableChangeSet().removeElements(...uris);
439
- }
440
- addElements(...elements) {
441
- return this.getMutableChangeSet().addElements(...elements);
442
- }
443
- setElements(...elements) {
444
- this.getMutableChangeSet().setElements(...elements);
445
- }
446
- setTitle(title) {
447
- this.getMutableChangeSet().setTitle(title);
448
- }
449
- getElementByURI(uri) {
450
- return this.currentElements.find(candidate => candidate.uri.isEqual(uri));
451
- }
452
- doHandleChangeSetChange() {
453
- var _a;
454
- const newElements = this.computeChangeSetElements();
455
- this.handleElementChange(newElements);
456
- this.currentElements = newElements;
457
- this.onDidChangeEmitter.fire({ kind: 'updateChangeSet', elements: this.currentElements, title: (_a = this.getCurrentChangeSet()) === null || _a === void 0 ? void 0 : _a.title });
458
- }
459
- getElements() {
460
- return this.currentElements;
461
- }
462
- computeChangeSetElements() {
463
- const allElements = change_set_1.ChangeSetImpl.combine((function* (requests) {
464
- for (let i = requests.length - 1; i >= 0; i--) {
465
- const changeSet = requests[i].changeSet;
466
- if (changeSet) {
467
- yield changeSet;
468
- }
469
- }
470
- })(this.hierarchy.activeRequests()));
471
- return core_1.ArrayUtils.coalesce(Array.from(allElements.values()));
472
- }
473
- handleElementChange(newElements) {
474
- var _a, _b;
475
- const old = new Set(this.currentElements);
476
- for (const element of newElements) {
477
- if (!old.delete(element)) {
478
- (_a = element.onShow) === null || _a === void 0 ? void 0 : _a.call(element);
479
- }
480
- }
481
- for (const element of old) {
482
- (_b = element.onHide) === null || _b === void 0 ? void 0 : _b.call(element);
483
- }
484
- }
485
- registerRequest(request) {
486
- request.onDidChange(event => event.kind === 'updateChangeSet' && this.handleChangeSetChange(), this, this.toDispose);
487
- if (this.localChangeSet) {
488
- request.changeSet = this.localChangeSet;
489
- this.localChangeSet = undefined;
490
- }
491
- this.toDisposeOnRequestAdded.dispose();
492
- }
493
- getMutableChangeSet() {
494
- const tipRequest = this.hierarchy.activeRequests().at(-1);
495
- const existingChangeSet = tipRequest === null || tipRequest === void 0 ? void 0 : tipRequest.changeSet;
496
- if (existingChangeSet) {
497
- return existingChangeSet;
498
- }
499
- if (this.localChangeSet && tipRequest) {
500
- throw new Error('Non-empty chat model retained reference to own change set. This is unexpected!');
501
- }
502
- if (this.localChangeSet) {
503
- return this.localChangeSet;
504
- }
505
- const newChangeSet = new change_set_1.ChangeSetImpl();
506
- if (tipRequest) {
507
- tipRequest.changeSet = newChangeSet;
508
- }
509
- else {
510
- this.localChangeSet = newChangeSet;
511
- newChangeSet.onDidChange(this.handleChangeSetChange, this, this.toDisposeOnRequestAdded);
512
- }
513
- return newChangeSet;
514
- }
515
- getCurrentChangeSet() {
516
- var _a;
517
- const holder = this.getBranchParent(candidate => !!candidate.get().changeSet);
518
- return (_a = holder === null || holder === void 0 ? void 0 : holder.get().changeSet) !== null && _a !== void 0 ? _a : this.localChangeSet;
519
- }
520
- /** Returns the lowest node among active nodes that satisfies {@link criterion} */
521
- getBranchParent(criterion) {
522
- const branches = this.hierarchy.activeBranches();
523
- for (let i = branches.length - 1; i >= 0; i--) {
524
- const branch = branches[i];
525
- if (criterion === null || criterion === void 0 ? void 0 : criterion(branch)) {
526
- return branch;
527
- }
528
- }
529
- return branches.at(0);
530
- }
531
- dispose() {
532
- this.toDispose.dispose();
533
- }
534
- }
535
- exports.ChatTreeChangeSet = ChatTreeChangeSet;
536
- class ChatRequestHierarchyImpl {
537
- constructor(serializedHierarchy, requestMap) {
538
- this.onDidChangeActiveBranchEmitter = new core_1.Emitter();
539
- this.onDidChange = this.onDidChangeActiveBranchEmitter.event;
540
- this.branch = new ChatRequestHierarchyBranchImpl(this);
541
- if (serializedHierarchy && requestMap) {
542
- this.restoreFromSerialized(serializedHierarchy, requestMap);
543
- }
544
- }
545
- /**
546
- * Restore the hierarchy from serialized data.
547
- */
548
- restoreFromSerialized(serializedHierarchy, requestMap) {
549
- // Build a map of branch IDs to restored branch objects
550
- const branchMap = new Map();
551
- // Function to restore a branch and its descendants
552
- const restoreBranch = (branchId) => {
553
- // Check if already restored
554
- if (branchMap.has(branchId)) {
555
- return branchMap.get(branchId);
556
- }
557
- const serializedBranch = serializedHierarchy.branches[branchId];
558
- if (!serializedBranch) {
559
- throw new Error(`Cannot find serialized branch with id: ${branchId}`);
560
- }
561
- // Restore items in this branch
562
- const items = serializedBranch.items.map(serializedItem => {
563
- const request = requestMap.get(serializedItem.requestId);
564
- if (!request) {
565
- throw new Error(`Cannot find request with id: ${serializedItem.requestId}`);
566
- }
567
- // Restore next branch if present
568
- const next = serializedItem.nextBranchId
569
- ? restoreBranch(serializedItem.nextBranchId)
570
- : undefined;
571
- return {
572
- element: request,
573
- next
574
- };
575
- });
576
- // Determine if this is the root branch
577
- const isRoot = branchId === serializedHierarchy.rootBranchId;
578
- if (isRoot) {
579
- // For root branch, we need to replace the existing branch's internals
580
- // Cast is safe here as we know this.branch is a ChatRequestHierarchyBranchImpl
581
- const rootBranch = this.branch;
582
- // Use Object.assign to update the readonly properties
583
- Object.assign(rootBranch, {
584
- id: branchId,
585
- items,
586
- _activeIndex: serializedBranch.activeBranchIndex
587
- });
588
- branchMap.set(branchId, rootBranch);
589
- return rootBranch;
590
- }
591
- else {
592
- // For non-root branches, use constructor-based deserialization
593
- const restoredBranch = new ChatRequestHierarchyBranchImpl(this, undefined, // previous will be set by parent
594
- items, serializedBranch.activeBranchIndex, branchId);
595
- branchMap.set(branchId, restoredBranch);
596
- return restoredBranch;
597
- }
598
- };
599
- // Start restoration from the root branch
600
- restoreBranch(serializedHierarchy.rootBranchId);
601
- }
602
- append(request) {
603
- const branches = this.activeBranches();
604
- if (branches.length === 0) {
605
- this.branch.add(request);
606
- return this.branch;
607
- }
608
- return branches.at(-1).continue(request);
609
- }
610
- activeRequests() {
611
- return this.activeBranches().map(h => h.get());
612
- }
613
- activeBranches() {
614
- return Array.from(this.iterateBranches());
615
- }
616
- *iterateBranches() {
617
- let current = this.branch;
618
- while (current) {
619
- if (current.items.length > 0) {
620
- yield current;
621
- current = current.next();
622
- }
623
- else {
624
- break;
625
- }
626
- }
627
- }
628
- findRequest(requestId) {
629
- var _a;
630
- const branch = this.findInBranch(this.branch, requestId);
631
- return (_a = branch === null || branch === void 0 ? void 0 : branch.items.find(item => item.element.id === requestId)) === null || _a === void 0 ? void 0 : _a.element;
632
- }
633
- findBranch(requestId) {
634
- return this.findInBranch(this.branch, requestId);
635
- }
636
- findInBranch(branch, requestId) {
637
- for (const item of branch.items) {
638
- if (item.element.id === requestId) {
639
- return branch;
640
- }
641
- }
642
- for (const item of branch.items) {
643
- if (item.next) {
644
- const found = this.findInBranch(item.next, requestId);
645
- if (found) {
646
- return found;
647
- }
648
- }
649
- }
650
- return undefined;
651
- }
652
- notifyChange(event) {
653
- this.onDidChangeActiveBranchEmitter.fire(event);
654
- }
655
- toSerializable() {
656
- const branches = {};
657
- // Recursively serialize all branches starting from the root
658
- this.serializeBranch(this.branch, branches);
659
- return {
660
- rootBranchId: this.branch.id,
661
- branches
662
- };
663
- }
664
- serializeBranch(branch, branches) {
665
- const items = branch.items.map(item => {
666
- var _a;
667
- if (item.next) {
668
- this.serializeBranch(item.next, branches);
669
- }
670
- return {
671
- requestId: item.element.id,
672
- nextBranchId: (_a = item.next) === null || _a === void 0 ? void 0 : _a.id
673
- };
674
- });
675
- branches[branch.id] = {
676
- id: branch.id,
677
- items,
678
- activeBranchIndex: branch.activeBranchIndex
679
- };
680
- }
681
- dispose() {
682
- this.onDidChangeActiveBranchEmitter.dispose();
683
- this.branch.dispose();
684
- }
685
- }
686
- exports.ChatRequestHierarchyImpl = ChatRequestHierarchyImpl;
687
- class ChatRequestHierarchyBranchImpl {
688
- constructor(hierarchy, previous, items = [], _activeIndex = -1, id) {
689
- this.hierarchy = hierarchy;
690
- this.previous = previous;
691
- this.items = items;
692
- this._activeIndex = _activeIndex;
693
- this.id = id !== null && id !== void 0 ? id : (0, core_1.generateUuid)();
694
- }
695
- get activeBranchIndex() {
696
- return this._activeIndex;
697
- }
698
- set activeBranchIndex(value) {
699
- this._activeIndex = value;
700
- this.hierarchy.notifyChange({
701
- branch: this,
702
- item: this.items[this._activeIndex]
703
- });
704
- }
705
- next() {
706
- var _a;
707
- return (_a = this.items[this.activeBranchIndex]) === null || _a === void 0 ? void 0 : _a.next;
708
- }
709
- get() {
710
- return this.items[this.activeBranchIndex].element;
711
- }
712
- add(request) {
713
- const branch = {
714
- element: request
715
- };
716
- this.items.push(branch);
717
- this.activeBranchIndex = this.items.length - 1;
718
- }
719
- remove(request) {
720
- const requestId = typeof request === 'string' ? request : request.id;
721
- const index = this.items.findIndex(version => version.element.id === requestId);
722
- if (index !== -1) {
723
- this.items.splice(index, 1);
724
- if (this.activeBranchIndex >= index) {
725
- this.activeBranchIndex--;
726
- }
727
- }
728
- }
729
- continue(request) {
730
- if (this.items.length === 0) {
731
- this.add(request);
732
- return this;
733
- }
734
- const item = this.items[this.activeBranchIndex];
735
- if (item) {
736
- const next = new ChatRequestHierarchyBranchImpl(this.hierarchy, this, [{ element: request }], 0);
737
- this.items[this.activeBranchIndex] = {
738
- ...item,
739
- next
740
- };
741
- return next;
742
- }
743
- throw new Error(`No current branch to continue from. Active Index: ${this.activeBranchIndex}`);
744
- }
745
- enable(request) {
746
- this.activeBranchIndex = this.items.findIndex(pred => pred.element.id === request.id);
747
- return this.items[this.activeBranchIndex];
748
- }
749
- enablePrevious() {
750
- if (this.activeBranchIndex > 0) {
751
- this.activeBranchIndex--;
752
- return this.items[this.activeBranchIndex];
753
- }
754
- return this.items[0];
755
- }
756
- enableNext() {
757
- if (this.activeBranchIndex < this.items.length - 1) {
758
- this.activeBranchIndex++;
759
- return this.items[this.activeBranchIndex];
760
- }
761
- return this.items[this.activeBranchIndex];
762
- }
763
- succeedingBranches() {
764
- const branches = [];
765
- let current = this;
766
- while (current !== undefined) {
767
- branches.push(current);
768
- current = current.next();
769
- }
770
- return branches;
771
- }
772
- dispose() {
773
- if (core_1.Disposable.is(this.get())) {
774
- this.items.forEach(({ element }) => core_1.Disposable.is(element) && element.dispose());
775
- }
776
- this.items.length = 0;
777
- }
778
- }
779
- exports.ChatRequestHierarchyBranchImpl = ChatRequestHierarchyBranchImpl;
780
- class ChatContextManagerImpl {
781
- get onDidChange() {
782
- return this.onDidChangeEmitter.event;
783
- }
784
- constructor(context) {
785
- this.variables = new Array();
786
- this.onDidChangeEmitter = new core_1.Emitter();
787
- if (context) {
788
- this.variables.push(...context.variables.map(ai_core_1.AIVariableResolutionRequest.fromResolved));
789
- }
790
- }
791
- getVariables() {
792
- const result = this.variables.slice();
793
- Object.freeze(result);
794
- return result;
795
- }
796
- addVariables(...variables) {
797
- let modified = false;
798
- variables.forEach(variable => {
799
- if (this.variables.some(existing => existing.variable.id === variable.variable.id && existing.arg === variable.arg)) {
800
- return;
801
- }
802
- this.variables.push(variable);
803
- modified = true;
804
- });
805
- if (modified) {
806
- this.onDidChangeEmitter.fire({ kind: 'addVariable' });
807
- }
808
- }
809
- deleteVariables(...indices) {
810
- const toDelete = indices.filter(candidate => candidate <= this.variables.length).sort((left, right) => right - left);
811
- if (toDelete.length) {
812
- toDelete.forEach(index => {
813
- this.variables.splice(index, 1);
814
- });
815
- this.onDidChangeEmitter.fire({ kind: 'removeVariable' });
816
- }
817
- }
818
- setVariables(variables) {
819
- this.variables.length = 0;
820
- variables.forEach(variable => {
821
- if (this.variables.some(existing => existing.variable.id === variable.variable.id && existing.arg === variable.arg)) {
822
- return;
823
- }
824
- this.variables.push(variable);
825
- });
826
- this.onDidChangeEmitter.fire({ kind: 'setVariables' });
827
- }
828
- clear() {
829
- if (this.variables.length) {
830
- this.variables.length = 0;
831
- this.onDidChangeEmitter.fire({ kind: 'removeVariable' });
832
- }
833
- }
834
- }
835
- exports.ChatContextManagerImpl = ChatContextManagerImpl;
836
- class MutableChatRequestModel {
837
- constructor(session, messageOrData, agentIdOrResponseData, context = { variables: [] }, data = {}) {
838
- this._onDidChangeEmitter = new core_1.Emitter();
839
- this.onDidChange = this._onDidChangeEmitter.event;
840
- this._isEditing = false;
841
- this.toDispose = new core_1.DisposableCollection();
842
- this._session = session;
843
- // Check if we're restoring from serialized data
844
- if (this.isSerializedRequestData(messageOrData)) {
845
- this.restoreFromSerializedData(messageOrData, agentIdOrResponseData);
846
- }
847
- else {
848
- // Normal creation path
849
- this._request = messageOrData.request;
850
- this._id = (0, core_1.generateUuid)();
851
- this._response = new MutableChatResponseModel(this._id, agentIdOrResponseData);
852
- this._context = context;
853
- this._agentId = agentIdOrResponseData;
854
- this._data = data;
855
- // Store the parsed message
856
- this.message = messageOrData;
857
- }
858
- this.editContextManager = new ChatContextManagerImpl(this._context);
859
- this.editContextManager.onDidChange(this._onDidChangeEmitter.fire, this._onDidChangeEmitter, this.toDispose);
860
- // Wire response changes to propagate through request to session
861
- this._response.onDidChange(() => {
862
- // Fire a generic addVariable event to propagate response changes
863
- this._onDidChangeEmitter.fire({ kind: 'responseChanged' });
864
- }, this, this.toDispose);
865
- this.toDispose.push(this._onDidChangeEmitter);
866
- }
867
- /**
868
- * Type guard to determine if we're receiving serialized data
869
- */
870
- isSerializedRequestData(data) {
871
- return 'id' in data && 'text' in data && !('request' in data);
872
- }
873
- /**
874
- * Restore this request model from serialized data
875
- */
876
- restoreFromSerializedData(reqData, respData) {
877
- this._id = reqData.id;
878
- this._request = { text: reqData.text };
879
- this._agentId = reqData.agentId;
880
- this._data = {};
881
- // Create minimal context
882
- this._context = { variables: [] };
883
- // TODO: More sophisticated restoration?
884
- // Casting required because 'message' is readonly
885
- this.message = {
886
- request: this._request,
887
- parts: [{
888
- kind: 'text',
889
- text: reqData.text,
890
- promptText: reqData.text,
891
- range: { start: 0, endExclusive: reqData.text.length }
892
- }],
893
- toolRequests: new Map(),
894
- variables: []
895
- };
896
- // Restore response if present
897
- if (respData) {
898
- this._response = new MutableChatResponseModel(this._id, this._agentId, respData);
899
- }
900
- else {
901
- this._response = new MutableChatResponseModel(this._id, this._agentId);
902
- }
903
- // Note: ChangeSet restoration will be handled by ChatService using deserializer registry
904
- }
905
- get changeSet() {
906
- return this._changeSet;
907
- }
908
- set changeSet(changeSet) {
909
- var _a;
910
- (_a = this._changeSet) === null || _a === void 0 ? void 0 : _a.dispose();
911
- this._changeSet = changeSet;
912
- this.toDispose.push(changeSet);
913
- changeSet.onDidChange(() => this._onDidChangeEmitter.fire({ kind: 'updateChangeSet', elements: changeSet.getElements(), title: changeSet.title }), this, this.toDispose);
914
- this._onDidChangeEmitter.fire({ kind: 'updateChangeSet', elements: changeSet.getElements(), title: changeSet.title });
915
- }
916
- get isEditing() {
917
- return this._isEditing;
918
- }
919
- enableEdit() {
920
- this._isEditing = true;
921
- this.emitEditRequest(this);
922
- }
923
- get data() {
924
- return this._data;
925
- }
926
- addData(key, value) {
927
- this._data[key] = value;
928
- }
929
- getDataByKey(key) {
930
- return this._data[key];
931
- }
932
- removeData(key) {
933
- delete this._data[key];
934
- }
935
- get id() {
936
- return this._id;
937
- }
938
- get session() {
939
- return this._session;
940
- }
941
- get request() {
942
- return this._request;
943
- }
944
- get response() {
945
- return this._response;
946
- }
947
- get context() {
948
- return this._context;
949
- }
950
- get agentId() {
951
- return this._agentId;
952
- }
953
- cancelEdit() {
954
- if (this.isEditing) {
955
- this._isEditing = false;
956
- this.emitCancelEdit(this);
957
- this.clearEditContext();
958
- }
959
- }
960
- submitEdit(newRequest) {
961
- var _a;
962
- if (this.isEditing) {
963
- this._isEditing = false;
964
- const variables = (_a = this.editContextManager.getVariables()) !== null && _a !== void 0 ? _a : [];
965
- this.emitSubmitEdit(this, {
966
- ...newRequest,
967
- referencedRequestId: this.id,
968
- variables
969
- });
970
- this.clearEditContext();
971
- }
972
- }
973
- cancel() {
974
- this.response.cancel();
975
- }
976
- toSerializable() {
977
- return {
978
- id: this.id,
979
- text: this.request.text,
980
- agentId: this.agentId,
981
- changeSet: this._changeSet ? {
982
- title: this._changeSet.title,
983
- elements: this._changeSet.getElements().map(elem => { var _a; return (_a = elem.toSerializable) === null || _a === void 0 ? void 0 : _a.call(elem); }).filter((elem) => elem !== undefined)
984
- } : undefined
985
- };
986
- }
987
- dispose() {
988
- this.toDispose.dispose();
989
- }
990
- clearEditContext() {
991
- this.editContextManager.setVariables(this.context.variables.map(ai_core_1.AIVariableResolutionRequest.fromResolved));
992
- }
993
- emitEditRequest(request) {
994
- const branch = this.session.getBranch(request.id);
995
- if (!branch) {
996
- throw new Error(`Cannot find hierarchy for requestId: ${request.id}`);
997
- }
998
- this._onDidChangeEmitter.fire({
999
- kind: 'enableEdit',
1000
- request,
1001
- branch,
1002
- });
1003
- }
1004
- emitCancelEdit(request) {
1005
- const branch = this.session.getBranch(request.id);
1006
- if (!branch) {
1007
- throw new Error(`Cannot find branch for requestId: ${request.id}`);
1008
- }
1009
- this._onDidChangeEmitter.fire({
1010
- kind: 'cancelEdit',
1011
- request,
1012
- branch,
1013
- });
1014
- }
1015
- emitSubmitEdit(request, newRequest) {
1016
- const branch = this.session.getBranch(request.id);
1017
- if (!branch) {
1018
- throw new Error(`Cannot find branch for requestId: ${request.id}`);
1019
- }
1020
- this._onDidChangeEmitter.fire({
1021
- kind: 'submitEdit',
1022
- request,
1023
- branch,
1024
- newRequest
1025
- });
1026
- }
1027
- }
1028
- exports.MutableChatRequestModel = MutableChatRequestModel;
1029
- class ErrorChatResponseContentImpl {
1030
- constructor(error) {
1031
- this.kind = 'error';
1032
- this._error = error;
1033
- }
1034
- get error() {
1035
- return this._error;
1036
- }
1037
- asString() {
1038
- return undefined;
1039
- }
1040
- toSerializable() {
1041
- return {
1042
- kind: 'error',
1043
- data: {
1044
- message: this._error.message,
1045
- stack: this._error.stack
1046
- }
1047
- };
1048
- }
1049
- }
1050
- exports.ErrorChatResponseContentImpl = ErrorChatResponseContentImpl;
1051
- class TextChatResponseContentImpl {
1052
- constructor(content) {
1053
- this.kind = 'text';
1054
- this._content = content;
1055
- }
1056
- get content() {
1057
- return this._content;
1058
- }
1059
- asString() {
1060
- return this._content;
1061
- }
1062
- asDisplayString() {
1063
- return this.asString();
1064
- }
1065
- merge(nextChatResponseContent) {
1066
- this._content += nextChatResponseContent.content;
1067
- return true;
1068
- }
1069
- toLanguageModelMessage() {
1070
- return {
1071
- actor: 'ai',
1072
- type: 'text',
1073
- text: this.content
1074
- };
1075
- }
1076
- toSerializable() {
1077
- return {
1078
- kind: 'text',
1079
- data: { content: this._content }
1080
- };
1081
- }
1082
- }
1083
- exports.TextChatResponseContentImpl = TextChatResponseContentImpl;
1084
- class ThinkingChatResponseContentImpl {
1085
- constructor(content, signature) {
1086
- this.kind = 'thinking';
1087
- this._content = content;
1088
- this._signature = signature;
1089
- }
1090
- get content() {
1091
- return this._content;
1092
- }
1093
- get signature() {
1094
- return this._signature;
1095
- }
1096
- asString() {
1097
- return JSON.stringify({
1098
- type: 'thinking',
1099
- thinking: this.content,
1100
- signature: this.signature
1101
- });
1102
- }
1103
- asDisplayString() {
1104
- return `<Thinking>${this.content}</Thinking>`;
1105
- }
1106
- merge(nextChatResponseContent) {
1107
- this._content += nextChatResponseContent.content;
1108
- this._signature += nextChatResponseContent.signature;
1109
- return true;
1110
- }
1111
- toLanguageModelMessage() {
1112
- return {
1113
- actor: 'ai',
1114
- type: 'thinking',
1115
- thinking: this.content,
1116
- signature: this.signature
1117
- };
1118
- }
1119
- toSerializable() {
1120
- return {
1121
- kind: 'thinking',
1122
- data: {
1123
- content: this._content,
1124
- signature: this._signature
1125
- }
1126
- };
1127
- }
1128
- }
1129
- exports.ThinkingChatResponseContentImpl = ThinkingChatResponseContentImpl;
1130
- class MarkdownChatResponseContentImpl {
1131
- constructor(content) {
1132
- this.kind = 'markdownContent';
1133
- this._content = new markdown_rendering_1.MarkdownStringImpl();
1134
- this._content.appendMarkdown(content);
1135
- }
1136
- get content() {
1137
- return this._content;
1138
- }
1139
- asString() {
1140
- return this._content.value;
1141
- }
1142
- asDisplayString() {
1143
- return this.asString();
1144
- }
1145
- merge(nextChatResponseContent) {
1146
- this._content.appendMarkdown(nextChatResponseContent.content.value);
1147
- return true;
1148
- }
1149
- toLanguageModelMessage() {
1150
- return {
1151
- actor: 'ai',
1152
- type: 'text',
1153
- text: this.content.value
1154
- };
1155
- }
1156
- toSerializable() {
1157
- return {
1158
- kind: 'markdownContent',
1159
- data: { content: this._content.value }
1160
- };
1161
- }
1162
- }
1163
- exports.MarkdownChatResponseContentImpl = MarkdownChatResponseContentImpl;
1164
- class InformationalChatResponseContentImpl {
1165
- constructor(content) {
1166
- this.kind = 'informational';
1167
- this._content = new markdown_rendering_1.MarkdownStringImpl(content);
1168
- }
1169
- get content() {
1170
- return this._content;
1171
- }
1172
- asString() {
1173
- return undefined;
1174
- }
1175
- merge(nextChatResponseContent) {
1176
- this._content.appendMarkdown(nextChatResponseContent.content.value);
1177
- return true;
1178
- }
1179
- toSerializable() {
1180
- return {
1181
- kind: 'informational',
1182
- data: { content: this._content.value }
1183
- };
1184
- }
1185
- }
1186
- exports.InformationalChatResponseContentImpl = InformationalChatResponseContentImpl;
1187
- class CodeChatResponseContentImpl {
1188
- constructor(code, language, location) {
1189
- this.kind = 'code';
1190
- this._code = code;
1191
- this._language = language;
1192
- this._location = location;
1193
- }
1194
- get code() {
1195
- return this._code;
1196
- }
1197
- get language() {
1198
- return this._language;
1199
- }
1200
- get location() {
1201
- return this._location;
1202
- }
1203
- asString() {
1204
- var _a;
1205
- return `\`\`\`${(_a = this._language) !== null && _a !== void 0 ? _a : ''}\n${this._code}\n\`\`\``;
1206
- }
1207
- merge(nextChatResponseContent) {
1208
- this._code += `${nextChatResponseContent.code}`;
1209
- return true;
1210
- }
1211
- toSerializable() {
1212
- return {
1213
- kind: 'code',
1214
- data: {
1215
- code: this._code,
1216
- language: this._language,
1217
- location: this._location
1218
- }
1219
- };
1220
- }
1221
- }
1222
- exports.CodeChatResponseContentImpl = CodeChatResponseContentImpl;
1223
- class ToolCallChatResponseContentImpl {
1224
- constructor(id, name, arg_string, finished, result) {
1225
- this.kind = 'toolCall';
1226
- this._id = id;
1227
- this._name = name;
1228
- this._arguments = arg_string;
1229
- this._finished = finished;
1230
- this._result = result;
1231
- // Initialize the confirmation promise immediately
1232
- this._confirmed = this.createConfirmationPromise();
1233
- }
1234
- get id() {
1235
- return this._id;
1236
- }
1237
- get name() {
1238
- return this._name;
1239
- }
1240
- get arguments() {
1241
- return this._arguments;
1242
- }
1243
- get finished() {
1244
- return this._finished === undefined ? false : this._finished;
1245
- }
1246
- get result() {
1247
- return this._result;
1248
- }
1249
- get confirmed() {
1250
- return this._confirmed;
1251
- }
1252
- /**
1253
- * Create a confirmation promise that can be resolved/rejected later
1254
- */
1255
- createConfirmationPromise() {
1256
- // The promise is always created, just ensure we have resolution handlers
1257
- if (!this._confirmationResolver) {
1258
- this._confirmed = new Promise((resolve, reject) => {
1259
- this._confirmationResolver = resolve;
1260
- this._confirmationRejecter = reject;
1261
- });
1262
- }
1263
- return this._confirmed;
1264
- }
1265
- /**
1266
- * Confirm the tool execution
1267
- */
1268
- confirm() {
1269
- if (this._confirmationResolver) {
1270
- this._confirmationResolver(true);
1271
- }
1272
- }
1273
- /**
1274
- * Deny the tool execution
1275
- */
1276
- deny() {
1277
- if (this._confirmationResolver) {
1278
- this._confirmationResolver(false);
1279
- this._finished = true;
1280
- this._result = 'Tool execution denied by user';
1281
- }
1282
- }
1283
- /**
1284
- * Cancel the confirmation (reject the promise)
1285
- */
1286
- cancelConfirmation(reason) {
1287
- if (this._confirmationRejecter) {
1288
- this._confirmationRejecter(reason);
1289
- }
1290
- }
1291
- asString() {
1292
- return '';
1293
- }
1294
- asDisplayString() {
1295
- var _a;
1296
- return `Tool call: ${this._name}(${(_a = this._arguments) !== null && _a !== void 0 ? _a : ''})`;
1297
- }
1298
- merge(nextChatResponseContent) {
1299
- if (nextChatResponseContent.id === this.id) {
1300
- this._finished = nextChatResponseContent.finished;
1301
- this._result = nextChatResponseContent.result;
1302
- const args = nextChatResponseContent.arguments;
1303
- this._arguments = (args && args.length > 0) ? args : this._arguments;
1304
- // Don't merge confirmation promises - they should be managed separately
1305
- return true;
1306
- }
1307
- if (nextChatResponseContent.name !== undefined) {
1308
- return false;
1309
- }
1310
- if (nextChatResponseContent.arguments === undefined) {
1311
- return false;
1312
- }
1313
- this._arguments += `${nextChatResponseContent.arguments}`;
1314
- return true;
1315
- }
1316
- toLanguageModelMessage() {
1317
- var _a, _b, _c, _d;
1318
- return [{
1319
- actor: 'ai',
1320
- type: 'tool_use',
1321
- id: (_a = this.id) !== null && _a !== void 0 ? _a : '',
1322
- input: this.arguments && this.arguments.length !== 0 ? JSON.parse(this.arguments) : {},
1323
- name: (_b = this.name) !== null && _b !== void 0 ? _b : ''
1324
- }, {
1325
- actor: 'user',
1326
- type: 'tool_result',
1327
- tool_use_id: (_c = this.id) !== null && _c !== void 0 ? _c : '',
1328
- content: this.result,
1329
- name: (_d = this.name) !== null && _d !== void 0 ? _d : ''
1330
- }];
1331
- }
1332
- toSerializable() {
1333
- return {
1334
- kind: 'toolCall',
1335
- data: {
1336
- id: this._id,
1337
- name: this._name,
1338
- arguments: this._arguments,
1339
- finished: this._finished,
1340
- result: this._result
1341
- }
1342
- };
1343
- }
1344
- }
1345
- exports.ToolCallChatResponseContentImpl = ToolCallChatResponseContentImpl;
1346
- exports.COMMAND_CHAT_RESPONSE_COMMAND = {
1347
- id: 'ai-chat.command-chat-response.generic'
1348
- };
1349
- class CommandChatResponseContentImpl {
1350
- constructor(command, customCallback, args) {
1351
- this.command = command;
1352
- this.customCallback = customCallback;
1353
- this.args = args;
1354
- this.kind = 'command';
1355
- }
1356
- get arguments() {
1357
- var _a;
1358
- return (_a = this.args) !== null && _a !== void 0 ? _a : [];
1359
- }
1360
- asString() {
1361
- var _a, _b;
1362
- return ((_a = this.command) === null || _a === void 0 ? void 0 : _a.id) || ((_b = this.customCallback) === null || _b === void 0 ? void 0 : _b.label) || 'command';
1363
- }
1364
- toSerializable() {
1365
- var _a, _b;
1366
- return {
1367
- kind: 'command',
1368
- data: {
1369
- commandId: (_a = this.command) === null || _a === void 0 ? void 0 : _a.id,
1370
- commandLabel: (_b = this.customCallback) === null || _b === void 0 ? void 0 : _b.label,
1371
- arguments: this.args
1372
- }
1373
- };
1374
- }
1375
- }
1376
- exports.CommandChatResponseContentImpl = CommandChatResponseContentImpl;
1377
- class HorizontalLayoutChatResponseContentImpl {
1378
- constructor(content = []) {
1379
- this.kind = 'horizontal';
1380
- this._content = content;
1381
- }
1382
- get content() {
1383
- return this._content;
1384
- }
1385
- asString() {
1386
- return this._content.map(child => child.asString && child.asString()).join(' ');
1387
- }
1388
- asDisplayString() {
1389
- return this.asString();
1390
- }
1391
- merge(nextChatResponseContent) {
1392
- if (HorizontalLayoutChatResponseContent.is(nextChatResponseContent)) {
1393
- this._content.push(...nextChatResponseContent.content);
1394
- }
1395
- else {
1396
- this._content.push(nextChatResponseContent);
1397
- }
1398
- return true;
1399
- }
1400
- toSerializable() {
1401
- return {
1402
- kind: 'horizontal',
1403
- data: {
1404
- content: this._content.map(child => {
1405
- var _a, _b, _c;
1406
- const serialized = (_a = child.toSerializable) === null || _a === void 0 ? void 0 : _a.call(child);
1407
- if (!serialized) {
1408
- return {
1409
- kind: child.kind,
1410
- fallbackMessage: (_b = child.asString) === null || _b === void 0 ? void 0 : _b.call(child),
1411
- data: undefined
1412
- };
1413
- }
1414
- return {
1415
- ...serialized,
1416
- fallbackMessage: (_c = child.asString) === null || _c === void 0 ? void 0 : _c.call(child)
1417
- };
1418
- })
1419
- }
1420
- };
1421
- }
1422
- }
1423
- exports.HorizontalLayoutChatResponseContentImpl = HorizontalLayoutChatResponseContentImpl;
1424
- /**
1425
- * Default implementation for the QuestionResponseContent.
1426
- * Can be created with or without handler/request for read-only (restored) mode.
1427
- */
1428
- class QuestionResponseContentImpl {
1429
- constructor(question, options, request, handler, selectedOption) {
1430
- this.question = question;
1431
- this.options = options;
1432
- this.request = request;
1433
- this.handler = handler;
1434
- this.kind = 'question';
1435
- this._selectedOption = selectedOption;
1436
- }
1437
- get isReadOnly() {
1438
- return !this.handler || !this.request;
1439
- }
1440
- set selectedOption(option) {
1441
- this._selectedOption = option;
1442
- // Only trigger change notification if request is available (not in read-only mode)
1443
- if (this.request) {
1444
- this.request.response.response.responseContentChanged();
1445
- }
1446
- }
1447
- get selectedOption() {
1448
- return this._selectedOption;
1449
- }
1450
- asString() {
1451
- var _a;
1452
- return `Question: ${this.question}
1453
- ${this.selectedOption ? `Answer: ${(_a = this.selectedOption) === null || _a === void 0 ? void 0 : _a.text}` : 'No answer'}`;
1454
- }
1455
- merge() {
1456
- return false;
1457
- }
1458
- toSerializable() {
1459
- return {
1460
- kind: 'question',
1461
- data: {
1462
- question: this.question,
1463
- options: this.options,
1464
- selectedOption: this._selectedOption
1465
- }
1466
- };
1467
- }
1468
- }
1469
- exports.QuestionResponseContentImpl = QuestionResponseContentImpl;
1470
- class ChatResponseImpl {
1471
- constructor() {
1472
- this._onDidChangeEmitter = new core_1.Emitter();
1473
- this.onDidChange = this._onDidChangeEmitter.event;
1474
- this._content = [];
1475
- }
1476
- get content() {
1477
- return this._content;
1478
- }
1479
- clearContent() {
1480
- this._content = [];
1481
- this._updateResponseRepresentation();
1482
- this._onDidChangeEmitter.fire();
1483
- }
1484
- addContents(contents) {
1485
- contents.forEach(c => this.doAddContent(c));
1486
- this._onDidChangeEmitter.fire();
1487
- }
1488
- addContent(nextContent) {
1489
- // TODO: Support more complex merges affecting different content than the last, e.g. via some kind of ProcessorRegistry
1490
- // TODO: Support more of the built-in VS Code behavior, see
1491
- // https://github.com/microsoft/vscode/blob/a2cab7255c0df424027be05d58e1b7b941f4ea60/src/vs/workbench/contrib/chat/common/chatModel.ts#L188-L244
1492
- this.doAddContent(nextContent);
1493
- this._onDidChangeEmitter.fire();
1494
- }
1495
- doAddContent(nextContent) {
1496
- var _a;
1497
- if (ToolCallChatResponseContent.is(nextContent) && nextContent.id !== undefined) {
1498
- const fittingTool = this._content.find(c => ToolCallChatResponseContent.is(c) && c.id === nextContent.id);
1499
- if (fittingTool !== undefined) {
1500
- (_a = fittingTool.merge) === null || _a === void 0 ? void 0 : _a.call(fittingTool, nextContent);
1501
- }
1502
- else {
1503
- this._content.push(nextContent);
1504
- }
1505
- }
1506
- else {
1507
- const lastElement = this._content.length > 0
1508
- ? this._content[this._content.length - 1]
1509
- : undefined;
1510
- if ((lastElement === null || lastElement === void 0 ? void 0 : lastElement.kind) === nextContent.kind && ChatResponseContent.hasMerge(lastElement)) {
1511
- const mergeSuccess = lastElement.merge(nextContent);
1512
- if (!mergeSuccess) {
1513
- this._content.push(nextContent);
1514
- }
1515
- }
1516
- else {
1517
- this._content.push(nextContent);
1518
- }
1519
- }
1520
- this._updateResponseRepresentation();
1521
- }
1522
- responseContentChanged() {
1523
- this._updateResponseRepresentation();
1524
- this._onDidChangeEmitter.fire();
1525
- }
1526
- _updateResponseRepresentation() {
1527
- this._responseRepresentation = this.responseRepresentationsToString(this._content, 'asString');
1528
- this._responseRepresentationForDisplay = this.responseRepresentationsToString(this.content, 'asDisplayString');
1529
- }
1530
- responseRepresentationsToString(content, collect) {
1531
- return content
1532
- .map(responseContent => {
1533
- if (collect === 'asDisplayString') {
1534
- if (ChatResponseContent.hasDisplayString(responseContent)) {
1535
- return responseContent.asDisplayString();
1536
- }
1537
- }
1538
- if (ChatResponseContent.hasAsString(responseContent)) {
1539
- return responseContent.asString();
1540
- }
1541
- if (TextChatResponseContent.is(responseContent)) {
1542
- return responseContent.content;
1543
- }
1544
- console.warn('Was not able to map responseContent to a string', responseContent);
1545
- return undefined;
1546
- })
1547
- .filter(text => (text !== undefined && text !== ''))
1548
- .join('\n\n');
1549
- }
1550
- asString() {
1551
- return this._responseRepresentation;
1552
- }
1553
- asDisplayString() {
1554
- return this._responseRepresentationForDisplay;
1555
- }
1556
- }
1557
- class MutableChatResponseModel {
1558
- constructor(requestId, agentId, serializedData) {
1559
- this._onDidChangeEmitter = new core_1.Emitter();
1560
- this.onDidChange = this._onDidChangeEmitter.event;
1561
- this.data = {};
1562
- this._requestId = requestId;
1563
- this._agentId = agentId;
1564
- this._cancellationToken = new core_1.CancellationTokenSource();
1565
- // Check if we're restoring from serialized data
1566
- if (serializedData) {
1567
- this.restoreFromSerializedData(serializedData);
1568
- }
1569
- else {
1570
- // Normal creation path
1571
- this._id = (0, core_1.generateUuid)();
1572
- this._progressMessages = [];
1573
- this._isComplete = false;
1574
- this._isWaitingForInput = false;
1575
- this._isError = false;
1576
- }
1577
- const response = new ChatResponseImpl();
1578
- response.onDidChange(() => this._onDidChangeEmitter.fire());
1579
- this._response = response;
1580
- }
1581
- /**
1582
- * Restore this response model from serialized data
1583
- */
1584
- restoreFromSerializedData(data) {
1585
- this._id = data.id;
1586
- // Always mark restored responses as complete since there's no active agent
1587
- this._isComplete = true;
1588
- this._isError = data.isError;
1589
- // Do not restore waitingForInput state - when a session is restored,
1590
- // the agent that was waiting for input is no longer running
1591
- this._isWaitingForInput = false;
1592
- // TODO: Restore progressMessages?
1593
- this._progressMessages = [];
1594
- if (data.errorMessage) {
1595
- this._errorObject = new Error(data.errorMessage);
1596
- }
1597
- // Note: Content restoration will be handled by ChatService using deserializer registry
1598
- }
1599
- get id() {
1600
- return this._id;
1601
- }
1602
- get requestId() {
1603
- return this._requestId;
1604
- }
1605
- get progressMessages() {
1606
- return this._progressMessages;
1607
- }
1608
- addProgressMessage(message) {
1609
- var _a, _b, _c;
1610
- const id = (_a = message.id) !== null && _a !== void 0 ? _a : (0, core_1.generateUuid)();
1611
- const existingMessage = this.getProgressMessage(id);
1612
- if (existingMessage) {
1613
- this.updateProgressMessage({ id, ...message });
1614
- return existingMessage;
1615
- }
1616
- const newMessage = {
1617
- kind: 'progressMessage',
1618
- id,
1619
- status: (_b = message.status) !== null && _b !== void 0 ? _b : 'inProgress',
1620
- show: (_c = message.show) !== null && _c !== void 0 ? _c : 'untilFirstContent',
1621
- ...message,
1622
- };
1623
- this._progressMessages.push(newMessage);
1624
- this._onDidChangeEmitter.fire();
1625
- return newMessage;
1626
- }
1627
- getProgressMessage(id) {
1628
- return this._progressMessages.find(message => message.id === id);
1629
- }
1630
- updateProgressMessage(message) {
1631
- const progressMessage = this.getProgressMessage(message.id);
1632
- if (progressMessage) {
1633
- Object.assign(progressMessage, message);
1634
- this._onDidChangeEmitter.fire();
1635
- }
1636
- }
1637
- get response() {
1638
- return this._response;
1639
- }
1640
- get isComplete() {
1641
- return this._isComplete;
1642
- }
1643
- get isCanceled() {
1644
- return this._cancellationToken.token.isCancellationRequested;
1645
- }
1646
- get isWaitingForInput() {
1647
- return this._isWaitingForInput;
1648
- }
1649
- get agentId() {
1650
- return this._agentId;
1651
- }
1652
- overrideAgentId(agentId) {
1653
- this._agentId = agentId;
1654
- }
1655
- complete() {
1656
- this._isComplete = true;
1657
- this._isWaitingForInput = false;
1658
- this._onDidChangeEmitter.fire();
1659
- }
1660
- cancel() {
1661
- this._cancellationToken.cancel();
1662
- this._isComplete = true;
1663
- this._isWaitingForInput = false;
1664
- // Ensure any pending tool confirmations are canceled when the chat is canceled
1665
- try {
1666
- const content = this._response.content;
1667
- for (const item of content) {
1668
- if (ToolCallChatResponseContent.is(item)) {
1669
- item.cancelConfirmation(new Error('Chat request canceled'));
1670
- }
1671
- }
1672
- }
1673
- catch (e) {
1674
- // best-effort: ignore errors while canceling confirmations
1675
- }
1676
- this._onDidChangeEmitter.fire();
1677
- }
1678
- get cancellationToken() {
1679
- return this._cancellationToken.token;
1680
- }
1681
- waitForInput() {
1682
- this._isWaitingForInput = true;
1683
- this._onDidChangeEmitter.fire();
1684
- }
1685
- stopWaitingForInput() {
1686
- this._isWaitingForInput = false;
1687
- this._onDidChangeEmitter.fire();
1688
- }
1689
- error(error) {
1690
- this._isComplete = true;
1691
- this._isWaitingForInput = false;
1692
- this._isError = true;
1693
- this._errorObject = error;
1694
- this._onDidChangeEmitter.fire();
1695
- }
1696
- get errorObject() {
1697
- return this._errorObject;
1698
- }
1699
- get isError() {
1700
- return this._isError;
1701
- }
1702
- toSerializable() {
1703
- var _a;
1704
- return {
1705
- id: this.id,
1706
- requestId: this.requestId,
1707
- isComplete: this.isComplete,
1708
- isError: this.isError,
1709
- errorMessage: (_a = this.errorObject) === null || _a === void 0 ? void 0 : _a.message,
1710
- content: this.response.content.map(c => {
1711
- var _a, _b, _c;
1712
- const serialized = (_a = c.toSerializable) === null || _a === void 0 ? void 0 : _a.call(c);
1713
- if (!serialized) {
1714
- // Fallback if toSerializable not implemented
1715
- return {
1716
- kind: c.kind,
1717
- fallbackMessage: (_b = c.asString) === null || _b === void 0 ? void 0 : _b.call(c),
1718
- data: undefined
1719
- };
1720
- }
1721
- return {
1722
- ...serialized,
1723
- fallbackMessage: (_c = c.asString) === null || _c === void 0 ? void 0 : _c.call(c)
1724
- };
1725
- })
1726
- };
1727
- }
1728
- }
1729
- exports.MutableChatResponseModel = MutableChatResponseModel;
1730
- class ErrorChatResponseModel extends MutableChatResponseModel {
1731
- constructor(requestId, error, agentId) {
1732
- super(requestId, agentId);
1733
- this.error(error);
1734
- }
1735
- }
1736
- exports.ErrorChatResponseModel = ErrorChatResponseModel;
1737
- class ProgressChatResponseContentImpl {
1738
- constructor(message) {
1739
- this.kind = 'progress';
1740
- this._message = message;
1741
- }
1742
- get message() {
1743
- return this._message;
1744
- }
1745
- asString() {
1746
- return JSON.stringify({
1747
- type: 'progress',
1748
- message: this.message
1749
- });
1750
- }
1751
- asDisplayString() {
1752
- return `<Progress>${this.message}</Progress>`;
1753
- }
1754
- merge(nextChatResponseContent) {
1755
- this._message = nextChatResponseContent.message;
1756
- return true;
1757
- }
1758
- toLanguageModelMessage() {
1759
- return {
1760
- actor: 'ai',
1761
- type: 'text',
1762
- text: this.message
1763
- };
1764
- }
1765
- toSerializable() {
1766
- return {
1767
- kind: 'progress',
1768
- data: { message: this._message }
1769
- };
1770
- }
1771
- }
1772
- exports.ProgressChatResponseContentImpl = ProgressChatResponseContentImpl;
1773
- class UnknownChatResponseContentImpl {
1774
- constructor(originalKind, fallbackMessage, data) {
1775
- this.originalKind = originalKind;
1776
- this.fallbackMessage = fallbackMessage;
1777
- this.data = data;
1778
- this.kind = 'unknown';
1779
- }
1780
- asString() {
1781
- return this.fallbackMessage;
1782
- }
1783
- toSerializable() {
1784
- return {
1785
- kind: 'unknown',
1786
- data: this.data
1787
- };
1788
- }
1789
- }
1790
- exports.UnknownChatResponseContentImpl = UnknownChatResponseContentImpl;
1791
- //# sourceMappingURL=chat-model.js.map