vidspotai-shared 1.0.30 → 1.0.31

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 (94) hide show
  1. package/lib/globals/aiModels/enums.d.ts +40 -0
  2. package/lib/globals/aiModels/enums.d.ts.map +1 -0
  3. package/lib/globals/aiModels/enums.js +46 -0
  4. package/lib/globals/aiModels/index.d.ts +6 -0
  5. package/lib/globals/aiModels/index.d.ts.map +1 -0
  6. package/lib/globals/aiModels/index.js +35 -0
  7. package/lib/globals/aiModels/providers/bytedance.d.ts +4 -0
  8. package/lib/globals/aiModels/providers/bytedance.d.ts.map +1 -0
  9. package/lib/globals/aiModels/providers/bytedance.js +65 -0
  10. package/lib/globals/aiModels/providers/google.d.ts +4 -0
  11. package/lib/globals/aiModels/providers/google.d.ts.map +1 -0
  12. package/lib/globals/aiModels/providers/google.js +111 -0
  13. package/lib/globals/aiModels/providers/kling.d.ts +4 -0
  14. package/lib/globals/aiModels/providers/kling.d.ts.map +1 -0
  15. package/lib/globals/aiModels/providers/kling.js +129 -0
  16. package/lib/globals/aiModels/providers/minimax.d.ts +4 -0
  17. package/lib/globals/aiModels/providers/minimax.d.ts.map +1 -0
  18. package/lib/globals/aiModels/providers/minimax.js +66 -0
  19. package/lib/globals/aiModels/providers/openai.d.ts +4 -0
  20. package/lib/globals/aiModels/providers/openai.d.ts.map +1 -0
  21. package/lib/globals/aiModels/providers/openai.js +82 -0
  22. package/lib/globals/aiModels/providers/pixverse.d.ts +4 -0
  23. package/lib/globals/aiModels/providers/pixverse.d.ts.map +1 -0
  24. package/lib/globals/aiModels/providers/pixverse.js +108 -0
  25. package/lib/globals/aiModels/providers/runway.d.ts +4 -0
  26. package/lib/globals/aiModels/providers/runway.d.ts.map +1 -0
  27. package/lib/globals/aiModels/providers/runway.js +52 -0
  28. package/lib/globals/aiModels/types.d.ts +45 -0
  29. package/lib/globals/aiModels/types.d.ts.map +1 -0
  30. package/lib/globals/aiModels/types.js +2 -0
  31. package/lib/globals/aiModels.d.ts +9 -14
  32. package/lib/globals/aiModels.d.ts.map +1 -1
  33. package/lib/globals/aiModels.js +187 -495
  34. package/lib/globals/index.d.ts +1 -0
  35. package/lib/globals/index.d.ts.map +1 -1
  36. package/lib/globals/index.js +1 -0
  37. package/lib/globals/ttsModels/index.d.ts +6 -0
  38. package/lib/globals/ttsModels/index.d.ts.map +1 -0
  39. package/lib/globals/ttsModels/index.js +25 -0
  40. package/lib/globals/ttsModels/providers/elevenlabs.d.ts +3 -0
  41. package/lib/globals/ttsModels/providers/elevenlabs.d.ts.map +1 -0
  42. package/lib/globals/ttsModels/providers/elevenlabs.js +13 -0
  43. package/lib/globals/ttsModels/types.d.ts +15 -0
  44. package/lib/globals/ttsModels/types.d.ts.map +1 -0
  45. package/lib/globals/ttsModels/types.js +2 -0
  46. package/lib/globals/ttsModels/voices.d.ts +21 -0
  47. package/lib/globals/ttsModels/voices.d.ts.map +1 -0
  48. package/lib/globals/ttsModels/voices.js +135 -0
  49. package/lib/models/user.model.d.ts +2 -0
  50. package/lib/models/user.model.d.ts.map +1 -1
  51. package/lib/models/video.model.d.ts +9 -0
  52. package/lib/models/video.model.d.ts.map +1 -1
  53. package/lib/services/aiGen/aiGenFactory.service.d.ts.map +1 -1
  54. package/lib/services/aiGen/aiGenFactory.service.js +36 -12
  55. package/lib/services/aiGen/providers/bytedance/bytedance.service.d.ts.map +1 -1
  56. package/lib/services/aiGen/providers/bytedance/bytedance.service.js +36 -7
  57. package/lib/services/aiGen/providers/google/google.service.js +1 -1
  58. package/lib/services/aiGen/providers/kling/kling.service.d.ts +7 -2
  59. package/lib/services/aiGen/providers/kling/kling.service.d.ts.map +1 -1
  60. package/lib/services/aiGen/providers/kling/kling.service.js +126 -10
  61. package/lib/services/aiGen/providers/kling/types.d.ts +13 -0
  62. package/lib/services/aiGen/providers/kling/types.d.ts.map +1 -1
  63. package/lib/services/aiGen/providers/pixverse/pixverse.service.d.ts +9 -0
  64. package/lib/services/aiGen/providers/pixverse/pixverse.service.d.ts.map +1 -0
  65. package/lib/services/aiGen/providers/pixverse/pixverse.service.js +188 -0
  66. package/lib/services/aiGen/providers/runway/runway.service.d.ts.map +1 -1
  67. package/lib/services/aiGen/providers/runway/runway.service.js +16 -4
  68. package/lib/services/aiGen/providers/types.d.ts +6 -0
  69. package/lib/services/aiGen/providers/types.d.ts.map +1 -1
  70. package/lib/services/credit.service.d.ts +1 -0
  71. package/lib/services/credit.service.d.ts.map +1 -1
  72. package/lib/services/credit.service.js +17 -0
  73. package/lib/services/index.d.ts +1 -0
  74. package/lib/services/index.d.ts.map +1 -1
  75. package/lib/services/index.js +1 -0
  76. package/lib/services/tts/index.d.ts +4 -0
  77. package/lib/services/tts/index.d.ts.map +1 -0
  78. package/lib/services/tts/index.js +19 -0
  79. package/lib/services/tts/providers/elevenlabs.service.d.ts +7 -0
  80. package/lib/services/tts/providers/elevenlabs.service.d.ts.map +1 -0
  81. package/lib/services/tts/providers/elevenlabs.service.js +44 -0
  82. package/lib/services/tts/ttsFactory.service.d.ts +4 -0
  83. package/lib/services/tts/ttsFactory.service.d.ts.map +1 -0
  84. package/lib/services/tts/ttsFactory.service.js +12 -0
  85. package/lib/services/tts/types.d.ts +14 -0
  86. package/lib/services/tts/types.d.ts.map +1 -0
  87. package/lib/services/tts/types.js +6 -0
  88. package/lib/utils/index.d.ts +1 -0
  89. package/lib/utils/index.d.ts.map +1 -1
  90. package/lib/utils/index.js +1 -0
  91. package/lib/utils/ttsUtils.d.ts +11 -0
  92. package/lib/utils/ttsUtils.d.ts.map +1 -0
  93. package/lib/utils/ttsUtils.js +16 -0
  94. package/package.json +1 -1
