Updates
This commit is contained in:
+21
-2
@@ -1,11 +1,15 @@
|
||||
import { EventEmitter } from 'node:events';
|
||||
import { HarnessBridge } from './harness-bridge.js';
|
||||
import { ComputerUseSession } from '../computer-use/session.js';
|
||||
import { VoiceStateMachine } from './voice-state.js';
|
||||
import { QvacScheduler } from './qvac-scheduler.js';
|
||||
|
||||
export class JarvisDaemon extends EventEmitter {
|
||||
constructor() {
|
||||
super();
|
||||
this.state = 'ARMED';
|
||||
this.voice = new VoiceStateMachine();
|
||||
this.scheduler = new QvacScheduler({ concurrency: 1 });
|
||||
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 || ''));
|
||||
@@ -13,8 +17,19 @@ export class JarvisDaemon extends EventEmitter {
|
||||
}
|
||||
|
||||
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'); }
|
||||
arm() { this.voice.wake(); this.setState('LISTENING'); }
|
||||
sleep() { this.voice.sleep(); this.setState('SLEEPING'); }
|
||||
say(text) { this.emit('Reply', String(text)); }
|
||||
async ask(text) {
|
||||
this.voice.utterance(); this.setState('THINKING');
|
||||
try {
|
||||
const reply = await this.scheduler.run(() => this.harness.ask(text), { lane: 'voice' });
|
||||
this.voice.speak(); this.setState('SPEAKING'); this.emit('Reply', reply); return reply;
|
||||
} catch (error) {
|
||||
this.emit('Error', 'QVAC', error.message); this.voice.cancel(); this.setState('ARMED'); throw error;
|
||||
}
|
||||
}
|
||||
cancel() { this.harness.cancel(); this.scheduler.cancelQueued((job) => job.lane === 'voice'); this.computer.revoke(); this.voice.cancel(); 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(); }
|
||||
@@ -22,6 +37,10 @@ export class JarvisDaemon extends EventEmitter {
|
||||
|
||||
if (import.meta.url === `file://${process.argv[1]}`) {
|
||||
const daemon = new JarvisDaemon();
|
||||
import('./dbus-service.js').then(({ serveOnSessionBus }) => serveOnSessionBus(daemon)).catch((error) => {
|
||||
daemon.emit('Error', 'DBUS_UNAVAILABLE', error.message);
|
||||
console.error(`jarvisd: D-Bus unavailable: ${error.message}`);
|
||||
});
|
||||
process.on('SIGINT', () => daemon.close().finally(() => process.exit(0)));
|
||||
console.log('jarvisd scaffold ready; use the D-Bus adapter when installed');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user