@runapi.ai/kling 0.2.8 → 0.2.9

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/dist/index.mjs CHANGED
@@ -2,9 +2,438 @@
2
2
  import { BaseClient } from "@runapi.ai/core";
3
3
 
4
4
  // src/resources/text-to-video.ts
5
- import { compactParams } from "@runapi.ai/core";
5
+ import { ValidationError, compactParams, validateParams } from "@runapi.ai/core";
6
6
  import { pollUntilComplete } from "@runapi.ai/core/internal";
7
+
8
+ // src/contract_gen.ts
9
+ var contract = {
10
+ "avatar": {
11
+ "models": [
12
+ "kling-ai-avatar-pro",
13
+ "kling-ai-avatar-standard",
14
+ "kling-ai-avatar-v1-pro",
15
+ "kling-v1-avatar-standard"
16
+ ],
17
+ "fields_by_model": {
18
+ "kling-ai-avatar-pro": {
19
+ "model": {
20
+ "required": true
21
+ },
22
+ "prompt": {
23
+ "required": true
24
+ },
25
+ "source_audio_url": {
26
+ "required": true
27
+ },
28
+ "source_image_url": {
29
+ "required": true
30
+ }
31
+ },
32
+ "kling-ai-avatar-standard": {
33
+ "model": {
34
+ "required": true
35
+ },
36
+ "prompt": {
37
+ "required": true
38
+ },
39
+ "source_audio_url": {
40
+ "required": true
41
+ },
42
+ "source_image_url": {
43
+ "required": true
44
+ }
45
+ },
46
+ "kling-ai-avatar-v1-pro": {
47
+ "model": {
48
+ "required": true
49
+ },
50
+ "prompt": {
51
+ "required": true
52
+ },
53
+ "source_audio_url": {
54
+ "required": true
55
+ },
56
+ "source_image_url": {
57
+ "required": true
58
+ }
59
+ },
60
+ "kling-v1-avatar-standard": {
61
+ "model": {
62
+ "required": true
63
+ },
64
+ "prompt": {
65
+ "required": true
66
+ },
67
+ "source_audio_url": {
68
+ "required": true
69
+ },
70
+ "source_image_url": {
71
+ "required": true
72
+ }
73
+ }
74
+ }
75
+ },
76
+ "image-to-video": {
77
+ "models": [
78
+ "kling-v2.1-master-image-to-video",
79
+ "kling-v2.1-pro",
80
+ "kling-v2.1-standard",
81
+ "kling-v2.5-turbo-image-to-video-pro",
82
+ "kling-v3-turbo-image-to-video"
83
+ ],
84
+ "fields_by_model": {
85
+ "kling-v2.1-master-image-to-video": {
86
+ "duration_seconds": {
87
+ "enum": [
88
+ 5,
89
+ 10
90
+ ],
91
+ "type": "integer"
92
+ },
93
+ "first_frame_image_url": {
94
+ "required": true
95
+ },
96
+ "model": {
97
+ "required": true
98
+ },
99
+ "prompt": {
100
+ "required": true
101
+ }
102
+ },
103
+ "kling-v2.1-pro": {
104
+ "duration_seconds": {
105
+ "enum": [
106
+ 5,
107
+ 10
108
+ ],
109
+ "type": "integer"
110
+ },
111
+ "first_frame_image_url": {
112
+ "required": true
113
+ },
114
+ "model": {
115
+ "required": true
116
+ },
117
+ "prompt": {
118
+ "required": true
119
+ }
120
+ },
121
+ "kling-v2.1-standard": {
122
+ "duration_seconds": {
123
+ "enum": [
124
+ 5,
125
+ 10
126
+ ],
127
+ "type": "integer"
128
+ },
129
+ "first_frame_image_url": {
130
+ "required": true
131
+ },
132
+ "model": {
133
+ "required": true
134
+ },
135
+ "prompt": {
136
+ "required": true
137
+ }
138
+ },
139
+ "kling-v2.5-turbo-image-to-video-pro": {
140
+ "duration_seconds": {
141
+ "enum": [
142
+ 5,
143
+ 10
144
+ ],
145
+ "type": "integer"
146
+ },
147
+ "first_frame_image_url": {
148
+ "required": true
149
+ },
150
+ "model": {
151
+ "required": true
152
+ },
153
+ "prompt": {
154
+ "required": true
155
+ }
156
+ },
157
+ "kling-v3-turbo-image-to-video": {
158
+ "duration_seconds": {
159
+ "enum": [
160
+ 3,
161
+ 4,
162
+ 5,
163
+ 6,
164
+ 7,
165
+ 8,
166
+ 9,
167
+ 10,
168
+ 11,
169
+ 12,
170
+ 13,
171
+ 14,
172
+ 15
173
+ ],
174
+ "type": "integer"
175
+ },
176
+ "first_frame_image_url": {
177
+ "required": true
178
+ },
179
+ "model": {
180
+ "required": true
181
+ },
182
+ "output_resolution": {
183
+ "enum": [
184
+ "720p",
185
+ "1080p"
186
+ ]
187
+ },
188
+ "prompt": {
189
+ "required": true,
190
+ "min": 1,
191
+ "max": 2500,
192
+ "length": true
193
+ }
194
+ }
195
+ },
196
+ "rules": [
197
+ {
198
+ "when": {
199
+ "model": "kling-v2.1-master-image-to-video"
200
+ },
201
+ "forbidden": [
202
+ "output_resolution"
203
+ ]
204
+ },
205
+ {
206
+ "when": {
207
+ "model": "kling-v2.1-pro"
208
+ },
209
+ "forbidden": [
210
+ "output_resolution"
211
+ ]
212
+ },
213
+ {
214
+ "when": {
215
+ "model": "kling-v2.1-standard"
216
+ },
217
+ "forbidden": [
218
+ "output_resolution"
219
+ ]
220
+ },
221
+ {
222
+ "when": {
223
+ "model": "kling-v2.5-turbo-image-to-video-pro"
224
+ },
225
+ "forbidden": [
226
+ "output_resolution"
227
+ ]
228
+ },
229
+ {
230
+ "when": {
231
+ "model": "kling-v3-turbo-image-to-video"
232
+ },
233
+ "forbidden": [
234
+ "aspect_ratio",
235
+ "negative_prompt",
236
+ "cfg_scale",
237
+ "last_frame_image_url"
238
+ ]
239
+ }
240
+ ]
241
+ },
242
+ "motion-control": {
243
+ "models": [
244
+ "kling-3.0"
245
+ ],
246
+ "fields_by_model": {
247
+ "kling-3.0": {
248
+ "background_source": {
249
+ "enum": [
250
+ "video",
251
+ "image"
252
+ ]
253
+ },
254
+ "character_orientation": {
255
+ "enum": [
256
+ "video",
257
+ "image"
258
+ ]
259
+ },
260
+ "model": {
261
+ "required": true
262
+ },
263
+ "output_resolution": {
264
+ "enum": [
265
+ "720p",
266
+ "1080p"
267
+ ]
268
+ },
269
+ "reference_video_url": {
270
+ "required": true
271
+ },
272
+ "source_image_url": {
273
+ "required": true
274
+ }
275
+ }
276
+ }
277
+ },
278
+ "text-to-video": {
279
+ "models": [
280
+ "kling-3.0",
281
+ "kling-v2.1-master-text-to-video",
282
+ "kling-v2.5-turbo-text-to-video-pro",
283
+ "kling-v3-turbo-text-to-video"
284
+ ],
285
+ "fields_by_model": {
286
+ "kling-3.0": {
287
+ "aspect_ratio": {
288
+ "enum": [
289
+ "16:9",
290
+ "9:16",
291
+ "1:1"
292
+ ]
293
+ },
294
+ "duration_seconds": {
295
+ "enum": [
296
+ 3,
297
+ 4,
298
+ 5,
299
+ 6,
300
+ 7,
301
+ 8,
302
+ 9,
303
+ 10,
304
+ 11,
305
+ 12,
306
+ 13,
307
+ 14,
308
+ 15
309
+ ],
310
+ "type": "integer"
311
+ },
312
+ "model": {
313
+ "required": true
314
+ },
315
+ "output_resolution": {
316
+ "enum": [
317
+ "720p",
318
+ "1080p",
319
+ "4k"
320
+ ]
321
+ }
322
+ },
323
+ "kling-v2.1-master-text-to-video": {
324
+ "aspect_ratio": {
325
+ "enum": [
326
+ "16:9",
327
+ "9:16",
328
+ "1:1"
329
+ ]
330
+ },
331
+ "duration_seconds": {
332
+ "enum": [
333
+ 5,
334
+ 10
335
+ ],
336
+ "type": "integer"
337
+ },
338
+ "model": {
339
+ "required": true
340
+ }
341
+ },
342
+ "kling-v2.5-turbo-text-to-video-pro": {
343
+ "aspect_ratio": {
344
+ "enum": [
345
+ "16:9",
346
+ "9:16",
347
+ "1:1"
348
+ ]
349
+ },
350
+ "duration_seconds": {
351
+ "enum": [
352
+ 5,
353
+ 10
354
+ ],
355
+ "type": "integer"
356
+ },
357
+ "model": {
358
+ "required": true
359
+ }
360
+ },
361
+ "kling-v3-turbo-text-to-video": {
362
+ "aspect_ratio": {
363
+ "enum": [
364
+ "16:9",
365
+ "9:16",
366
+ "1:1"
367
+ ]
368
+ },
369
+ "duration_seconds": {
370
+ "enum": [
371
+ 3,
372
+ 4,
373
+ 5,
374
+ 6,
375
+ 7,
376
+ 8,
377
+ 9,
378
+ 10,
379
+ 11,
380
+ 12,
381
+ 13,
382
+ 14,
383
+ 15
384
+ ],
385
+ "type": "integer"
386
+ },
387
+ "model": {
388
+ "required": true
389
+ },
390
+ "output_resolution": {
391
+ "enum": [
392
+ "720p",
393
+ "1080p"
394
+ ]
395
+ },
396
+ "prompt": {
397
+ "required": true,
398
+ "min": 1,
399
+ "max": 2500,
400
+ "length": true
401
+ }
402
+ }
403
+ },
404
+ "rules": [
405
+ {
406
+ "when": {
407
+ "model": "kling-v3-turbo-text-to-video"
408
+ },
409
+ "forbidden": [
410
+ "enable_sound",
411
+ "negative_prompt",
412
+ "cfg_scale",
413
+ "multi_shots",
414
+ "multi_prompt",
415
+ "first_frame_image_url",
416
+ "last_frame_image_url",
417
+ "kling_elements"
418
+ ]
419
+ }
420
+ ]
421
+ }
422
+ };
423
+
424
+ // src/resources/text-to-video.ts
7
425
  var ENDPOINT = "/api/v1/kling/text_to_video";
