@shop-os/modelkit 0.15.0 → 0.16.0
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/CHANGELOG.md +30 -0
- package/README.md +29 -2
- package/dist/catalog.cjs +24 -24
- package/dist/catalog.cjs.map +1 -1
- package/dist/catalog.d.cts +30 -2
- package/dist/catalog.d.ts +30 -2
- package/dist/catalog.js +24 -24
- package/dist/catalog.js.map +1 -1
- package/dist/index.cjs +319 -110
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +92 -2
- package/dist/index.d.ts +92 -2
- package/dist/index.js +314 -110
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -35,6 +35,7 @@ __export(index_exports, {
|
|
|
35
35
|
ADAPTER_KEYS: () => ADAPTER_KEYS,
|
|
36
36
|
ARRAY_INPUT_SPEC_KEYS: () => ARRAY_INPUT_SPEC_KEYS,
|
|
37
37
|
AUDIO_INPUT_SPEC_KEYS: () => AUDIO_INPUT_SPEC_KEYS,
|
|
38
|
+
BYOK_PROVIDERS: () => BYOK_PROVIDERS,
|
|
38
39
|
Catalog: () => Catalog,
|
|
39
40
|
CatalogModelSchema: () => CatalogModelSchema,
|
|
40
41
|
CatalogModelSchemaBase: () => CatalogModelSchemaBase,
|
|
@@ -59,6 +60,7 @@ __export(index_exports, {
|
|
|
59
60
|
aiSdkTextAdapter: () => aiSdkTextAdapter,
|
|
60
61
|
arkAdapter: () => arkAdapter,
|
|
61
62
|
aspectRatioToSize: () => aspectRatioToSize,
|
|
63
|
+
byokProviderForModel: () => byokProviderForModel,
|
|
62
64
|
classifyHttpError: () => classifyHttpError,
|
|
63
65
|
compareCatalogOrder: () => compareCatalogOrder,
|
|
64
66
|
createDefaultModelKit: () => createDefaultModelKit,
|
|
@@ -86,6 +88,7 @@ __export(index_exports, {
|
|
|
86
88
|
isListed: () => isListed,
|
|
87
89
|
isListedOn: () => isListedOn,
|
|
88
90
|
isModelKitError: () => isModelKitError,
|
|
91
|
+
keyOverrideFor: () => keyOverrideFor,
|
|
89
92
|
keysFromEnv: () => keysFromEnv,
|
|
90
93
|
languageModel: () => languageModel,
|
|
91
94
|
liveCatalog: () => liveCatalog,
|
|
@@ -102,6 +105,7 @@ __export(index_exports, {
|
|
|
102
105
|
model3dSeedFits: () => model3dSeedFits,
|
|
103
106
|
model3dSkus: () => model3dSkus,
|
|
104
107
|
model3dTexture: () => model3dTexture,
|
|
108
|
+
modelsPoweredBy: () => modelsPoweredBy,
|
|
105
109
|
nearestAspectRatio: () => nearestAspectRatio,
|
|
106
110
|
normalizeExposure: () => normalizeExposure,
|
|
107
111
|
openaiImageAdapter: () => openaiImageAdapter,
|
|
@@ -132,6 +136,7 @@ __export(index_exports, {
|
|
|
132
136
|
streamObject: () => streamObject,
|
|
133
137
|
streamText: () => streamText,
|
|
134
138
|
takesTargetAspectRatio: () => takesTargetAspectRatio,
|
|
139
|
+
testProviderKey: () => testProviderKey,
|
|
135
140
|
textUsageEvent: () => textUsageEvent,
|
|
136
141
|
toGeneratedImage: () => toGeneratedImage,
|
|
137
142
|
validateInputSpec: () => validateInputSpec,
|
|
@@ -283,8 +288,8 @@ function normalizeExposure(value) {
|
|
|
283
288
|
if (value.every(
|
|
284
289
|
(entry) => SURFACES.includes(entry)
|
|
285
290
|
)) {
|
|
286
|
-
const
|
|
287
|
-
return SURFACES.filter((surface) =>
|
|
291
|
+
const present3 = new Set(value);
|
|
292
|
+
return SURFACES.filter((surface) => present3.has(surface));
|
|
288
293
|
}
|
|
289
294
|
return value;
|
|
290
295
|
}
|
|
@@ -704,7 +709,7 @@ var IMAGE_MODELS = [
|
|
|
704
709
|
// Cowork "auto" lets OpenAI pick the size; the canonical equivalent is adaptive.
|
|
705
710
|
id: "gpt-image-2",
|
|
706
711
|
aliases: [],
|
|
707
|
-
label: "GPT
|
|
712
|
+
label: "GPT Image 2",
|
|
708
713
|
type: "image",
|
|
709
714
|
adapter: "openai-image",
|
|
710
715
|
providerModelId: "gpt-image-2",
|
|
@@ -891,7 +896,7 @@ var IMAGE_MODELS = [
|
|
|
891
896
|
display: {
|
|
892
897
|
provider: "bytedance",
|
|
893
898
|
logo: "https://d31vvfpk2ppdyq.cloudfront.net/assets/image/3bba5d81-4e57-4e71-911b-cdfa05acca2c_compressed.png",
|
|
894
|
-
description: "ByteDance Seedream 5.0 Pro text-to-image and multi-reference image-to-image (up to 10 inputs) with region editing; outputs 1K
|
|
899
|
+
description: "ByteDance Seedream 5.0 Pro text-to-image and multi-reference image-to-image (up to 10 inputs) with region editing; outputs 1K or 2K."
|
|
895
900
|
}
|
|
896
901
|
},
|
|
897
902
|
{
|
|
@@ -934,7 +939,7 @@ var IMAGE_MODELS = [
|
|
|
934
939
|
{
|
|
935
940
|
id: "flux-2-pro",
|
|
936
941
|
aliases: [],
|
|
937
|
-
label: "
|
|
942
|
+
label: "FLUX 2 Pro",
|
|
938
943
|
type: "image",
|
|
939
944
|
adapter: "prodia",
|
|
940
945
|
providerModelId: "flux-2-pro",
|
|
@@ -955,7 +960,7 @@ var IMAGE_MODELS = [
|
|
|
955
960
|
display: {
|
|
956
961
|
provider: "black-forest-labs",
|
|
957
962
|
logo: "https://cdn.jsdelivr.net/npm/@lobehub/icons-static-png@1.97.0/light/flux.png",
|
|
958
|
-
description: "Black Forest Labs FLUX.2 [pro] text-to-image and multi-reference editing model
|
|
963
|
+
description: "Black Forest Labs FLUX.2 [pro] text-to-image and multi-reference editing model; takes a prompt and up to 8 input images and outputs 1K images."
|
|
959
964
|
}
|
|
960
965
|
},
|
|
961
966
|
{
|
|
@@ -1015,7 +1020,7 @@ var IMAGE_MODELS = [
|
|
|
1015
1020
|
// https://replicate.com/wan-video/wan-2.7-image-pro (input schema)
|
|
1016
1021
|
id: "wan-2.7-image-pro",
|
|
1017
1022
|
aliases: [],
|
|
1018
|
-
label: "
|
|
1023
|
+
label: "Wan 2.7 Image Pro",
|
|
1019
1024
|
type: "image",
|
|
1020
1025
|
adapter: "replicate",
|
|
1021
1026
|
providerModelId: "wan-video/wan-2.7-image-pro",
|
|
@@ -1339,7 +1344,7 @@ var SAM_3_IMAGE = {
|
|
|
1339
1344
|
display: {
|
|
1340
1345
|
provider: "meta",
|
|
1341
1346
|
logo: META_LOGO,
|
|
1342
|
-
description: "Meta SAM 3
|
|
1347
|
+
description: "Meta SAM 3; finds every object a prompt names in one image and returns a black-and-white mask for each."
|
|
1343
1348
|
}
|
|
1344
1349
|
};
|
|
1345
1350
|
var VEED_SUBTITLES = {
|
|
@@ -2181,7 +2186,7 @@ var FISH_MODELS = [
|
|
|
2181
2186
|
"fish-s2.1-pro-free",
|
|
2182
2187
|
"Fish Audio S2.1 Pro Free",
|
|
2183
2188
|
"s2.1-pro-free",
|
|
2184
|
-
"Fish Audio S2.1 Pro
|
|
2189
|
+
"Fish Audio S2.1 Pro text to speech, with the same voices as S2.1 Pro."
|
|
2185
2190
|
),
|
|
2186
2191
|
fishTts(
|
|
2187
2192
|
"fish-drama-3",
|
|
@@ -3919,7 +3924,7 @@ var MEDIA_NODE_MODELS = [
|
|
|
3919
3924
|
formats: false,
|
|
3920
3925
|
// fal's schema states no limit; ElevenLabs documents 10,000 characters per request.
|
|
3921
3926
|
maxChars: 1e4,
|
|
3922
|
-
description: "ElevenLabs Multilingual v2 text to speech in 29 languages
|
|
3927
|
+
description: "ElevenLabs Multilingual v2 text to speech in 29 languages."
|
|
3923
3928
|
}),
|
|
3924
3929
|
geminiTts(
|
|
3925
3930
|
"gemini-3.8-flash-tts",
|
|
@@ -4015,7 +4020,7 @@ var MEDIA_NODE_MODELS = [
|
|
|
4015
4020
|
"Sync Lipsync 2",
|
|
4016
4021
|
"fal-ai/sync-lipsync/v2",
|
|
4017
4022
|
"lipsync-2",
|
|
4018
|
-
"Sync Lipsync 2 re-times the mouth in a video to new speech
|
|
4023
|
+
"Sync Lipsync 2 re-times the mouth in a video to new speech."
|
|
4019
4024
|
),
|
|
4020
4025
|
syncLipsync(
|
|
4021
4026
|
"lipsync-2-pro",
|
|
@@ -4053,7 +4058,7 @@ var MEDIA_NODE_MODELS = [
|
|
|
4053
4058
|
display: {
|
|
4054
4059
|
provider: "veed",
|
|
4055
4060
|
logo: "https://d31vvfpk2ppdyq.cloudfront.net/assets/image/d540d2bb-0022-4371-8889-48aefaf46bbe.png",
|
|
4056
|
-
description: "VEED Lipsync v2 re-times the mouth in a video to a new audio track
|
|
4061
|
+
description: "VEED Lipsync v2 re-times the mouth in a video to a new audio track."
|
|
4057
4062
|
},
|
|
4058
4063
|
capabilities: { acceptsSourceVideo: true }
|
|
4059
4064
|
},
|
|
@@ -4398,7 +4403,7 @@ var OTHER_MODELS = [
|
|
|
4398
4403
|
pricingKind: "flat",
|
|
4399
4404
|
display: {
|
|
4400
4405
|
provider: "mmaudio",
|
|
4401
|
-
description: "MMAudio V2 video-to-audio model
|
|
4406
|
+
description: "MMAudio V2 video-to-audio model; takes a source video and a prompt and synthesizes synchronized environmental, action, and speech-like audio."
|
|
4402
4407
|
},
|
|
4403
4408
|
capabilities: {}
|
|
4404
4409
|
},
|
|
@@ -4608,7 +4613,7 @@ var OTHER_MODELS = [
|
|
|
4608
4613
|
display: {
|
|
4609
4614
|
provider: "topaz",
|
|
4610
4615
|
logo: "https://cdn.jsdelivr.net/npm/@lobehub/icons-static-png@1.97.0/light/topazlabs.png",
|
|
4611
|
-
description: "Topaz Labs AI image upscaling
|
|
4616
|
+
description: "Topaz Labs AI image upscaling; takes one input image and upscales up to 6x with selectable enhancement models and optional face enhancement."
|
|
4612
4617
|
}
|
|
4613
4618
|
},
|
|
4614
4619
|
{
|
|
@@ -4634,7 +4639,7 @@ var OTHER_MODELS = [
|
|
|
4634
4639
|
display: {
|
|
4635
4640
|
provider: "bytedance",
|
|
4636
4641
|
logo: "https://d31vvfpk2ppdyq.cloudfront.net/assets/image/3bba5d81-4e57-4e71-911b-cdfa05acca2c_compressed.png",
|
|
4637
|
-
description: "ByteDance SeedVR2 one-step image upscaling and restoration
|
|
4642
|
+
description: "ByteDance SeedVR2 one-step image upscaling and restoration; takes one input image and upscales it 2x or 4x with sharp, faithful detail."
|
|
4638
4643
|
}
|
|
4639
4644
|
},
|
|
4640
4645
|
{
|
|
@@ -4658,7 +4663,7 @@ var OTHER_MODELS = [
|
|
|
4658
4663
|
pricingKind: "flat",
|
|
4659
4664
|
display: {
|
|
4660
4665
|
provider: "prodia",
|
|
4661
|
-
description: "
|
|
4666
|
+
description: "Background removal; takes one input image and returns a PNG cut-out of the subject plus an optional black-and-white mask."
|
|
4662
4667
|
}
|
|
4663
4668
|
}
|
|
4664
4669
|
];
|
|
@@ -5357,7 +5362,7 @@ var VIDEO_FAMILY_MODELS = [
|
|
|
5357
5362
|
display: {
|
|
5358
5363
|
provider: "kuaishou",
|
|
5359
5364
|
logo: KLING_LOGO,
|
|
5360
|
-
description: "Kuaishou Kling 4.0: text-to-video, start/end frames, or reference-to-video from up to 10 images and 5 videos (30 seconds combined),
|
|
5365
|
+
description: "Kuaishou Kling 4.0: text-to-video, start/end frames, or reference-to-video from up to 10 images and 5 videos (30 seconds combined), up to 30 seconds at 720p or 1080p. Prompts name references @Image1, @Video1."
|
|
5361
5366
|
},
|
|
5362
5367
|
capabilities: { lastFrameRequiresFirstFrame: true }
|
|
5363
5368
|
},
|
|
@@ -5702,7 +5707,7 @@ var VIDEO_FAMILY_MODELS = [
|
|
|
5702
5707
|
display: {
|
|
5703
5708
|
provider: "xai",
|
|
5704
5709
|
logo: XAI_LOGO,
|
|
5705
|
-
description: "xAI Grok Imagine 1.5: text- and image-to-video at native 1080p with lip-synced audio, or up to 14 reference images and pinned first and last frames at 720p,
|
|
5710
|
+
description: "xAI Grok Imagine 1.5: text- and image-to-video at native 1080p with lip-synced audio, or up to 14 reference images and pinned first and last frames at 720p, up to 15 seconds."
|
|
5706
5711
|
},
|
|
5707
5712
|
capabilities: {}
|
|
5708
5713
|
}
|
|
@@ -6059,7 +6064,7 @@ var VIDEO_MODELS = [
|
|
|
6059
6064
|
pricingKind: "video_per_second",
|
|
6060
6065
|
display: {
|
|
6061
6066
|
provider: "bytedance",
|
|
6062
|
-
description: "High-quality
|
|
6067
|
+
description: "High-quality ByteDance video generation guided by reference images, for clips up to 15 seconds.",
|
|
6063
6068
|
logo: BYTEDANCE_LOGO2
|
|
6064
6069
|
},
|
|
6065
6070
|
capabilities: { acceptsSourceVideo: true, videoEdit: false, ...FRAMES_EXCLUDE_REFERENCES }
|
|
@@ -6183,7 +6188,7 @@ var VIDEO_MODELS = [
|
|
|
6183
6188
|
pricingKind: "video_per_second",
|
|
6184
6189
|
display: {
|
|
6185
6190
|
provider: "xai",
|
|
6186
|
-
description: "xAI's reference-to-video model. Generates short clips conditioned on up to
|
|
6191
|
+
description: "xAI's reference-to-video model. Generates short clips conditioned on up to 7 reference images with flexible aspect ratios.",
|
|
6187
6192
|
logo: "https://d31vvfpk2ppdyq.cloudfront.net/assets/image/858b7fcc-9bd5-411d-aea1-a7b35ecfffab_compressed.png"
|
|
6188
6193
|
},
|
|
6189
6194
|
capabilities: { ...FRAMES_EXCLUDE_REFERENCES }
|
|
@@ -6267,7 +6272,7 @@ var VIDEO_MODELS = [
|
|
|
6267
6272
|
exposure: ["cowork", "space_builder"],
|
|
6268
6273
|
constraints: {
|
|
6269
6274
|
aspectRatios: [...KLING_OMNI_RATIOS],
|
|
6270
|
-
resolutions: ["720p", "1080p"
|
|
6275
|
+
resolutions: ["720p", "1080p"],
|
|
6271
6276
|
durations: { min: 3, max: 15 },
|
|
6272
6277
|
references: { images: 7, videos: 0, audios: 0 },
|
|
6273
6278
|
supports: ["generateAudio", "lastFrame"],
|
|
@@ -6280,7 +6285,7 @@ var VIDEO_MODELS = [
|
|
|
6280
6285
|
display: {
|
|
6281
6286
|
provider: "kuaishou",
|
|
6282
6287
|
logo: "https://cdn.jsdelivr.net/npm/@lobehub/icons-static-png@1.97.0/light/kling-color.png",
|
|
6283
|
-
description: "Kuaishou Kling Video 3.0 Omni generation from text, start/end images and up to 7 reference images, with optional native audio; up to 15 seconds at up to
|
|
6288
|
+
description: "Kuaishou Kling Video 3.0 Omni generation from text, start/end images and up to 7 reference images, with optional native audio; up to 15 seconds at up to 1080p."
|
|
6284
6289
|
}
|
|
6285
6290
|
// No lastFrameRequiresFirstFrame: fal image-to-video needs a start frame, so the adapter
|
|
6286
6291
|
// sends a lone end frame as the start frame, as the Replicate model took it.
|
|
@@ -6315,7 +6320,7 @@ var VIDEO_MODELS = [
|
|
|
6315
6320
|
display: {
|
|
6316
6321
|
provider: "minimax",
|
|
6317
6322
|
logo: "https://d31vvfpk2ppdyq.cloudfront.net/assets/image/f4c2e906-28b7-4a4a-b491-df8fef7808ed.png",
|
|
6318
|
-
description: "MiniMax H3 multimodal video model for text-to-video, image-to-video (first/last frame), and reference-to-video with native audio, up to
|
|
6323
|
+
description: "MiniMax H3 multimodal video model for text-to-video, image-to-video (first/last frame), and reference-to-video with native audio, up to 4K."
|
|
6319
6324
|
},
|
|
6320
6325
|
capabilities: { ...FRAMES_EXCLUDE_REFERENCES }
|
|
6321
6326
|
},
|
|
@@ -6435,7 +6440,7 @@ var VIDEO_MODELS = [
|
|
|
6435
6440
|
display: {
|
|
6436
6441
|
provider: "minimax",
|
|
6437
6442
|
logo: "https://d31vvfpk2ppdyq.cloudfront.net/assets/image/f4c2e906-28b7-4a4a-b491-df8fef7808ed.png",
|
|
6438
|
-
description: "MiniMax H3 Max reference-to-video
|
|
6443
|
+
description: "MiniMax H3 Max reference-to-video; conditions on reference images, videos, and audio."
|
|
6439
6444
|
},
|
|
6440
6445
|
// fal's reference-to-video endpoint never reads a frame; the resolver must drop the
|
|
6441
6446
|
// references instead of the adapter silently dropping the frame.
|
|
@@ -6479,7 +6484,7 @@ var VIDEO_MODELS = [
|
|
|
6479
6484
|
pricingKind: "video_per_second",
|
|
6480
6485
|
display: {
|
|
6481
6486
|
provider: "alibaba",
|
|
6482
|
-
description: "Alibaba Wan 3 video model for text-to-video, image-to-video (start/end frame), and reference-to-video from up to 10 images, 5 videos and 5 audio clips, with native audio;
|
|
6487
|
+
description: "Alibaba Wan 3 video model for text-to-video, image-to-video (start/end frame), and reference-to-video from up to 10 images, 5 videos and 5 audio clips, with native audio; up to 30 seconds at up to 1080p."
|
|
6483
6488
|
},
|
|
6484
6489
|
capabilities: { ...FRAMES_EXCLUDE_REFERENCES, lastFrameRequiresFirstFrame: true }
|
|
6485
6490
|
},
|
|
@@ -6521,7 +6526,7 @@ var VIDEO_MODELS = [
|
|
|
6521
6526
|
pricingKind: "video_per_second",
|
|
6522
6527
|
display: {
|
|
6523
6528
|
provider: "alibaba",
|
|
6524
|
-
description: "Alibaba Wan 3 Prime, the faster-generating tier of Wan 3, for text-to-video, image-to-video (start/end frame), and reference-to-video from up to 10 images, 5 videos and 5 audio clips, with native audio;
|
|
6529
|
+
description: "Alibaba Wan 3 Prime, the faster-generating tier of Wan 3, for text-to-video, image-to-video (start/end frame), and reference-to-video from up to 10 images, 5 videos and 5 audio clips, with native audio; up to 30 seconds at up to 1080p."
|
|
6525
6530
|
},
|
|
6526
6531
|
capabilities: { ...FRAMES_EXCLUDE_REFERENCES, lastFrameRequiresFirstFrame: true }
|
|
6527
6532
|
},
|
|
@@ -8589,9 +8594,6 @@ var aiSdkTextAdapter = {
|
|
|
8589
8594
|
// src/adapters/ark.ts
|
|
8590
8595
|
var import_zod7 = require("zod");
|
|
8591
8596
|
|
|
8592
|
-
// src/retry.ts
|
|
8593
|
-
var import_zod6 = require("zod");
|
|
8594
|
-
|
|
8595
8597
|
// src/json.ts
|
|
8596
8598
|
var import_zod5 = require("zod");
|
|
8597
8599
|
var JsonValueSchema = import_zod5.z.lazy(
|
|
@@ -8628,6 +8630,7 @@ function describeThrown(cause) {
|
|
|
8628
8630
|
}
|
|
8629
8631
|
|
|
8630
8632
|
// src/retry.ts
|
|
8633
|
+
var import_zod6 = require("zod");
|
|
8631
8634
|
var textBody = import_zod6.z.string();
|
|
8632
8635
|
var BILLING_CODES = /* @__PURE__ */ new Set([
|
|
8633
8636
|
"insufficient_quota",
|
|
@@ -8924,10 +8927,36 @@ function arkKey(ctx) {
|
|
|
8924
8927
|
}
|
|
8925
8928
|
return key;
|
|
8926
8929
|
}
|
|
8927
|
-
|
|
8930
|
+
var ARK_CODES = /* @__PURE__ */ new Map([
|
|
8931
|
+
["AccountOverdueError", { status: 403, code: "provider_billing" }],
|
|
8932
|
+
["OperationDenied.ServiceOverdue", { status: 403, code: "provider_billing" }],
|
|
8933
|
+
["QuotaExceeded", { status: 429, code: "provider_billing" }],
|
|
8934
|
+
["ModelNotOpen", { status: 404, code: "provider_rejected" }],
|
|
8935
|
+
["InvalidEndpointOrModel.NotFound", { status: 404, code: "provider_rejected" }]
|
|
8936
|
+
]);
|
|
8937
|
+
var ArkErrorBodySchema = import_zod7.z.object({ error: import_zod7.z.object({ code: import_zod7.z.string() }) });
|
|
8938
|
+
function arkErrorCode(body) {
|
|
8939
|
+
const text2 = import_zod7.z.string().safeParse(body);
|
|
8940
|
+
let decoded = body;
|
|
8941
|
+
if (text2.success) {
|
|
8942
|
+
try {
|
|
8943
|
+
decoded = JsonValueSchema.parse(JSON.parse(text2.data));
|
|
8944
|
+
} catch {
|
|
8945
|
+
return void 0;
|
|
8946
|
+
}
|
|
8947
|
+
}
|
|
8948
|
+
const parsed = ArkErrorBodySchema.safeParse(decoded);
|
|
8949
|
+
return parsed.success ? parsed.data.error.code : void 0;
|
|
8950
|
+
}
|
|
8951
|
+
function arkCodeRule(status, code) {
|
|
8952
|
+
const rule = code === void 0 ? void 0 : ARK_CODES.get(code);
|
|
8953
|
+
if (!rule || status !== void 0 && status !== rule.status) return void 0;
|
|
8954
|
+
return rule;
|
|
8955
|
+
}
|
|
8956
|
+
function throwArkError(status, body, model, code = arkErrorCode(body)) {
|
|
8928
8957
|
const parsed = import_zod7.z.string().safeParse(body);
|
|
8929
8958
|
const text2 = parsed.success ? parsed.data : JSON.stringify(body ?? "");
|
|
8930
|
-
if (/sensitive.?content|human.?face/i.test(text2)) {
|
|
8959
|
+
if (/sensitive.?content|human.?face/i.test(`${code ?? ""} ${text2}`)) {
|
|
8931
8960
|
const init = {
|
|
8932
8961
|
code: "content_blocked",
|
|
8933
8962
|
message: `ark rejected the request: ${text2.slice(0, 500)}`,
|
|
@@ -8939,15 +8968,18 @@ function throwArkError(status, body, model) {
|
|
|
8939
8968
|
if (status !== void 0) init.status = status;
|
|
8940
8969
|
throw new ModelKitError(init);
|
|
8941
8970
|
}
|
|
8942
|
-
|
|
8943
|
-
|
|
8944
|
-
|
|
8945
|
-
|
|
8971
|
+
const rule = arkCodeRule(status, code);
|
|
8972
|
+
if (rule || status === void 0) {
|
|
8973
|
+
const init = {
|
|
8974
|
+
code: rule?.code ?? "provider_rejected",
|
|
8975
|
+
message: `ark rejected the request${code ? ` (${code})` : ""}: ${text2.slice(0, 500)}`,
|
|
8946
8976
|
provider: "ark",
|
|
8947
8977
|
model,
|
|
8948
8978
|
body,
|
|
8949
8979
|
retryable: false
|
|
8950
|
-
}
|
|
8980
|
+
};
|
|
8981
|
+
if (status !== void 0) init.status = status;
|
|
8982
|
+
throw new ModelKitError(init);
|
|
8951
8983
|
}
|
|
8952
8984
|
throw classifyHttpError(status, body, "ark", model);
|
|
8953
8985
|
}
|
|
@@ -9063,9 +9095,15 @@ var SeedanceResponseSchema = import_zod7.z.object({
|
|
|
9063
9095
|
duration: import_zod7.z.number().optional(),
|
|
9064
9096
|
framespersecond: import_zod7.z.number().optional(),
|
|
9065
9097
|
resolution: import_zod7.z.string().optional(),
|
|
9066
|
-
error: import_zod7.z.union([
|
|
9098
|
+
error: import_zod7.z.union([
|
|
9099
|
+
import_zod7.z.string(),
|
|
9100
|
+
import_zod7.z.object({ code: import_zod7.z.string().optional(), message: import_zod7.z.string().optional() })
|
|
9101
|
+
]).optional()
|
|
9102
|
+
});
|
|
9103
|
+
var SeedanceErrorSchema = import_zod7.z.object({
|
|
9104
|
+
code: import_zod7.z.string().optional(),
|
|
9105
|
+
message: import_zod7.z.string().optional()
|
|
9067
9106
|
});
|
|
9068
|
-
var SeedanceErrorMessageSchema = import_zod7.z.object({ message: import_zod7.z.string().optional() });
|
|
9069
9107
|
function seedanceResolution(req) {
|
|
9070
9108
|
return req.resolution ?? "720p";
|
|
9071
9109
|
}
|
|
@@ -9086,10 +9124,14 @@ function seedanceInitialDuration(req) {
|
|
|
9086
9124
|
function seedanceErrorMessage(error, status) {
|
|
9087
9125
|
const asString = import_zod7.z.string().safeParse(error);
|
|
9088
9126
|
if (asString.success) return asString.data;
|
|
9089
|
-
const asObject =
|
|
9127
|
+
const asObject = SeedanceErrorSchema.safeParse(error);
|
|
9090
9128
|
if (asObject.success && asObject.data.message !== void 0) return asObject.data.message;
|
|
9091
9129
|
return `Seedance task ${status}`;
|
|
9092
9130
|
}
|
|
9131
|
+
function seedanceErrorCode(error) {
|
|
9132
|
+
const parsed = SeedanceErrorSchema.safeParse(error);
|
|
9133
|
+
return parsed.success ? parsed.data.code : void 0;
|
|
9134
|
+
}
|
|
9093
9135
|
function seedanceJob(ctx, key, jobId, usage5) {
|
|
9094
9136
|
const modelId = ctx.model.id;
|
|
9095
9137
|
const fetchStatus = async () => {
|
|
@@ -9097,9 +9139,9 @@ function seedanceJob(ctx, key, jobId, usage5) {
|
|
|
9097
9139
|
headers: { Authorization: `Bearer ${key}` }
|
|
9098
9140
|
});
|
|
9099
9141
|
if (!res.ok) {
|
|
9100
|
-
if (ctx.call.maxRetries !== 0 && (res.status === 429 || res.status >= 500))
|
|
9101
|
-
return void 0;
|
|
9102
9142
|
const text2 = await res.text().catch(() => "");
|
|
9143
|
+
const transient = (res.status === 429 || res.status >= 500) && !arkCodeRule(res.status, arkErrorCode(text2));
|
|
9144
|
+
if (ctx.call.maxRetries !== 0 && transient) return void 0;
|
|
9103
9145
|
throwArkError(res.status, text2, modelId);
|
|
9104
9146
|
}
|
|
9105
9147
|
const parsed = SeedanceResponseSchema.safeParse(await res.json());
|
|
@@ -9159,7 +9201,12 @@ function seedanceJob(ctx, key, jobId, usage5) {
|
|
|
9159
9201
|
};
|
|
9160
9202
|
}
|
|
9161
9203
|
if (status === "failed" || status === "expired" || status === "cancelled") {
|
|
9162
|
-
throwArkError(
|
|
9204
|
+
throwArkError(
|
|
9205
|
+
void 0,
|
|
9206
|
+
seedanceErrorMessage(polled.error, status),
|
|
9207
|
+
modelId,
|
|
9208
|
+
seedanceErrorCode(polled.error)
|
|
9209
|
+
);
|
|
9163
9210
|
}
|
|
9164
9211
|
return void 0;
|
|
9165
9212
|
}, pollOpts);
|
|
@@ -10942,8 +10989,8 @@ function falMediaError(row2, message, code) {
|
|
|
10942
10989
|
retryable: false
|
|
10943
10990
|
});
|
|
10944
10991
|
}
|
|
10945
|
-
function refuseMedia(row2,
|
|
10946
|
-
const extra = Object.entries(
|
|
10992
|
+
function refuseMedia(row2, present3) {
|
|
10993
|
+
const extra = Object.entries(present3).find(([, set]) => set);
|
|
10947
10994
|
if (extra) throw falMediaError(row2, `does not take ${extra[0]}`, "unsupported_option");
|
|
10948
10995
|
}
|
|
10949
10996
|
function setIf(input, key, value) {
|
|
@@ -18094,16 +18141,16 @@ function resolveVideoOptions(model, request, onUnsupported = "error") {
|
|
|
18094
18141
|
}
|
|
18095
18142
|
function checkVideoRequired(model, req) {
|
|
18096
18143
|
const c = model.constraints;
|
|
18097
|
-
const
|
|
18144
|
+
const present3 = (input) => input === "references" ? compact(req.referenceImages).length + compact(req.referenceVideos).length + compact(req.referenceAudios).length > 0 : input !== "sourceAudio" && req[input] !== void 0;
|
|
18098
18145
|
for (const input of c.requires ?? []) {
|
|
18099
|
-
if (!
|
|
18146
|
+
if (!present3(input))
|
|
18100
18147
|
throw new ModelKitError({
|
|
18101
18148
|
code: "missing_input",
|
|
18102
18149
|
message: `${model.id} requires ${input}`,
|
|
18103
18150
|
model: model.id
|
|
18104
18151
|
});
|
|
18105
18152
|
}
|
|
18106
|
-
if (c.requiresOneOf && !c.requiresOneOf.some(
|
|
18153
|
+
if (c.requiresOneOf && !c.requiresOneOf.some(present3)) {
|
|
18107
18154
|
throw new ModelKitError({
|
|
18108
18155
|
code: "missing_input",
|
|
18109
18156
|
message: `${model.id} requires one of: ${c.requiresOneOf.join(", ")}`,
|
|
@@ -18151,8 +18198,8 @@ function resolveAudioOptions(model, request, onUnsupported = "error") {
|
|
|
18151
18198
|
if (references.length > 0) merged.references = references;
|
|
18152
18199
|
else delete merged.references;
|
|
18153
18200
|
for (const input of c.requires ?? []) {
|
|
18154
|
-
const
|
|
18155
|
-
if (!
|
|
18201
|
+
const present3 = input === "references" ? references.length > 0 : input === "sourceVideo" && merged.sourceVideo !== void 0;
|
|
18202
|
+
if (!present3)
|
|
18156
18203
|
throw new ModelKitError({
|
|
18157
18204
|
code: "missing_input",
|
|
18158
18205
|
message: `${model.id} requires ${input}`,
|
|
@@ -18206,12 +18253,12 @@ function unsupported3(model, message) {
|
|
|
18206
18253
|
model: model.id
|
|
18207
18254
|
});
|
|
18208
18255
|
}
|
|
18209
|
-
function checkRequired(model,
|
|
18256
|
+
function checkRequired(model, present3) {
|
|
18210
18257
|
for (const input of model.constraints.requires ?? []) {
|
|
18211
|
-
if (
|
|
18258
|
+
if (present3[input] !== true) throw missing2(model, input);
|
|
18212
18259
|
}
|
|
18213
18260
|
const oneOf = model.constraints.requiresOneOf;
|
|
18214
|
-
if (oneOf !== void 0 && !oneOf.some((input) =>
|
|
18261
|
+
if (oneOf !== void 0 && !oneOf.some((input) => present3[input] === true)) {
|
|
18215
18262
|
throw missing2(model, `one of ${oneOf.join(", ")}`);
|
|
18216
18263
|
}
|
|
18217
18264
|
}
|
|
@@ -18543,6 +18590,39 @@ function resolveKeys(config, names, tier = "pro") {
|
|
|
18543
18590
|
}
|
|
18544
18591
|
return config.keys.pro;
|
|
18545
18592
|
}
|
|
18593
|
+
function present2(value) {
|
|
18594
|
+
return value !== void 0 && value.trim() !== "";
|
|
18595
|
+
}
|
|
18596
|
+
function overrideHolds(override, name) {
|
|
18597
|
+
if (!override || name === "aws" || !present2(override[name])) return false;
|
|
18598
|
+
return name !== "higgsfield" || present2(override.higgsfieldSecret);
|
|
18599
|
+
}
|
|
18600
|
+
function overrideCovers(override, names) {
|
|
18601
|
+
return names.filter((name) => overrideHolds(override, name));
|
|
18602
|
+
}
|
|
18603
|
+
function resolveCallKeys(config, names, tier = "pro", override) {
|
|
18604
|
+
const covered = overrideCovers(override, names);
|
|
18605
|
+
const tierNames = names.filter((name) => !covered.includes(name));
|
|
18606
|
+
const base = resolveKeys(config, tierNames, tier);
|
|
18607
|
+
if (!override || covered.length === 0)
|
|
18608
|
+
return { keys: base, source: tierSource(config, tierNames, tier), tierNames };
|
|
18609
|
+
const keys = { ...base };
|
|
18610
|
+
for (const name of covered) {
|
|
18611
|
+
const value = name === "aws" ? void 0 : override[name];
|
|
18612
|
+
if (name === "aws" || !present2(value)) continue;
|
|
18613
|
+
keys[name] = value;
|
|
18614
|
+
if (name === "higgsfield" && present2(override.higgsfieldSecret))
|
|
18615
|
+
keys.higgsfieldSecret = override.higgsfieldSecret;
|
|
18616
|
+
}
|
|
18617
|
+
return { keys, source: "byok", tierNames };
|
|
18618
|
+
}
|
|
18619
|
+
function keySourceField(source2) {
|
|
18620
|
+
return source2 === void 0 ? {} : { keySource: source2 };
|
|
18621
|
+
}
|
|
18622
|
+
function tierSource(config, names, tier) {
|
|
18623
|
+
if (tier === "enterprise") return hasAll(config.keys.enterprise, names) ? "enterprise" : "pro";
|
|
18624
|
+
return tier;
|
|
18625
|
+
}
|
|
18546
18626
|
function keysFromEnv(env, prefix = "") {
|
|
18547
18627
|
const pick2 = (...names) => names.map((n) => env[`${prefix}${n}`]).find((v) => v && v.length > 0);
|
|
18548
18628
|
const keys = {};
|
|
@@ -18567,10 +18647,10 @@ function keysFromEnv(env, prefix = "") {
|
|
|
18567
18647
|
set("fish", pick2("FISH_AUDIO_API_KEY"));
|
|
18568
18648
|
set("elevenlabs", pick2("ELEVENLABS_API_KEY"));
|
|
18569
18649
|
set("cloudflare", pick2("CF_AIG_TOKEN"));
|
|
18570
|
-
const
|
|
18650
|
+
const bearer2 = pick2("AWS_BEARER_TOKEN_BEDROCK");
|
|
18571
18651
|
const accessKeyId = pick2("AWS_ACCESS_KEY_ID");
|
|
18572
18652
|
const secretAccessKey = pick2("AWS_SECRET_ACCESS_KEY");
|
|
18573
|
-
if (
|
|
18653
|
+
if (bearer2 || accessKeyId && secretAccessKey) {
|
|
18574
18654
|
const aws = {
|
|
18575
18655
|
region: env[`${prefix}BEDROCK_REGION`] || "us-east-1"
|
|
18576
18656
|
};
|
|
@@ -18580,12 +18660,101 @@ function keysFromEnv(env, prefix = "") {
|
|
|
18580
18660
|
}
|
|
18581
18661
|
const sessionToken = pick2("AWS_SESSION_TOKEN");
|
|
18582
18662
|
if (sessionToken) aws.sessionToken = sessionToken;
|
|
18583
|
-
if (
|
|
18663
|
+
if (bearer2) aws.apiKey = bearer2;
|
|
18584
18664
|
keys.aws = aws;
|
|
18585
18665
|
}
|
|
18586
18666
|
return keys;
|
|
18587
18667
|
}
|
|
18588
18668
|
|
|
18669
|
+
// src/byok.ts
|
|
18670
|
+
var API_KEY = { id: "apiKey", label: "API key", required: true, secret: true };
|
|
18671
|
+
var BYOK_PROVIDERS = {
|
|
18672
|
+
ark: {
|
|
18673
|
+
id: "ark",
|
|
18674
|
+
label: "BytePlus ModelArk",
|
|
18675
|
+
keyName: "ark",
|
|
18676
|
+
fields: [
|
|
18677
|
+
API_KEY,
|
|
18678
|
+
{ id: "accessKeyId", label: "Access key ID", required: false, secret: true },
|
|
18679
|
+
{ id: "secretAccessKey", label: "Secret access key", required: false, secret: true },
|
|
18680
|
+
{ id: "assetGroupId", label: "Asset group ID", required: false, secret: false }
|
|
18681
|
+
]
|
|
18682
|
+
},
|
|
18683
|
+
fal: { id: "fal", label: "fal", keyName: "fal", fields: [API_KEY] },
|
|
18684
|
+
replicate: { id: "replicate", label: "Replicate", keyName: "replicate", fields: [API_KEY] },
|
|
18685
|
+
openai: { id: "openai", label: "OpenAI", keyName: "openai", fields: [API_KEY] },
|
|
18686
|
+
google: { id: "google", label: "Google AI Studio", keyName: "google", fields: [API_KEY] }
|
|
18687
|
+
};
|
|
18688
|
+
var BY_KEY_NAME = new Map(
|
|
18689
|
+
Object.values(BYOK_PROVIDERS).map((provider) => [provider.keyName, provider.id])
|
|
18690
|
+
);
|
|
18691
|
+
function byokProviderForModel(model) {
|
|
18692
|
+
const names = model.adapter === "ai-sdk-text" ? [textKeyName(model)] : ADAPTER_KEYS[model.adapter];
|
|
18693
|
+
const [name, ...rest] = names;
|
|
18694
|
+
if (name === void 0 || rest.length > 0) return null;
|
|
18695
|
+
return BY_KEY_NAME.get(name) ?? null;
|
|
18696
|
+
}
|
|
18697
|
+
function modelsPoweredBy(provider, catalog) {
|
|
18698
|
+
return [...catalog].filter((model) => byokProviderForModel(model) === provider);
|
|
18699
|
+
}
|
|
18700
|
+
function keyOverrideFor(secrets) {
|
|
18701
|
+
const override = {};
|
|
18702
|
+
for (const provider of Object.values(BYOK_PROVIDERS)) {
|
|
18703
|
+
const apiKey = secrets[provider.id]?.apiKey?.trim();
|
|
18704
|
+
if (apiKey) override[provider.keyName] = apiKey;
|
|
18705
|
+
}
|
|
18706
|
+
return override;
|
|
18707
|
+
}
|
|
18708
|
+
var bearer = (apiKey) => ({ Authorization: `Bearer ${apiKey}` });
|
|
18709
|
+
var PROBES = {
|
|
18710
|
+
ark: {
|
|
18711
|
+
url: (endpoints) => `${endpoints.ark ?? ARK_BASE_URL}/contents/generations/tasks?page_num=1&page_size=1`,
|
|
18712
|
+
headers: bearer
|
|
18713
|
+
},
|
|
18714
|
+
fal: {
|
|
18715
|
+
url: () => "https://api.fal.ai/v1/assets/collections?limit=1",
|
|
18716
|
+
headers: (apiKey) => ({ Authorization: `Key ${apiKey}` }),
|
|
18717
|
+
unverifiableStatus: 403
|
|
18718
|
+
},
|
|
18719
|
+
replicate: {
|
|
18720
|
+
url: () => "https://api.replicate.com/v1/account",
|
|
18721
|
+
headers: bearer
|
|
18722
|
+
},
|
|
18723
|
+
openai: {
|
|
18724
|
+
url: () => "https://api.openai.com/v1/models",
|
|
18725
|
+
headers: bearer,
|
|
18726
|
+
unverifiableStatus: 403
|
|
18727
|
+
},
|
|
18728
|
+
google: {
|
|
18729
|
+
url: () => "https://generativelanguage.googleapis.com/v1beta/models?pageSize=1",
|
|
18730
|
+
headers: (apiKey) => ({ "x-goog-api-key": apiKey }),
|
|
18731
|
+
unverifiableStatus: 403
|
|
18732
|
+
}
|
|
18733
|
+
};
|
|
18734
|
+
async function testProviderKey(provider, secret, opts = {}) {
|
|
18735
|
+
const apiKey = secret.apiKey?.trim();
|
|
18736
|
+
if (!apiKey) return { ok: false, reason: "invalid" };
|
|
18737
|
+
const probe = PROBES[provider];
|
|
18738
|
+
const fetchImpl = opts.fetch ?? globalThis.fetch;
|
|
18739
|
+
let res;
|
|
18740
|
+
try {
|
|
18741
|
+
res = await fetchImpl(probe.url(opts.endpoints ?? {}), {
|
|
18742
|
+
method: "GET",
|
|
18743
|
+
headers: probe.headers(apiKey),
|
|
18744
|
+
...opts.signal !== void 0 && { signal: opts.signal }
|
|
18745
|
+
});
|
|
18746
|
+
} catch (cause) {
|
|
18747
|
+
if (opts.signal?.aborted) throw cause;
|
|
18748
|
+
return { ok: false, reason: "unreachable" };
|
|
18749
|
+
}
|
|
18750
|
+
await res.body?.cancel().catch(() => void 0);
|
|
18751
|
+
if (res.ok) return { ok: true, credit: "unknown" };
|
|
18752
|
+
if (res.status === probe.unverifiableStatus) return { ok: false, reason: "unverifiable" };
|
|
18753
|
+
if (res.status === 400 || res.status === 401) return { ok: false, reason: "invalid" };
|
|
18754
|
+
if (res.status === 402 || res.status === 403) return { ok: false, reason: "denied" };
|
|
18755
|
+
return { ok: false, reason: "unreachable" };
|
|
18756
|
+
}
|
|
18757
|
+
|
|
18589
18758
|
// src/text.ts
|
|
18590
18759
|
var import_ai4 = require("ai");
|
|
18591
18760
|
var import_zod33 = require("zod");
|
|
@@ -18676,12 +18845,10 @@ function createTextSteps(initial, resolve, callerProviderOptions) {
|
|
|
18676
18845
|
const grouped = /* @__PURE__ */ new Map();
|
|
18677
18846
|
for (const [index, step] of results.entries()) {
|
|
18678
18847
|
const target = steps.get(index) ?? initial;
|
|
18679
|
-
const event =
|
|
18680
|
-
target.entry,
|
|
18681
|
-
target.
|
|
18682
|
-
|
|
18683
|
-
step.providerMetadata
|
|
18684
|
-
);
|
|
18848
|
+
const event = {
|
|
18849
|
+
...textUsageEvent(target.entry, target.provider, step.usage, step.providerMetadata),
|
|
18850
|
+
...keySourceField(target.keySource)
|
|
18851
|
+
};
|
|
18685
18852
|
const previous = grouped.get(target.entry.id);
|
|
18686
18853
|
if (previous) {
|
|
18687
18854
|
previous.quantity += event.quantity;
|
|
@@ -18732,8 +18899,9 @@ function preferredAnthropicTransport(model, routing) {
|
|
|
18732
18899
|
if (isAnthropicTransport(row2)) return row2;
|
|
18733
18900
|
return routing.anthropic ?? "direct";
|
|
18734
18901
|
}
|
|
18735
|
-
function resolveAnthropicTransport(model, config, tier, warn) {
|
|
18902
|
+
function resolveAnthropicTransport(model, config, tier, warn, keyOverride) {
|
|
18736
18903
|
if (model.adapter !== "ai-sdk-text" || textProviderOf(model) !== "anthropic") return void 0;
|
|
18904
|
+
if (overrideCovers(keyOverride, ["anthropic"]).length > 0) return "direct";
|
|
18737
18905
|
const rowValue = model.providerOptions?.["modelkit"]?.["transport"];
|
|
18738
18906
|
if (rowValue !== void 0 && !isAnthropicTransport(rowValue))
|
|
18739
18907
|
warn(
|
|
@@ -18822,8 +18990,7 @@ function providerJobMethods(kind, deps) {
|
|
|
18822
18990
|
const { methods, adapter, ctx } = target(sub.model, rest);
|
|
18823
18991
|
if (!methods.result) throw missing3(adapter, ctx.model);
|
|
18824
18992
|
const result = await methods.result(sub, ctx, webhook);
|
|
18825
|
-
const
|
|
18826
|
-
const usage5 = sub.submittedAt === void 0 ? base : deps.timed(base, sub.submittedAt);
|
|
18993
|
+
const usage5 = deps.rowUsage(ctx, result.usage, sub.submittedAt);
|
|
18827
18994
|
await deps.emit(usage5);
|
|
18828
18995
|
return { ...result, usage: usage5 };
|
|
18829
18996
|
},
|
|
@@ -18951,7 +19118,7 @@ function audioNodeMethods(deps) {
|
|
|
18951
19118
|
if (!adapter.generateSpeech) throw noMethod(adapter, model, "generate speech");
|
|
18952
19119
|
const startedAt = Date.now();
|
|
18953
19120
|
const result = await adapter.generateSpeech(resolved, ctx);
|
|
18954
|
-
return { ...result, usage: await deps.settle(
|
|
19121
|
+
return { ...result, usage: await deps.settle(ctx, result.usage, startedAt) };
|
|
18955
19122
|
},
|
|
18956
19123
|
async changeVoice(req, call = {}) {
|
|
18957
19124
|
mediaRetryOptions(call);
|
|
@@ -18966,7 +19133,7 @@ function audioNodeMethods(deps) {
|
|
|
18966
19133
|
if (!adapter.changeVoice) throw noMethod(adapter, model, "change a voice");
|
|
18967
19134
|
const startedAt = Date.now();
|
|
18968
19135
|
const result = await adapter.changeVoice(resolved, ctx);
|
|
18969
|
-
return { ...result, usage: await deps.settle(
|
|
19136
|
+
return { ...result, usage: await deps.settle(ctx, result.usage, startedAt) };
|
|
18970
19137
|
},
|
|
18971
19138
|
async lipsync(req, call = {}) {
|
|
18972
19139
|
mediaRetryOptions(call);
|
|
@@ -18981,7 +19148,7 @@ function audioNodeMethods(deps) {
|
|
|
18981
19148
|
if (!adapter.lipsync) throw noMethod(adapter, model, "lipsync");
|
|
18982
19149
|
const startedAt = Date.now();
|
|
18983
19150
|
const job = deps.wrapVideoJob(
|
|
18984
|
-
|
|
19151
|
+
ctx,
|
|
18985
19152
|
await adapter.lipsync(resolved, ctx),
|
|
18986
19153
|
warnings,
|
|
18987
19154
|
startedAt
|
|
@@ -19006,7 +19173,7 @@ function audioNodeMethods(deps) {
|
|
|
19006
19173
|
if (!adapter.transcribe) throw noMethod(adapter, model, "transcribe");
|
|
19007
19174
|
const startedAt = Date.now();
|
|
19008
19175
|
const result = await adapter.transcribe(resolved, ctx);
|
|
19009
|
-
return { ...result, usage: await deps.settle(
|
|
19176
|
+
return { ...result, usage: await deps.settle(ctx, result.usage, startedAt) };
|
|
19010
19177
|
},
|
|
19011
19178
|
async createVoice(req, call = {}) {
|
|
19012
19179
|
mediaRetryOptions(call);
|
|
@@ -19017,7 +19184,7 @@ function audioNodeMethods(deps) {
|
|
|
19017
19184
|
if (!adapter.createVoice) throw noMethod(adapter, model, "clone a voice");
|
|
19018
19185
|
const startedAt = Date.now();
|
|
19019
19186
|
const result = await adapter.createVoice(resolved, ctx);
|
|
19020
|
-
return { ...result, usage: await deps.settle(
|
|
19187
|
+
return { ...result, usage: await deps.settle(ctx, result.usage, startedAt) };
|
|
19021
19188
|
},
|
|
19022
19189
|
async designVoice(req, call = {}) {
|
|
19023
19190
|
mediaRetryOptions(call);
|
|
@@ -19032,7 +19199,7 @@ function audioNodeMethods(deps) {
|
|
|
19032
19199
|
if (!adapter.designVoice) throw noMethod(adapter, model, "design a voice");
|
|
19033
19200
|
const startedAt = Date.now();
|
|
19034
19201
|
const result = await adapter.designVoice(resolved, ctx);
|
|
19035
|
-
return { ...result, usage: await deps.settle(
|
|
19202
|
+
return { ...result, usage: await deps.settle(ctx, result.usage, startedAt) };
|
|
19036
19203
|
},
|
|
19037
19204
|
async deleteVoice(req, call = {}) {
|
|
19038
19205
|
mediaRetryOptions(call);
|
|
@@ -19068,11 +19235,11 @@ function audioNodeMethods(deps) {
|
|
|
19068
19235
|
const { audio, usage: usage5, raw } = outcome.result;
|
|
19069
19236
|
return {
|
|
19070
19237
|
audio,
|
|
19071
|
-
usage: await deps.settle(
|
|
19238
|
+
usage: await deps.settle(ctx, usage5, startedAt),
|
|
19072
19239
|
...raw !== void 0 && { raw }
|
|
19073
19240
|
};
|
|
19074
19241
|
}
|
|
19075
|
-
const job = deps.wrapVideoJob(
|
|
19242
|
+
const job = deps.wrapVideoJob(ctx, outcome.job, warnings, startedAt);
|
|
19076
19243
|
const out = await job.result(waitOptions(call, ctx.signal));
|
|
19077
19244
|
return {
|
|
19078
19245
|
video: out.video,
|
|
@@ -19084,14 +19251,28 @@ function audioNodeMethods(deps) {
|
|
|
19084
19251
|
}
|
|
19085
19252
|
|
|
19086
19253
|
// src/client.ts
|
|
19087
|
-
function
|
|
19088
|
-
const routing = config.routing ?? {};
|
|
19089
|
-
if (tier !== "sloosh") return routing;
|
|
19254
|
+
function directRouting(routing) {
|
|
19090
19255
|
const direct = { ...routing };
|
|
19091
19256
|
if (direct.text === "cloudflare") direct.text = "direct";
|
|
19092
19257
|
if (direct.fal === "cloudflare-passthrough") direct.fal = "direct";
|
|
19093
19258
|
return direct;
|
|
19094
19259
|
}
|
|
19260
|
+
function routingFor(config, model, call, transport) {
|
|
19261
|
+
const routing = config.routing ?? {};
|
|
19262
|
+
const direct = directRouting(routing);
|
|
19263
|
+
if (call.tier === "sloosh") return direct;
|
|
19264
|
+
const byok = overrideCovers(call.keyOverride, requiredKeys(model, direct, transport));
|
|
19265
|
+
return byok.length > 0 ? direct : routing;
|
|
19266
|
+
}
|
|
19267
|
+
function byokKeyMissing(provider, model) {
|
|
19268
|
+
return new ModelKitError({
|
|
19269
|
+
code: "byok_key_missing",
|
|
19270
|
+
message: `${model} needs the customer's ${provider} key and the call has none`,
|
|
19271
|
+
provider,
|
|
19272
|
+
model,
|
|
19273
|
+
retryable: false
|
|
19274
|
+
});
|
|
19275
|
+
}
|
|
19095
19276
|
function requiredKeys(model, routing, transport) {
|
|
19096
19277
|
if (model.adapter === "fal" && routing.fal === "cloudflare-passthrough") return ["cloudflare"];
|
|
19097
19278
|
if (model.adapter === "ai-sdk-text") {
|
|
@@ -19193,21 +19374,35 @@ function createModelKit(config, adapters) {
|
|
|
19193
19374
|
message: `No adapter registered for ${model.adapter}`,
|
|
19194
19375
|
model: model.id
|
|
19195
19376
|
});
|
|
19196
|
-
const transport = resolveAnthropicTransport(
|
|
19197
|
-
|
|
19377
|
+
const transport = resolveAnthropicTransport(
|
|
19378
|
+
model,
|
|
19379
|
+
config,
|
|
19380
|
+
call.tier,
|
|
19381
|
+
warnOnce,
|
|
19382
|
+
call.keyOverride
|
|
19383
|
+
);
|
|
19384
|
+
const routing = routingFor(config, model, call, transport);
|
|
19198
19385
|
const names = requiredKeys(model, routing, transport);
|
|
19386
|
+
if (call.requireOverride && overrideCovers(call.keyOverride, names).length === 0)
|
|
19387
|
+
throw byokKeyMissing(names[0] ?? model.adapter, model.id);
|
|
19388
|
+
const { keys, source: source2, tierNames } = resolveCallKeys(
|
|
19389
|
+
config,
|
|
19390
|
+
names,
|
|
19391
|
+
call.tier,
|
|
19392
|
+
call.keyOverride
|
|
19393
|
+
);
|
|
19199
19394
|
if (call.tier === "enterprise") {
|
|
19200
|
-
const missing3 = missingEnterpriseKeys(config,
|
|
19395
|
+
const missing3 = missingEnterpriseKeys(config, tierNames);
|
|
19201
19396
|
if (missing3.length > 0)
|
|
19202
19397
|
logger.warn(
|
|
19203
19398
|
`[modelkit] enterprise keys incomplete for ${model.adapter}; using pro`,
|
|
19204
19399
|
{ missing: missing3 }
|
|
19205
19400
|
);
|
|
19206
19401
|
}
|
|
19207
|
-
const keys = resolveKeys(config, names, call.tier);
|
|
19208
19402
|
const ctx = {
|
|
19209
19403
|
model,
|
|
19210
19404
|
keys,
|
|
19405
|
+
keySource: source2,
|
|
19211
19406
|
routing,
|
|
19212
19407
|
fetch: fetchImpl,
|
|
19213
19408
|
logger,
|
|
@@ -19222,7 +19417,7 @@ function createModelKit(config, adapters) {
|
|
|
19222
19417
|
const jobDeps = {
|
|
19223
19418
|
catalog,
|
|
19224
19419
|
context: (model, call) => context(model, call, []),
|
|
19225
|
-
|
|
19420
|
+
rowUsage,
|
|
19226
19421
|
emit
|
|
19227
19422
|
};
|
|
19228
19423
|
const videoToolJobs = providerJobMethods(VIDEO_TOOL_JOB, jobDeps);
|
|
@@ -19231,6 +19426,15 @@ function createModelKit(config, adapters) {
|
|
|
19231
19426
|
if (event.latencyMs !== void 0) return event;
|
|
19232
19427
|
return { ...event, latencyMs: Math.max(0, Date.now() - startedAt) };
|
|
19233
19428
|
}
|
|
19429
|
+
function rowUsage(ctx, event, startedAt) {
|
|
19430
|
+
const stamped = {
|
|
19431
|
+
...event,
|
|
19432
|
+
model: ctx.model.id,
|
|
19433
|
+
unit: ctx.model.usage.unit,
|
|
19434
|
+
...keySourceField(ctx.keySource)
|
|
19435
|
+
};
|
|
19436
|
+
return startedAt === void 0 ? stamped : timed(stamped, startedAt);
|
|
19437
|
+
}
|
|
19234
19438
|
function textTimed(event, stepCount, startedAt) {
|
|
19235
19439
|
return stepCount === 1 ? timed(event, startedAt) : event;
|
|
19236
19440
|
}
|
|
@@ -19247,6 +19451,7 @@ function createModelKit(config, adapters) {
|
|
|
19247
19451
|
}
|
|
19248
19452
|
function textTarget(model, call) {
|
|
19249
19453
|
if (!isCatalogId(model)) {
|
|
19454
|
+
if (call.requireOverride) throw byokKeyMissing(model.provider, model.modelId);
|
|
19250
19455
|
return {
|
|
19251
19456
|
entry: passthroughTextModel(model),
|
|
19252
19457
|
languageModel: model,
|
|
@@ -19270,7 +19475,8 @@ function createModelKit(config, adapters) {
|
|
|
19270
19475
|
return {
|
|
19271
19476
|
entry,
|
|
19272
19477
|
languageModel: adapter.languageModel(ctx),
|
|
19273
|
-
provider: textUsageProvider(entry, ctx.anthropicTransport)
|
|
19478
|
+
provider: textUsageProvider(entry, ctx.anthropicTransport),
|
|
19479
|
+
...keySourceField(ctx.keySource)
|
|
19274
19480
|
};
|
|
19275
19481
|
}
|
|
19276
19482
|
async function passthroughImage(req, call) {
|
|
@@ -19442,7 +19648,7 @@ function createModelKit(config, adapters) {
|
|
|
19442
19648
|
result: () => done
|
|
19443
19649
|
};
|
|
19444
19650
|
}
|
|
19445
|
-
function wrapVideoJob(
|
|
19651
|
+
function wrapVideoJob(ctx, job, warnings, startedAt) {
|
|
19446
19652
|
const result = job.result.bind(job);
|
|
19447
19653
|
let settled;
|
|
19448
19654
|
return {
|
|
@@ -19452,10 +19658,7 @@ function createModelKit(config, adapters) {
|
|
|
19452
19658
|
if (settled) return settled;
|
|
19453
19659
|
const pending = result(opts).then(
|
|
19454
19660
|
async (out) => {
|
|
19455
|
-
const usage5 =
|
|
19456
|
-
{ ...out.usage, model: model.id, unit: model.usage.unit },
|
|
19457
|
-
startedAt
|
|
19458
|
-
);
|
|
19661
|
+
const usage5 = rowUsage(ctx, out.usage, startedAt);
|
|
19459
19662
|
await emit(usage5);
|
|
19460
19663
|
return { ...out, usage: usage5 };
|
|
19461
19664
|
},
|
|
@@ -19476,8 +19679,8 @@ function createModelKit(config, adapters) {
|
|
|
19476
19679
|
const signal = combineSignals(abortSignal, call.signal);
|
|
19477
19680
|
return context(model, signal ? { ...call, signal } : call, warnings);
|
|
19478
19681
|
},
|
|
19479
|
-
async settle(
|
|
19480
|
-
const usage5 =
|
|
19682
|
+
async settle(ctx, event, startedAt) {
|
|
19683
|
+
const usage5 = rowUsage(ctx, event, startedAt);
|
|
19481
19684
|
await emit(usage5);
|
|
19482
19685
|
return usage5;
|
|
19483
19686
|
},
|
|
@@ -19490,6 +19693,8 @@ function createModelKit(config, adapters) {
|
|
|
19490
19693
|
async generateImage(req, call = {}) {
|
|
19491
19694
|
mediaRetryOptions(call);
|
|
19492
19695
|
if (!isCatalogId(req.model)) {
|
|
19696
|
+
if (call.requireOverride)
|
|
19697
|
+
throw byokKeyMissing(req.model.provider, req.model.modelId);
|
|
19493
19698
|
return passthroughImage({ ...req, model: req.model }, call);
|
|
19494
19699
|
}
|
|
19495
19700
|
const model = catalog.require(req.model);
|
|
@@ -19515,10 +19720,7 @@ function createModelKit(config, adapters) {
|
|
|
19515
19720
|
});
|
|
19516
19721
|
const startedAt = Date.now();
|
|
19517
19722
|
const result = await adapter.generateImage(request, ctx);
|
|
19518
|
-
const usage5 =
|
|
19519
|
-
{ ...result.usage, model: model.id, unit: model.usage.unit },
|
|
19520
|
-
startedAt
|
|
19521
|
-
);
|
|
19723
|
+
const usage5 = rowUsage(ctx, result.usage, startedAt);
|
|
19522
19724
|
await emit(usage5);
|
|
19523
19725
|
const images = result.images.map(toGeneratedImage);
|
|
19524
19726
|
const first = images[0];
|
|
@@ -19533,6 +19735,8 @@ function createModelKit(config, adapters) {
|
|
|
19533
19735
|
async generateVideo(req, call = {}) {
|
|
19534
19736
|
mediaRetryOptions(call);
|
|
19535
19737
|
if (!isCatalogId(req.model)) {
|
|
19738
|
+
if (call.requireOverride)
|
|
19739
|
+
throw byokKeyMissing(req.model.provider, req.model.modelId);
|
|
19536
19740
|
return passthroughVideo({ ...req, model: req.model }, call);
|
|
19537
19741
|
}
|
|
19538
19742
|
const model = catalog.require(req.model);
|
|
@@ -19558,7 +19762,7 @@ function createModelKit(config, adapters) {
|
|
|
19558
19762
|
});
|
|
19559
19763
|
const startedAt = Date.now();
|
|
19560
19764
|
const job = await adapter.generateVideo(request, ctx);
|
|
19561
|
-
return wrapVideoJob(
|
|
19765
|
+
return wrapVideoJob(ctx, job, warnings, startedAt);
|
|
19562
19766
|
},
|
|
19563
19767
|
async resumeVideo(req, jobId, call = {}) {
|
|
19564
19768
|
mediaRetryOptions(call);
|
|
@@ -19603,7 +19807,7 @@ function createModelKit(config, adapters) {
|
|
|
19603
19807
|
});
|
|
19604
19808
|
const startedAt = Date.now();
|
|
19605
19809
|
const job = adapter.resumeVideo(request, jobId, ctx);
|
|
19606
|
-
return wrapVideoJob(
|
|
19810
|
+
return wrapVideoJob(ctx, { ...job, jobId }, warnings, startedAt);
|
|
19607
19811
|
},
|
|
19608
19812
|
async generateAudio(req, call = {}) {
|
|
19609
19813
|
mediaRetryOptions(call);
|
|
@@ -19627,10 +19831,7 @@ function createModelKit(config, adapters) {
|
|
|
19627
19831
|
}
|
|
19628
19832
|
const startedAt = Date.now();
|
|
19629
19833
|
const result = await adapter.generateAudio(resolved, ctx);
|
|
19630
|
-
const usage5 =
|
|
19631
|
-
{ ...result.usage, model: model.id, unit: model.usage.unit },
|
|
19632
|
-
startedAt
|
|
19633
|
-
);
|
|
19834
|
+
const usage5 = rowUsage(ctx, result.usage, startedAt);
|
|
19634
19835
|
await emit(usage5);
|
|
19635
19836
|
return { ...result, usage: usage5 };
|
|
19636
19837
|
},
|
|
@@ -19643,7 +19844,7 @@ function createModelKit(config, adapters) {
|
|
|
19643
19844
|
return "url" in ref ? { type: "file", data: ref.url, mediaType } : { type: "file", data: ref.bytes, mediaType };
|
|
19644
19845
|
},
|
|
19645
19846
|
languageModel(modelId, call = {}) {
|
|
19646
|
-
const { entry, languageModel: model, provider } = textTarget(modelId, call);
|
|
19847
|
+
const { entry, languageModel: model, provider, keySource } = textTarget(modelId, call);
|
|
19647
19848
|
if (model.specificationVersion !== "v3")
|
|
19648
19849
|
throw new ModelKitError({
|
|
19649
19850
|
code: "unsupported_option",
|
|
@@ -19654,7 +19855,8 @@ function createModelKit(config, adapters) {
|
|
|
19654
19855
|
model,
|
|
19655
19856
|
providerOptions: withoutModelkit(entry.providerOptions),
|
|
19656
19857
|
catalog: entry,
|
|
19657
|
-
usageProvider: provider
|
|
19858
|
+
usageProvider: provider,
|
|
19859
|
+
...keySourceField(keySource)
|
|
19658
19860
|
};
|
|
19659
19861
|
},
|
|
19660
19862
|
submitVideoTool: videoToolJobs.submit,
|
|
@@ -19670,7 +19872,7 @@ function createModelKit(config, adapters) {
|
|
|
19670
19872
|
if (entry.type !== "text") return entry.adapter;
|
|
19671
19873
|
return textUsageProvider(
|
|
19672
19874
|
entry,
|
|
19673
|
-
resolveAnthropicTransport(entry, config, call.tier, warnOnce)
|
|
19875
|
+
resolveAnthropicTransport(entry, config, call.tier, warnOnce, call.keyOverride)
|
|
19674
19876
|
);
|
|
19675
19877
|
},
|
|
19676
19878
|
async generateText(options, call = {}) {
|
|
@@ -19719,7 +19921,7 @@ function createModelKit(config, adapters) {
|
|
|
19719
19921
|
});
|
|
19720
19922
|
},
|
|
19721
19923
|
async generateObject(options, call = {}) {
|
|
19722
|
-
const { entry, languageModel: languageModel2, provider } = textTarget(options.model, call);
|
|
19924
|
+
const { entry, languageModel: languageModel2, provider, keySource } = textTarget(options.model, call);
|
|
19723
19925
|
const sdkOptions = {
|
|
19724
19926
|
...options,
|
|
19725
19927
|
...textAbortOptions(options.abortSignal, call.signal),
|
|
@@ -19730,16 +19932,17 @@ function createModelKit(config, adapters) {
|
|
|
19730
19932
|
const result = await (0, import_ai5.generateObject)(sdkOptions);
|
|
19731
19933
|
await emit(
|
|
19732
19934
|
timed(
|
|
19733
|
-
withRowUnit(
|
|
19734
|
-
textUsageEvent(entry, provider, result.usage, result.providerMetadata)
|
|
19735
|
-
|
|
19935
|
+
withRowUnit({
|
|
19936
|
+
...textUsageEvent(entry, provider, result.usage, result.providerMetadata),
|
|
19937
|
+
...keySourceField(keySource)
|
|
19938
|
+
}),
|
|
19736
19939
|
startedAt
|
|
19737
19940
|
)
|
|
19738
19941
|
);
|
|
19739
19942
|
return result;
|
|
19740
19943
|
},
|
|
19741
19944
|
streamObject(options, call = {}) {
|
|
19742
|
-
const { entry, languageModel: languageModel2, provider } = textTarget(options.model, call);
|
|
19945
|
+
const { entry, languageModel: languageModel2, provider, keySource } = textTarget(options.model, call);
|
|
19743
19946
|
const callerOnFinish = options.onFinish;
|
|
19744
19947
|
const startedAt = Date.now();
|
|
19745
19948
|
const sdkOptions = {
|
|
@@ -19750,14 +19953,15 @@ function createModelKit(config, adapters) {
|
|
|
19750
19953
|
onFinish: async (event) => {
|
|
19751
19954
|
await emit(
|
|
19752
19955
|
timed(
|
|
19753
|
-
withRowUnit(
|
|
19754
|
-
textUsageEvent(
|
|
19956
|
+
withRowUnit({
|
|
19957
|
+
...textUsageEvent(
|
|
19755
19958
|
entry,
|
|
19756
19959
|
provider,
|
|
19757
19960
|
event.usage,
|
|
19758
19961
|
event.providerMetadata
|
|
19759
|
-
)
|
|
19760
|
-
|
|
19962
|
+
),
|
|
19963
|
+
...keySourceField(keySource)
|
|
19964
|
+
}),
|
|
19761
19965
|
startedAt
|
|
19762
19966
|
)
|
|
19763
19967
|
);
|
|
@@ -19801,6 +20005,7 @@ var describe = (modelId) => createDefaultModelKit().describe(modelId);
|
|
|
19801
20005
|
ADAPTER_KEYS,
|
|
19802
20006
|
ARRAY_INPUT_SPEC_KEYS,
|
|
19803
20007
|
AUDIO_INPUT_SPEC_KEYS,
|
|
20008
|
+
BYOK_PROVIDERS,
|
|
19804
20009
|
Catalog,
|
|
19805
20010
|
CatalogModelSchema,
|
|
19806
20011
|
CatalogModelSchemaBase,
|
|
@@ -19825,6 +20030,7 @@ var describe = (modelId) => createDefaultModelKit().describe(modelId);
|
|
|
19825
20030
|
aiSdkTextAdapter,
|
|
19826
20031
|
arkAdapter,
|
|
19827
20032
|
aspectRatioToSize,
|
|
20033
|
+
byokProviderForModel,
|
|
19828
20034
|
classifyHttpError,
|
|
19829
20035
|
compareCatalogOrder,
|
|
19830
20036
|
createDefaultModelKit,
|
|
@@ -19852,6 +20058,7 @@ var describe = (modelId) => createDefaultModelKit().describe(modelId);
|
|
|
19852
20058
|
isListed,
|
|
19853
20059
|
isListedOn,
|
|
19854
20060
|
isModelKitError,
|
|
20061
|
+
keyOverrideFor,
|
|
19855
20062
|
keysFromEnv,
|
|
19856
20063
|
languageModel,
|
|
19857
20064
|
liveCatalog,
|
|
@@ -19868,6 +20075,7 @@ var describe = (modelId) => createDefaultModelKit().describe(modelId);
|
|
|
19868
20075
|
model3dSeedFits,
|
|
19869
20076
|
model3dSkus,
|
|
19870
20077
|
model3dTexture,
|
|
20078
|
+
modelsPoweredBy,
|
|
19871
20079
|
nearestAspectRatio,
|
|
19872
20080
|
normalizeExposure,
|
|
19873
20081
|
openaiImageAdapter,
|
|
@@ -19898,6 +20106,7 @@ var describe = (modelId) => createDefaultModelKit().describe(modelId);
|
|
|
19898
20106
|
streamObject,
|
|
19899
20107
|
streamText,
|
|
19900
20108
|
takesTargetAspectRatio,
|
|
20109
|
+
testProviderKey,
|
|
19901
20110
|
textUsageEvent,
|
|
19902
20111
|
toGeneratedImage,
|
|
19903
20112
|
validateInputSpec,
|