@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.mjs
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { BaseClient } from "@runapi.ai/core";
|
|
3
3
|
|
|
4
4
|
// src/resources/text-to-video.ts
|
|
5
|
-
import { ValidationError, compactParams, validateParams } from "@runapi.ai/core";
|
|
5
|
+
import { ValidationError as ValidationError2, compactParams, validateParams } from "@runapi.ai/core";
|
|
6
6
|
import { pollUntilComplete } from "@runapi.ai/core/internal";
|
|
7
7
|
|
|
8
8
|
// src/contract_gen.ts
|
|
@@ -105,6 +105,7 @@ var contract = {
|
|
|
105
105
|
},
|
|
106
106
|
"image-to-video": {
|
|
107
107
|
"models": [
|
|
108
|
+
"kling-o1",
|
|
108
109
|
"kling-v2.1-master-image-to-video",
|
|
109
110
|
"kling-v2.1-pro",
|
|
110
111
|
"kling-v2.1-standard",
|
|
@@ -114,6 +115,49 @@ var contract = {
|
|
|
114
115
|
"kling-v3-turbo-image-to-video"
|
|
115
116
|
],
|
|
116
117
|
"fields_by_model": {
|
|
118
|
+
"kling-o1": {
|
|
119
|
+
"aspect_ratio": {
|
|
120
|
+
"enum": [
|
|
121
|
+
"16:9",
|
|
122
|
+
"9:16",
|
|
123
|
+
"1:1"
|
|
124
|
+
]
|
|
125
|
+
},
|
|
126
|
+
"duration_seconds": {
|
|
127
|
+
"enum": [
|
|
128
|
+
5
|
|
129
|
+
],
|
|
130
|
+
"type": "integer"
|
|
131
|
+
},
|
|
132
|
+
"first_frame_image_url": {
|
|
133
|
+
"required": true
|
|
134
|
+
},
|
|
135
|
+
"mode": {
|
|
136
|
+
"enum": [
|
|
137
|
+
"std",
|
|
138
|
+
"pro"
|
|
139
|
+
]
|
|
140
|
+
},
|
|
141
|
+
"model": {
|
|
142
|
+
"required": true
|
|
143
|
+
},
|
|
144
|
+
"prompt": {
|
|
145
|
+
"required": true,
|
|
146
|
+
"min": 1,
|
|
147
|
+
"max": 2500,
|
|
148
|
+
"length": true
|
|
149
|
+
},
|
|
150
|
+
"reference_image_urls": {
|
|
151
|
+
"min_items": 1,
|
|
152
|
+
"max_items": 7
|
|
153
|
+
},
|
|
154
|
+
"reference_video_type": {
|
|
155
|
+
"enum": [
|
|
156
|
+
"base",
|
|
157
|
+
"feature"
|
|
158
|
+
]
|
|
159
|
+
}
|
|
160
|
+
},
|
|
117
161
|
"kling-v2.1-master-image-to-video": {
|
|
118
162
|
"duration_seconds": {
|
|
119
163
|
"enum": [
|
|
@@ -306,13 +350,27 @@ var contract = {
|
|
|
306
350
|
}
|
|
307
351
|
},
|
|
308
352
|
"rules": [
|
|
353
|
+
{
|
|
354
|
+
"when": {
|
|
355
|
+
"model": "kling-o1"
|
|
356
|
+
},
|
|
357
|
+
"forbidden": [
|
|
358
|
+
"output_resolution",
|
|
359
|
+
"negative_prompt",
|
|
360
|
+
"cfg_scale"
|
|
361
|
+
]
|
|
362
|
+
},
|
|
309
363
|
{
|
|
310
364
|
"when": {
|
|
311
365
|
"model": "kling-v2.1-master-image-to-video"
|
|
312
366
|
},
|
|
313
367
|
"forbidden": [
|
|
314
368
|
"output_resolution",
|
|
315
|
-
"enable_sound"
|
|
369
|
+
"enable_sound",
|
|
370
|
+
"reference_image_urls",
|
|
371
|
+
"reference_video_url",
|
|
372
|
+
"reference_video_type",
|
|
373
|
+
"preserve_reference_video_audio"
|
|
316
374
|
]
|
|
317
375
|
},
|
|
318
376
|
{
|
|
@@ -321,7 +379,11 @@ var contract = {
|
|
|
321
379
|
},
|
|
322
380
|
"forbidden": [
|
|
323
381
|
"output_resolution",
|
|
324
|
-
"enable_sound"
|
|
382
|
+
"enable_sound",
|
|
383
|
+
"reference_image_urls",
|
|
384
|
+
"reference_video_url",
|
|
385
|
+
"reference_video_type",
|
|
386
|
+
"preserve_reference_video_audio"
|
|
325
387
|
]
|
|
326
388
|
},
|
|
327
389
|
{
|
|
@@ -330,7 +392,11 @@ var contract = {
|
|
|
330
392
|
},
|
|
331
393
|
"forbidden": [
|
|
332
394
|
"output_resolution",
|
|
333
|
-
"enable_sound"
|
|
395
|
+
"enable_sound",
|
|
396
|
+
"reference_image_urls",
|
|
397
|
+
"reference_video_url",
|
|
398
|
+
"reference_video_type",
|
|
399
|
+
"preserve_reference_video_audio"
|
|
334
400
|
]
|
|
335
401
|
},
|
|
336
402
|
{
|
|
@@ -339,7 +405,11 @@ var contract = {
|
|
|
339
405
|
},
|
|
340
406
|
"forbidden": [
|
|
341
407
|
"output_resolution",
|
|
342
|
-
"enable_sound"
|
|
408
|
+
"enable_sound",
|
|
409
|
+
"reference_image_urls",
|
|
410
|
+
"reference_video_url",
|
|
411
|
+
"reference_video_type",
|
|
412
|
+
"preserve_reference_video_audio"
|
|
343
413
|
]
|
|
344
414
|
},
|
|
345
415
|
{
|
|
@@ -349,7 +419,11 @@ var contract = {
|
|
|
349
419
|
"forbidden": [
|
|
350
420
|
"output_resolution",
|
|
351
421
|
"negative_prompt",
|
|
352
|
-
"cfg_scale"
|
|
422
|
+
"cfg_scale",
|
|
423
|
+
"reference_image_urls",
|
|
424
|
+
"reference_video_url",
|
|
425
|
+
"reference_video_type",
|
|
426
|
+
"preserve_reference_video_audio"
|
|
353
427
|
]
|
|
354
428
|
},
|
|
355
429
|
{
|
|
@@ -358,7 +432,11 @@ var contract = {
|
|
|
358
432
|
},
|
|
359
433
|
"forbidden": [
|
|
360
434
|
"negative_prompt",
|
|
361
|
-
"cfg_scale"
|
|
435
|
+
"cfg_scale",
|
|
436
|
+
"reference_image_urls",
|
|
437
|
+
"reference_video_url",
|
|
438
|
+
"reference_video_type",
|
|
439
|
+
"preserve_reference_video_audio"
|
|
362
440
|
]
|
|
363
441
|
},
|
|
364
442
|
{
|
|
@@ -370,7 +448,11 @@ var contract = {
|
|
|
370
448
|
"aspect_ratio",
|
|
371
449
|
"negative_prompt",
|
|
372
450
|
"cfg_scale",
|
|
373
|
-
"last_frame_image_url"
|
|
451
|
+
"last_frame_image_url",
|
|
452
|
+
"reference_image_urls",
|
|
453
|
+
"reference_video_url",
|
|
454
|
+
"reference_video_type",
|
|
455
|
+
"preserve_reference_video_audio"
|
|
374
456
|
]
|
|
375
457
|
}
|
|
376
458
|
]
|
|
@@ -454,6 +536,7 @@ var contract = {
|
|
|
454
536
|
"text-to-video": {
|
|
455
537
|
"models": [
|
|
456
538
|
"kling-3.0",
|
|
539
|
+
"kling-o1",
|
|
457
540
|
"kling-v2.1-master-text-to-video",
|
|
458
541
|
"kling-v2.5-turbo-text-to-video-pro",
|
|
459
542
|
"kling-v2.6",
|
|
@@ -498,6 +581,46 @@ var contract = {
|
|
|
498
581
|
]
|
|
499
582
|
}
|
|
500
583
|
},
|
|
584
|
+
"kling-o1": {
|
|
585
|
+
"aspect_ratio": {
|
|
586
|
+
"enum": [
|
|
587
|
+
"16:9",
|
|
588
|
+
"9:16",
|
|
589
|
+
"1:1"
|
|
590
|
+
]
|
|
591
|
+
},
|
|
592
|
+
"duration_seconds": {
|
|
593
|
+
"enum": [
|
|
594
|
+
5
|
|
595
|
+
],
|
|
596
|
+
"type": "integer"
|
|
597
|
+
},
|
|
598
|
+
"mode": {
|
|
599
|
+
"enum": [
|
|
600
|
+
"std",
|
|
601
|
+
"pro"
|
|
602
|
+
]
|
|
603
|
+
},
|
|
604
|
+
"model": {
|
|
605
|
+
"required": true
|
|
606
|
+
},
|
|
607
|
+
"prompt": {
|
|
608
|
+
"required": true,
|
|
609
|
+
"min": 1,
|
|
610
|
+
"max": 2500,
|
|
611
|
+
"length": true
|
|
612
|
+
},
|
|
613
|
+
"reference_image_urls": {
|
|
614
|
+
"min_items": 1,
|
|
615
|
+
"max_items": 7
|
|
616
|
+
},
|
|
617
|
+
"reference_video_type": {
|
|
618
|
+
"enum": [
|
|
619
|
+
"base",
|
|
620
|
+
"feature"
|
|
621
|
+
]
|
|
622
|
+
}
|
|
623
|
+
},
|
|
501
624
|
"kling-v2.1-master-text-to-video": {
|
|
502
625
|
"aspect_ratio": {
|
|
503
626
|
"enum": [
|
|
@@ -654,12 +777,54 @@ var contract = {
|
|
|
654
777
|
}
|
|
655
778
|
},
|
|
656
779
|
"rules": [
|
|
780
|
+
{
|
|
781
|
+
"when": {
|
|
782
|
+
"model": "kling-3.0"
|
|
783
|
+
},
|
|
784
|
+
"forbidden": [
|
|
785
|
+
"reference_image_urls",
|
|
786
|
+
"reference_video_url",
|
|
787
|
+
"reference_video_type",
|
|
788
|
+
"preserve_reference_video_audio"
|
|
789
|
+
]
|
|
790
|
+
},
|
|
791
|
+
{
|
|
792
|
+
"when": {
|
|
793
|
+
"model": "kling-o1"
|
|
794
|
+
},
|
|
795
|
+
"forbidden": [
|
|
796
|
+
"output_resolution",
|
|
797
|
+
"negative_prompt",
|
|
798
|
+
"cfg_scale",
|
|
799
|
+
"multi_shots",
|
|
800
|
+
"multi_prompt",
|
|
801
|
+
"first_frame_image_url",
|
|
802
|
+
"last_frame_image_url",
|
|
803
|
+
"kling_elements"
|
|
804
|
+
]
|
|
805
|
+
},
|
|
806
|
+
{
|
|
807
|
+
"when": {
|
|
808
|
+
"model": "kling-v2.1-master-text-to-video"
|
|
809
|
+
},
|
|
810
|
+
"forbidden": [
|
|
811
|
+
"mode",
|
|
812
|
+
"reference_image_urls",
|
|
813
|
+
"reference_video_url",
|
|
814
|
+
"reference_video_type",
|
|
815
|
+
"preserve_reference_video_audio"
|
|
816
|
+
]
|
|
817
|
+
},
|
|
657
818
|
{
|
|
658
819
|
"when": {
|
|
659
820
|
"model": "kling-v2.5-turbo-text-to-video-pro"
|
|
660
821
|
},
|
|
661
822
|
"forbidden": [
|
|
662
|
-
"mode"
|
|
823
|
+
"mode",
|
|
824
|
+
"reference_image_urls",
|
|
825
|
+
"reference_video_url",
|
|
826
|
+
"reference_video_type",
|
|
827
|
+
"preserve_reference_video_audio"
|
|
663
828
|
]
|
|
664
829
|
},
|
|
665
830
|
{
|
|
@@ -674,7 +839,11 @@ var contract = {
|
|
|
674
839
|
"multi_prompt",
|
|
675
840
|
"first_frame_image_url",
|
|
676
841
|
"last_frame_image_url",
|
|
677
|
-
"kling_elements"
|
|
842
|
+
"kling_elements",
|
|
843
|
+
"reference_image_urls",
|
|
844
|
+
"reference_video_url",
|
|
845
|
+
"reference_video_type",
|
|
846
|
+
"preserve_reference_video_audio"
|
|
678
847
|
]
|
|
679
848
|
},
|
|
680
849
|
{
|
|
@@ -688,7 +857,11 @@ var contract = {
|
|
|
688
857
|
"multi_prompt",
|
|
689
858
|
"first_frame_image_url",
|
|
690
859
|
"last_frame_image_url",
|
|
691
|
-
"kling_elements"
|
|
860
|
+
"kling_elements",
|
|
861
|
+
"reference_image_urls",
|
|
862
|
+
"reference_video_url",
|
|
863
|
+
"reference_video_type",
|
|
864
|
+
"preserve_reference_video_audio"
|
|
692
865
|
]
|
|
693
866
|
},
|
|
694
867
|
{
|
|
@@ -703,13 +876,227 @@ var contract = {
|
|
|
703
876
|
"multi_prompt",
|
|
704
877
|
"first_frame_image_url",
|
|
705
878
|
"last_frame_image_url",
|
|
706
|
-
"kling_elements"
|
|
879
|
+
"kling_elements",
|
|
880
|
+
"reference_image_urls",
|
|
881
|
+
"reference_video_url",
|
|
882
|
+
"reference_video_type",
|
|
883
|
+
"preserve_reference_video_audio"
|
|
707
884
|
]
|
|
708
885
|
}
|
|
709
886
|
]
|
|
710
887
|
}
|
|
711
888
|
};
|
|
712
889
|
|
|
890
|
+
// src/resources/o1-reference-validation.ts
|
|
891
|
+
import { ValidationError } from "@runapi.ai/core";
|
|
892
|
+
var O1_MODEL = "kling-o1";
|
|
893
|
+
var IMAGE_EXTENSIONS = /* @__PURE__ */ new Set([".jpg", ".jpeg", ".png"]);
|
|
894
|
+
var VIDEO_EXTENSIONS = /* @__PURE__ */ new Set([".mp4", ".mov"]);
|
|
895
|
+
var BLOCKED_IP_CIDRS = [
|
|
896
|
+
"0.0.0.0/8",
|
|
897
|
+
"10.0.0.0/8",
|
|
898
|
+
"100.64.0.0/10",
|
|
899
|
+
"127.0.0.0/8",
|
|
900
|
+
"169.254.0.0/16",
|
|
901
|
+
"172.16.0.0/12",
|
|
902
|
+
"192.0.0.0/24",
|
|
903
|
+
"192.0.2.0/24",
|
|
904
|
+
"192.88.99.0/24",
|
|
905
|
+
"192.168.0.0/16",
|
|
906
|
+
"198.18.0.0/15",
|
|
907
|
+
"198.51.100.0/24",
|
|
908
|
+
"203.0.113.0/24",
|
|
909
|
+
"224.0.0.0/4",
|
|
910
|
+
"240.0.0.0/4",
|
|
911
|
+
"255.255.255.255/32",
|
|
912
|
+
"::/128",
|
|
913
|
+
"::1/128",
|
|
914
|
+
"64:ff9b::/96",
|
|
915
|
+
"64:ff9b:1::/48",
|
|
916
|
+
"100::/64",
|
|
917
|
+
"2001::/32",
|
|
918
|
+
"2001:2::/48",
|
|
919
|
+
"2001:db8::/32",
|
|
920
|
+
"2002::/16",
|
|
921
|
+
"3fff::/20",
|
|
922
|
+
"fc00::/7",
|
|
923
|
+
"fe80::/10",
|
|
924
|
+
"ff00::/8"
|
|
925
|
+
];
|
|
926
|
+
var BLOCKED_IP_NETWORKS = BLOCKED_IP_CIDRS.map((cidr) => {
|
|
927
|
+
const [address, prefixText] = cidr.split("/");
|
|
928
|
+
const parsed = parseIpLiteral(address);
|
|
929
|
+
if (!parsed) throw new Error("Invalid blocked IP range: " + cidr);
|
|
930
|
+
return { ...parsed, prefix: Number(prefixText) };
|
|
931
|
+
});
|
|
932
|
+
function validateKlingO1References(body) {
|
|
933
|
+
if (body.model !== O1_MODEL) return;
|
|
934
|
+
if (body.enable_sound === true) {
|
|
935
|
+
throw new ValidationError(`enable_sound is not supported by ${O1_MODEL}`);
|
|
936
|
+
}
|
|
937
|
+
validateFrameUrls(body);
|
|
938
|
+
if (typeof body.prompt !== "string") {
|
|
939
|
+
throw new ValidationError("prompt must be a string");
|
|
940
|
+
}
|
|
941
|
+
const prompt = body.prompt;
|
|
942
|
+
const referenceImages = Array.isArray(body.reference_image_urls) ? body.reference_image_urls : [];
|
|
943
|
+
if ("reference_video_url" in body && typeof body.reference_video_url !== "string") {
|
|
944
|
+
throw new ValidationError("reference_video_url must be a string");
|
|
945
|
+
}
|
|
946
|
+
const referenceVideoUrl = body.reference_video_url;
|
|
947
|
+
if (present(body.last_frame_image_url) && (referenceImages.length > 0 || present(referenceVideoUrl))) {
|
|
948
|
+
throw new ValidationError(
|
|
949
|
+
"last_frame_image_url cannot be combined with reference_image_urls or reference_video_url"
|
|
950
|
+
);
|
|
951
|
+
}
|
|
952
|
+
if (referenceVideoUrl && referenceImages.length > 4) {
|
|
953
|
+
throw new ValidationError(
|
|
954
|
+
"reference_image_urls must contain at most 4 items when reference_video_url is present"
|
|
955
|
+
);
|
|
956
|
+
}
|
|
957
|
+
validateReferenceImages(prompt, referenceImages);
|
|
958
|
+
validateReferenceVideo(body, prompt, referenceVideoUrl);
|
|
959
|
+
}
|
|
960
|
+
function validateFrameUrls(body) {
|
|
961
|
+
for (const field of ["first_frame_image_url", "last_frame_image_url"]) {
|
|
962
|
+
const value = body[field];
|
|
963
|
+
if (typeof value !== "string" || value.length === 0) continue;
|
|
964
|
+
if (!isPublicHttpUrl(value)) {
|
|
965
|
+
throw new ValidationError(`${field} must be a public HTTP or HTTPS URL`);
|
|
966
|
+
}
|
|
967
|
+
if (!IMAGE_EXTENSIONS.has(urlExtension(value))) {
|
|
968
|
+
throw new ValidationError(`${field} must use a JPG, JPEG, or PNG URL`);
|
|
969
|
+
}
|
|
970
|
+
}
|
|
971
|
+
}
|
|
972
|
+
function validateReferenceImages(prompt, urls) {
|
|
973
|
+
urls.forEach((url, index) => {
|
|
974
|
+
if (typeof url !== "string") {
|
|
975
|
+
throw new ValidationError(`reference_image_urls[${index}] must be a string`);
|
|
976
|
+
}
|
|
977
|
+
if (!isPublicHttpUrl(url)) {
|
|
978
|
+
throw new ValidationError(
|
|
979
|
+
`reference_image_urls[${index}] must be a public HTTP or HTTPS URL`
|
|
980
|
+
);
|
|
981
|
+
}
|
|
982
|
+
if (!IMAGE_EXTENSIONS.has(urlExtension(url))) {
|
|
983
|
+
throw new ValidationError(
|
|
984
|
+
`reference_image_urls[${index}] must use a JPG, JPEG, or PNG URL`
|
|
985
|
+
);
|
|
986
|
+
}
|
|
987
|
+
const marker = `<<<image_${index + 1}>>>`;
|
|
988
|
+
if (!prompt.includes(marker)) {
|
|
989
|
+
throw new ValidationError(
|
|
990
|
+
`prompt must reference reference_image_urls[${index}] as ${marker}`
|
|
991
|
+
);
|
|
992
|
+
}
|
|
993
|
+
});
|
|
994
|
+
for (const match of prompt.matchAll(/<<<image_(\d+)>>>/g)) {
|
|
995
|
+
const index = Number(match[1]);
|
|
996
|
+
if (index < 1 || index > urls.length) {
|
|
997
|
+
throw new ValidationError(`prompt references missing image_${index}`);
|
|
998
|
+
}
|
|
999
|
+
}
|
|
1000
|
+
}
|
|
1001
|
+
function validateReferenceVideo(body, prompt, referenceVideoUrl) {
|
|
1002
|
+
if (!referenceVideoUrl) {
|
|
1003
|
+
if ("reference_video_type" in body) {
|
|
1004
|
+
throw new ValidationError("reference_video_type requires reference_video_url");
|
|
1005
|
+
}
|
|
1006
|
+
if ("preserve_reference_video_audio" in body) {
|
|
1007
|
+
throw new ValidationError("preserve_reference_video_audio requires reference_video_url");
|
|
1008
|
+
}
|
|
1009
|
+
const missingMarker = prompt.match(/<<<video_([^>]+)>>>/);
|
|
1010
|
+
if (missingMarker) {
|
|
1011
|
+
throw new ValidationError(`prompt references missing video_${missingMarker[1]}`);
|
|
1012
|
+
}
|
|
1013
|
+
return;
|
|
1014
|
+
}
|
|
1015
|
+
if (!isPublicHttpUrl(referenceVideoUrl)) {
|
|
1016
|
+
throw new ValidationError("reference_video_url must be a public HTTP or HTTPS URL");
|
|
1017
|
+
}
|
|
1018
|
+
if (!VIDEO_EXTENSIONS.has(urlExtension(referenceVideoUrl))) {
|
|
1019
|
+
throw new ValidationError("reference_video_url must use an MP4 or MOV URL");
|
|
1020
|
+
}
|
|
1021
|
+
if (!prompt.includes("<<<video_1>>>")) {
|
|
1022
|
+
throw new ValidationError("prompt must reference reference_video_url as <<<video_1>>>");
|
|
1023
|
+
}
|
|
1024
|
+
for (const match of prompt.matchAll(/<<<video_([^>]+)>>>/g)) {
|
|
1025
|
+
if (match[1] !== "1") {
|
|
1026
|
+
throw new ValidationError("prompt may only reference video_1");
|
|
1027
|
+
}
|
|
1028
|
+
}
|
|
1029
|
+
const referenceVideoType = body.reference_video_type ?? "base";
|
|
1030
|
+
if (referenceVideoType === "base" && (present(body.first_frame_image_url) || present(body.last_frame_image_url))) {
|
|
1031
|
+
throw new ValidationError(
|
|
1032
|
+
"reference_video_type base cannot be combined with first_frame_image_url or last_frame_image_url"
|
|
1033
|
+
);
|
|
1034
|
+
}
|
|
1035
|
+
}
|
|
1036
|
+
function present(value) {
|
|
1037
|
+
return typeof value === "string" ? value.trim().length > 0 : value !== void 0 && value !== null;
|
|
1038
|
+
}
|
|
1039
|
+
function urlExtension(value) {
|
|
1040
|
+
try {
|
|
1041
|
+
const path = new URL(value).pathname;
|
|
1042
|
+
const dot = path.lastIndexOf(".");
|
|
1043
|
+
return dot >= 0 ? path.slice(dot).toLowerCase() : "";
|
|
1044
|
+
} catch {
|
|
1045
|
+
return "";
|
|
1046
|
+
}
|
|
1047
|
+
}
|
|
1048
|
+
function isPublicHttpUrl(value) {
|
|
1049
|
+
try {
|
|
1050
|
+
const url = new URL(value);
|
|
1051
|
+
return (url.protocol === "http:" || url.protocol === "https:") && url.hostname.length > 0 && url.username.length === 0 && url.password.length === 0 && !isBlockedHost(url.hostname);
|
|
1052
|
+
} catch {
|
|
1053
|
+
return false;
|
|
1054
|
+
}
|
|
1055
|
+
}
|
|
1056
|
+
function isBlockedHost(hostname) {
|
|
1057
|
+
const host = hostname.toLowerCase().replace(/^\[|\]$/g, "").replace(/\.$/, "");
|
|
1058
|
+
if (host === "localhost" || host.endsWith(".localhost")) return true;
|
|
1059
|
+
const parsed = parseIpLiteral(host);
|
|
1060
|
+
if (!parsed) return false;
|
|
1061
|
+
return BLOCKED_IP_NETWORKS.some((network) => {
|
|
1062
|
+
if (network.bits !== parsed.bits) return false;
|
|
1063
|
+
const shift = BigInt(parsed.bits - network.prefix);
|
|
1064
|
+
return parsed.value >> shift === network.value >> shift;
|
|
1065
|
+
});
|
|
1066
|
+
}
|
|
1067
|
+
function parseIpLiteral(value) {
|
|
1068
|
+
const ipv4 = parseIpv4(value);
|
|
1069
|
+
if (ipv4 !== void 0) return { bits: 32, value: ipv4 };
|
|
1070
|
+
if (!value.includes(":")) return void 0;
|
|
1071
|
+
const halves = value.toLowerCase().split("::");
|
|
1072
|
+
if (halves.length > 2) return void 0;
|
|
1073
|
+
const head = parseIpv6Half(halves[0]);
|
|
1074
|
+
const tail = parseIpv6Half(halves[1] ?? "");
|
|
1075
|
+
if (!head || !tail) return void 0;
|
|
1076
|
+
const compressed = halves.length === 2;
|
|
1077
|
+
const missing = 8 - head.length - tail.length;
|
|
1078
|
+
if (!compressed && missing !== 0 || compressed && missing < 1) return void 0;
|
|
1079
|
+
const segments = [...head, ...Array(missing).fill(0), ...tail];
|
|
1080
|
+
const address = segments.reduce((result, segment) => result << 16n | BigInt(segment), 0n);
|
|
1081
|
+
if (address >> 32n === 0xffffn) {
|
|
1082
|
+
return { bits: 32, value: address & 0xffffffffn };
|
|
1083
|
+
}
|
|
1084
|
+
return { bits: 128, value: address };
|
|
1085
|
+
}
|
|
1086
|
+
function parseIpv4(value) {
|
|
1087
|
+
const parts = value.split(".");
|
|
1088
|
+
if (parts.length !== 4 || parts.some((part) => !/^\d+$/.test(part))) return void 0;
|
|
1089
|
+
const octets = parts.map(Number);
|
|
1090
|
+
if (octets.some((octet) => octet < 0 || octet > 255)) return void 0;
|
|
1091
|
+
return octets.reduce((result, octet) => result << 8n | BigInt(octet), 0n);
|
|
1092
|
+
}
|
|
1093
|
+
function parseIpv6Half(value) {
|
|
1094
|
+
if (value === "") return [];
|
|
1095
|
+
const parts = value.split(":");
|
|
1096
|
+
if (parts.some((part) => !/^[0-9a-f]{1,4}$/.test(part))) return void 0;
|
|
1097
|
+
return parts.map((part) => Number.parseInt(part, 16));
|
|
1098
|
+
}
|
|
1099
|
+
|
|
713
1100
|
// src/resources/text-to-video.ts
|
|
714
1101
|
var ENDPOINT = "/api/v1/kling/text_to_video";
|
|
715
1102
|
var V26_MODEL = "kling-v2.6";
|
|
@@ -754,6 +1141,7 @@ var TextToVideo = class {
|
|
|
754
1141
|
rejectUnsupportedV3TurboFields(body);
|
|
755
1142
|
validateParams(contract["text-to-video"], body);
|
|
756
1143
|
validateV26Params(body);
|
|
1144
|
+
validateKlingO1References(body);
|
|
757
1145
|
return this.http.request("POST", ENDPOINT, {
|
|
758
1146
|
body,
|
|
759
1147
|
...options
|
|
@@ -774,14 +1162,14 @@ var TextToVideo = class {
|
|
|
774
1162
|
function validateV26Params(body) {
|
|
775
1163
|
if (body.model !== V26_MODEL) return;
|
|
776
1164
|
if (body.enable_sound === true && body.mode !== "pro") {
|
|
777
|
-
throw new
|
|
1165
|
+
throw new ValidationError2(`enable_sound requires mode pro for ${V26_MODEL}`);
|
|
778
1166
|
}
|
|
779
1167
|
}
|
|
780
1168
|
function rejectUnsupportedV3TurboFields(body) {
|
|
781
1169
|
if (body.model !== V3_TURBO_MODEL) return;
|
|
782
1170
|
const field = V3_TURBO_UNSUPPORTED_FIELDS.find((candidate) => fieldPresent(body, candidate));
|
|
783
1171
|
if (field) {
|
|
784
|
-
throw new
|
|
1172
|
+
throw new ValidationError2(`${field} is not supported by ${V3_TURBO_MODEL}`);
|
|
785
1173
|
}
|
|
786
1174
|
}
|
|
787
1175
|
function fieldPresent(params, field) {
|
|
@@ -801,7 +1189,7 @@ function presentValue(value) {
|
|
|
801
1189
|
}
|
|
802
1190
|
|
|
803
1191
|
// src/resources/image-to-video.ts
|
|
804
|
-
import { ValidationError as
|
|
1192
|
+
import { ValidationError as ValidationError3, compactParams as compactParams2, validateParams as validateParams2 } from "@runapi.ai/core";
|
|
805
1193
|
import { pollUntilComplete as pollUntilComplete2 } from "@runapi.ai/core/internal";
|
|
806
1194
|
var ENDPOINT2 = "/api/v1/kling/image_to_video";
|
|
807
1195
|
var V26_MODEL2 = "kling-v2.6";
|
|
@@ -844,6 +1232,7 @@ var ImageToVideo = class {
|
|
|
844
1232
|
validateParams2(contract["image-to-video"], body);
|
|
845
1233
|
validateV26Params2(body);
|
|
846
1234
|
validateV3OmniFields(body);
|
|
1235
|
+
validateKlingO1References(body);
|
|
847
1236
|
return this.http.request("POST", ENDPOINT2, {
|
|
848
1237
|
body,
|
|
849
1238
|
...options
|
|
@@ -864,27 +1253,27 @@ var ImageToVideo = class {
|
|
|
864
1253
|
function validateV26Params2(body) {
|
|
865
1254
|
if (body.model !== V26_MODEL2) return;
|
|
866
1255
|
if (body.enable_sound === true && body.mode !== "pro") {
|
|
867
|
-
throw new
|
|
1256
|
+
throw new ValidationError3(`enable_sound requires mode pro for ${V26_MODEL2}`);
|
|
868
1257
|
}
|
|
869
1258
|
if (!fieldPresent2(body, "last_frame_image_url")) return;
|
|
870
1259
|
if (body.mode !== "pro") {
|
|
871
|
-
throw new
|
|
1260
|
+
throw new ValidationError3(`last_frame_image_url requires mode pro for ${V26_MODEL2}`);
|
|
872
1261
|
}
|
|
873
1262
|
if (body.duration_seconds !== void 0 && body.duration_seconds !== 5) {
|
|
874
|
-
throw new
|
|
1263
|
+
throw new ValidationError3(`last_frame_image_url requires duration_seconds 5 for ${V26_MODEL2}`);
|
|
875
1264
|
}
|
|
876
1265
|
}
|
|
877
1266
|
function validateV3OmniFields(body) {
|
|
878
1267
|
if (body.model !== V3_OMNI_MODEL || !fieldPresent2(body, "last_frame_image_url")) return;
|
|
879
1268
|
if ((body.duration_seconds ?? 5) !== 5) {
|
|
880
|
-
throw new
|
|
1269
|
+
throw new ValidationError3(`last_frame_image_url requires duration_seconds 5 for ${V3_OMNI_MODEL}`);
|
|
881
1270
|
}
|
|
882
1271
|
}
|
|
883
1272
|
function rejectUnsupportedV3TurboFields2(body) {
|
|
884
1273
|
if (body.model !== V3_TURBO_MODEL2) return;
|
|
885
1274
|
const field = V3_TURBO_UNSUPPORTED_FIELDS2.find((candidate) => fieldPresent2(body, candidate));
|
|
886
1275
|
if (field) {
|
|
887
|
-
throw new
|
|
1276
|
+
throw new ValidationError3(`${field} is not supported by ${V3_TURBO_MODEL2}`);
|
|
888
1277
|
}
|
|
889
1278
|
}
|
|
890
1279
|
function fieldPresent2(params, field) {
|
|
@@ -1056,7 +1445,7 @@ import {
|
|
|
1056
1445
|
AuthenticationError,
|
|
1057
1446
|
InsufficientCreditsError,
|
|
1058
1447
|
NotFoundError,
|
|
1059
|
-
ValidationError as
|
|
1448
|
+
ValidationError as ValidationError4,
|
|
1060
1449
|
RateLimitError,
|
|
1061
1450
|
ServiceUnavailableError,
|
|
1062
1451
|
NetworkError,
|
|
@@ -1076,6 +1465,6 @@ export {
|
|
|
1076
1465
|
TaskFailedError,
|
|
1077
1466
|
TaskTimeoutError,
|
|
1078
1467
|
TimeoutError,
|
|
1079
|
-
|
|
1468
|
+
ValidationError4 as ValidationError
|
|
1080
1469
|
};
|
|
1081
1470
|
//# sourceMappingURL=index.mjs.map
|