@crowdin/app-project-module 0.56.1 → 0.56.3
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 +3 -3
- package/out/modules/ai-tools/handlers/tool-calls.d.ts +2 -2
- package/out/modules/ai-tools/handlers/tool-calls.js +7 -3
- package/out/modules/ai-tools/index.d.ts +2 -2
- package/out/modules/ai-tools/index.js +26 -16
- package/out/modules/ai-tools/types.d.ts +12 -12
- package/out/modules/ai-tools/util/index.d.ts +5 -0
- package/out/modules/ai-tools/util/index.js +25 -0
- package/out/modules/manifest.js +9 -10
- package/out/static/js/form.js +1 -1
- package/out/types.d.ts +3 -3
- package/package.json +6 -6
package/out/index.js
CHANGED
|
@@ -62,7 +62,7 @@ const customMTApp = __importStar(require("./modules/custom-mt"));
|
|
|
62
62
|
const spellCheckApp = __importStar(require("./modules/custom-spell-check"));
|
|
63
63
|
const aiProvider = __importStar(require("./modules/ai-provider"));
|
|
64
64
|
const aiPromptProvider = __importStar(require("./modules/ai-prompt-provider"));
|
|
65
|
-
const
|
|
65
|
+
const aiTools = __importStar(require("./modules/ai-tools"));
|
|
66
66
|
const editorRightPanelApp = __importStar(require("./modules/editor-right-panel"));
|
|
67
67
|
const editorThemesApp = __importStar(require("./modules/editor-themes"));
|
|
68
68
|
const fileProcessingApps = __importStar(require("./modules/file-processing"));
|
|
@@ -168,8 +168,8 @@ function addCrowdinEndpoints(app, clientConfig) {
|
|
|
168
168
|
apiApp.register({ config, app });
|
|
169
169
|
aiProvider.register({ config, app });
|
|
170
170
|
aiPromptProvider.register({ config, app });
|
|
171
|
-
|
|
172
|
-
|
|
171
|
+
aiTools.registerAiTools({ config, app });
|
|
172
|
+
aiTools.registerAiToolWidgets({ config, app });
|
|
173
173
|
addFormSchema({ config, app });
|
|
174
174
|
return Object.assign(Object.assign({}, exports.metadataStore), { establishCrowdinConnection: (authRequest) => {
|
|
175
175
|
let jwtToken = '';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="qs" />
|
|
2
2
|
import { Response } from 'express';
|
|
3
3
|
import { CrowdinClientRequest } from '../../../types';
|
|
4
|
-
import {
|
|
5
|
-
export default function handle(
|
|
4
|
+
import { AiTool } from '../types';
|
|
5
|
+
export default function handle(aiTool: AiTool): (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;
|
|
@@ -11,7 +11,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
const util_1 = require("../../../util");
|
|
13
13
|
const logger_1 = require("../../../util/logger");
|
|
14
|
-
function handle(
|
|
14
|
+
function handle(aiTool) {
|
|
15
15
|
return (0, util_1.runAsyncWrapper)((req, res) => __awaiter(this, void 0, void 0, function* () {
|
|
16
16
|
try {
|
|
17
17
|
const { crowdinApiClient: client, crowdinContext: context, body: payload } = req;
|
|
@@ -21,8 +21,12 @@ function handle(aiToolCall) {
|
|
|
21
21
|
try {
|
|
22
22
|
args = JSON.parse(stringArgs);
|
|
23
23
|
}
|
|
24
|
-
catch (e) {
|
|
25
|
-
|
|
24
|
+
catch (e) {
|
|
25
|
+
if (req.logError) {
|
|
26
|
+
req.logError(e);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
const { content, error: message } = yield aiTool.toolCalls({
|
|
26
30
|
client,
|
|
27
31
|
args,
|
|
28
32
|
projectId,
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { Express } from 'express';
|
|
2
2
|
import { Config } from '../../types';
|
|
3
|
-
export declare function
|
|
3
|
+
export declare function registerAiTools({ config, app }: {
|
|
4
4
|
config: Config;
|
|
5
5
|
app: Express;
|
|
6
6
|
}): void;
|
|
7
|
-
export declare function
|
|
7
|
+
export declare function registerAiToolWidgets({ config, app }: {
|
|
8
8
|
config: Config;
|
|
9
9
|
app: Express;
|
|
10
10
|
}): void;
|
|
@@ -3,30 +3,40 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
6
|
+
exports.registerAiToolWidgets = exports.registerAiTools = void 0;
|
|
7
7
|
const json_response_1 = __importDefault(require("../../middlewares/json-response"));
|
|
8
8
|
const tool_calls_1 = __importDefault(require("./handlers/tool-calls"));
|
|
9
9
|
const ui_module_1 = __importDefault(require("../../middlewares/ui-module"));
|
|
10
10
|
const render_ui_module_1 = __importDefault(require("../../middlewares/render-ui-module"));
|
|
11
11
|
const crowdin_client_1 = __importDefault(require("../../middlewares/crowdin-client"));
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
12
|
+
const util_1 = require("./util");
|
|
13
|
+
function registerAiTools({ config, app }) {
|
|
14
|
+
if (!config.aiTools) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
const tools = Array.isArray(config.aiTools) ? config.aiTools : [config.aiTools];
|
|
18
|
+
for (const tool of tools) {
|
|
19
|
+
if ((0, util_1.isUniqueFunctionName)(tool)) {
|
|
20
|
+
app.post((0, util_1.getAiToolUrl)(tool), json_response_1.default, (0, crowdin_client_1.default)(config), (0, tool_calls_1.default)(tool));
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
throw new Error(`The function name '${tool.function.name}' is not unique within aiTools and aiToolsWidget`);
|
|
20
24
|
}
|
|
21
25
|
}
|
|
22
26
|
}
|
|
23
|
-
exports.
|
|
24
|
-
function
|
|
25
|
-
if (config.
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
exports.registerAiTools = registerAiTools;
|
|
28
|
+
function registerAiToolWidgets({ config, app }) {
|
|
29
|
+
if (!config.aiToolsWidget) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
const tools = Array.isArray(config.aiToolsWidget) ? config.aiToolsWidget : [config.aiToolsWidget];
|
|
33
|
+
for (const tool of tools) {
|
|
34
|
+
if ((0, util_1.isUniqueFunctionName)(tool)) {
|
|
35
|
+
app.use((0, util_1.getAiToolWidgetUrl)(tool), (0, ui_module_1.default)(config), (0, render_ui_module_1.default)(tool));
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
throw new Error(`The function name '${tool.function.name}' is not unique within aiTools and aiToolsWidget`);
|
|
29
39
|
}
|
|
30
40
|
}
|
|
31
41
|
}
|
|
32
|
-
exports.
|
|
42
|
+
exports.registerAiToolWidgets = registerAiToolWidgets;
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { CrowdinClientRequest, CrowdinContextInfo, Environments, UiModule } from '../../types';
|
|
2
2
|
import Crowdin from '@crowdin/crowdin-api-client';
|
|
3
|
-
export interface
|
|
3
|
+
export interface AiToolWidget extends BaseAiTool, UiModule {
|
|
4
4
|
}
|
|
5
|
-
export interface
|
|
5
|
+
export interface AiTool extends BaseAiTool {
|
|
6
6
|
/**
|
|
7
7
|
* function to handle requests
|
|
8
8
|
*/
|
|
9
|
-
|
|
9
|
+
toolCalls: (options: AiToolArguments) => Promise<AiToolResponse>;
|
|
10
10
|
}
|
|
11
|
-
interface
|
|
11
|
+
interface BaseAiTool extends Environments {
|
|
12
12
|
/**
|
|
13
13
|
* Tool type, default is 'function'
|
|
14
14
|
*/
|
|
@@ -16,9 +16,9 @@ interface AiTool extends Environments {
|
|
|
16
16
|
/**
|
|
17
17
|
* describe function object
|
|
18
18
|
*/
|
|
19
|
-
function:
|
|
19
|
+
function: AiToolFunction;
|
|
20
20
|
}
|
|
21
|
-
interface
|
|
21
|
+
interface AiToolFunction {
|
|
22
22
|
/**
|
|
23
23
|
* The name of the function to be called. Must be a-z, A-Z, 0-9, or contain underscores and dashes.
|
|
24
24
|
*/
|
|
@@ -36,27 +36,27 @@ interface AiToolCallFunction {
|
|
|
36
36
|
required?: string[];
|
|
37
37
|
};
|
|
38
38
|
}
|
|
39
|
-
interface
|
|
39
|
+
interface AiToolArguments {
|
|
40
40
|
client: Crowdin;
|
|
41
41
|
args: object | null;
|
|
42
42
|
projectId: number;
|
|
43
|
-
payload:
|
|
43
|
+
payload: AiToolPayload;
|
|
44
44
|
context: CrowdinContextInfo;
|
|
45
45
|
req: CrowdinClientRequest;
|
|
46
46
|
}
|
|
47
|
-
interface
|
|
47
|
+
interface AiToolPayload {
|
|
48
48
|
function: {
|
|
49
49
|
name: string;
|
|
50
50
|
arguments: string;
|
|
51
51
|
};
|
|
52
52
|
organization: {
|
|
53
|
-
[key: string]:
|
|
53
|
+
[key: string]: any;
|
|
54
54
|
};
|
|
55
55
|
project: {
|
|
56
|
-
[key: string]:
|
|
56
|
+
[key: string]: any;
|
|
57
57
|
};
|
|
58
58
|
}
|
|
59
|
-
interface
|
|
59
|
+
interface AiToolResponse {
|
|
60
60
|
content: string | object;
|
|
61
61
|
error?: string;
|
|
62
62
|
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { AiTool, AiToolWidget } from '../types';
|
|
2
|
+
export declare function isUniqueFunctionName(tool: AiTool | AiToolWidget): boolean;
|
|
3
|
+
export declare function getAiToolName(tool: AiTool | AiToolWidget): string;
|
|
4
|
+
export declare function getAiToolUrl(tool: AiTool): string;
|
|
5
|
+
export declare function getAiToolWidgetUrl(tool: AiToolWidget, isFull?: boolean): string;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getAiToolWidgetUrl = exports.getAiToolUrl = exports.getAiToolName = exports.isUniqueFunctionName = void 0;
|
|
4
|
+
const uniqueNames = [];
|
|
5
|
+
function isUniqueFunctionName(tool) {
|
|
6
|
+
if (uniqueNames.includes(tool.function.name)) {
|
|
7
|
+
return false;
|
|
8
|
+
}
|
|
9
|
+
uniqueNames.push(tool.function.name);
|
|
10
|
+
return true;
|
|
11
|
+
}
|
|
12
|
+
exports.isUniqueFunctionName = isUniqueFunctionName;
|
|
13
|
+
function getAiToolName(tool) {
|
|
14
|
+
return tool.function.name;
|
|
15
|
+
}
|
|
16
|
+
exports.getAiToolName = getAiToolName;
|
|
17
|
+
function getAiToolUrl(tool) {
|
|
18
|
+
return `/ai-tools/${getAiToolName(tool)}`;
|
|
19
|
+
}
|
|
20
|
+
exports.getAiToolUrl = getAiToolUrl;
|
|
21
|
+
function getAiToolWidgetUrl(tool, isFull = false) {
|
|
22
|
+
const suffix = isFull ? `/${tool.fileName || 'index.html'}` : '';
|
|
23
|
+
return `/ai-tools-widget/${getAiToolName(tool)}${suffix}`;
|
|
24
|
+
}
|
|
25
|
+
exports.getAiToolWidgetUrl = getAiToolWidgetUrl;
|
package/out/modules/manifest.js
CHANGED
|
@@ -4,6 +4,7 @@ const types_1 = require("../types");
|
|
|
4
4
|
const util_1 = require("../util");
|
|
5
5
|
const subscription_1 = require("../util/subscription");
|
|
6
6
|
const api_1 = require("./api/api");
|
|
7
|
+
const util_2 = require("./ai-tools/util");
|
|
7
8
|
function normalizeEnvironments(environments) {
|
|
8
9
|
if (Array.isArray(environments)) {
|
|
9
10
|
return environments;
|
|
@@ -188,22 +189,20 @@ function handle(config) {
|
|
|
188
189
|
: {})),
|
|
189
190
|
];
|
|
190
191
|
}
|
|
191
|
-
if (config.
|
|
192
|
-
const tools = Array.isArray(config.
|
|
193
|
-
modules['ai-
|
|
192
|
+
if (config.aiTools) {
|
|
193
|
+
const tools = Array.isArray(config.aiTools) ? config.aiTools : [config.aiTools];
|
|
194
|
+
modules['ai-tools'] = [];
|
|
194
195
|
for (const tool of tools) {
|
|
195
|
-
|
|
196
|
-
modules['ai-tool-calls'].push(Object.assign({ key, toolType: 'function', function: tool.function, url: `/ai-tool-calls/${key}` }, (!!tool.environments && {
|
|
196
|
+
modules['ai-tools'].push(Object.assign({ key: config.identifier + '-' + (0, util_2.getAiToolName)(tool), toolType: tool.toolType || 'function', function: tool.function, url: (0, util_2.getAiToolUrl)(tool) }, (!!tool.environments && {
|
|
197
197
|
environments: normalizeEnvironments(tool.environments),
|
|
198
198
|
})));
|
|
199
199
|
}
|
|
200
200
|
}
|
|
201
|
-
if (config.
|
|
202
|
-
const tools = Array.isArray(config.
|
|
203
|
-
modules['ai-
|
|
201
|
+
if (config.aiToolsWidget) {
|
|
202
|
+
const tools = Array.isArray(config.aiToolsWidget) ? config.aiToolsWidget : [config.aiToolsWidget];
|
|
203
|
+
modules['ai-tools-widget'] = [];
|
|
204
204
|
for (const tool of tools) {
|
|
205
|
-
|
|
206
|
-
modules['ai-tool-call-widgets'].push(Object.assign({ key, toolType: 'function', function: tool.function, url: `/ai-tool-call-widgets/${key}/${tool.fileName || 'index.html'}` }, (!!tool.environments && {
|
|
205
|
+
modules['ai-tools-widget'].push(Object.assign({ key: config.identifier + '-' + (0, util_2.getAiToolName)(tool), toolType: tool.toolType || 'function', function: tool.function, url: (0, util_2.getAiToolWidgetUrl)(tool, true) }, (!!tool.environments && {
|
|
207
206
|
environments: normalizeEnvironments(tool.environments),
|
|
208
207
|
})));
|
|
209
208
|
}
|