@broberg/ai-sdk 0.25.0 → 0.26.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
@@ -1353,7 +1353,9 @@ declare const transcribeInputSchema: z.ZodObject<{
1353
1353
  /** Bias toward brand/jargon terms (Azure phraseList, F029.3); others ignore it. */
1354
1354
  phrases: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
1355
1355
  /** Opt-in timestamps (F036) — a single granularity or an array. Omit → the
1356
- * current { text, usage } shape, unchanged. Pass ["word","segment"] for both. */
1356
+ * current { text, usage } shape, unchanged. Pass ["word","segment"] for both.
1357
+ * Supported by Whisper (openai) + Azure fast-transcription (F036.1); other
1358
+ * adapters (Voxtral/mistral) ignore it and return text only. */
1357
1359
  timestamps: z.ZodOptional<z.ZodUnion<[z.ZodEnum<["word", "segment"]>, z.ZodArray<z.ZodEnum<["word", "segment"]>, "many">]>>;
1358
1360
  }, "strip", z.ZodTypeAny, {
1359
1361
  audio: string | Uint8Array<ArrayBuffer>;
@@ -1695,7 +1697,10 @@ declare const aiConfigSchema: z.ZodObject<{
1695
1697
  transport: "http" | "subprocess";
1696
1698
  }>>>;
1697
1699
  providers: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodType<ProviderAdapter, z.ZodTypeDef, ProviderAdapter>>>;
1698
- costSink: z.ZodOptional<z.ZodType<CostSink, z.ZodTypeDef, CostSink>>;
1700
+ /** Omit → cost-tracking auto-wires from the upmetrics env (F034). Pass `null`
1701
+ * to opt OUT explicitly — for a consumer that already reports its own costs
1702
+ * and would otherwise be counted twice (F034.3). An object is used as-is. */
1703
+ costSink: z.ZodOptional<z.ZodNullable<z.ZodType<CostSink, z.ZodTypeDef, CostSink>>>;
1699
1704
  budget: z.ZodOptional<z.ZodObject<{
1700
1705
  perCallUsd: z.ZodOptional<z.ZodNumber>;
1701
1706
  rollingUsd: z.ZodOptional<z.ZodNumber>;
@@ -1723,7 +1728,7 @@ declare const aiConfigSchema: z.ZodObject<{
1723
1728
  transport: "http" | "subprocess";
1724
1729
  }>> | undefined;
1725
1730
  providers?: Record<string, ProviderAdapter> | undefined;
1726
- costSink?: CostSink | undefined;
1731
+ costSink?: CostSink | null | undefined;
1727
1732
  budget?: {
1728
1733
  perCallUsd?: number | undefined;
1729
1734
  rollingUsd?: number | undefined;
@@ -1739,7 +1744,7 @@ declare const aiConfigSchema: z.ZodObject<{
1739
1744
  transport: "http" | "subprocess";
1740
1745
  }>> | undefined;
1741
1746
  providers?: Record<string, ProviderAdapter> | undefined;
1742
- costSink?: CostSink | undefined;
1747
+ costSink?: CostSink | null | undefined;
1743
1748
  budget?: {
1744
1749
  perCallUsd?: number | undefined;
1745
1750
  rollingUsd?: number | undefined;
@@ -2043,8 +2048,8 @@ declare const falStubAdapter: ProviderAdapter;
2043
2048
  * wires the live adapters. */
2044
2049
  declare const stubProviders: Record<string, ProviderAdapter>;
2045
2050
 
2046
- declare const VERSION: "0.25.0";
2047
- declare const SDK_TAG: "@broberg/ai-sdk@0.25.0";
2051
+ declare const VERSION: "0.26.0";
2052
+ declare const SDK_TAG: "@broberg/ai-sdk@0.26.0";
2048
2053
 
2049
2054
  /** Built-in defaults. Every entry is overridable via AiConfig.defaults or a
2050
2055
  * per-call override.
package/dist/index.js CHANGED
@@ -1534,7 +1534,26 @@ function azureAdapter(config = {}) {
1534
1534
  outputTokens: 0
1535
1535
  });
1536
1536
  usage.costUsd = minutes * (config.sttPricePerMin ?? AZURE_STT_PRICE_PER_MIN);
1537
- return { text, usage };
1537
+ const result = { text, usage };
1538
+ if (req.timestamps && req.timestamps.length > 0 && data.phrases) {
1539
+ const toSec = (ms) => (ms ?? 0) / 1e3;
1540
+ if (req.timestamps.includes("word")) {
1541
+ const words = data.phrases.flatMap((p) => p.words ?? []);
1542
+ if (words.length > 0) {
1543
+ result.words = words.map((w) => ({
1544
+ word: w.text ?? "",
1545
+ start: toSec(w.offsetMilliseconds),
1546
+ end: toSec((w.offsetMilliseconds ?? 0) + (w.durationMilliseconds ?? 0))
1547
+ }));
1548
+ }
1549
+ }
1550
+ result.segments = data.phrases.map((p) => ({
1551
+ text: p.text ?? "",
1552
+ start: toSec(p.offsetMilliseconds),
1553
+ end: toSec((p.offsetMilliseconds ?? 0) + (p.durationMilliseconds ?? 0))
1554
+ }));
1555
+ }
1556
+ return result;
1538
1557
  }
1539
1558
  return { name: "azure", tts, transcribe };
1540
1559
  }
@@ -2538,7 +2557,9 @@ var transcribeInputSchema = z.object({
2538
2557
  /** Bias toward brand/jargon terms (Azure phraseList, F029.3); others ignore it. */
2539
2558
  phrases: z.array(z.string()).optional(),
2540
2559
  /** Opt-in timestamps (F036) — a single granularity or an array. Omit → the
2541
- * current { text, usage } shape, unchanged. Pass ["word","segment"] for both. */
2560
+ * current { text, usage } shape, unchanged. Pass ["word","segment"] for both.
2561
+ * Supported by Whisper (openai) + Azure fast-transcription (F036.1); other
2562
+ * adapters (Voxtral/mistral) ignore it and return text only. */
2542
2563
  timestamps: z.union([z.enum(["word", "segment"]), z.array(z.enum(["word", "segment"]))]).optional(),
2543
2564
  ...callOptions
2544
2565
  });
@@ -2580,14 +2601,17 @@ var aiConfigSchema = z.object({
2580
2601
  // Functions can't be deeply validated — z.custom asserts the TS type and
2581
2602
  // passes the value through untouched.
2582
2603
  providers: z.record(z.string(), z.custom()).optional(),
2583
- costSink: z.custom().optional(),
2604
+ /** Omit → cost-tracking auto-wires from the upmetrics env (F034). Pass `null`
2605
+ * to opt OUT explicitly — for a consumer that already reports its own costs
2606
+ * and would otherwise be counted twice (F034.3). An object is used as-is. */
2607
+ costSink: z.custom().nullable().optional(),
2584
2608
  budget: budgetSchema.optional(),
2585
2609
  availability: availabilitySchema.optional()
2586
2610
  });
2587
2611
 
2588
2612
  // src/version.ts
2589
- var VERSION = "0.25.0";
2590
- var SDK_TAG = "@broberg/ai-sdk@0.25.0";
2613
+ var VERSION = "0.26.0";
2614
+ var SDK_TAG = "@broberg/ai-sdk@0.26.0";
2591
2615
 
2592
2616
  // src/cost/sinks/upmetrics.ts
2593
2617
  function upmetricsSink(config) {
@@ -2707,7 +2731,7 @@ function defaultCostSink() {
2707
2731
  function createAI(config = {}) {
2708
2732
  const cfg = aiConfigSchema.parse(config);
2709
2733
  const providers = cfg.providers ?? defaultProviders;
2710
- const costSink = cfg.costSink ?? defaultCostSink();
2734
+ const costSink = cfg.costSink === void 0 ? defaultCostSink() : cfg.costSink ?? void 0;
2711
2735
  const budget = cfg.budget ? new BudgetGuard(cfg.budget) : void 0;
2712
2736
  const estTokens = (s) => Math.ceil(s.length / 4);
2713
2737
  async function preflight(spec, estInTokens, estOutTokens) {