426
+ var V3_TURBO_MODEL = "kling-v3-turbo-text-to-video";
427
+ var V3_TURBO_UNSUPPORTED_FIELDS = [
428
+ "enable_sound",
429
+ "negative_prompt",
430
+ "cfg_scale",
431
+ "multi_shots",
432
+ "multi_prompt",
433
+ "first_frame_image_url",
434
+ "last_frame_image_url",
435
+ "kling_elements"
436
+ ];
8
437
  var TextToVideo = class {
9
438
  constructor(http) {
10
439
  this.http = http;
@@ -31,8 +460,11 @@ var TextToVideo = class {
31
460
  * @returns The task creation result with id.
32
461
  */
33
462
  async create(params, options) {
463
+ const body = compactParams(params);
464
+ rejectUnsupportedV3TurboFields(body);
465
+ validateParams(contract["text-to-video"], body);
34
466
  return this.http.request("POST", ENDPOINT, {
35
- body: compactParams(params),
467
+ body,
36
468
  ...options
37
469
  });
38
470
  }
@@ -48,11 +480,40 @@ var TextToVideo = class {
48
480
  });
49
481
  }
50
482
  };
483
+ function rejectUnsupportedV3TurboFields(body) {
484
+ if (body.model !== V3_TURBO_MODEL) return;
485
+ const field = V3_TURBO_UNSUPPORTED_FIELDS.find((candidate) => fieldPresent(body, candidate));
486
+ if (field) {
487
+ throw new ValidationError(`${field} is not supported by ${V3_TURBO_MODEL}`);
488
+ }
489
+ }
490
+ function fieldPresent(params, field) {
491
+ if (!(field in params)) return false;
492
+ const value = params[field];
493
+ if (value === false) return true;
494
+ if (Array.isArray(value)) return value.some((item) => presentValue(item));
495
+ return presentValue(value);
496
+ }
497
+ function presentValue(value) {
498
+ if (value === null || value === void 0 || value === false) return false;
499
+ if (value === true) return true;
500
+ if (typeof value === "string") return value.trim() !== "";
501
+ if (Array.isArray(value)) return value.length > 0;
502
+ if (typeof value === "object") return Object.keys(value).length > 0;
503
+ return true;
504
+ }
51
505
 
