webhelm 1.0.26 → 1.0.27

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "webhelm",
3
- "version": "1.0.26",
3
+ "version": "1.0.27",
4
4
  "description": "Agent browser automation in a visible managed Chrome with persistent JavaScript sessions",
5
5
  "type": "module",
6
6
  "bin": {
@@ -7,8 +7,34 @@ export function targetUrl(projectId, threadId, message) {
7
7
  return "https://chatgpt.com/c/" + encodeURIComponent(threadId) +
8
8
  "?" + new URLSearchParams({ prompt: message });
9
9
  }
10
- export const PROBE_JS =
11
- `(() => { const visible=e=>!!e&&!!e.getClientRects().length&&getComputedStyle(e).visibility!=='hidden'; const body=(document.body?.innerText||'').toLowerCase(); if(body.includes('could not load this chatgpt conversation'))return {state:'BLOCKED',error:'thread_load_failed'}; if(body.includes('log in to chatgpt')||body.includes('sign in to chatgpt'))return {state:'BLOCKED',error:'authentication_required'}; const stop=[...document.querySelectorAll('button')].some(b=>{if(!visible(b))return false;const l=(b.getAttribute('aria-label')||'').trim().toLowerCase(),t=(b.getAttribute('title')||'').trim().toLowerCase(),d=(b.getAttribute('data-testid')||'').trim().toLowerCase();return ['stop generating','stop answering','stop response','stop'].includes(l)||['stop generating','stop answering'].includes(t)||['stop-button','stop-generating-button'].includes(d)}); if(stop)return {state:'RUNNING',stop_visible:true}; const e=document.querySelector('#prompt-textarea,[contenteditable="true"][data-lexical-editor="true"],[role="textbox"][contenteditable="true"],textarea'); const editable=e?.getAttribute?.('contenteditable')==='true'; return {state:visible(e)?'READY':'NOT_READY',stop_visible:false,composer_text:e?(editable?(e.textContent||''):(e.value||e.textContent||e.innerText||'')):''}; })()`;
10
+ export const PROBE_JS = `(() => {
11
+ const visible = e => !!e && !!e.getClientRects().length && getComputedStyle(e).visibility !== 'hidden';
12
+ const body = (document.body?.innerText || '').toLowerCase();
13
+ if (body.includes('could not load this chatgpt conversation'))
14
+ return {state: 'BLOCKED', error: 'thread_load_failed'};
15
+ if (body.includes('log in to chatgpt') || body.includes('sign in to chatgpt'))
16
+ return {state: 'BLOCKED', error: 'authentication_required'};
17
+ const stop = [...document.querySelectorAll('button')].some(b => {
18
+ if (!visible(b)) return false;
19
+ const label = (b.getAttribute('aria-label') || '').trim().toLowerCase();
20
+ const title = (b.getAttribute('title') || '').trim().toLowerCase();
21
+ const testId = (b.getAttribute('data-testid') || '').trim().toLowerCase();
22
+ return ['stop generating', 'stop answering', 'stop response', 'stop'].includes(label) ||
23
+ ['stop generating', 'stop answering'].includes(title) ||
24
+ ['stop-button', 'stop-generating-button'].includes(testId);
25
+ });
26
+ if (stop) return {state: 'RUNNING', stop_visible: true};
27
+ const e = [...document.querySelectorAll('#prompt-textarea,[contenteditable="true"][data-lexical-editor="true"],[role="textbox"][contenteditable="true"],textarea')].find(visible);
28
+ const editable = e?.getAttribute?.('contenteditable') === 'true';
29
+ // ProseMirror uses <p> for each visual line, including empty lines.
30
+ // e.textContent and, in some Chrome builds, e.innerText omit those line
31
+ // boundaries, so a correctly prefilled multiline prompt never matches.
32
+ const paragraphs = editable ? [...e.children] : [];
33
+ const composerText = editable && paragraphs.length && paragraphs.every(p => p.tagName === 'P')
34
+ ? paragraphs.map(p => p.textContent || '').join('\\n')
35
+ : editable ? (e.innerText || e.textContent || '') : (e?.value || e?.textContent || e?.innerText || '');
36
+ return {state: visible(e) ? 'READY' : 'NOT_READY', stop_visible: false, composer_text: composerText};
37
+ })()`;
12
38
  export function classifyProbe(observedUrl, expectedUrl, state) {
13
39
  const actual = new URL(observedUrl), expected = new URL(expectedUrl);
14
40
  const thread = url => {
@@ -64,6 +64,10 @@ const chatgptQueuePolicy = {
64
64
  claim(db, owner, now, leaseSeconds) {
65
65
  db.prepare("UPDATE turns SET state='UNCERTAIN',lease_owner=NULL,lease_until=NULL WHERE state='SENDING' AND lease_until<=?").run(now);
66
66
  db.prepare("UPDATE turns SET state='WAITING',lease_owner=NULL,lease_until=NULL,next_check_at=? WHERE state='CHECKING' AND lease_until<=?").run(now,now);
67
+ // BLOCKED is a pre-send failure. Retry after cooldown so a transient
68
+ // login or redirect cannot permanently starve all later turns in a thread.
69
+ // UNCERTAIN remains excluded: that turn might already have been sent.
70
+ db.prepare("UPDATE turns SET state='WAITING',lease_owner=NULL,lease_until=NULL,next_check_at=? WHERE state='BLOCKED' AND next_check_at<=?").run(now,now);
67
71
  const row=this.one(db, `SELECT t.* FROM turns t WHERE t.state IN ('QUEUED','WAITING') AND t.next_check_at<=? AND NOT EXISTS(SELECT 1 FROM turns older WHERE older.thread_id=t.thread_id AND older.seq<t.seq AND (older.state NOT IN ('SENT','CANCELLED') OR (older.state='SENT' AND older.next_check_at>?))) ORDER BY t.seq LIMIT 1`,now,now);
68
72
  if (!row) return null;
69
73
  db.prepare("UPDATE turns SET state='CHECKING',lease_owner=?,lease_until=?,attempts=attempts+1 WHERE id=?").run(owner,now+leaseSeconds,row.id);
@@ -181,7 +185,7 @@ export class ChatGPTQueue extends DurableQueueCore {
181
185
  target,
182
186
  release ? null : owner,
183
187
  release ? null : now + 120,
184
- ["WAITING", "SENT"].includes(target) ? now + delay : now,
188
+ ["WAITING", "SENT", "BLOCKED"].includes(target) ? now + delay : now,
185
189
  receipt,
186
190
  id,
187
191
  );
@@ -283,9 +287,12 @@ export class ChatGPTQueue extends DurableQueueCore {
283
287
  return;
284
288
  }
285
289
  if (state === "BLOCKED") {
290
+ // Recheck pre-send failures with bounded exponential backoff (1m..1h).
291
+ const delay = Math.min(3600, 60 * (2 ** Math.min(6, Math.max(0, item.attempts - 1))));
286
292
  this.transition(item.id, owner, "CHECKING", "BLOCKED", {
287
- receipt: "page blocked",
293
+ receipt: "page blocked", delay,
288
294
  });
295
+ this.logger({event: "page_blocked", queue_id: item.id, attempts: item.attempts, retry_in_seconds: delay});
289
296
  return;
290
297
  }
291
298
  if (state !== "READY") {
@@ -1,6 +1,6 @@
1
1
  import { waitUntilStable } from "./readiness.mjs";
2
2
  export const SEND_ENABLED_JS =
3
- `(() => { const b=document.querySelector('button[data-testid="send-button"],button[aria-label="Send prompt"],button[aria-label="Send"],form button[type="submit"]'); return !!b && !b.disabled && b.getAttribute('aria-disabled') !== 'true'; })()`;
3
+ `(() => { const buttons=[...document.querySelectorAll('button[data-testid="send-button"],button[aria-label="Send prompt"],button[aria-label="Send"],form button[type="submit"]')]; const b=buttons.find(e=>e.getClientRects().length>0); return !!b && !b.disabled && b.getAttribute('aria-disabled') !== 'true'; })()`;
4
4
  export const CLICK_SEND_JS =
5
5
  `(() => { const visible=e=>!!e&&!!e.getClientRects().length; const running=[...document.querySelectorAll('button')].some(b=>{ if(!visible(b))return false; const l=(b.getAttribute('aria-label')||'').trim().toLowerCase(),t=(b.getAttribute('title')||'').trim().toLowerCase(),d=(b.getAttribute('data-testid')||'').trim().toLowerCase(); return ['stop generating','stop answering','stop response','stop'].includes(l)||['stop generating','stop answering'].includes(t)||['stop-button','stop-generating-button'].includes(d); }); if(running)return false; const b=document.querySelector('button[data-testid="send-button"],button[aria-label="Send prompt"],button[aria-label="Send"],form button[type="submit"]'); if(!b||b.disabled||b.getAttribute('aria-disabled')==='true')return false; b.click(); return true; })()`;
6
6
  export function targetUrl(