@crowdin/app-project-module 0.50.1 → 0.51.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/out/index.js +2 -0
- package/out/modules/ai-provider/handlers/chat-completions.d.ts +5 -0
- package/out/modules/ai-provider/handlers/chat-completions.js +53 -0
- package/out/modules/ai-provider/handlers/get-model-list.d.ts +5 -0
- package/out/modules/ai-provider/handlers/get-model-list.js +31 -0
- package/out/modules/ai-provider/index.d.ts +6 -0
- package/out/modules/ai-provider/index.js +25 -0
- package/out/modules/ai-provider/types.d.ts +41 -0
- package/out/modules/ai-provider/types.js +2 -0
- package/out/modules/manifest.js +8 -0
- package/out/types.d.ts +5 -0
- package/package.json +2 -2
package/out/index.js
CHANGED
|
@@ -60,6 +60,7 @@ const apiApp = __importStar(require("./modules/api"));
|
|
|
60
60
|
const contextMenuApp = __importStar(require("./modules/context-menu"));
|
|
61
61
|
const customMTApp = __importStar(require("./modules/custom-mt"));
|
|
62
62
|
const spellCheckApp = __importStar(require("./modules/custom-spell-check"));
|
|
63
|
+
const aiProvider = __importStar(require("./modules/ai-provider"));
|
|
63
64
|
const editorRightPanelApp = __importStar(require("./modules/editor-right-panel"));
|
|
64
65
|
const editorThemesApp = __importStar(require("./modules/editor-themes"));
|
|
65
66
|
const fileProcessingApps = __importStar(require("./modules/file-processing"));
|
|
@@ -163,6 +164,7 @@ function addCrowdinEndpoints(app, clientConfig) {
|
|
|
163
164
|
fileProcessingApps.registerFilePreExport({ config, app });
|
|
164
165
|
fileProcessingApps.registerFilePostExport({ config, app });
|
|
165
166
|
apiApp.register({ config, app });
|
|
167
|
+
aiProvider.register({ config, app });
|
|
166
168
|
addFormSchema({ config, app });
|
|
167
169
|
return Object.assign(Object.assign({}, exports.metadataStore), { establishCrowdinConnection: (authRequest) => {
|
|
168
170
|
let jwtToken = '';
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/// <reference types="qs" />
|
|
2
|
+
import { Response } from 'express';
|
|
3
|
+
import { CrowdinClientRequest } from '../../../types';
|
|
4
|
+
import { AiProviderModule } from '../types';
|
|
5
|
+
export default function handle(aiProvider: AiProviderModule): (req: CrowdinClientRequest | import("express").Request<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs, Record<string, any>>, res: Response<any, Record<string, any>>, next: Function) => void;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const util_1 = require("../../../util");
|
|
13
|
+
const logger_1 = require("../../../util/logger");
|
|
14
|
+
const files_1 = require("../../integration/util/files");
|
|
15
|
+
function handle(aiProvider) {
|
|
16
|
+
return (0, util_1.runAsyncWrapper)((req, res) => __awaiter(this, void 0, void 0, function* () {
|
|
17
|
+
try {
|
|
18
|
+
let choices;
|
|
19
|
+
let message;
|
|
20
|
+
let data;
|
|
21
|
+
const result = yield aiProvider.chatCompletions({
|
|
22
|
+
messages: req.body.messages,
|
|
23
|
+
model: req.body.model,
|
|
24
|
+
client: req.crowdinApiClient,
|
|
25
|
+
context: req.crowdinContext,
|
|
26
|
+
req,
|
|
27
|
+
});
|
|
28
|
+
if ((0, files_1.isExtendedResultType)(result)) {
|
|
29
|
+
data = result.data;
|
|
30
|
+
message = result.message;
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
data = result;
|
|
34
|
+
}
|
|
35
|
+
if (data && data.length > 0) {
|
|
36
|
+
choices = data.map((message) => ({
|
|
37
|
+
message: {
|
|
38
|
+
role: message.role || 'assistant',
|
|
39
|
+
content: message.content,
|
|
40
|
+
},
|
|
41
|
+
}));
|
|
42
|
+
}
|
|
43
|
+
res.send({ choices, message });
|
|
44
|
+
}
|
|
45
|
+
catch (e) {
|
|
46
|
+
if (req.logError) {
|
|
47
|
+
req.logError(e);
|
|
48
|
+
}
|
|
49
|
+
res.send({ error: { message: (0, logger_1.getErrorMessage)(e) } });
|
|
50
|
+
}
|
|
51
|
+
}));
|
|
52
|
+
}
|
|
53
|
+
exports.default = handle;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/// <reference types="qs" />
|
|
2
|
+
import { Response } from 'express';
|
|
3
|
+
import { CrowdinClientRequest } from '../../../types';
|
|
4
|
+
import { AiProviderModule } from '../types';
|
|
5
|
+
export default function handle(aiProvider: AiProviderModule): (req: CrowdinClientRequest | import("express").Request<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs, Record<string, any>>, res: Response<any, Record<string, any>>, next: Function) => void;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const util_1 = require("../../../util");
|
|
13
|
+
const logger_1 = require("../../../util/logger");
|
|
14
|
+
function handle(aiProvider) {
|
|
15
|
+
return (0, util_1.runAsyncWrapper)((req, res) => __awaiter(this, void 0, void 0, function* () {
|
|
16
|
+
try {
|
|
17
|
+
const data = yield aiProvider.getModelsList({
|
|
18
|
+
client: req.crowdinApiClient,
|
|
19
|
+
context: req.crowdinContext,
|
|
20
|
+
});
|
|
21
|
+
res.send({ data });
|
|
22
|
+
}
|
|
23
|
+
catch (e) {
|
|
24
|
+
if (req.logError) {
|
|
25
|
+
req.logError(e);
|
|
26
|
+
}
|
|
27
|
+
res.send({ error: { message: (0, logger_1.getErrorMessage)(e) } });
|
|
28
|
+
}
|
|
29
|
+
}));
|
|
30
|
+
}
|
|
31
|
+
exports.default = handle;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.register = void 0;
|
|
7
|
+
const json_response_1 = __importDefault(require("../../middlewares/json-response"));
|
|
8
|
+
const get_model_list_1 = __importDefault(require("./handlers/get-model-list"));
|
|
9
|
+
const chat_completions_1 = __importDefault(require("./handlers/chat-completions"));
|
|
10
|
+
const ui_module_1 = __importDefault(require("../../middlewares/ui-module"));
|
|
11
|
+
const render_ui_module_1 = __importDefault(require("../../middlewares/render-ui-module"));
|
|
12
|
+
const util_1 = require("../../util");
|
|
13
|
+
const crowdin_client_1 = __importDefault(require("../../middlewares/crowdin-client"));
|
|
14
|
+
function register({ config, app }) {
|
|
15
|
+
if (!config.aiProvider) {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
if (config.aiProvider.settingsUiModule) {
|
|
19
|
+
app.use('/settings', (0, ui_module_1.default)(config, true), (0, render_ui_module_1.default)(config.aiProvider.settingsUiModule));
|
|
20
|
+
}
|
|
21
|
+
app.get((0, util_1.getLogoUrl)(config.aiProvider, '/aiprovider'), (req, res) => { var _a; return res.sendFile(((_a = config.aiProvider) === null || _a === void 0 ? void 0 : _a.imagePath) || config.imagePath); });
|
|
22
|
+
app.get('/models', json_response_1.default, (0, crowdin_client_1.default)(config), (0, get_model_list_1.default)(config.aiProvider));
|
|
23
|
+
app.post('/completions', json_response_1.default, (0, crowdin_client_1.default)(config), (0, chat_completions_1.default)(config.aiProvider));
|
|
24
|
+
}
|
|
25
|
+
exports.register = register;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { CrowdinClientRequest, CrowdinContextInfo, Environments, UiModule } from '../../types';
|
|
2
|
+
import Crowdin from '@crowdin/crowdin-api-client';
|
|
3
|
+
import { ExtendedResult } from '../integration/types';
|
|
4
|
+
export interface AiProviderModule extends Environments {
|
|
5
|
+
/**
|
|
6
|
+
* module name
|
|
7
|
+
*/
|
|
8
|
+
name: string;
|
|
9
|
+
/**
|
|
10
|
+
* module description
|
|
11
|
+
*/
|
|
12
|
+
description: string;
|
|
13
|
+
/**
|
|
14
|
+
* Settings UI module
|
|
15
|
+
*/
|
|
16
|
+
settingsUiModule?: UiModule;
|
|
17
|
+
/**
|
|
18
|
+
* processes a sequence of conversation messages and generates responses from the assistant
|
|
19
|
+
*/
|
|
20
|
+
chatCompletions: ({ messages, model, client, context, req, }: {
|
|
21
|
+
messages: Message[];
|
|
22
|
+
model: string;
|
|
23
|
+
client: Crowdin;
|
|
24
|
+
context: CrowdinContextInfo;
|
|
25
|
+
req: CrowdinClientRequest;
|
|
26
|
+
}) => Promise<Message[] | ExtendedResult<Message[]>>;
|
|
27
|
+
/**
|
|
28
|
+
* provides a list of available model
|
|
29
|
+
*/
|
|
30
|
+
getModelsList: ({ client, context, }: {
|
|
31
|
+
client: Crowdin;
|
|
32
|
+
context: CrowdinContextInfo;
|
|
33
|
+
}) => Promise<SupportedModels[]>;
|
|
34
|
+
}
|
|
35
|
+
export interface SupportedModels {
|
|
36
|
+
id: string;
|
|
37
|
+
}
|
|
38
|
+
export interface Message {
|
|
39
|
+
role?: string;
|
|
40
|
+
content: string;
|
|
41
|
+
}
|
package/out/modules/manifest.js
CHANGED
|
@@ -171,6 +171,14 @@ function handle(config) {
|
|
|
171
171
|
})), (uiModule ? { url: '/settings/' + (uiModule.fileName || 'index.html') } : {})),
|
|
172
172
|
];
|
|
173
173
|
}
|
|
174
|
+
if (config.aiProvider) {
|
|
175
|
+
const uiModule = config.aiProvider.settingsUiModule;
|
|
176
|
+
modules['ai-provider'] = [
|
|
177
|
+
Object.assign(Object.assign({ key: config.identifier + '-aiprovider', name: config.aiProvider.name || config.name, description: config.aiProvider.description || config.description, logo: (0, util_1.getLogoUrl)(config.aiProvider, '/aiprovider'), chatCompletionsUrl: '/completions', modelsUrl: '/models' }, (!!config.aiProvider.environments && {
|
|
178
|
+
environments: normalizeEnvironments(config.aiProvider.environments),
|
|
179
|
+
})), (uiModule ? { url: '/settings/' + (uiModule.fileName || 'index.html') } : {})),
|
|
180
|
+
];
|
|
181
|
+
}
|
|
174
182
|
const events = {
|
|
175
183
|
installed: '/installed',
|
|
176
184
|
uninstall: '/uninstall',
|
package/out/types.d.ts
CHANGED
|
@@ -12,6 +12,7 @@ import { MySQLStorageConfig } from './storage/mysql';
|
|
|
12
12
|
import { PostgreStorageConfig } from './storage/postgre';
|
|
13
13
|
import { ApiModule } from './modules/api/types';
|
|
14
14
|
import { LogErrorFunction, LogFunction } from './util/logger';
|
|
15
|
+
import { AiProviderModule } from './modules/ai-provider/types';
|
|
15
16
|
export interface ClientConfig extends ImagePath {
|
|
16
17
|
/**
|
|
17
18
|
* Authentication Crowdin App type: "authorization_code", "crowdin_app". Default: "crowdin_app"
|
|
@@ -171,6 +172,10 @@ export interface ClientConfig extends ImagePath {
|
|
|
171
172
|
*/
|
|
172
173
|
awsConfig?: AWSConfig;
|
|
173
174
|
customSpellchecker?: CustomSpellcheckerModule;
|
|
175
|
+
/**
|
|
176
|
+
* ai provider module
|
|
177
|
+
*/
|
|
178
|
+
aiProvider?: AiProviderModule & ImagePath;
|
|
174
179
|
}
|
|
175
180
|
export interface Environments {
|
|
176
181
|
environments?: Environment | Environment[];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@crowdin/app-project-module",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.51.0",
|
|
4
4
|
"description": "Module that generates for you all common endpoints for serving standalone Crowdin App",
|
|
5
5
|
"main": "out/index.js",
|
|
6
6
|
"types": "out/index.d.ts",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"express": "4.19.2",
|
|
29
29
|
"express-handlebars": "^5.3.5",
|
|
30
30
|
"lodash.uniqby": "^4.7.0",
|
|
31
|
-
"mysql2": "^3.9.
|
|
31
|
+
"mysql2": "^3.9.7",
|
|
32
32
|
"node-cron": "^3.0.3",
|
|
33
33
|
"pg": "^8.11.5",
|
|
34
34
|
"redoc-express": "^2.1.0",
|