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

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 (253) hide show
  1. package/lib/browser/agent-delegation-tool.d.ts +25 -0
  2. package/lib/browser/agent-delegation-tool.d.ts.map +1 -0
  3. package/lib/browser/agent-delegation-tool.js +196 -0
  4. package/lib/browser/agent-delegation-tool.js.map +1 -0
  5. package/lib/browser/ai-chat-frontend-contribution.d.ts +11 -0
  6. package/lib/browser/ai-chat-frontend-contribution.d.ts.map +1 -0
  7. package/lib/browser/ai-chat-frontend-contribution.js +56 -0
  8. package/lib/browser/ai-chat-frontend-contribution.js.map +1 -0
  9. package/lib/browser/ai-chat-frontend-module.d.ts +4 -0
  10. package/lib/browser/ai-chat-frontend-module.d.ts.map +1 -0
  11. package/lib/browser/ai-chat-frontend-module.js +143 -0
  12. package/lib/browser/ai-chat-frontend-module.js.map +1 -0
  13. package/lib/browser/change-set-decorator-service.d.ts +24 -0
  14. package/lib/browser/change-set-decorator-service.d.ts.map +1 -0
  15. package/lib/browser/change-set-decorator-service.js +66 -0
  16. package/lib/browser/change-set-decorator-service.js.map +1 -0
  17. package/lib/browser/change-set-file-element-deserializer.d.ts +7 -0
  18. package/lib/browser/change-set-file-element-deserializer.d.ts.map +1 -0
  19. package/lib/browser/change-set-file-element-deserializer.js +61 -0
  20. package/lib/browser/change-set-file-element-deserializer.js.map +1 -0
  21. package/lib/browser/change-set-file-element.d.ts +122 -0
  22. package/lib/browser/change-set-file-element.d.ts.map +1 -0
  23. package/lib/browser/change-set-file-element.js +435 -0
  24. package/lib/browser/change-set-file-element.js.map +1 -0
  25. package/lib/browser/change-set-file-resource.d.ts +4 -0
  26. package/lib/browser/change-set-file-resource.d.ts.map +1 -0
  27. package/lib/browser/change-set-file-resource.js +24 -0
  28. package/lib/browser/change-set-file-resource.js.map +1 -0
  29. package/lib/browser/change-set-file-service.d.ts +32 -0
  30. package/lib/browser/change-set-file-service.d.ts.map +1 -0
  31. package/lib/browser/change-set-file-service.js +161 -0
  32. package/lib/browser/change-set-file-service.js.map +1 -0
  33. package/lib/browser/change-set-variable.d.ts +11 -0
  34. package/lib/browser/change-set-variable.d.ts.map +1 -0
  35. package/lib/browser/change-set-variable.js +64 -0
  36. package/lib/browser/change-set-variable.js.map +1 -0
  37. package/lib/browser/chat-session-store-impl.d.ts +36 -0
  38. package/lib/browser/chat-session-store-impl.d.ts.map +1 -0
  39. package/lib/browser/chat-session-store-impl.js +287 -0
  40. package/lib/browser/chat-session-store-impl.js.map +1 -0
  41. package/lib/browser/chat-tool-preference-bindings.d.ts +34 -0
  42. package/lib/browser/chat-tool-preference-bindings.d.ts.map +1 -0
  43. package/lib/browser/chat-tool-preference-bindings.js +122 -0
  44. package/lib/browser/chat-tool-preference-bindings.js.map +1 -0
  45. package/lib/browser/chat-tool-request-service.d.ts +21 -0
  46. package/lib/browser/chat-tool-request-service.d.ts.map +1 -0
  47. package/lib/browser/chat-tool-request-service.js +90 -0
  48. package/lib/browser/chat-tool-request-service.js.map +1 -0
  49. package/lib/browser/context-file-validation-service.d.ts +15 -0
  50. package/lib/browser/context-file-validation-service.d.ts.map +1 -0
  51. package/lib/browser/context-file-validation-service.js +26 -0
  52. package/lib/browser/context-file-validation-service.js.map +1 -0
  53. package/lib/browser/context-file-variable-label-provider.d.ts +14 -0
  54. package/lib/browser/context-file-variable-label-provider.d.ts.map +1 -0
  55. package/lib/browser/context-file-variable-label-provider.js +63 -0
  56. package/lib/browser/context-file-variable-label-provider.js.map +1 -0
  57. package/lib/browser/context-variable-label-provider.d.ts +9 -0
  58. package/lib/browser/context-variable-label-provider.d.ts.map +1 -0
  59. package/lib/browser/context-variable-label-provider.js +55 -0
  60. package/lib/browser/context-variable-label-provider.js.map +1 -0
  61. package/lib/browser/custom-agent-factory.d.ts +4 -0
  62. package/lib/browser/custom-agent-factory.d.ts.map +1 -0
  63. package/lib/browser/custom-agent-factory.js +20 -0
  64. package/lib/browser/custom-agent-factory.js.map +1 -0
  65. package/lib/browser/custom-agent-frontend-application-contribution.d.ts +13 -0
  66. package/lib/browser/custom-agent-frontend-application-contribution.d.ts.map +1 -0
  67. package/lib/browser/custom-agent-frontend-application-contribution.js +83 -0
  68. package/lib/browser/custom-agent-frontend-application-contribution.js.map +1 -0
  69. package/lib/browser/delegation-response-content.d.ts +20 -0
  70. package/lib/browser/delegation-response-content.d.ts.map +1 -0
  71. package/lib/browser/delegation-response-content.js +47 -0
  72. package/lib/browser/delegation-response-content.js.map +1 -0
  73. package/lib/browser/file-chat-variable-contribution.d.ts +32 -0
  74. package/lib/browser/file-chat-variable-contribution.d.ts.map +1 -0
  75. package/lib/browser/file-chat-variable-contribution.js +241 -0
  76. package/lib/browser/file-chat-variable-contribution.js.map +1 -0
  77. package/lib/browser/frontend-chat-service.d.ts +15 -0
  78. package/lib/browser/frontend-chat-service.d.ts.map +1 -0
  79. package/lib/browser/frontend-chat-service.js +72 -0
  80. package/lib/browser/frontend-chat-service.js.map +1 -0
  81. package/lib/browser/image-context-variable-contribution.d.ts +27 -0
  82. package/lib/browser/image-context-variable-contribution.d.ts.map +1 -0
  83. package/lib/browser/image-context-variable-contribution.js +149 -0
  84. package/lib/browser/image-context-variable-contribution.js.map +1 -0
  85. package/lib/browser/task-context-service.d.ts +46 -0
  86. package/lib/browser/task-context-service.d.ts.map +1 -0
  87. package/lib/browser/task-context-service.js +256 -0
  88. package/lib/browser/task-context-service.js.map +1 -0
  89. package/lib/browser/task-context-storage-service.d.ts +19 -0
  90. package/lib/browser/task-context-storage-service.d.ts.map +1 -0
  91. package/lib/browser/task-context-storage-service.js +80 -0
  92. package/lib/browser/task-context-storage-service.js.map +1 -0
  93. package/lib/browser/task-context-variable-contribution.d.ts +20 -0
  94. package/lib/browser/task-context-variable-contribution.d.ts.map +1 -0
  95. package/lib/browser/task-context-variable-contribution.js +101 -0
  96. package/lib/browser/task-context-variable-contribution.js.map +1 -0
  97. package/lib/browser/task-context-variable-label-provider.d.ts +21 -0
  98. package/lib/browser/task-context-variable-label-provider.d.ts.map +1 -0
  99. package/lib/browser/task-context-variable-label-provider.js +83 -0
  100. package/lib/browser/task-context-variable-label-provider.js.map +1 -0
  101. package/lib/browser/task-context-variable.d.ts +3 -0
  102. package/lib/browser/task-context-variable.d.ts.map +1 -0
  103. package/lib/browser/task-context-variable.js +33 -0
  104. package/lib/browser/task-context-variable.js.map +1 -0
  105. package/lib/common/ai-chat-preferences.d.ts +5 -0
  106. package/lib/common/ai-chat-preferences.d.ts.map +1 -0
  107. package/lib/common/ai-chat-preferences.js +40 -0
  108. package/lib/common/ai-chat-preferences.js.map +1 -0
  109. package/lib/common/change-set-element-deserializer.d.ts +30 -0
  110. package/lib/common/change-set-element-deserializer.d.ts.map +1 -0
  111. package/lib/common/change-set-element-deserializer.js +81 -0
  112. package/lib/common/change-set-element-deserializer.js.map +1 -0
  113. package/lib/common/change-set.d.ts +85 -0
  114. package/lib/common/change-set.d.ts.map +1 -0
  115. package/lib/common/change-set.js +133 -0
  116. package/lib/common/change-set.js.map +1 -0
  117. package/lib/common/chat-agent-service.d.ts +46 -0
  118. package/lib/common/chat-agent-service.d.ts.map +1 -0
  119. package/lib/common/chat-agent-service.js +79 -0
  120. package/lib/common/chat-agent-service.js.map +1 -0
  121. package/lib/common/chat-agents-variable-contribution.d.ts +17 -0
  122. package/lib/common/chat-agents-variable-contribution.d.ts.map +1 -0
  123. package/lib/common/chat-agents-variable-contribution.js +67 -0
  124. package/lib/common/chat-agents-variable-contribution.js.map +1 -0
  125. package/lib/common/chat-agents.d.ts +138 -0
  126. package/lib/common/chat-agents.d.ts.map +1 -0
  127. package/lib/common/chat-agents.js +428 -0
  128. package/lib/common/chat-agents.js.map +1 -0
  129. package/lib/common/chat-auto-save.spec.d.ts +2 -0
  130. package/lib/common/chat-auto-save.spec.d.ts.map +1 -0
  131. package/lib/common/chat-auto-save.spec.js +304 -0
  132. package/lib/common/chat-auto-save.spec.js.map +1 -0
  133. package/lib/common/chat-content-deserializer.d.ts +161 -0
  134. package/lib/common/chat-content-deserializer.d.ts.map +1 -0
  135. package/lib/common/chat-content-deserializer.js +166 -0
  136. package/lib/common/chat-content-deserializer.js.map +1 -0
  137. package/lib/common/chat-content-deserializer.spec.d.ts +2 -0
  138. package/lib/common/chat-content-deserializer.spec.d.ts.map +1 -0
  139. package/lib/common/chat-content-deserializer.spec.js +307 -0
  140. package/lib/common/chat-content-deserializer.spec.js.map +1 -0
  141. package/lib/common/chat-model-serialization.d.ts +110 -0
  142. package/lib/common/chat-model-serialization.d.ts.map +1 -0
  143. package/lib/common/chat-model-serialization.js +20 -0
  144. package/lib/common/chat-model-serialization.js.map +1 -0
  145. package/lib/common/chat-model-serialization.spec.d.ts +2 -0
  146. package/lib/common/chat-model-serialization.spec.d.ts.map +1 -0
  147. package/lib/common/chat-model-serialization.spec.js +278 -0
  148. package/lib/common/chat-model-serialization.spec.js.map +1 -0
  149. package/lib/common/chat-model-util.d.ts +7 -0
  150. package/lib/common/chat-model-util.d.ts.map +1 -0
  151. package/lib/common/chat-model-util.js +50 -0
  152. package/lib/common/chat-model-util.js.map +1 -0
  153. package/lib/common/chat-model.d.ts +923 -0
  154. package/lib/common/chat-model.d.ts.map +1 -0
  155. package/lib/common/chat-model.js +1791 -0
  156. package/lib/common/chat-model.js.map +1 -0
  157. package/lib/common/chat-request-parser.d.ts +38 -0
  158. package/lib/common/chat-request-parser.d.ts.map +1 -0
  159. package/lib/common/chat-request-parser.js +230 -0
  160. package/lib/common/chat-request-parser.js.map +1 -0
  161. package/lib/common/chat-request-parser.spec.d.ts +2 -0
  162. package/lib/common/chat-request-parser.spec.d.ts.map +1 -0
  163. package/lib/common/chat-request-parser.spec.js +235 -0
  164. package/lib/common/chat-request-parser.spec.js.map +1 -0
  165. package/lib/common/chat-service-deletion.spec.d.ts +2 -0
  166. package/lib/common/chat-service-deletion.spec.d.ts.map +1 -0
  167. package/lib/common/chat-service-deletion.spec.js +221 -0
  168. package/lib/common/chat-service-deletion.spec.js.map +1 -0
  169. package/lib/common/chat-service.d.ts +153 -0
  170. package/lib/common/chat-service.d.ts.map +1 -0
  171. package/lib/common/chat-service.js +474 -0
  172. package/lib/common/chat-service.js.map +1 -0
  173. package/lib/common/chat-session-naming-prompt-template.d.ts +3 -0
  174. package/lib/common/chat-session-naming-prompt-template.d.ts.map +1 -0
  175. package/lib/common/chat-session-naming-prompt-template.js +31 -0
  176. package/lib/common/chat-session-naming-prompt-template.js.map +1 -0
  177. package/lib/common/chat-session-naming-service.d.ts +26 -0
  178. package/lib/common/chat-session-naming-service.d.ts.map +1 -0
  179. package/lib/common/chat-session-naming-service.js +119 -0
  180. package/lib/common/chat-session-naming-service.js.map +1 -0
  181. package/lib/common/chat-session-store.d.ts +43 -0
  182. package/lib/common/chat-session-store.d.ts.map +1 -0
  183. package/lib/common/chat-session-store.js +20 -0
  184. package/lib/common/chat-session-store.js.map +1 -0
  185. package/lib/common/chat-session-summary-agent-prompt.d.ts +8 -0
  186. package/lib/common/chat-session-summary-agent-prompt.d.ts.map +1 -0
  187. package/lib/common/chat-session-summary-agent-prompt.js +33 -0
  188. package/lib/common/chat-session-summary-agent-prompt.js.map +1 -0
  189. package/lib/common/chat-session-summary-agent.d.ts +16 -0
  190. package/lib/common/chat-session-summary-agent.d.ts.map +1 -0
  191. package/lib/common/chat-session-summary-agent.js +48 -0
  192. package/lib/common/chat-session-summary-agent.js.map +1 -0
  193. package/lib/common/chat-string-utils.d.ts +3 -0
  194. package/lib/common/chat-string-utils.d.ts.map +1 -0
  195. package/lib/common/chat-string-utils.js +27 -0
  196. package/lib/common/chat-string-utils.js.map +1 -0
  197. package/lib/common/chat-tool-preferences.d.ts +23 -0
  198. package/lib/common/chat-tool-preferences.d.ts.map +1 -0
  199. package/lib/common/chat-tool-preferences.js +68 -0
  200. package/lib/common/chat-tool-preferences.js.map +1 -0
  201. package/lib/common/chat-tool-request-service.d.ts +18 -0
  202. package/lib/common/chat-tool-request-service.d.ts.map +1 -0
  203. package/lib/common/chat-tool-request-service.js +52 -0
  204. package/lib/common/chat-tool-request-service.js.map +1 -0
  205. package/lib/common/context-details-variable.d.ts +9 -0
  206. package/lib/common/context-details-variable.d.ts.map +1 -0
  207. package/lib/common/context-details-variable.js +57 -0
  208. package/lib/common/context-details-variable.js.map +1 -0
  209. package/lib/common/context-summary-variable.d.ts +9 -0
  210. package/lib/common/context-summary-variable.d.ts.map +1 -0
  211. package/lib/common/context-summary-variable.js +57 -0
  212. package/lib/common/context-summary-variable.js.map +1 -0
  213. package/lib/common/context-variables.d.ts +4 -0
  214. package/lib/common/context-variables.d.ts.map +1 -0
  215. package/lib/common/context-variables.js +22 -0
  216. package/lib/common/context-variables.js.map +1 -0
  217. package/lib/common/custom-chat-agent.d.ts +10 -0
  218. package/lib/common/custom-chat-agent.d.ts.map +1 -0
  219. package/lib/common/custom-chat-agent.js +40 -0
  220. package/lib/common/custom-chat-agent.js.map +1 -0
  221. package/lib/common/image-context-variable.d.ts +29 -0
  222. package/lib/common/image-context-variable.d.ts.map +1 -0
  223. package/lib/common/image-context-variable.js +114 -0
  224. package/lib/common/image-context-variable.js.map +1 -0
  225. package/lib/common/index.d.ts +13 -0
  226. package/lib/common/index.d.ts.map +1 -0
  227. package/lib/common/index.js +31 -0
  228. package/lib/common/index.js.map +1 -0
  229. package/lib/common/parse-contents-with-incomplete-parts.spec.d.ts +2 -0
  230. package/lib/common/parse-contents-with-incomplete-parts.spec.d.ts.map +1 -0
  231. package/lib/common/parse-contents-with-incomplete-parts.spec.js +103 -0
  232. package/lib/common/parse-contents-with-incomplete-parts.spec.js.map +1 -0
  233. package/lib/common/parse-contents.d.ts +12 -0
  234. package/lib/common/parse-contents.d.ts.map +1 -0
  235. package/lib/common/parse-contents.js +107 -0
  236. package/lib/common/parse-contents.js.map +1 -0
  237. package/lib/common/parse-contents.spec.d.ts +10 -0
  238. package/lib/common/parse-contents.spec.d.ts.map +1 -0
  239. package/lib/common/parse-contents.spec.js +146 -0
  240. package/lib/common/parse-contents.spec.js.map +1 -0
  241. package/lib/common/parsed-chat-request.d.ts +66 -0
  242. package/lib/common/parsed-chat-request.d.ts.map +1 -0
  243. package/lib/common/parsed-chat-request.js +83 -0
  244. package/lib/common/parsed-chat-request.js.map +1 -0
  245. package/lib/common/response-content-matcher.d.ts +69 -0
  246. package/lib/common/response-content-matcher.d.ts.map +1 -0
  247. package/lib/common/response-content-matcher.js +97 -0
  248. package/lib/common/response-content-matcher.js.map +1 -0
  249. package/lib/node/ai-chat-backend-module.d.ts +4 -0
  250. package/lib/node/ai-chat-backend-module.d.ts.map +1 -0
  251. package/lib/node/ai-chat-backend-module.js +26 -0
  252. package/lib/node/ai-chat-backend-module.js.map +1 -0
  253. package/package.json +9 -9
