web: wait for C2's created conversation instead of sampling it
The created chat loads its history asynchronously; reading the DOM once raced the load (worse when the OpenCode endpoint is busy), reporting a permanent 'Loading conversation...' that the app never showed.
This commit is contained in:
+24
-14
@@ -3094,20 +3094,30 @@ try {
|
||||
{ timeout: 30000, what: "the C2-created session to be selected" },
|
||||
);
|
||||
createdSessionId = createdId;
|
||||
const created = await page.evaluate(`(() => {
|
||||
const rows = [...document.querySelectorAll("#chatRows .chat-row")];
|
||||
const row = document.querySelector('.chat-row[data-session="${createdId}"]');
|
||||
return {
|
||||
first: rows[0]?.dataset.session ?? "",
|
||||
title: row?.querySelector(".chat-row-title")?.textContent ?? "",
|
||||
selected: row?.classList.contains("selected") ?? false,
|
||||
closed: !!row?.querySelector(".chat-closed-chip"),
|
||||
header: document.querySelector(".chat-bar-title")?.textContent ?? "",
|
||||
empty: document.querySelector(".chat-detail .chat-transcript-empty")?.textContent ?? "",
|
||||
composer: !!document.querySelector("#chatComposer"),
|
||||
pickerGone: !document.querySelector(".chat-create"),
|
||||
};
|
||||
})()`);
|
||||
// The created conversation loads its history asynchronously; sample it only once
|
||||
// it has settled (a loaded OpenCode endpoint can take a few seconds).
|
||||
const created = await eventually(
|
||||
() =>
|
||||
page
|
||||
.evaluate(`(() => {
|
||||
const rows = [...document.querySelectorAll("#chatRows .chat-row")];
|
||||
const row = document.querySelector('.chat-row[data-session="${createdId}"]');
|
||||
return {
|
||||
first: rows[0]?.dataset.session ?? "",
|
||||
title: row?.querySelector(".chat-row-title")?.textContent ?? "",
|
||||
selected: row?.classList.contains("selected") ?? false,
|
||||
closed: !!row?.querySelector(".chat-closed-chip"),
|
||||
header: document.querySelector(".chat-bar-title")?.textContent ?? "",
|
||||
empty: document.querySelector(".chat-detail .chat-transcript-empty")?.textContent ?? "",
|
||||
composer: !!document.querySelector("#chatComposer"),
|
||||
pickerGone: !document.querySelector(".chat-create"),
|
||||
};
|
||||
})()`)
|
||||
.then((value) =>
|
||||
value.empty === "This chat has no messages yet. Ask something below." ? value : false,
|
||||
),
|
||||
{ timeout: 30000, what: "the created chat's empty conversation to load" },
|
||||
);
|
||||
const createBodies = await page.evaluate(`window.__chatCreateBodies || []`);
|
||||
if (createBodies.length !== 1) {
|
||||
throw new Error(`C2 sent ${createBodies.length} chat_create request(s) for one create`);
|
||||
|
||||
Reference in New Issue
Block a user