feat(companion): add task PWA and original execution controls

This commit is contained in:
Agent Workbench Dev
2026-10-31 17:53:15 +08:00
parent dfe2e40387
commit bc67e6e0a3
57 changed files with 1212 additions and 15 deletions
+10 -2
View File
@@ -31,7 +31,10 @@ const cookieName = '__Host-Workbench-Device';
const privateV4 = value => /^10\./.test(value) || /^192\.168\./.test(value) || /^172\.(1[6-9]|2\d|3[01])\./.test(value);
export function companionAddresses() {
return Object.entries(os.networkInterfaces()).flatMap(([name, entries]) => (entries ?? []).filter(entry => entry.family === 'IPv4' && !entry.internal && privateV4(entry.address))
.map(entry => ({ name, address: entry.address })));
.map(entry => ({ name, address: entry.address }))).sort((left, right) => {
const virtual = value => /vethernet|hyper-v|wsl|virtual|vmware|vbox|docker|vpn|\btun\b|\btap\b|虚拟/i.test(value.name) ? 1 : 0;
return virtual(left) - virtual(right) || left.name.localeCompare(right.name);
});
}
function reply(response, data, status = 200) {
response.writeHead(status, { 'Content-Type': 'application/json; charset=utf-8' }); response.end(JSON.stringify(data));
@@ -197,7 +200,12 @@ export class CompanionGateway {
const device = this.registry.authenticate(cookie(request)); this.limit('device:' + device.id, 240);
if (!this.sockets.has(request.socket)) request.socket.once('close', () => this.sockets.delete(request.socket));
this.sockets.set(request.socket, device.id);
if (method === 'GET' && route === '/mobile-api/me') return reply(response, { device: { id: device.id, name: device.name, projectIds: device.projectIds, permissions: device.permissions, expiresAt: device.expiresAt, revision: device.revision }, gatewayId: this.registry.read().gatewayId });
if (method === 'GET' && route === '/mobile-api/me') {
const state = this.registry.read();
return reply(response, { device: { id: device.id, name: device.name, projectIds: device.projectIds, permissions: device.permissions, expiresAt: device.expiresAt, revision: device.revision },
gatewayId: state.gatewayId, operations: Object.values(state.operations).filter(value => value.deviceId === device.id && device.projectIds.includes(value.projectId)).slice(-20)
.map(value => ({ requestId: value.requestId, action: value.action, status: value.status === 'pending' ? 'unknown' : value.status, taskId: value.taskId, runId: value.runId, createdAt: value.createdAt })) });
}
if (method === 'POST' && route === '/mobile-api/rotate') {
fields(await input(request), []); const token = this.registry.rotate(device); setCookie(response, token, device.expiresAt); return reply(response, { rotated: true });
}