@broberg/ai-sdk 0.78.6 → 0.78.8
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 +28 -4
- package/dist/index.js +127 -33
- package/dist/index.js.map +1 -1
- package/dist/{registry-UIY_A6GR.d.ts → registry-C65-nbWA.d.ts} +17 -2
- package/dist/registry.d.ts +1 -1
- package/package.json +1 -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 LATEST, N as LatestEntry, Q as LoraWeight, S as Message, W as ModelStatus, X as ModelUnavailableError, Y as ModerationItem, Z as ModerationRequest, _ as OcrPage, $ as OcrRequest, a0 as ResolveOptions, a1 as ResolveResult, a2 as Role, a3 as TierDescription, a4 as TrainStyleRequest, a5 as TranscribeRequest, a6 as
|
|
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-C65-nbWA.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 LATEST, N as LatestEntry, Q as LoraWeight, S as Message, W as ModelStatus, X as ModelUnavailableError, Y as ModerationItem, Z as ModerationRequest, _ as OcrPage, $ as OcrRequest, a0 as ResolveOptions, a1 as ResolveResult, a2 as Role, a3 as TierDescription, a4 as TrainStyleRequest, a5 as TranscribeRequest, a6 as TranscriptCorrection, a7 as TtsRequest, a8 as WordTiming, a9 as alignWordTimings, aa as classifyRegionName, ab as describeTier, ac as listLatest, ad as listModels, ae as regionOfHost, af as regionOfProvider, ag as resolveLatest, ah as resolveModel } from './registry-C65-nbWA.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
|
|
|
@@ -341,6 +341,7 @@ declare const INPUT_LIMITS: {
|
|
|
341
341
|
readonly stateItems: 10000;
|
|
342
342
|
readonly scriptLines: 10000;
|
|
343
343
|
readonly pronunciations: 10000;
|
|
344
|
+
readonly corrections: 10000;
|
|
344
345
|
};
|
|
345
346
|
declare const tierSpecSchema: z.ZodObject<{
|
|
346
347
|
provider: z.ZodString;
|
|
@@ -416,6 +417,7 @@ declare const chatInputSchema: z.ZodObject<{
|
|
|
416
417
|
purpose: z.ZodOptional<z.ZodString>;
|
|
417
418
|
allowFloating: z.ZodOptional<z.ZodBoolean>;
|
|
418
419
|
labels: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
420
|
+
retryOn429: z.ZodOptional<z.ZodBoolean>;
|
|
419
421
|
promptCacheKey: z.ZodOptional<z.ZodString>;
|
|
420
422
|
promptCache: z.ZodOptional<z.ZodBoolean>;
|
|
421
423
|
prompt: z.ZodOptional<z.ZodString>;
|
|
@@ -501,6 +503,7 @@ declare const visionInputSchema: z.ZodObject<{
|
|
|
501
503
|
purpose: z.ZodOptional<z.ZodString>;
|
|
502
504
|
allowFloating: z.ZodOptional<z.ZodBoolean>;
|
|
503
505
|
labels: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
506
|
+
retryOn429: z.ZodOptional<z.ZodBoolean>;
|
|
504
507
|
image: z.ZodUnion<readonly [z.ZodString, z.ZodInstanceOf<Uint8Array<ArrayBuffer>>]>;
|
|
505
508
|
prompt: z.ZodString;
|
|
506
509
|
mimeType: z.ZodOptional<z.ZodString>;
|
|
@@ -551,6 +554,7 @@ declare const videoInputSchema: z.ZodObject<{
|
|
|
551
554
|
purpose: z.ZodOptional<z.ZodString>;
|
|
552
555
|
allowFloating: z.ZodOptional<z.ZodBoolean>;
|
|
553
556
|
labels: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
557
|
+
retryOn429: z.ZodOptional<z.ZodBoolean>;
|
|
554
558
|
video: z.ZodUnion<readonly [z.ZodString, z.ZodInstanceOf<Uint8Array<ArrayBuffer>>]>;
|
|
555
559
|
prompt: z.ZodString;
|
|
556
560
|
mimeType: z.ZodOptional<z.ZodString>;
|
|
@@ -593,6 +597,7 @@ declare const translateInputSchema: z.ZodObject<{
|
|
|
593
597
|
purpose: z.ZodOptional<z.ZodString>;
|
|
594
598
|
allowFloating: z.ZodOptional<z.ZodBoolean>;
|
|
595
599
|
labels: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
600
|
+
retryOn429: z.ZodOptional<z.ZodBoolean>;
|
|
596
601
|
text: z.ZodString;
|
|
597
602
|
to: z.ZodString;
|
|
598
603
|
from: z.ZodOptional<z.ZodString>;
|
|
@@ -634,6 +639,7 @@ declare const imageInputSchema: z.ZodObject<{
|
|
|
634
639
|
purpose: z.ZodOptional<z.ZodString>;
|
|
635
640
|
allowFloating: z.ZodOptional<z.ZodBoolean>;
|
|
636
641
|
labels: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
642
|
+
retryOn429: z.ZodOptional<z.ZodBoolean>;
|
|
637
643
|
prompt: z.ZodString;
|
|
638
644
|
width: z.ZodOptional<z.ZodNumber>;
|
|
639
645
|
height: z.ZodOptional<z.ZodNumber>;
|
|
@@ -691,6 +697,7 @@ declare const animateInputSchema: z.ZodObject<{
|
|
|
691
697
|
purpose: z.ZodOptional<z.ZodString>;
|
|
692
698
|
allowFloating: z.ZodOptional<z.ZodBoolean>;
|
|
693
699
|
labels: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
700
|
+
retryOn429: z.ZodOptional<z.ZodBoolean>;
|
|
694
701
|
image: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodInstanceOf<Uint8Array<ArrayBuffer>>]>>;
|
|
695
702
|
prompt: z.ZodOptional<z.ZodString>;
|
|
696
703
|
durationSec: z.ZodOptional<z.ZodNumber>;
|
|
@@ -734,6 +741,7 @@ declare const trainStyleInputSchema: z.ZodObject<{
|
|
|
734
741
|
purpose: z.ZodOptional<z.ZodString>;
|
|
735
742
|
allowFloating: z.ZodOptional<z.ZodBoolean>;
|
|
736
743
|
labels: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
744
|
+
retryOn429: z.ZodOptional<z.ZodBoolean>;
|
|
737
745
|
images: z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>;
|
|
738
746
|
isStyle: z.ZodOptional<z.ZodBoolean>;
|
|
739
747
|
triggerWord: z.ZodOptional<z.ZodString>;
|
|
@@ -777,6 +785,7 @@ declare const embeddingInputSchema: z.ZodObject<{
|
|
|
777
785
|
purpose: z.ZodOptional<z.ZodString>;
|
|
778
786
|
allowFloating: z.ZodOptional<z.ZodBoolean>;
|
|
779
787
|
labels: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
788
|
+
retryOn429: z.ZodOptional<z.ZodBoolean>;
|
|
780
789
|
text: z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>;
|
|
781
790
|
}, z.core.$strip>;
|
|
782
791
|
declare const transcribeInputSchema: z.ZodObject<{
|
|
@@ -816,10 +825,15 @@ declare const transcribeInputSchema: z.ZodObject<{
|
|
|
816
825
|
purpose: z.ZodOptional<z.ZodString>;
|
|
817
826
|
allowFloating: z.ZodOptional<z.ZodBoolean>;
|
|
818
827
|
labels: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
828
|
+
retryOn429: z.ZodOptional<z.ZodBoolean>;
|
|
819
829
|
audio: z.ZodUnion<readonly [z.ZodString, z.ZodInstanceOf<Uint8Array<ArrayBuffer>>]>;
|
|
820
830
|
language: z.ZodOptional<z.ZodString>;
|
|
821
831
|
durationSec: z.ZodOptional<z.ZodNumber>;
|
|
822
832
|
phrases: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
833
|
+
corrections: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
834
|
+
from: z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>;
|
|
835
|
+
to: z.ZodString;
|
|
836
|
+
}, z.core.$strip>>>;
|
|
823
837
|
timestamps: z.ZodOptional<z.ZodUnion<readonly [z.ZodEnum<{
|
|
824
838
|
word: "word";
|
|
825
839
|
segment: "segment";
|
|
@@ -865,6 +879,7 @@ declare const ocrInputSchema: z.ZodObject<{
|
|
|
865
879
|
purpose: z.ZodOptional<z.ZodString>;
|
|
866
880
|
allowFloating: z.ZodOptional<z.ZodBoolean>;
|
|
867
881
|
labels: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
882
|
+
retryOn429: z.ZodOptional<z.ZodBoolean>;
|
|
868
883
|
document: z.ZodUnion<readonly [z.ZodString, z.ZodInstanceOf<Uint8Array<ArrayBuffer>>]>;
|
|
869
884
|
mimeType: z.ZodOptional<z.ZodString>;
|
|
870
885
|
}, z.core.$strip>;
|
|
@@ -905,6 +920,7 @@ declare const moderationInputSchema: z.ZodObject<{
|
|
|
905
920
|
purpose: z.ZodOptional<z.ZodString>;
|
|
906
921
|
allowFloating: z.ZodOptional<z.ZodBoolean>;
|
|
907
922
|
labels: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
923
|
+
retryOn429: z.ZodOptional<z.ZodBoolean>;
|
|
908
924
|
input: z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>;
|
|
909
925
|
}, z.core.$strip>;
|
|
910
926
|
declare const vectorizeInputSchema: z.ZodObject<{
|
|
@@ -944,6 +960,7 @@ declare const vectorizeInputSchema: z.ZodObject<{
|
|
|
944
960
|
purpose: z.ZodOptional<z.ZodString>;
|
|
945
961
|
allowFloating: z.ZodOptional<z.ZodBoolean>;
|
|
946
962
|
labels: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
963
|
+
retryOn429: z.ZodOptional<z.ZodBoolean>;
|
|
947
964
|
image: z.ZodUnion<readonly [z.ZodString, z.ZodInstanceOf<Uint8Array<ArrayBuffer>>]>;
|
|
948
965
|
shapeStacking: z.ZodOptional<z.ZodEnum<{
|
|
949
966
|
hierarchical: "hierarchical";
|
|
@@ -987,6 +1004,7 @@ declare const judgeInputSchema: z.ZodObject<{
|
|
|
987
1004
|
purpose: z.ZodOptional<z.ZodString>;
|
|
988
1005
|
allowFloating: z.ZodOptional<z.ZodBoolean>;
|
|
989
1006
|
labels: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
1007
|
+
retryOn429: z.ZodOptional<z.ZodBoolean>;
|
|
990
1008
|
state: z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>, z.ZodRecord<z.ZodString, z.ZodUnknown>]>;
|
|
991
1009
|
questions: z.ZodRecord<z.ZodString, z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
992
1010
|
type: z.ZodLiteral<"noul">;
|
|
@@ -1042,6 +1060,7 @@ declare const podcastInputSchema: z.ZodObject<{
|
|
|
1042
1060
|
purpose: z.ZodOptional<z.ZodString>;
|
|
1043
1061
|
allowFloating: z.ZodOptional<z.ZodBoolean>;
|
|
1044
1062
|
labels: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
1063
|
+
retryOn429: z.ZodOptional<z.ZodBoolean>;
|
|
1045
1064
|
script: z.ZodArray<z.ZodObject<{
|
|
1046
1065
|
speaker: z.ZodString;
|
|
1047
1066
|
text: z.ZodString;
|
|
@@ -1093,6 +1112,7 @@ declare const ttsInputSchema: z.ZodObject<{
|
|
|
1093
1112
|
purpose: z.ZodOptional<z.ZodString>;
|
|
1094
1113
|
allowFloating: z.ZodOptional<z.ZodBoolean>;
|
|
1095
1114
|
labels: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
1115
|
+
retryOn429: z.ZodOptional<z.ZodBoolean>;
|
|
1096
1116
|
text: z.ZodString;
|
|
1097
1117
|
voice: z.ZodString;
|
|
1098
1118
|
pronunciations: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
@@ -1109,6 +1129,7 @@ declare const ttsInputSchema: z.ZodObject<{
|
|
|
1109
1129
|
rate: z.ZodOptional<z.ZodNumber>;
|
|
1110
1130
|
}, z.core.$strip>;
|
|
1111
1131
|
declare const aiConfigSchema: z.ZodObject<{
|
|
1132
|
+
retryOn429: z.ZodOptional<z.ZodBoolean>;
|
|
1112
1133
|
byok: z.ZodOptional<z.ZodBoolean>;
|
|
1113
1134
|
labels: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
1114
1135
|
promptCache: z.ZodOptional<z.ZodBoolean>;
|
|
@@ -1600,8 +1621,8 @@ declare const falStubAdapter: ProviderAdapter;
|
|
|
1600
1621
|
* wires the live adapters. */
|
|
1601
1622
|
declare const stubProviders: Record<string, ProviderAdapter>;
|
|
1602
1623
|
|
|
1603
|
-
declare const VERSION: "0.78.
|
|
1604
|
-
declare const SDK_TAG: "@broberg/ai-sdk@0.78.
|
|
1624
|
+
declare const VERSION: "0.78.8";
|
|
1625
|
+
declare const SDK_TAG: "@broberg/ai-sdk@0.78.8";
|
|
1605
1626
|
|
|
1606
1627
|
/** Built-in defaults. Every entry is overridable via AiConfig.defaults or a
|
|
1607
1628
|
* per-call override.
|
|
@@ -2091,6 +2112,9 @@ interface HttpResponse {
|
|
|
2091
2112
|
* holds what the server actually said, which is the only useful thing to show on a
|
|
2092
2113
|
* gateway error. */
|
|
2093
2114
|
text: string;
|
|
2115
|
+
/** F089 — the server's Retry-After, in ms (seconds or an HTTP date). Absent when the
|
|
2116
|
+
* header was not sent or could not be read. */
|
|
2117
|
+
retryAfterMs?: number;
|
|
2094
2118
|
}
|
|
2095
2119
|
/** Subprocess transport result — already normalized from the `claude -p` JSON.
|
|
2096
2120
|
* costUsd is always 0 (Max plan is not a metered charge); subprocess flags it. */
|
package/dist/index.js
CHANGED
|
@@ -461,8 +461,30 @@ async function httpTransport(req) {
|
|
|
461
461
|
} catch {
|
|
462
462
|
json = void 0;
|
|
463
463
|
}
|
|
464
|
-
|
|
465
|
-
|
|
464
|
+
const out = { ok: res.ok, status: res.status, json, text };
|
|
465
|
+
const ra = parseRetryAfter(res.headers?.get?.("retry-after") ?? null);
|
|
466
|
+
if (ra !== void 0) out.retryAfterMs = ra;
|
|
467
|
+
return out;
|
|
468
|
+
}
|
|
469
|
+
function parseRetryAfter(v, now = Date.now()) {
|
|
470
|
+
if (v === null || v.trim() === "") return void 0;
|
|
471
|
+
const t = v.trim();
|
|
472
|
+
if (/^\d+(\.\d+)?$/.test(t)) return Math.round(Number(t) * 1e3);
|
|
473
|
+
const at = Date.parse(t);
|
|
474
|
+
if (Number.isNaN(at)) return void 0;
|
|
475
|
+
const ms = at - now;
|
|
476
|
+
return ms >= 0 ? ms : void 0;
|
|
477
|
+
}
|
|
478
|
+
var ProviderHttpError = class extends Error {
|
|
479
|
+
status;
|
|
480
|
+
retryAfterMs;
|
|
481
|
+
constructor(message, status, retryAfterMs) {
|
|
482
|
+
super(message);
|
|
483
|
+
this.name = "ProviderHttpError";
|
|
484
|
+
this.status = status;
|
|
485
|
+
if (retryAfterMs !== void 0) this.retryAfterMs = retryAfterMs;
|
|
486
|
+
}
|
|
487
|
+
};
|
|
466
488
|
function errorBody(json, rawText) {
|
|
467
489
|
const fallback = rawText && rawText.trim() ? rawText.slice(0, 300) : "(no body)";
|
|
468
490
|
if (json === void 0 || json === null) return fallback;
|
|
@@ -1209,7 +1231,7 @@ function makeOpenAICompatibleAdapter(config) {
|
|
|
1209
1231
|
}
|
|
1210
1232
|
});
|
|
1211
1233
|
if (!res.ok) {
|
|
1212
|
-
throw new
|
|
1234
|
+
throw new ProviderHttpError(`${config.name} ${res.status}: ${errorBody(res.json, res.text)}`, res.status, res.retryAfterMs);
|
|
1213
1235
|
}
|
|
1214
1236
|
const data = res.json;
|
|
1215
1237
|
const msg = data.choices?.[0]?.message;
|
|
@@ -3788,6 +3810,32 @@ async function resolveAudio(audio, fetchImpl = fetch) {
|
|
|
3788
3810
|
if (!res.ok) throw new Error(`transcribe: failed to fetch audio (${res.status})`);
|
|
3789
3811
|
return new Uint8Array(await res.arrayBuffer());
|
|
3790
3812
|
}
|
|
3813
|
+
function applyTranscriptCorrections(result, corrections) {
|
|
3814
|
+
if (!corrections || corrections.length === 0) return result;
|
|
3815
|
+
const to = /* @__PURE__ */ new Map();
|
|
3816
|
+
for (const c of corrections) {
|
|
3817
|
+
for (const f of Array.isArray(c.from) ? c.from : [c.from]) {
|
|
3818
|
+
const k = f.toLowerCase();
|
|
3819
|
+
if (!to.has(k)) to.set(k, c.to);
|
|
3820
|
+
}
|
|
3821
|
+
}
|
|
3822
|
+
const keys = [...to.keys()].sort((a, b) => b.length - a.length);
|
|
3823
|
+
const esc = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
3824
|
+
const re = new RegExp(`(?<![\\p{L}\\p{N}])(?:${keys.map(esc).join("|")})(?![\\p{L}\\p{N}])`, "giu");
|
|
3825
|
+
const counts = /* @__PURE__ */ new Map();
|
|
3826
|
+
const fix = (s, count) => s.replace(re, (m) => {
|
|
3827
|
+
const out2 = to.get(m.toLowerCase()) ?? m;
|
|
3828
|
+
if (count) counts.set(out2, (counts.get(out2) ?? 0) + 1);
|
|
3829
|
+
return out2;
|
|
3830
|
+
});
|
|
3831
|
+
const text = fix(result.text, true);
|
|
3832
|
+
if (counts.size === 0) return result;
|
|
3833
|
+
const out = { ...result, text };
|
|
3834
|
+
if (result.segments) out.segments = result.segments.map((s) => ({ ...s, text: fix(s.text, false) }));
|
|
3835
|
+
if (result.words) out.words = result.words.map((w) => ({ ...w, word: fix(w.word, false) }));
|
|
3836
|
+
out.correctionsApplied = [...counts.entries()].map(([t, count]) => ({ to: t, count }));
|
|
3837
|
+
return out;
|
|
3838
|
+
}
|
|
3791
3839
|
|
|
3792
3840
|
// src/capabilities/contracts/index.ts
|
|
3793
3841
|
var RAW_SNIPPET_CHARS = 200;
|
|
@@ -4316,7 +4364,8 @@ var INPUT_LIMITS = {
|
|
|
4316
4364
|
judgeEntryItems: 1e3,
|
|
4317
4365
|
stateItems: 1e4,
|
|
4318
4366
|
scriptLines: 1e4,
|
|
4319
|
-
pronunciations: 1e4
|
|
4367
|
+
pronunciations: 1e4,
|
|
4368
|
+
corrections: 1e4
|
|
4320
4369
|
};
|
|
4321
4370
|
var L = INPUT_LIMITS;
|
|
4322
4371
|
var transportSchema = z.enum(["http", "subprocess"]);
|
|
@@ -4375,7 +4424,10 @@ var callOptions = {
|
|
|
4375
4424
|
allowFloating: z.boolean().optional(),
|
|
4376
4425
|
/** Consumer-defined attribution dimensions (e.g. {tenantId}) ridden into the
|
|
4377
4426
|
* cost sink for per-tenant/per-customer cost breakdown (F011). */
|
|
4378
|
-
labels: z.record(z.string(), z.string()).optional()
|
|
4427
|
+
labels: z.record(z.string(), z.string()).optional(),
|
|
4428
|
+
/** F089 — on HTTP 429 wait the provider's Retry-After (cap 10 s, 2 s if unstated) and try
|
|
4429
|
+
* the SAME route once more before any fallback. Default on; false turns it off. */
|
|
4430
|
+
retryOn429: z.boolean().optional()
|
|
4379
4431
|
};
|
|
4380
4432
|
var chatInputSchema = z.object({
|
|
4381
4433
|
/** F039 — reuse a cached prompt prefix on Mistral at 10% of the input rate.
|
|
@@ -4494,6 +4546,10 @@ var embeddingInputSchema = z.object({
|
|
|
4494
4546
|
text: z.union([z.string(), z.array(z.string()).max(L.texts)]),
|
|
4495
4547
|
...callOptions
|
|
4496
4548
|
});
|
|
4549
|
+
var correctionSchema = z.object({
|
|
4550
|
+
from: z.union([z.string().min(1).max(200), z.array(z.string().min(1).max(200)).min(1).max(100)]),
|
|
4551
|
+
to: z.string().min(1).max(200)
|
|
4552
|
+
});
|
|
4497
4553
|
var transcribeInputSchema = z.object({
|
|
4498
4554
|
/** Audio URL or raw bytes. */
|
|
4499
4555
|
audio: z.union([z.string(), z.instanceof(Uint8Array)]),
|
|
@@ -4502,6 +4558,9 @@ var transcribeInputSchema = z.object({
|
|
|
4502
4558
|
durationSec: z.number().positive().optional(),
|
|
4503
4559
|
/** Bias toward brand/jargon terms (Azure phraseList, F029.3); others ignore it. */
|
|
4504
4560
|
phrases: z.array(z.string()).max(L.phrases).optional(),
|
|
4561
|
+
/** F102 — fix what the provider mis-hears, AFTER it answers: whole-word, case-insensitive,
|
|
4562
|
+
* consumer-owned. Works on every provider. `phrases` is only best-effort (measured no effect). */
|
|
4563
|
+
corrections: z.array(correctionSchema).max(L.corrections).optional(),
|
|
4505
4564
|
/** Opt-in timestamps (F036) — a single granularity or an array. Omit → the
|
|
4506
4565
|
* current { text, usage } shape, unchanged. Pass ["word","segment"] for both.
|
|
4507
4566
|
* Supported by Whisper (openai) + Azure fast-transcription (F036.1); other
|
|
@@ -4607,6 +4666,8 @@ var availabilitySchema = z.object({
|
|
|
4607
4666
|
fallback: z.union([z.string(), z.array(z.string()).max(L.fallback)]).optional()
|
|
4608
4667
|
});
|
|
4609
4668
|
var aiConfigSchema = z.object({
|
|
4669
|
+
/** F089 — client-wide default for the one retry on HTTP 429 (default on). */
|
|
4670
|
+
retryOn429: z.boolean().optional(),
|
|
4610
4671
|
/** F069.1 — customer-key mode. Every provider must be built with byokAdapter(), so no
|
|
4611
4672
|
* call can fall back to the fleet's env keys; createAI throws at setup otherwise. */
|
|
4612
4673
|
byok: z.boolean().optional(),
|
|
@@ -4637,8 +4698,8 @@ var aiConfigSchema = z.object({
|
|
|
4637
4698
|
import { randomUUID } from "crypto";
|
|
4638
4699
|
|
|
4639
4700
|
// src/version.ts
|
|
4640
|
-
var VERSION = "0.78.
|
|
4641
|
-
var SDK_TAG = "@broberg/ai-sdk@0.78.
|
|
4701
|
+
var VERSION = "0.78.8";
|
|
4702
|
+
var SDK_TAG = "@broberg/ai-sdk@0.78.8";
|
|
4642
4703
|
|
|
4643
4704
|
// src/cost/sinks/upmetrics.ts
|
|
4644
4705
|
function isRetryableStatus(status) {
|
|
@@ -4936,6 +4997,8 @@ var DEFAULT_TRAINSTYLE_SPEC = {
|
|
|
4936
4997
|
model: "fal-ai/flux-lora-fast-training",
|
|
4937
4998
|
transport: "http"
|
|
4938
4999
|
};
|
|
5000
|
+
var RETRY_429_CAP_MS = 1e4;
|
|
5001
|
+
var RETRY_429_DEFAULT_MS = 2e3;
|
|
4939
5002
|
var DEFAULT_ANIMATE_SPEC = {
|
|
4940
5003
|
provider: "bfl",
|
|
4941
5004
|
model: "flux-3-video",
|
|
@@ -5125,6 +5188,7 @@ function createAI(config = {}) {
|
|
|
5125
5188
|
return true;
|
|
5126
5189
|
}
|
|
5127
5190
|
async function runCapability(opts) {
|
|
5191
|
+
const retry429 = opts.retryOn429 ?? cfg.retryOn429 ?? true;
|
|
5128
5192
|
const routes = [
|
|
5129
5193
|
applyAvailability(opts.primary),
|
|
5130
5194
|
...(opts.fallback ?? []).map(
|
|
@@ -5136,35 +5200,49 @@ function createAI(config = {}) {
|
|
|
5136
5200
|
const spec = routes[i];
|
|
5137
5201
|
const floating = checkPinning(spec, opts.allowFloating);
|
|
5138
5202
|
await preflight(spec, opts.estIn, opts.estOut);
|
|
5139
|
-
|
|
5140
|
-
|
|
5141
|
-
|
|
5142
|
-
|
|
5143
|
-
|
|
5144
|
-
|
|
5145
|
-
|
|
5146
|
-
|
|
5147
|
-
|
|
5148
|
-
|
|
5149
|
-
|
|
5150
|
-
|
|
5151
|
-
|
|
5152
|
-
|
|
5153
|
-
|
|
5154
|
-
|
|
5155
|
-
|
|
5156
|
-
|
|
5157
|
-
|
|
5158
|
-
|
|
5159
|
-
|
|
5160
|
-
|
|
5161
|
-
|
|
5162
|
-
|
|
5163
|
-
|
|
5203
|
+
for (let attempt = 0; attempt < 2; attempt++) {
|
|
5204
|
+
const t0 = performance.now();
|
|
5205
|
+
try {
|
|
5206
|
+
const res = await opts.invoke(spec);
|
|
5207
|
+
enrich(res.usage, opts.capability, i === 0 ? opts.tier : void 0, opts.purpose, performance.now() - t0, opts.labels);
|
|
5208
|
+
if (floating) res.usage.floating = true;
|
|
5209
|
+
await settle(res.usage);
|
|
5210
|
+
await report(res.usage);
|
|
5211
|
+
return res;
|
|
5212
|
+
} catch (e) {
|
|
5213
|
+
lastErr = e;
|
|
5214
|
+
const labels = { ...cfg.labels, ...opts.labels };
|
|
5215
|
+
await reportFailure(
|
|
5216
|
+
{
|
|
5217
|
+
provider: spec.provider,
|
|
5218
|
+
model: spec.model,
|
|
5219
|
+
transport: spec.transport,
|
|
5220
|
+
capability: opts.capability,
|
|
5221
|
+
...i === 0 && opts.tier ? { tier: opts.tier } : {},
|
|
5222
|
+
...opts.purpose ? { purpose: opts.purpose } : {},
|
|
5223
|
+
...Object.keys(labels).length ? { labels } : {},
|
|
5224
|
+
latencyMs: Math.round(performance.now() - t0)
|
|
5225
|
+
},
|
|
5226
|
+
e
|
|
5227
|
+
);
|
|
5228
|
+
if (isCallerAbort(e)) throw e;
|
|
5229
|
+
const wait = attempt === 0 && retry429 ? retryWaitFor429(e) : void 0;
|
|
5230
|
+
if (wait !== void 0) {
|
|
5231
|
+
await new Promise((r) => setTimeout(r, wait));
|
|
5232
|
+
continue;
|
|
5233
|
+
}
|
|
5234
|
+
break;
|
|
5235
|
+
}
|
|
5164
5236
|
}
|
|
5165
5237
|
}
|
|
5166
5238
|
throw lastErr;
|
|
5167
5239
|
}
|
|
5240
|
+
function retryWaitFor429(e) {
|
|
5241
|
+
const err = e;
|
|
5242
|
+
if (err?.status !== 429) return void 0;
|
|
5243
|
+
const ms = err.retryAfterMs ?? RETRY_429_DEFAULT_MS;
|
|
5244
|
+
return ms <= RETRY_429_CAP_MS ? ms : void 0;
|
|
5245
|
+
}
|
|
5168
5246
|
function eligibleForFallback(e) {
|
|
5169
5247
|
const status = e?.status;
|
|
5170
5248
|
if (status === void 0) return true;
|
|
@@ -5273,6 +5351,7 @@ function createAI(config = {}) {
|
|
|
5273
5351
|
capability: "chat",
|
|
5274
5352
|
tier,
|
|
5275
5353
|
purpose: input.purpose,
|
|
5354
|
+
retryOn429: input.retryOn429,
|
|
5276
5355
|
labels: input.labels,
|
|
5277
5356
|
allowFloating: input.allowFloating,
|
|
5278
5357
|
estIn,
|
|
@@ -5299,6 +5378,7 @@ function createAI(config = {}) {
|
|
|
5299
5378
|
capability: "vision",
|
|
5300
5379
|
tier,
|
|
5301
5380
|
purpose: input.purpose,
|
|
5381
|
+
retryOn429: input.retryOn429,
|
|
5302
5382
|
labels: input.labels,
|
|
5303
5383
|
allowFloating: input.allowFloating,
|
|
5304
5384
|
estIn: estTokens(input.prompt) + 1e3,
|
|
@@ -5321,6 +5401,7 @@ function createAI(config = {}) {
|
|
|
5321
5401
|
capability: "video",
|
|
5322
5402
|
tier,
|
|
5323
5403
|
purpose: input.purpose,
|
|
5404
|
+
retryOn429: input.retryOn429,
|
|
5324
5405
|
labels: input.labels,
|
|
5325
5406
|
allowFloating: input.allowFloating,
|
|
5326
5407
|
estIn: estTokens(input.prompt) + 4e3,
|
|
@@ -5344,6 +5425,7 @@ function createAI(config = {}) {
|
|
|
5344
5425
|
capability: "translate",
|
|
5345
5426
|
tier,
|
|
5346
5427
|
purpose: input.purpose,
|
|
5428
|
+
retryOn429: input.retryOn429,
|
|
5347
5429
|
labels: input.labels,
|
|
5348
5430
|
allowFloating: input.allowFloating,
|
|
5349
5431
|
estIn,
|
|
@@ -5369,6 +5451,7 @@ function createAI(config = {}) {
|
|
|
5369
5451
|
fallback: input.fallback,
|
|
5370
5452
|
capability: "image",
|
|
5371
5453
|
purpose: input.purpose,
|
|
5454
|
+
retryOn429: input.retryOn429,
|
|
5372
5455
|
labels: input.labels,
|
|
5373
5456
|
allowFloating: input.allowFloating,
|
|
5374
5457
|
estIn: 0,
|
|
@@ -5402,6 +5485,7 @@ function createAI(config = {}) {
|
|
|
5402
5485
|
fallback: input.fallback,
|
|
5403
5486
|
capability: "animate",
|
|
5404
5487
|
purpose: input.purpose,
|
|
5488
|
+
retryOn429: input.retryOn429,
|
|
5405
5489
|
labels: input.labels,
|
|
5406
5490
|
allowFloating: input.allowFloating,
|
|
5407
5491
|
estIn: 0,
|
|
@@ -5435,6 +5519,7 @@ function createAI(config = {}) {
|
|
|
5435
5519
|
fallback: input.fallback,
|
|
5436
5520
|
capability: "trainStyle",
|
|
5437
5521
|
purpose: input.purpose,
|
|
5522
|
+
retryOn429: input.retryOn429,
|
|
5438
5523
|
labels: input.labels,
|
|
5439
5524
|
allowFloating: input.allowFloating,
|
|
5440
5525
|
estIn: 0,
|
|
@@ -5462,6 +5547,7 @@ function createAI(config = {}) {
|
|
|
5462
5547
|
fallback: input.fallback,
|
|
5463
5548
|
capability: "ocr",
|
|
5464
5549
|
purpose: input.purpose,
|
|
5550
|
+
retryOn429: input.retryOn429,
|
|
5465
5551
|
labels: input.labels,
|
|
5466
5552
|
allowFloating: input.allowFloating,
|
|
5467
5553
|
estIn: 0,
|
|
@@ -5482,6 +5568,7 @@ function createAI(config = {}) {
|
|
|
5482
5568
|
fallback: input.fallback,
|
|
5483
5569
|
capability: "moderation",
|
|
5484
5570
|
purpose: input.purpose,
|
|
5571
|
+
retryOn429: input.retryOn429,
|
|
5485
5572
|
labels: input.labels,
|
|
5486
5573
|
allowFloating: input.allowFloating,
|
|
5487
5574
|
estIn: items.reduce((n, s) => n + estTokens(s), 0),
|
|
@@ -5505,6 +5592,7 @@ function createAI(config = {}) {
|
|
|
5505
5592
|
fallback: input.fallback,
|
|
5506
5593
|
capability: "judge",
|
|
5507
5594
|
purpose: input.purpose,
|
|
5595
|
+
retryOn429: input.retryOn429,
|
|
5508
5596
|
labels: input.labels,
|
|
5509
5597
|
allowFloating: input.allowFloating,
|
|
5510
5598
|
estIn: estTokens(stateText) + estTokens(JSON.stringify(input.questions)),
|
|
@@ -5524,6 +5612,7 @@ function createAI(config = {}) {
|
|
|
5524
5612
|
fallback: input.fallback,
|
|
5525
5613
|
capability: "vectorize",
|
|
5526
5614
|
purpose: input.purpose,
|
|
5615
|
+
retryOn429: input.retryOn429,
|
|
5527
5616
|
labels: input.labels,
|
|
5528
5617
|
estIn: 0,
|
|
5529
5618
|
estOut: 0,
|
|
@@ -5549,6 +5638,7 @@ function createAI(config = {}) {
|
|
|
5549
5638
|
fallback: input.fallback,
|
|
5550
5639
|
capability: "podcast",
|
|
5551
5640
|
purpose: input.purpose,
|
|
5641
|
+
retryOn429: input.retryOn429,
|
|
5552
5642
|
labels: input.labels,
|
|
5553
5643
|
allowFloating: input.allowFloating,
|
|
5554
5644
|
estIn: chars,
|
|
@@ -5569,6 +5659,7 @@ function createAI(config = {}) {
|
|
|
5569
5659
|
fallback: input.fallback,
|
|
5570
5660
|
capability: "tts",
|
|
5571
5661
|
purpose: input.purpose,
|
|
5662
|
+
retryOn429: input.retryOn429,
|
|
5572
5663
|
labels: input.labels,
|
|
5573
5664
|
allowFloating: input.allowFloating,
|
|
5574
5665
|
estIn: input.text.length,
|
|
@@ -5600,6 +5691,7 @@ function createAI(config = {}) {
|
|
|
5600
5691
|
capability: "embedding",
|
|
5601
5692
|
tier,
|
|
5602
5693
|
purpose: input.purpose,
|
|
5694
|
+
retryOn429: input.retryOn429,
|
|
5603
5695
|
labels: input.labels,
|
|
5604
5696
|
allowFloating: input.allowFloating,
|
|
5605
5697
|
estIn: text.reduce((n, t) => n + estTokens(t), 0),
|
|
@@ -5620,6 +5712,7 @@ function createAI(config = {}) {
|
|
|
5620
5712
|
fallback: input.fallback,
|
|
5621
5713
|
capability: "transcribe",
|
|
5622
5714
|
purpose: input.purpose,
|
|
5715
|
+
retryOn429: input.retryOn429,
|
|
5623
5716
|
labels: input.labels,
|
|
5624
5717
|
allowFloating: input.allowFloating,
|
|
5625
5718
|
estIn: 0,
|
|
@@ -5628,7 +5721,8 @@ function createAI(config = {}) {
|
|
|
5628
5721
|
const adapter = pickProvider(spec.provider);
|
|
5629
5722
|
if (!adapter.transcribe) throw new Error(`createAI: provider "${spec.provider}" does not support transcribe`);
|
|
5630
5723
|
const timestamps = input.timestamps === void 0 ? void 0 : Array.isArray(input.timestamps) ? input.timestamps : [input.timestamps];
|
|
5631
|
-
|
|
5724
|
+
const r = await adapter.transcribe({ audio, language: input.language, durationSec: input.durationSec, phrases: input.phrases, timestamps, spec });
|
|
5725
|
+
return applyTranscriptCorrections(r, input.corrections);
|
|
5632
5726
|
}
|
|
5633
5727
|
});
|
|
5634
5728
|
},
|