@theia/ai-core 1.54.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (209) hide show
  1. package/README.md +30 -0
  2. package/data/prompttemplate.tmLanguage.json +52 -0
  3. package/lib/browser/ai-activation-service.d.ts +17 -0
  4. package/lib/browser/ai-activation-service.d.ts.map +1 -0
  5. package/lib/browser/ai-activation-service.js +63 -0
  6. package/lib/browser/ai-activation-service.js.map +1 -0
  7. package/lib/browser/ai-command-handler-factory.d.ts +4 -0
  8. package/lib/browser/ai-command-handler-factory.d.ts.map +1 -0
  9. package/lib/browser/ai-command-handler-factory.js +20 -0
  10. package/lib/browser/ai-command-handler-factory.js.map +1 -0
  11. package/lib/browser/ai-configuration/agent-configuration-widget.d.ts +27 -0
  12. package/lib/browser/ai-configuration/agent-configuration-widget.d.ts.map +1 -0
  13. package/lib/browser/ai-configuration/agent-configuration-widget.js +231 -0
  14. package/lib/browser/ai-configuration/agent-configuration-widget.js.map +1 -0
  15. package/lib/browser/ai-configuration/ai-configuration-service.d.ts +13 -0
  16. package/lib/browser/ai-configuration/ai-configuration-service.d.ts.map +1 -0
  17. package/lib/browser/ai-configuration/ai-configuration-service.js +44 -0
  18. package/lib/browser/ai-configuration/ai-configuration-service.js.map +1 -0
  19. package/lib/browser/ai-configuration/ai-configuration-view-contribution.d.ts +12 -0
  20. package/lib/browser/ai-configuration/ai-configuration-view-contribution.d.ts.map +1 -0
  21. package/lib/browser/ai-configuration/ai-configuration-view-contribution.js +41 -0
  22. package/lib/browser/ai-configuration/ai-configuration-view-contribution.js.map +1 -0
  23. package/lib/browser/ai-configuration/ai-configuration-widget.d.ts +20 -0
  24. package/lib/browser/ai-configuration/ai-configuration-widget.d.ts.map +1 -0
  25. package/lib/browser/ai-configuration/ai-configuration-widget.js +88 -0
  26. package/lib/browser/ai-configuration/ai-configuration-widget.js.map +1 -0
  27. package/lib/browser/ai-configuration/language-model-renderer.d.ts +13 -0
  28. package/lib/browser/ai-configuration/language-model-renderer.d.ts.map +1 -0
  29. package/lib/browser/ai-configuration/language-model-renderer.js +104 -0
  30. package/lib/browser/ai-configuration/language-model-renderer.js.map +1 -0
  31. package/lib/browser/ai-configuration/template-settings-renderer.d.ts +11 -0
  32. package/lib/browser/ai-configuration/template-settings-renderer.d.ts.map +1 -0
  33. package/lib/browser/ai-configuration/template-settings-renderer.js +33 -0
  34. package/lib/browser/ai-configuration/template-settings-renderer.js.map +1 -0
  35. package/lib/browser/ai-configuration/variable-configuration-widget.d.ts +20 -0
  36. package/lib/browser/ai-configuration/variable-configuration-widget.d.ts.map +1 -0
  37. package/lib/browser/ai-configuration/variable-configuration-widget.js +99 -0
  38. package/lib/browser/ai-configuration/variable-configuration-widget.js.map +1 -0
  39. package/lib/browser/ai-core-frontend-application-contribution.d.ts +8 -0
  40. package/lib/browser/ai-core-frontend-application-contribution.d.ts.map +1 -0
  41. package/lib/browser/ai-core-frontend-application-contribution.js +46 -0
  42. package/lib/browser/ai-core-frontend-application-contribution.js.map +1 -0
  43. package/lib/browser/ai-core-frontend-module.d.ts +4 -0
  44. package/lib/browser/ai-core-frontend-module.d.ts.map +1 -0
  45. package/lib/browser/ai-core-frontend-module.js +122 -0
  46. package/lib/browser/ai-core-frontend-module.js.map +1 -0
  47. package/lib/browser/ai-core-preferences.d.ts +14 -0
  48. package/lib/browser/ai-core-preferences.d.ts.map +1 -0
  49. package/lib/browser/ai-core-preferences.js +69 -0
  50. package/lib/browser/ai-core-preferences.js.map +1 -0
  51. package/lib/browser/ai-settings-service.d.ts +14 -0
  52. package/lib/browser/ai-settings-service.d.ts.map +1 -0
  53. package/lib/browser/ai-settings-service.js +56 -0
  54. package/lib/browser/ai-settings-service.js.map +1 -0
  55. package/lib/browser/ai-view-contribution.d.ts +14 -0
  56. package/lib/browser/ai-view-contribution.d.ts.map +1 -0
  57. package/lib/browser/ai-view-contribution.js +71 -0
  58. package/lib/browser/ai-view-contribution.js.map +1 -0
  59. package/lib/browser/frontend-language-model-registry.d.ts +39 -0
  60. package/lib/browser/frontend-language-model-registry.d.ts.map +1 -0
  61. package/lib/browser/frontend-language-model-registry.js +321 -0
  62. package/lib/browser/frontend-language-model-registry.js.map +1 -0
  63. package/lib/browser/frontend-prompt-customization-service.d.ts +31 -0
  64. package/lib/browser/frontend-prompt-customization-service.d.ts.map +1 -0
  65. package/lib/browser/frontend-prompt-customization-service.js +194 -0
  66. package/lib/browser/frontend-prompt-customization-service.js.map +1 -0
  67. package/lib/browser/frontend-variable-service.d.ts +6 -0
  68. package/lib/browser/frontend-variable-service.d.ts.map +1 -0
  69. package/lib/browser/frontend-variable-service.js +31 -0
  70. package/lib/browser/frontend-variable-service.js.map +1 -0
  71. package/lib/browser/index.d.ts +11 -0
  72. package/lib/browser/index.d.ts.map +1 -0
  73. package/lib/browser/index.js +29 -0
  74. package/lib/browser/index.js.map +1 -0
  75. package/lib/browser/prompttemplate-contribution.d.ts +28 -0
  76. package/lib/browser/prompttemplate-contribution.d.ts.map +1 -0
  77. package/lib/browser/prompttemplate-contribution.js +207 -0
  78. package/lib/browser/prompttemplate-contribution.js.map +1 -0
  79. package/lib/browser/theia-variable-contribution.d.ts +13 -0
  80. package/lib/browser/theia-variable-contribution.d.ts.map +1 -0
  81. package/lib/browser/theia-variable-contribution.js +64 -0
  82. package/lib/browser/theia-variable-contribution.js.map +1 -0
  83. package/lib/common/agent-service.d.ts +48 -0
  84. package/lib/common/agent-service.d.ts.map +1 -0
  85. package/lib/common/agent-service.js +88 -0
  86. package/lib/common/agent-service.js.map +1 -0
  87. package/lib/common/agent.d.ts +45 -0
  88. package/lib/common/agent.d.ts.map +1 -0
  89. package/lib/common/agent.js +20 -0
  90. package/lib/common/agent.js.map +1 -0
  91. package/lib/common/agents-variable-contribution.d.ts +19 -0
  92. package/lib/common/agents-variable-contribution.d.ts.map +1 -0
  93. package/lib/common/agents-variable-contribution.js +56 -0
  94. package/lib/common/agents-variable-contribution.js.map +1 -0
  95. package/lib/common/communication-recording-service.d.ts +23 -0
  96. package/lib/common/communication-recording-service.d.ts.map +1 -0
  97. package/lib/common/communication-recording-service.js +20 -0
  98. package/lib/common/communication-recording-service.js.map +1 -0
  99. package/lib/common/index.d.ts +16 -0
  100. package/lib/common/index.d.ts.map +1 -0
  101. package/lib/common/index.js +34 -0
  102. package/lib/common/index.js.map +1 -0
  103. package/lib/common/language-model-delegate.d.ts +24 -0
  104. package/lib/common/language-model-delegate.d.ts.map +1 -0
  105. package/lib/common/language-model-delegate.js +26 -0
  106. package/lib/common/language-model-delegate.js.map +1 -0
  107. package/lib/common/language-model-util.d.ts +5 -0
  108. package/lib/common/language-model-util.d.ts.map +1 -0
  109. package/lib/common/language-model-util.js +75 -0
  110. package/lib/common/language-model-util.js.map +1 -0
  111. package/lib/common/language-model.d.ts +137 -0
  112. package/lib/common/language-model.d.ts.map +1 -0
  113. package/lib/common/language-model.js +142 -0
  114. package/lib/common/language-model.js.map +1 -0
  115. package/lib/common/language-model.spec.d.ts +2 -0
  116. package/lib/common/language-model.spec.d.ts.map +1 -0
  117. package/lib/common/language-model.spec.js +62 -0
  118. package/lib/common/language-model.spec.js.map +1 -0
  119. package/lib/common/prompt-service-util.d.ts +5 -0
  120. package/lib/common/prompt-service-util.d.ts.map +1 -0
  121. package/lib/common/prompt-service-util.js +23 -0
  122. package/lib/common/prompt-service-util.js.map +1 -0
  123. package/lib/common/prompt-service.d.ts +101 -0
  124. package/lib/common/prompt-service.d.ts.map +1 -0
  125. package/lib/common/prompt-service.js +139 -0
  126. package/lib/common/prompt-service.js.map +1 -0
  127. package/lib/common/prompt-service.spec.d.ts +2 -0
  128. package/lib/common/prompt-service.spec.d.ts.map +1 -0
  129. package/lib/common/prompt-service.spec.js +86 -0
  130. package/lib/common/prompt-service.spec.js.map +1 -0
  131. package/lib/common/protocol.d.ts +7 -0
  132. package/lib/common/protocol.d.ts.map +1 -0
  133. package/lib/common/protocol.js +20 -0
  134. package/lib/common/protocol.js.map +1 -0
  135. package/lib/common/settings-service.d.ts +18 -0
  136. package/lib/common/settings-service.d.ts.map +1 -0
  137. package/lib/common/settings-service.js +5 -0
  138. package/lib/common/settings-service.js.map +1 -0
  139. package/lib/common/today-variable-contribution.d.ts +17 -0
  140. package/lib/common/today-variable-contribution.d.ts.map +1 -0
  141. package/lib/common/today-variable-contribution.js +48 -0
  142. package/lib/common/today-variable-contribution.js.map +1 -0
  143. package/lib/common/tomorrow-variable-contribution.d.ts +17 -0
  144. package/lib/common/tomorrow-variable-contribution.d.ts.map +1 -0
  145. package/lib/common/tomorrow-variable-contribution.js +48 -0
  146. package/lib/common/tomorrow-variable-contribution.js.map +1 -0
  147. package/lib/common/tool-invocation-registry.d.ts +23 -0
  148. package/lib/common/tool-invocation-registry.d.ts.map +1 -0
  149. package/lib/common/tool-invocation-registry.js +72 -0
  150. package/lib/common/tool-invocation-registry.js.map +1 -0
  151. package/lib/common/variable-service.d.ts +70 -0
  152. package/lib/common/variable-service.d.ts.map +1 -0
  153. package/lib/common/variable-service.js +122 -0
  154. package/lib/common/variable-service.js.map +1 -0
  155. package/lib/node/ai-core-backend-module.d.ts +4 -0
  156. package/lib/node/ai-core-backend-module.d.ts.map +1 -0
  157. package/lib/node/ai-core-backend-module.js +47 -0
  158. package/lib/node/ai-core-backend-module.js.map +1 -0
  159. package/lib/node/backend-language-model-registry.d.ts +12 -0
  160. package/lib/node/backend-language-model-registry.d.ts.map +1 -0
  161. package/lib/node/backend-language-model-registry.js +61 -0
  162. package/lib/node/backend-language-model-registry.js.map +1 -0
  163. package/lib/node/language-model-frontend-delegate.d.ts +18 -0
  164. package/lib/node/language-model-frontend-delegate.d.ts.map +1 -0
  165. package/lib/node/language-model-frontend-delegate.js +100 -0
  166. package/lib/node/language-model-frontend-delegate.js.map +1 -0
  167. package/package.json +59 -0
  168. package/src/browser/ai-activation-service.ts +56 -0
  169. package/src/browser/ai-command-handler-factory.ts +20 -0
  170. package/src/browser/ai-configuration/agent-configuration-widget.tsx +299 -0
  171. package/src/browser/ai-configuration/ai-configuration-service.ts +43 -0
  172. package/src/browser/ai-configuration/ai-configuration-view-contribution.ts +54 -0
  173. package/src/browser/ai-configuration/ai-configuration-widget.tsx +80 -0
  174. package/src/browser/ai-configuration/language-model-renderer.tsx +113 -0
  175. package/src/browser/ai-configuration/template-settings-renderer.tsx +39 -0
  176. package/src/browser/ai-configuration/variable-configuration-widget.tsx +110 -0
  177. package/src/browser/ai-core-frontend-application-contribution.ts +40 -0
  178. package/src/browser/ai-core-frontend-module.ts +161 -0
  179. package/src/browser/ai-core-preferences.ts +76 -0
  180. package/src/browser/ai-settings-service.ts +50 -0
  181. package/src/browser/ai-view-contribution.ts +77 -0
  182. package/src/browser/frontend-language-model-registry.ts +405 -0
  183. package/src/browser/frontend-prompt-customization-service.ts +197 -0
  184. package/src/browser/frontend-variable-service.ts +26 -0
  185. package/src/browser/index.ts +26 -0
  186. package/src/browser/prompttemplate-contribution.ts +250 -0
  187. package/src/browser/style/index.css +90 -0
  188. package/src/browser/theia-variable-contribution.ts +58 -0
  189. package/src/common/agent-service.ts +108 -0
  190. package/src/common/agent.ts +70 -0
  191. package/src/common/agents-variable-contribution.ts +64 -0
  192. package/src/common/communication-recording-service.ts +44 -0
  193. package/src/common/index.ts +30 -0
  194. package/src/common/language-model-delegate.ts +45 -0
  195. package/src/common/language-model-util.ts +67 -0
  196. package/src/common/language-model.spec.ts +86 -0
  197. package/src/common/language-model.ts +237 -0
  198. package/src/common/prompt-service-util.ts +21 -0
  199. package/src/common/prompt-service.spec.ts +98 -0
  200. package/src/common/prompt-service.ts +213 -0
  201. package/src/common/protocol.ts +23 -0
  202. package/src/common/settings-service.ts +33 -0
  203. package/src/common/today-variable-contribution.ts +67 -0
  204. package/src/common/tomorrow-variable-contribution.ts +66 -0
  205. package/src/common/tool-invocation-registry.ts +79 -0
  206. package/src/common/variable-service.ts +177 -0
  207. package/src/node/ai-core-backend-module.ts +83 -0
  208. package/src/node/backend-language-model-registry.ts +59 -0
  209. package/src/node/language-model-frontend-delegate.ts +116 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"language-model.spec.d.ts","sourceRoot":"","sources":["../../src/common/language-model.spec.ts"],"names":[],"mappings":""}
