@broberg/ai-sdk 0.10.3 → 0.10.5

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
@@ -715,9 +715,13 @@ declare const visionInputSchema: z.ZodObject<{
715
715
  image: z.ZodUnion<[z.ZodString, z.ZodType<Uint8Array<ArrayBuffer>, z.ZodTypeDef, Uint8Array<ArrayBuffer>>]>;
716
716
  prompt: z.ZodString;
717
717
  mimeType: z.ZodOptional<z.ZodString>;
718
+ /** System instruction — drives instruction-following far better than stuffing
719
+ * rules into `prompt` for instruction-heavy vision tasks (e.g. a JSON critic). */
720
+ system: z.ZodOptional<z.ZodString>;
718
721
  }, "strip", z.ZodTypeAny, {
719
722
  image: string | Uint8Array<ArrayBuffer>;
720
723
  prompt: string;
724
+ system?: string | undefined;
721
725
  mimeType?: string | undefined;
722
726
  purpose?: string | undefined;
723
727
  tier?: "fast" | "smart" | "powerful" | "cheap" | "vision" | "video" | "embedding" | undefined;
@@ -735,6 +739,7 @@ declare const visionInputSchema: z.ZodObject<{
735
739
  }, {
736
740
  image: string | Uint8Array<ArrayBuffer>;
737
741
  prompt: string;
742
+ system?: string | undefined;
738
743
  mimeType?: string | undefined;
739
744
  purpose?: string | undefined;
740
745
  tier?: "fast" | "smart" | "powerful" | "cheap" | "vision" | "video" | "embedding" | undefined;
@@ -783,9 +788,12 @@ declare const videoInputSchema: z.ZodObject<{
783
788
  video: z.ZodUnion<[z.ZodString, z.ZodType<Uint8Array<ArrayBuffer>, z.ZodTypeDef, Uint8Array<ArrayBuffer>>]>;
784
789
  prompt: z.ZodString;
785
790
  mimeType: z.ZodOptional<z.ZodString>;
791
+ /** System instruction — same instruction-following benefit as on vision. */
792
+ system: z.ZodOptional<z.ZodString>;
786
793
  }, "strip", z.ZodTypeAny, {
787
794
  video: string | Uint8Array<ArrayBuffer>;
788
795
  prompt: string;
796
+ system?: string | undefined;
789
797
  mimeType?: string | undefined;
790
798
  purpose?: string | undefined;
791
799
  tier?: "fast" | "smart" | "powerful" | "cheap" | "vision" | "video" | "embedding" | undefined;
@@ -803,6 +811,7 @@ declare const videoInputSchema: z.ZodObject<{
803
811
  }, {
804
812
  video: string | Uint8Array<ArrayBuffer>;
805
813
  prompt: string;
814
+ system?: string | undefined;
806
815
  mimeType?: string | undefined;
807
816
  purpose?: string | undefined;
808
817
  tier?: "fast" | "smart" | "powerful" | "cheap" | "vision" | "video" | "embedding" | undefined;
@@ -1687,8 +1696,8 @@ declare const falStubAdapter: ProviderAdapter;
1687
1696
  * wires the live adapters. */
1688
1697
  declare const stubProviders: Record<string, ProviderAdapter>;
1689
1698
 
1690
- declare const VERSION: "0.10.3";
1691
- declare const SDK_TAG: "@broberg/ai-sdk@0.10.3";
1699
+ declare const VERSION: "0.10.5";
1700
+ declare const SDK_TAG: "@broberg/ai-sdk@0.10.5";
1692
1701
 
1693
1702
  /** Built-in defaults. Every entry is overridable via AiConfig.defaults or a
1694
1703
  * per-call override. Model IDs are current at scaffold time; callers pin their
package/dist/index.js CHANGED
@@ -638,7 +638,7 @@ function makeOpenAICompatibleAdapter(config) {
638
638
  }
639
639
  const data = res.json;
640
640
  const msg = data.choices?.[0]?.message;
641
- const text = msg?.content ?? "";
641
+ const text = contentToText(msg?.content);
642
642
  const toolCalls = msg?.tool_calls?.map(
643
643
  (tc) => fromProviderToolCall(tc, "openai")
644
644
  );
@@ -745,6 +745,17 @@ function makeOpenAICompatibleAdapter(config) {
745
745
  vision: chat
746
746
  };
747
747
  }
748
+ function contentToText(content) {
749
+ if (typeof content === "string") return content;
750
+ if (Array.isArray(content)) {
751
+ return content.map((p) => {
752
+ if (typeof p === "string") return p;
753
+ const t = p?.text;
754
+ return typeof t === "string" ? t : "";
755
+ }).join("");
756
+ }
757
+ return "";
758
+ }
748
759
  function mapFinishReason(reason) {
749
760
  switch (reason) {
750
761
  case "tool_calls":
@@ -1618,29 +1629,31 @@ var BudgetGuard = class {
1618
1629
  // src/capabilities/vision.ts
1619
1630
  var VISION_DEFAULT_TIER = "vision";
1620
1631
  function buildVisionMessages(input) {
1621
- return [
1622
- {
1623
- role: "user",
1624
- content: [
1625
- { type: "text", text: input.prompt },
1626
- { type: "image", image: input.image, mimeType: input.mimeType }
1627
- ]
1628
- }
1629
- ];
1632
+ const messages = [];
1633
+ if (input.system) messages.push({ role: "system", content: input.system });
1634
+ messages.push({
1635
+ role: "user",
1636
+ content: [
1637
+ { type: "text", text: input.prompt },
1638
+ { type: "image", image: input.image, mimeType: input.mimeType }
1639
+ ]
1640
+ });
1641
+ return messages;
1630
1642
  }
1631
1643
 
1632
1644
  // src/capabilities/video.ts
1633
1645
  var VIDEO_DEFAULT_TIER = "video";
1634
1646
  function buildVideoMessages(input) {
1635
- return [
1636
- {
1637
- role: "user",
1638
- content: [
1639
- { type: "video", video: input.video, mimeType: input.mimeType },
1640
- { type: "text", text: input.prompt }
1641
- ]
1642
- }
1643
- ];
1647
+ const messages = [];
1648
+ if (input.system) messages.push({ role: "system", content: input.system });
1649
+ messages.push({
1650
+ role: "user",
1651
+ content: [
1652
+ { type: "video", video: input.video, mimeType: input.mimeType },
1653
+ { type: "text", text: input.prompt }
1654
+ ]
1655
+ });
1656
+ return messages;
1644
1657
  }
1645
1658
 
1646
1659
  // src/capabilities/translate.ts
@@ -1834,12 +1847,17 @@ var visionInputSchema = z.object({
1834
1847
  image: z.union([z.string(), z.instanceof(Uint8Array)]),
1835
1848
  prompt: z.string(),
1836
1849
  mimeType: z.string().optional(),
1850
+ /** System instruction — drives instruction-following far better than stuffing
1851
+ * rules into `prompt` for instruction-heavy vision tasks (e.g. a JSON critic). */
1852
+ system: z.string().optional(),
1837
1853
  ...callOptions
1838
1854
  });
1839
1855
  var videoInputSchema = z.object({
1840
1856
  video: z.union([z.string(), z.instanceof(Uint8Array)]),
1841
1857
  prompt: z.string(),
1842
1858
  mimeType: z.string().optional(),
1859
+ /** System instruction — same instruction-following benefit as on vision. */
1860
+ system: z.string().optional(),
1843
1861
  ...callOptions
1844
1862
  });
1845
1863
  var translateInputSchema = z.object({
@@ -1980,7 +1998,12 @@ function createAI(config = {}) {
1980
1998
  }
1981
1999
  }
1982
2000
  function toMessages(input) {
1983
- if (input.messages && input.messages.length > 0) return input.messages;
2001
+ if (input.messages && input.messages.length > 0) {
2002
+ if (input.system && input.messages[0]?.role !== "system") {
2003
+ return [{ role: "system", content: input.system }, ...input.messages];
2004
+ }
2005
+ return input.messages;
2006
+ }
1984
2007
  const msgs = [];
1985
2008
  if (input.system) msgs.push({ role: "system", content: input.system });
1986
2009
  msgs.push({ role: "user", content: input.prompt ?? "" });
@@ -2447,8 +2470,8 @@ var stubProviders = {
2447
2470
  };
2448
2471
 
2449
2472
  // src/version.ts
2450
- var VERSION = "0.10.3";
2451
- var SDK_TAG = "@broberg/ai-sdk@0.10.3";
2473
+ var VERSION = "0.10.5";
2474
+ var SDK_TAG = "@broberg/ai-sdk@0.10.5";
2452
2475
 
2453
2476
  // src/cost/budget-store.ts
2454
2477
  function sqliteBudgetStore(config) {