Support concurrent chats (#1478)

Fixes #212 


<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> Add concurrent chat support with per-chat state, chat activity UI, IPC
per-chat handling, and accompanying tests.
> 
> - **Frontend (Chat concurrency)**
> - Replace global chat atoms with per-chat maps:
`chatMessagesByIdAtom`, `isStreamingByIdAtom`, `chatErrorByIdAtom`,
`chatStreamCountByIdAtom`, `recentStreamChatIdsAtom`.
> - Update `ChatPanel`, `ChatInput`, `MessagesList`,
`DyadMarkdownParser`, and `useVersions` to read/write per-chat state.
> - Add `useSelectChat` to centralize selecting/navigating chats; wire
into `ChatList`.
> - **UI**
> - Add chat activity popover: `ChatActivityButton` and list; integrate
into `preview_panel/ActionHeader` (renamed from `PreviewHeader`) and
swap in `TitleBar`.
> - **IPC/Main**
> - Send error payloads with `chatId` on `chat:response:error`; update
`ipc_client` to route errors per chat.
> - Persist streaming partial assistant content periodically; improve
cancellation/end handling.
> - Make `FileUploadsState` per-chat (`addFileUpload({chatId,fileId},
...)`, `clear(chatId)`, `getFileUploadsForChat(chatId)`); update
handlers/processors accordingly.
> - **Testing**
> - Add e2e `concurrent_chat.spec.ts` and snapshots; extend helpers
(`snapshotMessages` timeout, chat activity helpers).
> - Fake LLM server: support `tc=` with options, optional sleep delay to
simulate concurrency.
> 
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
9035f30b73a1f2e5a366a0cac1c63411742b16f3. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
This commit is contained in:
Will Chen
2025-10-09 10:51:01 -07:00
committed by GitHub
parent 263f401172
commit 9691c9834b
21 changed files with 487 additions and 125 deletions

View File

@@ -0,0 +1,25 @@
import { test } from "./helpers/test_helper";
import { expect } from "@playwright/test";
test("concurrent chat", async ({ po }) => {
await po.setUp();
await po.sendPrompt("tc=chat1 [sleep=medium]", {
skipWaitForCompletion: true,
});
// Need a short wait otherwise the click on Apps tab is ignored.
await po.sleep(2_000);
await po.goToAppsTab();
await po.sendPrompt("tc=chat2");
await po.snapshotMessages();
await po.clickChatActivityButton();
// Chat #1 will be the last in the list
expect(
await po.page.getByTestId(`chat-activity-list-item-1`).textContent(),
).toContain("Chat #1");
await po.page.getByTestId(`chat-activity-list-item-1`).click();
await po.snapshotMessages({ timeout: 12_000 });
//
});

View File

@@ -400,7 +400,8 @@ export class PageObject {
async snapshotMessages({
replaceDumpPath = false,
}: { replaceDumpPath?: boolean } = {}) {
timeout,
}: { replaceDumpPath?: boolean; timeout?: number } = {}) {
if (replaceDumpPath) {
// Update page so that "[[dyad-dump-path=*]]" is replaced with a placeholder path
// which is stable across runs.
@@ -417,7 +418,9 @@ export class PageObject {
);
});
}
await expect(this.page.getByTestId("messages-list")).toMatchAriaSnapshot();
await expect(this.page.getByTestId("messages-list")).toMatchAriaSnapshot({
timeout,
});
}
async approveProposal() {
@@ -461,6 +464,16 @@ export class PageObject {
await this.page.getByTestId(`${mode}-mode-button`).click();
}
async clickChatActivityButton() {
await this.page.getByTestId("chat-activity-button").click();
}
async snapshotChatActivityList() {
await expect(
this.page.getByTestId("chat-activity-list"),
).toMatchAriaSnapshot();
}
async clickRecheckProblems() {
await this.page.getByTestId("recheck-button").click();
}

View File

@@ -0,0 +1,8 @@
- paragraph: tc=chat2
- paragraph: chat2
- button:
- img
- img
- text: less than a minute ago
- button "Retry":
- img

View File

@@ -0,0 +1,8 @@
- paragraph: tc=chat1 [sleep=medium]
- paragraph: chat1
- button:
- img
- img
- text: less than a minute ago
- button "Retry":
- img