@purpleschool/gptbot 0.7.24 → 0.7.26

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/api/routes.ts CHANGED
@@ -281,4 +281,7 @@ export const REST_API = {
281
281
  FEEDBACK_PRIVATE: {
282
282
  CHECK_IF_USER_READY_FOR_FEEDBACK: `${ROOT}/${CONTROLLERS.FEEDBACK_CONTROLLER_PRIVATE}/${CONTROLLERS.FEEDBACK_ROUTES.CHECK_IF_USER_READY_FOR_FEEDBACK}`,
283
283
  },
284
+ FEEDBACK_PUBLIC: {
285
+ CHECK_IF_USER_READY_FOR_FEEDBACK: `${ROOT}/${CONTROLLERS.FEEDBACK_CONTROLLER_PUBLIC}/${CONTROLLERS.FEEDBACK_ROUTES.CHECK_IF_USER_READY_FOR_FEEDBACK}`,
286
+ },
284
287
  } as const;
@@ -253,4 +253,7 @@ exports.REST_API = {
253
253
  FEEDBACK_PRIVATE: {
254
254
  CHECK_IF_USER_READY_FOR_FEEDBACK: `${exports.ROOT}/${CONTROLLERS.FEEDBACK_CONTROLLER_PRIVATE}/${CONTROLLERS.FEEDBACK_ROUTES.CHECK_IF_USER_READY_FOR_FEEDBACK}`,
255
255
  },
256
+ FEEDBACK_PUBLIC: {
257
+ CHECK_IF_USER_READY_FOR_FEEDBACK: `${exports.ROOT}/${CONTROLLERS.FEEDBACK_CONTROLLER_PUBLIC}/${CONTROLLERS.FEEDBACK_ROUTES.CHECK_IF_USER_READY_FOR_FEEDBACK}`,
258
+ },
256
259
  };
@@ -8,12 +8,7 @@ var VideoCommand;
8
8
  VideoCommand.RequestSchema = zod_1.z.object({
9
9
  modelId: zod_1.z.string().uuid(),
10
10
  prompt: zod_1.z.string(),
11
- params: zod_1.z.object({
12
- imageUrls: zod_1.z.array(zod_1.z.string()).optional(),
13
- duration: zod_1.z.number(),
14
- aspectRatio: zod_1.z.string().optional(),
15
- quality: zod_1.z.string().optional(),
16
- }),
11
+ params: models_1.VideoGenerationRequestParamsSchema,
17
12
  });
