ai 5.0.13 → 5.0.15
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/CHANGELOG.md +14 -0
- package/dist/index.d.mts +19 -1
- package/dist/index.d.ts +19 -1
- package/dist/index.js +253 -11
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +243 -0
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
@@ -514,6 +514,31 @@ var audioMediaTypeSignatures = [
|
|
514
514
|
bytesPrefix: [255, 251],
|
515
515
|
base64Prefix: "//s="
|
516
516
|
},
|
517
|
+
{
|
518
|
+
mediaType: "audio/mpeg",
|
519
|
+
bytesPrefix: [255, 250],
|
520
|
+
base64Prefix: "//o="
|
521
|
+
},
|
522
|
+
{
|
523
|
+
mediaType: "audio/mpeg",
|
524
|
+
bytesPrefix: [255, 243],
|
525
|
+
base64Prefix: "//M="
|
526
|
+
},
|
527
|
+
{
|
528
|
+
mediaType: "audio/mpeg",
|
529
|
+
bytesPrefix: [255, 242],
|
530
|
+
base64Prefix: "//I="
|
531
|
+
},
|
532
|
+
{
|
533
|
+
mediaType: "audio/mpeg",
|
534
|
+
bytesPrefix: [255, 227],
|
535
|
+
base64Prefix: "/+M="
|
536
|
+
},
|
537
|
+
{
|
538
|
+
mediaType: "audio/mpeg",
|
539
|
+
bytesPrefix: [255, 226],
|
540
|
+
base64Prefix: "/+I="
|
541
|
+
},
|
517
542
|
{
|
518
543
|
mediaType: "audio/wav",
|
519
544
|
bytesPrefix: [82, 73, 70, 70],
|
@@ -9645,6 +9670,223 @@ var TextStreamChatTransport = class extends HttpChatTransport {
|
|
9645
9670
|
}
|
9646
9671
|
};
|
9647
9672
|
|
9673
|
+
// src/ui/validate-ui-messages.ts
|
9674
|
+
import { TypeValidationError as TypeValidationError4 } from "@ai-sdk/provider";
|
9675
|
+
import {
|
9676
|
+
validateTypes as validateTypes2
|
9677
|
+
} from "@ai-sdk/provider-utils";
|
9678
|
+
import { z as z10 } from "zod/v4";
|
9679
|
+
var textUIPartSchema = z10.object({
|
9680
|
+
type: z10.literal("text"),
|
9681
|
+
text: z10.string(),
|
9682
|
+
state: z10.enum(["streaming", "done"]).optional(),
|
9683
|
+
providerMetadata: providerMetadataSchema.optional()
|
9684
|
+
});
|
9685
|
+
var reasoningUIPartSchema = z10.object({
|
9686
|
+
type: z10.literal("reasoning"),
|
9687
|
+
text: z10.string(),
|
9688
|
+
state: z10.enum(["streaming", "done"]).optional(),
|
9689
|
+
providerMetadata: providerMetadataSchema.optional()
|
9690
|
+
});
|
9691
|
+
var sourceUrlUIPartSchema = z10.object({
|
9692
|
+
type: z10.literal("source-url"),
|
9693
|
+
sourceId: z10.string(),
|
9694
|
+
url: z10.string(),
|
9695
|
+
title: z10.string().optional(),
|
9696
|
+
providerMetadata: providerMetadataSchema.optional()
|
9697
|
+
});
|
9698
|
+
var sourceDocumentUIPartSchema = z10.object({
|
9699
|
+
type: z10.literal("source-document"),
|
9700
|
+
sourceId: z10.string(),
|
9701
|
+
mediaType: z10.string(),
|
9702
|
+
title: z10.string(),
|
9703
|
+
filename: z10.string().optional(),
|
9704
|
+
providerMetadata: providerMetadataSchema.optional()
|
9705
|
+
});
|
9706
|
+
var fileUIPartSchema = z10.object({
|
9707
|
+
type: z10.literal("file"),
|
9708
|
+
mediaType: z10.string(),
|
9709
|
+
filename: z10.string().optional(),
|
9710
|
+
url: z10.string(),
|
9711
|
+
providerMetadata: providerMetadataSchema.optional()
|
9712
|
+
});
|
9713
|
+
var stepStartUIPartSchema = z10.object({
|
9714
|
+
type: z10.literal("step-start")
|
9715
|
+
});
|
9716
|
+
var dataUIPartSchema = z10.object({
|
9717
|
+
type: z10.string().startsWith("data-"),
|
9718
|
+
id: z10.string().optional(),
|
9719
|
+
data: z10.unknown()
|
9720
|
+
});
|
9721
|
+
var dynamicToolUIPartSchemas = [
|
9722
|
+
z10.object({
|
9723
|
+
type: z10.literal("dynamic-tool"),
|
9724
|
+
toolName: z10.string(),
|
9725
|
+
toolCallId: z10.string(),
|
9726
|
+
state: z10.literal("input-streaming"),
|
9727
|
+
input: z10.unknown().optional(),
|
9728
|
+
output: z10.never().optional(),
|
9729
|
+
errorText: z10.never().optional()
|
9730
|
+
}),
|
9731
|
+
z10.object({
|
9732
|
+
type: z10.literal("dynamic-tool"),
|
9733
|
+
toolName: z10.string(),
|
9734
|
+
toolCallId: z10.string(),
|
9735
|
+
state: z10.literal("input-available"),
|
9736
|
+
input: z10.unknown(),
|
9737
|
+
output: z10.never().optional(),
|
9738
|
+
errorText: z10.never().optional(),
|
9739
|
+
callProviderMetadata: providerMetadataSchema.optional()
|
9740
|
+
}),
|
9741
|
+
z10.object({
|
9742
|
+
type: z10.literal("dynamic-tool"),
|
9743
|
+
toolName: z10.string(),
|
9744
|
+
toolCallId: z10.string(),
|
9745
|
+
state: z10.literal("output-available"),
|
9746
|
+
input: z10.unknown(),
|
9747
|
+
output: z10.unknown(),
|
9748
|
+
errorText: z10.never().optional(),
|
9749
|
+
callProviderMetadata: providerMetadataSchema.optional(),
|
9750
|
+
preliminary: z10.boolean().optional()
|
9751
|
+
}),
|
9752
|
+
z10.object({
|
9753
|
+
type: z10.literal("dynamic-tool"),
|
9754
|
+
toolName: z10.string(),
|
9755
|
+
toolCallId: z10.string(),
|
9756
|
+
state: z10.literal("output-error"),
|
9757
|
+
input: z10.unknown(),
|
9758
|
+
output: z10.never().optional(),
|
9759
|
+
errorText: z10.string(),
|
9760
|
+
callProviderMetadata: providerMetadataSchema.optional()
|
9761
|
+
})
|
9762
|
+
];
|
9763
|
+
var toolUIPartSchemas = [
|
9764
|
+
z10.object({
|
9765
|
+
type: z10.string().startsWith("tool-"),
|
9766
|
+
toolCallId: z10.string(),
|
9767
|
+
state: z10.literal("input-streaming"),
|
9768
|
+
input: z10.unknown().optional(),
|
9769
|
+
output: z10.never().optional(),
|
9770
|
+
errorText: z10.never().optional()
|
9771
|
+
}),
|
9772
|
+
z10.object({
|
9773
|
+
type: z10.string().startsWith("tool-"),
|
9774
|
+
toolCallId: z10.string(),
|
9775
|
+
state: z10.literal("input-available"),
|
9776
|
+
input: z10.unknown(),
|
9777
|
+
output: z10.never().optional(),
|
9778
|
+
errorText: z10.never().optional(),
|
9779
|
+
callProviderMetadata: providerMetadataSchema.optional()
|
9780
|
+
}),
|
9781
|
+
z10.object({
|
9782
|
+
type: z10.string().startsWith("tool-"),
|
9783
|
+
toolCallId: z10.string(),
|
9784
|
+
state: z10.literal("output-available"),
|
9785
|
+
input: z10.unknown(),
|
9786
|
+
output: z10.unknown(),
|
9787
|
+
errorText: z10.never().optional(),
|
9788
|
+
callProviderMetadata: providerMetadataSchema.optional(),
|
9789
|
+
preliminary: z10.boolean().optional()
|
9790
|
+
}),
|
9791
|
+
z10.object({
|
9792
|
+
type: z10.string().startsWith("tool-"),
|
9793
|
+
toolCallId: z10.string(),
|
9794
|
+
state: z10.literal("output-error"),
|
9795
|
+
input: z10.unknown(),
|
9796
|
+
output: z10.never().optional(),
|
9797
|
+
errorText: z10.string(),
|
9798
|
+
callProviderMetadata: providerMetadataSchema.optional()
|
9799
|
+
})
|
9800
|
+
];
|
9801
|
+
var uiMessageSchema = z10.object({
|
9802
|
+
id: z10.string(),
|
9803
|
+
role: z10.enum(["system", "user", "assistant"]),
|
9804
|
+
metadata: z10.unknown().optional(),
|
9805
|
+
parts: z10.array(
|
9806
|
+
z10.union([
|
9807
|
+
textUIPartSchema,
|
9808
|
+
reasoningUIPartSchema,
|
9809
|
+
sourceUrlUIPartSchema,
|
9810
|
+
sourceDocumentUIPartSchema,
|
9811
|
+
fileUIPartSchema,
|
9812
|
+
stepStartUIPartSchema,
|
9813
|
+
dataUIPartSchema,
|
9814
|
+
...dynamicToolUIPartSchemas,
|
9815
|
+
...toolUIPartSchemas
|
9816
|
+
])
|
9817
|
+
)
|
9818
|
+
});
|
9819
|
+
async function validateUIMessages({
|
9820
|
+
messages,
|
9821
|
+
metadataSchema,
|
9822
|
+
dataSchemas,
|
9823
|
+
tools
|
9824
|
+
}) {
|
9825
|
+
const validatedMessages = await validateTypes2({
|
9826
|
+
value: messages,
|
9827
|
+
schema: z10.array(uiMessageSchema)
|
9828
|
+
});
|
9829
|
+
if (metadataSchema) {
|
9830
|
+
for (const message of validatedMessages) {
|
9831
|
+
await validateTypes2({
|
9832
|
+
value: message.metadata,
|
9833
|
+
schema: metadataSchema
|
9834
|
+
});
|
9835
|
+
}
|
9836
|
+
}
|
9837
|
+
if (dataSchemas) {
|
9838
|
+
for (const message of validatedMessages) {
|
9839
|
+
const dataParts = message.parts.filter(
|
9840
|
+
(part) => part.type.startsWith("data-")
|
9841
|
+
);
|
9842
|
+
for (const dataPart of dataParts) {
|
9843
|
+
const dataName = dataPart.type.slice(5);
|
9844
|
+
const dataSchema = dataSchemas[dataName];
|
9845
|
+
if (!dataSchema) {
|
9846
|
+
throw new TypeValidationError4({
|
9847
|
+
value: dataPart.data,
|
9848
|
+
cause: `No data schema found for data part ${dataName}`
|
9849
|
+
});
|
9850
|
+
}
|
9851
|
+
await validateTypes2({
|
9852
|
+
value: dataPart.data,
|
9853
|
+
schema: dataSchema
|
9854
|
+
});
|
9855
|
+
}
|
9856
|
+
}
|
9857
|
+
}
|
9858
|
+
if (tools) {
|
9859
|
+
for (const message of validatedMessages) {
|
9860
|
+
const toolParts = message.parts.filter(
|
9861
|
+
(part) => part.type.startsWith("tool-")
|
9862
|
+
);
|
9863
|
+
for (const toolPart of toolParts) {
|
9864
|
+
const toolName = toolPart.type.slice(5);
|
9865
|
+
const tool3 = tools[toolName];
|
9866
|
+
if (!tool3) {
|
9867
|
+
throw new TypeValidationError4({
|
9868
|
+
value: toolPart.input,
|
9869
|
+
cause: `No tool schema found for tool part ${toolName}`
|
9870
|
+
});
|
9871
|
+
}
|
9872
|
+
if (toolPart.state === "input-available" || toolPart.state === "output-available" || toolPart.state === "output-error") {
|
9873
|
+
await validateTypes2({
|
9874
|
+
value: toolPart.input,
|
9875
|
+
schema: tool3.inputSchema
|
9876
|
+
});
|
9877
|
+
}
|
9878
|
+
if (toolPart.state === "output-available" && tool3.outputSchema) {
|
9879
|
+
await validateTypes2({
|
9880
|
+
value: toolPart.output,
|
9881
|
+
schema: tool3.outputSchema
|
9882
|
+
});
|
9883
|
+
}
|
9884
|
+
}
|
9885
|
+
}
|
9886
|
+
}
|
9887
|
+
return validatedMessages;
|
9888
|
+
}
|
9889
|
+
|
9648
9890
|
// src/ui-message-stream/create-ui-message-stream.ts
|
9649
9891
|
import {
|
9650
9892
|
generateId as generateIdFunc2,
|
@@ -9874,6 +10116,7 @@ export {
|
|
9874
10116
|
tool2 as tool,
|
9875
10117
|
toolModelMessageSchema,
|
9876
10118
|
userModelMessageSchema,
|
10119
|
+
validateUIMessages,
|
9877
10120
|
wrapLanguageModel,
|
9878
10121
|
wrapProvider,
|
9879
10122
|
zodSchema
|