@crowdin/app-project-module 0.51.0 → 0.51.2
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 +4 -3
- package/out/modules/ai-provider/handlers/chat-completions.js +7 -4
- package/out/modules/ai-provider/handlers/get-model-list.d.ts +1 -0
- package/out/modules/ai-provider/handlers/get-model-list.js +12 -1
- package/out/modules/ai-provider/types.d.ts +6 -1
- package/out/util/index.d.ts +1 -0
- package/out/util/index.js +9 -1
- package/package.json +1 -1
package/out/index.js
CHANGED
|
@@ -187,10 +187,11 @@ function addCrowdinEndpoints(app, clientConfig) {
|
|
|
187
187
|
}
|
|
188
188
|
exports.addCrowdinEndpoints = addCrowdinEndpoints;
|
|
189
189
|
function addFormSchema({ app, config }) {
|
|
190
|
-
|
|
190
|
+
const shouldAddRoutes = Object.keys(config).some((moduleKey) => {
|
|
191
191
|
const moduleConfig = config[moduleKey];
|
|
192
|
-
return
|
|
193
|
-
})
|
|
192
|
+
return (0, util_1.hasFormSchema)(moduleConfig);
|
|
193
|
+
});
|
|
194
|
+
if (shouldAddRoutes) {
|
|
194
195
|
app.get('/api/form-data', json_response_1.default, (0, crowdin_client_1.default)(config), (0, form_data_display_1.default)());
|
|
195
196
|
app.post('/api/form-data', (0, crowdin_client_1.default)(config), (0, form_data_save_1.default)());
|
|
196
197
|
}
|
|
@@ -18,11 +18,14 @@ function handle(aiProvider) {
|
|
|
18
18
|
let choices;
|
|
19
19
|
let message;
|
|
20
20
|
let data;
|
|
21
|
+
const { crowdinApiClient: client, crowdinContext: context, body: { messages, model, action, responseFormat: { type: responseFormatType } = { type: undefined } }, } = req;
|
|
21
22
|
const result = yield aiProvider.chatCompletions({
|
|
22
|
-
messages
|
|
23
|
-
model
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
messages,
|
|
24
|
+
model,
|
|
25
|
+
action,
|
|
26
|
+
responseFormat: responseFormatType,
|
|
27
|
+
client,
|
|
28
|
+
context,
|
|
26
29
|
req,
|
|
27
30
|
});
|
|
28
31
|
if ((0, files_1.isExtendedResultType)(result)) {
|
|
@@ -2,4 +2,5 @@
|
|
|
2
2
|
import { Response } from 'express';
|
|
3
3
|
import { CrowdinClientRequest } from '../../../types';
|
|
4
4
|
import { AiProviderModule } from '../types';
|
|
5
|
+
export declare const CONTEXT_WINDOW_LIMIT = 4096;
|
|
5
6
|
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;
|
|
@@ -9,15 +9,26 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.CONTEXT_WINDOW_LIMIT = void 0;
|
|
12
13
|
const util_1 = require("../../../util");
|
|
13
14
|
const logger_1 = require("../../../util/logger");
|
|
15
|
+
exports.CONTEXT_WINDOW_LIMIT = 4096;
|
|
14
16
|
function handle(aiProvider) {
|
|
15
17
|
return (0, util_1.runAsyncWrapper)((req, res) => __awaiter(this, void 0, void 0, function* () {
|
|
16
18
|
try {
|
|
17
|
-
const
|
|
19
|
+
const modelList = yield aiProvider.getModelsList({
|
|
18
20
|
client: req.crowdinApiClient,
|
|
19
21
|
context: req.crowdinContext,
|
|
20
22
|
});
|
|
23
|
+
const data = modelList.map((model) => {
|
|
24
|
+
var _a, _b, _c;
|
|
25
|
+
return ({
|
|
26
|
+
id: model.id,
|
|
27
|
+
supportsJsonMode: (_a = model.supportsJsonMode) !== null && _a !== void 0 ? _a : false,
|
|
28
|
+
supportsFunctionCalling: (_b = model.supportsFunctionCalling) !== null && _b !== void 0 ? _b : false,
|
|
29
|
+
contextWindowLimit: (_c = model.contextWindowLimit) !== null && _c !== void 0 ? _c : exports.CONTEXT_WINDOW_LIMIT,
|
|
30
|
+
});
|
|
31
|
+
});
|
|
21
32
|
res.send({ data });
|
|
22
33
|
}
|
|
23
34
|
catch (e) {
|
|
@@ -17,9 +17,11 @@ export interface AiProviderModule extends Environments {
|
|
|
17
17
|
/**
|
|
18
18
|
* processes a sequence of conversation messages and generates responses from the assistant
|
|
19
19
|
*/
|
|
20
|
-
chatCompletions: ({ messages, model, client, context, req, }: {
|
|
20
|
+
chatCompletions: ({ messages, model, action, responseFormat, client, context, req, }: {
|
|
21
21
|
messages: Message[];
|
|
22
22
|
model: string;
|
|
23
|
+
action: string;
|
|
24
|
+
responseFormat: string;
|
|
23
25
|
client: Crowdin;
|
|
24
26
|
context: CrowdinContextInfo;
|
|
25
27
|
req: CrowdinClientRequest;
|
|
@@ -34,6 +36,9 @@ export interface AiProviderModule extends Environments {
|
|
|
34
36
|
}
|
|
35
37
|
export interface SupportedModels {
|
|
36
38
|
id: string;
|
|
39
|
+
supportsJsonMode?: boolean;
|
|
40
|
+
supportsFunctionCalling?: boolean;
|
|
41
|
+
contextWindowLimit?: number;
|
|
37
42
|
}
|
|
38
43
|
export interface Message {
|
|
39
44
|
role?: string;
|
package/out/util/index.d.ts
CHANGED
|
@@ -10,3 +10,4 @@ export declare function decryptData(config: Config, data: string): string;
|
|
|
10
10
|
export declare function executeWithRetry<T>(func: () => Promise<T>, numOfRetries?: number): Promise<T>;
|
|
11
11
|
export declare function getLogoUrl(moduleConfig?: ImagePath, modulePath?: string): string;
|
|
12
12
|
export declare function isAuthorizedConfig(config: Config | UnauthorizedConfig): config is Config;
|
|
13
|
+
export declare function hasFormSchema(moduleConfig: any): boolean;
|
package/out/util/index.js
CHANGED
|
@@ -32,7 +32,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
32
32
|
});
|
|
33
33
|
};
|
|
34
34
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
|
-
exports.isAuthorizedConfig = exports.getLogoUrl = exports.executeWithRetry = exports.decryptData = exports.encryptData = exports.runAsyncWrapper = exports.CodeError = void 0;
|
|
35
|
+
exports.hasFormSchema = exports.isAuthorizedConfig = exports.getLogoUrl = exports.executeWithRetry = exports.decryptData = exports.encryptData = exports.runAsyncWrapper = exports.CodeError = void 0;
|
|
36
36
|
const crypto = __importStar(require("crypto-js"));
|
|
37
37
|
const storage_1 = require("../storage");
|
|
38
38
|
const types_1 = require("../types");
|
|
@@ -118,3 +118,11 @@ function isAuthorizedConfig(config) {
|
|
|
118
118
|
return !!config.clientId && !!config.clientSecret && config.authenticationType !== types_1.AuthenticationType.NONE;
|
|
119
119
|
}
|
|
120
120
|
exports.isAuthorizedConfig = isAuthorizedConfig;
|
|
121
|
+
function hasFormSchema(moduleConfig) {
|
|
122
|
+
var _a;
|
|
123
|
+
if (typeof moduleConfig === 'object' && moduleConfig !== null) {
|
|
124
|
+
return moduleConfig.formSchema || ((_a = moduleConfig.settingsUiModule) === null || _a === void 0 ? void 0 : _a.formSchema);
|
|
125
|
+
}
|
|
126
|
+
return false;
|
|
127
|
+
}
|
|
128
|
+
exports.hasFormSchema = hasFormSchema;
|
package/package.json
CHANGED