@theia/ai-llamafile 1.46.0-next.241
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/README.md +57 -0
- package/lib/browser/llamafile-command-contribution.d.ts +21 -0
- package/lib/browser/llamafile-command-contribution.d.ts.map +1 -0
- package/lib/browser/llamafile-command-contribution.js +104 -0
- package/lib/browser/llamafile-command-contribution.js.map +1 -0
- package/lib/browser/llamafile-frontend-application-contribution.d.ts +18 -0
- package/lib/browser/llamafile-frontend-application-contribution.d.ts.map +1 -0
- package/lib/browser/llamafile-frontend-application-contribution.js +113 -0
- package/lib/browser/llamafile-frontend-application-contribution.js.map +1 -0
- package/lib/browser/llamafile-frontend-module.d.ts +4 -0
- package/lib/browser/llamafile-frontend-module.d.ts.map +1 -0
- package/lib/browser/llamafile-frontend-module.js +46 -0
- package/lib/browser/llamafile-frontend-module.js.map +1 -0
- package/lib/browser/llamafile-preferences.d.ts +7 -0
- package/lib/browser/llamafile-preferences.d.ts.map +1 -0
- package/lib/browser/llamafile-preferences.js +62 -0
- package/lib/browser/llamafile-preferences.js.map +1 -0
- package/lib/common/llamafile-language-model.d.ts +25 -0
- package/lib/common/llamafile-language-model.d.ts.map +1 -0
- package/lib/common/llamafile-language-model.js +122 -0
- package/lib/common/llamafile-language-model.js.map +1 -0
- package/lib/common/llamafile-manager.d.ts +29 -0
- package/lib/common/llamafile-manager.d.ts.map +1 -0
- package/lib/common/llamafile-manager.js +21 -0
- package/lib/common/llamafile-manager.js.map +1 -0
- package/lib/node/llamafile-backend-module.d.ts +4 -0
- package/lib/node/llamafile-backend-module.d.ts.map +1 -0
- package/lib/node/llamafile-backend-module.js +30 -0
- package/lib/node/llamafile-backend-module.js.map +1 -0
- package/lib/node/llamafile-manager-impl.d.ts +18 -0
- package/lib/node/llamafile-manager-impl.d.ts.map +1 -0
- package/lib/node/llamafile-manager-impl.js +123 -0
- package/lib/node/llamafile-manager-impl.js.map +1 -0
- package/lib/package.spec.d.ts +1 -0
- package/lib/package.spec.d.ts.map +1 -0
- package/lib/package.spec.js +26 -0
- package/lib/package.spec.js.map +1 -0
- package/package.json +51 -0
- package/src/browser/llamafile-command-contribution.ts +93 -0
- package/src/browser/llamafile-frontend-application-contribution.ts +126 -0
- package/src/browser/llamafile-frontend-module.ts +45 -0
- package/src/browser/llamafile-preferences.ts +62 -0
- package/src/common/llamafile-language-model.ts +126 -0
- package/src/common/llamafile-manager.ts +42 -0
- package/src/node/llamafile-backend-module.ts +32 -0
- package/src/node/llamafile-manager-impl.ts +129 -0
- package/src/package.spec.ts +27 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"llamafile-language-model.js","sourceRoot":"","sources":["../../src/common/llamafile-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;;;AAIhF,MAAa,sBAAsB;IAK/B;;;;;OAKG;IACH,YACoB,IAAY,EACZ,GAAW,EACX,IAAY,EACrB,sBAAmD;QAH1C,SAAI,GAAJ,IAAI,CAAQ;QACZ,QAAG,GAAH,GAAG,CAAQ;QACX,SAAI,GAAJ,IAAI,CAAQ;QACrB,2BAAsB,GAAtB,sBAAsB,CAA6B;QAbrD,eAAU,GAAG,WAAW,CAAC;QACzB,WAAM,GAAW,SAAS,CAAC;IAahC,CAAC;IAEL,IAAI,EAAE;QACF,OAAO,IAAI,CAAC,IAAI,CAAC;IACrB,CAAC;IACS,WAAW,CAAC,OAA6B;QAC/C,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,sBAAsB,CAAC;QACnF,IAAI,CAAC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,GAAG,CAAC;oCACf,CAAC;oCAAC,OAAO,KAAK,EAAE,CAAC;wCACb,OAAO,CAAC,KAAK,CAAC,qBAAqB,EAAE,KAAK,CAAC,CAAC;wCAC5C,OAAO,GAAG,CAAC;oCACf,CAAC;gCACL,CAAC,EAAE,EAAE,CAAC,CAAC;gCACP,OAAO,EAAE,KAAK,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;4BACtD,CAAC;yBACJ,CAAC;oBACN,CAAC;iBACJ;aACJ,CAAC;QACN,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACb,OAAO,CAAC,KAAK,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;YAC/B,OAAO;gBACH,IAAI,EAAE,UAAU,KAAK,EAAE;aAC1B,CAAC;QACN,CAAC;IACL,CAAC;CAEJ;AA3GD,wDA2GC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export declare const LlamafileManager: unique symbol;
|
|
2
|
+
export declare const LlamafileManagerPath = "/services/llamafilemanager";
|
|
3
|
+
export interface LlamafileModelDescription {
|
|
4
|
+
name: string;
|
|
5
|
+
uri: string;
|
|
6
|
+
port: number;
|
|
7
|
+
/**
|
|
8
|
+
* Default request settings for the Llama model.
|
|
9
|
+
*/
|
|
10
|
+
defaultRequestSettings?: {
|
|
11
|
+
[key: string]: unknown;
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
export interface LlamafileManager {
|
|
15
|
+
startServer(name: string): Promise<void>;
|
|
16
|
+
stopServer(name: string): void;
|
|
17
|
+
getStartedLlamafiles(): Promise<string[]>;
|
|
18
|
+
setClient(client: LlamafileServerManagerClient): void;
|
|
19
|
+
addLanguageModels(llamaFiles: LlamafileModelDescription[]): Promise<void>;
|
|
20
|
+
removeLanguageModels(modelIds: string[]): void;
|
|
21
|
+
updateRequestSettings(modelId: string, requestSettings?: {
|
|
22
|
+
[key: string]: unknown;
|
|
23
|
+
}): void;
|
|
24
|
+
}
|
|
25
|
+
export interface LlamafileServerManagerClient {
|
|
26
|
+
log(llamafileName: string, message: string): void;
|
|
27
|
+
error(llamafileName: string, message: string): void;
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=llamafile-manager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"llamafile-manager.d.ts","sourceRoot":"","sources":["../../src/common/llamafile-manager.ts"],"names":[],"mappings":"AAeA,eAAO,MAAM,gBAAgB,eAA6B,CAAC;AAE3D,eAAO,MAAM,oBAAoB,+BAA+B,CAAC;AAEjE,MAAM,WAAW,yBAAyB;IACtC,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb;;OAEG;IACH,sBAAsB,CAAC,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;KAAE,CAAC;CACvD;AAED,MAAM,WAAW,gBAAgB;IAC7B,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACzC,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,oBAAoB,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;IAC1C,SAAS,CAAC,MAAM,EAAE,4BAA4B,GAAG,IAAI,CAAC;IACtD,iBAAiB,CAAC,UAAU,EAAE,yBAAyB,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC1E,oBAAoB,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC;IAC/C,qBAAqB,CAAC,OAAO,EAAE,MAAM,EAAE,eAAe,CAAC,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;KAAE,GAAG,IAAI,CAAC;CAC9F;AACD,MAAM,WAAW,4BAA4B;IACzC,GAAG,CAAC,aAAa,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IAClD,KAAK,CAAC,aAAa,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;CACvD"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LlamafileManagerPath = exports.LlamafileManager = 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.LlamafileManager = Symbol('LlamafileManager');
|
|
20
|
+
exports.LlamafileManagerPath = '/services/llamafilemanager';
|
|
21
|
+
//# sourceMappingURL=llamafile-manager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"llamafile-manager.js","sourceRoot":"","sources":["../../src/common/llamafile-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,gBAAgB,GAAG,MAAM,CAAC,kBAAkB,CAAC,CAAC;AAE9C,QAAA,oBAAoB,GAAG,4BAA4B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"llamafile-backend-module.d.ts","sourceRoot":"","sources":["../../src/node/llamafile-backend-module.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;;AAK/D,wBAUG"}
|
|
@@ -0,0 +1,30 @@
|
|
|
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 llamafile_manager_impl_1 = require("./llamafile-manager-impl");
|
|
20
|
+
const llamafile_manager_1 = require("../common/llamafile-manager");
|
|
21
|
+
const core_1 = require("@theia/core");
|
|
22
|
+
exports.default = new inversify_1.ContainerModule(bind => {
|
|
23
|
+
bind(llamafile_manager_1.LlamafileManager).to(llamafile_manager_impl_1.LlamafileManagerImpl).inSingletonScope();
|
|
24
|
+
bind(core_1.ConnectionHandler).toDynamicValue(ctx => new core_1.RpcConnectionHandler(llamafile_manager_1.LlamafileManagerPath, client => {
|
|
25
|
+
const service = ctx.container.get(llamafile_manager_1.LlamafileManager);
|
|
26
|
+
service.setClient(client);
|
|
27
|
+
return service;
|
|
28
|
+
})).inSingletonScope();
|
|
29
|
+
});
|
|
30
|
+
//# sourceMappingURL=llamafile-backend-module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"llamafile-backend-module.js","sourceRoot":"","sources":["../../src/node/llamafile-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,qEAAgE;AAChE,mEAAmH;AACnH,sCAAsE;AAEtE,kBAAe,IAAI,2BAAe,CAAC,IAAI,CAAC,EAAE;IACtC,IAAI,CAAC,oCAAgB,CAAC,CAAC,EAAE,CAAC,6CAAoB,CAAC,CAAC,gBAAgB,EAAE,CAAC;IACnE,IAAI,CAAC,wBAAiB,CAAC,CAAC,cAAc,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,2BAAoB,CAClE,wCAAoB,EACpB,MAAM,CAAC,EAAE;QACL,MAAM,OAAO,GAAG,GAAG,CAAC,SAAS,CAAC,GAAG,CAAmB,oCAAgB,CAAC,CAAC;QACtE,OAAO,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;QAC1B,OAAO,OAAO,CAAC;IACnB,CAAC,CACJ,CAAC,CAAC,gBAAgB,EAAE,CAAC;AAC1B,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { LanguageModelRegistry } from '@theia/ai-core';
|
|
2
|
+
import { LlamafileManager, LlamafileModelDescription, LlamafileServerManagerClient } from '../common/llamafile-manager';
|
|
3
|
+
export declare class LlamafileManagerImpl implements LlamafileManager {
|
|
4
|
+
protected languageModelRegistry: LanguageModelRegistry;
|
|
5
|
+
private processMap;
|
|
6
|
+
private client;
|
|
7
|
+
addLanguageModels(LlamafileModelDescriptions: LlamafileModelDescription[]): Promise<void>;
|
|
8
|
+
updateRequestSettings(modelId: string, requestSettings?: {
|
|
9
|
+
[key: string]: unknown;
|
|
10
|
+
}): Promise<void>;
|
|
11
|
+
removeLanguageModels(modelIds: string[]): void;
|
|
12
|
+
getStartedLlamafiles(): Promise<string[]>;
|
|
13
|
+
startServer(name: string): Promise<void>;
|
|
14
|
+
stopServer(name: string): void;
|
|
15
|
+
isStarted(name: string): boolean;
|
|
16
|
+
setClient(client: LlamafileServerManagerClient): void;
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=llamafile-manager-impl.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"llamafile-manager-impl.d.ts","sourceRoot":"","sources":["../../src/node/llamafile-manager-impl.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAC;AAMvD,OAAO,EAAE,gBAAgB,EAAE,yBAAyB,EAAE,4BAA4B,EAAE,MAAM,6BAA6B,CAAC;AAExH,qBACa,oBAAqB,YAAW,gBAAgB;IAGzD,SAAS,CAAC,qBAAqB,EAAE,qBAAqB,CAAC;IAEvD,OAAO,CAAC,UAAU,CAA0D;IAC5E,OAAO,CAAC,MAAM,CAA+B;IAEvC,iBAAiB,CAAC,0BAA0B,EAAE,yBAAyB,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAwBzF,qBAAqB,CAAC,OAAO,EAAE,MAAM,EAAE,eAAe,CAAC,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAY1G,oBAAoB,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,IAAI;IAKxC,oBAAoB,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;IAKzC,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAkC9C,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAQ9B,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAIhC,SAAS,CAAC,MAAM,EAAE,4BAA4B,GAAG,IAAI;CAIxD"}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LlamafileManagerImpl = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
// *****************************************************************************
|
|
6
|
+
// Copyright (C) 2024 EclipseSource GmbH.
|
|
7
|
+
//
|
|
8
|
+
// This program and the accompanying materials are made available under the
|
|
9
|
+
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
10
|
+
// http://www.eclipse.org/legal/epl-2.0.
|
|
11
|
+
//
|
|
12
|
+
// This Source Code may also be made available under the following Secondary
|
|
13
|
+
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
14
|
+
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
15
|
+
// with the GNU Classpath Exception which is available at
|
|
16
|
+
// https://www.gnu.org/software/classpath/license.html.
|
|
17
|
+
//
|
|
18
|
+
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
19
|
+
// *****************************************************************************
|
|
20
|
+
const ai_core_1 = require("@theia/ai-core");
|
|
21
|
+
const inversify_1 = require("@theia/core/shared/inversify");
|
|
22
|
+
const child_process_1 = require("child_process");
|
|
23
|
+
const path_1 = require("path");
|
|
24
|
+
const url_1 = require("url");
|
|
25
|
+
const llamafile_language_model_1 = require("../common/llamafile-language-model");
|
|
26
|
+
let LlamafileManagerImpl = class LlamafileManagerImpl {
|
|
27
|
+
constructor() {
|
|
28
|
+
this.processMap = new Map();
|
|
29
|
+
}
|
|
30
|
+
async addLanguageModels(LlamafileModelDescriptions) {
|
|
31
|
+
for (const llamafile of LlamafileModelDescriptions) {
|
|
32
|
+
const model = await this.languageModelRegistry.getLanguageModel(llamafile.name);
|
|
33
|
+
if (model) {
|
|
34
|
+
if (!(model instanceof llamafile_language_model_1.LlamafileLanguageModel)) {
|
|
35
|
+
console.warn(`Llamafile: model ${model.id} is not a Llamafile model`);
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
// This can happen during the initializing of more than one frontends, changes are handled in the frontend
|
|
40
|
+
console.info(`Llamafile: skip creating or updating model ${llamafile.name} because it already exists.`);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
this.languageModelRegistry.addLanguageModels([
|
|
45
|
+
new llamafile_language_model_1.LlamafileLanguageModel(llamafile.name, llamafile.uri, llamafile.port, llamafile.defaultRequestSettings)
|
|
46
|
+
]);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
async updateRequestSettings(modelId, requestSettings) {
|
|
51
|
+
const model = await this.languageModelRegistry.getLanguageModel(modelId);
|
|
52
|
+
if (model) {
|
|
53
|
+
if (!(model instanceof llamafile_language_model_1.LlamafileLanguageModel)) {
|
|
54
|
+
console.warn(`Llamafile: model ${model.id} is not a Llamafile model`);
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
model.defaultRequestSettings = requestSettings;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
removeLanguageModels(modelIds) {
|
|
63
|
+
modelIds.filter(modelId => this.isStarted(modelId)).forEach(modelId => this.stopServer(modelId));
|
|
64
|
+
this.languageModelRegistry.removeLanguageModels(modelIds);
|
|
65
|
+
}
|
|
66
|
+
async getStartedLlamafiles() {
|
|
67
|
+
const models = await this.languageModelRegistry.getLanguageModels();
|
|
68
|
+
return models.filter(model => model instanceof llamafile_language_model_1.LlamafileLanguageModel && this.isStarted(model.name)).map(model => model.id);
|
|
69
|
+
}
|
|
70
|
+
async startServer(name) {
|
|
71
|
+
if (!this.processMap.has(name)) {
|
|
72
|
+
const models = await this.languageModelRegistry.getLanguageModels();
|
|
73
|
+
const llm = models.find(model => model.id === name && model instanceof llamafile_language_model_1.LlamafileLanguageModel);
|
|
74
|
+
if (llm === undefined) {
|
|
75
|
+
return Promise.reject(`Llamafile ${name} not found`);
|
|
76
|
+
}
|
|
77
|
+
const filePath = (0, url_1.fileURLToPath)(llm.uri);
|
|
78
|
+
// Extract the directory and file name
|
|
79
|
+
const dir = (0, path_1.dirname)(filePath);
|
|
80
|
+
const fileName = (0, path_1.basename)(filePath);
|
|
81
|
+
const currentProcess = (0, child_process_1.spawn)(`./${fileName}`, ['--port', '' + llm.port, '--server', '--nobrowser'], { cwd: dir });
|
|
82
|
+
this.processMap.set(name, currentProcess);
|
|
83
|
+
currentProcess.stdout.on('data', (data) => {
|
|
84
|
+
const output = data.toString();
|
|
85
|
+
this.client.log(name, output);
|
|
86
|
+
});
|
|
87
|
+
currentProcess.stderr.on('data', (data) => {
|
|
88
|
+
const output = data.toString();
|
|
89
|
+
this.client.error(name, output);
|
|
90
|
+
});
|
|
91
|
+
currentProcess.on('close', code => {
|
|
92
|
+
this.client.log(name, `LlamaFile process for file ${name} exited with code ${code}`);
|
|
93
|
+
this.processMap.delete(name);
|
|
94
|
+
});
|
|
95
|
+
currentProcess.on('error', error => {
|
|
96
|
+
this.client.error(name, `Error starting LlamaFile process for file ${name}: ${error.message}`);
|
|
97
|
+
this.processMap.delete(name);
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
stopServer(name) {
|
|
102
|
+
if (this.processMap.has(name)) {
|
|
103
|
+
const currentProcess = this.processMap.get(name);
|
|
104
|
+
currentProcess.kill();
|
|
105
|
+
this.processMap.delete(name);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
isStarted(name) {
|
|
109
|
+
return this.processMap.has(name);
|
|
110
|
+
}
|
|
111
|
+
setClient(client) {
|
|
112
|
+
this.client = client;
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
exports.LlamafileManagerImpl = LlamafileManagerImpl;
|
|
116
|
+
tslib_1.__decorate([
|
|
117
|
+
(0, inversify_1.inject)(ai_core_1.LanguageModelRegistry),
|
|
118
|
+
tslib_1.__metadata("design:type", Object)
|
|
119
|
+
], LlamafileManagerImpl.prototype, "languageModelRegistry", void 0);
|
|
120
|
+
exports.LlamafileManagerImpl = LlamafileManagerImpl = tslib_1.__decorate([
|
|
121
|
+
(0, inversify_1.injectable)()
|
|
122
|
+
], LlamafileManagerImpl);
|
|
123
|
+
//# sourceMappingURL=llamafile-manager-impl.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"llamafile-manager-impl.js","sourceRoot":"","sources":["../../src/node/llamafile-manager-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;AAChF,4CAAuD;AACvD,4DAAkE;AAClE,iDAAsE;AACtE,+BAAyC;AACzC,6BAAoC;AACpC,iFAA4E;AAIrE,IAAM,oBAAoB,GAA1B,MAAM,oBAAoB;IAA1B;QAKK,eAAU,GAAgD,IAAI,GAAG,EAAE,CAAC;IAmGhF,CAAC;IAhGG,KAAK,CAAC,iBAAiB,CAAC,0BAAuD;QAC3E,KAAK,MAAM,SAAS,IAAI,0BAA0B,EAAE,CAAC;YACjD,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,qBAAqB,CAAC,gBAAgB,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;YAChF,IAAI,KAAK,EAAE,CAAC;gBACR,IAAI,CAAC,CAAC,K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AE,CAAC;YACvB,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QACjC,CAAC;IACL,CAAC;IAED,SAAS,CAAC,IAAY;QAClB,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IACrC,CAAC;IAED,SAAS,CAAC,MAAoC;QAC1C,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACzB,CAAC;CAEJ,CAAA;AAxGY,oDAAoB;AAGnB;IADT,IAAA,kBAAM,EAAC,+BAAqB,CAAC;;mEACyB;+BAH9C,oBAAoB;IADhC,IAAA,sBAAU,GAAE;GACA,oBAAoB,CAwGhC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=package.spec.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"package.spec.d.ts","sourceRoot":"","sources":["../src/package.spec.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// *****************************************************************************
|
|
2
|
+
// Copyright (C) 2024 TypeFox GmbH and others.
|
|
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
|
+
/* note: this bogus test file is required so that
|
|
17
|
+
we are able to run mocha unit tests on this
|
|
18
|
+
package, without having any actual unit tests in it.
|
|
19
|
+
This way a coverage report will be generated,
|
|
20
|
+
showing 0% coverage, instead of no report.
|
|
21
|
+
This file can be removed once we have real unit
|
|
22
|
+
tests in place. */
|
|
23
|
+
describe('ai-llamafile package', () => {
|
|
24
|
+
it('support code coverage statistics', () => true);
|
|
25
|
+
});
|
|
26
|
+
//# sourceMappingURL=package.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"package.spec.js","sourceRoot":"","sources":["../src/package.spec.ts"],"names":[],"mappings":"AAAA,gFAAgF;AAChF,8CAA8C;AAC9C,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;;;;;;qBAMqB;AAErB,QAAQ,CAAC,sBAAsB,EAAE,GAAG,EAAE;IAClC,EAAE,CAAC,kCAAkC,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,CAAC;AACvD,CAAC,CAAC,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@theia/ai-llamafile",
|
|
3
|
+
"version": "1.46.0-next.241+4295c1a8c",
|
|
4
|
+
"description": "Theia - Llamafile Integration",
|
|
5
|
+
"dependencies": {
|
|
6
|
+
"@theia/ai-core": "1.46.0-next.241+4295c1a8c",
|
|
7
|
+
"@theia/core": "1.46.0-next.241+4295c1a8c",
|
|
8
|
+
"@theia/output": "1.46.0-next.241+4295c1a8c",
|
|
9
|
+
"tslib": "^2.6.2"
|
|
10
|
+
},
|
|
11
|
+
"publishConfig": {
|
|
12
|
+
"access": "public"
|
|
13
|
+
},
|
|
14
|
+
"theiaExtensions": [
|
|
15
|
+
{
|
|
16
|
+
"frontend": "lib/browser/llamafile-frontend-module",
|
|
17
|
+
"backend": "lib/node/llamafile-backend-module"
|
|
18
|
+
}
|
|
19
|
+
],
|
|
20
|
+
"keywords": [
|
|
21
|
+
"theia-extension"
|
|
22
|
+
],
|
|
23
|
+
"license": "EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0",
|
|
24
|
+
"repository": {
|
|
25
|
+
"type": "git",
|
|
26
|
+
"url": "https://github.com/eclipse-theia/theia.git"
|
|
27
|
+
},
|
|
28
|
+
"bugs": {
|
|
29
|
+
"url": "https://github.com/eclipse-theia/theia/issues"
|
|
30
|
+
},
|
|
31
|
+
"homepage": "https://github.com/eclipse-theia/theia",
|
|
32
|
+
"files": [
|
|
33
|
+
"lib",
|
|
34
|
+
"src"
|
|
35
|
+
],
|
|
36
|
+
"scripts": {
|
|
37
|
+
"build": "theiaext build",
|
|
38
|
+
"clean": "theiaext clean",
|
|
39
|
+
"compile": "theiaext compile",
|
|
40
|
+
"lint": "theiaext lint",
|
|
41
|
+
"test": "theiaext test",
|
|
42
|
+
"watch": "theiaext watch"
|
|
43
|
+
},
|
|
44
|
+
"devDependencies": {
|
|
45
|
+
"@theia/ext-scripts": "1.56.0"
|
|
46
|
+
},
|
|
47
|
+
"nyc": {
|
|
48
|
+
"extends": "../../configs/nyc.json"
|
|
49
|
+
},
|
|
50
|
+
"gitHead": "4295c1a8c8b5d23471f274265c798bac9e6baecc"
|
|
51
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
// *****************************************************************************
|
|
2
|
+
// Copyright (C) 2024 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
|
+
import { AICommandHandlerFactory } from '@theia/ai-core/lib/browser/ai-command-handler-factory';
|
|
17
|
+
import { CommandContribution, CommandRegistry, MessageService } from '@theia/core';
|
|
18
|
+
import { PreferenceService, QuickInputService } from '@theia/core/lib/browser';
|
|
19
|
+
import { inject, injectable } from '@theia/core/shared/inversify';
|
|
20
|
+
import { LlamafileManager } from '../common/llamafile-manager';
|
|
21
|
+
import { PREFERENCE_LLAMAFILE } from './llamafile-preferences';
|
|
22
|
+
import { LlamafileEntry } from './llamafile-frontend-application-contribution';
|
|
23
|
+
|
|
24
|
+
export const StartLlamafileCommand = {
|
|
25
|
+
id: 'llamafile.start',
|
|
26
|
+
label: 'Start Llamafile',
|
|
27
|
+
};
|
|
28
|
+
export const StopLlamafileCommand = {
|
|
29
|
+
id: 'llamafile.stop',
|
|
30
|
+
label: 'Stop Llamafile',
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
@injectable()
|
|
34
|
+
export class LlamafileCommandContribution implements CommandContribution {
|
|
35
|
+
|
|
36
|
+
@inject(QuickInputService)
|
|
37
|
+
protected readonly quickInputService: QuickInputService;
|
|
38
|
+
|
|
39
|
+
@inject(AICommandHandlerFactory)
|
|
40
|
+
protected readonly commandHandlerFactory: AICommandHandlerFactory;
|
|
41
|
+
|
|
42
|
+
@inject(PreferenceService)
|
|
43
|
+
protected preferenceService: PreferenceService;
|
|
44
|
+
|
|
45
|
+
@inject(MessageService)
|
|
46
|
+
protected messageService: MessageService;
|
|
47
|
+
|
|
48
|
+
@inject(LlamafileManager)
|
|
49
|
+
protected llamafileManager: LlamafileManager;
|
|
50
|
+
|
|
51
|
+
registerCommands(commandRegistry: CommandRegistry): void {
|
|
52
|
+
commandRegistry.registerCommand(StartLlamafileCommand, this.commandHandlerFactory({
|
|
53
|
+
execute: async () => {
|
|
54
|
+
try {
|
|
55
|
+
const llamaFiles = this.preferenceService.get<LlamafileEntry[]>(PREFERENCE_LLAMAFILE);
|
|
56
|
+
if (llamaFiles === undefined || llamaFiles.length === 0) {
|
|
57
|
+
this.messageService.error('No Llamafiles configured.');
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
const options = llamaFiles.map(llamaFile => ({ label: llamaFile.name }));
|
|
61
|
+
const result = await this.quickInputService.showQuickPick(options);
|
|
62
|
+
if (result === undefined) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
this.llamafileManager.startServer(result.label);
|
|
66
|
+
} catch (error) {
|
|
67
|
+
console.error('Something went wrong during the llamafile start.', error);
|
|
68
|
+
this.messageService.error(`Something went wrong during the llamafile start: ${error.message}.\nFor more information, see the console.`);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}));
|
|
72
|
+
commandRegistry.registerCommand(StopLlamafileCommand, this.commandHandlerFactory({
|
|
73
|
+
execute: async () => {
|
|
74
|
+
try {
|
|
75
|
+
const llamaFiles = await this.llamafileManager.getStartedLlamafiles();
|
|
76
|
+
if (llamaFiles === undefined || llamaFiles.length === 0) {
|
|
77
|
+
this.messageService.error('No Llamafiles running.');
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
const options = llamaFiles.map(llamaFile => ({ label: llamaFile }));
|
|
81
|
+
const result = await this.quickInputService.showQuickPick(options);
|
|
82
|
+
if (result === undefined) {
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
this.llamafileManager.stopServer(result.label);
|
|
86
|
+
} catch (error) {
|
|
87
|
+
console.error('Something went wrong during the llamafile stop.', error);
|
|
88
|
+
this.messageService.error(`Something went wrong during the llamafile stop: ${error.message}.\nFor more information, see the console.`);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}));
|
|
92
|
+
}
|
|
93
|
+
}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
// *****************************************************************************
|
|
2
|
+
// Copyright (C) 2024 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 { FrontendApplicationContribution, PreferenceService } from '@theia/core/lib/browser';
|
|
18
|
+
import { inject, injectable } from '@theia/core/shared/inversify';
|
|
19
|
+
import { LlamafileManager, LlamafileModelDescription } from '../common/llamafile-manager';
|
|
20
|
+
import { PREFERENCE_LLAMAFILE } from './llamafile-preferences';
|
|
21
|
+
import { PREFERENCE_NAME_REQUEST_SETTINGS, RequestSetting } from '@theia/ai-core/lib/browser/ai-core-preferences';
|
|
22
|
+
|
|
23
|
+
const LLAMAFILE_PROVIDER_ID = 'llamafile';
|
|
24
|
+
@injectable()
|
|
25
|
+
export class LlamafileFrontendApplicationContribution implements FrontendApplicationContribution {
|
|
26
|
+
|
|
27
|
+
@inject(PreferenceService)
|
|
28
|
+
protected preferenceService: PreferenceService;
|
|
29
|
+
|
|
30
|
+
@inject(LlamafileManager)
|
|
31
|
+
protected llamafileManager: LlamafileManager;
|
|
32
|
+
|
|
33
|
+
private _knownLlamaFiles: Map<string, LlamafileEntry> = new Map();
|
|
34
|
+
|
|
35
|
+
onStart(): void {
|
|
36
|
+
this.preferenceService.ready.then(() => {
|
|
37
|
+
const llamafiles = this.preferenceService.get<LlamafileEntry[]>(PREFERENCE_LLAMAFILE, []);
|
|
38
|
+
const validLlamafiles = llamafiles.filter(LlamafileEntry.is);
|
|
39
|
+
|
|
40
|
+
const LlamafileModelDescriptions = this.getLLamaFileModelDescriptions(validLlamafiles);
|
|
41
|
+
|
|
42
|
+
this.llamafileManager.addLanguageModels(LlamafileModelDescriptions);
|
|
43
|
+
validLlamafiles.forEach(model => this._knownLlamaFiles.set(model.name, model));
|
|
44
|
+
|
|
45
|
+
this.preferenceService.onPreferenceChanged(event => {
|
|
46
|
+
if (event.preferenceName === PREFERENCE_LLAMAFILE) {
|
|
47
|
+
const newModels = event.newValue.filter((llamafileEntry: unknown) => LlamafileEntry.is(llamafileEntry)) as LlamafileEntry[];
|
|
48
|
+
this.handleLlamaFilePreferenceChange(newModels);
|
|
49
|
+
} else if (event.preferenceName === PREFERENCE_NAME_REQUEST_SETTINGS) {
|
|
50
|
+
this.handleRequestSettingsChange(event.newValue as RequestSetting[]);
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
protected getLLamaFileModelDescriptions(llamafiles: LlamafileEntry[]): LlamafileModelDescription[] {
|
|
57
|
+
const requestSettings = this.preferenceService.get<RequestSetting[]>(PREFERENCE_NAME_REQUEST_SETTINGS, []);
|
|
58
|
+
return llamafiles.map(llamafile => {
|
|
59
|
+
const matchingSettings = requestSettings.filter(
|
|
60
|
+
setting =>
|
|
61
|
+
(!setting.providerId || setting.providerId === LLAMAFILE_PROVIDER_ID) &&
|
|
62
|
+
setting.modelId === llamafile.name
|
|
63
|
+
);
|
|
64
|
+
if (matchingSettings.length > 1) {
|
|
65
|
+
console.warn(`Multiple entries found for model "${llamafile.name}". Using the first match.`);
|
|
66
|
+
}
|
|
67
|
+
return {
|
|
68
|
+
name: llamafile.name,
|
|
69
|
+
uri: llamafile.uri,
|
|
70
|
+
port: llamafile.port,
|
|
71
|
+
defaultRequestSettings: matchingSettings[0]?.requestSettings
|
|
72
|
+
};
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
protected handleLlamaFilePreferenceChange(newModels: LlamafileEntry[]): void {
|
|
77
|
+
const llamafilesToAdd = newModels.filter(llamafile =>
|
|
78
|
+
!this._knownLlamaFiles.has(llamafile.name) ||
|
|
79
|
+
!LlamafileEntry.equals(this._knownLlamaFiles.get(llamafile.name)!, llamafile));
|
|
80
|
+
|
|
81
|
+
const llamafileIdsToRemove = [...this._knownLlamaFiles.values()].filter(llamafile =>
|
|
82
|
+
!newModels.find(newModel => LlamafileEntry.equals(newModel, llamafile)))
|
|
83
|
+
.map(llamafile => llamafile.name);
|
|
84
|
+
|
|
85
|
+
this.llamafileManager.removeLanguageModels(llamafileIdsToRemove);
|
|
86
|
+
llamafileIdsToRemove.forEach(id => this._knownLlamaFiles.delete(id));
|
|
87
|
+
|
|
88
|
+
this.llamafileManager.addLanguageModels(this.getLLamaFileModelDescriptions(llamafilesToAdd));
|
|
89
|
+
llamafilesToAdd.forEach(model => this._knownLlamaFiles.set(model.name, model));
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
protected handleRequestSettingsChange(newSettings: RequestSetting[]): void {
|
|
93
|
+
const llamafiles = Array.from(this._knownLlamaFiles.values());
|
|
94
|
+
const llamafileModelDescriptions = this.getLLamaFileModelDescriptions(llamafiles);
|
|
95
|
+
llamafileModelDescriptions.forEach(llamafileModelDescription => {
|
|
96
|
+
this.llamafileManager.updateRequestSettings(llamafileModelDescription.name, llamafileModelDescription.defaultRequestSettings);
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export interface LlamafileEntry {
|
|
102
|
+
name: string;
|
|
103
|
+
uri: string;
|
|
104
|
+
port: number;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
namespace LlamafileEntry {
|
|
108
|
+
export function equals(a: LlamafileEntry, b: LlamafileEntry): boolean {
|
|
109
|
+
return (
|
|
110
|
+
a.name === b.name &&
|
|
111
|
+
a.uri === b.uri &&
|
|
112
|
+
a.port === b.port
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export function is(entry: unknown): entry is LlamafileEntry {
|
|
117
|
+
return (
|
|
118
|
+
typeof entry === 'object' &&
|
|
119
|
+
// eslint-disable-next-line no-null/no-null
|
|
120
|
+
entry !== null &&
|
|
121
|
+
'name' in entry && typeof (entry as LlamafileEntry).name === 'string' &&
|
|
122
|
+
'uri' in entry && typeof (entry as LlamafileEntry).uri === 'string' &&
|
|
123
|
+
'port' in entry && typeof (entry as LlamafileEntry).port === 'number'
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// *****************************************************************************
|
|
2
|
+
// Copyright (C) 2024 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
|
+
import { CommandContribution } from '@theia/core';
|
|
17
|
+
import { FrontendApplicationContribution, RemoteConnectionProvider, ServiceConnectionProvider } from '@theia/core/lib/browser';
|
|
18
|
+
import { ContainerModule } from '@theia/core/shared/inversify';
|
|
19
|
+
import { OutputChannelManager, OutputChannelSeverity } from '@theia/output/lib/browser/output-channel';
|
|
20
|
+
import { LlamafileManager, LlamafileManagerPath, LlamafileServerManagerClient } from '../common/llamafile-manager';
|
|
21
|
+
import { LlamafileCommandContribution } from './llamafile-command-contribution';
|
|
22
|
+
import { LlamafileFrontendApplicationContribution } from './llamafile-frontend-application-contribution';
|
|
23
|
+
import { bindAILlamafilePreferences } from './llamafile-preferences';
|
|
24
|
+
|
|
25
|
+
export default new ContainerModule(bind => {
|
|
26
|
+
bind(FrontendApplicationContribution).to(LlamafileFrontendApplicationContribution).inSingletonScope();
|
|
27
|
+
bind(CommandContribution).to(LlamafileCommandContribution).inSingletonScope();
|
|
28
|
+
bind(LlamafileManager).toDynamicValue(ctx => {
|
|
29
|
+
const connection = ctx.container.get<ServiceConnectionProvider>(RemoteConnectionProvider);
|
|
30
|
+
const outputChannelManager = ctx.container.get(OutputChannelManager);
|
|
31
|
+
const client: LlamafileServerManagerClient = {
|
|
32
|
+
error: (llamafileName, message) => {
|
|
33
|
+
const channel = outputChannelManager.getChannel(`${llamafileName}-llamafile`);
|
|
34
|
+
channel.appendLine(message, OutputChannelSeverity.Error);
|
|
35
|
+
},
|
|
36
|
+
log: (llamafileName, message) => {
|
|
37
|
+
const channel = outputChannelManager.getChannel(`${llamafileName}-llamafile`);
|
|
38
|
+
channel.appendLine(message, OutputChannelSeverity.Info);
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
return connection.createProxy<LlamafileManager>(LlamafileManagerPath, client);
|
|
42
|
+
}).inSingletonScope();
|
|
43
|
+
|
|
44
|
+
bindAILlamafilePreferences(bind);
|
|
45
|
+
});
|