@@ -10,6 +10,7 @@ const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
10
10
  const aiModels_1 = require("../../../../globals/aiModels");
11
11
  const types_1 = require("../../../../globals/types");
12
12
  const firebase_1 = require("../../../../libs/firebase");
13
+ const logger_1 = require("../../../../utils/logger");
13
14
  const helpers_1 = require("../../helpers");
14
15
  const types_2 = require("../../types");
15
16
  const baseAiGenProvider_service_1 = require("../baseAiGenProvider.service");
@@ -18,12 +19,13 @@ class KlingService extends baseAiGenProvider_service_1.BaseAiGenProviderService
18
19
  constructor() {
19
20
  super();
20
21
  this.baseUrl = "https://api-singapore.klingai.com";
21
- this.timeout = 60000; // 1 min
22
+ this.generateTimeout = 120000; // 2 min — submit endpoint can be slow under Kling load
23
+ this.statusTimeout = 60000; // 1 min — status/poll should be fast
22
24
  if (!process.env.KLING_SECRET_KEY || !process.env.KLING_ACCESS_KEY) {
23
25
  throw new Error("Missing KLING_SECRET_KEY or KLING_ACCESS_KEY in environment variables");
24
26
  }
25
27
  }
26
- async request(endpoint, method, body) {
28
+ async request(endpoint, method, body, timeout = this.generateTimeout) {
27
29
  const config = {
28
30
  method,
29
31
  url: `${this.baseUrl}${endpoint}`,
@@ -31,7 +33,7 @@ class KlingService extends baseAiGenProvider_service_1.BaseAiGenProviderService
31
33
  Authorization: `Bearer ${this.encodeJwtToken()}`,
32
34
  "Content-Type": "application/json",
33
35
  },
34
- timeout: this.timeout,
36
+ timeout,
35
37
  data: body,
36
38
  };
37
39
  const response = await axios_1.default.request(config);
@@ -42,6 +44,9 @@ class KlingService extends baseAiGenProvider_service_1.BaseAiGenProviderService
42
44
  }
43
45
  async generateVideo(params) {
44
46
  (0, helpers_1.validateParams)(params);
47
+ if (params.modelKey === "kling-avatar") {
48
+ return this.generateAvatarVideo(params);
49
+ }
45
50
  const modelId = aiModels_1.aiModelConfigs[params.modelKey]?.modelId;
46
51
  if (!modelId)
47
52
  throw new Error(`Unknown modelKey: ${params.modelKey}`);
@@ -53,14 +58,75 @@ class KlingService extends baseAiGenProvider_service_1.BaseAiGenProviderService
53
58
  mode: params.mode || types_2.EVideoMode.STANDARD,
54
59
  };
55
60
  const starttime = Date.now();
