@purpleschool/gptbot 0.7.51 → 0.7.52-chats

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 (31) hide show
  1. package/api/controllers/http/cabinet.ts +5 -0
  2. package/api/controllers/http/index.ts +1 -0
  3. package/api/routes.ts +3 -0
  4. package/build/api/controllers/http/cabinet.js +7 -0
  5. package/build/api/controllers/http/index.js +1 -0
  6. package/build/api/routes.js +3 -0
  7. package/build/commands/cabinet/get-user-statistics.command.js +30 -0
  8. package/build/commands/cabinet/index.js +17 -0
  9. package/build/commands/chat/create-chat.command.js +1 -3
  10. package/build/commands/chat/find-chat-by-uuid.command.js +1 -1
  11. package/build/commands/chat/find-chats.command.js +1 -3
  12. package/build/commands/chat/get-last-active-chat-command.js +1 -1
  13. package/build/commands/folder/find-folder-by-uuid-with-chats.command.js +1 -3
  14. package/build/commands/index.js +1 -0
  15. package/build/constants/errors/errors.js +10 -0
  16. package/build/models/chat-with-messages.schema.js +9 -0
  17. package/build/models/chat.schema.js +0 -2
  18. package/build/models/index.js +1 -0
  19. package/commands/cabinet/get-user-statistics.command.ts +36 -0
  20. package/commands/cabinet/index.ts +1 -0
  21. package/commands/chat/create-chat.command.ts +2 -4
  22. package/commands/chat/find-chat-by-uuid.command.ts +2 -2
  23. package/commands/chat/find-chats.command.ts +2 -6
  24. package/commands/chat/get-last-active-chat-command.ts +2 -2
  25. package/commands/folder/find-folder-by-uuid-with-chats.command.ts +2 -6
  26. package/commands/index.ts +1 -0
  27. package/constants/errors/errors.ts +10 -0
  28. package/models/chat-with-messages.schema.ts +7 -0
  29. package/models/chat.schema.ts +0 -2
  30. package/models/index.ts +1 -0
  31. package/package.json +1 -1
@@ -0,0 +1,5 @@
1
+ export const CABINET_CONTROLLER = 'cabinet' as const;
2
+
3
+ export const CABINET_ROUTES = {
4
+ GET_USER_STATISTICS: 'statistics',
5
+ } as const;
@@ -48,3 +48,4 @@ export * from './video';
48
48
  export * from './writer';
49
49
  export * from './image-editor';
50
50
  export * from './daily-streak';
51
+ export * from './cabinet';
package/api/routes.ts CHANGED
@@ -301,4 +301,7 @@ export const REST_API = {
301
301
  GET: `${ROOT}/${CONTROLLERS.DAILY_STREAK_PRIVATE_CONTROLLER}/${CONTROLLERS.DAILY_STREAK_ROUTES.GET}`,
302
302
  COLLECT: `${ROOT}/${CONTROLLERS.DAILY_STREAK_PRIVATE_CONTROLLER}/${CONTROLLERS.DAILY_STREAK_ROUTES.COLLECT}`,
303
303
  },
304
+ CABINET: {
305
+ GET_USER_STATISTICS: `${ROOT}/${CONTROLLERS.CABINET_CONTROLLER}/${CONTROLLERS.CABINET_ROUTES.GET_USER_STATISTICS}`,
306
+ },
304
307
  } as const;
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CABINET_ROUTES = exports.CABINET_CONTROLLER = void 0;
4
+ exports.CABINET_CONTROLLER = 'cabinet';
5
+ exports.CABINET_ROUTES = {
6
+ GET_USER_STATISTICS: 'statistics',
7
+ };
@@ -64,3 +64,4 @@ __exportStar(require("./video"), exports);
64
64
  __exportStar(require("./writer"), exports);
65
65
  __exportStar(require("./image-editor"), exports);
66
66
  __exportStar(require("./daily-streak"), exports);
