@mastra/ai-sdk 1.0.0-beta.3 → 1.0.1-alpha.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 +94 -31
- 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
|
};
|
|
@@ -531,8 +517,8 @@ function AgentStreamToAISDKTransformer({
|
|
|
531
517
|
sendStart,
|
|
532
518
|
sendFinish,
|
|
533
519
|
responseMessageId: lastMessageId,
|
|
534
|
-
onError(
|
|
535
|
-
return
|
|
520
|
+
onError() {
|
|
521
|
+
return "Error";
|
|
536
522
|
}
|
|
537
523
|
});
|
|
538
524
|
if (transformedChunk) {
|
|
@@ -1045,8 +1031,8 @@ function transformNetwork(payload, bufferedNetworks, isNested) {
|
|
|
1045
1031
|
}
|
|
1046
1032
|
}
|
|
1047
1033
|
|
|
1048
|
-
// src/
|
|
1049
|
-
function
|
|
1034
|
+
// src/to-ai-sdk-format.ts
|
|
1035
|
+
function toAISdkFormat(stream, options = {
|
|
1050
1036
|
from: "agent",
|
|
1051
1037
|
sendStart: true,
|
|
1052
1038
|
sendFinish: true
|
|
@@ -1179,7 +1165,7 @@ function chatRoute({
|
|
|
1179
1165
|
handler: async (c) => {
|
|
1180
1166
|
const { messages, ...rest } = await c.req.json();
|
|
1181
1167
|
const mastra = c.get("mastra");
|
|
1182
|
-
const
|
|
1168
|
+
const runtimeContext = c.get("runtimeContext");
|
|
1183
1169
|
let agentToUse = agent;
|
|
1184
1170
|
if (!agent) {
|
|
1185
1171
|
const agentId = c.req.param("agentId");
|
|
@@ -1190,8 +1176,8 @@ function chatRoute({
|
|
|
1190
1176
|
`Fixed agent ID was set together with an agentId path parameter. This can lead to unexpected behavior.`
|
|
1191
1177
|
);
|
|
1192
1178
|
}
|
|
1193
|
-
if (
|
|
1194
|
-
mastra.getLogger()?.warn(`"
|
|
1179
|
+
if (runtimeContext && defaultOptions?.runtimeContext) {
|
|
1180
|
+
mastra.getLogger()?.warn(`"runtimeContext" set in the route options will be overridden by the request's "runtimeContext".`);
|
|
1195
1181
|
}
|
|
1196
1182
|
if (!agentToUse) {
|
|
1197
1183
|
throw new Error("Agent ID is required");
|
|
@@ -1203,7 +1189,7 @@ function chatRoute({
|
|
|
1203
1189
|
const result = await agentObj.stream(messages, {
|
|
1204
1190
|
...defaultOptions,
|
|
1205
1191
|
...rest,
|
|
1206
|
-
|
|
1192
|
+
runtimeContext: runtimeContext || defaultOptions?.runtimeContext
|
|
1207
1193
|
});
|
|
1208
1194
|
let lastMessageId;
|
|
1209
1195
|
if (messages.length > 0 && messages[messages.length - 1].role === "assistant") {
|
|
@@ -1212,7 +1198,7 @@ function chatRoute({
|
|
|
1212
1198
|
const uiMessageStream = createUIMessageStream({
|
|
1213
1199
|
originalMessages: messages,
|
|
1214
1200
|
execute: async ({ writer }) => {
|
|
1215
|
-
for await (const part of
|
|
1201
|
+
for await (const part of toAISdkFormat(result, {
|
|
1216
1202
|
from: "agent",
|
|
1217
1203
|
lastMessageId,
|
|
1218
1204
|
sendStart,
|
|
@@ -1263,7 +1249,7 @@ function workflowRoute({
|
|
|
1263
1249
|
resourceId: { type: "string" },
|
|
1264
1250
|
inputData: { type: "object", additionalProperties: true },
|
|
1265
1251
|
resumeData: { type: "object", additionalProperties: true },
|
|
1266
|
-
|
|
1252
|
+
runtimeContext: { type: "object", additionalProperties: true },
|
|
1267
1253
|
tracingOptions: { type: "object", additionalProperties: true },
|
|
1268
1254
|
step: { type: "string" }
|
|
1269
1255
|
}
|
|
@@ -1302,11 +1288,11 @@ function workflowRoute({
|
|
|
1302
1288
|
if (!workflowObj) {
|
|
1303
1289
|
throw new Error(`Workflow ${workflowToUse} not found`);
|
|
1304
1290
|
}
|
|
1305
|
-
const run = await workflowObj.
|
|
1291
|
+
const run = await workflowObj.createRunAsync({ runId, resourceId, ...rest });
|
|
1306
1292
|
const stream = resumeData ? run.resumeStream({ resumeData, ...rest }) : run.stream({ inputData, ...rest });
|
|
1307
1293
|
const uiMessageStream = createUIMessageStream({
|
|
1308
1294
|
execute: async ({ writer }) => {
|
|
1309
|
-
for await (const part of
|
|
1295
|
+
for await (const part of toAISdkFormat(stream, { from: "workflow" })) {
|
|
1310
1296
|
writer.write(part);
|
|
1311
1297
|
}
|
|
1312
1298
|
}
|
|
@@ -1346,12 +1332,13 @@ function networkRoute({
|
|
|
1346
1332
|
type: "object",
|
|
1347
1333
|
properties: {
|
|
1348
1334
|
messages: { type: "array", items: { type: "object" } },
|
|
1349
|
-
|
|
1335
|
+
runtimeContext: { type: "object", additionalProperties: true },
|
|
1350
1336
|
runId: { type: "string" },
|
|
1351
1337
|
maxSteps: { type: "number" },
|
|
1352
1338
|
threadId: { type: "string" },
|
|
1353
1339
|
resourceId: { type: "string" },
|
|
1354
1340
|
modelSettings: { type: "object", additionalProperties: true },
|
|
1341
|
+
telemetry: { type: "object", additionalProperties: true },
|
|
1355
1342
|
tools: { type: "array", items: { type: "object" } }
|
|
1356
1343
|
},
|
|
1357
1344
|
required: ["messages"]
|
|
@@ -1400,7 +1387,7 @@ function networkRoute({
|
|
|
1400
1387
|
});
|
|
1401
1388
|
const uiMessageStream = createUIMessageStream({
|
|
1402
1389
|
execute: async ({ writer }) => {
|
|
1403
|
-
for await (const part of
|
|
1390
|
+
for await (const part of toAISdkFormat(result, { from: "network" })) {
|
|
1404
1391
|
writer.write(part);
|
|
1405
1392
|
}
|
|
1406
1393
|
}
|
|
@@ -1410,13 +1397,6 @@ function networkRoute({
|
|
|
1410
1397
|
});
|
|
1411
1398
|
}
|
|
1412
1399
|
|
|
1413
|
-
|
|
1414
|
-
function toAISdkFormat() {
|
|
1415
|
-
throw new Error(
|
|
1416
|
-
'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.'
|
|
1417
|
-
);
|
|
1418
|
-
}
|
|
1419
|
-
|
|
1420
|
-
export { chatRoute, networkRoute, toAISdkFormat, toAISdkV5Stream as toAISdkStream, workflowRoute };
|
|
1400
|
+
export { chatRoute, networkRoute, toAISdkFormat, workflowRoute };
|
|
1421
1401
|
//# sourceMappingURL=index.js.map
|
|
1422
1402
|
//# sourceMappingURL=index.js.map
|