webhelm 1.0.50 → 1.0.51
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 +1 -1
- package/runtime/extension/control-channel.mjs +3 -2
- package/runtime/extension/manifest.json +1 -1
- package/runtime/extension/popup-data.mjs +5 -9
- package/runtime/extension/popup.mjs +5 -9
- package/runtime/platform-delivery-queue.mjs +38 -28
- package/runtime/queue-registry.mjs +2 -1
- package/scripts/chatgpt-three-mvps.mjs +7 -2
package/package.json
CHANGED
|
@@ -82,11 +82,12 @@ export class ControlChannel {
|
|
|
82
82
|
return this.serialize(async () => {
|
|
83
83
|
if (typeof queueId !== 'string' || !queueId) throw new Error('Queue item is required');
|
|
84
84
|
const state = this.normalize(await this.read());
|
|
85
|
+
// The popup can lag the daemon. A vanished item is always a no-op.
|
|
86
|
+
if (!(state.queue || []).some(item => item.id === queueId))
|
|
87
|
+
return {ok:true,skipped:true};
|
|
85
88
|
if (state.request) throw new Error('Another WebHelm operation is already running');
|
|
86
89
|
if (!Number.isFinite(state.daemon?.seenAt) || this.now() - state.daemon.seenAt >= FRESH_MS)
|
|
87
90
|
throw new Error('WebHelm daemon is not responding');
|
|
88
|
-
if (!(state.queue || []).some(item => item.id === queueId && ['QUEUED','WAITING','BLOCKED','UNCERTAIN'].includes(item.state)))
|
|
89
|
-
throw new Error('Queue item is no longer cancellable');
|
|
90
91
|
const request = {id:this.makeId(), action:'queue-cancel', queueId, state:'pending', createdAt:this.now()};
|
|
91
92
|
await this.save({...state, request, lastResult:null});
|
|
92
93
|
return {id:request.id,state:'pending'};
|
|
@@ -55,14 +55,14 @@ export async function setStoredSite(chromeApi, url, enabled) {
|
|
|
55
55
|
return {id:origin,enabled:Boolean(enabled)};
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
-
const priority = {
|
|
58
|
+
const priority = {SENDING:0,CHECKING:0,QUEUED:1};
|
|
59
59
|
function threadKey(item) {
|
|
60
60
|
// Queue groups are provided by registered Platform Policies.
|
|
61
61
|
return `${item.platform||'Queue'}\u0000${item.group||item.id}`;
|
|
62
62
|
}
|
|
63
63
|
|
|
64
64
|
export function compactQueue(items, {expanded=false,maxHeads=8}={}) {
|
|
65
|
-
const all=Array.isArray(items) ? items : [];
|
|
65
|
+
const all=Array.isArray(items) ? items.filter(item=>['QUEUED','CHECKING','SENDING'].includes(item.state)) : [];
|
|
66
66
|
const threads=new Map();
|
|
67
67
|
for (const [index,item] of all.entries()) {
|
|
68
68
|
const key=threadKey(item);
|
|
@@ -75,9 +75,8 @@ export function compactQueue(items, {expanded=false,maxHeads=8}={}) {
|
|
|
75
75
|
const visible=expanded ? heads.flatMap(x=>x.items) : heads.slice(0,Math.max(1,maxHeads)).map(x=>x.head);
|
|
76
76
|
const headFor=new Map(heads.flatMap(x=>x.items.map(item=>[item.id,x.head])));
|
|
77
77
|
const behind=new Map(heads.map(x=>[x.head.id,x.count-1]));
|
|
78
|
-
const failed=all.filter(x=>x.state==='FAILED').length;
|
|
79
78
|
return {visible,total:all.length,threads:threads.size,behind,headFor,
|
|
80
|
-
hidden:all.length-visible.length
|
|
79
|
+
hidden:all.length-visible.length};
|
|
81
80
|
}
|
|
82
81
|
|
|
83
82
|
// Statuses describe what the user can do, not internal retry counters.
|
|
@@ -86,17 +85,14 @@ export function queueStatusText(item,{head=item,remaining=0}={}) {
|
|
|
86
85
|
const state=String(item.state||'QUEUED').toUpperCase();
|
|
87
86
|
const following=head.id!==item.id;
|
|
88
87
|
let message;
|
|
89
|
-
if(following
|
|
90
|
-
else if(following) message='Waiting behind earlier message';
|
|
88
|
+
if(following) message='Waiting behind earlier message';
|
|
91
89
|
else message=({
|
|
92
|
-
FAILED:'Action failed — not retried',
|
|
93
90
|
SENDING:'Sending',
|
|
94
91
|
CHECKING:'Checking delivery',
|
|
95
|
-
WAITING:'Waiting to send',
|
|
96
92
|
QUEUED:'Queued to send',
|
|
97
93
|
})[state]||state.toLowerCase();
|
|
98
94
|
if(!following && remaining>0)
|
|
99
|
-
message+=' · '+remaining+' later message'+(remaining===1?'':'s')+
|
|
95
|
+
message+=' · '+remaining+' later message'+(remaining===1?'':'s')+' waiting';
|
|
100
96
|
return message;
|
|
101
97
|
}
|
|
102
98
|
|
|
@@ -229,8 +229,7 @@ function renderQueue(items, busy, connected) {
|
|
|
229
229
|
const remove=actionButton('×',false,async()=>{
|
|
230
230
|
try{
|
|
231
231
|
const result=await rpc('workspace.control.queueCancel',{queueId:item.id});
|
|
232
|
-
if(
|
|
233
|
-
el('message').textContent='Waiting for WebHelm daemon…';
|
|
232
|
+
if(result.id)el('message').textContent='Waiting for WebHelm daemon…';
|
|
234
233
|
}catch(error){el('message').textContent=error.message;}
|
|
235
234
|
refresh();
|
|
236
235
|
},'queue-remove');
|
|
@@ -238,18 +237,15 @@ function renderQueue(items, busy, connected) {
|
|
|
238
237
|
}
|
|
239
238
|
const title=row.querySelector('.queue-title');
|
|
240
239
|
title.textContent=item.title||platform+' message';
|
|
241
|
-
title.title=
|
|
242
|
-
(item.state==='FAILED'?' — Action failed; no automatic retry.':'');
|
|
240
|
+
title.title=item.title||platform+' message';
|
|
243
241
|
row.dataset.queueId=item.id;
|
|
244
242
|
row.dataset.state=item.state;
|
|
245
|
-
row.classList.toggle('queue-failed',item.state==='FAILED');
|
|
246
243
|
const elapsed=formatQueueElapsed(item.created_at,queueOpenedAtSeconds);
|
|
247
244
|
const attempts=Math.max(0,Number(item.attempts)||0);
|
|
248
|
-
row.querySelector('.queue-meta').textContent=
|
|
245
|
+
row.querySelector('.queue-meta').textContent='('+(elapsed??'–')+'/'+attempts+')';
|
|
249
246
|
const remove=row.querySelector('.queue-remove');
|
|
250
|
-
|
|
251
|
-
remove.
|
|
252
|
-
remove.title=cancellable?'Remove '+title.textContent+' from queue':'Cannot remove a running or completed submission';
|
|
247
|
+
remove.disabled=busy||!connected;
|
|
248
|
+
remove.title='Cancel '+title.textContent+' (best effort before sending)';
|
|
253
249
|
remove.setAttribute('aria-label',remove.title);
|
|
254
250
|
if(row.parentElement!==rows)rows.append(row);
|
|
255
251
|
}
|
|
@@ -55,7 +55,7 @@ const dbPolicy = {
|
|
|
55
55
|
}
|
|
56
56
|
const meta = display(this.definition, config);
|
|
57
57
|
const tail = db.prepare('SELECT * FROM items WHERE group_key=? ORDER BY seq DESC LIMIT 1').get(meta.group);
|
|
58
|
-
if (tail && config.mergeable === true &&
|
|
58
|
+
if (tail && config.mergeable === true && tail.state === 'QUEUED' &&
|
|
59
59
|
tail.lease_owner === null && typeof this.definition.merge === 'function') {
|
|
60
60
|
const previous = JSON.parse(tail.payload_json);
|
|
61
61
|
if (previous.mergeable === true) {
|
|
@@ -81,26 +81,32 @@ const dbPolicy = {
|
|
|
81
81
|
return {ok:true,status:'queued',queue_id:id,state:'QUEUED',group:meta.group};
|
|
82
82
|
},
|
|
83
83
|
claim(db, owner, now, leaseSeconds) {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
84
|
+
const retries=this.definition.retries??1;
|
|
85
|
+
// Expired sending leases have already counted as an attempt. Never exceed the policy budget.
|
|
86
|
+
db.prepare(`UPDATE items SET state=CASE WHEN attempts<=? THEN 'QUEUED' ELSE 'FAILED' END,
|
|
87
|
+
lease_owner=NULL,lease_until=NULL,next_check_at=?,receipt=COALESCE(receipt,'send_interrupted')
|
|
88
|
+
WHERE state='SENDING' AND lease_until<=?`).run(retries,now+(this.definition.intervalMs??10000)/1000,now);
|
|
89
|
+
// Expired read-only checks count as failures but cannot have clicked Send.
|
|
90
|
+
db.prepare(`UPDATE items SET state=CASE WHEN attempts<? THEN 'QUEUED' ELSE 'FAILED' END,
|
|
91
|
+
attempts=attempts+1,lease_owner=NULL,lease_until=NULL,next_check_at=?,receipt='validate_interrupted'
|
|
92
|
+
WHERE state='CHECKING' AND lease_until<=?`).run(retries,now+(this.definition.intervalMs??10000)/1000,now);
|
|
93
|
+
const row = db.prepare(`SELECT item.* FROM items item WHERE item.state='QUEUED' AND item.next_check_at<=?
|
|
87
94
|
AND NOT EXISTS (SELECT 1 FROM items older WHERE older.group_key=item.group_key AND older.seq<item.seq
|
|
88
95
|
AND (older.state NOT IN ('SENT','FAILED','CANCELLED') OR (older.state='SENT' AND older.next_check_at>?)))
|
|
89
96
|
ORDER BY item.seq LIMIT 1`).get(now,now);
|
|
90
97
|
if (!row) return null;
|
|
91
|
-
db.prepare("UPDATE items SET state='CHECKING',lease_owner=?,lease_until
|
|
98
|
+
db.prepare("UPDATE items SET state='CHECKING',lease_owner=?,lease_until=? WHERE id=?")
|
|
92
99
|
.run(owner,now+leaseSeconds,row.id);
|
|
93
100
|
return db.prepare('SELECT * FROM items WHERE id=?').get(row.id);
|
|
94
101
|
},
|
|
95
102
|
cancel(db, id) {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
return {ok:true,queue_id:id,state:'CANCELLED'};
|
|
103
|
+
// Best effort: a read-only CHECKING action can be cancelled before it sends.
|
|
104
|
+
// An already SENDING action must finish; the caller sees a silent no-op.
|
|
105
|
+
const result=db.prepare("UPDATE items SET state='CANCELLED',lease_owner=NULL,lease_until=NULL WHERE id=? AND state IN ('QUEUED','CHECKING')").run(id);
|
|
106
|
+
return {ok:true,queue_id:id,...(result.changes ? {state:'CANCELLED'} : {skipped:true})};
|
|
101
107
|
},
|
|
102
108
|
list(db) {
|
|
103
|
-
const items = db.prepare("SELECT * FROM items WHERE state
|
|
109
|
+
const items = db.prepare("SELECT * FROM items WHERE state IN ('QUEUED','CHECKING','SENDING') ORDER BY seq").all();
|
|
104
110
|
return {ok:true,items:items.map(row => ({id:row.id,queue_id:row.id,group:row.group_key,
|
|
105
111
|
state:row.state,attempts:row.attempts,created_at:row.created_at,
|
|
106
112
|
receipt:row.receipt,title:row.title,url:row.url}))};
|
|
@@ -123,6 +129,8 @@ export class PlatformDeliveryQueue extends DurableQueueCore {
|
|
|
123
129
|
attempts INTEGER NOT NULL DEFAULT 0, receipt TEXT);
|
|
124
130
|
CREATE INDEX IF NOT EXISTS queue_group_fifo ON items(group_key,seq);
|
|
125
131
|
CREATE TABLE IF NOT EXISTS request_keys(idem_key TEXT PRIMARY KEY,queue_id TEXT NOT NULL,payload_hash TEXT NOT NULL);`);
|
|
132
|
+
// Discard obsolete WAITING entries; never silently replay stale sends.
|
|
133
|
+
db.exec("UPDATE items SET state='CANCELLED' WHERE state='WAITING'");
|
|
126
134
|
const adapter=Object.create(dbPolicy);
|
|
127
135
|
super(db,adapter,now,{concurrency:concurrency??definition.concurrency??1,intervalMs:intervalMs??definition.intervalMs??10000});
|
|
128
136
|
adapter.definition=definition;
|
|
@@ -170,15 +178,15 @@ export class PlatformDeliveryQueue extends DurableQueueCore {
|
|
|
170
178
|
})};
|
|
171
179
|
}
|
|
172
180
|
has(id) { return Boolean(this.db.prepare('SELECT 1 FROM items WHERE id=?').get(id)); }
|
|
173
|
-
transition(id,owner,from,to,{delay=0,receipt=null}={}) {
|
|
181
|
+
transition(id,owner,from,to,{delay=0,receipt=null,incrementAttempt=false}={}) {
|
|
174
182
|
const now=this.now();
|
|
175
183
|
return this._transaction(()=>{
|
|
176
184
|
const row=this.db.prepare('SELECT state,lease_owner,lease_until FROM items WHERE id=?').get(id);
|
|
177
185
|
if (!row || row.state!==from || row.lease_owner!==owner || row.lease_until<=now) throw Error('stale queue lease');
|
|
178
|
-
this.db.prepare('UPDATE items SET state=?,lease_owner=?,lease_until=?,next_check_at=?,receipt
|
|
179
|
-
.run(to,['SENT','FAILED','
|
|
180
|
-
['SENT','FAILED','
|
|
181
|
-
now+delay,receipt,id);
|
|
186
|
+
this.db.prepare('UPDATE items SET state=?,lease_owner=?,lease_until=?,next_check_at=?,receipt=?,attempts=attempts+? WHERE id=?')
|
|
187
|
+
.run(to,['SENT','FAILED','QUEUED'].includes(to)?null:owner,
|
|
188
|
+
['SENT','FAILED','QUEUED'].includes(to)?null:now+this.leaseSeconds,
|
|
189
|
+
now+delay,receipt,incrementAttempt?1:0,id);
|
|
182
190
|
});
|
|
183
191
|
}
|
|
184
192
|
process(item) { return this._process(item); }
|
|
@@ -201,23 +209,17 @@ export class PlatformDeliveryQueue extends DurableQueueCore {
|
|
|
201
209
|
sid=started.session_id??started.sessionId;
|
|
202
210
|
if (!sid) throw Error('queue Session creation did not return session_id');
|
|
203
211
|
const checked=await this.runAction({platform:this.platform,action:definition.validate,config,session_id:sid});
|
|
204
|
-
if (checked?.result?.ok !== true)
|
|
205
|
-
// A failed read-only gate must not silently drop its FIFO head.
|
|
206
|
-
this.transition(item.id,item.lease_owner,'CHECKING','WAITING',{
|
|
207
|
-
delay:this.intervalMs/1000,receipt:'validate_error',
|
|
208
|
-
});
|
|
209
|
-
return;
|
|
210
|
-
}
|
|
212
|
+
if (checked?.result?.ok !== true) throw Error('validate_failed');
|
|
211
213
|
const value=checked.result.value;
|
|
212
214
|
const ready=checked?.result?.ok === true && (value === true || value?.ready === true || value?.status === 'ready');
|
|
213
215
|
if (!ready) {
|
|
214
|
-
this.transition(item.id,item.lease_owner,'CHECKING','
|
|
216
|
+
this.transition(item.id,item.lease_owner,'CHECKING','QUEUED',{
|
|
215
217
|
delay:this.intervalMs/1000,
|
|
216
218
|
receipt:'not_ready',
|
|
217
219
|
});
|
|
218
220
|
return;
|
|
219
221
|
}
|
|
220
|
-
this.transition(item.id,item.lease_owner,'CHECKING','SENDING');
|
|
222
|
+
this.transition(item.id,item.lease_owner,'CHECKING','SENDING',{incrementAttempt:true});
|
|
221
223
|
const outcome=await this.runAction({platform:this.platform,action:definition.action,
|
|
222
224
|
config:typeof definition.execute==='function'?definition.execute(config):config,session_id:sid});
|
|
223
225
|
if (outcome?.result?.ok!==true ||
|
|
@@ -229,9 +231,17 @@ export class PlatformDeliveryQueue extends DurableQueueCore {
|
|
|
229
231
|
} catch(error) {
|
|
230
232
|
const diagnostic='Error;fingerprint='+createHash('sha256').update(String(error)).digest('hex').slice(0,16);
|
|
231
233
|
try {
|
|
232
|
-
const row=this.db.prepare('SELECT state FROM items WHERE id=?').get(item.id);
|
|
233
|
-
|
|
234
|
-
|
|
234
|
+
const row=this.db.prepare('SELECT state,attempts FROM items WHERE id=?').get(item.id);
|
|
235
|
+
const retries=definition.retries??1;
|
|
236
|
+
if (row?.state==='SENDING') {
|
|
237
|
+
const retry=row.attempts<=retries;
|
|
238
|
+
this.transition(item.id,item.lease_owner,'SENDING',retry?'QUEUED':'FAILED',{
|
|
239
|
+
delay:retry?this.intervalMs/1000:0,receipt:diagnostic});
|
|
240
|
+
} else if (row?.state==='CHECKING') {
|
|
241
|
+
const retry=row.attempts<retries;
|
|
242
|
+
this.transition(item.id,item.lease_owner,'CHECKING',retry?'QUEUED':'FAILED',{
|
|
243
|
+
delay:retry?this.intervalMs/1000:0,receipt:diagnostic,incrementAttempt:true});
|
|
244
|
+
}
|
|
235
245
|
} catch(transitionError) { this.onDispatchError(transitionError); }
|
|
236
246
|
} finally {
|
|
237
247
|
clearInterval(heartbeat);
|
|
@@ -43,6 +43,7 @@ function validPolicy(definition, platform, root) {
|
|
|
43
43
|
}
|
|
44
44
|
if (definition.concurrency!==undefined && (!Number.isInteger(definition.concurrency) || definition.concurrency<1 || definition.concurrency>32)) throw TypeError('concurrency must be 1..32');
|
|
45
45
|
if (definition.intervalMs!==undefined && (!Number.isInteger(definition.intervalMs) || definition.intervalMs<100 || definition.intervalMs>3600000)) throw TypeError('intervalMs must be 100..3600000');
|
|
46
|
+
if (definition.retries!==undefined && (!Number.isInteger(definition.retries) || definition.retries<0 || definition.retries>100)) throw TypeError('retries must be 0..100');
|
|
46
47
|
}
|
|
47
48
|
|
|
48
49
|
export class PlatformQueueRegistry {
|
|
@@ -147,7 +148,7 @@ export class PlatformQueueRegistry {
|
|
|
147
148
|
list() { return {ok:true,items:[...this.records.values()].flatMap(({instance})=>instance.list().items)}; }
|
|
148
149
|
cancel(id) {
|
|
149
150
|
for (const {instance} of this.records.values()) if (instance.has(id)) return instance.cancel(id);
|
|
150
|
-
return {ok:
|
|
151
|
+
return {ok:true,queue_id:id,skipped:true};
|
|
151
152
|
}
|
|
152
153
|
activeCount() { return [...this.records.values()].reduce((sum,{instance})=>sum+instance.active.size,0); }
|
|
153
154
|
async stopScheduler() { this.paused=true;await Promise.all([...this.records.values()].map(({instance})=>instance.stopScheduler())); }
|
|
@@ -60,6 +60,10 @@ try {
|
|
|
60
60
|
assert.ok(sid,'failed to create owned real Chrome Session');
|
|
61
61
|
evidence.session_ids.push(sid);
|
|
62
62
|
record('session_started',{session_id:sid});
|
|
63
|
+
// Session creation schedules initial navigation; wait for it to settle before
|
|
64
|
+
// the new-thread Action navigates with its own ?prompt= URL.
|
|
65
|
+
const initialLoad=await ipc('exec',{session_id:sid,code:'await wait_for_load();'});
|
|
66
|
+
assert.equal(initialLoad?.ok,true,'new-thread browser Session did not finish initial load');
|
|
63
67
|
async function runDirect(action,config,session_id=sid) {
|
|
64
68
|
const value=await ipc('platform-run',{platform:'chatgpt',action,config,session_id,workspace:'WebHelm'});
|
|
65
69
|
const result=value?.result;
|
|
@@ -163,8 +167,9 @@ try {
|
|
|
163
167
|
states:[a.state,b.state],receipts:[a.receipt,b.receipt],
|
|
164
168
|
ordered_seq:[a.seq,b.seq],isolated_harness:isolatedManual};
|
|
165
169
|
record('MVP3_PASS',evidence.mvp3);
|
|
166
|
-
//
|
|
167
|
-
|
|
170
|
+
// A queue receipt can persist before its browser Session has fully returned to idle.
|
|
171
|
+
// Allow the daemon's awaited cleanup to finish without touching unrelated Sessions.
|
|
172
|
+
for(let i=0;i<45;i++) {
|
|
168
173
|
const remaining=(await sessions()).filter(x=>!existing.has(x.session_id));
|
|
169
174
|
if(!remaining.length) break;
|
|
170
175
|
await sleep(1000);
|