@theia/ai-core 1.60.2 → 1.61.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (98) hide show
  1. package/lib/browser/ai-core-frontend-module.d.ts.map +1 -1
  2. package/lib/browser/ai-core-frontend-module.js +16 -0
  3. package/lib/browser/ai-core-frontend-module.js.map +1 -1
  4. package/lib/browser/ai-variable-uri-label-provider.d.ts +17 -0
  5. package/lib/browser/ai-variable-uri-label-provider.d.ts.map +1 -0
  6. package/lib/browser/ai-variable-uri-label-provider.js +85 -0
  7. package/lib/browser/ai-variable-uri-label-provider.js.map +1 -0
  8. package/lib/browser/file-variable-contribution.d.ts +9 -3
  9. package/lib/browser/file-variable-contribution.d.ts.map +1 -1
  10. package/lib/browser/file-variable-contribution.js +26 -8
  11. package/lib/browser/file-variable-contribution.js.map +1 -1
  12. package/lib/browser/frontend-prompt-customization-service.d.ts +22 -1
  13. package/lib/browser/frontend-prompt-customization-service.d.ts.map +1 -1
  14. package/lib/browser/frontend-prompt-customization-service.js +63 -25
  15. package/lib/browser/frontend-prompt-customization-service.js.map +1 -1
  16. package/lib/browser/frontend-variable-service.d.ts +28 -4
  17. package/lib/browser/frontend-variable-service.d.ts.map +1 -1
  18. package/lib/browser/frontend-variable-service.js +84 -1
  19. package/lib/browser/frontend-variable-service.js.map +1 -1
  20. package/lib/browser/prompttemplate-contribution.d.ts +0 -3
  21. package/lib/browser/prompttemplate-contribution.d.ts.map +1 -1
  22. package/lib/browser/prompttemplate-contribution.js +5 -24
  23. package/lib/browser/prompttemplate-contribution.js.map +1 -1
  24. package/lib/browser/token-usage-frontend-service-impl.d.ts +25 -0
  25. package/lib/browser/token-usage-frontend-service-impl.d.ts.map +1 -0
  26. package/lib/browser/token-usage-frontend-service-impl.js +120 -0
  27. package/lib/browser/token-usage-frontend-service-impl.js.map +1 -0
  28. package/lib/browser/token-usage-frontend-service.d.ts +29 -0
  29. package/lib/browser/token-usage-frontend-service.d.ts.map +1 -0
  30. package/lib/browser/token-usage-frontend-service.js +23 -0
  31. package/lib/browser/token-usage-frontend-service.js.map +1 -0
  32. package/lib/common/ai-variable-resource.d.ts +18 -0
  33. package/lib/common/ai-variable-resource.d.ts.map +1 -0
  34. package/lib/common/ai-variable-resource.js +103 -0
  35. package/lib/common/ai-variable-resource.js.map +1 -0
  36. package/lib/common/configurable-in-memory-resources.d.ts +45 -0
  37. package/lib/common/configurable-in-memory-resources.d.ts.map +1 -0
  38. package/lib/common/configurable-in-memory-resources.js +147 -0
  39. package/lib/common/configurable-in-memory-resources.js.map +1 -0
  40. package/lib/common/index.d.ts +3 -0
  41. package/lib/common/index.d.ts.map +1 -1
  42. package/lib/common/index.js +3 -0
  43. package/lib/common/index.js.map +1 -1
  44. package/lib/common/language-model.d.ts +7 -2
  45. package/lib/common/language-model.d.ts.map +1 -1
  46. package/lib/common/language-model.js +5 -1
  47. package/lib/common/language-model.js.map +1 -1
  48. package/lib/common/prompt-service.d.ts +16 -4
  49. package/lib/common/prompt-service.d.ts.map +1 -1
  50. package/lib/common/prompt-service.js +1 -1
  51. package/lib/common/prompt-service.js.map +1 -1
  52. package/lib/common/prompt-variable-contribution.d.ts +2 -1
  53. package/lib/common/prompt-variable-contribution.d.ts.map +1 -1
  54. package/lib/common/prompt-variable-contribution.js +10 -1
  55. package/lib/common/prompt-variable-contribution.js.map +1 -1
  56. package/lib/common/protocol.d.ts +14 -0
  57. package/lib/common/protocol.d.ts.map +1 -1
  58. package/lib/common/protocol.js +3 -1
  59. package/lib/common/protocol.js.map +1 -1
  60. package/lib/common/token-usage-service.d.ts +35 -0
  61. package/lib/common/token-usage-service.d.ts.map +1 -0
  62. package/lib/common/token-usage-service.js +20 -0
  63. package/lib/common/token-usage-service.js.map +1 -0
  64. package/lib/common/variable-service.d.ts +17 -2
  65. package/lib/common/variable-service.d.ts.map +1 -1
  66. package/lib/common/variable-service.js +43 -32
  67. package/lib/common/variable-service.js.map +1 -1
  68. package/lib/node/ai-core-backend-module.d.ts.map +1 -1
  69. package/lib/node/ai-core-backend-module.js +9 -0
  70. package/lib/node/ai-core-backend-module.js.map +1 -1
  71. package/lib/node/language-model-frontend-delegate.d.ts +2 -2
  72. package/lib/node/language-model-frontend-delegate.d.ts.map +1 -1
  73. package/lib/node/language-model-frontend-delegate.js.map +1 -1
  74. package/lib/node/token-usage-service-impl.d.ts +23 -0
  75. package/lib/node/token-usage-service-impl.d.ts.map +1 -0
  76. package/lib/node/token-usage-service-impl.js +65 -0
  77. package/lib/node/token-usage-service-impl.js.map +1 -0
  78. package/package.json +11 -10
  79. package/src/browser/ai-core-frontend-module.ts +26 -5
  80. package/src/browser/ai-variable-uri-label-provider.ts +66 -0
  81. package/src/browser/file-variable-contribution.ts +34 -14
  82. package/src/browser/frontend-prompt-customization-service.ts +72 -25
  83. package/src/browser/frontend-variable-service.ts +115 -5
  84. package/src/browser/prompttemplate-contribution.ts +5 -26
  85. package/src/browser/token-usage-frontend-service-impl.ts +117 -0
  86. package/src/browser/token-usage-frontend-service.ts +47 -0
  87. package/src/common/ai-variable-resource.ts +86 -0
  88. package/src/common/configurable-in-memory-resources.ts +156 -0
  89. package/src/common/index.ts +3 -0
  90. package/src/common/language-model.ts +10 -2
  91. package/src/common/prompt-service.ts +14 -4
  92. package/src/common/prompt-variable-contribution.ts +10 -2
  93. package/src/common/protocol.ts +18 -0
  94. package/src/common/token-usage-service.ts +56 -0
  95. package/src/common/variable-service.ts +58 -44
  96. package/src/node/ai-core-backend-module.ts +21 -1
  97. package/src/node/language-model-frontend-delegate.ts +2 -2
  98. package/src/node/token-usage-service-impl.ts +65 -0
