@mastra/react 1.4.13-alpha.1 → 1.5.0-alpha.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/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { $ as useEntity, A as TooltipContentClass, B as ToolApprovalContent, C as CodeBlock, D as IconButtonClass, E as IconButton, F as EntryTitleClass, G as ToolApprovalTitleClass, H as ToolApprovalHeader, I as ToolApproval, J as EntityContent, K as Entity, L as ToolApprovalActions, M as Entry, N as EntryClass, O as Tooltip, P as EntryTitle, Q as EntityTriggerVariantClasses, R as ToolApprovalActionsClass, S as AgentIcon, T as CodeCopyButton, U as ToolApprovalHeaderClass, V as ToolApprovalContentClass, W as ToolApprovalTitle, X as EntityTrigger, Y as EntityContentClass, Z as EntityTriggerClass, _ as MessageUsageValueClass, a as MessageClass, b as WorkflowIcon, c as MessageList, d as MessageStreamingClass, et as Icon, f as MessageUsage, g as MessageUsageValue, h as MessageUsageEntryClass, i as MessageActionsClass, j as TooltipTrigger, k as TooltipContent, l as MessageListClass, m as MessageUsageEntry, n as Message, o as MessageContent, p as MessageUsageClass, q as EntityCaret, r as MessageActions, s as MessageContentClass, t as MessageFactory, tt as IconSizes, u as MessageStreaming, v as MessageUsages, w as CodeBlockClass, x as ToolsIcon, y as MessageUsagesClass, z as ToolApprovalClass } from "./ui-Bd2cu1B9.js";
1
+ import { $ as useEntity, A as TooltipContentClass, B as ToolApprovalContent, C as CodeBlock, D as IconButtonClass, E as IconButton, F as EntryTitleClass, G as ToolApprovalTitleClass, H as ToolApprovalHeader, I as ToolApproval, J as EntityContent, K as Entity, L as ToolApprovalActions, M as Entry, N as EntryClass, O as Tooltip, P as EntryTitle, Q as EntityTriggerVariantClasses, R as ToolApprovalActionsClass, S as AgentIcon, T as CodeCopyButton, U as ToolApprovalHeaderClass, V as ToolApprovalContentClass, W as ToolApprovalTitle, X as EntityTrigger, Y as EntityContentClass, Z as EntityTriggerClass, _ as MessageUsageValueClass, a as MessageClass, b as WorkflowIcon, c as MessageList, d as MessageStreamingClass, et as Icon, f as MessageUsage, g as MessageUsageValue, h as MessageUsageEntryClass, i as MessageActionsClass, j as TooltipTrigger, k as TooltipContent, l as MessageListClass, m as MessageUsageEntry, n as Message, o as MessageContent, p as MessageUsageClass, q as EntityCaret, r as MessageActions, s as MessageContentClass, t as MessageFactory, tt as IconSizes, u as MessageStreaming, v as MessageUsages, w as CodeBlockClass, x as ToolsIcon, y as MessageUsagesClass, z as ToolApprovalClass } from "./ui-BQyoxYsH.js";
2
2
  import { MastraClient } from "@mastra/client-js";
3
3
  import { createContext, memo, useCallback, useContext, useEffect, useMemo, useRef, useState } from "react";
4
4
  import { Fragment as Fragment$1, jsx } from "react/jsx-runtime";
@@ -1908,7 +1908,7 @@ const dbFromServerUiMessages = (uiMessages, metadata) => uiMessages.map((uiMsg)
1908
1908
  }
1909
1909
  };
1910
1910
  });
