@broberg/ai-sdk 0.68.1 → 0.69.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
|
@@ -1437,8 +1437,8 @@ declare const falStubAdapter: ProviderAdapter;
|
|
|
1437
1437
|
* wires the live adapters. */
|
|
1438
1438
|
declare const stubProviders: Record<string, ProviderAdapter>;
|
|
1439
1439
|
|
|
1440
|
-
declare const VERSION: "0.
|
|
1441
|
-
declare const SDK_TAG: "@broberg/ai-sdk@0.
|
|
1440
|
+
declare const VERSION: "0.69.0";
|
|
1441
|
+
declare const SDK_TAG: "@broberg/ai-sdk@0.69.0";
|
|
1442
1442
|
|
|
1443
1443
|
/** Built-in defaults. Every entry is overridable via AiConfig.defaults or a
|
|
1444
1444
|
* per-call override.
|
package/dist/index.js
CHANGED
|
@@ -23,7 +23,7 @@ import {
|
|
|
23
23
|
listMediaPrices,
|
|
24
24
|
pricingFreshness,
|
|
25
25
|
pricingGeneratedAt
|
|
26
|
-
} from "./chunk-
|
|
26
|
+
} from "./chunk-6AXGUZFA.js";
|
|
27
27
|
import {
|
|
28
28
|
PRICING,
|
|
29
29
|
getPrice
|
|
@@ -2008,6 +2008,63 @@ function mistralAdapter(config = {}) {
|
|
|
2008
2008
|
}
|
|
2009
2009
|
return { audio: new Uint8Array(Buffer.from(data.audio_data, "base64")), mimeType, usage };
|
|
2010
2010
|
}
|
|
2011
|
+
async function image(req) {
|
|
2012
|
+
const unsupported = [
|
|
2013
|
+
["width/height", req.width !== void 0 || req.height !== void 0],
|
|
2014
|
+
["referenceImages", !!req.referenceImages?.length],
|
|
2015
|
+
["finetune", req.finetune !== void 0],
|
|
2016
|
+
["loras", !!req.loras?.length],
|
|
2017
|
+
["seed", req.seed !== void 0],
|
|
2018
|
+
["outputFormat", req.outputFormat !== void 0]
|
|
2019
|
+
].filter(([, set]) => set).map(([name]) => name);
|
|
2020
|
+
if (unsupported.length) {
|
|
2021
|
+
throw new Error(
|
|
2022
|
+
`mistral image: ${unsupported.join(", ")} not supported by Mistral's image tool \u2014 route this call to bfl (override:{ provider:"bfl", model:"flux-2-pro" }).`
|
|
2023
|
+
);
|
|
2024
|
+
}
|
|
2025
|
+
const res = await fetchImpl(`${baseUrl}/conversations`, {
|
|
2026
|
+
method: "POST",
|
|
2027
|
+
headers: { "content-type": "application/json", authorization: `Bearer ${key()}` },
|
|
2028
|
+
body: JSON.stringify({
|
|
2029
|
+
model: req.spec.model,
|
|
2030
|
+
inputs: req.prompt,
|
|
2031
|
+
tools: [{ type: "image_generation" }],
|
|
2032
|
+
store: false,
|
|
2033
|
+
// Without this the model echoes the URL back as markdown — ~350 output tokens
|
|
2034
|
+
// per image (measured) for text nobody reads.
|
|
2035
|
+
instructions: "Call image_generation exactly once with the user's request as the prompt. Afterwards reply only: done"
|
|
2036
|
+
})
|
|
2037
|
+
});
|
|
2038
|
+
if (!res.ok) {
|
|
2039
|
+
const body = await res.text().catch(() => "");
|
|
2040
|
+
throw new Error(`mistral image ${res.status}: ${body.slice(0, 300)}`);
|
|
2041
|
+
}
|
|
2042
|
+
const data = await res.json();
|
|
2043
|
+
const exec = data.outputs?.find((o) => o.type === "tool.execution" && o.name === "image_generation");
|
|
2044
|
+
let url;
|
|
2045
|
+
try {
|
|
2046
|
+
url = exec?.info?.result ? JSON.parse(exec.info.result).url : void 0;
|
|
2047
|
+
} catch {
|
|
2048
|
+
url = void 0;
|
|
2049
|
+
}
|
|
2050
|
+
if (!url) {
|
|
2051
|
+
const said = data.outputs?.find((o) => o.type === "message.output")?.content;
|
|
2052
|
+
throw new Error(`mistral image: the model returned no image (${String(said ?? "no output").slice(0, 200)})`);
|
|
2053
|
+
}
|
|
2054
|
+
const usage = freshUsage({
|
|
2055
|
+
provider: "mistral",
|
|
2056
|
+
region: regionOfHost(baseUrl),
|
|
2057
|
+
model: req.spec.model,
|
|
2058
|
+
transport: "http",
|
|
2059
|
+
capability: "image",
|
|
2060
|
+
inputTokens: data.usage?.prompt_tokens ?? 0,
|
|
2061
|
+
outputTokens: data.usage?.completion_tokens ?? 0
|
|
2062
|
+
});
|
|
2063
|
+
const images = data.usage?.connectors?.image_generation ?? 1;
|
|
2064
|
+
usage.costUsd += images * (getMediaPrice("mistral", "image_generation")?.usd ?? 0);
|
|
2065
|
+
usage.costBasis = "estimated";
|
|
2066
|
+
return { url, usage };
|
|
2067
|
+
}
|
|
2011
2068
|
async function batchSubmit(req) {
|
|
2012
2069
|
const jsonl = req.items.map(
|
|
2013
2070
|
(it) => JSON.stringify({
|
|
@@ -2053,7 +2110,7 @@ function mistralAdapter(config = {}) {
|
|
|
2053
2110
|
return { customId: row.custom_id ?? "", text: row.response?.body?.choices?.[0]?.message?.content ?? "" };
|
|
2054
2111
|
});
|
|
2055
2112
|
}
|
|
2056
|
-
return { ...base, ocr, moderate, embedding, transcribe, tts, batchSubmit, batchStatus, batchResults };
|
|
2113
|
+
return { ...base, ocr, moderate, embedding, transcribe, tts, image, batchSubmit, batchStatus, batchResults };
|
|
2057
2114
|
}
|
|
2058
2115
|
|
|
2059
2116
|
// src/providers/elevenlabs.ts
|
|
@@ -4142,8 +4199,8 @@ var aiConfigSchema = z.object({
|
|
|
4142
4199
|
import { randomUUID } from "crypto";
|
|
4143
4200
|
|
|
4144
4201
|
// src/version.ts
|
|
4145
|
-
var VERSION = "0.
|
|
4146
|
-
var SDK_TAG = "@broberg/ai-sdk@0.
|
|
4202
|
+
var VERSION = "0.69.0";
|
|
4203
|
+
var SDK_TAG = "@broberg/ai-sdk@0.69.0";
|
|
4147
4204
|
|
|
4148
4205
|
// src/cost/sinks/upmetrics.ts
|
|
4149
4206
|
function isRetryableStatus(status) {
|