From f1f413e4be3ec2185c998b16e024eb64d58bb1eb Mon Sep 17 00:00:00 2001 From: wangtiance Date: Tue, 1 Dec 2026 16:20:07 +0800 Subject: [PATCH 1/2] [bugfix] canvas: show video frames in the reference picker ## summary Load saved video previews when their reference rows enter view. Reuse cached first frames and keep the video option available on failure. Cover preview loading and reuse in the assistant browser workflow. --- docs/guides/user-guide.md | 2 + docs/guides/user-guide.zh-CN.md | 2 + src/backend/creationClient.ts | 7 +-- src/canvas/ChatReferenceEditor.tsx | 54 +++++++++++++++++---- src/canvas/referenceMentions.ts | 11 +++-- tests/browser/assistant_chat_references.mjs | 27 ++++++++++- 6 files changed, 86 insertions(+), 17 deletions(-) diff --git a/docs/guides/user-guide.md b/docs/guides/user-guide.md index 9fe1d001c..853e0606e 100644 --- a/docs/guides/user-guide.md +++ b/docs/guides/user-guide.md @@ -126,6 +126,8 @@ For GPT Image models, open **Generation settings** and choose **Quality** from * After typing `@`, use the up and down arrow keys to select an asset, the left and right arrow keys to switch categories, `Enter` to insert, and `Esc` to close the picker. References are inserted into the text as single units. Removing the last reference to a source also removes its corresponding reference connection. +The picker shows the first frame for saved video nodes. If a preview is unavailable, the video icon appears and the reference remains selectable. + When an image or video node is connected to a text node with content, the prompt may stay blank: generation uses the text as is as the prompt, and anything typed in the prompt is added to it. Connected text carries no "Reference N: title" label; only text inserted with `@` keeps its label so the inline mention points at it. One text node can feed several generation nodes that use different models, and they all pick up edits to the text. Speech and music never read text references and still need their own text or style. An empty node must first receive an upload, saved text, or generated content before it can serve as a valid reference for other nodes. When uploading a node's own content, the file type must match the node. To add references, use connections, `@`, or the reference controls in the generation panel. diff --git a/docs/guides/user-guide.zh-CN.md b/docs/guides/user-guide.zh-CN.md index 2d279e8d4..d423f894d 100644 --- a/docs/guides/user-guide.zh-CN.md +++ b/docs/guides/user-guide.zh-CN.md @@ -126,6 +126,8 @@ GPT Image 模型可在“生成参数”中选择“质量”,取值为“自 输入 `@` 后可用上下方向键选择素材、左右方向键切换分类,按 `Enter` 插入,按 `Esc` 关闭选择。引用以整体形式插入正文;删除同一来源的最后一次引用会移除相应参考连线。 +选择列表会显示画布上已保存视频的首帧。预览不可用时显示视频图标,仍可选择该素材作为引用。 + 图片或视频节点连接了有内容的文本节点时,提示词可以留空:生成时直接把文本原样作为提示词,也可以在提示词中补充要求。连线的文本不加“参考N:标题”标签;只有用 `@` 插入的文本保留标签,以便提示词中的引用对应到它。一个文本节点可以同时连到多个使用不同模型的生成节点,修改文本后各节点都会使用新内容。语音和音乐不读取文本参考,仍需填写正文或风格。 空白节点需要先上传、保存文本或生成内容,才能作为其他节点的有效参考。向已有节点上传本体素材时,文件类型应与节点一致;添加参考请使用连线、`@` 或生成面板的添加入口。 diff --git a/src/backend/creationClient.ts b/src/backend/creationClient.ts index 392c47e44..b29b587eb 100644 --- a/src/backend/creationClient.ts +++ b/src/backend/creationClient.ts @@ -602,8 +602,9 @@ export class CreationClient { this.mediaListeners.delete(listener); }; } - thumbnailUrl(assetId: string) { - const key = `thumbnail:${assetId}`; + thumbnailUrl(assetId: string, kind: "image" | "video" = "image") { + const rendition = kind === "video" ? "preview" : "thumbnail"; + const key = `${rendition}:${assetId}`; let pending = this.media.get(key); if (!pending) { pending = this.mediaReader.run( @@ -611,7 +612,7 @@ export class CreationClient { resilientRead( async (signal) => { const response = await fetch( - `/api${creationPath(this.id)}/assets/${assetId}/thumbnail`, + `/api${creationPath(this.id)}/assets/${assetId}/${rendition}`, { headers, signal }, ); if (!response.ok) throw await responseError(response); diff --git a/src/canvas/ChatReferenceEditor.tsx b/src/canvas/ChatReferenceEditor.tsx index 6f073e9bb..71d33a44c 100644 --- a/src/canvas/ChatReferenceEditor.tsx +++ b/src/canvas/ChatReferenceEditor.tsx @@ -49,9 +49,37 @@ import "./reference-mentions.css"; import { assetDisplayName } from "./assetNames.ts"; import { useT } from "../i18n/I18nProvider.tsx"; import type { MessageKey } from "../i18n/types.ts"; -import { AssetMedia } from "./useAssetMedia.tsx"; +import { AssetMedia, useInViewport } from "./useAssetMedia.tsx"; import { parseAssetSource } from "../backend/assetSource.ts"; -import { resolveMediaSource } from "../backend/creationClient.ts"; +import { creationClient, resolveMediaSource } from "../backend/creationClient.ts"; + +function MentionVideoPreview({ + source, + kind, +}: { source: string; kind: MentionOption["kind"] }) { + const [observe, visible] = useInViewport(); + const [src, setSrc] = useState(); + useEffect(() => { + const asset = parseAssetSource(source); + if (!visible || !asset) return; + let mounted = true; + void creationClient(asset.projectId).thumbnailUrl(asset.assetId, "video") + .then((url) => { + if (mounted) setSrc(url); + }) + .catch(() => {}); + return () => { mounted = false; }; + }, [source, visible]); + return ( + + {src ? ( + setSrc(undefined)} /> + ) : ( + + )} + + ); +} export interface ChatReferenceEditorHandle { focus: () => void; @@ -1346,13 +1374,21 @@ export function ChatReferenceEditor({ onMouseEnter={() => setActive(index)} onClick={() => void choose(option)} > - - {option.thumbnail ? ( - - ) : ( - - )} - + {option.videoPreview && !option.disabledReason ? ( + + ) : ( + + {option.thumbnail ? ( + + ) : ( + + )} + + )} {option.title} {option.disabledReason || option.detail} diff --git a/src/canvas/referenceMentions.ts b/src/canvas/referenceMentions.ts index df3bcc3fe..33290c43f 100644 --- a/src/canvas/referenceMentions.ts +++ b/src/canvas/referenceMentions.ts @@ -3,6 +3,7 @@ import { canSourceReference } from "./connectionPolicy.ts"; import { assetDisplayName } from "./assetNames.ts"; import { tNow } from "../i18n/messages.ts"; import type { MessageKey } from "../i18n/types.ts"; +import { parseAssetSource } from "../backend/assetSource.ts"; export const REFERENCE_CATEGORIES = [ { id: "all", label: "errors.stats.all" }, @@ -20,6 +21,7 @@ export interface MentionOption { title: string; detail: string; thumbnail?: string; + videoPreview?: string; disabledReason?: string | null; } export interface MentionRange { @@ -83,7 +85,9 @@ export function nodeMentionOptions( return nodes.flatMap((node) => { const category = REFERENCE_CATEGORIES.find((item) => item.id === node.type); if (!category || !canSourceReference(node)) return []; - const image = node.type === "subject" ? node.data.subject?.main : undefined; + const main = node.type === "subject" ? node.data.subject?.main : undefined; + const video = + node.type === "video" ? node.data.src : main?.kind === "video" ? main.src : undefined; return [ { id: node.id, @@ -93,9 +97,10 @@ export function nodeMentionOptions( thumbnail: node.type === "image" ? node.data.src - : image?.kind === "image" - ? image.src + : main?.kind === "image" + ? main.src : undefined, + videoPreview: parseAssetSource(video) ? video : undefined, disabledReason: issue(node), }, ]; diff --git a/tests/browser/assistant_chat_references.mjs b/tests/browser/assistant_chat_references.mjs index 17bdaea90..0cde00345 100644 --- a/tests/browser/assistant_chat_references.mjs +++ b/tests/browser/assistant_chat_references.mjs @@ -169,14 +169,37 @@ try { const editor = panel.getByRole("textbox", { name: "消息内容", exact: true }); await editor.waitFor(); const picker = page.getByRole("dialog", { name: "引用项目资产", exact: true }); + const videoOption = picker.getByRole("option", { name: /^镜头\.mp4/ }); + const previewPath = `/api/creation/projects/${projectId}/assets/${nodes.video.asset.id}/preview`; + const previewReads = () => requests.filter((path) => path === previewPath).length; + assert.equal(previewReads(), 0); + await page.route(`**${previewPath}`, (route) => route.fulfill({ status: 422, json: {} }), { times: 1 }); await editor.click(); + const unavailable = page.waitForResponse(`**${previewPath}`); await editor.pressSequentially("参考 @"); - await picker.getByRole("option").first().waitFor(); + assert.equal((await unavailable).status(), 422); + await videoOption.locator(".cw-reference-mention-thumbnail svg").waitFor(); + assert.notEqual(await videoOption.getAttribute("aria-disabled"), "true"); + await editor.press("Escape"); + await picker.waitFor({ state: "hidden" }); + await panel.getByRole("button", { name: "引用项目素材", exact: true }).click(); + const thumbnail = videoOption.locator("img"); + await thumbnail.waitFor(); + assert.ok(await thumbnail.evaluate(async (image) => { + await image.decode(); + return image.naturalWidth > 0; + })); + assert.equal(previewReads(), 2); + await page.keyboard.press("Escape"); + await picker.waitFor({ state: "hidden" }); + await panel.getByRole("button", { name: "引用项目素材", exact: true }).click(); + await thumbnail.waitFor(); + assert.equal(previewReads(), 2, "Reopening must reuse the cached video frame"); assert.equal(await picker.getByRole("status").count(), 0, "The picker must not wait on the catalog"); assert.equal(await picker.getByRole("option").count(), 2); const before = requests.length; - await picker.getByRole("option", { name: /^镜头\.mp4/ }).click(); + await videoOption.click(); await picker.waitFor({ state: "hidden" }); const chip = editor.locator("[data-reference]"); await chip.waitFor(); From 92bc845481bddb7ba6926525c8dc24d53ed2382b Mon Sep 17 00:00:00 2001 From: wangtiance Date: Tue, 1 Dec 2026 16:36:47 +0800 Subject: [PATCH 2/2] [test] canvas: preserve typed mention journey in preview regression ## summary Exercise the toolbar for preview fallback and retry, then verify cache reuse through the original typed mention and send journey. --- tests/browser/assistant_chat_references.mjs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/tests/browser/assistant_chat_references.mjs b/tests/browser/assistant_chat_references.mjs index 0cde00345..16daf9800 100644 --- a/tests/browser/assistant_chat_references.mjs +++ b/tests/browser/assistant_chat_references.mjs @@ -175,15 +175,15 @@ try { assert.equal(previewReads(), 0); await page.route(`**${previewPath}`, (route) => route.fulfill({ status: 422, json: {} }), { times: 1 }); - await editor.click(); + const referenceButton = panel.getByRole("button", { name: "引用项目素材", exact: true }); const unavailable = page.waitForResponse(`**${previewPath}`); - await editor.pressSequentially("参考 @"); + await referenceButton.click(); assert.equal((await unavailable).status(), 422); await videoOption.locator(".cw-reference-mention-thumbnail svg").waitFor(); assert.notEqual(await videoOption.getAttribute("aria-disabled"), "true"); - await editor.press("Escape"); + await page.keyboard.press("Escape"); await picker.waitFor({ state: "hidden" }); - await panel.getByRole("button", { name: "引用项目素材", exact: true }).click(); + await referenceButton.click(); const thumbnail = videoOption.locator("img"); await thumbnail.waitFor(); assert.ok(await thumbnail.evaluate(async (image) => { @@ -193,7 +193,8 @@ try { assert.equal(previewReads(), 2); await page.keyboard.press("Escape"); await picker.waitFor({ state: "hidden" }); - await panel.getByRole("button", { name: "引用项目素材", exact: true }).click(); + await editor.click(); + await editor.pressSequentially("参考 @"); await thumbnail.waitFor(); assert.equal(previewReads(), 2, "Reopening must reuse the cached video frame"); assert.equal(await picker.getByRole("status").count(), 0, "The picker must not wait on the catalog"); @@ -208,7 +209,7 @@ try { assert.equal(reference.nodeId, nodes.video.id); const pick = requests.slice(before); assert.deepEqual( - pick.filter((path) => path.includes("/reference-catalog")), + pick.filter((path) => path.includes("/reference-catalog?")), [`/api/creation/projects/${projectId}/reference-catalog?nodeId=${nodes.video.id}`], ); assert.deepEqual(