@mastra/ai-sdk 0.0.0-netlify-no-bundle-20251127120354 → 0.0.0-partial-response-backport-20251204204441
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 +163 -175
- package/dist/helpers.d.ts +1 -1
- package/dist/helpers.d.ts.map +1 -1
- package/dist/index.cjs +19 -26
- 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 +20 -26
- package/dist/index.js.map +1 -1
- package/dist/network-route.d.ts.map +1 -1
- package/dist/to-ai-sdk-format.d.ts +78 -11
- package/dist/to-ai-sdk-format.d.ts.map +1 -1
- package/dist/workflow-route.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 -82
- 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
|
@@ -1200,15 +1200,15 @@ function transformNetwork(payload, bufferedNetworks, isNested) {
|
|
|
1200
1200
|
}
|
|
1201
1201
|
}
|
|
1202
1202
|
|
|
1203
|
-
// src/
|
|
1204
|
-
function
|
|
1203
|
+
// src/to-ai-sdk-format.ts
|
|
1204
|
+
function toAISdkFormat(stream, options = {
|
|
1205
1205
|
from: "agent",
|
|
1206
1206
|
sendStart: true,
|
|
1207
1207
|
sendFinish: true
|
|
1208
1208
|
}) {
|
|
1209
1209
|
const from = options?.from;
|
|
1210
1210
|
if (from === "workflow") {
|
|
1211
|
-
const includeTextStreamParts = options?.includeTextStreamParts ??
|
|
1211
|
+
const includeTextStreamParts = options?.includeTextStreamParts ?? false;
|
|
1212
1212
|
return stream.pipeThrough(
|
|
1213
1213
|
WorkflowStreamToAISDKTransformer({ includeTextStreamParts })
|
|
1214
1214
|
);
|
|
@@ -1339,7 +1339,7 @@ function chatRoute({
|
|
|
1339
1339
|
handler: async (c) => {
|
|
1340
1340
|
const { messages, ...rest } = await c.req.json();
|
|
1341
1341
|
const mastra = c.get("mastra");
|
|
1342
|
-
const
|
|
1342
|
+
const runtimeContext = c.get("runtimeContext");
|
|
1343
1343
|
let agentToUse = agent;
|
|
1344
1344
|
if (!agent) {
|
|
1345
1345
|
const agentId = c.req.param("agentId");
|
|
@@ -1350,8 +1350,8 @@ function chatRoute({
|
|
|
1350
1350
|
`Fixed agent ID was set together with an agentId path parameter. This can lead to unexpected behavior.`
|
|
1351
1351
|
);
|
|
1352
1352
|
}
|
|
1353
|
-
if (
|
|
1354
|
-
mastra.getLogger()?.warn(`"
|
|
1353
|
+
if (runtimeContext && defaultOptions?.runtimeContext) {
|
|
1354
|
+
mastra.getLogger()?.warn(`"runtimeContext" set in the route options will be overridden by the request's "runtimeContext".`);
|
|
1355
1355
|
}
|
|
1356
1356
|
if (!agentToUse) {
|
|
1357
1357
|
throw new Error("Agent ID is required");
|
|
@@ -1363,7 +1363,7 @@ function chatRoute({
|
|
|
1363
1363
|
const result = await agentObj.stream(messages, {
|
|
1364
1364
|
...defaultOptions,
|
|
1365
1365
|
...rest,
|
|
1366
|
-
|
|
1366
|
+
runtimeContext: runtimeContext || defaultOptions?.runtimeContext
|
|
1367
1367
|
});
|
|
1368
1368
|
let lastMessageId;
|
|
1369
1369
|
if (messages.length > 0 && messages[messages.length - 1].role === "assistant") {
|
|
@@ -1372,7 +1372,7 @@ function chatRoute({
|
|
|
1372
1372
|
const uiMessageStream = createUIMessageStream({
|
|
1373
1373
|
originalMessages: messages,
|
|
1374
1374
|
execute: async ({ writer }) => {
|
|
1375
|
-
for await (const part of
|
|
1375
|
+
for await (const part of toAISdkFormat(result, {
|
|
1376
1376
|
from: "agent",
|
|
1377
1377
|
lastMessageId,
|
|
1378
1378
|
sendStart,
|
|
@@ -1393,7 +1393,7 @@ function chatRoute({
|
|
|
1393
1393
|
function workflowRoute({
|
|
1394
1394
|
path = "/api/workflows/:workflowId/stream",
|
|
1395
1395
|
workflow,
|
|
1396
|
-
includeTextStreamParts =
|
|
1396
|
+
includeTextStreamParts = false
|
|
1397
1397
|
}) {
|
|
1398
1398
|
if (!workflow && !path.includes("/:workflowId")) {
|
|
1399
1399
|
throw new Error("Path must include :workflowId to route to the correct workflow or pass the workflow explicitly");
|
|
@@ -1424,7 +1424,7 @@ function workflowRoute({
|
|
|
1424
1424
|
resourceId: { type: "string" },
|
|
1425
1425
|
inputData: { type: "object", additionalProperties: true },
|
|
1426
1426
|
resumeData: { type: "object", additionalProperties: true },
|
|
1427
|
-
|
|
1427
|
+
runtimeContext: { type: "object", additionalProperties: true },
|
|
1428
1428
|
tracingOptions: { type: "object", additionalProperties: true },
|
|
1429
1429
|
step: { type: "string" }
|
|
1430
1430
|
}
|
|
@@ -1446,7 +1446,7 @@ function workflowRoute({
|
|
|
1446
1446
|
handler: async (c) => {
|
|
1447
1447
|
const { runId, resourceId, inputData, resumeData, ...rest } = await c.req.json();
|
|
1448
1448
|
const mastra = c.get("mastra");
|
|
1449
|
-
const
|
|
1449
|
+
const runtimeContext = c.get("runtimeContext");
|
|
1450
1450
|
let workflowToUse = workflow;
|
|
1451
1451
|
if (!workflow) {
|
|
1452
1452
|
const workflowId = c.req.param("workflowId");
|
|
@@ -1464,16 +1464,16 @@ function workflowRoute({
|
|
|
1464
1464
|
if (!workflowObj) {
|
|
1465
1465
|
throw new Error(`Workflow ${workflowToUse} not found`);
|
|
1466
1466
|
}
|
|
1467
|
-
if (
|
|
1467
|
+
if (runtimeContext && rest.runtimeContext) {
|
|
1468
1468
|
mastra.getLogger()?.warn(
|
|
1469
|
-
`"
|
|
1469
|
+
`"runtimeContext" from the request body will be ignored because "runtimeContext" is already set in the route options.`
|
|
1470
1470
|
);
|
|
1471
1471
|
}
|
|
1472
|
-
const run = await workflowObj.
|
|
1473
|
-
const stream = resumeData ? run.resumeStream({ resumeData, ...rest,
|
|
1472
|
+
const run = await workflowObj.createRunAsync({ runId, resourceId, ...rest });
|
|
1473
|
+
const stream = resumeData ? run.resumeStream({ resumeData, ...rest, runtimeContext: runtimeContext || rest.runtimeContext }) : run.stream({ inputData, ...rest, runtimeContext: runtimeContext || rest.runtimeContext });
|
|
1474
1474
|
const uiMessageStream = createUIMessageStream({
|
|
1475
1475
|
execute: async ({ writer }) => {
|
|
1476
|
-
for await (const part of
|
|
1476
|
+
for await (const part of toAISdkFormat(stream, { from: "workflow", includeTextStreamParts })) {
|
|
1477
1477
|
writer.write(part);
|
|
1478
1478
|
}
|
|
1479
1479
|
}
|
|
@@ -1513,12 +1513,13 @@ function networkRoute({
|
|
|
1513
1513
|
type: "object",
|
|
1514
1514
|
properties: {
|
|
1515
1515
|
messages: { type: "array", items: { type: "object" } },
|
|
1516
|
-
|
|
1516
|
+
runtimeContext: { type: "object", additionalProperties: true },
|
|
1517
1517
|
runId: { type: "string" },
|
|
1518
1518
|
maxSteps: { type: "number" },
|
|
1519
1519
|
threadId: { type: "string" },
|
|
1520
1520
|
resourceId: { type: "string" },
|
|
1521
1521
|
modelSettings: { type: "object", additionalProperties: true },
|
|
1522
|
+
telemetry: { type: "object", additionalProperties: true },
|
|
1522
1523
|
tools: { type: "array", items: { type: "object" } }
|
|
1523
1524
|
},
|
|
1524
1525
|
required: ["messages"]
|
|
@@ -1567,7 +1568,7 @@ function networkRoute({
|
|
|
1567
1568
|
});
|
|
1568
1569
|
const uiMessageStream = createUIMessageStream({
|
|
1569
1570
|
execute: async ({ writer }) => {
|
|
1570
|
-
for await (const part of
|
|
1571
|
+
for await (const part of toAISdkFormat(result, { from: "network" })) {
|
|
1571
1572
|
writer.write(part);
|
|
1572
1573
|
}
|
|
1573
1574
|
}
|
|
@@ -1577,13 +1578,6 @@ function networkRoute({
|
|
|
1577
1578
|
});
|
|
1578
1579
|
}
|
|
1579
1580
|
|
|
1580
|
-
|
|
1581
|
-
function toAISdkFormat() {
|
|
1582
|
-
throw new Error(
|
|
1583
|
-
'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.'
|
|
1584
|
-
);
|
|
1585
|
-
}
|
|
1586
|
-
|
|
1587
|
-
export { chatRoute, networkRoute, toAISdkFormat, toAISdkV5Stream as toAISdkStream, workflowRoute };
|
|
1581
|
+
export { chatRoute, networkRoute, toAISdkFormat, workflowRoute };
|
|
1588
1582
|
//# sourceMappingURL=index.js.map
|
|
1589
1583
|
//# sourceMappingURL=index.js.map
|