@@ -0,0 +1,65 @@
1
+ // *****************************************************************************
2
+ // Copyright (C) 2025 EclipseSource GmbH.
3
+ //
4
+ // This program and the accompanying materials are made available under the
5
+ // terms of the Eclipse Public License v. 2.0 which is available at
6
+ // http://www.eclipse.org/legal/epl-2.0.
7
+ //
8
+ // This Source Code may also be made available under the following Secondary
9
+ // Licenses when the conditions for such availability set forth in the Eclipse
10
+ // Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
+ // with the GNU Classpath Exception which is available at
12
+ // https://www.gnu.org/software/classpath/license.html.
13
+ //
14
+ // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
15
+ // *****************************************************************************
16
+
17
+ import { injectable } from '@theia/core/shared/inversify';
18
+ import { TokenUsage, TokenUsageParams, TokenUsageService } from '../common/token-usage-service';
19
+ import { TokenUsageServiceClient } from '../common/protocol';
20
+
21
+ @injectable()
22
+ export class TokenUsageServiceImpl implements TokenUsageService {
23
+ private client: TokenUsageServiceClient | undefined;
24
+
25
+ /**
26
+ * Sets the client to notify about token usage changes
27
+ */
28
+ setClient(client: TokenUsageServiceClient | undefined): void {
29
+ this.client = client;
30
+ }
31
+
32
+ private readonly tokenUsages: TokenUsage[] = [];
33
+
34
+ /**
35
+ * Records token usage for a model interaction.
36
+ *
37
+ * @param model The model identifier
38
+ * @param params Token usage parameters
39
+ * @returns A promise that resolves when the token usage has been recorded
40
+ */
41
+ async recordTokenUsage(model: string, params: TokenUsageParams): Promise<void> {
42
+ const usage: TokenUsage = {
43
+ inputTokens: params.inputTokens,
44
+ outputTokens: params.outputTokens,
45
+ model,
46
+ timestamp: new Date(),
47
+ requestId: params.requestId
48
+ };
49
+
50
+ this.tokenUsages.push(usage);
51
+ this.client?.notifyTokenUsage(usage);
52
+
53
+ console.log(`Input Tokens: ${params.inputTokens}; Output Tokens: ${params.outputTokens}; Model: ${model}${params.requestId ? `; RequestId: ${params.requestId}` : ''}`);
54
+ // For now we just store in memory
55
+ // In the future, this could be persisted to disk, a database, or sent to a service
56
+ return Promise.resolve();
57
+ }
58
+
59
+ /**
60
+ * Gets all token usage records stored in this service.
61
+ */
62
+ async getTokenUsages(): Promise<TokenUsage[]> {
63
+ return [...this.tokenUsages];
64
+ }
65
+ }