@mastra/ai-sdk 1.0.0-beta.12 → 1.0.0-beta.13
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 +63 -0
- package/dist/chat-route.d.ts +2 -0
- package/dist/chat-route.d.ts.map +1 -1
- package/dist/helpers.d.ts.map +1 -1
- package/dist/index.cjs +47 -20
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +48 -21
- package/dist/index.js.map +1 -1
- package/dist/middleware.d.ts.map +1 -1
- package/dist/transformers.d.ts +3 -1
- package/dist/transformers.d.ts.map +1 -1
- package/package.json +6 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,68 @@
|
|
|
1
1
|
# @mastra/ai-sdk
|
|
2
2
|
|
|
3
|
+
## 1.0.0-beta.13
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Add embedded documentation support for Mastra packages ([#11472](https://github.com/mastra-ai/mastra/pull/11472))
|
|
8
|
+
|
|
9
|
+
Mastra packages now include embedded documentation in the published npm package under `dist/docs/`. This enables coding agents and AI assistants to understand and use the framework by reading documentation directly from `node_modules`.
|
|
10
|
+
|
|
11
|
+
Each package includes:
|
|
12
|
+
- **SKILL.md** - Entry point explaining the package's purpose and capabilities
|
|
13
|
+
- **SOURCE_MAP.json** - Machine-readable index mapping exports to types and implementation files
|
|
14
|
+
- **Topic folders** - Conceptual documentation organized by feature area
|
|
15
|
+
|
|
16
|
+
Documentation is driven by the `packages` frontmatter field in MDX files, which maps docs to their corresponding packages. CI validation ensures all docs include this field.
|
|
17
|
+
|
|
18
|
+
- Fixed agent network not returning text response when routing agent handles requests without delegation. ([#11497](https://github.com/mastra-ai/mastra/pull/11497))
|
|
19
|
+
|
|
20
|
+
**What changed:**
|
|
21
|
+
- Agent networks now correctly stream text responses when the routing agent decides to handle a request itself instead of delegating to sub-agents, workflows, or tools
|
|
22
|
+
- Added fallback in transformers to ensure text is always returned even if core events are missing
|
|
23
|
+
|
|
24
|
+
**Why this matters:**
|
|
25
|
+
Previously, when using `toAISdkV5Stream` or `networkRoute()` outside of the Mastra Studio UI, no text content was returned when the routing agent handled requests directly. This fix ensures consistent behavior across all API routes.
|
|
26
|
+
|
|
27
|
+
Fixes #11219
|
|
28
|
+
|
|
29
|
+
- Refactor the MessageList class from ~4000 LOC monolith to ~850 LOC with focused, single-responsibility modules. This improves maintainability, testability, and makes the codebase easier to understand. ([#11658](https://github.com/mastra-ai/mastra/pull/11658))
|
|
30
|
+
- Extract message format adapters (AIV4Adapter, AIV5Adapter) for SDK conversions
|
|
31
|
+
- Extract TypeDetector for centralized message format identification
|
|
32
|
+
- Extract MessageStateManager for tracking message sources and persistence
|
|
33
|
+
- Extract MessageMerger for streaming message merge logic
|
|
34
|
+
- Extract StepContentExtractor for step content extraction
|
|
35
|
+
- Extract CacheKeyGenerator for message deduplication
|
|
36
|
+
- Consolidate provider compatibility utilities (Gemini, Anthropic, OpenAI)
|
|
37
|
+
|
|
38
|
+
```
|
|
39
|
+
message-list/
|
|
40
|
+
├── message-list.ts # Main class (~850 LOC, down from ~4000)
|
|
41
|
+
├── adapters/ # SDK format conversions
|
|
42
|
+
│ ├── AIV4Adapter.ts # MastraDBMessage <-> AI SDK V4
|
|
43
|
+
│ └── AIV5Adapter.ts # MastraDBMessage <-> AI SDK V5
|
|
44
|
+
├── cache/
|
|
45
|
+
│ └── CacheKeyGenerator.ts # Deduplication keys
|
|
46
|
+
├── conversion/
|
|
47
|
+
│ ├── input-converter.ts # Any format -> MastraDBMessage
|
|
48
|
+
│ ├── output-converter.ts # MastraDBMessage -> SDK formats
|
|
49
|
+
│ ├── step-content.ts # Step content extraction
|
|
50
|
+
│ └── to-prompt.ts # LLM prompt formatting
|
|
51
|
+
├── detection/
|
|
52
|
+
│ └── TypeDetector.ts # Format identification
|
|
53
|
+
├── merge/
|
|
54
|
+
│ └── MessageMerger.ts # Streaming merge logic
|
|
55
|
+
├── state/
|
|
56
|
+
│ └── MessageStateManager.ts # Source & persistence tracking
|
|
57
|
+
└── utils/
|
|
58
|
+
└── provider-compat.ts # Provider-specific fixes
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
- Fix autoresume not working fine in useChat ([#11486](https://github.com/mastra-ai/mastra/pull/11486))
|
|
62
|
+
|
|
63
|
+
- Updated dependencies [[`d2d3e22`](https://github.com/mastra-ai/mastra/commit/d2d3e22a419ee243f8812a84e3453dd44365ecb0), [`bc72b52`](https://github.com/mastra-ai/mastra/commit/bc72b529ee4478fe89ecd85a8be47ce0127b82a0), [`05b8bee`](https://github.com/mastra-ai/mastra/commit/05b8bee9e50e6c2a4a2bf210eca25ee212ca24fa), [`c042bd0`](https://github.com/mastra-ai/mastra/commit/c042bd0b743e0e86199d0cb83344ca7690e34a9c), [`940a2b2`](https://github.com/mastra-ai/mastra/commit/940a2b27480626ed7e74f55806dcd2181c1dd0c2), [`e0941c3`](https://github.com/mastra-ai/mastra/commit/e0941c3d7fc75695d5d258e7008fd5d6e650800c), [`0c0580a`](https://github.com/mastra-ai/mastra/commit/0c0580a42f697cd2a7d5973f25bfe7da9055038a), [`28f5f89`](https://github.com/mastra-ai/mastra/commit/28f5f89705f2409921e3c45178796c0e0d0bbb64), [`e601b27`](https://github.com/mastra-ai/mastra/commit/e601b272c70f3a5ecca610373aa6223012704892), [`3d3366f`](https://github.com/mastra-ai/mastra/commit/3d3366f31683e7137d126a3a57174a222c5801fb), [`5a4953f`](https://github.com/mastra-ai/mastra/commit/5a4953f7d25bb15ca31ed16038092a39cb3f98b3), [`eb9e522`](https://github.com/mastra-ai/mastra/commit/eb9e522ce3070a405e5b949b7bf5609ca51d7fe2), [`20e6f19`](https://github.com/mastra-ai/mastra/commit/20e6f1971d51d3ff6dd7accad8aaaae826d540ed), [`4f0b3c6`](https://github.com/mastra-ai/mastra/commit/4f0b3c66f196c06448487f680ccbb614d281e2f7), [`74c4f22`](https://github.com/mastra-ai/mastra/commit/74c4f22ed4c71e72598eacc346ba95cdbc00294f), [`81b6a8f`](https://github.com/mastra-ai/mastra/commit/81b6a8ff79f49a7549d15d66624ac1a0b8f5f971), [`e4d366a`](https://github.com/mastra-ai/mastra/commit/e4d366aeb500371dd4210d6aa8361a4c21d87034), [`a4f010b`](https://github.com/mastra-ai/mastra/commit/a4f010b22e4355a5fdee70a1fe0f6e4a692cc29e), [`73b0bb3`](https://github.com/mastra-ai/mastra/commit/73b0bb394dba7c9482eb467a97ab283dbc0ef4db), [`5627a8c`](https://github.com/mastra-ai/mastra/commit/5627a8c6dc11fe3711b3fa7a6ffd6eb34100a306), [`3ff45d1`](https://github.com/mastra-ai/mastra/commit/3ff45d10e0c80c5335a957ab563da72feb623520), [`251df45`](https://github.com/mastra-ai/mastra/commit/251df4531407dfa46d805feb40ff3fb49769f455), [`f894d14`](https://github.com/mastra-ai/mastra/commit/f894d148946629af7b1f452d65a9cf864cec3765), [`c2b9547`](https://github.com/mastra-ai/mastra/commit/c2b9547bf435f56339f23625a743b2147ab1c7a6), [`580b592`](https://github.com/mastra-ai/mastra/commit/580b5927afc82fe460dfdf9a38a902511b6b7e7f), [`58e3931`](https://github.com/mastra-ai/mastra/commit/58e3931af9baa5921688566210f00fb0c10479fa), [`08bb631`](https://github.com/mastra-ai/mastra/commit/08bb631ae2b14684b2678e3549d0b399a6f0561e), [`4fba91b`](https://github.com/mastra-ai/mastra/commit/4fba91bec7c95911dc28e369437596b152b04cd0), [`12b0cc4`](https://github.com/mastra-ai/mastra/commit/12b0cc4077d886b1a552637dedb70a7ade93528c)]:
|
|
64
|
+
- @mastra/core@1.0.0-beta.20
|
|
65
|
+
|
|
3
66
|
## 1.0.0-beta.12
|
|
4
67
|
|
|
5
68
|
### Patch Changes
|
package/dist/chat-route.d.ts
CHANGED
|
@@ -6,6 +6,8 @@ import type { InferUIMessageChunk, UIMessage } from 'ai';
|
|
|
6
6
|
export type ChatStreamHandlerParams<UI_MESSAGE extends UIMessage, OUTPUT extends OutputSchema = undefined> = AgentExecutionOptions<OUTPUT> & {
|
|
7
7
|
messages: UI_MESSAGE[];
|
|
8
8
|
resumeData?: Record<string, any>;
|
|
9
|
+
/** The trigger for the request - sent by AI SDK's useChat hook */
|
|
10
|
+
trigger?: 'submit-message' | 'regenerate-message';
|
|
9
11
|
};
|
|
10
12
|
export type ChatStreamHandlerOptions<UI_MESSAGE extends UIMessage, OUTPUT extends OutputSchema = undefined> = {
|
|
11
13
|
mastra: Mastra;
|
package/dist/chat-route.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chat-route.d.ts","sourceRoot":"","sources":["../src/chat-route.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAEhE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAElD,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAExD,OAAO,KAAK,EAAE,mBAAmB,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC;AAGzD,MAAM,MAAM,uBAAuB,CACjC,UAAU,SAAS,SAAS,EAC5B,MAAM,SAAS,YAAY,GAAG,SAAS,IACrC,qBAAqB,CAAC,MAAM,CAAC,GAAG;IAClC,QAAQ,EAAE,UAAU,EAAE,CAAC;IACvB,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"chat-route.d.ts","sourceRoot":"","sources":["../src/chat-route.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAEhE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAElD,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,q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,IAAI;IACtE,cAAc,CAAC,EAAE,qBAAqB,CAAC,MAAM,CAAC,CAAC;CAChD,GAAG,CACA;IACE,IAAI,EAAE,GAAG,MAAM,WAAW,MAAM,EAAE,CAAC;IACnC,KAAK,CAAC,EAAE,KAAK,CAAC;CACf,GACD;IACE,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;CACf,CACJ,GAAG;IACA,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB,CAAC;AAEJ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AACH,wBAAgB,SAAS,CAAC,MAAM,SAAS,YAAY,GAAG,SAAS,EAAE,EACjE,IAAuB,EACvB,KAAK,EACL,cAAc,EACd,SAAgB,EAChB,UAAiB,EACjB,aAAqB,EACrB,WAAmB,GACpB,EAAE,gBAAgB,CAAC,MAAM,CAAC,GAAG,UAAU,CAAC,OAAO,gBAAgB,CAAC,CAiKhE"}
|
package/dist/helpers.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,mBAAmB,EACnB,YAAY,EACZ,aAAa,EACb,SAAS,EACT,kBAAkB,EACnB,MAAM,qBAAqB,CAAC;AAE7B,OAAO,KAAK,EACV,mBAAmB,EAEnB,gBAAgB,EAChB,cAAc,EACd,OAAO,EACP,SAAS,EACT,YAAY,EACb,MAAM,IAAI,CAAC;AAGZ;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,kBAAkB,GAAG,YAAY,CAK5E;AAED,MAAM,MAAM,eAAe,CAAC,MAAM,SAAS,YAAY,GAAG,SAAS,IAC/D,cAAc,CAAC,OAAO,CAAC,GAC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,CAAC,EAAE,OAAO,CAAC;IACrB,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC5B,GAAG,mBAAmB,CAAC,UAAU,CAAC,GAAG,kBAAkB,GAAG,qBAAqB,GAAG,oBAAoB,GAAG,SAAS,CA6OlH"}
|
package/dist/index.cjs
CHANGED
|
@@ -239,7 +239,7 @@ function secureJsonParse(text2) {
|
|
|
239
239
|
Error.stackTraceLimit = stackTraceLimit;
|
|
240
240
|
}
|
|
241
241
|
}
|
|
242
|
-
var validatorSymbol = Symbol.for("vercel.ai.validator");
|
|
242
|
+
var validatorSymbol = /* @__PURE__ */ Symbol.for("vercel.ai.validator");
|
|
243
243
|
function validator(validate) {
|
|
244
244
|
return { [validatorSymbol]: true, validate };
|
|
245
245
|
}
|
|
@@ -322,7 +322,7 @@ var getRelativePath = (pathA, pathB) => {
|
|
|
322
322
|
}
|
|
323
323
|
return [(pathA.length - i).toString(), ...pathB.slice(i)].join("/");
|
|
324
324
|
};
|
|
325
|
-
var ignoreOverride = Symbol(
|
|
325
|
+
var ignoreOverride = /* @__PURE__ */ Symbol(
|
|
326
326
|
"Let zodToJsonSchema decide on which parser to use"
|
|
327
327
|
);
|
|
328
328
|
var defaultOptions = {
|
|
@@ -1442,7 +1442,7 @@ function zodSchema(zodSchema2, options) {
|
|
|
1442
1442
|
return zod3Schema(zodSchema2);
|
|
1443
1443
|
}
|
|
1444
1444
|
}
|
|
1445
|
-
var schemaSymbol = Symbol.for("vercel.ai.schema");
|
|
1445
|
+
var schemaSymbol = /* @__PURE__ */ Symbol.for("vercel.ai.schema");
|
|
1446
1446
|
function jsonSchema(jsonSchema2, {
|
|
1447
1447
|
validate
|
|
1448
1448
|
} = {}) {
|
|
@@ -2999,7 +2999,8 @@ function convertMastraChunkToAISDKv5({
|
|
|
2999
2999
|
runId: chunk.runId,
|
|
3000
3000
|
toolCallId: chunk.payload.toolCallId,
|
|
3001
3001
|
toolName: chunk.payload.toolName,
|
|
3002
|
-
args: chunk.payload.args
|
|
3002
|
+
args: chunk.payload.args,
|
|
3003
|
+
resumeSchema: chunk.payload.resumeSchema
|
|
3003
3004
|
}
|
|
3004
3005
|
};
|
|
3005
3006
|
case "tool-call-suspended":
|
|
@@ -3010,7 +3011,8 @@ function convertMastraChunkToAISDKv5({
|
|
|
3010
3011
|
runId: chunk.runId,
|
|
3011
3012
|
toolCallId: chunk.payload.toolCallId,
|
|
3012
3013
|
toolName: chunk.payload.toolName,
|
|
3013
|
-
suspendPayload: chunk.payload.suspendPayload
|
|
3014
|
+
suspendPayload: chunk.payload.suspendPayload,
|
|
3015
|
+
resumeSchema: chunk.payload.resumeSchema
|
|
3014
3016
|
}
|
|
3015
3017
|
};
|
|
3016
3018
|
case "tool-call-input-streaming-start":
|
|
@@ -3348,7 +3350,7 @@ function convertFullStreamChunkToUIMessageStream({
|
|
|
3348
3350
|
}
|
|
3349
3351
|
|
|
3350
3352
|
// src/transformers.ts
|
|
3351
|
-
var PRIMITIVE_CACHE_SYMBOL = Symbol("primitive-cache");
|
|
3353
|
+
var PRIMITIVE_CACHE_SYMBOL = /* @__PURE__ */ Symbol("primitive-cache");
|
|
3352
3354
|
function WorkflowStreamToAISDKTransformer({
|
|
3353
3355
|
includeTextStreamParts
|
|
3354
3356
|
} = {}) {
|
|
@@ -3385,7 +3387,15 @@ function AgentNetworkToAISDKTransformer() {
|
|
|
3385
3387
|
},
|
|
3386
3388
|
transform(chunk, controller) {
|
|
3387
3389
|
const transformed = transformNetwork(chunk, bufferedNetworks);
|
|
3388
|
-
if (transformed)
|
|
3390
|
+
if (transformed) {
|
|
3391
|
+
if (Array.isArray(transformed)) {
|
|
3392
|
+
for (const item of transformed) {
|
|
3393
|
+
controller.enqueue(item);
|
|
3394
|
+
}
|
|
3395
|
+
} else {
|
|
3396
|
+
controller.enqueue(transformed);
|
|
3397
|
+
}
|
|
3398
|
+
}
|
|
3389
3399
|
}
|
|
3390
3400
|
});
|
|
3391
3401
|
}
|
|
@@ -3730,7 +3740,8 @@ function transformNetwork(payload, bufferedNetworks, isNested) {
|
|
|
3730
3740
|
name: payload.payload.networkId,
|
|
3731
3741
|
steps: [],
|
|
3732
3742
|
usage: null,
|
|
3733
|
-
output: null
|
|
3743
|
+
output: null,
|
|
3744
|
+
hasEmittedText: false
|
|
3734
3745
|
});
|
|
3735
3746
|
}
|
|
3736
3747
|
const current = bufferedNetworks.get(payload.runId);
|
|
@@ -3765,6 +3776,7 @@ function transformNetwork(payload, bufferedNetworks, isNested) {
|
|
|
3765
3776
|
case "routing-agent-text-start": {
|
|
3766
3777
|
const current = bufferedNetworks.get(payload.runId);
|
|
3767
3778
|
if (!current) return null;
|
|
3779
|
+
current.hasEmittedText = true;
|
|
3768
3780
|
return {
|
|
3769
3781
|
type: "text-start",
|
|
3770
3782
|
id: payload.runId
|
|
@@ -3773,6 +3785,7 @@ function transformNetwork(payload, bufferedNetworks, isNested) {
|
|
|
3773
3785
|
case "routing-agent-text-delta": {
|
|
3774
3786
|
const current = bufferedNetworks.get(payload.runId);
|
|
3775
3787
|
if (!current) return null;
|
|
3788
|
+
current.hasEmittedText = true;
|
|
3776
3789
|
return {
|
|
3777
3790
|
type: "text-delta",
|
|
3778
3791
|
id: payload.runId,
|
|
@@ -3947,15 +3960,25 @@ function transformNetwork(payload, bufferedNetworks, isNested) {
|
|
|
3947
3960
|
case "network-execution-event-step-finish": {
|
|
3948
3961
|
const current = bufferedNetworks.get(payload.runId);
|
|
3949
3962
|
if (!current) return null;
|
|
3950
|
-
|
|
3963
|
+
const resultText = payload.payload?.result;
|
|
3964
|
+
const dataNetworkChunk = {
|
|
3951
3965
|
type: isNested ? "data-tool-network" : "data-network",
|
|
3952
3966
|
id: payload.runId,
|
|
3953
3967
|
data: {
|
|
3954
3968
|
...current,
|
|
3955
3969
|
status: "finished",
|
|
3956
|
-
output:
|
|
3970
|
+
output: resultText ?? current.output
|
|
3957
3971
|
}
|
|
3958
3972
|
};
|
|
3973
|
+
if (!current.hasEmittedText && resultText && typeof resultText === "string" && resultText.length > 0) {
|
|
3974
|
+
current.hasEmittedText = true;
|
|
3975
|
+
return [
|
|
3976
|
+
{ type: "text-start", id: payload.runId },
|
|
3977
|
+
{ type: "text-delta", id: payload.runId, delta: resultText },
|
|
3978
|
+
dataNetworkChunk
|
|
3979
|
+
];
|
|
3980
|
+
}
|
|
3981
|
+
return dataNetworkChunk;
|
|
3959
3982
|
}
|
|
3960
3983
|
case "network-execution-event-finish": {
|
|
3961
3984
|
const current = bufferedNetworks.get(payload.runId);
|
|
@@ -4099,7 +4122,7 @@ async function handleChatStream({
|
|
|
4099
4122
|
sendReasoning = false,
|
|
4100
4123
|
sendSources = false
|
|
4101
4124
|
}) {
|
|
4102
|
-
const { messages, resumeData, runId, requestContext, ...rest } = params;
|
|
4125
|
+
const { messages, resumeData, runId, requestContext, trigger, ...rest } = params;
|
|
4103
4126
|
if (resumeData && !runId) {
|
|
4104
4127
|
throw new Error("runId is required when resumeData is provided");
|
|
4105
4128
|
}
|
|
@@ -4110,20 +4133,24 @@ async function handleChatStream({
|
|
|
4110
4133
|
if (!Array.isArray(messages)) {
|
|
4111
4134
|
throw new Error("Messages must be an array of UIMessage objects");
|
|
4112
4135
|
}
|
|
4113
|
-
const mergedOptions = {
|
|
4114
|
-
...defaultOptions2,
|
|
4115
|
-
...rest,
|
|
4116
|
-
...runId && { runId },
|
|
4117
|
-
requestContext: requestContext || defaultOptions2?.requestContext
|
|
4118
|
-
};
|
|
4119
|
-
const result = resumeData ? await agentObj.resumeStream(resumeData, mergedOptions) : await agentObj.stream(messages, mergedOptions);
|
|
4120
4136
|
let lastMessageId;
|
|
4121
|
-
|
|
4137
|
+
let messagesToSend = messages;
|
|
4138
|
+
if (messages.length > 0) {
|
|
4122
4139
|
const lastMessage = messages[messages.length - 1];
|
|
4123
4140
|
if (lastMessage?.role === "assistant") {
|
|
4124
4141
|
lastMessageId = lastMessage.id;
|
|
4142
|
+
if (trigger === "regenerate-message") {
|
|
4143
|
+
messagesToSend = messages.slice(0, -1);
|
|
4144
|
+
}
|
|
4125
4145
|
}
|
|
4126
4146
|
}
|
|
4147
|
+
const mergedOptions = {
|
|
4148
|
+
...defaultOptions2,
|
|
4149
|
+
...rest,
|
|
4150
|
+
...runId && { runId },
|
|
4151
|
+
requestContext: requestContext || defaultOptions2?.requestContext
|
|
4152
|
+
};
|
|
4153
|
+
const result = resumeData ? await agentObj.resumeStream(resumeData, mergedOptions) : await agentObj.stream(messagesToSend, mergedOptions);
|
|
4127
4154
|
return createUIMessageStream({
|
|
4128
4155
|
originalMessages: messages,
|
|
4129
4156
|
execute: async ({ writer }) => {
|
|
@@ -4630,7 +4657,7 @@ function createProcessorMiddleware(options) {
|
|
|
4630
4657
|
}
|
|
4631
4658
|
}
|
|
4632
4659
|
}
|
|
4633
|
-
const newPrompt = messageList.get.all.aiV5.prompt().map(agent.
|
|
4660
|
+
const newPrompt = messageList.get.all.aiV5.prompt().map(agent.aiV5ModelMessageToV2PromptMessage);
|
|
4634
4661
|
return {
|
|
4635
4662
|
...params,
|
|
4636
4663
|
prompt: newPrompt
|