first commit
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
import { EventEmitter } from 'node:events';
|
||||
import { acquireQvac, closeQvac, releaseQvac, Agent } from './qvac-master.js';
|
||||
|
||||
export class HarnessBridge extends EventEmitter {
|
||||
constructor({ cwd = process.cwd(), model = 'qwen3.5-4b', tools = [], permissionMode = 'ask' } = {}) {
|
||||
super();
|
||||
this.options = { cwd, model, tools, permissionMode, origin: 'jarvis-qvac', system: 'You are Jarvis on a local Ubuntu GNOME desktop. Keep spoken replies short and never claim cloud access.' };
|
||||
this.session = null;
|
||||
}
|
||||
|
||||
async start() {
|
||||
if (this.session) return this.session;
|
||||
if (process.env.JARVIS_QVAC_MODEL && this.options.model !== process.env.JARVIS_QVAC_MODEL) {
|
||||
throw new Error(`Jarvis uses one QVAC master model (${process.env.JARVIS_QVAC_MODEL}); requested ${this.options.model}`);
|
||||
}
|
||||
await acquireQvac();
|
||||
try {
|
||||
this.session = await Agent.create(this.options);
|
||||
} catch (error) {
|
||||
releaseQvac();
|
||||
await closeQvac();
|
||||
throw error;
|
||||
}
|
||||
for (const event of ['agent_message_chunk', 'tool_call', 'permission', 'ask_user', 'cap-chunk', 'error']) {
|
||||
this.session.on(event, (payload) => this.emit(event, payload));
|
||||
}
|
||||
return this.session;
|
||||
}
|
||||
|
||||
async ask(text) {
|
||||
if (!this.session) await this.start();
|
||||
return this.session.prompt(text);
|
||||
}
|
||||
|
||||
cancel() { this.session?.cancel(); }
|
||||
|
||||
async close() {
|
||||
await this.session?.dispose();
|
||||
releaseQvac();
|
||||
await closeQvac();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user