@mastra/react 0.2.18-alpha.6 → 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 +18 -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 +6 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# @mastra/react
|
|
2
2
|
|
|
3
|
+
## 0.2.18-alpha.8
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Added requestContext support to tool approval and decline methods, ensuring agent version context is preserved when resuming after tool approval. ([#14847](https://github.com/mastra-ai/mastra/pull/14847))
|
|
8
|
+
|
|
9
|
+
- Updated dependencies [[`12c647c`](https://github.com/mastra-ai/mastra/commit/12c647cf3a26826eb72d40b42e3c8356ceae16ed), [`12c647c`](https://github.com/mastra-ai/mastra/commit/12c647cf3a26826eb72d40b42e3c8356ceae16ed), [`819f03c`](https://github.com/mastra-ai/mastra/commit/819f03c25823373b32476413bd76be28a5d8705a), [`819f03c`](https://github.com/mastra-ai/mastra/commit/819f03c25823373b32476413bd76be28a5d8705a)]:
|
|
10
|
+
- @mastra/client-js@1.11.0-alpha.8
|
|
11
|
+
- @mastra/core@1.18.0-alpha.5
|
|
12
|
+
|
|
13
|
+
## 0.2.18-alpha.7
|
|
14
|
+
|
|
15
|
+
### Patch Changes
|
|
16
|
+
|
|
17
|
+
- Updated dependencies [[`fbf22a7`](https://github.com/mastra-ai/mastra/commit/fbf22a7ad86bcb50dcf30459f0d075e51ddeb468), [`fbf22a7`](https://github.com/mastra-ai/mastra/commit/fbf22a7ad86bcb50dcf30459f0d075e51ddeb468), [`04160ee`](https://github.com/mastra-ai/mastra/commit/04160eedf3130003cf842ad08428c8ff69af4cc1), [`2c27503`](https://github.com/mastra-ai/mastra/commit/2c275032510d131d2cde47f99953abf0fe02c081), [`424a1df`](https://github.com/mastra-ai/mastra/commit/424a1df7bee59abb5c83717a54807fdd674a6224), [`12c88a6`](https://github.com/mastra-ai/mastra/commit/12c88a6e32bf982c2fe0c6af62e65a3414519a75), [`43595bf`](https://github.com/mastra-ai/mastra/commit/43595bf7b8df1a6edce7a23b445b5124d2a0b473), [`78670e9`](https://github.com/mastra-ai/mastra/commit/78670e97e76d7422cf7025faf371b2aeafed860d), [`d400e7c`](https://github.com/mastra-ai/mastra/commit/d400e7c8b8d7afa6ba2c71769eace4048e3cef8e), [`f58d1a7`](https://github.com/mastra-ai/mastra/commit/f58d1a7a457588a996c3ecb53201a68f3d28c432), [`a49a929`](https://github.com/mastra-ai/mastra/commit/a49a92904968b4fc67e01effee8c7c8d0464ba85)]:
|
|
18
|
+
- @mastra/core@1.18.0-alpha.4
|
|
19
|
+
- @mastra/client-js@1.11.0-alpha.7
|
|
20
|
+
|
|
3
21
|
## 0.2.18-alpha.6
|
|
4
22
|
|
|
5
23
|
### Patch Changes
|
package/dist/agent/hooks.d.ts
CHANGED
|
@@ -9,6 +9,8 @@ export interface MastraChatProps {
|
|
|
9
9
|
agentId: string;
|
|
10
10
|
resourceId?: string;
|
|
11
11
|
initialMessages?: MastraUIMessage[];
|
|
12
|
+
/** Persistent request context used for tool approval/decline calls (e.g. agentVersionId). */
|
|
13
|
+
requestContext?: RequestContext;
|
|
12
14
|
}
|
|
13
15
|
interface SharedArgs {
|
|
14
16
|
coreUserMessages: CoreUserMessage[];
|
|
@@ -39,7 +41,7 @@ export type StreamArgs = SharedArgs & {
|
|
|
39
41
|
export type NetworkArgs = SharedArgs & {
|
|
40
42
|
onNetworkChunk?: (chunk: NetworkChunkType) => Promise<void>;
|
|
41
43
|
};
|
|
42
|
-
export declare const useChat: ({ agentId, resourceId, initialMessages }: MastraChatProps) => {
|
|
44
|
+
export declare const useChat: ({ agentId, resourceId, initialMessages, requestContext: propsRequestContext, }: MastraChatProps) => {
|
|
43
45
|
setMessages: import("react").Dispatch<import("react").SetStateAction<MastraUIMessage[]>>;
|
|
44
46
|
sendMessage: ({ mode, ...args }: SendMessageArgs) => Promise<void>;
|
|
45
47
|
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;AAG/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,EAA2B,eAAe,EAAE,MAAM,eAAe,CAAC;AAC9E,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAO7C,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,eAAe,CAAC,EAAE,eAAe,EAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../../src/agent/hooks.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAG/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,EAA2B,eA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AAU,GAAG;IACpC,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,SAAS,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CAC/C,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG,UAAU,GAAG;IACrC,cAAc,CAAC,EAAE,CAAC,KAAK,EAAE,gBAAgB,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CAC7D,CAAC;AAgBF,eAAO,MAAM,OAAO,GAAI,gFAKrB,eAAe;;qCA0cyC,eAAe;;;kCA3L7B,MAAM;kCA6BN,MAAM;0CA4BE,MAAM;0CAgCN,MAAM;;;;oBAhWvB,UAAU,GAAG,UAAU;;;uCAgYT,MAAM,UAAU,MAAM;uCAiCtB,MAAM,UAAU,MAAM;;;oBA9ZtC,UAAU,GAAG,UAAU;;;CAkexD,CAAC"}
|
package/dist/index.cjs
CHANGED
|
@@ -1690,11 +1690,17 @@ var extractRunIdFromMessages = (messages) => {
|
|
|
1690
1690
|
}
|
|
1691
1691
|
return void 0;
|
|
1692
1692
|
};
|
|
1693
|
-
var useChat = ({
|
|
1693
|
+
var useChat = ({
|
|
1694
|
+
agentId,
|
|
1695
|
+
resourceId,
|
|
1696
|
+
initialMessages,
|
|
1697
|
+
requestContext: propsRequestContext
|
|
1698
|
+
}) => {
|
|
1694
1699
|
const _currentRunId = react.useRef(void 0);
|
|
1695
1700
|
const _onChunk = react.useRef(void 0);
|
|
1696
1701
|
const _networkRunId = react.useRef(void 0);
|
|
1697
1702
|
const _onNetworkChunk = react.useRef(void 0);
|
|
1703
|
+
const _requestContext = react.useRef(propsRequestContext);
|
|
1698
1704
|
const [messages, setMessages] = react.useState([]);
|
|
1699
1705
|
const [toolCallApprovals, setToolCallApprovals] = react.useState({});
|
|
1700
1706
|
const [networkToolCallApprovals, setNetworkToolCallApprovals] = react.useState({});
|
|
@@ -1705,6 +1711,9 @@ var useChat = ({ agentId, resourceId, initialMessages }) => {
|
|
|
1705
1711
|
setMessages(formattedMessages);
|
|
1706
1712
|
_currentRunId.current = extractRunIdFromMessages(formattedMessages);
|
|
1707
1713
|
}, [initialMessages]);
|
|
1714
|
+
react.useEffect(() => {
|
|
1715
|
+
_requestContext.current = propsRequestContext;
|
|
1716
|
+
}, [propsRequestContext]);
|
|
1708
1717
|
const generate = async ({
|
|
1709
1718
|
coreUserMessages,
|
|
1710
1719
|
requestContext,
|
|
@@ -1727,6 +1736,8 @@ var useChat = ({ agentId, resourceId, initialMessages }) => {
|
|
|
1727
1736
|
maxSteps,
|
|
1728
1737
|
requireToolApproval
|
|
1729
1738
|
} = modelSettings || {};
|
|
1739
|
+
const resolvedRequestContext = requestContext ?? propsRequestContext;
|
|
1740
|
+
_requestContext.current = resolvedRequestContext;
|
|
1730
1741
|
setIsRunning(true);
|
|
1731
1742
|
const clientWithAbort = new clientJs.MastraClient({
|
|
1732
1743
|
...baseClient.options,
|
|
@@ -1748,7 +1759,7 @@ var useChat = ({ agentId, resourceId, initialMessages }) => {
|
|
|
1748
1759
|
topP
|
|
1749
1760
|
},
|
|
1750
1761
|
instructions,
|
|
1751
|
-
requestContext,
|
|
1762
|
+
requestContext: resolvedRequestContext,
|
|
1752
1763
|
...threadId ? { memory: { thread: threadId, resource: resourceId || agentId } } : {},
|
|
1753
1764
|
providerOptions,
|
|
1754
1765
|
tracingOptions,
|
|
@@ -1809,6 +1820,8 @@ var useChat = ({ agentId, resourceId, initialMessages }) => {
|
|
|
1809
1820
|
maxSteps,
|
|
1810
1821
|
requireToolApproval
|
|
1811
1822
|
} = modelSettings || {};
|
|
1823
|
+
const resolvedRequestContext = requestContext ?? propsRequestContext;
|
|
1824
|
+
_requestContext.current = resolvedRequestContext;
|
|
1812
1825
|
setIsRunning(true);
|
|
1813
1826
|
const clientWithAbort = new clientJs.MastraClient({
|
|
1814
1827
|
...baseClient.options,
|
|
@@ -1829,7 +1842,7 @@ var useChat = ({ agentId, resourceId, initialMessages }) => {
|
|
|
1829
1842
|
topP
|
|
1830
1843
|
},
|
|
1831
1844
|
instructions,
|
|
1832
|
-
requestContext,
|
|
1845
|
+
requestContext: resolvedRequestContext,
|
|
1833
1846
|
...threadId ? { memory: { thread: threadId, resource: resourceId || agentId } } : {},
|
|
1834
1847
|
providerOptions,
|
|
1835
1848
|
requireToolApproval,
|
|
@@ -1855,6 +1868,8 @@ var useChat = ({ agentId, resourceId, initialMessages }) => {
|
|
|
1855
1868
|
tracingOptions
|
|
1856
1869
|
}) => {
|
|
1857
1870
|
const { frequencyPenalty, presencePenalty, maxRetries, maxTokens, temperature, topK, topP, maxSteps } = modelSettings || {};
|
|
1871
|
+
const resolvedRequestContext = requestContext ?? propsRequestContext;
|
|
1872
|
+
_requestContext.current = resolvedRequestContext;
|
|
1858
1873
|
setIsRunning(true);
|
|
1859
1874
|
const clientWithAbort = new clientJs.MastraClient({
|
|
1860
1875
|
...baseClient.options,
|
|
@@ -1874,7 +1889,7 @@ var useChat = ({ agentId, resourceId, initialMessages }) => {
|
|
|
1874
1889
|
topP
|
|
1875
1890
|
},
|
|
1876
1891
|
runId,
|
|
1877
|
-
requestContext,
|
|
1892
|
+
requestContext: resolvedRequestContext,
|
|
1878
1893
|
...threadId ? { memory: { thread: threadId, resource: resourceId || agentId } } : {},
|
|
1879
1894
|
tracingOptions
|
|
1880
1895
|
});
|
|
@@ -1895,6 +1910,7 @@ var useChat = ({ agentId, resourceId, initialMessages }) => {
|
|
|
1895
1910
|
_onChunk.current = void 0;
|
|
1896
1911
|
_networkRunId.current = void 0;
|
|
1897
1912
|
_onNetworkChunk.current = void 0;
|
|
1913
|
+
_requestContext.current = void 0;
|
|
1898
1914
|
};
|
|
1899
1915
|
const approveToolCall = async (toolCallId) => {
|
|
1900
1916
|
const onChunk = _onChunk.current;
|
|
@@ -1904,7 +1920,11 @@ var useChat = ({ agentId, resourceId, initialMessages }) => {
|
|
|
1904
1920
|
setIsRunning(true);
|
|
1905
1921
|
setToolCallApprovals((prev) => ({ ...prev, [toolCallId]: { status: "approved" } }));
|
|
1906
1922
|
const agent = baseClient.getAgent(agentId);
|
|
1907
|
-
const response = await agent.approveToolCall({
|
|
1923
|
+
const response = await agent.approveToolCall({
|
|
1924
|
+
runId: currentRunId,
|
|
1925
|
+
toolCallId,
|
|
1926
|
+
requestContext: _requestContext.current
|
|
1927
|
+
});
|
|
1908
1928
|
await response.processDataStream({
|
|
1909
1929
|
onChunk: async (chunk) => {
|
|
1910
1930
|
setMessages((prev) => toUIMessage({ chunk, conversation: prev, metadata: { mode: "stream" } }));
|
|
@@ -1921,7 +1941,11 @@ var useChat = ({ agentId, resourceId, initialMessages }) => {
|
|
|
1921
1941
|
setIsRunning(true);
|
|
1922
1942
|
setToolCallApprovals((prev) => ({ ...prev, [toolCallId]: { status: "declined" } }));
|
|
1923
1943
|
const agent = baseClient.getAgent(agentId);
|
|
1924
|
-
const response = await agent.declineToolCall({
|
|
1944
|
+
const response = await agent.declineToolCall({
|
|
1945
|
+
runId: currentRunId,
|
|
1946
|
+
toolCallId,
|
|
1947
|
+
requestContext: _requestContext.current
|
|
1948
|
+
});
|
|
1925
1949
|
await response.processDataStream({
|
|
1926
1950
|
onChunk: async (chunk) => {
|
|
1927
1951
|
setMessages((prev) => toUIMessage({ chunk, conversation: prev, metadata: { mode: "stream" } }));
|
|
@@ -1939,7 +1963,11 @@ var useChat = ({ agentId, resourceId, initialMessages }) => {
|
|
|
1939
1963
|
setIsRunning(true);
|
|
1940
1964
|
setToolCallApprovals((prev) => ({ ...prev, [toolCallId]: { status: "approved" } }));
|
|
1941
1965
|
const agent = baseClient.getAgent(agentId);
|
|
1942
|
-
const response = await agent.approveToolCallGenerate({
|
|
1966
|
+
const response = await agent.approveToolCallGenerate({
|
|
1967
|
+
runId: currentRunId,
|
|
1968
|
+
toolCallId,
|
|
1969
|
+
requestContext: _requestContext.current
|
|
1970
|
+
});
|
|
1943
1971
|
if (response && "uiMessages" in response.response && response.response.uiMessages) {
|
|
1944
1972
|
const mastraUIMessages = (response.response.uiMessages || []).map((message) => ({
|
|
1945
1973
|
...message,
|
|
@@ -1960,7 +1988,11 @@ var useChat = ({ agentId, resourceId, initialMessages }) => {
|
|
|
1960
1988
|
setIsRunning(true);
|
|
1961
1989
|
setToolCallApprovals((prev) => ({ ...prev, [toolCallId]: { status: "declined" } }));
|
|
1962
1990
|
const agent = baseClient.getAgent(agentId);
|
|
1963
|
-
const response = await agent.declineToolCallGenerate({
|
|
1991
|
+
const response = await agent.declineToolCallGenerate({
|
|
1992
|
+
runId: currentRunId,
|
|
1993
|
+
toolCallId,
|
|
1994
|
+
requestContext: _requestContext.current
|
|
1995
|
+
});
|
|
1964
1996
|
if (response && "uiMessages" in response.response && response.response.uiMessages) {
|
|
1965
1997
|
const mastraUIMessages = (response.response.uiMessages || []).map((message) => ({
|
|
1966
1998
|
...message,
|
|
@@ -1985,7 +2017,10 @@ var useChat = ({ agentId, resourceId, initialMessages }) => {
|
|
|
1985
2017
|
[runId ? `${runId}-${toolName}` : toolName]: { status: "approved" }
|
|
1986
2018
|
}));
|
|
1987
2019
|
const agent = baseClient.getAgent(agentId);
|
|
1988
|
-
const response = await agent.approveNetworkToolCall({
|
|
2020
|
+
const response = await agent.approveNetworkToolCall({
|
|
2021
|
+
runId: networkRunId,
|
|
2022
|
+
requestContext: _requestContext.current
|
|
2023
|
+
});
|
|
1989
2024
|
const transformer = new AISdkNetworkTransformer();
|
|
1990
2025
|
await response.processDataStream({
|
|
1991
2026
|
onChunk: async (chunk) => {
|
|
@@ -2008,7 +2043,10 @@ var useChat = ({ agentId, resourceId, initialMessages }) => {
|
|
|
2008
2043
|
[runId ? `${runId}-${toolName}` : toolName]: { status: "declined" }
|
|
2009
2044
|
}));
|
|
2010
2045
|
const agent = baseClient.getAgent(agentId);
|
|
2011
|
-
const response = await agent.declineNetworkToolCall({
|
|
2046
|
+
const response = await agent.declineNetworkToolCall({
|
|
2047
|
+
runId: networkRunId,
|
|
2048
|
+
requestContext: _requestContext.current
|
|
2049
|
+
});
|
|
2012
2050
|
const transformer = new AISdkNetworkTransformer();
|
|
2013
2051
|
await response.processDataStream({
|
|
2014
2052
|
onChunk: async (chunk) => {
|