fix: preserve image attachments in live and restored conversations
This commit is contained in:
@@ -603,6 +603,23 @@ async function installCodingFirstChatHost(
|
||||
await new Promise<void>((resolve) => { state.releaseSnapshot = resolve; });
|
||||
state.snapshotPending = false;
|
||||
}
|
||||
const posted = state.captured.find((request) => (
|
||||
request.path === `/api/coding/conversations/${conversation.id}/prompt` && request.method === 'POST'
|
||||
));
|
||||
if (!featureComplete && posted?.body) {
|
||||
const refs = posted.body.attachments as Array<{ attachmentId: string }>;
|
||||
return respond({ snapshot: {
|
||||
...snapshot,
|
||||
nodes: [{ kind: 'message', id: 'entry:sent-image', sourceEntryId: 'sent-image',
|
||||
role: 'user', status: 'complete', blocks: [
|
||||
{ kind: 'text', id: 'entry:sent-image:content:0', text: posted.body.text, status: 'complete' },
|
||||
...refs.map(({ attachmentId }, index) => ({
|
||||
kind: 'image', id: `entry:sent-image:image:${index}`, attachmentId, mime: 'image/png',
|
||||
})),
|
||||
] }],
|
||||
cursor: { workerGeneration: 1, seq: 1 },
|
||||
} });
|
||||
}
|
||||
const currentSnapshot = state.snapshotSettled
|
||||
? {
|
||||
...snapshot,
|
||||
@@ -872,6 +889,20 @@ test('first PI Conversation is editable under 500 ms and submits before runtime
|
||||
{ attachmentId: expect.any(String) },
|
||||
]);
|
||||
expect(JSON.stringify(prompt?.body)).not.toContain('data:image');
|
||||
await releaseSnapshot(electronApp);
|
||||
const persistedMessage = page.locator('[data-node-id="entry:sent-image"]');
|
||||
await expect(persistedMessage).toBeVisible();
|
||||
await expect(persistedMessage.getByRole('img', { name: '对话图片附件' })).toBeVisible();
|
||||
await expect(persistedMessage.getByRole('button', { name: '从这里创建新对话分支' })).toBeVisible();
|
||||
// A full renderer reload discards its optimistic state and blob URLs.
|
||||
await page.reload();
|
||||
page = await getStableWindow(electronApp);
|
||||
await expect.poll(async () => (await readState(electronApp)).snapshotPending).toBe(true);
|
||||
await releaseSnapshot(electronApp);
|
||||
await expect(page.locator('[data-node-id="entry:sent-image"]').getByRole('img', {
|
||||
name: '对话图片附件',
|
||||
})).toBeVisible();
|
||||
|
||||
} finally {
|
||||
await releaseSnapshot(electronApp);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user