@mastra/react 0.3.0 → 0.3.1-alpha.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/CHANGELOG.md CHANGED
@@ -1,5 +1,23 @@
1
1
  # @mastra/react
2
2
 
3
+ ## 0.3.1-alpha.1
4
+
5
+ ### Patch Changes
6
+
7
+ - Add an `enableThreadSignals` option to `useChat` for explicitly opting into the agent-signals streaming path. The option defaults to `false`, keeping consumers on the legacy `streamUntilIdle` route unless they pass `true`. ([#16551](https://github.com/mastra-ai/mastra/pull/16551))
8
+
9
+ - Updated dependencies [[`3e63fca`](https://github.com/mastra-ai/mastra/commit/3e63fca7aa41269b2a9518effdd09b8ab8f1ff04), [`bc386e0`](https://github.com/mastra-ai/mastra/commit/bc386e08249dd30f3e66cf59de0c151a8dc26afb)]:
10
+ - @mastra/core@1.33.1-alpha.1
11
+ - @mastra/client-js@1.18.1-alpha.1
12
+
13
+ ## 0.3.1-alpha.0
14
+
15
+ ### Patch Changes
16
+
17
+ - Updated dependencies [[`6ba46dc`](https://github.com/mastra-ai/mastra/commit/6ba46dc1ac04af635d0f59377d7384ca6af44cd1)]:
18
+ - @mastra/core@1.33.1-alpha.0
19
+ - @mastra/client-js@1.18.1-alpha.0
20
+
3
21
  ## 0.3.0
4
22
 
5
23
  ### Minor Changes
@@ -15,6 +15,12 @@ export interface MastraChatProps {
15
15
  onSignalSent?: (signalId: string, preview: string) => void;
16
16
  onSignalEcho?: (signalId: string) => void;
17
17
  onThreadSignalsUnsupported?: () => void;
18
+ /**
19
+ * Opt into the agent-signals streaming path (sendSignal + subscribeToThread).
20
+ * Defaults to `false` so consumers stay on the legacy `streamUntilIdle` route
21
+ * unless they explicitly enable the signals path.
22
+ */
23
+ enableThreadSignals?: boolean;
18
24
  }
19
25
  interface SharedArgs {
20
26
  coreUserMessages: CoreUserMessage[];
@@ -46,7 +52,7 @@ export type StreamArgs = SharedArgs & {
46
52
  export type NetworkArgs = SharedArgs & {
47
53
  onNetworkChunk?: (chunk: NetworkChunkType) => Promise<void>;
48
54
  };
49
- export declare const useChat: ({ agentId, resourceId, threadId, initialMessages, requestContext: propsRequestContext, onSignalSent, onSignalEcho, onThreadSignalsUnsupported, }: MastraChatProps) => {
55
+ export declare const useChat: ({ agentId, resourceId, threadId, initialMessages, requestContext: propsRequestContext, onSignalSent, onSignalEcho, onThreadSignalsUnsupported, enableThreadSignals, }: MastraChatProps) => {
50
56
  setMessages: import("react").Dispatch<import("react").SetStateAction<MastraUIMessage[]>>;
51
57
  sendMessage: ({ mode, ...args }: SendMessageArgs) => Promise<void>;
52
58
  isRunning: boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../../src/agent/hooks.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAI/C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACxD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AACnE,OAAO,KAAK,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAEvE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAErD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAO7C,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,eAAe,CAAC,EAAE,eAAe,EAAE,CAAC;IACpC,6FAA6F;IAC7F,cAAc,CAAC,EAAE,cAAc,CAAC;IAChC,YAAY,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IAC3D,YAAY,CAAC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AM,WAAW,GAAG,UAAU,GAAG;IACrC,cAAc,CAAC,EAAE,CAAC,KAAK,EAAE,gBAAgB,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CAC7D,CAAC;AAYF,eAAO,MAAM,OAAO,GAAI,uKAUrB,eAAe;;qCAurByC,eAAe;;;kCAnM7B,MAAM;kCAiCN,MAAM;0CAgCE,MAAM;0CAgCN,MAAM;;;;oBAlkBvB,UAAU,GAAG,UAAU;;;uCAkmBT,MAAM,UAAU,MAAM;uCAiCtB,MAAM,UAAU,MAAM;;;oBAhoBtC,UAAU,GAAG,UAAU;;;CA0sBxD,CAAC"}
package/dist/index.cjs CHANGED
@@ -1962,8 +1962,10 @@ var useChat = ({
1962
1962
  requestContext: propsRequestContext,
1963
1963
  onSignalSent,
1964
1964
  onSignalEcho,
1965
- onThreadSignalsUnsupported
1965
+ onThreadSignalsUnsupported,
1966
+ enableThreadSignals = false
1966
1967
  }) => {
1968
+ const threadSignalsDisabled = enableThreadSignals === false;
1967
1969
  const _currentRunId = react.useRef(void 0);
1968
1970
  const _onChunk = react.useRef(void 0);
1969
1971
  const _networkRunId = react.useRef(void 0);
@@ -2091,13 +2093,16 @@ var useChat = ({
2091
2093
  return closeThreadSubscription;
2092
2094
  }, [agentId, resourceId, threadId, closeThreadSubscription]);
2093
2095
  react.useEffect(() => {
2094
- if (!threadId) return;
2096
+ if (!threadId || threadSignalsDisabled) {
2097
+ closeThreadSubscription();
2098
+ return;
2099
+ }
2095
2100
  void ensureThreadSubscription({ threadId, resourceId: resourceId || agentId }).catch((error) => {
2096
2101
  if (error.name !== "AbortError") {
2097
2102
  console.error("[useChat] Thread subscription failed", error);
2098
2103
  }
2099
2104
  });
2100
- }, [agentId, ensureThreadSubscription, resourceId, threadId]);
2105
+ }, [agentId, closeThreadSubscription, ensureThreadSubscription, resourceId, threadId, threadSignalsDisabled]);
2101
2106
  const generate = async ({
2102
2107
  coreUserMessages,
2103
2108
  requestContext,
@@ -2251,7 +2256,7 @@ var useChat = ({
2251
2256
  }
2252
2257
  setIsRunning(false);
2253
2258
  };
2254
- if (!threadId2 || _threadSignalsUnsupportedRef.current) {
2259
+ if (!threadId2 || _threadSignalsUnsupportedRef.current || threadSignalsDisabled) {
2255
2260
  await streamWithLegacyRoute();
2256
2261
  return;
2257
2262
  }
@@ -2521,7 +2526,7 @@ var useChat = ({
2521
2526
  coreUserMessages.push(...args.coreUserMessages);
2522
2527
  }
2523
2528
  const uiMessages = coreUserMessages.map(fromCoreUserMessageToUIMessage);
2524
- const signalId = mode === "stream" && args.threadId && !_threadSignalsUnsupportedRef.current ? uiMessages[0]?.id : void 0;
2529
+ const signalId = mode === "stream" && args.threadId && !_threadSignalsUnsupportedRef.current && !threadSignalsDisabled ? uiMessages[0]?.id : void 0;
2525
2530
  if (!signalId) {
2526
2531
  setMessages((s) => [...s, ...uiMessages]);
2527
2532
  }