@mastra/react 1.2.6-alpha.9 → 1.3.0-alpha.11

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/dist/index.js CHANGED
@@ -1981,7 +1981,7 @@ var useChat = ({
1981
1981
  const _onChunk = useRef(void 0);
1982
1982
  const _networkRunId = useRef(void 0);
1983
1983
  const _onNetworkChunk = useRef(void 0);
1984
- const _requestContext = useRef(propsRequestContext);
1984
+ const _activeContinuation = useRef({ requestContext: propsRequestContext });
1985
1985
  const _streamAbortRef = useRef(null);
1986
1986
  const _threadSubscriptionAbortRef = useRef(null);
1987
1987
  const _threadSubscriptionRef = useRef(
@@ -2007,7 +2007,10 @@ var useChat = ({
2007
2007
  _currentRunId.current = extractRunIdFromMessages(formattedMessages);
2008
2008
  }, [initialMessages]);
2009
2009
  useEffect(() => {
2010
- _requestContext.current = propsRequestContext;
2010
+ _activeContinuation.current = {
2011
+ ..._activeContinuation.current,
2012
+ requestContext: propsRequestContext
2013
+ };
2011
2014
  }, [propsRequestContext]);
2012
2015
  const normalizeSignalFileData = (data) => {
2013
2016
  if (data instanceof URL) return data.toString();
@@ -2179,6 +2182,7 @@ var useChat = ({
2179
2182
  }, [agentId, closeThreadSubscription, ensureThreadSubscription, resourceId, threadId, threadSignalsDisabled]);
2180
2183
  const generate = async ({
2181
2184
  coreUserMessages,
2185
+ model,
2182
2186
  requestContext,
2183
2187
  threadId: threadId2,
2184
2188
  modelSettings,
@@ -2202,7 +2206,10 @@ var useChat = ({
2202
2206
  } = modelSettings || {};
2203
2207
  const resolvedRequestContext = requestContext ?? propsRequestContext;
2204
2208
  const resolvedClientTools = clientTools ?? hookClientTools;
2205
- _requestContext.current = resolvedRequestContext;
2209
+ _activeContinuation.current = {
2210
+ model,
2211
+ requestContext: resolvedRequestContext
2212
+ };
2206
2213
  setIsRunning(true);
2207
2214
  const clientWithAbort = new MastraClient({
2208
2215
  ...baseClient.options,
@@ -2212,6 +2219,7 @@ var useChat = ({
2212
2219
  const runId = v4();
2213
2220
  _currentRunId.current = runId;
2214
2221
  const response = await agent.generate(coreUserMessages, {
2222
+ model,
2215
2223
  runId,
2216
2224
  maxSteps,
2217
2225
  modelSettings: {
@@ -2254,6 +2262,7 @@ var useChat = ({
2254
2262
  };
2255
2263
  const stream = async ({
2256
2264
  coreUserMessages,
2265
+ model,
2257
2266
  requestContext,
2258
2267
  threadId: threadId2,
2259
2268
  onChunk,
@@ -2280,6 +2289,7 @@ var useChat = ({
2280
2289
  const resolvedRequestContext = requestContext ?? propsRequestContext;
2281
2290
  const resolvedClientTools = clientTools ?? hookClientTools;
2282
2291
  const signalContinuationOptions = {
2292
+ model,
2283
2293
  maxSteps,
2284
2294
  modelSettings: {
2285
2295
  frequencyPenalty,
@@ -2295,7 +2305,10 @@ var useChat = ({
2295
2305
  requireToolApproval,
2296
2306
  tracingOptions
2297
2307
  };
2298
- _requestContext.current = resolvedRequestContext;
2308
+ _activeContinuation.current = {
2309
+ model,
2310
+ requestContext: resolvedRequestContext
2311
+ };
2299
2312
  setIsRunning(true);
2300
2313
  _streamAbortRef.current?.abort();
2301
2314
  const internalAbort = new AbortController();
@@ -2312,6 +2325,7 @@ var useChat = ({
2312
2325
  const streamWithLegacyRoute = async () => {
2313
2326
  const runId = v4();
2314
2327
  const response = await agent.stream(coreUserMessages, {
2328
+ model,
2315
2329
  runId,
2316
2330
  maxSteps,
2317
2331
  untilIdle: true,
@@ -2356,6 +2370,7 @@ var useChat = ({
2356
2370
  const messageContents = getSignalContents(coreUserMessages);
2357
2371
  const requestContextRecord = resolvedRequestContext;
2358
2372
  const streamOptions = {
2373
+ model,
2359
2374
  maxSteps,
2360
2375
  modelSettings: {
2361
2376
  frequencyPenalty,
@@ -2424,6 +2439,7 @@ var useChat = ({
2424
2439
  };
2425
2440
  const network = async ({
2426
2441
  coreUserMessages,
2442
+ model,
2427
2443
  requestContext,
2428
2444
  threadId: threadId2,
2429
2445
  onNetworkChunk,
@@ -2433,7 +2449,10 @@ var useChat = ({
2433
2449
  }) => {
2434
2450
  const { frequencyPenalty, presencePenalty, maxRetries, maxTokens, temperature, topK, topP, maxSteps } = modelSettings || {};
2435
2451
  const resolvedRequestContext = requestContext ?? propsRequestContext;
2436
- _requestContext.current = resolvedRequestContext;
2452
+ _activeContinuation.current = {
2453
+ model,
2454
+ requestContext: resolvedRequestContext
2455
+ };
2437
2456
  setIsRunning(true);
2438
2457
  const clientWithAbort = new MastraClient({
2439
2458
  ...baseClient.options,
@@ -2442,6 +2461,7 @@ var useChat = ({
2442
2461
  const agent = clientWithAbort.getAgent(agentId);
2443
2462
  const runId = v4();
2444
2463
  const response = await agent.network(coreUserMessages, {
2464
+ model,
2445
2465
  maxSteps,
2446
2466
  modelSettings: {
2447
2467
  frequencyPenalty,
@@ -2484,11 +2504,12 @@ var useChat = ({
2484
2504
  _onChunk.current = void 0;
2485
2505
  _networkRunId.current = void 0;
2486
2506
  _onNetworkChunk.current = void 0;
2487
- _requestContext.current = void 0;
2507
+ _activeContinuation.current = {};
2488
2508
  };
2489
2509
  const approveToolCall = async (toolCallId, resumeData) => {
2490
2510
  const onChunk = _onChunk.current;
2491
2511
  const currentRunId = _currentRunId.current;
2512
+ const continuation = _activeContinuation.current;
2492
2513
  if (!currentRunId)
2493
2514
  return console.info("[approveToolCall] approveToolCall can only be called after a stream has started");
2494
2515
  setIsRunning(true);
@@ -2501,8 +2522,9 @@ var useChat = ({
2501
2522
  threadId,
2502
2523
  toolCallId,
2503
2524
  approved: true,
2525
+ ...continuation.model !== void 0 ? { streamOptions: { model: continuation.model } } : {},
2504
2526
  ...resumeData !== void 0 ? { resumeData } : {},
2505
- requestContext: _requestContext.current
2527
+ requestContext: continuation.requestContext
2506
2528
  });
2507
2529
  pendingToolApprovalIdsRef.current.delete(toolCallId);
2508
2530
  setIsAwaitingToolApproval(pendingToolApprovalIdsRef.current.size > 0);
@@ -2521,7 +2543,7 @@ var useChat = ({
2521
2543
  const response = await agent.approveToolCall({
2522
2544
  runId: currentRunId,
2523
2545
  toolCallId,
2524
- requestContext: _requestContext.current
2546
+ ...continuation
2525
2547
  });
2526
2548
  await response.processDataStream({
2527
2549
  onChunk: async (chunk) => {
@@ -2533,6 +2555,7 @@ var useChat = ({
2533
2555
  const declineToolCall = async (toolCallId) => {
2534
2556
  const onChunk = _onChunk.current;
2535
2557
  const currentRunId = _currentRunId.current;
2558
+ const continuation = _activeContinuation.current;
2536
2559
  if (!currentRunId)
2537
2560
  return console.info("[declineToolCall] declineToolCall can only be called after a stream has started");
2538
2561
  setIsRunning(true);
@@ -2545,7 +2568,8 @@ var useChat = ({
2545
2568
  threadId,
2546
2569
  toolCallId,
2547
2570
  approved: false,
2548
- requestContext: _requestContext.current
2571
+ ...continuation.model !== void 0 ? { streamOptions: { model: continuation.model } } : {},
2572
+ requestContext: continuation.requestContext
2549
2573
  });
2550
2574
  pendingToolApprovalIdsRef.current.delete(toolCallId);
2551
2575
  setIsAwaitingToolApproval(pendingToolApprovalIdsRef.current.size > 0);
@@ -2564,7 +2588,7 @@ var useChat = ({
2564
2588
  const response = await agent.declineToolCall({
2565
2589
  runId: currentRunId,
2566
2590
  toolCallId,
2567
- requestContext: _requestContext.current
2591
+ ...continuation
2568
2592
  });
2569
2593
  await response.processDataStream({
2570
2594
  onChunk: async (chunk) => {
@@ -2575,6 +2599,7 @@ var useChat = ({
2575
2599
  };
2576
2600
  const approveToolCallGenerate = async (toolCallId) => {
2577
2601
  const currentRunId = _currentRunId.current;
2602
+ const continuation = _activeContinuation.current;
2578
2603
  if (!currentRunId)
2579
2604
  return console.info(
2580
2605
  "[approveToolCallGenerate] approveToolCallGenerate can only be called after a generate has started"
@@ -2585,7 +2610,7 @@ var useChat = ({
2585
2610
  const response = await agent.approveToolCallGenerate({
2586
2611
  runId: currentRunId,
2587
2612
  toolCallId,
2588
- requestContext: _requestContext.current
2613
+ ...continuation
2589
2614
  });
2590
2615
  if (response && "uiMessages" in response.response && response.response.uiMessages) {
2591
2616
  const dbMessages = dbFromServerUiMessages(response.response.uiMessages, { mode: "generate" });
@@ -2595,6 +2620,7 @@ var useChat = ({
2595
2620
  };
2596
2621
  const declineToolCallGenerate = async (toolCallId) => {
2597
2622
  const currentRunId = _currentRunId.current;
2623
+ const continuation = _activeContinuation.current;
2598
2624
  if (!currentRunId)
2599
2625
  return console.info(
2600
2626
  "[declineToolCallGenerate] declineToolCallGenerate can only be called after a generate has started"
@@ -2605,7 +2631,7 @@ var useChat = ({
2605
2631
  const response = await agent.declineToolCallGenerate({
2606
2632
  runId: currentRunId,
2607
2633
  toolCallId,
2608
- requestContext: _requestContext.current
2634
+ ...continuation
2609
2635
  });
2610
2636
  if (response && "uiMessages" in response.response && response.response.uiMessages) {
2611
2637
  const dbMessages = dbFromServerUiMessages(response.response.uiMessages, { mode: "generate" });
@@ -2616,6 +2642,7 @@ var useChat = ({
2616
2642
  const approveNetworkToolCall = async (toolName, runId) => {
2617
2643
  const onNetworkChunk = _onNetworkChunk.current;
2618
2644
  const networkRunId = runId || _networkRunId.current;
2645
+ const continuation = _activeContinuation.current;
2619
2646
  if (!networkRunId)
2620
2647
  return console.info(
2621
2648
  "[approveNetworkToolCall] approveNetworkToolCall can only be called after a network stream has started"
@@ -2628,7 +2655,7 @@ var useChat = ({
2628
2655
  const agent = baseClient.getAgent(agentId);
2629
2656
  const response = await agent.approveNetworkToolCall({
2630
2657
  runId: networkRunId,
2631
- requestContext: _requestContext.current
2658
+ ...continuation
2632
2659
  });
2633
2660
  await response.processDataStream({
2634
2661
  onChunk: async (chunk) => {
@@ -2642,6 +2669,7 @@ var useChat = ({
2642
2669
  const declineNetworkToolCall = async (toolName, runId) => {
2643
2670
  const onNetworkChunk = _onNetworkChunk.current;
2644
2671
  const networkRunId = runId || _networkRunId.current;
2672
+ const continuation = _activeContinuation.current;
2645
2673
  if (!networkRunId)
2646
2674
  return console.info(
2647
2675
  "[declineNetworkToolCall] declineNetworkToolCall can only be called after a network stream has started"
@@ -2654,7 +2682,7 @@ var useChat = ({
2654
2682
  const agent = baseClient.getAgent(agentId);
2655
2683
  const response = await agent.declineNetworkToolCall({
2656
2684
  runId: networkRunId,
2657
- requestContext: _requestContext.current
2685
+ ...continuation
2658
2686
  });
2659
2687
  await response.processDataStream({
2660
2688
  onChunk: async (chunk) => {