@@ -19,7 +19,7 @@ import {
1919 type McpAppReference ,
2020} from "@t3tools/shared/mcpApp" ;
2121import { Minimize2Icon } from "lucide-react" ;
22- import { useEffect , useLayoutEffect , useMemo , useRef , useState } from "react" ;
22+ import { useEffect , useLayoutEffect , useRef , useState } from "react" ;
2323import { flushSync } from "react-dom" ;
2424
2525import { useAssetUrlRefresh , useAssetUrlState } from "~/assets/assetUrls" ;
@@ -60,6 +60,18 @@ function saveBlob(blob: Blob, name: string) {
6060 setTimeout ( ( ) => URL . revokeObjectURL ( url ) , 60_000 ) ;
6161}
6262
63+ // The host gets the tool call pushed by an effect keyed on it, so it stays
64+ // stable across the command hooks that follow.
65+ function useToolCall (
66+ storedItem : NonNullable < ReturnType < typeof useTurnItemDetail > [ "data" ] > [ "item" ] | undefined ,
67+ ) {
68+ "use memo" ;
69+ if ( storedItem ?. type !== "dynamic_tool" ) return undefined ;
70+ const output = storedItem . output as { readonly result ?: unknown } | undefined ;
71+ const result = output ?. result as McpAppCallToolResult | undefined ;
72+ return { arguments : storedItem . input , result } ;
73+ }
74+
6375export function McpAppFrame ( props : {
6476 readonly environmentId : EnvironmentId ;
6577 readonly threadId : ThreadId ;
@@ -91,17 +103,14 @@ export function McpAppFrame(props: {
91103 // oxlint-disable-next-line react/exhaustive-effect-dependencies -- Closing and reopening replaces the box.
92104 } , [ closed ] ) ;
93105
94- const resource = useMemo (
95- ( ) => ( {
96- _tag : "attachment" as const ,
97- attachmentId : app . attachmentId ,
98- fileName : mcpAppFileName ( app ) ,
99- mimeType : "text/html" ,
100- disposition : "inline" as const ,
101- renderIntent : "mcp-app" as const ,
102- } ) ,
103- [ app ] ,
104- ) ;
106+ const resource = {
107+ _tag : "attachment" as const ,
108+ attachmentId : app . attachmentId ,
109+ fileName : mcpAppFileName ( app ) ,
110+ mimeType : "text/html" ,
111+ disposition : "inline" as const ,
112+ renderIntent : "mcp-app" as const ,
113+ } ;
105114 const asset = useAssetUrlState ( props . environmentId , resource ) ;
106115 const refreshAsset = useAssetUrlRefresh ( props . environmentId , resource ) ;
107116 // The frame keeps its first URL: a re-minted one would reload the app. A
@@ -133,12 +142,7 @@ export function McpAppFrame(props: {
133142 revision : props . revision ,
134143 } ) ;
135144 const storedItem = detail . data ?. item ;
136- const toolCall = useMemo ( ( ) => {
137- if ( storedItem ?. type !== "dynamic_tool" ) return undefined ;
138- const output = storedItem . output as { readonly result ?: unknown } | undefined ;
139- const result = output ?. result as McpAppCallToolResult | undefined ;
140- return { arguments : storedItem . input , result } ;
141- } , [ storedItem ] ) ;
145+ const toolCall = useToolCall ( storedItem ) ;
142146
143147 const callTool = useAtomCommand ( mcpAppEnvironment . callTool , { reportFailure : false } ) ;
144148 const toolInfo = useAtomCommand ( mcpAppEnvironment . toolInfo , { reportFailure : false } ) ;
0 commit comments