@shop-os/modelkit 0.2.24 → 0.2.25
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 +6 -0
- package/README.md +1 -1
- package/dist/catalog.d.cts +6 -3
- package/dist/catalog.d.ts +6 -3
- package/dist/index.cjs +28 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +12 -6
- package/dist/index.d.ts +12 -6
- package/dist/index.js +27 -5
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -9,6 +9,12 @@ header in the release PR.
|
|
|
9
9
|
|
|
10
10
|
## [Unreleased]
|
|
11
11
|
|
|
12
|
+
## [0.2.25] - Unreleased
|
|
13
|
+
|
|
14
|
+
### Added
|
|
15
|
+
- Third key set `sloosh` (ENG-2990). `CallContext.tier` is now `KeyTier = "pro" | "enterprise" | "sloosh"` and `ModelKitConfig.keys.sloosh` holds the keys (`keysFromEnv(env, "SLOOSH_")`). A `sloosh` call uses `keys.sloosh` only: a missing key throws `ModelKitError` code `auth` and never falls back to the pro key. Enterprise keeps its fall-back-to-pro rule. `createDefaultModelKit` gives the sloosh key set the pro AWS credentials when it has none of its own (one shared Bedrock identity), for keys read from the environment and for keys passed in `config.keys`.
|
|
16
|
+
- `missingTierKeys(config, tier, names)`; `missingEnterpriseKeys` delegates to it.
|
|
17
|
+
|
|
12
18
|
## [0.2.24] - Unreleased
|
|
13
19
|
|
|
14
20
|
### Added
|
package/README.md
CHANGED
|
@@ -51,7 +51,7 @@ await kit.generateText({
|
|
|
51
51
|
await clip.cleanup?.();
|
|
52
52
|
```
|
|
53
53
|
|
|
54
|
-
Keys come from `process.env` by default: bare names for pro (`OPENAI_API_KEY`, `FAL_KEY`, `ARK_API_KEY` ...) and the `
|
|
54
|
+
Keys come from `process.env` by default: bare names for pro (`OPENAI_API_KEY`, `FAL_KEY`, `ARK_API_KEY` ...), the `ENTERPRISE_` prefix for enterprise and the `SLOOSH_` prefix for sloosh. Pass `keys: { pro, enterprise, sloosh }` to override. `tier: "sloosh"` uses the sloosh keys only: a missing key is a `ModelKitError` with code `auth`, never a fallback to pro.
|
|
55
55
|
|
|
56
56
|
## Browser-safe catalog
|
|
57
57
|
|
package/dist/catalog.d.cts
CHANGED
|
@@ -437,6 +437,8 @@ type ProviderKeys = Partial<Record<ProviderKeyName, string>> & {
|
|
|
437
437
|
}>;
|
|
438
438
|
};
|
|
439
439
|
};
|
|
440
|
+
/** Which key set a call uses. Enterprise falls back to pro; sloosh never falls back. */
|
|
441
|
+
type KeyTier = "pro" | "enterprise" | "sloosh";
|
|
440
442
|
/** Key names a call can require, including the Bedrock credentials object. */
|
|
441
443
|
type RequiredKeyName = ProviderKeyName | "aws";
|
|
442
444
|
/** True when region is set AND (apiKey OR credentialProvider OR both static keys). */
|
|
@@ -468,6 +470,7 @@ interface ModelKitConfig {
|
|
|
468
470
|
keys: {
|
|
469
471
|
pro: ProviderKeys;
|
|
470
472
|
enterprise?: ProviderKeys;
|
|
473
|
+
sloosh?: ProviderKeys;
|
|
471
474
|
};
|
|
472
475
|
routing?: Routing;
|
|
473
476
|
/** Provider base-url overrides; unset entries use each adapter's documented default. */
|
|
@@ -480,8 +483,8 @@ interface ModelKitConfig {
|
|
|
480
483
|
logger?: Pick<Console, "debug" | "info" | "warn" | "error">;
|
|
481
484
|
}
|
|
482
485
|
interface CallContext {
|
|
483
|
-
/** "enterprise" picks keys.enterprise when every key for the provider is set, else falls back to pro. */
|
|
484
|
-
tier?:
|
|
486
|
+
/** "enterprise" picks keys.enterprise when every key for the provider is set, else falls back to pro. "sloosh" uses keys.sloosh only and never falls back. */
|
|
487
|
+
tier?: KeyTier;
|
|
485
488
|
signal?: AbortSignal;
|
|
486
489
|
/** Media retries after the initial request. Set 0 when a durable host owns recovery.
|
|
487
490
|
* Unset preserves adapter defaults. Successful pending-job polls are not retries.
|
|
@@ -992,4 +995,4 @@ declare function isModelKitError(err: unknown): err is ModelKitError;
|
|
|
992
995
|
/** Resolve caller options against a catalog row, dispatching on `model.type`. */
|
|
993
996
|
declare function resolveOptions(model: CatalogModel, request: ImageRequest | VideoRequest | AudioRequest, onUnsupported?: OnUnsupported): ResolveResult<ImageRequest | VideoRequest | AudioRequest>;
|
|
994
997
|
|
|
995
|
-
export { ADAPTER_IDS, AUDIO_OUTPUTS, type AdapterEndpoints, type AdapterId, type AspectRatio, type AudioOutput, type AudioRequest, type AudioResult, type CallContext, Catalog, type CatalogAuth, type CatalogCache, type CatalogCapabilities, type CatalogDisplay, type CatalogEnvelope, type CatalogModel, CatalogModelSchema, CatalogModelSchemaBase, type CatalogOrigin, CatalogSchema, type CatalogSource, type Exposure, ExposureSchema, type GeneratedImage, IMAGE_MODELS, type ImageBytes, type ImageCallOptions, type ImageCallResult, type ImageQuality, type ImageRequest, type ImageResult, type ImageSafetySetting, type ImageSize, type JsonObject, type JsonPrimitive, type JsonValue, type Lifecycle, type LiveCatalogState, MODELS, type MediaPart, type MediaRef, type ModelConstraints, type ModelKitConfig, ModelKitError, type ModelKitErrorCode, type ModelKitErrorInit, type ModelType, OTHER_MODELS, type OnUnsupported, type OutputFormat, type PricingKind, type PrimeCatalogResult, type PromptConventions, type ProviderErrorBody, type ProviderKeyName, type ProviderKeys, type ProviderOptionValue, type ProviderOptions, type QuarantineResult, REFERENCE_SYNTAXES, type ReferenceLimits, type ReferenceSyntax, type RequiredInput, type RequiredKeyName, type ResolveResult, type Routing, SURFACES, type SupportedOption, type Surface, SurfaceSchema, TEXT_MODELS, type UpscaleOptions, type UsageEvent, type UsageModality, type UsageUnit, VIDEO_MODELS, type VideoCallJob, type VideoCallOptions, type VideoJob, type VideoModel, type VideoRequest, type VideoResolution, type VideoResult, type VideoSecondsLimits, type Warning, billedAudio, compareCatalogOrder, hasAwsCredentials, isListed, isListedOn, isModelKitError, liveCatalog, liveState, nearestAspectRatio, normalizeExposure, outputAudio, primeCatalog, promptConventions, resetLiveCatalog, resolveAudioOptions, resolveImageOptions, resolveOptions, resolveVideoOptions, sortCatalogRows, videoLengthViolation };
|
|
998
|
+
export { ADAPTER_IDS, AUDIO_OUTPUTS, type AdapterEndpoints, type AdapterId, type AspectRatio, type AudioOutput, type AudioRequest, type AudioResult, type CallContext, Catalog, type CatalogAuth, type CatalogCache, type CatalogCapabilities, type CatalogDisplay, type CatalogEnvelope, type CatalogModel, CatalogModelSchema, CatalogModelSchemaBase, type CatalogOrigin, CatalogSchema, type CatalogSource, type Exposure, ExposureSchema, type GeneratedImage, IMAGE_MODELS, type ImageBytes, type ImageCallOptions, type ImageCallResult, type ImageQuality, type ImageRequest, type ImageResult, type ImageSafetySetting, type ImageSize, type JsonObject, type JsonPrimitive, type JsonValue, type KeyTier, type Lifecycle, type LiveCatalogState, MODELS, type MediaPart, type MediaRef, type ModelConstraints, type ModelKitConfig, ModelKitError, type ModelKitErrorCode, type ModelKitErrorInit, type ModelType, OTHER_MODELS, type OnUnsupported, type OutputFormat, type PricingKind, type PrimeCatalogResult, type PromptConventions, type ProviderErrorBody, type ProviderKeyName, type ProviderKeys, type ProviderOptionValue, type ProviderOptions, type QuarantineResult, REFERENCE_SYNTAXES, type ReferenceLimits, type ReferenceSyntax, type RequiredInput, type RequiredKeyName, type ResolveResult, type Routing, SURFACES, type SupportedOption, type Surface, SurfaceSchema, TEXT_MODELS, type UpscaleOptions, type UsageEvent, type UsageModality, type UsageUnit, VIDEO_MODELS, type VideoCallJob, type VideoCallOptions, type VideoJob, type VideoModel, type VideoRequest, type VideoResolution, type VideoResult, type VideoSecondsLimits, type Warning, billedAudio, compareCatalogOrder, hasAwsCredentials, isListed, isListedOn, isModelKitError, liveCatalog, liveState, nearestAspectRatio, normalizeExposure, outputAudio, primeCatalog, promptConventions, resetLiveCatalog, resolveAudioOptions, resolveImageOptions, resolveOptions, resolveVideoOptions, sortCatalogRows, videoLengthViolation };
|
package/dist/catalog.d.ts
CHANGED
|
@@ -437,6 +437,8 @@ type ProviderKeys = Partial<Record<ProviderKeyName, string>> & {
|
|
|
437
437
|
}>;
|
|
438
438
|
};
|
|
439
439
|
};
|
|
440
|
+
/** Which key set a call uses. Enterprise falls back to pro; sloosh never falls back. */
|
|
441
|
+
type KeyTier = "pro" | "enterprise" | "sloosh";
|
|
440
442
|
/** Key names a call can require, including the Bedrock credentials object. */
|
|
441
443
|
type RequiredKeyName = ProviderKeyName | "aws";
|
|
442
444
|
/** True when region is set AND (apiKey OR credentialProvider OR both static keys). */
|
|
@@ -468,6 +470,7 @@ interface ModelKitConfig {
|
|
|
468
470
|
keys: {
|
|
469
471
|
pro: ProviderKeys;
|
|
470
472
|
enterprise?: ProviderKeys;
|
|
473
|
+
sloosh?: ProviderKeys;
|
|
471
474
|
};
|
|
472
475
|
routing?: Routing;
|
|
473
476
|
/** Provider base-url overrides; unset entries use each adapter's documented default. */
|
|
@@ -480,8 +483,8 @@ interface ModelKitConfig {
|
|
|
480
483
|
logger?: Pick<Console, "debug" | "info" | "warn" | "error">;
|
|
481
484
|
}
|
|
482
485
|
interface CallContext {
|
|
483
|
-
/** "enterprise" picks keys.enterprise when every key for the provider is set, else falls back to pro. */
|
|
484
|
-
tier?:
|
|
486
|
+
/** "enterprise" picks keys.enterprise when every key for the provider is set, else falls back to pro. "sloosh" uses keys.sloosh only and never falls back. */
|
|
487
|
+
tier?: KeyTier;
|
|
485
488
|
signal?: AbortSignal;
|
|
486
489
|
/** Media retries after the initial request. Set 0 when a durable host owns recovery.
|
|
487
490
|
* Unset preserves adapter defaults. Successful pending-job polls are not retries.
|
|
@@ -992,4 +995,4 @@ declare function isModelKitError(err: unknown): err is ModelKitError;
|
|
|
992
995
|
/** Resolve caller options against a catalog row, dispatching on `model.type`. */
|
|
993
996
|
declare function resolveOptions(model: CatalogModel, request: ImageRequest | VideoRequest | AudioRequest, onUnsupported?: OnUnsupported): ResolveResult<ImageRequest | VideoRequest | AudioRequest>;
|
|
994
997
|
|
|
995
|
-
export { ADAPTER_IDS, AUDIO_OUTPUTS, type AdapterEndpoints, type AdapterId, type AspectRatio, type AudioOutput, type AudioRequest, type AudioResult, type CallContext, Catalog, type CatalogAuth, type CatalogCache, type CatalogCapabilities, type CatalogDisplay, type CatalogEnvelope, type CatalogModel, CatalogModelSchema, CatalogModelSchemaBase, type CatalogOrigin, CatalogSchema, type CatalogSource, type Exposure, ExposureSchema, type GeneratedImage, IMAGE_MODELS, type ImageBytes, type ImageCallOptions, type ImageCallResult, type ImageQuality, type ImageRequest, type ImageResult, type ImageSafetySetting, type ImageSize, type JsonObject, type JsonPrimitive, type JsonValue, type Lifecycle, type LiveCatalogState, MODELS, type MediaPart, type MediaRef, type ModelConstraints, type ModelKitConfig, ModelKitError, type ModelKitErrorCode, type ModelKitErrorInit, type ModelType, OTHER_MODELS, type OnUnsupported, type OutputFormat, type PricingKind, type PrimeCatalogResult, type PromptConventions, type ProviderErrorBody, type ProviderKeyName, type ProviderKeys, type ProviderOptionValue, type ProviderOptions, type QuarantineResult, REFERENCE_SYNTAXES, type ReferenceLimits, type ReferenceSyntax, type RequiredInput, type RequiredKeyName, type ResolveResult, type Routing, SURFACES, type SupportedOption, type Surface, SurfaceSchema, TEXT_MODELS, type UpscaleOptions, type UsageEvent, type UsageModality, type UsageUnit, VIDEO_MODELS, type VideoCallJob, type VideoCallOptions, type VideoJob, type VideoModel, type VideoRequest, type VideoResolution, type VideoResult, type VideoSecondsLimits, type Warning, billedAudio, compareCatalogOrder, hasAwsCredentials, isListed, isListedOn, isModelKitError, liveCatalog, liveState, nearestAspectRatio, normalizeExposure, outputAudio, primeCatalog, promptConventions, resetLiveCatalog, resolveAudioOptions, resolveImageOptions, resolveOptions, resolveVideoOptions, sortCatalogRows, videoLengthViolation };
|
|
998
|
+
export { ADAPTER_IDS, AUDIO_OUTPUTS, type AdapterEndpoints, type AdapterId, type AspectRatio, type AudioOutput, type AudioRequest, type AudioResult, type CallContext, Catalog, type CatalogAuth, type CatalogCache, type CatalogCapabilities, type CatalogDisplay, type CatalogEnvelope, type CatalogModel, CatalogModelSchema, CatalogModelSchemaBase, type CatalogOrigin, CatalogSchema, type CatalogSource, type Exposure, ExposureSchema, type GeneratedImage, IMAGE_MODELS, type ImageBytes, type ImageCallOptions, type ImageCallResult, type ImageQuality, type ImageRequest, type ImageResult, type ImageSafetySetting, type ImageSize, type JsonObject, type JsonPrimitive, type JsonValue, type KeyTier, type Lifecycle, type LiveCatalogState, MODELS, type MediaPart, type MediaRef, type ModelConstraints, type ModelKitConfig, ModelKitError, type ModelKitErrorCode, type ModelKitErrorInit, type ModelType, OTHER_MODELS, type OnUnsupported, type OutputFormat, type PricingKind, type PrimeCatalogResult, type PromptConventions, type ProviderErrorBody, type ProviderKeyName, type ProviderKeys, type ProviderOptionValue, type ProviderOptions, type QuarantineResult, REFERENCE_SYNTAXES, type ReferenceLimits, type ReferenceSyntax, type RequiredInput, type RequiredKeyName, type ResolveResult, type Routing, SURFACES, type SupportedOption, type Surface, SurfaceSchema, TEXT_MODELS, type UpscaleOptions, type UsageEvent, type UsageModality, type UsageUnit, VIDEO_MODELS, type VideoCallJob, type VideoCallOptions, type VideoJob, type VideoModel, type VideoRequest, type VideoResolution, type VideoResult, type VideoSecondsLimits, type Warning, billedAudio, compareCatalogOrder, hasAwsCredentials, isListed, isListedOn, isModelKitError, liveCatalog, liveState, nearestAspectRatio, normalizeExposure, outputAudio, primeCatalog, promptConventions, resetLiveCatalog, resolveAudioOptions, resolveImageOptions, resolveOptions, resolveVideoOptions, sortCatalogRows, videoLengthViolation };
|
package/dist/index.cjs
CHANGED
|
@@ -81,6 +81,7 @@ __export(index_exports, {
|
|
|
81
81
|
liveCatalog: () => liveCatalog,
|
|
82
82
|
liveState: () => liveState,
|
|
83
83
|
mergeTextProviderOptions: () => mergeTextProviderOptions,
|
|
84
|
+
missingTierKeys: () => missingTierKeys,
|
|
84
85
|
nearestAspectRatio: () => nearestAspectRatio,
|
|
85
86
|
normalizeExposure: () => normalizeExposure,
|
|
86
87
|
openaiImageAdapter: () => openaiImageAdapter,
|
|
@@ -8095,10 +8096,22 @@ function hasAll(keys, names) {
|
|
|
8095
8096
|
function hasKey(keys, name) {
|
|
8096
8097
|
return hasAll(keys, [name]);
|
|
8097
8098
|
}
|
|
8099
|
+
function missingTierKeys(config, tier, names) {
|
|
8100
|
+
return names.filter((name) => !hasAll(config.keys[tier], [name]));
|
|
8101
|
+
}
|
|
8098
8102
|
function missingEnterpriseKeys(config, names) {
|
|
8099
|
-
return
|
|
8103
|
+
return missingTierKeys(config, "enterprise", names);
|
|
8100
8104
|
}
|
|
8101
8105
|
function resolveKeys(config, names, tier = "pro") {
|
|
8106
|
+
if (tier === "sloosh") {
|
|
8107
|
+
if (names.length === 0) return config.keys.sloosh ?? {};
|
|
8108
|
+
if (hasAll(config.keys.sloosh, names)) return config.keys.sloosh;
|
|
8109
|
+
throw new ModelKitError({
|
|
8110
|
+
code: "auth",
|
|
8111
|
+
message: `Missing Sloosh API key for ${names.join(", ")}`,
|
|
8112
|
+
retryable: false
|
|
8113
|
+
});
|
|
8114
|
+
}
|
|
8102
8115
|
if (tier === "enterprise" && hasAll(config.keys.enterprise, names))
|
|
8103
8116
|
return config.keys.enterprise;
|
|
8104
8117
|
if (names.length > 0 && !hasAll(config.keys.pro, names)) {
|
|
@@ -8287,6 +8300,7 @@ function resolveAnthropicTransport(model, config, tier, warn) {
|
|
|
8287
8300
|
const preferred = preferredAnthropicTransport(model, config.routing ?? {});
|
|
8288
8301
|
const usable = (transport) => {
|
|
8289
8302
|
const name = transport === "bedrock" ? "aws" : "anthropic";
|
|
8303
|
+
if (tier === "sloosh") return hasKey(config.keys.sloosh, name);
|
|
8290
8304
|
return hasKey(config.keys.pro, name) || tier === "enterprise" && hasKey(config.keys.enterprise, name);
|
|
8291
8305
|
};
|
|
8292
8306
|
if (usable(preferred)) return preferred;
|
|
@@ -8868,11 +8882,19 @@ function createModelKit(config, adapters) {
|
|
|
8868
8882
|
}
|
|
8869
8883
|
|
|
8870
8884
|
// src/default.ts
|
|
8885
|
+
function withSharedAws(keys) {
|
|
8886
|
+
const { pro, sloosh } = keys;
|
|
8887
|
+
if (!sloosh || sloosh.aws || !pro.aws) return keys;
|
|
8888
|
+
return { ...keys, sloosh: { ...sloosh, aws: pro.aws } };
|
|
8889
|
+
}
|
|
8871
8890
|
function createDefaultModelKit(config = {}) {
|
|
8872
|
-
const keys =
|
|
8873
|
-
|
|
8874
|
-
|
|
8875
|
-
|
|
8891
|
+
const keys = withSharedAws(
|
|
8892
|
+
config.keys ?? {
|
|
8893
|
+
pro: keysFromEnv(process.env),
|
|
8894
|
+
enterprise: keysFromEnv(process.env, "ENTERPRISE_"),
|
|
8895
|
+
sloosh: keysFromEnv(process.env, "SLOOSH_")
|
|
8896
|
+
}
|
|
8897
|
+
);
|
|
8876
8898
|
return createModelKit({ ...config, keys }, DEFAULT_ADAPTERS);
|
|
8877
8899
|
}
|
|
8878
8900
|
var generateText2 = (options, call) => createDefaultModelKit().generateText(options, call);
|
|
@@ -8937,6 +8959,7 @@ var describe = (modelId) => createDefaultModelKit().describe(modelId);
|
|
|
8937
8959
|
liveCatalog,
|
|
8938
8960
|
liveState,
|
|
8939
8961
|
mergeTextProviderOptions,
|
|
8962
|
+
missingTierKeys,
|
|
8940
8963
|
nearestAspectRatio,
|
|
8941
8964
|
normalizeExposure,
|
|
8942
8965
|
openaiImageAdapter,
|