@broberg/ai-sdk 0.72.0 → 0.74.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-KCHMZ6P5.js → chunk-GMR2UFWI.js} +2 -2
- package/dist/chunk-GMR2UFWI.js.map +1 -0
- package/dist/{chunk-ZL6TFGZ2.js → chunk-XKN2PYBQ.js} +16 -1
- package/dist/chunk-XKN2PYBQ.js.map +1 -0
- package/dist/index.d.ts +23 -8
- package/dist/index.js +81 -12
- package/dist/index.js.map +1 -1
- package/dist/pricing.js +1 -1
- package/dist/{registry-CCKJyveA.d.ts → registry-Dwe4cmUM.d.ts} +2 -0
- package/dist/registry.d.ts +1 -1
- package/dist/registry.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-KCHMZ6P5.js.map +0 -1
- package/dist/chunk-ZL6TFGZ2.js.map +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { U as Usage, C as CostSink, T as Tier, a as ChatResult, b as ChatStreamEvent, c as TranslateResult, I as ImageResult, A as AnimateResult, d as TrainStyleResult, E as EmbeddingResult, e as TranscribeResult, O as OcrResult, M as ModerationResult, J as JudgeResult, V as VectorizeResult, P as PodcastResult, B as BatchRequestItem, f as TierSpec, g as BatchJob, h as BatchResultItem, i as ProviderAdapter, j as ToolCall, k as Tool, l as Transport, m as Capability, R as Region, n as BudgetConfig, o as BudgetStore } from './registry-
|
|
2
|
-
export { p as AlignedWordTimings, q as AvailabilitySource, r as AvailabilityStatus, s as AzureWordBoundary, t as CallOptions, u as ChatRequest, v as ContentPart, D as DialogueRequest, w as DialogueTurn, x as EmbeddingRequest, y as ImageRequest, z as JudgeAnswer, F as JudgeChoiceAnswer, G as JudgeNoulAnswer, H as JudgeQuestion, K as JudgeScoreAnswer, L as LoraWeight, N as Message, Q as ModelStatus, S as ModelUnavailableError, W as ModerationItem, X as ModerationRequest, Y as OcrPage, Z as OcrRequest, _ as ResolveOptions, $ as ResolveResult, a0 as Role, a1 as TierDescription, a2 as TrainStyleRequest, a3 as TranscribeRequest, a4 as TtsRequest, a5 as WordTiming, a6 as alignWordTimings, a7 as classifyRegionName, a8 as describeTier, a9 as listModels, aa as regionOfHost, ab as regionOfProvider, ac as resolveModel } from './registry-
|
|
1
|
+
import { U as Usage, C as CostSink, T as Tier, a as ChatResult, b as ChatStreamEvent, c as TranslateResult, I as ImageResult, A as AnimateResult, d as TrainStyleResult, E as EmbeddingResult, e as TranscribeResult, O as OcrResult, M as ModerationResult, J as JudgeResult, V as VectorizeResult, P as PodcastResult, B as BatchRequestItem, f as TierSpec, g as BatchJob, h as BatchResultItem, i as ProviderAdapter, j as ToolCall, k as Tool, l as Transport, m as Capability, R as Region, n as BudgetConfig, o as BudgetStore } from './registry-Dwe4cmUM.js';
|
|
2
|
+
export { p as AlignedWordTimings, q as AvailabilitySource, r as AvailabilityStatus, s as AzureWordBoundary, t as CallOptions, u as ChatRequest, v as ContentPart, D as DialogueRequest, w as DialogueTurn, x as EmbeddingRequest, y as ImageRequest, z as JudgeAnswer, F as JudgeChoiceAnswer, G as JudgeNoulAnswer, H as JudgeQuestion, K as JudgeScoreAnswer, L as LoraWeight, N as Message, Q as ModelStatus, S as ModelUnavailableError, W as ModerationItem, X as ModerationRequest, Y as OcrPage, Z as OcrRequest, _ as ResolveOptions, $ as ResolveResult, a0 as Role, a1 as TierDescription, a2 as TrainStyleRequest, a3 as TranscribeRequest, a4 as TtsRequest, a5 as WordTiming, a6 as alignWordTimings, a7 as classifyRegionName, a8 as describeTier, a9 as listModels, aa as regionOfHost, ab as regionOfProvider, ac as resolveModel } from './registry-Dwe4cmUM.js';
|
|
3
3
|
import { z } from 'zod';
|
|
4
4
|
export { CheapestQuery, CheapestResult, CheapestRow, DEFAULT_CLIP_SEC, MEDIA_PRICING_CHECKED_AT, MediaPrice, MediaUnit, PRICING_STALE_AFTER_DAYS, PriceKind, PricingFreshness, UnitFreshness, UpstreamStatus, cheapestModels, classifyKind, getMediaPrice, listMediaPrices, pricingFreshness, pricingGeneratedAt } from './pricing.js';
|
|
5
5
|
|
|
@@ -30,9 +30,10 @@ interface SecondOpinionInput {
|
|
|
30
30
|
synthesize?: boolean;
|
|
31
31
|
maxTokens?: number;
|
|
32
32
|
/** F088.5 — per-model time limit. A model that has not answered by then gets an
|
|
33
|
-
* error row ("timeout") and the others are delivered. Default 5 min.
|
|
34
|
-
*
|
|
35
|
-
*
|
|
33
|
+
* error row ("timeout") and the others are delivered. Default 5 min. Since F090
|
|
34
|
+
* (v0.74) the provider request itself is aborted — the connection closes, so a late
|
|
35
|
+
* answer is not billed. The race below stays as a backstop for an adapter that does
|
|
36
|
+
* not forward the signal. */
|
|
36
37
|
timeoutMs?: number;
|
|
37
38
|
/** USD→DKK rate for the price line. Omitted: the ECB reference rate is fetched. */
|
|
38
39
|
usdToDkk?: number;
|
|
@@ -460,6 +461,8 @@ declare const chatInputSchema: z.ZodObject<{
|
|
|
460
461
|
text: "text";
|
|
461
462
|
json: "json";
|
|
462
463
|
}>>;
|
|
464
|
+
timeoutMs: z.ZodOptional<z.ZodNumber>;
|
|
465
|
+
signal: z.ZodOptional<z.ZodInstanceOf<AbortSignal>>;
|
|
463
466
|
}, z.core.$strip>;
|
|
464
467
|
declare const visionInputSchema: z.ZodObject<{
|
|
465
468
|
tier: z.ZodOptional<z.ZodEnum<{
|
|
@@ -1233,6 +1236,16 @@ type ChatVision = Pick<AiClient, "chat" | "vision">;
|
|
|
1233
1236
|
declare function matchLabel(answer: unknown, labels: string[]): string | null;
|
|
1234
1237
|
declare function makeContracts(client: ChatVision): Contracts;
|
|
1235
1238
|
|
|
1239
|
+
/** The call ran longer than the caller's `timeoutMs`; the request was aborted. */
|
|
1240
|
+
declare class AiTimeoutError extends Error {
|
|
1241
|
+
readonly timeoutMs: number;
|
|
1242
|
+
constructor(timeoutMs: number, what?: string);
|
|
1243
|
+
}
|
|
1244
|
+
/** The caller's own `signal` aborted the call. */
|
|
1245
|
+
declare class AiAbortError extends Error {
|
|
1246
|
+
constructor(what?: string);
|
|
1247
|
+
}
|
|
1248
|
+
|
|
1236
1249
|
/** Convert SDK tools to a provider's request format. */
|
|
1237
1250
|
declare function toProviderTools(tools: Tool[], provider: string): unknown;
|
|
1238
1251
|
/** Parse a single provider-shaped tool call back into the SDK ToolCall shape. */
|
|
@@ -1569,8 +1582,8 @@ declare const falStubAdapter: ProviderAdapter;
|
|
|
1569
1582
|
* wires the live adapters. */
|
|
1570
1583
|
declare const stubProviders: Record<string, ProviderAdapter>;
|
|
1571
1584
|
|
|
1572
|
-
declare const VERSION: "0.
|
|
1573
|
-
declare const SDK_TAG: "@broberg/ai-sdk@0.
|
|
1585
|
+
declare const VERSION: "0.74.0";
|
|
1586
|
+
declare const SDK_TAG: "@broberg/ai-sdk@0.74.0";
|
|
1574
1587
|
|
|
1575
1588
|
/** Built-in defaults. Every entry is overridable via AiConfig.defaults or a
|
|
1576
1589
|
* per-call override.
|
|
@@ -2036,6 +2049,8 @@ interface TransportRequest {
|
|
|
2036
2049
|
* config MUST pass it here, or a test's fake fetch is silently bypassed and the call
|
|
2037
2050
|
* reaches the real provider with whatever key is in the environment. */
|
|
2038
2051
|
fetch?: typeof fetch;
|
|
2052
|
+
/** F090 — aborts the fetch itself (timeoutMs / caller signal). */
|
|
2053
|
+
signal?: AbortSignal;
|
|
2039
2054
|
http?: {
|
|
2040
2055
|
url: string;
|
|
2041
2056
|
method?: string;
|
|
@@ -2137,4 +2152,4 @@ declare function memorySearchCache(max?: number): SearchCache;
|
|
|
2137
2152
|
|
|
2138
2153
|
declare function search(req: SearchRequest, opts?: SearchOptions): Promise<SearchResult>;
|
|
2139
2154
|
|
|
2140
|
-
export { AZURE_DANISH_VOICES, AZURE_DANISH_VOICE_LIST, type AiClient, type AiConfig, type AzureVoiceInfo, BatchJob, BatchRequestItem, BatchResultItem, type BflAdapterConfig, type BflCredits, BudgetConfig, BudgetExceededError, BudgetGuard, BudgetStore, CONFIG_DERIVED_HOSTS, Capability, type ChatInput, ChatResult, ChatStreamEvent, type CheckVoiceOptions, type ClassifyInput, type ClassifyResult, type Contracts, type CostQuery, CostSink, type CostSummary, type CostSummaryQuery, type CostTimeseriesQuery, DEFAULT_BASE_URLS, DEFAULT_SEARCH_ROUTES, DEFAULT_TIER_MAP, type DesignInput, type DesignResult, type DiscordSinkConfig, ELEVENLABS_DANISH_VOICES, type EmbeddingInput, EmbeddingResult, type ExtractInput, type ExtractResult, type FalAdapterConfig, type FixedHostProvider, type HttpResponse, INPUT_LIMITS, type ImageInput, ImageResult, type JudgeInput, JudgeResult, LOCALLY_PINNED_HOSTS, MICROSOFT_DECISION_DEFAULT_DEPLOYMENT, type MockupInput, type MockupResult, type ModerationInput, ModerationResult, type OcrInput, OcrResult, type OpenAICompatibleConfig, type Opinion, type PanelMember, type PodcastInput, PodcastResult, type PriceDriftResult, type PriceDriftRow, type PricingEntry, ProviderAdapter, type RefreshOptions, type RefreshResult, Region, type RerankInput, type RerankResult, type RouteForecast, SDK_TAG, SEARCH_CACHE_TTL_MS, SEARCH_PRICE_USD, SECOND_OPINION_DEFAULT_TIMEOUT_MS, SECOND_OPINION_INSTRUCTION, SECOND_OPINION_PANEL, SECOND_OPINION_SYNTH, SECOND_OPINION_SYNTH_INSTRUCTION, SearchBudgetExceededError, type SearchCache, type SearchCapStore, type SearchCredentials, type SearchItem, SearchKeyMissingError, type SearchOptions, type SearchProviderId, type SearchPurpose, type SearchRequest, type SearchResult, type SearchRoute, type SecondOpinionInput, type SecondOpinionResult, type SqliteBudgetStoreConfig, type SqliteSinkConfig, StreamHttpError, type SubprocessResponse, Tier, TierSpec, Tool, ToolCall, type TrainStyleInput, TrainStyleResult, type TranscribeInput, TranscribeResult, type TranslateInput, TranslateResult, Transport, type TransportRequest, type TransportResponse, type TtsInput, type UpmetricsCostClientConfig, UpmetricsCostError, type UpmetricsCostRow, type UpmetricsCostSummary, type UpmetricsCostTimeseries, type UpmetricsSink, type UpmetricsSinkConfig, type UpmetricsSinkStats, Usage, VERSION, type VideoInput, type VisionInput, type VoiceInfo, type VoiceProvider, type VoiceResolveResult, type VoiceStatus, VoiceUnavailableError, type WebSearchContext, type WebSearchToolResult, ZDR_PROVIDERS, aiConfigSchema, anthropicAdapter, anthropicApiAdapter, anthropicSubprocessAdapter, azureAdapter, bflAdapter, bflCredits, byokAdapter, chatInputSchema, checkPriceDrift, checkVoice, 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, memorySearchCache, messageSchema, microsoftDecisionAdapter, mistralAdapter, mistralStubAdapter, multiSink, noopSink, openaiAdapter, openaiStubAdapter, openrouterAdapter, parseClaudeCliJson, parseJsonLoose, recraftAdapter, refreshAvailability, requestyAdapter, resetRefreshState, resetRegistry, resolveAzureVoice, resolveTier, resolveVoice, routeSearch, runWebSearch, search, sqliteBudgetStore, sqliteSink, streamTransport, stubProviders, subprocessTransport, tierSpecSchema, toProviderTools, toolSchema, translateInputSchema, typesafeAdapter, upmetricsCostClient, upmetricsSink, usdFromMicro, vertexAdapter, visionInputSchema, webSearchTool, wouldProviderRouteTo, wouldRouteTo };
|
|
2155
|
+
export { AZURE_DANISH_VOICES, AZURE_DANISH_VOICE_LIST, AiAbortError, type AiClient, type AiConfig, AiTimeoutError, type AzureVoiceInfo, BatchJob, BatchRequestItem, BatchResultItem, type BflAdapterConfig, type BflCredits, BudgetConfig, BudgetExceededError, BudgetGuard, BudgetStore, CONFIG_DERIVED_HOSTS, Capability, type ChatInput, ChatResult, ChatStreamEvent, type CheckVoiceOptions, type ClassifyInput, type ClassifyResult, type Contracts, type CostQuery, CostSink, type CostSummary, type CostSummaryQuery, type CostTimeseriesQuery, DEFAULT_BASE_URLS, DEFAULT_SEARCH_ROUTES, DEFAULT_TIER_MAP, type DesignInput, type DesignResult, type DiscordSinkConfig, ELEVENLABS_DANISH_VOICES, type EmbeddingInput, EmbeddingResult, type ExtractInput, type ExtractResult, type FalAdapterConfig, type FixedHostProvider, type HttpResponse, INPUT_LIMITS, type ImageInput, ImageResult, type JudgeInput, JudgeResult, LOCALLY_PINNED_HOSTS, MICROSOFT_DECISION_DEFAULT_DEPLOYMENT, type MockupInput, type MockupResult, type ModerationInput, ModerationResult, type OcrInput, OcrResult, type OpenAICompatibleConfig, type Opinion, type PanelMember, type PodcastInput, PodcastResult, type PriceDriftResult, type PriceDriftRow, type PricingEntry, ProviderAdapter, type RefreshOptions, type RefreshResult, Region, type RerankInput, type RerankResult, type RouteForecast, SDK_TAG, SEARCH_CACHE_TTL_MS, SEARCH_PRICE_USD, SECOND_OPINION_DEFAULT_TIMEOUT_MS, SECOND_OPINION_INSTRUCTION, SECOND_OPINION_PANEL, SECOND_OPINION_SYNTH, SECOND_OPINION_SYNTH_INSTRUCTION, SearchBudgetExceededError, type SearchCache, type SearchCapStore, type SearchCredentials, type SearchItem, SearchKeyMissingError, type SearchOptions, type SearchProviderId, type SearchPurpose, type SearchRequest, type SearchResult, type SearchRoute, type SecondOpinionInput, type SecondOpinionResult, type SqliteBudgetStoreConfig, type SqliteSinkConfig, StreamHttpError, type SubprocessResponse, Tier, TierSpec, Tool, ToolCall, type TrainStyleInput, TrainStyleResult, type TranscribeInput, TranscribeResult, type TranslateInput, TranslateResult, Transport, type TransportRequest, type TransportResponse, type TtsInput, type UpmetricsCostClientConfig, UpmetricsCostError, type UpmetricsCostRow, type UpmetricsCostSummary, type UpmetricsCostTimeseries, type UpmetricsSink, type UpmetricsSinkConfig, type UpmetricsSinkStats, Usage, VERSION, type VideoInput, type VisionInput, type VoiceInfo, type VoiceProvider, type VoiceResolveResult, type VoiceStatus, VoiceUnavailableError, type WebSearchContext, type WebSearchToolResult, ZDR_PROVIDERS, aiConfigSchema, anthropicAdapter, anthropicApiAdapter, anthropicSubprocessAdapter, azureAdapter, bflAdapter, bflCredits, byokAdapter, chatInputSchema, checkPriceDrift, checkVoice, 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, memorySearchCache, messageSchema, microsoftDecisionAdapter, mistralAdapter, mistralStubAdapter, multiSink, noopSink, openaiAdapter, openaiStubAdapter, openrouterAdapter, parseClaudeCliJson, parseJsonLoose, recraftAdapter, refreshAvailability, requestyAdapter, resetRefreshState, resetRegistry, resolveAzureVoice, resolveTier, resolveVoice, routeSearch, runWebSearch, search, sqliteBudgetStore, sqliteSink, streamTransport, stubProviders, subprocessTransport, tierSpecSchema, toProviderTools, toolSchema, translateInputSchema, typesafeAdapter, upmetricsCostClient, upmetricsSink, usdFromMicro, vertexAdapter, visionInputSchema, webSearchTool, wouldProviderRouteTo, wouldRouteTo };
|
package/dist/index.js
CHANGED
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
resolveModel,
|
|
12
12
|
resolveTier,
|
|
13
13
|
setAvailability
|
|
14
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-GMR2UFWI.js";
|
|
15
15
|
import {
|
|
16
16
|
DEFAULT_CLIP_SEC,
|
|
17
17
|
MEDIA_PRICING,
|
|
@@ -23,7 +23,7 @@ import {
|
|
|
23
23
|
listMediaPrices,
|
|
24
24
|
pricingFreshness,
|
|
25
25
|
pricingGeneratedAt
|
|
26
|
-
} from "./chunk-
|
|
26
|
+
} from "./chunk-XKN2PYBQ.js";
|
|
27
27
|
import {
|
|
28
28
|
PRICING,
|
|
29
29
|
getPrice
|
|
@@ -170,7 +170,8 @@ function classifyFailure(err) {
|
|
|
170
170
|
const e = err;
|
|
171
171
|
const name = e?.name ?? "";
|
|
172
172
|
const message = String(e?.message ?? "");
|
|
173
|
-
if (name === "
|
|
173
|
+
if (name === "AiAbortError") return { errorCode: "aborted", errorKind: "other" };
|
|
174
|
+
if (name === "AbortError" || name === "TimeoutError" || name === "AiTimeoutError" || /timed? ?out/i.test(message.split("\n")[0] ?? "")) {
|
|
174
175
|
return { errorCode: "timeout", errorKind: "timeout" };
|
|
175
176
|
}
|
|
176
177
|
let status = typeof e?.status === "number" ? e.status : void 0;
|
|
@@ -437,6 +438,7 @@ async function httpTransport(req) {
|
|
|
437
438
|
const res = await (req.fetch ?? fetch)(url, {
|
|
438
439
|
method,
|
|
439
440
|
headers,
|
|
441
|
+
signal: req.signal,
|
|
440
442
|
body: body === void 0 ? void 0 : typeof body === "string" ? body : JSON.stringify(body)
|
|
441
443
|
});
|
|
442
444
|
const text = await res.text().catch(() => "");
|
|
@@ -529,6 +531,7 @@ async function* streamTransport(req) {
|
|
|
529
531
|
const res = await fetchImpl(url, {
|
|
530
532
|
method,
|
|
531
533
|
headers,
|
|
534
|
+
signal: req.signal,
|
|
532
535
|
body: body === void 0 ? void 0 : typeof body === "string" ? body : JSON.stringify(body)
|
|
533
536
|
});
|
|
534
537
|
if (!res.ok || !res.body) {
|
|
@@ -879,6 +882,7 @@ function anthropicAdapter(config = {}) {
|
|
|
879
882
|
const res = await httpTransport({
|
|
880
883
|
spec: req.spec,
|
|
881
884
|
fetch: config.fetch,
|
|
885
|
+
signal: req.signal,
|
|
882
886
|
http: {
|
|
883
887
|
url: `${baseUrl}/v1/messages`,
|
|
884
888
|
headers: {
|
|
@@ -937,6 +941,7 @@ function anthropicAdapter(config = {}) {
|
|
|
937
941
|
const stream = streamTransport({
|
|
938
942
|
spec: req.spec,
|
|
939
943
|
fetch: config.fetch,
|
|
944
|
+
signal: req.signal,
|
|
940
945
|
http: {
|
|
941
946
|
url: `${baseUrl}/v1/messages`,
|
|
942
947
|
headers: {
|
|
@@ -1165,6 +1170,7 @@ function makeOpenAICompatibleAdapter(config) {
|
|
|
1165
1170
|
const res = await httpTransport({
|
|
1166
1171
|
spec: req.spec,
|
|
1167
1172
|
fetch: config.fetch,
|
|
1173
|
+
signal: req.signal,
|
|
1168
1174
|
http: {
|
|
1169
1175
|
url: `${config.baseUrl}/chat/completions`,
|
|
1170
1176
|
headers: {
|
|
@@ -1223,6 +1229,7 @@ function makeOpenAICompatibleAdapter(config) {
|
|
|
1223
1229
|
const stream = streamTransport({
|
|
1224
1230
|
spec: req.spec,
|
|
1225
1231
|
fetch: config.fetch,
|
|
1232
|
+
signal: req.signal,
|
|
1226
1233
|
http: {
|
|
1227
1234
|
url: `${config.baseUrl}/chat/completions`,
|
|
1228
1235
|
headers: {
|
|
@@ -1482,6 +1489,7 @@ function geminiAdapter(config = {}) {
|
|
|
1482
1489
|
const res = await httpTransport({
|
|
1483
1490
|
spec: req.spec,
|
|
1484
1491
|
fetch: config.fetch,
|
|
1492
|
+
signal: req.signal,
|
|
1485
1493
|
http: {
|
|
1486
1494
|
url: `${baseUrl}/models/${req.spec.model}:generateContent?key=${encodeURIComponent(apiKey)}`,
|
|
1487
1495
|
headers: { "content-type": "application/json" },
|
|
@@ -1513,6 +1521,7 @@ function geminiAdapter(config = {}) {
|
|
|
1513
1521
|
const stream = streamTransport({
|
|
1514
1522
|
spec: req.spec,
|
|
1515
1523
|
fetch: config.fetch,
|
|
1524
|
+
signal: req.signal,
|
|
1516
1525
|
http: {
|
|
1517
1526
|
url: `${baseUrl}/models/${req.spec.model}:streamGenerateContent?alt=sse&key=${encodeURIComponent(apiKey)}`,
|
|
1518
1527
|
headers: { "content-type": "application/json" },
|
|
@@ -3311,7 +3320,17 @@ function bflAdapter(config = {}) {
|
|
|
3311
3320
|
const headers = { "content-type": "application/json", "x-key": apiKey };
|
|
3312
3321
|
const body = { prompt: req.prompt };
|
|
3313
3322
|
const flux2PromptOnly = !req.referenceImages?.length && !req.finetune && req.spec.model.startsWith("flux-2");
|
|
3314
|
-
if (req.
|
|
3323
|
+
if (req.spec.model.startsWith("flux-3-image")) {
|
|
3324
|
+
if (req.finetune) throw new Error(`bfl adapter: ${req.spec.model} takes no finetune \u2014 finetunes run on flux-pro-1.1-ultra-finetuned`);
|
|
3325
|
+
if (req.referenceImages?.length) body.images = req.referenceImages.map(toBflImage);
|
|
3326
|
+
if (req.width) body.width = req.width;
|
|
3327
|
+
if (req.height) body.height = req.height;
|
|
3328
|
+
body.safety_tolerance = req.safetyTolerance ?? 2;
|
|
3329
|
+
if (req.spec.model === "flux-3-image-klein") {
|
|
3330
|
+
if (req.seed !== void 0) body.seed = req.seed;
|
|
3331
|
+
body.output_format = req.outputFormat ?? "jpeg";
|
|
3332
|
+
}
|
|
3333
|
+
} else if (req.referenceImages?.length || flux2PromptOnly) {
|
|
3315
3334
|
req.referenceImages?.forEach((img, i) => {
|
|
3316
3335
|
body[i === 0 ? "input_image" : `input_image_${i + 1}`] = toBflImage(img);
|
|
3317
3336
|
});
|
|
@@ -3356,7 +3375,7 @@ function bflAdapter(config = {}) {
|
|
|
3356
3375
|
usage.costUsd = submit.cost * BFL_CREDIT_USD;
|
|
3357
3376
|
usage.costBasis = "reported";
|
|
3358
3377
|
} else {
|
|
3359
|
-
usage.costUsd = config.pricePerImage ?? getMediaPrice("bfl", "flux-pro-1.1-ultra-finetuned")?.usd ?? 0;
|
|
3378
|
+
usage.costUsd = config.pricePerImage ?? getMediaPrice("bfl", req.spec.model)?.usd ?? getMediaPrice("bfl", "flux-pro-1.1-ultra-finetuned")?.usd ?? 0;
|
|
3360
3379
|
usage.costBasis = config.pricePerImage !== void 0 ? "computed" : "estimated";
|
|
3361
3380
|
}
|
|
3362
3381
|
return { url: sample, usage };
|
|
@@ -3908,7 +3927,8 @@ Write your entire answer in ${input.language ?? "Danish"}.`;
|
|
|
3908
3927
|
prompt,
|
|
3909
3928
|
maxTokens,
|
|
3910
3929
|
override: override(m),
|
|
3911
|
-
purpose: "second-opinion"
|
|
3930
|
+
purpose: "second-opinion",
|
|
3931
|
+
timeoutMs
|
|
3912
3932
|
}),
|
|
3913
3933
|
timeoutMs,
|
|
3914
3934
|
m.label
|
|
@@ -3932,7 +3952,8 @@ ${o.text}
|
|
|
3932
3952
|
prompt: reviews,
|
|
3933
3953
|
maxTokens: 6e3,
|
|
3934
3954
|
override: override(SECOND_OPINION_SYNTH),
|
|
3935
|
-
purpose: "second-opinion-synthesis"
|
|
3955
|
+
purpose: "second-opinion-synthesis",
|
|
3956
|
+
timeoutMs
|
|
3936
3957
|
}),
|
|
3937
3958
|
timeoutMs,
|
|
3938
3959
|
SECOND_OPINION_SYNTH.label
|
|
@@ -3979,6 +4000,38 @@ function toMarkdown(input, opinions, synthesis, cost) {
|
|
|
3979
4000
|
return lines.join("\n");
|
|
3980
4001
|
}
|
|
3981
4002
|
|
|
4003
|
+
// src/transport/abort.ts
|
|
4004
|
+
var AiTimeoutError = class extends Error {
|
|
4005
|
+
timeoutMs;
|
|
4006
|
+
constructor(timeoutMs, what = "ai call") {
|
|
4007
|
+
super(`${what} timed out after ${timeoutMs} ms \u2014 the request was aborted`);
|
|
4008
|
+
this.name = "AiTimeoutError";
|
|
4009
|
+
this.timeoutMs = timeoutMs;
|
|
4010
|
+
}
|
|
4011
|
+
};
|
|
4012
|
+
var AiAbortError = class extends Error {
|
|
4013
|
+
constructor(what = "ai call") {
|
|
4014
|
+
super(`${what} was aborted by the caller's signal`);
|
|
4015
|
+
this.name = "AiAbortError";
|
|
4016
|
+
}
|
|
4017
|
+
};
|
|
4018
|
+
function callAbort(callerSignal, timeoutMs) {
|
|
4019
|
+
const timeout = timeoutMs !== void 0 ? AbortSignal.timeout(timeoutMs) : void 0;
|
|
4020
|
+
const parts = [callerSignal, timeout].filter((s) => !!s);
|
|
4021
|
+
const signal = parts.length === 0 ? void 0 : parts.length === 1 ? parts[0] : AbortSignal.any(parts);
|
|
4022
|
+
return {
|
|
4023
|
+
signal,
|
|
4024
|
+
translate(e, what) {
|
|
4025
|
+
if (!signal?.aborted) return e;
|
|
4026
|
+
if (timeout?.aborted && !callerSignal?.aborted) return new AiTimeoutError(timeoutMs, what);
|
|
4027
|
+
return new AiAbortError(what);
|
|
4028
|
+
}
|
|
4029
|
+
};
|
|
4030
|
+
}
|
|
4031
|
+
function isCallerAbort(e) {
|
|
4032
|
+
return e instanceof AiTimeoutError || e instanceof AiAbortError;
|
|
4033
|
+
}
|
|
4034
|
+
|
|
3982
4035
|
// src/voices/registry.ts
|
|
3983
4036
|
var CHECKED_AT = {
|
|
3984
4037
|
// All 5 curated ids confirmed by SYNTHESIS — POST /v1/text-to-speech/{id} returned
|
|
@@ -4215,6 +4268,11 @@ var chatInputSchema = z.object({
|
|
|
4215
4268
|
reasoningEffort: z.enum(["none", "low", "medium", "high"]).optional(),
|
|
4216
4269
|
/** "json" requests JSON-object output (OpenAI-compatible response_format). */
|
|
4217
4270
|
responseFormat: z.enum(["json", "text"]).optional(),
|
|
4271
|
+
/** F090 — abort the request after this many ms (the connection is closed, not just
|
|
4272
|
+
* abandoned). Throws AiTimeoutError. */
|
|
4273
|
+
timeoutMs: z.number().int().positive().optional(),
|
|
4274
|
+
/** F090 — abort the request from outside. Throws AiAbortError. */
|
|
4275
|
+
signal: z.instanceof(AbortSignal).optional(),
|
|
4218
4276
|
...callOptions
|
|
4219
4277
|
});
|
|
4220
4278
|
var visionInputSchema = z.object({
|
|
@@ -4448,8 +4506,8 @@ var aiConfigSchema = z.object({
|
|
|
4448
4506
|
import { randomUUID } from "crypto";
|
|
4449
4507
|
|
|
4450
4508
|
// src/version.ts
|
|
4451
|
-
var VERSION = "0.
|
|
4452
|
-
var SDK_TAG = "@broberg/ai-sdk@0.
|
|
4509
|
+
var VERSION = "0.74.0";
|
|
4510
|
+
var SDK_TAG = "@broberg/ai-sdk@0.74.0";
|
|
4453
4511
|
|
|
4454
4512
|
// src/cost/sinks/upmetrics.ts
|
|
4455
4513
|
function isRetryableStatus(status) {
|
|
@@ -4970,6 +5028,7 @@ function createAI(config = {}) {
|
|
|
4970
5028
|
},
|
|
4971
5029
|
e
|
|
4972
5030
|
);
|
|
5031
|
+
if (isCallerAbort(e)) throw e;
|
|
4973
5032
|
}
|
|
4974
5033
|
}
|
|
4975
5034
|
throw lastErr;
|
|
@@ -4990,6 +5049,7 @@ function createAI(config = {}) {
|
|
|
4990
5049
|
}
|
|
4991
5050
|
async function* chatStreamImpl(input) {
|
|
4992
5051
|
input = chatInputSchema.parse(input);
|
|
5052
|
+
const abort = callAbort(input.signal, input.timeoutMs);
|
|
4993
5053
|
const tier = input.tier ?? "smart";
|
|
4994
5054
|
const messages = toMessages(input);
|
|
4995
5055
|
const estIn = messages.reduce(
|
|
@@ -5016,6 +5076,7 @@ function createAI(config = {}) {
|
|
|
5016
5076
|
let emitted = false;
|
|
5017
5077
|
try {
|
|
5018
5078
|
for await (const ev of adapter.chatStream({
|
|
5079
|
+
signal: abort.signal,
|
|
5019
5080
|
messages,
|
|
5020
5081
|
spec,
|
|
5021
5082
|
tools: input.tools,
|
|
@@ -5040,7 +5101,8 @@ function createAI(config = {}) {
|
|
|
5040
5101
|
yield ev;
|
|
5041
5102
|
}
|
|
5042
5103
|
return;
|
|
5043
|
-
} catch (
|
|
5104
|
+
} catch (raw) {
|
|
5105
|
+
const e = abort.translate(raw, "ai.chatStream");
|
|
5044
5106
|
lastErr = e;
|
|
5045
5107
|
await reportFailure(
|
|
5046
5108
|
{
|
|
@@ -5055,7 +5117,7 @@ function createAI(config = {}) {
|
|
|
5055
5117
|
},
|
|
5056
5118
|
e
|
|
5057
5119
|
);
|
|
5058
|
-
if (emitted || !eligibleForFallback(e)) {
|
|
5120
|
+
if (emitted || isCallerAbort(e) || !eligibleForFallback(e)) {
|
|
5059
5121
|
yield errorEvent(e);
|
|
5060
5122
|
return;
|
|
5061
5123
|
}
|
|
@@ -5066,6 +5128,7 @@ function createAI(config = {}) {
|
|
|
5066
5128
|
const client = {
|
|
5067
5129
|
async chat(input) {
|
|
5068
5130
|
input = chatInputSchema.parse(input);
|
|
5131
|
+
const abort = callAbort(input.signal, input.timeoutMs);
|
|
5069
5132
|
const tier = input.tier ?? "smart";
|
|
5070
5133
|
const messages = toMessages(input);
|
|
5071
5134
|
const estIn = messages.reduce(
|
|
@@ -5085,7 +5148,11 @@ function createAI(config = {}) {
|
|
|
5085
5148
|
invoke: async (spec) => {
|
|
5086
5149
|
const adapter = pickProvider(spec.provider);
|
|
5087
5150
|
if (!adapter.chat) throw new Error(`createAI: provider "${spec.provider}" does not support chat`);
|
|
5088
|
-
|
|
5151
|
+
try {
|
|
5152
|
+
return await adapter.chat({ signal: abort.signal, messages, spec, tools: input.tools, maxTokens: input.maxTokens, temperature: input.temperature, reasoningEffort: input.reasoningEffort, responseFormat: input.responseFormat, promptCacheKey: input.promptCacheKey, promptCache: input.promptCache ?? cfg.promptCache });
|
|
5153
|
+
} catch (e) {
|
|
5154
|
+
throw abort.translate(e, "ai.chat");
|
|
5155
|
+
}
|
|
5089
5156
|
}
|
|
5090
5157
|
});
|
|
5091
5158
|
},
|
|
@@ -6049,6 +6116,8 @@ function wouldRouteTo(tier) {
|
|
|
6049
6116
|
export {
|
|
6050
6117
|
AZURE_DANISH_VOICES,
|
|
6051
6118
|
AZURE_DANISH_VOICE_LIST,
|
|
6119
|
+
AiAbortError,
|
|
6120
|
+
AiTimeoutError,
|
|
6052
6121
|
BudgetExceededError,
|
|
6053
6122
|
BudgetGuard,
|
|
6054
6123
|
CONFIG_DERIVED_HOSTS,
|