@theia/ai-anthropic 1.57.0-next.37

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 (47) hide show
  1. package/README.md +31 -0
  2. package/lib/browser/anthropic-frontend-application-contribution.d.ts +15 -0
  3. package/lib/browser/anthropic-frontend-application-contribution.d.ts.map +1 -0
  4. package/lib/browser/anthropic-frontend-application-contribution.js +99 -0
  5. package/lib/browser/anthropic-frontend-application-contribution.js.map +1 -0
  6. package/lib/browser/anthropic-frontend-module.d.ts +4 -0
  7. package/lib/browser/anthropic-frontend-module.d.ts.map +1 -0
  8. package/lib/browser/anthropic-frontend-module.js +32 -0
  9. package/lib/browser/anthropic-frontend-module.js.map +1 -0
  10. package/lib/browser/anthropic-preferences.d.ts +5 -0
  11. package/lib/browser/anthropic-preferences.d.ts.map +1 -0
  12. package/lib/browser/anthropic-preferences.js +42 -0
  13. package/lib/browser/anthropic-preferences.js.map +1 -0
  14. package/lib/common/anthropic-language-models-manager.d.ts +33 -0
  15. package/lib/common/anthropic-language-models-manager.d.ts.map +1 -0
  16. package/lib/common/anthropic-language-models-manager.js +21 -0
  17. package/lib/common/anthropic-language-models-manager.js.map +1 -0
  18. package/lib/common/index.d.ts +2 -0
  19. package/lib/common/index.d.ts.map +1 -0
  20. package/lib/common/index.js +20 -0
  21. package/lib/common/index.js.map +1 -0
  22. package/lib/node/anthropic-backend-module.d.ts +4 -0
  23. package/lib/node/anthropic-backend-module.d.ts.map +1 -0
  24. package/lib/node/anthropic-backend-module.js +27 -0
  25. package/lib/node/anthropic-backend-module.js.map +1 -0
  26. package/lib/node/anthropic-language-model.d.ts +22 -0
  27. package/lib/node/anthropic-language-model.d.ts.map +1 -0
  28. package/lib/node/anthropic-language-model.js +132 -0
  29. package/lib/node/anthropic-language-model.js.map +1 -0
  30. package/lib/node/anthropic-language-models-manager-impl.d.ts +11 -0
  31. package/lib/node/anthropic-language-models-manager-impl.d.ts.map +1 -0
  32. package/lib/node/anthropic-language-models-manager-impl.js +77 -0
  33. package/lib/node/anthropic-language-models-manager-impl.js.map +1 -0
  34. package/lib/package.spec.d.ts +1 -0
  35. package/lib/package.spec.d.ts.map +1 -0
  36. package/lib/package.spec.js +26 -0
  37. package/lib/package.spec.js.map +1 -0
  38. package/package.json +50 -0
  39. package/src/browser/anthropic-frontend-application-contribution.ts +107 -0
  40. package/src/browser/anthropic-frontend-module.ts +31 -0
  41. package/src/browser/anthropic-preferences.ts +42 -0
  42. package/src/common/anthropic-language-models-manager.ts +45 -0
  43. package/src/common/index.ts +16 -0
  44. package/src/node/anthropic-backend-module.ts +28 -0
  45. package/src/node/anthropic-language-model.ts +172 -0
  46. package/src/node/anthropic-language-models-manager-impl.ts +81 -0
  47. package/src/package.spec.ts +28 -0