18
13
  VideoCommand.ResponseSchema = zod_1.z.object({
19
14
  data: models_1.ToolJobSchema,
@@ -22,3 +22,4 @@ __exportStar(require("./veo-aspect-ratio.enum"), exports);
22
22
  __exportStar(require("./veo-person-allow.enum"), exports);
23
23
  __exportStar(require("./veo-job-params-type.enum"), exports);
24
24
  __exportStar(require("./video-resolution.enum"), exports);
25
+ __exportStar(require("./video-pricing-rule-type.enum"), exports);
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.VIDEO_PRICING_RULE_TYPE = void 0;
4
+ var VIDEO_PRICING_RULE_TYPE;
5
+ (function (VIDEO_PRICING_RULE_TYPE) {
6
+ VIDEO_PRICING_RULE_TYPE["FLAT"] = "flat";
7
+ })(VIDEO_PRICING_RULE_TYPE || (exports.VIDEO_PRICING_RULE_TYPE = VIDEO_PRICING_RULE_TYPE = {}));
@@ -1,8 +1,28 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.calculateVideoPrice = calculateVideoPrice;
4
- const videoMaxDuration_1 = require("../../constants/tool-video/videoMaxDuration");
5
- function calculateVideoPrice(pricePerSecond) {
6
- const rawCost = videoMaxDuration_1.videoMaxDuration * pricePerSecond;
7
- return Math.ceil(rawCost);
3
+ exports.calculateVideoGenerationPrice = calculateVideoGenerationPrice;
4
+ const constants_1 = require("../../constants");
5
+ function matchesCondition(condition, params) {
6
+ const keys = Object.keys(condition);
7
+ return keys.every((key) => {
8
+ const expected = condition[key];
9
+ if (expected === undefined || expected === null || expected === '') {
10
+ return true;
11
+ }
12
+ const value = params[key];
13
+ if (value === undefined || value === null) {
14
+ return false;
15
+ }
16
+ return value === expected;
17
+ });
18
+ }
19
+ function calculateVideoGenerationPrice({ pricePerSecond, params, rules, }) {
20
+ const base = pricePerSecond * params.duration;
21
+ const flatMarkup = rules.reduce((sum, r) => {
22
+ if (r.type !== constants_1.VIDEO_PRICING_RULE_TYPE.FLAT) {
23
+ return sum;
24
+ }
25
+ return matchesCondition(r.condition, params) ? sum + r.value : sum;
26
+ }, 0);
27
+ return Math.ceil(base + flatMarkup);
8
28
  }
@@ -1,9 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.VideoModelSchema = exports.VideoModelParamsSchema = void 0;
3
+ exports.VideoModelSchema = exports.VideoModelPricingRulesSchema = exports.VideoModelPricingRuleConditionSchema = exports.VideoGenerationRequestParamsSchema = exports.VideoModelParamsSchema = void 0;
4
4
  const zod_1 = require("zod");
5
5
  const icon_variants_schema_1 = require("../../icon-variants.schema");
6
6
  const unlocked_by_subscription_schema_1 = require("../../unlocked-by-subscription.schema");
7
+ const constants_1 = require("../../../constants");
7
8
  exports.VideoModelParamsSchema = zod_1.z.object({
8
9
  imageAttachment: zod_1.z.object({
9
10
  supported: zod_1.z.boolean(),
@@ -19,6 +20,20 @@ exports.VideoModelParamsSchema = zod_1.z.object({
19
20
  .optional(),
20
21
  quality: zod_1.z.string().optional(),
21
22
  });
23
+ exports.VideoGenerationRequestParamsSchema = zod_1.z.object({
24
+ imageUrls: zod_1.z.string().array().optional(),
25
+ duration: zod_1.z.number(),
26
+ aspectRatio: zod_1.z.string().optional(),
27
+ quality: zod_1.z.string().optional(),
28
+ });
29
+ exports.VideoModelPricingRuleConditionSchema = zod_1.z.object({
30
+ aspectRatio: zod_1.z.string(),
31
+ });
32
+ exports.VideoModelPricingRulesSchema = zod_1.z.array(zod_1.z.object({
33
+ type: zod_1.z.nativeEnum(constants_1.VIDEO_PRICING_RULE_TYPE),
34
+ condition: exports.VideoModelPricingRuleConditionSchema,
35
+ value: zod_1.z.number(),
36
+ }));
22
37
  exports.VideoModelSchema = zod_1.z.object({
23
38
  uuid: zod_1.z.string(),
24
39
  title: zod_1.z.string(),
@@ -29,6 +44,7 @@ exports.VideoModelSchema = zod_1.z.object({
29
44
  maxInputLength: zod_1.z.number(),
30
45
  maxNegativeInputLength: zod_1.z.number(),
31
46
  params: exports.VideoModelParamsSchema,
47
+ pricingRules: exports.VideoModelPricingRulesSchema,
32
48
  unlockedBy: unlocked_by_subscription_schema_1.UnlockedBySchema.nullable(),
33
49
  canUse: zod_1.z.boolean(),
34
50
  });
@@ -1,15 +1,10 @@
1
1
  import { z } from 'zod';
2
- import { ToolJobSchema } from '../../../models';
2
+ import { ToolJobSchema, VideoGenerationRequestParamsSchema } from '../../../models';
3
3
  export namespace VideoCommand {
4
4
  export const RequestSchema = z.object({
5
5
  modelId: z.string().uuid(),
6
6
  prompt: z.string(),
7
- params: z.object({
8
- imageUrls: z.array(z.string()).optional(),
9
- duration: z.number(),
10
- aspectRatio: z.string().optional(),
11
- quality: z.string().optional(),
12
- }),
7
+ params: VideoGenerationRequestParamsSchema,
13
8
  });
14
9
 
15
10
  export type Request = z.infer<typeof RequestSchema>;
@@ -6,3 +6,4 @@ export * from './veo-aspect-ratio.enum';
6
6
  export * from './veo-person-allow.enum';
7
7
  export * from './veo-job-params-type.enum';
8
8
  export * from './video-resolution.enum';
9
+ export * from './video-pricing-rule-type.enum';
@@ -0,0 +1,3 @@
1
+ export enum VIDEO_PRICING_RULE_TYPE {
2
+ FLAT = 'flat',
3
+ }
@@ -1,6 +1,50 @@
1
- import { videoMaxDuration } from '../../constants/tool-video/videoMaxDuration';
1
+ import { VIDEO_PRICING_RULE_TYPE } from '../../constants';
2
+ import {
3
+ VideoGenerationRequestParams,
4
+ VideoModelPricingRuleCondition,
5
+ VideoModelPricingRules,
6
+ } from '../../models';
2
7
 
3
- export function calculateVideoPrice(pricePerSecond: number): number {
4
- const rawCost = videoMaxDuration * pricePerSecond;
5
- return Math.ceil(rawCost);
8
+ function matchesCondition(
9
+ condition: VideoModelPricingRuleCondition,
10
+ params: VideoGenerationRequestParams,
11
+ ): boolean {
12
+ const keys = Object.keys(condition) as (keyof VideoModelPricingRuleCondition)[];
13
+
14
+ return keys.every((key) => {
15
+ const expected = condition[key];
16
+
17
+ if (expected === undefined || expected === null || expected === '') {
18
+ return true;
19
+ }
20
+
21
+ const value = params[key];
22
+ if (value === undefined || value === null) {
23
+ return false;
24
+ }
25
+
26
+ return value === expected;
27
+ });
28
+ }
29
+
30
+ export function calculateVideoGenerationPrice({
31
+ pricePerSecond,
32
+ params,
33
+ rules,
34
+ }: {
35
+ pricePerSecond: number;
36
+ params: VideoGenerationRequestParams;
37
+ rules: VideoModelPricingRules;
38
+ }) {
39
+ const base = pricePerSecond * params.duration;
40
+
41
+ const flatMarkup = rules.reduce((sum, r) => {
42
+ if (r.type !== VIDEO_PRICING_RULE_TYPE.FLAT) {
43
+ return sum;
44
+ }
45
+
46
+ return matchesCondition(r.condition, params) ? sum + r.value : sum;
47
+ }, 0);
48
+
49
+ return Math.ceil(base + flatMarkup);
6
50
  }
@@ -1,6 +1,7 @@
1
1
  import { z } from 'zod';
2
2
  import { IconVariantsSchema } from '../../icon-variants.schema';
3
3
  import { UnlockedBySchema } from '../../unlocked-by-subscription.schema';
4
+ import { VIDEO_PRICING_RULE_TYPE } from '../../../constants';
4
5
 
5
6
  export const VideoModelParamsSchema = z.object({
6
7
  imageAttachment: z.object({
@@ -18,6 +19,28 @@ export const VideoModelParamsSchema = z.object({
18
19
  quality: z.string().optional(),
19
20
  });
20
21
 
22
+ export const VideoGenerationRequestParamsSchema = z.object({
23
+ imageUrls: z.string().array().optional(),
24
+ duration: z.number(),
25
+ aspectRatio: z.string().optional(),
26
+ quality: z.string().optional(),
27
+ });
28
+ export type VideoGenerationRequestParams = z.infer<typeof VideoGenerationRequestParamsSchema>;
29
+
30
+ export const VideoModelPricingRuleConditionSchema = z.object({
31
+ aspectRatio: z.string(),
32
+ });
33
+ export type VideoModelPricingRuleCondition = z.infer<typeof VideoModelPricingRuleConditionSchema>;
34
+
35
+ export const VideoModelPricingRulesSchema = z.array(
36
+ z.object({
37
+ type: z.nativeEnum(VIDEO_PRICING_RULE_TYPE),
38
+ condition: VideoModelPricingRuleConditionSchema,
39
+ value: z.number(),
40
+ }),
41
+ );
42
+ export type VideoModelPricingRules = z.infer<typeof VideoModelPricingRulesSchema>;
43
+
21
44
  export const VideoModelSchema = z.object({
22
45
  uuid: z.string(),
23
46
  title: z.string(),
@@ -28,6 +51,7 @@ export const VideoModelSchema = z.object({
28
51
  maxInputLength: z.number(),
29
52
  maxNegativeInputLength: z.number(),
30
53
  params: VideoModelParamsSchema,
54
+ pricingRules: VideoModelPricingRulesSchema,
31
55
  unlockedBy: UnlockedBySchema.nullable(),
32
56
  canUse: z.boolean(),
33
57
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@purpleschool/gptbot",
3
- "version": "0.7.24",
3
+ "version": "0.7.26",
4
4
  "description": "",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",