67
+ __exportStar(require("./cabinet"), exports);
@@ -270,4 +270,7 @@ exports.REST_API = {
270
270
  GET: `${exports.ROOT}/${CONTROLLERS.DAILY_STREAK_PRIVATE_CONTROLLER}/${CONTROLLERS.DAILY_STREAK_ROUTES.GET}`,
271
271
  COLLECT: `${exports.ROOT}/${CONTROLLERS.DAILY_STREAK_PRIVATE_CONTROLLER}/${CONTROLLERS.DAILY_STREAK_ROUTES.COLLECT}`,
272
272
  },
273
+ CABINET: {
274
+ GET_USER_STATISTICS: `${exports.ROOT}/${CONTROLLERS.CABINET_CONTROLLER}/${CONTROLLERS.CABINET_ROUTES.GET_USER_STATISTICS}`,
275
+ },
273
276
  };
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GetUserStatisticsCommand = void 0;
4
+ const zod_1 = require("zod");
5
+ var GetUserStatisticsCommand;
6
+ (function (GetUserStatisticsCommand) {
7
+ GetUserStatisticsCommand.RequestSchema = zod_1.z.object({
8
+ startDate: zod_1.z.string().refine((v) => !isNaN(Date.parse(v)), {
9
+ message: 'from must be a valid date string',
10
+ }),
11
+ endDate: zod_1.z.string().refine((v) => !isNaN(Date.parse(v)), {
12
+ message: 'to must be a valid date string',
13
+ }),
14
+ groupByDays: zod_1.z
15
+ .preprocess((val) => (val === undefined ? 1 : Number(val)), zod_1.z.number().int().positive().max(31))
16
+ .default(1),
17
+ });
18
+ GetUserStatisticsCommand.UserStatisticsResponseSchema = zod_1.z.object({
19
+ startDate: zod_1.z.string(),
20
+ endDate: zod_1.z.string(),
21
+ total_tokens: zod_1.z.number(),
22
+ total_messages: zod_1.z.number(),
23
+ total_images: zod_1.z.number(),
24
+ total_videos: zod_1.z.number(),
25
+ total_presentations: zod_1.z.number(),
26
+ });
27
+ GetUserStatisticsCommand.ResponseSchema = zod_1.z.object({
28
+ data: zod_1.z.array(GetUserStatisticsCommand.UserStatisticsResponseSchema),
29
+ });
30
+ })(GetUserStatisticsCommand || (exports.GetUserStatisticsCommand = GetUserStatisticsCommand = {}));
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./get-user-statistics.command"), exports);
@@ -12,8 +12,6 @@ var CreateChatCommand;
12
12
  folderId: zod_1.z.string().uuid().optional(),
13
13
  });
14
14
  CreateChatCommand.ResponseSchema = zod_1.z.object({
15
- data: models_1.ChatSchema.extend({
16
- messages: zod_1.z.array(models_1.MessageSchema),
17
- }),
15
+ data: models_1.ChatWithMessagesSchema,
18
16
  });
19
17
  })(CreateChatCommand || (exports.CreateChatCommand = CreateChatCommand = {}));
@@ -9,6 +9,6 @@ var FindChatByUUIDCommand;
9
9
  uuid: true,
10
10
  });
11
11
  FindChatByUUIDCommand.ResponseSchema = zod_1.z.object({
12
- data: models_1.ChatSchema,
12
+ data: models_1.ChatWithMessagesSchema,
13
13
  });
14
14
  })(FindChatByUUIDCommand || (exports.FindChatByUUIDCommand = FindChatByUUIDCommand = {}));
@@ -13,9 +13,7 @@ var FindChatsCommand;
13
13
  const QuerySchema = zod_1.z.intersection(models_1.ChatSchema.pick({ categoryId: true, aIModelId: true }).partial(), models_1.AiModelSchema.pick({ contentType: true }).partial());
14
14
  FindChatsCommand.RequestQuerySchema = zod_1.z.intersection(QuerySchema, PaginationQuerySchema);
