@purpleschool/gptbot-tools 0.1.4 → 0.1.6

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.
@@ -17,4 +17,5 @@ var TOOL_CONTENT_TYPE;
17
17
  TOOL_CONTENT_TYPE["NONE"] = "NONE";
18
18
  TOOL_CONTENT_TYPE["MARKETPLACE_CARD_GENERATION"] = "MARKETPLACE_CARD";
19
19
  TOOL_CONTENT_TYPE["SOLVING_EDU_TASK"] = "SOLVING_EDU_TASK";
20
+ TOOL_CONTENT_TYPE["SPELL_CORRECTOR"] = "SPELL_CORRECTOR";
20
21
  })(TOOL_CONTENT_TYPE || (exports.TOOL_CONTENT_TYPE = TOOL_CONTENT_TYPE = {}));
@@ -16,6 +16,7 @@ const stt_1 = require("../../stt");
16
16
  const models_1 = require("../../marketplace-card/models");
17
17
  const interior_design_1 = require("../../interior-design");
18
18
  const solving_edu_task_1 = require("../../solving-edu-task");
19
+ const spell_corrector_1 = require("../../spell-corrector");
19
20
  exports.GlobalToolsConfigSchema = zod_1.z.object({
20
21
  [enums_1.TOOL_CONTENT_TYPE.VIDEO]: video_1.VideoConfigSchema,
21
22
  [enums_1.TOOL_CONTENT_TYPE.MUSIC]: music_1.MusicConfigSchema,
@@ -30,4 +31,5 @@ exports.GlobalToolsConfigSchema = zod_1.z.object({
30
31
  [enums_1.TOOL_CONTENT_TYPE.MARKETPLACE_CARD_GENERATION]: models_1.MarketplaceCardConfigSchema,
31
32
  [enums_1.TOOL_CONTENT_TYPE.INTERIOR_DESIGN]: interior_design_1.InteriorDesignConfigSchema,
32
33
  [enums_1.TOOL_CONTENT_TYPE.SOLVING_EDU_TASK]: solving_edu_task_1.SolvingEduTaskConfigSchema,
34
+ [enums_1.TOOL_CONTENT_TYPE.SPELL_CORRECTOR]: spell_corrector_1.SpellCorrectorToolConfigSchema,
33
35
  });
@@ -17,6 +17,7 @@ const models_1 = require("../../marketplace-card/models");
17
17
  const tool_schema_1 = require("./tool.schema");
18
18
  const interior_design_1 = require("../../interior-design");
19
19
  const solving_edu_task_1 = require("../../solving-edu-task");
20
+ const spell_corrector_1 = require("../../spell-corrector");
20
21
  // Discriminated union array: Tools with their configs
21
22
  exports.ToolWithConfigSchema = zod_1.z.discriminatedUnion('contentType', [
22
23
  tool_schema_1.ToolSchema.merge(zod_1.z.object({
@@ -71,5 +72,9 @@ exports.ToolWithConfigSchema = zod_1.z.discriminatedUnion('contentType', [
71
72
  contentType: zod_1.z.literal(enums_1.TOOL_CONTENT_TYPE.SOLVING_EDU_TASK),
72
73
  config: solving_edu_task_1.SolvingEduTaskConfigSchema,
73
74
  })),
75
+ tool_schema_1.ToolSchema.merge(zod_1.z.object({
76
+ contentType: zod_1.z.literal(enums_1.TOOL_CONTENT_TYPE.SPELL_CORRECTOR),
77
+ config: spell_corrector_1.SpellCorrectorToolConfigSchema,
78
+ })),
74
79
  ]);
75
80
  exports.ToolsWithConfigsSchema = zod_1.z.array(exports.ToolWithConfigSchema);
@@ -16,6 +16,7 @@ var EditVideoCommand;
16
16
  modelId: zod_1.z.string().uuid(),
17
17
  tokenReservationId: zod_1.z.string().uuid(),
18
18
  precalculatedPrice: zod_1.z.number(),
19
+ params: models_1.VideoEditorJobParamsSchema.optional(),
19
20
  });
20
21
  EditVideoCommand.ResponseSchema = (0, command_response_schema_1.ICommandResponseSchema)(models_1.VideoEditorJobSchema);
21
22
  })(EditVideoCommand || (exports.EditVideoCommand = EditVideoCommand = {}));