52
506
  // src/resources/image-to-video.ts
53
- import { compactParams as compactParams2 } from "@runapi.ai/core";
507
+ import { ValidationError as ValidationError2, compactParams as compactParams2, validateParams as validateParams2 } from "@runapi.ai/core";
54
508
  import { pollUntilComplete as pollUntilComplete2 } from "@runapi.ai/core/internal";
55
509
  var ENDPOINT2 = "/api/v1/kling/image_to_video";
510
+ var V3_TURBO_MODEL2 = "kling-v3-turbo-image-to-video";
511
+ var V3_TURBO_UNSUPPORTED_FIELDS2 = [
512
+ "aspect_ratio",
513
+ "negative_prompt",
514
+ "cfg_scale",
515
+ "last_frame_image_url"
516
+ ];
56
517
  var ImageToVideo = class {
57
518
  constructor(http) {
58
519
  this.http = http;
@@ -79,8 +540,11 @@ var ImageToVideo = class {
79
540
  * @returns The task creation result with id.
80
541
  */
81
542
  async create(params, options) {
543
+ const body = compactParams2(params);
544
+ rejectUnsupportedV3TurboFields2(body);
545
+ validateParams2(contract["image-to-video"], body);
82
546
  return this.http.request("POST", ENDPOINT2, {
83
- body: compactParams2(params),
547
+ body,
84
548
  ...options
85
549
  });
86
550
  }
@@ -96,9 +560,31 @@ var ImageToVideo = class {
96
560
  });
97
561
  }
98
562
  };
