@broberg/ai-sdk 0.65.0 → 0.66.1
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 +537 -1454
- package/dist/index.js +41 -23
- package/dist/index.js.map +1 -1
- package/package.json +5 -4
package/dist/index.js
CHANGED
|
@@ -3716,6 +3716,23 @@ function checkVoice(requested, opts = {}) {
|
|
|
3716
3716
|
|
|
3717
3717
|
// src/schema/inputs.ts
|
|
3718
3718
|
import { z } from "zod";
|
|
3719
|
+
var INPUT_LIMITS = {
|
|
3720
|
+
messages: 1e4,
|
|
3721
|
+
contentParts: 1e3,
|
|
3722
|
+
toolCalls: 1e3,
|
|
3723
|
+
tools: 1e3,
|
|
3724
|
+
fallback: 32,
|
|
3725
|
+
loras: 32,
|
|
3726
|
+
trainImages: 1e3,
|
|
3727
|
+
texts: 1e4,
|
|
3728
|
+
phrases: 1e4,
|
|
3729
|
+
granularities: 10,
|
|
3730
|
+
judgeEntryItems: 1e3,
|
|
3731
|
+
stateItems: 1e4,
|
|
3732
|
+
scriptLines: 1e4,
|
|
3733
|
+
pronunciations: 1e4
|
|
3734
|
+
};
|
|
3735
|
+
var L = INPUT_LIMITS;
|
|
3719
3736
|
var transportSchema = z.enum(["http", "subprocess"]);
|
|
3720
3737
|
var tierSchema = z.enum([
|
|
3721
3738
|
"fast",
|
|
@@ -3734,13 +3751,13 @@ var tierSpecSchema = z.object({
|
|
|
3734
3751
|
var toolSchema = z.object({
|
|
3735
3752
|
name: z.string(),
|
|
3736
3753
|
description: z.string(),
|
|
3737
|
-
parameters: z.record(z.unknown())
|
|
3754
|
+
parameters: z.record(z.string(), z.unknown())
|
|
3738
3755
|
});
|
|
3739
3756
|
var toolCallSchema = z.object({
|
|
3740
3757
|
id: z.string(),
|
|
3741
3758
|
name: z.string(),
|
|
3742
|
-
arguments: z.record(z.unknown()).optional(),
|
|
3743
|
-
args: z.record(z.unknown()).optional()
|
|
3759
|
+
arguments: z.record(z.string(), z.unknown()).optional(),
|
|
3760
|
+
args: z.record(z.string(), z.unknown()).optional()
|
|
3744
3761
|
}).refine((tc) => tc.arguments !== void 0 || tc.args !== void 0, {
|
|
3745
3762
|
message: "tool call needs `arguments` (canonical) or `args` (@broberg/chat's spelling)",
|
|
3746
3763
|
path: ["arguments"]
|
|
@@ -3755,8 +3772,8 @@ var contentPartSchema = z.union([
|
|
|
3755
3772
|
]);
|
|
3756
3773
|
var messageSchema = z.object({
|
|
3757
3774
|
role: z.enum(["system", "user", "assistant", "tool"]),
|
|
3758
|
-
content: z.union([z.string(), z.array(contentPartSchema)]),
|
|
3759
|
-
toolCalls: z.array(toolCallSchema).optional(),
|
|
3775
|
+
content: z.union([z.string(), z.array(contentPartSchema).max(L.contentParts)]),
|
|
3776
|
+
toolCalls: z.array(toolCallSchema).max(L.toolCalls).optional(),
|
|
3760
3777
|
toolCallId: z.string().optional(),
|
|
3761
3778
|
/** F049 — see Message.prefix. Position/role validity is enforced in the adapter,
|
|
3762
3779
|
* not here: the rule is about a message's place in the ARRAY, which a per-message
|
|
@@ -3766,7 +3783,7 @@ var messageSchema = z.object({
|
|
|
3766
3783
|
var callOptions = {
|
|
3767
3784
|
tier: tierSchema.optional(),
|
|
3768
3785
|
override: tierSpecSchema.partial().optional(),
|
|
3769
|
-
fallback: z.array(z.union([tierSchema, tierSpecSchema])).optional(),
|
|
3786
|
+
fallback: z.array(z.union([tierSchema, tierSpecSchema])).max(L.fallback).optional(),
|
|
3770
3787
|
purpose: z.string().optional(),
|
|
3771
3788
|
/** F077.3 — you MEAN to call a floating "-latest" id (no warning, no strictPinning error). */
|
|
3772
3789
|
allowFloating: z.boolean().optional(),
|
|
@@ -3784,9 +3801,9 @@ var chatInputSchema = z.object({
|
|
|
3784
3801
|
* false opts out; an explicit promptCacheKey always wins. */
|
|
3785
3802
|
promptCache: z.boolean().optional(),
|
|
3786
3803
|
prompt: z.string().optional(),
|
|
3787
|
-
messages: z.array(messageSchema).optional(),
|
|
3804
|
+
messages: z.array(messageSchema).max(L.messages).optional(),
|
|
3788
3805
|
system: z.string().optional(),
|
|
3789
|
-
tools: z.array(toolSchema).optional(),
|
|
3806
|
+
tools: z.array(toolSchema).max(L.tools).optional(),
|
|
3790
3807
|
maxTokens: z.number().int().positive().optional(),
|
|
3791
3808
|
temperature: z.number().min(0).max(2).optional(),
|
|
3792
3809
|
/** F074.3 — Mistral reasoning ("thinking") before the answer. Large 4 thinks by
|
|
@@ -3828,7 +3845,7 @@ var imageInputSchema = z.object({
|
|
|
3828
3845
|
width: z.number().int().positive().optional(),
|
|
3829
3846
|
height: z.number().int().positive().optional(),
|
|
3830
3847
|
/** LoRAs to merge at inference (F021). */
|
|
3831
|
-
loras: z.array(loraWeightSchema).optional(),
|
|
3848
|
+
loras: z.array(loraWeightSchema).max(L.loras).optional(),
|
|
3832
3849
|
/** Shorthand for a single LoRA — normalized to loras:[{path, scale:1}]. */
|
|
3833
3850
|
lora: z.string().optional(),
|
|
3834
3851
|
/** F023 — a BFL finetune id (subject trained in the BFL dashboard). Routes to the
|
|
@@ -3866,7 +3883,7 @@ var animateInputSchema = z.object({
|
|
|
3866
3883
|
});
|
|
3867
3884
|
var trainStyleInputSchema = z.object({
|
|
3868
3885
|
/** A hosted archive URL, or an array of image URLs the SDK zips in-memory. */
|
|
3869
|
-
images: z.union([z.string(), z.array(z.string())]),
|
|
3886
|
+
images: z.union([z.string(), z.array(z.string()).max(L.trainImages)]),
|
|
3870
3887
|
/** Style LoRA (disables captioning/masks). Default true. */
|
|
3871
3888
|
isStyle: z.boolean().optional(),
|
|
3872
3889
|
triggerWord: z.string().optional(),
|
|
@@ -3875,7 +3892,7 @@ var trainStyleInputSchema = z.object({
|
|
|
3875
3892
|
...callOptions
|
|
3876
3893
|
});
|
|
3877
3894
|
var embeddingInputSchema = z.object({
|
|
3878
|
-
text: z.union([z.string(), z.array(z.string())]),
|
|
3895
|
+
text: z.union([z.string(), z.array(z.string()).max(L.texts)]),
|
|
3879
3896
|
...callOptions
|
|
3880
3897
|
});
|
|
3881
3898
|
var transcribeInputSchema = z.object({
|
|
@@ -3885,12 +3902,12 @@ var transcribeInputSchema = z.object({
|
|
|
3885
3902
|
/** Audio length in seconds — enables Whisper per-minute cost. */
|
|
3886
3903
|
durationSec: z.number().positive().optional(),
|
|
3887
3904
|
/** Bias toward brand/jargon terms (Azure phraseList, F029.3); others ignore it. */
|
|
3888
|
-
phrases: z.array(z.string()).optional(),
|
|
3905
|
+
phrases: z.array(z.string()).max(L.phrases).optional(),
|
|
3889
3906
|
/** Opt-in timestamps (F036) — a single granularity or an array. Omit → the
|
|
3890
3907
|
* current { text, usage } shape, unchanged. Pass ["word","segment"] for both.
|
|
3891
3908
|
* Supported by Whisper (openai) + Azure fast-transcription (F036.1); other
|
|
3892
3909
|
* adapters (Voxtral/mistral) ignore it and return text only. */
|
|
3893
|
-
timestamps: z.union([z.enum(["word", "segment"]), z.array(z.enum(["word", "segment"]))]).optional(),
|
|
3910
|
+
timestamps: z.union([z.enum(["word", "segment"]), z.array(z.enum(["word", "segment"])).max(L.granularities)]).optional(),
|
|
3894
3911
|
...callOptions
|
|
3895
3912
|
});
|
|
3896
3913
|
var ocrInputSchema = z.object({
|
|
@@ -3901,10 +3918,10 @@ var ocrInputSchema = z.object({
|
|
|
3901
3918
|
...callOptions
|
|
3902
3919
|
});
|
|
3903
3920
|
var moderationInputSchema = z.object({
|
|
3904
|
-
input: z.union([z.string(), z.array(z.string())]),
|
|
3921
|
+
input: z.union([z.string(), z.array(z.string()).max(L.texts)]),
|
|
3905
3922
|
...callOptions
|
|
3906
3923
|
});
|
|
3907
|
-
var judgeEntrySchema = z.union([z.string().min(1), z.null(), z.array(z.unknown()), z.record(z.unknown())]);
|
|
3924
|
+
var judgeEntrySchema = z.union([z.string().min(1), z.null(), z.array(z.unknown()).max(L.judgeEntryItems), z.record(z.string(), z.unknown())]);
|
|
3908
3925
|
var judgeQuestionSchema = z.discriminatedUnion("type", [
|
|
3909
3926
|
z.object({
|
|
3910
3927
|
type: z.literal("noul"),
|
|
@@ -3929,7 +3946,7 @@ var judgeQuestionSchema = z.discriminatedUnion("type", [
|
|
|
3929
3946
|
})
|
|
3930
3947
|
]);
|
|
3931
3948
|
var judgeInputSchema = z.object({
|
|
3932
|
-
state: z.union([z.string().min(1), z.array(z.string()), z.record(z.unknown())]),
|
|
3949
|
+
state: z.union([z.string().min(1), z.array(z.string()).max(L.stateItems), z.record(z.string(), z.unknown())]),
|
|
3933
3950
|
questions: z.record(z.string(), judgeQuestionSchema).refine((q) => Object.keys(q).length > 0, {
|
|
3934
3951
|
message: "judge needs at least one question"
|
|
3935
3952
|
}),
|
|
@@ -3944,13 +3961,13 @@ var pronunciationSchema = z.object({
|
|
|
3944
3961
|
matchInCompounds: z.boolean().optional()
|
|
3945
3962
|
});
|
|
3946
3963
|
var podcastInputSchema = z.object({
|
|
3947
|
-
script: z.array(z.object({ speaker: z.string(), text: z.string() })).min(1),
|
|
3964
|
+
script: z.array(z.object({ speaker: z.string(), text: z.string() })).min(1).max(L.scriptLines),
|
|
3948
3965
|
voices: z.record(z.string(), z.string()),
|
|
3949
3966
|
format: z.string().optional(),
|
|
3950
3967
|
/** F051.4 — same field, same semantics as tts. Applied PER LINE: ElevenLabs'
|
|
3951
3968
|
* /text-to-dialogue takes inputs[].text separately, so there is no composed string
|
|
3952
3969
|
* a replacement could run across a speaker boundary in. */
|
|
3953
|
-
pronunciations: z.array(pronunciationSchema).optional(),
|
|
3970
|
+
pronunciations: z.array(pronunciationSchema).max(L.pronunciations).optional(),
|
|
3954
3971
|
...callOptions
|
|
3955
3972
|
});
|
|
3956
3973
|
var ttsInputSchema = z.object({
|
|
@@ -3958,7 +3975,7 @@ var ttsInputSchema = z.object({
|
|
|
3958
3975
|
voice: z.string(),
|
|
3959
3976
|
/** F051 — see TtsRequest.pronunciations. The alias/ipa exclusivity is enforced in
|
|
3960
3977
|
* the adapter, not here: the message must name the provider that cannot do it. */
|
|
3961
|
-
pronunciations: z.array(pronunciationSchema).optional(),
|
|
3978
|
+
pronunciations: z.array(pronunciationSchema).max(L.pronunciations).optional(),
|
|
3962
3979
|
/** F055 — per-word timings (Azure only). Changes the route to batch synthesis. */
|
|
3963
3980
|
wordTimings: z.boolean().optional(),
|
|
3964
3981
|
/** F037: voice to use if `voice` is one we know the provider has retired. Without
|
|
@@ -3983,7 +4000,7 @@ var budgetSchema = z.object({
|
|
|
3983
4000
|
});
|
|
3984
4001
|
var availabilitySchema = z.object({
|
|
3985
4002
|
autoResolve: z.boolean().optional(),
|
|
3986
|
-
fallback: z.union([z.string(), z.array(z.string())]).optional()
|
|
4003
|
+
fallback: z.union([z.string(), z.array(z.string()).max(L.fallback)]).optional()
|
|
3987
4004
|
});
|
|
3988
4005
|
var aiConfigSchema = z.object({
|
|
3989
4006
|
/** F069.1 — customer-key mode. Every provider must be built with byokAdapter(), so no
|
|
@@ -3997,7 +4014,7 @@ var aiConfigSchema = z.object({
|
|
|
3997
4014
|
promptCache: z.boolean().optional(),
|
|
3998
4015
|
/** F077.3 — refuse any "-latest" model id unless the call passes allowFloating: true. */
|
|
3999
4016
|
strictPinning: z.boolean().optional(),
|
|
4000
|
-
defaults: z.
|
|
4017
|
+
defaults: z.partialRecord(tierSchema, tierSpecSchema).optional(),
|
|
4001
4018
|
// Functions can't be deeply validated — z.custom asserts the TS type and
|
|
4002
4019
|
// passes the value through untouched.
|
|
4003
4020
|
providers: z.record(z.string(), z.custom()).optional(),
|
|
@@ -4016,8 +4033,8 @@ var aiConfigSchema = z.object({
|
|
|
4016
4033
|
import { randomUUID } from "crypto";
|
|
4017
4034
|
|
|
4018
4035
|
// src/version.ts
|
|
4019
|
-
var VERSION = "0.
|
|
4020
|
-
var SDK_TAG = "@broberg/ai-sdk@0.
|
|
4036
|
+
var VERSION = "0.66.1";
|
|
4037
|
+
var SDK_TAG = "@broberg/ai-sdk@0.66.1";
|
|
4021
4038
|
|
|
4022
4039
|
// src/cost/sinks/upmetrics.ts
|
|
4023
4040
|
function isRetryableStatus(status) {
|
|
@@ -5572,6 +5589,7 @@ export {
|
|
|
5572
5589
|
DEFAULT_SEARCH_ROUTES,
|
|
5573
5590
|
DEFAULT_TIER_MAP,
|
|
5574
5591
|
ELEVENLABS_DANISH_VOICES,
|
|
5592
|
+
INPUT_LIMITS,
|
|
5575
5593
|
LOCALLY_PINNED_HOSTS,
|
|
5576
5594
|
MEDIA_PRICING_CHECKED_AT,
|
|
5577
5595
|
ModelUnavailableError,
|