@purpleschool/gptbot 0.5.73 → 0.5.75

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.
Files changed (47) hide show
  1. package/api/controllers/http/chat-private.ts +2 -0
  2. package/api/controllers/http/chat-public.ts +2 -0
  3. package/build/api/controllers/http/chat-private.js +2 -0
  4. package/build/api/controllers/http/chat-public.js +2 -0
  5. package/build/commands/chat/get-last-active-chat-command.js +1 -3
  6. package/build/commands/message/create-image-message.command.js +4 -1
  7. package/build/commands/message/create-speech-to-text-message.command.js +17 -0
  8. package/build/commands/message/create-text-to-speech-message.command.js +22 -0
  9. package/build/commands/message/index.js +2 -0
  10. package/build/constants/ai-model/enums/ai-model-config-selector-type.enum.js +8 -0
  11. package/build/constants/ai-model/enums/ai-model-content-type.enum.js +2 -0
  12. package/build/constants/ai-model/enums/ai-model-feature.enum.js +1 -0
  13. package/build/constants/ai-model/enums/ai-model-strategy.enum.js +2 -0
  14. package/build/constants/ai-model/enums/index.js +1 -0
  15. package/build/constants/chat/enums/image-format.enum.js +9 -0
  16. package/build/constants/chat/enums/index.js +1 -1
  17. package/build/constants/errors/errors.js +35 -0
  18. package/build/constants/file/enums/file-type.enum.js +1 -0
  19. package/build/constants/file/file.constants.js +12 -4
  20. package/build/models/ai-model-config.schema.js +48 -0
  21. package/build/models/ai-model.schema.js +2 -0
  22. package/build/models/chat.schema.js +2 -0
  23. package/build/models/index.js +1 -0
  24. package/build/models/message.schema.js +1 -1
  25. package/commands/chat/get-last-active-chat-command.ts +2 -4
  26. package/commands/message/create-image-message.command.ts +7 -2
  27. package/commands/message/create-speech-to-text-message.command.ts +19 -0
  28. package/commands/message/create-text-to-speech-message.command.ts +26 -0
  29. package/commands/message/index.ts +2 -0
  30. package/constants/ai-model/enums/ai-model-config-selector-type.enum.ts +4 -0
  31. package/constants/ai-model/enums/ai-model-content-type.enum.ts +2 -0
  32. package/constants/ai-model/enums/ai-model-feature.enum.ts +1 -0
  33. package/constants/ai-model/enums/ai-model-strategy.enum.ts +2 -0
  34. package/constants/ai-model/enums/index.ts +1 -0
  35. package/constants/chat/enums/image-format.enum.ts +5 -0
  36. package/constants/chat/enums/index.ts +1 -1
  37. package/constants/errors/errors.ts +35 -0
  38. package/constants/file/enums/file-type.enum.ts +1 -0
  39. package/constants/file/file.constants.ts +17 -3
  40. package/models/ai-model-config.schema.ts +63 -0
  41. package/models/ai-model.schema.ts +2 -0
  42. package/models/chat.schema.ts +2 -0
  43. package/models/index.ts +1 -0
  44. package/models/message.schema.ts +2 -10
  45. package/package.json +1 -1
  46. package/build/constants/chat/enums/dalle-image-format.enum.js +0 -9
  47. package/constants/chat/enums/dalle-image-format.enum.ts +0 -10
@@ -10,6 +10,8 @@ export const CHAT_PRIVATE_ROUTES = {
10
10
  FIND_BY_UUID: (uuid: string) => `${uuid}`,
11
11
  SEND_TEXT_MESSAGE: (uuid: string) => `${uuid}/messages/text`,
12
12
  SEND_IMAGE_MESSAGE: (uuid: string) => `${uuid}/messages/image`,
13
+ SEND_TEXT_TO_SPEECH_MESSAGE: (uuid: string) => `${uuid}/messages/text-to-speech`,
14
+ SEND_SPEECH_TO_TEXT_MESSAGE: (uuid: string) => `${uuid}/messages/speech-to-text`,
13
15
  ARCHIVE: 'archive',
14
16
  DELETE: (uuid: string) => `${uuid}`,
15
17
  UPDATE: (uuid: string) => `${uuid}`,
@@ -9,5 +9,7 @@ export const CHAT_PUBLIC_ROUTES = {
9
9
  FIND_BY_UUID: (uuid: string) => `${uuid}`,
10
10
  SEND_TEXT_MESSAGE: (uuid: string) => `${uuid}/messages/text`,
11
11
  SEND_IMAGE_MESSAGE: (uuid: string) => `${uuid}/messages/image`,
12
+ SEND_TEXT_TO_SPEECH_MESSAGE: (uuid: string) => `${uuid}/messages/text-to-speech`,
13
+ SEND_SPEECH_TO_TEXT_MESSAGE: (uuid: string) => `${uuid}/messages/speech-to-text`,
12
14
  INPUT_LIMITS: 'input-limits',
13
15
  } as const;
@@ -12,6 +12,8 @@ exports.CHAT_PRIVATE_ROUTES = {
12
12
  FIND_BY_UUID: (uuid) => `${uuid}`,
13
13
  SEND_TEXT_MESSAGE: (uuid) => `${uuid}/messages/text`,
14
14
  SEND_IMAGE_MESSAGE: (uuid) => `${uuid}/messages/image`,
15
+ SEND_TEXT_TO_SPEECH_MESSAGE: (uuid) => `${uuid}/messages/text-to-speech`,
16
+ SEND_SPEECH_TO_TEXT_MESSAGE: (uuid) => `${uuid}/messages/speech-to-text`,
15
17
  ARCHIVE: 'archive',
16
18
  DELETE: (uuid) => `${uuid}`,
17
19
  UPDATE: (uuid) => `${uuid}`,
@@ -11,5 +11,7 @@ exports.CHAT_PUBLIC_ROUTES = {
11
11
  FIND_BY_UUID: (uuid) => `${uuid}`,
12
12
  SEND_TEXT_MESSAGE: (uuid) => `${uuid}/messages/text`,
13
13
  SEND_IMAGE_MESSAGE: (uuid) => `${uuid}/messages/image`,
14
+ SEND_TEXT_TO_SPEECH_MESSAGE: (uuid) => `${uuid}/messages/text-to-speech`,
15
+ SEND_SPEECH_TO_TEXT_MESSAGE: (uuid) => `${uuid}/messages/speech-to-text`,
14
16
  INPUT_LIMITS: 'input-limits',
15
17
  };
@@ -10,8 +10,6 @@ var GetLastActiveChatCommand;
10
10
  aIModelId: true,
11
11
  });
