Skip to content

Commit c2a574e

Browse files
committed
chore: include latest main web updates
2 parents bea4331 + 2a337fe commit c2a574e

17 files changed

Lines changed: 609 additions & 674 deletions

‎apps/web/src/components/chat/HtmlRenderFrame.tsx‎

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
type HtmlRenderReference,
99
} from "@t3tools/shared/htmlRender";
1010
import { Maximize2Icon } from "lucide-react";
11-
import { useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from "react";
11+
import { useEffect, useLayoutEffect, useRef, useState } from "react";
1212

1313
import { useAssetUrlRefresh, useAssetUrlState } from "~/assets/assetUrls";
1414
import { cn } from "~/lib/utils";
@@ -45,28 +45,25 @@ export function HtmlRenderFrame(props: {
4545
const [contentHeight, setContentHeight] = useState<number>();
4646
const height = htmlRenderFrameHeight(props.htmlRender, width, contentHeight);
4747
const fileName = htmlRenderFileName(title);
48-
const resource = useMemo(
49-
() => ({
50-
_tag: "attachment" as const,
51-
attachmentId,
52-
fileName,
53-
mimeType: "text/html",
54-
disposition: "inline" as const,
55-
}),
56-
[attachmentId, fileName],
57-
);
48+
const resource = {
49+
_tag: "attachment" as const,
50+
attachmentId,
51+
fileName,
52+
mimeType: "text/html",
53+
disposition: "inline" as const,
54+
};
5855
// A cached URL with life left is reused, so the browser's cache serves the
5956
// page again; one near expiry is minted afresh, since a frame cannot report a
6057
// failed load.
6158
const [src, setSrc] = useState<string | null>(null);
6259
const srcExpiresAt = useRef(0);
6360
const [expandedSrc, setExpandedSrc] = useState<string | null>(null);
6461
const [ready, setReady] = useState(false);
65-
const showPage = useCallback(() => setReady(true), []);
66-
const fitPage = useCallback((contentHeight: number) => {
62+
const showPage = () => setReady(true);
63+
const fitPage = (contentHeight: number) => {
6764
setContentHeight(contentHeight);
6865
setReady(true);
69-
}, []);
66+
};
7067
const { onFullscreenChange } = props;
7168
useEffect(() => {
7269
if (expandedSrc === null) return;

‎apps/web/src/components/chat/McpAppFrame.tsx‎

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import {
1919
type McpAppReference,
2020
} from "@t3tools/shared/mcpApp";
2121
import { Minimize2Icon } from "lucide-react";
22-
import { useEffect, useLayoutEffect, useMemo, useRef, useState } from "react";
22+
import { useEffect, useLayoutEffect, useRef, useState } from "react";
2323
import { flushSync } from "react-dom";
2424

2525
import { 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+
6375
export 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

Comments
 (0)