@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.js
CHANGED
|
@@ -140,8 +140,8 @@ function normalizeExposure(value) {
|
|
|
140
140
|
if (value.every(
|
|
141
141
|
(entry) => SURFACES.includes(entry)
|
|
142
142
|
)) {
|
|
143
|
-
const
|
|
144
|
-
return SURFACES.filter((surface) =>
|
|
143
|
+
const present3 = new Set(value);
|
|
144
|
+
return SURFACES.filter((surface) => present3.has(surface));
|
|
145
145
|
}
|
|
146
146
|
return value;
|
|
147
147
|
}
|
|
@@ -561,7 +561,7 @@ var IMAGE_MODELS = [
|
|
|
561
561
|
// Cowork "auto" lets OpenAI pick the size; the canonical equivalent is adaptive.
|
|
562
562
|
id: "gpt-image-2",
|
|
563
563
|
aliases: [],
|
|
564
|
-
label: "GPT
|
|
564
|
+
label: "GPT Image 2",
|
|
565
565
|
type: "image",
|
|
566
566
|
adapter: "openai-image",
|
|
567
567
|
providerModelId: "gpt-image-2",
|
|
@@ -748,7 +748,7 @@ var IMAGE_MODELS = [
|
|
|
748
748
|
display: {
|
|
749
749
|
provider: "bytedance",
|
|
750
750
|
logo: "https://d31vvfpk2ppdyq.cloudfront.net/assets/image/3bba5d81-4e57-4e71-911b-cdfa05acca2c_compressed.png",
|
|
751
|
-
description: "ByteDance Seedream 5.0 Pro text-to-image and multi-reference image-to-image (up to 10 inputs) with region editing; outputs 1K
|
|
751
|
+
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."
|
|
752
752
|
}
|
|
753
753
|
},
|
|
754
754
|
{
|
|
@@ -791,7 +791,7 @@ var IMAGE_MODELS = [
|
|
|
791
791
|
{
|
|
792
792
|
id: "flux-2-pro",
|
|
793
793
|
aliases: [],
|
|
794
|
-
label: "
|
|
794
|
+
label: "FLUX 2 Pro",
|
|
795
795
|
type: "image",
|
|
796
796
|
adapter: "prodia",
|
|
797
797
|
providerModelId: "flux-2-pro",
|
|
@@ -812,7 +812,7 @@ var IMAGE_MODELS = [
|
|
|
812
812
|
display: {
|
|
813
813
|
provider: "black-forest-labs",
|
|
814
814
|
logo: "https://cdn.jsdelivr.net/npm/@lobehub/icons-static-png@1.97.0/light/flux.png",
|
|
815
|
-
description: "Black Forest Labs FLUX.2 [pro] text-to-image and multi-reference editing model
|
|
815
|
+
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."
|
|
816
816
|
}
|
|
817
817
|
},
|
|
818
818
|
{
|
|
@@ -872,7 +872,7 @@ var IMAGE_MODELS = [
|
|
|
872
872
|
// https://replicate.com/wan-video/wan-2.7-image-pro (input schema)
|
|
873
873
|
id: "wan-2.7-image-pro",
|
|
874
874
|
aliases: [],
|
|
875
|
-
label: "
|
|
875
|
+
label: "Wan 2.7 Image Pro",
|
|
876
876
|
type: "image",
|
|
877
877
|
adapter: "replicate",
|
|
878
878
|
providerModelId: "wan-video/wan-2.7-image-pro",
|
|
@@ -1196,7 +1196,7 @@ var SAM_3_IMAGE = {
|
|
|
1196
1196
|
display: {
|
|
1197
1197
|
provider: "meta",
|
|
1198
1198
|
logo: META_LOGO,
|
|
1199
|
-
description: "Meta SAM 3
|
|
1199
|
+
description: "Meta SAM 3; finds every object a prompt names in one image and returns a black-and-white mask for each."
|
|
1200
1200
|
}
|
|
1201
1201
|
};
|
|
1202
1202
|
var VEED_SUBTITLES = {
|
|
@@ -2038,7 +2038,7 @@ var FISH_MODELS = [
|
|
|
2038
2038
|
"fish-s2.1-pro-free",
|
|
2039
2039
|
"Fish Audio S2.1 Pro Free",
|
|
2040
2040
|
"s2.1-pro-free",
|
|
2041
|
-
"Fish Audio S2.1 Pro
|
|
2041
|
+
"Fish Audio S2.1 Pro text to speech, with the same voices as S2.1 Pro."
|
|
2042
2042
|
),
|
|
2043
2043
|
fishTts(
|
|
2044
2044
|
"fish-drama-3",
|
|
@@ -3776,7 +3776,7 @@ var MEDIA_NODE_MODELS = [
|
|
|
3776
3776
|
formats: false,
|
|
3777
3777
|
// fal's schema states no limit; ElevenLabs documents 10,000 characters per request.
|
|
3778
3778
|
maxChars: 1e4,
|
|
3779
|
-
description: "ElevenLabs Multilingual v2 text to speech in 29 languages
|
|
3779
|
+
description: "ElevenLabs Multilingual v2 text to speech in 29 languages."
|
|
3780
3780
|
}),
|
|
3781
3781
|
geminiTts(
|
|
3782
3782
|
"gemini-3.8-flash-tts",
|
|
@@ -3872,7 +3872,7 @@ var MEDIA_NODE_MODELS = [
|
|
|
3872
3872
|
"Sync Lipsync 2",
|
|
3873
3873
|
"fal-ai/sync-lipsync/v2",
|
|
3874
3874
|
"lipsync-2",
|
|
3875
|
-
"Sync Lipsync 2 re-times the mouth in a video to new speech
|
|
3875
|
+
"Sync Lipsync 2 re-times the mouth in a video to new speech."
|
|
3876
3876
|
),
|
|
3877
3877
|
syncLipsync(
|
|
3878
3878
|
"lipsync-2-pro",
|
|
@@ -3910,7 +3910,7 @@ var MEDIA_NODE_MODELS = [
|
|
|
3910
3910
|
display: {
|
|
3911
3911
|
provider: "veed",
|
|
3912
3912
|
logo: "https://d31vvfpk2ppdyq.cloudfront.net/assets/image/d540d2bb-0022-4371-8889-48aefaf46bbe.png",
|
|
3913
|
-
description: "VEED Lipsync v2 re-times the mouth in a video to a new audio track
|
|
3913
|
+
description: "VEED Lipsync v2 re-times the mouth in a video to a new audio track."
|
|
3914
3914
|
},
|
|
3915
3915
|
capabilities: { acceptsSourceVideo: true }
|
|
3916
3916
|
},
|
|
@@ -4255,7 +4255,7 @@ var OTHER_MODELS = [
|
|
|
4255
4255
|
pricingKind: "flat",
|
|
4256
4256
|
display: {
|
|
4257
4257
|
provider: "mmaudio",
|
|
4258
|
-
description: "MMAudio V2 video-to-audio model
|
|
4258
|
+
description: "MMAudio V2 video-to-audio model; takes a source video and a prompt and synthesizes synchronized environmental, action, and speech-like audio."
|
|
4259
4259
|
},
|
|
4260
4260
|
capabilities: {}
|
|
4261
4261
|
},
|
|
@@ -4465,7 +4465,7 @@ var OTHER_MODELS = [
|
|
|
4465
4465
|
display: {
|
|
4466
4466
|
provider: "topaz",
|
|
4467
4467
|
logo: "https://cdn.jsdelivr.net/npm/@lobehub/icons-static-png@1.97.0/light/topazlabs.png",
|
|
4468
|
-
description: "Topaz Labs AI image upscaling
|
|
4468
|
+
description: "Topaz Labs AI image upscaling; takes one input image and upscales up to 6x with selectable enhancement models and optional face enhancement."
|
|
4469
4469
|
}
|
|
4470
4470
|
},
|
|
4471
4471
|
{
|
|
@@ -4491,7 +4491,7 @@ var OTHER_MODELS = [
|
|
|
4491
4491
|
display: {
|
|
4492
4492
|
provider: "bytedance",
|
|
4493
4493
|
logo: "https://d31vvfpk2ppdyq.cloudfront.net/assets/image/3bba5d81-4e57-4e71-911b-cdfa05acca2c_compressed.png",
|
|
4494
|
-
description: "ByteDance SeedVR2 one-step image upscaling and restoration
|
|
4494
|
+
description: "ByteDance SeedVR2 one-step image upscaling and restoration; takes one input image and upscales it 2x or 4x with sharp, faithful detail."
|
|
4495
4495
|
}
|
|
4496
4496
|
},
|
|
4497
4497
|
{
|
|
@@ -4515,7 +4515,7 @@ var OTHER_MODELS = [
|
|
|
4515
4515
|
pricingKind: "flat",
|
|
4516
4516
|
display: {
|
|
4517
4517
|
provider: "prodia",
|
|
4518
|
-
description: "
|
|
4518
|
+
description: "Background removal; takes one input image and returns a PNG cut-out of the subject plus an optional black-and-white mask."
|
|
4519
4519
|
}
|
|
4520
4520
|
}
|
|
4521
4521
|
];
|
|
@@ -5214,7 +5214,7 @@ var VIDEO_FAMILY_MODELS = [
|
|
|
5214
5214
|
display: {
|
|
5215
5215
|
provider: "kuaishou",
|
|
5216
5216
|
logo: KLING_LOGO,
|
|
5217
|
-
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),
|
|
5217
|
+
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."
|
|
5218
5218
|
},
|
|
5219
5219
|
capabilities: { lastFrameRequiresFirstFrame: true }
|
|
5220
5220
|
},
|
|
@@ -5559,7 +5559,7 @@ var VIDEO_FAMILY_MODELS = [
|
|
|
5559
5559
|
display: {
|
|
5560
5560
|
provider: "xai",
|
|
5561
5561
|
logo: XAI_LOGO,
|
|
5562
|
-
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,
|
|
5562
|
+
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."
|
|
5563
5563
|
},
|
|
5564
5564
|
capabilities: {}
|
|
5565
5565
|
}
|
|
@@ -5916,7 +5916,7 @@ var VIDEO_MODELS = [
|
|
|
5916
5916
|
pricingKind: "video_per_second",
|
|
5917
5917
|
display: {
|
|
5918
5918
|
provider: "bytedance",
|
|
5919
|
-
description: "High-quality
|
|
5919
|
+
description: "High-quality ByteDance video generation guided by reference images, for clips up to 15 seconds.",
|
|
5920
5920
|
logo: BYTEDANCE_LOGO2
|
|
5921
5921
|
},
|
|
5922
5922
|
capabilities: { acceptsSourceVideo: true, videoEdit: false, ...FRAMES_EXCLUDE_REFERENCES }
|
|
@@ -6040,7 +6040,7 @@ var VIDEO_MODELS = [
|
|
|
6040
6040
|
pricingKind: "video_per_second",
|
|
6041
6041
|
display: {
|
|
6042
6042
|
provider: "xai",
|
|
6043
|
-
description: "xAI's reference-to-video model. Generates short clips conditioned on up to
|
|
6043
|
+
description: "xAI's reference-to-video model. Generates short clips conditioned on up to 7 reference images with flexible aspect ratios.",
|
|
6044
6044
|
logo: "https://d31vvfpk2ppdyq.cloudfront.net/assets/image/858b7fcc-9bd5-411d-aea1-a7b35ecfffab_compressed.png"
|
|
6045
6045
|
},
|
|
6046
6046
|
capabilities: { ...FRAMES_EXCLUDE_REFERENCES }
|
|
@@ -6124,7 +6124,7 @@ var VIDEO_MODELS = [
|
|
|
6124
6124
|
exposure: ["cowork", "space_builder"],
|
|
6125
6125
|
constraints: {
|
|
6126
6126
|
aspectRatios: [...KLING_OMNI_RATIOS],
|
|
6127
|
-
resolutions: ["720p", "1080p"
|
|
6127
|
+
resolutions: ["720p", "1080p"],
|
|
6128
6128
|
durations: { min: 3, max: 15 },
|
|
6129
6129
|
references: { images: 7, videos: 0, audios: 0 },
|
|
6130
6130
|
supports: ["generateAudio", "lastFrame"],
|
|
@@ -6137,7 +6137,7 @@ var VIDEO_MODELS = [
|
|
|
6137
6137
|
display: {
|
|
6138
6138
|
provider: "kuaishou",
|
|
6139
6139
|
logo: "https://cdn.jsdelivr.net/npm/@lobehub/icons-static-png@1.97.0/light/kling-color.png",
|
|
6140
|
-
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
|
|
6140
|
+
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."
|
|
6141
6141
|
}
|
|
6142
6142
|
// No lastFrameRequiresFirstFrame: fal image-to-video needs a start frame, so the adapter
|
|
6143
6143
|
// sends a lone end frame as the start frame, as the Replicate model took it.
|
|
@@ -6172,7 +6172,7 @@ var VIDEO_MODELS = [
|
|
|
6172
6172
|
display: {
|
|
6173
6173
|
provider: "minimax",
|
|
6174
6174
|
logo: "https://d31vvfpk2ppdyq.cloudfront.net/assets/image/f4c2e906-28b7-4a4a-b491-df8fef7808ed.png",
|
|
6175
|
-
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
|
|
6175
|
+
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."
|
|
6176
6176
|
},
|
|
6177
6177
|
capabilities: { ...FRAMES_EXCLUDE_REFERENCES }
|
|
6178
6178
|
},
|
|
@@ -6292,7 +6292,7 @@ var VIDEO_MODELS = [
|
|
|
6292
6292
|
display: {
|
|
6293
6293
|
provider: "minimax",
|
|
6294
6294
|
logo: "https://d31vvfpk2ppdyq.cloudfront.net/assets/image/f4c2e906-28b7-4a4a-b491-df8fef7808ed.png",
|
|
6295
|
-
description: "MiniMax H3 Max reference-to-video
|
|
6295
|
+
description: "MiniMax H3 Max reference-to-video; conditions on reference images, videos, and audio."
|
|
6296
6296
|
},
|
|
6297
6297
|
// fal's reference-to-video endpoint never reads a frame; the resolver must drop the
|
|
6298
6298
|
// references instead of the adapter silently dropping the frame.
|
|
@@ -6336,7 +6336,7 @@ var VIDEO_MODELS = [
|
|
|
6336
6336
|
pricingKind: "video_per_second",
|
|
6337
6337
|
display: {
|
|
6338
6338
|
provider: "alibaba",
|
|
6339
|
-
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;
|
|
6339
|
+
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."
|
|
6340
6340
|
},
|
|
6341
6341
|
capabilities: { ...FRAMES_EXCLUDE_REFERENCES, lastFrameRequiresFirstFrame: true }
|
|
6342
6342
|
},
|
|
@@ -6378,7 +6378,7 @@ var VIDEO_MODELS = [
|
|
|
6378
6378
|
pricingKind: "video_per_second",
|
|
6379
6379
|
display: {
|
|
6380
6380
|
provider: "alibaba",
|
|
6381
|
-
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;
|
|
6381
|
+
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."
|
|
6382
6382
|
},
|
|
6383
6383
|
capabilities: { ...FRAMES_EXCLUDE_REFERENCES, lastFrameRequiresFirstFrame: true }
|
|
6384
6384
|
},
|
|
@@ -8446,9 +8446,6 @@ var aiSdkTextAdapter = {
|
|
|
8446
8446
|
// src/adapters/ark.ts
|
|
8447
8447
|
import { z as z7 } from "zod";
|
|
8448
8448
|
|
|
8449
|
-
// src/retry.ts
|
|
8450
|
-
import { z as z6 } from "zod";
|
|
8451
|
-
|
|
8452
8449
|
// src/json.ts
|
|
8453
8450
|
import { z as z5 } from "zod";
|
|
8454
8451
|
var JsonValueSchema = z5.lazy(
|
|
@@ -8485,6 +8482,7 @@ function describeThrown(cause) {
|
|
|
8485
8482
|
}
|
|
8486
8483
|
|
|
8487
8484
|
// src/retry.ts
|
|
8485
|
+
import { z as z6 } from "zod";
|
|
8488
8486
|
var textBody = z6.string();
|
|
8489
8487
|
var BILLING_CODES = /* @__PURE__ */ new Set([
|
|
8490
8488
|
"insufficient_quota",
|
|
@@ -8781,10 +8779,36 @@ function arkKey(ctx) {
|
|
|
8781
8779
|
}
|
|
8782
8780
|
return key;
|
|
8783
8781
|
}
|
|
8784
|
-
|
|
8782
|
+
var ARK_CODES = /* @__PURE__ */ new Map([
|
|
8783
|
+
["AccountOverdueError", { status: 403, code: "provider_billing" }],
|
|
8784
|
+
["OperationDenied.ServiceOverdue", { status: 403, code: "provider_billing" }],
|
|
8785
|
+
["QuotaExceeded", { status: 429, code: "provider_billing" }],
|
|
8786
|
+
["ModelNotOpen", { status: 404, code: "provider_rejected" }],
|
|
8787
|
+
["InvalidEndpointOrModel.NotFound", { status: 404, code: "provider_rejected" }]
|
|
8788
|
+
]);
|
|
8789
|
+
var ArkErrorBodySchema = z7.object({ error: z7.object({ code: z7.string() }) });
|
|
8790
|
+
function arkErrorCode(body) {
|
|
8791
|
+
const text2 = z7.string().safeParse(body);
|
|
8792
|
+
let decoded = body;
|
|
8793
|
+
if (text2.success) {
|
|
8794
|
+
try {
|
|
8795
|
+
decoded = JsonValueSchema.parse(JSON.parse(text2.data));
|
|
8796
|
+
} catch {
|
|
8797
|
+
return void 0;
|
|
8798
|
+
}
|
|
8799
|
+
}
|
|
8800
|
+
const parsed = ArkErrorBodySchema.safeParse(decoded);
|
|
8801
|
+
return parsed.success ? parsed.data.error.code : void 0;
|
|
8802
|
+
}
|
|
8803
|
+
function arkCodeRule(status, code) {
|
|
8804
|
+
const rule = code === void 0 ? void 0 : ARK_CODES.get(code);
|
|
8805
|
+
if (!rule || status !== void 0 && status !== rule.status) return void 0;
|
|
8806
|
+
return rule;
|
|
8807
|
+
}
|
|
8808
|
+
function throwArkError(status, body, model, code = arkErrorCode(body)) {
|
|
8785
8809
|
const parsed = z7.string().safeParse(body);
|
|
8786
8810
|
const text2 = parsed.success ? parsed.data : JSON.stringify(body ?? "");
|
|
8787
|
-
if (/sensitive.?content|human.?face/i.test(text2)) {
|
|
8811
|
+
if (/sensitive.?content|human.?face/i.test(`${code ?? ""} ${text2}`)) {
|
|
8788
8812
|
const init = {
|
|
8789
8813
|
code: "content_blocked",
|
|
8790
8814
|
message: `ark rejected the request: ${text2.slice(0, 500)}`,
|
|
@@ -8796,15 +8820,18 @@ function throwArkError(status, body, model) {
|
|
|
8796
8820
|
if (status !== void 0) init.status = status;
|
|
8797
8821
|
throw new ModelKitError(init);
|
|
8798
8822
|
}
|
|
8799
|
-
|
|
8800
|
-
|
|
8801
|
-
|
|
8802
|
-
|
|
8823
|
+
const rule = arkCodeRule(status, code);
|
|
8824
|
+
if (rule || status === void 0) {
|
|
8825
|
+
const init = {
|
|
8826
|
+
code: rule?.code ?? "provider_rejected",
|
|
8827
|
+
message: `ark rejected the request${code ? ` (${code})` : ""}: ${text2.slice(0, 500)}`,
|
|
8803
8828
|
provider: "ark",
|
|
8804
8829
|
model,
|
|
8805
8830
|
body,
|
|
8806
8831
|
retryable: false
|
|
8807
|
-
}
|
|
8832
|
+
};
|
|
8833
|
+
if (status !== void 0) init.status = status;
|
|
8834
|
+
throw new ModelKitError(init);
|
|
8808
8835
|
}
|
|
8809
8836
|
throw classifyHttpError(status, body, "ark", model);
|
|
8810
8837
|
}
|
|
@@ -8920,9 +8947,15 @@ var SeedanceResponseSchema = z7.object({
|
|
|
8920
8947
|
duration: z7.number().optional(),
|
|
8921
8948
|
framespersecond: z7.number().optional(),
|
|
8922
8949
|
resolution: z7.string().optional(),
|
|
8923
|
-
error: z7.union([
|
|
8950
|
+
error: z7.union([
|
|
8951
|
+
z7.string(),
|
|
8952
|
+
z7.object({ code: z7.string().optional(), message: z7.string().optional() })
|
|
8953
|
+
]).optional()
|
|
8954
|
+
});
|
|
8955
|
+
var SeedanceErrorSchema = z7.object({
|
|
8956
|
+
code: z7.string().optional(),
|
|
8957
|
+
message: z7.string().optional()
|
|
8924
8958
|
});
|
|
8925
|
-
var SeedanceErrorMessageSchema = z7.object({ message: z7.string().optional() });
|
|
8926
8959
|
function seedanceResolution(req) {
|
|
8927
8960
|
return req.resolution ?? "720p";
|
|
8928
8961
|
}
|
|
@@ -8943,10 +8976,14 @@ function seedanceInitialDuration(req) {
|
|
|
8943
8976
|
function seedanceErrorMessage(error, status) {
|
|
8944
8977
|
const asString = z7.string().safeParse(error);
|
|
8945
8978
|
if (asString.success) return asString.data;
|
|
8946
|
-
const asObject =
|
|
8979
|
+
const asObject = SeedanceErrorSchema.safeParse(error);
|
|
8947
8980
|
if (asObject.success && asObject.data.message !== void 0) return asObject.data.message;
|
|
8948
8981
|
return `Seedance task ${status}`;
|
|
8949
8982
|
}
|
|
8983
|
+
function seedanceErrorCode(error) {
|
|
8984
|
+
const parsed = SeedanceErrorSchema.safeParse(error);
|
|
8985
|
+
return parsed.success ? parsed.data.code : void 0;
|
|
8986
|
+
}
|
|
8950
8987
|
function seedanceJob(ctx, key, jobId, usage5) {
|
|
8951
8988
|
const modelId = ctx.model.id;
|
|
8952
8989
|
const fetchStatus = async () => {
|
|
@@ -8954,9 +8991,9 @@ function seedanceJob(ctx, key, jobId, usage5) {
|
|
|
8954
8991
|
headers: { Authorization: `Bearer ${key}` }
|
|
8955
8992
|
});
|
|
8956
8993
|
if (!res.ok) {
|
|
8957
|
-
if (ctx.call.maxRetries !== 0 && (res.status === 429 || res.status >= 500))
|
|
8958
|
-
return void 0;
|
|
8959
8994
|
const text2 = await res.text().catch(() => "");
|
|
8995
|
+
const transient = (res.status === 429 || res.status >= 500) && !arkCodeRule(res.status, arkErrorCode(text2));
|
|
8996
|
+
if (ctx.call.maxRetries !== 0 && transient) return void 0;
|
|
8960
8997
|
throwArkError(res.status, text2, modelId);
|
|
8961
8998
|
}
|
|
8962
8999
|
const parsed = SeedanceResponseSchema.safeParse(await res.json());
|
|
@@ -9016,7 +9053,12 @@ function seedanceJob(ctx, key, jobId, usage5) {
|
|
|
9016
9053
|
};
|
|
9017
9054
|
}
|
|
9018
9055
|
if (status === "failed" || status === "expired" || status === "cancelled") {
|
|
9019
|
-
throwArkError(
|
|
9056
|
+
throwArkError(
|
|
9057
|
+
void 0,
|
|
9058
|
+
seedanceErrorMessage(polled.error, status),
|
|
9059
|
+
modelId,
|
|
9060
|
+
seedanceErrorCode(polled.error)
|
|
9061
|
+
);
|
|
9020
9062
|
}
|
|
9021
9063
|
return void 0;
|
|
9022
9064
|
}, pollOpts);
|
|
@@ -10799,8 +10841,8 @@ function falMediaError(row2, message, code) {
|
|
|
10799
10841
|
retryable: false
|
|
10800
10842
|
});
|
|
10801
10843
|
}
|
|
10802
|
-
function refuseMedia(row2,
|
|
10803
|
-
const extra = Object.entries(
|
|
10844
|
+
function refuseMedia(row2, present3) {
|
|
10845
|
+
const extra = Object.entries(present3).find(([, set]) => set);
|
|
10804
10846
|
if (extra) throw falMediaError(row2, `does not take ${extra[0]}`, "unsupported_option");
|
|
10805
10847
|
}
|
|
10806
10848
|
function setIf(input, key, value) {
|
|
@@ -17953,16 +17995,16 @@ function resolveVideoOptions(model, request, onUnsupported = "error") {
|
|
|
17953
17995
|
}
|
|
17954
17996
|
function checkVideoRequired(model, req) {
|
|
17955
17997
|
const c = model.constraints;
|
|
17956
|
-
const
|
|
17998
|
+
const present3 = (input) => input === "references" ? compact(req.referenceImages).length + compact(req.referenceVideos).length + compact(req.referenceAudios).length > 0 : input !== "sourceAudio" && req[input] !== void 0;
|
|
17957
17999
|
for (const input of c.requires ?? []) {
|
|
17958
|
-
if (!
|
|
18000
|
+
if (!present3(input))
|
|
17959
18001
|
throw new ModelKitError({
|
|
17960
18002
|
code: "missing_input",
|
|
17961
18003
|
message: `${model.id} requires ${input}`,
|
|
17962
18004
|
model: model.id
|
|
17963
18005
|
});
|
|
17964
18006
|
}
|
|
17965
|
-
if (c.requiresOneOf && !c.requiresOneOf.some(
|
|
18007
|
+
if (c.requiresOneOf && !c.requiresOneOf.some(present3)) {
|
|
17966
18008
|
throw new ModelKitError({
|
|
17967
18009
|
code: "missing_input",
|
|
17968
18010
|
message: `${model.id} requires one of: ${c.requiresOneOf.join(", ")}`,
|
|
@@ -18010,8 +18052,8 @@ function resolveAudioOptions(model, request, onUnsupported = "error") {
|
|
|
18010
18052
|
if (references.length > 0) merged.references = references;
|
|
18011
18053
|
else delete merged.references;
|
|
18012
18054
|
for (const input of c.requires ?? []) {
|
|
18013
|
-
const
|
|
18014
|
-
if (!
|
|
18055
|
+
const present3 = input === "references" ? references.length > 0 : input === "sourceVideo" && merged.sourceVideo !== void 0;
|
|
18056
|
+
if (!present3)
|
|
18015
18057
|
throw new ModelKitError({
|
|
18016
18058
|
code: "missing_input",
|
|
18017
18059
|
message: `${model.id} requires ${input}`,
|
|
@@ -18065,12 +18107,12 @@ function unsupported3(model, message) {
|
|
|
18065
18107
|
model: model.id
|
|
18066
18108
|
});
|
|
18067
18109
|
}
|
|
18068
|
-
function checkRequired(model,
|
|
18110
|
+
function checkRequired(model, present3) {
|
|
18069
18111
|
for (const input of model.constraints.requires ?? []) {
|
|
18070
|
-
if (
|
|
18112
|
+
if (present3[input] !== true) throw missing2(model, input);
|
|
18071
18113
|
}
|
|
18072
18114
|
const oneOf = model.constraints.requiresOneOf;
|
|
18073
|
-
if (oneOf !== void 0 && !oneOf.some((input) =>
|
|
18115
|
+
if (oneOf !== void 0 && !oneOf.some((input) => present3[input] === true)) {
|
|
18074
18116
|
throw missing2(model, `one of ${oneOf.join(", ")}`);
|
|
18075
18117
|
}
|
|
18076
18118
|
}
|
|
@@ -18402,6 +18444,39 @@ function resolveKeys(config, names, tier = "pro") {
|
|
|
18402
18444
|
}
|
|
18403
18445
|
return config.keys.pro;
|
|
18404
18446
|
}
|
|
18447
|
+
function present2(value) {
|
|
18448
|
+
return value !== void 0 && value.trim() !== "";
|
|
18449
|
+
}
|
|
18450
|
+
function overrideHolds(override, name) {
|
|
18451
|
+
if (!override || name === "aws" || !present2(override[name])) return false;
|
|
18452
|
+
return name !== "higgsfield" || present2(override.higgsfieldSecret);
|
|
18453
|
+
}
|
|
18454
|
+
function overrideCovers(override, names) {
|
|
18455
|
+
return names.filter((name) => overrideHolds(override, name));
|
|
18456
|
+
}
|
|
18457
|
+
function resolveCallKeys(config, names, tier = "pro", override) {
|
|
18458
|
+
const covered = overrideCovers(override, names);
|
|
18459
|
+
const tierNames = names.filter((name) => !covered.includes(name));
|
|
18460
|
+
const base = resolveKeys(config, tierNames, tier);
|
|
18461
|
+
if (!override || covered.length === 0)
|
|
18462
|
+
return { keys: base, source: tierSource(config, tierNames, tier), tierNames };
|
|
18463
|
+
const keys = { ...base };
|
|
18464
|
+
for (const name of covered) {
|
|
18465
|
+
const value = name === "aws" ? void 0 : override[name];
|
|
18466
|
+
if (name === "aws" || !present2(value)) continue;
|
|
18467
|
+
keys[name] = value;
|
|
18468
|
+
if (name === "higgsfield" && present2(override.higgsfieldSecret))
|
|
18469
|
+
keys.higgsfieldSecret = override.higgsfieldSecret;
|
|
18470
|
+
}
|
|
18471
|
+
return { keys, source: "byok", tierNames };
|
|
18472
|
+
}
|
|
18473
|
+
function keySourceField(source2) {
|
|
18474
|
+
return source2 === void 0 ? {} : { keySource: source2 };
|
|
18475
|
+
}
|
|
18476
|
+
function tierSource(config, names, tier) {
|
|
18477
|
+
if (tier === "enterprise") return hasAll(config.keys.enterprise, names) ? "enterprise" : "pro";
|
|
18478
|
+
return tier;
|
|
18479
|
+
}
|
|
18405
18480
|
function keysFromEnv(env, prefix = "") {
|
|
18406
18481
|
const pick2 = (...names) => names.map((n) => env[`${prefix}${n}`]).find((v) => v && v.length > 0);
|
|
18407
18482
|
const keys = {};
|
|
@@ -18426,10 +18501,10 @@ function keysFromEnv(env, prefix = "") {
|
|
|
18426
18501
|
set("fish", pick2("FISH_AUDIO_API_KEY"));
|
|
18427
18502
|
set("elevenlabs", pick2("ELEVENLABS_API_KEY"));
|
|
18428
18503
|
set("cloudflare", pick2("CF_AIG_TOKEN"));
|
|
18429
|
-
const
|
|
18504
|
+
const bearer2 = pick2("AWS_BEARER_TOKEN_BEDROCK");
|
|
18430
18505
|
const accessKeyId = pick2("AWS_ACCESS_KEY_ID");
|
|
18431
18506
|
const secretAccessKey = pick2("AWS_SECRET_ACCESS_KEY");
|
|
18432
|
-
if (
|
|
18507
|
+
if (bearer2 || accessKeyId && secretAccessKey) {
|
|
18433
18508
|
const aws = {
|
|
18434
18509
|
region: env[`${prefix}BEDROCK_REGION`] || "us-east-1"
|
|
18435
18510
|
};
|
|
@@ -18439,12 +18514,101 @@ function keysFromEnv(env, prefix = "") {
|
|
|
18439
18514
|
}
|
|
18440
18515
|
const sessionToken = pick2("AWS_SESSION_TOKEN");
|
|
18441
18516
|
if (sessionToken) aws.sessionToken = sessionToken;
|
|
18442
|
-
if (
|
|
18517
|
+
if (bearer2) aws.apiKey = bearer2;
|
|
18443
18518
|
keys.aws = aws;
|
|
18444
18519
|
}
|
|
18445
18520
|
return keys;
|
|
18446
18521
|
}
|
|
18447
18522
|
|
|
18523
|
+
// src/byok.ts
|
|
18524
|
+
var API_KEY = { id: "apiKey", label: "API key", required: true, secret: true };
|
|
18525
|
+
var BYOK_PROVIDERS = {
|
|
18526
|
+
ark: {
|
|
18527
|
+
id: "ark",
|
|
18528
|
+
label: "BytePlus ModelArk",
|
|
18529
|
+
keyName: "ark",
|
|
18530
|
+
fields: [
|
|
18531
|
+
API_KEY,
|
|
18532
|
+
{ id: "accessKeyId", label: "Access key ID", required: false, secret: true },
|
|
18533
|
+
{ id: "secretAccessKey", label: "Secret access key", required: false, secret: true },
|
|
18534
|
+
{ id: "assetGroupId", label: "Asset group ID", required: false, secret: false }
|
|
18535
|
+
]
|
|
18536
|
+
},
|
|
18537
|
+
fal: { id: "fal", label: "fal", keyName: "fal", fields: [API_KEY] },
|
|
18538
|
+
replicate: { id: "replicate", label: "Replicate", keyName: "replicate", fields: [API_KEY] },
|
|
18539
|
+
openai: { id: "openai", label: "OpenAI", keyName: "openai", fields: [API_KEY] },
|
|
18540
|
+
google: { id: "google", label: "Google AI Studio", keyName: "google", fields: [API_KEY] }
|
|
18541
|
+
};
|
|
18542
|
+
var BY_KEY_NAME = new Map(
|
|
18543
|
+
Object.values(BYOK_PROVIDERS).map((provider) => [provider.keyName, provider.id])
|
|
18544
|
+
);
|
|
18545
|
+
function byokProviderForModel(model) {
|
|
18546
|
+
const names = model.adapter === "ai-sdk-text" ? [textKeyName(model)] : ADAPTER_KEYS[model.adapter];
|
|
18547
|
+
const [name, ...rest] = names;
|
|
18548
|
+
if (name === void 0 || rest.length > 0) return null;
|
|
18549
|
+
return BY_KEY_NAME.get(name) ?? null;
|
|
18550
|
+
}
|
|
18551
|
+
function modelsPoweredBy(provider, catalog) {
|
|
18552
|
+
return [...catalog].filter((model) => byokProviderForModel(model) === provider);
|
|
18553
|
+
}
|
|
18554
|
+
function keyOverrideFor(secrets) {
|
|
18555
|
+
const override = {};
|
|
18556
|
+
for (const provider of Object.values(BYOK_PROVIDERS)) {
|
|
18557
|
+
const apiKey = secrets[provider.id]?.apiKey?.trim();
|
|
18558
|
+
if (apiKey) override[provider.keyName] = apiKey;
|
|
18559
|
+
}
|
|
18560
|
+
return override;
|
|
18561
|
+
}
|
|
18562
|
+
var bearer = (apiKey) => ({ Authorization: `Bearer ${apiKey}` });
|
|
18563
|
+
var PROBES = {
|
|
18564
|
+
ark: {
|
|
18565
|
+
url: (endpoints) => `${endpoints.ark ?? ARK_BASE_URL}/contents/generations/tasks?page_num=1&page_size=1`,
|
|
18566
|
+
headers: bearer
|
|
18567
|
+
},
|
|
18568
|
+
fal: {
|
|
18569
|
+
url: () => "https://api.fal.ai/v1/assets/collections?limit=1",
|
|
18570
|
+
headers: (apiKey) => ({ Authorization: `Key ${apiKey}` }),
|
|
18571
|
+
unverifiableStatus: 403
|
|
18572
|
+
},
|
|
18573
|
+
replicate: {
|
|
18574
|
+
url: () => "https://api.replicate.com/v1/account",
|
|
18575
|
+
headers: bearer
|
|
18576
|
+
},
|
|
18577
|
+
openai: {
|
|
18578
|
+
url: () => "https://api.openai.com/v1/models",
|
|
18579
|
+
headers: bearer,
|
|
18580
|
+
unverifiableStatus: 403
|
|
18581
|
+
},
|
|
18582
|
+
google: {
|
|
18583
|
+
url: () => "https://generativelanguage.googleapis.com/v1beta/models?pageSize=1",
|
|
18584
|
+
headers: (apiKey) => ({ "x-goog-api-key": apiKey }),
|
|
18585
|
+
unverifiableStatus: 403
|
|
18586
|
+
}
|
|
18587
|
+
};
|
|
18588
|
+
async function testProviderKey(provider, secret, opts = {}) {
|
|
18589
|
+
const apiKey = secret.apiKey?.trim();
|
|
18590
|
+
if (!apiKey) return { ok: false, reason: "invalid" };
|
|
18591
|
+
const probe = PROBES[provider];
|
|
18592
|
+
const fetchImpl = opts.fetch ?? globalThis.fetch;
|
|
18593
|
+
let res;
|
|
18594
|
+
try {
|
|
18595
|
+
res = await fetchImpl(probe.url(opts.endpoints ?? {}), {
|
|
18596
|
+
method: "GET",
|
|
18597
|
+
headers: probe.headers(apiKey),
|
|
18598
|
+
...opts.signal !== void 0 && { signal: opts.signal }
|
|
18599
|
+
});
|
|
18600
|
+
} catch (cause) {
|
|
18601
|
+
if (opts.signal?.aborted) throw cause;
|
|
18602
|
+
return { ok: false, reason: "unreachable" };
|
|
18603
|
+
}
|
|
18604
|
+
await res.body?.cancel().catch(() => void 0);
|
|
18605
|
+
if (res.ok) return { ok: true, credit: "unknown" };
|
|
18606
|
+
if (res.status === probe.unverifiableStatus) return { ok: false, reason: "unverifiable" };
|
|
18607
|
+
if (res.status === 400 || res.status === 401) return { ok: false, reason: "invalid" };
|
|
18608
|
+
if (res.status === 402 || res.status === 403) return { ok: false, reason: "denied" };
|
|
18609
|
+
return { ok: false, reason: "unreachable" };
|
|
18610
|
+
}
|
|
18611
|
+
|
|
18448
18612
|
// src/text.ts
|
|
18449
18613
|
import "ai";
|
|
18450
18614
|
import { z as z33 } from "zod";
|
|
@@ -18535,12 +18699,10 @@ function createTextSteps(initial, resolve, callerProviderOptions) {
|
|
|
18535
18699
|
const grouped = /* @__PURE__ */ new Map();
|
|
18536
18700
|
for (const [index, step] of results.entries()) {
|
|
18537
18701
|
const target = steps.get(index) ?? initial;
|
|
18538
|
-
const event =
|
|
18539
|
-
target.entry,
|
|
18540
|
-
target.
|
|
18541
|
-
|
|
18542
|
-
step.providerMetadata
|
|
18543
|
-
);
|
|
18702
|
+
const event = {
|
|
18703
|
+
...textUsageEvent(target.entry, target.provider, step.usage, step.providerMetadata),
|
|
18704
|
+
...keySourceField(target.keySource)
|
|
18705
|
+
};
|
|
18544
18706
|
const previous = grouped.get(target.entry.id);
|
|
18545
18707
|
if (previous) {
|
|
18546
18708
|
previous.quantity += event.quantity;
|
|
@@ -18598,8 +18760,9 @@ function preferredAnthropicTransport(model, routing) {
|
|
|
18598
18760
|
if (isAnthropicTransport(row2)) return row2;
|
|
18599
18761
|
return routing.anthropic ?? "direct";
|
|
18600
18762
|
}
|
|
18601
|
-
function resolveAnthropicTransport(model, config, tier, warn) {
|
|
18763
|
+
function resolveAnthropicTransport(model, config, tier, warn, keyOverride) {
|
|
18602
18764
|
if (model.adapter !== "ai-sdk-text" || textProviderOf(model) !== "anthropic") return void 0;
|
|
18765
|
+
if (overrideCovers(keyOverride, ["anthropic"]).length > 0) return "direct";
|
|
18603
18766
|
const rowValue = model.providerOptions?.["modelkit"]?.["transport"];
|
|
18604
18767
|
if (rowValue !== void 0 && !isAnthropicTransport(rowValue))
|
|
18605
18768
|
warn(
|
|
@@ -18688,8 +18851,7 @@ function providerJobMethods(kind, deps) {
|
|
|
18688
18851
|
const { methods, adapter, ctx } = target(sub.model, rest);
|
|
18689
18852
|
if (!methods.result) throw missing3(adapter, ctx.model);
|
|
18690
18853
|
const result = await methods.result(sub, ctx, webhook);
|
|
18691
|
-
const
|
|
18692
|
-
const usage5 = sub.submittedAt === void 0 ? base : deps.timed(base, sub.submittedAt);
|
|
18854
|
+
const usage5 = deps.rowUsage(ctx, result.usage, sub.submittedAt);
|
|
18693
18855
|
await deps.emit(usage5);
|
|
18694
18856
|
return { ...result, usage: usage5 };
|
|
18695
18857
|
},
|
|
@@ -18817,7 +18979,7 @@ function audioNodeMethods(deps) {
|
|
|
18817
18979
|
if (!adapter.generateSpeech) throw noMethod(adapter, model, "generate speech");
|
|
18818
18980
|
const startedAt = Date.now();
|
|
18819
18981
|
const result = await adapter.generateSpeech(resolved, ctx);
|
|
18820
|
-
return { ...result, usage: await deps.settle(
|
|
18982
|
+
return { ...result, usage: await deps.settle(ctx, result.usage, startedAt) };
|
|
18821
18983
|
},
|
|
18822
18984
|
async changeVoice(req, call = {}) {
|
|
18823
18985
|
mediaRetryOptions(call);
|
|
@@ -18832,7 +18994,7 @@ function audioNodeMethods(deps) {
|
|
|
18832
18994
|
if (!adapter.changeVoice) throw noMethod(adapter, model, "change a voice");
|
|
18833
18995
|
const startedAt = Date.now();
|
|
18834
18996
|
const result = await adapter.changeVoice(resolved, ctx);
|
|
18835
|
-
return { ...result, usage: await deps.settle(
|
|
18997
|
+
return { ...result, usage: await deps.settle(ctx, result.usage, startedAt) };
|
|
18836
18998
|
},
|
|
18837
18999
|
async lipsync(req, call = {}) {
|
|
18838
19000
|
mediaRetryOptions(call);
|
|
@@ -18847,7 +19009,7 @@ function audioNodeMethods(deps) {
|
|
|
18847
19009
|
if (!adapter.lipsync) throw noMethod(adapter, model, "lipsync");
|
|
18848
19010
|
const startedAt = Date.now();
|
|
18849
19011
|
const job = deps.wrapVideoJob(
|
|
18850
|
-
|
|
19012
|
+
ctx,
|
|
18851
19013
|
await adapter.lipsync(resolved, ctx),
|
|
18852
19014
|
warnings,
|
|
18853
19015
|
startedAt
|
|
@@ -18872,7 +19034,7 @@ function audioNodeMethods(deps) {
|
|
|
18872
19034
|
if (!adapter.transcribe) throw noMethod(adapter, model, "transcribe");
|
|
18873
19035
|
const startedAt = Date.now();
|
|
18874
19036
|
const result = await adapter.transcribe(resolved, ctx);
|
|
18875
|
-
return { ...result, usage: await deps.settle(
|
|
19037
|
+
return { ...result, usage: await deps.settle(ctx, result.usage, startedAt) };
|
|
18876
19038
|
},
|
|
18877
19039
|
async createVoice(req, call = {}) {
|
|
18878
19040
|
mediaRetryOptions(call);
|
|
@@ -18883,7 +19045,7 @@ function audioNodeMethods(deps) {
|
|
|
18883
19045
|
if (!adapter.createVoice) throw noMethod(adapter, model, "clone a voice");
|
|
18884
19046
|
const startedAt = Date.now();
|
|
18885
19047
|
const result = await adapter.createVoice(resolved, ctx);
|
|
18886
|
-
return { ...result, usage: await deps.settle(
|
|
19048
|
+
return { ...result, usage: await deps.settle(ctx, result.usage, startedAt) };
|
|
18887
19049
|
},
|
|
18888
19050
|
async designVoice(req, call = {}) {
|
|
18889
19051
|
mediaRetryOptions(call);
|
|
@@ -18898,7 +19060,7 @@ function audioNodeMethods(deps) {
|
|
|
18898
19060
|
if (!adapter.designVoice) throw noMethod(adapter, model, "design a voice");
|
|
18899
19061
|
const startedAt = Date.now();
|
|
18900
19062
|
const result = await adapter.designVoice(resolved, ctx);
|
|
18901
|
-
return { ...result, usage: await deps.settle(
|
|
19063
|
+
return { ...result, usage: await deps.settle(ctx, result.usage, startedAt) };
|
|
18902
19064
|
},
|
|
18903
19065
|
async deleteVoice(req, call = {}) {
|
|
18904
19066
|
mediaRetryOptions(call);
|
|
@@ -18934,11 +19096,11 @@ function audioNodeMethods(deps) {
|
|
|
18934
19096
|
const { audio, usage: usage5, raw } = outcome.result;
|
|
18935
19097
|
return {
|
|
18936
19098
|
audio,
|
|
18937
|
-
usage: await deps.settle(
|
|
19099
|
+
usage: await deps.settle(ctx, usage5, startedAt),
|
|
18938
19100
|
...raw !== void 0 && { raw }
|
|
18939
19101
|
};
|
|
18940
19102
|
}
|
|
18941
|
-
const job = deps.wrapVideoJob(
|
|
19103
|
+
const job = deps.wrapVideoJob(ctx, outcome.job, warnings, startedAt);
|
|
18942
19104
|
const out = await job.result(waitOptions(call, ctx.signal));
|
|
18943
19105
|
return {
|
|
18944
19106
|
video: out.video,
|
|
@@ -18950,14 +19112,28 @@ function audioNodeMethods(deps) {
|
|
|
18950
19112
|
}
|
|
18951
19113
|
|
|
18952
19114
|
// src/client.ts
|
|
18953
|
-
function
|
|
18954
|
-
const routing = config.routing ?? {};
|
|
18955
|
-
if (tier !== "sloosh") return routing;
|
|
19115
|
+
function directRouting(routing) {
|
|
18956
19116
|
const direct = { ...routing };
|
|
18957
19117
|
if (direct.text === "cloudflare") direct.text = "direct";
|
|
18958
19118
|
if (direct.fal === "cloudflare-passthrough") direct.fal = "direct";
|
|
18959
19119
|
return direct;
|
|
18960
19120
|
}
|
|
19121
|
+
function routingFor(config, model, call, transport) {
|
|
19122
|
+
const routing = config.routing ?? {};
|
|
19123
|
+
const direct = directRouting(routing);
|
|
19124
|
+
if (call.tier === "sloosh") return direct;
|
|
19125
|
+
const byok = overrideCovers(call.keyOverride, requiredKeys(model, direct, transport));
|
|
19126
|
+
return byok.length > 0 ? direct : routing;
|
|
19127
|
+
}
|
|
19128
|
+
function byokKeyMissing(provider, model) {
|
|
19129
|
+
return new ModelKitError({
|
|
19130
|
+
code: "byok_key_missing",
|
|
19131
|
+
message: `${model} needs the customer's ${provider} key and the call has none`,
|
|
19132
|
+
provider,
|
|
19133
|
+
model,
|
|
19134
|
+
retryable: false
|
|
19135
|
+
});
|
|
19136
|
+
}
|
|
18961
19137
|
function requiredKeys(model, routing, transport) {
|
|
18962
19138
|
if (model.adapter === "fal" && routing.fal === "cloudflare-passthrough") return ["cloudflare"];
|
|
18963
19139
|
if (model.adapter === "ai-sdk-text") {
|
|
@@ -19059,21 +19235,35 @@ function createModelKit(config, adapters) {
|
|
|
19059
19235
|
message: `No adapter registered for ${model.adapter}`,
|
|
19060
19236
|
model: model.id
|
|
19061
19237
|
});
|
|
19062
|
-
const transport = resolveAnthropicTransport(
|
|
19063
|
-
|
|
19238
|
+
const transport = resolveAnthropicTransport(
|
|
19239
|
+
model,
|
|
19240
|
+
config,
|
|
19241
|
+
call.tier,
|
|
19242
|
+
warnOnce,
|
|
19243
|
+
call.keyOverride
|
|
19244
|
+
);
|
|
19245
|
+
const routing = routingFor(config, model, call, transport);
|
|
19064
19246
|
const names = requiredKeys(model, routing, transport);
|
|
19247
|
+
if (call.requireOverride && overrideCovers(call.keyOverride, names).length === 0)
|
|
19248
|
+
throw byokKeyMissing(names[0] ?? model.adapter, model.id);
|
|
19249
|
+
const { keys, source: source2, tierNames } = resolveCallKeys(
|
|
19250
|
+
config,
|
|
19251
|
+
names,
|
|
19252
|
+
call.tier,
|
|
19253
|
+
call.keyOverride
|
|
19254
|
+
);
|
|
19065
19255
|
if (call.tier === "enterprise") {
|
|
19066
|
-
const missing3 = missingEnterpriseKeys(config,
|
|
19256
|
+
const missing3 = missingEnterpriseKeys(config, tierNames);
|
|
19067
19257
|
if (missing3.length > 0)
|
|
19068
19258
|
logger.warn(
|
|
19069
19259
|
`[modelkit] enterprise keys incomplete for ${model.adapter}; using pro`,
|
|
19070
19260
|
{ missing: missing3 }
|
|
19071
19261
|
);
|
|
19072
19262
|
}
|
|
19073
|
-
const keys = resolveKeys(config, names, call.tier);
|
|
19074
19263
|
const ctx = {
|
|
19075
19264
|
model,
|
|
19076
19265
|
keys,
|
|
19266
|
+
keySource: source2,
|
|
19077
19267
|
routing,
|
|
19078
19268
|
fetch: fetchImpl,
|
|
19079
19269
|
logger,
|
|
@@ -19088,7 +19278,7 @@ function createModelKit(config, adapters) {
|
|
|
19088
19278
|
const jobDeps = {
|
|
19089
19279
|
catalog,
|
|
19090
19280
|
context: (model, call) => context(model, call, []),
|
|
19091
|
-
|
|
19281
|
+
rowUsage,
|
|
19092
19282
|
emit
|
|
19093
19283
|
};
|
|
19094
19284
|
const videoToolJobs = providerJobMethods(VIDEO_TOOL_JOB, jobDeps);
|
|
@@ -19097,6 +19287,15 @@ function createModelKit(config, adapters) {
|
|
|
19097
19287
|
if (event.latencyMs !== void 0) return event;
|
|
19098
19288
|
return { ...event, latencyMs: Math.max(0, Date.now() - startedAt) };
|
|
19099
19289
|
}
|
|
19290
|
+
function rowUsage(ctx, event, startedAt) {
|
|
19291
|
+
const stamped = {
|
|
19292
|
+
...event,
|
|
19293
|
+
model: ctx.model.id,
|
|
19294
|
+
unit: ctx.model.usage.unit,
|
|
19295
|
+
...keySourceField(ctx.keySource)
|
|
19296
|
+
};
|
|
19297
|
+
return startedAt === void 0 ? stamped : timed(stamped, startedAt);
|
|
19298
|
+
}
|
|
19100
19299
|
function textTimed(event, stepCount, startedAt) {
|
|
19101
19300
|
return stepCount === 1 ? timed(event, startedAt) : event;
|
|
19102
19301
|
}
|
|
@@ -19113,6 +19312,7 @@ function createModelKit(config, adapters) {
|
|
|
19113
19312
|
}
|
|
19114
19313
|
function textTarget(model, call) {
|
|
19115
19314
|
if (!isCatalogId(model)) {
|
|
19315
|
+
if (call.requireOverride) throw byokKeyMissing(model.provider, model.modelId);
|
|
19116
19316
|
return {
|
|
19117
19317
|
entry: passthroughTextModel(model),
|
|
19118
19318
|
languageModel: model,
|
|
@@ -19136,7 +19336,8 @@ function createModelKit(config, adapters) {
|
|
|
19136
19336
|
return {
|
|
19137
19337
|
entry,
|
|
19138
19338
|
languageModel: adapter.languageModel(ctx),
|
|
19139
|
-
provider: textUsageProvider(entry, ctx.anthropicTransport)
|
|
19339
|
+
provider: textUsageProvider(entry, ctx.anthropicTransport),
|
|
19340
|
+
...keySourceField(ctx.keySource)
|
|
19140
19341
|
};
|
|
19141
19342
|
}
|
|
19142
19343
|
async function passthroughImage(req, call) {
|
|
@@ -19308,7 +19509,7 @@ function createModelKit(config, adapters) {
|
|
|
19308
19509
|
result: () => done
|
|
19309
19510
|
};
|
|
19310
19511
|
}
|
|
19311
|
-
function wrapVideoJob(
|
|
19512
|
+
function wrapVideoJob(ctx, job, warnings, startedAt) {
|
|
19312
19513
|
const result = job.result.bind(job);
|
|
19313
19514
|
let settled;
|
|
19314
19515
|
return {
|
|
@@ -19318,10 +19519,7 @@ function createModelKit(config, adapters) {
|
|
|
19318
19519
|
if (settled) return settled;
|
|
19319
19520
|
const pending = result(opts).then(
|
|
19320
19521
|
async (out) => {
|
|
19321
|
-
const usage5 =
|
|
19322
|
-
{ ...out.usage, model: model.id, unit: model.usage.unit },
|
|
19323
|
-
startedAt
|
|
19324
|
-
);
|
|
19522
|
+
const usage5 = rowUsage(ctx, out.usage, startedAt);
|
|
19325
19523
|
await emit(usage5);
|
|
19326
19524
|
return { ...out, usage: usage5 };
|
|
19327
19525
|
},
|
|
@@ -19342,8 +19540,8 @@ function createModelKit(config, adapters) {
|
|
|
19342
19540
|
const signal = combineSignals(abortSignal, call.signal);
|
|
19343
19541
|
return context(model, signal ? { ...call, signal } : call, warnings);
|
|
19344
19542
|
},
|
|
19345
|
-
async settle(
|
|
19346
|
-
const usage5 =
|
|
19543
|
+
async settle(ctx, event, startedAt) {
|
|
19544
|
+
const usage5 = rowUsage(ctx, event, startedAt);
|
|
19347
19545
|
await emit(usage5);
|
|
19348
19546
|
return usage5;
|
|
19349
19547
|
},
|
|
@@ -19356,6 +19554,8 @@ function createModelKit(config, adapters) {
|
|
|
19356
19554
|
async generateImage(req, call = {}) {
|
|
19357
19555
|
mediaRetryOptions(call);
|
|
19358
19556
|
if (!isCatalogId(req.model)) {
|
|
19557
|
+
if (call.requireOverride)
|
|
19558
|
+
throw byokKeyMissing(req.model.provider, req.model.modelId);
|
|
19359
19559
|
return passthroughImage({ ...req, model: req.model }, call);
|
|
19360
19560
|
}
|
|
19361
19561
|
const model = catalog.require(req.model);
|
|
@@ -19381,10 +19581,7 @@ function createModelKit(config, adapters) {
|
|
|
19381
19581
|
});
|
|
19382
19582
|
const startedAt = Date.now();
|
|
19383
19583
|
const result = await adapter.generateImage(request, ctx);
|
|
19384
|
-
const usage5 =
|
|
19385
|
-
{ ...result.usage, model: model.id, unit: model.usage.unit },
|
|
19386
|
-
startedAt
|
|
19387
|
-
);
|
|
19584
|
+
const usage5 = rowUsage(ctx, result.usage, startedAt);
|
|
19388
19585
|
await emit(usage5);
|
|
19389
19586
|
const images = result.images.map(toGeneratedImage);
|
|
19390
19587
|
const first = images[0];
|
|
@@ -19399,6 +19596,8 @@ function createModelKit(config, adapters) {
|
|
|
19399
19596
|
async generateVideo(req, call = {}) {
|
|
19400
19597
|
mediaRetryOptions(call);
|
|
19401
19598
|
if (!isCatalogId(req.model)) {
|
|
19599
|
+
if (call.requireOverride)
|
|
19600
|
+
throw byokKeyMissing(req.model.provider, req.model.modelId);
|
|
19402
19601
|
return passthroughVideo({ ...req, model: req.model }, call);
|
|
19403
19602
|
}
|
|
19404
19603
|
const model = catalog.require(req.model);
|
|
@@ -19424,7 +19623,7 @@ function createModelKit(config, adapters) {
|
|
|
19424
19623
|
});
|
|
19425
19624
|
const startedAt = Date.now();
|
|
19426
19625
|
const job = await adapter.generateVideo(request, ctx);
|
|
19427
|
-
return wrapVideoJob(
|
|
19626
|
+
return wrapVideoJob(ctx, job, warnings, startedAt);
|
|
19428
19627
|
},
|
|
19429
19628
|
async resumeVideo(req, jobId, call = {}) {
|
|
19430
19629
|
mediaRetryOptions(call);
|
|
@@ -19469,7 +19668,7 @@ function createModelKit(config, adapters) {
|
|
|
19469
19668
|
});
|
|
19470
19669
|
const startedAt = Date.now();
|
|
19471
19670
|
const job = adapter.resumeVideo(request, jobId, ctx);
|
|
19472
|
-
return wrapVideoJob(
|
|
19671
|
+
return wrapVideoJob(ctx, { ...job, jobId }, warnings, startedAt);
|
|
19473
19672
|
},
|
|
19474
19673
|
async generateAudio(req, call = {}) {
|
|
19475
19674
|
mediaRetryOptions(call);
|
|
@@ -19493,10 +19692,7 @@ function createModelKit(config, adapters) {
|
|
|
19493
19692
|
}
|
|
19494
19693
|
const startedAt = Date.now();
|
|
19495
19694
|
const result = await adapter.generateAudio(resolved, ctx);
|
|
19496
|
-
const usage5 =
|
|
19497
|
-
{ ...result.usage, model: model.id, unit: model.usage.unit },
|
|
19498
|
-
startedAt
|
|
19499
|
-
);
|
|
19695
|
+
const usage5 = rowUsage(ctx, result.usage, startedAt);
|
|
19500
19696
|
await emit(usage5);
|
|
19501
19697
|
return { ...result, usage: usage5 };
|
|
19502
19698
|
},
|
|
@@ -19509,7 +19705,7 @@ function createModelKit(config, adapters) {
|
|
|
19509
19705
|
return "url" in ref ? { type: "file", data: ref.url, mediaType } : { type: "file", data: ref.bytes, mediaType };
|
|
19510
19706
|
},
|
|
19511
19707
|
languageModel(modelId, call = {}) {
|
|
19512
|
-
const { entry, languageModel: model, provider } = textTarget(modelId, call);
|
|
19708
|
+
const { entry, languageModel: model, provider, keySource } = textTarget(modelId, call);
|
|
19513
19709
|
if (model.specificationVersion !== "v3")
|
|
19514
19710
|
throw new ModelKitError({
|
|
19515
19711
|
code: "unsupported_option",
|
|
@@ -19520,7 +19716,8 @@ function createModelKit(config, adapters) {
|
|
|
19520
19716
|
model,
|
|
19521
19717
|
providerOptions: withoutModelkit(entry.providerOptions),
|
|
19522
19718
|
catalog: entry,
|
|
19523
|
-
usageProvider: provider
|
|
19719
|
+
usageProvider: provider,
|
|
19720
|
+
...keySourceField(keySource)
|
|
19524
19721
|
};
|
|
19525
19722
|
},
|
|
19526
19723
|
submitVideoTool: videoToolJobs.submit,
|
|
@@ -19536,7 +19733,7 @@ function createModelKit(config, adapters) {
|
|
|
19536
19733
|
if (entry.type !== "text") return entry.adapter;
|
|
19537
19734
|
return textUsageProvider(
|
|
19538
19735
|
entry,
|
|
19539
|
-
resolveAnthropicTransport(entry, config, call.tier, warnOnce)
|
|
19736
|
+
resolveAnthropicTransport(entry, config, call.tier, warnOnce, call.keyOverride)
|
|
19540
19737
|
);
|
|
19541
19738
|
},
|
|
19542
19739
|
async generateText(options, call = {}) {
|
|
@@ -19585,7 +19782,7 @@ function createModelKit(config, adapters) {
|
|
|
19585
19782
|
});
|
|
19586
19783
|
},
|
|
19587
19784
|
async generateObject(options, call = {}) {
|
|
19588
|
-
const { entry, languageModel: languageModel2, provider } = textTarget(options.model, call);
|
|
19785
|
+
const { entry, languageModel: languageModel2, provider, keySource } = textTarget(options.model, call);
|
|
19589
19786
|
const sdkOptions = {
|
|
19590
19787
|
...options,
|
|
19591
19788
|
...textAbortOptions(options.abortSignal, call.signal),
|
|
@@ -19596,16 +19793,17 @@ function createModelKit(config, adapters) {
|
|
|
19596
19793
|
const result = await aiGenerateObject2(sdkOptions);
|
|
19597
19794
|
await emit(
|
|
19598
19795
|
timed(
|
|
19599
|
-
withRowUnit(
|
|
19600
|
-
textUsageEvent(entry, provider, result.usage, result.providerMetadata)
|
|
19601
|
-
|
|
19796
|
+
withRowUnit({
|
|
19797
|
+
...textUsageEvent(entry, provider, result.usage, result.providerMetadata),
|
|
19798
|
+
...keySourceField(keySource)
|
|
19799
|
+
}),
|
|
19602
19800
|
startedAt
|
|
19603
19801
|
)
|
|
19604
19802
|
);
|
|
19605
19803
|
return result;
|
|
19606
19804
|
},
|
|
19607
19805
|
streamObject(options, call = {}) {
|
|
19608
|
-
const { entry, languageModel: languageModel2, provider } = textTarget(options.model, call);
|
|
19806
|
+
const { entry, languageModel: languageModel2, provider, keySource } = textTarget(options.model, call);
|
|
19609
19807
|
const callerOnFinish = options.onFinish;
|
|
19610
19808
|
const startedAt = Date.now();
|
|
19611
19809
|
const sdkOptions = {
|
|
@@ -19616,14 +19814,15 @@ function createModelKit(config, adapters) {
|
|
|
19616
19814
|
onFinish: async (event) => {
|
|
19617
19815
|
await emit(
|
|
19618
19816
|
timed(
|
|
19619
|
-
withRowUnit(
|
|
19620
|
-
textUsageEvent(
|
|
19817
|
+
withRowUnit({
|
|
19818
|
+
...textUsageEvent(
|
|
19621
19819
|
entry,
|
|
19622
19820
|
provider,
|
|
19623
19821
|
event.usage,
|
|
19624
19822
|
event.providerMetadata
|
|
19625
|
-
)
|
|
19626
|
-
|
|
19823
|
+
),
|
|
19824
|
+
...keySourceField(keySource)
|
|
19825
|
+
}),
|
|
19627
19826
|
startedAt
|
|
19628
19827
|
)
|
|
19629
19828
|
);
|
|
@@ -19666,6 +19865,7 @@ export {
|
|
|
19666
19865
|
ADAPTER_KEYS,
|
|
19667
19866
|
ARRAY_INPUT_SPEC_KEYS,
|
|
19668
19867
|
AUDIO_INPUT_SPEC_KEYS,
|
|
19868
|
+
BYOK_PROVIDERS,
|
|
19669
19869
|
Catalog,
|
|
19670
19870
|
CatalogModelSchema,
|
|
19671
19871
|
CatalogModelSchemaBase,
|
|
@@ -19690,6 +19890,7 @@ export {
|
|
|
19690
19890
|
aiSdkTextAdapter,
|
|
19691
19891
|
arkAdapter,
|
|
19692
19892
|
aspectRatioToSize,
|
|
19893
|
+
byokProviderForModel,
|
|
19693
19894
|
classifyHttpError,
|
|
19694
19895
|
compareCatalogOrder,
|
|
19695
19896
|
createDefaultModelKit,
|
|
@@ -19717,6 +19918,7 @@ export {
|
|
|
19717
19918
|
isListed,
|
|
19718
19919
|
isListedOn,
|
|
19719
19920
|
isModelKitError,
|
|
19921
|
+
keyOverrideFor,
|
|
19720
19922
|
keysFromEnv,
|
|
19721
19923
|
languageModel,
|
|
19722
19924
|
liveCatalog,
|
|
@@ -19733,6 +19935,7 @@ export {
|
|
|
19733
19935
|
model3dSeedFits,
|
|
19734
19936
|
model3dSkus,
|
|
19735
19937
|
model3dTexture,
|
|
19938
|
+
modelsPoweredBy,
|
|
19736
19939
|
nearestAspectRatio,
|
|
19737
19940
|
normalizeExposure,
|
|
19738
19941
|
openaiImageAdapter,
|
|
@@ -19763,6 +19966,7 @@ export {
|
|
|
19763
19966
|
streamObject,
|
|
19764
19967
|
streamText,
|
|
19765
19968
|
takesTargetAspectRatio,
|
|
19969
|
+
testProviderKey,
|
|
19766
19970
|
textUsageEvent,
|
|
19767
19971
|
toGeneratedImage,
|
|
19768
19972
|
validateInputSpec,
|