@@ -3,10 +3,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.GetVideoEditorPriceCommand = void 0;
4
4
  const zod_1 = require("zod");
5
5
  const command_response_schema_1 = require("../../common/models/command-response.schema");
6
+ const models_1 = require("../models");
6
7
  var GetVideoEditorPriceCommand;
7
8
  (function (GetVideoEditorPriceCommand) {
8
9
  GetVideoEditorPriceCommand.RequestSchema = zod_1.z.object({
9
10
  modelId: zod_1.z.string(),
11
+ params: models_1.VideoEditorPricingRequestParamsSchema,
10
12
  });
11
13
  GetVideoEditorPriceCommand.ResponseDataSchema = zod_1.z.object({
12
14
  price: zod_1.z.number(),
@@ -17,6 +17,7 @@ var RetryVideoEditorJobCommand;
17
17
  modelId: zod_1.z.string().uuid().optional(),
18
18
  tokenReservationId: zod_1.z.string().uuid(),
19
19
  precalculatedPrice: zod_1.z.number(),
20
+ params: video_editor_job_schema_1.VideoEditorJobParamsSchema.optional(),
20
21
  });
21
22
  RetryVideoEditorJobCommand.ResponseSchema = (0, command_response_schema_1.ICommandResponseSchema)(video_editor_job_schema_1.VideoEditorJobSchema);
22
23
  })(RetryVideoEditorJobCommand || (exports.RetryVideoEditorJobCommand = RetryVideoEditorJobCommand = {}));
@@ -15,4 +15,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./video-editor-model-limitation.enum"), exports);
18
+ __exportStar(require("./video-editor-pricing-rule-type.enum"), exports);
18
19
  __exportStar(require("./video-editor-model-strategy.enum"), exports);
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.VIDEO_EDITOR_PRICING_RULE_TYPE = void 0;
4
+ var VIDEO_EDITOR_PRICING_RULE_TYPE;
5
+ (function (VIDEO_EDITOR_PRICING_RULE_TYPE) {
6
+ VIDEO_EDITOR_PRICING_RULE_TYPE["FLAT"] = "flat";
7
+ VIDEO_EDITOR_PRICING_RULE_TYPE["PER_SECOND"] = "per_second";
8
+ })(VIDEO_EDITOR_PRICING_RULE_TYPE || (exports.VIDEO_EDITOR_PRICING_RULE_TYPE = VIDEO_EDITOR_PRICING_RULE_TYPE = {}));
@@ -1,9 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.VideoEditorJobSchema = void 0;
3
+ exports.VideoEditorJobSchema = exports.VideoEditorJobParamsSchema = void 0;
4
4
  const zod_1 = require("zod");
5
5
  const tools_1 = require("../../tools");
6
6
  const common_1 = require("../../common");
