28 lines
1.5 KiB
JavaScript
28 lines
1.5 KiB
JavaScript
import { EventEmitter } from 'node:events';
|
|
import { HarnessBridge } from './harness-bridge.js';
|
|
import { ComputerUseSession } from '../computer-use/session.js';
|
|
|
|
export class JarvisDaemon extends EventEmitter {
|
|
constructor() {
|
|
super();
|
|
this.state = 'ARMED';
|
|
this.computer = new ComputerUseSession();
|
|
this.harness = new HarnessBridge({ cwd: process.cwd() });
|
|
this.harness.on('agent_message_chunk', (ev) => this.emit('Token', ev?.text || ev?.delta || ''));
|
|
this.harness.on('permission', (ev) => this.emit('ConfirmationRequired', ev));
|
|
}
|
|
|
|
setState(state) { this.state = state; this.emit('StateChanged', state); }
|
|
async ask(text) { this.setState('THINKING'); try { const reply = await this.harness.ask(text); this.emit('Reply', reply); return reply; } finally { this.setState('LISTENING'); } }
|
|
cancel() { this.harness.cancel(); this.computer.revoke(); this.setState('ARMED'); }
|
|
computerGrant(persist = false) { const result = this.computer.grant({ persist }); this.emit('ComputerStep', JSON.stringify({ action: 'grant', ...result })); return result; }
|
|
computerRevoke() { this.computer.revoke(); this.emit('ComputerStep', JSON.stringify({ action: 'revoke' })); }
|
|
async close() { this.computerRevoke(); await this.harness.close(); }
|
|
}
|
|
|
|
if (import.meta.url === `file://${process.argv[1]}`) {
|
|
const daemon = new JarvisDaemon();
|
|
process.on('SIGINT', () => daemon.close().finally(() => process.exit(0)));
|
|
console.log('jarvisd scaffold ready; use the D-Bus adapter when installed');
|
|
}
|