@mastra/ai-sdk 1.0.0-beta.11 → 1.0.0-beta.13
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 +79 -0
- package/dist/chat-route.d.ts +2 -0
- package/dist/chat-route.d.ts.map +1 -1
- package/dist/helpers.d.ts.map +1 -1
- package/dist/index.cjs +65 -30
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +66 -31
- package/dist/index.js.map +1 -1
- package/dist/middleware.d.ts.map +1 -1
- package/dist/transformers.d.ts +8 -7
- package/dist/transformers.d.ts.map +1 -1
- package/package.json +6 -6
package/dist/index.js
CHANGED
|
@@ -3,7 +3,7 @@ import * as z4 from 'zod/v4';
|
|
|
3
3
|
import { z } from 'zod/v4';
|
|
4
4
|
import { ZodFirstPartyTypeKind } from 'zod/v3';
|
|
5
5
|
import { convertFullStreamChunkToMastra, DefaultGeneratedFile, DefaultGeneratedFileWithType } from '@mastra/core/stream';
|
|
6
|
-
import { TripWire, MessageList } from '@mastra/core/agent';
|
|
6
|
+
import { TripWire, MessageList, aiV5ModelMessageToV2PromptMessage } from '@mastra/core/agent';
|
|
7
7
|
import { RequestContext } from '@mastra/core/di';
|
|
8
8
|
import { WorkingMemory, MessageHistory, SemanticRecall } from '@mastra/core/processors';
|
|
9
9
|
|
|
@@ -218,7 +218,7 @@ function secureJsonParse(text2) {
|
|
|
218
218
|
Error.stackTraceLimit = stackTraceLimit;
|
|
219
219
|
}
|
|
220
220
|
}
|
|
221
|
-
var validatorSymbol = Symbol.for("vercel.ai.validator");
|
|
221
|
+
var validatorSymbol = /* @__PURE__ */ Symbol.for("vercel.ai.validator");
|
|
222
222
|
function validator(validate) {
|
|
223
223
|
return { [validatorSymbol]: true, validate };
|
|
224
224
|
}
|
|
@@ -301,7 +301,7 @@ var getRelativePath = (pathA, pathB) => {
|
|
|
301
301
|
}
|
|
302
302
|
return [(pathA.length - i).toString(), ...pathB.slice(i)].join("/");
|
|
303
303
|
};
|
|
304
|
-
var ignoreOverride = Symbol(
|
|
304
|
+
var ignoreOverride = /* @__PURE__ */ Symbol(
|
|
305
305
|
"Let zodToJsonSchema decide on which parser to use"
|
|
306
306
|
);
|
|
307
307
|
var defaultOptions = {
|
|
@@ -1421,7 +1421,7 @@ function zodSchema(zodSchema2, options) {
|
|
|
1421
1421
|
return zod3Schema(zodSchema2);
|
|
1422
1422
|
}
|
|
1423
1423
|
}
|
|
1424
|
-
var schemaSymbol = Symbol.for("vercel.ai.schema");
|
|
1424
|
+
var schemaSymbol = /* @__PURE__ */ Symbol.for("vercel.ai.schema");
|
|
1425
1425
|
function jsonSchema(jsonSchema2, {
|
|
1426
1426
|
validate
|
|
1427
1427
|
} = {}) {
|
|
@@ -2978,7 +2978,8 @@ function convertMastraChunkToAISDKv5({
|
|
|
2978
2978
|
runId: chunk.runId,
|
|
2979
2979
|
toolCallId: chunk.payload.toolCallId,
|
|
2980
2980
|
toolName: chunk.payload.toolName,
|
|
2981
|
-
args: chunk.payload.args
|
|
2981
|
+
args: chunk.payload.args,
|
|
2982
|
+
resumeSchema: chunk.payload.resumeSchema
|
|
2982
2983
|
}
|
|
2983
2984
|
};
|
|
2984
2985
|
case "tool-call-suspended":
|
|
@@ -2989,7 +2990,8 @@ function convertMastraChunkToAISDKv5({
|
|
|
2989
2990
|
runId: chunk.runId,
|
|
2990
2991
|
toolCallId: chunk.payload.toolCallId,
|
|
2991
2992
|
toolName: chunk.payload.toolName,
|
|
2992
|
-
suspendPayload: chunk.payload.suspendPayload
|
|
2993
|
+
suspendPayload: chunk.payload.suspendPayload,
|
|
2994
|
+
resumeSchema: chunk.payload.resumeSchema
|
|
2993
2995
|
}
|
|
2994
2996
|
};
|
|
2995
2997
|
case "tool-call-input-streaming-start":
|
|
@@ -3255,7 +3257,8 @@ function convertFullStreamChunkToUIMessageStream({
|
|
|
3255
3257
|
${JSON.stringify(part)}`
|
|
3256
3258
|
);
|
|
3257
3259
|
}
|
|
3258
|
-
|
|
3260
|
+
const { type, data, id } = part.output;
|
|
3261
|
+
return { type, data, ...id !== void 0 && { id } };
|
|
3259
3262
|
}
|
|
3260
3263
|
return;
|
|
3261
3264
|
}
|
|
@@ -3317,7 +3320,8 @@ function convertFullStreamChunkToUIMessageStream({
|
|
|
3317
3320
|
${JSON.stringify(part)}`
|
|
3318
3321
|
);
|
|
3319
3322
|
}
|
|
3320
|
-
|
|
3323
|
+
const { type, data, id } = part;
|
|
3324
|
+
return { type, data, ...id !== void 0 && { id } };
|
|
3321
3325
|
}
|
|
3322
3326
|
return;
|
|
3323
3327
|
}
|
|
@@ -3325,7 +3329,7 @@ function convertFullStreamChunkToUIMessageStream({
|
|
|
3325
3329
|
}
|
|
3326
3330
|
|
|
3327
3331
|
// src/transformers.ts
|
|
3328
|
-
var PRIMITIVE_CACHE_SYMBOL = Symbol("primitive-cache");
|
|
3332
|
+
var PRIMITIVE_CACHE_SYMBOL = /* @__PURE__ */ Symbol("primitive-cache");
|
|
3329
3333
|
function WorkflowStreamToAISDKTransformer({
|
|
3330
3334
|
includeTextStreamParts
|
|
3331
3335
|
} = {}) {
|
|
@@ -3362,7 +3366,15 @@ function AgentNetworkToAISDKTransformer() {
|
|
|
3362
3366
|
},
|
|
3363
3367
|
transform(chunk, controller) {
|
|
3364
3368
|
const transformed = transformNetwork(chunk, bufferedNetworks);
|
|
3365
|
-
if (transformed)
|
|
3369
|
+
if (transformed) {
|
|
3370
|
+
if (Array.isArray(transformed)) {
|
|
3371
|
+
for (const item of transformed) {
|
|
3372
|
+
controller.enqueue(item);
|
|
3373
|
+
}
|
|
3374
|
+
} else {
|
|
3375
|
+
controller.enqueue(transformed);
|
|
3376
|
+
}
|
|
3377
|
+
}
|
|
3366
3378
|
}
|
|
3367
3379
|
});
|
|
3368
3380
|
}
|
|
@@ -3675,7 +3687,8 @@ function transformWorkflow(payload, bufferedWorkflows, isNested, includeTextStre
|
|
|
3675
3687
|
${JSON.stringify(output)}`
|
|
3676
3688
|
);
|
|
3677
3689
|
}
|
|
3678
|
-
|
|
3690
|
+
const { type, data, id } = output;
|
|
3691
|
+
return { type, data, ...id !== void 0 && { id } };
|
|
3679
3692
|
}
|
|
3680
3693
|
return null;
|
|
3681
3694
|
}
|
|
@@ -3687,7 +3700,12 @@ function transformWorkflow(payload, bufferedWorkflows, isNested, includeTextStre
|
|
|
3687
3700
|
${JSON.stringify(payload)}`
|
|
3688
3701
|
);
|
|
3689
3702
|
}
|
|
3690
|
-
|
|
3703
|
+
const { type, data, id } = payload;
|
|
3704
|
+
return {
|
|
3705
|
+
type,
|
|
3706
|
+
data,
|
|
3707
|
+
...id !== void 0 && { id }
|
|
3708
|
+
};
|
|
3691
3709
|
}
|
|
3692
3710
|
return null;
|
|
3693
3711
|
}
|
|
@@ -3701,7 +3719,8 @@ function transformNetwork(payload, bufferedNetworks, isNested) {
|
|
|
3701
3719
|
name: payload.payload.networkId,
|
|
3702
3720
|
steps: [],
|
|
3703
3721
|
usage: null,
|
|
3704
|
-
output: null
|
|
3722
|
+
output: null,
|
|
3723
|
+
hasEmittedText: false
|
|
3705
3724
|
});
|
|
3706
3725
|
}
|
|
3707
3726
|
const current = bufferedNetworks.get(payload.runId);
|
|
@@ -3736,6 +3755,7 @@ function transformNetwork(payload, bufferedNetworks, isNested) {
|
|
|
3736
3755
|
case "routing-agent-text-start": {
|
|
3737
3756
|
const current = bufferedNetworks.get(payload.runId);
|
|
3738
3757
|
if (!current) return null;
|
|
3758
|
+
current.hasEmittedText = true;
|
|
3739
3759
|
return {
|
|
3740
3760
|
type: "text-start",
|
|
3741
3761
|
id: payload.runId
|
|
@@ -3744,6 +3764,7 @@ function transformNetwork(payload, bufferedNetworks, isNested) {
|
|
|
3744
3764
|
case "routing-agent-text-delta": {
|
|
3745
3765
|
const current = bufferedNetworks.get(payload.runId);
|
|
3746
3766
|
if (!current) return null;
|
|
3767
|
+
current.hasEmittedText = true;
|
|
3747
3768
|
return {
|
|
3748
3769
|
type: "text-delta",
|
|
3749
3770
|
id: payload.runId,
|
|
@@ -3918,15 +3939,25 @@ function transformNetwork(payload, bufferedNetworks, isNested) {
|
|
|
3918
3939
|
case "network-execution-event-step-finish": {
|
|
3919
3940
|
const current = bufferedNetworks.get(payload.runId);
|
|
3920
3941
|
if (!current) return null;
|
|
3921
|
-
|
|
3942
|
+
const resultText = payload.payload?.result;
|
|
3943
|
+
const dataNetworkChunk = {
|
|
3922
3944
|
type: isNested ? "data-tool-network" : "data-network",
|
|
3923
3945
|
id: payload.runId,
|
|
3924
3946
|
data: {
|
|
3925
3947
|
...current,
|
|
3926
3948
|
status: "finished",
|
|
3927
|
-
output:
|
|
3949
|
+
output: resultText ?? current.output
|
|
3928
3950
|
}
|
|
3929
3951
|
};
|
|
3952
|
+
if (!current.hasEmittedText && resultText && typeof resultText === "string" && resultText.length > 0) {
|
|
3953
|
+
current.hasEmittedText = true;
|
|
3954
|
+
return [
|
|
3955
|
+
{ type: "text-start", id: payload.runId },
|
|
3956
|
+
{ type: "text-delta", id: payload.runId, delta: resultText },
|
|
3957
|
+
dataNetworkChunk
|
|
3958
|
+
];
|
|
3959
|
+
}
|
|
3960
|
+
return dataNetworkChunk;
|
|
3930
3961
|
}
|
|
3931
3962
|
case "network-execution-event-finish": {
|
|
3932
3963
|
const current = bufferedNetworks.get(payload.runId);
|
|
@@ -3950,8 +3981,8 @@ function transformNetwork(payload, bufferedNetworks, isNested) {
|
|
|
3950
3981
|
${JSON.stringify(payload)}`
|
|
3951
3982
|
);
|
|
3952
3983
|
}
|
|
3953
|
-
const { type, data } = payload.payload;
|
|
3954
|
-
return { type, data };
|
|
3984
|
+
const { type, data, id } = payload.payload;
|
|
3985
|
+
return { type, data, ...id !== void 0 && { id } };
|
|
3955
3986
|
}
|
|
3956
3987
|
if (isWorkflowExecutionDataChunkType(payload)) {
|
|
3957
3988
|
if (!("data" in payload.payload)) {
|
|
@@ -3960,8 +3991,8 @@ function transformNetwork(payload, bufferedNetworks, isNested) {
|
|
|
3960
3991
|
${JSON.stringify(payload)}`
|
|
3961
3992
|
);
|
|
3962
3993
|
}
|
|
3963
|
-
const { type, data } = payload.payload;
|
|
3964
|
-
return { type, data };
|
|
3994
|
+
const { type, data, id } = payload.payload;
|
|
3995
|
+
return { type, data, ...id !== void 0 && { id } };
|
|
3965
3996
|
}
|
|
3966
3997
|
if (payload.type.startsWith("agent-execution-event-")) {
|
|
3967
3998
|
const stepId = payload.payload.runId;
|
|
@@ -4021,8 +4052,8 @@ function transformNetwork(payload, bufferedNetworks, isNested) {
|
|
|
4021
4052
|
${JSON.stringify(payload)}`
|
|
4022
4053
|
);
|
|
4023
4054
|
}
|
|
4024
|
-
const { type, data } = payload;
|
|
4025
|
-
return { type, data };
|
|
4055
|
+
const { type, data, id } = payload;
|
|
4056
|
+
return { type, data, ...id !== void 0 && { id } };
|
|
4026
4057
|
}
|
|
4027
4058
|
return null;
|
|
4028
4059
|
}
|
|
@@ -4070,7 +4101,7 @@ async function handleChatStream({
|
|
|
4070
4101
|
sendReasoning = false,
|
|
4071
4102
|
sendSources = false
|
|
4072
4103
|
}) {
|
|
4073
|
-
const { messages, resumeData, runId, requestContext, ...rest } = params;
|
|
4104
|
+
const { messages, resumeData, runId, requestContext, trigger, ...rest } = params;
|
|
4074
4105
|
if (resumeData && !runId) {
|
|
4075
4106
|
throw new Error("runId is required when resumeData is provided");
|
|
4076
4107
|
}
|
|
@@ -4081,20 +4112,24 @@ async function handleChatStream({
|
|
|
4081
4112
|
if (!Array.isArray(messages)) {
|
|
4082
4113
|
throw new Error("Messages must be an array of UIMessage objects");
|
|
4083
4114
|
}
|
|
4084
|
-
const mergedOptions = {
|
|
4085
|
-
...defaultOptions2,
|
|
4086
|
-
...rest,
|
|
4087
|
-
...runId && { runId },
|
|
4088
|
-
requestContext: requestContext || defaultOptions2?.requestContext
|
|
4089
|
-
};
|
|
4090
|
-
const result = resumeData ? await agentObj.resumeStream(resumeData, mergedOptions) : await agentObj.stream(messages, mergedOptions);
|
|
4091
4115
|
let lastMessageId;
|
|
4092
|
-
|
|
4116
|
+
let messagesToSend = messages;
|
|
4117
|
+
if (messages.length > 0) {
|
|
4093
4118
|
const lastMessage = messages[messages.length - 1];
|
|
4094
4119
|
if (lastMessage?.role === "assistant") {
|
|
4095
4120
|
lastMessageId = lastMessage.id;
|
|
4121
|
+
if (trigger === "regenerate-message") {
|
|
4122
|
+
messagesToSend = messages.slice(0, -1);
|
|
4123
|
+
}
|
|
4096
4124
|
}
|
|
4097
4125
|
}
|
|
4126
|
+
const mergedOptions = {
|
|
4127
|
+
...defaultOptions2,
|
|
4128
|
+
...rest,
|
|
4129
|
+
...runId && { runId },
|
|
4130
|
+
requestContext: requestContext || defaultOptions2?.requestContext
|
|
4131
|
+
};
|
|
4132
|
+
const result = resumeData ? await agentObj.resumeStream(resumeData, mergedOptions) : await agentObj.stream(messagesToSend, mergedOptions);
|
|
4098
4133
|
return createUIMessageStream({
|
|
4099
4134
|
originalMessages: messages,
|
|
4100
4135
|
execute: async ({ writer }) => {
|
|
@@ -4601,7 +4636,7 @@ function createProcessorMiddleware(options) {
|
|
|
4601
4636
|
}
|
|
4602
4637
|
}
|
|
4603
4638
|
}
|
|
4604
|
-
const newPrompt = messageList.get.all.aiV5.prompt().map(
|
|
4639
|
+
const newPrompt = messageList.get.all.aiV5.prompt().map(aiV5ModelMessageToV2PromptMessage);
|
|
4605
4640
|
return {
|
|
4606
4641
|
...params,
|
|
4607
4642
|
prompt: newPrompt
|