@crowdin/app-project-module 0.56.2 → 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 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 aiToolCalls = __importStar(require("./modules/ai-tools"));
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
- aiToolCalls.registerAiToolCalls({ config, app });
172
- aiToolCalls.registerAiToolCallWidgets({ config, app });
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 { 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;
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(aiToolCall) {
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
- const { content, error: message } = yield aiToolCall.handle({
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 registerAiToolCalls({ config, app }: {
3
+ export declare function registerAiTools({ config, app }: {
4
4
  config: Config;
5
5
  app: Express;
6
6
  }): void;
7
- export declare function registerAiToolCallWidgets({ config, app }: {
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.registerAiToolCallWidgets = exports.registerAiToolCalls = void 0;
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
- 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));
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.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));
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.registerAiToolCallWidgets = registerAiToolCallWidgets;
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 AiToolCallWidget extends AiTool, UiModule {
3
+ export interface AiToolWidget extends BaseAiTool, UiModule {
4
4
  }
5
- export interface AiToolCall extends AiTool {
5
+ export interface AiTool extends BaseAiTool {
6
6
  /**
7
7
  * function to handle requests
8
8
  */
9
- handle: (options: AiToolCallArguments) => Promise<AiToolCallResponse>;
9
+ toolCalls: (options: AiToolArguments) => Promise<AiToolResponse>;
10
10
  }
11
- interface AiTool extends Environments {
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: AiToolCallFunction;
19
+ function: AiToolFunction;
20
20
  }
21
- interface AiToolCallFunction {
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 AiToolCallArguments {
39
+ interface AiToolArguments {
40
40
  client: Crowdin;
41
41
  args: object | null;
42
42
  projectId: number;
43
- payload: AiToolCallPayload;
43
+ payload: AiToolPayload;
44
44
  context: CrowdinContextInfo;
45
45
  req: CrowdinClientRequest;
46
46
  }
47
- interface AiToolCallPayload {
47
+ interface AiToolPayload {
48
48
  function: {
49
49
  name: string;
50
50
  arguments: string;
51
51
  };
52
52
  organization: {
53
- [key: string]: unknown;
53
+ [key: string]: any;
54
54
  };
55
55
  project: {
56
- [key: string]: unknown;
56
+ [key: string]: any;
57
57
  };
58
58
  }
59
- interface AiToolCallResponse {
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;
@@ -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.aiToolCalls) {
192
- const tools = Array.isArray(config.aiToolCalls) ? config.aiToolCalls : [config.aiToolCalls];
193
- modules['ai-tool-calls'] = [];
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
- 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 && {
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.aiToolCallWidgets) {
202
- const tools = Array.isArray(config.aiToolCallWidgets) ? config.aiToolCallWidgets : [config.aiToolCallWidgets];
203
- modules['ai-tool-call-widgets'] = [];
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
- 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 && {
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
  }
package/out/types.d.ts CHANGED
@@ -14,7 +14,7 @@ import { ApiModule } from './modules/api/types';
14
14
  import { LogErrorFunction, LogFunction } from './util/logger';
15
15
  import { AiProviderModule } from './modules/ai-provider/types';
16
16
  import { AiPromptProviderModule } from './modules/ai-prompt-provider/types';
17
- import { AiToolCall, AiToolCallWidget } from './modules/ai-tools/types';
17
+ import { AiTool, AiToolWidget } from './modules/ai-tools/types';
18
18
  export interface ClientConfig extends ImagePath {
19
19
  /**
20
20
  * Authentication Crowdin App type: "authorization_code", "crowdin_app". Default: "crowdin_app"
@@ -189,11 +189,11 @@ export interface ClientConfig extends ImagePath {
189
189
  /**
190
190
  * AI tool_calls modules
191
191
  */
192
- aiToolCalls?: AiToolCall | AiToolCall[];
192
+ aiTools?: AiTool | AiTool[];
193
193
  /**
194
194
  * AI tool_calls modules with UI widgets
195
195
  */
196
- aiToolCallWidgets?: AiToolCallWidget | AiToolCallWidget[];
196
+ aiToolsWidget?: AiToolWidget | AiToolWidget[];
197
197
  }
198
198
  export interface Environments {
199
199
  environments?: Environment | Environment[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crowdin/app-project-module",
3
- "version": "0.56.2",
3
+ "version": "0.56.3",
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",