@crowdin/app-project-module 0.54.2 → 0.56.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 CHANGED
@@ -61,6 +61,8 @@ 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
63
  const aiProvider = __importStar(require("./modules/ai-provider"));
64
+ const aiPromptProvider = __importStar(require("./modules/ai-prompt-provider"));
65
+ const aiToolCalls = __importStar(require("./modules/ai-tools"));
64
66
  const editorRightPanelApp = __importStar(require("./modules/editor-right-panel"));
65
67
  const editorThemesApp = __importStar(require("./modules/editor-themes"));
66
68
  const fileProcessingApps = __importStar(require("./modules/file-processing"));
@@ -165,6 +167,9 @@ function addCrowdinEndpoints(app, clientConfig) {
165
167
  fileProcessingApps.registerFilePostExport({ config, app });
166
168
  apiApp.register({ config, app });
167
169
  aiProvider.register({ config, app });
170
+ aiPromptProvider.register({ config, app });
171
+ aiToolCalls.registerAiToolCalls({ config, app });
172
+ aiToolCalls.registerAiToolCallWidgets({ config, app });
168
173
  addFormSchema({ config, app });
169
174
  return Object.assign(Object.assign({}, exports.metadataStore), { establishCrowdinConnection: (authRequest) => {
170
175
  let jwtToken = '';
@@ -0,0 +1,5 @@
1
+ /// <reference types="qs" />
2
+ import { Response } from 'express';
3
+ import { CrowdinClientRequest } from '../../../types';
4
+ import { AiPromptProviderModule } from '../types';
5
+ export default function handle(aiPromptProvider: AiPromptProviderModule): (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,28 @@
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(aiPromptProvider) {
15
+ return (0, util_1.runAsyncWrapper)((req, res) => __awaiter(this, void 0, void 0, function* () {
16
+ try {
17
+ const compiledPrompt = yield aiPromptProvider.compile(req.body.options, req.body.payload, req.crowdinApiClient, req.crowdinContext);
18
+ res.send({ data: { content: compiledPrompt } });
19
+ }
20
+ catch (e) {
21
+ if (req.logError) {
22
+ req.logError(e);
23
+ }
24
+ res.send({ error: { message: (0, logger_1.getErrorMessage)(e) } });
25
+ }
26
+ }));
27
+ }
28
+ exports.default = handle;
@@ -0,0 +1,6 @@
1
+ import { Express } from 'express';
2
+ import { Config } from '../../types';
3
+ export declare function register({ config, app }: {
4
+ config: Config;
5
+ app: Express;
6
+ }): void;
@@ -0,0 +1,23 @@
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 ui_module_1 = __importDefault(require("../../middlewares/ui-module"));
9
+ const render_ui_module_1 = __importDefault(require("../../middlewares/render-ui-module"));
10
+ const util_1 = require("../../util");
11
+ const crowdin_client_1 = __importDefault(require("../../middlewares/crowdin-client"));
12
+ const compile_1 = __importDefault(require("./handlers/compile"));
13
+ function register({ config, app }) {
14
+ if (!config.aiPromptProvider) {
15
+ return;
16
+ }
17
+ app.post('/prompt-provider/compile', json_response_1.default, (0, crowdin_client_1.default)(config), (0, compile_1.default)(config.aiPromptProvider));
18
+ if (config.aiPromptProvider.formSchema) {
19
+ app.use('/prompt-provider/settings', (0, ui_module_1.default)(config, true), (0, render_ui_module_1.default)(config.aiPromptProvider));
20
+ }
21
+ app.get((0, util_1.getLogoUrl)(config.aiPromptProvider, '/ai-prompt-provider'), (req, res) => { var _a; return res.sendFile(((_a = config.aiPromptProvider) === null || _a === void 0 ? void 0 : _a.imagePath) || config.imagePath); });
22
+ }
23
+ exports.register = register;
@@ -0,0 +1,8 @@
1
+ import { CrowdinContextInfo, UiModule } from '../../types';
2
+ import Crowdin from '@crowdin/crowdin-api-client';
3
+ export interface AiPromptProviderModule extends UiModule {
4
+ /**
5
+ * generates prompt text based on provided options
6
+ */
7
+ compile: (options: any, payload: any, client: Crowdin, context: CrowdinContextInfo) => Promise<string>;
8
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,5 @@
1
+ /// <reference types="qs" />
2
+ import { Response } from 'express';
3
+ import { CrowdinClientRequest } from '../../../types';
4
+ import { AiToolCall } from '../types';
5
+ export default function handle(aiToolCall: AiToolCall): (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,48 @@
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(aiToolCall) {
15
+ return (0, util_1.runAsyncWrapper)((req, res) => __awaiter(this, void 0, void 0, function* () {
16
+ try {
17
+ const { crowdinApiClient: client, crowdinContext: context, body: payload } = req;
18
+ const { function: { arguments: stringArgs = '' }, } = payload;
19
+ const { jwtPayload: { context: { project_id: projectId }, }, } = context;
20
+ let args = null;
21
+ try {
22
+ args = JSON.parse(stringArgs);
23
+ }
24
+ catch (e) { }
25
+ const { content, error: message } = yield aiToolCall.handle({
26
+ client,
27
+ args,
28
+ projectId,
29
+ payload,
30
+ context,
31
+ req,
32
+ });
33
+ res.send({
34
+ data: {
35
+ content: typeof content === 'string' ? content : JSON.stringify(content),
36
+ error: message ? { message } : undefined,
37
+ },
38
+ });
39
+ }
40
+ catch (e) {
41
+ if (req.logError) {
42
+ req.logError(e);
43
+ }
44
+ res.send({ error: { message: (0, logger_1.getErrorMessage)(e) } });
45
+ }
46
+ }));
47
+ }
48
+ exports.default = handle;
@@ -0,0 +1,10 @@
1
+ import { Express } from 'express';
2
+ import { Config } from '../../types';
3
+ export declare function registerAiToolCalls({ config, app }: {
4
+ config: Config;
5
+ app: Express;
6
+ }): void;
7
+ export declare function registerAiToolCallWidgets({ config, app }: {
8
+ config: Config;
9
+ app: Express;
10
+ }): void;
@@ -0,0 +1,32 @@
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.registerAiToolCallWidgets = exports.registerAiToolCalls = void 0;
7
+ const json_response_1 = __importDefault(require("../../middlewares/json-response"));
8
+ const tool_calls_1 = __importDefault(require("./handlers/tool-calls"));
9
+ const ui_module_1 = __importDefault(require("../../middlewares/ui-module"));
10
+ const render_ui_module_1 = __importDefault(require("../../middlewares/render-ui-module"));
11
+ const crowdin_client_1 = __importDefault(require("../../middlewares/crowdin-client"));
12
+ function getToolKey(tool) {
13
+ return tool.function.name;
14
+ }
15
+ function registerAiToolCalls({ config, app }) {
16
+ if (config.aiToolCalls) {
17
+ const tools = Array.isArray(config.aiToolCalls) ? config.aiToolCalls : [config.aiToolCalls];
18
+ for (const tool of tools) {
19
+ app.post(`/ai-tool-calls/${getToolKey(tool)}`, json_response_1.default, (0, crowdin_client_1.default)(config), (0, tool_calls_1.default)(tool));
20
+ }
21
+ }
22
+ }
23
+ exports.registerAiToolCalls = registerAiToolCalls;
24
+ function registerAiToolCallWidgets({ config, app }) {
25
+ if (config.aiToolCallWidgets) {
26
+ const tools = Array.isArray(config.aiToolCallWidgets) ? config.aiToolCallWidgets : [config.aiToolCallWidgets];
27
+ for (const tool of tools) {
28
+ app.use(`/ai-tool-call-widgets/${getToolKey(tool)}`, (0, ui_module_1.default)(config), (0, render_ui_module_1.default)(tool));
29
+ }
30
+ }
31
+ }
32
+ exports.registerAiToolCallWidgets = registerAiToolCallWidgets;
@@ -0,0 +1,63 @@
1
+ import { CrowdinClientRequest, CrowdinContextInfo, Environments, UiModule } from '../../types';
2
+ import Crowdin from '@crowdin/crowdin-api-client';
3
+ export interface AiToolCallWidget extends AiTool, UiModule {
4
+ }
5
+ export interface AiToolCall extends AiTool {
6
+ /**
7
+ * function to handle requests
8
+ */
9
+ handle: (options: AiToolCallArguments) => Promise<AiToolCallResponse>;
10
+ }
11
+ interface AiTool extends Environments {
12
+ /**
13
+ * Tool type, default is 'function'
14
+ */
15
+ toolType: string;
16
+ /**
17
+ * describe function object
18
+ */
19
+ function: AiToolCallFunction;
20
+ }
21
+ interface AiToolCallFunction {
22
+ /**
23
+ * The name of the function to be called. Must be a-z, A-Z, 0-9, or contain underscores and dashes.
24
+ */
25
+ name: string;
26
+ /**
27
+ * A description of what the function does, used by the AI model to choose when and how to call the function.
28
+ */
29
+ description: string;
30
+ /**
31
+ * Describe as a JSON Schema object
32
+ */
33
+ parameters?: {
34
+ type: string;
35
+ properties: object;
36
+ required?: string[];
37
+ };
38
+ }
39
+ interface AiToolCallArguments {
40
+ client: Crowdin;
41
+ args: object | null;
42
+ projectId: number;
43
+ payload: AiToolCallPayload;
44
+ context: CrowdinContextInfo;
45
+ req: CrowdinClientRequest;
46
+ }
47
+ interface AiToolCallPayload {
48
+ function: {
49
+ name: string;
50
+ arguments: string;
51
+ };
52
+ organization: {
53
+ [key: string]: unknown;
54
+ };
55
+ project: {
56
+ [key: string]: unknown;
57
+ };
58
+ }
59
+ interface AiToolCallResponse {
60
+ content: string | object;
61
+ error?: string;
62
+ }
63
+ export {};
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -179,6 +179,35 @@ function handle(config) {
179
179
  })), (uiModule ? { url: '/settings/' + (uiModule.fileName || 'index.html') } : {})),
180
180
  ];
181
181
  }
182
+ if (config.aiPromptProvider) {
183
+ modules['ai-prompt-provider'] = [
184
+ Object.assign({ key: config.identifier + '-ai-prompt-provider', name: config.aiPromptProvider.name || config.name, logo: (0, util_1.getLogoUrl)(config.aiPromptProvider, '/ai-prompt-provider'), compileUrl: '/prompt-provider/compile' }, (!!config.aiPromptProvider.formSchema
185
+ ? {
186
+ configuratorUrl: '/prompt-provider/settings/' + (config.aiPromptProvider.fileName || 'index.html'),
187
+ }
188
+ : {})),
189
+ ];
190
+ }
191
+ if (config.aiToolCalls) {
192
+ const tools = Array.isArray(config.aiToolCalls) ? config.aiToolCalls : [config.aiToolCalls];
193
+ modules['ai-tool-calls'] = [];
194
+ for (const tool of tools) {
195
+ const key = tool.function.name;
196
+ modules['ai-tool-calls'].push(Object.assign({ key, toolType: 'function', function: tool.function, url: `/ai-tool-calls/${key}` }, (!!tool.environments && {
197
+ environments: normalizeEnvironments(tool.environments),
198
+ })));
199
+ }
200
+ }
201
+ if (config.aiToolCallWidgets) {
202
+ const tools = Array.isArray(config.aiToolCallWidgets) ? config.aiToolCallWidgets : [config.aiToolCallWidgets];
203
+ modules['ai-tool-call-widgets'] = [];
204
+ for (const tool of tools) {
205
+ const key = tool.function.name;
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 && {
207
+ environments: normalizeEnvironments(tool.environments),
208
+ })));
209
+ }
210
+ }
182
211
  const events = {
183
212
  installed: '/installed',
184
213
  uninstall: '/uninstall',
@@ -241,4 +241,17 @@
241
241
  .ai-provider-form .i_w {
242
242
  max-width: 100% !important;
243
243
  padding: 0;
244
+ }
245
+
246
+ .form-without-submit {
247
+ body {
248
+ margin: 0;
249
+ }
250
+ .i_w {
251
+ padding: 0px !important;
252
+ max-width: 100% !important;
253
+ }
254
+ form > .MuiBox-root {
255
+ display: none;
256
+ }
244
257
  }