@mastra/ai-sdk 1.0.0-beta.2 → 1.0.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/CHANGELOG.md +90 -27
- package/dist/helpers.d.ts +2 -1
- package/dist/helpers.d.ts.map +1 -1
- package/dist/index.cjs +15 -36
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +16 -36
- package/dist/index.js.map +1 -1
- package/dist/network-route.d.ts.map +1 -1
- package/dist/to-ai-sdk-format.d.ts +61 -11
- package/dist/to-ai-sdk-format.d.ts.map +1 -1
- package/dist/transformers.d.ts.map +1 -1
- package/dist/utils.d.ts +0 -1
- package/dist/utils.d.ts.map +1 -1
- package/package.json +12 -20
- package/dist/convert-messages.d.ts +0 -10
- package/dist/convert-messages.d.ts.map +0 -1
- package/dist/convert-streams.d.ts +0 -66
- package/dist/convert-streams.d.ts.map +0 -1
- package/dist/ui.cjs +0 -16
- package/dist/ui.cjs.map +0 -1
- package/dist/ui.d.ts +0 -2
- package/dist/ui.d.ts.map +0 -1
- package/dist/ui.js +0 -13
- package/dist/ui.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -8,20 +8,6 @@ import { DefaultGeneratedFile, DefaultGeneratedFileWithType } from '@mastra/core
|
|
|
8
8
|
var isDataChunkType = (chunk) => {
|
|
9
9
|
return chunk && typeof chunk === "object" && "type" in chunk && chunk.type?.startsWith("data-");
|
|
10
10
|
};
|
|
11
|
-
function safeParseErrorObject(obj) {
|
|
12
|
-
if (typeof obj !== "object" || obj === null) {
|
|
13
|
-
return String(obj);
|
|
14
|
-
}
|
|
15
|
-
try {
|
|
16
|
-
const stringified = JSON.stringify(obj);
|
|
17
|
-
if (stringified === "{}") {
|
|
18
|
-
return String(obj);
|
|
19
|
-
}
|
|
20
|
-
return stringified;
|
|
21
|
-
} catch {
|
|
22
|
-
return String(obj);
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
11
|
var isAgentExecutionDataChunkType = (chunk) => {
|
|
26
12
|
return chunk && typeof chunk === "object" && "type" in chunk && chunk.type?.startsWith("agent-execution-event-") && "payload" in chunk && typeof chunk.payload === "object" && "type" in chunk.payload && chunk.payload.type?.startsWith("data-");
|
|
27
13
|
};
|
|
@@ -516,8 +502,8 @@ function AgentStreamToAISDKTransformer({
|
|
|
516
502
|
sendStart,
|
|
517
503
|
sendFinish,
|
|
518
504
|
responseMessageId: lastMessageId,
|
|
519
|
-
onError(
|
|
520
|
-
return
|
|
505
|
+
onError() {
|
|
506
|
+
return "Error";
|
|
521
507
|
}
|
|
522
508
|
});
|
|
523
509
|
if (transformedChunk) {
|
|
@@ -1022,8 +1008,8 @@ function transformNetwork(payload, bufferedNetworks, isNested) {
|
|
|
1022
1008
|
}
|
|
1023
1009
|
}
|
|
1024
1010
|
|
|
1025
|
-
// src/
|
|
1026
|
-
function
|
|
1011
|
+
// src/to-ai-sdk-format.ts
|
|
1012
|
+
function toAISdkFormat(stream, options = {
|
|
1027
1013
|
from: "agent",
|
|
1028
1014
|
sendStart: true,
|
|
1029
1015
|
sendFinish: true
|
|
@@ -1156,7 +1142,7 @@ function chatRoute({
|
|
|
1156
1142
|
handler: async (c) => {
|
|
1157
1143
|
const { messages, ...rest } = await c.req.json();
|
|
1158
1144
|
const mastra = c.get("mastra");
|
|
1159
|
-
const
|
|
1145
|
+
const runtimeContext = c.get("runtimeContext");
|
|
1160
1146
|
let agentToUse = agent;
|
|
1161
1147
|
if (!agent) {
|
|
1162
1148
|
const agentId = c.req.param("agentId");
|
|
@@ -1167,8 +1153,8 @@ function chatRoute({
|
|
|
1167
1153
|
`Fixed agent ID was set together with an agentId path parameter. This can lead to unexpected behavior.`
|
|
1168
1154
|
);
|
|
1169
1155
|
}
|
|
1170
|
-
if (
|
|
1171
|
-
mastra.getLogger()?.warn(`"
|
|
1156
|
+
if (runtimeContext && defaultOptions?.runtimeContext) {
|
|
1157
|
+
mastra.getLogger()?.warn(`"runtimeContext" set in the route options will be overridden by the request's "runtimeContext".`);
|
|
1172
1158
|
}
|
|
1173
1159
|
if (!agentToUse) {
|
|
1174
1160
|
throw new Error("Agent ID is required");
|
|
@@ -1180,7 +1166,7 @@ function chatRoute({
|
|
|
1180
1166
|
const result = await agentObj.stream(messages, {
|
|
1181
1167
|
...defaultOptions,
|
|
1182
1168
|
...rest,
|
|
1183
|
-
|
|
1169
|
+
runtimeContext: runtimeContext || defaultOptions?.runtimeContext
|
|
1184
1170
|
});
|
|
1185
1171
|
let lastMessageId;
|
|
1186
1172
|
if (messages.length > 0 && messages[messages.length - 1].role === "assistant") {
|
|
@@ -1189,7 +1175,7 @@ function chatRoute({
|
|
|
1189
1175
|
const uiMessageStream = createUIMessageStream({
|
|
1190
1176
|
originalMessages: messages,
|
|
1191
1177
|
execute: async ({ writer }) => {
|
|
1192
|
-
for await (const part of
|
|
1178
|
+
for await (const part of toAISdkFormat(result, {
|
|
1193
1179
|
from: "agent",
|
|
1194
1180
|
lastMessageId,
|
|
1195
1181
|
sendStart,
|
|
@@ -1240,7 +1226,7 @@ function workflowRoute({
|
|
|
1240
1226
|
resourceId: { type: "string" },
|
|
1241
1227
|
inputData: { type: "object", additionalProperties: true },
|
|
1242
1228
|
resumeData: { type: "object", additionalProperties: true },
|
|
1243
|
-
|
|
1229
|
+
runtimeContext: { type: "object", additionalProperties: true },
|
|
1244
1230
|
tracingOptions: { type: "object", additionalProperties: true },
|
|
1245
1231
|
step: { type: "string" }
|
|
1246
1232
|
}
|
|
@@ -1279,11 +1265,11 @@ function workflowRoute({
|
|
|
1279
1265
|
if (!workflowObj) {
|
|
1280
1266
|
throw new Error(`Workflow ${workflowToUse} not found`);
|
|
1281
1267
|
}
|
|
1282
|
-
const run = await workflowObj.
|
|
1268
|
+
const run = await workflowObj.createRunAsync({ runId, resourceId, ...rest });
|
|
1283
1269
|
const stream = resumeData ? run.resumeStream({ resumeData, ...rest }) : run.stream({ inputData, ...rest });
|
|
1284
1270
|
const uiMessageStream = createUIMessageStream({
|
|
1285
1271
|
execute: async ({ writer }) => {
|
|
1286
|
-
for await (const part of
|
|
1272
|
+
for await (const part of toAISdkFormat(stream, { from: "workflow" })) {
|
|
1287
1273
|
writer.write(part);
|
|
1288
1274
|
}
|
|
1289
1275
|
}
|
|
@@ -1323,12 +1309,13 @@ function networkRoute({
|
|
|
1323
1309
|
type: "object",
|
|
1324
1310
|
properties: {
|
|
1325
1311
|
messages: { type: "array", items: { type: "object" } },
|
|
1326
|
-
|
|
1312
|
+
runtimeContext: { type: "object", additionalProperties: true },
|
|
1327
1313
|
runId: { type: "string" },
|
|
1328
1314
|
maxSteps: { type: "number" },
|
|
1329
1315
|
threadId: { type: "string" },
|
|
1330
1316
|
resourceId: { type: "string" },
|
|
1331
1317
|
modelSettings: { type: "object", additionalProperties: true },
|
|
1318
|
+
telemetry: { type: "object", additionalProperties: true },
|
|
1332
1319
|
tools: { type: "array", items: { type: "object" } }
|
|
1333
1320
|
},
|
|
1334
1321
|
required: ["messages"]
|
|
@@ -1377,7 +1364,7 @@ function networkRoute({
|
|
|
1377
1364
|
});
|
|
1378
1365
|
const uiMessageStream = createUIMessageStream({
|
|
1379
1366
|
execute: async ({ writer }) => {
|
|
1380
|
-
for await (const part of
|
|
1367
|
+
for await (const part of toAISdkFormat(result, { from: "network" })) {
|
|
1381
1368
|
writer.write(part);
|
|
1382
1369
|
}
|
|
1383
1370
|
}
|
|
@@ -1387,13 +1374,6 @@ function networkRoute({
|
|
|
1387
1374
|
});
|
|
1388
1375
|
}
|
|
1389
1376
|
|
|
1390
|
-
|
|
1391
|
-
function toAISdkFormat() {
|
|
1392
|
-
throw new Error(
|
|
1393
|
-
'toAISdkFormat() has been deprecated. Please use toAISdkStream() instead.\n\nMigration:\n import { toAISdkFormat } from "@mastra/ai-sdk";\n // Change to:\n import { toAISdkStream } from "@mastra/ai-sdk";\n\nThe function signature remains the same.'
|
|
1394
|
-
);
|
|
1395
|
-
}
|
|
1396
|
-
|
|
1397
|
-
export { chatRoute, networkRoute, toAISdkFormat, toAISdkV5Stream as toAISdkStream, workflowRoute };
|
|
1377
|
+
export { chatRoute, networkRoute, toAISdkFormat, workflowRoute };
|
|
1398
1378
|
//# sourceMappingURL=index.js.map
|
|
1399
1379
|
//# sourceMappingURL=index.js.map
|