package/README.md ADDED
@@ -0,0 +1,31 @@
1
+ <div align='center'>
2
+
3
+ <br />
4
+
5
+ <img src='https://raw.githubusercontent.com/eclipse-theia/theia/master/logo/theia.svg?sanitize=true' alt='theia-ext-logo' width='100px' />
6
+
7
+ <h2>ECLIPSE THEIA - Anthropic EXTENSION</h2>
8
+
9
+ <hr />
10
+
11
+ </div>
12
+
13
+ ## Description
14
+
15
+ The `@theia/anthropic` integrates Anthropic's models with Theia AI.
16
+ The Anthropic API key and the models to use can be configured via preferences.
17
+ Alternatively the API key can also be handed in via the `ANTHROPIC_API_KEY` environment variable.
18
+
19
+ ## Additional Information
20
+
21
+ - [Theia - GitHub](https://github.com/eclipse-theia/theia)
22
+ - [Theia - Website](https://theia-ide.org/)
23
+
24
+ ## License
25
+
26
+ - [Eclipse Public License 2.0](http://www.eclipse.org/legal/epl-2.0/)
27
+ - [一 (Secondary) GNU General Public License, version 2 with the GNU Classpath Exception](https://projects.eclipse.org/license/secondary-gpl-2.0-cp)
28
+
29
+ ## Trademark
30
+ "Theia" is a trademark of the Eclipse Foundation
31
+ https://www.eclipse.org/theia
@@ -0,0 +1,15 @@
1
+ import { FrontendApplicationContribution, PreferenceService } from '@theia/core/lib/browser';
2
+ import { AnthropicLanguageModelsManager, AnthropicModelDescription } from '../common';
3
+ import { RequestSetting } from '@theia/ai-core/lib/browser/ai-core-preferences';
4
+ export declare class AnthropicFrontendApplicationContribution implements FrontendApplicationContribution {
5
+ protected preferenceService: PreferenceService;
6
+ protected manager: AnthropicLanguageModelsManager;
7
+ protected prevModels: string[];
8
+ onStart(): void;
9
+ protected handleModelChanges(newModels: string[]): void;
10
+ private getRequestSettingsPref;
11
+ protected handleRequestSettingsChanges(newSettings: RequestSetting[]): void;
12
+ protected createAnthropicModelDescription(modelId: string, requestSettings: RequestSetting[]): AnthropicModelDescription;
13
+ protected getMatchingRequestSetting(modelId: string, providerId: string, requestSettings: RequestSetting[]): RequestSetting | undefined;
14
+ }
15
+ //# sourceMappingURL=anthropic-frontend-application-contribution.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"anthropic-frontend-application-contribution.d.ts","sourceRoot":"","sources":["../../src/browser/anthropic-frontend-application-contribution.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,+BAA+B,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAE7F,OAAO,EAAE,8BAA8B,EAAE,yBAAyB,EAAE,MAAM,WAAW,CAAC;AAEtF,OAAO,EAAoC,cAAc,EAAE,MAAM,gDAAgD,CAAC;AAIlH,qBACa,wCAAyC,YAAW,+BAA+B;IAG5F,SAAS,CAAC,iBAAiB,EAAE,iBAAiB,CAAC;IAG/C,SAAS,CAAC,OAAO,EAAE,8BAA8B,CAAC;IAElD,SAAS,CAAC,UAAU,EAAE,MAAM,EAAE,CAAM;IAEpC,OAAO,IAAI,IAAI;IAsBf,SAAS,CAAC,kBAAkB,CAAC,SAAS,EAAE,MAAM,EAAE,GAAG,IAAI;IAavD,OAAO,CAAC,sBAAsB;IAI9B,SAAS,CAAC,4BAA4B,CAAC,WAAW,EAAE,cAAc,EAAE,GAAG,IAAI;IAK3E,SAAS,CAAC,+BAA+B,CAAC,OAAO,EAAE,MAAM,EAAE,eAAe,EAAE,cAAc,EAAE,GAAG,yBAAyB;IAYxH,SAAS,CAAC,yBAAyB,CAC/B,OAAO,EAAE,MAAM,EACf,UAAU,EAAE,MAAM,EAClB,eAAe,EAAE,cAAc,EAAE,GAClC,cAAc,GAAG,SAAS;CAWhC"}
@@ -0,0 +1,99 @@
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.AnthropicFrontendApplicationContribution = void 0;
19
+ const tslib_1 = require("tslib");
20
+ const browser_1 = require("@theia/core/lib/browser");
21
+ const inversify_1 = require("@theia/core/shared/inversify");
22
+ const common_1 = require("../common");
23
+ const anthropic_preferences_1 = require("./anthropic-preferences");
24
+ const ai_core_preferences_1 = require("@theia/ai-core/lib/browser/ai-core-preferences");
25
+ const ANTHROPIC_PROVIDER_ID = 'anthropic';
26
+ let AnthropicFrontendApplicationContribution = class AnthropicFrontendApplicationContribution {
27
+ constructor() {
28
+ this.prevModels = [];
29
+ }
30
+ onStart() {
31
+ this.preferenceService.ready.then(() => {
32
+ const apiKey = this.preferenceService.get(anthropic_preferences_1.API_KEY_PREF, undefined);
33
+ this.manager.setApiKey(apiKey);
34
+ const models = this.preferenceService.get(anthropic_preferences_1.MODELS_PREF, []);
35
+ const requestSettings = this.getRequestSettingsPref();
36
+ this.manager.createOrUpdateLanguageModels(...models.map(modelId => this.createAnthropicModelDescription(modelId, requestSettings)));
37
+ this.prevModels = [...models];
38
+ this.preferenceService.onPreferenceChanged(event => {
39
+ if (event.preferenceName === anthropic_preferences_1.API_KEY_PREF) {
40
+ this.manager.setApiKey(event.newValue);
41
+ }
42
+ else if (event.preferenceName === anthropic_preferences_1.MODELS_PREF) {
43
+ this.handleModelChanges(event.newValue);
44
+ }
45
+ else if (event.preferenceName === ai_core_preferences_1.PREFERENCE_NAME_REQUEST_SETTINGS) {
46
+ this.handleRequestSettingsChanges(event.newValue);
47
+ }
48
+ });
49
+ });
50
+ }
51
+ handleModelChanges(newModels) {
52
+ const oldModels = new Set(this.prevModels);
53
+ const updatedModels = new Set(newModels);
54
+ const modelsToRemove = [...oldModels].filter(model => !updatedModels.has(model));
55
+ const modelsToAdd = [...updatedModels].filter(model => !oldModels.has(model));
56
+ this.manager.removeLanguageModels(...modelsToRemove.map(model => `${ANTHROPIC_PROVIDER_ID}/${model}`));
57
+ const requestSettings = this.getRequestSettingsPref();
58
+ this.manager.createOrUpdateLanguageModels(...modelsToAdd.map(modelId => this.createAnthropicModelDescription(modelId, requestSettings)));
59
+ this.prevModels = newModels;
60
+ }
61
+ getRequestSettingsPref() {
62
+ return this.preferenceService.get(ai_core_preferences_1.PREFERENCE_NAME_REQUEST_SETTINGS, []);
63
+ }
64
+ handleRequestSettingsChanges(newSettings) {
65
+ const models = this.preferenceService.get(anthropic_preferences_1.MODELS_PREF, []);
66
+ this.manager.createOrUpdateLanguageModels(...models.map(modelId => this.createAnthropicModelDescription(modelId, newSettings)));
67
+ }
68
+ createAnthropicModelDescription(modelId, requestSettings) {
69
+ const id = `${ANTHROPIC_PROVIDER_ID}/${modelId}`;
70
+ const modelRequestSetting = this.getMatchingRequestSetting(modelId, ANTHROPIC_PROVIDER_ID, requestSettings);
71
+ return {
72
+ id: id,
73
+ model: modelId,
74
+ apiKey: true,
75
+ enableStreaming: true,
76
+ defaultRequestSettings: modelRequestSetting === null || modelRequestSetting === void 0 ? void 0 : modelRequestSetting.requestSettings
77
+ };
78
+ }
79
+ getMatchingRequestSetting(modelId, providerId, requestSettings) {
80
+ const matchingSettings = requestSettings.filter(setting => (!setting.providerId || setting.providerId === providerId) && setting.modelId === modelId);
81
+ if (matchingSettings.length > 1) {
82
+ console.warn(`Multiple entries found for provider "${providerId}" and model "${modelId}". Using the first match.`);
83
+ }
84
+ return matchingSettings[0];
85
+ }
86
+ };
87
+ exports.AnthropicFrontendApplicationContribution = AnthropicFrontendApplicationContribution;
88
+ tslib_1.__decorate([
89
+ (0, inversify_1.inject)(browser_1.PreferenceService),
90
+ tslib_1.__metadata("design:type", Object)
91
+ ], AnthropicFrontendApplicationContribution.prototype, "preferenceService", void 0);
92
+ tslib_1.__decorate([
93
+ (0, inversify_1.inject)(common_1.AnthropicLanguageModelsManager),
94
+ tslib_1.__metadata("design:type", Object)
95
+ ], AnthropicFrontendApplicationContribution.prototype, "manager", void 0);
96
+ exports.AnthropicFrontendApplicationContribution = AnthropicFrontendApplicationContribution = tslib_1.__decorate([
97
+ (0, inversify_1.injectable)()
98
+ ], AnthropicFrontendApplicationContribution);
99
+ //# sourceMappingURL=anthropic-frontend-application-contribution.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"anthropic-frontend-application-contribution.js","sourceRoot":"","sources":["../../src/browser/anthropic-frontend-application-contribution.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,qDAA6F;AAC7F,4DAAkE;AAClE,sCAAsF;AACtF,mEAAoE;AACpE,wFAAkH;AAElH,MAAM,qBAAqB,GAAG,WAAW,CAAC;AAGnC,IAAM,wCAAwC,GAA9C,MAAM,w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,WAAW,CAAC,CAAC,CAAC,CAAC;IACpI,CAAC;IAES,+BAA+B,CAAC,OAAe,EAAE,eAAiC;QACxF,MAAM,EAAE,GAAG,GAAG,qBAAqB,IAAI,OAAO,EAAE,CAAC;QACjD,MAAM,mBAAmB,GAAG,IAAI,CAAC,yBAAyB,CAAC,OAAO,EAAE,qBAAqB,EAAE,eAAe,CAAC,CAAC;QAC5G,OAAO;YACH,EAAE,EAAE,EAAE;YACN,KAAK,EAAE,OAAO;YACd,MAAM,EAAE,IAAI;YACZ,eAAe,EAAE,IAAI;YACrB,sBAAsB,EAAE,mBAAmB,aAAnB,mBAAmB,uBAAnB,mBAAmB,CAAE,eAAe;SAC/D,CAAC;IACN,CAAC;IAES,yBAAyB,CAC/B,OAAe,EACf,UAAkB,EAClB,eAAiC;QAEjC,MAAM,gBAAgB,GAAG,eAAe,CAAC,MAAM,CAC3C,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,UAAU,IAAI,OAAO,CAAC,UAAU,KAAK,UAAU,CAAC,IAAI,OAAO,CAAC,OAAO,KAAK,OAAO,CACvG,CAAC;QACF,IAAI,gBAAgB,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC9B,OAAO,CAAC,IAAI,CACR,wCAAwC,UAAU,gBAAgB,OAAO,2BAA2B,CACvG,CAAC;QACN,CAAC;QACD,OAAO,gBAAgB,CAAC,CAAC,CAAC,CAAC;IAC/B,CAAC;CACJ,CAAA;AAjFY,4FAAwC;AAGvC;IADT,IAAA,kBAAM,EAAC,2BAAiB,CAAC;;mFACqB;AAGrC;IADT,IAAA,kBAAM,EAAC,uCAA8B,CAAC;;yEACW;mDANzC,wCAAwC;IADpD,IAAA,sBAAU,GAAE;GACA,wCAAwC,CAiFpD"}
@@ -0,0 +1,4 @@
1
+ import { ContainerModule } from '@theia/core/shared/inversify';
2
+ declare const _default: ContainerModule;
3
+ export default _default;
4
+ //# sourceMappingURL=anthropic-frontend-module.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"anthropic-frontend-module.d.ts","sourceRoot":"","sources":["../../src/browser/anthropic-frontend-module.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;;AAM/D,wBAQG"}
@@ -0,0 +1,32 @@
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 inversify_1 = require("@theia/core/shared/inversify");
19
+ const anthropic_preferences_1 = require("./anthropic-preferences");
20
+ const browser_1 = require("@theia/core/lib/browser");
21
+ const anthropic_frontend_application_contribution_1 = require("./anthropic-frontend-application-contribution");
22
+ const common_1 = require("../common");
23
+ exports.default = new inversify_1.ContainerModule(bind => {
24
+ bind(browser_1.PreferenceContribution).toConstantValue({ schema: anthropic_preferences_1.AnthropicPreferencesSchema });
25
+ bind(anthropic_frontend_application_contribution_1.AnthropicFrontendApplicationContribution).toSelf().inSingletonScope();
26
+ bind(browser_1.FrontendApplicationContribution).toService(anthropic_frontend_application_contribution_1.AnthropicFrontendApplicationContribution);
27
+ bind(common_1.AnthropicLanguageModelsManager).toDynamicValue(ctx => {
28
+ const provider = ctx.container.get(browser_1.RemoteConnectionProvider);
29
+ return provider.createProxy(common_1.ANTHROPIC_LANGUAGE_MODELS_MANAGER_PATH);
30
+ }).inSingletonScope();
31
+ });
32
+ //# sourceMappingURL=anthropic-frontend-module.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"anthropic-frontend-module.js","sourceRoot":"","sources":["../../src/browser/anthropic-frontend-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;;AAEhF,4DAA+D;AAC/D,mEAAqE;AACrE,qDAAuJ;AACvJ,+GAAyG;AACzG,sCAAmG;AAEnG,kBAAe,IAAI,2BAAe,CAAC,IAAI,CAAC,EAAE;IACtC,IAAI,CAAC,gCAAsB,CAAC,CAAC,eAAe,CAAC,EAAE,MAAM,EAAE,kDAA0B,EAAE,CAAC,CAAC;IACrF,IAAI,CAAC,sFAAwC,CAAC,CAAC,MAAM,EAAE,CAAC,gBAAgB,EAAE,CAAC;IAC3E,IAAI,CAAC,yCAA+B,CAAC,CAAC,SAAS,CAAC,sFAAwC,CAAC,CAAC;IAC1F,IAAI,CAAC,uCAA8B,CAAC,CAAC,cAAc,CAAC,GAAG,CAAC,EAAE;QACtD,MAAM,QAAQ,GAAG,GAAG,CAAC,SAAS,CAAC,GAAG,CAA4B,kCAAwB,CAAC,CAAC;QACxF,OAAO,QAAQ,CAAC,WAAW,CAAiC,+CAAsC,CAAC,CAAC;IACxG,CAAC,CAAC,CAAC,gBAAgB,EAAE,CAAC;AAC1B,CAAC,CAAC,CAAC"}
@@ -0,0 +1,5 @@
1
+ import { PreferenceSchema } from '@theia/core/lib/browser/preferences/preference-contribution';
2
+ export declare const API_KEY_PREF = "ai-features.anthropic.AnthropicApiKey";
3
+ export declare const MODELS_PREF = "ai-features.anthropic.AnthropicModels";
4
+ export declare const AnthropicPreferencesSchema: PreferenceSchema;
5
+ //# sourceMappingURL=anthropic-preferences.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"anthropic-preferences.d.ts","sourceRoot":"","sources":["../../src/browser/anthropic-preferences.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,gBAAgB,EAAE,MAAM,6DAA6D,CAAC;AAG/F,eAAO,MAAM,YAAY,0CAA0C,CAAC;AACpE,eAAO,MAAM,WAAW,0CAA0C,CAAC;AAEnE,eAAO,MAAM,0BAA0B,EAAE,gBAmBxC,CAAC"}
@@ -0,0 +1,42 @@
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.AnthropicPreferencesSchema = exports.MODELS_PREF = exports.API_KEY_PREF = void 0;
19
+ const ai_core_preferences_1 = require("@theia/ai-core/lib/browser/ai-core-preferences");
20
+ exports.API_KEY_PREF = 'ai-features.anthropic.AnthropicApiKey';
21
+ exports.MODELS_PREF = 'ai-features.anthropic.AnthropicModels';
22
+ exports.AnthropicPreferencesSchema = {
23
+ type: 'object',
24
+ properties: {
25
+ [exports.API_KEY_PREF]: {
26
+ type: 'string',
27
+ markdownDescription: 'Enter an API Key of your official Anthropic Account. **Please note:** By using this preference the Anthropic API key will be stored in clear text\
28
+ on the machine running Theia. Use the environment variable `ANTHROPIC_API_KEY` to set the key securely.',
29
+ title: ai_core_preferences_1.AI_CORE_PREFERENCES_TITLE,
30
+ },
31
+ [exports.MODELS_PREF]: {
32
+ type: 'array',
33
+ description: 'Official Anthropic models to use',
34
+ title: ai_core_preferences_1.AI_CORE_PREFERENCES_TITLE,
35
+ default: ['claude-3-5-sonnet-latest', 'claude-3-5-haiku-latest', 'claude-3-opus-latest'],
36
+ items: {
37
+ type: 'string'
38
+ }
39
+ },
40
+ }
41
+ };
42
+ //# sourceMappingURL=anthropic-preferences.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"anthropic-preferences.js","sourceRoot":"","sources":["../../src/browser/anthropic-preferences.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,wFAA2F;AAE9E,QAAA,YAAY,GAAG,uCAAuC,CAAC;AACvD,QAAA,WAAW,GAAG,uCAAuC,CAAC;AAEtD,QAAA,0BAA0B,GAAqB;IACxD,IAAI,EAAE,QAAQ;IACd,UAAU,EAAE;QACR,CAAC,oBAAY,CAAC,EAAE;YACZ,IAAI,EAAE,QAAQ;YACd,mBAAmB,EAAE;oHACmF;YACxG,KAAK,EAAE,+CAAyB;SACnC;QACD,CAAC,mBAAW,CAAC,EAAE;YACX,IAAI,EAAE,OAAO;YACb,WAAW,EAAE,kCAAkC;YAC/C,KAAK,EAAE,+CAAyB;YAChC,OAAO,EAAE,CAAC,0BAA0B,EAAE,yBAAyB,EAAE,sBAAsB,CAAC;YACxF,KAAK,EAAE;gBACH,IAAI,EAAE,QAAQ;aACjB;SACJ;KACJ;CACJ,CAAC"}
@@ -0,0 +1,33 @@
1
+ export declare const ANTHROPIC_LANGUAGE_MODELS_MANAGER_PATH = "/services/anthropic/language-model-manager";
2
+ export declare const AnthropicLanguageModelsManager: unique symbol;
3
+ export interface AnthropicModelDescription {
4
+ /**
5
+ * The identifier of the model which will be shown in the UI.
6
+ */
7
+ id: string;
8
+ /**
9
+ * The model ID as used by the Anthropic API.
10
+ */
11
+ model: string;
12
+ /**
13
+ * The key for the model. If 'true' is provided the global Anthropic API key will be used.
14
+ */
15
+ apiKey: string | true | undefined;
16
+ /**
17
+ * Indicate whether the streaming API shall be used.
18
+ */
19
+ enableStreaming: boolean;
20
+ /**
21
+ * Default request settings for the Anthropic model.
22
+ */
23
+ defaultRequestSettings?: {
24
+ [key: string]: unknown;
25
+ };
26
+ }
27
+ export interface AnthropicLanguageModelsManager {
28
+ apiKey: string | undefined;
29
+ setApiKey(key: string | undefined): void;
30
+ createOrUpdateLanguageModels(...models: AnthropicModelDescription[]): Promise<void>;
31
+ removeLanguageModels(...modelIds: string[]): void;
32
+ }
33
+ //# sourceMappingURL=anthropic-language-models-manager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"anthropic-language-models-manager.d.ts","sourceRoot":"","sources":["../../src/common/anthropic-language-models-manager.ts"],"names":[],"mappings":"AAeA,eAAO,MAAM,sCAAsC,+CAA+C,CAAC;AACnG,eAAO,MAAM,8BAA8B,eAA2C,CAAC;AACvF,MAAM,WAAW,yBAAyB;IACtC;;OAEG;IACH,EAAE,EAAE,MAAM,CAAC;IACX;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IACd;;OAEG;IACH,MAAM,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;IAClC;;OAEG;IACH,eAAe,EAAE,OAAO,CAAC;IACzB;;OAEG;IACH,sBAAsB,CAAC,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;KAAE,CAAC;CACvD;AACD,MAAM,WAAW,8BAA8B;IAC3C,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;IAC3B,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,CAAC;IACzC,4BAA4B,CAAC,GAAG,MAAM,EAAE,yBAAyB,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACpF,oBAAoB,CAAC,GAAG,QAAQ,EAAE,MAAM,EAAE,GAAG,IAAI,CAAA;CACpD"}
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AnthropicLanguageModelsManager = exports.ANTHROPIC_LANGUAGE_MODELS_MANAGER_PATH = void 0;
4
+ // *****************************************************************************
5
+ // Copyright (C) 2024 EclipseSource GmbH.
6
+ //
7
+ // This program and the accompanying materials are made available under the
8
+ // terms of the Eclipse Public License v. 2.0 which is available at
9
+ // http://www.eclipse.org/legal/epl-2.0.
10
+ //
11
+ // This Source Code may also be made available under the following Secondary
12
+ // Licenses when the conditions for such availability set forth in the Eclipse
13
+ // Public License v. 2.0 are satisfied: GNU General Public License, version 2
14
+ // with the GNU Classpath Exception which is available at
15
+ // https://www.gnu.org/software/classpath/license.html.
16
+ //
17
+ // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
18
+ // *****************************************************************************
19
+ exports.ANTHROPIC_LANGUAGE_MODELS_MANAGER_PATH = '/services/anthropic/language-model-manager';
20
+ exports.AnthropicLanguageModelsManager = Symbol('AnthropicLanguageModelsManager');
21
+ //# sourceMappingURL=anthropic-language-models-manager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"anthropic-language-models-manager.js","sourceRoot":"","sources":["../../src/common/anthropic-language-models-manager.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;AACnE,QAAA,sCAAsC,GAAG,4CAA4C,CAAC;AACtF,QAAA,8BAA8B,GAAG,MAAM,CAAC,gCAAgC,CAAC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from './anthropic-language-models-manager';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/common/index.ts"],"names":[],"mappings":"AAeA,cAAc,qCAAqC,CAAC"}
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ // *****************************************************************************
5
+ // Copyright (C) 2024 EclipseSource GmbH.
6
+ //
7
+ // This program and the accompanying materials are made available under the
8
+ // terms of the Eclipse Public License v. 2.0 which is available at
9
+ // http://www.eclipse.org/legal/epl-2.0.
10
+ //
11
+ // This Source Code may also be made available under the following Secondary
12
+ // Licenses when the conditions for such availability set forth in the Eclipse
13
+ // Public License v. 2.0 are satisfied: GNU General Public License, version 2
14
+ // with the GNU Classpath Exception which is available at
15
+ // https://www.gnu.org/software/classpath/license.html.
16
+ //
17
+ // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
18
+ // *****************************************************************************
19
+ tslib_1.__exportStar(require("./anthropic-language-models-manager"), exports);
20
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/common/index.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,8EAAoD"}
@@ -0,0 +1,4 @@
1
+ import { ContainerModule } from '@theia/core/shared/inversify';
2
+ declare const _default: ContainerModule;
3
+ export default _default;
4
+ //# sourceMappingURL=anthropic-backend-module.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"anthropic-backend-module.d.ts","sourceRoot":"","sources":["../../src/node/anthropic-backend-module.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;;AAK/D,wBAMG"}
@@ -0,0 +1,27 @@
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 inversify_1 = require("@theia/core/shared/inversify");
19
+ const anthropic_language_models_manager_1 = require("../common/anthropic-language-models-manager");
20
+ const core_1 = require("@theia/core");
21
+ const anthropic_language_models_manager_impl_1 = require("./anthropic-language-models-manager-impl");
22
+ exports.default = new inversify_1.ContainerModule(bind => {
23
+ bind(anthropic_language_models_manager_impl_1.AnthropicLanguageModelsManagerImpl).toSelf().inSingletonScope();
24
+ bind(anthropic_language_models_manager_1.AnthropicLanguageModelsManager).toService(anthropic_language_models_manager_impl_1.AnthropicLanguageModelsManagerImpl);
25
+ bind(core_1.ConnectionHandler).toDynamicValue(ctx => new core_1.RpcConnectionHandler(anthropic_language_models_manager_1.ANTHROPIC_LANGUAGE_MODELS_MANAGER_PATH, () => ctx.container.get(anthropic_language_models_manager_1.AnthropicLanguageModelsManager))).inSingletonScope();
26
+ });
27
+ //# sourceMappingURL=anthropic-backend-module.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"anthropic-backend-module.js","sourceRoot":"","sources":["../../src/node/anthropic-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;;AAEhF,4DAA+D;AAC/D,mGAAqI;AACrI,sCAAsE;AACtE,qGAA8F;AAE9F,kBAAe,IAAI,2BAAe,CAAC,IAAI,CAAC,EAAE;IACtC,IAAI,CAAC,2EAAkC,CAAC,CAAC,MAAM,EAAE,CAAC,gBAAgB,EAAE,CAAC;IACrE,IAAI,CAAC,kEAA8B,CAAC,CAAC,SAAS,CAAC,2EAAkC,CAAC,CAAC;IACnF,IAAI,CAAC,wBAAiB,CAAC,CAAC,cAAc,CAAC,GAAG,CAAC,EAAE,CACzC,IAAI,2BAAoB,CAAC,0EAAsC,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,SAAS,CAAC,GAAG,CAAC,kEAA8B,CAAC,CAAC,CAC5H,CAAC,gBAAgB,EAAE,CAAC;AACzB,CAAC,CAAC,CAAC"}
@@ -0,0 +1,22 @@
1
+ import { LanguageModel, LanguageModelRequest, LanguageModelResponse, LanguageModelStreamResponse, LanguageModelTextResponse } from '@theia/ai-core';
2
+ import { CancellationToken } from '@theia/core';
3
+ import { Anthropic } from '@anthropic-ai/sdk';
4
+ export declare const AnthropicModelIdentifier: unique symbol;
5
+ export declare class AnthropicModel implements LanguageModel {
6
+ readonly id: string;
7
+ model: string;
8
+ enableStreaming: boolean;
9
+ apiKey: () => string | undefined;
10
+ defaultRequestSettings?: {
11
+ [key: string]: unknown;
12
+ } | undefined;
13
+ constructor(id: string, model: string, enableStreaming: boolean, apiKey: () => string | undefined, defaultRequestSettings?: {
14
+ [key: string]: unknown;
15
+ } | undefined);
16
+ protected getSettings(request: LanguageModelRequest): Record<string, unknown>;
17
+ request(request: LanguageModelRequest, cancellationToken?: CancellationToken): Promise<LanguageModelResponse>;
18
+ protected handleStreamingRequest(anthropic: Anthropic, request: LanguageModelRequest, cancellationToken?: CancellationToken): Promise<LanguageModelStreamResponse>;
19
+ protected handleNonStreamingRequest(anthropic: Anthropic, request: LanguageModelRequest): Promise<LanguageModelTextResponse>;
20
+ protected initializeAnthropic(): Anthropic;
21
+ }
22
+ //# sourceMappingURL=anthropic-language-model.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"anthropic-language-model.d.ts","sourceRoot":"","sources":["../../src/node/anthropic-language-model.ts"],"names":[],"mappings":"AAgBA,OAAO,EACH,aAAa,EACb,oBAAoB,EAEpB,qBAAqB,EACrB,2BAA2B,EAE3B,yBAAyB,EAC5B,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAG9C,eAAO,MAAM,wBAAwB,eAAqC,CAAC;AA+B3E,qBAAa,cAAe,YAAW,aAAa;aAG5B,EAAE,EAAE,MAAM;IACnB,KAAK,EAAE,MAAM;IACb,eAAe,EAAE,OAAO;IACxB,MAAM,EAAE,MAAM,MAAM,GAAG,SAAS;IAChC,sBAAsB,CAAC;;;gBAJd,EAAE,EAAE,MAAM,EACnB,KAAK,EAAE,MAAM,EACb,eAAe,EAAE,OAAO,EACxB,MAAM,EAAE,MAAM,MAAM,GAAG,SAAS,EAChC,sBAAsB,CAAC;;iBAA4B;IAG9D,SAAS,CAAC,WAAW,CAAC,OAAO,EAAE,oBAAoB,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAQvE,OAAO,CAAC,OAAO,EAAE,oBAAoB,EAAE,iBAAiB,CAAC,EAAE,iBAAiB,GAAG,OAAO,CAAC,qBAAqB,CAAC;cAQnG,sBAAsB,CAClC,SAAS,EAAE,SAAS,EACpB,OAAO,EAAE,oBAAoB,EAC7B,iBAAiB,CAAC,EAAE,iBAAiB,GACtC,OAAO,CAAC,2BAA2B,CAAC;cA6CvB,yBAAyB,CACrC,SAAS,EAAE,SAAS,EACpB,OAAO,EAAE,oBAAoB,GAC9B,OAAO,CAAC,yBAAyB,CAAC;IAyBrC,SAAS,CAAC,mBAAmB,IAAI,SAAS;CAQ7C"}
@@ -0,0 +1,132 @@
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.AnthropicModel = exports.AnthropicModelIdentifier = void 0;
19
+ const sdk_1 = require("@anthropic-ai/sdk");
20
+ exports.AnthropicModelIdentifier = Symbol('AnthropicModelIdentifier');
21
+ function transformToAnthropicParams(messages) {
22
+ // Extract the system message (if any), as it is a separate parameter in the Anthropic API.
23
+ const systemMessageObj = messages.find(message => message.actor === 'system');
24
+ const systemMessage = systemMessageObj === null || systemMessageObj === void 0 ? void 0 : systemMessageObj.query;
25
+ const convertedMessages = messages
26
+ .filter(message => message.actor !== 'system')
27
+ .map(message => ({
28
+ role: toAnthropicRole(message),
29
+ content: message.query || '',
30
+ }));
31
+ return {
32
+ messages: convertedMessages,
33
+ systemMessage,
34
+ };
35
+ }
36
+ function toAnthropicRole(message) {
37
+ switch (message.actor) {
38
+ case 'ai':
39
+ return 'assistant';
40
+ default:
41
+ return 'user';
42
+ }
43
+ }
44
+ class AnthropicModel {
45
+ constructor(id, model, enableStreaming, apiKey, defaultRequestSettings) {
46
+ this.id = id;
47
+ this.model = model;
48
+ this.enableStreaming = enableStreaming;
49
+ this.apiKey = apiKey;
50
+ this.defaultRequestSettings = defaultRequestSettings;
51
+ }
52
+ getSettings(request) {
53
+ const settings = request.settings ? request.settings : this.defaultRequestSettings;
54
+ if (!settings) {
55
+ return {};
56
+ }
57
+ return settings;
58
+ }
59
+ async request(request, cancellationToken) {
60
+ const anthropic = this.initializeAnthropic();
61
+ if (this.enableStreaming) {
62
+ return this.handleStreamingRequest(anthropic, request, cancellationToken);
63
+ }
64
+ return this.handleNonStreamingRequest(anthropic, request);
65
+ }
66
+ async handleStreamingRequest(anthropic, request, cancellationToken) {
67
+ const settings = this.getSettings(request);
68
+ const { messages, systemMessage } = transformToAnthropicParams(request.messages);
69
+ const params = {
70
+ max_tokens: 2048, // Setting max_tokens is mandatory for Anthropic, settings can override this default
71
+ messages,
72
+ model: this.model,
73
+ ...(systemMessage && { system: systemMessage }),
74
+ ...settings
75
+ };
76
+ const stream = anthropic.messages.stream(params);
77
+ cancellationToken === null || cancellationToken === void 0 ? void 0 : cancellationToken.onCancellationRequested(() => {
78
+ stream.abort();
79
+ });
80
+ const asyncIterator = {
81
+ async *[Symbol.asyncIterator]() {
82
+ for await (const event of stream) {
83
+ if (event.type === 'content_block_start') {
84
+ const contentBlock = event.content_block;
85
+ if (contentBlock.type === 'text') {
86
+ yield { content: contentBlock.text };
87
+ }
88
+ }
89
+ else if (event.type === 'content_block_delta') {
90
+ const delta = event.delta;
91
+ if (delta.type === 'text_delta') {
92
+ yield { content: delta.text };
93
+ }
94
+ }
95
+ }
96
+ },
97
+ };
98
+ stream.on('error', (error) => {
99
+ console.error('Error in Anthropic streaming:', error);
100
+ });
101
+ return { stream: asyncIterator };
102
+ }
103
+ async handleNonStreamingRequest(anthropic, request) {
104
+ const settings = this.getSettings(request);
105
+ const { messages, systemMessage } = transformToAnthropicParams(request.messages);
106
+ const params = {
107
+ max_tokens: 2048,
108
+ messages,
109
+ model: this.model,
110
+ ...(systemMessage && { system: systemMessage }),
111
+ ...settings,
112
+ };
113
+ const response = await anthropic.messages.create(params);
114
+ if (response.content[0] && response.content[0].type === 'text') {
115
+ return {
116
+ text: response.content[0].text,
117
+ };
118
+ }
119
+ return {
120
+ text: '',
121
+ };
122
+ }
123
+ initializeAnthropic() {
124
+ const apiKey = this.apiKey();
125
+ if (!apiKey) {
126
+ throw new Error('Please provide ANTHROPIC_API_KEY in preferences or via environment variable');
127
+ }
128
+ return new sdk_1.Anthropic({ apiKey: apiKey });
129
+ }
130
+ }
131
+ exports.AnthropicModel = AnthropicModel;
132
+ //# sourceMappingURL=anthropic-language-model.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"anthropic-language-model.js","sourceRoot":"","sources":["../../src/node/anthropic-language-model.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;;;AAYhF,2CAA8C;AAGjC,QAAA,wBAAwB,GAAG,MAAM,CAAC,0BAA0B,CAAC,CAAC;AAE3E,SAAS,0BAA0B,CAC/B,QAAuC;IAEvC,2FAA2F;IAC3F,MAAM,gBAAgB,GAAG,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,OAAO,CAAC,KAAK,KAAK,QAAQ,CAAC,CAAC;IAC9E,MAAM,aAAa,GAAG,gBAAgB,aAAhB,gBAAgB,uBAAhB,gBAAgB,CAAE,KAAK,CAAC;IAE9C,MAAM,iBAAiB,GAAG,QAAQ;SAC7B,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC,OAAO,CAAC,KAAK,KAAK,QAAQ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AAC,MAAM,EAAE,CAAC;YACV,MAAM,IAAI,KAAK,CAAC,6EAA6E,CAAC,CAAC;QACnG,CAAC;QAED,OAAO,IAAI,eAAS,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;IAC7C,CAAC;CACJ;AA/GD,wCA+GC"}
@@ -0,0 +1,11 @@
1
+ import { LanguageModelRegistry } from '@theia/ai-core';
2
+ import { AnthropicLanguageModelsManager, AnthropicModelDescription } from '../common';
3
+ export declare class AnthropicLanguageModelsManagerImpl implements AnthropicLanguageModelsManager {
4
+ protected _apiKey: string | undefined;
5
+ protected readonly languageModelRegistry: LanguageModelRegistry;
6
+ get apiKey(): string | undefined;
7
+ createOrUpdateLanguageModels(...modelDescriptions: AnthropicModelDescription[]): Promise<void>;
8
+ removeLanguageModels(...modelIds: string[]): void;
9
+ setApiKey(apiKey: string | undefined): void;
10
+ }
11
+ //# sourceMappingURL=anthropic-language-models-manager-impl.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"anthropic-language-models-manager-impl.d.ts","sourceRoot":"","sources":["../../src/node/anthropic-language-models-manager-impl.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAC;AAGvD,OAAO,EAAE,8BAA8B,EAAE,yBAAyB,EAAE,MAAM,WAAW,CAAC;AAEtF,qBACa,kCAAmC,YAAW,8BAA8B;IAErF,SAAS,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;IAGtC,SAAS,CAAC,QAAQ,CAAC,qBAAqB,EAAE,qBAAqB,CAAC;IAEhE,IAAI,MAAM,IAAI,MAAM,GAAG,SAAS,CAE/B;IAEK,4BAA4B,CAAC,GAAG,iBAAiB,EAAE,yBAAyB,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAoCpG,oBAAoB,CAAC,GAAG,QAAQ,EAAE,MAAM,EAAE,GAAG,IAAI;IAIjD,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI;CAO9C"}