@mastra/react 0.2.18-alpha.7 → 0.2.18-alpha.8
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 +10 -0
- package/dist/agent/hooks.d.ts +3 -1
- package/dist/agent/hooks.d.ts.map +1 -1
- package/dist/index.cjs +48 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +48 -10
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
package/dist/index.js
CHANGED
|
@@ -1688,11 +1688,17 @@ var extractRunIdFromMessages = (messages) => {
|
|
|
1688
1688
|
}
|
|
1689
1689
|
return void 0;
|
|
1690
1690
|
};
|
|
1691
|
-
var useChat = ({
|
|
1691
|
+
var useChat = ({
|
|
1692
|
+
agentId,
|
|
1693
|
+
resourceId,
|
|
1694
|
+
initialMessages,
|
|
1695
|
+
requestContext: propsRequestContext
|
|
1696
|
+
}) => {
|
|
1692
1697
|
const _currentRunId = useRef(void 0);
|
|
1693
1698
|
const _onChunk = useRef(void 0);
|
|
1694
1699
|
const _networkRunId = useRef(void 0);
|
|
1695
1700
|
const _onNetworkChunk = useRef(void 0);
|
|
1701
|
+
const _requestContext = useRef(propsRequestContext);
|
|
1696
1702
|
const [messages, setMessages] = useState([]);
|
|
1697
1703
|
const [toolCallApprovals, setToolCallApprovals] = useState({});
|
|
1698
1704
|
const [networkToolCallApprovals, setNetworkToolCallApprovals] = useState({});
|
|
@@ -1703,6 +1709,9 @@ var useChat = ({ agentId, resourceId, initialMessages }) => {
|
|
|
1703
1709
|
setMessages(formattedMessages);
|
|
1704
1710
|
_currentRunId.current = extractRunIdFromMessages(formattedMessages);
|
|
1705
1711
|
}, [initialMessages]);
|
|
1712
|
+
useEffect(() => {
|
|
1713
|
+
_requestContext.current = propsRequestContext;
|
|
1714
|
+
}, [propsRequestContext]);
|
|
1706
1715
|
const generate = async ({
|
|
1707
1716
|
coreUserMessages,
|
|
1708
1717
|
requestContext,
|
|
@@ -1725,6 +1734,8 @@ var useChat = ({ agentId, resourceId, initialMessages }) => {
|
|
|
1725
1734
|
maxSteps,
|
|
1726
1735
|
requireToolApproval
|
|
1727
1736
|
} = modelSettings || {};
|
|
1737
|
+
const resolvedRequestContext = requestContext ?? propsRequestContext;
|
|
1738
|
+
_requestContext.current = resolvedRequestContext;
|
|
1728
1739
|
setIsRunning(true);
|
|
1729
1740
|
const clientWithAbort = new MastraClient({
|
|
1730
1741
|
...baseClient.options,
|
|
@@ -1746,7 +1757,7 @@ var useChat = ({ agentId, resourceId, initialMessages }) => {
|
|
|
1746
1757
|
topP
|
|
1747
1758
|
},
|
|
1748
1759
|
instructions,
|
|
1749
|
-
requestContext,
|
|
1760
|
+
requestContext: resolvedRequestContext,
|
|
1750
1761
|
...threadId ? { memory: { thread: threadId, resource: resourceId || agentId } } : {},
|
|
1751
1762
|
providerOptions,
|
|
1752
1763
|
tracingOptions,
|
|
@@ -1807,6 +1818,8 @@ var useChat = ({ agentId, resourceId, initialMessages }) => {
|
|
|
1807
1818
|
maxSteps,
|
|
1808
1819
|
requireToolApproval
|
|
1809
1820
|
} = modelSettings || {};
|
|
1821
|
+
const resolvedRequestContext = requestContext ?? propsRequestContext;
|
|
1822
|
+
_requestContext.current = resolvedRequestContext;
|
|
1810
1823
|
setIsRunning(true);
|
|
1811
1824
|
const clientWithAbort = new MastraClient({
|
|
1812
1825
|
...baseClient.options,
|
|
@@ -1827,7 +1840,7 @@ var useChat = ({ agentId, resourceId, initialMessages }) => {
|
|
|
1827
1840
|
topP
|
|
1828
1841
|
},
|
|
1829
1842
|
instructions,
|
|
1830
|
-
requestContext,
|
|
1843
|
+
requestContext: resolvedRequestContext,
|
|
1831
1844
|
...threadId ? { memory: { thread: threadId, resource: resourceId || agentId } } : {},
|
|
1832
1845
|
providerOptions,
|
|
1833
1846
|
requireToolApproval,
|
|
@@ -1853,6 +1866,8 @@ var useChat = ({ agentId, resourceId, initialMessages }) => {
|
|
|
1853
1866
|
tracingOptions
|
|
1854
1867
|
}) => {
|
|
1855
1868
|
const { frequencyPenalty, presencePenalty, maxRetries, maxTokens, temperature, topK, topP, maxSteps } = modelSettings || {};
|
|
1869
|
+
const resolvedRequestContext = requestContext ?? propsRequestContext;
|
|
1870
|
+
_requestContext.current = resolvedRequestContext;
|
|
1856
1871
|
setIsRunning(true);
|
|
1857
1872
|
const clientWithAbort = new MastraClient({
|
|
1858
1873
|
...baseClient.options,
|
|
@@ -1872,7 +1887,7 @@ var useChat = ({ agentId, resourceId, initialMessages }) => {
|
|
|
1872
1887
|
topP
|
|
1873
1888
|
},
|
|
1874
1889
|
runId,
|
|
1875
|
-
requestContext,
|
|
1890
|
+
requestContext: resolvedRequestContext,
|
|
1876
1891
|
...threadId ? { memory: { thread: threadId, resource: resourceId || agentId } } : {},
|
|
1877
1892
|
tracingOptions
|
|
1878
1893
|
});
|
|
@@ -1893,6 +1908,7 @@ var useChat = ({ agentId, resourceId, initialMessages }) => {
|
|
|
1893
1908
|
_onChunk.current = void 0;
|
|
1894
1909
|
_networkRunId.current = void 0;
|
|
1895
1910
|
_onNetworkChunk.current = void 0;
|
|
1911
|
+
_requestContext.current = void 0;
|
|
1896
1912
|
};
|
|
1897
1913
|
const approveToolCall = async (toolCallId) => {
|
|
1898
1914
|
const onChunk = _onChunk.current;
|
|
@@ -1902,7 +1918,11 @@ var useChat = ({ agentId, resourceId, initialMessages }) => {
|
|
|
1902
1918
|
setIsRunning(true);
|
|
1903
1919
|
setToolCallApprovals((prev) => ({ ...prev, [toolCallId]: { status: "approved" } }));
|
|
1904
1920
|
const agent = baseClient.getAgent(agentId);
|
|
1905
|
-
const response = await agent.approveToolCall({
|
|
1921
|
+
const response = await agent.approveToolCall({
|
|
1922
|
+
runId: currentRunId,
|
|
1923
|
+
toolCallId,
|
|
1924
|
+
requestContext: _requestContext.current
|
|
1925
|
+
});
|
|
1906
1926
|
await response.processDataStream({
|
|
1907
1927
|
onChunk: async (chunk) => {
|
|
1908
1928
|
setMessages((prev) => toUIMessage({ chunk, conversation: prev, metadata: { mode: "stream" } }));
|
|
@@ -1919,7 +1939,11 @@ var useChat = ({ agentId, resourceId, initialMessages }) => {
|
|
|
1919
1939
|
setIsRunning(true);
|
|
1920
1940
|
setToolCallApprovals((prev) => ({ ...prev, [toolCallId]: { status: "declined" } }));
|
|
1921
1941
|
const agent = baseClient.getAgent(agentId);
|
|
1922
|
-
const response = await agent.declineToolCall({
|
|
1942
|
+
const response = await agent.declineToolCall({
|
|
1943
|
+
runId: currentRunId,
|
|
1944
|
+
toolCallId,
|
|
1945
|
+
requestContext: _requestContext.current
|
|
1946
|
+
});
|
|
1923
1947
|
await response.processDataStream({
|
|
1924
1948
|
onChunk: async (chunk) => {
|
|
1925
1949
|
setMessages((prev) => toUIMessage({ chunk, conversation: prev, metadata: { mode: "stream" } }));
|
|
@@ -1937,7 +1961,11 @@ var useChat = ({ agentId, resourceId, initialMessages }) => {
|
|
|
1937
1961
|
setIsRunning(true);
|
|
1938
1962
|
setToolCallApprovals((prev) => ({ ...prev, [toolCallId]: { status: "approved" } }));
|
|
1939
1963
|
const agent = baseClient.getAgent(agentId);
|
|
1940
|
-
const response = await agent.approveToolCallGenerate({
|
|
1964
|
+
const response = await agent.approveToolCallGenerate({
|
|
1965
|
+
runId: currentRunId,
|
|
1966
|
+
toolCallId,
|
|
1967
|
+
requestContext: _requestContext.current
|
|
1968
|
+
});
|
|
1941
1969
|
if (response && "uiMessages" in response.response && response.response.uiMessages) {
|
|
1942
1970
|
const mastraUIMessages = (response.response.uiMessages || []).map((message) => ({
|
|
1943
1971
|
...message,
|
|
@@ -1958,7 +1986,11 @@ var useChat = ({ agentId, resourceId, initialMessages }) => {
|
|
|
1958
1986
|
setIsRunning(true);
|
|
1959
1987
|
setToolCallApprovals((prev) => ({ ...prev, [toolCallId]: { status: "declined" } }));
|
|
1960
1988
|
const agent = baseClient.getAgent(agentId);
|
|
1961
|
-
const response = await agent.declineToolCallGenerate({
|
|
1989
|
+
const response = await agent.declineToolCallGenerate({
|
|
1990
|
+
runId: currentRunId,
|
|
1991
|
+
toolCallId,
|
|
1992
|
+
requestContext: _requestContext.current
|
|
1993
|
+
});
|
|
1962
1994
|
if (response && "uiMessages" in response.response && response.response.uiMessages) {
|
|
1963
1995
|
const mastraUIMessages = (response.response.uiMessages || []).map((message) => ({
|
|
1964
1996
|
...message,
|
|
@@ -1983,7 +2015,10 @@ var useChat = ({ agentId, resourceId, initialMessages }) => {
|
|
|
1983
2015
|
[runId ? `${runId}-${toolName}` : toolName]: { status: "approved" }
|
|
1984
2016
|
}));
|
|
1985
2017
|
const agent = baseClient.getAgent(agentId);
|
|
1986
|
-
const response = await agent.approveNetworkToolCall({
|
|
2018
|
+
const response = await agent.approveNetworkToolCall({
|
|
2019
|
+
runId: networkRunId,
|
|
2020
|
+
requestContext: _requestContext.current
|
|
2021
|
+
});
|
|
1987
2022
|
const transformer = new AISdkNetworkTransformer();
|
|
1988
2023
|
await response.processDataStream({
|
|
1989
2024
|
onChunk: async (chunk) => {
|
|
@@ -2006,7 +2041,10 @@ var useChat = ({ agentId, resourceId, initialMessages }) => {
|
|
|
2006
2041
|
[runId ? `${runId}-${toolName}` : toolName]: { status: "declined" }
|
|
2007
2042
|
}));
|
|
2008
2043
|
const agent = baseClient.getAgent(agentId);
|
|
2009
|
-
const response = await agent.declineNetworkToolCall({
|
|
2044
|
+
const response = await agent.declineNetworkToolCall({
|
|
2045
|
+
runId: networkRunId,
|
|
2046
|
+
requestContext: _requestContext.current
|
|
2047
|
+
});
|
|
2010
2048
|
const transformer = new AISdkNetworkTransformer();
|
|
2011
2049
|
await response.processDataStream({
|
|
2012
2050
|
onChunk: async (chunk) => {
|