@broberg/ai-sdk 0.14.0 → 0.15.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 +33 -6
- package/dist/index.js +50 -17
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -170,6 +170,16 @@ interface ImageRequest {
|
|
|
170
170
|
finetune?: string;
|
|
171
171
|
/** F023 — how strongly the finetune is applied (BFL finetune_strength, ~0–2). */
|
|
172
172
|
finetuneStrength?: number;
|
|
173
|
+
/** F023.5 — 1–8 reference photos of a subject (URL or raw bytes). Routes to the
|
|
174
|
+
* EU-resident BFL FLUX 2 multi-reference endpoint — generate a likeness with NO
|
|
175
|
+
* training step. Bytes are base64-inlined into the EU call (no cross-region fetch). */
|
|
176
|
+
referenceImages?: (string | Uint8Array)[];
|
|
177
|
+
/** F023.5 — fixed seed for reproducible output (BFL). */
|
|
178
|
+
seed?: number;
|
|
179
|
+
/** F023.5 — output container (BFL FLUX 2): "jpeg" | "png" | "webp". Default jpeg. */
|
|
180
|
+
outputFormat?: "jpeg" | "png" | "webp";
|
|
181
|
+
/** F023.5 — BFL content-moderation strictness, 0 (strict) … 6 (lax). Default 2. */
|
|
182
|
+
safetyTolerance?: number;
|
|
173
183
|
/** F021.4 — re-roll once with a fresh seed if fal's safety-checker false-positives
|
|
174
184
|
* and returns a black image (has_nsfw_concepts). fal only. */
|
|
175
185
|
retryOnBlack?: boolean;
|
|
@@ -952,6 +962,15 @@ declare const imageInputSchema: z.ZodObject<{
|
|
|
952
962
|
finetune: z.ZodOptional<z.ZodString>;
|
|
953
963
|
/** F023 — BFL finetune_strength (~0–2; higher = stronger likeness). */
|
|
954
964
|
finetuneStrength: z.ZodOptional<z.ZodNumber>;
|
|
965
|
+
/** F023.5 — 1–8 reference photos (URL or raw bytes) → EU-resident BFL FLUX 2
|
|
966
|
+
* multi-reference generation (likeness, no training step). */
|
|
967
|
+
referenceImages: z.ZodOptional<z.ZodArray<z.ZodUnion<[z.ZodString, z.ZodType<Uint8Array<ArrayBuffer>, z.ZodTypeDef, Uint8Array<ArrayBuffer>>]>, "many">>;
|
|
968
|
+
/** F023.5 — fixed seed for reproducible output (BFL). */
|
|
969
|
+
seed: z.ZodOptional<z.ZodNumber>;
|
|
970
|
+
/** F023.5 — output container (BFL FLUX 2). Default jpeg. */
|
|
971
|
+
outputFormat: z.ZodOptional<z.ZodEnum<["jpeg", "png", "webp"]>>;
|
|
972
|
+
/** F023.5 — BFL content-moderation strictness, 0 (strict) … 6 (lax). Default 2. */
|
|
973
|
+
safetyTolerance: z.ZodOptional<z.ZodNumber>;
|
|
955
974
|
/** F021.4 — re-roll once if fal returns a black image (NSFW false-positive). */
|
|
956
975
|
retryOnBlack: z.ZodOptional<z.ZodBoolean>;
|
|
957
976
|
}, "strip", z.ZodTypeAny, {
|
|
@@ -961,7 +980,10 @@ declare const imageInputSchema: z.ZodObject<{
|
|
|
961
980
|
path: string;
|
|
962
981
|
scale?: number | undefined;
|
|
963
982
|
}[] | undefined;
|
|
983
|
+
seed?: number | undefined;
|
|
964
984
|
lora?: string | undefined;
|
|
985
|
+
width?: number | undefined;
|
|
986
|
+
height?: number | undefined;
|
|
965
987
|
tier?: "fast" | "smart" | "powerful" | "cheap" | "vision" | "video" | "embedding" | undefined;
|
|
966
988
|
override?: {
|
|
967
989
|
provider?: string | undefined;
|
|
@@ -974,10 +996,11 @@ declare const imageInputSchema: z.ZodObject<{
|
|
|
974
996
|
transport: "http" | "subprocess";
|
|
975
997
|
})[] | undefined;
|
|
976
998
|
labels?: Record<string, string> | undefined;
|
|
977
|
-
width?: number | undefined;
|
|
978
|
-
height?: number | undefined;
|
|
979
999
|
finetune?: string | undefined;
|
|
980
1000
|
finetuneStrength?: number | undefined;
|
|
1001
|
+
referenceImages?: (string | Uint8Array<ArrayBuffer>)[] | undefined;
|
|
1002
|
+
outputFormat?: "jpeg" | "png" | "webp" | undefined;
|
|
1003
|
+
safetyTolerance?: number | undefined;
|
|
981
1004
|
retryOnBlack?: boolean | undefined;
|
|
982
1005
|
}, {
|
|
983
1006
|
prompt: string;
|
|
@@ -986,7 +1009,10 @@ declare const imageInputSchema: z.ZodObject<{
|
|
|
986
1009
|
path: string;
|
|
987
1010
|
scale?: number | undefined;
|
|
988
1011
|
}[] | undefined;
|
|
1012
|
+
seed?: number | undefined;
|
|
989
1013
|
lora?: string | undefined;
|
|
1014
|
+
width?: number | undefined;
|
|
1015
|
+
height?: number | undefined;
|
|
990
1016
|
tier?: "fast" | "smart" | "powerful" | "cheap" | "vision" | "video" | "embedding" | undefined;
|
|
991
1017
|
override?: {
|
|
992
1018
|
provider?: string | undefined;
|
|
@@ -999,10 +1025,11 @@ declare const imageInputSchema: z.ZodObject<{
|
|
|
999
1025
|
transport: "http" | "subprocess";
|
|
1000
1026
|
})[] | undefined;
|
|
1001
1027
|
labels?: Record<string, string> | undefined;
|
|
1002
|
-
width?: number | undefined;
|
|
1003
|
-
height?: number | undefined;
|
|
1004
1028
|
finetune?: string | undefined;
|
|
1005
1029
|
finetuneStrength?: number | undefined;
|
|
1030
|
+
referenceImages?: (string | Uint8Array<ArrayBuffer>)[] | undefined;
|
|
1031
|
+
outputFormat?: "jpeg" | "png" | "webp" | undefined;
|
|
1032
|
+
safetyTolerance?: number | undefined;
|
|
1006
1033
|
retryOnBlack?: boolean | undefined;
|
|
1007
1034
|
}>;
|
|
1008
1035
|
declare const trainStyleInputSchema: z.ZodObject<{
|
|
@@ -1741,8 +1768,8 @@ declare const falStubAdapter: ProviderAdapter;
|
|
|
1741
1768
|
* wires the live adapters. */
|
|
1742
1769
|
declare const stubProviders: Record<string, ProviderAdapter>;
|
|
1743
1770
|
|
|
1744
|
-
declare const VERSION: "0.
|
|
1745
|
-
declare const SDK_TAG: "@broberg/ai-sdk@0.
|
|
1771
|
+
declare const VERSION: "0.15.0";
|
|
1772
|
+
declare const SDK_TAG: "@broberg/ai-sdk@0.15.0";
|
|
1746
1773
|
|
|
1747
1774
|
/** Built-in defaults. Every entry is overridable via AiConfig.defaults or a
|
|
1748
1775
|
* per-call override. Model IDs are current at scaffold time; callers pin their
|
package/dist/index.js
CHANGED
|
@@ -1575,6 +1575,7 @@ function buildZip(files) {
|
|
|
1575
1575
|
|
|
1576
1576
|
// src/providers/bfl.ts
|
|
1577
1577
|
var EU_BASE = "https://api.eu.bfl.ai";
|
|
1578
|
+
var BFL_CREDIT_USD = 0.01;
|
|
1578
1579
|
var BFL_IMAGE_PRICE = 0.06;
|
|
1579
1580
|
var sleep2 = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
1580
1581
|
function gcd(a, b) {
|
|
@@ -1589,22 +1590,30 @@ function bflAdapter(config = {}) {
|
|
|
1589
1590
|
async function image(req) {
|
|
1590
1591
|
const apiKey = resolveKey();
|
|
1591
1592
|
if (!apiKey) throw new Error("bfl adapter: BFL_API_KEY not set");
|
|
1592
|
-
|
|
1593
|
+
const headers = { "content-type": "application/json", "x-key": apiKey };
|
|
1594
|
+
const body = { prompt: req.prompt };
|
|
1595
|
+
if (req.referenceImages?.length) {
|
|
1596
|
+
req.referenceImages.forEach((img, i) => {
|
|
1597
|
+
body[i === 0 ? "input_image" : `input_image_${i + 1}`] = toBflImage(img);
|
|
1598
|
+
});
|
|
1599
|
+
if (req.width) body.width = req.width;
|
|
1600
|
+
if (req.height) body.height = req.height;
|
|
1601
|
+
if (req.seed !== void 0) body.seed = req.seed;
|
|
1602
|
+
body.output_format = req.outputFormat ?? "jpeg";
|
|
1603
|
+
body.safety_tolerance = req.safetyTolerance ?? 2;
|
|
1604
|
+
} else if (req.finetune) {
|
|
1605
|
+
body.finetune_id = req.finetune;
|
|
1606
|
+
if (req.finetuneStrength !== void 0) body.finetune_strength = req.finetuneStrength;
|
|
1607
|
+
if (req.width && req.height) {
|
|
1608
|
+
const g = gcd(req.width, req.height) || 1;
|
|
1609
|
+
body.aspect_ratio = `${req.width / g}:${req.height / g}`;
|
|
1610
|
+
}
|
|
1611
|
+
} else {
|
|
1593
1612
|
throw new Error(
|
|
1594
|
-
"bfl adapter: requires a finetune id
|
|
1613
|
+
"bfl adapter: requires referenceImages (FLUX 2 multi-reference) or a finetune id. ai.image({ referenceImages: [...] }) needs no training; ai.image({ finetune }) uses a subject trained once in the BFL dashboard (dashboard.bfl.ai \u2014 finetune-create is not in the public API)."
|
|
1595
1614
|
);
|
|
1596
1615
|
}
|
|
1597
|
-
const
|
|
1598
|
-
const body = {
|
|
1599
|
-
finetune_id: req.finetune,
|
|
1600
|
-
prompt: req.prompt
|
|
1601
|
-
};
|
|
1602
|
-
if (req.finetuneStrength !== void 0) body.finetune_strength = req.finetuneStrength;
|
|
1603
|
-
if (req.width && req.height) {
|
|
1604
|
-
const g = gcd(req.width, req.height) || 1;
|
|
1605
|
-
body.aspect_ratio = `${req.width / g}:${req.height / g}`;
|
|
1606
|
-
}
|
|
1607
|
-
const submitRes = await doFetch(`${base}/v1/flux-pro-1.1-ultra-finetuned`, {
|
|
1616
|
+
const submitRes = await doFetch(`${base}/v1/${req.spec.model}`, {
|
|
1608
1617
|
method: "POST",
|
|
1609
1618
|
headers,
|
|
1610
1619
|
body: JSON.stringify(body)
|
|
@@ -1623,9 +1632,15 @@ function bflAdapter(config = {}) {
|
|
|
1623
1632
|
inputTokens: 0,
|
|
1624
1633
|
outputTokens: 0
|
|
1625
1634
|
});
|
|
1626
|
-
usage.costUsd = config.pricePerImage ?? BFL_IMAGE_PRICE;
|
|
1635
|
+
usage.costUsd = typeof submit.cost === "number" ? submit.cost * BFL_CREDIT_USD : config.pricePerImage ?? BFL_IMAGE_PRICE;
|
|
1627
1636
|
return { url: sample, usage };
|
|
1628
1637
|
}
|
|
1638
|
+
function toBflImage(img) {
|
|
1639
|
+
if (typeof img !== "string") return Buffer.from(img).toString("base64");
|
|
1640
|
+
if (/^https?:\/\//i.test(img)) return img;
|
|
1641
|
+
const comma = img.startsWith("data:") ? img.indexOf(",") : -1;
|
|
1642
|
+
return comma >= 0 ? img.slice(comma + 1) : img;
|
|
1643
|
+
}
|
|
1629
1644
|
async function poll(id, apiKey) {
|
|
1630
1645
|
const headers = { "x-key": apiKey };
|
|
1631
1646
|
const deadline = Date.now() + timeoutMs;
|
|
@@ -1979,6 +1994,15 @@ var imageInputSchema = z.object({
|
|
|
1979
1994
|
finetune: z.string().optional(),
|
|
1980
1995
|
/** F023 — BFL finetune_strength (~0–2; higher = stronger likeness). */
|
|
1981
1996
|
finetuneStrength: z.number().min(0).max(2).optional(),
|
|
1997
|
+
/** F023.5 — 1–8 reference photos (URL or raw bytes) → EU-resident BFL FLUX 2
|
|
1998
|
+
* multi-reference generation (likeness, no training step). */
|
|
1999
|
+
referenceImages: z.array(z.union([z.string(), z.instanceof(Uint8Array)])).min(1).max(8).optional(),
|
|
2000
|
+
/** F023.5 — fixed seed for reproducible output (BFL). */
|
|
2001
|
+
seed: z.number().int().optional(),
|
|
2002
|
+
/** F023.5 — output container (BFL FLUX 2). Default jpeg. */
|
|
2003
|
+
outputFormat: z.enum(["jpeg", "png", "webp"]).optional(),
|
|
2004
|
+
/** F023.5 — BFL content-moderation strictness, 0 (strict) … 6 (lax). Default 2. */
|
|
2005
|
+
safetyTolerance: z.number().int().min(0).max(6).optional(),
|
|
1982
2006
|
/** F021.4 — re-roll once if fal returns a black image (NSFW false-positive). */
|
|
1983
2007
|
retryOnBlack: z.boolean().optional(),
|
|
1984
2008
|
...callOptions
|
|
@@ -2066,6 +2090,11 @@ var DEFAULT_BFL_FINETUNE_SPEC = {
|
|
|
2066
2090
|
model: "flux-pro-1.1-ultra-finetuned",
|
|
2067
2091
|
transport: "http"
|
|
2068
2092
|
};
|
|
2093
|
+
var DEFAULT_BFL_REFERENCE_SPEC = {
|
|
2094
|
+
provider: "bfl",
|
|
2095
|
+
model: "flux-2-max",
|
|
2096
|
+
transport: "http"
|
|
2097
|
+
};
|
|
2069
2098
|
var DEFAULT_OCR_SPEC = { provider: "mistral", model: "mistral-ocr-latest", transport: "http" };
|
|
2070
2099
|
var DEFAULT_MODERATION_SPEC = { provider: "mistral", model: "mistral-moderation-latest", transport: "http" };
|
|
2071
2100
|
var DEFAULT_PODCAST_SPEC = { provider: "elevenlabs", model: "eleven_v3", transport: "http" };
|
|
@@ -2312,7 +2341,7 @@ function createAI(config = {}) {
|
|
|
2312
2341
|
...input.loras ?? [],
|
|
2313
2342
|
...input.lora ? [{ path: input.lora }] : []
|
|
2314
2343
|
];
|
|
2315
|
-
const base = input.finetune ? DEFAULT_BFL_FINETUNE_SPEC : loras.length > 0 ? DEFAULT_LORA_IMAGE_SPEC : DEFAULT_IMAGE_SPEC;
|
|
2344
|
+
const base = input.referenceImages?.length ? DEFAULT_BFL_REFERENCE_SPEC : input.finetune ? DEFAULT_BFL_FINETUNE_SPEC : loras.length > 0 ? DEFAULT_LORA_IMAGE_SPEC : DEFAULT_IMAGE_SPEC;
|
|
2316
2345
|
return runCapability({
|
|
2317
2346
|
primary: { ...base, ...input.override },
|
|
2318
2347
|
fallback: input.fallback,
|
|
@@ -2333,6 +2362,10 @@ function createAI(config = {}) {
|
|
|
2333
2362
|
loras: loras.length ? loras : void 0,
|
|
2334
2363
|
finetune: input.finetune,
|
|
2335
2364
|
finetuneStrength: input.finetuneStrength,
|
|
2365
|
+
referenceImages: input.referenceImages,
|
|
2366
|
+
seed: input.seed,
|
|
2367
|
+
outputFormat: input.outputFormat,
|
|
2368
|
+
safetyTolerance: input.safetyTolerance,
|
|
2336
2369
|
retryOnBlack: input.retryOnBlack
|
|
2337
2370
|
});
|
|
2338
2371
|
}
|
|
@@ -2588,8 +2621,8 @@ var stubProviders = {
|
|
|
2588
2621
|
};
|
|
2589
2622
|
|
|
2590
2623
|
// src/version.ts
|
|
2591
|
-
var VERSION = "0.
|
|
2592
|
-
var SDK_TAG = "@broberg/ai-sdk@0.
|
|
2624
|
+
var VERSION = "0.15.0";
|
|
2625
|
+
var SDK_TAG = "@broberg/ai-sdk@0.15.0";
|
|
2593
2626
|
|
|
2594
2627
|
// src/availability/refresh.ts
|
|
2595
2628
|
var NOT_REFRESHED = { refreshed: false, checked: 0, markedUnavailable: [] };
|