@broberg/ai-sdk 0.73.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/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
|
@@ -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" },
|
|
@@ -3918,7 +3927,8 @@ Write your entire answer in ${input.language ?? "Danish"}.`;
|
|
|
3918
3927
|
prompt,
|
|
3919
3928
|
maxTokens,
|
|
3920
3929
|
override: override(m),
|
|
3921
|
-
purpose: "second-opinion"
|
|
3930
|
+
purpose: "second-opinion",
|
|
3931
|
+
timeoutMs
|
|
3922
3932
|
}),
|
|
3923
3933
|
timeoutMs,
|
|
3924
3934
|
m.label
|
|
@@ -3942,7 +3952,8 @@ ${o.text}
|
|
|
3942
3952
|
prompt: reviews,
|
|
3943
3953
|
maxTokens: 6e3,
|
|
3944
3954
|
override: override(SECOND_OPINION_SYNTH),
|
|
3945
|
-
purpose: "second-opinion-synthesis"
|
|
3955
|
+
purpose: "second-opinion-synthesis",
|
|
3956
|
+
timeoutMs
|
|
3946
3957
|
}),
|
|
3947
3958
|
timeoutMs,
|
|
3948
3959
|
SECOND_OPINION_SYNTH.label
|
|
@@ -3989,6 +4000,38 @@ function toMarkdown(input, opinions, synthesis, cost) {
|
|
|
3989
4000
|
return lines.join("\n");
|
|
3990
4001
|
}
|
|
3991
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
|
+
|
|
3992
4035
|
// src/voices/registry.ts
|
|
3993
4036
|
var CHECKED_AT = {
|
|
3994
4037
|
// All 5 curated ids confirmed by SYNTHESIS — POST /v1/text-to-speech/{id} returned
|
|
@@ -4225,6 +4268,11 @@ var chatInputSchema = z.object({
|
|
|
4225
4268
|
reasoningEffort: z.enum(["none", "low", "medium", "high"]).optional(),
|
|
4226
4269
|
/** "json" requests JSON-object output (OpenAI-compatible response_format). */
|
|
4227
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(),
|
|
4228
4276
|
...callOptions
|
|
4229
4277
|
});
|
|
4230
4278
|
var visionInputSchema = z.object({
|
|
@@ -4458,8 +4506,8 @@ var aiConfigSchema = z.object({
|
|
|
4458
4506
|
import { randomUUID } from "crypto";
|
|
4459
4507
|
|
|
4460
4508
|
// src/version.ts
|
|
4461
|
-
var VERSION = "0.
|
|
4462
|
-
var SDK_TAG = "@broberg/ai-sdk@0.
|
|
4509
|
+
var VERSION = "0.74.0";
|
|
4510
|
+
var SDK_TAG = "@broberg/ai-sdk@0.74.0";
|
|
4463
4511
|
|
|
4464
4512
|
// src/cost/sinks/upmetrics.ts
|
|
4465
4513
|
function isRetryableStatus(status) {
|
|
@@ -4980,6 +5028,7 @@ function createAI(config = {}) {
|
|
|
4980
5028
|
},
|
|
4981
5029
|
e
|
|
4982
5030
|
);
|
|
5031
|
+
if (isCallerAbort(e)) throw e;
|
|
4983
5032
|
}
|
|
4984
5033
|
}
|
|
4985
5034
|
throw lastErr;
|
|
@@ -5000,6 +5049,7 @@ function createAI(config = {}) {
|
|
|
5000
5049
|
}
|
|
5001
5050
|
async function* chatStreamImpl(input) {
|
|
5002
5051
|
input = chatInputSchema.parse(input);
|
|
5052
|
+
const abort = callAbort(input.signal, input.timeoutMs);
|
|
5003
5053
|
const tier = input.tier ?? "smart";
|
|
5004
5054
|
const messages = toMessages(input);
|
|
5005
5055
|
const estIn = messages.reduce(
|
|
@@ -5026,6 +5076,7 @@ function createAI(config = {}) {
|
|
|
5026
5076
|
let emitted = false;
|
|
5027
5077
|
try {
|
|
5028
5078
|
for await (const ev of adapter.chatStream({
|
|
5079
|
+
signal: abort.signal,
|
|
5029
5080
|
messages,
|
|
5030
5081
|
spec,
|
|
5031
5082
|
tools: input.tools,
|
|
@@ -5050,7 +5101,8 @@ function createAI(config = {}) {
|
|
|
5050
5101
|
yield ev;
|
|
5051
5102
|
}
|
|
5052
5103
|
return;
|
|
5053
|
-
} catch (
|
|
5104
|
+
} catch (raw) {
|
|
5105
|
+
const e = abort.translate(raw, "ai.chatStream");
|
|
5054
5106
|
lastErr = e;
|
|
5055
5107
|
await reportFailure(
|
|
5056
5108
|
{
|
|
@@ -5065,7 +5117,7 @@ function createAI(config = {}) {
|
|
|
5065
5117
|
},
|
|
5066
5118
|
e
|
|
5067
5119
|
);
|
|
5068
|
-
if (emitted || !eligibleForFallback(e)) {
|
|
5120
|
+
if (emitted || isCallerAbort(e) || !eligibleForFallback(e)) {
|
|
5069
5121
|
yield errorEvent(e);
|
|
5070
5122
|
return;
|
|
5071
5123
|
}
|
|
@@ -5076,6 +5128,7 @@ function createAI(config = {}) {
|
|
|
5076
5128
|
const client = {
|
|
5077
5129
|
async chat(input) {
|
|
5078
5130
|
input = chatInputSchema.parse(input);
|
|
5131
|
+
const abort = callAbort(input.signal, input.timeoutMs);
|
|
5079
5132
|
const tier = input.tier ?? "smart";
|
|
5080
5133
|
const messages = toMessages(input);
|
|
5081
5134
|
const estIn = messages.reduce(
|
|
@@ -5095,7 +5148,11 @@ function createAI(config = {}) {
|
|
|
5095
5148
|
invoke: async (spec) => {
|
|
5096
5149
|
const adapter = pickProvider(spec.provider);
|
|
5097
5150
|
if (!adapter.chat) throw new Error(`createAI: provider "${spec.provider}" does not support chat`);
|
|
5098
|
-
|
|
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
|
+
}
|
|
5099
5156
|
}
|
|
5100
5157
|
});
|
|
5101
5158
|
},
|
|
@@ -6059,6 +6116,8 @@ function wouldRouteTo(tier) {
|
|
|
6059
6116
|
export {
|
|
6060
6117
|
AZURE_DANISH_VOICES,
|
|
6061
6118
|
AZURE_DANISH_VOICE_LIST,
|
|
6119
|
+
AiAbortError,
|
|
6120
|
+
AiTimeoutError,
|
|
6062
6121
|
BudgetExceededError,
|
|
6063
6122
|
BudgetGuard,
|
|
6064
6123
|
CONFIG_DERIVED_HOSTS,
|