@mastra/ai-sdk 0.0.0-fix-local-pkg-cwd-20251226155239 → 0.0.0-fix-agent-network-schema-20260119184437
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 +243 -6
- package/dist/chat-route.d.ts +7 -6
- package/dist/chat-route.d.ts.map +1 -1
- package/dist/convert-streams.d.ts +3 -3
- package/dist/convert-streams.d.ts.map +1 -1
- package/dist/helpers.d.ts +3 -3
- package/dist/helpers.d.ts.map +1 -1
- package/dist/index.cjs +69 -30
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +70 -31
- package/dist/index.js.map +1 -1
- package/dist/middleware.d.ts.map +1 -1
- package/dist/network-route.d.ts +5 -6
- package/dist/network-route.d.ts.map +1 -1
- package/dist/transformers.d.ts +14 -14
- package/dist/transformers.d.ts.map +1 -1
- package/package.json +8 -8
package/dist/index.cjs
CHANGED
|
@@ -239,7 +239,7 @@ function secureJsonParse(text2) {
|
|
|
239
239
|
Error.stackTraceLimit = stackTraceLimit;
|
|
240
240
|
}
|
|
241
241
|
}
|
|
242
|
-
var validatorSymbol = Symbol.for("vercel.ai.validator");
|
|
242
|
+
var validatorSymbol = /* @__PURE__ */ Symbol.for("vercel.ai.validator");
|
|
243
243
|
function validator(validate) {
|
|
244
244
|
return { [validatorSymbol]: true, validate };
|
|
245
245
|
}
|
|
@@ -322,7 +322,7 @@ var getRelativePath = (pathA, pathB) => {
|
|
|
322
322
|
}
|
|
323
323
|
return [(pathA.length - i).toString(), ...pathB.slice(i)].join("/");
|
|
324
324
|
};
|
|
325
|
-
var ignoreOverride = Symbol(
|
|
325
|
+
var ignoreOverride = /* @__PURE__ */ Symbol(
|
|
326
326
|
"Let zodToJsonSchema decide on which parser to use"
|
|
327
327
|
);
|
|
328
328
|
var defaultOptions = {
|
|
@@ -1442,7 +1442,7 @@ function zodSchema(zodSchema2, options) {
|
|
|
1442
1442
|
return zod3Schema(zodSchema2);
|
|
1443
1443
|
}
|
|
1444
1444
|
}
|
|
1445
|
-
var schemaSymbol = Symbol.for("vercel.ai.schema");
|
|
1445
|
+
var schemaSymbol = /* @__PURE__ */ Symbol.for("vercel.ai.schema");
|
|
1446
1446
|
function jsonSchema(jsonSchema2, {
|
|
1447
1447
|
validate
|
|
1448
1448
|
} = {}) {
|
|
@@ -2999,7 +2999,8 @@ function convertMastraChunkToAISDKv5({
|
|
|
2999
2999
|
runId: chunk.runId,
|
|
3000
3000
|
toolCallId: chunk.payload.toolCallId,
|
|
3001
3001
|
toolName: chunk.payload.toolName,
|
|
3002
|
-
args: chunk.payload.args
|
|
3002
|
+
args: chunk.payload.args,
|
|
3003
|
+
resumeSchema: chunk.payload.resumeSchema
|
|
3003
3004
|
}
|
|
3004
3005
|
};
|
|
3005
3006
|
case "tool-call-suspended":
|
|
@@ -3010,7 +3011,8 @@ function convertMastraChunkToAISDKv5({
|
|
|
3010
3011
|
runId: chunk.runId,
|
|
3011
3012
|
toolCallId: chunk.payload.toolCallId,
|
|
3012
3013
|
toolName: chunk.payload.toolName,
|
|
3013
|
-
suspendPayload: chunk.payload.suspendPayload
|
|
3014
|
+
suspendPayload: chunk.payload.suspendPayload,
|
|
3015
|
+
resumeSchema: chunk.payload.resumeSchema
|
|
3014
3016
|
}
|
|
3015
3017
|
};
|
|
3016
3018
|
case "tool-call-input-streaming-start":
|
|
@@ -3276,7 +3278,8 @@ function convertFullStreamChunkToUIMessageStream({
|
|
|
3276
3278
|
${JSON.stringify(part)}`
|
|
3277
3279
|
);
|
|
3278
3280
|
}
|
|
3279
|
-
|
|
3281
|
+
const { type, data, id } = part.output;
|
|
3282
|
+
return { type, data, ...id !== void 0 && { id } };
|
|
3280
3283
|
}
|
|
3281
3284
|
return;
|
|
3282
3285
|
}
|
|
@@ -3338,7 +3341,8 @@ function convertFullStreamChunkToUIMessageStream({
|
|
|
3338
3341
|
${JSON.stringify(part)}`
|
|
3339
3342
|
);
|
|
3340
3343
|
}
|
|
3341
|
-
|
|
3344
|
+
const { type, data, id } = part;
|
|
3345
|
+
return { type, data, ...id !== void 0 && { id } };
|
|
3342
3346
|
}
|
|
3343
3347
|
return;
|
|
3344
3348
|
}
|
|
@@ -3346,7 +3350,7 @@ function convertFullStreamChunkToUIMessageStream({
|
|
|
3346
3350
|
}
|
|
3347
3351
|
|
|
3348
3352
|
// src/transformers.ts
|
|
3349
|
-
var PRIMITIVE_CACHE_SYMBOL = Symbol("primitive-cache");
|
|
3353
|
+
var PRIMITIVE_CACHE_SYMBOL = /* @__PURE__ */ Symbol("primitive-cache");
|
|
3350
3354
|
function WorkflowStreamToAISDKTransformer({
|
|
3351
3355
|
includeTextStreamParts
|
|
3352
3356
|
} = {}) {
|
|
@@ -3383,7 +3387,15 @@ function AgentNetworkToAISDKTransformer() {
|
|
|
3383
3387
|
},
|
|
3384
3388
|
transform(chunk, controller) {
|
|
3385
3389
|
const transformed = transformNetwork(chunk, bufferedNetworks);
|
|
3386
|
-
if (transformed)
|
|
3390
|
+
if (transformed) {
|
|
3391
|
+
if (Array.isArray(transformed)) {
|
|
3392
|
+
for (const item of transformed) {
|
|
3393
|
+
controller.enqueue(item);
|
|
3394
|
+
}
|
|
3395
|
+
} else {
|
|
3396
|
+
controller.enqueue(transformed);
|
|
3397
|
+
}
|
|
3398
|
+
}
|
|
3387
3399
|
}
|
|
3388
3400
|
});
|
|
3389
3401
|
}
|
|
@@ -3696,7 +3708,8 @@ function transformWorkflow(payload, bufferedWorkflows, isNested, includeTextStre
|
|
|
3696
3708
|
${JSON.stringify(output)}`
|
|
3697
3709
|
);
|
|
3698
3710
|
}
|
|
3699
|
-
|
|
3711
|
+
const { type, data, id } = output;
|
|
3712
|
+
return { type, data, ...id !== void 0 && { id } };
|
|
3700
3713
|
}
|
|
3701
3714
|
return null;
|
|
3702
3715
|
}
|
|
@@ -3708,7 +3721,12 @@ function transformWorkflow(payload, bufferedWorkflows, isNested, includeTextStre
|
|
|
3708
3721
|
${JSON.stringify(payload)}`
|
|
3709
3722
|
);
|
|
3710
3723
|
}
|
|
3711
|
-
|
|
3724
|
+
const { type, data, id } = payload;
|
|
3725
|
+
return {
|
|
3726
|
+
type,
|
|
3727
|
+
data,
|
|
3728
|
+
...id !== void 0 && { id }
|
|
3729
|
+
};
|
|
3712
3730
|
}
|
|
3713
3731
|
return null;
|
|
3714
3732
|
}
|
|
@@ -3722,7 +3740,8 @@ function transformNetwork(payload, bufferedNetworks, isNested) {
|
|
|
3722
3740
|
name: payload.payload.networkId,
|
|
3723
3741
|
steps: [],
|
|
3724
3742
|
usage: null,
|
|
3725
|
-
output: null
|
|
3743
|
+
output: null,
|
|
3744
|
+
hasEmittedText: false
|
|
3726
3745
|
});
|
|
3727
3746
|
}
|
|
3728
3747
|
const current = bufferedNetworks.get(payload.runId);
|
|
@@ -3757,6 +3776,7 @@ function transformNetwork(payload, bufferedNetworks, isNested) {
|
|
|
3757
3776
|
case "routing-agent-text-start": {
|
|
3758
3777
|
const current = bufferedNetworks.get(payload.runId);
|
|
3759
3778
|
if (!current) return null;
|
|
3779
|
+
current.hasEmittedText = true;
|
|
3760
3780
|
return {
|
|
3761
3781
|
type: "text-start",
|
|
3762
3782
|
id: payload.runId
|
|
@@ -3765,6 +3785,7 @@ function transformNetwork(payload, bufferedNetworks, isNested) {
|
|
|
3765
3785
|
case "routing-agent-text-delta": {
|
|
3766
3786
|
const current = bufferedNetworks.get(payload.runId);
|
|
3767
3787
|
if (!current) return null;
|
|
3788
|
+
current.hasEmittedText = true;
|
|
3768
3789
|
return {
|
|
3769
3790
|
type: "text-delta",
|
|
3770
3791
|
id: payload.runId,
|
|
@@ -3939,15 +3960,25 @@ function transformNetwork(payload, bufferedNetworks, isNested) {
|
|
|
3939
3960
|
case "network-execution-event-step-finish": {
|
|
3940
3961
|
const current = bufferedNetworks.get(payload.runId);
|
|
3941
3962
|
if (!current) return null;
|
|
3942
|
-
|
|
3963
|
+
const resultText = payload.payload?.result;
|
|
3964
|
+
const dataNetworkChunk = {
|
|
3943
3965
|
type: isNested ? "data-tool-network" : "data-network",
|
|
3944
3966
|
id: payload.runId,
|
|
3945
3967
|
data: {
|
|
3946
3968
|
...current,
|
|
3947
3969
|
status: "finished",
|
|
3948
|
-
output:
|
|
3970
|
+
output: resultText ?? current.output
|
|
3949
3971
|
}
|
|
3950
3972
|
};
|
|
3973
|
+
if (!current.hasEmittedText && resultText && typeof resultText === "string" && resultText.length > 0) {
|
|
3974
|
+
current.hasEmittedText = true;
|
|
3975
|
+
return [
|
|
3976
|
+
{ type: "text-start", id: payload.runId },
|
|
3977
|
+
{ type: "text-delta", id: payload.runId, delta: resultText },
|
|
3978
|
+
dataNetworkChunk
|
|
3979
|
+
];
|
|
3980
|
+
}
|
|
3981
|
+
return dataNetworkChunk;
|
|
3951
3982
|
}
|
|
3952
3983
|
case "network-execution-event-finish": {
|
|
3953
3984
|
const current = bufferedNetworks.get(payload.runId);
|
|
@@ -3963,6 +3994,10 @@ function transformNetwork(payload, bufferedNetworks, isNested) {
|
|
|
3963
3994
|
}
|
|
3964
3995
|
};
|
|
3965
3996
|
}
|
|
3997
|
+
case "network-object":
|
|
3998
|
+
case "network-object-result": {
|
|
3999
|
+
return null;
|
|
4000
|
+
}
|
|
3966
4001
|
default: {
|
|
3967
4002
|
if (isAgentExecutionDataChunkType(payload)) {
|
|
3968
4003
|
if (!("data" in payload.payload)) {
|
|
@@ -3971,8 +4006,8 @@ function transformNetwork(payload, bufferedNetworks, isNested) {
|
|
|
3971
4006
|
${JSON.stringify(payload)}`
|
|
3972
4007
|
);
|
|
3973
4008
|
}
|
|
3974
|
-
const { type, data } = payload.payload;
|
|
3975
|
-
return { type, data };
|
|
4009
|
+
const { type, data, id } = payload.payload;
|
|
4010
|
+
return { type, data, ...id !== void 0 && { id } };
|
|
3976
4011
|
}
|
|
3977
4012
|
if (isWorkflowExecutionDataChunkType(payload)) {
|
|
3978
4013
|
if (!("data" in payload.payload)) {
|
|
@@ -3981,8 +4016,8 @@ function transformNetwork(payload, bufferedNetworks, isNested) {
|
|
|
3981
4016
|
${JSON.stringify(payload)}`
|
|
3982
4017
|
);
|
|
3983
4018
|
}
|
|
3984
|
-
const { type, data } = payload.payload;
|
|
3985
|
-
return { type, data };
|
|
4019
|
+
const { type, data, id } = payload.payload;
|
|
4020
|
+
return { type, data, ...id !== void 0 && { id } };
|
|
3986
4021
|
}
|
|
3987
4022
|
if (payload.type.startsWith("agent-execution-event-")) {
|
|
3988
4023
|
const stepId = payload.payload.runId;
|
|
@@ -4042,8 +4077,8 @@ function transformNetwork(payload, bufferedNetworks, isNested) {
|
|
|
4042
4077
|
${JSON.stringify(payload)}`
|
|
4043
4078
|
);
|
|
4044
4079
|
}
|
|
4045
|
-
const { type, data } = payload;
|
|
4046
|
-
return { type, data };
|
|
4080
|
+
const { type, data, id } = payload;
|
|
4081
|
+
return { type, data, ...id !== void 0 && { id } };
|
|
4047
4082
|
}
|
|
4048
4083
|
return null;
|
|
4049
4084
|
}
|
|
@@ -4091,7 +4126,7 @@ async function handleChatStream({
|
|
|
4091
4126
|
sendReasoning = false,
|
|
4092
4127
|
sendSources = false
|
|
4093
4128
|
}) {
|
|
4094
|
-
const { messages, resumeData, runId, requestContext, ...rest } = params;
|
|
4129
|
+
const { messages, resumeData, runId, requestContext, trigger, ...rest } = params;
|
|
4095
4130
|
if (resumeData && !runId) {
|
|
4096
4131
|
throw new Error("runId is required when resumeData is provided");
|
|
4097
4132
|
}
|
|
@@ -4102,20 +4137,24 @@ async function handleChatStream({
|
|
|
4102
4137
|
if (!Array.isArray(messages)) {
|
|
4103
4138
|
throw new Error("Messages must be an array of UIMessage objects");
|
|
4104
4139
|
}
|
|
4105
|
-
const mergedOptions = {
|
|
4106
|
-
...defaultOptions2,
|
|
4107
|
-
...rest,
|
|
4108
|
-
...runId && { runId },
|
|
4109
|
-
requestContext: requestContext || defaultOptions2?.requestContext
|
|
4110
|
-
};
|
|
4111
|
-
const result = resumeData ? await agentObj.resumeStream(resumeData, mergedOptions) : await agentObj.stream(messages, mergedOptions);
|
|
4112
4140
|
let lastMessageId;
|
|
4113
|
-
|
|
4141
|
+
let messagesToSend = messages;
|
|
4142
|
+
if (messages.length > 0) {
|
|
4114
4143
|
const lastMessage = messages[messages.length - 1];
|
|
4115
4144
|
if (lastMessage?.role === "assistant") {
|
|
4116
4145
|
lastMessageId = lastMessage.id;
|
|
4146
|
+
if (trigger === "regenerate-message") {
|
|
4147
|
+
messagesToSend = messages.slice(0, -1);
|
|
4148
|
+
}
|
|
4117
4149
|
}
|
|
4118
4150
|
}
|
|
4151
|
+
const mergedOptions = {
|
|
4152
|
+
...defaultOptions2,
|
|
4153
|
+
...rest,
|
|
4154
|
+
...runId && { runId },
|
|
4155
|
+
requestContext: requestContext || defaultOptions2?.requestContext
|
|
4156
|
+
};
|
|
4157
|
+
const result = resumeData ? await agentObj.resumeStream(resumeData, mergedOptions) : await agentObj.stream(messagesToSend, mergedOptions);
|
|
4119
4158
|
return createUIMessageStream({
|
|
4120
4159
|
originalMessages: messages,
|
|
4121
4160
|
execute: async ({ writer }) => {
|
|
@@ -4622,7 +4661,7 @@ function createProcessorMiddleware(options) {
|
|
|
4622
4661
|
}
|
|
4623
4662
|
}
|
|
4624
4663
|
}
|
|
4625
|
-
const newPrompt = messageList.get.all.aiV5.prompt().map(agent.
|
|
4664
|
+
const newPrompt = messageList.get.all.aiV5.prompt().map(agent.aiV5ModelMessageToV2PromptMessage);
|
|
4626
4665
|
return {
|
|
4627
4666
|
...params,
|
|
4628
4667
|
prompt: newPrompt
|