@shop-os/modelkit 0.2.10 → 0.2.11
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 +11 -0
- package/README.md +61 -0
- package/dist/catalog.cjs +12 -1
- package/dist/catalog.cjs.map +1 -1
- package/dist/catalog.d.cts +23 -4
- package/dist/catalog.d.ts +23 -4
- package/dist/catalog.js +12 -1
- package/dist/catalog.js.map +1 -1
- package/dist/index.cjs +199 -23
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +29 -5
- package/dist/index.d.ts +29 -5
- package/dist/index.js +196 -21
- package/dist/index.js.map +1 -1
- package/package.json +3 -2
package/dist/index.d.cts
CHANGED
|
@@ -371,17 +371,36 @@ type ProviderKeys = Partial<Record<ProviderKeyName, string>> & {
|
|
|
371
371
|
higgsfieldSecret?: string;
|
|
372
372
|
/** Bedrock runtime credentials for Anthropic models when routing.anthropic = "bedrock". */
|
|
373
373
|
aws?: {
|
|
374
|
-
|
|
375
|
-
secretAccessKey: string;
|
|
374
|
+
/** Bedrock region. Must serve the chosen inference profile (us-east-1 for "us"). */
|
|
376
375
|
region: string;
|
|
376
|
+
accessKeyId?: string;
|
|
377
|
+
secretAccessKey?: string;
|
|
377
378
|
sessionToken?: string;
|
|
379
|
+
/** Bedrock API key (AWS_BEARER_TOKEN_BEDROCK). Wins over SigV4. */
|
|
380
|
+
apiKey?: string;
|
|
381
|
+
/** For ECS task roles and other chains. The kit has no AWS SDK dependency; the app passes e.g. defaultProvider(). */
|
|
382
|
+
credentialProvider?: () => PromiseLike<{
|
|
383
|
+
accessKeyId: string;
|
|
384
|
+
secretAccessKey: string;
|
|
385
|
+
sessionToken?: string;
|
|
386
|
+
}>;
|
|
378
387
|
};
|
|
379
388
|
};
|
|
389
|
+
/** Key names a call can require, including the Bedrock credentials object. */
|
|
390
|
+
type RequiredKeyName = ProviderKeyName | "aws";
|
|
391
|
+
/** True when region is set AND (apiKey OR credentialProvider OR both static keys). */
|
|
392
|
+
declare function hasAwsCredentials(aws: ProviderKeys["aws"]): aws is NonNullable<ProviderKeys["aws"]>;
|
|
380
393
|
interface Routing {
|
|
381
394
|
/** Text models: direct provider or the Cloudflare AI Gateway. */
|
|
382
395
|
text?: "direct" | "cloudflare";
|
|
383
|
-
/**
|
|
396
|
+
/**
|
|
397
|
+
* Anthropic chat via Bedrock or the Anthropic API. Default "direct". A row's
|
|
398
|
+
* `providerOptions.modelkit.transport` wins over this. When the chosen transport has
|
|
399
|
+
* no credentials and the other one has, the kit uses the other one and warns.
|
|
400
|
+
*/
|
|
384
401
|
anthropic?: "direct" | "bedrock";
|
|
402
|
+
/** Inference profile prefix for Bedrock ids. Default "us". */
|
|
403
|
+
bedrockProfile?: "us" | "global" | "eu" | "jp" | "au";
|
|
385
404
|
/** fal from geo-blocked regions goes through the Cloudflare passthrough. */
|
|
386
405
|
fal?: "direct" | "cloudflare-passthrough";
|
|
387
406
|
cloudflare?: {
|
|
@@ -559,7 +578,7 @@ declare const ADAPTER_KEYS: Record<AdapterId, ProviderKeyName[]>;
|
|
|
559
578
|
* enterprise tier; otherwise the pro keys are used. Mirrors trigger-workflows
|
|
560
579
|
* enterprise-keys.ts, extended to Ark and Prodia.
|
|
561
580
|
*/
|
|
562
|
-
declare function resolveKeys(config: ModelKitConfig, names:
|
|
581
|
+
declare function resolveKeys(config: ModelKitConfig, names: RequiredKeyName[], tier?: "pro" | "enterprise"): ProviderKeys;
|
|
563
582
|
/** Build a ProviderKeys map from env with the given prefix ("" for pro, "ENTERPRISE_" for enterprise). */
|
|
564
583
|
declare function keysFromEnv(env: NodeJS.ProcessEnv, prefix?: string): ProviderKeys;
|
|
565
584
|
|
|
@@ -588,11 +607,16 @@ declare function pollUntil<T>(check: () => Promise<T | undefined>, opts: {
|
|
|
588
607
|
maxIntervalMs?: number;
|
|
589
608
|
}): Promise<T>;
|
|
590
609
|
|
|
610
|
+
declare const ANTHROPIC_TRANSPORTS: readonly ["direct", "bedrock"];
|
|
611
|
+
type AnthropicTransport = (typeof ANTHROPIC_TRANSPORTS)[number];
|
|
612
|
+
|
|
591
613
|
/** Everything an adapter needs for one call. Resolved by the core before dispatch. */
|
|
592
614
|
interface AdapterContext {
|
|
593
615
|
model: CatalogModel;
|
|
594
616
|
keys: ProviderKeys;
|
|
595
617
|
routing: Routing;
|
|
618
|
+
/** Resolved transport of an Anthropic text row (see anthropic-transport.ts); unset means direct. */
|
|
619
|
+
anthropicTransport?: AnthropicTransport;
|
|
596
620
|
endpoints?: AdapterEndpoints;
|
|
597
621
|
fetch: typeof fetch;
|
|
598
622
|
logger: Pick<Console, "debug" | "info" | "warn" | "error">;
|
|
@@ -782,4 +806,4 @@ declare function describeThrown(cause: unknown): ThrownErrorInfo;
|
|
|
782
806
|
/** Add the AI SDK `GeneratedFile` accessors to adapter image bytes. base64 is computed on first read. */
|
|
783
807
|
declare function toGeneratedImage(image: ImageBytes): GeneratedImage;
|
|
784
808
|
|
|
785
|
-
export { ADAPTER_IDS, ADAPTER_KEYS, type Adapter, type AdapterContext, type AdapterEndpoints, type AdapterId, type AdapterRegistry, type AiTextProviderOptions, type AspectRatio, type AudioRequest, type AudioResult, type CallContext, Catalog, type CatalogAuth, type CatalogCache, type CatalogCapabilities, type CatalogDisplay, type CatalogEnvelope, type CatalogModel, CatalogModelSchema, type CatalogOrigin, CatalogSchema, type CatalogSource, type CatalogTextModel, DEFAULT_ADAPTERS, type DefaultObjectOutput, type Exposure, ExposureSchema, type GeneratedImage, type ImageBytes, type ImageCallOptions, type ImageCallResult, type ImageQuality, type ImageRequest, type ImageResult, type ImageSafetySetting, type ImageSize, type JsonObject, JsonObjectSchema, type JsonPrimitive, type JsonValue, JsonValueSchema, type LanguageModelHandle, type Lifecycle, type LiveCatalogState, MODELS, type MediaPart, type MediaRef, type ModelConstraints, type ModelKit, type ModelKitConfig, ModelKitError, type ModelKitErrorCode, type ModelKitErrorInit, type ModelType, type ModelkitGenerateObjectOptions, type ModelkitGenerateTextOptions, type ModelkitStreamObjectOptions, type ModelkitStreamTextOptions, type ObjectOutput, type ObjectResult, type OnUnsupported, type OutputFormat, type PricingKind, type PrimeCatalogResult, type ProviderErrorBody, type ProviderKeyName, type ProviderKeys, type ProviderOptionValue, type ProviderOptions, type ReferenceLimits, type RequiredInput, type ResolveResult, type Routing, SURFACES, type SupportedOption, type Surface, SurfaceSchema, type TextMethods, type TextModelInstance, type UpscaleOptions, type UsageEvent, type UsageModality, type UsageUnit, type VideoCallJob, type VideoCallOptions, type VideoJob, type VideoModel, type VideoRequest, type VideoResolution, type VideoResult, type Warning, aiSdkTextAdapter, arkAdapter, aspectRatioToSize, classifyHttpError, compareCatalogOrder, createDefaultModelKit, createModelKit, describe, describeThrown, generateImage as experimental_generateImage, falAdapter, fileCatalogCache, generateAudio, generateImage, generateObject, generateText, generateVideo, googleGenaiAdapter, googleImageAdapter, higgsfieldAdapter, isListed, isListedOn, isModelKitError, keysFromEnv, languageModel, liveCatalog, liveState, mergeTextProviderOptions, nearestAspectRatio, normalizeExposure, openaiImageAdapter, passthroughTextModel, pollUntil, prepareMediaPart, primeCatalog, prodiaAdapter, readErrorBody, replicateAdapter, resetLiveCatalog, resolveAudioOptions, resolveImageOptions, resolveKeys, resolveVideoOptions, shouldRetry, sleep, sortCatalogRows, streamObject, streamText, textUsageEvent, toGeneratedImage, withRetry, xaiVideoAdapter };
|
|
809
|
+
export { ADAPTER_IDS, ADAPTER_KEYS, type Adapter, type AdapterContext, type AdapterEndpoints, type AdapterId, type AdapterRegistry, type AiTextProviderOptions, type AspectRatio, type AudioRequest, type AudioResult, type CallContext, Catalog, type CatalogAuth, type CatalogCache, type CatalogCapabilities, type CatalogDisplay, type CatalogEnvelope, type CatalogModel, CatalogModelSchema, type CatalogOrigin, CatalogSchema, type CatalogSource, type CatalogTextModel, DEFAULT_ADAPTERS, type DefaultObjectOutput, type Exposure, ExposureSchema, type GeneratedImage, type ImageBytes, type ImageCallOptions, type ImageCallResult, type ImageQuality, type ImageRequest, type ImageResult, type ImageSafetySetting, type ImageSize, type JsonObject, JsonObjectSchema, type JsonPrimitive, type JsonValue, JsonValueSchema, type LanguageModelHandle, type Lifecycle, type LiveCatalogState, MODELS, type MediaPart, type MediaRef, type ModelConstraints, type ModelKit, type ModelKitConfig, ModelKitError, type ModelKitErrorCode, type ModelKitErrorInit, type ModelType, type ModelkitGenerateObjectOptions, type ModelkitGenerateTextOptions, type ModelkitStreamObjectOptions, type ModelkitStreamTextOptions, type ObjectOutput, type ObjectResult, type OnUnsupported, type OutputFormat, type PricingKind, type PrimeCatalogResult, type ProviderErrorBody, type ProviderKeyName, type ProviderKeys, type ProviderOptionValue, type ProviderOptions, type ReferenceLimits, type RequiredInput, type RequiredKeyName, type ResolveResult, type Routing, SURFACES, type SupportedOption, type Surface, SurfaceSchema, type TextMethods, type TextModelInstance, type UpscaleOptions, type UsageEvent, type UsageModality, type UsageUnit, type VideoCallJob, type VideoCallOptions, type VideoJob, type VideoModel, type VideoRequest, type VideoResolution, type VideoResult, type Warning, aiSdkTextAdapter, arkAdapter, aspectRatioToSize, classifyHttpError, compareCatalogOrder, createDefaultModelKit, createModelKit, describe, describeThrown, generateImage as experimental_generateImage, falAdapter, fileCatalogCache, generateAudio, generateImage, generateObject, generateText, generateVideo, googleGenaiAdapter, googleImageAdapter, hasAwsCredentials, higgsfieldAdapter, isListed, isListedOn, isModelKitError, keysFromEnv, languageModel, liveCatalog, liveState, mergeTextProviderOptions, nearestAspectRatio, normalizeExposure, openaiImageAdapter, passthroughTextModel, pollUntil, prepareMediaPart, primeCatalog, prodiaAdapter, readErrorBody, replicateAdapter, resetLiveCatalog, resolveAudioOptions, resolveImageOptions, resolveKeys, resolveVideoOptions, shouldRetry, sleep, sortCatalogRows, streamObject, streamText, textUsageEvent, toGeneratedImage, withRetry, xaiVideoAdapter };
|
package/dist/index.d.ts
CHANGED
|
@@ -371,17 +371,36 @@ type ProviderKeys = Partial<Record<ProviderKeyName, string>> & {
|
|
|
371
371
|
higgsfieldSecret?: string;
|
|
372
372
|
/** Bedrock runtime credentials for Anthropic models when routing.anthropic = "bedrock". */
|
|
373
373
|
aws?: {
|
|
374
|
-
|
|
375
|
-
secretAccessKey: string;
|
|
374
|
+
/** Bedrock region. Must serve the chosen inference profile (us-east-1 for "us"). */
|
|
376
375
|
region: string;
|
|
376
|
+
accessKeyId?: string;
|
|
377
|
+
secretAccessKey?: string;
|
|
377
378
|
sessionToken?: string;
|
|
379
|
+
/** Bedrock API key (AWS_BEARER_TOKEN_BEDROCK). Wins over SigV4. */
|
|
380
|
+
apiKey?: string;
|
|
381
|
+
/** For ECS task roles and other chains. The kit has no AWS SDK dependency; the app passes e.g. defaultProvider(). */
|
|
382
|
+
credentialProvider?: () => PromiseLike<{
|
|
383
|
+
accessKeyId: string;
|
|
384
|
+
secretAccessKey: string;
|
|
385
|
+
sessionToken?: string;
|
|
386
|
+
}>;
|
|
378
387
|
};
|
|
379
388
|
};
|
|
389
|
+
/** Key names a call can require, including the Bedrock credentials object. */
|
|
390
|
+
type RequiredKeyName = ProviderKeyName | "aws";
|
|
391
|
+
/** True when region is set AND (apiKey OR credentialProvider OR both static keys). */
|
|
392
|
+
declare function hasAwsCredentials(aws: ProviderKeys["aws"]): aws is NonNullable<ProviderKeys["aws"]>;
|
|
380
393
|
interface Routing {
|
|
381
394
|
/** Text models: direct provider or the Cloudflare AI Gateway. */
|
|
382
395
|
text?: "direct" | "cloudflare";
|
|
383
|
-
/**
|
|
396
|
+
/**
|
|
397
|
+
* Anthropic chat via Bedrock or the Anthropic API. Default "direct". A row's
|
|
398
|
+
* `providerOptions.modelkit.transport` wins over this. When the chosen transport has
|
|
399
|
+
* no credentials and the other one has, the kit uses the other one and warns.
|
|
400
|
+
*/
|
|
384
401
|
anthropic?: "direct" | "bedrock";
|
|
402
|
+
/** Inference profile prefix for Bedrock ids. Default "us". */
|
|
403
|
+
bedrockProfile?: "us" | "global" | "eu" | "jp" | "au";
|
|
385
404
|
/** fal from geo-blocked regions goes through the Cloudflare passthrough. */
|
|
386
405
|
fal?: "direct" | "cloudflare-passthrough";
|
|
387
406
|
cloudflare?: {
|
|
@@ -559,7 +578,7 @@ declare const ADAPTER_KEYS: Record<AdapterId, ProviderKeyName[]>;
|
|
|
559
578
|
* enterprise tier; otherwise the pro keys are used. Mirrors trigger-workflows
|
|
560
579
|
* enterprise-keys.ts, extended to Ark and Prodia.
|
|
561
580
|
*/
|
|
562
|
-
declare function resolveKeys(config: ModelKitConfig, names:
|
|
581
|
+
declare function resolveKeys(config: ModelKitConfig, names: RequiredKeyName[], tier?: "pro" | "enterprise"): ProviderKeys;
|
|
563
582
|
/** Build a ProviderKeys map from env with the given prefix ("" for pro, "ENTERPRISE_" for enterprise). */
|
|
564
583
|
declare function keysFromEnv(env: NodeJS.ProcessEnv, prefix?: string): ProviderKeys;
|
|
565
584
|
|
|
@@ -588,11 +607,16 @@ declare function pollUntil<T>(check: () => Promise<T | undefined>, opts: {
|
|
|
588
607
|
maxIntervalMs?: number;
|
|
589
608
|
}): Promise<T>;
|
|
590
609
|
|
|
610
|
+
declare const ANTHROPIC_TRANSPORTS: readonly ["direct", "bedrock"];
|
|
611
|
+
type AnthropicTransport = (typeof ANTHROPIC_TRANSPORTS)[number];
|
|
612
|
+
|
|
591
613
|
/** Everything an adapter needs for one call. Resolved by the core before dispatch. */
|
|
592
614
|
interface AdapterContext {
|
|
593
615
|
model: CatalogModel;
|
|
594
616
|
keys: ProviderKeys;
|
|
595
617
|
routing: Routing;
|
|
618
|
+
/** Resolved transport of an Anthropic text row (see anthropic-transport.ts); unset means direct. */
|
|
619
|
+
anthropicTransport?: AnthropicTransport;
|
|
596
620
|
endpoints?: AdapterEndpoints;
|
|
597
621
|
fetch: typeof fetch;
|
|
598
622
|
logger: Pick<Console, "debug" | "info" | "warn" | "error">;
|
|
@@ -782,4 +806,4 @@ declare function describeThrown(cause: unknown): ThrownErrorInfo;
|
|
|
782
806
|
/** Add the AI SDK `GeneratedFile` accessors to adapter image bytes. base64 is computed on first read. */
|
|
783
807
|
declare function toGeneratedImage(image: ImageBytes): GeneratedImage;
|
|
784
808
|
|
|
785
|
-
export { ADAPTER_IDS, ADAPTER_KEYS, type Adapter, type AdapterContext, type AdapterEndpoints, type AdapterId, type AdapterRegistry, type AiTextProviderOptions, type AspectRatio, type AudioRequest, type AudioResult, type CallContext, Catalog, type CatalogAuth, type CatalogCache, type CatalogCapabilities, type CatalogDisplay, type CatalogEnvelope, type CatalogModel, CatalogModelSchema, type CatalogOrigin, CatalogSchema, type CatalogSource, type CatalogTextModel, DEFAULT_ADAPTERS, type DefaultObjectOutput, type Exposure, ExposureSchema, type GeneratedImage, type ImageBytes, type ImageCallOptions, type ImageCallResult, type ImageQuality, type ImageRequest, type ImageResult, type ImageSafetySetting, type ImageSize, type JsonObject, JsonObjectSchema, type JsonPrimitive, type JsonValue, JsonValueSchema, type LanguageModelHandle, type Lifecycle, type LiveCatalogState, MODELS, type MediaPart, type MediaRef, type ModelConstraints, type ModelKit, type ModelKitConfig, ModelKitError, type ModelKitErrorCode, type ModelKitErrorInit, type ModelType, type ModelkitGenerateObjectOptions, type ModelkitGenerateTextOptions, type ModelkitStreamObjectOptions, type ModelkitStreamTextOptions, type ObjectOutput, type ObjectResult, type OnUnsupported, type OutputFormat, type PricingKind, type PrimeCatalogResult, type ProviderErrorBody, type ProviderKeyName, type ProviderKeys, type ProviderOptionValue, type ProviderOptions, type ReferenceLimits, type RequiredInput, type ResolveResult, type Routing, SURFACES, type SupportedOption, type Surface, SurfaceSchema, type TextMethods, type TextModelInstance, type UpscaleOptions, type UsageEvent, type UsageModality, type UsageUnit, type VideoCallJob, type VideoCallOptions, type VideoJob, type VideoModel, type VideoRequest, type VideoResolution, type VideoResult, type Warning, aiSdkTextAdapter, arkAdapter, aspectRatioToSize, classifyHttpError, compareCatalogOrder, createDefaultModelKit, createModelKit, describe, describeThrown, generateImage as experimental_generateImage, falAdapter, fileCatalogCache, generateAudio, generateImage, generateObject, generateText, generateVideo, googleGenaiAdapter, googleImageAdapter, higgsfieldAdapter, isListed, isListedOn, isModelKitError, keysFromEnv, languageModel, liveCatalog, liveState, mergeTextProviderOptions, nearestAspectRatio, normalizeExposure, openaiImageAdapter, passthroughTextModel, pollUntil, prepareMediaPart, primeCatalog, prodiaAdapter, readErrorBody, replicateAdapter, resetLiveCatalog, resolveAudioOptions, resolveImageOptions, resolveKeys, resolveVideoOptions, shouldRetry, sleep, sortCatalogRows, streamObject, streamText, textUsageEvent, toGeneratedImage, withRetry, xaiVideoAdapter };
|
|
809
|
+
export { ADAPTER_IDS, ADAPTER_KEYS, type Adapter, type AdapterContext, type AdapterEndpoints, type AdapterId, type AdapterRegistry, type AiTextProviderOptions, type AspectRatio, type AudioRequest, type AudioResult, type CallContext, Catalog, type CatalogAuth, type CatalogCache, type CatalogCapabilities, type CatalogDisplay, type CatalogEnvelope, type CatalogModel, CatalogModelSchema, type CatalogOrigin, CatalogSchema, type CatalogSource, type CatalogTextModel, DEFAULT_ADAPTERS, type DefaultObjectOutput, type Exposure, ExposureSchema, type GeneratedImage, type ImageBytes, type ImageCallOptions, type ImageCallResult, type ImageQuality, type ImageRequest, type ImageResult, type ImageSafetySetting, type ImageSize, type JsonObject, JsonObjectSchema, type JsonPrimitive, type JsonValue, JsonValueSchema, type LanguageModelHandle, type Lifecycle, type LiveCatalogState, MODELS, type MediaPart, type MediaRef, type ModelConstraints, type ModelKit, type ModelKitConfig, ModelKitError, type ModelKitErrorCode, type ModelKitErrorInit, type ModelType, type ModelkitGenerateObjectOptions, type ModelkitGenerateTextOptions, type ModelkitStreamObjectOptions, type ModelkitStreamTextOptions, type ObjectOutput, type ObjectResult, type OnUnsupported, type OutputFormat, type PricingKind, type PrimeCatalogResult, type ProviderErrorBody, type ProviderKeyName, type ProviderKeys, type ProviderOptionValue, type ProviderOptions, type ReferenceLimits, type RequiredInput, type RequiredKeyName, type ResolveResult, type Routing, SURFACES, type SupportedOption, type Surface, SurfaceSchema, type TextMethods, type TextModelInstance, type UpscaleOptions, type UsageEvent, type UsageModality, type UsageUnit, type VideoCallJob, type VideoCallOptions, type VideoJob, type VideoModel, type VideoRequest, type VideoResolution, type VideoResult, type Warning, aiSdkTextAdapter, arkAdapter, aspectRatioToSize, classifyHttpError, compareCatalogOrder, createDefaultModelKit, createModelKit, describe, describeThrown, generateImage as experimental_generateImage, falAdapter, fileCatalogCache, generateAudio, generateImage, generateObject, generateText, generateVideo, googleGenaiAdapter, googleImageAdapter, hasAwsCredentials, higgsfieldAdapter, isListed, isListedOn, isModelKitError, keysFromEnv, languageModel, liveCatalog, liveState, mergeTextProviderOptions, nearestAspectRatio, normalizeExposure, openaiImageAdapter, passthroughTextModel, pollUntil, prepareMediaPart, primeCatalog, prodiaAdapter, readErrorBody, replicateAdapter, resetLiveCatalog, resolveAudioOptions, resolveImageOptions, resolveKeys, resolveVideoOptions, shouldRetry, sleep, sortCatalogRows, streamObject, streamText, textUsageEvent, toGeneratedImage, withRetry, xaiVideoAdapter };
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
2
|
export * from "ai";
|
|
3
3
|
|
|
4
|
+
// src/types.ts
|
|
5
|
+
function hasAwsCredentials(aws) {
|
|
6
|
+
if (!aws || !aws.region) return false;
|
|
7
|
+
if (aws.apiKey) return true;
|
|
8
|
+
if (aws.credentialProvider) return true;
|
|
9
|
+
return Boolean(aws.accessKeyId && aws.secretAccessKey);
|
|
10
|
+
}
|
|
11
|
+
|
|
4
12
|
// src/errors.ts
|
|
5
13
|
var ModelKitError = class extends Error {
|
|
6
14
|
code;
|
|
@@ -2037,7 +2045,18 @@ var CatalogModelSchemaBase = z.looseObject({
|
|
|
2037
2045
|
});
|
|
2038
2046
|
}
|
|
2039
2047
|
});
|
|
2040
|
-
var CatalogModelSchema = CatalogModelSchemaBase
|
|
2048
|
+
var CatalogModelSchema = CatalogModelSchemaBase.superRefine(
|
|
2049
|
+
(row, ctx) => {
|
|
2050
|
+
const transport = row.providerOptions?.["modelkit"]?.["transport"];
|
|
2051
|
+
if (transport !== void 0 && transport !== "direct" && transport !== "bedrock") {
|
|
2052
|
+
ctx.addIssue({
|
|
2053
|
+
code: "custom",
|
|
2054
|
+
path: ["providerOptions", "modelkit", "transport"],
|
|
2055
|
+
message: 'transport must be "direct" or "bedrock"'
|
|
2056
|
+
});
|
|
2057
|
+
}
|
|
2058
|
+
}
|
|
2059
|
+
);
|
|
2041
2060
|
var CatalogSchema = z.array(CatalogModelSchemaBase).superRefine((rows, ctx) => {
|
|
2042
2061
|
const seenIds = /* @__PURE__ */ new Map();
|
|
2043
2062
|
rows.forEach((row, index) => {
|
|
@@ -2642,9 +2661,12 @@ var ADAPTER_KEYS = {
|
|
|
2642
2661
|
function hasAll(keys, names) {
|
|
2643
2662
|
if (!keys) return false;
|
|
2644
2663
|
return names.every(
|
|
2645
|
-
(n) => Boolean(keys[n]) && (n !== "higgsfield" || Boolean(keys.higgsfieldSecret))
|
|
2664
|
+
(n) => n === "aws" ? hasAwsCredentials(keys.aws) : Boolean(keys[n]) && (n !== "higgsfield" || Boolean(keys.higgsfieldSecret))
|
|
2646
2665
|
);
|
|
2647
2666
|
}
|
|
2667
|
+
function hasKey(keys, name) {
|
|
2668
|
+
return hasAll(keys, [name]);
|
|
2669
|
+
}
|
|
2648
2670
|
function missingEnterpriseKeys(config, names) {
|
|
2649
2671
|
return names.filter((name) => !hasAll(config.keys.enterprise, [name]));
|
|
2650
2672
|
}
|
|
@@ -2681,6 +2703,22 @@ function keysFromEnv(env, prefix = "") {
|
|
|
2681
2703
|
set("higgsfield", pick("HIGGSFIELD_API_KEY"));
|
|
2682
2704
|
set("higgsfieldSecret", pick("HIGGSFIELD_API_SECRET"));
|
|
2683
2705
|
set("cloudflare", pick("CLOUDFLARE_AI_GATEWAY_TOKEN", "CF_AIG_TOKEN"));
|
|
2706
|
+
const bearer = pick("AWS_BEARER_TOKEN_BEDROCK");
|
|
2707
|
+
const accessKeyId = pick("AWS_ACCESS_KEY_ID");
|
|
2708
|
+
const secretAccessKey = pick("AWS_SECRET_ACCESS_KEY");
|
|
2709
|
+
if (bearer || accessKeyId && secretAccessKey) {
|
|
2710
|
+
const aws = {
|
|
2711
|
+
region: env[`${prefix}BEDROCK_REGION`] || "us-east-1"
|
|
2712
|
+
};
|
|
2713
|
+
if (accessKeyId && secretAccessKey) {
|
|
2714
|
+
aws.accessKeyId = accessKeyId;
|
|
2715
|
+
aws.secretAccessKey = secretAccessKey;
|
|
2716
|
+
}
|
|
2717
|
+
const sessionToken = pick("AWS_SESSION_TOKEN");
|
|
2718
|
+
if (sessionToken) aws.sessionToken = sessionToken;
|
|
2719
|
+
if (bearer) aws.apiKey = bearer;
|
|
2720
|
+
keys.aws = aws;
|
|
2721
|
+
}
|
|
2684
2722
|
return keys;
|
|
2685
2723
|
}
|
|
2686
2724
|
|
|
@@ -3016,6 +3054,7 @@ function toGeneratedImage(image) {
|
|
|
3016
3054
|
}
|
|
3017
3055
|
|
|
3018
3056
|
// src/adapters/ai-sdk-text.ts
|
|
3057
|
+
import { createBedrockAnthropic } from "@ai-sdk/amazon-bedrock/anthropic";
|
|
3019
3058
|
import { createAnthropic } from "@ai-sdk/anthropic";
|
|
3020
3059
|
import { createGoogleGenerativeAI } from "@ai-sdk/google";
|
|
3021
3060
|
import { createOpenAI } from "@ai-sdk/openai";
|
|
@@ -3067,16 +3106,47 @@ function detectTextProvider(modelId) {
|
|
|
3067
3106
|
message: `ai-sdk-text cannot detect a provider for "${modelId}". Set providerOptions.provider to one of ${TEXT_PROVIDERS.join(", ")}.`
|
|
3068
3107
|
});
|
|
3069
3108
|
}
|
|
3070
|
-
function textKeyName(model,
|
|
3071
|
-
|
|
3109
|
+
function textKeyName(model, transport) {
|
|
3110
|
+
const provider = textProviderOf(model);
|
|
3111
|
+
return provider === "anthropic" && transport === "bedrock" ? "aws" : provider;
|
|
3072
3112
|
}
|
|
3073
3113
|
function textProviderOf(model) {
|
|
3074
3114
|
const explicit = model.providerOptions?.["modelkit"]?.["provider"];
|
|
3075
3115
|
return isTextProvider(explicit) ? explicit : detectTextProvider(model.providerModelId);
|
|
3076
3116
|
}
|
|
3077
|
-
function textUsesCloudflareGateway(model, routing) {
|
|
3117
|
+
function textUsesCloudflareGateway(model, routing, transport) {
|
|
3078
3118
|
if (routing.text !== "cloudflare") return false;
|
|
3079
|
-
|
|
3119
|
+
const provider = textProviderOf(model);
|
|
3120
|
+
if (provider === "anthropic" && transport === "bedrock") return false;
|
|
3121
|
+
return GATEWAY_SLUGS[provider] !== void 0;
|
|
3122
|
+
}
|
|
3123
|
+
var BEDROCK_DATED_MODEL_IDS = {
|
|
3124
|
+
"claude-haiku-4-5": "anthropic.claude-haiku-4-5-20251001-v1:0",
|
|
3125
|
+
"claude-haiku-4-5-20251001": "anthropic.claude-haiku-4-5-20251001-v1:0",
|
|
3126
|
+
"claude-sonnet-4-5": "anthropic.claude-sonnet-4-5-20250929-v1:0",
|
|
3127
|
+
"claude-sonnet-4-5-20250929": "anthropic.claude-sonnet-4-5-20250929-v1:0"
|
|
3128
|
+
};
|
|
3129
|
+
var BEDROCK_PROFILE_PREFIXES = ["us.", "global.", "eu.", "jp.", "au.", "apac."];
|
|
3130
|
+
function toBedrockModelId(model, routing) {
|
|
3131
|
+
const profile = routing.bedrockProfile ?? "us";
|
|
3132
|
+
const override = model.providerOptions?.["modelkit"]?.["bedrockModelId"];
|
|
3133
|
+
if (typeof override === "string" && override.length > 0) {
|
|
3134
|
+
if (BEDROCK_PROFILE_PREFIXES.some((prefix) => override.startsWith(prefix))) return override;
|
|
3135
|
+
if (override.startsWith("anthropic.")) return `${profile}.${override}`;
|
|
3136
|
+
return override;
|
|
3137
|
+
}
|
|
3138
|
+
const id = model.providerModelId;
|
|
3139
|
+
if (BEDROCK_PROFILE_PREFIXES.some((prefix) => id.startsWith(prefix))) return id;
|
|
3140
|
+
const dated = BEDROCK_DATED_MODEL_IDS[id];
|
|
3141
|
+
if (dated) return `${profile}.${dated}`;
|
|
3142
|
+
if (id.startsWith("claude-")) return `${profile}.anthropic.${id}`;
|
|
3143
|
+
throw new ModelKitError({
|
|
3144
|
+
code: "unsupported_option",
|
|
3145
|
+
message: `No Bedrock model id for "${id}". Set providerOptions.modelkit.bedrockModelId on the catalog row.`,
|
|
3146
|
+
provider: "ai-sdk-text",
|
|
3147
|
+
model: model.id,
|
|
3148
|
+
retryable: false
|
|
3149
|
+
});
|
|
3080
3150
|
}
|
|
3081
3151
|
function nativeClientFor(provider) {
|
|
3082
3152
|
switch (provider) {
|
|
@@ -3101,14 +3171,14 @@ function nativeClientFor(provider) {
|
|
|
3101
3171
|
function resolveTextRoute(ctx) {
|
|
3102
3172
|
const provider = textProviderOf(ctx.model);
|
|
3103
3173
|
const mode = ctx.routing.text ?? "direct";
|
|
3104
|
-
if (provider === "anthropic" && ctx.
|
|
3105
|
-
|
|
3106
|
-
|
|
3107
|
-
|
|
3108
|
-
|
|
3109
|
-
|
|
3110
|
-
|
|
3111
|
-
}
|
|
3174
|
+
if (provider === "anthropic" && ctx.anthropicTransport === "bedrock") {
|
|
3175
|
+
return {
|
|
3176
|
+
provider,
|
|
3177
|
+
client: "bedrock-anthropic",
|
|
3178
|
+
modelId: toBedrockModelId(ctx.model, ctx.routing),
|
|
3179
|
+
keyName: "aws",
|
|
3180
|
+
canonicalModelId: ctx.model.id
|
|
3181
|
+
};
|
|
3112
3182
|
}
|
|
3113
3183
|
const compatBase = OPENAI_COMPATIBLE_BASE_URLS[provider];
|
|
3114
3184
|
const route2 = {
|
|
@@ -3152,6 +3222,70 @@ function missingKey(ctx, name) {
|
|
|
3152
3222
|
retryable: false
|
|
3153
3223
|
});
|
|
3154
3224
|
}
|
|
3225
|
+
function bedrockMiddleware(ctx, canonicalModelId) {
|
|
3226
|
+
let warned = false;
|
|
3227
|
+
return {
|
|
3228
|
+
specificationVersion: "v3",
|
|
3229
|
+
transformParams: async ({ params }) => {
|
|
3230
|
+
const anthropic = params.providerOptions?.["anthropic"];
|
|
3231
|
+
if (typeof anthropic !== "object" || anthropic === null || !("cacheControl" in anthropic))
|
|
3232
|
+
return params;
|
|
3233
|
+
if (!warned) {
|
|
3234
|
+
warned = true;
|
|
3235
|
+
ctx.logger.warn(
|
|
3236
|
+
`[modelkit] ${canonicalModelId} drops call-level providerOptions.anthropic.cacheControl: not supported on Bedrock, use message-level cacheControl`
|
|
3237
|
+
);
|
|
3238
|
+
}
|
|
3239
|
+
const { cacheControl: _dropped, ...rest } = anthropic;
|
|
3240
|
+
return {
|
|
3241
|
+
...params,
|
|
3242
|
+
providerOptions: { ...params.providerOptions, anthropic: rest }
|
|
3243
|
+
};
|
|
3244
|
+
},
|
|
3245
|
+
// Bedrock echoes its own id for dated models (anthropic.claude-haiku-4-5-20251001-v1:0),
|
|
3246
|
+
// and consumers bill on response.modelId.
|
|
3247
|
+
wrapGenerate: async ({ doGenerate }) => {
|
|
3248
|
+
const result = await doGenerate();
|
|
3249
|
+
if (!result.response) return result;
|
|
3250
|
+
return { ...result, response: { ...result.response, modelId: canonicalModelId } };
|
|
3251
|
+
},
|
|
3252
|
+
wrapStream: async ({ doStream }) => {
|
|
3253
|
+
const result = await doStream();
|
|
3254
|
+
return {
|
|
3255
|
+
...result,
|
|
3256
|
+
stream: result.stream.pipeThrough(
|
|
3257
|
+
new TransformStream({
|
|
3258
|
+
transform(part, controller) {
|
|
3259
|
+
controller.enqueue(
|
|
3260
|
+
part.type === "response-metadata" && part.modelId !== void 0 ? { ...part, modelId: canonicalModelId } : part
|
|
3261
|
+
);
|
|
3262
|
+
}
|
|
3263
|
+
})
|
|
3264
|
+
)
|
|
3265
|
+
};
|
|
3266
|
+
}
|
|
3267
|
+
};
|
|
3268
|
+
}
|
|
3269
|
+
function bedrockLanguageModel(ctx, route2) {
|
|
3270
|
+
const aws = ctx.keys.aws;
|
|
3271
|
+
if (!hasAwsCredentials(aws)) throw missingKey(ctx, "aws");
|
|
3272
|
+
const canonical = route2.canonicalModelId ?? ctx.model.id;
|
|
3273
|
+
const inner = createBedrockAnthropic({
|
|
3274
|
+
region: aws.region,
|
|
3275
|
+
fetch: ctx.fetch,
|
|
3276
|
+
...aws.apiKey ? { apiKey: aws.apiKey } : aws.credentialProvider ? { credentialProvider: aws.credentialProvider } : aws.accessKeyId !== void 0 && aws.secretAccessKey !== void 0 ? {
|
|
3277
|
+
accessKeyId: aws.accessKeyId,
|
|
3278
|
+
secretAccessKey: aws.secretAccessKey,
|
|
3279
|
+
...aws.sessionToken !== void 0 ? { sessionToken: aws.sessionToken } : {}
|
|
3280
|
+
} : {}
|
|
3281
|
+
})(route2.modelId);
|
|
3282
|
+
return wrapLanguageModel({
|
|
3283
|
+
model: inner,
|
|
3284
|
+
middleware: bedrockMiddleware(ctx, canonical),
|
|
3285
|
+
modelId: canonical,
|
|
3286
|
+
providerId: "anthropic.messages"
|
|
3287
|
+
});
|
|
3288
|
+
}
|
|
3155
3289
|
function minimaxDefaults(params) {
|
|
3156
3290
|
return params.responseFormat?.type === "json" ? { reasoning_split: true, thinking: { type: "disabled" } } : { reasoning_split: true };
|
|
3157
3291
|
}
|
|
@@ -3190,8 +3324,11 @@ var aiSdkTextAdapter = {
|
|
|
3190
3324
|
id: "ai-sdk-text",
|
|
3191
3325
|
languageModel(ctx) {
|
|
3192
3326
|
const route2 = resolveTextRoute(ctx);
|
|
3193
|
-
|
|
3194
|
-
|
|
3327
|
+
if (route2.client === "bedrock-anthropic") return bedrockLanguageModel(ctx, route2);
|
|
3328
|
+
const { keyName } = route2;
|
|
3329
|
+
if (keyName === "aws") throw missingKey(ctx, keyName);
|
|
3330
|
+
const apiKey = ctx.keys[keyName];
|
|
3331
|
+
if (!apiKey) throw missingKey(ctx, keyName);
|
|
3195
3332
|
const settings = { apiKey, fetch: ctx.fetch };
|
|
3196
3333
|
if (route2.baseURL !== void 0) settings.baseURL = route2.baseURL;
|
|
3197
3334
|
if (route2.headers !== void 0) settings.headers = route2.headers;
|
|
@@ -3230,14 +3367,43 @@ var aiSdkTextAdapter = {
|
|
|
3230
3367
|
}
|
|
3231
3368
|
};
|
|
3232
3369
|
|
|
3370
|
+
// src/anthropic-transport.ts
|
|
3371
|
+
var ANTHROPIC_TRANSPORTS = ["direct", "bedrock"];
|
|
3372
|
+
function isAnthropicTransport(value) {
|
|
3373
|
+
return ANTHROPIC_TRANSPORTS.some((transport) => transport === value);
|
|
3374
|
+
}
|
|
3375
|
+
function preferredAnthropicTransport(model, routing) {
|
|
3376
|
+
const row = model.providerOptions?.["modelkit"]?.["transport"];
|
|
3377
|
+
if (isAnthropicTransport(row)) return row;
|
|
3378
|
+
return routing.anthropic ?? "direct";
|
|
3379
|
+
}
|
|
3380
|
+
function resolveAnthropicTransport(model, config, tier, warn) {
|
|
3381
|
+
if (model.adapter !== "ai-sdk-text" || textProviderOf(model) !== "anthropic") return void 0;
|
|
3382
|
+
const rowValue = model.providerOptions?.["modelkit"]?.["transport"];
|
|
3383
|
+
if (rowValue !== void 0 && !isAnthropicTransport(rowValue))
|
|
3384
|
+
warn(
|
|
3385
|
+
`[modelkit] ${model.id} has an unknown providerOptions.modelkit.transport "${String(rowValue)}"; ignoring it`
|
|
3386
|
+
);
|
|
3387
|
+
const preferred = preferredAnthropicTransport(model, config.routing ?? {});
|
|
3388
|
+
const usable = (transport) => {
|
|
3389
|
+
const name = transport === "bedrock" ? "aws" : "anthropic";
|
|
3390
|
+
return hasKey(config.keys.pro, name) || tier === "enterprise" && hasKey(config.keys.enterprise, name);
|
|
3391
|
+
};
|
|
3392
|
+
if (usable(preferred)) return preferred;
|
|
3393
|
+
const other = preferred === "bedrock" ? "direct" : "bedrock";
|
|
3394
|
+
if (!usable(other)) return preferred;
|
|
3395
|
+
warn(`[modelkit] ${model.id}: no credentials for the ${preferred} transport; using ${other}`);
|
|
3396
|
+
return other;
|
|
3397
|
+
}
|
|
3398
|
+
|
|
3233
3399
|
// src/client.ts
|
|
3234
|
-
function requiredKeys(model, config) {
|
|
3400
|
+
function requiredKeys(model, config, transport) {
|
|
3235
3401
|
if (model.adapter === "fal" && config.routing?.fal === "cloudflare-passthrough")
|
|
3236
3402
|
return ["cloudflare"];
|
|
3237
3403
|
if (model.adapter === "ai-sdk-text") {
|
|
3238
3404
|
const routing = config.routing ?? {};
|
|
3239
|
-
const names = [textKeyName(model,
|
|
3240
|
-
if (textUsesCloudflareGateway(model, routing)) names.push("cloudflare");
|
|
3405
|
+
const names = [textKeyName(model, transport)];
|
|
3406
|
+
if (textUsesCloudflareGateway(model, routing, transport)) names.push("cloudflare");
|
|
3241
3407
|
return names;
|
|
3242
3408
|
}
|
|
3243
3409
|
return ADAPTER_KEYS[model.adapter];
|
|
@@ -3324,6 +3490,12 @@ function createModelKit(config, adapters) {
|
|
|
3324
3490
|
const catalog = config.catalogOverride ? liveCatalog.withOverrides(config.catalogOverride) : liveCatalog;
|
|
3325
3491
|
const logger = config.logger ?? console;
|
|
3326
3492
|
const fetchImpl = config.fetch ?? globalThis.fetch;
|
|
3493
|
+
const transportWarnings = /* @__PURE__ */ new Set();
|
|
3494
|
+
function warnOnce(message) {
|
|
3495
|
+
if (transportWarnings.has(message)) return;
|
|
3496
|
+
transportWarnings.add(message);
|
|
3497
|
+
logger.warn(message);
|
|
3498
|
+
}
|
|
3327
3499
|
function context(model, call, warnings) {
|
|
3328
3500
|
const adapter = adapters[model.adapter];
|
|
3329
3501
|
if (!adapter)
|
|
@@ -3332,7 +3504,8 @@ function createModelKit(config, adapters) {
|
|
|
3332
3504
|
message: `No adapter registered for ${model.adapter}`,
|
|
3333
3505
|
model: model.id
|
|
3334
3506
|
});
|
|
3335
|
-
const
|
|
3507
|
+
const transport = resolveAnthropicTransport(model, config, call.tier, warnOnce);
|
|
3508
|
+
const names = requiredKeys(model, config, transport);
|
|
3336
3509
|
if (call.tier === "enterprise") {
|
|
3337
3510
|
const missing = missingEnterpriseKeys(config, names);
|
|
3338
3511
|
if (missing.length > 0)
|
|
@@ -3351,6 +3524,7 @@ function createModelKit(config, adapters) {
|
|
|
3351
3524
|
call,
|
|
3352
3525
|
warnings
|
|
3353
3526
|
};
|
|
3527
|
+
if (transport) ctx.anthropicTransport = transport;
|
|
3354
3528
|
if (config.endpoints) ctx.endpoints = config.endpoints;
|
|
3355
3529
|
if (call.signal) ctx.signal = call.signal;
|
|
3356
3530
|
return { adapter, ctx };
|
|
@@ -3685,7 +3859,7 @@ function createModelKit(config, adapters) {
|
|
|
3685
3859
|
async prepareMediaPart(modelId, ref, mediaType, call = {}) {
|
|
3686
3860
|
const model = catalog.require(modelId);
|
|
3687
3861
|
const { adapter, ctx } = context(model, call, []);
|
|
3688
|
-
const fileStore = model.adapter === "ai-sdk-text" && textKeyName(model
|
|
3862
|
+
const fileStore = model.adapter === "ai-sdk-text" && textKeyName(model) === "google" ? adapters["google-genai"] : adapter;
|
|
3689
3863
|
if (fileStore?.prepareMediaPart) return fileStore.prepareMediaPart(ref, mediaType, ctx);
|
|
3690
3864
|
return "url" in ref ? { type: "file", data: ref.url, mediaType } : { type: "file", data: ref.bytes, mediaType };
|
|
3691
3865
|
},
|
|
@@ -7478,6 +7652,7 @@ export {
|
|
|
7478
7652
|
generateVideo,
|
|
7479
7653
|
googleGenaiAdapter,
|
|
7480
7654
|
googleImageAdapter,
|
|
7655
|
+
hasAwsCredentials,
|
|
7481
7656
|
higgsfieldAdapter,
|
|
7482
7657
|
isListed,
|
|
7483
7658
|
isListedOn,
|