@theia/ai-core 1.60.1 → 1.61.0-next.8
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 +9 -0
- package/lib/browser/ai-core-frontend-module.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/index.d.ts +1 -0
- package/lib/common/index.d.ts.map +1 -1
- package/lib/common/index.js +1 -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/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/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 +10 -10
- package/src/browser/ai-core-frontend-module.ts +15 -1
- 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/index.ts +1 -0
- package/src/common/language-model.ts +10 -2
- package/src/common/protocol.ts +18 -0
- package/src/common/token-usage-service.ts +56 -0
- 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,35 @@
|
|
|
1
|
+
import { TokenUsageServiceClient } from './protocol';
|
|
2
|
+
export declare const TokenUsageService: unique symbol;
|
|
3
|
+
export interface TokenUsage {
|
|
4
|
+
/** The input token count */
|
|
5
|
+
inputTokens: number;
|
|
6
|
+
/** The output token count */
|
|
7
|
+
outputTokens: number;
|
|
8
|
+
/** The model identifier */
|
|
9
|
+
model: string;
|
|
10
|
+
/** The timestamp of when the tokens were used */
|
|
11
|
+
timestamp: Date;
|
|
12
|
+
/** Request identifier */
|
|
13
|
+
requestId: string;
|
|
14
|
+
}
|
|
15
|
+
export interface TokenUsageParams {
|
|
16
|
+
/** The input token count */
|
|
17
|
+
inputTokens: number;
|
|
18
|
+
/** The output token count */
|
|
19
|
+
outputTokens: number;
|
|
20
|
+
/** Request identifier */
|
|
21
|
+
requestId: string;
|
|
22
|
+
}
|
|
23
|
+
export interface TokenUsageService {
|
|
24
|
+
/**
|
|
25
|
+
* Records token usage for a model interaction.
|
|
26
|
+
*
|
|
27
|
+
* @param model The identifier of the model that was used
|
|
28
|
+
* @param params Object containing token usage information
|
|
29
|
+
* @returns A promise that resolves when the token usage has been recorded
|
|
30
|
+
*/
|
|
31
|
+
recordTokenUsage(model: string, params: TokenUsageParams): Promise<void>;
|
|
32
|
+
getTokenUsages(): Promise<TokenUsage[]>;
|
|
33
|
+
setClient(tokenUsageClient: TokenUsageServiceClient): void;
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=token-usage-service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"token-usage-service.d.ts","sourceRoot":"","sources":["../../src/common/token-usage-service.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,uBAAuB,EAAE,MAAM,YAAY,CAAC;AAErD,eAAO,MAAM,iBAAiB,eAA8B,CAAC;AAE7D,MAAM,WAAW,UAAU;IACvB,4BAA4B;IAC5B,WAAW,EAAE,MAAM,CAAC;IACpB,6BAA6B;IAC7B,YAAY,EAAE,MAAM,CAAC;IACrB,2BAA2B;IAC3B,KAAK,EAAE,MAAM,CAAC;IACd,iDAAiD;IACjD,SAAS,EAAE,IAAI,CAAC;IAChB,yBAAyB;IACzB,SAAS,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,gBAAgB;IAC7B,4BAA4B;IAC5B,WAAW,EAAE,MAAM,CAAC;IACpB,6BAA6B;IAC7B,YAAY,EAAE,MAAM,CAAC;IACrB,yBAAyB;IACzB,SAAS,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,iBAAiB;IAC9B;;;;;;OAMG;IACH,gBAAgB,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEzE,cAAc,IAAI,OAAO,CAAC,UAAU,EAAE,CAAC,CAAC;IAExC,SAAS,CAAC,gBAAgB,EAAE,uBAAuB,GAAG,IAAI,CAAC;CAC9D"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// *****************************************************************************
|
|
3
|
+
// Copyright (C) 2025 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.TokenUsageService = void 0;
|
|
19
|
+
exports.TokenUsageService = Symbol('TokenUsageService');
|
|
20
|
+
//# sourceMappingURL=token-usage-service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"token-usage-service.js","sourceRoot":"","sources":["../../src/common/token-usage-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;;;AAInE,QAAA,iBAAiB,GAAG,MAAM,CAAC,mBAAmB,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ai-core-backend-module.d.ts","sourceRoot":"","sources":["../../src/node/ai-core-backend-module.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;;
|
|
1
|
+
{"version":3,"file":"ai-core-backend-module.d.ts","sourceRoot":"","sources":["../../src/node/ai-core-backend-module.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;;AA6F/D,wBAEG"}
|
|
@@ -21,11 +21,20 @@ const core_1 = require("@theia/core");
|
|
|
21
21
|
const connection_container_module_1 = require("@theia/core/lib/node/messaging/connection-container-module");
|
|
22
22
|
const common_1 = require("../common");
|
|
23
23
|
const backend_language_model_registry_1 = require("./backend-language-model-registry");
|
|
24
|
+
const token_usage_service_impl_1 = require("./token-usage-service-impl");
|
|
24
25
|
// We use a connection module to handle AI services separately for each frontend.
|
|
25
26
|
const aiCoreConnectionModule = connection_container_module_1.ConnectionContainerModule.create(({ bind, bindBackendService, bindFrontendService }) => {
|
|
26
27
|
(0, core_1.bindContributionProvider)(bind, common_1.LanguageModelProvider);
|
|
27
28
|
bind(backend_language_model_registry_1.BackendLanguageModelRegistry).toSelf().inSingletonScope();
|
|
28
29
|
bind(common_1.LanguageModelRegistry).toService(backend_language_model_registry_1.BackendLanguageModelRegistry);
|
|
30
|
+
bind(common_1.TokenUsageService).to(token_usage_service_impl_1.TokenUsageServiceImpl).inSingletonScope();
|
|
31
|
+
bind(core_1.ConnectionHandler)
|
|
32
|
+
.toDynamicValue(({ container }) => new core_1.RpcConnectionHandler(common_1.TOKEN_USAGE_SERVICE_PATH, client => {
|
|
33
|
+
const service = container.get(common_1.TokenUsageService);
|
|
34
|
+
service.setClient(client);
|
|
35
|
+
return service;
|
|
36
|
+
}))
|
|
37
|
+
.inSingletonScope();
|
|
29
38
|
bind(common_1.LanguageModelRegistryFrontendDelegate).to(language_model_frontend_delegate_1.LanguageModelRegistryFrontendDelegateImpl).inSingletonScope();
|
|
30
39
|
bind(core_1.ConnectionHandler)
|
|
31
40
|
.toDynamicValue(ctx => new core_1.RpcConnectionHandler(common_1.languageModelRegistryDelegatePath, client => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ai-core-backend-module.js","sourceRoot":"","sources":["../../src/node/ai-core-backend-module.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;AAChF,4DAA+D;AAC/D,yFAG4C;AAC5C,sCAIqB;AACrB,4GAEoE;AACpE,
|
|
1
|
+
{"version":3,"file":"ai-core-backend-module.js","sourceRoot":"","sources":["../../src/node/ai-core-backend-module.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;AAChF,4DAA+D;AAC/D,yFAG4C;AAC5C,sCAIqB;AACrB,4GAEoE;AACpE,sCAcmB;AACnB,uFAAiF;AACjF,yEAAmE;AAEnE,iFAAiF;AACjF,MAAM,sBAAsB,GAAG,uDAAyB,CAAC,MAAM,CAAC,CAAC,EAAE,IAAI,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,EAAE,EAAE;IAClH,IAAA,+BAAwB,EAAC,IAAI,EAAE,8BAAqB,CAAC,CAAC;IACtD,IAAI,CAAC,8DAA4B,CAAC,CAAC,MAAM,EAAE,CAAC,gBAAgB,EAAE,CAAC;IAC/D,IAAI,CAAC,8BAAqB,CAAC,CAAC,SAAS,CAAC,8DAA4B,CAAC,CAAC;IAEpE,IAAI,CAAC,0BAAiB,CAAC,CAAC,EAAE,CAAC,gDAAqB,CAAC,CAAC,gBAAgB,EAAE,CAAC;IAErE,IAAI,CAAC,wBAAiB,CAAC;SAClB,cAAc,CACX,CAAC,EAAE,SAAS,EAAE,EAAE,EAAE,CACd,IAAI,2BAAoB,CACpB,i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AAC,SAAS,CAAC,0BAAiB,CAAC,CAAC;AACrD,CAAC,CAAC,CAAC;AAEH,kBAAe,IAAI,2BAAe,CAAC,IAAI,CAAC,EAAE;IACtC,IAAI,CAAC,uDAAyB,CAAC,CAAC,eAAe,CAAC,sBAAsB,CAAC,CAAC;AAC5E,CAAC,CAAC,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CancellationToken } from '@theia/core';
|
|
2
|
-
import { LanguageModelMetaData,
|
|
2
|
+
import { LanguageModelMetaData, LanguageModelStreamResponsePart, LanguageModelDelegateClient, LanguageModelFrontendDelegate, LanguageModelRegistryFrontendDelegate, LanguageModelResponseDelegate, LanguageModelRegistryClient, UserRequest } from '../common';
|
|
3
3
|
export declare class LanguageModelRegistryFrontendDelegateImpl implements LanguageModelRegistryFrontendDelegate {
|
|
4
4
|
private registry;
|
|
5
5
|
setClient(client: LanguageModelRegistryClient): void;
|
|
@@ -12,7 +12,7 @@ export declare class LanguageModelFrontendDelegateImpl implements LanguageModelF
|
|
|
12
12
|
private requestCancellationTokenMap;
|
|
13
13
|
setClient(client: LanguageModelDelegateClient): void;
|
|
14
14
|
cancel(requestId: string): void;
|
|
15
|
-
request(modelId: string, request:
|
|
15
|
+
request(modelId: string, request: UserRequest, requestId: string, cancellationToken?: CancellationToken): Promise<LanguageModelResponseDelegate>;
|
|
16
16
|
protected sendTokens(id: string, stream: AsyncIterable<LanguageModelStreamResponsePart>, cancellationToken?: CancellationToken): void;
|
|
17
17
|
}
|
|
18
18
|
//# sourceMappingURL=language-model-frontend-delegate.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"language-model-frontend-delegate.d.ts","sourceRoot":"","sources":["../../src/node/language-model-frontend-delegate.ts"],"names":[],"mappings":"AAiBA,OAAO,EAAE,iBAAiB,EAAkD,MAAM,aAAa,CAAC;AAChG,OAAO,EACH,qBAAqB,
|
|
1
|
+
{"version":3,"file":"language-model-frontend-delegate.d.ts","sourceRoot":"","sources":["../../src/node/language-model-frontend-delegate.ts"],"names":[],"mappings":"AAiBA,OAAO,EAAE,iBAAiB,EAAkD,MAAM,aAAa,CAAC;AAChG,OAAO,EACH,qBAAqB,EAIrB,+BAA+B,EAC/B,2BAA2B,EAC3B,6BAA6B,EAC7B,qCAAqC,EACrC,6BAA6B,EAC7B,2BAA2B,EAE3B,WAAW,EACd,MAAM,WAAW,CAAC;AAGnB,qBACa,yCAA0C,YAAW,qCAAqC;IAGnG,OAAO,CAAC,QAAQ,CAA+B;IAE/C,SAAS,CAAC,MAAM,EAAE,2BAA2B,GAAG,IAAI;IAI9C,4BAA4B,IAAI,OAAO,CAAC,qBAAqB,EAAE,CAAC;CAGzE;AAED,qBACa,iCAAkC,YAAW,6BAA6B;IAGnF,OAAO,CAAC,QAAQ,CAAwB;IAGxC,OAAO,CAAC,MAAM,CAAU;IAExB,OAAO,CAAC,sBAAsB,CAA8B;IAC5D,OAAO,CAAC,2BAA2B,CAAmD;IAEtF,SAAS,CAAC,MAAM,EAAE,2BAA2B,GAAG,IAAI;IAIpD,MAAM,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI;IAIzB,OAAO,CACT,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,WAAW,EACpB,SAAS,EAAE,MAAM,EACjB,iBAAiB,CAAC,EAAE,iBAAiB,GACtC,OAAO,CAAC,6BAA6B,CAAC;IAiCzC,SAAS,CAAC,UAAU,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,aAAa,CAAC,+BAA+B,CAAC,EAAE,iBAAiB,CAAC,EAAE,iBAAiB,GAAG,IAAI;CAexI"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"language-model-frontend-delegate.js","sourceRoot":"","sources":["../../src/node/language-model-frontend-delegate.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,4DAAkE;AAClE,sCAAgG;AAChG,sCAamB;AACnB,uFAAiF;AAG1E,IAAM,yCAAyC,GAA/C,MAAM,yCAAyC;IAKlD,SAAS,CAAC,MAAmC;QACzC,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;IACpC,CAAC;IAED,KAAK,CAAC,4BAA4B;QAC9B,OAAO,CAAC,MAAM,IAAI,CAAC,QAAQ,CAAC,iBAAiB,EAAE,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC,CAAC;IACtG,CAAC;CACJ,CAAA;AAZY,8FAAyC;AAG1C;IADP,IAAA,kBAAM,EAAC,8BAAqB,CAAC;sCACZ,8DAA4B;2EAAC;oDAHtC,yCAAyC;IADrD,IAAA,sBAAU,GAAE;GACA,yCAAyC,CAYrD;AAGM,IAAM,iCAAiC,GAAvC,MAAM,iCAAiC;IAAvC;QASK,gCAA2B,GAAyC,IAAI,GAAG,EAAE,CAAC;IA+D1F,CAAC;IA7DG,SAAS,CAAC,MAAmC;QACzC,IAAI,CAAC,sBAAsB,GAAG,MAAM,CAAC;IACzC,CAAC;IAED,MAAM,CAAC,SAAiB;;QACpB,MAAA,IAAI,CAAC,2BAA2B,CAAC,GAAG,CAAC,SAAS,CAAC,0CAAE,MAAM,EAAE,CAAC;IAC9D,CAAC;IAED,KAAK,CAAC,OAAO,CACT,OAAe,EACf,
|
|
1
|
+
{"version":3,"file":"language-model-frontend-delegate.js","sourceRoot":"","sources":["../../src/node/language-model-frontend-delegate.ts"],"names":[],"mappings":";AAAA,gFAAgF;AAChF,yCAAyC;AACzC,EAAE;AACF,2EAA2E;AAC3E,mEAAmE;AACnE,wCAAwC;AACxC,EAAE;AAC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AAI,KAAK,EAAE,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;oBAC/B,IAAI,CAAC,sBAAsB,CAAC,IAAI,CAAC,EAAE,EAAE,KAAK,CAAC,CAAC;gBAChD,CAAC;YACL,CAAC;YAAC,OAAO,CAAC,EAAE,CAAC;gBACT,IAAI,CAAC,CAAA,iBAAiB,aAAjB,iBAAiB,uBAAjB,iBAAiB,CAAE,uBAAuB,CAAA,EAAE,CAAC;oBAC9C,IAAI,CAAC,sBAAsB,CAAC,KAAK,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;gBAC7C,CAAC;YACL,CAAC;oBAAS,CAAC;gBACP,IAAI,CAAC,sBAAsB,CAAC,IAAI,CAAC,EAAE,EAAE,SAAS,CAAC,CAAC;YACpD,CAAC;QACL,CAAC,CAAC,EAAE,CAAC;IACT,CAAC;CACJ,CAAA;AAxEY,8EAAiC;AAGlC;IADP,IAAA,kBAAM,EAAC,8BAAqB,CAAC;;mEACU;AAGhC;IADP,IAAA,kBAAM,EAAC,cAAO,CAAC;;iEACQ;4CANf,iCAAiC;IAD7C,IAAA,sBAAU,GAAE;GACA,iCAAiC,CAwE7C"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { TokenUsage, TokenUsageParams, TokenUsageService } from '../common/token-usage-service';
|
|
2
|
+
import { TokenUsageServiceClient } from '../common/protocol';
|
|
3
|
+
export declare class TokenUsageServiceImpl implements TokenUsageService {
|
|
4
|
+
private client;
|
|
5
|
+
/**
|
|
6
|
+
* Sets the client to notify about token usage changes
|
|
7
|
+
*/
|
|
8
|
+
setClient(client: TokenUsageServiceClient | undefined): void;
|
|
9
|
+
private readonly tokenUsages;
|
|
10
|
+
/**
|
|
11
|
+
* Records token usage for a model interaction.
|
|
12
|
+
*
|
|
13
|
+
* @param model The model identifier
|
|
14
|
+
* @param params Token usage parameters
|
|
15
|
+
* @returns A promise that resolves when the token usage has been recorded
|
|
16
|
+
*/
|
|
17
|
+
recordTokenUsage(model: string, params: TokenUsageParams): Promise<void>;
|
|
18
|
+
/**
|
|
19
|
+
* Gets all token usage records stored in this service.
|
|
20
|
+
*/
|
|
21
|
+
getTokenUsages(): Promise<TokenUsage[]>;
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=token-usage-service-impl.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"token-usage-service-impl.d.ts","sourceRoot":"","sources":["../../src/node/token-usage-service-impl.ts"],"names":[],"mappings":"AAiBA,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AAChG,OAAO,EAAE,uBAAuB,EAAE,MAAM,oBAAoB,CAAC;AAE7D,qBACa,qBAAsB,YAAW,iBAAiB;IAC3D,OAAO,CAAC,MAAM,CAAsC;IAEpD;;OAEG;IACH,SAAS,CAAC,MAAM,EAAE,uBAAuB,GAAG,SAAS,GAAG,IAAI;IAI5D,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAoB;IAEhD;;;;;;OAMG;IACG,gBAAgB,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC;IAkB9E;;OAEG;IACG,cAAc,IAAI,OAAO,CAAC,UAAU,EAAE,CAAC;CAGhD"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// *****************************************************************************
|
|
3
|
+
// Copyright (C) 2025 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.TokenUsageServiceImpl = void 0;
|
|
19
|
+
const tslib_1 = require("tslib");
|
|
20
|
+
const inversify_1 = require("@theia/core/shared/inversify");
|
|
21
|
+
let TokenUsageServiceImpl = class TokenUsageServiceImpl {
|
|
22
|
+
constructor() {
|
|
23
|
+
this.tokenUsages = [];
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Sets the client to notify about token usage changes
|
|
27
|
+
*/
|
|
28
|
+
setClient(client) {
|
|
29
|
+
this.client = client;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Records token usage for a model interaction.
|
|
33
|
+
*
|
|
34
|
+
* @param model The model identifier
|
|
35
|
+
* @param params Token usage parameters
|
|
36
|
+
* @returns A promise that resolves when the token usage has been recorded
|
|
37
|
+
*/
|
|
38
|
+
async recordTokenUsage(model, params) {
|
|
39
|
+
var _a;
|
|
40
|
+
const usage = {
|
|
41
|
+
inputTokens: params.inputTokens,
|
|
42
|
+
outputTokens: params.outputTokens,
|
|
43
|
+
model,
|
|
44
|
+
timestamp: new Date(),
|
|
45
|
+
requestId: params.requestId
|
|
46
|
+
};
|
|
47
|
+
this.tokenUsages.push(usage);
|
|
48
|
+
(_a = this.client) === null || _a === void 0 ? void 0 : _a.notifyTokenUsage(usage);
|
|
49
|
+
console.log(`Input Tokens: ${params.inputTokens}; Output Tokens: ${params.outputTokens}; Model: ${model}${params.requestId ? `; RequestId: ${params.requestId}` : ''}`);
|
|
50
|
+
// For now we just store in memory
|
|
51
|
+
// In the future, this could be persisted to disk, a database, or sent to a service
|
|
52
|
+
return Promise.resolve();
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Gets all token usage records stored in this service.
|
|
56
|
+
*/
|
|
57
|
+
async getTokenUsages() {
|
|
58
|
+
return [...this.tokenUsages];
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
exports.TokenUsageServiceImpl = TokenUsageServiceImpl;
|
|
62
|
+
exports.TokenUsageServiceImpl = TokenUsageServiceImpl = tslib_1.__decorate([
|
|
63
|
+
(0, inversify_1.injectable)()
|
|
64
|
+
], TokenUsageServiceImpl);
|
|
65
|
+
//# sourceMappingURL=token-usage-service-impl.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"token-usage-service-impl.js","sourceRoot":"","sources":["../../src/node/token-usage-service-impl.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,4DAA0D;AAKnD,IAAM,qBAAqB,GAA3B,MAAM,qBAAqB;IAA3B;QAUc,gBAAW,GAAiB,EAAE,CAAC;IAiCpD,CAAC;IAxCG;;OAEG;IACH,SAAS,CAAC,MAA2C;QACjD,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACzB,CAAC;IAID;;;;;;OAMG;IACH,KAAK,CAAC,gBAAgB,CAAC,KAAa,EAAE,MAAwB;;QAC1D,MAAM,KAAK,GAAe;YACtB,WAAW,EAAE,MAAM,CAAC,WAAW;YAC/B,YAAY,EAAE,MAAM,CAAC,YAAY;YACjC,KAAK;YACL,SAAS,EAAE,IAAI,IAAI,EAAE;YACrB,SAAS,EAAE,MAAM,CAAC,SAAS;SAC9B,CAAC;QAEF,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAC7B,MAAA,IAAI,CAAC,MAAM,0CAAE,gBAAgB,CAAC,KAAK,CAAC,CAAC;QAErC,OAAO,CAAC,GAAG,CAAC,iBAAiB,MAAM,CAAC,WAAW,oBAAoB,MAAM,CAAC,YAAY,YAAY,KAAK,GAAG,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,gBAAgB,MAAM,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;QACxK,kCAAkC;QAClC,mFAAmF;QACnF,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;IAC7B,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,cAAc;QAChB,OAAO,CAAC,GAAG,IAAI,CAAC,WAAW,CAAC,CAAC;IACjC,CAAC;CACJ,CAAA;AA3CY,sDAAqB;gCAArB,qBAAqB;IADjC,IAAA,sBAAU,GAAE;GACA,qBAAqB,CA2CjC"}
|
package/package.json
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@theia/ai-core",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.61.0-next.8+436de3c45",
|
|
4
4
|
"description": "Theia - AI Core",
|
|
5
5
|
"dependencies": {
|
|
6
|
-
"@theia/core": "1.
|
|
7
|
-
"@theia/editor": "1.
|
|
8
|
-
"@theia/filesystem": "1.
|
|
9
|
-
"@theia/monaco": "1.
|
|
6
|
+
"@theia/core": "1.61.0-next.8+436de3c45",
|
|
7
|
+
"@theia/editor": "1.61.0-next.8+436de3c45",
|
|
8
|
+
"@theia/filesystem": "1.61.0-next.8+436de3c45",
|
|
9
|
+
"@theia/monaco": "1.61.0-next.8+436de3c45",
|
|
10
10
|
"@theia/monaco-editor-core": "1.96.302",
|
|
11
|
-
"@theia/output": "1.
|
|
12
|
-
"@theia/variable-resolver": "1.
|
|
13
|
-
"@theia/workspace": "1.
|
|
11
|
+
"@theia/output": "1.61.0-next.8+436de3c45",
|
|
12
|
+
"@theia/variable-resolver": "1.61.0-next.8+436de3c45",
|
|
13
|
+
"@theia/workspace": "1.61.0-next.8+436de3c45",
|
|
14
14
|
"@types/js-yaml": "^4.0.9",
|
|
15
15
|
"js-yaml": "^4.1.0",
|
|
16
16
|
"minimatch": "^5.1.0",
|
|
@@ -52,10 +52,10 @@
|
|
|
52
52
|
"watch": "theiaext watch"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
|
-
"@theia/ext-scripts": "1.60.
|
|
55
|
+
"@theia/ext-scripts": "1.60.0"
|
|
56
56
|
},
|
|
57
57
|
"nyc": {
|
|
58
58
|
"extends": "../../configs/nyc.json"
|
|
59
59
|
},
|
|
60
|
-
"gitHead": "
|
|
60
|
+
"gitHead": "436de3c4571e0000fdcbbf2e94ddfc992f38ccb2"
|
|
61
61
|
}
|
|
@@ -35,7 +35,10 @@ import {
|
|
|
35
35
|
PromptCustomizationService,
|
|
36
36
|
PromptService,
|
|
37
37
|
PromptServiceImpl,
|
|
38
|
-
ToolProvider
|
|
38
|
+
ToolProvider,
|
|
39
|
+
TokenUsageService,
|
|
40
|
+
TOKEN_USAGE_SERVICE_PATH,
|
|
41
|
+
TokenUsageServiceClient
|
|
39
42
|
} from '../common';
|
|
40
43
|
import {
|
|
41
44
|
FrontendLanguageModelRegistryImpl,
|
|
@@ -65,6 +68,8 @@ import { AiCoreCommandContribution } from './ai-core-command-contribution';
|
|
|
65
68
|
import { PromptVariableContribution } from '../common/prompt-variable-contribution';
|
|
66
69
|
import { LanguageModelService } from '../common/language-model-service';
|
|
67
70
|
import { FrontendLanguageModelServiceImpl } from './frontend-language-model-service';
|
|
71
|
+
import { TokenUsageFrontendService } from './token-usage-frontend-service';
|
|
72
|
+
import { TokenUsageFrontendServiceImpl, TokenUsageServiceClientImpl } from './token-usage-frontend-service-impl';
|
|
68
73
|
|
|
69
74
|
export default new ContainerModule(bind => {
|
|
70
75
|
bindContributionProvider(bind, LanguageModelProvider);
|
|
@@ -144,4 +149,13 @@ export default new ContainerModule(bind => {
|
|
|
144
149
|
bind(CommandContribution).toService(AiCoreCommandContribution);
|
|
145
150
|
bind(FrontendLanguageModelServiceImpl).toSelf().inSingletonScope();
|
|
146
151
|
bind(LanguageModelService).toService(FrontendLanguageModelServiceImpl);
|
|
152
|
+
|
|
153
|
+
bind(TokenUsageFrontendService).to(TokenUsageFrontendServiceImpl).inSingletonScope();
|
|
154
|
+
bind(TokenUsageServiceClient).to(TokenUsageServiceClientImpl).inSingletonScope();
|
|
155
|
+
|
|
156
|
+
bind(TokenUsageService).toDynamicValue(ctx => {
|
|
157
|
+
const connection = ctx.container.get<ServiceConnectionProvider>(RemoteConnectionProvider);
|
|
158
|
+
const client = ctx.container.get<TokenUsageServiceClient>(TokenUsageServiceClient);
|
|
159
|
+
return connection.createProxy<TokenUsageService>(TOKEN_USAGE_SERVICE_PATH, client);
|
|
160
|
+
}).inSingletonScope();
|
|
147
161
|
});
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
import { inject, injectable } from '@theia/core/shared/inversify';
|
|
18
18
|
import { GrammarDefinition, GrammarDefinitionProvider, LanguageGrammarDefinitionContribution, TextmateRegistry } from '@theia/monaco/lib/browser/textmate';
|
|
19
19
|
import * as monaco from '@theia/monaco-editor-core';
|
|
20
|
-
import { Command, CommandContribution, CommandRegistry,
|
|
20
|
+
import { Command, CommandContribution, CommandRegistry, nls } from '@theia/core';
|
|
21
21
|
import { TabBarToolbarContribution, TabBarToolbarRegistry } from '@theia/core/lib/browser/shell/tab-bar-toolbar';
|
|
22
22
|
|
|
23
23
|
import { codicon, Widget } from '@theia/core/lib/browser';
|
|
@@ -33,17 +33,10 @@ export const PROMPT_TEMPLATE_EXTENSION = '.prompttemplate';
|
|
|
33
33
|
|
|
34
34
|
export const DISCARD_PROMPT_TEMPLATE_CUSTOMIZATIONS: Command = Command.toLocalizedCommand({
|
|
35
35
|
id: 'theia-ai-prompt-template:discard',
|
|
36
|
+
label: 'Discard AI Prompt Template',
|
|
36
37
|
iconClass: codicon('discard'),
|
|
37
|
-
category: '
|
|
38
|
-
}, '', 'theia/ai/core/prompts/category');
|
|
39
|
-
|
|
40
|
-
// TODO this command is mainly for testing purposes
|
|
41
|
-
export const SHOW_ALL_PROMPTS_COMMAND: Command = Command.toLocalizedCommand({
|
|
42
|
-
id: 'theia-ai-prompt-template:show-prompts-command',
|
|
43
|
-
label: 'Show all prompts',
|
|
44
|
-
iconClass: codicon('beaker'),
|
|
45
|
-
category: 'Theia AI Prompt Templates',
|
|
46
|
-
}, 'theia/ai/core/showAllPrompts/label', 'theia/ai/core/prompts/category');
|
|
38
|
+
category: 'AI Prompt Templates'
|
|
39
|
+
}, 'theia/ai/core/discard/label', 'theia/ai/core/prompts/category');
|
|
47
40
|
|
|
48
41
|
@injectable()
|
|
49
42
|
export class PromptTemplateContribution implements LanguageGrammarDefinitionContribution, CommandContribution, TabBarToolbarContribution {
|
|
@@ -51,9 +44,6 @@ export class PromptTemplateContribution implements LanguageGrammarDefinitionCont
|
|
|
51
44
|
@inject(PromptService)
|
|
52
45
|
private readonly promptService: PromptService;
|
|
53
46
|
|
|
54
|
-
@inject(MessageService)
|
|
55
|
-
private readonly messageService: MessageService;
|
|
56
|
-
|
|
57
47
|
@inject(PromptCustomizationService)
|
|
58
48
|
protected readonly customizationService: PromptCustomizationService;
|
|
59
49
|
|
|
@@ -89,7 +79,7 @@ export class PromptTemplateContribution implements LanguageGrammarDefinitionCont
|
|
|
89
79
|
monaco.languages.register({
|
|
90
80
|
id: PROMPT_TEMPLATE_LANGUAGE_ID,
|
|
91
81
|
'aliases': [
|
|
92
|
-
'
|
|
82
|
+
'AI Prompt Template'
|
|
93
83
|
],
|
|
94
84
|
'extensions': [
|
|
95
85
|
PROMPT_TEMPLATE_EXTENSION,
|
|
@@ -253,10 +243,6 @@ export class PromptTemplateContribution implements LanguageGrammarDefinitionCont
|
|
|
253
243
|
isEnabled: (widget: EditorWidget) => this.canDiscard(widget),
|
|
254
244
|
execute: (widget: EditorWidget) => this.discard(widget)
|
|
255
245
|
});
|
|
256
|
-
|
|
257
|
-
commands.registerCommand(SHOW_ALL_PROMPTS_COMMAND, {
|
|
258
|
-
execute: () => this.showAllPrompts()
|
|
259
|
-
});
|
|
260
246
|
}
|
|
261
247
|
|
|
262
248
|
protected isPromptTemplateWidget(widget: Widget): boolean {
|
|
@@ -311,13 +297,6 @@ export class PromptTemplateContribution implements LanguageGrammarDefinitionCont
|
|
|
311
297
|
});
|
|
312
298
|
}
|
|
313
299
|
|
|
314
|
-
private showAllPrompts(): void {
|
|
315
|
-
const allPrompts = this.promptService.getAllPrompts();
|
|
316
|
-
Object.keys(allPrompts).forEach(id => {
|
|
317
|
-
this.messageService.info(`Prompt Template ID: ${id}\n${allPrompts[id].template}`, 'Got it');
|
|
318
|
-
});
|
|
319
|
-
}
|
|
320
|
-
|
|
321
300
|
registerToolbarItems(registry: TabBarToolbarRegistry): void {
|
|
322
301
|
registry.registerItem({
|
|
323
302
|
id: DISCARD_PROMPT_TEMPLATE_CUSTOMIZATIONS.id,
|
|
@@ -0,0 +1,117 @@
|
|
|
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, inject, postConstruct } from '@theia/core/shared/inversify';
|
|
18
|
+
import { Emitter } from '@theia/core';
|
|
19
|
+
import { ModelTokenUsageData, TokenUsageFrontendService } from './token-usage-frontend-service';
|
|
20
|
+
import { TokenUsage, TokenUsageService } from '../common/token-usage-service';
|
|
21
|
+
import { TokenUsageServiceClient } from '../common/protocol';
|
|
22
|
+
|
|
23
|
+
@injectable()
|
|
24
|
+
export class TokenUsageServiceClientImpl implements TokenUsageServiceClient {
|
|
25
|
+
private readonly _onTokenUsageUpdated = new Emitter<TokenUsage>();
|
|
26
|
+
readonly onTokenUsageUpdated = this._onTokenUsageUpdated.event;
|
|
27
|
+
|
|
28
|
+
notifyTokenUsage(usage: TokenUsage): void {
|
|
29
|
+
this._onTokenUsageUpdated.fire(usage);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
@injectable()
|
|
35
|
+
export class TokenUsageFrontendServiceImpl implements TokenUsageFrontendService {
|
|
36
|
+
|
|
37
|
+
@inject(TokenUsageServiceClient)
|
|
38
|
+
protected readonly tokenUsageServiceClient: TokenUsageServiceClient;
|
|
39
|
+
|
|
40
|
+
@inject(TokenUsageService)
|
|
41
|
+
protected readonly tokenUsageService: TokenUsageService;
|
|
42
|
+
|
|
43
|
+
private readonly _onTokenUsageUpdated = new Emitter<ModelTokenUsageData[]>();
|
|
44
|
+
readonly onTokenUsageUpdated = this._onTokenUsageUpdated.event;
|
|
45
|
+
|
|
46
|
+
private cachedUsageData: ModelTokenUsageData[] = [];
|
|
47
|
+
|
|
48
|
+
@postConstruct()
|
|
49
|
+
protected init(): void {
|
|
50
|
+
this.tokenUsageServiceClient.onTokenUsageUpdated(() => {
|
|
51
|
+
this.getTokenUsageData().then(data => {
|
|
52
|
+
this._onTokenUsageUpdated.fire(data);
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Gets the current token usage data for all models
|
|
59
|
+
*/
|
|
60
|
+
async getTokenUsageData(): Promise<ModelTokenUsageData[]> {
|
|
61
|
+
try {
|
|
62
|
+
const usages = await this.tokenUsageService.getTokenUsages();
|
|
63
|
+
this.cachedUsageData = this.aggregateTokenUsages(usages);
|
|
64
|
+
return this.cachedUsageData;
|
|
65
|
+
} catch (error) {
|
|
66
|
+
console.error('Failed to get token usage data:', error);
|
|
67
|
+
return [];
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Aggregates token usages by model
|
|
73
|
+
*/
|
|
74
|
+
private aggregateTokenUsages(usages: TokenUsage[]): ModelTokenUsageData[] {
|
|
75
|
+
// Group by model
|
|
76
|
+
const modelMap = new Map<string, {
|
|
77
|
+
inputTokens: number;
|
|
78
|
+
outputTokens: number;
|
|
79
|
+
lastUsed?: Date;
|
|
80
|
+
}>();
|
|
81
|
+
|
|
82
|
+
// Process each usage record
|
|
83
|
+
for (const usage of usages) {
|
|
84
|
+
const existing = modelMap.get(usage.model);
|
|
85
|
+
|
|
86
|
+
if (existing) {
|
|
87
|
+
existing.inputTokens += usage.inputTokens;
|
|
88
|
+
existing.outputTokens += usage.outputTokens;
|
|
89
|
+
|
|
90
|
+
// Update last used if this usage is more recent
|
|
91
|
+
if (!existing.lastUsed || (usage.timestamp && usage.timestamp > existing.lastUsed)) {
|
|
92
|
+
existing.lastUsed = usage.timestamp;
|
|
93
|
+
}
|
|
94
|
+
} else {
|
|
95
|
+
modelMap.set(usage.model, {
|
|
96
|
+
inputTokens: usage.inputTokens,
|
|
97
|
+
outputTokens: usage.outputTokens,
|
|
98
|
+
lastUsed: usage.timestamp
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// Convert map to array of model usage data
|
|
104
|
+
const result: ModelTokenUsageData[] = [];
|
|
105
|
+
|
|
106
|
+
for (const [modelId, data] of modelMap.entries()) {
|
|
107
|
+
result.push({
|
|
108
|
+
modelId,
|
|
109
|
+
inputTokens: data.inputTokens,
|
|
110
|
+
outputTokens: data.outputTokens,
|
|
111
|
+
lastUsed: data.lastUsed
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
return result;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
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 { Event } from '@theia/core';
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Data structure for token usage data specific to a model.
|
|
21
|
+
*/
|
|
22
|
+
export interface ModelTokenUsageData {
|
|
23
|
+
/** The model identifier */
|
|
24
|
+
modelId: string;
|
|
25
|
+
/** Number of input tokens used */
|
|
26
|
+
inputTokens: number;
|
|
27
|
+
/** Number of output tokens used */
|
|
28
|
+
outputTokens: number;
|
|
29
|
+
/** Date when the model was last used */
|
|
30
|
+
lastUsed?: Date;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Service for managing token usage data on the frontend.
|
|
35
|
+
*/
|
|
36
|
+
export const TokenUsageFrontendService = Symbol('TokenUsageFrontendService');
|
|
37
|
+
export interface TokenUsageFrontendService {
|
|
38
|
+
/**
|
|
39
|
+
* Event emitted when token usage data is updated
|
|
40
|
+
*/
|
|
41
|
+
readonly onTokenUsageUpdated: Event<ModelTokenUsageData[]>;
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Gets the current token usage data for all models
|
|
45
|
+
*/
|
|
46
|
+
getTokenUsageData(): Promise<ModelTokenUsageData[]>;
|
|
47
|
+
}
|
package/src/common/index.ts
CHANGED
|
@@ -172,7 +172,15 @@ export interface LanguageModelTextResponse {
|
|
|
172
172
|
export const isLanguageModelTextResponse = (obj: unknown): obj is LanguageModelTextResponse =>
|
|
173
173
|
!!(obj && typeof obj === 'object' && 'text' in obj && typeof (obj as { text: unknown }).text === 'string');
|
|
174
174
|
|
|
175
|
-
export type LanguageModelStreamResponsePart = TextResponsePart | ToolCallResponsePart | ThinkingResponsePart;
|
|
175
|
+
export type LanguageModelStreamResponsePart = TextResponsePart | ToolCallResponsePart | ThinkingResponsePart | UsageResponsePart;
|
|
176
|
+
export interface UsageResponsePart {
|
|
177
|
+
input_tokens: number;
|
|
178
|
+
output_tokens: number;
|
|
179
|
+
}
|
|
180
|
+
export const isUsageResponsePart = (part: unknown): part is UsageResponsePart =>
|
|
181
|
+
!!(part && typeof part === 'object' &&
|
|
182
|
+
'input_tokens' in part && typeof part.input_tokens === 'number' &&
|
|
183
|
+
'output_tokens' in part && typeof part.output_tokens === 'number');
|
|
176
184
|
export interface TextResponsePart {
|
|
177
185
|
content: string;
|
|
178
186
|
}
|
|
@@ -242,7 +250,7 @@ export namespace LanguageModelMetaData {
|
|
|
242
250
|
}
|
|
243
251
|
|
|
244
252
|
export interface LanguageModel extends LanguageModelMetaData {
|
|
245
|
-
request(request:
|
|
253
|
+
request(request: UserRequest, cancellationToken?: CancellationToken): Promise<LanguageModelResponse>;
|
|
246
254
|
}
|
|
247
255
|
|
|
248
256
|
export namespace LanguageModel {
|
package/src/common/protocol.ts
CHANGED
|
@@ -14,10 +14,28 @@
|
|
|
14
14
|
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
15
|
// *****************************************************************************
|
|
16
16
|
|
|
17
|
+
import { Event } from '@theia/core';
|
|
17
18
|
import { LanguageModelMetaData } from './language-model';
|
|
19
|
+
import { TokenUsage } from './token-usage-service';
|
|
18
20
|
|
|
19
21
|
export const LanguageModelRegistryClient = Symbol('LanguageModelRegistryClient');
|
|
20
22
|
export interface LanguageModelRegistryClient {
|
|
21
23
|
languageModelAdded(metadata: LanguageModelMetaData): void;
|
|
22
24
|
languageModelRemoved(id: string): void;
|
|
23
25
|
}
|
|
26
|
+
|
|
27
|
+
export const TOKEN_USAGE_SERVICE_PATH = '/services/token-usage';
|
|
28
|
+
|
|
29
|
+
export const TokenUsageServiceClient = Symbol('TokenUsageServiceClient');
|
|
30
|
+
|
|
31
|
+
export interface TokenUsageServiceClient {
|
|
32
|
+
/**
|
|
33
|
+
* Notify the client about new token usage
|
|
34
|
+
*/
|
|
35
|
+
notifyTokenUsage(usage: TokenUsage): void;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* An event that is fired when token usage data is updated.
|
|
39
|
+
*/
|
|
40
|
+
readonly onTokenUsageUpdated: Event<TokenUsage>;
|
|
41
|
+
}
|