@mastra/ai-sdk 1.0.0-beta.1 → 1.0.0-beta.3
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 +54 -0
- package/dist/chat-route.d.ts +52 -2
- package/dist/chat-route.d.ts.map +1 -1
- package/dist/convert-messages.d.ts +1 -1
- package/dist/convert-messages.d.ts.map +1 -1
- package/dist/convert-streams.d.ts +48 -0
- package/dist/convert-streams.d.ts.map +1 -1
- package/dist/helpers.d.ts +1 -1
- package/dist/helpers.d.ts.map +1 -1
- package/dist/index.cjs +99 -14
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +99 -14
- package/dist/index.js.map +1 -1
- package/dist/transformers.d.ts +7 -1
- package/dist/transformers.d.ts.map +1 -1
- package/dist/workflow-route.d.ts.map +1 -1
- package/package.json +6 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,59 @@
|
|
|
1
1
|
# @mastra/ai-sdk
|
|
2
2
|
|
|
3
|
+
## 1.0.0-beta.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Added support for tripwire data chunks in streaming responses. ([#10269](https://github.com/mastra-ai/mastra/pull/10269))
|
|
8
|
+
|
|
9
|
+
Tripwire chunks allow the AI SDK to emit special data events when certain conditions are triggered during stream processing. These chunks include a `tripwireReason` field explaining why the tripwire was activated.
|
|
10
|
+
|
|
11
|
+
#### Usage
|
|
12
|
+
|
|
13
|
+
When converting Mastra chunks to AI SDK v5 format, tripwire chunks are now automatically handled:
|
|
14
|
+
|
|
15
|
+
```typescript
|
|
16
|
+
// Tripwire chunks are converted to data-tripwire format
|
|
17
|
+
const chunk = {
|
|
18
|
+
type: 'tripwire',
|
|
19
|
+
payload: { tripwireReason: 'Rate limit approaching' }
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
// Converts to:
|
|
23
|
+
{
|
|
24
|
+
type: 'data-tripwire',
|
|
25
|
+
data: { tripwireReason: 'Rate limit approaching' }
|
|
26
|
+
}
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
- Updated dependencies [[`352a5d6`](https://github.com/mastra-ai/mastra/commit/352a5d625cfe09849b21e8f52a24c9f0366759d5), [`a0a5b4b`](https://github.com/mastra-ai/mastra/commit/a0a5b4bbebe6c701ebbadf744873aa0d5ca01371), [`69ea758`](https://github.com/mastra-ai/mastra/commit/69ea758358edd7117f191c2e69c8bb5fc79e7a1a), [`993ad98`](https://github.com/mastra-ai/mastra/commit/993ad98d7ad3bebda9ecef5fec5c94349a0d04bc), [`3ff2c17`](https://github.com/mastra-ai/mastra/commit/3ff2c17a58e312fad5ea37377262c12d92ca0908)]:
|
|
30
|
+
- @mastra/core@1.0.0-beta.4
|
|
31
|
+
|
|
32
|
+
## 1.0.0-beta.2
|
|
33
|
+
|
|
34
|
+
### Major Changes
|
|
35
|
+
|
|
36
|
+
- Add sendStart, sendFinish, sendReasoning, and sendSources options to toAISdkV5Stream function, allowing fine-grained control over which message chunks are included in the converted stream. Previously, these values were hardcoded in the transformer. ([#10127](https://github.com/mastra-ai/mastra/pull/10127))
|
|
37
|
+
|
|
38
|
+
BREAKING CHANGE: AgentStreamToAISDKTransformer now accepts an options object instead of a single lastMessageId parameter
|
|
39
|
+
|
|
40
|
+
Also, add sendStart, sendFinish, sendReasoning, and sendSources parameters to
|
|
41
|
+
chatRoute function, enabling fine-grained control over which chunks are
|
|
42
|
+
included in the AI SDK stream output.
|
|
43
|
+
|
|
44
|
+
### Patch Changes
|
|
45
|
+
|
|
46
|
+
- Extend the workflow route to accept optional runId and resourceId ([#10034](https://github.com/mastra-ai/mastra/pull/10034))
|
|
47
|
+
parameters, allowing clients to specify custom identifiers when
|
|
48
|
+
creating workflow runs. These parameters are now properly validated
|
|
49
|
+
in the OpenAPI schema and passed through to the createRun method.
|
|
50
|
+
|
|
51
|
+
Also updates the OpenAPI schema to include previously undocumented
|
|
52
|
+
resumeData and step fields.
|
|
53
|
+
|
|
54
|
+
- Updated dependencies [[`2319326`](https://github.com/mastra-ai/mastra/commit/2319326f8c64e503a09bbcf14be2dd65405445e0), [`d629361`](https://github.com/mastra-ai/mastra/commit/d629361a60f6565b5bfb11976fdaf7308af858e2), [`08c31c1`](https://github.com/mastra-ai/mastra/commit/08c31c188ebccd598acaf55e888b6397d01f7eae), [`fd3d338`](https://github.com/mastra-ai/mastra/commit/fd3d338a2c362174ed5b383f1f011ad9fb0302aa), [`c30400a`](https://github.com/mastra-ai/mastra/commit/c30400a49b994b1b97256fe785eb6c906fc2b232), [`69e0a87`](https://github.com/mastra-ai/mastra/commit/69e0a878896a2da9494945d86e056a5f8f05b851), [`01f8878`](https://github.com/mastra-ai/mastra/commit/01f88783de25e4de048c1c8aace43e26373c6ea5), [`4c77209`](https://github.com/mastra-ai/mastra/commit/4c77209e6c11678808b365d545845918c40045c8), [`d827d08`](https://github.com/mastra-ai/mastra/commit/d827d0808ffe1f3553a84e975806cc989b9735dd), [`23c10a1`](https://github.com/mastra-ai/mastra/commit/23c10a1efdd9a693c405511ab2dc8a1236603162), [`676ccc7`](https://github.com/mastra-ai/mastra/commit/676ccc7fe92468d2d45d39c31a87825c89fd1ea0), [`c10398d`](https://github.com/mastra-ai/mastra/commit/c10398d5b88f1d4af556f4267ff06f1d11e89179), [`00c2387`](https://github.com/mastra-ai/mastra/commit/00c2387f5f04a365316f851e58666ac43f8c4edf), [`ad6250d`](https://github.com/mastra-ai/mastra/commit/ad6250dbdaad927e29f74a27b83f6c468b50a705), [`3a73998`](https://github.com/mastra-ai/mastra/commit/3a73998fa4ebeb7f3dc9301afe78095fc63e7999), [`e16d553`](https://github.com/mastra-ai/mastra/commit/e16d55338403c7553531cc568125c63d53653dff), [`4d59f58`](https://github.com/mastra-ai/mastra/commit/4d59f58de2d90d6e2810a19d4518e38ddddb9038), [`e1bb9c9`](https://github.com/mastra-ai/mastra/commit/e1bb9c94b4eb68b019ae275981be3feb769b5365), [`351a11f`](https://github.com/mastra-ai/mastra/commit/351a11fcaf2ed1008977fa9b9a489fc422e51cd4)]:
|
|
55
|
+
- @mastra/core@1.0.0-beta.3
|
|
56
|
+
|
|
3
57
|
## 1.0.0-beta.1
|
|
4
58
|
|
|
5
59
|
### Patch Changes
|
package/dist/chat-route.d.ts
CHANGED
|
@@ -9,6 +9,56 @@ export type chatRouteOptions<OUTPUT extends OutputSchema = undefined> = {
|
|
|
9
9
|
} | {
|
|
10
10
|
path: string;
|
|
11
11
|
agent: string;
|
|
12
|
-
})
|
|
13
|
-
|
|
12
|
+
}) & {
|
|
13
|
+
sendStart?: boolean;
|
|
14
|
+
sendFinish?: boolean;
|
|
15
|
+
sendReasoning?: boolean;
|
|
16
|
+
sendSources?: boolean;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Creates a chat route handler for streaming agent conversations using the AI SDK format.
|
|
20
|
+
*
|
|
21
|
+
* This function registers an HTTP POST endpoint that accepts messages, executes an agent,
|
|
22
|
+
* and streams the response back to the client in AI SDK v5 compatible format.
|
|
23
|
+
* *
|
|
24
|
+
* @param {chatRouteOptions} options - Configuration options for the chat route
|
|
25
|
+
* @param {string} [options.path='/chat/:agentId'] - The route path. Include `:agentId` for dynamic routing
|
|
26
|
+
* @param {string} [options.agent] - Fixed agent ID when not using dynamic routing
|
|
27
|
+
* @param {AgentExecutionOptions} [options.defaultOptions] - Default options passed to agent execution
|
|
28
|
+
* @param {boolean} [options.sendStart=true] - Whether to send start events in the stream
|
|
29
|
+
* @param {boolean} [options.sendFinish=true] - Whether to send finish events in the stream
|
|
30
|
+
* @param {boolean} [options.sendReasoning=false] - Whether to include reasoning steps in the stream
|
|
31
|
+
* @param {boolean} [options.sendSources=false] - Whether to include source citations in the stream
|
|
32
|
+
*
|
|
33
|
+
* @returns {ReturnType<typeof registerApiRoute>} A registered API route handler
|
|
34
|
+
*
|
|
35
|
+
* @throws {Error} When path doesn't include `:agentId` and no fixed agent is specified
|
|
36
|
+
* @throws {Error} When agent ID is missing at runtime
|
|
37
|
+
* @throws {Error} When specified agent is not found in Mastra instance
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* // Dynamic agent routing
|
|
41
|
+
* chatRoute({
|
|
42
|
+
* path: '/chat/:agentId',
|
|
43
|
+
* sendReasoning: true,
|
|
44
|
+
* });
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* // Fixed agent with custom path
|
|
48
|
+
* chatRoute({
|
|
49
|
+
* path: '/api/support-chat',
|
|
50
|
+
* agent: 'support-agent',
|
|
51
|
+
* defaultOptions: {
|
|
52
|
+
* maxSteps: 5,
|
|
53
|
+
* },
|
|
54
|
+
* });
|
|
55
|
+
*
|
|
56
|
+
* @remarks
|
|
57
|
+
* - The route handler expects a JSON body with a `messages` array
|
|
58
|
+
* - Messages should follow the format: `{ role: 'user' | 'assistant' | 'system', content: string }`
|
|
59
|
+
* - The response is a Server-Sent Events (SSE) stream compatible with AI SDK v5
|
|
60
|
+
* - If both `agent` and `:agentId` are present, a warning is logged and the fixed `agent` takes precedence
|
|
61
|
+
* - Request context from the incoming request overrides `defaultOptions.requestContext` if both are present
|
|
62
|
+
*/
|
|
63
|
+
export declare function chatRoute<OUTPUT extends OutputSchema = undefined>({ path, agent, defaultOptions, sendStart, sendFinish, sendReasoning, sendSources, }: chatRouteOptions<OUTPUT>): ReturnType<typeof registerApiRoute>;
|
|
14
64
|
//# sourceMappingURL=chat-route.d.ts.map
|
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,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAIxD,MAAM,MAAM,gBAAgB,CAAC,MAAM,SAAS,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GACpB,EAAE,gBAAgB,CAAC,MAAM,CAAC,GAAG,UAAU,CAAC,OAAO,gBAAgB,CAAC,CAoKhE"}
|
|
@@ -2,7 +2,7 @@ import type { MessageListInput } from '@mastra/core/agent/message-list';
|
|
|
2
2
|
/**
|
|
3
3
|
* Converts messages to AI SDK V5 UI format
|
|
4
4
|
*/
|
|
5
|
-
export declare function toAISdkV5Messages(messages: MessageListInput): import("ai").UIMessage<unknown, import("ai").UIDataTypes, import("ai").UITools>[];
|
|
5
|
+
export declare function toAISdkV5Messages(messages: MessageListInput): import("ai-v5").UIMessage<unknown, import("ai-v5").UIDataTypes, import("ai-v5").UITools>[];
|
|
6
6
|
/**
|
|
7
7
|
* Converts messages to AI SDK V4 UI format
|
|
8
8
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"convert-messages.d.ts","sourceRoot":"","sources":["../src/convert-messages.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AAExE;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,gBAAgB,
|
|
1
|
+
{"version":3,"file":"convert-messages.d.ts","sourceRoot":"","sources":["../src/convert-messages.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AAExE;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,gBAAgB,8FAE3D;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,gBAAgB,wDAE3D"}
|
|
@@ -2,6 +2,50 @@ import type { MastraModelOutput, OutputSchema, MastraAgentNetworkStream, Workflo
|
|
|
2
2
|
import type { MastraWorkflowStream, Step, WorkflowResult } from '@mastra/core/workflows';
|
|
3
3
|
import type { InferUIMessageChunk, UIMessage } from 'ai';
|
|
4
4
|
import type { ZodObject, ZodType } from 'zod';
|
|
5
|
+
/**
|
|
6
|
+
* Converts Mastra streams (workflow, agent network, or agent) to AI SDK v5 compatible streams.
|
|
7
|
+
*
|
|
8
|
+
* This function transforms various Mastra stream types into ReadableStream objects that are compatible
|
|
9
|
+
* with the AI SDK v5, enabling seamless integration with AI SDK's streaming capabilities.
|
|
10
|
+
*
|
|
11
|
+
*
|
|
12
|
+
* @param {MastraWorkflowStream | WorkflowRunOutput | MastraAgentNetworkStream | MastraModelOutput} stream
|
|
13
|
+
* The Mastra stream to convert. Can be one of:
|
|
14
|
+
* - MastraWorkflowStream: A workflow execution stream
|
|
15
|
+
* - WorkflowRunOutput: The output of a workflow run
|
|
16
|
+
* - MastraAgentNetworkStream: An agent network execution stream
|
|
17
|
+
* - MastraModelOutput: An agent model output stream
|
|
18
|
+
*
|
|
19
|
+
* @param {Object} options - Conversion options
|
|
20
|
+
* @param {'workflow' | 'network' | 'agent'} options.from - The type of stream being converted. Defaults to 'agent'
|
|
21
|
+
* @param {string} [options.lastMessageId] - (Agent only) The ID of the last message in the conversation
|
|
22
|
+
* @param {boolean} [options.sendStart=true] - (Agent only) Whether to send start events. Defaults to true
|
|
23
|
+
* @param {boolean} [options.sendFinish=true] - (Agent only) Whether to send finish events. Defaults to true
|
|
24
|
+
* @param {boolean} [options.sendReasoning] - (Agent only) Whether to include reasoning in the output
|
|
25
|
+
* @param {boolean} [options.sendSources] - (Agent only) Whether to include sources in the output
|
|
26
|
+
*
|
|
27
|
+
* @returns {ReadableStream<InferUIMessageChunk<UIMessage>>} A ReadableStream compatible with AI SDK v5
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* // Convert a workflow stream
|
|
31
|
+
* const workflowStream = await workflowRun.stream(...);
|
|
32
|
+
* const aiSDKStream = toAISdkV5Stream(workflowStream, { from: 'workflow' });
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* // Convert an agent network stream
|
|
36
|
+
* const networkStream = await agentNetwork.network(...);
|
|
37
|
+
* const aiSDKStream = toAISdkV5Stream(networkStream, { from: 'network' });
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* // Convert an agent stream with custom options
|
|
41
|
+
* const agentStream = await agent.stream(...);
|
|
42
|
+
* const aiSDKStream = toAISdkV5Stream(agentStream, {
|
|
43
|
+
* from: 'agent',
|
|
44
|
+
* lastMessageId: 'msg-123',
|
|
45
|
+
* sendReasoning: true,
|
|
46
|
+
* sendSources: true
|
|
47
|
+
* });
|
|
48
|
+
*/
|
|
5
49
|
export declare function toAISdkV5Stream<TOutput extends ZodType<any>, TInput extends ZodType<any>, TSteps extends Step<string, any, any, any, any, any>[], TState extends ZodObject<any>>(stream: MastraWorkflowStream<TState, TInput, TOutput, TSteps>, options: {
|
|
6
50
|
from: 'workflow';
|
|
7
51
|
}): ReadableStream<InferUIMessageChunk<UIMessage>>;
|
|
@@ -14,5 +58,9 @@ export declare function toAISdkV5Stream(stream: MastraAgentNetworkStream, option
|
|
|
14
58
|
export declare function toAISdkV5Stream<TOutput extends OutputSchema>(stream: MastraModelOutput<TOutput>, options: {
|
|
15
59
|
from: 'agent';
|
|
16
60
|
lastMessageId?: string;
|
|
61
|
+
sendStart?: boolean;
|
|
62
|
+
sendFinish?: boolean;
|
|
63
|
+
sendReasoning?: boolean;
|
|
64
|
+
sendSources?: boolean;
|
|
17
65
|
}): ReadableStream<InferUIMessageChunk<UIMessage>>;
|
|
18
66
|
//# sourceMappingURL=convert-streams.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"convert-streams.d.ts","sourceRoot":"","sources":["../src/convert-streams.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,iBAAiB,EAEjB,YAAY,EACZ,wBAAwB,EACxB,iBAAiB,EAClB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,KAAK,EAAE,oBAAoB,EAAE,IAAI,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACzF,OAAO,KAAK,EAAE,mBAAmB,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC;AACzD,OAAO,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c,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC,EAC1E,OAAO,EAAE;IAAE,IAAI,EAAE,UAAU,CAAA;CAAE,GAC5B,cAAc,CAAC,mBAAmB,CAAC,SAAS,CAAC,CAAC,CAAC;AAClD,wBAAgB,eAAe,CAC7B,MAAM,EAAE,wBAAwB,EAChC,OAAO,EAAE;IAAE,IAAI,EAAE,SAAS,CAAA;CAAE,GAC3B,cAAc,CAAC,mBAAmB,CAAC,SAAS,CAAC,CAAC,CAAC;AAClD,wBAAgB,eAAe,CAAC,OAAO,SAAS,YAAY,EAC1D,MAAM,EAAE,iBAAiB,CAAC,OAAO,CAAC,EAClC,OAAO,EAAE;IACP,IAAI,EAAE,OAAO,CAAC;IACd,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB,GACA,cAAc,CAAC,mBAAmB,CAAC,SAAS,CAAC,CAAC,CAAC"}
|
package/dist/helpers.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { PartialSchemaOutput, OutputSchema, DataChunkType, ChunkType } from '@mastra/core/stream';
|
|
2
2
|
import type { InferUIMessageChunk, ObjectStreamPart, TextStreamPart, ToolSet, UIMessage } from 'ai';
|
|
3
|
-
export type OutputChunkType<OUTPUT extends OutputSchema = undefined> = TextStreamPart<ToolSet> | ObjectStreamPart<PartialSchemaOutput<OUTPUT>> | undefined;
|
|
3
|
+
export type OutputChunkType<OUTPUT extends OutputSchema = undefined> = TextStreamPart<ToolSet> | ObjectStreamPart<PartialSchemaOutput<OUTPUT>> | DataChunkType | undefined;
|
|
4
4
|
export type ToolAgentChunkType = {
|
|
5
5
|
type: 'tool-agent';
|
|
6
6
|
toolCallId: string;
|
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,EAAE,mBAAmB,EAAE,YAAY,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAEvG,OAAO,KAAK,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,cAAc,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC;AAGpG,MAAM,MAAM,eAAe,CAAC,MAAM,SAAS,YAAY,GAAG,SAAS,IAC/D,cAAc,CAAC,OAAO,CAAC,GACvB,gBAAgB,CAAC,mBAAmB,CAAC,MAAM,CAAC,CAAC,GAC7C,SAAS,CAAC;AAEd,MAAM,MAAM,kBAAkB,GAAG;IAAE,IAAI,EAAE,YAAY,CAAC;IAAC,UAAU,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,GAAG,CAAA;CAAE,CAAC;AAC1F,MAAM,MAAM,qBAAqB,GAAG;IAAE,IAAI,EAAE,eAAe,CAAC;IAAC,UAAU,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,GAAG,CAAA;CAAE,CAAC;AAChG,MAAM,MAAM,oBAAoB,GAAG;IAAE,IAAI,EAAE,cAAc,CAAC;IAAC,UAAU,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,GAAG,CAAA;CAAE,CAAC;AAE9F,wBAAgB,2BAA2B,CAAC,MAAM,SAAS,YAAY,GAAG,SAAS,EAAE,EACnF,KAAK,EACL,IAAe,GAChB,EAAE;IACD,KAAK,EAAE,SAAS,CAAC,MAAM,CAAC,CAAC;IACzB,IAAI,CAAC,EAAE,UAAU,GAAG,QAAQ,CAAC;CAC9B,GAAG,eAAe,CAAC,MAAM,CAAC,
|
|
1
|
+
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,mBAAmB,EAAE,YAAY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QAAC,UAAU,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,GAAG,CAAA;KAAE,CAAC;IACzG,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,OAAO,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,MAAM,CAAC;IACpC,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC5B,GAAG,mBAAmB,CAAC,UAAU,CAAC,GAAG,kBAAkB,GAAG,qBAAqB,GAAG,oBAAoB,GAAG,SAAS,CAwOlH"}
|
package/dist/index.cjs
CHANGED
|
@@ -230,6 +230,13 @@ function convertMastraChunkToAISDKv5({
|
|
|
230
230
|
type: "object",
|
|
231
231
|
object: chunk.object
|
|
232
232
|
};
|
|
233
|
+
case "tripwire":
|
|
234
|
+
return {
|
|
235
|
+
type: "data-tripwire",
|
|
236
|
+
data: {
|
|
237
|
+
tripwireReason: chunk.payload.tripwireReason
|
|
238
|
+
}
|
|
239
|
+
};
|
|
233
240
|
default:
|
|
234
241
|
if (chunk.type && "payload" in chunk && chunk.payload) {
|
|
235
242
|
return {
|
|
@@ -285,6 +292,14 @@ function convertFullStreamChunkToUIMessageStream({
|
|
|
285
292
|
};
|
|
286
293
|
}
|
|
287
294
|
case "reasoning-delta": {
|
|
295
|
+
if (sendReasoning) {
|
|
296
|
+
return {
|
|
297
|
+
type: "reasoning-delta",
|
|
298
|
+
id: part.id,
|
|
299
|
+
delta: part.text,
|
|
300
|
+
...part.providerMetadata != null ? { providerMetadata: part.providerMetadata } : {}
|
|
301
|
+
};
|
|
302
|
+
}
|
|
288
303
|
return;
|
|
289
304
|
}
|
|
290
305
|
case "reasoning-end": {
|
|
@@ -302,6 +317,25 @@ function convertFullStreamChunkToUIMessageStream({
|
|
|
302
317
|
};
|
|
303
318
|
}
|
|
304
319
|
case "source": {
|
|
320
|
+
if (sendSources && part.sourceType === "url") {
|
|
321
|
+
return {
|
|
322
|
+
type: "source-url",
|
|
323
|
+
sourceId: part.id,
|
|
324
|
+
url: part.url,
|
|
325
|
+
title: part.title,
|
|
326
|
+
...part.providerMetadata != null ? { providerMetadata: part.providerMetadata } : {}
|
|
327
|
+
};
|
|
328
|
+
}
|
|
329
|
+
if (sendSources && part.sourceType === "document") {
|
|
330
|
+
return {
|
|
331
|
+
type: "source-document",
|
|
332
|
+
sourceId: part.id,
|
|
333
|
+
mediaType: part.mediaType,
|
|
334
|
+
title: part.title,
|
|
335
|
+
filename: part.filename,
|
|
336
|
+
...part.providerMetadata != null ? { providerMetadata: part.providerMetadata } : {}
|
|
337
|
+
};
|
|
338
|
+
}
|
|
305
339
|
return;
|
|
306
340
|
}
|
|
307
341
|
case "tool-input-start": {
|
|
@@ -392,21 +426,23 @@ function convertFullStreamChunkToUIMessageStream({
|
|
|
392
426
|
return { type: "finish-step" };
|
|
393
427
|
}
|
|
394
428
|
case "start": {
|
|
395
|
-
{
|
|
429
|
+
if (sendStart) {
|
|
396
430
|
return {
|
|
397
431
|
type: "start",
|
|
398
432
|
...messageMetadataValue != null ? { messageMetadata: messageMetadataValue } : {},
|
|
399
433
|
...responseMessageId != null ? { messageId: responseMessageId } : {}
|
|
400
434
|
};
|
|
401
435
|
}
|
|
436
|
+
return;
|
|
402
437
|
}
|
|
403
438
|
case "finish": {
|
|
404
|
-
{
|
|
439
|
+
if (sendFinish) {
|
|
405
440
|
return {
|
|
406
441
|
type: "finish",
|
|
407
442
|
...messageMetadataValue != null ? { messageMetadata: messageMetadataValue } : {}
|
|
408
443
|
};
|
|
409
444
|
}
|
|
445
|
+
return;
|
|
410
446
|
}
|
|
411
447
|
case "abort": {
|
|
412
448
|
return part;
|
|
@@ -471,17 +507,31 @@ function AgentNetworkToAISDKTransformer() {
|
|
|
471
507
|
}
|
|
472
508
|
});
|
|
473
509
|
}
|
|
474
|
-
function AgentStreamToAISDKTransformer(
|
|
510
|
+
function AgentStreamToAISDKTransformer({
|
|
511
|
+
lastMessageId,
|
|
512
|
+
sendStart,
|
|
513
|
+
sendFinish,
|
|
514
|
+
sendReasoning,
|
|
515
|
+
sendSources
|
|
516
|
+
}) {
|
|
475
517
|
let bufferedSteps = /* @__PURE__ */ new Map();
|
|
518
|
+
let tripwireOccurred = false;
|
|
519
|
+
let finishEventSent = false;
|
|
476
520
|
return new TransformStream({
|
|
477
521
|
transform(chunk, controller) {
|
|
522
|
+
if (chunk.type === "tripwire") {
|
|
523
|
+
tripwireOccurred = true;
|
|
524
|
+
}
|
|
525
|
+
if (chunk.type === "finish") {
|
|
526
|
+
finishEventSent = true;
|
|
527
|
+
}
|
|
478
528
|
const part = convertMastraChunkToAISDKv5({ chunk, mode: "stream" });
|
|
479
529
|
const transformedChunk = convertFullStreamChunkToUIMessageStream({
|
|
480
530
|
part,
|
|
481
|
-
sendReasoning
|
|
482
|
-
sendSources
|
|
483
|
-
sendStart
|
|
484
|
-
sendFinish
|
|
531
|
+
sendReasoning,
|
|
532
|
+
sendSources,
|
|
533
|
+
sendStart,
|
|
534
|
+
sendFinish,
|
|
485
535
|
responseMessageId: lastMessageId,
|
|
486
536
|
onError(error) {
|
|
487
537
|
return safeParseErrorObject(error);
|
|
@@ -504,6 +554,14 @@ function AgentStreamToAISDKTransformer(lastMessageId) {
|
|
|
504
554
|
controller.enqueue(transformedChunk);
|
|
505
555
|
}
|
|
506
556
|
}
|
|
557
|
+
},
|
|
558
|
+
flush(controller) {
|
|
559
|
+
if (tripwireOccurred && !finishEventSent && sendFinish) {
|
|
560
|
+
controller.enqueue({
|
|
561
|
+
type: "finish",
|
|
562
|
+
finishReason: "other"
|
|
563
|
+
});
|
|
564
|
+
}
|
|
507
565
|
}
|
|
508
566
|
});
|
|
509
567
|
}
|
|
@@ -990,7 +1048,11 @@ function transformNetwork(payload, bufferedNetworks, isNested) {
|
|
|
990
1048
|
}
|
|
991
1049
|
|
|
992
1050
|
// src/convert-streams.ts
|
|
993
|
-
function toAISdkV5Stream(stream, options = {
|
|
1051
|
+
function toAISdkV5Stream(stream, options = {
|
|
1052
|
+
from: "agent",
|
|
1053
|
+
sendStart: true,
|
|
1054
|
+
sendFinish: true
|
|
1055
|
+
}) {
|
|
994
1056
|
const from = options?.from;
|
|
995
1057
|
if (from === "workflow") {
|
|
996
1058
|
return stream.pipeThrough(WorkflowStreamToAISDKTransformer());
|
|
@@ -999,14 +1061,26 @@ function toAISdkV5Stream(stream, options = { from: "agent" }) {
|
|
|
999
1061
|
return stream.pipeThrough(AgentNetworkToAISDKTransformer());
|
|
1000
1062
|
}
|
|
1001
1063
|
const agentReadable = "fullStream" in stream ? stream.fullStream : stream;
|
|
1002
|
-
return agentReadable.pipeThrough(
|
|
1064
|
+
return agentReadable.pipeThrough(
|
|
1065
|
+
AgentStreamToAISDKTransformer({
|
|
1066
|
+
lastMessageId: options?.lastMessageId,
|
|
1067
|
+
sendStart: options?.sendStart,
|
|
1068
|
+
sendFinish: options?.sendFinish,
|
|
1069
|
+
sendReasoning: options?.sendReasoning,
|
|
1070
|
+
sendSources: options?.sendSources
|
|
1071
|
+
})
|
|
1072
|
+
);
|
|
1003
1073
|
}
|
|
1004
1074
|
|
|
1005
1075
|
// src/chat-route.ts
|
|
1006
1076
|
function chatRoute({
|
|
1007
1077
|
path = "/chat/:agentId",
|
|
1008
1078
|
agent,
|
|
1009
|
-
defaultOptions
|
|
1079
|
+
defaultOptions,
|
|
1080
|
+
sendStart = true,
|
|
1081
|
+
sendFinish = true,
|
|
1082
|
+
sendReasoning = false,
|
|
1083
|
+
sendSources = false
|
|
1010
1084
|
}) {
|
|
1011
1085
|
if (!agent && !path.includes("/:agentId")) {
|
|
1012
1086
|
throw new Error("Path must include :agentId to route to the correct agent or pass the agent explicitly");
|
|
@@ -1140,7 +1214,14 @@ function chatRoute({
|
|
|
1140
1214
|
const uiMessageStream = ai.createUIMessageStream({
|
|
1141
1215
|
originalMessages: messages,
|
|
1142
1216
|
execute: async ({ writer }) => {
|
|
1143
|
-
for await (const part of toAISdkV5Stream(result, {
|
|
1217
|
+
for await (const part of toAISdkV5Stream(result, {
|
|
1218
|
+
from: "agent",
|
|
1219
|
+
lastMessageId,
|
|
1220
|
+
sendStart,
|
|
1221
|
+
sendFinish,
|
|
1222
|
+
sendReasoning,
|
|
1223
|
+
sendSources
|
|
1224
|
+
})) {
|
|
1144
1225
|
writer.write(part);
|
|
1145
1226
|
}
|
|
1146
1227
|
}
|
|
@@ -1180,9 +1261,13 @@ function workflowRoute({
|
|
|
1180
1261
|
schema: {
|
|
1181
1262
|
type: "object",
|
|
1182
1263
|
properties: {
|
|
1264
|
+
runId: { type: "string" },
|
|
1265
|
+
resourceId: { type: "string" },
|
|
1183
1266
|
inputData: { type: "object", additionalProperties: true },
|
|
1267
|
+
resumeData: { type: "object", additionalProperties: true },
|
|
1184
1268
|
requestContext: { type: "object", additionalProperties: true },
|
|
1185
|
-
tracingOptions: { type: "object", additionalProperties: true }
|
|
1269
|
+
tracingOptions: { type: "object", additionalProperties: true },
|
|
1270
|
+
step: { type: "string" }
|
|
1186
1271
|
}
|
|
1187
1272
|
}
|
|
1188
1273
|
}
|
|
@@ -1200,7 +1285,7 @@ function workflowRoute({
|
|
|
1200
1285
|
}
|
|
1201
1286
|
},
|
|
1202
1287
|
handler: async (c) => {
|
|
1203
|
-
const { inputData, resumeData, ...rest } = await c.req.json();
|
|
1288
|
+
const { runId, resourceId, inputData, resumeData, ...rest } = await c.req.json();
|
|
1204
1289
|
const mastra = c.get("mastra");
|
|
1205
1290
|
let workflowToUse = workflow;
|
|
1206
1291
|
if (!workflow) {
|
|
@@ -1219,7 +1304,7 @@ function workflowRoute({
|
|
|
1219
1304
|
if (!workflowObj) {
|
|
1220
1305
|
throw new Error(`Workflow ${workflowToUse} not found`);
|
|
1221
1306
|
}
|
|
1222
|
-
const run = await workflowObj.createRun();
|
|
1307
|
+
const run = await workflowObj.createRun({ runId, resourceId, ...rest });
|
|
1223
1308
|
const stream = resumeData ? run.resumeStream({ resumeData, ...rest }) : run.stream({ inputData, ...rest });
|
|
1224
1309
|
const uiMessageStream = ai.createUIMessageStream({
|
|
1225
1310
|
execute: async ({ writer }) => {
|