+19
-1
@@ -35,6 +35,7 @@ export class JarvisDaemon extends EventEmitter {
|
||||
this.locked = false;
|
||||
this.lastReply = '';
|
||||
this.voiceLoop = null;
|
||||
this._activeAsk = null;
|
||||
this._idleTimer = setInterval(() => this.tickIdle(), 30_000);
|
||||
this._idleTimer.unref?.();
|
||||
this.telemetry = new RuntimeTelemetry();
|
||||
@@ -61,13 +62,30 @@ export class JarvisDaemon extends EventEmitter {
|
||||
this.voiceLoop?.interrupt?.();
|
||||
try {
|
||||
this.voice.typedUtterance(); this.setState('THINKING');
|
||||
const startedAt = Date.now(); const reply = await this.scheduler.run(() => this.harness.ask(text), { lane: 'voice' }); this.telemetry.record('llm', startedAt, { success: true });
|
||||
const startedAt = Date.now();
|
||||
const job = this.scheduler.run(() => this.harness.ask(text), { lane: 'voice' });
|
||||
this._activeAsk = job;
|
||||
const reply = await job;
|
||||
this.telemetry.record('llm', startedAt, { success: true });
|
||||
const spoken = spokenReply(reply);
|
||||
this._beginSpeech(); this.lastReply = spoken; this.emit('Reply', spoken); this._speakReply(spoken); return spoken;
|
||||
} catch (error) {
|
||||
this.telemetry.record('llm', Date.now(), { success: false }); this.emit('Error', 'QVAC', error.message); this.voice.cancel(); this.setState('ARMED'); throw error;
|
||||
} finally {
|
||||
this._activeAsk = null;
|
||||
}
|
||||
}
|
||||
async resetContext() {
|
||||
this.harness.cancel();
|
||||
this.scheduler.cancelQueued((job) => job.lane === 'voice');
|
||||
await this._activeAsk?.catch?.(() => {});
|
||||
await this.harness.resetContext();
|
||||
this.lastReply = '';
|
||||
this.voiceLoop?.interrupt?.();
|
||||
this.voice.cancel();
|
||||
this.setState('ARMED');
|
||||
this.emit('ContextReset');
|
||||
}
|
||||
_beginSpeech() {
|
||||
try {
|
||||
if (this.voice.state === 'ARMED' || this.voice.state === 'SLEEPING') this.voice.wake();
|
||||
|
||||
Reference in New Issue
Block a user