@mastra/ai-sdk 1.0.0-beta.0 → 1.0.0-beta.2

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 CHANGED
@@ -1,5 +1,39 @@
1
1
  # @mastra/ai-sdk
2
2
 
3
+ ## 1.0.0-beta.2
4
+
5
+ ### Major Changes
6
+
7
+ - 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))
8
+
9
+ BREAKING CHANGE: AgentStreamToAISDKTransformer now accepts an options object instead of a single lastMessageId parameter
10
+
11
+ Also, add sendStart, sendFinish, sendReasoning, and sendSources parameters to
12
+ chatRoute function, enabling fine-grained control over which chunks are
13
+ included in the AI SDK stream output.
14
+
15
+ ### Patch Changes
16
+
17
+ - Extend the workflow route to accept optional runId and resourceId ([#10034](https://github.com/mastra-ai/mastra/pull/10034))
18
+ parameters, allowing clients to specify custom identifiers when
19
+ creating workflow runs. These parameters are now properly validated
20
+ in the OpenAPI schema and passed through to the createRun method.
21
+
22
+ Also updates the OpenAPI schema to include previously undocumented
23
+ resumeData and step fields.
24
+
25
+ - 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)]:
26
+ - @mastra/core@1.0.0-beta.3
27
+
28
+ ## 1.0.0-beta.1
29
+
30
+ ### Patch Changes
31
+
32
+ - Improve ai-sdk transformers, handle custom data from agent sub workflow, sug agent tools ([#9919](https://github.com/mastra-ai/mastra/pull/9919))
33
+
34
+ - Updated dependencies [[`465ac05`](https://github.com/mastra-ai/mastra/commit/465ac0526a91d175542091c675181f1a96c98c46)]:
35
+ - @mastra/core@1.0.0-beta.2
36
+
3
37
  ## 1.0.0-beta.0
4
38
 
5
39
  ### Major Changes
@@ -9,6 +9,56 @@ export type chatRouteOptions<OUTPUT extends OutputSchema = undefined> = {
9
9
  } | {
10
10
  path: string;
11
11
  agent: string;
12
- });
13
- export declare function chatRoute<OUTPUT extends OutputSchema = undefined>({ path, agent, defaultOptions, }: chatRouteOptions<OUTPUT>): ReturnType<typeof registerApiRoute>;
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
@@ -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,YAAY,GAAG,SAAS,IAAI;IACtE,cAAc,CAAC,EAAE,qBAAqB,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACzD,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,CAAC;AAEF,wBAAgB,SAAS,CAAC,MAAM,SAAS,YAAY,GAAG,SAAS,EAAE,EACjE,IAAuB,EACvB,KAAK,EACL,cAAc,GACf,EAAE,gBAAgB,CAAC,MAAM,CAAC,GAAG,UAAU,CAAC,OAAO,gBAAgB,CAAC,CA6JhE"}
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,YAAY,GAAG,SAAS,IAAI;IACtE,cAAc,CAAC,EAAE,qBAAqB,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACzD,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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4CG;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,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,qFAE3D;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,gBAAgB,wDAE3D"}
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":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AAM,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,CAqN1B;AAED,wBAAgB,uCAAuC,CAAC,UAAU,SAAS,SAAS,EAAE,EACpF,IAAI,EACJ,oBAAoB,EACpB,aAAa,EACb,WAAW,EACX,OAAO,EACP,SAAS,EACT,UAAU,EACV,iBAAiB,GAClB,EAAE;IAED,IAAI,EAAE,cAAc,CAAC,OAAO,CAAC,GAAG,aAAa,GAAG;QAAE,IAAI,EAAE,aAAa,CAAC;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
@@ -285,6 +285,14 @@ function convertFullStreamChunkToUIMessageStream({
285
285
  };
286
286
  }
287
287
  case "reasoning-delta": {
288
+ if (sendReasoning) {
289
+ return {
290
+ type: "reasoning-delta",
291
+ id: part.id,
292
+ delta: part.text,
293
+ ...part.providerMetadata != null ? { providerMetadata: part.providerMetadata } : {}
294
+ };
295
+ }
288
296
  return;
289
297
  }
290
298
  case "reasoning-end": {
@@ -302,6 +310,25 @@ function convertFullStreamChunkToUIMessageStream({
302
310
  };
303
311
  }
304
312
  case "source": {
313
+ if (sendSources && part.sourceType === "url") {
314
+ return {
315
+ type: "source-url",
316
+ sourceId: part.id,
317
+ url: part.url,
318
+ title: part.title,
319
+ ...part.providerMetadata != null ? { providerMetadata: part.providerMetadata } : {}
320
+ };
321
+ }
322
+ if (sendSources && part.sourceType === "document") {
323
+ return {
324
+ type: "source-document",
325
+ sourceId: part.id,
326
+ mediaType: part.mediaType,
327
+ title: part.title,
328
+ filename: part.filename,
329
+ ...part.providerMetadata != null ? { providerMetadata: part.providerMetadata } : {}
330
+ };
331
+ }
305
332
  return;
306
333
  }
307
334
  case "tool-input-start": {
@@ -359,6 +386,14 @@ function convertFullStreamChunkToUIMessageStream({
359
386
  toolCallId: part.toolCallId,
360
387
  payload: part.output
361
388
  };
389
+ } else if (isDataChunkType(part.output)) {
390
+ if (!("data" in part.output)) {
391
+ throw new Error(
392
+ `UI Messages require a data property when using data- prefixed chunks
393
+ ${JSON.stringify(part)}`
394
+ );
395
+ }
396
+ return part.output;
362
397
  }
363
398
  return;
364
399
  }
@@ -384,21 +419,23 @@ function convertFullStreamChunkToUIMessageStream({
384
419
  return { type: "finish-step" };
385
420
  }
386
421
  case "start": {
387
- {
422
+ if (sendStart) {
388
423
  return {
389
424
  type: "start",
390
425
  ...messageMetadataValue != null ? { messageMetadata: messageMetadataValue } : {},
391
426
  ...responseMessageId != null ? { messageId: responseMessageId } : {}
392
427
  };
393
428
  }
429
+ return;
394
430
  }
395
431
  case "finish": {
396
- {
432
+ if (sendFinish) {
397
433
  return {
398
434
  type: "finish",
399
435
  ...messageMetadataValue != null ? { messageMetadata: messageMetadataValue } : {}
400
436
  };
401
437
  }
438
+ return;
402
439
  }
403
440
  case "abort": {
404
441
  return part;
@@ -463,17 +500,23 @@ function AgentNetworkToAISDKTransformer() {
463
500
  }
464
501
  });
465
502
  }
466
- function AgentStreamToAISDKTransformer(lastMessageId) {
503
+ function AgentStreamToAISDKTransformer({
504
+ lastMessageId,
505
+ sendStart,
506
+ sendFinish,
507
+ sendReasoning,
508
+ sendSources
509
+ }) {
467
510
  let bufferedSteps = /* @__PURE__ */ new Map();
468
511
  return new TransformStream({
469
512
  transform(chunk, controller) {
470
513
  const part = convertMastraChunkToAISDKv5({ chunk, mode: "stream" });
471
514
  const transformedChunk = convertFullStreamChunkToUIMessageStream({
472
515
  part,
473
- sendReasoning: false,
474
- sendSources: false,
475
- sendStart: true,
476
- sendFinish: true,
516
+ sendReasoning,
517
+ sendSources,
518
+ sendStart,
519
+ sendFinish,
477
520
  responseMessageId: lastMessageId,
478
521
  onError(error) {
479
522
  return safeParseErrorObject(error);
@@ -982,7 +1025,11 @@ function transformNetwork(payload, bufferedNetworks, isNested) {
982
1025
  }
983
1026
 
984
1027
  // src/convert-streams.ts
985
- function toAISdkV5Stream(stream, options = { from: "agent" }) {
1028
+ function toAISdkV5Stream(stream, options = {
1029
+ from: "agent",
1030
+ sendStart: true,
1031
+ sendFinish: true
1032
+ }) {
986
1033
  const from = options?.from;
987
1034
  if (from === "workflow") {
988
1035
  return stream.pipeThrough(WorkflowStreamToAISDKTransformer());
@@ -991,14 +1038,26 @@ function toAISdkV5Stream(stream, options = { from: "agent" }) {
991
1038
  return stream.pipeThrough(AgentNetworkToAISDKTransformer());
992
1039
  }
993
1040
  const agentReadable = "fullStream" in stream ? stream.fullStream : stream;
994
- return agentReadable.pipeThrough(AgentStreamToAISDKTransformer(options?.lastMessageId));
1041
+ return agentReadable.pipeThrough(
1042
+ AgentStreamToAISDKTransformer({
1043
+ lastMessageId: options?.lastMessageId,
1044
+ sendStart: options?.sendStart,
1045
+ sendFinish: options?.sendFinish,
1046
+ sendReasoning: options?.sendReasoning,
1047
+ sendSources: options?.sendSources
1048
+ })
1049
+ );
995
1050
  }
996
1051
 
997
1052
  // src/chat-route.ts
998
1053
  function chatRoute({
999
1054
  path = "/chat/:agentId",
1000
1055
  agent,
1001
- defaultOptions
1056
+ defaultOptions,
1057
+ sendStart = true,
1058
+ sendFinish = true,
1059
+ sendReasoning = false,
1060
+ sendSources = false
1002
1061
  }) {
1003
1062
  if (!agent && !path.includes("/:agentId")) {
1004
1063
  throw new Error("Path must include :agentId to route to the correct agent or pass the agent explicitly");
@@ -1132,7 +1191,14 @@ function chatRoute({
1132
1191
  const uiMessageStream = ai.createUIMessageStream({
1133
1192
  originalMessages: messages,
1134
1193
  execute: async ({ writer }) => {
1135
- for await (const part of toAISdkV5Stream(result, { from: "agent", lastMessageId })) {
1194
+ for await (const part of toAISdkV5Stream(result, {
1195
+ from: "agent",
1196
+ lastMessageId,
1197
+ sendStart,
1198
+ sendFinish,
1199
+ sendReasoning,
1200
+ sendSources
1201
+ })) {
1136
1202
  writer.write(part);
1137
1203
  }
1138
1204
  }
@@ -1172,9 +1238,13 @@ function workflowRoute({
1172
1238
  schema: {
1173
1239
  type: "object",
1174
1240
  properties: {
1241
+ runId: { type: "string" },
1242
+ resourceId: { type: "string" },
1175
1243
  inputData: { type: "object", additionalProperties: true },
1244
+ resumeData: { type: "object", additionalProperties: true },
1176
1245
  requestContext: { type: "object", additionalProperties: true },
1177
- tracingOptions: { type: "object", additionalProperties: true }
1246
+ tracingOptions: { type: "object", additionalProperties: true },
1247
+ step: { type: "string" }
1178
1248
  }
1179
1249
  }
1180
1250
  }
@@ -1192,7 +1262,7 @@ function workflowRoute({
1192
1262
  }
1193
1263
  },
1194
1264
  handler: async (c) => {
1195
- const { inputData, resumeData, ...rest } = await c.req.json();
1265
+ const { runId, resourceId, inputData, resumeData, ...rest } = await c.req.json();
1196
1266
  const mastra = c.get("mastra");
1197
1267
  let workflowToUse = workflow;
1198
1268
  if (!workflow) {
@@ -1211,7 +1281,7 @@ function workflowRoute({
1211
1281
  if (!workflowObj) {
1212
1282
  throw new Error(`Workflow ${workflowToUse} not found`);
1213
1283
  }
1214
- const run = await workflowObj.createRun();
1284
+ const run = await workflowObj.createRun({ runId, resourceId, ...rest });
1215
1285
  const stream = resumeData ? run.resumeStream({ resumeData, ...rest }) : run.stream({ inputData, ...rest });
1216
1286
  const uiMessageStream = ai.createUIMessageStream({
1217
1287
  execute: async ({ writer }) => {