fix(web-probe): add observe new session command

This commit is contained in:
Codex
2026-06-20 16:14:42 +00:00
parent 72c2081710
commit cb761a1691
3 changed files with 50 additions and 3 deletions
@@ -224,6 +224,7 @@ async function processCommand(command) {
case "login": return authenticate(context);
case "preflight": return preflightSummary();
case "goto": return gotoTarget(command.path || command.url || targetPath);
case "newSession": return createSessionFromUi();
case "sendPrompt": return sendPrompt(String(command.text || ""));
case "selectProvider": return selectProvider(String(command.provider || command.value || command.text || ""));
case "clickSession": return clickSession(String(command.sessionId || command.value || ""));
@@ -286,6 +287,50 @@ async function gotoTarget(rawTarget) {
return { beforeUrl, afterUrl: currentPageUrl(), httpStatus: response ? response.status() : null, pageId };
}
async function createSessionFromUi() {
const beforeUrl = currentPageUrl();
const before = await workbenchSessionSnapshot();
const create = page.locator("#session-create").first();
await create.waitFor({ state: "visible", timeout: 15000 });
await create.click();
await page.waitForFunction((initial) => {
const activeTab = document.querySelector(".session-tab[data-active='true'], .session-tab[aria-selected='true']");
const sessionId = activeTab?.getAttribute("data-session-id") || "";
const warning = document.querySelector(".composer-warning")?.textContent?.trim() || "";
const input = document.querySelector("#command-input");
return Boolean(activeTab && sessionId && sessionId !== initial.sessionId && input && !input.disabled && !warning);
}, { sessionId: before?.activeSessionId || "" }, { timeout: 30000 }).catch(() => null);
const after = await workbenchSessionSnapshot();
return {
beforeUrl,
afterUrl: currentPageUrl(),
ok: Boolean(after?.activeSessionId && after.activeSessionId !== before?.activeSessionId),
before,
after,
sessionId: after?.activeSessionId || null,
pageId
};
}
async function workbenchSessionSnapshot() {
return page.evaluate(() => {
const activeTab = document.querySelector(".session-tab[data-active='true'], .session-tab[aria-selected='true']");
const routeMatch = window.location.pathname.match(/\/workbench\/sessions\/([^/]+)/u) || window.location.pathname.match(/\/workspace\/sessions\/([^/]+)/u);
const input = document.querySelector("#command-input");
const warning = document.querySelector(".composer-warning")?.textContent?.trim() || null;
return {
url: window.location.href,
routeSessionId: routeMatch ? decodeURIComponent(routeMatch[1] || "") : null,
activeSessionId: activeTab?.getAttribute("data-session-id") || null,
activeConversationId: activeTab?.getAttribute("data-conversation-id") || null,
activeStatus: activeTab?.getAttribute("data-status") || null,
tabCount: document.querySelectorAll(".session-tab").length,
composerReady: Boolean(activeTab && input && !input.disabled && !warning),
warning
};
}).catch(() => null);
}
async function sendPrompt(text) {
if (text.trim().length === 0) throw new Error("sendPrompt requires non-empty text");
const beforeUrl = currentPageUrl();