563
+ function rejectUnsupportedV3TurboFields2(body) {
564
+ if (body.model !== V3_TURBO_MODEL2) return;
565
+ const field = V3_TURBO_UNSUPPORTED_FIELDS2.find((candidate) => fieldPresent2(body, candidate));
566
+ if (field) {
567
+ throw new ValidationError2(`${field} is not supported by ${V3_TURBO_MODEL2}`);
568
+ }
569
+ }
570
+ function fieldPresent2(params, field) {
571
+ if (!(field in params)) return false;
572
+ const value = params[field];
573
+ if (value === false) return true;
574
+ if (Array.isArray(value)) return value.some((item) => presentValue2(item));
575
+ return presentValue2(value);
576
+ }
577
+ function presentValue2(value) {
578
+ if (value === null || value === void 0 || value === false) return false;
579
+ if (value === true) return true;
580
+ if (typeof value === "string") return value.trim() !== "";
581
+ if (Array.isArray(value)) return value.length > 0;
582
+ if (typeof value === "object") return Object.keys(value).length > 0;
583
+ return true;
584
+ }
99
585
 
100
586
  // src/resources/ai-avatar.ts
101
- import { compactParams as compactParams3 } from "@runapi.ai/core";
587
+ import { compactParams as compactParams3, validateParams as validateParams3 } from "@runapi.ai/core";
102
588
  import { pollUntilComplete as pollUntilComplete3 } from "@runapi.ai/core/internal";
103
589
  var ENDPOINT3 = "/api/v1/kling/ai_avatar";
104
590
  var AiAvatar = class {
@@ -127,8 +613,10 @@ var AiAvatar = class {
127
613
  * @returns The task creation result with id.
128
614
  */
129
615
  async create(params, options) {
616
+ const body = compactParams3(params);
617
+ validateParams3(contract["avatar"], body);
130
618
  return this.http.request("POST", ENDPOINT3, {
131
- body: compactParams3(params),
619
+ body,
132
620
  ...options
133
621
  });
134
622
  }
@@ -146,7 +634,7 @@ var AiAvatar = class {
146
634
  };
147
635
 
148
636
  // src/resources/motion-control.ts
149
- import { compactParams as compactParams4 } from "@runapi.ai/core";
637
+ import { compactParams as compactParams4, validateParams as validateParams4 } from "@runapi.ai/core";
150
638
  import { pollUntilComplete as pollUntilComplete4 } from "@runapi.ai/core/internal";
151
639
  var ENDPOINT4 = "/api/v1/kling/motion_control";
152
640
  var MotionControl = class {
@@ -175,8 +663,10 @@ var MotionControl = class {
175
663
  * @returns The task creation result with id.
176
664
  */
177
665
  async create(params, options) {
666
+ const body = compactParams4(params);
667
+ validateParams4(contract["motion-control"], body);
178
668
  return this.http.request("POST", ENDPOINT4, {
179
- body: compactParams4(params),
669
+ body,
180
670
  ...options
181
671
  });
182
672
  }
@@ -218,7 +708,7 @@ import {
218
708
  AuthenticationError,
219
709
  InsufficientCreditsError,
220
710
  NotFoundError,
221
- ValidationError,
711
+ ValidationError as ValidationError3,
222
712
  RateLimitError,
223
713
  ServiceUnavailableError,
224
714
  NetworkError,
@@ -238,6 +728,6 @@ export {
238
728
  TaskFailedError,
239
729
  TaskTimeoutError,
240
730
  TimeoutError,
241
- ValidationError
731
+ ValidationError3 as ValidationError
242
732
  };
243
733
  //# sourceMappingURL=index.mjs.map