@mastra/react 1.4.13-alpha.0 → 1.4.13-alpha.3

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.
@@ -1 +1 @@
1
- {"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../../src/agent/hooks.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAY,eAAe,EAA4B,MAAM,iCAAiC,CAAC;AAE3G,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;AAEnE,OAAO,KAAK,EAAE,SAAS,EAAiB,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAkBtF,OAAO,KAAK,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AA0I/D,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;;;;OAIG;IACH,WAAW,CAAC,EAAE,gBAAgB,CAAC;IAC/B,YAAY,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IAC3D,YAAY,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,CAAC;IAC1C,0BAA0B,CAAC,EAAE,MAAM,IAAI,CAAC;IACxC;;;OAGG;IACH,mBAAmB,CAAC,EAAE,OAAO,CAAC;CAC/B;AAED,UAAU,UAAU;IAClB,gBAAgB,EAAE,eAAe,EAAE,CAAC;IACpC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,cAAc,CA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AAC;IAC9C,WAAW,CAAC,EAAE,gBAAgB,CAAC;IAC/B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;;OAGG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG,UAAU,GAAG;IACrC,cAAc,CAAC,EAAE,CAAC,KAAK,EAAE,gBAAgB,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CAC7D,CAAC;AAoDF,eAAO,MAAM,OAAO,wMAWjB,eAAe;;qCAu8ByC,eAAe;;;;;;;;;;kCAnP7B,MAAM,eAAe,OAAO;kCAuE5B,MAAM;0CAoDE,MAAM;0CA2BN,MAAM;;;;oBAl1BvB,UAAU,GAAG,UAAU;;;uCA62BT,MAAM,UAAU,MAAM;uCAiCtB,MAAM,UAAU,MAAM;;;oBA34BtC,UAAU,GAAG,UAAU;;;CAg/BxD,CAAC"}
package/dist/index.cjs CHANGED
@@ -1796,7 +1796,7 @@ const extractRunIdFromMessages = (messages) => {
1796
1796
  };
1797
1797
  //#endregion
1798
1798
  //#region src/agent/hooks.ts