7
+ exports.VideoEditorJobParamsSchema = zod_1.z.object({
8
+ duration: zod_1.z.number().optional(),
9
+ resolution: zod_1.z.string().optional(),
10
+ });
7
11
  exports.VideoEditorJobSchema = zod_1.z.object({
8
12
  uuid: zod_1.z.string(),
9
13
  prompt: zod_1.z.string(),
@@ -20,6 +24,7 @@ exports.VideoEditorJobSchema = zod_1.z.object({
20
24
  outputVideoUrl: zod_1.z.string().nullable(),
21
25
  outputVideoId: zod_1.z.string().nullable(),
22
26
  previewUrl: zod_1.z.string().nullable(),
27
+ params: exports.VideoEditorJobParamsSchema.optional(),
23
28
  duration: zod_1.z.number(),
24
29
  attempts: zod_1.z.array(zod_1.z.any()),
25
30
  userId: zod_1.z.string().nullable().optional(),
@@ -1,9 +1,34 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.VideoEditorModelSchema = void 0;
3
+ exports.VideoEditorModelSchema = exports.VideoEditorModelPricingRulesSchema = exports.VideoEditorModelPricingRuleConditionSchema = exports.VideoEditorPricingRequestParamsSchema = exports.VideoEditorModelParamsSchema = void 0;
4
4
  const zod_1 = require("zod");
5
5
  const common_1 = require("../../common");
6
6
  const enums_1 = require("../enums");
7
+ exports.VideoEditorModelParamsSchema = zod_1.z.object({
8
+ duration: zod_1.z
9
+ .object({
10
+ options: zod_1.z.array(zod_1.z.number()),
11
+ })
12
+ .optional(),
13
+ resolution: zod_1.z
14
+ .object({
15
+ options: zod_1.z.array(zod_1.z.string()),
16
+ })
17
+ .optional(),
18
+ });
19
+ exports.VideoEditorPricingRequestParamsSchema = zod_1.z.object({
20
+ duration: zod_1.z.number(),
21
+ resolution: zod_1.z.string().optional(),
22
+ });
23
+ exports.VideoEditorModelPricingRuleConditionSchema = zod_1.z.object({
24
+ duration: zod_1.z.number().optional(),
25
+ resolution: zod_1.z.string().optional(),
26
+ });
27
+ exports.VideoEditorModelPricingRulesSchema = zod_1.z.array(zod_1.z.object({
28
+ type: zod_1.z.nativeEnum(enums_1.VIDEO_EDITOR_PRICING_RULE_TYPE),
29
+ condition: exports.VideoEditorModelPricingRuleConditionSchema,
30
+ value: zod_1.z.number(),
31
+ }));
7
32
  exports.VideoEditorModelSchema = zod_1.z.object({
8
33
  uuid: zod_1.z.string(),
9
34
  title: zod_1.z.string(),
@@ -17,6 +42,8 @@ exports.VideoEditorModelSchema = zod_1.z.object({
17
42
  maxInputVideoSizeBytes: zod_1.z.number(),
18
43
  maxInputVideoDurationInSeconds: zod_1.z.number(),
19
44
  supportedFormats: zod_1.z.array(zod_1.z.string()),
45
+ params: exports.VideoEditorModelParamsSchema,
46
+ pricingRules: exports.VideoEditorModelPricingRulesSchema,
20
47
  needsTranslation: zod_1.z.boolean(),
21
48
  pricePerCall: zod_1.z.number(),
22
49
  limitations: zod_1.z.array(zod_1.z.nativeEnum(enums_1.VIDEO_EDITOR_MODEL_LIMITATION)),
@@ -1,6 +1,28 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.calculateVideoEditingPrice = calculateVideoEditingPrice;
4
- function calculateVideoEditingPrice({ pricePerCall }) {
5
- return pricePerCall;
4
+ const enums_1 = require("../enums");
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
+ const value = params[key];
12
+ if (value === undefined || value === null)
13
+ return false;
14
+ return value === expected;
15
+ });
16
+ }
17
+ function calculateVideoEditingPrice({ pricePerCall, params, rules, }) {
18
+ const perSecondRule = rules
19
+ .filter((r) => r.type === enums_1.VIDEO_EDITOR_PRICING_RULE_TYPE.PER_SECOND)
20
+ .find((r) => matchesCondition(r.condition, params));
21
+ const base = perSecondRule ? perSecondRule.value * params.duration : pricePerCall;
22
+ const flatMarkup = rules.reduce((sum, r) => {
23
+ if (r.type !== enums_1.VIDEO_EDITOR_PRICING_RULE_TYPE.FLAT)
24
+ return sum;
25
+ return matchesCondition(r.condition, params) ? sum + r.value : sum;
26
+ }, 0);
27
+ return Math.ceil(base + flatMarkup);
6
28
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@purpleschool/gptbot-tools",
3
- "version": "0.1.4",
3
+ "version": "0.1.6",
4
4
  "main": "build/index.js",
5
5
  "types": "build/index.d.ts",
6
6
  "scripts": {
@@ -13,4 +13,5 @@ export enum TOOL_CONTENT_TYPE {
13
13
  NONE = 'NONE',
14
14
  MARKETPLACE_CARD_GENERATION = 'MARKETPLACE_CARD',
15
15
  SOLVING_EDU_TASK = 'SOLVING_EDU_TASK',
16
+ SPELL_CORRECTOR = 'SPELL_CORRECTOR',
16
17
  }
@@ -13,6 +13,7 @@ import { STTConfigSchema } from '../../stt';
13
13
  import { MarketplaceCardConfigSchema } from '../../marketplace-card/models';
14
14
  import { InteriorDesignConfigSchema } from '../../interior-design';
15
15
  import { SolvingEduTaskConfigSchema } from '../../solving-edu-task';
16
+ import { SpellCorrectorToolConfigSchema } from '../../spell-corrector';
16
17
 
17
18
  export const GlobalToolsConfigSchema = z.object({
18
19
  [TOOL_CONTENT_TYPE.VIDEO]: VideoConfigSchema,
@@ -28,6 +29,7 @@ export const GlobalToolsConfigSchema = z.object({
28
29
  [TOOL_CONTENT_TYPE.MARKETPLACE_CARD_GENERATION]: MarketplaceCardConfigSchema,
29
30
  [TOOL_CONTENT_TYPE.INTERIOR_DESIGN]: InteriorDesignConfigSchema,
30
31
  [TOOL_CONTENT_TYPE.SOLVING_EDU_TASK]: SolvingEduTaskConfigSchema,
32
+ [TOOL_CONTENT_TYPE.SPELL_CORRECTOR]: SpellCorrectorToolConfigSchema,
31
33
  });
32
34
 
33
35
  export type GlobalToolsConfig = z.infer<typeof GlobalToolsConfigSchema>;
@@ -14,6 +14,7 @@ import { MarketplaceCardConfigSchema } from '../../marketplace-card/models';
14
14
  import { ToolSchema } from './tool.schema';
15
15
  import { InteriorDesignConfigSchema } from '../../interior-design';
16
16
  import { SolvingEduTaskConfigSchema } from '../../solving-edu-task';
17
+ import { SpellCorrectorToolConfigSchema } from '../../spell-corrector';
17
18
 
18
19
  // Discriminated union array: Tools with their configs
19
20
  export const ToolWithConfigSchema = z.discriminatedUnion('contentType', [
@@ -95,6 +96,12 @@ export const ToolWithConfigSchema = z.discriminatedUnion('contentType', [
95
96
  config: SolvingEduTaskConfigSchema,
96
97
  }),
97
98
  ),
99
+ ToolSchema.merge(
100
+ z.object({
101
+ contentType: z.literal(TOOL_CONTENT_TYPE.SPELL_CORRECTOR),
102
+ config: SpellCorrectorToolConfigSchema,
103
+ }),
104
+ ),
98
105
  ]);
99
106
 
100
107
  export type ToolWithConfig = z.infer<typeof ToolWithConfigSchema>;
@@ -1,6 +1,6 @@
1
1
  import { z } from 'zod';
2
2
  import { ICommandResponseSchema } from '../../common/models/command-response.schema';
3
- import { VideoEditorJobSchema } from '../models';
3
+ import { VideoEditorJobSchema, VideoEditorJobParamsSchema } from '../models';
4
4
 
5
5
  export namespace EditVideoCommand {
6
6
  export const RequestSchema = z.object({
@@ -13,6 +13,7 @@ export namespace EditVideoCommand {
13
13
  modelId: z.string().uuid(),
14
14
  tokenReservationId: z.string().uuid(),
15
15
  precalculatedPrice: z.number(),
16
+ params: VideoEditorJobParamsSchema.optional(),
16
17
  });
17
18
  export type Request = z.infer<typeof RequestSchema>;
18
19
 
@@ -1,9 +1,11 @@
1
1
  import { z } from 'zod';
2
2
  import { ICommandResponseSchema } from '../../common/models/command-response.schema';
3
+ import { VideoEditorPricingRequestParamsSchema } from '../models';
3
4
 
4
5
  export namespace GetVideoEditorPriceCommand {
5
6
  export const RequestSchema = z.object({
6
7
  modelId: z.string(),
8
+ params: VideoEditorPricingRequestParamsSchema,
7
9
  });
8
10
  export type Request = z.infer<typeof RequestSchema>;
9
11
 
@@ -1,6 +1,9 @@
1
1
  import { z } from 'zod';
2
2
  import { ICommandResponseSchema } from '../../common/models/command-response.schema';
3
- import { VideoEditorJobSchema } from '../models/video-editor-job.schema';
3
+ import {
4
+ VideoEditorJobParamsSchema,
5
+ VideoEditorJobSchema,
6
+ } from '../models/video-editor-job.schema';
4
7
 
5
8
  export namespace RetryVideoEditorJobCommand {
6
9
  export const RequestSchema = z.object({
@@ -14,6 +17,7 @@ export namespace RetryVideoEditorJobCommand {
14
17
  modelId: z.string().uuid().optional(),
15
18
  tokenReservationId: z.string().uuid(),
16
19
  precalculatedPrice: z.number(),
20
+ params: VideoEditorJobParamsSchema.optional(),
17
21
  });
18
22
  export type Request = z.infer<typeof RequestSchema>;
19
23
 
@@ -1,2 +1,3 @@
1
1
  export * from './video-editor-model-limitation.enum';
2
+ export * from './video-editor-pricing-rule-type.enum';
2
3
  export * from './video-editor-model-strategy.enum';
@@ -0,0 +1,4 @@
1
+ export enum VIDEO_EDITOR_PRICING_RULE_TYPE {
2
+ FLAT = 'flat',
3
+ PER_SECOND = 'per_second',
4
+ }
@@ -2,6 +2,13 @@ import { z } from 'zod';
2
2
  import { JOB_STATUS } from '../../tools';
3
3
  import { USER_REACTION } from '../../common';
4
4
 
5
+ export const VideoEditorJobParamsSchema = z.object({
6
+ duration: z.number().optional(),
7
+ resolution: z.string().optional(),
8
+ });
9
+
10
+ export type VideoEditorJobParams = z.infer<typeof VideoEditorJobParamsSchema>;
11
+
5
12
  export const VideoEditorJobSchema = z.object({
6
13
  uuid: z.string(),
7
14
  prompt: z.string(),
@@ -18,6 +25,7 @@ export const VideoEditorJobSchema = z.object({
18
25
  outputVideoUrl: z.string().nullable(),
19
26
  outputVideoId: z.string().nullable(),
20
27
  previewUrl: z.string().nullable(),
28
+ params: VideoEditorJobParamsSchema.optional(),
21
29
  duration: z.number(),
22
30
  attempts: z.array(z.any()),
23
31
  userId: z.string().nullable().optional(),
@@ -1,6 +1,48 @@
1
1
  import { z } from 'zod';
2
2
  import { IconVariantsSchema, TOOL_MODEL_STATUS } from '../../common';
3
- import { VIDEO_EDITOR_MODEL_LIMITATION, VIDEO_EDITOR_MODEL_STRATEGY } from '../enums';
3
+ import {
4
+ VIDEO_EDITOR_MODEL_LIMITATION,
5
+ VIDEO_EDITOR_MODEL_STRATEGY,
6
+ VIDEO_EDITOR_PRICING_RULE_TYPE,
7
+ } from '../enums';
8
+
9
+ export const VideoEditorModelParamsSchema = z.object({
10
+ duration: z
11
+ .object({
12
+ options: z.array(z.number()),
13
+ })
14
+ .optional(),
15
+ resolution: z
16
+ .object({
17
+ options: z.array(z.string()),
18
+ })
19
+ .optional(),
20
+ });
21
+
22
+ export type VideoEditorModelParams = z.infer<typeof VideoEditorModelParamsSchema>;
23
+
24
+ export const VideoEditorPricingRequestParamsSchema = z.object({
25
+ duration: z.number(),
26
+ resolution: z.string().optional(),
27
+ });
28
+ export type VideoEditorPricingRequestParams = z.infer<typeof VideoEditorPricingRequestParamsSchema>;
29
+
30
+ export const VideoEditorModelPricingRuleConditionSchema = z.object({
31
+ duration: z.number().optional(),
32
+ resolution: z.string().optional(),
33
+ });
34
+ export type VideoEditorModelPricingRuleCondition = z.infer<
35
+ typeof VideoEditorModelPricingRuleConditionSchema
36
+ >;
37
+
38
+ export const VideoEditorModelPricingRulesSchema = z.array(
39
+ z.object({
40
+ type: z.nativeEnum(VIDEO_EDITOR_PRICING_RULE_TYPE),
41
+ condition: VideoEditorModelPricingRuleConditionSchema,
42
+ value: z.number(),
43
+ }),
44
+ );
45
+ export type VideoEditorModelPricingRules = z.infer<typeof VideoEditorModelPricingRulesSchema>;
4
46
 
5
47
  export const VideoEditorModelSchema = z.object({
6
48
  uuid: z.string(),
@@ -15,6 +57,8 @@ export const VideoEditorModelSchema = z.object({
15
57
  maxInputVideoSizeBytes: z.number(),
16
58
  maxInputVideoDurationInSeconds: z.number(),
17
59
  supportedFormats: z.array(z.string()),
60
+ params: VideoEditorModelParamsSchema,
61
+ pricingRules: VideoEditorModelPricingRulesSchema,
18
62
  needsTranslation: z.boolean(),
19
63
  pricePerCall: z.number(),
20
64
  limitations: z.array(z.nativeEnum(VIDEO_EDITOR_MODEL_LIMITATION)),
@@ -1,3 +1,46 @@
1
- export function calculateVideoEditingPrice({ pricePerCall }: { pricePerCall: number }): number {
2
- return pricePerCall;
1
+ import { VIDEO_EDITOR_PRICING_RULE_TYPE } from '../enums';
2
+ import {
3
+ VideoEditorModelPricingRuleCondition,
4
+ VideoEditorModelPricingRules,
5
+ VideoEditorPricingRequestParams,
6
+ } from '../models';
7
+
8
+ function matchesCondition(
9
+ condition: VideoEditorModelPricingRuleCondition,
10
+ params: VideoEditorPricingRequestParams,
11
+ ): boolean {
12
+ const keys = Object.keys(condition) as (keyof VideoEditorModelPricingRuleCondition)[];
13
+
14
+ return keys.every((key) => {
15
+ const expected = condition[key];
16
+ if (expected === undefined || expected === null || expected === '') return true;
17
+
18
+ const value = params[key];
19
+ if (value === undefined || value === null) return false;
20
+
21
+ return value === expected;
22
+ });
23
+ }
24
+
25
+ export function calculateVideoEditingPrice({
26
+ pricePerCall,
27
+ params,
28
+ rules,
29
+ }: {
30
+ pricePerCall: number;
31
+ params: VideoEditorPricingRequestParams;
32
+ rules: VideoEditorModelPricingRules;
33
+ }): number {
34
+ const perSecondRule = rules
35
+ .filter((r) => r.type === VIDEO_EDITOR_PRICING_RULE_TYPE.PER_SECOND)
36
+ .find((r) => matchesCondition(r.condition, params));
37
+
38
+ const base = perSecondRule ? perSecondRule.value * params.duration : pricePerCall;
39
+
40
+ const flatMarkup = rules.reduce((sum, r) => {
41
+ if (r.type !== VIDEO_EDITOR_PRICING_RULE_TYPE.FLAT) return sum;
42
+ return matchesCondition(r.condition, params) ? sum + r.value : sum;
43
+ }, 0);
44
+
45
+ return Math.ceil(base + flatMarkup);
3
46
  }