@broberg/ai-sdk 0.10.4 → 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 +11 -2
- package/dist/index.js +39 -21
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
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.
|
|
1691
|
-
declare const SDK_TAG: "@broberg/ai-sdk@0.10.
|
|
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
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
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
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
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({
|
|
@@ -2452,8 +2470,8 @@ var stubProviders = {
|
|
|
2452
2470
|
};
|
|
2453
2471
|
|
|
2454
2472
|
// src/version.ts
|
|
2455
|
-
var VERSION = "0.10.
|
|
2456
|
-
var SDK_TAG = "@broberg/ai-sdk@0.10.
|
|
2473
|
+
var VERSION = "0.10.5";
|
|
2474
|
+
var SDK_TAG = "@broberg/ai-sdk@0.10.5";
|
|
2457
2475
|
|
|
2458
2476
|
// src/cost/budget-store.ts
|
|
2459
2477
|
function sqliteBudgetStore(config) {
|