56
- const task = await this.request("/v1/videos/text2video", "POST", request);
57
- console.log(`Kling generateVideo API call took ${Date.now() - starttime} ms`, task ? `(task ID: ${task.data.task_id})` : "(failed)");
61
+ const task = await this.requestWithTimeoutRetry("/v1/videos/text2video", "POST", request, 4, this.generateTimeout);
62
+ logger_1.logger.info("Kling generateVideo submitted", {
63
+ modelKey: params.modelKey,
64
+ taskId: task.data.task_id,
65
+ durationMs: Date.now() - starttime,
66
+ });
67
+ return { task: task.data.task_id, status: types_1.EVideoSceneStatus.TRIGGERED };
68
+ }
69
+ async generateAvatarVideo(params) {
70
+ if (!params.inputImageUrl) {
71
+ throw new Error("inputImageUrl (avatar face image) is required for Kling Avatar generation");
72
+ }
73
+ if (!params.inputAudioUrl) {
74
+ throw new Error("inputAudioUrl (audio file) is required for Kling Avatar generation");
75
+ }
76
+ const request = {
77
+ image: params.inputImageUrl,
78
+ sound_file: params.inputAudioUrl,
79
+ prompt: params.prompt,
80
+ mode: params.mode || "std",
81
+ };
82
+ const starttime = Date.now();
83
+ // Use requestWithTimeoutRetry so transient Kling server slowness doesn't fail the job outright.
84
+ // generateTimeout (2 min) gives enough headroom; up to 4 attempts before giving up.
85
+ const task = await this.requestWithTimeoutRetry("/v1/videos/avatar/image2video", "POST", request, 4, this.generateTimeout);
86
+ logger_1.logger.info("Kling generateAvatarVideo submitted", {
87
+ taskId: task.data.task_id,
88
+ durationMs: Date.now() - starttime,
89
+ });
58
90
  return { task: task.data.task_id, status: types_1.EVideoSceneStatus.TRIGGERED };
59
91
  }