@@ -0,0 +1,62 @@
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
+ const language_model_1 = require("./language-model");
19
+ const chai_1 = require("chai");
20
+ describe('isModelMatching', () => {
21
+ it('returns false with one of two parameter mismatches', () => {
22
+ (0, chai_1.expect)((0, language_model_1.isModelMatching)({
23
+ name: 'XXX',
24
+ family: 'YYY',
25
+ }, {
26
+ name: 'gpt-4o',
27
+ family: 'YYY',
28
+ })).eql(false);
29
+ });
30
+ it('returns false with two parameter mismatches', () => {
31
+ (0, chai_1.expect)((0, language_model_1.isModelMatching)({
32
+ name: 'XXX',
33
+ family: 'YYY',
34
+ }, {
35
+ name: 'gpt-4o',
36
+ family: 'ZZZ',
37
+ })).eql(false);
38
+ });
39
+ it('returns true with one parameter match', () => {
40
+ (0, chai_1.expect)((0, language_model_1.isModelMatching)({
41
+ name: 'gpt-4o',
42
+ }, {
43
+ name: 'gpt-4o',
44
+ })).eql(true);
45
+ });
46
+ it('returns true with two parameter matches', () => {
47
+ (0, chai_1.expect)((0, language_model_1.isModelMatching)({
48
+ name: 'gpt-4o',
49
+ family: 'YYY',
50
+ }, {
51
+ name: 'gpt-4o',
52
+ family: 'YYY',
53
+ })).eql(true);
54
+ });
55
+ it('returns true if there are no parameters in selector', () => {
56
+ (0, chai_1.expect)((0, language_model_1.isModelMatching)({}, {
57
+ name: 'gpt-4o',
58
+ family: 'YYY',
59
+ })).eql(true);
60
+ });
61
+ });
62
+ //# sourceMappingURL=language-model.spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"language-model.spec.js","sourceRoot":"","sources":["../../src/common/language-model.spec.ts"],"names":[],"mappings":";AAAA,gFAAgF;AAChF,yCAAyC;AACzC,EAAE;AACF,2EAA2E;AAC3E,mEAAmE;AACnE,wCAAwC;AACxC,EAAE;AACF,4EAA4E;AAC5E,8EAA8E;AAC9E,6EAA6E;AAC7E,yDAAyD;AACzD,uDAAuD;AACvD,EAAE;AACF,gFAAgF;AAChF,gFAAgF;;AAEhF,qDAAyF;AACzF,+BAA8B;AAE9B,QAAQ,CAAC,iBAAiB,EAAE,GAAG,EAAE;IAC7B,EAAE,CAAC,oDAAoD,EAAE,GAAG,EAAE;QAC1D,IAAA,aAAM,EACF,IAAA,gCAAe,EACY;YACnB,IAAI,EAAE,KAAK;YACX,MAAM,EAAE,KAAK;SAChB,EACc;YACX,IAAI,EAAE,QAAQ;YACd,MAAM,EAAE,KAAK;SAChB,CACJ,CACJ,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IACjB,CAAC,CAAC,CAAC;IACH,EAAE,CAAC,6CAA6C,EAAE,GAAG,EAAE;QACnD,IAAA,aAAM,EACF,IAAA,gCAAe,EACY;YACnB,IAAI,EAAE,KAAK;YACX,MAAM,EAAE,KAAK;SAChB,EACc;YACX,IAAI,EAAE,QAAQ;YACd,MAAM,EAAE,KAAK;SAChB,CACJ,CACJ,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IACjB,CAAC,CAAC,CAAC;IACH,EAAE,CAAC,uCAAuC,EAAE,GAAG,EAAE;QAC7C,IAAA,aAAM,EACF,IAAA,gCAAe,EACY;YACnB,IAAI,EAAE,QAAQ;SACjB,EACc;YACX,IAAI,EAAE,QAAQ;SACjB,CACJ,CACJ,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAChB,CAAC,CAAC,CAAC;IACH,EAAE,CAAC,yCAAyC,EAAE,GAAG,EAAE;QAC/C,IAAA,aAAM,EACF,IAAA,gCAAe,EACY;YACnB,IAAI,EAAE,QAAQ;YACd,MAAM,EAAE,KAAK;SAChB,EACc;YACX,IAAI,EAAE,QAAQ;YACd,MAAM,EAAE,KAAK;SAChB,CACJ,CACJ,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAChB,CAAC,CAAC,CAAC;IACH,EAAE,CAAC,qDAAqD,EAAE,GAAG,EAAE;QAC3D,IAAA,aAAM,EACF,IAAA,gCAAe,EACY,EAAE,EACV;YACX,IAAI,EAAE,QAAQ;YACd,MAAM,EAAE,KAAK;SAChB,CACJ,CACJ,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAChB,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}
@@ -0,0 +1,5 @@
1
+ /** Should match the one from VariableResolverService. The format is `{{variableName:arg}}`. */
2
+ export declare const PROMPT_VARIABLE_REGEX: RegExp;
3
+ /** Match function/tool references in the prompt. The format is `~{functionId}`. */
4
+ export declare const PROMPT_FUNCTION_REGEX: RegExp;
5
+ //# sourceMappingURL=prompt-service-util.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prompt-service-util.d.ts","sourceRoot":"","sources":["../../src/common/prompt-service-util.ts"],"names":[],"mappings":"AAgBA,+FAA+F;AAC/F,eAAO,MAAM,qBAAqB,QAAyB,CAAC;AAE5D,mFAAmF;AACnF,eAAO,MAAM,qBAAqB,QAAuB,CAAC"}
@@ -0,0 +1,23 @@
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.PROMPT_FUNCTION_REGEX = exports.PROMPT_VARIABLE_REGEX = void 0;
19
+ /** Should match the one from VariableResolverService. The format is `{{variableName:arg}}`. */
20
+ exports.PROMPT_VARIABLE_REGEX = /\{\{\s*(.*?)\s*\}\}/g;
21
+ /** Match function/tool references in the prompt. The format is `~{functionId}`. */
22
+ exports.PROMPT_FUNCTION_REGEX = /\~\{\s*(.*?)\s*\}/g;
23
+ //# sourceMappingURL=prompt-service-util.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prompt-service-util.js","sourceRoot":"","sources":["../../src/common/prompt-service-util.ts"],"names":[],"mappings":";AAAA,gFAAgF;AAChF,yCAAyC;AACzC,EAAE;AACF,2EAA2E;AAC3E,mEAAmE;AACnE,wCAAwC;AACxC,EAAE;AACF,4EAA4E;AAC5E,8EAA8E;AAC9E,6EAA6E;AAC7E,yDAAyD;AACzD,uDAAuD;AACvD,EAAE;AACF,gFAAgF;AAChF,gFAAgF;;;AAEhF,+FAA+F;AAClF,QAAA,qBAAqB,GAAG,sBAAsB,CAAC;AAE5D,mFAAmF;AACtE,QAAA,qBAAqB,GAAG,oBAAoB,CAAC"}
@@ -0,0 +1,101 @@
1
+ import { URI, Event } from '@theia/core';
2
+ import { AIVariableService } from './variable-service';
3
+ import { ToolInvocationRegistry } from './tool-invocation-registry';
4
+ import { ToolRequest } from './language-model';
5
+ export interface PromptTemplate {
6
+ id: string;
7
+ template: string;
8
+ }
9
+ export interface PromptMap {
10
+ [id: string]: PromptTemplate;
11
+ }
12
+ export interface ResolvedPromptTemplate {
13
+ id: string;
14
+ /** The resolved prompt text with variables and function requests being replaced. */
15
+ text: string;
16
+ /** All functions referenced in the prompt template. */
17
+ functionDescriptions?: Map<string, ToolRequest>;
18
+ }
19
+ export declare const PromptService: unique symbol;
20
+ export interface PromptService {
21
+ /**
22
+ * Retrieve the raw {@link PromptTemplate} object.
23
+ * @param id the id of the {@link PromptTemplate}
24
+ */
25
+ getRawPrompt(id: string): PromptTemplate | undefined;
26
+ /**
27
+ * Retrieve the default raw {@link PromptTemplate} object.
28
+ * @param id the id of the {@link PromptTemplate}
29
+ */
30
+ getDefaultRawPrompt(id: string): PromptTemplate | undefined;
31
+ /**
32
+ * Allows to directly replace placeholders in the prompt. The supported format is 'Hi {{name}}!'.
33
+ * The placeholder is then searched inside the args object and replaced.
34
+ * Function references are also supported via format '~{functionId}'.
35
+ * @param id the id of the prompt
36
+ * @param args the object with placeholders, mapping the placeholder key to the value
37
+ */
38
+ getPrompt(id: string, args?: {
39
+ [key: string]: unknown;
40
+ }): Promise<ResolvedPromptTemplate | undefined>;
41
+ /**
42
+ * Manually add a prompt to the list of prompts.
43
+ * @param id the id of the prompt
44
+ * @param prompt the prompt template to store
45
+ */
46
+ storePrompt(id: string, prompt: string): void;
47
+ /**
48
+ * Return all known prompts as a {@link PromptMap map}.
49
+ */
50
+ getAllPrompts(): PromptMap;
51
+ }
52
+ export declare const PromptCustomizationService: unique symbol;
53
+ export interface PromptCustomizationService {
54
+ /**
55
+ * Whether there is a customization for a {@link PromptTemplate} object
56
+ * @param id the id of the {@link PromptTemplate} to check
57
+ */
58
+ isPromptTemplateCustomized(id: string): boolean;
59
+ /**
60
+ * Returns the customization of {@link PromptTemplate} object or undefined if there is none
61
+ * @param id the id of the {@link PromptTemplate} to check
62
+ */
63
+ getCustomizedPromptTemplate(id: string): string | undefined;
64
+ /**
65
+ * Edit the template. If the content is specified, is will be
66
+ * used to customize the template. Otherwise, the behavior depends
67
+ * on the implementation. Implementation may for example decide to
68
+ * open an editor, or request more information from the user, ...
69
+ * @param id the template id.
70
+ * @param content optional content to customize the template.
71
+ */
72
+ editTemplate(id: string, content?: string): void;
73
+ /**
74
+ * Reset the template to its default value.
75
+ * @param id the template id.
76
+ */
77
+ resetTemplate(id: string): void;
78
+ /**
79
+ * Return the template id for a given template file.
80
+ * @param uri the uri of the template file
81
+ */
82
+ getTemplateIDFromURI(uri: URI): string | undefined;
83
+ /**
84
+ * Event which is fired when the prompt template is changed.
85
+ */
86
+ readonly onDidChangePrompt: Event<string>;
87
+ }
88
+ export declare class PromptServiceImpl implements PromptService {
89
+ protected readonly customizationService: PromptCustomizationService | undefined;
90
+ protected readonly variableService: AIVariableService | undefined;
91
+ protected readonly toolInvocationRegistry: ToolInvocationRegistry | undefined;
92
+ protected _prompts: PromptMap;
93
+ getRawPrompt(id: string): PromptTemplate | undefined;
94
+ getDefaultRawPrompt(id: string): PromptTemplate | undefined;
95
+ getPrompt(id: string, args?: {
96
+ [key: string]: unknown;
97
+ }): Promise<ResolvedPromptTemplate | undefined>;
98
+ getAllPrompts(): PromptMap;
99
+ storePrompt(id: string, prompt: string): void;
100
+ }
101
+ //# sourceMappingURL=prompt-service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prompt-service.d.ts","sourceRoot":"","sources":["../../src/common/prompt-service.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAEzC,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAC;AAEpE,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAG/C,MAAM,WAAW,cAAc;IAC3B,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,SAAS;IAAG,CAAC,EA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,GAAG,SAAS,CAAC;IAEnD;;OAEG;IACH,QAAQ,CAAC,iBAAiB,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;CAC7C;AAED,qBACa,iBAAkB,YAAW,aAAa;IAEnD,SAAS,CAAC,QAAQ,CAAC,oBAAoB,EAAE,0BAA0B,GAAG,SAAS,CAAC;IAGhF,SAAS,CAAC,QAAQ,CAAC,eAAe,EAAE,iBAAiB,GAAG,SAAS,CAAC;IAGlE,SAAS,CAAC,QAAQ,CAAC,sBAAsB,EAAE,sBAAsB,GAAG,SAAS,CAAC;IAE9E,SAAS,CAAC,QAAQ,EAAE,SAAS,CAAM;IAEnC,YAAY,CAAC,EAAE,EAAE,MAAM,GAAG,cAAc,GAAG,SAAS;IASpD,mBAAmB,CAAC,EAAE,EAAE,MAAM,GAAG,cAAc,GAAG,SAAS;IAGrD,SAAS,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;KAAE,GAAG,OAAO,CAAC,sBAAsB,GAAG,SAAS,CAAC;IAkD3G,aAAa,IAAI,SAAS;IAqB1B,WAAW,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI;CAGhD"}
@@ -0,0 +1,139 @@
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.PromptServiceImpl = exports.PromptCustomizationService = exports.PromptService = void 0;
19
+ const tslib_1 = require("tslib");
20
+ const inversify_1 = require("@theia/core/shared/inversify");
21
+ const variable_service_1 = require("./variable-service");
22
+ const tool_invocation_registry_1 = require("./tool-invocation-registry");
23
+ const language_model_util_1 = require("./language-model-util");
24
+ const prompt_service_util_1 = require("./prompt-service-util");
25
+ exports.PromptService = Symbol('PromptService');
26
+ exports.PromptCustomizationService = Symbol('PromptCustomizationService');
27
+ let PromptServiceImpl = class PromptServiceImpl {
28
+ constructor() {
29
+ this._prompts = {};
30
+ }
31
+ getRawPrompt(id) {
32
+ if (this.customizationService !== undefined && this.customizationService.isPromptTemplateCustomized(id)) {
33
+ const template = this.customizationService.getCustomizedPromptTemplate(id);
34
+ if (template !== undefined) {
35
+ return { id, template };
36
+ }
37
+ }
38
+ return this.getDefaultRawPrompt(id);
39
+ }
40
+ getDefaultRawPrompt(id) {
41
+ return this._prompts[id];
42
+ }
43
+ async getPrompt(id, args) {
44
+ const prompt = this.getRawPrompt(id);
45
+ if (prompt === undefined) {
46
+ return undefined;
47
+ }
48
+ const matches = [...prompt.template.matchAll(prompt_service_util_1.PROMPT_VARIABLE_REGEX)];
49
+ const variableAndArgReplacements = await Promise.all(matches.map(async (match) => {
50
+ var _a, _b, _c, _d;
51
+ const completeText = match[0];
52
+ const variableAndArg = match[1];
53
+ let variableName = variableAndArg;
54
+ let argument;
55
+ const parts = variableAndArg.split(':', 2);
56
+ if (parts.length > 1) {
57
+ variableName = parts[0];
58
+ argument = parts[1];
59
+ }
60
+ return {
61
+ placeholder: completeText,
62
+ value: String((_d = (_a = args === null || args === void 0 ? void 0 : args[variableAndArg]) !== null && _a !== void 0 ? _a : (_c = (await ((_b = this.variableService) === null || _b === void 0 ? void 0 : _b.resolveVariable({
63
+ variable: variableName,
64
+ arg: argument
65
+ }, {})))) === null || _c === void 0 ? void 0 : _c.value) !== null && _d !== void 0 ? _d : completeText)
66
+ };
67
+ }));
68
+ const functionMatches = [...prompt.template.matchAll(prompt_service_util_1.PROMPT_FUNCTION_REGEX)];
69
+ const functions = new Map();
70
+ const functionReplacements = functionMatches.map(match => {
71
+ var _a;
72
+ const completeText = match[0];
73
+ const functionId = match[1];
74
+ const toolRequest = (_a = this.toolInvocationRegistry) === null || _a === void 0 ? void 0 : _a.getFunction(functionId);
75
+ if (toolRequest) {
76
+ functions.set(toolRequest.id, toolRequest);
77
+ }
78
+ return {
79
+ placeholder: completeText,
80
+ value: toolRequest ? (0, language_model_util_1.toolRequestToPromptText)(toolRequest) : completeText
81
+ };
82
+ });
83
+ let resolvedTemplate = prompt.template;
84
+ const replacements = [...variableAndArgReplacements, ...functionReplacements];
85
+ replacements.forEach(replacement => resolvedTemplate = resolvedTemplate.replace(replacement.placeholder, replacement.value));
86
+ return {
87
+ id,
88
+ text: resolvedTemplate,
89
+ functionDescriptions: functions.size > 0 ? functions : undefined
90
+ };
91
+ }
92
+ getAllPrompts() {
93
+ if (this.customizationService !== undefined) {
94
+ const myCustomization = this.customizationService;
95
+ const result = {};
96
+ Object.keys(this._prompts).forEach(id => {
97
+ if (myCustomization.isPromptTemplateCustomized(id)) {
98
+ const template = myCustomization.getCustomizedPromptTemplate(id);
99
+ if (template !== undefined) {
100
+ result[id] = { id, template };
101
+ }
102
+ else {
103
+ result[id] = { ...this._prompts[id] };
104
+ }
105
+ }
106
+ else {
107
+ result[id] = { ...this._prompts[id] };
108
+ }
109
+ });
110
+ return result;
111
+ }
112
+ else {
113
+ return { ...this._prompts };
114
+ }
115
+ }
116
+ storePrompt(id, prompt) {
117
+ this._prompts[id] = { id, template: prompt };
118
+ }
119
+ };
120
+ exports.PromptServiceImpl = PromptServiceImpl;
121
+ tslib_1.__decorate([
122
+ (0, inversify_1.inject)(exports.PromptCustomizationService),
123
+ (0, inversify_1.optional)(),
124
+ tslib_1.__metadata("design:type", Object)
125
+ ], PromptServiceImpl.prototype, "customizationService", void 0);
126
+ tslib_1.__decorate([
127
+ (0, inversify_1.inject)(variable_service_1.AIVariableService),
128
+ (0, inversify_1.optional)(),
129
+ tslib_1.__metadata("design:type", Object)
130
+ ], PromptServiceImpl.prototype, "variableService", void 0);
131
+ tslib_1.__decorate([
132
+ (0, inversify_1.inject)(tool_invocation_registry_1.ToolInvocationRegistry),
133
+ (0, inversify_1.optional)(),
134
+ tslib_1.__metadata("design:type", Object)
135
+ ], PromptServiceImpl.prototype, "toolInvocationRegistry", void 0);
136
+ exports.PromptServiceImpl = PromptServiceImpl = tslib_1.__decorate([
137
+ (0, inversify_1.injectable)()
138
+ ], PromptServiceImpl);
139
+ //# sourceMappingURL=prompt-service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prompt-service.js","sourceRoot":"","sources":["../../src/common/prompt-service.ts"],"names":[],"mappings":";AAAA,gFAAgF;AAChF,yCAAyC;AACzC,EAAE;AACF,2EAA2E;AAC3E,mEAAmE;AACnE,wCAAwC;AACxC,EAAE;AACF,4EAA4E;AAC5E,8EAA8E;AAC9E,6EAA6E;AAC7E,yDAAyD;AACzD,uDAAuD;AACvD,EAAE;AACF,gFAAgF;AAChF,gFAAgF;;;;AAGhF,4DAA4E;AAC5E,yDAAuD;AACvD,yEAAoE;AACpE,+DAAgE;AAEhE,+DAAqF;AAiBxE,QAAA,aAAa,GAAG,MAAM,CAAC,eAAe,CAAC,CAAC;AAgCxC,QAAA,0BAA0B,GAAG,MAAM,CAAC,4BAA4B,CAAC,CAAC;AA2CxE,IAAM,iBAAiB,GAAvB,MAAM,iBAAiB;IAAvB;QAUO,aAAQ,GAAc,EAAE,CAAC;IAwFvC,CAAC;IAtFG,YAAY,CAAC,EAAU;QACnB,IAAI,IAAI,CAAC,oBAAoB,KAAK,SAAS,IAAI,IAAI,CAAC,oBAAoB,CAAC,0BAA0B,CAAC,EAAE,CAAC,EAAE,CAAC;YACtG,MAAM,QAAQ,GAAG,IAAI,CAAC,oBAAoB,CAAC,2BAA2B,CAAC,E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AM,EAAE,CAAC;IACjD,CAAC;CACJ,CAAA;AAlGY,8CAAiB;AAEP;IADlB,IAAA,kBAAM,EAAC,kCAA0B,CAAC;IAAE,IAAA,oBAAQ,GAAE;;+DACiC;AAG7D;IADlB,IAAA,kBAAM,EAAC,oCAAiB,CAAC;IAAE,IAAA,oBAAQ,GAAE;;0DAC4B;AAG/C;IADlB,IAAA,kBAAM,EAAC,iDAAsB,CAAC;IAAE,IAAA,oBAAQ,GAAE;;iEACmC;4BARrE,iBAAiB;IAD7B,IAAA,sBAAU,GAAE;GACA,iBAAiB,CAkG7B"}
@@ -0,0 +1,2 @@
1
+ import 'reflect-metadata';
2
+ //# sourceMappingURL=prompt-service.spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prompt-service.spec.d.ts","sourceRoot":"","sources":["../../src/common/prompt-service.spec.ts"],"names":[],"mappings":"AAgBA,OAAO,kBAAkB,CAAC"}
@@ -0,0 +1,86 @@
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
+ require("reflect-metadata");
19
+ const chai_1 = require("chai");
20
+ const inversify_1 = require("inversify");
21
+ const prompt_service_1 = require("./prompt-service");
22
+ const variable_service_1 = require("./variable-service");
23
+ describe('PromptService', () => {
24
+ let promptService;
25
+ beforeEach(() => {
26
+ const container = new inversify_1.Container();
27
+ container.bind(prompt_service_1.PromptService).to(prompt_service_1.PromptServiceImpl).inSingletonScope();
28
+ const variableService = new variable_service_1.DefaultAIVariableService({ getContributions: () => [] });
29
+ const nameVariable = { id: 'test', name: 'name', description: 'Test name ' };
30
+ variableService.registerResolver(nameVariable, {
31
+ canResolve: () => 100,
32
+ resolve: async () => ({ variable: nameVariable, value: 'Jane' })
33
+ });
34
+ container.bind(variable_service_1.AIVariableService).toConstantValue(variableService);
35
+ promptService = container.get(prompt_service_1.PromptService);
36
+ promptService.storePrompt('1', 'Hello, {{name}}!');
37
+ promptService.storePrompt('2', 'Goodbye, {{name}}!');
38
+ promptService.storePrompt('3', 'Ciao, {{invalid}}!');
39
+ });
40
+ it('should initialize prompts from PromptCollectionService', () => {
41
+ const allPrompts = promptService.getAllPrompts();
42
+ (0, chai_1.expect)(allPrompts['1'].template).to.equal('Hello, {{name}}!');
43
+ (0, chai_1.expect)(allPrompts['2'].template).to.equal('Goodbye, {{name}}!');
44
+ (0, chai_1.expect)(allPrompts['3'].template).to.equal('Ciao, {{invalid}}!');
45
+ });
46
+ it('should retrieve raw prompt by id', () => {
47
+ const rawPrompt = promptService.getRawPrompt('1');
48
+ (0, chai_1.expect)(rawPrompt === null || rawPrompt === void 0 ? void 0 : rawPrompt.template).to.equal('Hello, {{name}}!');
49
+ });
50
+ it('should format prompt with provided arguments', async () => {
51
+ const formattedPrompt = await promptService.getPrompt('1', { name: 'John' });
52
+ (0, chai_1.expect)(formattedPrompt === null || formattedPrompt === void 0 ? void 0 : formattedPrompt.text).to.equal('Hello, John!');
53
+ });
54
+ it('should store a new prompt', () => {
55
+ promptService.storePrompt('3', 'Welcome, {{name}}!');
56
+ const newPrompt = promptService.getRawPrompt('3');
57
+ (0, chai_1.expect)(newPrompt === null || newPrompt === void 0 ? void 0 : newPrompt.template).to.equal('Welcome, {{name}}!');
58
+ });
59
+ it('should replace placeholders with provided arguments', async () => {
60
+ const prompt = await promptService.getPrompt('1', { name: 'John' });
61
+ (0, chai_1.expect)(prompt === null || prompt === void 0 ? void 0 : prompt.text).to.equal('Hello, John!');
62
+ });
63
+ it('should use variable service to resolve placeholders if argument value is not provided', async () => {
64
+ const prompt = await promptService.getPrompt('1');
65
+ (0, chai_1.expect)(prompt === null || prompt === void 0 ? void 0 : prompt.text).to.equal('Hello, Jane!');
66
+ });
67
+ it('should return the prompt even if there are no replacements', async () => {
68
+ const prompt = await promptService.getPrompt('3');
69
+ (0, chai_1.expect)(prompt === null || prompt === void 0 ? void 0 : prompt.text).to.equal('Ciao, {{invalid}}!');
70
+ });
71
+ it('should return undefined if the prompt id is not found', async () => {
72
+ const prompt = await promptService.getPrompt('4');
73
+ (0, chai_1.expect)(prompt).to.be.undefined;
74
+ });
75
+ it('should ignore whitespace in variables', async () => {
76
+ promptService.storePrompt('4', 'Hello, {{name }}!');
77
+ promptService.storePrompt('5', 'Hello, {{ name}}!');
78
+ promptService.storePrompt('6', 'Hello, {{ name }}!');
79
+ promptService.storePrompt('7', 'Hello, {{ name }}!');
80
+ for (let i = 4; i <= 7; i++) {
81
+ const prompt = await promptService.getPrompt(`${i}`, { name: 'John' });
82
+ (0, chai_1.expect)(prompt === null || prompt === void 0 ? void 0 : prompt.text).to.equal('Hello, John!');
83
+ }
84
+ });
85
+ });
86
+ //# sourceMappingURL=prompt-service.spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prompt-service.spec.js","sourceRoot":"","sources":["../../src/common/prompt-service.spec.ts"],"names":[],"mappings":";AAAA,gFAAgF;AAChF,yCAAyC;AACzC,EAAE;AACF,2EAA2E;AAC3E,mEAAmE;AACnE,wCAAwC;AACxC,EAAE;AACF,4EAA4E;AAC5E,8EAA8E;AAC9E,6EAA6E;AAC7E,yDAAyD;AACzD,uDAAuD;AACvD,EAAE;AACF,gFAAgF;AAChF,gFAAgF;;AAEhF,4BAA0B;AAE1B,+BAA8B;AAC9B,yCAAsC;AACtC,qDAAoE;AACpE,yDAAiF;AAEjF,QAAQ,CAAC,eAA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AC;QACrD,aAAa,CAAC,WAAW,CAAC,GAAG,EAAE,oCAAoC,CAAC,CAAC;QACrE,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;YAC1B,MAAM,MAAM,GAAG,MAAM,aAAa,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC;YACvE,IAAA,aAAM,EAAC,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,IAAI,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC;QAClD,CAAC;IACL,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}
@@ -0,0 +1,7 @@
1
+ import { LanguageModelMetaData } from './language-model';
2
+ export declare const LanguageModelRegistryClient: unique symbol;
3
+ export interface LanguageModelRegistryClient {
4
+ languageModelAdded(metadata: LanguageModelMetaData): void;
5
+ languageModelRemoved(id: string): void;
6
+ }
7
+ //# sourceMappingURL=protocol.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"protocol.d.ts","sourceRoot":"","sources":["../../src/common/protocol.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AAEzD,eAAO,MAAM,2BAA2B,eAAwC,CAAC;AACjF,MAAM,WAAW,2BAA2B;IACxC,kBAAkB,CAAC,QAAQ,EAAE,qBAAqB,GAAG,IAAI,CAAC;IAC1D,oBAAoB,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI,CAAC;CAC1C"}
@@ -0,0 +1,20 @@
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.LanguageModelRegistryClient = void 0;
19
+ exports.LanguageModelRegistryClient = Symbol('LanguageModelRegistryClient');
20
+ //# sourceMappingURL=protocol.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"protocol.js","sourceRoot":"","sources":["../../src/common/protocol.ts"],"names":[],"mappings":";AAAA,gFAAgF;AAChF,yCAAyC;AACzC,EAAE;AACF,2EAA2E;AAC3E,mEAAmE;AACnE,wCAAwC;AACxC,EAAE;AACF,4EAA4E;AAC5E,8EAA8E;AAC9E,6EAA6E;AAC7E,yDAAyD;AACzD,uDAAuD;AACvD,EAAE;AACF,gFAAgF;AAChF,gFAAgF;;;AAInE,QAAA,2BAA2B,GAAG,MAAM,CAAC,6BAA6B,CAAC,CAAC"}
@@ -0,0 +1,18 @@
1
+ import { Event } from '@theia/core';
2
+ import { LanguageModelRequirement } from './language-model';
3
+ export declare const AISettingsService: unique symbol;
4
+ /**
5
+ * Service to store and retrieve settings on a per-agent basis.
6
+ */
7
+ export interface AISettingsService {
8
+ updateAgentSettings(agent: string, agentSettings: Partial<AgentSettings>): Promise<void>;
9
+ getAgentSettings(agent: string): Promise<AgentSettings | undefined>;
10
+ getSettings(): Promise<AISettings>;
11
+ onDidChange: Event<void>;
12
+ }
13
+ export type AISettings = Record<string, AgentSettings>;
14
+ export interface AgentSettings {
15
+ languageModelRequirements?: LanguageModelRequirement[];
16
+ enable?: boolean;
17
+ }
18
+ //# sourceMappingURL=settings-service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"settings-service.d.ts","sourceRoot":"","sources":["../../src/common/settings-service.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,EAAE,wBAAwB,EAAE,MAAM,kBAAkB,CAAC;AAE5D,eAAO,MAAM,iBAAiB,eAA8B,CAAC;AAC7D;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAC9B,mBAAmB,CAAC,KAAK,EAAE,MAAM,EAAE,aAAa,EAAE,OAAO,CAAC,aAAa,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACzF,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,GAAG,SAAS,CAAC,CAAC;IACpE,WAAW,IAAI,OAAO,CAAC,UAAU,CAAC,CAAC;IACnC,WAAW,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC;CAC5B;AACD,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;AACvD,MAAM,WAAW,aAAa;IAC1B,yBAAyB,CAAC,EAAE,wBAAwB,EAAE,CAAC;IACvD,MAAM,CAAC,EAAE,OAAO,CAAC;CACpB"}
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AISettingsService = void 0;
4
+ exports.AISettingsService = Symbol('AISettingsService');
5
+ //# sourceMappingURL=settings-service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"settings-service.js","sourceRoot":"","sources":["../../src/common/settings-service.ts"],"names":[],"mappings":";;;AAkBa,QAAA,iBAAiB,GAAG,MAAM,CAAC,mBAAmB,CAAC,CAAC"}
@@ -0,0 +1,17 @@
1
+ import { MaybePromise } from '@theia/core';
2
+ import { AIVariable, ResolvedAIVariable, AIVariableContribution, AIVariableResolver, AIVariableService, AIVariableResolutionRequest, AIVariableContext } from './variable-service';
3
+ export declare namespace TodayVariableArgs {
4
+ const IN_UNIX_SECONDS = "inUnixSeconds";
5
+ const IN_ISO_8601 = "inIso8601";
6
+ }
7
+ export declare const TODAY_VARIABLE: AIVariable;
8
+ export interface ResolvedTodayVariable extends ResolvedAIVariable {
9
+ date: Date;
10
+ }
11
+ export declare class TodayVariableContribution implements AIVariableContribution, AIVariableResolver {
12
+ registerVariables(service: AIVariableService): void;
13
+ canResolve(request: AIVariableResolutionRequest, context: AIVariableContext): MaybePromise<number>;
14
+ resolve(request: AIVariableResolutionRequest, context: AIVariableContext): Promise<ResolvedAIVariable | undefined>;
15
+ private resolveTodayVariable;
16
+ }
17
+ //# sourceMappingURL=today-variable-contribution.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"today-variable-contribution.d.ts","sourceRoot":"","sources":["../../src/common/today-variable-contribution.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C,OAAO,EAAE,UAAU,EAAE,kBAAkB,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,2BAA2B,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAEnL,yBAAiB,iBAAiB,CAAC;IACxB,MAAM,eAAe,kBAAkB,CAAC;IACxC,MAAM,WAAW,cAAc,CAAC;CAC1C;AAED,eAAO,MAAM,cAAc,EAAE,UAQ5B,CAAC;AAEF,MAAM,WAAW,qBAAsB,SAAQ,kBAAkB;IAC7D,IAAI,EAAE,IAAI,CAAC;CACd;AAED,qBACa,yBAA0B,YAAW,sBAAsB,EAAE,kBAAkB;IACxF,iBAAiB,CAAC,OAAO,EAAE,iBAAiB,GAAG,IAAI;IAInD,UAAU,CAAC,OAAO,EAAE,2BAA2B,EAAE,OAAO,EAAE,iBAAiB,GAAG,YAAY,CAAC,MAAM,CAAC;IAI5F,OAAO,CAAC,OAAO,EAAE,2BAA2B,EAAE,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAAC,kBAAkB,GAAG,SAAS,CAAC;IAOxH,OAAO,CAAC,oBAAoB;CAU/B"}
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TodayVariableContribution = exports.TODAY_VARIABLE = exports.TodayVariableArgs = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const inversify_1 = require("@theia/core/shared/inversify");
6
+ var TodayVariableArgs;
7
+ (function (TodayVariableArgs) {
8
+ TodayVariableArgs.IN_UNIX_SECONDS = 'inUnixSeconds';
9
+ TodayVariableArgs.IN_ISO_8601 = 'inIso8601';
10
+ })(TodayVariableArgs || (exports.TodayVariableArgs = TodayVariableArgs = {}));
11
+ exports.TODAY_VARIABLE = {
12
+ id: 'today-provider',
13
+ description: 'Does something for today',
14
+ name: 'today',
15
+ args: [
16
+ { name: TodayVariableArgs.IN_ISO_8601, description: 'Returns the current date in ISO 8601 format' },
17
+ { name: TodayVariableArgs.IN_UNIX_SECONDS, description: 'Returns the current date in unix seconds format' }
18
+ ]
19
+ };
20
+ let TodayVariableContribution = class TodayVariableContribution {
21
+ registerVariables(service) {
22
+ service.registerResolver(exports.TODAY_VARIABLE, this);
23
+ }
24
+ canResolve(request, context) {
25
+ return 1;
26
+ }
27
+ async resolve(request, context) {
28
+ if (request.variable.name === exports.TODAY_VARIABLE.name) {
29
+ return this.resolveTodayVariable(request);
30
+ }
31
+ return undefined;
32
+ }
33
+ resolveTodayVariable(request) {
34
+ const date = new Date();
35
+ if (request.arg === TodayVariableArgs.IN_ISO_8601) {
36
+ return { variable: request.variable, value: date.toISOString(), date };
37
+ }
38
+ if (request.arg === TodayVariableArgs.IN_UNIX_SECONDS) {
39
+ return { variable: request.variable, value: Math.round(date.getTime() / 1000).toString(), date };
40
+ }
41
+ return { variable: request.variable, value: date.toDateString(), date };
42
+ }
43
+ };
44
+ exports.TodayVariableContribution = TodayVariableContribution;
45
+ exports.TodayVariableContribution = TodayVariableContribution = tslib_1.__decorate([
46
+ (0, inversify_1.injectable)()
47
+ ], TodayVariableContribution);
48
+ //# sourceMappingURL=today-variable-contribution.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"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