15
15
  FindChatsCommand.ResponseSchema = zod_1.z.object({
16
- data: zod_1.z.array(models_1.ChatSchema.extend({
17
- messages: zod_1.z.array(models_1.MessageSchema),
18
- })),
16
+ data: zod_1.z.array(models_1.ChatSchema),
19
17
  page: zod_1.z.number(),
20
18
  totalPages: zod_1.z.number(),
21
19
  });
@@ -10,6 +10,6 @@ var GetLastActiveChatCommand;
10
10
  aIModelId: true,
11
11
  });
12
12
  GetLastActiveChatCommand.Response = zod_1.z.object({
13
- data: models_1.ChatSchema,
13
+ data: models_1.ChatWithMessagesSchema,
14
14
  });
15
15
  })(GetLastActiveChatCommand || (exports.GetLastActiveChatCommand = GetLastActiveChatCommand = {}));
@@ -17,9 +17,7 @@ var FindFolderByUuidWithChatsCommand;
17
17
  });
18
18
  FindFolderByUuidWithChatsCommand.ResponseSchema = zod_1.default.object({
19
19
  data: models_1.FolderSchema.extend({
20
- chats: zod_1.default.array(models_1.ChatSchema.extend({
21
- messages: zod_1.default.array(models_1.MessageSchema),
22
- })),
20
+ chats: zod_1.default.array(models_1.ChatSchema),
23
21
  }),
24
22
  page: zod_1.default.number(),
25
23
  totalPages: zod_1.default.number(),
@@ -52,3 +52,4 @@ __exportStar(require("./prompt"), exports);
52
52
  __exportStar(require("./folder"), exports);
53
53
  __exportStar(require("./user-to-product"), exports);
54
54
  __exportStar(require("./daily-streak"), exports);
55
+ __exportStar(require("./cabinet"), exports);
@@ -1991,4 +1991,14 @@ exports.ERRORS = {
1991
1991
  message: 'Запрос был отклонен, т.к. может не соответствовать политике безопасности сервиса',
1992
1992
  httpCode: 400,
1993
1993
  },
1994
+ FAILED_TO_SAVE_USER_STATISTICS: {
1995
+ code: 'A409',
1996
+ message: 'не удалось сохранить статистику пользователя',
1997
+ httpCode: 500,
1998
+ },
1999
+ FAILED_TO_GET_USER_STATISTICS: {
2000
+ code: 'A410',
2001
+ message: 'не удалось получить статистику пользователя',
2002
+ httpCode: 500,
2003
+ },
1994
2004
  };
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ChatWithMessagesSchema = void 0;
4
+ const zod_1 = require("zod");
5
+ const chat_schema_1 = require("./chat.schema");
6
+ const message_schema_1 = require("./message.schema");
7
+ exports.ChatWithMessagesSchema = chat_schema_1.ChatSchema.extend({
8
+ messages: zod_1.z.array(message_schema_1.MessageSchema),
9
+ });
@@ -3,7 +3,6 @@ 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");
7
6
  exports.ChatSchema = zod_1.z.object({
8
7
  uuid: zod_1.z.string().uuid(),
9
8
  userId: zod_1.z.nullable(zod_1.z.string().uuid()),
@@ -12,7 +11,6 @@ exports.ChatSchema = zod_1.z.object({
12
11
  aIModelId: zod_1.z.string().uuid(),
13
12
  title: zod_1.z.string(),
14
13
  chatStatus: zod_1.z.enum(Object.values(constants_1.CHAT_STATUS_ENUM)),
15
- messages: zod_1.z.array(message_schema_1.MessageSchema),
16
14
  folderId: zod_1.z.string().nullable(),
17
15
  createdAt: zod_1.z.date(),
18
16
  updatedAt: zod_1.z.date(),
@@ -20,6 +20,7 @@ __exportStar(require("./ai-model-formatted.schema"), exports);
20
20
  __exportStar(require("./ai-model.schema"), exports);
21
21
  __exportStar(require("./ai-vendor.schema"), exports);
22
22
  __exportStar(require("./category.schema"), exports);
23
+ __exportStar(require("./chat-with-messages.schema"), exports);
23
24
  __exportStar(require("./chat.schema"), exports);
24
25
  __exportStar(require("./cloud-payments-receipt.schema"), exports);
25
26
  __exportStar(require("./course-author.schema"), exports);
@@ -0,0 +1,36 @@
1
+ import { z } from 'zod';
2
+
3
+ export namespace GetUserStatisticsCommand {
4
+ export const RequestSchema = z.object({
5
+ startDate: z.string().refine((v) => !isNaN(Date.parse(v)), {
6
+ message: 'from must be a valid date string',
7
+ }),
8
+ endDate: z.string().refine((v) => !isNaN(Date.parse(v)), {
9
+ message: 'to must be a valid date string',
10
+ }),
11
+ groupByDays: z
12
+ .preprocess(
13
+ (val) => (val === undefined ? 1 : Number(val)),
14
+ z.number().int().positive().max(31),
15
+ )
16
+ .default(1),
17
+ });
18
+
19
+ export type Request = z.infer<typeof RequestSchema>;
20
+
21
+ export const UserStatisticsResponseSchema = z.object({
22
+ startDate: z.string(),
23
+ endDate: z.string(),
24
+ total_tokens: z.number(),
25
+ total_messages: z.number(),
26
+ total_images: z.number(),
27
+ total_videos: z.number(),
28
+ total_presentations: z.number(),
29
+ });
30
+
31
+ export const ResponseSchema = z.object({
32
+ data: z.array(UserStatisticsResponseSchema),
33
+ });
34
+
35
+ export type Response = z.infer<typeof ResponseSchema>;
36
+ }
@@ -0,0 +1 @@
1
+ export * from './get-user-statistics.command';
@@ -1,4 +1,4 @@
1
- import { ChatSchema, MessageSchema } from '../../models';
1
+ import { ChatSchema, ChatWithMessagesSchema } from '../../models';
2
2
  import { z } from 'zod';
3
3
 
4
4
  export namespace CreateChatCommand {
@@ -12,9 +12,7 @@ export namespace CreateChatCommand {
12
12
  export type RequestSchema = z.infer<typeof RequestSchema>;
13
13
 
14
14
  export const ResponseSchema = z.object({
15
- data: ChatSchema.extend({
16
- messages: z.array(MessageSchema),
17
- }),
15
+ data: ChatWithMessagesSchema,
18
16
  });
19
17
 
20
18
  export type Response = z.infer<typeof ResponseSchema>;
@@ -1,4 +1,4 @@
1
- import { ChatSchema } from '../../models';
1
+ import { ChatSchema, ChatWithMessagesSchema } from '../../models';
2
2
  import { z } from 'zod';
3
3
 
4
4
  export namespace FindChatByUUIDCommand {
@@ -9,7 +9,7 @@ export namespace FindChatByUUIDCommand {
9
9
  export type Request = z.infer<typeof RequestParamsSchema>;
10
10
 
11
11
  export const ResponseSchema = z.object({
12
- data: ChatSchema,
12
+ data: ChatWithMessagesSchema,
13
13
  });
14
14
 
15
15
  export type Response = z.infer<typeof ResponseSchema>;
@@ -1,4 +1,4 @@
1
- import { AiModelSchema, ChatSchema, MessageSchema } from '../../models';
1
+ import { AiModelSchema, ChatSchema } from '../../models';
2
2
  import { z } from 'zod';
3
3
 
4
4
  export namespace FindChatsCommand {
@@ -18,11 +18,7 @@ export namespace FindChatsCommand {
18
18
  export type RequestQuery = z.infer<typeof RequestQuerySchema>;
19
19
 
20
20
  export const ResponseSchema = z.object({
21
- data: z.array(
22
- ChatSchema.extend({
23
- messages: z.array(MessageSchema),
24
- }),
25
- ),
21
+ data: z.array(ChatSchema),
26
22
  page: z.number(),
27
23
  totalPages: z.number(),
28
24
  });
@@ -1,4 +1,4 @@
1
- import { ChatSchema } from '../../models';
1
+ import { ChatSchema, ChatWithMessagesSchema } from '../../models';
2
2
  import { z } from 'zod';
3
3
 
4
4
  export namespace GetLastActiveChatCommand {
@@ -8,7 +8,7 @@ export namespace GetLastActiveChatCommand {
8
8
  });
9
9
 
10
10
  export const Response = z.object({
11
- data: ChatSchema,
11
+ data: ChatWithMessagesSchema,
12
12
  });
13
13
 
14
14
  export type Response = z.infer<typeof Response>;
@@ -1,5 +1,5 @@
1
1
  import z from 'zod';
2
- import { ChatSchema, FolderSchema, MessageSchema } from '../../models';
2
+ import { ChatSchema, FolderSchema } from '../../models';
3
3
 
4
4
  export namespace FindFolderByUuidWithChatsCommand {
5
5
  export const RequestParamSchema = FolderSchema.pick({
@@ -17,11 +17,7 @@ export namespace FindFolderByUuidWithChatsCommand {
17
17
 
18
18
  export const ResponseSchema = z.object({
19
19
  data: FolderSchema.extend({
20
- chats: z.array(
21
- ChatSchema.extend({
22
- messages: z.array(MessageSchema),
23
- }),
24
- ),
20
+ chats: z.array(ChatSchema),
25
21
  }),
26
22
  page: z.number(),
27
23
  totalPages: z.number(),
package/commands/index.ts CHANGED
@@ -36,3 +36,4 @@ export * from './prompt';
36
36
  export * from './folder';
37
37
  export * from './user-to-product';
38
38
  export * from './daily-streak';
39
+ export * from './cabinet';
@@ -1999,4 +1999,14 @@ export const ERRORS = {
1999
1999
  message: 'Запрос был отклонен, т.к. может не соответствовать политике безопасности сервиса',
2000
2000
  httpCode: 400,
2001
2001
  },
2002
+ FAILED_TO_SAVE_USER_STATISTICS: {
2003
+ code: 'A409',
2004
+ message: 'не удалось сохранить статистику пользователя',
2005
+ httpCode: 500,
2006
+ },
2007
+ FAILED_TO_GET_USER_STATISTICS: {
2008
+ code: 'A410',
2009
+ message: 'не удалось получить статистику пользователя',
2010
+ httpCode: 500,
2011
+ },
2002
2012
  };
@@ -0,0 +1,7 @@
1
+ import { z } from 'zod';
2
+ import { ChatSchema } from './chat.schema';
3
+ import { MessageSchema } from './message.schema';
4
+
5
+ export const ChatWithMessagesSchema = ChatSchema.extend({
6
+ messages: z.array(MessageSchema),
7
+ });
@@ -1,6 +1,5 @@
1
1
  import { z } from 'zod';
2
2
  import { CHAT_STATUS_ENUM, TChatStatusEnum } from '../constants';
3
- import { MessageSchema } from './message.schema';
4
3
 
5
4
  export const ChatSchema = z.object({
6
5
  uuid: z.string().uuid(),
@@ -10,7 +9,6 @@ export const ChatSchema = z.object({
10
9
  aIModelId: z.string().uuid(),
11
10
  title: z.string(),
12
11
  chatStatus: z.enum(Object.values(CHAT_STATUS_ENUM) as [TChatStatusEnum]),
13
- messages: z.array(MessageSchema),
14
12
  folderId: z.string().nullable(),
15
13
 
16
14
  createdAt: z.date(),
package/models/index.ts CHANGED
@@ -4,6 +4,7 @@ export * from './ai-model-formatted.schema';
4
4
  export * from './ai-model.schema';
5
5
  export * from './ai-vendor.schema';
6
6
  export * from './category.schema';
7
+ export * from './chat-with-messages.schema';
7
8
  export * from './chat.schema';
8
9
  export * from './cloud-payments-receipt.schema';
9
10
  export * from './course-author.schema';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@purpleschool/gptbot",
3
- "version": "0.7.51",
3
+ "version": "0.7.52-chats",
4
4
  "description": "",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",