1911
- const useChat = ({ agentId, resourceId, threadId, initialMessages, requestContext: propsRequestContext, clientTools: hookClientTools, onSignalSent, onSignalEcho, onThreadSignalsUnsupported, enableThreadSignals = false }) => {
1911
+ const useChat = ({ agentId, resourceId, threadId, initialMessages, requestContext: propsRequestContext, clientTools: hookClientTools, onSignalSent, onSignalEcho, onThreadSignalsUnsupported, enableThreadSignals = false, streamPath }) => {
1912
1912
  const threadSignalsDisabled = enableThreadSignals === false;
1913
1913
  const _currentRunId = useRef(void 0);
1914
1914
  const _onChunk = useRef(void 0);
@@ -2084,7 +2084,7 @@ const useChat = ({ agentId, resourceId, threadId, initialMessages, requestContex
2084
2084
  (onChunk ?? _onChunk.current)?.(chunk);
2085
2085
  }, [onSignalEcho]);
2086
2086
  const ensureThreadSubscription = useCallback(async ({ threadId, resourceId }) => {
2087
- const subscriptionKey = `${agentId}:${resourceId ?? ""}:${threadId}`;
2087
+ const subscriptionKey = `${agentId}:${resourceId ?? ""}:${threadId}:${streamPath ?? ""}`;
2088
2088
  if (_threadSubscriptionKeyRef.current === subscriptionKey && _threadSubscriptionPromiseRef.current) {
2089
2089
  await _threadSubscriptionPromiseRef.current;
2090
2090
  return;
@@ -2103,7 +2103,7 @@ const useChat = ({ agentId, resourceId, threadId, initialMessages, requestContex
2103
2103
  const subscriptionAgent = new MastraClient({
2104
2104
  ...baseClient.options,
2105
2105
  abortSignal: subscriptionAbort.signal
2106
- }).getAgent(agentId);
2106
+ }).getAgent(agentId, void 0, { stream: streamPath });
2107
2107
  _threadSubscriptionPromiseRef.current = subscriptionAgent.subscribeToThread({
2108
2108
  resourceId,
2109
2109
  threadId
@@ -2141,7 +2141,8 @@ const useChat = ({ agentId, resourceId, threadId, initialMessages, requestContex
2141
2141
  baseClient,
2142
2142
  closeThreadSubscription,
2143
2143
  markThreadSignalsUnsupported,
2144
- processStreamChunk
2144
+ processStreamChunk,
2145
+ streamPath
2145
2146
  ]);
2146
2147
  useEffect(() => {
2147
2148
  _threadSignalsUnsupportedRef.current = false;
@@ -2171,7 +2172,7 @@ const useChat = ({ agentId, resourceId, threadId, initialMessages, requestContex
2171
2172
  threadId,
2172
2173
  threadSignalsDisabled
2173
2174
  ]);
2174
- const generate = async ({ coreUserMessages, model, requestContext, threadId, modelSettings, signal, onFinish, tracingOptions, clientTools }) => {
2175
+ const generate = async ({ coreUserMessages, model, requestContext, threadId, modelSettings, signal, onFinish, tracingOptions, clientTools, clientToolsResolver }) => {
2175
2176
  const { frequencyPenalty, presencePenalty, maxRetries, maxTokens, temperature, topK, topP, instructions, system, providerOptions, maxSteps, requireToolApproval } = modelSettings || {};
2176
2177
  const resolvedRequestContext = requestContext ?? propsRequestContext;
2177
2178
  const resolvedClientTools = clientTools ?? hookClientTools;
@@ -2183,7 +2184,7 @@ const useChat = ({ agentId, resourceId, threadId, initialMessages, requestContex
2183
2184
  const agent = new MastraClient({
2184
2185
  ...baseClient.options,
2185
2186
  abortSignal: signal
2186
- }).getAgent(agentId);
2187
+ }).getAgent(agentId, void 0, { stream: streamPath });
2187
2188
  const runId = v4();
2188
2189
  _currentRunId.current = runId;
2189
2190
  const response = await agent.generate(coreUserMessages, {
@@ -2209,7 +2210,8 @@ const useChat = ({ agentId, resourceId, threadId, initialMessages, requestContex
2209
2210
  providerOptions,
2210
2211
  tracingOptions,
2211
2212
  requireToolApproval,
2212
- clientTools: resolvedClientTools
2213
+ clientTools: resolvedClientTools,
2214
+ clientToolsResolver
2213
2215
  });
2214
2216
  if (response.finishReason === "suspended" && response.suspendPayload) {
2215
2217
  const { toolCallId, toolName, args } = response.suspendPayload;
@@ -2234,7 +2236,7 @@ const useChat = ({ agentId, resourceId, threadId, initialMessages, requestContex
2234
2236
  setMessages((prev) => [...prev, ...dbMessages]);
2235
2237
  }
2236
2238
  };
2237
- const stream = async ({ coreUserMessages, model, requestContext, threadId, onChunk, modelSettings, signal, tracingOptions, clientTools, signalId, clientMessageId }) => {
2239
+ const stream = async ({ coreUserMessages, model, requestContext, threadId, onChunk, modelSettings, signal, tracingOptions, clientTools, clientToolsResolver, signalId, clientMessageId }) => {
2238
2240
  const { frequencyPenalty, presencePenalty, maxRetries, maxTokens, temperature, topK, topP, instructions, system, providerOptions, maxSteps, requireToolApproval } = modelSettings || {};
2239
2241
  const resolvedRequestContext = requestContext ?? propsRequestContext;
2240
2242
  const resolvedClientTools = clientTools ?? hookClientTools;
@@ -2269,7 +2271,7 @@ const useChat = ({ agentId, resourceId, threadId, initialMessages, requestContex
2269
2271
  const agent = new MastraClient({
2270
2272
  ...baseClient.options,
2271
2273
  abortSignal: internalAbort.signal
2272
- }).getAgent(agentId);
2274
+ }).getAgent(agentId, void 0, { stream: streamPath });
2273
2275
  const streamWithLegacyRoute = async () => {
2274
2276
  const runId = v4();
2275
2277
  const response = await agent.stream(coreUserMessages, {
@@ -2296,7 +2298,8 @@ const useChat = ({ agentId, resourceId, threadId, initialMessages, requestContex
2296
2298
  providerOptions,
2297
2299
  requireToolApproval,
2298
2300
  tracingOptions,
2299
- clientTools: resolvedClientTools
2301
+ clientTools: resolvedClientTools,
2302
+ clientToolsResolver
2300
2303
  });
2301
2304
  _onChunk.current = onChunk;
2302
2305
  _currentRunId.current = runId;
@@ -2337,7 +2340,9 @@ const useChat = ({ agentId, resourceId, threadId, initialMessages, requestContex
2337
2340
  requestContext: requestContextRecord,
2338
2341
  providerOptions,
2339
2342
  requireToolApproval,
2340
- tracingOptions
2343
+ tracingOptions,
2344
+ clientTools: resolvedClientTools,
2345
+ clientToolsResolver
2341
2346
  };
2342
2347
  try {
2343
2348
  const result = await agent.sendMessage({
@@ -2350,7 +2355,8 @@ const useChat = ({ agentId, resourceId, threadId, initialMessages, requestContex
2350
2355
  ifIdle: { streamOptions: {
2351
2356
  ...signalContinuationOptions,
2352
2357
  requestContext: requestContextRecord,
2353
- clientTools: resolvedClientTools
2358
+ clientTools: resolvedClientTools,
2359
+ clientToolsResolver
2354
2360
  } }
2355
2361
  });
2356
2362
  const echoedSignalId = result.signal && typeof result.signal === "object" && "id" in result.signal && typeof result.signal.id === "string" ? result.signal.id : resolvedSignalId;
@@ -2395,7 +2401,7 @@ const useChat = ({ agentId, resourceId, threadId, initialMessages, requestContex
2395
2401
  const agent = new MastraClient({
2396
2402
  ...baseClient.options,
2397
2403
  abortSignal: signal
2398
- }).getAgent(agentId);
2404
+ }).getAgent(agentId, void 0, { stream: streamPath });
2399
2405
  const runId = v4();
2400
2406
  const response = await agent.network(coreUserMessages, {
2401
2407
  model,
@@ -2459,7 +2465,7 @@ const useChat = ({ agentId, resourceId, threadId, initialMessages, requestContex
2459
2465
  ...prev,
2460
2466
  [toolCallId]: { status: "approved" }
2461
2467
  }));
2462
- const agent = baseClient.getAgent(agentId);
2468
+ const agent = baseClient.getAgent(agentId, void 0, { stream: streamPath });
2463
2469
  if (_threadSubscriptionKeyRef.current && threadId) {
2464
2470
  try {
2465
2471
  await agent.sendToolApproval({
@@ -2520,7 +2526,7 @@ const useChat = ({ agentId, resourceId, threadId, initialMessages, requestContex
2520
2526
  ...prev,
2521
2527
  [toolCallId]: { status: "declined" }
2522
2528
  }));
2523
- const agent = baseClient.getAgent(agentId);
2529
+ const agent = baseClient.getAgent(agentId, void 0, { stream: streamPath });
2524
2530
  if (_threadSubscriptionKeyRef.current && threadId) {
2525
2531
  try {
2526
2532
  await agent.sendToolApproval({
@@ -2565,7 +2571,7 @@ const useChat = ({ agentId, resourceId, threadId, initialMessages, requestContex
2565
2571
  ...prev,
2566
2572
  [toolCallId]: { status: "approved" }
2567
2573
  }));
2568
- const response = await baseClient.getAgent(agentId).approveToolCallGenerate({
2574
+ const response = await baseClient.getAgent(agentId, void 0, { stream: streamPath }).approveToolCallGenerate({
2569
2575
  runId: currentRunId,
2570
2576
  toolCallId,
2571
2577
  ...continuation
@@ -2585,7 +2591,7 @@ const useChat = ({ agentId, resourceId, threadId, initialMessages, requestContex
2585
2591
  ...prev,
2586
2592
  [toolCallId]: { status: "declined" }
2587
2593
  }));
2588
- const response = await baseClient.getAgent(agentId).declineToolCallGenerate({
2594
+ const response = await baseClient.getAgent(agentId, void 0, { stream: streamPath }).declineToolCallGenerate({
2589
2595
  runId: currentRunId,
2590
2596
  toolCallId,
2591
2597
  ...continuation
@@ -2606,7 +2612,7 @@ const useChat = ({ agentId, resourceId, threadId, initialMessages, requestContex
2606
2612
  ...prev,
2607
2613
  [runId ? `${runId}-${toolName}` : toolName]: { status: "approved" }
2608
2614
  }));
2609
- await (await baseClient.getAgent(agentId).approveNetworkToolCall({
2615
+ await (await baseClient.getAgent(agentId, void 0, { stream: streamPath }).approveNetworkToolCall({
2610
2616
  runId: networkRunId,
2611
2617
  ...continuation
2612
2618
  })).processDataStream({ onChunk: async (chunk) => {
@@ -2630,7 +2636,7 @@ const useChat = ({ agentId, resourceId, threadId, initialMessages, requestContex
2630
2636
  ...prev,
2631
2637
  [runId ? `${runId}-${toolName}` : toolName]: { status: "declined" }
2632
2638
  }));
2633
- await (await baseClient.getAgent(agentId).declineNetworkToolCall({
2639
+ await (await baseClient.getAgent(agentId, void 0, { stream: streamPath }).declineNetworkToolCall({
2634
2640
  runId: networkRunId,
2635
2641
  ...continuation
2636
2642
  })).processDataStream({ onChunk: async (chunk) => {