@broberg/ai-sdk 0.78.6 → 0.78.7
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 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;
|
|
@@ -820,6 +821,10 @@ declare const transcribeInputSchema: z.ZodObject<{
|
|
|
820
821
|
language: z.ZodOptional<z.ZodString>;
|
|
821
822
|
durationSec: z.ZodOptional<z.ZodNumber>;
|
|
822
823
|
phrases: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
824
|
+
corrections: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
825
|
+
from: z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>;
|
|
826
|
+
to: z.ZodString;
|
|
827
|
+
}, z.core.$strip>>>;
|
|
823
828
|
timestamps: z.ZodOptional<z.ZodUnion<readonly [z.ZodEnum<{
|
|
824
829
|
word: "word";
|
|
825
830
|
segment: "segment";
|
|
@@ -1600,8 +1605,8 @@ declare const falStubAdapter: ProviderAdapter;
|
|
|
1600
1605
|
* wires the live adapters. */
|
|
1601
1606
|
declare const stubProviders: Record<string, ProviderAdapter>;
|
|
1602
1607
|
|
|
1603
|
-
declare const VERSION: "0.78.
|
|
1604
|
-
declare const SDK_TAG: "@broberg/ai-sdk@0.78.
|
|
1608
|
+
declare const VERSION: "0.78.7";
|
|
1609
|
+
declare const SDK_TAG: "@broberg/ai-sdk@0.78.7";
|
|
1605
1610
|
|
|
1606
1611
|
/** Built-in defaults. Every entry is overridable via AiConfig.defaults or a
|
|
1607
1612
|
* per-call override.
|
package/dist/index.js
CHANGED
|
@@ -3788,6 +3788,32 @@ async function resolveAudio(audio, fetchImpl = fetch) {
|
|
|
3788
3788
|
if (!res.ok) throw new Error(`transcribe: failed to fetch audio (${res.status})`);
|
|
3789
3789
|
return new Uint8Array(await res.arrayBuffer());
|
|
3790
3790
|
}
|
|
3791
|
+
function applyTranscriptCorrections(result, corrections) {
|
|
3792
|
+
if (!corrections || corrections.length === 0) return result;
|
|
3793
|
+
const to = /* @__PURE__ */ new Map();
|
|
3794
|
+
for (const c of corrections) {
|
|
3795
|
+
for (const f of Array.isArray(c.from) ? c.from : [c.from]) {
|
|
3796
|
+
const k = f.toLowerCase();
|
|
3797
|
+
if (!to.has(k)) to.set(k, c.to);
|
|
3798
|
+
}
|
|
3799
|
+
}
|
|
3800
|
+
const keys = [...to.keys()].sort((a, b) => b.length - a.length);
|
|
3801
|
+
const esc = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
3802
|
+
const re = new RegExp(`(?<![\\p{L}\\p{N}])(?:${keys.map(esc).join("|")})(?![\\p{L}\\p{N}])`, "giu");
|
|
3803
|
+
const counts = /* @__PURE__ */ new Map();
|
|
3804
|
+
const fix = (s, count) => s.replace(re, (m) => {
|
|
3805
|
+
const out2 = to.get(m.toLowerCase()) ?? m;
|
|
3806
|
+
if (count) counts.set(out2, (counts.get(out2) ?? 0) + 1);
|
|
3807
|
+
return out2;
|
|
3808
|
+
});
|
|
3809
|
+
const text = fix(result.text, true);
|
|
3810
|
+
if (counts.size === 0) return result;
|
|
3811
|
+
const out = { ...result, text };
|
|
3812
|
+
if (result.segments) out.segments = result.segments.map((s) => ({ ...s, text: fix(s.text, false) }));
|
|
3813
|
+
if (result.words) out.words = result.words.map((w) => ({ ...w, word: fix(w.word, false) }));
|
|
3814
|
+
out.correctionsApplied = [...counts.entries()].map(([t, count]) => ({ to: t, count }));
|
|
3815
|
+
return out;
|
|
3816
|
+
}
|
|
3791
3817
|
|
|
3792
3818
|
// src/capabilities/contracts/index.ts
|
|
3793
3819
|
var RAW_SNIPPET_CHARS = 200;
|
|
@@ -4316,7 +4342,8 @@ var INPUT_LIMITS = {
|
|
|
4316
4342
|
judgeEntryItems: 1e3,
|
|
4317
4343
|
stateItems: 1e4,
|
|
4318
4344
|
scriptLines: 1e4,
|
|
4319
|
-
pronunciations: 1e4
|
|
4345
|
+
pronunciations: 1e4,
|
|
4346
|
+
corrections: 1e4
|
|
4320
4347
|
};
|
|
4321
4348
|
var L = INPUT_LIMITS;
|
|
4322
4349
|
var transportSchema = z.enum(["http", "subprocess"]);
|
|
@@ -4494,6 +4521,10 @@ var embeddingInputSchema = z.object({
|
|
|
4494
4521
|
text: z.union([z.string(), z.array(z.string()).max(L.texts)]),
|
|
4495
4522
|
...callOptions
|
|
4496
4523
|
});
|
|
4524
|
+
var correctionSchema = z.object({
|
|
4525
|
+
from: z.union([z.string().min(1).max(200), z.array(z.string().min(1).max(200)).min(1).max(100)]),
|
|
4526
|
+
to: z.string().min(1).max(200)
|
|
4527
|
+
});
|
|
4497
4528
|
var transcribeInputSchema = z.object({
|
|
4498
4529
|
/** Audio URL or raw bytes. */
|
|
4499
4530
|
audio: z.union([z.string(), z.instanceof(Uint8Array)]),
|
|
@@ -4502,6 +4533,9 @@ var transcribeInputSchema = z.object({
|
|
|
4502
4533
|
durationSec: z.number().positive().optional(),
|
|
4503
4534
|
/** Bias toward brand/jargon terms (Azure phraseList, F029.3); others ignore it. */
|
|
4504
4535
|
phrases: z.array(z.string()).max(L.phrases).optional(),
|
|
4536
|
+
/** F102 — fix what the provider mis-hears, AFTER it answers: whole-word, case-insensitive,
|
|
4537
|
+
* consumer-owned. Works on every provider. `phrases` is only best-effort (measured no effect). */
|
|
4538
|
+
corrections: z.array(correctionSchema).max(L.corrections).optional(),
|
|
4505
4539
|
/** Opt-in timestamps (F036) — a single granularity or an array. Omit → the
|
|
4506
4540
|
* current { text, usage } shape, unchanged. Pass ["word","segment"] for both.
|
|
4507
4541
|
* Supported by Whisper (openai) + Azure fast-transcription (F036.1); other
|
|
@@ -4637,8 +4671,8 @@ var aiConfigSchema = z.object({
|
|
|
4637
4671
|
import { randomUUID } from "crypto";
|
|
4638
4672
|
|
|
4639
4673
|
// src/version.ts
|
|
4640
|
-
var VERSION = "0.78.
|
|
4641
|
-
var SDK_TAG = "@broberg/ai-sdk@0.78.
|
|
4674
|
+
var VERSION = "0.78.7";
|
|
4675
|
+
var SDK_TAG = "@broberg/ai-sdk@0.78.7";
|
|
4642
4676
|
|
|
4643
4677
|
// src/cost/sinks/upmetrics.ts
|
|
4644
4678
|
function isRetryableStatus(status) {
|
|
@@ -5628,7 +5662,8 @@ function createAI(config = {}) {
|
|
|
5628
5662
|
const adapter = pickProvider(spec.provider);
|
|
5629
5663
|
if (!adapter.transcribe) throw new Error(`createAI: provider "${spec.provider}" does not support transcribe`);
|
|
5630
5664
|
const timestamps = input.timestamps === void 0 ? void 0 : Array.isArray(input.timestamps) ? input.timestamps : [input.timestamps];
|
|
5631
|
-
|
|
5665
|
+
const r = await adapter.transcribe({ audio, language: input.language, durationSec: input.durationSec, phrases: input.phrases, timestamps, spec });
|
|
5666
|
+
return applyTranscriptCorrections(r, input.corrections);
|
|
5632
5667
|
}
|
|
5633
5668
|
});
|
|
5634
5669
|
},
|