copilot-operator 0.1.88 → 0.1.90
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/api/operator.controller.js +66 -3
- package/dist/src/api/operator.service.js +141 -0
- package/dist/src/api/server.js +5 -1
- package/dist/src/cli.js +6 -0
- package/dist/src/config/live.js +1 -1
- package/dist/src/config/schema.js +12 -0
- package/dist/src/orchestrator/taskRunner.js +9 -2
- package/dist/src/plan/systemGuide.js +158 -0
- package/dist/src/session/locatorFailures.js +55 -0
- package/dist/src/transport/copilotTransport.js +310 -65
- package/dist/src/transport/keptWindow.js +3 -0
- package/dist/src/transport/locators.js +126 -5
- package/dist/src/transport/pageHtml.js +62 -0
- package/dist/web/404.html +2 -2
- package/dist/web/_next/static/chunks/{1077.26ca37faa3726fff.js → 1077.1cc6d439e3dd0fa9.js} +1 -1
- package/dist/web/_next/static/chunks/{1548.f5790cd11a91309f.js → 1548.3de9dc874e47558e.js} +1 -1
- package/dist/web/_next/static/chunks/{2163.aa9d9b82fcde6caa.js → 2163.66458fb9c54fb52d.js} +1 -1
- package/dist/web/_next/static/chunks/{714.b7dbce98ba0b59a8.js → 714.cffed2b87154be0f.js} +1 -1
- package/dist/web/_next/static/chunks/{7220.0ca53eefec5d01ea.js → 7220.30b6a3e1bd41e51a.js} +1 -1
- package/dist/web/_next/static/chunks/7921-d3a4a261e08950e0.js +1 -0
- package/dist/web/_next/static/chunks/{8584.9f3b058a8f67d3d7.js → 8584.36422ed19d6c43e9.js} +1 -1
- package/dist/web/_next/static/chunks/{9067.107f6164157e0aa1.js → 9067.e579f97591576de2.js} +1 -1
- package/dist/web/_next/static/chunks/{9747.984a86f70f9cd973.js → 9747.11247f0e21542f6d.js} +1 -1
- package/dist/web/_next/static/chunks/app/layout-7b5fa7c74ecd6939.js +1 -0
- package/dist/web/_next/static/chunks/app/queue/{page-317151444eda8115.js → page-7909ba7c9e3d4c2d.js} +1 -1
- package/dist/web/_next/static/chunks/app/settings/page-7651920337bbb580.js +1 -0
- package/dist/web/_next/static/chunks/{webpack-c015bbeb103c0856.js → webpack-78ec62098b09e4a0.js} +1 -1
- package/dist/web/_next/static/css/{0c5d6d5914aa3824.css → d74aa18c98dacdb4.css} +1 -1
- package/dist/web/defaults.html +2 -2
- package/dist/web/defaults.txt +8 -8
- package/dist/web/index.html +3 -3
- package/dist/web/index.txt +9 -9
- package/dist/web/queue.html +2 -2
- package/dist/web/queue.txt +9 -9
- package/dist/web/settings.html +2 -2
- package/dist/web/settings.txt +9 -9
- package/dist/web/system.html +2 -2
- package/dist/web/system.txt +9 -9
- package/package.json +3 -2
- package/dist/web/_next/static/chunks/7921-8f6503aba840928a.js +0 -1
- package/dist/web/_next/static/chunks/app/layout-127e5af1ebf21876.js +0 -1
- package/dist/web/_next/static/chunks/app/settings/page-95069cb94d79e909.js +0 -1
- /package/dist/web/_next/static/{hLBBsG7Kn4vd0p_J-47BJ → 3VkK1sxEugkae88HSFR-i}/_buildManifest.js +0 -0
- /package/dist/web/_next/static/{hLBBsG7Kn4vd0p_J-47BJ → 3VkK1sxEugkae88HSFR-i}/_ssgManifest.js +0 -0
|
@@ -16,9 +16,10 @@ import { mkdir, writeFile } from 'node:fs/promises';
|
|
|
16
16
|
import { join } from 'node:path';
|
|
17
17
|
import { findRecentCrash, describeCrash } from './edgeCrash.js';
|
|
18
18
|
import { landed } from './acceptance.js';
|
|
19
|
-
import { Blocker, Css, fillLocator, Label, Model, ModelPicking, pageQuery, playwrightSelector, Rename,
|
|
19
|
+
import { Blocker, CHAT_ID, CHAT_LOCATOR_KEYS, ChatLocatorGroupOf, ChatLocatorWhat, Css, DefaultChatLocators, fillLocator, Label, Model, ModelPicking, pageQuery, playwrightSelector, Rename, resolveChatLocators, resolvePickerLocators, Signal, Surface, Upload, Url, } from './locators.js';
|
|
20
20
|
import { acquireProfileLock } from './profileLock.js';
|
|
21
21
|
import { chatNameForms, parseChatId } from './chatSession.js';
|
|
22
|
+
import { strippedPageHtml } from './pageHtml.js';
|
|
22
23
|
/**
|
|
23
24
|
* The chat did not finish a reply within `copilot.replyTimeoutSec`.
|
|
24
25
|
*
|
|
@@ -276,6 +277,26 @@ export const CLIPBOARD_GUARD = `(() => {
|
|
|
276
277
|
};
|
|
277
278
|
} catch (e) { /* as above */ }
|
|
278
279
|
})();`;
|
|
280
|
+
/**
|
|
281
|
+
* A locator of the chat that found nothing where the bot needed it (operator, 2026-11-17: "a mechanism that detects
|
|
282
|
+
* which locator exactly the bot failed on, so we can easily see which locator has to be updated"): which one, as it
|
|
283
|
+
* was in force, and the page's HTML and picture kept for finding the right one. The runner says it like any other
|
|
284
|
+
* error; the transport has said it already (`locator-missing`), which the API keeps for Settings (`LocatorFailures`).
|
|
285
|
+
*/
|
|
286
|
+
export class LocatorMissing extends Error {
|
|
287
|
+
key;
|
|
288
|
+
locator;
|
|
289
|
+
html;
|
|
290
|
+
picture;
|
|
291
|
+
constructor(key, locator, message, html, picture) {
|
|
292
|
+
super(message);
|
|
293
|
+
this.key = key;
|
|
294
|
+
this.locator = locator;
|
|
295
|
+
this.html = html;
|
|
296
|
+
this.picture = picture;
|
|
297
|
+
this.name = 'LocatorMissing';
|
|
298
|
+
}
|
|
299
|
+
}
|
|
279
300
|
export class CopilotTransport {
|
|
280
301
|
opts;
|
|
281
302
|
context = null;
|
|
@@ -293,6 +314,10 @@ export class CopilotTransport {
|
|
|
293
314
|
gone = false;
|
|
294
315
|
/** The model menu's locators in force: Settings' own, else the defaults (see `resolvePickerLocators`). */
|
|
295
316
|
locators;
|
|
317
|
+
/** The chat page's locators in force — the box to write in: Settings' own, else the default (see `resolveChatLocators`). */
|
|
318
|
+
chatLocators;
|
|
319
|
+
/** Why a chat locator saved in Settings is not used; said once, when the chat is first opened. */
|
|
320
|
+
chatLocatorProblems;
|
|
296
321
|
/** Why a locator saved in Settings is not used; said once, at the first choice or reading of the models. */
|
|
297
322
|
locatorProblems;
|
|
298
323
|
/** Whether the rows' locator has been said not to work in the page (see `readMenuRows`). */
|
|
@@ -320,10 +345,23 @@ export class CopilotTransport {
|
|
|
320
345
|
settleMs = 2_000;
|
|
321
346
|
/** How long another page of the work Copilot is given to turn into its chat on its own before the bot opens the chat. */
|
|
322
347
|
otherPageMs = 3_000;
|
|
348
|
+
/** How long the answer is waited for with not one message of the conversation found, before the `turn` locator is said. */
|
|
349
|
+
turnsGraceMs = 20_000;
|
|
350
|
+
/** How long Copilot's newest answer may stand still, not written and not finished, before its locator is said. */
|
|
351
|
+
answerStillMs = 60_000;
|
|
352
|
+
/** The locators said already in this window, where the work went on without them: said once. */
|
|
353
|
+
warned = new Set();
|
|
354
|
+
/** How long Send is waited for once the message is in the box. */
|
|
355
|
+
sendWaitMs = 20_000;
|
|
356
|
+
/** How long a message sent is waited for in the conversation before it is taken as not accepted. */
|
|
357
|
+
acceptMs = 30_000;
|
|
323
358
|
constructor(opts) {
|
|
324
359
|
this.opts = opts;
|
|
325
360
|
const { locators, problems } = resolvePickerLocators(opts.pickerLocators);
|
|
326
361
|
this.locators = locators;
|
|
362
|
+
const chat = resolveChatLocators(opts.chatLocators);
|
|
363
|
+
this.chatLocators = chat.locators;
|
|
364
|
+
this.chatLocatorProblems = chat.problems;
|
|
327
365
|
this.locatorProblems = problems;
|
|
328
366
|
this.chatOrigin = surfaceOfUrl(opts.chatUrl) === 'work' ? new URL(opts.chatUrl).origin : Url.origin;
|
|
329
367
|
}
|
|
@@ -555,8 +593,163 @@ export class CopilotTransport {
|
|
|
555
593
|
return false;
|
|
556
594
|
}
|
|
557
595
|
}
|
|
596
|
+
/**
|
|
597
|
+
* The box to write in, by the chat's locator in force (Settings' own, else the default; 2026-11-17). What it finds is
|
|
598
|
+
* taken if it can be written in, else the first box inside it that can: a locator copied from the page's inspector for
|
|
599
|
+
* an element around the box (the operator's of 2026-11-17 named the box's wrapper, `data-chat-input-pill`) finds it all
|
|
600
|
+
* the same.
|
|
601
|
+
*/
|
|
558
602
|
composer() {
|
|
559
|
-
return this.p
|
|
603
|
+
return this.p
|
|
604
|
+
.locator(this.sel('composer'))
|
|
605
|
+
.first()
|
|
606
|
+
.locator("xpath=descendant-or-self::*[(@contenteditable and @contenteditable != 'false') or self::textarea]")
|
|
607
|
+
.first();
|
|
608
|
+
}
|
|
609
|
+
/** What the message says when the box is not found: its locator in force, and where Settings has it. */
|
|
610
|
+
composerHint() {
|
|
611
|
+
return (`If the picture shows the chat with its box to write in, the box's locator does not find it: ${this.chatLocators.composer} ` +
|
|
612
|
+
'(Settings → "The chat\'s locators" → "Box to write in").');
|
|
613
|
+
}
|
|
614
|
+
/** A chat locator in force, as Playwright takes it; `chatId` goes where a template has its place. */
|
|
615
|
+
sel(key, chatId) {
|
|
616
|
+
const s = this.chatLocators[key];
|
|
617
|
+
return playwrightSelector(chatId === undefined ? s : s.split(CHAT_ID).join(chatId));
|
|
618
|
+
}
|
|
619
|
+
/** What a chat locator in force finds in the page. */
|
|
620
|
+
el(key, chatId) {
|
|
621
|
+
return this.p.locator(this.sel(key, chatId));
|
|
622
|
+
}
|
|
623
|
+
/**
|
|
624
|
+
* A locator that found nothing where the bot needed it (2026-11-17): a picture of the page and its HTML for a chatbot
|
|
625
|
+
* to find the right one in (scripts, styles and the sidebar out — see `pageHtml.ts`), kept in the failures folder, and
|
|
626
|
+
* said (`locator-missing`, which the API keeps so Settings can show the field in red). The error to throw when the
|
|
627
|
+
* work cannot go on without it; `stopped: false` when it goes on (a conversation's name). `message` is given the
|
|
628
|
+
* sentence naming the files.
|
|
629
|
+
*/
|
|
630
|
+
async locatorMissing(key, why, opts = {}) {
|
|
631
|
+
const stopped = opts.stopped ?? true;
|
|
632
|
+
const locator = this.chatLocators[key];
|
|
633
|
+
const open = !!this.page && !this.page.isClosed();
|
|
634
|
+
const dir = join(this.opts.transportDir, '..', 'failures');
|
|
635
|
+
const tag = `locator-${key}-${Date.now()}`;
|
|
636
|
+
let picture;
|
|
637
|
+
let html;
|
|
638
|
+
if (open) {
|
|
639
|
+
await mkdir(dir, { recursive: true }).catch(() => undefined);
|
|
640
|
+
const png = join(dir, `${tag}.png`);
|
|
641
|
+
if (await this.p.screenshot({ path: png, fullPage: true }).then(() => true, () => false))
|
|
642
|
+
picture = png;
|
|
643
|
+
const text = await this.p.evaluate(strippedPageHtml, ChatLocatorGroupOf[key] === 'conversations').catch(() => '');
|
|
644
|
+
const file = join(dir, `${tag}.html`);
|
|
645
|
+
if (text && (await writeFile(file, text, 'utf8').then(() => true, () => false)))
|
|
646
|
+
html = file;
|
|
647
|
+
}
|
|
648
|
+
const url = open ? whereIs(this.p.url()) : undefined;
|
|
649
|
+
this.emit('locator-missing', { key, locator, why, stopped, ...(html ? { html } : {}), ...(picture ? { picture } : {}), ...(url ? { url } : {}) });
|
|
650
|
+
const files = [picture ? `A picture of the page: ${picture}.` : '', html ? `The page's HTML, for a chatbot to find the right locator in: ${html}.` : ''].filter(Boolean).join(' ');
|
|
651
|
+
const message = opts.message?.(files) ??
|
|
652
|
+
`Not found on Copilot's page: ${ChatLocatorWhat[key]}. The "${key}" locator found nothing ${why}. In force: ${locator} ` +
|
|
653
|
+
`(Settings → "The chat's locators"). ${files}`.trim();
|
|
654
|
+
return new LocatorMissing(key, locator, message, html, picture);
|
|
655
|
+
}
|
|
656
|
+
/** A locator that found nothing where the work goes on without it (a conversation's name): said once a window. */
|
|
657
|
+
async warnLocator(key, why, chatId) {
|
|
658
|
+
if (this.warned.has(key) || !this.page || this.page.isClosed())
|
|
659
|
+
return;
|
|
660
|
+
if ((await this.el(key, chatId).count().catch(() => 1)) > 0)
|
|
661
|
+
return;
|
|
662
|
+
this.warned.add(key);
|
|
663
|
+
await this.locatorMissing(key, why, { stopped: false, ...(chatId ? { chatId } : {}) });
|
|
664
|
+
}
|
|
665
|
+
/**
|
|
666
|
+
* Looks for each of the chat's locators in force in the page (operator, 2026-11-17: "make the 'Check the locators'
|
|
667
|
+
* button too"), and says for each what it found. Only reads and looks:
|
|
668
|
+
* - the chat as it was opened: its box, and its Send (one letter typed and taken out again, if Send shows only with
|
|
669
|
+
* text; nothing is sent);
|
|
670
|
+
* - the sidebar;
|
|
671
|
+
* - the newest conversation in it, opened by its address: its messages, its answers, their Copy;
|
|
672
|
+
* - its "More" button, whose menu is opened and closed again with Escape, for "Rename".
|
|
673
|
+
* The rename dialog is not opened, and Stop shows only while Copilot writes: those are said as not on the page then.
|
|
674
|
+
* One that finds nothing is said as a failure the work went on without (`locator-missing`, its HTML kept), so its
|
|
675
|
+
* field goes red in Settings.
|
|
676
|
+
*/
|
|
677
|
+
async checkLocators() {
|
|
678
|
+
const out = new Map();
|
|
679
|
+
const why = 'when the locators were checked ("Check the locators" in Settings)';
|
|
680
|
+
const count = async (key, chatId) => await this.el(key, chatId).count().catch(() => 0);
|
|
681
|
+
const record = async (key, n, chatId, note) => {
|
|
682
|
+
out.set(key, { key, status: n > 0 ? 'found' : 'none', count: n, ...(note ? { note } : {}) });
|
|
683
|
+
if (n === 0)
|
|
684
|
+
await this.locatorMissing(key, why, { stopped: false, ...(chatId ? { chatId } : {}) }).catch(() => undefined);
|
|
685
|
+
return n;
|
|
686
|
+
};
|
|
687
|
+
const look = async (key, chatId) => await record(key, await count(key, chatId), chatId);
|
|
688
|
+
const notHere = (key, note) => {
|
|
689
|
+
out.set(key, { key, status: 'not-here', count: 0, note });
|
|
690
|
+
};
|
|
691
|
+
// The chat as it was opened: its box, and its Send.
|
|
692
|
+
const box = await look('composer');
|
|
693
|
+
let send = await count('send');
|
|
694
|
+
if (send === 0 && box > 0) {
|
|
695
|
+
// Send shown only once the box holds text: one letter, taken out again. Nothing is sent.
|
|
696
|
+
await this.composer().fill('x').catch(() => undefined);
|
|
697
|
+
await this.p.waitForTimeout(500);
|
|
698
|
+
send = await count('send');
|
|
699
|
+
await this.composer().fill('').catch(() => undefined);
|
|
700
|
+
}
|
|
701
|
+
await record('send', send);
|
|
702
|
+
// Stop shows only while Copilot writes.
|
|
703
|
+
const stop = await count('stop');
|
|
704
|
+
if (stop > 0)
|
|
705
|
+
out.set('stop', { key: 'stop', status: 'found', count: stop });
|
|
706
|
+
else
|
|
707
|
+
notHere('stop', 'writing');
|
|
708
|
+
// The sidebar, and the newest conversation in it, opened by its address: only read.
|
|
709
|
+
const links = await look('conversationLink');
|
|
710
|
+
const href = links > 0 ? await this.el('conversationLink').first().getAttribute('href').catch(() => null) : null;
|
|
711
|
+
const chatId = href ? parseChatId(href) : null;
|
|
712
|
+
const opened = chatId ? await this.openConversation(chatId).catch(() => false) : false;
|
|
713
|
+
if (opened && chatId) {
|
|
714
|
+
for (const key of ['turn', 'userMessage', 'answer', 'copy'])
|
|
715
|
+
await look(key);
|
|
716
|
+
// Its "More" button: by the locator; at its default and finding nothing, by its name in the row, as the bot does.
|
|
717
|
+
let more = this.el('chatMore', chatId).first();
|
|
718
|
+
let found = await count('chatMore', chatId);
|
|
719
|
+
let note;
|
|
720
|
+
if (found === 0 && this.chatLocators.chatMore === DefaultChatLocators.chatMore) {
|
|
721
|
+
const row = this.el('conversationLink').and(this.p.locator(`[href*="${chatId}"]`)).first();
|
|
722
|
+
const byName = row.locator('xpath=ancestor-or-self::*[self::li or self::div][1]').getByRole('button', { name: Rename.moreButtonLabel, exact: true });
|
|
723
|
+
const n = await byName.count().catch(() => 0);
|
|
724
|
+
if (n > 0) {
|
|
725
|
+
more = byName.first();
|
|
726
|
+
found = n;
|
|
727
|
+
note = 'byName';
|
|
728
|
+
}
|
|
729
|
+
}
|
|
730
|
+
await record('chatMore', found, chatId, note);
|
|
731
|
+
if (found > 0) {
|
|
732
|
+
await this.press(more).catch(() => undefined);
|
|
733
|
+
await this.el('renameItem').first().waitFor({ state: 'visible', timeout: 3_000 }).catch(() => undefined);
|
|
734
|
+
await look('renameItem');
|
|
735
|
+
await this.dismissOpenMenu().catch(() => undefined);
|
|
736
|
+
}
|
|
737
|
+
else
|
|
738
|
+
notHere('renameItem', 'noMenu');
|
|
739
|
+
}
|
|
740
|
+
else {
|
|
741
|
+
for (const key of ['turn', 'userMessage', 'answer', 'copy', 'chatMore', 'renameItem'])
|
|
742
|
+
notHere(key, 'noConversation');
|
|
743
|
+
}
|
|
744
|
+
// The rename dialog is not opened: renaming is not this check's to do.
|
|
745
|
+
notHere('renameInput', 'dialog');
|
|
746
|
+
notHere('renameSave', 'dialog');
|
|
747
|
+
this.emit('locators-checked', { found: [...out.values()].filter((c) => c.status === 'found').length, none: [...out.values()].filter((c) => c.status === 'none').map((c) => c.key) });
|
|
748
|
+
return CHAT_LOCATOR_KEYS.map((k) => out.get(k) ?? { key: k, status: 'not-here', count: 0 });
|
|
749
|
+
}
|
|
750
|
+
/** Whether the box to write in is empty: a message clicked away with Send leaves it so. */
|
|
751
|
+
async boxIsEmpty() {
|
|
752
|
+
return ((await this.composer().innerText({ timeout: 2_000 }).catch(() => 'unread')) ?? '').trim() === '';
|
|
560
753
|
}
|
|
561
754
|
/** Whether the composer shows within `ms`, looked for a second at a time; a Stop ends the wait with `StoppedByOperator`. */
|
|
562
755
|
async composerWithin(ms, signal, stopped) {
|
|
@@ -581,10 +774,13 @@ export class CopilotTransport {
|
|
|
581
774
|
chatAddress(path) {
|
|
582
775
|
return `${this.chatOrigin}${path}`;
|
|
583
776
|
}
|
|
584
|
-
/**
|
|
777
|
+
/**
|
|
778
|
+
* Keeps the host the chat was found on — its box there, and staying — when it is the work Copilot's: the chat's
|
|
779
|
+
* addresses are opened there from then on. Whatever the path: on 2026-11-17 the work machine's chat was at `/home`.
|
|
780
|
+
*/
|
|
585
781
|
learnChatOrigin() {
|
|
586
782
|
const url = this.p.url();
|
|
587
|
-
if (
|
|
783
|
+
if (surfaceOfUrl(url) === 'work')
|
|
588
784
|
this.chatOrigin = new URL(url).origin;
|
|
589
785
|
}
|
|
590
786
|
/** Whether the box to write in is still there, on the same page, after `settleMs`: one that showed on the way elsewhere is not. */
|
|
@@ -679,12 +875,12 @@ export class CopilotTransport {
|
|
|
679
875
|
*/
|
|
680
876
|
async notTheChat() {
|
|
681
877
|
const url = this.p.url();
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
878
|
+
// Most likely the box itself (2026-11-17: Copilot's chat was at /home, its box changed): said as the box's locator.
|
|
879
|
+
return await this.locatorMissing('composer', `on ${whereIs(url)}, which did not turn into the chat`, {
|
|
880
|
+
message: (files) => `Copilot showed its page ${whereIs(url)} instead of the chat, and the chat did not open from there ` +
|
|
881
|
+
`(by its address on that host, nor by a link to it on the page). Nothing was sent. ${files} ${this.composerHint()}
|
|
882
|
+
Current URL: ${url}`,
|
|
883
|
+
});
|
|
688
884
|
}
|
|
689
885
|
/**
|
|
690
886
|
* Which Copilot we actually landed on.
|
|
@@ -699,7 +895,8 @@ Current URL: ${url}`);
|
|
|
699
895
|
const where = surfaceOfUrl(this.p.url());
|
|
700
896
|
if (where !== 'work')
|
|
701
897
|
return where;
|
|
702
|
-
|
|
898
|
+
// The box by the chat's locator in force (2026-11-17: the work page's box changed, and Settings may name it).
|
|
899
|
+
const hasWorkComposer = (await this.composer().count().catch(() => 0)) > 0;
|
|
703
900
|
return hasWorkComposer ? 'work' : 'unknown';
|
|
704
901
|
}
|
|
705
902
|
/**
|
|
@@ -776,14 +973,11 @@ Current URL: ${url}`);
|
|
|
776
973
|
'sign-in': 'The profile is signed out. Run "cop login".',
|
|
777
974
|
unknown: 'The page is not the Microsoft 365 Copilot chat.',
|
|
778
975
|
};
|
|
779
|
-
let picture = '';
|
|
780
976
|
if (where === 'unknown') {
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
await this.dumpFailure(dir, tag).catch(() => undefined);
|
|
784
|
-
picture = ` A picture of the page: ${join(dir, `${tag}.png`)}`;
|
|
977
|
+
throw await this.locatorMissing('composer', `on ${whereIs(url)}`, { message: (files) => `${explain.unknown} ${files} ${this.composerHint()}
|
|
978
|
+
Current URL: ${url}` });
|
|
785
979
|
}
|
|
786
|
-
throw new Error(`${explain[where] ?? explain.unknown}
|
|
980
|
+
throw new Error(`${explain[where] ?? explain.unknown}
|
|
787
981
|
Current URL: ${url}`);
|
|
788
982
|
}
|
|
789
983
|
/**
|
|
@@ -877,6 +1071,9 @@ Current URL: ${url}`);
|
|
|
877
1071
|
* types credentials; it only waits for the composer to appear.
|
|
878
1072
|
*/
|
|
879
1073
|
async ensureSignedIn(url = this.opts.chatUrl, opts = {}) {
|
|
1074
|
+
// A box locator saved in Settings that cannot be used: said once, before the box is looked for with the default.
|
|
1075
|
+
for (const problem of this.chatLocatorProblems.splice(0))
|
|
1076
|
+
this.emit('chat-locator-not-used', { problem });
|
|
880
1077
|
// Copilot's home page, where no conversation is expected until the run enters one.
|
|
881
1078
|
this.onChat = null;
|
|
882
1079
|
await this.p.goto(url, { waitUntil: 'domcontentloaded' });
|
|
@@ -915,8 +1112,14 @@ Current URL: ${url}`);
|
|
|
915
1112
|
// Another of Copilot's pages instead (2026-11-17): the chat opened from it, and said so when it would not.
|
|
916
1113
|
if ((await this.arrive(Url.newChatPath, undefined, '')) === 'elsewhere')
|
|
917
1114
|
throw await this.notTheChat();
|
|
918
|
-
// A chat slow to load: the rest of the minute it was always given (the page's default timeout).
|
|
919
|
-
await this.composer()
|
|
1115
|
+
// A chat slow to load: the rest of the minute it was always given (the page's default timeout); none by then, said.
|
|
1116
|
+
await this.composer()
|
|
1117
|
+
.waitFor({ state: 'visible', timeout: 45_000 })
|
|
1118
|
+
.catch(async (e) => {
|
|
1119
|
+
if (e.name !== 'TimeoutError')
|
|
1120
|
+
throw e;
|
|
1121
|
+
throw await this.locatorMissing('composer', 'on a new chat, within a minute');
|
|
1122
|
+
});
|
|
920
1123
|
await this.dismissPopups();
|
|
921
1124
|
this.onChat = 'new';
|
|
922
1125
|
}
|
|
@@ -935,7 +1138,7 @@ Current URL: ${url}`);
|
|
|
935
1138
|
}
|
|
936
1139
|
/** Finds a conversation by its exact name in the sidebar. */
|
|
937
1140
|
async openConversationByName(name) {
|
|
938
|
-
const row = this.p.locator(
|
|
1141
|
+
const row = this.el('conversationLink').and(this.p.locator(`[aria-label="${name.replace(/"/g, '\\"')}"]`));
|
|
939
1142
|
if ((await row.count()) === 0)
|
|
940
1143
|
return false;
|
|
941
1144
|
// The conversation it is, from the link's own address: the page's follows a moment after the click.
|
|
@@ -1068,7 +1271,7 @@ Current URL: ${url}`);
|
|
|
1068
1271
|
* of it when Copilot's dialog refused that one (see `chatNameForms`) — or false when it could not be renamed.
|
|
1069
1272
|
*/
|
|
1070
1273
|
async nameChat(chatId, name, opts = {}) {
|
|
1071
|
-
const row = this.p.locator(
|
|
1274
|
+
const row = this.el('conversationLink').and(this.p.locator(`[href*="${chatId}"]`)).first();
|
|
1072
1275
|
// Waited for, like everything below: a new chat's row appears in the sidebar some seconds after the
|
|
1073
1276
|
// reply, and `count()` read it as missing and returned without a word (live run 2026-10-03). The run
|
|
1074
1277
|
// tries again later when it is still not there (see `nameIfStillUnnamed` in taskRunner.ts).
|
|
@@ -1078,6 +1281,8 @@ Current URL: ${url}`);
|
|
|
1078
1281
|
}
|
|
1079
1282
|
catch {
|
|
1080
1283
|
this.emit('chat-name-failed', { chatId, name, error: `the conversation did not appear in the sidebar within ${Math.round(waitMs / 1000)} s` });
|
|
1284
|
+
// Not one conversation in the sidebar by its locator: the locator's, said; this one not there yet is not.
|
|
1285
|
+
await this.warnLocator('conversationLink', 'in the sidebar, while the conversation was to be named').catch(() => undefined);
|
|
1081
1286
|
return false;
|
|
1082
1287
|
}
|
|
1083
1288
|
/*
|
|
@@ -1090,6 +1295,8 @@ Current URL: ${url}`);
|
|
|
1090
1295
|
* own auto-generated titles instead of the name this runner gave them.
|
|
1091
1296
|
*/
|
|
1092
1297
|
let opened = false;
|
|
1298
|
+
// Which locator the step under way looks for: the one said when it finds nothing.
|
|
1299
|
+
let step = 'chatMore';
|
|
1093
1300
|
try {
|
|
1094
1301
|
await row.scrollIntoViewIfNeeded().catch(() => undefined);
|
|
1095
1302
|
// Briefly: a hover the sidebar takes waits out the page's whole timeout otherwise.
|
|
@@ -1100,20 +1307,24 @@ Current URL: ${url}`);
|
|
|
1100
1307
|
* section header — and Playwright retried for the whole minute (live 2026-10-05), so `press` clicks
|
|
1101
1308
|
* the element itself when the mouse cannot reach it.
|
|
1102
1309
|
*/
|
|
1103
|
-
const byChat = this.
|
|
1104
|
-
|
|
1310
|
+
const byChat = this.el('chatMore', chatId).first();
|
|
1311
|
+
// Through the row by its name only while the locator is the default: one set in Settings is the one used.
|
|
1312
|
+
const more = (await byChat.count()) > 0 || this.chatLocators.chatMore !== DefaultChatLocators.chatMore
|
|
1105
1313
|
? byChat
|
|
1106
1314
|
: row.locator('xpath=ancestor-or-self::*[self::li or self::div][1]').getByRole('button', { name: Rename.moreButtonLabel, exact: true }).first();
|
|
1107
1315
|
await more.waitFor({ state: 'attached', timeout: 5_000 });
|
|
1108
1316
|
await this.press(more);
|
|
1109
1317
|
opened = true;
|
|
1110
|
-
|
|
1318
|
+
step = 'renameItem';
|
|
1319
|
+
const item = this.el('renameItem').first();
|
|
1111
1320
|
await item.waitFor({ state: 'visible', timeout: 5_000 });
|
|
1112
1321
|
await this.press(item);
|
|
1113
1322
|
opened = false;
|
|
1114
|
-
|
|
1323
|
+
step = 'renameInput';
|
|
1324
|
+
const input = this.el('renameInput').first();
|
|
1115
1325
|
await input.waitFor({ state: 'visible', timeout: 10_000 });
|
|
1116
|
-
|
|
1326
|
+
step = 'renameSave';
|
|
1327
|
+
const save = this.el('renameSave').first();
|
|
1117
1328
|
/*
|
|
1118
1329
|
* Offered in shorter forms until the dialog takes one. Copilot refuses a name it counts as longer than 50
|
|
1119
1330
|
* characters, by a count that is not always ours, and its dialog then stays open over the chat (2026-10-17: "the
|
|
@@ -1155,6 +1366,8 @@ Current URL: ${url}`);
|
|
|
1155
1366
|
}
|
|
1156
1367
|
catch (e) {
|
|
1157
1368
|
this.emit('chat-name-failed', { chatId, name, error: e.message });
|
|
1369
|
+
// The step's locator, when it finds nothing: said (the name is the work's convenience; the work goes on).
|
|
1370
|
+
await this.warnLocator(step, `while the conversation was being named "${name}"`, chatId).catch(() => undefined);
|
|
1158
1371
|
return false;
|
|
1159
1372
|
}
|
|
1160
1373
|
finally {
|
|
@@ -2097,8 +2310,8 @@ Current URL: ${url}`);
|
|
|
2097
2310
|
* counted, with the rendered count as the fallback for a page that does not carry it.
|
|
2098
2311
|
*/
|
|
2099
2312
|
async turnCount() {
|
|
2100
|
-
|
|
2101
|
-
|
|
2313
|
+
// By the `turn` locator in force (2026-11-17), whatever its kind: CSS, XPath or Playwright's own.
|
|
2314
|
+
return await this.el('turn').evaluateAll((nodes) => {
|
|
2102
2315
|
let size = 0;
|
|
2103
2316
|
for (const n of nodes) {
|
|
2104
2317
|
const carrier = n.matches('[aria-setsize]') ? n : (n.querySelector('[aria-setsize]') ?? n.closest('[aria-setsize]'));
|
|
@@ -2107,17 +2320,13 @@ Current URL: ${url}`);
|
|
|
2107
2320
|
size = v;
|
|
2108
2321
|
}
|
|
2109
2322
|
return size > 0 ? size : nodes.length;
|
|
2110
|
-
}
|
|
2323
|
+
});
|
|
2111
2324
|
}
|
|
2112
2325
|
/** The newest user message as shown, for telling "landed but not counted" from "not sent". */
|
|
2113
2326
|
async lastUserTurnText() {
|
|
2114
|
-
|
|
2115
|
-
|
|
2116
|
-
|
|
2117
|
-
const last = nodes[nodes.length - 1];
|
|
2118
|
-
return last ? last.innerText : '';
|
|
2119
|
-
})
|
|
2120
|
-
.catch(() => '');
|
|
2327
|
+
const all = this.el('userMessage');
|
|
2328
|
+
const n = await all.count().catch(() => 0);
|
|
2329
|
+
return n > 0 ? ((await all.nth(n - 1).innerText({ timeout: 2_000 }).catch(() => '')) ?? '') : '';
|
|
2121
2330
|
}
|
|
2122
2331
|
/** Puts text in the composer and clicks Send. Enter is not used: it does not submit. */
|
|
2123
2332
|
async send(text, attachments = []) {
|
|
@@ -2128,10 +2337,17 @@ Current URL: ${url}`);
|
|
|
2128
2337
|
if (attachments.length > 0)
|
|
2129
2338
|
await this.attach(attachments);
|
|
2130
2339
|
const composer = this.composer();
|
|
2340
|
+
// The box, before it is clicked: none, its locator is said, rather than a minute's wait on the click.
|
|
2341
|
+
if (!(await this.composerWithin(10_000, undefined, '')))
|
|
2342
|
+
throw await this.locatorMissing('composer', 'when a message was to be written in it');
|
|
2131
2343
|
await composer.click();
|
|
2132
2344
|
await composer.fill(text);
|
|
2133
2345
|
const send = await this.sendButton();
|
|
2134
|
-
await send.waitFor({ state: 'visible', timeout:
|
|
2346
|
+
await send.waitFor({ state: 'visible', timeout: this.sendWaitMs }).catch(async (e) => {
|
|
2347
|
+
if (e.name !== 'TimeoutError')
|
|
2348
|
+
throw e;
|
|
2349
|
+
throw await this.locatorMissing('send', `after the message was written in the box, within ${Math.round(this.sendWaitMs / 1000)} s`);
|
|
2350
|
+
});
|
|
2135
2351
|
await send.click();
|
|
2136
2352
|
this.emit('message-sent', { chars: text.length, attachments: attachments.length });
|
|
2137
2353
|
}
|
|
@@ -2145,9 +2361,9 @@ Current URL: ${url}`);
|
|
|
2145
2361
|
* change here is the attribute name rather than the button.
|
|
2146
2362
|
*/
|
|
2147
2363
|
async sendButton() {
|
|
2148
|
-
|
|
2149
|
-
if ((await
|
|
2150
|
-
return
|
|
2364
|
+
// Settings' own; or the default — the Send in the box's wrapper — wherever the wrapper is on the page.
|
|
2365
|
+
if (this.chatLocators.send !== DefaultChatLocators.send || (await this.p.locator(Css.composerWrapper).count()) > 0) {
|
|
2366
|
+
return this.el('send').first();
|
|
2151
2367
|
}
|
|
2152
2368
|
const submit = this.p.locator(Css.composerSendSubmit);
|
|
2153
2369
|
if ((await submit.count()) > 0) {
|
|
@@ -2206,12 +2422,22 @@ Current URL: ${url}`);
|
|
|
2206
2422
|
this.retryBaselineTurns = before;
|
|
2207
2423
|
}
|
|
2208
2424
|
await this.send(text, attachments);
|
|
2209
|
-
const accepted = await this.waitForAccepted(before,
|
|
2425
|
+
const accepted = await this.waitForAccepted(before, this.acceptMs, text, shownBefore);
|
|
2210
2426
|
if (accepted)
|
|
2211
2427
|
return before;
|
|
2212
2428
|
const found = await this.detectBlocker();
|
|
2213
2429
|
lastProblem = found.kind === 'none' ? 'the message did not appear in the chat' : `${found.kind}: ${found.reason}`;
|
|
2214
2430
|
this.emit('send-not-accepted', { attempt, problem: lastProblem });
|
|
2431
|
+
/*
|
|
2432
|
+
* Sent — the box is empty — and neither a message of the conversation nor the one sent is found: the locators, not
|
|
2433
|
+
* the chat (2026-11-17). Said, and not sent again: a message that did land would be in the chat twice.
|
|
2434
|
+
*/
|
|
2435
|
+
if (found.kind === 'none' &&
|
|
2436
|
+
(await this.boxIsEmpty()) &&
|
|
2437
|
+
(await this.el('turn').count().catch(() => 0)) === 0 &&
|
|
2438
|
+
(await this.el('userMessage').count().catch(() => 0)) === 0) {
|
|
2439
|
+
throw await this.locatorMissing('turn', "after a message was sent: the box emptied, and neither the conversation's messages nor the message sent were found (the userMessage locator found nothing either)");
|
|
2440
|
+
}
|
|
2215
2441
|
if (found.kind !== 'none') {
|
|
2216
2442
|
const cleared = await this.handleBlocker(found);
|
|
2217
2443
|
if (!cleared) {
|
|
@@ -2285,29 +2511,25 @@ Current URL: ${url}`);
|
|
|
2285
2511
|
async waitForReply(previousTurns) {
|
|
2286
2512
|
const startedAt = Date.now();
|
|
2287
2513
|
const deadline = startedAt + this.opts.replyTimeoutMs;
|
|
2288
|
-
|
|
2289
|
-
|
|
2290
|
-
|
|
2291
|
-
|
|
2292
|
-
|
|
2293
|
-
|
|
2294
|
-
|
|
2295
|
-
|
|
2296
|
-
|
|
2297
|
-
|
|
2298
|
-
const
|
|
2299
|
-
const
|
|
2300
|
-
const
|
|
2301
|
-
|
|
2302
|
-
|
|
2303
|
-
}, {
|
|
2304
|
-
turnSel: `[data-testid="${TestId.turn}"]`,
|
|
2305
|
-
stopLabel: Label.stopGenerating,
|
|
2306
|
-
wrapperSel: Signal.answerWrapper,
|
|
2307
|
-
copySel: Signal.copyButtonInAnswer,
|
|
2308
|
-
});
|
|
2514
|
+
/*
|
|
2515
|
+
* Through the chat's locators in force (2026-11-17: each can be set in Settings): the conversation's size as the app
|
|
2516
|
+
* reports it (see turnCount), whether Copilot is still writing, and whether its newest answer is finished — its Copy
|
|
2517
|
+
* button there — with how long that answer's text is, to tell one standing still.
|
|
2518
|
+
*/
|
|
2519
|
+
const state = async () => {
|
|
2520
|
+
const turns = await this.turnCount();
|
|
2521
|
+
const streaming = (await this.el('stop').count()) > 0;
|
|
2522
|
+
const answers = this.el('answer');
|
|
2523
|
+
const n = await answers.count();
|
|
2524
|
+
const newest = n > 0 ? answers.nth(n - 1) : null;
|
|
2525
|
+
const chars = newest ? await newest.evaluate((el) => (el.textContent ?? '').length).catch(() => 0) : 0;
|
|
2526
|
+
const finished = !streaming && !!newest && (await newest.locator(this.sel('copy')).count()) > 0;
|
|
2527
|
+
return { turns, streaming, finished, answers: n, chars };
|
|
2528
|
+
};
|
|
2309
2529
|
let sawNewTurn = false;
|
|
2310
|
-
let last = { turns: previousTurns, streaming: false, finished: false };
|
|
2530
|
+
let last = { turns: previousTurns, streaming: false, finished: false, answers: 0, chars: 0 };
|
|
2531
|
+
// Since when Copilot's newest answer has stood still, not written and not finished (see below).
|
|
2532
|
+
let still = { since: Date.now(), chars: -1, answers: -1 };
|
|
2311
2533
|
while (Date.now() < deadline) {
|
|
2312
2534
|
if (this.p.isClosed()) {
|
|
2313
2535
|
throw new Error('The browser window was closed while waiting for a reply. If you did not close it, ' +
|
|
@@ -2331,6 +2553,29 @@ Current URL: ${url}`);
|
|
|
2331
2553
|
sawNewTurn = true;
|
|
2332
2554
|
if (sawNewTurn && last.finished)
|
|
2333
2555
|
break;
|
|
2556
|
+
/*
|
|
2557
|
+
* What a locator that no longer finds its element looks like (2026-11-17), said rather than waiting out the whole
|
|
2558
|
+
* reply time: not one message of the conversation found, though the message sent is in it; or Copilot's answer
|
|
2559
|
+
* begun, then standing still — not written any more, never finished — with no answer found at all, or no Copy
|
|
2560
|
+
* button anywhere on the page. A Copy missing from the newest answer alone is Copilot's, not the locator's.
|
|
2561
|
+
*/
|
|
2562
|
+
if (last.turns === 0 && Date.now() - startedAt >= this.turnsGraceMs) {
|
|
2563
|
+
throw await this.locatorMissing('turn', 'while the answer was awaited: not one message of the conversation was found, though the message sent is in it');
|
|
2564
|
+
}
|
|
2565
|
+
if (sawNewTurn && !last.streaming) {
|
|
2566
|
+
if (last.chars !== still.chars || last.answers !== still.answers)
|
|
2567
|
+
still = { since: Date.now(), chars: last.chars, answers: last.answers };
|
|
2568
|
+
else if (Date.now() - still.since >= this.answerStillMs) {
|
|
2569
|
+
if (last.answers === 0) {
|
|
2570
|
+
throw await this.locatorMissing('answer', `while the answer was awaited: Copilot's turn began and, ${Math.round((Date.now() - startedAt) / 1000)} s on, no answer was found`);
|
|
2571
|
+
}
|
|
2572
|
+
if ((await this.el('copy').count().catch(() => 1)) === 0) {
|
|
2573
|
+
throw await this.locatorMissing('copy', `in Copilot's answers: the newest had not changed for ${Math.round(this.answerStillMs / 1000)} s, was not being written, and no answer had a Copy button`);
|
|
2574
|
+
}
|
|
2575
|
+
}
|
|
2576
|
+
}
|
|
2577
|
+
else
|
|
2578
|
+
still = { since: Date.now(), chars: -1, answers: -1 };
|
|
2334
2579
|
// Only look for blockers while nothing is streaming, so the check stays cheap.
|
|
2335
2580
|
if (!last.streaming) {
|
|
2336
2581
|
const blocker = await this.detectBlocker();
|
|
@@ -2393,7 +2638,7 @@ Current URL: ${url}`);
|
|
|
2393
2638
|
* all reachable from one locator.
|
|
2394
2639
|
*/
|
|
2395
2640
|
lastAnswer() {
|
|
2396
|
-
return this.
|
|
2641
|
+
return this.el('answer').last();
|
|
2397
2642
|
}
|
|
2398
2643
|
async lastMessageText() {
|
|
2399
2644
|
return (await this.lastAnswer().innerText().catch(() => '')) ?? '';
|
|
@@ -2428,7 +2673,7 @@ Current URL: ${url}`);
|
|
|
2428
2673
|
* as degraded, because that text is known to be lossy.
|
|
2429
2674
|
*/
|
|
2430
2675
|
async copyLastReply() {
|
|
2431
|
-
const copy = this.lastAnswer().
|
|
2676
|
+
const copy = this.lastAnswer().locator(this.sel('copy')).first();
|
|
2432
2677
|
try {
|
|
2433
2678
|
/*
|
|
2434
2679
|
* Two guards around one click, both about the neighbours.
|
|
@@ -230,6 +230,9 @@ export class KeptWindow {
|
|
|
230
230
|
listModels(...a) {
|
|
231
231
|
return this.withWindow(() => this.inner.listModels(...a));
|
|
232
232
|
}
|
|
233
|
+
checkLocators(...a) {
|
|
234
|
+
return this.withWindow(() => this.inner.checkLocators(...a));
|
|
235
|
+
}
|
|
233
236
|
}
|
|
234
237
|
/** A window kept for the work, its `window-closed` heard as it happens. */
|
|
235
238
|
export function keptWindow(make, opts) {
|