12
12
  GetLastActiveChatCommand.Response = zod_1.z.object({
13
- data: models_1.ChatSchema.extend({
14
- messages: zod_1.z.array(models_1.MessageSchema),
15
- }),
13
+ data: models_1.ChatSchema,
16
14
  });
17
15
  })(GetLastActiveChatCommand || (exports.GetLastActiveChatCommand = GetLastActiveChatCommand = {}));
@@ -7,7 +7,10 @@ const constants_1 = require("../../constants");
7
7
  var CreateImageMessageCommand;
8
8
  (function (CreateImageMessageCommand) {
9
9
  CreateImageMessageCommand.RequestSchema = zod_1.z.intersection(models_1.MessageSchema.pick({ text: true }), zod_1.z.object({
10
- size: zod_1.z.nativeEnum(constants_1.DALLE_IMAGE_SIZE),
10
+ params: zod_1.z.array(zod_1.z.object({
11
+ type: zod_1.z.nativeEnum(constants_1.AI_MODEL_CONFIG_PARAM),
12
+ option: zod_1.z.string().uuid(),
13
+ })),
11
14
  }));
12
15
  CreateImageMessageCommand.RequestParamSchema = models_1.ChatSchema.pick({
13
16
  uuid: true,
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CreateSpeechToTextMessageCommand = void 0;
4
+ const models_1 = require("../../models");
5
+ const zod_1 = require("zod");
6
+ var CreateSpeechToTextMessageCommand;
7
+ (function (CreateSpeechToTextMessageCommand) {
8
+ CreateSpeechToTextMessageCommand.RequestSchema = zod_1.z.object({
9
+ fileId: zod_1.z.string().uuid(),
10
+ });
11
+ CreateSpeechToTextMessageCommand.RequestParamSchema = models_1.ChatSchema.pick({
12
+ uuid: true,
13
+ });
14
+ CreateSpeechToTextMessageCommand.ResponseSchema = zod_1.z.object({
15
+ data: models_1.MessageSchema,
16
+ });
17
+ })(CreateSpeechToTextMessageCommand || (exports.CreateSpeechToTextMessageCommand = CreateSpeechToTextMessageCommand = {}));
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CreateTextToSpeechMessageCommand = void 0;
4
+ const constants_1 = require("../../constants");
5
+ const models_1 = require("../../models");
6
+ const zod_1 = require("zod");
7
+ var CreateTextToSpeechMessageCommand;
8
+ (function (CreateTextToSpeechMessageCommand) {
9
+ CreateTextToSpeechMessageCommand.RequestSchema = zod_1.z.object({
10
+ text: zod_1.z.string(),
11
+ params: zod_1.z.array(zod_1.z.object({
12
+ type: zod_1.z.nativeEnum(constants_1.AI_MODEL_CONFIG_PARAM),
13
+ option: zod_1.z.string().uuid(),
14
+ })),
15
+ });
16
+ CreateTextToSpeechMessageCommand.RequestParamSchema = models_1.ChatSchema.pick({
17
+ uuid: true,
18
+ });
19
+ CreateTextToSpeechMessageCommand.ResponseSchema = zod_1.z.object({
20
+ data: models_1.MessageSchema,
21
+ });
22
+ })(CreateTextToSpeechMessageCommand || (exports.CreateTextToSpeechMessageCommand = CreateTextToSpeechMessageCommand = {}));
@@ -15,6 +15,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./create-image-message.command"), exports);
18
+ __exportStar(require("./create-speech-to-text-message.command"), exports);
18
19
  __exportStar(require("./create-text-message.command"), exports);
20
+ __exportStar(require("./create-text-to-speech-message.command"), exports);
19
21
  __exportStar(require("./find-message-by-uuid.command"), exports);
20
22
  __exportStar(require("./rate-message.command"), exports);
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AI_MODEL_CONFIG_PARAM = void 0;
4
+ var AI_MODEL_CONFIG_PARAM;
5
+ (function (AI_MODEL_CONFIG_PARAM) {
6
+ AI_MODEL_CONFIG_PARAM["IMAGE_SIZE"] = "image-size";
7
+ AI_MODEL_CONFIG_PARAM["VOICE_TYPE"] = "voice-type";
8
+ })(AI_MODEL_CONFIG_PARAM || (exports.AI_MODEL_CONFIG_PARAM = AI_MODEL_CONFIG_PARAM = {}));
@@ -4,4 +4,6 @@ exports.AI_MODEL_CONTENT_TYPE = void 0;
4
4
  exports.AI_MODEL_CONTENT_TYPE = {
5
5
  TEXT: 'TEXT',
6
6
  IMAGE: 'IMAGE',
7
+ TEXT_TO_SPEECH: 'TEXT_TO_SPEECH',
8
+ SPEECH_TO_TEXT: 'SPEECH_TO_TEXT',
7
9
  };
@@ -4,4 +4,5 @@ exports.AI_MODEL_FEATURE = void 0;
4
4
  var AI_MODEL_FEATURE;
5
5
  (function (AI_MODEL_FEATURE) {
6
6
  AI_MODEL_FEATURE["IMAGE_ATTACHMENT"] = "image_attachment";
7
+ AI_MODEL_FEATURE["AUDIO_ATTACHMENT"] = "audio_attachment";
7
8
  })(AI_MODEL_FEATURE || (exports.AI_MODEL_FEATURE = AI_MODEL_FEATURE = {}));
@@ -15,4 +15,6 @@ var AI_MODEL_STRATEGY;
15
15
  AI_MODEL_STRATEGY["LLAMA_TEXT_GENERATION"] = "llama_text_generation";
16
16
  AI_MODEL_STRATEGY["QWEN_TEXT_GENERATION"] = "qwen_text_generation";
17
17
  AI_MODEL_STRATEGY["GROK_IMAGE_GENERATION"] = "grok_image_generation";
18
+ AI_MODEL_STRATEGY["ELEVENLABS_SPEECH_TO_TEXT"] = "elevenlabs_speech_to_text";
19
+ AI_MODEL_STRATEGY["ELEVENLABS_TEXT_TO_SPEECH"] = "elevenlabs_text_to_speech";
18
20
  })(AI_MODEL_STRATEGY || (exports.AI_MODEL_STRATEGY = AI_MODEL_STRATEGY = {}));
@@ -14,6 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./ai-model-config-selector-type.enum"), exports);
17
18
  __exportStar(require("./ai-model-content-type.enum"), exports);
18
19
  __exportStar(require("./ai-model-feature.enum"), exports);
19
20
  __exportStar(require("./ai-model-status.enum"), exports);
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.IMAGE_FORMAT = void 0;
4
+ var IMAGE_FORMAT;
5
+ (function (IMAGE_FORMAT) {
6
+ IMAGE_FORMAT["SQUARE"] = "SQUARE";
7
+ IMAGE_FORMAT["VERTICAL"] = "VERTICAL";
8
+ IMAGE_FORMAT["HORIZONTAL"] = "HORIZONTAL";
9
+ })(IMAGE_FORMAT || (exports.IMAGE_FORMAT = IMAGE_FORMAT = {}));
@@ -15,5 +15,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./chat-status.enum"), exports);
18
- __exportStar(require("./dalle-image-format.enum"), exports);
18
+ __exportStar(require("./image-format.enum"), exports);
19
19
  __exportStar(require("./dalle-image-size.enum"), exports);
@@ -1089,4 +1089,39 @@ exports.ERRORS = {
1089
1089
  message: 'Произошла ошибка при отправке Email',
1090
1090
  httpCode: 422,
1091
1091
  },
1092
+ CHAT_INVALID_PARAMS: {
1093
+ code: 'A243',
1094
+ message: 'Указаны неверные параметры при отправке сообщения',
1095
+ httpCode: 400,
1096
+ },
1097
+ CHAT_FILE_MUST_BE_AUDIO: {
1098
+ code: 'A244',
1099
+ message: 'Загруженный файл должен быть в аудио формате',
1100
+ httpCode: 400,
1101
+ },
1102
+ S3_STREAM_ERROR: {
1103
+ code: 'A245',
1104
+ message: 'Произошла ошибка при потоковом чтении файла из хранилища',
1105
+ httpCode: 500,
1106
+ },
1107
+ CHAT_DOES_NOT_SUPPORT_CONVERSATION: {
1108
+ code: 'A246',
1109
+ message: 'Чат поддерживает отправку только одного сообщения',
1110
+ httpCode: 400,
1111
+ },
1112
+ CHAT_INVALID_FILE_ATTACHMENT: {
1113
+ code: 'A247',
1114
+ message: 'Чат не поддерживает один или несколько из приложенных файлов',
1115
+ httpCode: 400,
1116
+ },
1117
+ FFMPEG_AUDIO_COMPRESSION_ERROR: {
1118
+ code: 'A248',
1119
+ message: 'Произошла ошибка при компрессии аудио',
1120
+ httpCode: 500,
1121
+ },
1122
+ VOICE_TYPE_NOT_FOUND: {
1123
+ code: 'A249',
1124
+ message: 'Не удалось найти указанный тип голоса',
1125
+ httpCode: 400,
1126
+ },
1092
1127
  };
@@ -4,5 +4,6 @@ exports.FILE_TYPE = void 0;
4
4
  var FILE_TYPE;
5
5
  (function (FILE_TYPE) {
6
6
  FILE_TYPE["IMAGE"] = "image";
7
+ FILE_TYPE["AUDIO"] = "audio";
7
8
  FILE_TYPE["OTHER"] = "other";
8
9
  })(FILE_TYPE || (exports.FILE_TYPE = FILE_TYPE = {}));
@@ -1,7 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DELETE_UNUSED_FILES_AFTER_HOURS = exports.VALID_MIMETYPES = exports.IMAGE_MIMETYPES = exports.MAX_UPLOAD_SIZE = void 0;
4
- exports.MAX_UPLOAD_SIZE = 5 * 1024 * 1024; // 5MB
5
- exports.IMAGE_MIMETYPES = ['image/jpeg', 'image/png', 'image/webp'];
6
- exports.VALID_MIMETYPES = [...exports.IMAGE_MIMETYPES];
3
+ exports.DELETE_UNUSED_FILES_AFTER_HOURS = exports.SUPPORTED_FILES = exports.MAX_AUDIO_UPLOAD_SIZE = exports.MAX_IMAGE_UPLOAD_SIZE = void 0;
4
+ const enums_1 = require("./enums");
5
+ exports.MAX_IMAGE_UPLOAD_SIZE = 5 * 1024 * 1024; // 5 MB
6
+ exports.MAX_AUDIO_UPLOAD_SIZE = 500 * 1024 * 1024; // 500 MB
7
+ exports.SUPPORTED_FILES = new Map([
8
+ ['image/jpeg', { type: enums_1.FILE_TYPE.IMAGE, size: exports.MAX_IMAGE_UPLOAD_SIZE }],
9
+ ['image/png', { type: enums_1.FILE_TYPE.IMAGE, size: exports.MAX_IMAGE_UPLOAD_SIZE }],
10
+ ['image/webp', { type: enums_1.FILE_TYPE.IMAGE, size: exports.MAX_IMAGE_UPLOAD_SIZE }],
11
+ ['audio/mp3', { type: enums_1.FILE_TYPE.AUDIO, size: exports.MAX_AUDIO_UPLOAD_SIZE }],
12
+ ['audio/mpeg', { type: enums_1.FILE_TYPE.AUDIO, size: exports.MAX_AUDIO_UPLOAD_SIZE }],
13
+ ['audio/wav', { type: enums_1.FILE_TYPE.AUDIO, size: exports.MAX_AUDIO_UPLOAD_SIZE }],
14
+ ]);
7
15
  exports.DELETE_UNUSED_FILES_AFTER_HOURS = 12;
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AiModelConfigSchema = exports.AiModelVoiceTypeParameter = exports.AiModelVoiceTypeOptionSchema = exports.AiModelImageSizeParameter = exports.AiModelImageSizeOptionSchema = exports.AiModelConfigParameterSchema = void 0;
4
+ const zod_1 = require("zod");
5
+ const constants_1 = require("../constants");
6
+ exports.AiModelConfigParameterSchema = zod_1.z.object({
7
+ id: zod_1.z.string(),
8
+ title: zod_1.z.string(),
9
+ order: zod_1.z.number(),
10
+ icon: zod_1.z.string().optional(),
11
+ });
12
+ // IMAGE SIZE
13
+ exports.AiModelImageSizeOptionSchema = exports.AiModelConfigParameterSchema.extend({
14
+ dimensions: zod_1.z.object({
15
+ w: zod_1.z.number(),
16
+ h: zod_1.z.number(),
17
+ }),
18
+ });
19
+ exports.AiModelImageSizeParameter = zod_1.z.object({
20
+ title: zod_1.z.string(),
21
+ options: zod_1.z.array(exports.AiModelImageSizeOptionSchema),
22
+ });
23
+ // VOICE TYPE
24
+ exports.AiModelVoiceTypeOptionSchema = exports.AiModelConfigParameterSchema.extend({
25
+ title: zod_1.z.string(),
26
+ previewUrl: zod_1.z.string(),
27
+ languages: zod_1.z.array(zod_1.z.object({
28
+ title: zod_1.z.string(),
29
+ icon: zod_1.z.string(),
30
+ })),
31
+ description: zod_1.z.string(),
32
+ tags: zod_1.z.array(zod_1.z.string()),
33
+ order: zod_1.z.number(),
34
+ voice_id: zod_1.z.string(),
35
+ });
36
+ exports.AiModelVoiceTypeParameter = zod_1.z.object({
37
+ title: zod_1.z.string(),
38
+ options: zod_1.z.array(exports.AiModelVoiceTypeOptionSchema),
39
+ });
40
+ // CONFIG
41
+ exports.AiModelConfigSchema = zod_1.z.object({
42
+ parameters: zod_1.z
43
+ .object({
44
+ [constants_1.AI_MODEL_CONFIG_PARAM.IMAGE_SIZE]: exports.AiModelImageSizeParameter.optional(),
45
+ [constants_1.AI_MODEL_CONFIG_PARAM.VOICE_TYPE]: exports.AiModelVoiceTypeParameter.optional(),
46
+ })
47
+ .strict(),
48
+ });
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.AiModelWithUnlockedBySchema = exports.CreateAiModelSchema = exports.AiModelSchema = void 0;
4
4
  const zod_1 = require("zod");
5
5
  const constants_1 = require("../constants");
6
+ const ai_model_config_schema_1 = require("./ai-model-config.schema");
6
7
  exports.AiModelSchema = zod_1.z.object({
7
8
  uuid: zod_1.z.string().uuid(),
8
9
  title: zod_1.z.string(),
@@ -19,6 +20,7 @@ exports.AiModelSchema = zod_1.z.object({
19
20
  png: zod_1.z.string(),
20
21
  }),
21
22
  maxInputLength: zod_1.z.number(),
23
+ config: ai_model_config_schema_1.AiModelConfigSchema,
22
24
  createdAt: zod_1.z.date(),
23
25
  updatedAt: zod_1.z.date(),
24
26
  });
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ChatSchema = void 0;
4
4
  const zod_1 = require("zod");
5
5
  const constants_1 = require("../constants");
6
+ const message_schema_1 = require("./message.schema");
6
7
  exports.ChatSchema = zod_1.z.object({
7
8
  uuid: zod_1.z.string().uuid(),
8
9
  userId: zod_1.z.nullable(zod_1.z.string().uuid()),
@@ -11,6 +12,7 @@ exports.ChatSchema = zod_1.z.object({
11
12
  aIModelId: zod_1.z.string().uuid(),
12
13
  title: zod_1.z.string(),
13
14
  chatStatus: zod_1.z.enum(Object.values(constants_1.CHAT_STATUS_ENUM)),
15
+ messages: zod_1.z.array(message_schema_1.MessageSchema),
14
16
  createdAt: zod_1.z.date(),
15
17
  updatedAt: zod_1.z.date(),
16
18
  deletedAt: zod_1.z.nullable(zod_1.z.date()),
@@ -14,6 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./ai-model-config.schema"), exports);
17
18
  __exportStar(require("./ai-model-formatted.schema"), exports);
18
19
  __exportStar(require("./ai-model.schema"), exports);
19
20
  __exportStar(require("./category.schema"), exports);
@@ -12,7 +12,7 @@ exports.MessageSchema = zod_1.z.object({
12
12
  tokenUsage: zod_1.z.number(),
13
13
  userReaction: zod_1.z.nullable(zod_1.z.enum(Object.values(constants_1.USER_REACTION))),
14
14
  files: zod_1.z.array(file_schema_1.FileSchema),
15
- imageFormat: zod_1.z.nullable(zod_1.z.enum(Object.values(constants_1.DALLE_IMAGE_FORMAT_ENUM))),
15
+ imageFormat: zod_1.z.nullable(zod_1.z.nativeEnum(constants_1.IMAGE_FORMAT)),
16
16
  status: zod_1.z.nativeEnum(constants_1.MESSAGE_STATUS),
17
17
  createdAt: zod_1.z.date(),
18
18
  updatedAt: zod_1.z.date(),
@@ -1,4 +1,4 @@
1
- import { ChatSchema, MessageSchema } from '../../models';
1
+ import { ChatSchema } from '../../models';
2
2
  import { z } from 'zod';
3
3
 
4
4
  export namespace GetLastActiveChatCommand {
@@ -8,9 +8,7 @@ export namespace GetLastActiveChatCommand {
8
8
  });
9
9
 
10
10
  export const Response = z.object({
11
- data: ChatSchema.extend({
12
- messages: z.array(MessageSchema),
13
- }),
11
+ data: ChatSchema,
14
12
  });
15
13
 
16
14
  export type Response = z.infer<typeof Response>;
@@ -1,12 +1,17 @@
1
1
  import { ChatSchema, MessageSchema } from '../../models';
2
2
  import { z } from 'zod';
3
- import { DALLE_IMAGE_SIZE } from '../../constants';
3
+ import { AI_MODEL_CONFIG_PARAM } from '../../constants';
4
4
 
5
5
  export namespace CreateImageMessageCommand {
6
6
  export const RequestSchema = z.intersection(
7
7
  MessageSchema.pick({ text: true }),
8
8
  z.object({
9
- size: z.nativeEnum(DALLE_IMAGE_SIZE),
9
+ params: z.array(
10
+ z.object({
11
+ type: z.nativeEnum(AI_MODEL_CONFIG_PARAM),
12
+ option: z.string().uuid(),
13
+ }),
14
+ ),
10
15
  }),
11
16
  );
12
17
 
@@ -0,0 +1,19 @@
1
+ import { ChatSchema, MessageSchema } from '../../models';
2
+ import { z } from 'zod';
3
+
4
+ export namespace CreateSpeechToTextMessageCommand {
5
+ export const RequestSchema = z.object({
6
+ fileId: z.string().uuid(),
7
+ });
8
+ export type Request = z.infer<typeof RequestSchema>;
9
+
10
+ export const RequestParamSchema = ChatSchema.pick({
11
+ uuid: true,
12
+ });
13
+ export type RequestParam = z.infer<typeof RequestParamSchema>;
14
+
15
+ export const ResponseSchema = z.object({
16
+ data: MessageSchema,
17
+ });
18
+ export type Response = z.infer<typeof ResponseSchema>;
19
+ }
@@ -0,0 +1,26 @@
1
+ import { AI_MODEL_CONFIG_PARAM } from '../../constants';
2
+ import { ChatSchema, MessageSchema } from '../../models';
3
+ import { z } from 'zod';
4
+
5
+ export namespace CreateTextToSpeechMessageCommand {
6
+ export const RequestSchema = z.object({
7
+ text: z.string(),
8
+ params: z.array(
9
+ z.object({
10
+ type: z.nativeEnum(AI_MODEL_CONFIG_PARAM),
11
+ option: z.string().uuid(),
12
+ }),
13
+ ),
14
+ });
15
+ export type Request = z.infer<typeof RequestSchema>;
16
+
17
+ export const RequestParamSchema = ChatSchema.pick({
18
+ uuid: true,
19
+ });
20
+ export type RequestParam = z.infer<typeof RequestParamSchema>;
21
+
22
+ export const ResponseSchema = z.object({
23
+ data: MessageSchema,
24
+ });
25
+ export type Response = z.infer<typeof ResponseSchema>;
26
+ }
@@ -1,4 +1,6 @@
1
1
  export * from './create-image-message.command';
2
+ export * from './create-speech-to-text-message.command';
2
3
  export * from './create-text-message.command';
4
+ export * from './create-text-to-speech-message.command';
3
5
  export * from './find-message-by-uuid.command';
4
6
  export * from './rate-message.command';
@@ -0,0 +1,4 @@
1
+ export enum AI_MODEL_CONFIG_PARAM {
2
+ IMAGE_SIZE = 'image-size',
3
+ VOICE_TYPE = 'voice-type',
4
+ }
@@ -1,6 +1,8 @@
1
1
  export const AI_MODEL_CONTENT_TYPE = {
2
2
  TEXT: 'TEXT',
3
3
  IMAGE: 'IMAGE',
4
+ TEXT_TO_SPEECH: 'TEXT_TO_SPEECH',
5
+ SPEECH_TO_TEXT: 'SPEECH_TO_TEXT',
4
6
  } as const;
5
7
 
6
8
  export type TAIModelContentTypeEnum =
@@ -1,3 +1,4 @@
1
1
  export enum AI_MODEL_FEATURE {
2
2
  IMAGE_ATTACHMENT = 'image_attachment',
3
+ AUDIO_ATTACHMENT = 'audio_attachment',
3
4
  }
@@ -11,4 +11,6 @@ export enum AI_MODEL_STRATEGY {
11
11
  LLAMA_TEXT_GENERATION = 'llama_text_generation',
12
12
  QWEN_TEXT_GENERATION = 'qwen_text_generation',
13
13
  GROK_IMAGE_GENERATION = 'grok_image_generation',
14
+ ELEVENLABS_SPEECH_TO_TEXT = 'elevenlabs_speech_to_text',
15
+ ELEVENLABS_TEXT_TO_SPEECH = 'elevenlabs_text_to_speech',
14
16
  }
@@ -1,3 +1,4 @@
1
+ export * from './ai-model-config-selector-type.enum';
1
2
  export * from './ai-model-content-type.enum';
2
3
  export * from './ai-model-feature.enum';
3
4
  export * from './ai-model-status.enum';
@@ -0,0 +1,5 @@
1
+ export enum IMAGE_FORMAT {
2
+ SQUARE = 'SQUARE',
3
+ VERTICAL = 'VERTICAL',
4
+ HORIZONTAL = 'HORIZONTAL',
5
+ }
@@ -1,3 +1,3 @@
1
1
  export * from './chat-status.enum';
2
- export * from './dalle-image-format.enum';
2
+ export * from './image-format.enum';
3
3
  export * from './dalle-image-size.enum';
@@ -1095,4 +1095,39 @@ export const ERRORS = {
1095
1095
  message: 'Произошла ошибка при отправке Email',
1096
1096
  httpCode: 422,
1097
1097
  },
1098
+ CHAT_INVALID_PARAMS: {
1099
+ code: 'A243',
1100
+ message: 'Указаны неверные параметры при отправке сообщения',
1101
+ httpCode: 400,
1102
+ },
1103
+ CHAT_FILE_MUST_BE_AUDIO: {
1104
+ code: 'A244',
1105
+ message: 'Загруженный файл должен быть в аудио формате',
1106
+ httpCode: 400,
1107
+ },
1108
+ S3_STREAM_ERROR: {
1109
+ code: 'A245',
1110
+ message: 'Произошла ошибка при потоковом чтении файла из хранилища',
1111
+ httpCode: 500,
1112
+ },
1113
+ CHAT_DOES_NOT_SUPPORT_CONVERSATION: {
1114
+ code: 'A246',
1115
+ message: 'Чат поддерживает отправку только одного сообщения',
1116
+ httpCode: 400,
1117
+ },
1118
+ CHAT_INVALID_FILE_ATTACHMENT: {
1119
+ code: 'A247',
1120
+ message: 'Чат не поддерживает один или несколько из приложенных файлов',
1121
+ httpCode: 400,
1122
+ },
1123
+ FFMPEG_AUDIO_COMPRESSION_ERROR: {
1124
+ code: 'A248',
1125
+ message: 'Произошла ошибка при компрессии аудио',
1126
+ httpCode: 500,
1127
+ },
1128
+ VOICE_TYPE_NOT_FOUND: {
1129
+ code: 'A249',
1130
+ message: 'Не удалось найти указанный тип голоса',
1131
+ httpCode: 400,
1132
+ },
1098
1133
  };
@@ -1,4 +1,5 @@
1
1
  export enum FILE_TYPE {
2
2
  IMAGE = 'image',
3
+ AUDIO = 'audio',
3
4
  OTHER = 'other',
4
5
  }
@@ -1,7 +1,21 @@
1
- export const MAX_UPLOAD_SIZE = 5 * 1024 * 1024; // 5MB
1
+ import { FILE_TYPE } from './enums';
2
2
 
3
- export const IMAGE_MIMETYPES = ['image/jpeg', 'image/png', 'image/webp'];
3
+ export const MAX_IMAGE_UPLOAD_SIZE = 5 * 1024 * 1024; // 5 MB
4
+ export const MAX_AUDIO_UPLOAD_SIZE = 500 * 1024 * 1024; // 500 MB
4
5
 
5
- export const VALID_MIMETYPES = [...IMAGE_MIMETYPES];
6
+ export const SUPPORTED_FILES = new Map<
7
+ string,
8
+ {
9
+ type: FILE_TYPE;
10
+ size: number;
11
+ }
12
+ >([
13
+ ['image/jpeg', { type: FILE_TYPE.IMAGE, size: MAX_IMAGE_UPLOAD_SIZE }],
14
+ ['image/png', { type: FILE_TYPE.IMAGE, size: MAX_IMAGE_UPLOAD_SIZE }],
15
+ ['image/webp', { type: FILE_TYPE.IMAGE, size: MAX_IMAGE_UPLOAD_SIZE }],
16
+ ['audio/mp3', { type: FILE_TYPE.AUDIO, size: MAX_AUDIO_UPLOAD_SIZE }],
17
+ ['audio/mpeg', { type: FILE_TYPE.AUDIO, size: MAX_AUDIO_UPLOAD_SIZE }],
18
+ ['audio/wav', { type: FILE_TYPE.AUDIO, size: MAX_AUDIO_UPLOAD_SIZE }],
19
+ ]);
6
20
 
7
21
  export const DELETE_UNUSED_FILES_AFTER_HOURS = 12;
@@ -0,0 +1,63 @@
1
+ import { z } from 'zod';
2
+ import { AI_MODEL_CONFIG_PARAM } from '../constants';
3
+
4
+ export const AiModelConfigParameterSchema = z.object({
5
+ id: z.string(),
6
+ title: z.string(),
7
+ order: z.number(),
8
+ icon: z.string().optional(),
9
+ });
10
+
11
+ // IMAGE SIZE
12
+
13
+ export const AiModelImageSizeOptionSchema = AiModelConfigParameterSchema.extend({
14
+ dimensions: z.object({
15
+ w: z.number(),
16
+ h: z.number(),
17
+ }),
18
+ });
19
+
20
+ export const AiModelImageSizeParameter = z.object({
21
+ title: z.string(),
22
+ options: z.array(AiModelImageSizeOptionSchema),
23
+ });
24
+
25
+ // VOICE TYPE
26
+
27
+ export const AiModelVoiceTypeOptionSchema = AiModelConfigParameterSchema.extend({
28
+ title: z.string(),
29
+ previewUrl: z.string(),
30
+ languages: z.array(
31
+ z.object({
32
+ title: z.string(),
33
+ icon: z.string(),
34
+ }),
35
+ ),
36
+ description: z.string(),
37
+ tags: z.array(z.string()),
38
+ order: z.number(),
39
+ voice_id: z.string(),
40
+ });
41
+
42
+ export const AiModelVoiceTypeParameter = z.object({
43
+ title: z.string(),
44
+ options: z.array(AiModelVoiceTypeOptionSchema),
45
+ });
46
+
47
+ // CONFIG
48
+
49
+ export const AiModelConfigSchema = z.object({
50
+ parameters: z
51
+ .object({
52
+ [AI_MODEL_CONFIG_PARAM.IMAGE_SIZE]: AiModelImageSizeParameter.optional(),
53
+ [AI_MODEL_CONFIG_PARAM.VOICE_TYPE]: AiModelVoiceTypeParameter.optional(),
54
+ })
55
+ .strict(),
56
+ });
57
+
58
+ export type AiModelConfigParameter = z.infer<typeof AiModelConfigParameterSchema>;
59
+ export type AiModelImageSizeOption = z.infer<typeof AiModelImageSizeOptionSchema>;
60
+ export type AiModelImageSizeParameter = z.infer<typeof AiModelImageSizeParameter>;
61
+ export type AiModelConfig = z.infer<typeof AiModelConfigSchema>;
62
+ export type AiModelVoiceTypeOption = z.infer<typeof AiModelVoiceTypeOptionSchema>;
63
+ export type AiModelVoiceTypeParameter = z.infer<typeof AiModelVoiceTypeParameter>;
@@ -5,6 +5,7 @@ import {
5
5
  AI_MODEL_STATUS,
6
6
  TAIModelContentTypeEnum,
7
7
  } from '../constants';
8
+ import { AiModelConfigSchema } from './ai-model-config.schema';
8
9
 
9
10
  export const AiModelSchema = z.object({
10
11
  uuid: z.string().uuid(),
@@ -22,6 +23,7 @@ export const AiModelSchema = z.object({
22
23
  png: z.string(),
23
24
  }),
24
25
  maxInputLength: z.number(),
26
+ config: AiModelConfigSchema,
25
27
  createdAt: z.date(),
26
28
  updatedAt: z.date(),
27
29
  });
@@ -1,5 +1,6 @@
1
1
  import { z } from 'zod';
2
2
  import { CHAT_STATUS_ENUM, TChatStatusEnum } from '../constants';
3
+ import { MessageSchema } from './message.schema';
3
4
 
4
5
  export const ChatSchema = z.object({
5
6
  uuid: z.string().uuid(),
@@ -9,6 +10,7 @@ export const ChatSchema = z.object({
9
10
  aIModelId: z.string().uuid(),
10
11
  title: z.string(),
11
12
  chatStatus: z.enum(Object.values(CHAT_STATUS_ENUM) as [TChatStatusEnum]),
13
+ messages: z.array(MessageSchema),
12
14
 
13
15
  createdAt: z.date(),
14
16
  updatedAt: z.date(),
package/models/index.ts CHANGED
@@ -1,3 +1,4 @@
1
+ export * from './ai-model-config.schema';
1
2
  export * from './ai-model-formatted.schema';
2
3
  export * from './ai-model.schema';
3
4
  export * from './category.schema';
@@ -1,11 +1,5 @@
1
1
  import { z } from 'zod';
2
- import {
3
- DALLE_IMAGE_FORMAT_ENUM,
4
- MESSAGE_STATUS,
5
- TDalleImageFormatEnum,
6
- TUserReactionEnum,
7
- USER_REACTION,
8
- } from '../constants';
2
+ import { IMAGE_FORMAT, MESSAGE_STATUS, TUserReactionEnum, USER_REACTION } from '../constants';
9
3
  import { FileSchema } from './file.schema';
10
4
 
11
5
  export const MessageSchema = z.object({
@@ -16,9 +10,7 @@ export const MessageSchema = z.object({
16
10
  tokenUsage: z.number(),
17
11
  userReaction: z.nullable(z.enum(Object.values(USER_REACTION) as [TUserReactionEnum])),
18
12
  files: z.array(FileSchema),
19
- imageFormat: z.nullable(
20
- z.enum(Object.values(DALLE_IMAGE_FORMAT_ENUM) as [TDalleImageFormatEnum]),
21
- ),
13
+ imageFormat: z.nullable(z.nativeEnum(IMAGE_FORMAT)),
22
14
  status: z.nativeEnum(MESSAGE_STATUS),
23
15
 
24
16
  createdAt: z.date(),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@purpleschool/gptbot",
3
- "version": "0.5.73",
3
+ "version": "0.5.75",
4
4
  "description": "",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",
@@ -1,9 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DALLE_IMAGE_FORMAT_ARRAY = exports.DALLE_IMAGE_FORMAT_ENUM = void 0;
4
- exports.DALLE_IMAGE_FORMAT_ENUM = {
5
- SQUARE: 'SQUARE',
6
- VERTICAL: 'VERTICAL',
7
- HORIZONTAL: 'HORIZONTAL',
8
- };
9
- exports.DALLE_IMAGE_FORMAT_ARRAY = Object.values(exports.DALLE_IMAGE_FORMAT_ENUM);
@@ -1,10 +0,0 @@
1
- export const DALLE_IMAGE_FORMAT_ENUM = {
2
- SQUARE: 'SQUARE',
3
- VERTICAL: 'VERTICAL',
4
- HORIZONTAL: 'HORIZONTAL',
5
- } as const;
6
-
7
- export type TDalleImageFormatEnum =
8
- (typeof DALLE_IMAGE_FORMAT_ENUM)[keyof typeof DALLE_IMAGE_FORMAT_ENUM];
9
- export const DALLE_IMAGE_FORMAT_ARRAY: TDalleImageFormatEnum[] =
10
- Object.values(DALLE_IMAGE_FORMAT_ENUM);