webhelm 1.0.32 → 1.0.34
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/README.md +1 -1
- package/package.json +1 -1
- package/runtime/admin.mjs +2 -1
- package/runtime/extension/control-rpc.mjs +3 -1
- package/runtime/extension/manifest.json +1 -1
- package/runtime/extension/popup-data.mjs +87 -0
- package/runtime/extension/popup.html +8 -1
- package/runtime/extension/popup.mjs +95 -53
- package/runtime/extension/service-worker.mjs +1 -1
- package/runtime/extension/workspace-manager.mjs +28 -5
- package/runtime/extension/workspace-summary.mjs +2 -1
- package/runtime/extension-manager.mjs +1 -1
- package/runtime/node-daemon.mjs +5 -2
package/README.md
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
|
|
12
12
|
The npm package **does not include** the Skill or site Actions. The Skill's executable uses `npm exec --yes --package=webhelm@latest -- webhelm` to avoid inherited npm lifecycle variable conflicts; its contents may update without a Runtime release.
|
|
13
13
|
|
|
14
|
-
The agent-facing `webhelm` CLI uses only the `WebHelm` Workspace. It intentionally does not accept `--workspace` or expose Workspace management helpers in `session exec`. `session stop --all` only stops WebHelm Sessions. Application services such as Relay provision their own named Workspaces through
|
|
14
|
+
The agent-facing `webhelm` CLI uses only the `WebHelm` Workspace. It intentionally does not accept `--workspace` or expose Workspace management helpers in `session exec`. `session stop --all` only stops WebHelm Sessions. Application services such as Relay provision their own named Workspaces through daemon IPC `workspace-create`, `workspace-resize`, `workspace-configure`, and `workspace-delete`; they may start Sessions via the daemon `start` operation for those pre-provisioned names. To hide a group from the extension toolbar menu without removing its Chrome tab group or Sessions, send `{ "op": "workspace-configure", "name": "WeChat", "show_in_menu": false }`. On creation, `workspace-create` also accepts optional `show_in_menu: false`. The setting is persisted in the Chrome profile; omitted values preserve existing visibility, and the default is visible. `workspace.list` and `workspace.status` still expose hidden groups and their `showInMenu` property; only `workspace.control.status().workspaces` filters hidden groups for the menu. Leasing a missing Workspace fails rather than creating it.
|
|
15
15
|
|
|
16
16
|
Neo Master development uses the Git checkout directly via local symlinks for the CLI, Skill, and Extension; production nodes use published npm Runtime installations. Set `WEBHELM_SOURCE_MODE=1` when running the checkout directly; this loads the Extension from the repository and creates a LaunchAgent that references the repository's CLI without staging an npm Runtime copy.
|
|
17
17
|
|
package/package.json
CHANGED
package/runtime/admin.mjs
CHANGED
|
@@ -3,5 +3,6 @@ import { RUNTIME_DIR } from './config-paths.mjs';
|
|
|
3
3
|
import path from 'node:path';
|
|
4
4
|
const socketPath=()=>process.env.WEBHELM_SOCKET||path.join(process.env.WEBHELM_RUNTIME_DIR||RUNTIME_DIR,'session-node.sock');
|
|
5
5
|
function request(payload){return new Promise((resolve,reject)=>{const s=net.createConnection(socketPath());let buf='';s.setEncoding('utf8');s.on('connect',()=>s.write(JSON.stringify(payload)+'\n'));s.on('data',d=>{buf+=d;if(!buf.includes('\n'))return;s.end();try{const v=JSON.parse(buf);v.error?reject(Error(v.error)):resolve(v)}catch(e){reject(e)}});s.on('error',reject)})}
|
|
6
|
-
export async function ensureWorkspace(name,size=5){if(typeof name!=='string'||!name.trim())throw TypeError('workspace name must be a non-empty string');if(!Number.isInteger(size)||size<1)throw TypeError('workspace size must be a positive integer');return request({op:'workspace-create',name:name.trim(),pool_size:size})}
|
|
6
|
+
export async function ensureWorkspace(name,size=5,{showInMenu}={}){if(typeof name!=='string'||!name.trim())throw TypeError('workspace name must be a non-empty string');if(!Number.isInteger(size)||size<1)throw TypeError('workspace size must be a positive integer');if(showInMenu!==undefined&&typeof showInMenu!=='boolean')throw TypeError('showInMenu must be a boolean');return request({op:'workspace-create',name:name.trim(),pool_size:size,...(showInMenu===undefined?{}:{show_in_menu:showInMenu})})}
|
|
7
|
+
export async function configureWorkspace(name,{showInMenu}={}){if(typeof name!=='string'||!name.trim())throw TypeError('workspace name must be a non-empty string');if(typeof showInMenu!=='boolean')throw TypeError('showInMenu must be a boolean');return request({op:'workspace-configure',name:name.trim(),show_in_menu:showInMenu})}
|
|
7
8
|
export async function deleteWorkspace(name,{force=false}={}){if(typeof name!=='string'||!name.trim())throw TypeError('workspace name must be a non-empty string');return request({op:'workspace-delete',name:name.trim(),force:Boolean(force)})}
|
|
@@ -22,7 +22,9 @@ export function createControlRpc({control, manager, summarizeWorkspaces, schedul
|
|
|
22
22
|
} catch { return {...session, tabId:null}; }
|
|
23
23
|
})),
|
|
24
24
|
})));
|
|
25
|
-
return {...state,...summary,
|
|
25
|
+
return {...state,...summary,
|
|
26
|
+
workspaces:workspaces.filter(workspace => workspace.showInMenu !== false),
|
|
27
|
+
keptSites:chromeApi.storage?.local ? await sitesWithStatus(chromeApi) : []};
|
|
26
28
|
}
|
|
27
29
|
case "workspace.control.activateTab": {
|
|
28
30
|
const state = await control.status();
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
// Pure display shaping. Keep pending work intact: folding never acknowledges,
|
|
2
|
+
// cancels, retries or removes an entry from the durable queue.
|
|
3
|
+
export const SITE_STORAGE_KEY = 'webhelm.keepalive.sites.v1';
|
|
4
|
+
export const SITE_STATUS_KEY = 'webhelm.keepalive.status.v1';
|
|
5
|
+
|
|
6
|
+
function validSite(site) {
|
|
7
|
+
if (!site || typeof site.id !== 'string' || site.id !== site.url || site.enabled !== true) return false;
|
|
8
|
+
try { const url = new URL(site.url); return url.protocol === 'https:' && url.origin === site.id; }
|
|
9
|
+
catch { return false; }
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function mergeKeptSites(persisted, statusById, reported) {
|
|
13
|
+
const sites = new Map();
|
|
14
|
+
for (const site of Array.isArray(persisted) ? persisted : []) {
|
|
15
|
+
if (validSite(site)) sites.set(site.id, {...site, status:statusById?.[site.id]?.status || 'pending'});
|
|
16
|
+
}
|
|
17
|
+
for (const site of Array.isArray(reported) ? reported : []) {
|
|
18
|
+
if (validSite(site)) sites.set(site.id, {...sites.get(site.id), ...site});
|
|
19
|
+
}
|
|
20
|
+
return [...sites.values()].sort((a,b)=>a.id.localeCompare(b.id));
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export async function readKeptSites(chromeApi, reported) {
|
|
24
|
+
let persisted=[], statuses={};
|
|
25
|
+
try {
|
|
26
|
+
const stored=await chromeApi.storage.local.get(SITE_STORAGE_KEY);
|
|
27
|
+
persisted=stored[SITE_STORAGE_KEY];
|
|
28
|
+
const latest=await chromeApi.storage.session.get(SITE_STATUS_KEY);
|
|
29
|
+
statuses=latest[SITE_STATUS_KEY] || {};
|
|
30
|
+
} catch { /* Keep any site entries returned by the current service worker. */ }
|
|
31
|
+
return mergeKeptSites(persisted,statuses,reported);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export async function setStoredSite(chromeApi, url, enabled) {
|
|
35
|
+
const origin = new URL(url).origin;
|
|
36
|
+
if (!/^https:\/\//.test(origin)) throw Error('Keep Alive requires HTTPS');
|
|
37
|
+
const stored=await chromeApi.storage.local.get(SITE_STORAGE_KEY);
|
|
38
|
+
const current=Array.isArray(stored[SITE_STORAGE_KEY]) ? stored[SITE_STORAGE_KEY] : [];
|
|
39
|
+
const next=current.filter(site=>site?.id!==origin);
|
|
40
|
+
if (enabled) next.push({id:origin,url:origin,enabled:true,addedAt:Date.now(),revision:crypto.randomUUID()});
|
|
41
|
+
await chromeApi.storage.local.set({[SITE_STORAGE_KEY]: next.sort((a,b)=>a.id.localeCompare(b.id))});
|
|
42
|
+
if (!enabled) {
|
|
43
|
+
const storedStates=await chromeApi.storage.session.get(SITE_STATUS_KEY);
|
|
44
|
+
const states=storedStates[SITE_STATUS_KEY] || {};
|
|
45
|
+
delete states[origin];
|
|
46
|
+
await chromeApi.storage.session.set({[SITE_STATUS_KEY]:states});
|
|
47
|
+
}
|
|
48
|
+
return {id:origin,enabled:Boolean(enabled)};
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const priority = {UNCERTAIN:0,BLOCKED:1,SENDING:2,CHECKING:2,WAITING:3,QUEUED:4};
|
|
52
|
+
function threadKey(item) {
|
|
53
|
+
// Old queue adapters might not identify threads; don't merge unrelated IDs.
|
|
54
|
+
return `${item.platform||'Queue'}\u0000${item.thread_id||item.id}`;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function compactQueue(items, {expanded=false,maxHeads=8}={}) {
|
|
58
|
+
const all=Array.isArray(items) ? items : [];
|
|
59
|
+
const threads=new Map();
|
|
60
|
+
for (const [index,item] of all.entries()) {
|
|
61
|
+
const key=threadKey(item);
|
|
62
|
+
if (!threads.has(key)) threads.set(key,{head:item,index,count:0});
|
|
63
|
+
threads.get(key).count++;
|
|
64
|
+
}
|
|
65
|
+
const heads=[...threads.values()].sort((a,b)=>
|
|
66
|
+
(priority[a.head.state]??5)-(priority[b.head.state]??5)||a.index-b.index);
|
|
67
|
+
const visible=expanded ? all : heads.slice(0,Math.max(1,maxHeads)).map(x=>x.head);
|
|
68
|
+
const behind=new Map(heads.map(x=>[x.head.id,x.count-1]));
|
|
69
|
+
const uncertain=all.filter(x=>x.state==='UNCERTAIN').length;
|
|
70
|
+
const blocked=all.filter(x=>x.state==='BLOCKED').length;
|
|
71
|
+
return {visible,total:all.length,threads:threads.size,behind,
|
|
72
|
+
hidden:all.length-visible.length,uncertain,blocked};
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// Keep hidden groups out of the toolbar even if a running older worker has
|
|
76
|
+
// not yet reloaded its control RPC. Do not mutate the persisted configuration.
|
|
77
|
+
export const WORKSPACE_STORAGE_KEY='browserWorkspaceManager.v1';
|
|
78
|
+
export function menuWorkspaces(workspaces,config={}) {
|
|
79
|
+
return (Array.isArray(workspaces)?workspaces:[]).filter(workspace =>
|
|
80
|
+
workspace.showInMenu !== false && config?.workspaces?.[workspace.name]?.showInMenu !== false);
|
|
81
|
+
}
|
|
82
|
+
export async function readMenuWorkspaces(chromeApi,workspaces) {
|
|
83
|
+
try {
|
|
84
|
+
const record=await chromeApi.storage.local.get(WORKSPACE_STORAGE_KEY);
|
|
85
|
+
return menuWorkspaces(workspaces,record[WORKSPACE_STORAGE_KEY]);
|
|
86
|
+
} catch { return menuWorkspaces(workspaces); }
|
|
87
|
+
}
|
|
@@ -41,7 +41,12 @@
|
|
|
41
41
|
.keepalive-row .keepalive-name.is-logged-in { color:#23915c; }
|
|
42
42
|
.keepalive-row .keepalive-remove { flex:0 0 19px; width:19px; padding:1px; border:0; background:transparent; color:light-dark(var(--muted),#acb8c9); font-size:16px; font-weight:400; line-height:18px; }
|
|
43
43
|
.session-row button.site-enabled { color:#23915c; }
|
|
44
|
-
#queue-list { border-top:1px solid light-dark(var(--border),#334155); padding-top:6px; margin-top:2px; }
|
|
44
|
+
#queue-list { border-top:1px solid light-dark(var(--border),#334155); padding-top:6px; margin-top:2px; max-height:240px; }
|
|
45
|
+
#queue-heading { display:flex; justify-content:space-between; align-items:center; gap:8px; margin-top:8px; }
|
|
46
|
+
#queue-heading strong { font-size:12px; }
|
|
47
|
+
#queue-count { color:light-dark(var(--muted),#acb8c9); font-size:11px; font-weight:400; }
|
|
48
|
+
#queue-toggle { width:auto; flex-shrink:0; padding:3px 6px; font-size:11px; }
|
|
49
|
+
#queue-note { color:light-dark(var(--muted),#acb8c9); font-size:11px; padding:5px 0; }
|
|
45
50
|
.queue-platform { padding:5px 0; }
|
|
46
51
|
.queue-platform + .queue-platform { border-top:1px solid light-dark(var(--border),#334155); }
|
|
47
52
|
.queue-platform-title { font-size:12px; }
|
|
@@ -68,6 +73,8 @@
|
|
|
68
73
|
<strong>Keep Alive Sites</strong>
|
|
69
74
|
<div id="keepalive-list" aria-label="Keep Alive Sites">Loading…</div>
|
|
70
75
|
<div id="workspace-list" class="session-list" aria-label="Workspaces" aria-live="polite">Connecting…</div>
|
|
76
|
+
<div id="queue-heading"><strong>Queue <span id="queue-count"></span></strong><button id="queue-toggle" type="button" aria-controls="queue-list" aria-expanded="false" hidden>Show all</button></div>
|
|
77
|
+
<div id="queue-note" role="status" hidden></div>
|
|
71
78
|
<div id="queue-list" class="session-list" aria-label="Queue" aria-live="polite">No queue entries</div>
|
|
72
79
|
<section id="confirmation" hidden aria-label="Confirm clear sessions">
|
|
73
80
|
<p id="confirm-text">Stop the selected WebHelm session(s)? Tasks in progress may be interrupted. Queued jobs remain and may create new sessions.</p>
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import {readKeptSites, setStoredSite, compactQueue, readMenuWorkspaces} from './popup-data.mjs';
|
|
1
2
|
const el = id => document.getElementById(id);
|
|
2
3
|
let confirming = false;
|
|
3
4
|
let chosen = null;
|
|
@@ -6,6 +7,11 @@ let lastQueueSignature = '';
|
|
|
6
7
|
let lastSiteSignature = '';
|
|
7
8
|
let currentSites = [];
|
|
8
9
|
let refreshRunning = false;
|
|
10
|
+
let canControlSites = false;
|
|
11
|
+
let queueExpanded = false;
|
|
12
|
+
let currentQueue = [];
|
|
13
|
+
let queueBusy = false;
|
|
14
|
+
let queueConnected = false;
|
|
9
15
|
const queueRows = new Map();
|
|
10
16
|
const queueGroups = new Map();
|
|
11
17
|
|
|
@@ -63,14 +69,19 @@ function renderKeptSites(sites, busy, connected) {
|
|
|
63
69
|
status.title=statusText;
|
|
64
70
|
status.setAttribute('aria-hidden','true');
|
|
65
71
|
const name=actionButton(new URL(site.url).hostname,false,async()=>{
|
|
66
|
-
try {
|
|
67
|
-
|
|
72
|
+
try {
|
|
73
|
+
if (canControlSites) await rpc('workspace.control.site.open',{siteId:site.id});
|
|
74
|
+
else await chrome.tabs.create({url:site.url,active:true});
|
|
75
|
+
} catch(error){el('message').textContent=error.message;}
|
|
68
76
|
},`tab-title keepalive-name ${loggedIn?'is-logged-in':''}`);
|
|
69
77
|
name.title=`${statusText} · Click to open site`;
|
|
70
78
|
name.setAttribute('aria-label',`${new URL(site.url).hostname}: ${statusText}. Open site`);
|
|
71
79
|
const remove=actionButton('×',false,async()=>{
|
|
72
|
-
try {
|
|
73
|
-
|
|
80
|
+
try {
|
|
81
|
+
if (canControlSites) await rpc('workspace.control.site.remove',{siteId:site.id});
|
|
82
|
+
else await setStoredSite(chrome,site.url,false);
|
|
83
|
+
lastSiteSignature='';lastSignature='';refresh();
|
|
84
|
+
} catch(error){el('message').textContent=error.message;}
|
|
74
85
|
},'keepalive-remove');
|
|
75
86
|
remove.title=`Remove ${new URL(site.url).hostname} from Keep Alive`;
|
|
76
87
|
remove.setAttribute('aria-label',remove.title);
|
|
@@ -82,7 +93,7 @@ function renderKeptSites(sites, busy, connected) {
|
|
|
82
93
|
function renderWorkspaces(workspaces, busy, connected) {
|
|
83
94
|
const signature = JSON.stringify(workspaces.map(w => [
|
|
84
95
|
w.name,w.initialized,w.available,w.poolSize,w.idleTabs,w.leasedTabs,w.sessions.map(s => [s.session_id,s.tab_title,s.tabId,s.tab_url]),
|
|
85
|
-
])) + ':' + JSON.stringify(currentSites.map(site=>site.id)) + ':' + busy + ':' + connected;
|
|
96
|
+
])) + ':' + JSON.stringify(currentSites.map(site=>site.id)) + ':' + canControlSites + ':' + busy + ':' + connected;
|
|
86
97
|
if (signature === lastSignature) return;
|
|
87
98
|
lastSignature = signature;
|
|
88
99
|
const target = el('workspace-list');
|
|
@@ -121,12 +132,14 @@ function renderWorkspaces(workspaces, busy, connected) {
|
|
|
121
132
|
sessionRow.append(details);
|
|
122
133
|
if (workspace.name === 'WebHelm' && siteId) {
|
|
123
134
|
const enabled=currentSites.some(site=>site.id===siteId);
|
|
124
|
-
|
|
135
|
+
const toggle=actionButton(enabled?'On':'Keep Alive',busy||!connected||!canControlSites,async()=>{
|
|
125
136
|
try {
|
|
126
137
|
await rpc('workspace.control.site.toggle',{sessionId:session.session_id,enabled:!enabled});
|
|
127
138
|
lastSignature='';refresh();
|
|
128
139
|
} catch(error){el('message').textContent=error.message;}
|
|
129
|
-
},enabled?'site-enabled':'')
|
|
140
|
+
},enabled?'site-enabled':'');
|
|
141
|
+
if(!canControlSites) toggle.title='Update the running WebHelm daemon to manage Keep Alive sites';
|
|
142
|
+
sessionRow.append(toggle);
|
|
130
143
|
}
|
|
131
144
|
sessionRow.append(actionButton('Stop', busy || !connected,
|
|
132
145
|
() => showConfirmation('stop', {sessionId:session.session_id})));
|
|
@@ -137,72 +150,92 @@ function renderWorkspaces(workspaces, busy, connected) {
|
|
|
137
150
|
}
|
|
138
151
|
|
|
139
152
|
function renderQueue(items, busy, connected) {
|
|
140
|
-
|
|
153
|
+
if(!items.length)queueExpanded=false;
|
|
154
|
+
const view=compactQueue(items,{expanded:queueExpanded,maxHeads:8});
|
|
155
|
+
const shown=view.visible;
|
|
156
|
+
const signature=JSON.stringify({shown:shown.map(item=>[item.id,item.platform,item.thread_id,item.title,item.url,item.state,item.attempts]),
|
|
157
|
+
total:view.total,threads:view.threads,hidden:view.hidden,uncertain:view.uncertain,blocked:view.blocked,
|
|
158
|
+
behind:[...view.behind],busy,connected,queueExpanded});
|
|
141
159
|
if (signature===lastQueueSignature) return;
|
|
142
160
|
lastQueueSignature=signature;
|
|
161
|
+
const count=el('queue-count');
|
|
162
|
+
count.textContent=view.total ? `${view.total} pending · ${view.threads} thread${view.threads===1?'':'s'}` : 'Empty';
|
|
163
|
+
const toggle=el('queue-toggle');
|
|
164
|
+
toggle.hidden=!(queueExpanded || view.hidden>0);
|
|
165
|
+
toggle.textContent=queueExpanded?'Show less':`Show all ${view.total}`;
|
|
166
|
+
toggle.setAttribute('aria-expanded',String(queueExpanded));
|
|
167
|
+
const note=el('queue-note');
|
|
168
|
+
note.hidden=!view.uncertain && !view.blocked;
|
|
169
|
+
if(!note.hidden) note.textContent=[
|
|
170
|
+
view.uncertain ? `${view.uncertain} uncertain` : '',
|
|
171
|
+
view.blocked ? `${view.blocked} blocked` : '',
|
|
172
|
+
].filter(Boolean).join(' · ') + ' — verify before retrying; later turns in the same thread may be waiting.';
|
|
173
|
+
|
|
143
174
|
const target=el('queue-list');
|
|
144
|
-
const grouped
|
|
145
|
-
for (const item of
|
|
146
|
-
const platform
|
|
147
|
-
if
|
|
175
|
+
const grouped=new Map();
|
|
176
|
+
for (const item of shown) {
|
|
177
|
+
const platform=String(item.platform||'Queue');
|
|
178
|
+
if(!grouped.has(platform)) grouped.set(platform,[]);
|
|
148
179
|
grouped.get(platform).push(item);
|
|
149
180
|
}
|
|
150
|
-
const activeGroupKeys
|
|
151
|
-
const activeRowKeys
|
|
152
|
-
for (const [key, group] of queueGroups) if
|
|
153
|
-
group.remove();
|
|
181
|
+
const activeGroupKeys=new Set(grouped.keys());
|
|
182
|
+
const activeRowKeys=new Set(shown.map(item=>`${item.platform||'Queue'}:${item.id}`));
|
|
183
|
+
for (const [key, group] of queueGroups) if(!activeGroupKeys.has(key)) {
|
|
184
|
+
group.remove();queueGroups.delete(key);
|
|
154
185
|
}
|
|
155
|
-
for (const [key, row] of queueRows) if
|
|
156
|
-
row.remove();
|
|
186
|
+
for (const [key, row] of queueRows) if(!activeRowKeys.has(key)) {
|
|
187
|
+
row.remove();queueRows.delete(key);
|
|
157
188
|
}
|
|
158
|
-
if
|
|
159
|
-
target.replaceChildren();
|
|
160
|
-
const empty=document.createElement('div');
|
|
189
|
+
if(!items.length) {
|
|
190
|
+
target.replaceChildren();queueGroups.clear();queueRows.clear();
|
|
191
|
+
const empty=document.createElement('div');empty.className='empty-queue';empty.textContent='No queue entries';
|
|
161
192
|
target.append(empty);
|
|
162
193
|
return;
|
|
163
194
|
}
|
|
164
195
|
target.querySelector('.empty-queue')?.remove();
|
|
165
|
-
for (const [platform,
|
|
166
|
-
let group
|
|
167
|
-
if
|
|
168
|
-
group
|
|
169
|
-
const heading
|
|
196
|
+
for (const [platform,entries] of grouped) {
|
|
197
|
+
let group=queueGroups.get(platform);
|
|
198
|
+
if(!group) {
|
|
199
|
+
group=document.createElement('section');group.className='queue-platform';
|
|
200
|
+
const heading=document.createElement('strong');heading.className='queue-platform-title';
|
|
170
201
|
heading.textContent=platform==='Queue'?'Queue':`${platform} Queue`;
|
|
171
|
-
const rows
|
|
172
|
-
group.append(heading,
|
|
202
|
+
const rows=document.createElement('div');rows.className='queue-platform-rows';
|
|
203
|
+
group.append(heading,rows);queueGroups.set(platform,group);target.append(group);
|
|
173
204
|
}
|
|
174
205
|
for (const item of entries) {
|
|
175
|
-
const key
|
|
176
|
-
let row
|
|
177
|
-
if
|
|
178
|
-
row=document.createElement('div');
|
|
179
|
-
const info=document.createElement('div');
|
|
180
|
-
const title=actionButton('',
|
|
181
|
-
try {
|
|
182
|
-
catch(error)
|
|
183
|
-
},
|
|
184
|
-
const detail=document.createElement('span');
|
|
185
|
-
const remove=actionButton('Remove',
|
|
186
|
-
try {
|
|
187
|
-
catch(error)
|
|
206
|
+
const key=`${platform}:${item.id}`;
|
|
207
|
+
let row=queueRows.get(key);
|
|
208
|
+
if(!row) {
|
|
209
|
+
row=document.createElement('div');row.className='queue-row';
|
|
210
|
+
const info=document.createElement('div');info.className='queue-info';
|
|
211
|
+
const title=actionButton('',false,async()=>{
|
|
212
|
+
try {await rpc('workspace.control.openQueue',{queueId:item.id});el('message').textContent='Queue destination opened.';}
|
|
213
|
+
catch(error){el('message').textContent=error.message;}
|
|
214
|
+
},'queue-title');
|
|
215
|
+
const detail=document.createElement('span');detail.className='queue-detail';
|
|
216
|
+
const remove=actionButton('Remove',false,async()=>{
|
|
217
|
+
try {const result=await rpc('workspace.control.queueCancel',{queueId:item.id});if(!result.id)throw Error('Missing queue request ID');el('message').textContent='Waiting for WebHelm daemon…';}
|
|
218
|
+
catch(error){el('message').textContent=error.message;}
|
|
188
219
|
refresh();
|
|
189
220
|
});
|
|
190
|
-
row.append(info,
|
|
191
|
-
queueRows.set(key,row);
|
|
221
|
+
row.append(info,remove);info.append(title,detail);queueRows.set(key,row);
|
|
192
222
|
}
|
|
193
223
|
const title=row.querySelector('.queue-title');
|
|
194
|
-
title.textContent=item.title
|
|
195
|
-
title.title=item.title
|
|
196
|
-
title.disabled=!connected
|
|
197
|
-
|
|
224
|
+
title.textContent=item.title||`${platform} message`;
|
|
225
|
+
title.title=item.title||`${platform} message`;
|
|
226
|
+
title.disabled=!connected||!item.url;
|
|
227
|
+
const attempts=Number(item.attempts)||0;
|
|
228
|
+
const more=!queueExpanded ? (view.behind.get(item.id)||0) : 0;
|
|
229
|
+
row.querySelector('.queue-detail').textContent=`${String(item.state||'queued').toLowerCase()} · ${attempts} attempt${attempts===1?'':'s'}`+
|
|
230
|
+
(more ? ` · ${more} more in this thread` : '');
|
|
198
231
|
const remove=row.querySelector('button:last-child');
|
|
199
232
|
const safe=['QUEUED','WAITING','BLOCKED','UNCERTAIN'].includes(item.state);
|
|
200
|
-
remove.disabled=!safe
|
|
233
|
+
remove.disabled=!safe||busy||!connected;
|
|
201
234
|
remove.title=safe?'':'Cannot remove a running or completed submission';
|
|
202
235
|
const rows=group.querySelector('.queue-platform-rows');
|
|
203
|
-
if
|
|
236
|
+
if(row.parentElement!==rows)rows.append(row);
|
|
204
237
|
}
|
|
205
|
-
if
|
|
238
|
+
if(group.parentElement!==target)target.append(group);
|
|
206
239
|
}
|
|
207
240
|
}
|
|
208
241
|
|
|
@@ -214,10 +247,13 @@ async function refresh() {
|
|
|
214
247
|
el('daemon-status').textContent = state.connected ? 'Online' : 'Offline';
|
|
215
248
|
el('daemon-status').className = `daemon-state ${state.connected ? 'online' : 'offline'}`;
|
|
216
249
|
const busy = Boolean(state.request);
|
|
217
|
-
|
|
250
|
+
canControlSites=Array.isArray(state.keptSites);
|
|
251
|
+
currentSites=await readKeptSites(chrome,state.keptSites);
|
|
218
252
|
renderKeptSites(currentSites,busy,state.connected);
|
|
219
|
-
renderWorkspaces(state.workspaces || [],
|
|
220
|
-
|
|
253
|
+
renderWorkspaces(await readMenuWorkspaces(chrome,state.workspaces || []),busy,state.connected);
|
|
254
|
+
currentQueue=state.queue||[];
|
|
255
|
+
queueBusy=busy;queueConnected=state.connected;
|
|
256
|
+
renderQueue(currentQueue,busy,state.connected);
|
|
221
257
|
el('confirm').disabled = !state.connected || busy;
|
|
222
258
|
if (busy) {
|
|
223
259
|
el('message').textContent = 'Applying WebHelm action…';
|
|
@@ -236,6 +272,12 @@ async function refresh() {
|
|
|
236
272
|
}
|
|
237
273
|
}
|
|
238
274
|
|
|
275
|
+
el('queue-toggle').addEventListener('click',()=>{
|
|
276
|
+
queueExpanded=!queueExpanded;
|
|
277
|
+
lastQueueSignature='';
|
|
278
|
+
renderQueue(currentQueue,queueBusy,queueConnected);
|
|
279
|
+
});
|
|
280
|
+
|
|
239
281
|
el('cancel').addEventListener('click', () => {
|
|
240
282
|
confirming = false;
|
|
241
283
|
el('confirmation').hidden = true;
|
|
@@ -89,7 +89,7 @@ globalThis.browserWorkspaceManagerRpc = async (request) => {
|
|
|
89
89
|
// or restore Workspace identities. A browser Session on an extension page must
|
|
90
90
|
// not gain management rights through chrome.runtime.sendMessage().
|
|
91
91
|
const APPLICATION_ONLY_METHODS = new Set([
|
|
92
|
-
"workspace.create", "workspace.resize", "workspace.delete",
|
|
92
|
+
"workspace.create", "workspace.resize", "workspace.configure", "workspace.delete",
|
|
93
93
|
"workspace.ensure", "workspace.migrateDefault",
|
|
94
94
|
"workspace.acquire", "workspace.acquireIdentity",
|
|
95
95
|
"workspace.release", "workspace.releaseAll",
|
|
@@ -208,6 +208,19 @@ export class WorkspaceManager {
|
|
|
208
208
|
await this.saveConfig(config);
|
|
209
209
|
}
|
|
210
210
|
|
|
211
|
+
async configure(name, {showInMenu} = {}) {
|
|
212
|
+
const normalizedName = normalizeWorkspaceName(name);
|
|
213
|
+
if (typeof showInMenu !== 'boolean') throw Error('showInMenu must be a boolean');
|
|
214
|
+
return this.workspaceLock(normalizedName).run(async () => {
|
|
215
|
+
const { config, entry } = await this.configuredWorkspace(normalizedName);
|
|
216
|
+
if (!entry) throw Error(`Workspace ${normalizedName} does not exist`);
|
|
217
|
+
config.workspaces[normalizedName] = {...entry, showInMenu};
|
|
218
|
+
await this.saveConfig(config);
|
|
219
|
+
// Visibility is presentation-only: never navigate, close or regroup tabs.
|
|
220
|
+
return this.status(normalizedName);
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
|
|
211
224
|
async removeConfig(name) {
|
|
212
225
|
const config = await this.loadConfig();
|
|
213
226
|
delete config.workspaces[name];
|
|
@@ -506,11 +519,18 @@ export class WorkspaceManager {
|
|
|
506
519
|
return await this.status(name);
|
|
507
520
|
}
|
|
508
521
|
|
|
509
|
-
async ensureWorkspace(name, poolSize = null) {
|
|
522
|
+
async ensureWorkspace(name, poolSize = null, showInMenu = undefined) {
|
|
510
523
|
const normalizedName = normalizeWorkspaceName(name);
|
|
511
524
|
const { entry } = await this.configuredWorkspace(normalizedName);
|
|
512
525
|
const wanted = normalizePoolSize(poolSize, entry?.poolSize ?? 8);
|
|
513
|
-
if (
|
|
526
|
+
if (showInMenu !== undefined && typeof showInMenu !== 'boolean')
|
|
527
|
+
throw Error('showInMenu must be a boolean');
|
|
528
|
+
if (!entry || entry.poolSize !== wanted || (showInMenu !== undefined && entry.showInMenu !== showInMenu)) {
|
|
529
|
+
const {config} = await this.configuredWorkspace(normalizedName);
|
|
530
|
+
config.workspaces[normalizedName] = {...(entry || {}), poolSize:wanted,
|
|
531
|
+
...(showInMenu === undefined ? {} : {showInMenu})};
|
|
532
|
+
await this.saveConfig(config);
|
|
533
|
+
}
|
|
514
534
|
|
|
515
535
|
const group = await this.workspaceGroup(normalizedName);
|
|
516
536
|
if (!group) return await this.createGroup(normalizedName, wanted);
|
|
@@ -545,6 +565,7 @@ export class WorkspaceManager {
|
|
|
545
565
|
name: normalizedName,
|
|
546
566
|
initialized: false,
|
|
547
567
|
poolSize: entry.poolSize,
|
|
568
|
+
showInMenu: entry.showInMenu !== false,
|
|
548
569
|
reason: "group-missing",
|
|
549
570
|
};
|
|
550
571
|
}
|
|
@@ -556,6 +577,7 @@ export class WorkspaceManager {
|
|
|
556
577
|
initialized: true,
|
|
557
578
|
groupId: group.id,
|
|
558
579
|
poolSize: entry.poolSize,
|
|
580
|
+
showInMenu: entry.showInMenu !== false,
|
|
559
581
|
maxCapacity: entry.poolSize,
|
|
560
582
|
physicalTabs: tabs.length,
|
|
561
583
|
idle: idle.length,
|
|
@@ -640,8 +662,8 @@ export class WorkspaceManager {
|
|
|
640
662
|
);
|
|
641
663
|
}
|
|
642
664
|
|
|
643
|
-
async create(name, poolSize = 8) {
|
|
644
|
-
return await this.ensureWorkspace(name, normalizePoolSize(poolSize));
|
|
665
|
+
async create(name, poolSize = 8, showInMenu = undefined) {
|
|
666
|
+
return await this.ensureWorkspace(name, normalizePoolSize(poolSize), showInMenu);
|
|
645
667
|
}
|
|
646
668
|
|
|
647
669
|
async resize(name, poolSize) {
|
|
@@ -833,7 +855,8 @@ export class WorkspaceManager {
|
|
|
833
855
|
async rpc(request) {
|
|
834
856
|
const method = String(request?.method || "");
|
|
835
857
|
const args = request?.args || {};
|
|
836
|
-
if (method === "workspace.create") return await this.create(args.name, args.poolSize);
|
|
858
|
+
if (method === "workspace.create") return await this.create(args.name, args.poolSize, args.showInMenu);
|
|
859
|
+
if (method === "workspace.configure") return await this.configure(args.name, {showInMenu:args.showInMenu});
|
|
837
860
|
if (method === "workspace.ensure") return await this.ensure(args.name, args.poolSize);
|
|
838
861
|
if (method === "workspace.status") return await this.status(args.name);
|
|
839
862
|
if (method === "workspace.list") return await this.list();
|
|
@@ -3,6 +3,7 @@ export function summarizeWorkspaces(workspaces, sessions = []) {
|
|
|
3
3
|
const configured = workspaces.map(workspace => ({
|
|
4
4
|
name: workspace.name,
|
|
5
5
|
initialized: Boolean(workspace.initialized),
|
|
6
|
+
showInMenu: workspace.showInMenu !== false,
|
|
6
7
|
poolSize: Number.isInteger(workspace.poolSize) ? workspace.poolSize : null,
|
|
7
8
|
idleTabs: workspace.initialized ? workspace.idle : null,
|
|
8
9
|
leasedTabs: workspace.initialized ? workspace.leased : null,
|
|
@@ -17,7 +18,7 @@ export function summarizeWorkspaces(workspaces, sessions = []) {
|
|
|
17
18
|
if (configuredNames.has(session.workspace)) continue;
|
|
18
19
|
configuredNames.add(session.workspace);
|
|
19
20
|
configured.push({
|
|
20
|
-
name: session.workspace, initialized: false, poolSize: null, idleTabs: null,
|
|
21
|
+
name: session.workspace, initialized: false, showInMenu: true, poolSize: null, idleTabs: null,
|
|
21
22
|
leasedTabs: null, available: null, sessions: sessions.filter(s => s.workspace === session.workspace),
|
|
22
23
|
reason: 'not-configured',
|
|
23
24
|
});
|
|
@@ -12,7 +12,7 @@ export const EXTENSION_HOME=path.resolve(process.env.WEBHELM_EXTENSION_HOME ||
|
|
|
12
12
|
(SOURCE_MODE ? SOURCE : path.join(LOCAL_ROOT,'extension')));
|
|
13
13
|
const FILES=[
|
|
14
14
|
'manifest.json','service-worker.mjs','workspace-manager.mjs','workspace.html','helm.html','workspace-page.mjs',
|
|
15
|
-
'control-channel.mjs','control-rpc.mjs','site-registry.mjs','workspace-summary.mjs','session-badge.mjs','popup.html','popup.mjs',
|
|
15
|
+
'control-channel.mjs','control-rpc.mjs','site-registry.mjs','popup-data.mjs','workspace-summary.mjs','session-badge.mjs','popup.html','popup.mjs',
|
|
16
16
|
...[16,32,48,128].map(size => `icons/webhelm-${size}.png`),
|
|
17
17
|
];
|
|
18
18
|
|
package/runtime/node-daemon.mjs
CHANGED
|
@@ -569,7 +569,10 @@ function heartbeatSession(sid){
|
|
|
569
569
|
async function workspaceOp(req) {
|
|
570
570
|
if (typeof req.name !== 'string' || !req.name.trim()) throw Error('workspace name required');
|
|
571
571
|
if (req.op === 'workspace-create')
|
|
572
|
-
return extensionCall(null,'workspace.create',{name:req.name,poolSize:req.pool_size ?? 8
|
|
572
|
+
return extensionCall(null,'workspace.create',{name:req.name,poolSize:req.pool_size ?? 8,
|
|
573
|
+
showInMenu:req.show_in_menu});
|
|
574
|
+
if (req.op === 'workspace-configure')
|
|
575
|
+
return extensionCall(null,'workspace.configure',{name:req.name,showInMenu:req.show_in_menu});
|
|
573
576
|
if (req.op === 'workspace-resize')
|
|
574
577
|
return extensionCall(null,'workspace.resize',{name:req.name,poolSize:req.pool_size});
|
|
575
578
|
if (req.op === 'workspace-delete')
|
|
@@ -735,7 +738,7 @@ const siteKeepalive = createSiteKeepaliveScheduler({
|
|
|
735
738
|
},
|
|
736
739
|
});
|
|
737
740
|
|
|
738
|
-
export async function handle(req){switch(req.op){case'ping':return {ok:true,pid:process.pid,version:PACKAGE_VERSION,queue_paused:process.env.WEBHELM_CHATGPT_QUEUE_PAUSED==='1',session_count:sessions.size,managed_chrome:managedChrome||{profile_dir:PROFILE_DIR, endpoint:process.env.WEBHELM_CDP_URL||'http://127.0.0.1:9222',reused:true},chrome_guard:managedChromeGuard.status()};case'guard-check':{let status=await managedChromeGuard.tick();for(let retry=0;retry<6 && status.status!=='healthy' && !status.skipped;retry++){await delay(800);status=await managedChromeGuard.tick();}if(status.status!=='healthy' && !status.skipped)throw Error(`WebHelm Chrome health degraded: ${status.error||status.status}`);return {ok:true,chrome_guard:status};}case'heartbeat':return heartbeatSession(req.session_id);case'list':return {session_count:sessions.size,sessions:[...sessions.values()].map(s=>({session_id:s.session_id,workspace:s.workspace,target_id:s.targetId,last_used_at:s.last_used_at}))};case'start':return createSession(req);case'exec':return execute(req);case'stop':return stopSession(req.session_id);case'stop-all':return stopAllSessions();case'stop-workspace':{if(typeof req.workspace!=='string'||!req.workspace.trim())throw Error('workspace required');return stopWorkspaceSessions(req.workspace)}case'capacity':return workspaceCapacity(req);case'workspace-create':case'workspace-resize':case'workspace-delete':return workspaceOp(req);case'chatgpt-new-turn-enqueue':return getChatGPTQueue().enqueue(req.config);case'queue-list':return getChatGPTQueue().list();case'queue-cancel':return getChatGPTQueue().cancel(req.queue_id);case'platform-run':return runPlatform(req);default:throw Error(`unknown op: ${req.op}`)}}
|
|
741
|
+
export async function handle(req){switch(req.op){case'ping':return {ok:true,pid:process.pid,version:PACKAGE_VERSION,queue_paused:process.env.WEBHELM_CHATGPT_QUEUE_PAUSED==='1',session_count:sessions.size,managed_chrome:managedChrome||{profile_dir:PROFILE_DIR, endpoint:process.env.WEBHELM_CDP_URL||'http://127.0.0.1:9222',reused:true},chrome_guard:managedChromeGuard.status()};case'guard-check':{let status=await managedChromeGuard.tick();for(let retry=0;retry<6 && status.status!=='healthy' && !status.skipped;retry++){await delay(800);status=await managedChromeGuard.tick();}if(status.status!=='healthy' && !status.skipped)throw Error(`WebHelm Chrome health degraded: ${status.error||status.status}`);return {ok:true,chrome_guard:status};}case'heartbeat':return heartbeatSession(req.session_id);case'list':return {session_count:sessions.size,sessions:[...sessions.values()].map(s=>({session_id:s.session_id,workspace:s.workspace,target_id:s.targetId,last_used_at:s.last_used_at}))};case'start':return createSession(req);case'exec':return execute(req);case'stop':return stopSession(req.session_id);case'stop-all':return stopAllSessions();case'stop-workspace':{if(typeof req.workspace!=='string'||!req.workspace.trim())throw Error('workspace required');return stopWorkspaceSessions(req.workspace)}case'capacity':return workspaceCapacity(req);case'workspace-create':case'workspace-configure':case'workspace-resize':case'workspace-delete':return workspaceOp(req);case'chatgpt-new-turn-enqueue':return getChatGPTQueue().enqueue(req.config);case'queue-list':return getChatGPTQueue().list();case'queue-cancel':return getChatGPTQueue().cancel(req.queue_id);case'platform-run':return runPlatform(req);default:throw Error(`unknown op: ${req.op}`)}}
|
|
739
742
|
export function serve(conn) {
|
|
740
743
|
let buffer = '', dispatched = false;
|
|
741
744
|
conn.on('error',()=>{ /* A disconnected client must not crash the daemon. */ });
|