1799
- const extractPendingToolApprovalIdsFromMessages = (messages) => {
1799
+ const extractPendingToolApprovalIdsFromMessages = (messages, runId) => {
1800
1800
  const pendingToolApprovalIds = /* @__PURE__ */ new Set();
1801
1801
  for (const message of messages) {
1802
1802
  const metadata = message.content?.metadata;
@@ -1809,6 +1809,7 @@ const extractPendingToolApprovalIdsFromMessages = (messages) => {
1809
1809
  for (const source of metadataSources) {
1810
1810
  if (!source || typeof source !== "object") continue;
1811
1811
  for (const suspensionData of Object.values(source)) {
1812
+ if (runId && suspensionData?.runId !== runId) continue;
1812
1813
  const toolCallId = suspensionData?.toolCallId;
1813
1814
  if (typeof toolCallId === "string" && toolCallId.length > 0) pendingToolApprovalIds.add(toolCallId);
1814
1815
  }
@@ -1822,6 +1823,11 @@ const toolCallHasOutput = (parts, toolCallId) => parts.some((part) => {
1822
1823
  if (invocation.toolCallId !== toolCallId) return false;
1823
1824
  return invocation.state === "result" || invocation.result != null;
1824
1825
  });
1826
+ const filterUnresolvedApprovals = (entries, parts) => {
1827
+ if (!entries || typeof entries !== "object") return void 0;
1828
+ const pending = Object.fromEntries(Object.entries(entries).filter(([, approval]) => approval && typeof approval === "object" && typeof approval.toolCallId === "string" && !toolCallHasOutput(parts, approval.toolCallId)));
1829
+ return Object.keys(pending).length ? pending : void 0;
1830
+ };
1825
1831
  /**
1826
1832
  * Normalize persisted initial messages back into the stream-friendly shape the
1827
1833
  * UI renders from. Mirrors `main`'s `resolveInitialMessages`:
@@ -1851,22 +1857,25 @@ const resolveInitialMessages = (messages) => messages.filter((message) => {
1851
1857
  };
1852
1858
  })() : message;
1853
1859
  const normalizedMetadata = normalizedMessage.content?.metadata;
1854
- const pendingToolApprovals = normalizedMetadata?.pendingToolApprovals;
1855
- if (!pendingToolApprovals || typeof pendingToolApprovals !== "object") return normalizedMessage;
1856
- const stillPending = Object.fromEntries(Object.entries(pendingToolApprovals).filter(([, approval]) => approval && typeof approval === "object" && typeof approval.toolCallId === "string" && !toolCallHasOutput(normalizedMessage.content.parts, approval.toolCallId)));
1857
- const { pendingToolApprovals: _omit, ...restMetadata } = normalizedMetadata;
1858
- const hasStillPending = Object.keys(stillPending).length > 0;
1860
+ if (!normalizedMetadata?.pendingToolApprovals && !normalizedMetadata?.requireApprovalMetadata && !normalizedMetadata?.suspendedTools) return normalizedMessage;
1861
+ const { pendingToolApprovals, requireApprovalMetadata, suspendedTools, ...restMetadata } = normalizedMetadata;
1862
+ const parts = normalizedMessage.content.parts;
1863
+ const pending = filterUnresolvedApprovals(pendingToolApprovals, parts);
1864
+ const required = {
1865
+ ...filterUnresolvedApprovals(requireApprovalMetadata, parts),
1866
+ ...pending
1867
+ };
1868
+ const suspended = filterUnresolvedApprovals(suspendedTools, parts);
1859
1869
  return {
1860
1870
  ...normalizedMessage,
1861
1871
  content: {
1862
1872
  ...normalizedMessage.content,
1863
1873
  metadata: {
1864
1874
  ...restMetadata,
1865
- mode: "stream",
1866
- ...hasStillPending ? {
1867
- pendingToolApprovals: stillPending,
1868
- requireApprovalMetadata: stillPending
1869
- } : {}
1875
+ ...pendingToolApprovals ? { mode: "stream" } : {},
1876
+ ...pending ? { pendingToolApprovals: pending } : {},
1877
+ ...Object.keys(required).length ? { requireApprovalMetadata: required } : {},
1878
+ ...suspended ? { suspendedTools: suspended } : {}
1870
1879
  }
1871
1880
  }
1872
1881
  };
@@ -1915,20 +1924,64 @@ const useChat = ({ agentId, resourceId, threadId, initialMessages, requestContex
1915
1924
  const _threadSignalsUnsupportedRef = (0, react.useRef)(false);
1916
1925
  const [messages, setMessages] = (0, react.useState)([]);
1917
1926
  const [tasks, setTasks] = (0, react.useState)([]);
1927
+ const liveTasks = (0, react.useRef)(void 0);
1918
1928
  const [toolCallApprovals, setToolCallApprovals] = (0, react.useState)({});
1919
1929
  const [networkToolCallApprovals, setNetworkToolCallApprovals] = (0, react.useState)({});
1920
1930
  const pendingToolApprovalIdsRef = (0, react.useRef)(/* @__PURE__ */ new Set());
1931
+ const liveApprovalIds = (0, react.useRef)(/* @__PURE__ */ new Set());
1932
+ const liveRunId = (0, react.useRef)(void 0);
1933
+ const liveRunFinished = (0, react.useRef)(false);
1921
1934
  const [isAwaitingToolApproval, setIsAwaitingToolApproval] = (0, react.useState)(false);
1922
1935
  const baseClient = useMastraClient();
1923
1936
  const [isRunning, setIsRunning] = (0, react.useState)(false);
1937
+ const lastHydration = (0, react.useRef)(void 0);
1924
1938
  (0, react.useEffect)(() => {
1939
+ const previous = lastHydration.current;
1940
+ const sameThread = previous?.agentId === agentId && previous.resourceId === resourceId && previous.threadId === threadId;
1941
+ if (sameThread && previous.initialMessages === initialMessages) return;
1925
1942
  const formattedMessages = resolveInitialMessages(initialMessages ?? []);
1926
- setMessages(formattedMessages);
1927
- setTasks(extractLatestTasksFromMessages(formattedMessages));
1928
- pendingToolApprovalIdsRef.current = extractPendingToolApprovalIdsFromMessages(formattedMessages);
1929
- setIsAwaitingToolApproval(pendingToolApprovalIdsRef.current.size > 0);
1930
- _currentRunId.current = extractRunIdFromMessages(formattedMessages);
1931
- }, [initialMessages]);
1943
+ lastHydration.current = {
1944
+ agentId,
1945
+ resourceId,
1946
+ threadId,
1947
+ initialMessages,
1948
+ formattedMessages
1949
+ };
1950
+ if (sameThread) {
1951
+ const previousById = new Map(previous.formattedMessages.map((message) => [message.id, message]));
1952
+ setMessages((current) => {
1953
+ const live = current.filter((message) => previousById.get(message.id) !== message);
1954
+ const liveById = new Map(live.map((message) => [message.id, message]));
1955
+ const historyIds = new Set(formattedMessages.map((message) => message.id));
1956
+ return [...formattedMessages.map((message) => liveById.get(message.id) ?? message), ...live.filter((message) => !historyIds.has(message.id))];
1957
+ });
1958
+ setTasks(liveTasks.current ?? extractLatestTasksFromMessages(formattedMessages));
1959
+ const historyRunId = extractRunIdFromMessages(formattedMessages);
1960
+ if (liveRunFinished.current) return;
1961
+ if (!liveRunId.current && isRunning && historyRunId !== _currentRunId.current) return;
1962
+ } else {
1963
+ liveTasks.current = void 0;
1964
+ liveApprovalIds.current.clear();
1965
+ liveRunId.current = void 0;
1966
+ liveRunFinished.current = false;
1967
+ if (previous) setIsRunning(false);
1968
+ setMessages(formattedMessages);
1969
+ setTasks(extractLatestTasksFromMessages(formattedMessages));
1970
+ }
1971
+ const pendingApprovals = extractPendingToolApprovalIdsFromMessages(formattedMessages, liveRunId.current);
1972
+ for (const toolCallId of liveApprovalIds.current) if (pendingToolApprovalIdsRef.current.has(toolCallId)) pendingApprovals.add(toolCallId);
1973
+ else pendingApprovals.delete(toolCallId);
1974
+ pendingToolApprovalIdsRef.current = pendingApprovals;
1975
+ setIsAwaitingToolApproval(pendingApprovals.size > 0);
1976
+ _currentRunId.current = liveRunId.current ?? extractRunIdFromMessages(formattedMessages);
1977
+ }, [
1978
+ agentId,
1979
+ resourceId,
1980
+ threadId,
1981
+ initialMessages,
1982
+ isRunning,
1983
+ isAwaitingToolApproval
1984
+ ]);
1932
1985
  (0, react.useEffect)(() => {
1933
1986
  _activeContinuation.current = {
1934
1987
  ..._activeContinuation.current,
@@ -1991,29 +2044,40 @@ const useChat = ({ agentId, resourceId, threadId, initialMessages, requestContex
1991
2044
  _threadSubscriptionPromiseRef.current = null;
1992
2045
  }, []);
1993
2046
  const processStreamChunk = (0, react.useCallback)(async (chunk, onChunk) => {
2047
+ const isTerminal = chunk.type === "finish" || chunk.type === "abort" || chunk.type === "error";
2048
+ if (isTerminal && liveRunId.current && chunk.runId !== liveRunId.current) return;
1994
2049
  setMessages((prev) => accumulateChunk({
1995
2050
  chunk,
1996
2051
  conversation: prev,
1997
2052
  metadata: { mode: "stream" }
1998
2053
  }));
1999
- const signalTasks = extractTasksFromSignalChunk(chunk);
2000
- if (signalTasks !== void 0) setTasks(signalTasks);
2001
- const toolTasks = extractTasksFromToolResultChunk(chunk);
2002
- if (toolTasks !== void 0) setTasks(toolTasks);
2054
+ const streamedTasks = extractTasksFromToolResultChunk(chunk) ?? extractTasksFromSignalChunk(chunk);
2055
+ if (streamedTasks !== void 0) {
2056
+ liveTasks.current = streamedTasks;
2057
+ setTasks(streamedTasks);
2058
+ }
2003
2059
  if (chunk.type === "data-user-message" && isDataChunk(chunk) && (chunk.data?.type === "user-message" || chunk.data?.type === "user") && typeof chunk.data?.id === "string") onSignalEcho?.(chunk.data.id);
2004
2060
  if (chunk.type === "start") {
2005
2061
  setIsRunning(true);
2006
- if ("runId" in chunk && typeof chunk.runId === "string") _currentRunId.current = chunk.runId;
2062
+ if ("runId" in chunk && typeof chunk.runId === "string") {
2063
+ if (liveRunId.current !== chunk.runId) liveApprovalIds.current.clear();
2064
+ liveRunFinished.current = false;
2065
+ liveRunId.current = chunk.runId;
2066
+ _currentRunId.current = chunk.runId;
2067
+ }
2007
2068
  }
2008
2069
  if (chunk.type === "tool-call-approval" || chunk.type === "tool-call-suspended") {
2009
2070
  const toolCallId = chunk.payload?.toolCallId;
2010
2071
  if (typeof toolCallId === "string") {
2072
+ liveApprovalIds.current.add(toolCallId);
2011
2073
  pendingToolApprovalIdsRef.current.add(toolCallId);
2012
2074
  setIsAwaitingToolApproval(true);
2013
2075
  }
2014
2076
  setIsRunning(false);
2015
2077
  }
2016
- if (chunk.type === "finish" || chunk.type === "abort" || chunk.type === "error") {
2078
+ if (isTerminal) {
2079
+ if (chunk.runId === liveRunId.current) liveRunFinished.current = true;
2080
+ for (const toolCallId of pendingToolApprovalIdsRef.current) liveApprovalIds.current.add(toolCallId);
2017
2081
  pendingToolApprovalIdsRef.current.clear();
2018
2082
  setIsAwaitingToolApproval(false);
2019
2083
  setIsRunning(false);
@@ -2294,30 +2358,28 @@ const useChat = ({ agentId, resourceId, threadId, initialMessages, requestContex
2294
2358
  onSignalSent?.(echoedSignalId, getSignalPreview(coreUserMessages));
2295
2359
  if (pendingToolApprovalIdsRef.current.size > 0) setIsRunning(false);
2296
2360
  } catch (error) {
2297
- if (isThreadSignalUnsupportedError(error)) {
2361
+ if (isThreadSignalUnsupportedError(error)) try {
2362
+ await agent.sendSignal({
2363
+ signal: {
2364
+ id: resolvedSignalId,
2365
+ type: "user-message",
2366
+ contents: messageContents
2367
+ },
2368
+ resourceId: resourceId || agentId,
2369
+ threadId,
2370
+ ifIdle: { streamOptions }
2371
+ });
2298
2372
  onSignalSent?.(resolvedSignalId, getSignalPreview(coreUserMessages));
2299
- try {
2300
- await agent.sendSignal({
2301
- signal: {
2302
- id: resolvedSignalId,
2303
- type: "user-message",
2304
- contents: messageContents
2305
- },
2306
- resourceId: resourceId || agentId,
2307
- threadId,
2308
- ifIdle: { streamOptions }
2309
- });
2373
+ return;
2374
+ } catch (signalError) {
2375
+ onSignalEcho?.(resolvedSignalId);
2376
+ if (isThreadSignalUnsupportedError(signalError)) {
2377
+ markThreadSignalsUnsupported();
2378
+ setMessages((prev) => [...prev, fromCoreUserMessagesToMastraDBMessage(coreUserMessages)]);
2379
+ await streamWithLegacyRoute();
2310
2380
  return;
2311
- } catch (signalError) {
2312
- onSignalEcho?.(resolvedSignalId);
2313
- if (isThreadSignalUnsupportedError(signalError)) {
2314
- markThreadSignalsUnsupported();
2315
- setMessages((prev) => [...prev, fromCoreUserMessagesToMastraDBMessage(coreUserMessages)]);
2316
- await streamWithLegacyRoute();
2317
- return;
2318
- }
2319
- throw signalError;
2320
2381
  }
2382
+ throw signalError;
2321
2383
  }
2322
2384
  throw error;
2323
2385
  }
@@ -2378,6 +2440,7 @@ const useChat = ({ agentId, resourceId, threadId, initialMessages, requestContex
2378
2440
  });
2379
2441
  closeThreadSubscription();
2380
2442
  setMessages((prev) => finishStreamingAssistantMessage(prev));
2443
+ liveRunFinished.current = true;
2381
2444
  pendingToolApprovalIdsRef.current.clear();
2382
2445
  setIsAwaitingToolApproval(false);
2383
2446
  setIsRunning(false);
@@ -2409,6 +2472,8 @@ const useChat = ({ agentId, resourceId, threadId, initialMessages, requestContex
2409
2472
  ...resumeData !== void 0 ? { resumeData } : {},
2410
2473
  requestContext: continuation.requestContext
2411
2474
  });
2475
+ liveRunId.current ??= currentRunId;
2476
+ liveApprovalIds.current.add(toolCallId);
2412
2477
  pendingToolApprovalIdsRef.current.delete(toolCallId);
2413
2478
  setIsAwaitingToolApproval(pendingToolApprovalIdsRef.current.size > 0);
2414
2479
  setIsRunning(false);
@@ -2467,6 +2532,8 @@ const useChat = ({ agentId, resourceId, threadId, initialMessages, requestContex
2467
2532
  ...continuation.model !== void 0 ? { streamOptions: { model: continuation.model } } : {},
2468
2533
  requestContext: continuation.requestContext
2469
2534
  });
2535
+ liveRunId.current ??= currentRunId;
2536
+ liveApprovalIds.current.add(toolCallId);
2470
2537
  pendingToolApprovalIdsRef.current.delete(toolCallId);
2471
2538
  setIsAwaitingToolApproval(pendingToolApprovalIdsRef.current.size > 0);
2472
2539
  setIsRunning(false);