@mastra/ai-sdk 1.5.1-alpha.0 → 1.6.0-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 +42 -0
- package/dist/convert-snapshot.d.ts +25 -0
- package/dist/convert-snapshot.d.ts.map +1 -0
- package/dist/index.cjs +64 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +64 -1
- package/dist/index.js.map +1 -1
- package/dist/transformers.d.ts +17 -2
- package/dist/transformers.d.ts.map +1 -1
- package/package.json +9 -9
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,47 @@
|
|
|
1
1
|
# @mastra/ai-sdk
|
|
2
2
|
|
|
3
|
+
## 1.6.0-alpha.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- Added `workflowSnapshotToStream` utility to convert a `WorkflowState` (as returned by `getWorkflowRunById`) into an AI SDK-compatible stream. This lets you display historical workflow runs using the same `useChat`-powered UI components used for live workflow streams. ([#18453](https://github.com/mastra-ai/mastra/pull/18453))
|
|
8
|
+
|
|
9
|
+
**Example usage:**
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
import { workflowSnapshotToStream } from '@mastra/ai-sdk';
|
|
13
|
+
import { createUIMessageStreamResponse } from 'ai';
|
|
14
|
+
|
|
15
|
+
const workflowRun = await mastra.getWorkflow('myWorkflow').getWorkflowRunById(runId);
|
|
16
|
+
const stream = workflowSnapshotToStream(workflowRun);
|
|
17
|
+
return createUIMessageStreamResponse({ stream });
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
### Patch Changes
|
|
21
|
+
|
|
22
|
+
- Updated dependencies [[`bf3fe49`](https://github.com/mastra-ai/mastra/commit/bf3fe49f9467dbbdb8f9eaf74e0f7971ffb19559), [`24ceaea`](https://github.com/mastra-ai/mastra/commit/24ceaea0bdd8609cabbab764380608ca6621a194), [`6ccf67b`](https://github.com/mastra-ai/mastra/commit/6ccf67bf075753754927a57bc2e1734ba2c820c5), [`825d8de`](https://github.com/mastra-ai/mastra/commit/825d8def9fa64c2bcc3d8dd6b49e09342c3ac5c7), [`ffa09e7`](https://github.com/mastra-ai/mastra/commit/ffa09e772a5c92270eabe2090fc42d45bd8ec4b7), [`461a7c5`](https://github.com/mastra-ai/mastra/commit/461a7c501449295287f4f0ee4b0b42344f39fcf8), [`4211472`](https://github.com/mastra-ai/mastra/commit/4211472a5a2bd319c60cd2e42d9109c3eef7ac1c), [`9e45902`](https://github.com/mastra-ai/mastra/commit/9e4590208e745055cecca202e2db0e5c65e17d3c), [`5c0df77`](https://github.com/mastra-ai/mastra/commit/5c0df776c40efa420f8c07a2f3ee66010296618e)]:
|
|
23
|
+
- @mastra/core@1.47.0-alpha.3
|
|
24
|
+
|
|
25
|
+
## 1.5.1
|
|
26
|
+
|
|
27
|
+
### Patch Changes
|
|
28
|
+
|
|
29
|
+
- `workflowRoute` now uses `MASTRA_RESOURCE_ID_KEY` from `requestContext` (set by server middleware) as the `resourceId` when creating a workflow run, falling back to the client-supplied value. This matches the precedence contract already enforced in agent calls. ([#18315](https://github.com/mastra-ai/mastra/pull/18315))
|
|
30
|
+
|
|
31
|
+
- Security: error responses from `chatRoute` and `handleChatStream` no longer leak the agent's system prompt back to the client when an upstream LLM call fails. The default error serializer now strips sensitive payload fields before they reach the response stream. ([#18335](https://github.com/mastra-ai/mastra/pull/18335))
|
|
32
|
+
|
|
33
|
+
`chatRoute` also accepts an optional `onError` for callers that want richer diagnostics on a trusted surface:
|
|
34
|
+
|
|
35
|
+
```ts
|
|
36
|
+
chatRoute({
|
|
37
|
+
agent: 'support-agent',
|
|
38
|
+
onError: error => JSON.stringify(error), // full payload — only safe on trusted surfaces
|
|
39
|
+
});
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
- Updated dependencies [[`5bd72d2`](https://github.com/mastra-ai/mastra/commit/5bd72d255f45b5ea8ab342643bd463814a980a24), [`1cc9ee1`](https://github.com/mastra-ai/mastra/commit/1cc9ee1ba51db53020a735626d33017a60b4b5b3), [`417baae`](https://github.com/mastra-ai/mastra/commit/417baae40b995db5819c845036947f0c27dc1c00), [`65f255a`](https://github.com/mastra-ai/mastra/commit/65f255a38667beb6ceeadabfa9eb5059bfec8298), [`74955f9`](https://github.com/mastra-ai/mastra/commit/74955f9120cde8b1d8ce4399232b4033236be858), [`30ebaf0`](https://github.com/mastra-ai/mastra/commit/30ebaf07bed5f4d30f2f257836c15d1bf7e40aae), [`5704634`](https://github.com/mastra-ai/mastra/commit/5704634b22133167dea337a942a34f57aaa3fa14), [`5c4e9a4`](https://github.com/mastra-ai/mastra/commit/5c4e9a4cfb2216bb3ea7f8988ad3727f3b92bb3a), [`4a88c6e`](https://github.com/mastra-ai/mastra/commit/4a88c6e2bdce316f8d7551b4ec3449b0b06fc71c), [`417baae`](https://github.com/mastra-ai/mastra/commit/417baae40b995db5819c845036947f0c27dc1c00), [`74955f9`](https://github.com/mastra-ai/mastra/commit/74955f9120cde8b1d8ce4399232b4033236be858), [`74955f9`](https://github.com/mastra-ai/mastra/commit/74955f9120cde8b1d8ce4399232b4033236be858), [`25961e3`](https://github.com/mastra-ai/mastra/commit/25961e3260ff3b1464637af8fcdb36210551c39f), [`6a1428a`](https://github.com/mastra-ai/mastra/commit/6a1428a23133fc070fc6c1caa08d28f3ba4fe5ff), [`87a17ef`](https://github.com/mastra-ai/mastra/commit/87a17efbd725aca6639febdc5e69e2abb3048689), [`e11ff30`](https://github.com/mastra-ai/mastra/commit/e11ff301408bf1731dca2fb7fbfcd8c819500a35), [`7794d71`](https://github.com/mastra-ai/mastra/commit/7794d71872c68733a30e028dfb7b1705daf6c5d2), [`9d2c946`](https://github.com/mastra-ai/mastra/commit/9d2c946d0859e90ae4bcec5beeb1da7398d2ad1e), [`c0eda2b`](https://github.com/mastra-ai/mastra/commit/c0eda2bcd91a228427314b12c91d8b147f3a739f), [`7b29f33`](https://github.com/mastra-ai/mastra/commit/7b29f332a357a83e555f29e718e5f2fab9979943), [`c0eda2b`](https://github.com/mastra-ai/mastra/commit/c0eda2bcd91a228427314b12c91d8b147f3a739f), [`b13925b`](https://github.com/mastra-ai/mastra/commit/b13925bfa91aa8700f56fa54a9ce707ee7e4ba62), [`f1ec385`](https://github.com/mastra-ai/mastra/commit/f1ec385386f62b1a0847ec5353ae2bb169d1c3d9), [`e14986f`](https://github.com/mastra-ai/mastra/commit/e14986f6e5478d6384d04ff9a7f9a79a46a8b529), [`24912b1`](https://github.com/mastra-ai/mastra/commit/24912b1f855d29ec36af4ef4bde1f7417e20cdf5), [`bf94ec6`](https://github.com/mastra-ai/mastra/commit/bf94ec68192d9f16e46ef7e5ac36370aeeddf35d), [`a29f371`](https://github.com/mastra-ai/mastra/commit/a29f371aef629ac8562661524a497127e93b5131), [`7686216`](https://github.com/mastra-ai/mastra/commit/7686216f37e74568feddec17cef3c3d24e10e60a), [`74955f9`](https://github.com/mastra-ai/mastra/commit/74955f9120cde8b1d8ce4399232b4033236be858), [`073f910`](https://github.com/mastra-ai/mastra/commit/073f910481e7d94b95ba3830f96531774ae95d33), [`0be490f`](https://github.com/mastra-ai/mastra/commit/0be490fabb538c5a7de796ea0aff7d04a0bea1f3), [`0be490f`](https://github.com/mastra-ai/mastra/commit/0be490fabb538c5a7de796ea0aff7d04a0bea1f3), [`ebbe1d3`](https://github.com/mastra-ai/mastra/commit/ebbe1d31a965a3adb0e728758f326b8122b4b55f), [`974f614`](https://github.com/mastra-ai/mastra/commit/974f614e083bd68278536f94453f7b320b86a3c7), [`3818814`](https://github.com/mastra-ai/mastra/commit/38188149ce454c4403fe9fcbdf73b735c68d36be), [`975c59a`](https://github.com/mastra-ai/mastra/commit/975c59ae363ee275fc55062392e1ffd2cbccbd53), [`1f97ce5`](https://github.com/mastra-ai/mastra/commit/1f97ce5695463bebb4eaacf501da6fb403e20885), [`74955f9`](https://github.com/mastra-ai/mastra/commit/74955f9120cde8b1d8ce4399232b4033236be858), [`7f51548`](https://github.com/mastra-ai/mastra/commit/7f515481213780be7047cef00640b9d35f3d545c), [`64f58c0`](https://github.com/mastra-ai/mastra/commit/64f58c04e78b40137497d47f781e897e416f22a5), [`74955f9`](https://github.com/mastra-ai/mastra/commit/74955f9120cde8b1d8ce4399232b4033236be858), [`ebbe1d3`](https://github.com/mastra-ai/mastra/commit/ebbe1d31a965a3adb0e728758f326b8122b4b55f), [`d95f394`](https://github.com/mastra-ai/mastra/commit/d95f394fd24c8411886930d727679c4d5252aa26), [`417baae`](https://github.com/mastra-ai/mastra/commit/417baae40b995db5819c845036947f0c27dc1c00), [`8e25a78`](https://github.com/mastra-ai/mastra/commit/8e25a78e0597575f0b0729bae8c5e190c84869b5), [`417baae`](https://github.com/mastra-ai/mastra/commit/417baae40b995db5819c845036947f0c27dc1c00), [`f3f0c9d`](https://github.com/mastra-ai/mastra/commit/f3f0c9d7c878db5a13177871ce3523a14f14b311), [`a5b22d3`](https://github.com/mastra-ai/mastra/commit/a5b22d314d62a68d801886a8d3d0eb6c089473db), [`31be1cf`](https://github.com/mastra-ai/mastra/commit/31be1cf5f2a7b5eef12f6123a40653b4d8115c16), [`417baae`](https://github.com/mastra-ai/mastra/commit/417baae40b995db5819c845036947f0c27dc1c00), [`74955f9`](https://github.com/mastra-ai/mastra/commit/74955f9120cde8b1d8ce4399232b4033236be858), [`74955f9`](https://github.com/mastra-ai/mastra/commit/74955f9120cde8b1d8ce4399232b4033236be858)]:
|
|
43
|
+
- @mastra/core@1.46.0
|
|
44
|
+
|
|
3
45
|
## 1.5.1-alpha.0
|
|
4
46
|
|
|
5
47
|
### Patch Changes
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { WorkflowState } from '@mastra/core/workflows';
|
|
2
|
+
import type { WorkflowDataPart, WorkflowStepDataPart } from './transformers.js';
|
|
3
|
+
/**
|
|
4
|
+
* Converts a `WorkflowState` (as returned by `getWorkflowRunById` or the
|
|
5
|
+
* workflow runs API) into a `ReadableStream` of AI SDK UIMessage data parts —
|
|
6
|
+
* the same `WorkflowDataPart` and `WorkflowStepDataPart` chunks that the live
|
|
7
|
+
* workflow stream transformer produces. This lets you display historical
|
|
8
|
+
* workflow runs using the same `useChat`-powered components used for live runs.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* import { workflowSnapshotToStream } from '@mastra/ai-sdk';
|
|
13
|
+
* import { createUIMessageStreamResponse } from 'ai';
|
|
14
|
+
*
|
|
15
|
+
* const workflowRun = await mastra.getWorkflow('myWorkflow').getWorkflowRunById(runId);
|
|
16
|
+
* const stream = workflowSnapshotToStream(workflowRun);
|
|
17
|
+
* return createUIMessageStreamResponse({ stream });
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export declare function workflowSnapshotToStream(workflowRun: WorkflowState): ReadableStream<WorkflowDataPart | WorkflowStepDataPart | {
|
|
21
|
+
type: 'start';
|
|
22
|
+
} | {
|
|
23
|
+
type: 'finish';
|
|
24
|
+
}>;
|
|
25
|
+
//# sourceMappingURL=convert-snapshot.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"convert-snapshot.d.ts","sourceRoot":"","sources":["../src/convert-snapshot.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAA0D,MAAM,wBAAwB,CAAC;AACpH,OAAO,KAAK,EAAE,gBAAgB,EAAE,oBAAoB,EAAc,MAAM,gBAAgB,CAAC;AAGzF;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,wBAAwB,CACtC,WAAW,EAAE,aAAa,GACzB,cAAc,CAAC,gBAAgB,GAAG,oBAAoB,GAAG;IAAE,IAAI,EAAE,OAAO,CAAA;CAAE,GAAG;IAAE,IAAI,EAAE,QAAQ,CAAA;CAAE,CAAC,CAmClG"}
|
package/dist/index.cjs
CHANGED
|
@@ -14517,6 +14517,69 @@ function networkRoute({
|
|
|
14517
14517
|
}
|
|
14518
14518
|
});
|
|
14519
14519
|
}
|
|
14520
|
+
|
|
14521
|
+
// src/convert-snapshot.ts
|
|
14522
|
+
function workflowSnapshotToStream(workflowRun) {
|
|
14523
|
+
const steps = workflowStateToSteps(workflowRun.steps ?? {});
|
|
14524
|
+
const current = { name: workflowRun.workflowName, steps };
|
|
14525
|
+
const runId = workflowRun.runId;
|
|
14526
|
+
const status = workflowRun.status;
|
|
14527
|
+
return new ReadableStream({
|
|
14528
|
+
start(controller) {
|
|
14529
|
+
controller.enqueue({ type: "start" });
|
|
14530
|
+
controller.enqueue(
|
|
14531
|
+
createWorkflowDataPart({
|
|
14532
|
+
current,
|
|
14533
|
+
runId,
|
|
14534
|
+
status,
|
|
14535
|
+
includeOutputs: true,
|
|
14536
|
+
output: null
|
|
14537
|
+
})
|
|
14538
|
+
);
|
|
14539
|
+
for (const stepId of Object.keys(steps)) {
|
|
14540
|
+
controller.enqueue(
|
|
14541
|
+
createWorkflowStepDataPart({
|
|
14542
|
+
current,
|
|
14543
|
+
runId,
|
|
14544
|
+
status,
|
|
14545
|
+
stepId
|
|
14546
|
+
})
|
|
14547
|
+
);
|
|
14548
|
+
}
|
|
14549
|
+
controller.enqueue({ type: "finish" });
|
|
14550
|
+
controller.close();
|
|
14551
|
+
}
|
|
14552
|
+
});
|
|
14553
|
+
}
|
|
14554
|
+
function workflowStateToSteps(stateSteps) {
|
|
14555
|
+
const steps = {};
|
|
14556
|
+
for (const [key, value] of Object.entries(stateSteps)) {
|
|
14557
|
+
const stepResult = Array.isArray(value) ? mergeForEachStepResult(value) : value;
|
|
14558
|
+
if (!stepResult || typeof stepResult !== "object" || !("status" in stepResult)) continue;
|
|
14559
|
+
steps[key] = {
|
|
14560
|
+
name: key,
|
|
14561
|
+
status: stepResult.status,
|
|
14562
|
+
input: stepResult.payload ?? null,
|
|
14563
|
+
output: stepResult.output ?? null,
|
|
14564
|
+
suspendPayload: stepResult.suspendPayload ?? null,
|
|
14565
|
+
resumePayload: stepResult.resumePayload ?? null
|
|
14566
|
+
};
|
|
14567
|
+
}
|
|
14568
|
+
return steps;
|
|
14569
|
+
}
|
|
14570
|
+
function mergeForEachStepResult(results) {
|
|
14571
|
+
const stepResults = results.filter(
|
|
14572
|
+
(result) => !!result && typeof result === "object" && "status" in result
|
|
14573
|
+
);
|
|
14574
|
+
if (stepResults.length === 0) return void 0;
|
|
14575
|
+
const representative = stepResults.find((result) => result.status === "suspended") ?? stepResults.find((result) => result.status === "failed") ?? stepResults[0];
|
|
14576
|
+
if (!representative) return void 0;
|
|
14577
|
+
return {
|
|
14578
|
+
...representative,
|
|
14579
|
+
payload: stepResults.map((result) => result.payload),
|
|
14580
|
+
output: stepResults.map((result) => result.output)
|
|
14581
|
+
};
|
|
14582
|
+
}
|
|
14520
14583
|
function withMastra(model, options = {}) {
|
|
14521
14584
|
const { memory, inputProcessors = [], outputProcessors = [] } = options;
|
|
14522
14585
|
const allInputProcessors = [...inputProcessors];
|
|
@@ -15216,5 +15279,6 @@ exports.toAISdkStream = toAISdkStream;
|
|
|
15216
15279
|
exports.toAISdkV5Stream = toAISdkV5Stream;
|
|
15217
15280
|
exports.withMastra = withMastra;
|
|
15218
15281
|
exports.workflowRoute = workflowRoute;
|
|
15282
|
+
exports.workflowSnapshotToStream = workflowSnapshotToStream;
|
|
15219
15283
|
//# sourceMappingURL=index.cjs.map
|
|
15220
15284
|
//# sourceMappingURL=index.cjs.map
|