@mastra/ai-sdk 1.0.3 → 1.0.4

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,43 @@
1
1
  # @mastra/ai-sdk
2
2
 
3
+ ## 1.0.4
4
+
5
+ ### Patch Changes
6
+
7
+ - Fixed duplicate assistant messages appearing when using `addToolOutput` with `sendAutomaticallyWhen`. Previously, continuation flows (e.g. client-side tool results) generated a new assistant message instead of updating the existing one. Now the response correctly appends to the original assistant message, so `useChat` no longer shows two separate replies. ([#12745](https://github.com/mastra-ai/mastra/pull/12745))
8
+
9
+ - Fixed `toAISdkStream()` so it accepts `WorkflowRunOutput` from `run.stream()` and `run.resumeStream()` without TypeScript errors. This improves type inference for workflow streams. ([#12777](https://github.com/mastra-ai/mastra/pull/12777))
10
+
11
+ - Fixed missing `state` field in `data-tool-call-approval` and `data-tool-call-suspended` stream chunks. Frontend consumers can now use the `state` property on the data payload to identify the part's state consistently with other tool UI parts. ([#12893](https://github.com/mastra-ai/mastra/pull/12893))
12
+
13
+ - Added initialState support to handleWorkflowStream in @mastra/ai-sdk. Previously, the WorkflowStreamHandlerParams type was missing the initialState property, preventing users from initializing global workflow state when using handleWorkflowStream. ([#12894](https://github.com/mastra-ai/mastra/pull/12894))
14
+
15
+ - Fixed direct routing responses showing internal routing reasoning before the final answer. Users now see only the final response when no delegation is needed. Fixes #12545. ([#12786](https://github.com/mastra-ai/mastra/pull/12786))
16
+
17
+ - Added sendReasoning and sendSources support to handleWorkflowStream and workflowRoute. Reasoning and source chunks from agents running inside workflows are now forwarded to the client when these options are enabled, matching the existing behavior of handleChatStream. Closes #12571. ([#12746](https://github.com/mastra-ai/mastra/pull/12746))
18
+
19
+ - Updated dependencies [[`717ffab`](https://github.com/mastra-ai/mastra/commit/717ffab42cfd58ff723b5c19ada4939997773004), [`b31c922`](https://github.com/mastra-ai/mastra/commit/b31c922215b513791d98feaea1b98784aa00803a), [`e4b6dab`](https://github.com/mastra-ai/mastra/commit/e4b6dab171c5960e340b3ea3ea6da8d64d2b8672), [`5719fa8`](https://github.com/mastra-ai/mastra/commit/5719fa8880e86e8affe698ec4b3807c7e0e0a06f), [`83cda45`](https://github.com/mastra-ai/mastra/commit/83cda4523e588558466892bff8f80f631a36945a), [`11804ad`](https://github.com/mastra-ai/mastra/commit/11804adf1d6be46ebe216be40a43b39bb8b397d7), [`aa95f95`](https://github.com/mastra-ai/mastra/commit/aa95f958b186ae5c9f4219c88e268f5565c277a2), [`90f7894`](https://github.com/mastra-ai/mastra/commit/90f7894568dc9481f40a4d29672234fae23090bb), [`f5501ae`](https://github.com/mastra-ai/mastra/commit/f5501aedb0a11106c7db7e480d6eaf3971b7bda8), [`44573af`](https://github.com/mastra-ai/mastra/commit/44573afad0a4bc86f627d6cbc0207961cdcb3bc3), [`00e3861`](https://github.com/mastra-ai/mastra/commit/00e3861863fbfee78faeb1ebbdc7c0223aae13ff), [`8109aee`](https://github.com/mastra-ai/mastra/commit/8109aeeab758e16cd4255a6c36f044b70eefc6a6), [`7bfbc52`](https://github.com/mastra-ai/mastra/commit/7bfbc52a8604feb0fff2c0a082c13c0c2a3df1a2), [`1445994`](https://github.com/mastra-ai/mastra/commit/1445994aee19c9334a6a101cf7bd80ca7ed4d186), [`61f44a2`](https://github.com/mastra-ai/mastra/commit/61f44a26861c89e364f367ff40825bdb7f19df55), [`37145d2`](https://github.com/mastra-ai/mastra/commit/37145d25f99dc31f1a9105576e5452609843ce32), [`fdad759`](https://github.com/mastra-ai/mastra/commit/fdad75939ff008b27625f5ec0ce9c6915d99d9ec), [`e4569c5`](https://github.com/mastra-ai/mastra/commit/e4569c589e00c4061a686c9eb85afe1b7050b0a8), [`7309a85`](https://github.com/mastra-ai/mastra/commit/7309a85427281a8be23f4fb80ca52e18eaffd596), [`99424f6`](https://github.com/mastra-ai/mastra/commit/99424f6862ffb679c4ec6765501486034754a4c2), [`44eb452`](https://github.com/mastra-ai/mastra/commit/44eb4529b10603c279688318bebf3048543a1d61), [`6c40593`](https://github.com/mastra-ai/mastra/commit/6c40593d6d2b1b68b0c45d1a3a4c6ac5ecac3937), [`8c1135d`](https://github.com/mastra-ai/mastra/commit/8c1135dfb91b057283eae7ee11f9ec28753cc64f), [`dd39e54`](https://github.com/mastra-ai/mastra/commit/dd39e54ea34532c995b33bee6e0e808bf41a7341), [`b6fad9a`](https://github.com/mastra-ai/mastra/commit/b6fad9a602182b1cc0df47cd8c55004fa829ad61), [`4129c07`](https://github.com/mastra-ai/mastra/commit/4129c073349b5a66643fd8136ebfe9d7097cf793), [`5b930ab`](https://github.com/mastra-ai/mastra/commit/5b930aba1834d9898e8460a49d15106f31ac7c8d), [`4be93d0`](https://github.com/mastra-ai/mastra/commit/4be93d09d68e20aaf0ea3f210749422719618b5f), [`047635c`](https://github.com/mastra-ai/mastra/commit/047635ccd7861d726c62d135560c0022a5490aec), [`8c90ff4`](https://github.com/mastra-ai/mastra/commit/8c90ff4d3414e7f2a2d216ea91274644f7b29133), [`ed232d1`](https://github.com/mastra-ai/mastra/commit/ed232d1583f403925dc5ae45f7bee948cf2a182b), [`3891795`](https://github.com/mastra-ai/mastra/commit/38917953518eb4154a984ee36e6ededdcfe80f72), [`4f955b2`](https://github.com/mastra-ai/mastra/commit/4f955b20c7f66ed282ee1fd8709696fa64c4f19d), [`55a4c90`](https://github.com/mastra-ai/mastra/commit/55a4c9044ac7454349b9f6aeba0bbab5ee65d10f)]:
20
+ - @mastra/core@1.3.0
21
+
22
+ ## 1.0.4-alpha.0
23
+
24
+ ### Patch Changes
25
+
26
+ - Fixed duplicate assistant messages appearing when using `addToolOutput` with `sendAutomaticallyWhen`. Previously, continuation flows (e.g. client-side tool results) generated a new assistant message instead of updating the existing one. Now the response correctly appends to the original assistant message, so `useChat` no longer shows two separate replies. ([#12745](https://github.com/mastra-ai/mastra/pull/12745))
27
+
28
+ - Fixed `toAISdkStream()` so it accepts `WorkflowRunOutput` from `run.stream()` and `run.resumeStream()` without TypeScript errors. This improves type inference for workflow streams. ([#12777](https://github.com/mastra-ai/mastra/pull/12777))
29
+
30
+ - Fixed missing `state` field in `data-tool-call-approval` and `data-tool-call-suspended` stream chunks. Frontend consumers can now use the `state` property on the data payload to identify the part's state consistently with other tool UI parts. ([#12893](https://github.com/mastra-ai/mastra/pull/12893))
31
+
32
+ - Added initialState support to handleWorkflowStream in @mastra/ai-sdk. Previously, the WorkflowStreamHandlerParams type was missing the initialState property, preventing users from initializing global workflow state when using handleWorkflowStream. ([#12894](https://github.com/mastra-ai/mastra/pull/12894))
33
+
34
+ - Fixed direct routing responses showing internal routing reasoning before the final answer. Users now see only the final response when no delegation is needed. Fixes #12545. ([#12786](https://github.com/mastra-ai/mastra/pull/12786))
35
+
36
+ - Added sendReasoning and sendSources support to handleWorkflowStream and workflowRoute. Reasoning and source chunks from agents running inside workflows are now forwarded to the client when these options are enabled, matching the existing behavior of handleChatStream. Closes #12571. ([#12746](https://github.com/mastra-ai/mastra/pull/12746))
37
+
38
+ - Updated dependencies [[`717ffab`](https://github.com/mastra-ai/mastra/commit/717ffab42cfd58ff723b5c19ada4939997773004), [`e4b6dab`](https://github.com/mastra-ai/mastra/commit/e4b6dab171c5960e340b3ea3ea6da8d64d2b8672), [`5719fa8`](https://github.com/mastra-ai/mastra/commit/5719fa8880e86e8affe698ec4b3807c7e0e0a06f), [`83cda45`](https://github.com/mastra-ai/mastra/commit/83cda4523e588558466892bff8f80f631a36945a), [`11804ad`](https://github.com/mastra-ai/mastra/commit/11804adf1d6be46ebe216be40a43b39bb8b397d7), [`aa95f95`](https://github.com/mastra-ai/mastra/commit/aa95f958b186ae5c9f4219c88e268f5565c277a2), [`f5501ae`](https://github.com/mastra-ai/mastra/commit/f5501aedb0a11106c7db7e480d6eaf3971b7bda8), [`44573af`](https://github.com/mastra-ai/mastra/commit/44573afad0a4bc86f627d6cbc0207961cdcb3bc3), [`00e3861`](https://github.com/mastra-ai/mastra/commit/00e3861863fbfee78faeb1ebbdc7c0223aae13ff), [`7bfbc52`](https://github.com/mastra-ai/mastra/commit/7bfbc52a8604feb0fff2c0a082c13c0c2a3df1a2), [`1445994`](https://github.com/mastra-ai/mastra/commit/1445994aee19c9334a6a101cf7bd80ca7ed4d186), [`61f44a2`](https://github.com/mastra-ai/mastra/commit/61f44a26861c89e364f367ff40825bdb7f19df55), [`37145d2`](https://github.com/mastra-ai/mastra/commit/37145d25f99dc31f1a9105576e5452609843ce32), [`fdad759`](https://github.com/mastra-ai/mastra/commit/fdad75939ff008b27625f5ec0ce9c6915d99d9ec), [`e4569c5`](https://github.com/mastra-ai/mastra/commit/e4569c589e00c4061a686c9eb85afe1b7050b0a8), [`7309a85`](https://github.com/mastra-ai/mastra/commit/7309a85427281a8be23f4fb80ca52e18eaffd596), [`99424f6`](https://github.com/mastra-ai/mastra/commit/99424f6862ffb679c4ec6765501486034754a4c2), [`44eb452`](https://github.com/mastra-ai/mastra/commit/44eb4529b10603c279688318bebf3048543a1d61), [`6c40593`](https://github.com/mastra-ai/mastra/commit/6c40593d6d2b1b68b0c45d1a3a4c6ac5ecac3937), [`8c1135d`](https://github.com/mastra-ai/mastra/commit/8c1135dfb91b057283eae7ee11f9ec28753cc64f), [`dd39e54`](https://github.com/mastra-ai/mastra/commit/dd39e54ea34532c995b33bee6e0e808bf41a7341), [`b6fad9a`](https://github.com/mastra-ai/mastra/commit/b6fad9a602182b1cc0df47cd8c55004fa829ad61), [`4129c07`](https://github.com/mastra-ai/mastra/commit/4129c073349b5a66643fd8136ebfe9d7097cf793), [`5b930ab`](https://github.com/mastra-ai/mastra/commit/5b930aba1834d9898e8460a49d15106f31ac7c8d), [`4be93d0`](https://github.com/mastra-ai/mastra/commit/4be93d09d68e20aaf0ea3f210749422719618b5f), [`047635c`](https://github.com/mastra-ai/mastra/commit/047635ccd7861d726c62d135560c0022a5490aec), [`8c90ff4`](https://github.com/mastra-ai/mastra/commit/8c90ff4d3414e7f2a2d216ea91274644f7b29133), [`ed232d1`](https://github.com/mastra-ai/mastra/commit/ed232d1583f403925dc5ae45f7bee948cf2a182b), [`3891795`](https://github.com/mastra-ai/mastra/commit/38917953518eb4154a984ee36e6ededdcfe80f72), [`4f955b2`](https://github.com/mastra-ai/mastra/commit/4f955b20c7f66ed282ee1fd8709696fa64c4f19d), [`55a4c90`](https://github.com/mastra-ai/mastra/commit/55a4c9044ac7454349b9f6aeba0bbab5ee65d10f)]:
39
+ - @mastra/core@1.3.0-alpha.1
40
+
3
41
  ## 1.0.3
4
42
 
5
43
  ### Patch Changes
@@ -21,8 +21,8 @@ import type { ZodObject, ZodType } from 'zod';
21
21
  * @param {string} [options.lastMessageId] - (Agent only) The ID of the last message in the conversation
22
22
  * @param {boolean} [options.sendStart=true] - (Agent only) Whether to send start events. Defaults to true
23
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
24
+ * @param {boolean} [options.sendReasoning] - (Agent and Workflow) Whether to include reasoning in the output
25
+ * @param {boolean} [options.sendSources] - (Agent and Workflow) Whether to include sources in the output
26
26
  * @param {Function} [options.messageMetadata] - (Agent only) A function that receives the current stream part and returns metadata to attach to start and finish chunks
27
27
  * @param {Function} [options.onError] - (Agent only) A function to handle errors during stream conversion. Receives the error and should return a string representation
28
28
  *
@@ -61,10 +61,14 @@ import type { ZodObject, ZodType } from 'zod';
61
61
  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: {
62
62
  from: 'workflow';
63
63
  includeTextStreamParts?: boolean;
64
+ sendReasoning?: boolean;
65
+ sendSources?: boolean;
64
66
  }): ReadableStream<InferUIMessageChunk<UIMessage>>;
65
67
  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: WorkflowRunOutput<WorkflowResult<TState, TInput, TOutput, TSteps>>, options: {
66
68
  from: 'workflow';
67
69
  includeTextStreamParts?: boolean;
70
+ sendReasoning?: boolean;
71
+ sendSources?: boolean;
68
72
  }): ReadableStream<InferUIMessageChunk<UIMessage>>;
69
73
  export declare function toAISdkV5Stream<OUTPUT = undefined>(stream: MastraAgentNetworkStream<OUTPUT>, options: {
70
74
  from: 'network';
@@ -1 +1 @@
1
- {"version":3,"file":"convert-streams.d.ts","sourceRoot":"","sources":["../src/convert-streams.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACtD,OAAO,KAAK,EAAE,iBAAiB,EAAa,wBAAwB,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACrH,OAAO,KAAK,EAAE,oBAAoB,EAAE,IAAI,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACzF,OAAO,KAAK,EAAE,mBAAmB,EAAE,SAAS,EAAE,sBAAsB,EAAE,MAAM,IAAI,CAAC;AACjF,OAAO,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,KAAK,CAAC;AAS9C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsDG;AACH,wBAAgB,eAAe,CAC7B,OAAO,SAAS,OAAO,CAAC,GAAG,CAAC,EAC5B,MAAM,SAAS,OAAO,CAAC,GAAG,CAAC,EAC3B,MAAM,SAAS,IAAI,CAAC,MAAM,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,EAAE,EACtD,MAAM,SAAS,SAAS,CAAC,GAAG,CAAC,EAE7B,MAAM,EAAE,oBAAoB,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,CAAC,EAC7D,OAAO,EAAE;IA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AAC,UAAU,CAAC,GAAG,kBAAkB,GAAG,qBAAqB,GAAG,oBAAoB,GAAG,SAAS,CAgPlH"}
package/dist/index.cjs CHANGED
@@ -2997,6 +2997,7 @@ function convertMastraChunkToAISDKv5({
2997
2997
  type: "data-tool-call-approval",
2998
2998
  id: chunk.payload.toolCallId,
2999
2999
  data: {
3000
+ state: "data-tool-call-approval",
3000
3001
  runId: chunk.runId,
3001
3002
  toolCallId: chunk.payload.toolCallId,
3002
3003
  toolName: chunk.payload.toolName,
@@ -3009,6 +3010,7 @@ function convertMastraChunkToAISDKv5({
3009
3010
  type: "data-tool-call-suspended",
3010
3011
  id: chunk.payload.toolCallId,
3011
3012
  data: {
3013
+ state: "data-tool-call-suspended",
3012
3014
  runId: chunk.runId,
3013
3015
  toolCallId: chunk.payload.toolCallId,
3014
3016
  toolName: chunk.payload.toolName,
@@ -3307,7 +3309,7 @@ function convertFullStreamChunkToUIMessageStream({
3307
3309
  }
3308
3310
  case "start": {
3309
3311
  if (sendStart) {
3310
- const messageId = ("messageId" in part ? part.messageId : void 0) || responseMessageId;
3312
+ const messageId = responseMessageId || ("messageId" in part ? part.messageId : void 0);
3311
3313
  return {
3312
3314
  type: "start",
3313
3315
  ...messageMetadataValue != null ? { messageMetadata: messageMetadataValue } : {},
@@ -3353,7 +3355,9 @@ function convertFullStreamChunkToUIMessageStream({
3353
3355
  // src/transformers.ts
3354
3356
  var PRIMITIVE_CACHE_SYMBOL = /* @__PURE__ */ Symbol("primitive-cache");
3355
3357
  function WorkflowStreamToAISDKTransformer({
3356
- includeTextStreamParts
3358
+ includeTextStreamParts,
3359
+ sendReasoning,
3360
+ sendSources
3357
3361
  } = {}) {
3358
3362
  const bufferedWorkflows = /* @__PURE__ */ new Map();
3359
3363
  return new web.TransformStream({
@@ -3368,7 +3372,10 @@ function WorkflowStreamToAISDKTransformer({
3368
3372
  });
3369
3373
  },
3370
3374
  transform(chunk, controller) {
3371
- const transformed = transformWorkflow(chunk, bufferedWorkflows, false, includeTextStreamParts);
3375
+ const transformed = transformWorkflow(chunk, bufferedWorkflows, false, includeTextStreamParts, {
3376
+ sendReasoning,
3377
+ sendSources
3378
+ });
3372
3379
  if (transformed) controller.enqueue(transformed);
3373
3380
  }
3374
3381
  });
@@ -3597,7 +3604,7 @@ function transformAgent(payload, bufferedSteps) {
3597
3604
  }
3598
3605
  return null;
3599
3606
  }
3600
- function transformWorkflow(payload, bufferedWorkflows, isNested, includeTextStreamParts) {
3607
+ function transformWorkflow(payload, bufferedWorkflows, isNested, includeTextStreamParts, streamOptions) {
3601
3608
  switch (payload.type) {
3602
3609
  case "workflow-start":
3603
3610
  bufferedWorkflows.set(payload.runId, {
@@ -3696,6 +3703,8 @@ function transformWorkflow(payload, bufferedWorkflows, isNested, includeTextStre
3696
3703
  const part = convertMastraChunkToAISDKv5({ chunk: output, mode: "stream" });
3697
3704
  const transformedChunk = convertFullStreamChunkToUIMessageStream({
3698
3705
  part,
3706
+ sendReasoning: streamOptions?.sendReasoning,
3707
+ sendSources: streamOptions?.sendSources,
3699
3708
  onError(error) {
3700
3709
  return safeParseErrorObject(error);
3701
3710
  }
@@ -3971,7 +3980,12 @@ function transformNetwork(payload, bufferedNetworks, isNested) {
3971
3980
  output: resultText ?? current.output
3972
3981
  }
3973
3982
  };
3974
- if (!current.hasEmittedText && resultText && typeof resultText === "string" && resultText.length > 0) {
3983
+ const finishStepId = payload.payload?.runId;
3984
+ const routingStep = current.steps.find(
3985
+ (step) => step.id === finishStepId && step.task?.id === "none" && step.task?.type === "none"
3986
+ );
3987
+ const isDirectHandling = !!routingStep;
3988
+ if (!isDirectHandling && !current.hasEmittedText && resultText && typeof resultText === "string" && resultText.length > 0) {
3975
3989
  current.hasEmittedText = true;
3976
3990
  return [
3977
3991
  { type: "text-start", id: payload.runId },
@@ -4095,8 +4109,13 @@ function toAISdkV5Stream(stream, options = {
4095
4109
  const from = options?.from;
4096
4110
  if (from === "workflow") {
4097
4111
  const includeTextStreamParts = options?.includeTextStreamParts ?? true;
4098
- return stream.pipeThrough(
4099
- WorkflowStreamToAISDKTransformer({ includeTextStreamParts })
4112
+ const workflowStream = "fullStream" in stream ? stream.fullStream : stream;
4113
+ return workflowStream.pipeThrough(
4114
+ WorkflowStreamToAISDKTransformer({
4115
+ includeTextStreamParts,
4116
+ sendReasoning: options?.sendReasoning,
4117
+ sendSources: options?.sendSources
4118
+ })
4100
4119
  );
4101
4120
  }
4102
4121
  if (from === "network") {
@@ -4329,18 +4348,25 @@ async function handleWorkflowStream({
4329
4348
  mastra,
4330
4349
  workflowId,
4331
4350
  params,
4332
- includeTextStreamParts = true
4351
+ includeTextStreamParts = true,
4352
+ sendReasoning = false,
4353
+ sendSources = false
4333
4354
  }) {
4334
- const { runId, resourceId, inputData, resumeData, requestContext, ...rest } = params;
4355
+ const { runId, resourceId, inputData, initialState, resumeData, requestContext, ...rest } = params;
4335
4356
  const workflowObj = mastra.getWorkflowById(workflowId);
4336
4357
  if (!workflowObj) {
4337
4358
  throw new Error(`Workflow ${workflowId} not found`);
4338
4359
  }
4339
4360
  const run = await workflowObj.createRun({ runId, resourceId, ...rest });
4340
- const stream = resumeData ? run.resumeStream({ resumeData, ...rest, requestContext }) : run.stream({ inputData, ...rest, requestContext });
4361
+ const stream = resumeData ? run.resumeStream({ resumeData, ...rest, requestContext }) : run.stream({ inputData, initialState, ...rest, requestContext });
4341
4362
  return createUIMessageStream({
4342
4363
  execute: async ({ writer }) => {
4343
- for await (const part of toAISdkV5Stream(stream, { from: "workflow", includeTextStreamParts })) {
4364
+ for await (const part of toAISdkV5Stream(stream, {
4365
+ from: "workflow",
4366
+ includeTextStreamParts,
4367
+ sendReasoning,
4368
+ sendSources
4369
+ })) {
4344
4370
  writer.write(part);
4345
4371
  }
4346
4372
  }
@@ -4349,7 +4375,9 @@ async function handleWorkflowStream({
4349
4375
  function workflowRoute({
4350
4376
  path = "/api/workflows/:workflowId/stream",
4351
4377
  workflow,
4352
- includeTextStreamParts = true
4378
+ includeTextStreamParts = true,
4379
+ sendReasoning = false,
4380
+ sendSources = false
4353
4381
  }) {
4354
4382
  if (!workflow && !path.includes("/:workflowId")) {
4355
4383
  throw new Error("Path must include :workflowId to route to the correct workflow or pass the workflow explicitly");
@@ -4428,7 +4456,9 @@ function workflowRoute({
4428
4456
  ...params,
4429
4457
  requestContext: contextRequestContext || params.requestContext
4430
4458
  },
4431
- includeTextStreamParts
4459
+ includeTextStreamParts,
4460
+ sendReasoning,
4461
+ sendSources
4432
4462
  });
4433
4463
  return createUIMessageStreamResponse({ stream: uiMessageStream });
4434
4464
  }