@runapi.ai/kling 0.2.12 → 0.2.13
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/README.md +17 -0
- package/dist/index.d.mts +42 -6
- package/dist/index.d.ts +42 -6
- package/dist/index.js +436 -47
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +411 -22
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
- package/skills/kling/README.md +2 -0
- package/skills/kling/SKILL.md +2 -0
package/dist/index.js
CHANGED
|
@@ -20,26 +20,26 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/index.ts
|
|
21
21
|
var index_exports = {};
|
|
22
22
|
__export(index_exports, {
|
|
23
|
-
AuthenticationError: () =>
|
|
24
|
-
InsufficientCreditsError: () =>
|
|
23
|
+
AuthenticationError: () => import_core8.AuthenticationError,
|
|
24
|
+
InsufficientCreditsError: () => import_core8.InsufficientCreditsError,
|
|
25
25
|
KlingClient: () => KlingClient,
|
|
26
|
-
NetworkError: () =>
|
|
27
|
-
NotFoundError: () =>
|
|
28
|
-
RateLimitError: () =>
|
|
29
|
-
RunApiError: () =>
|
|
30
|
-
ServiceUnavailableError: () =>
|
|
31
|
-
TaskFailedError: () =>
|
|
32
|
-
TaskTimeoutError: () =>
|
|
33
|
-
TimeoutError: () =>
|
|
34
|
-
ValidationError: () =>
|
|
26
|
+
NetworkError: () => import_core8.NetworkError,
|
|
27
|
+
NotFoundError: () => import_core8.NotFoundError,
|
|
28
|
+
RateLimitError: () => import_core8.RateLimitError,
|
|
29
|
+
RunApiError: () => import_core8.RunApiError,
|
|
30
|
+
ServiceUnavailableError: () => import_core8.ServiceUnavailableError,
|
|
31
|
+
TaskFailedError: () => import_core8.TaskFailedError,
|
|
32
|
+
TaskTimeoutError: () => import_core8.TaskTimeoutError,
|
|
33
|
+
TimeoutError: () => import_core8.TimeoutError,
|
|
34
|
+
ValidationError: () => import_core8.ValidationError
|
|
35
35
|
});
|
|
36
36
|
module.exports = __toCommonJS(index_exports);
|
|
37
37
|
|
|
38
38
|
// src/client.ts
|
|
39
|
-
var
|
|
39
|
+
var import_core7 = require("@runapi.ai/core");
|
|
40
40
|
|
|
41
41
|
// src/resources/text-to-video.ts
|
|
42
|
-
var
|
|
42
|
+
var import_core2 = require("@runapi.ai/core");
|
|
43
43
|
var import_internal = require("@runapi.ai/core/internal");
|
|
44
44
|
|
|
45
45
|
// src/contract_gen.ts
|
|
@@ -142,6 +142,7 @@ var contract = {
|
|
|
142
142
|
},
|
|
143
143
|
"image-to-video": {
|
|
144
144
|
"models": [
|
|
145
|
+
"kling-o1",
|
|
145
146
|
"kling-v2.1-master-image-to-video",
|
|
146
147
|
"kling-v2.1-pro",
|
|
147
148
|
"kling-v2.1-standard",
|
|
@@ -151,6 +152,49 @@ var contract = {
|
|
|
151
152
|
"kling-v3-turbo-image-to-video"
|
|
152
153
|
],
|
|
153
154
|
"fields_by_model": {
|
|
155
|
+
"kling-o1": {
|
|
156
|
+
"aspect_ratio": {
|
|
157
|
+
"enum": [
|
|
158
|
+
"16:9",
|
|
159
|
+
"9:16",
|
|
160
|
+
"1:1"
|
|
161
|
+
]
|
|
162
|
+
},
|
|
163
|
+
"duration_seconds": {
|
|
164
|
+
"enum": [
|
|
165
|
+
5
|
|
166
|
+
],
|
|
167
|
+
"type": "integer"
|
|
168
|
+
},
|
|
169
|
+
"first_frame_image_url": {
|
|
170
|
+
"required": true
|
|
171
|
+
},
|
|
172
|
+
"mode": {
|
|
173
|
+
"enum": [
|
|
174
|
+
"std",
|
|
175
|
+
"pro"
|
|
176
|
+
]
|
|
177
|
+
},
|
|
178
|
+
"model": {
|
|
179
|
+
"required": true
|
|
180
|
+
},
|
|
181
|
+
"prompt": {
|
|
182
|
+
"required": true,
|
|
183
|
+
"min": 1,
|
|
184
|
+
"max": 2500,
|
|
185
|
+
"length": true
|
|
186
|
+
},
|
|
187
|
+
"reference_image_urls": {
|
|
188
|
+
"min_items": 1,
|
|
189
|
+
"max_items": 7
|
|
190
|
+
},
|
|
191
|
+
"reference_video_type": {
|
|
192
|
+
"enum": [
|
|
193
|
+
"base",
|
|
194
|
+
"feature"
|
|
195
|
+
]
|
|
196
|
+
}
|
|
197
|
+
},
|
|
154
198
|
"kling-v2.1-master-image-to-video": {
|
|
155
199
|
"duration_seconds": {
|
|
156
200
|
"enum": [
|
|
@@ -343,13 +387,27 @@ var contract = {
|
|
|
343
387
|
}
|
|
344
388
|
},
|
|
345
389
|
"rules": [
|
|
390
|
+
{
|
|
391
|
+
"when": {
|
|
392
|
+
"model": "kling-o1"
|
|
393
|
+
},
|
|
394
|
+
"forbidden": [
|
|
395
|
+
"output_resolution",
|
|
396
|
+
"negative_prompt",
|
|
397
|
+
"cfg_scale"
|
|
398
|
+
]
|
|
399
|
+
},
|
|
346
400
|
{
|
|
347
401
|
"when": {
|
|
348
402
|
"model": "kling-v2.1-master-image-to-video"
|
|
349
403
|
},
|
|
350
404
|
"forbidden": [
|
|
351
405
|
"output_resolution",
|
|
352
|
-
"enable_sound"
|
|
406
|
+
"enable_sound",
|
|
407
|
+
"reference_image_urls",
|
|
408
|
+
"reference_video_url",
|
|
409
|
+
"reference_video_type",
|
|
410
|
+
"preserve_reference_video_audio"
|
|
353
411
|
]
|
|
354
412
|
},
|
|
355
413
|
{
|
|
@@ -358,7 +416,11 @@ var contract = {
|
|
|
358
416
|
},
|
|
359
417
|
"forbidden": [
|
|
360
418
|
"output_resolution",
|
|
361
|
-
"enable_sound"
|
|
419
|
+
"enable_sound",
|
|
420
|
+
"reference_image_urls",
|
|
421
|
+
"reference_video_url",
|
|
422
|
+
"reference_video_type",
|
|
423
|
+
"preserve_reference_video_audio"
|
|
362
424
|
]
|
|
363
425
|
},
|
|
364
426
|
{
|
|
@@ -367,7 +429,11 @@ var contract = {
|
|
|
367
429
|
},
|
|
368
430
|
"forbidden": [
|
|
369
431
|
"output_resolution",
|
|
370
|
-
"enable_sound"
|
|
432
|
+
"enable_sound",
|
|
433
|
+
"reference_image_urls",
|
|
434
|
+
"reference_video_url",
|
|
435
|
+
"reference_video_type",
|
|
436
|
+
"preserve_reference_video_audio"
|
|
371
437
|
]
|
|
372
438
|
},
|
|
373
439
|
{
|
|
@@ -376,7 +442,11 @@ var contract = {
|
|
|
376
442
|
},
|
|
377
443
|
"forbidden": [
|
|
378
444
|
"output_resolution",
|
|
379
|
-
"enable_sound"
|
|
445
|
+
"enable_sound",
|
|
446
|
+
"reference_image_urls",
|
|
447
|
+
"reference_video_url",
|
|
448
|
+
"reference_video_type",
|
|
449
|
+
"preserve_reference_video_audio"
|
|
380
450
|
]
|
|
381
451
|
},
|
|
382
452
|
{
|
|
@@ -386,7 +456,11 @@ var contract = {
|
|
|
386
456
|
"forbidden": [
|
|
387
457
|
"output_resolution",
|
|
388
458
|
"negative_prompt",
|
|
389
|
-
"cfg_scale"
|
|
459
|
+
"cfg_scale",
|
|
460
|
+
"reference_image_urls",
|
|
461
|
+
"reference_video_url",
|
|
462
|
+
"reference_video_type",
|
|
463
|
+
"preserve_reference_video_audio"
|
|
390
464
|
]
|
|
391
465
|
},
|
|
392
466
|
{
|
|
@@ -395,7 +469,11 @@ var contract = {
|
|
|
395
469
|
},
|
|
396
470
|
"forbidden": [
|
|
397
471
|
"negative_prompt",
|
|
398
|
-
"cfg_scale"
|
|
472
|
+
"cfg_scale",
|
|
473
|
+
"reference_image_urls",
|
|
474
|
+
"reference_video_url",
|
|
475
|
+
"reference_video_type",
|
|
476
|
+
"preserve_reference_video_audio"
|
|
399
477
|
]
|
|
400
478
|
},
|
|
401
479
|
{
|
|
@@ -407,7 +485,11 @@ var contract = {
|
|
|
407
485
|
"aspect_ratio",
|
|
408
486
|
"negative_prompt",
|
|
409
487
|
"cfg_scale",
|
|
410
|
-
"last_frame_image_url"
|
|
488
|
+
"last_frame_image_url",
|
|
489
|
+
"reference_image_urls",
|
|
490
|
+
"reference_video_url",
|
|
491
|
+
"reference_video_type",
|
|
492
|
+
"preserve_reference_video_audio"
|
|
411
493
|
]
|
|
412
494
|
}
|
|
413
495
|
]
|
|
@@ -491,6 +573,7 @@ var contract = {
|
|
|
491
573
|
"text-to-video": {
|
|
492
574
|
"models": [
|
|
493
575
|
"kling-3.0",
|
|
576
|
+
"kling-o1",
|
|
494
577
|
"kling-v2.1-master-text-to-video",
|
|
495
578
|
"kling-v2.5-turbo-text-to-video-pro",
|
|
496
579
|
"kling-v2.6",
|
|
@@ -535,6 +618,46 @@ var contract = {
|
|
|
535
618
|
]
|
|
536
619
|
}
|
|
537
620
|
},
|
|
621
|
+
"kling-o1": {
|
|
622
|
+
"aspect_ratio": {
|
|
623
|
+
"enum": [
|
|
624
|
+
"16:9",
|
|
625
|
+
"9:16",
|
|
626
|
+
"1:1"
|
|
627
|
+
]
|
|
628
|
+
},
|
|
629
|
+
"duration_seconds": {
|
|
630
|
+
"enum": [
|
|
631
|
+
5
|
|
632
|
+
],
|
|
633
|
+
"type": "integer"
|
|
634
|
+
},
|
|
635
|
+
"mode": {
|
|
636
|
+
"enum": [
|
|
637
|
+
"std",
|
|
638
|
+
"pro"
|
|
639
|
+
]
|
|
640
|
+
},
|
|
641
|
+
"model": {
|
|
642
|
+
"required": true
|
|
643
|
+
},
|
|
644
|
+
"prompt": {
|
|
645
|
+
"required": true,
|
|
646
|
+
"min": 1,
|
|
647
|
+
"max": 2500,
|
|
648
|
+
"length": true
|
|
649
|
+
},
|
|
650
|
+
"reference_image_urls": {
|
|
651
|
+
"min_items": 1,
|
|
652
|
+
"max_items": 7
|
|
653
|
+
},
|
|
654
|
+
"reference_video_type": {
|
|
655
|
+
"enum": [
|
|
656
|
+
"base",
|
|
657
|
+
"feature"
|
|
658
|
+
]
|
|
659
|
+
}
|
|
660
|
+
},
|
|
538
661
|
"kling-v2.1-master-text-to-video": {
|
|
539
662
|
"aspect_ratio": {
|
|
540
663
|
"enum": [
|
|
@@ -691,12 +814,54 @@ var contract = {
|
|
|
691
814
|
}
|
|
692
815
|
},
|
|
693
816
|
"rules": [
|
|
817
|
+
{
|
|
818
|
+
"when": {
|
|
819
|
+
"model": "kling-3.0"
|
|
820
|
+
},
|
|
821
|
+
"forbidden": [
|
|
822
|
+
"reference_image_urls",
|
|
823
|
+
"reference_video_url",
|
|
824
|
+
"reference_video_type",
|
|
825
|
+
"preserve_reference_video_audio"
|
|
826
|
+
]
|
|
827
|
+
},
|
|
828
|
+
{
|
|
829
|
+
"when": {
|
|
830
|
+
"model": "kling-o1"
|
|
831
|
+
},
|
|
832
|
+
"forbidden": [
|
|
833
|
+
"output_resolution",
|
|
834
|
+
"negative_prompt",
|
|
835
|
+
"cfg_scale",
|
|
836
|
+
"multi_shots",
|
|
837
|
+
"multi_prompt",
|
|
838
|
+
"first_frame_image_url",
|
|
839
|
+
"last_frame_image_url",
|
|
840
|
+
"kling_elements"
|
|
841
|
+
]
|
|
842
|
+
},
|
|
843
|
+
{
|
|
844
|
+
"when": {
|
|
845
|
+
"model": "kling-v2.1-master-text-to-video"
|
|
846
|
+
},
|
|
847
|
+
"forbidden": [
|
|
848
|
+
"mode",
|
|
849
|
+
"reference_image_urls",
|
|
850
|
+
"reference_video_url",
|
|
851
|
+
"reference_video_type",
|
|
852
|
+
"preserve_reference_video_audio"
|
|
853
|
+
]
|
|
854
|
+
},
|
|
694
855
|
{
|
|
695
856
|
"when": {
|
|
696
857
|
"model": "kling-v2.5-turbo-text-to-video-pro"
|
|
697
858
|
},
|
|
698
859
|
"forbidden": [
|
|
699
|
-
"mode"
|
|
860
|
+
"mode",
|
|
861
|
+
"reference_image_urls",
|
|
862
|
+
"reference_video_url",
|
|
863
|
+
"reference_video_type",
|
|
864
|
+
"preserve_reference_video_audio"
|
|
700
865
|
]
|
|
701
866
|
},
|
|
702
867
|
{
|
|
@@ -711,7 +876,11 @@ var contract = {
|
|
|
711
876
|
"multi_prompt",
|
|
712
877
|
"first_frame_image_url",
|
|
713
878
|
"last_frame_image_url",
|
|
714
|
-
"kling_elements"
|
|
879
|
+
"kling_elements",
|
|
880
|
+
"reference_image_urls",
|
|
881
|
+
"reference_video_url",
|
|
882
|
+
"reference_video_type",
|
|
883
|
+
"preserve_reference_video_audio"
|
|
715
884
|
]
|
|
716
885
|
},
|
|
717
886
|
{
|
|
@@ -725,7 +894,11 @@ var contract = {
|
|
|
725
894
|
"multi_prompt",
|
|
726
895
|
"first_frame_image_url",
|
|
727
896
|
"last_frame_image_url",
|
|
728
|
-
"kling_elements"
|
|
897
|
+
"kling_elements",
|
|
898
|
+
"reference_image_urls",
|
|
899
|
+
"reference_video_url",
|
|
900
|
+
"reference_video_type",
|
|
901
|
+
"preserve_reference_video_audio"
|
|
729
902
|
]
|
|
730
903
|
},
|
|
731
904
|
{
|
|
@@ -740,13 +913,227 @@ var contract = {
|
|
|
740
913
|
"multi_prompt",
|
|
741
914
|
"first_frame_image_url",
|
|
742
915
|
"last_frame_image_url",
|
|
743
|
-
"kling_elements"
|
|
916
|
+
"kling_elements",
|
|
917
|
+
"reference_image_urls",
|
|
918
|
+
"reference_video_url",
|
|
919
|
+
"reference_video_type",
|
|
920
|
+
"preserve_reference_video_audio"
|
|
744
921
|
]
|
|
745
922
|
}
|
|
746
923
|
]
|
|
747
924
|
}
|
|
748
925
|
};
|
|
749
926
|
|
|
927
|
+
// src/resources/o1-reference-validation.ts
|
|
928
|
+
var import_core = require("@runapi.ai/core");
|
|
929
|
+
var O1_MODEL = "kling-o1";
|
|
930
|
+
var IMAGE_EXTENSIONS = /* @__PURE__ */ new Set([".jpg", ".jpeg", ".png"]);
|
|
931
|
+
var VIDEO_EXTENSIONS = /* @__PURE__ */ new Set([".mp4", ".mov"]);
|
|
932
|
+
var BLOCKED_IP_CIDRS = [
|
|
933
|
+
"0.0.0.0/8",
|
|
934
|
+
"10.0.0.0/8",
|
|
935
|
+
"100.64.0.0/10",
|
|
936
|
+
"127.0.0.0/8",
|
|
937
|
+
"169.254.0.0/16",
|
|
938
|
+
"172.16.0.0/12",
|
|
939
|
+
"192.0.0.0/24",
|
|
940
|
+
"192.0.2.0/24",
|
|
941
|
+
"192.88.99.0/24",
|
|
942
|
+
"192.168.0.0/16",
|
|
943
|
+
"198.18.0.0/15",
|
|
944
|
+
"198.51.100.0/24",
|
|
945
|
+
"203.0.113.0/24",
|
|
946
|
+
"224.0.0.0/4",
|
|
947
|
+
"240.0.0.0/4",
|
|
948
|
+
"255.255.255.255/32",
|
|
949
|
+
"::/128",
|
|
950
|
+
"::1/128",
|
|
951
|
+
"64:ff9b::/96",
|
|
952
|
+
"64:ff9b:1::/48",
|
|
953
|
+
"100::/64",
|
|
954
|
+
"2001::/32",
|
|
955
|
+
"2001:2::/48",
|
|
956
|
+
"2001:db8::/32",
|
|
957
|
+
"2002::/16",
|
|
958
|
+
"3fff::/20",
|
|
959
|
+
"fc00::/7",
|
|
960
|
+
"fe80::/10",
|
|
961
|
+
"ff00::/8"
|
|
962
|
+
];
|
|
963
|
+
var BLOCKED_IP_NETWORKS = BLOCKED_IP_CIDRS.map((cidr) => {
|
|
964
|
+
const [address, prefixText] = cidr.split("/");
|
|
965
|
+
const parsed = parseIpLiteral(address);
|
|
966
|
+
if (!parsed) throw new Error("Invalid blocked IP range: " + cidr);
|
|
967
|
+
return { ...parsed, prefix: Number(prefixText) };
|
|
968
|
+
});
|
|
969
|
+
function validateKlingO1References(body) {
|
|
970
|
+
if (body.model !== O1_MODEL) return;
|
|
971
|
+
if (body.enable_sound === true) {
|
|
972
|
+
throw new import_core.ValidationError(`enable_sound is not supported by ${O1_MODEL}`);
|
|
973
|
+
}
|
|
974
|
+
validateFrameUrls(body);
|
|
975
|
+
if (typeof body.prompt !== "string") {
|
|
976
|
+
throw new import_core.ValidationError("prompt must be a string");
|
|
977
|
+
}
|
|
978
|
+
const prompt = body.prompt;
|
|
979
|
+
const referenceImages = Array.isArray(body.reference_image_urls) ? body.reference_image_urls : [];
|
|
980
|
+
if ("reference_video_url" in body && typeof body.reference_video_url !== "string") {
|
|
981
|
+
throw new import_core.ValidationError("reference_video_url must be a string");
|
|
982
|
+
}
|
|
983
|
+
const referenceVideoUrl = body.reference_video_url;
|
|
984
|
+
if (present(body.last_frame_image_url) && (referenceImages.length > 0 || present(referenceVideoUrl))) {
|
|
985
|
+
throw new import_core.ValidationError(
|
|
986
|
+
"last_frame_image_url cannot be combined with reference_image_urls or reference_video_url"
|
|
987
|
+
);
|
|
988
|
+
}
|
|
989
|
+
if (referenceVideoUrl && referenceImages.length > 4) {
|
|
990
|
+
throw new import_core.ValidationError(
|
|
991
|
+
"reference_image_urls must contain at most 4 items when reference_video_url is present"
|
|
992
|
+
);
|
|
993
|
+
}
|
|
994
|
+
validateReferenceImages(prompt, referenceImages);
|
|
995
|
+
validateReferenceVideo(body, prompt, referenceVideoUrl);
|
|
996
|
+
}
|
|
997
|
+
function validateFrameUrls(body) {
|
|
998
|
+
for (const field of ["first_frame_image_url", "last_frame_image_url"]) {
|
|
999
|
+
const value = body[field];
|
|
1000
|
+
if (typeof value !== "string" || value.length === 0) continue;
|
|
1001
|
+
if (!isPublicHttpUrl(value)) {
|
|
1002
|
+
throw new import_core.ValidationError(`${field} must be a public HTTP or HTTPS URL`);
|
|
1003
|
+
}
|
|
1004
|
+
if (!IMAGE_EXTENSIONS.has(urlExtension(value))) {
|
|
1005
|
+
throw new import_core.ValidationError(`${field} must use a JPG, JPEG, or PNG URL`);
|
|
1006
|
+
}
|
|
1007
|
+
}
|
|
1008
|
+
}
|
|
1009
|
+
function validateReferenceImages(prompt, urls) {
|
|
1010
|
+
urls.forEach((url, index) => {
|
|
1011
|
+
if (typeof url !== "string") {
|
|
1012
|
+
throw new import_core.ValidationError(`reference_image_urls[${index}] must be a string`);
|
|
1013
|
+
}
|
|
1014
|
+
if (!isPublicHttpUrl(url)) {
|
|
1015
|
+
throw new import_core.ValidationError(
|
|
1016
|
+
`reference_image_urls[${index}] must be a public HTTP or HTTPS URL`
|
|
1017
|
+
);
|
|
1018
|
+
}
|
|
1019
|
+
if (!IMAGE_EXTENSIONS.has(urlExtension(url))) {
|
|
1020
|
+
throw new import_core.ValidationError(
|
|
1021
|
+
`reference_image_urls[${index}] must use a JPG, JPEG, or PNG URL`
|
|
1022
|
+
);
|
|
1023
|
+
}
|
|
1024
|
+
const marker = `<<<image_${index + 1}>>>`;
|
|
1025
|
+
if (!prompt.includes(marker)) {
|
|
1026
|
+
throw new import_core.ValidationError(
|
|
1027
|
+
`prompt must reference reference_image_urls[${index}] as ${marker}`
|
|
1028
|
+
);
|
|
1029
|
+
}
|
|
1030
|
+
});
|
|
1031
|
+
for (const match of prompt.matchAll(/<<<image_(\d+)>>>/g)) {
|
|
1032
|
+
const index = Number(match[1]);
|
|
1033
|
+
if (index < 1 || index > urls.length) {
|
|
1034
|
+
throw new import_core.ValidationError(`prompt references missing image_${index}`);
|
|
1035
|
+
}
|
|
1036
|
+
}
|
|
1037
|
+
}
|
|
1038
|
+
function validateReferenceVideo(body, prompt, referenceVideoUrl) {
|
|
1039
|
+
if (!referenceVideoUrl) {
|
|
1040
|
+
if ("reference_video_type" in body) {
|
|
1041
|
+
throw new import_core.ValidationError("reference_video_type requires reference_video_url");
|
|
1042
|
+
}
|
|
1043
|
+
if ("preserve_reference_video_audio" in body) {
|
|
1044
|
+
throw new import_core.ValidationError("preserve_reference_video_audio requires reference_video_url");
|
|
1045
|
+
}
|
|
1046
|
+
const missingMarker = prompt.match(/<<<video_([^>]+)>>>/);
|
|
1047
|
+
if (missingMarker) {
|
|
1048
|
+
throw new import_core.ValidationError(`prompt references missing video_${missingMarker[1]}`);
|
|
1049
|
+
}
|
|
1050
|
+
return;
|
|
1051
|
+
}
|
|
1052
|
+
if (!isPublicHttpUrl(referenceVideoUrl)) {
|
|
1053
|
+
throw new import_core.ValidationError("reference_video_url must be a public HTTP or HTTPS URL");
|
|
1054
|
+
}
|
|
1055
|
+
if (!VIDEO_EXTENSIONS.has(urlExtension(referenceVideoUrl))) {
|
|
1056
|
+
throw new import_core.ValidationError("reference_video_url must use an MP4 or MOV URL");
|
|
1057
|
+
}
|
|
1058
|
+
if (!prompt.includes("<<<video_1>>>")) {
|
|
1059
|
+
throw new import_core.ValidationError("prompt must reference reference_video_url as <<<video_1>>>");
|
|
1060
|
+
}
|
|
1061
|
+
for (const match of prompt.matchAll(/<<<video_([^>]+)>>>/g)) {
|
|
1062
|
+
if (match[1] !== "1") {
|
|
1063
|
+
throw new import_core.ValidationError("prompt may only reference video_1");
|
|
1064
|
+
}
|
|
1065
|
+
}
|
|
1066
|
+
const referenceVideoType = body.reference_video_type ?? "base";
|
|
1067
|
+
if (referenceVideoType === "base" && (present(body.first_frame_image_url) || present(body.last_frame_image_url))) {
|
|
1068
|
+
throw new import_core.ValidationError(
|
|
1069
|
+
"reference_video_type base cannot be combined with first_frame_image_url or last_frame_image_url"
|
|
1070
|
+
);
|
|
1071
|
+
}
|
|
1072
|
+
}
|
|
1073
|
+
function present(value) {
|
|
1074
|
+
return typeof value === "string" ? value.trim().length > 0 : value !== void 0 && value !== null;
|
|
1075
|
+
}
|
|
1076
|
+
function urlExtension(value) {
|
|
1077
|
+
try {
|
|
1078
|
+
const path = new URL(value).pathname;
|
|
1079
|
+
const dot = path.lastIndexOf(".");
|
|
1080
|
+
return dot >= 0 ? path.slice(dot).toLowerCase() : "";
|
|
1081
|
+
} catch {
|
|
1082
|
+
return "";
|
|
1083
|
+
}
|
|
1084
|
+
}
|
|
1085
|
+
function isPublicHttpUrl(value) {
|
|
1086
|
+
try {
|
|
1087
|
+
const url = new URL(value);
|
|
1088
|
+
return (url.protocol === "http:" || url.protocol === "https:") && url.hostname.length > 0 && url.username.length === 0 && url.password.length === 0 && !isBlockedHost(url.hostname);
|
|
1089
|
+
} catch {
|
|
1090
|
+
return false;
|
|
1091
|
+
}
|
|
1092
|
+
}
|
|
1093
|
+
function isBlockedHost(hostname) {
|
|
1094
|
+
const host = hostname.toLowerCase().replace(/^\[|\]$/g, "").replace(/\.$/, "");
|
|
1095
|
+
if (host === "localhost" || host.endsWith(".localhost")) return true;
|
|
1096
|
+
const parsed = parseIpLiteral(host);
|
|
1097
|
+
if (!parsed) return false;
|
|
1098
|
+
return BLOCKED_IP_NETWORKS.some((network) => {
|
|
1099
|
+
if (network.bits !== parsed.bits) return false;
|
|
1100
|
+
const shift = BigInt(parsed.bits - network.prefix);
|
|
1101
|
+
return parsed.value >> shift === network.value >> shift;
|
|
1102
|
+
});
|
|
1103
|
+
}
|
|
1104
|
+
function parseIpLiteral(value) {
|
|
1105
|
+
const ipv4 = parseIpv4(value);
|
|
1106
|
+
if (ipv4 !== void 0) return { bits: 32, value: ipv4 };
|
|
1107
|
+
if (!value.includes(":")) return void 0;
|
|
1108
|
+
const halves = value.toLowerCase().split("::");
|
|
1109
|
+
if (halves.length > 2) return void 0;
|
|
1110
|
+
const head = parseIpv6Half(halves[0]);
|
|
1111
|
+
const tail = parseIpv6Half(halves[1] ?? "");
|
|
1112
|
+
if (!head || !tail) return void 0;
|
|
1113
|
+
const compressed = halves.length === 2;
|
|
1114
|
+
const missing = 8 - head.length - tail.length;
|
|
1115
|
+
if (!compressed && missing !== 0 || compressed && missing < 1) return void 0;
|
|
1116
|
+
const segments = [...head, ...Array(missing).fill(0), ...tail];
|
|
1117
|
+
const address = segments.reduce((result, segment) => result << 16n | BigInt(segment), 0n);
|
|
1118
|
+
if (address >> 32n === 0xffffn) {
|
|
1119
|
+
return { bits: 32, value: address & 0xffffffffn };
|
|
1120
|
+
}
|
|
1121
|
+
return { bits: 128, value: address };
|
|
1122
|
+
}
|
|
1123
|
+
function parseIpv4(value) {
|
|
1124
|
+
const parts = value.split(".");
|
|
1125
|
+
if (parts.length !== 4 || parts.some((part) => !/^\d+$/.test(part))) return void 0;
|
|
1126
|
+
const octets = parts.map(Number);
|
|
1127
|
+
if (octets.some((octet) => octet < 0 || octet > 255)) return void 0;
|
|
1128
|
+
return octets.reduce((result, octet) => result << 8n | BigInt(octet), 0n);
|
|
1129
|
+
}
|
|
1130
|
+
function parseIpv6Half(value) {
|
|
1131
|
+
if (value === "") return [];
|
|
1132
|
+
const parts = value.split(":");
|
|
1133
|
+
if (parts.some((part) => !/^[0-9a-f]{1,4}$/.test(part))) return void 0;
|
|
1134
|
+
return parts.map((part) => Number.parseInt(part, 16));
|
|
1135
|
+
}
|
|
1136
|
+
|
|
750
1137
|
// src/resources/text-to-video.ts
|
|
751
1138
|
var ENDPOINT = "/api/v1/kling/text_to_video";
|
|
752
1139
|
var V26_MODEL = "kling-v2.6";
|
|
@@ -787,10 +1174,11 @@ var TextToVideo = class {
|
|
|
787
1174
|
* @returns The task creation result with id.
|
|
788
1175
|
*/
|
|
789
1176
|
async create(params, options) {
|
|
790
|
-
const body = (0,
|
|
1177
|
+
const body = (0, import_core2.compactParams)(params);
|
|
791
1178
|
rejectUnsupportedV3TurboFields(body);
|
|
792
|
-
(0,
|
|
1179
|
+
(0, import_core2.validateParams)(contract["text-to-video"], body);
|
|
793
1180
|
validateV26Params(body);
|
|
1181
|
+
validateKlingO1References(body);
|
|
794
1182
|
return this.http.request("POST", ENDPOINT, {
|
|
795
1183
|
body,
|
|
796
1184
|
...options
|
|
@@ -811,14 +1199,14 @@ var TextToVideo = class {
|
|
|
811
1199
|
function validateV26Params(body) {
|
|
812
1200
|
if (body.model !== V26_MODEL) return;
|
|
813
1201
|
if (body.enable_sound === true && body.mode !== "pro") {
|
|
814
|
-
throw new
|
|
1202
|
+
throw new import_core2.ValidationError(`enable_sound requires mode pro for ${V26_MODEL}`);
|
|
815
1203
|
}
|
|
816
1204
|
}
|
|
817
1205
|
function rejectUnsupportedV3TurboFields(body) {
|
|
818
1206
|
if (body.model !== V3_TURBO_MODEL) return;
|
|
819
1207
|
const field = V3_TURBO_UNSUPPORTED_FIELDS.find((candidate) => fieldPresent(body, candidate));
|
|
820
1208
|
if (field) {
|
|
821
|
-
throw new
|
|
1209
|
+
throw new import_core2.ValidationError(`${field} is not supported by ${V3_TURBO_MODEL}`);
|
|
822
1210
|
}
|
|
823
1211
|
}
|
|
824
1212
|
function fieldPresent(params, field) {
|
|
@@ -838,7 +1226,7 @@ function presentValue(value) {
|
|
|
838
1226
|
}
|
|
839
1227
|
|
|
840
1228
|
// src/resources/image-to-video.ts
|
|
841
|
-
var
|
|
1229
|
+
var import_core3 = require("@runapi.ai/core");
|
|
842
1230
|
var import_internal2 = require("@runapi.ai/core/internal");
|
|
843
1231
|
var ENDPOINT2 = "/api/v1/kling/image_to_video";
|
|
844
1232
|
var V26_MODEL2 = "kling-v2.6";
|
|
@@ -876,11 +1264,12 @@ var ImageToVideo = class {
|
|
|
876
1264
|
* @returns The task creation result with id.
|
|
877
1265
|
*/
|
|
878
1266
|
async create(params, options) {
|
|
879
|
-
const body = (0,
|
|
1267
|
+
const body = (0, import_core3.compactParams)(params);
|
|
880
1268
|
rejectUnsupportedV3TurboFields2(body);
|
|
881
|
-
(0,
|
|
1269
|
+
(0, import_core3.validateParams)(contract["image-to-video"], body);
|
|
882
1270
|
validateV26Params2(body);
|
|
883
1271
|
validateV3OmniFields(body);
|
|
1272
|
+
validateKlingO1References(body);
|
|
884
1273
|
return this.http.request("POST", ENDPOINT2, {
|
|
885
1274
|
body,
|
|
886
1275
|
...options
|
|
@@ -901,27 +1290,27 @@ var ImageToVideo = class {
|
|
|
901
1290
|
function validateV26Params2(body) {
|
|
902
1291
|
if (body.model !== V26_MODEL2) return;
|
|
903
1292
|
if (body.enable_sound === true && body.mode !== "pro") {
|
|
904
|
-
throw new
|
|
1293
|
+
throw new import_core3.ValidationError(`enable_sound requires mode pro for ${V26_MODEL2}`);
|
|
905
1294
|
}
|
|
906
1295
|
if (!fieldPresent2(body, "last_frame_image_url")) return;
|
|
907
1296
|
if (body.mode !== "pro") {
|
|
908
|
-
throw new
|
|
1297
|
+
throw new import_core3.ValidationError(`last_frame_image_url requires mode pro for ${V26_MODEL2}`);
|
|
909
1298
|
}
|
|
910
1299
|
if (body.duration_seconds !== void 0 && body.duration_seconds !== 5) {
|
|
911
|
-
throw new
|
|
1300
|
+
throw new import_core3.ValidationError(`last_frame_image_url requires duration_seconds 5 for ${V26_MODEL2}`);
|
|
912
1301
|
}
|
|
913
1302
|
}
|
|
914
1303
|
function validateV3OmniFields(body) {
|
|
915
1304
|
if (body.model !== V3_OMNI_MODEL || !fieldPresent2(body, "last_frame_image_url")) return;
|
|
916
1305
|
if ((body.duration_seconds ?? 5) !== 5) {
|
|
917
|
-
throw new
|
|
1306
|
+
throw new import_core3.ValidationError(`last_frame_image_url requires duration_seconds 5 for ${V3_OMNI_MODEL}`);
|
|
918
1307
|
}
|
|
919
1308
|
}
|
|
920
1309
|
function rejectUnsupportedV3TurboFields2(body) {
|
|
921
1310
|
if (body.model !== V3_TURBO_MODEL2) return;
|
|
922
1311
|
const field = V3_TURBO_UNSUPPORTED_FIELDS2.find((candidate) => fieldPresent2(body, candidate));
|
|
923
1312
|
if (field) {
|
|
924
|
-
throw new
|
|
1313
|
+
throw new import_core3.ValidationError(`${field} is not supported by ${V3_TURBO_MODEL2}`);
|
|
925
1314
|
}
|
|
926
1315
|
}
|
|
927
1316
|
function fieldPresent2(params, field) {
|
|
@@ -941,7 +1330,7 @@ function presentValue2(value) {
|
|
|
941
1330
|
}
|
|
942
1331
|
|
|
943
1332
|
// src/resources/ai-avatar.ts
|
|
944
|
-
var
|
|
1333
|
+
var import_core4 = require("@runapi.ai/core");
|
|
945
1334
|
var import_internal3 = require("@runapi.ai/core/internal");
|
|
946
1335
|
var ENDPOINT3 = "/api/v1/kling/ai_avatar";
|
|
947
1336
|
var AiAvatar = class {
|
|
@@ -970,8 +1359,8 @@ var AiAvatar = class {
|
|
|
970
1359
|
* @returns The task creation result with id.
|
|
971
1360
|
*/
|
|
972
1361
|
async create(params, options) {
|
|
973
|
-
const body = (0,
|
|
974
|
-
(0,
|
|
1362
|
+
const body = (0, import_core4.compactParams)(params);
|
|
1363
|
+
(0, import_core4.validateParams)(contract["avatar"], body);
|
|
975
1364
|
return this.http.request("POST", ENDPOINT3, {
|
|
976
1365
|
body,
|
|
977
1366
|
...options
|
|
@@ -991,7 +1380,7 @@ var AiAvatar = class {
|
|
|
991
1380
|
};
|
|
992
1381
|
|
|
993
1382
|
// src/resources/motion-control.ts
|
|
994
|
-
var
|
|
1383
|
+
var import_core5 = require("@runapi.ai/core");
|
|
995
1384
|
var import_internal4 = require("@runapi.ai/core/internal");
|
|
996
1385
|
var ENDPOINT4 = "/api/v1/kling/motion_control";
|
|
997
1386
|
var MotionControl = class {
|
|
@@ -1020,8 +1409,8 @@ var MotionControl = class {
|
|
|
1020
1409
|
* @returns The task creation result with id.
|
|
1021
1410
|
*/
|
|
1022
1411
|
async create(params, options) {
|
|
1023
|
-
const body = (0,
|
|
1024
|
-
(0,
|
|
1412
|
+
const body = (0, import_core5.compactParams)(params);
|
|
1413
|
+
(0, import_core5.validateParams)(contract["motion-control"], body);
|
|
1025
1414
|
return this.http.request("POST", ENDPOINT4, {
|
|
1026
1415
|
body,
|
|
1027
1416
|
...options
|
|
@@ -1041,7 +1430,7 @@ var MotionControl = class {
|
|
|
1041
1430
|
};
|
|
1042
1431
|
|
|
1043
1432
|
// src/resources/extend-video.ts
|
|
1044
|
-
var
|
|
1433
|
+
var import_core6 = require("@runapi.ai/core");
|
|
1045
1434
|
var import_internal5 = require("@runapi.ai/core/internal");
|
|
1046
1435
|
var ENDPOINT5 = "/api/v1/kling/extend_video";
|
|
1047
1436
|
var ExtendVideo = class {
|
|
@@ -1057,8 +1446,8 @@ var ExtendVideo = class {
|
|
|
1057
1446
|
});
|
|
1058
1447
|
}
|
|
1059
1448
|
async create(params, options) {
|
|
1060
|
-
const body = (0,
|
|
1061
|
-
(0,
|
|
1449
|
+
const body = (0, import_core6.compactParams)(params);
|
|
1450
|
+
(0, import_core6.validateParams)(contract["extend-video"], body);
|
|
1062
1451
|
return this.http.request("POST", ENDPOINT5, { body, ...options });
|
|
1063
1452
|
}
|
|
1064
1453
|
async get(id, options) {
|
|
@@ -1067,7 +1456,7 @@ var ExtendVideo = class {
|
|
|
1067
1456
|
};
|
|
1068
1457
|
|
|
1069
1458
|
// src/client.ts
|
|
1070
|
-
var KlingClient = class extends
|
|
1459
|
+
var KlingClient = class extends import_core7.BaseClient {
|
|
1071
1460
|
/** Text-to-video generation with multi-shot, sound, and Kling elements support on kling-3.0. */
|
|
1072
1461
|
textToVideo;
|
|
1073
1462
|
/** Image-to-video animation from a first-frame image guided by a text prompt. */
|
|
@@ -1088,7 +1477,7 @@ var KlingClient = class extends import_core6.BaseClient {
|
|
|
1088
1477
|
};
|
|
1089
1478
|
|
|
1090
1479
|
// src/index.ts
|
|
1091
|
-
var
|
|
1480
|
+
var import_core8 = require("@runapi.ai/core");
|
|
1092
1481
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1093
1482
|
0 && (module.exports = {
|
|
1094
1483
|
AuthenticationError,
|