@@ -0,0 +1,107 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.findFirstMatch = exports.parseContents = void 0;
4
+ const response_content_matcher_1 = require("./response-content-matcher");
5
+ function parseContents(text, request, contentMatchers = [response_content_matcher_1.CodeContentMatcher], defaultContentFactory = response_content_matcher_1.MarkdownContentFactory) {
6
+ const result = [];
7
+ let currentIndex = 0;
8
+ while (currentIndex < text.length) {
9
+ const remainingText = text.substring(currentIndex);
10
+ const match = findFirstMatch(contentMatchers, remainingText);
11
+ if (!match) {
12
+ // Add the remaining text as default content
13
+ if (remainingText.length > 0) {
14
+ result.push(defaultContentFactory(remainingText, request));
15
+ }
16
+ break;
17
+ }
18
+ // We have a match
19
+ // 1. Add preceding text as default content
20
+ if (match.index > 0) {
21
+ const precedingContent = remainingText.substring(0, match.index);
22
+ if (precedingContent.trim().length > 0) {
23
+ result.push(defaultContentFactory(precedingContent, request));
24
+ }
25
+ }
26
+ // 2. Add the matched content object
27
+ if (match.isComplete) {
28
+ // Complete match, use regular content factory
29
+ result.push(match.matcher.contentFactory(match.content, request));
30
+ }
31
+ else if (match.matcher.incompleteContentFactory) {
32
+ // Incomplete match with an incomplete content factory available
33
+ result.push(match.matcher.incompleteContentFactory(match.content, request));
34
+ }
35
+ else {
36
+ // Incomplete match but no incomplete content factory available, use default
37
+ result.push(defaultContentFactory(match.content, request));
38
+ }
39
+ // Update currentIndex to the end of the end of the match
40
+ // And continue with the search after the end of the match
41
+ currentIndex += match.index + match.content.length;
42
+ }
43
+ return result;
44
+ }
45
+ exports.parseContents = parseContents;
46
+ function findFirstMatch(contentMatchers, text) {
47
+ let firstMatch;
48
+ let firstIncompleteMatch;
49
+ for (const matcher of contentMatchers) {
50
+ const startMatch = matcher.start.exec(text);
51
+ if (!startMatch) {
52
+ // No start match found, try next matcher.
53
+ continue;
54
+ }
55
+ const endOfStartMatch = startMatch.index + startMatch[0].length;
56
+ if (endOfStartMatch >= text.length) {
57
+ // There is no text after the start match.
58
+ // This is an incomplete match if the matcher has an incompleteContentFactory
59
+ if (matcher.incompleteContentFactory) {
60
+ const incompleteMatch = {
61
+ matcher,
62
+ index: startMatch.index,
63
+ content: text.substring(startMatch.index),
64
+ isComplete: false
65
+ };
66
+ if (!firstIncompleteMatch || incompleteMatch.index < firstIncompleteMatch.index) {
67
+ firstIncompleteMatch = incompleteMatch;
68
+ }
69
+ }
70
+ continue;
71
+ }
72
+ const remainingTextAfterStartMatch = text.substring(endOfStartMatch);
73
+ const endMatch = matcher.end.exec(remainingTextAfterStartMatch);
74
+ if (!endMatch) {
75
+ // No end match found, this is an incomplete match
76
+ if (matcher.incompleteContentFactory) {
77
+ const incompleteMatch = {
78
+ matcher,
79
+ index: startMatch.index,
80
+ content: text.substring(startMatch.index),
81
+ isComplete: false
82
+ };
83
+ if (!firstIncompleteMatch || incompleteMatch.index < firstIncompleteMatch.index) {
84
+ firstIncompleteMatch = incompleteMatch;
85
+ }
86
+ }
87
+ continue;
88
+ }
89
+ // Found start and end match.
90
+ // Record the full match, if it is the earliest found so far.
91
+ const index = startMatch.index;
92
+ const contentEnd = index + startMatch[0].length + endMatch.index + endMatch[0].length;
93
+ const content = text.substring(index, contentEnd);
94
+ const completeMatch = { matcher, index, content, isComplete: true };
95
+ if (!firstMatch || index < firstMatch.index) {
96
+ firstMatch = completeMatch;
97
+ }
98
+ }
99
+ // If we found a complete match, return it
100
+ if (firstMatch) {
101
+ return firstMatch;
102
+ }
103
+ // Otherwise, return the first incomplete match if one exists
104
+ return firstIncompleteMatch;
105
+ }
106
+ exports.findFirstMatch = findFirstMatch;
107
+ //# sourceMappingURL=parse-contents.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parse-contents.js","sourceRoot":"","sources":["../../src/common/parse-contents.ts"],"names":[],"mappings":";;;AAgBA,yEAAwI;AASxI,SAAgB,aAAa,CACzB,IAAY,EACZ,OAAgC,EAChC,kBAA4C,CAAC,6CAAkB,CAAC,EAChE,wBAAgD,iDAAsB;IAEtE,MAAM,MAAM,GAA0B,EAAE,CAAC;IAEzC,IAAI,YAAY,GAAG,CAAC,CAAC;IACrB,OAAO,YAAY,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC;QAChC,MAAM,aAAa,GAAG,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC,CAAC;QACnD,MAAM,KAAK,GAAG,cAAc,CAAC,eAAe,EAAE,aAAa,CAAC,CAAC;QAC7D,IAAI,CAAC,KAAK,EAAE,CAAC;YACT,4CAA4C;YAC5C,IAAI,aAAa,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBAC3B,MAAM,CAAC,IAAI,CAAC,qBAAqB,CAAC,aAAa,EAAE,OAAO,CAAC,CAAC,CAAC;YAC/D,CAAC;YACD,MAAM;QACV,CAAC;QACD,kBAAkB;QAClB,2CAA2C;QAC3C,IAAI,KAAK,CAAC,KAAK,GAAG,CAAC,EAAE,CAAC;YAClB,MAAM,gBAAgB,GAAG,aAAa,CAAC,SAAS,CAAC,CAAC,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC;YACjE,IAAI,gBAAgB,CAAC,IAAI,EAAE,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBACrC,MAAM,C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AAC,CAAC,MAAM,CAAC;QACtF,MAAM,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,UAAU,CAAC,CAAC;QAClD,MAAM,aAAa,GAAU,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC;QAE3E,IAAI,CAAC,UAAU,IAAI,KAAK,GAAG,UAAU,CAAC,KAAK,EAAE,CAAC;YAC1C,UAAU,GAAG,aAAa,CAAC;QAC/B,CAAC;IACL,CAAC;IAED,0CAA0C;IAC1C,IAAI,UAAU,EAAE,CAAC;QACb,OAAO,UAAU,CAAC;IACtB,CAAC;IAED,6DAA6D;IAC7D,OAAO,oBAAoB,CAAC;AAChC,CAAC;AAlED,wCAkEC"}
@@ -0,0 +1,10 @@
1
+ import { ChatResponseContent } from './chat-model';
2
+ import { ResponseContentMatcher } from './response-content-matcher';
3
+ export declare const TestCodeContentMatcher: ResponseContentMatcher;
4
+ export declare class CommandChatResponseContentImpl implements ChatResponseContent {
5
+ readonly command: string;
6
+ constructor(command: string);
7
+ kind: string;
8
+ }
9
+ export declare const CommandContentMatcher: ResponseContentMatcher;
10
+ //# sourceMappingURL=parse-contents.spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parse-contents.spec.d.ts","sourceRoot":"","sources":["../../src/common/parse-contents.spec.ts"],"names":[],"mappings":"AAiBA,OAAO,EAA2B,mBAAmB,EAAgE,MAAM,cAAc,CAAC;AAE1I,OAAO,EAAsB,sBAAsB,EAAE,MAAM,4BAA4B,CAAC;AAExF,eAAO,MAAM,sBAAsB,EAAE,sBAQpC,CAAC;AAEF,qBAAa,8BAA+B,YAAW,mBAAmB;aAC1C,OAAO,EAAE,MAAM;gBAAf,OAAO,EAAE,MAAM;IAC3C,IAAI,SAAa;CACpB;AAED,eAAO,MAAM,qBAAqB,EAAE,sBAOnC,CAAC"}
@@ -0,0 +1,146 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.CommandContentMatcher = exports.CommandChatResponseContentImpl = exports.TestCodeContentMatcher = void 0;
19
+ const chai_1 = require("chai");
20
+ const chat_model_1 = require("./chat-model");
21
+ const parse_contents_1 = require("./parse-contents");
22
+ const response_content_matcher_1 = require("./response-content-matcher");
23
+ exports.TestCodeContentMatcher = {
24
+ start: /^```.*?$/m,
25
+ end: /^```$/m,
26
+ contentFactory: (content) => {
27
+ var _a;
28
+ const language = ((_a = content.match(/^```(\w+)/)) === null || _a === void 0 ? void 0 : _a[1]) || '';
29
+ const code = content.replace(/^```(\w+)\n|```$/g, '');
30
+ return new chat_model_1.CodeChatResponseContentImpl(code.trim(), language);
31
+ }
32
+ };
33
+ class CommandChatResponseContentImpl {
34
+ constructor(command) {
35
+ this.command = command;
36
+ this.kind = 'command';
37
+ }
38
+ }
39
+ exports.CommandChatResponseContentImpl = CommandChatResponseContentImpl;
40
+ exports.CommandContentMatcher = {
41
+ start: /^<command>$/m,
42
+ end: /^<\/command>$/m,
43
+ contentFactory: (content) => {
44
+ const code = content.replace(/^<command>\n|<\/command>$/g, '');
45
+ return new CommandChatResponseContentImpl(code.trim());
46
+ }
47
+ };
48
+ const fakeRequest = {};
49
+ describe('parseContents', () => {
50
+ it('should parse code content', () => {
51
+ const text = '```typescript\nconsole.log("Hello World");\n```';
52
+ const result = (0, parse_contents_1.parseContents)(text, fakeRequest, [exports.TestCodeContentMatcher]);
53
+ (0, chai_1.expect)(result).to.deep.equal([new chat_model_1.CodeChatResponseContentImpl('console.log("Hello World");', 'typescript')]);
54
+ });
55
+ it('should parse markdown content', () => {
56
+ const text = 'Hello **World**';
57
+ const result = (0, parse_contents_1.parseContents)(text, fakeRequest, [exports.TestCodeContentMatcher]);
58
+ (0, chai_1.expect)(result).to.deep.equal([new chat_model_1.MarkdownChatResponseContentImpl('Hello **World**')]);
59
+ });
60
+ it('should parse multiple content blocks', () => {
61
+ const text = '```typescript\nconsole.log("Hello World");\n```\nHello **World**';
62
+ const result = (0, parse_contents_1.parseContents)(text, fakeRequest, [exports.TestCodeContentMatcher]);
63
+ (0, chai_1.expect)(result).to.deep.equal([
64
+ new chat_model_1.CodeChatResponseContentImpl('console.log("Hello World");', 'typescript'),
65
+ new chat_model_1.MarkdownChatResponseContentImpl('\nHello **World**')
66
+ ]);
67
+ });
68
+ it('should parse multiple content blocks with different languages', () => {
69
+ const text = '```typescript\nconsole.log("Hello World");\n```\n```python\nprint("Hello World")\n```';
70
+ const result = (0, parse_contents_1.parseContents)(text, fakeRequest, [exports.TestCodeContentMatcher]);
71
+ (0, chai_1.expect)(result).to.deep.equal([
72
+ new chat_model_1.CodeChatResponseContentImpl('console.log("Hello World");', 'typescript'),
73
+ new chat_model_1.CodeChatResponseContentImpl('print("Hello World")', 'python')
74
+ ]);
75
+ });
76
+ it('should parse multiple content blocks with different languages and markdown', () => {
77
+ const text = '```typescript\nconsole.log("Hello World");\n```\nHello **World**\n```python\nprint("Hello World")\n```';
78
+ const result = (0, parse_contents_1.parseContents)(text, fakeRequest, [exports.TestCodeContentMatcher]);
79
+ (0, chai_1.expect)(result).to.deep.equal([
80
+ new chat_model_1.CodeChatResponseContentImpl('console.log("Hello World");', 'typescript'),
81
+ new chat_model_1.MarkdownChatResponseContentImpl('\nHello **World**\n'),
82
+ new chat_model_1.CodeChatResponseContentImpl('print("Hello World")', 'python')
83
+ ]);
84
+ });
85
+ it('should parse content blocks with empty content', () => {
86
+ const text = '```typescript\n```\nHello **World**\n```python\nprint("Hello World")\n```';
87
+ const result = (0, parse_contents_1.parseContents)(text, fakeRequest, [exports.TestCodeContentMatcher]);
88
+ (0, chai_1.expect)(result).to.deep.equal([
89
+ new chat_model_1.CodeChatResponseContentImpl('', 'typescript'),
90
+ new chat_model_1.MarkdownChatResponseContentImpl('\nHello **World**\n'),
91
+ new chat_model_1.CodeChatResponseContentImpl('print("Hello World")', 'python')
92
+ ]);
93
+ });
94
+ it('should parse content with markdown, code, and markdown', () => {
95
+ const text = 'Hello **World**\n```typescript\nconsole.log("Hello World");\n```\nGoodbye **World**';
96
+ const result = (0, parse_contents_1.parseContents)(text, fakeRequest, [exports.TestCodeContentMatcher]);
97
+ (0, chai_1.expect)(result).to.deep.equal([
98
+ new chat_model_1.MarkdownChatResponseContentImpl('Hello **World**\n'),
99
+ new chat_model_1.CodeChatResponseContentImpl('console.log("Hello World");', 'typescript'),
100
+ new chat_model_1.MarkdownChatResponseContentImpl('\nGoodbye **World**')
101
+ ]);
102
+ });
103
+ it('should handle text with no special content', () => {
104
+ const text = 'Just some plain text.';
105
+ const result = (0, parse_contents_1.parseContents)(text, fakeRequest, [exports.TestCodeContentMatcher]);
106
+ (0, chai_1.expect)(result).to.deep.equal([new chat_model_1.MarkdownChatResponseContentImpl('Just some plain text.')]);
107
+ });
108
+ it('should handle text with only start code block', () => {
109
+ const text = '```typescript\nconsole.log("Hello World");';
110
+ // We're using the standard CodeContentMatcher which has incompleteContentFactory
111
+ const result = (0, parse_contents_1.parseContents)(text, fakeRequest);
112
+ (0, chai_1.expect)(result).to.deep.equal([new chat_model_1.CodeChatResponseContentImpl('console.log("Hello World");', 'typescript')]);
113
+ });
114
+ it('should handle text with only end code block', () => {
115
+ const text = 'console.log("Hello World");\n```';
116
+ const result = (0, parse_contents_1.parseContents)(text, fakeRequest, [exports.TestCodeContentMatcher]);
117
+ (0, chai_1.expect)(result).to.deep.equal([new chat_model_1.MarkdownChatResponseContentImpl('console.log("Hello World");\n```')]);
118
+ });
119
+ it('should handle text with unmatched code block', () => {
120
+ const text = '```typescript\nconsole.log("Hello World");\n```\n```python\nprint("Hello World")';
121
+ // We're using the standard CodeContentMatcher which has incompleteContentFactory
122
+ const result = (0, parse_contents_1.parseContents)(text, fakeRequest);
123
+ (0, chai_1.expect)(result).to.deep.equal([
124
+ new chat_model_1.CodeChatResponseContentImpl('console.log("Hello World");', 'typescript'),
125
+ new chat_model_1.CodeChatResponseContentImpl('print("Hello World")', 'python')
126
+ ]);
127
+ });
128
+ it('should parse code block without newline after language', () => {
129
+ const text = '```typescript console.log("Hello World");```';
130
+ const result = (0, parse_contents_1.parseContents)(text, fakeRequest, [exports.TestCodeContentMatcher]);
131
+ (0, chai_1.expect)(result).to.deep.equal([
132
+ new chat_model_1.MarkdownChatResponseContentImpl('```typescript console.log("Hello World");```')
133
+ ]);
134
+ });
135
+ it('should parse with matches of multiple different matchers and default', () => {
136
+ const text = '<command>\nMY_SPECIAL_COMMAND\n</command>\nHello **World**\n```python\nprint("Hello World")\n```\n<command>\nMY_SPECIAL_COMMAND2\n</command>';
137
+ const result = (0, parse_contents_1.parseContents)(text, fakeRequest, [response_content_matcher_1.CodeContentMatcher, exports.CommandContentMatcher]);
138
+ (0, chai_1.expect)(result).to.deep.equal([
139
+ new CommandChatResponseContentImpl('MY_SPECIAL_COMMAND'),
140
+ new chat_model_1.MarkdownChatResponseContentImpl('\nHello **World**\n'),
141
+ new chat_model_1.CodeChatResponseContentImpl('print("Hello World")', 'python'),
142
+ new CommandChatResponseContentImpl('MY_SPECIAL_COMMAND2'),
143
+ ]);
144
+ });
145
+ });
146
+ //# sourceMappingURL=parse-contents.spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parse-contents.spec.js","sourceRoot":"","sources":["../../src/common/parse-contents.spec.ts"],"names":[],"mappings":";AAAA,gFAAgF;AAChF,yCAAyC;AACzC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AAC,qBAAqB,CAAC;YAC1D,IAAI,wCAA2B,CAAC,sBAAsB,EAAE,QAAQ,CAAC;YACjE,IAAI,8BAA8B,CAAC,qBAAqB,CAAC;SAC5D,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}
@@ -0,0 +1,66 @@
1
+ import { ResolvedAIVariable, ToolRequest } from '@theia/ai-core';
2
+ import { ChatRequest } from './chat-model';
3
+ export declare const chatVariableLeader = "#";
4
+ export declare const chatAgentLeader = "@";
5
+ export declare const chatFunctionLeader = "~";
6
+ export declare const chatSubcommandLeader = "/";
7
+ /**********************
8
+ * INTERFACES AND TYPE GUARDS
9
+ **********************/
10
+ export interface OffsetRange {
11
+ readonly start: number;
12
+ readonly endExclusive: number;
13
+ }
14
+ export interface ParsedChatRequest {
15
+ readonly request: ChatRequest;
16
+ readonly parts: ParsedChatRequestPart[];
17
+ readonly toolRequests: Map<string, ToolRequest>;
18
+ readonly variables: ResolvedAIVariable[];
19
+ }
20
+ export interface ParsedChatRequestPart {
21
+ readonly kind: string;
22
+ /**
23
+ * The text as represented in the ChatRequest
24
+ */
25
+ readonly text: string;
26
+ /**
27
+ * The text as will be sent to the LLM
28
+ */
29
+ readonly promptText: string;
30
+ readonly range: OffsetRange;
31
+ }
32
+ export declare class ParsedChatRequestTextPart implements ParsedChatRequestPart {
33
+ readonly range: OffsetRange;
34
+ readonly text: string;
35
+ readonly kind: 'text';
36
+ constructor(range: OffsetRange, text: string);
37
+ get promptText(): string;
38
+ }
39
+ export declare class ParsedChatRequestVariablePart implements ParsedChatRequestPart {
40
+ readonly range: OffsetRange;
41
+ readonly variableName: string;
42
+ readonly variableArg: string | undefined;
43
+ readonly kind: 'var';
44
+ resolution: ResolvedAIVariable;
45
+ constructor(range: OffsetRange, variableName: string, variableArg: string | undefined);
46
+ get text(): string;
47
+ get promptText(): string;
48
+ }
49
+ export declare class ParsedChatRequestFunctionPart implements ParsedChatRequestPart {
50
+ readonly range: OffsetRange;
51
+ readonly toolRequest: ToolRequest;
52
+ readonly kind: 'function';
53
+ constructor(range: OffsetRange, toolRequest: ToolRequest);
54
+ get text(): string;
55
+ get promptText(): string;
56
+ }
57
+ export declare class ParsedChatRequestAgentPart implements ParsedChatRequestPart {
58
+ readonly range: OffsetRange;
59
+ readonly agentId: string;
60
+ readonly agentName: string;
61
+ readonly kind: 'agent';
62
+ constructor(range: OffsetRange, agentId: string, agentName: string);
63
+ get text(): string;
64
+ get promptText(): string;
65
+ }
66
+ //# sourceMappingURL=parsed-chat-request.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parsed-chat-request.d.ts","sourceRoot":"","sources":["../../src/common/parsed-chat-request.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAE,kBAAkB,EAAE,WAAW,EAA2B,MAAM,gBAAgB,CAAC;AAC1F,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAE3C,eAAO,MAAM,kBAAkB,MAAM,CAAC;AACtC,eAAO,MAAM,eAAe,MAAM,CAAC;AACnC,eAAO,MAAM,kBAAkB,MAAM,CAAC;AACtC,eAAO,MAAM,oBAAoB,MAAM,CAAC;AAExC;;wBAEwB;AAExB,MAAM,WAAW,WAAW;IACxB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;CACjC;AAED,MAAM,WAAW,iBAAiB;IAC9B,QAAQ,CAAC,OAAO,EAAE,WAAW,CAAC;IAC9B,QAAQ,CAAC,KAAK,EAAE,qBAAqB,EAAE,CAAC;IACxC,QAAQ,CAAC,YAAY,EAAE,GAAG,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;IAChD,QAAQ,CAAC,SAAS,EAAE,kBAAkB,EAAE,CAAC;CAC5C;AAED,MAAM,WAAW,qBAAqB;IAClC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB;;OAEG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACt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BACF,KAAK,EAAE,WAAW,EAAW,OAAO,EAAE,MAAM,EAAW,SAAS,EAAE,MAAM;IAE7F,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED,IAAI,UAAU,IAAI,MAAM,CAEvB;CACJ"}
@@ -0,0 +1,83 @@
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/chatParserTypes.ts
22
+ // Partially copied from https://github.com/microsoft/vscode/blob/a2cab7255c0df424027be05d58e1b7b941f4ea60/src/vs/editor/common/core/offsetRange.ts
23
+ Object.defineProperty(exports, "__esModule", { value: true });
24
+ exports.ParsedChatRequestAgentPart = exports.ParsedChatRequestFunctionPart = exports.ParsedChatRequestVariablePart = exports.ParsedChatRequestTextPart = exports.chatSubcommandLeader = exports.chatFunctionLeader = exports.chatAgentLeader = exports.chatVariableLeader = void 0;
25
+ const ai_core_1 = require("@theia/ai-core");
26
+ exports.chatVariableLeader = '#';
27
+ exports.chatAgentLeader = '@';
28
+ exports.chatFunctionLeader = '~';
29
+ exports.chatSubcommandLeader = '/';
30
+ class ParsedChatRequestTextPart {
31
+ constructor(range, text) {
32
+ this.range = range;
33
+ this.text = text;
34
+ }
35
+ get promptText() {
36
+ return this.text;
37
+ }
38
+ }
39
+ exports.ParsedChatRequestTextPart = ParsedChatRequestTextPart;
40
+ class ParsedChatRequestVariablePart {
41
+ constructor(range, variableName, variableArg) {
42
+ this.range = range;
43
+ this.variableName = variableName;
44
+ this.variableArg = variableArg;
45
+ }
46
+ get text() {
47
+ const argPart = this.variableArg ? `:${this.variableArg}` : '';
48
+ return `${exports.chatVariableLeader}${this.variableName}${argPart}`;
49
+ }
50
+ get promptText() {
51
+ var _a, _b;
52
+ return (_b = (_a = this.resolution) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : this.text;
53
+ }
54
+ }
55
+ exports.ParsedChatRequestVariablePart = ParsedChatRequestVariablePart;
56
+ class ParsedChatRequestFunctionPart {
57
+ constructor(range, toolRequest) {
58
+ this.range = range;
59
+ this.toolRequest = toolRequest;
60
+ }
61
+ get text() {
62
+ return `${exports.chatFunctionLeader}${this.toolRequest.id}`;
63
+ }
64
+ get promptText() {
65
+ return (0, ai_core_1.toolRequestToPromptText)(this.toolRequest);
66
+ }
67
+ }
68
+ exports.ParsedChatRequestFunctionPart = ParsedChatRequestFunctionPart;
69
+ class ParsedChatRequestAgentPart {
70
+ constructor(range, agentId, agentName) {
71
+ this.range = range;
72
+ this.agentId = agentId;
73
+ this.agentName = agentName;
74
+ }
75
+ get text() {
76
+ return `${exports.chatAgentLeader}${this.agentName}`;
77
+ }
78
+ get promptText() {
79
+ return '';
80
+ }
81
+ }
82
+ exports.ParsedChatRequestAgentPart = ParsedChatRequestAgentPart;
83
+ //# sourceMappingURL=parsed-chat-request.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parsed-chat-request.js","sourceRoot":"","sources":["../../src/common/parsed-chat-request.ts"],"names":[],"mappings":";AAAA,gFAAgF;AAChF,yCAAyC;AACzC,EAAE;AACF,2EAA2E;AAC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AAW,CAAa;IAAI,CAAC;IAE/E,IAAI,IAAI;QACJ,OAAO,GAAG,0BAAkB,GAAG,IAAI,CAAC,WAAW,CAAC,EAAE,EAAE,CAAC;IACzD,CAAC;IAED,IAAI,UAAU;QACV,OAAO,IAAA,iCAAuB,EAAC,IAAI,CAAC,WAAW,CAAC,CAAC;IACrD,CAAC;CACJ;AAXD,sEAWC;AAED,MAAa,0BAA0B;IAEnC,YAAqB,KAAkB,EAAW,OAAe,EAAW,SAAiB;QAAxE,UAAK,GAAL,KAAK,CAAa;QAAW,YAAO,GAAP,OAAO,CAAQ;QAAW,cAAS,GAAT,SAAS,CAAQ;IAAI,CAAC;IAElG,IAAI,IAAI;QACJ,OAAO,GAAG,uBAAe,GAAG,IAAI,CAAC,SAAS,EAAE,CAAC;IACjD,CAAC;IAED,IAAI,UAAU;QACV,OAAO,EAAE,CAAC;IACd,CAAC;CACJ;AAXD,gEAWC"}
@@ -0,0 +1,69 @@
1
+ import { MutableChatRequestModel, ChatResponseContent } from './chat-model';
2
+ export type ResponseContentFactory = (content: string, request: MutableChatRequestModel) => ChatResponseContent;
3
+ export declare const MarkdownContentFactory: ResponseContentFactory;
4
+ /**
5
+ * Default response content factory used if no other `ResponseContentMatcher` applies.
6
+ * By default, this factory creates a markdown content object.
7
+ *
8
+ * @see MarkdownChatResponseContentImpl
9
+ */
10
+ export declare class DefaultResponseContentFactory {
11
+ create(content: string, request: MutableChatRequestModel): ChatResponseContent;
12
+ }
13
+ /**
14
+ * Clients can contribute response content matchers to parse a chat response into specific
15
+ * `ChatResponseContent` instances.
16
+ */
17
+ export interface ResponseContentMatcher {
18
+ /** Regular expression for finding the start delimiter. */
19
+ start: RegExp;
20
+ /** Regular expression for finding the start delimiter. */
21
+ end: RegExp;
22
+ /**
23
+ * The factory creating a response content from the matching content,
24
+ * from start index to end index of the match (including delimiters).
25
+ */
26
+ contentFactory: ResponseContentFactory;
27
+ /**
28
+ * Optional factory for creating a response content when only the start delimiter has been matched,
29
+ * but not yet the end delimiter. Used during streaming to provide better visual feedback.
30
+ * If not provided, the default content factory will be used until the end delimiter is matched.
31
+ */
32
+ incompleteContentFactory?: ResponseContentFactory;
33
+ }
34
+ export declare const CodeContentMatcher: ResponseContentMatcher;
35
+ /**
36
+ * Clients can contribute response content matchers to parse the response content.
37
+ *
38
+ * The default chat user interface will collect all contributed matchers and use them
39
+ * to parse the response into structured content parts (e.g. code blocks, markdown blocks),
40
+ * which are then rendered with a `ChatResponsePartRenderer` registered for the respective
41
+ * content part type.
42
+ *
43
+ * ### Example
44
+ * ```ts
45
+ * bind(ResponseContentMatcherProvider).to(MyResponseContentMatcherProvider);
46
+ * ...
47
+ * @injectable()
48
+ * export class MyResponseContentMatcherProvider implements ResponseContentMatcherProvider {
49
+ * readonly matchers: ResponseContentMatcher[] = [{
50
+ * start: /^<command>$/m,
51
+ * end: /^</command>$/m,
52
+ * contentFactory: (content: string) => {
53
+ * const command = content.replace(/^<command>\n|<\/command>$/g, '');
54
+ * return new MyChatResponseContentImpl(command.trim());
55
+ * }
56
+ * }];
57
+ * }
58
+ * ```
59
+ *
60
+ * @see ResponseContentMatcher
61
+ */
62
+ export declare const ResponseContentMatcherProvider: unique symbol;
63
+ export interface ResponseContentMatcherProvider {
64
+ readonly matchers: ResponseContentMatcher[];
65
+ }
66
+ export declare class DefaultResponseContentMatcherProvider implements ResponseContentMatcherProvider {
67
+ readonly matchers: ResponseContentMatcher[];
68
+ }
69
+ //# sourceMappingURL=response-content-matcher.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"response-content-matcher.d.ts","sourceRoot":"","sources":["../../src/common/response-content-matcher.ts"],"names":[],"mappings":"AAeA,OAAO,EACH,uBAAuB,EACvB,mBAAmB,EAGtB,MAAM,cAAc,CAAC;AAGtB,MAAM,MAAM,sBAAsB,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,uBAAuB,KAAK,mBAAmB,CAAC;AAEhH,eAAO,MAAM,sBAAsB,EAAE,sBACW,CAAC;AAEjD;;;;;GAKG;AACH,qBACa,6BAA6B;IACtC,MAAM,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,uBAAuB,GAAG,mBAAmB;CAGjF;AAED;;;GAGG;AACH,MAAM,WAAW,sBAAsB;IACnC,0DAA0D;IAC1D,KAAK,EAAE,MAAM,CAAC;IACd,0DAA0D;IAC1D,GAAG,EAAE,MAAM,CAAC;IACZ;;;OAGG;IACH,cAAc,EAAE,sBAAsB,CAAC;IACvC;;;;OAIG;IACH,wBAAwB,CAAC,EAAE,sBAAsB,CAAC;CACrD;AAED,eAAO,MAAM,kBAAkB,EAAE,sBAoBhC,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,eAAO,MAAM,8BAA8B,eAA2C,CAAC;AACvF,MAAM,WAAW,8BAA8B;IAC3C,QAAQ,CAAC,QAAQ,EAAE,sBAAsB,EAAE,CAAC;CAC/C;AAED,qBACa,qCAAsC,YAAW,8BAA8B;IACxF,QAAQ,CAAC,QAAQ,EAAE,sBAAsB,EAAE,CAAwB;CACtE"}
@@ -0,0 +1,97 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DefaultResponseContentMatcherProvider = exports.ResponseContentMatcherProvider = exports.CodeContentMatcher = exports.DefaultResponseContentFactory = exports.MarkdownContentFactory = 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 chat_model_1 = require("./chat-model");
21
+ const inversify_1 = require("@theia/core/shared/inversify");
22
+ const MarkdownContentFactory = (content, request) => new chat_model_1.MarkdownChatResponseContentImpl(content);
23
+ exports.MarkdownContentFactory = MarkdownContentFactory;
24
+ /**
25
+ * Default response content factory used if no other `ResponseContentMatcher` applies.
26
+ * By default, this factory creates a markdown content object.
27
+ *
28
+ * @see MarkdownChatResponseContentImpl
29
+ */
30
+ let DefaultResponseContentFactory = class DefaultResponseContentFactory {
31
+ create(content, request) {
32
+ return (0, exports.MarkdownContentFactory)(content, request);
33
+ }
34
+ };
35
+ exports.DefaultResponseContentFactory = DefaultResponseContentFactory;
36
+ exports.DefaultResponseContentFactory = DefaultResponseContentFactory = tslib_1.__decorate([
37
+ (0, inversify_1.injectable)()
38
+ ], DefaultResponseContentFactory);
39
+ exports.CodeContentMatcher = {
40
+ // Only match when we have the complete first line ending with a newline
41
+ // This ensures we have the full language specification before creating the editor
42
+ start: /^```.*\n/m,
43
+ end: /^```$/m,
44
+ contentFactory: (content, request) => {
45
+ var _a;
46
+ const language = ((_a = content.match(/^```(\w+)/)) === null || _a === void 0 ? void 0 : _a[1]) || '';
47
+ const code = content.replace(/^```(\w+)\n|```$/g, '');
48
+ return new chat_model_1.CodeChatResponseContentImpl(code.trim(), language);
49
+ },
50
+ incompleteContentFactory: (content, request) => {
51
+ var _a;
52
+ // By this point, we know we have at least the complete first line with ```
53
+ const firstLine = content.split('\n')[0];
54
+ const language = ((_a = firstLine.match(/^```(\w+)/)) === null || _a === void 0 ? void 0 : _a[1]) || '';
55
+ // Remove the first line to get just the code content
56
+ const code = content.substring(content.indexOf('\n') + 1);
57
+ return new chat_model_1.CodeChatResponseContentImpl(code.trim(), language);
58
+ }
59
+ };
60
+ /**
61
+ * Clients can contribute response content matchers to parse the response content.
62
+ *
63
+ * The default chat user interface will collect all contributed matchers and use them
64
+ * to parse the response into structured content parts (e.g. code blocks, markdown blocks),
65
+ * which are then rendered with a `ChatResponsePartRenderer` registered for the respective
66
+ * content part type.
67
+ *
68
+ * ### Example
69
+ * ```ts
70
+ * bind(ResponseContentMatcherProvider).to(MyResponseContentMatcherProvider);
71
+ * ...
72
+ * @injectable()
73
+ * export class MyResponseContentMatcherProvider implements ResponseContentMatcherProvider {
74
+ * readonly matchers: ResponseContentMatcher[] = [{
75
+ * start: /^<command>$/m,
76
+ * end: /^</command>$/m,
77
+ * contentFactory: (content: string) => {
78
+ * const command = content.replace(/^<command>\n|<\/command>$/g, '');
79
+ * return new MyChatResponseContentImpl(command.trim());
80
+ * }
81
+ * }];
82
+ * }
83
+ * ```
84
+ *
85
+ * @see ResponseContentMatcher
86
+ */
87
+ exports.ResponseContentMatcherProvider = Symbol('ResponseContentMatcherProvider');
88
+ let DefaultResponseContentMatcherProvider = class DefaultResponseContentMatcherProvider {
89
+ constructor() {
90
+ this.matchers = [exports.CodeContentMatcher];
91
+ }
92
+ };
93
+ exports.DefaultResponseContentMatcherProvider = DefaultResponseContentMatcherProvider;
94
+ exports.DefaultResponseContentMatcherProvider = DefaultResponseContentMatcherProvider = tslib_1.__decorate([
95
+ (0, inversify_1.injectable)()
96
+ ], DefaultResponseContentMatcherProvider);
97
+ //# sourceMappingURL=response-content-matcher.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"response-content-matcher.js","sourceRoot":"","sources":["../../src/common/response-content-matcher.ts"],"names":[],"mappings":";;;;AAAA;;;;;;;;;;;;;;GAcG;AACH,6CAKsB;AACtB,4DAA0D;AAInD,MAAM,sBAAsB,GAA2B,CAAC,OAAe,EAAE,OAAgC,EAAE,EAAE,CAChH,IAAI,4CAA+B,CAAC,OAAO,CAAC,CAAC;AADpC,QAAA,sBAAsB,0BACc;AAEjD;;;;;GAKG;AAEI,IAAM,6BAA6B,GAAnC,MAAM,6BAA6B;IACtC,MAAM,CAAC,OAAe,EAAE,OAAgC;QACpD,OAAO,IAAA,8BAAsB,EAAC,OAAO,EAAE,O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A6B,CAAC,0BAAkB,CAAC,CAAC;IACvE,CAAC;CAAA,CAAA;AAFY,sFAAqC;gDAArC,qCAAqC;IADjD,IAAA,sBAAU,GAAE;GACA,qCAAqC,CAEjD"}
@@ -0,0 +1,4 @@
1
+ import { ContainerModule } from '@theia/core/shared/inversify';
2
+ declare const _default: ContainerModule;
3
+ export default _default;
4
+ //# sourceMappingURL=ai-chat-backend-module.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ai-chat-backend-module.d.ts","sourceRoot":"","sources":["../../src/node/ai-chat-backend-module.ts"],"names":[],"mappings":"AAiBA,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;;AAI/D,wBAGG"}