60
- async checkVideoStatus({ task, outputFilename, outputFilePath = "videos", }) {
92
+ async requestWithTimeoutRetry(endpoint, method, body, maxAttempts = 4, timeout = this.statusTimeout) {
93
+ for (let attempt = 1; attempt <= maxAttempts; attempt++) {
94
+ try {
95
+ return await this.request(endpoint, method, body, timeout);
96
+ }
97
+ catch (err) {
98
+ const isTimeout = err.code === "ECONNABORTED" || err.message?.includes("timeout");
99
+ const isNetworkError = err.code === "ECONNRESET" ||
100
+ err.code === "ECONNREFUSED" ||
101
+ err.code === "ENOTFOUND" ||
102
+ err.code === "ERR_NETWORK" ||
103
+ err?.name === "AggregateError";
104
+ const isRetryable = isTimeout || isNetworkError;
105
+ if (!isRetryable || attempt === maxAttempts)
106
+ throw err;
107
+ logger_1.logger.warn("Kling request failed with transient error — retrying", {
108
+ endpoint,
109
+ attempt,
110
+ maxAttempts,
111
+ timeoutMs: timeout,
112
+ errorCode: err.code,
113
+ errorName: err?.name,
114
+ });
115
+ await new Promise((r) => setTimeout(r, 1000));
116
+ }
117
+ }
118
+ throw new Error("Unreachable");
119
+ }
120
+ async checkVideoStatus(params) {
121
+ if (params.modelKey === "kling-avatar") {
122
+ return this.checkAvatarVideoStatus(params);
123
+ }
124
+ return this.checkRegularVideoStatus(params);
125
+ }
126
+ async checkRegularVideoStatus({ task, outputFilename, outputFilePath = "videos", }) {
61
127
  const startTime = Date.now();
62
- const result = await this.request(`/v1/videos/text2video/${task}`, "GET");
63
- console.log(`Kling checkVideoStatus API call took ${Date.now() - startTime} ms`);
128
+ const result = await this.requestWithTimeoutRetry(`/v1/videos/text2video/${task}`, "GET");
129
+ logger_1.logger.info("Kling checkVideoStatus polled", { task, durationMs: Date.now() - startTime, status: result?.data?.task_status });
64
130
  if (!result) {
65
131
  return {
66
132
  status: types_1.EVideoSceneStatus.FAILED,
@@ -78,10 +144,53 @@ class KlingService extends baseAiGenProvider_service_1.BaseAiGenProviderService
78
144
  // console.log("Kling video URL:", videoUrl);
79
145
  const filePath = `${outputFilePath}/${outputFilename}.mp4`;
80
146
  const file = (0, firebase_1.getBucket)().file(filePath);
81
- // Download video using axios
147
+ // Download video using axios — use generateTimeout since video files can be large
82
148
  const videoResp = await axios_1.default.get(videoUrl, {
83
149
  responseType: "arraybuffer",
84
- timeout: this.timeout,
150
+ timeout: this.generateTimeout,
151
+ });
152
+ const buffer = Buffer.from(videoResp.data);
153
+ await file.save(buffer, { contentType: "video/mp4" });
154
+ const [signedUrl] = await file.getSignedUrl({
155
+ action: "read",
156
+ expires: "03-09-2491",
157
+ });
158
+ return {
159
+ videoUrl: signedUrl,
160
+ status: types_1.EVideoSceneStatus.COMPLETED,
161
+ };
162
+ }
163
+ if (result.data.task_status === "failed") {
164
+ return {
165
+ status: types_1.EVideoSceneStatus.FAILED,
166
+ errorMessage: `${result.code}: ${result.message}`,
167
+ };
168
+ }
169
+ return { status: types_1.EVideoSceneStatus.PENDING };
170
+ }
171
+ async checkAvatarVideoStatus({ task, outputFilename, outputFilePath = "videos", }) {
172
+ const startTime = Date.now();
173
+ const result = await this.requestWithTimeoutRetry(`/v1/videos/avatar/image2video/${task}`, "GET");
174
+ logger_1.logger.info("Kling checkAvatarVideoStatus polled", { task, durationMs: Date.now() - startTime, status: result?.data?.task_status });
175
+ if (!result) {
176
+ return {
177
+ status: types_1.EVideoSceneStatus.FAILED,
178
+ errorMessage: "No response from Kling Avatar API",
179
+ };
180
+ }
181
+ if (result.data.task_status === "succeed") {
182
+ const videoUrl = result.data.task_result?.videos?.[0]?.url;
183
+ if (!videoUrl) {
184
+ return {
185
+ status: types_1.EVideoSceneStatus.FAILED,
186
+ errorMessage: "No video URL in avatar response",
187
+ };
188
+ }
189
+ const filePath = `${outputFilePath}/${outputFilename}.mp4`;
190
+ const file = (0, firebase_1.getBucket)().file(filePath);
191
+ const videoResp = await axios_1.default.get(videoUrl, {
192
+ responseType: "arraybuffer",
193
+ timeout: this.generateTimeout,
85
194
  });
86
195
  const buffer = Buffer.from(videoResp.data);
87
196
  await file.save(buffer, { contentType: "video/mp4" });
@@ -116,6 +225,13 @@ class KlingService extends baseAiGenProvider_service_1.BaseAiGenProviderService
116
225
  }
117
226
  getCreditUsed({ modelKey, mode = types_2.EVideoMode.PROFESSIONAL, duration = 5, }) {
118
227
  const modelConfig = aiModels_1.aiModelConfigs[modelKey];
228
+ // Avatar: per-second pricing based on mode
229
+ if (modelKey === "kling-avatar") {
230
+ const perSecond = modelConfig?.cost?.[mode]?.perSecond
231
+ ?? modelConfig?.cost?.["std"]?.perSecond
232
+ ?? 0.014;
233
+ return (0, helpers_2.getCreditsFromCost)(perSecond * duration);
234
+ }
119
235
  const cost = modelConfig?.cost?.table?.[mode]?.[duration];
120
236
  return (0, helpers_2.getCreditsFromCost)(cost ?? 1);
121
237
  }
@@ -68,6 +68,19 @@ export interface TaskResult {
68
68
  export interface VideoResult {
69
69
  id: string;
70
70
  url: string;
71
+ watermark_url?: string;
71
72
  duration: string;
72
73
  }
74
+ export interface KlingAvatarGenerateRequest {
75
+ image: string;
76
+ audio_id?: string;
77
+ sound_file?: string;
78
+ prompt?: string;
79
+ mode?: "std" | "pro";
80
+ watermark_info?: {
81
+ enabled: boolean;
82
+ };
83
+ callback_url?: string;
84
+ external_task_id?: string;
85
+ }
73
86
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../../src/services/aiGen/providers/kling/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAGzC,MAAM,WAAW,0BAA0B;IACzC,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,aAAa,CAAC;CACrB;AAED,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,WAAW,GAAG,YAAY,GAAG,SAAS,GAAG,QAAQ,CAAC;IAC/D,SAAS,EAAE,QAAQ,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,QAAQ;IACvB,gBAAgB,EAAE,MAAM,CAAC;CAC1B;AAED,MAAM,MAAM,cAAc,GACtB,UAAU,GACV,YAAY,GACZ,iBAAiB,GACjB,mBAAmB,CAAC;AAExB,MAAM,MAAM,UAAU,GAClB,QAAQ,GACR,WAAW,GACX,YAAY,GACZ,oBAAoB,GACpB,mBAAmB,CAAC;AAExB,MAAM,MAAM,gBAAgB,GAAG,MAAM,GAAG,MAAM,GAAG,KAA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AE,MAAM,CAAC;CAC1B;AAED,MAAM,WAAW,UAAU;IACzB,MAAM,EAAE,WAAW,EAAE,CAAC;CACvB;AAED,MAAM,WAAW,WAAW;IAC1B,EAAE,EAAE,MAAM,CAAC;IACX,GAAG,EAAE,MAAM,CAAC;IACZ,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAID,MAAM,WAAW,0BAA0B;IACzC,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,KAAK,GAAG,KAAK,CAAC;IACrB,cAAc,CAAC,EAAE;QAAE,OAAO,EAAE,OAAO,CAAA;KAAE,CAAC;IACtC,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B"}
@@ -0,0 +1,9 @@
1
+ import { BaseAiGenProviderService } from "../baseAiGenProvider.service";
2
+ import { CreditUsageParams, VideoGenerationParams, VideoGenerationResult, VideoStatusParams, VideoStatusResult } from "../types";
3
+ export declare class PixVerseService extends BaseAiGenProviderService {
4
+ private readonly baseUrl;
5
+ generateVideo(params: VideoGenerationParams): Promise<VideoGenerationResult>;
6
+ checkVideoStatus({ task, outputFilename, outputFilePath, }: VideoStatusParams): Promise<VideoStatusResult>;
7
+ getCreditUsed(params: CreditUsageParams): number;
8
+ }
9
+ //# sourceMappingURL=pixverse.service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pixverse.service.d.ts","sourceRoot":"","sources":["../../../../../src/services/aiGen/providers/pixverse/pixverse.service.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,wBAAwB,EAAE,MAAM,8BAA8B,CAAC;AACxE,OAAO,EACL,iBAAiB,EACjB,qBAAqB,EACrB,qBAAqB,EACrB,iBAAiB,EACjB,iBAAiB,EAClB,MAAM,UAAU,CAAC;AASlB,qBAAa,eAAgB,SAAQ,wBAAwB;IAC3D,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAkD;IAKpE,aAAa,CACjB,MAAM,EAAE,qBAAqB,GAC5B,OAAO,CAAC,qBAAqB,CAAC;IAqE3B,gBAAgB,CAAC,EACrB,IAAI,EACJ,cAAc,EACd,cAAyB,GAC1B,EAAE,iBAAiB,GAAG,OAAO,CAAC,iBAAiB,CAAC;IAmGjD,aAAa,CAAC,MAAM,EAAE,iBAAiB,GAAG,MAAM;CA+CjD"}
@@ -0,0 +1,188 @@
1
+ "use strict";
2
+ // pixverse.service.ts
3
+ var __importDefault = (this && this.__importDefault) || function (mod) {
4
+ return (mod && mod.__esModule) ? mod : { "default": mod };
5
+ };
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.PixVerseService = void 0;
8
+ const baseAiGenProvider_service_1 = require("../baseAiGenProvider.service");
9
+ const helpers_1 = require("../../helpers");
10
+ const aiModels_1 = require("../../../../globals/aiModels");
11
+ const types_1 = require("../../../../globals/types");
12
+ const firebase_1 = require("../../../../libs/firebase");
13
+ const helpers_2 = require("../../../../utils/helpers");
14
+ const logger_1 = require("../../../../utils/logger");
15
+ const crypto_1 = __importDefault(require("crypto"));
16
+ class PixVerseService extends baseAiGenProvider_service_1.BaseAiGenProviderService {
17
+ constructor() {
18
+ super(...arguments);
19
+ this.baseUrl = "https://app-api.pixverse.ai/openapi/v2/video";
20
+ }
21
+ // =========================================================
22
+ // GENERATE VIDEO
23
+ // =========================================================
24
+ async generateVideo(params) {
25
+ (0, helpers_1.validateParams)(params);
26
+ const modelConfig = aiModels_1.aiModelConfigs[params.modelKey];
27
+ const modelId = modelConfig.modelId;
28
+ const traceId = crypto_1.default.randomUUID();
29
+ const body = {
30
+ aspect_ratio: params.aspectRatio,
31
+ duration: params.duration,
32
+ model: modelId,
33
+ prompt: params.prompt,
34
+ quality: params.resolution,
35
+ };
36
+ // Optional negative prompt
37
+ if (params.negativePrompt) {
38
+ body.negative_prompt = params.negativePrompt;
39
+ }
40
+ // Optional audio support (v5.5 / v5.6)
41
+ if (params.audio !== undefined) {
42
+ body.generate_audio_switch = Boolean(params.audio);
43
+ }
44
+ // Multi clip (v5.5 only)
45
+ if (params.multiClip !== undefined) {
46
+ body.generate_multi_clip_switch = Boolean(params.multiClip);
47
+ }
48
+ const resp = await fetch(`${this.baseUrl}/text/generate`, {
49
+ method: "POST",
50
+ headers: {
51
+ "Content-Type": "application/json",
52
+ "API-KEY": process.env.PIXVERSE_API_KEY,
53
+ "Ai-trace-id": traceId,
54
+ },
55
+ body: JSON.stringify(body),
56
+ });
57
+ if (!resp.ok) {
58
+ const errText = await resp.text();
59
+ throw new Error(`PixVerse generateVideo failed (${resp.status}): ${errText}`);
60
+ }
61
+ const data = await resp.json();
62
+ if (data.ErrCode !== 0) {
63
+ throw new Error(`PixVerse API error: ${data.ErrMsg || "Unknown error"}`);
64
+ }
65
+ const videoId = data?.Resp?.video_id;
66
+ if (!videoId) {
67
+ throw new Error("PixVerse API did not return video_id");
68
+ }
69
+ return {
70
+ task: String(videoId),
71
+ status: types_1.EVideoSceneStatus.TRIGGERED,
72
+ };
73
+ }
74
+ // =========================================================
75
+ // CHECK STATUS
76
+ // =========================================================
77
+ async checkVideoStatus({ task, outputFilename, outputFilePath = "videos", }) {
78
+ const traceId = crypto_1.default.randomUUID();
79
+ const resp = await fetch(`${this.baseUrl}/result/${task}`, {
80
+ method: "GET",
81
+ headers: {
82
+ "API-KEY": process.env.PIXVERSE_API_KEY,
83
+ "Ai-trace-id": traceId,
84
+ },
85
+ });
86
+ if (!resp.ok) {
87
+ const errText = await resp.text();
88
+ throw new Error(`PixVerse checkVideoStatus failed (${resp.status}): ${errText}`);
89
+ }
90
+ const data = await resp.json();
91
+ if (data.ErrCode !== 0) {
92
+ throw new Error(`PixVerse API error: ${data.ErrMsg || "Unknown error"}`);
93
+ }
94
+ const status = data?.Resp?.status;
95
+ // ---- Status Mapping ----
96
+ switch (status) {
97
+ case 5: // Generating
98
+ return { status: types_1.EVideoSceneStatus.PENDING };
99
+ case 7: // moderation failed
100
+ case 8: // generation failed
101
+ return {
102
+ status: types_1.EVideoSceneStatus.FAILED,
103
+ errorMessage: "PixVerse video generation failed",
104
+ };
105
+ case 1: // success
106
+ break;
107
+ default:
108
+ return {
109
+ status: types_1.EVideoSceneStatus.FAILED,
110
+ errorMessage: `Unknown PixVerse status: ${status}`,
111
+ };
112
+ }
113
+ const sourceVideoUrl = data?.Resp?.url;
114
+ if (!sourceVideoUrl) {
115
+ return {
116
+ status: types_1.EVideoSceneStatus.FAILED,
117
+ errorMessage: "PixVerse response missing video url",
118
+ };
119
+ }
120
+ // Download generated video
121
+ const videoResp = await fetch(sourceVideoUrl);
122
+ if (!videoResp.ok) {
123
+ throw new Error(`Failed to download PixVerse video (${videoResp.status})`);
124
+ }
125
+ const buffer = Buffer.from(await videoResp.arrayBuffer());
126
+ // ---- Upload to Firebase ----
127
+ const filePath = `${outputFilePath}/${outputFilename}.mp4`;
128
+ const bucket = (0, firebase_1.getBucket)();
129
+ const file = bucket.file(filePath);
130
+ const downloadToken = crypto_1.default.randomUUID();
131
+ await file.save(buffer, {
132
+ contentType: "video/mp4",
133
+ resumable: false,
134
+ metadata: {
135
+ cacheControl: "public, max-age=31536000",
136
+ metadata: {
137
+ firebaseStorageDownloadTokens: downloadToken,
138
+ },
139
+ },
140
+ });
141
+ const publicVideoUrl = `https://firebasestorage.googleapis.com/v0/b/${bucket.name}` +
142
+ `/o/${encodeURIComponent(filePath)}?alt=media&token=${downloadToken}`;
143
+ return {
144
+ videoUrl: publicVideoUrl,
145
+ status: types_1.EVideoSceneStatus.COMPLETED,
146
+ };
147
+ }
148
+ // =========================================================
149
+ // CREDIT CALCULATION
150
+ // =========================================================
151
+ getCreditUsed(params) {
152
+ const modelConfig = aiModels_1.aiModelConfigs[params.modelKey];
153
+ if (!params.resolution || !params.duration) {
154
+ logger_1.logger.warn(`Missing resolution/duration for PixVerse credit calculation`);
155
+ return 10;
156
+ }
157
+ const hasAudio = Boolean(params.audio);
158
+ const multiClip = Boolean(params.multiClip);
159
+ try {
160
+ let cost;
161
+ if (modelConfig.cost?.audio || modelConfig.cost?.noAudio) {
162
+ const costGroup = hasAudio
163
+ ? modelConfig.cost.audio
164
+ : modelConfig.cost.noAudio;
165
+ // v5.5 structure (singleClip / multiClip)
166
+ if ("singleClip" in costGroup) {
167
+ const clipType = multiClip ? "multiClip" : "singleClip";
168
+ cost =
169
+ costGroup[clipType]?.table?.[params.resolution]?.[params.duration];
170
+ }
171
+ else {
172
+ // v5 / v5.6 structure
173
+ cost = costGroup?.table?.[params.resolution]?.[params.duration];
174
+ }
175
+ }
176
+ if (!cost) {
177
+ logger_1.logger.warn(`Unsupported combination for PixVerse credit calc: ${JSON.stringify(params)}`);
178
+ return 10;
179
+ }
180
+ return (0, helpers_2.getCreditsFromCost)(cost);
181
+ }
182
+ catch (err) {
183
+ logger_1.logger.error(`PixVerse credit calculation failed`, err);
184
+ return 10;
185
+ }
186
+ }
187
+ }
188
+ exports.PixVerseService = PixVerseService;
@@ -1 +1 @@
1
- {"version":3,"file":"runway.service.d.ts","sourceRoot":"","sources":["../../../../../src/services/aiGen/providers/runway/runway.service.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,wBAAwB,EAAE,MAAM,8BAA8B,CAAC;AACxE,OAAO,EACL,iBAAiB,EACjB,qBAAqB,EACrB,qBAAqB,EACrB,iBAAiB,EACjB,iBAAiB,EAClB,MAAM,UAAU,CAAC;AAGlB,qBAAa,aAAc,SAAQ,wBAAwB;IACzD,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAiC;IACzD,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;;YAUlB,OAAO;IA+Bf,aAAa,CACjB,MAAM,EAAE,qBAAqB,GAC5B,OAAO,CAAC,qBAAqB,CAAC;IAuC3B,gBAAgB,CAAC,EACrB,IAAI,EACJ,cAAc,EACd,cAAyB,GAC1B,EAAE,iBAAiB,GAAG,OAAO,CAAC,iBAAiB,CAAC;IA4DjD,aAAa,CAAC,EAAE,QAAQ,EAAE,QAAY,EAAE,EAAE,iBAAiB,GAAG,MAAM;CAIrE"}
1
+ {"version":3,"file":"runway.service.d.ts","sourceRoot":"","sources":["../../../../../src/services/aiGen/providers/runway/runway.service.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,wBAAwB,EAAE,MAAM,8BAA8B,CAAC;AACxE,OAAO,EACL,iBAAiB,EACjB,qBAAqB,EACrB,qBAAqB,EACrB,iBAAiB,EACjB,iBAAiB,EAClB,MAAM,UAAU,CAAC;AAGlB,qBAAa,aAAc,SAAQ,wBAAwB;IACzD,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAqC;IAC7D,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;;YAUlB,OAAO;IAgCf,aAAa,CACjB,MAAM,EAAE,qBAAqB,GAC5B,OAAO,CAAC,qBAAqB,CAAC;IAqD3B,gBAAgB,CAAC,EACrB,IAAI,EACJ,cAAc,EACd,cAAyB,GAC1B,EAAE,iBAAiB,GAAG,OAAO,CAAC,iBAAiB,CAAC;IA4DjD,aAAa,CAAC,EAAE,QAAQ,EAAE,QAAY,EAAE,EAAE,iBAAiB,GAAG,MAAM;CAIrE"}
@@ -14,7 +14,7 @@ const baseAiGenProvider_service_1 = require("../baseAiGenProvider.service");
14
14
  class RunwayService extends baseAiGenProvider_service_1.BaseAiGenProviderService {
15
15
  constructor() {
16
16
  super();
17
- this.baseUrl = "https://api.runwayml.com/v1";
17
+ this.baseUrl = "https://api.dev.runwayml.com/v1";
18
18
  if (!process.env.RUNWAYML_API_SECRET) {
19
19
  throw new Error("Missing RUNWAYML_API_SECRET in environment variables");
20
20
  }
@@ -25,6 +25,7 @@ class RunwayService extends baseAiGenProvider_service_1.BaseAiGenProviderService
25
25
  const headers = {
26
26
  Authorization: `Bearer ${this.apiKey}`,
27
27
  "Content-Type": "application/json",
28
+ "X-Runway-Version": "2024-11-06",
28
29
  };
29
30
  const response = await (0, axios_1.default)({
30
31
  url,
@@ -45,8 +46,19 @@ class RunwayService extends baseAiGenProvider_service_1.BaseAiGenProviderService
45
46
  if (!modelId)
46
47
  throw new Error(`Unknown modelKey: ${params.modelKey}`);
47
48
  let run;
48
- // IMAGE → VIDEO
49
- if (modelId === "gen4_turbo") {
49
+ // TEXT → VIDEO (gen4.5)
50
+ if (modelId === "gen4.5") {
51
+ const ratio = (params.aspectRatio || "1280x720").replace("x", ":");
52
+ const body = {
53
+ model: "gen4.5",
54
+ promptText: params.prompt,
55
+ ratio,
56
+ duration: params.duration || 5,
57
+ };
58
+ run = await this.request("/text_to_video", "POST", body);
59
+ }
60
+ // IMAGE → VIDEO (gen4_turbo)
61
+ else if (modelId === "gen4_turbo") {
50
62
  const body = {
51
63
  model: "gen4_turbo",
52
64
  promptText: params.prompt,
@@ -56,7 +68,7 @@ class RunwayService extends baseAiGenProvider_service_1.BaseAiGenProviderService
56
68
  };
57
69
  run = await this.request("/image-to-video", "POST", body);
58
70
  }
59
- // VIDEO → VIDEO
71
+ // VIDEO → VIDEO (gen4_aleph)
60
72
  else if (modelId === "gen4_aleph") {
61
73
  const body = {
62
74
  model: "gen4_aleph",
@@ -10,8 +10,12 @@ export interface VideoGenerationParams {
10
10
  duration?: number;
11
11
  inputVideoUrl?: string;
12
12
  inputImageUrl?: string;
13
+ inputAudioUrl?: string;
13
14
  mode?: EVideoMode;
14
15
  type?: "text-to-video" | "image-to-video" | "video-to-video";
16
+ audio?: boolean;
17
+ negativePrompt?: string;
18
+ multiClip?: boolean;
15
19
  }
16
20
  export interface VideoGenerationResult {
17
21
  status: EVideoSceneStatus.TRIGGERED;
@@ -45,5 +49,7 @@ export interface CreditUsageParams {
45
49
  aspectRatio?: string;
46
50
  inputType?: "text" | "image" | "video";
47
51
  outputType?: "text" | "image" | "video";
52
+ audio?: boolean;
53
+ multiClip?: boolean;
48
54
  }
49
55
  //# sourceMappingURL=types.d.ts.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,MAAM,CAAC;IACxB,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB;AAED,MAAM,WAAW,qBAAqB;IACpC,MAAM,EAAE,iBAAiB,CAAC,SAAS,CAAC;IACpC,IAAI,EAAE,aAAa,CAAC;CACrB;AAED,MAAM,WAAW,iBAAiB;IAChC,MAAM,EAAE,iBAAiB,CAAC;IAC1B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,YAAY,CAAC,EAAE,MAAM,CAAC;CAEvB;AAED,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,aAAa,CAAC;IACpB,QAAQ,EAAE,eAAe,CAAC;IAC1B,cAAc,EAAE,MAAM,CAAC;IACvB,cAAc,CAAC,EAAE,MAAM,CAAC;CAMzB;AAED,MAAM,WAAW,oBAAoB;IAEnC,KAAK,EAAE,GAAG,CAAC;IACX,QAAQ,EAAE,cAAc,CAAC;IACzB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAC/B;AAED,MAAM,WAAW,oBAAoB;IACnC,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,iBAAiB;IAChC,QAAQ,EAAE,eAAe,GAAG,cAAc,CAAC;IAC3C,IAAI,CAAC,EAAE,UAAU,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,GAAG,OAAO,GAAG,OAAO,CAAC;IACvC,UAAU,CAAC,EAAE,MAAM,GAAG,OAAO,GAAG,OAAO,CAAC;IACxC,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB"}
@@ -1,4 +1,5 @@
1
1
  export declare class CreditService {
2
2
  static consumeCredits(userId: string, creditsToConsume: number): Promise<void>;
3
+ static refundCredits(userId: string, creditsToRefund: number): Promise<void>;
3
4
  }
4
5
  //# sourceMappingURL=credit.service.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"credit.service.d.ts","sourceRoot":"","sources":["../../src/services/credit.service.ts"],"names":[],"mappings":"AAGA,qBAAa,aAAa;WACX,cAAc,CACzB,MAAM,EAAE,MAAM,EACd,gBAAgB,EAAE,MAAM,GACvB,OAAO,CAAC,IAAI,CAAC;CAwBjB"}
1
+ {"version":3,"file":"credit.service.d.ts","sourceRoot":"","sources":["../../src/services/credit.service.ts"],"names":[],"mappings":"AAGA,qBAAa,aAAa;WACX,cAAc,CACzB,MAAM,EAAE,MAAM,EACd,gBAAgB,EAAE,MAAM,GACvB,OAAO,CAAC,IAAI,CAAC;WAyBH,aAAa,CACxB,MAAM,EAAE,MAAM,EACd,eAAe,EAAE,MAAM,GACtB,OAAO,CAAC,IAAI,CAAC;CAoBjB"}
@@ -25,5 +25,22 @@ class CreditService {
25
25
  });
26
26
  });
27
27
  }
28
+ static async refundCredits(userId, creditsToRefund) {
29
+ if (creditsToRefund <= 0)
30
+ return;
31
+ await firebase_1.firestore.runTransaction(async (tx) => {
32
+ const userRef = firestore_service_1.FirestoreService.usersCol.doc(userId);
33
+ const snap = await tx.get(userRef);
34
+ if (!snap.exists) {
35
+ throw new Error("USER_NOT_FOUND");
36
+ }
37
+ const consumed = snap.data()?.credits?.consumed ?? 0;
38
+ // Never let consumed go below 0
39
+ const newConsumed = Math.max(0, consumed - creditsToRefund);
40
+ tx.update(userRef, {
41
+ "credits.consumed": newConsumed,
42
+ });
43
+ });
44
+ }
28
45
  }
29
46
  exports.CreditService = CreditService;
@@ -4,4 +4,5 @@ export * from "./aiGen";
4
4
  export * from "./bullmq.service";
5
5
  export * from "./gcp";
6
6
  export * from "./credit.service";
7
+ export * from "./tts";
7
8
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/services/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,qBAAqB,CAAC;AACpC,cAAc,SAAS,CAAC;AACxB,cAAc,kBAAkB,CAAC;AACjC,cAAc,OAAO,CAAC;AACtB,cAAc,kBAAkB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/services/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,qBAAqB,CAAC;AACpC,cAAc,SAAS,CAAC;AACxB,cAAc,kBAAkB,CAAC;AACjC,cAAc,OAAO,CAAC;AACtB,cAAc,kBAAkB,CAAC;AACjC,cAAc,OAAO,CAAC"}
@@ -20,3 +20,4 @@ __exportStar(require("./aiGen"), exports);
20
20
  __exportStar(require("./bullmq.service"), exports);
21
21
  __exportStar(require("./gcp"), exports);
22
22
  __exportStar(require("./credit.service"), exports);
23
+ __exportStar(require("./tts"), exports);
@@ -0,0 +1,4 @@
1
+ export * from "./types";
2
+ export * from "./providers/elevenlabs.service";
3
+ export * from "./ttsFactory.service";
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/services/tts/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,gCAAgC,CAAC;AAC/C,cAAc,sBAAsB,CAAC"}
@@ -0,0 +1,19 @@
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("./types"), exports);
18
+ __exportStar(require("./providers/elevenlabs.service"), exports);
19
+ __exportStar(require("./ttsFactory.service"), exports);
@@ -0,0 +1,7 @@
1
+ import { BaseTtsProviderService, TtsParams, TtsResult } from "../types";
2
+ export declare class ElevenLabsService extends BaseTtsProviderService {
3
+ private readonly baseUrl;
4
+ constructor();
5
+ generate(params: TtsParams): Promise<TtsResult>;
6
+ }
7
+ //# sourceMappingURL=elevenlabs.service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"elevenlabs.service.d.ts","sourceRoot":"","sources":["../../../../src/services/tts/providers/elevenlabs.service.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,sBAAsB,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAExE,qBAAa,iBAAkB,SAAQ,sBAAsB;IAC3D,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAkC;;IASpD,QAAQ,CAAC,MAAM,EAAE,SAAS,GAAG,OAAO,CAAC,SAAS,CAAC;CA+BtD"}