@broberg/ai-sdk 0.50.0 → 0.51.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/dist/chunk-O4LR6X4U.js +478 -0
- package/dist/chunk-O4LR6X4U.js.map +1 -0
- package/dist/index.d.ts +21 -3
- package/dist/index.js +39 -3
- package/dist/index.js.map +1 -1
- package/dist/pricing.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-NHU5FWKT.js +0 -475
- package/dist/chunk-NHU5FWKT.js.map +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -2425,6 +2425,9 @@ declare const ttsInputSchema: z.ZodObject<{
|
|
|
2425
2425
|
rate?: number | undefined;
|
|
2426
2426
|
}>;
|
|
2427
2427
|
declare const aiConfigSchema: z.ZodObject<{
|
|
2428
|
+
/** F069.1 — customer-key mode. Every provider must be built with byokAdapter(), so no
|
|
2429
|
+
* call can fall back to the fleet's env keys; createAI throws at setup otherwise. */
|
|
2430
|
+
byok: z.ZodOptional<z.ZodBoolean>;
|
|
2428
2431
|
/** F039.2 — client-wide opt-out from prompt caching (default: on where the
|
|
2429
2432
|
* provider supports it). A per-call `promptCache` wins over this. */
|
|
2430
2433
|
promptCache: z.ZodOptional<z.ZodBoolean>;
|
|
@@ -2468,6 +2471,7 @@ declare const aiConfigSchema: z.ZodObject<{
|
|
|
2468
2471
|
}>>;
|
|
2469
2472
|
}, "strip", z.ZodTypeAny, {
|
|
2470
2473
|
promptCache?: boolean | undefined;
|
|
2474
|
+
byok?: boolean | undefined;
|
|
2471
2475
|
defaults?: Partial<Record<"fast" | "smart" | "powerful" | "cheap" | "vision" | "video" | "embedding", {
|
|
2472
2476
|
provider: string;
|
|
2473
2477
|
model: string;
|
|
@@ -2485,6 +2489,7 @@ declare const aiConfigSchema: z.ZodObject<{
|
|
|
2485
2489
|
} | undefined;
|
|
2486
2490
|
}, {
|
|
2487
2491
|
promptCache?: boolean | undefined;
|
|
2492
|
+
byok?: boolean | undefined;
|
|
2488
2493
|
defaults?: Partial<Record<"fast" | "smart" | "powerful" | "cheap" | "vision" | "video" | "embedding", {
|
|
2489
2494
|
provider: string;
|
|
2490
2495
|
model: string;
|
|
@@ -2836,6 +2841,19 @@ interface OpenAICompatibleConfig {
|
|
|
2836
2841
|
}
|
|
2837
2842
|
declare function makeOpenAICompatibleAdapter(config: OpenAICompatibleConfig): ProviderAdapter;
|
|
2838
2843
|
|
|
2844
|
+
/** The key-carrying fields an adapter config may hold. `credentials` is Vertex's
|
|
2845
|
+
* service-account JSON; every other adapter takes `apiKey`. */
|
|
2846
|
+
interface KeyedConfig {
|
|
2847
|
+
apiKey?: string;
|
|
2848
|
+
credentials?: string;
|
|
2849
|
+
}
|
|
2850
|
+
/** Build an adapter that is guaranteed to use the key you pass and never the fleet's
|
|
2851
|
+
* env key. Throws at construction when the key is missing or blank — a blank string
|
|
2852
|
+
* is not a key, and treating it as one would only move the failure to a 401 later. */
|
|
2853
|
+
declare function byokAdapter<C extends KeyedConfig>(factory: (config: C) => ProviderAdapter, config: C): ProviderAdapter;
|
|
2854
|
+
/** True when the adapter was built by byokAdapter with a real key. */
|
|
2855
|
+
declare function isByokKeyed(adapter: ProviderAdapter): boolean;
|
|
2856
|
+
|
|
2839
2857
|
declare const defaultProviders: Record<string, ProviderAdapter>;
|
|
2840
2858
|
|
|
2841
2859
|
/** Anthropic adapter stub (HTTP path). */
|
|
@@ -2854,8 +2872,8 @@ declare const falStubAdapter: ProviderAdapter;
|
|
|
2854
2872
|
* wires the live adapters. */
|
|
2855
2873
|
declare const stubProviders: Record<string, ProviderAdapter>;
|
|
2856
2874
|
|
|
2857
|
-
declare const VERSION: "0.
|
|
2858
|
-
declare const SDK_TAG: "@broberg/ai-sdk@0.
|
|
2875
|
+
declare const VERSION: "0.51.0";
|
|
2876
|
+
declare const SDK_TAG: "@broberg/ai-sdk@0.51.0";
|
|
2859
2877
|
|
|
2860
2878
|
/** Built-in defaults. Every entry is overridable via AiConfig.defaults or a
|
|
2861
2879
|
* per-call override.
|
|
@@ -3366,4 +3384,4 @@ interface StreamTransportRequest extends TransportRequest {
|
|
|
3366
3384
|
*/
|
|
3367
3385
|
declare function streamTransport(req: StreamTransportRequest): AsyncIterable<string>;
|
|
3368
3386
|
|
|
3369
|
-
export { AZURE_DANISH_VOICES, AZURE_DANISH_VOICE_LIST, type AiClient, type AiConfig, type AlignedWordTimings, type AzureVoiceInfo, type AzureWordBoundary, type BatchJob, type BatchRequestItem, type BatchResultItem, type BflAdapterConfig, type BflCredits, type BudgetConfig, BudgetExceededError, BudgetGuard, type BudgetStore, CONFIG_DERIVED_HOSTS, type CallOptions, type Capability, type ChatInput, type ChatRequest, type ChatResult, type ChatStreamEvent, type CheckVoiceOptions, type ClassifyInput, type ClassifyResult, type ContentPart, type Contracts, type CostQuery, type CostSink, type CostSummary, type CostSummaryQuery, type CostTimeseriesQuery, DEFAULT_BASE_URLS, DEFAULT_TIER_MAP, type DesignInput, type DesignResult, type DialogueRequest, type DialogueTurn, type DiscordSinkConfig, ELEVENLABS_DANISH_VOICES, type EmbeddingInput, type EmbeddingRequest, type EmbeddingResult, type ExtractInput, type ExtractResult, type FalAdapterConfig, type FixedHostProvider, type HttpResponse, type ImageInput, type ImageRequest, type ImageResult, type JudgeAnswer, type JudgeChoiceAnswer, type JudgeInput, type JudgeNoulAnswer, type JudgeQuestion, type JudgeResult, type JudgeScoreAnswer, LOCALLY_PINNED_HOSTS, type LoraWeight, type Message, type MockupInput, type MockupResult, type ModerationInput, type ModerationItem, type ModerationRequest, type ModerationResult, type OcrInput, type OcrPage, type OcrRequest, type OcrResult, type OpenAICompatibleConfig, type PodcastInput, type PodcastResult, type PricingEntry, type ProviderAdapter, type RefreshOptions, type RefreshResult, type Region, type RerankInput, type RerankResult, type Role, type RouteForecast, SDK_TAG, type SqliteBudgetStoreConfig, type SqliteSinkConfig, StreamHttpError, type SubprocessResponse, type Tier, type TierSpec, type Tool, type ToolCall, type TrainStyleInput, type TrainStyleRequest, type TrainStyleResult, type TranscribeInput, type TranscribeRequest, type TranscribeResult, type TranslateInput, type TranslateResult, type Transport, type TransportRequest, type TransportResponse, type TtsInput, type TtsRequest, type UpmetricsCostClientConfig, UpmetricsCostError, type UpmetricsCostRow, type UpmetricsCostSummary, type UpmetricsCostTimeseries, type UpmetricsSink, type UpmetricsSinkConfig, type UpmetricsSinkStats, type Usage, VERSION, type VideoInput, type VisionInput, type VoiceInfo, type VoiceProvider, type VoiceResolveResult, type VoiceStatus, VoiceUnavailableError, type WordTiming, aiConfigSchema, alignWordTimings, anthropicAdapter, anthropicApiAdapter, anthropicSubprocessAdapter, azureAdapter, bflAdapter, bflCredits, chatInputSchema, checkVoice, classifyRegionName, computeCost, createAI, deepinfraAdapter, deeplAdapter, deepseekAdapter, defaultBaseUrl, defaultProviders, discordSink, elevenlabsAdapter, embeddingInputSchema, falAdapter, falStubAdapter, freshUsage, fromProviderToolCall, geminiAdapter, getCostSummary, getPrice, httpTransport, imageInputSchema, listAzureDanishVoices, listVoices, makeContracts, makeOpenAICompatibleAdapter, matchLabel, messageSchema, mistralAdapter, mistralStubAdapter, multiSink, noopSink, openaiAdapter, openaiStubAdapter, openrouterAdapter, parseClaudeCliJson, parseJsonLoose, refreshAvailability, regionOfHost, regionOfProvider, requestyAdapter, resetRefreshState, resetRegistry, resolveAzureVoice, resolveTier, resolveVoice, sqliteBudgetStore, sqliteSink, streamTransport, stubProviders, subprocessTransport, tierSpecSchema, toProviderTools, toolSchema, translateInputSchema, typesafeAdapter, upmetricsCostClient, upmetricsSink, usdFromMicro, vertexAdapter, visionInputSchema, wouldProviderRouteTo, wouldRouteTo };
|
|
3387
|
+
export { AZURE_DANISH_VOICES, AZURE_DANISH_VOICE_LIST, type AiClient, type AiConfig, type AlignedWordTimings, type AzureVoiceInfo, type AzureWordBoundary, type BatchJob, type BatchRequestItem, type BatchResultItem, type BflAdapterConfig, type BflCredits, type BudgetConfig, BudgetExceededError, BudgetGuard, type BudgetStore, CONFIG_DERIVED_HOSTS, type CallOptions, type Capability, type ChatInput, type ChatRequest, type ChatResult, type ChatStreamEvent, type CheckVoiceOptions, type ClassifyInput, type ClassifyResult, type ContentPart, type Contracts, type CostQuery, type CostSink, type CostSummary, type CostSummaryQuery, type CostTimeseriesQuery, DEFAULT_BASE_URLS, DEFAULT_TIER_MAP, type DesignInput, type DesignResult, type DialogueRequest, type DialogueTurn, type DiscordSinkConfig, ELEVENLABS_DANISH_VOICES, type EmbeddingInput, type EmbeddingRequest, type EmbeddingResult, type ExtractInput, type ExtractResult, type FalAdapterConfig, type FixedHostProvider, type HttpResponse, type ImageInput, type ImageRequest, type ImageResult, type JudgeAnswer, type JudgeChoiceAnswer, type JudgeInput, type JudgeNoulAnswer, type JudgeQuestion, type JudgeResult, type JudgeScoreAnswer, LOCALLY_PINNED_HOSTS, type LoraWeight, type Message, type MockupInput, type MockupResult, type ModerationInput, type ModerationItem, type ModerationRequest, type ModerationResult, type OcrInput, type OcrPage, type OcrRequest, type OcrResult, type OpenAICompatibleConfig, type PodcastInput, type PodcastResult, type PricingEntry, type ProviderAdapter, type RefreshOptions, type RefreshResult, type Region, type RerankInput, type RerankResult, type Role, type RouteForecast, SDK_TAG, type SqliteBudgetStoreConfig, type SqliteSinkConfig, StreamHttpError, type SubprocessResponse, type Tier, type TierSpec, type Tool, type ToolCall, type TrainStyleInput, type TrainStyleRequest, type TrainStyleResult, type TranscribeInput, type TranscribeRequest, type TranscribeResult, type TranslateInput, type TranslateResult, type Transport, type TransportRequest, type TransportResponse, type TtsInput, type TtsRequest, type UpmetricsCostClientConfig, UpmetricsCostError, type UpmetricsCostRow, type UpmetricsCostSummary, type UpmetricsCostTimeseries, type UpmetricsSink, type UpmetricsSinkConfig, type UpmetricsSinkStats, type Usage, VERSION, type VideoInput, type VisionInput, type VoiceInfo, type VoiceProvider, type VoiceResolveResult, type VoiceStatus, VoiceUnavailableError, type WordTiming, aiConfigSchema, alignWordTimings, anthropicAdapter, anthropicApiAdapter, anthropicSubprocessAdapter, azureAdapter, bflAdapter, bflCredits, byokAdapter, chatInputSchema, checkVoice, classifyRegionName, computeCost, createAI, deepinfraAdapter, deeplAdapter, deepseekAdapter, defaultBaseUrl, defaultProviders, discordSink, elevenlabsAdapter, embeddingInputSchema, falAdapter, falStubAdapter, freshUsage, fromProviderToolCall, geminiAdapter, getCostSummary, getPrice, httpTransport, imageInputSchema, isByokKeyed, listAzureDanishVoices, listVoices, makeContracts, makeOpenAICompatibleAdapter, matchLabel, messageSchema, mistralAdapter, mistralStubAdapter, multiSink, noopSink, openaiAdapter, openaiStubAdapter, openrouterAdapter, parseClaudeCliJson, parseJsonLoose, refreshAvailability, regionOfHost, regionOfProvider, requestyAdapter, resetRefreshState, resetRegistry, resolveAzureVoice, resolveTier, resolveVoice, sqliteBudgetStore, sqliteSink, streamTransport, stubProviders, subprocessTransport, tierSpecSchema, toProviderTools, toolSchema, translateInputSchema, typesafeAdapter, upmetricsCostClient, upmetricsSink, usdFromMicro, vertexAdapter, visionInputSchema, wouldProviderRouteTo, wouldRouteTo };
|
package/dist/index.js
CHANGED
|
@@ -18,7 +18,7 @@ import {
|
|
|
18
18
|
listMediaPrices,
|
|
19
19
|
pricingFreshness,
|
|
20
20
|
pricingGeneratedAt
|
|
21
|
-
} from "./chunk-
|
|
21
|
+
} from "./chunk-O4LR6X4U.js";
|
|
22
22
|
|
|
23
23
|
// src/cost/default-hosts.ts
|
|
24
24
|
var DEFAULT_BASE_URLS = {
|
|
@@ -3495,6 +3495,9 @@ var availabilitySchema = z.object({
|
|
|
3495
3495
|
fallback: z.union([z.string(), z.array(z.string())]).optional()
|
|
3496
3496
|
});
|
|
3497
3497
|
var aiConfigSchema = z.object({
|
|
3498
|
+
/** F069.1 — customer-key mode. Every provider must be built with byokAdapter(), so no
|
|
3499
|
+
* call can fall back to the fleet's env keys; createAI throws at setup otherwise. */
|
|
3500
|
+
byok: z.boolean().optional(),
|
|
3498
3501
|
/** F039.2 — client-wide opt-out from prompt caching (default: on where the
|
|
3499
3502
|
* provider supports it). A per-call `promptCache` wins over this. */
|
|
3500
3503
|
promptCache: z.boolean().optional(),
|
|
@@ -3514,8 +3517,8 @@ var aiConfigSchema = z.object({
|
|
|
3514
3517
|
import { randomUUID } from "crypto";
|
|
3515
3518
|
|
|
3516
3519
|
// src/version.ts
|
|
3517
|
-
var VERSION = "0.
|
|
3518
|
-
var SDK_TAG = "@broberg/ai-sdk@0.
|
|
3520
|
+
var VERSION = "0.51.0";
|
|
3521
|
+
var SDK_TAG = "@broberg/ai-sdk@0.51.0";
|
|
3519
3522
|
|
|
3520
3523
|
// src/cost/sinks/upmetrics.ts
|
|
3521
3524
|
function isRetryableStatus(status) {
|
|
@@ -3709,6 +3712,36 @@ function upmetricsSink(config) {
|
|
|
3709
3712
|
};
|
|
3710
3713
|
}
|
|
3711
3714
|
|
|
3715
|
+
// src/byok.ts
|
|
3716
|
+
var BYOK_KEYED = /* @__PURE__ */ Symbol.for("@broberg/ai-sdk/byok-keyed");
|
|
3717
|
+
function byokAdapter(factory, config) {
|
|
3718
|
+
const key = config.apiKey ?? config.credentials;
|
|
3719
|
+
if (typeof key !== "string" || key.trim() === "") {
|
|
3720
|
+
throw new Error(
|
|
3721
|
+
"byokAdapter: no customer key (apiKey/credentials is missing or blank). Refusing to build an adapter that would fall back to the fleet's env key."
|
|
3722
|
+
);
|
|
3723
|
+
}
|
|
3724
|
+
const adapter = factory(config);
|
|
3725
|
+
Object.defineProperty(adapter, BYOK_KEYED, { value: true, enumerable: false });
|
|
3726
|
+
return adapter;
|
|
3727
|
+
}
|
|
3728
|
+
function isByokKeyed(adapter) {
|
|
3729
|
+
return adapter[BYOK_KEYED] === true;
|
|
3730
|
+
}
|
|
3731
|
+
function assertByokProviders(providers) {
|
|
3732
|
+
if (!providers || Object.keys(providers).length === 0) {
|
|
3733
|
+
throw new Error(
|
|
3734
|
+
"createAI({ byok: true }) needs `providers` built with byokAdapter \u2014 without them the fleet's default adapters (and the fleet's keys) would be used."
|
|
3735
|
+
);
|
|
3736
|
+
}
|
|
3737
|
+
const unkeyed = Object.entries(providers).filter(([, a]) => !isByokKeyed(a)).map(([name]) => name);
|
|
3738
|
+
if (unkeyed.length > 0) {
|
|
3739
|
+
throw new Error(
|
|
3740
|
+
`createAI({ byok: true }): provider(s) ${unkeyed.join(", ")} were not built with byokAdapter, so they may read the fleet's env key. Build each one as byokAdapter(openaiAdapter, { apiKey }).`
|
|
3741
|
+
);
|
|
3742
|
+
}
|
|
3743
|
+
}
|
|
3744
|
+
|
|
3712
3745
|
// src/client.ts
|
|
3713
3746
|
var DEFAULT_IMAGE_SPEC = {
|
|
3714
3747
|
provider: "fal",
|
|
@@ -3764,6 +3797,7 @@ function defaultCostSink() {
|
|
|
3764
3797
|
}
|
|
3765
3798
|
function createAI(config = {}) {
|
|
3766
3799
|
const cfg = aiConfigSchema.parse(config);
|
|
3800
|
+
if (cfg.byok) assertByokProviders(cfg.providers);
|
|
3767
3801
|
const providers = cfg.providers ?? defaultProviders;
|
|
3768
3802
|
const costSink = cfg.costSink === void 0 ? defaultCostSink() : cfg.costSink ?? void 0;
|
|
3769
3803
|
const budget = cfg.budget ? new BudgetGuard(cfg.budget) : void 0;
|
|
@@ -4714,6 +4748,7 @@ export {
|
|
|
4714
4748
|
azureAdapter,
|
|
4715
4749
|
bflAdapter,
|
|
4716
4750
|
bflCredits,
|
|
4751
|
+
byokAdapter,
|
|
4717
4752
|
chatInputSchema,
|
|
4718
4753
|
checkVoice,
|
|
4719
4754
|
classifyRegionName,
|
|
@@ -4737,6 +4772,7 @@ export {
|
|
|
4737
4772
|
getPrice,
|
|
4738
4773
|
httpTransport,
|
|
4739
4774
|
imageInputSchema,
|
|
4775
|
+
isByokKeyed,
|
|
4740
4776
|
listAzureDanishVoices,
|
|
4741
4777
|
listMediaPrices,
|
|
4742
4778
|
listModels,
|