@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.
- package/lib/browser/ai-core-frontend-module.d.ts.map +1 -1
- package/lib/browser/ai-core-frontend-module.js +16 -0
- package/lib/browser/ai-core-frontend-module.js.map +1 -1
- package/lib/browser/ai-variable-uri-label-provider.d.ts +17 -0
- package/lib/browser/ai-variable-uri-label-provider.d.ts.map +1 -0
- package/lib/browser/ai-variable-uri-label-provider.js +85 -0
- package/lib/browser/ai-variable-uri-label-provider.js.map +1 -0
- package/lib/browser/file-variable-contribution.d.ts +9 -3
- package/lib/browser/file-variable-contribution.d.ts.map +1 -1
- package/lib/browser/file-variable-contribution.js +26 -8
- package/lib/browser/file-variable-contribution.js.map +1 -1
- package/lib/browser/frontend-prompt-customization-service.d.ts +22 -1
- package/lib/browser/frontend-prompt-customization-service.d.ts.map +1 -1
- package/lib/browser/frontend-prompt-customization-service.js +63 -25
- package/lib/browser/frontend-prompt-customization-service.js.map +1 -1
- package/lib/browser/frontend-variable-service.d.ts +28 -4
- package/lib/browser/frontend-variable-service.d.ts.map +1 -1
- package/lib/browser/frontend-variable-service.js +84 -1
- package/lib/browser/frontend-variable-service.js.map +1 -1
- package/lib/browser/prompttemplate-contribution.d.ts +0 -3
- package/lib/browser/prompttemplate-contribution.d.ts.map +1 -1
- package/lib/browser/prompttemplate-contribution.js +5 -24
- package/lib/browser/prompttemplate-contribution.js.map +1 -1
- package/lib/browser/token-usage-frontend-service-impl.d.ts +25 -0
- package/lib/browser/token-usage-frontend-service-impl.d.ts.map +1 -0
- package/lib/browser/token-usage-frontend-service-impl.js +120 -0
- package/lib/browser/token-usage-frontend-service-impl.js.map +1 -0
- package/lib/browser/token-usage-frontend-service.d.ts +29 -0
- package/lib/browser/token-usage-frontend-service.d.ts.map +1 -0
- package/lib/browser/token-usage-frontend-service.js +23 -0
- package/lib/browser/token-usage-frontend-service.js.map +1 -0
- package/lib/common/ai-variable-resource.d.ts +18 -0
- package/lib/common/ai-variable-resource.d.ts.map +1 -0
- package/lib/common/ai-variable-resource.js +103 -0
- package/lib/common/ai-variable-resource.js.map +1 -0
- package/lib/common/configurable-in-memory-resources.d.ts +45 -0
- package/lib/common/configurable-in-memory-resources.d.ts.map +1 -0
- package/lib/common/configurable-in-memory-resources.js +147 -0
- package/lib/common/configurable-in-memory-resources.js.map +1 -0
- package/lib/common/index.d.ts +3 -0
- package/lib/common/index.d.ts.map +1 -1
- package/lib/common/index.js +3 -0
- package/lib/common/index.js.map +1 -1
- package/lib/common/language-model.d.ts +7 -2
- package/lib/common/language-model.d.ts.map +1 -1
- package/lib/common/language-model.js +5 -1
- package/lib/common/language-model.js.map +1 -1
- package/lib/common/prompt-service.d.ts +16 -4
- package/lib/common/prompt-service.d.ts.map +1 -1
- package/lib/common/prompt-service.js +1 -1
- package/lib/common/prompt-service.js.map +1 -1
- package/lib/common/prompt-variable-contribution.d.ts +2 -1
- package/lib/common/prompt-variable-contribution.d.ts.map +1 -1
- package/lib/common/prompt-variable-contribution.js +10 -1
- package/lib/common/prompt-variable-contribution.js.map +1 -1
- package/lib/common/protocol.d.ts +14 -0
- package/lib/common/protocol.d.ts.map +1 -1
- package/lib/common/protocol.js +3 -1
- package/lib/common/protocol.js.map +1 -1
- package/lib/common/token-usage-service.d.ts +35 -0
- package/lib/common/token-usage-service.d.ts.map +1 -0
- package/lib/common/token-usage-service.js +20 -0
- package/lib/common/token-usage-service.js.map +1 -0
- package/lib/common/variable-service.d.ts +17 -2
- package/lib/common/variable-service.d.ts.map +1 -1
- package/lib/common/variable-service.js +43 -32
- package/lib/common/variable-service.js.map +1 -1
- package/lib/node/ai-core-backend-module.d.ts.map +1 -1
- package/lib/node/ai-core-backend-module.js +9 -0
- package/lib/node/ai-core-backend-module.js.map +1 -1
- package/lib/node/language-model-frontend-delegate.d.ts +2 -2
- package/lib/node/language-model-frontend-delegate.d.ts.map +1 -1
- package/lib/node/language-model-frontend-delegate.js.map +1 -1
- package/lib/node/token-usage-service-impl.d.ts +23 -0
- package/lib/node/token-usage-service-impl.d.ts.map +1 -0
- package/lib/node/token-usage-service-impl.js +65 -0
- package/lib/node/token-usage-service-impl.js.map +1 -0
- package/package.json +11 -10
- package/src/browser/ai-core-frontend-module.ts +26 -5
- package/src/browser/ai-variable-uri-label-provider.ts +66 -0
- package/src/browser/file-variable-contribution.ts +34 -14
- package/src/browser/frontend-prompt-customization-service.ts +72 -25
- package/src/browser/frontend-variable-service.ts +115 -5
- package/src/browser/prompttemplate-contribution.ts +5 -26
- package/src/browser/token-usage-frontend-service-impl.ts +117 -0
- package/src/browser/token-usage-frontend-service.ts +47 -0
- package/src/common/ai-variable-resource.ts +86 -0
- package/src/common/configurable-in-memory-resources.ts +156 -0
- package/src/common/index.ts +3 -0
- package/src/common/language-model.ts +10 -2
- package/src/common/prompt-service.ts +14 -4
- package/src/common/prompt-variable-contribution.ts +10 -2
- package/src/common/protocol.ts +18 -0
- package/src/common/token-usage-service.ts +56 -0
- package/src/common/variable-service.ts +58 -44
- package/src/node/ai-core-backend-module.ts +21 -1
- package/src/node/language-model-frontend-delegate.ts +2 -2
- 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
|
+
}
|