Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

fix(desktop): hold the thumbnail src on pending bot image chips too

MagicLizi3a50233e10d4
diff --git a/apps/desktop/src/renderer/components/chat/GeneratedFilesCard.tsx b/apps/desktop/src/renderer/components/chat/GeneratedFilesCard.tsx
index 32b4423737..213463047a 100644
--- a/apps/desktop/src/renderer/components/chat/GeneratedFilesCard.tsx
+++ b/apps/desktop/src/renderer/components/chat/GeneratedFilesCard.tsx
@@ -21,7 +21,9 @@ import { FileTypeIcon } from '@/components/ui/file-type-icon';
* 可能无法打开的完成卡。首屏等检查完成再出现;本机路径若本次运行已 stat 过,重挂载时
* 按当前时间窗同步判定先出卡,再整卡复核(见 seedLocalGeneratedFilesFromStatCache);
* 复核落地前该 chip 不可交互 —— 历史 stat 不充当当前可点结论(同 §14.5:本机
- * 会话以真实存在性检查决定可点态)。
+ * 会话以真实存在性检查决定可点态)。伙伴成果图片同理:pending 期间占位但不挂
+ * 真实 src,避免复核落地前把旧/替换文件的内容短暂加载出来,也不让这次预取失败
+ * 提前锁死 thumbnailFailed。
* 流式期间只 stat 已完成(ready !== false,或本轮已封口)且尚未确认的路径;内容指纹不变就不发 IPC,
* 已确认的 chip 留在原地,避免 messages 换引用把整页带着跳。
*
@@ -400,7 +402,10 @@ function GeneratedFileChip({
</>
) : botImage ? (
<>
- {botThumbnail && !thumbnailFailed ? (
+ {/* pending 期间不挂 src:复核落地前这路径的内容未经确认,先出
+ 占位(与真实图片同高,避免复核落地时再跳一次),不预取可能已
+ 不属于本轮的旧/替换文件,也不让这次失败预支 thumbnailFailed。 */}
+ {!pending && botThumbnail && !thumbnailFailed ? (
<img
src={botThumbnail}
alt={file.name}
@@ -408,7 +413,12 @@ function GeneratedFileChip({
className="h-[148px] w-full border-b border-[var(--border-default)] bg-[var(--surface-hover)] object-contain"
/>
) : (
- <span className="flex h-[104px] w-full items-center justify-center border-b border-[var(--border-default)] bg-[var(--surface-hover)] text-[var(--text-tertiary)]">
+ <span
+ className={cn(
+ 'flex w-full items-center justify-center border-b border-[var(--border-default)] bg-[var(--surface-hover)] text-[var(--text-tertiary)]',
+ pending ? 'h-[148px]' : 'h-[104px]',
+ )}
+ >
<FileTypeIcon name={file.name} size={24} aria-hidden="true" />
</span>
)}
diff --git a/apps/desktop/src/renderer/components/chat/__tests__/GeneratedFilesCard.localSeed.test.tsx b/apps/desktop/src/renderer/components/chat/__tests__/GeneratedFilesCard.localSeed.test.tsx
index b46bbfd2fb..3fb51e77ce 100644
--- a/apps/desktop/src/renderer/components/chat/__tests__/GeneratedFilesCard.localSeed.test.tsx
+++ b/apps/desktop/src/renderer/components/chat/__tests__/GeneratedFilesCard.localSeed.test.tsx
@@ -37,6 +37,7 @@ function renderCard(props: {
files?: readonly GeneratedFileRef[];
turnStartMs: number;
turnEndMs?: number | null;
+ botArtifacts?: boolean;
}) {
return render(cardElement(props));
}
@@ -46,6 +47,7 @@ function cardElement(props: {
files?: readonly GeneratedFileRef[];
turnStartMs: number;
turnEndMs?: number | null;
+ botArtifacts?: boolean;
}) {
return (
<ChatSessionFileProvider
@@ -56,6 +58,7 @@ function cardElement(props: {
files={props.files ?? [report]}
turnStartMs={props.turnStartMs}
turnEndMs={props.turnEndMs ?? null}
+ botArtifacts={props.botArtifacts}
/>
</ChatSessionFileProvider>
);
@@ -137,6 +140,48 @@ describe('local generated files remount', () => {
);
});
+ it('does not render a stale bot image thumbnail while its seeded chip is pending', async () => {
+ const picture: GeneratedFileRef = {
+ path: 'C:\\work\\pic.png',
+ name: 'pic.png',
+ source: 'tool',
+ ready: true,
+ };
+ const pendingStat: Array<(stat: unknown) => void> = [];
+ const statPath = vi.fn(
+ () =>
+ new Promise((resolve) => {
+ pendingStat.push(resolve);
+ }),
+ );
+ stubStat(statPath);
+ const first = renderCard({
+ renderItemKey: 'genfiles-a',
+ files: [picture],
+ turnStartMs: START,
+ botArtifacts: true,
+ });
+ await waitFor(() => expect(pendingStat).toHaveLength(1));
+ pendingStat[0]({ kind: 'file', birthtimeMs: START + 5_000, mtimeMs: START + 5_000 });
+ await waitFor(() => expect(screen.getByText('pic.png')).toBeTruthy());
+ first.unmount();
+
+ // A re-mounted seeded chip is disabled, but DESIGN.md §14.5 also bars
+ // loading the file's content before the recheck lands: a deleted or
+ // replaced image at the same path must not flash through <img src>.
+ renderCard({
+ renderItemKey: 'genfiles-a',
+ files: [picture],
+ turnStartMs: START,
+ botArtifacts: true,
+ });
+ expect(screen.getByText('pic.png')).toBeTruthy();
+ expect(document.querySelector('img')).toBeNull();
+ await waitFor(() => expect(pendingStat).toHaveLength(2));
+ pendingStat[1]({ kind: 'file', birthtimeMs: START + 5_000, mtimeMs: START + 5_000 });
+ await waitFor(() => expect(document.querySelector('img')).not.toBeNull());
+ });
+
it('re-checks a seeded path when another file finishes during the first check', async () => {
const notes: GeneratedFileRef = {
path: 'C:\\work\\notes.md',