@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/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(error) {
535
- return safeParseErrorObject(error);
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/convert-streams.ts
1049
- function toAISdkV5Stream(stream, options = {
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 requestContext = c.get("requestContext");
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 (requestContext && defaultOptions?.requestContext) {
1194
- mastra.getLogger()?.warn(`"requestContext" set in the route options will be overridden by the request's "requestContext".`);
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
- requestContext: requestContext || defaultOptions?.requestContext
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 toAISdkV5Stream(result, {
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
- requestContext: { type: "object", additionalProperties: true },
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.createRun({ runId, resourceId, ...rest });
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 toAISdkV5Stream(stream, { from: "workflow" })) {
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
- requestContext: { type: "object", additionalProperties: true },
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 toAISdkV5Stream(result, { from: "network" })) {
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
- // src/to-ai-sdk-format.ts
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