@mastra/react 0.3.1-alpha.0 → 0.3.1

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
@@ -1960,8 +1960,10 @@ var useChat = ({
1960
1960
  requestContext: propsRequestContext,
1961
1961
  onSignalSent,
1962
1962
  onSignalEcho,
1963
- onThreadSignalsUnsupported
1963
+ onThreadSignalsUnsupported,
1964
+ enableThreadSignals = false
1964
1965
  }) => {
1966
+ const threadSignalsDisabled = enableThreadSignals === false;
1965
1967
  const _currentRunId = useRef(void 0);
1966
1968
  const _onChunk = useRef(void 0);
1967
1969
  const _networkRunId = useRef(void 0);
@@ -2089,13 +2091,16 @@ var useChat = ({
2089
2091
  return closeThreadSubscription;
2090
2092
  }, [agentId, resourceId, threadId, closeThreadSubscription]);
2091
2093
  useEffect(() => {
2092
- if (!threadId) return;
2094
+ if (!threadId || threadSignalsDisabled) {
2095
+ closeThreadSubscription();
2096
+ return;
2097
+ }
2093
2098
  void ensureThreadSubscription({ threadId, resourceId: resourceId || agentId }).catch((error) => {
2094
2099
  if (error.name !== "AbortError") {
2095
2100
  console.error("[useChat] Thread subscription failed", error);
2096
2101
  }
2097
2102
  });
2098
- }, [agentId, ensureThreadSubscription, resourceId, threadId]);
2103
+ }, [agentId, closeThreadSubscription, ensureThreadSubscription, resourceId, threadId, threadSignalsDisabled]);
2099
2104
  const generate = async ({
2100
2105
  coreUserMessages,
2101
2106
  requestContext,
@@ -2249,7 +2254,7 @@ var useChat = ({
2249
2254
  }
2250
2255
  setIsRunning(false);
2251
2256
  };
2252
- if (!threadId2 || _threadSignalsUnsupportedRef.current) {
2257
+ if (!threadId2 || _threadSignalsUnsupportedRef.current || threadSignalsDisabled) {
2253
2258
  await streamWithLegacyRoute();
2254
2259
  return;
2255
2260
  }
@@ -2519,7 +2524,7 @@ var useChat = ({
2519
2524
  coreUserMessages.push(...args.coreUserMessages);
2520
2525
  }
2521
2526
  const uiMessages = coreUserMessages.map(fromCoreUserMessageToUIMessage);
2522
- const signalId = mode === "stream" && args.threadId && !_threadSignalsUnsupportedRef.current ? uiMessages[0]?.id : void 0;
2527
+ const signalId = mode === "stream" && args.threadId && !_threadSignalsUnsupportedRef.current && !threadSignalsDisabled ? uiMessages[0]?.id : void 0;
2523
2528
  if (!signalId) {
2524
2529
  setMessages((s) => [...s, ...uiMessages]);
2525
2530
  }