first commit
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
import { Agent } from './qvac-master.js';
|
||||
|
||||
try {
|
||||
const resources = await Agent.engine.resources();
|
||||
const hasGpu = Array.isArray(resources.gpus) && resources.gpus.length > 0;
|
||||
console.log(JSON.stringify({
|
||||
policy: 'gpu-required',
|
||||
hasGpu,
|
||||
backendHints: resources.drivers || {},
|
||||
gpus: resources.gpus || [],
|
||||
vramBytes: resources.vramBytes || 0,
|
||||
}, null, 2));
|
||||
if (!hasGpu) {
|
||||
console.error('gpu-doctor: QVAC did not observe a usable GPU; Jarvis will refuse CPU inference');
|
||||
process.exitCode = 1;
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(`gpu-doctor: ${error.message}`);
|
||||
process.exitCode = 1;
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
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');
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"name": "@jarvis-qvac/daemon",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"main": "index.js"
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
import { createRequire } from 'node:module';
|
||||
import path from 'node:path';
|
||||
|
||||
const harnessPath = process.env.JARVIS_HARNESS_PATH || '/home/raven/dev/agent-harness';
|
||||
const require = createRequire(import.meta.url);
|
||||
process.env.QVAC_CONFIG_PATH ||= path.resolve(new URL('../qvac.config.json', import.meta.url).pathname);
|
||||
const Agent = require(path.join(harnessPath, 'index.js'));
|
||||
|
||||
let loadPromise = null;
|
||||
let ownerCount = 0;
|
||||
|
||||
export const QVAC_MASTER = Object.freeze({
|
||||
configPath: process.env.QVAC_CONFIG_PATH,
|
||||
model: process.env.JARVIS_QVAC_MODEL || 'qwen3.5-4b',
|
||||
device: 'gpu',
|
||||
gpuLayers: 99,
|
||||
});
|
||||
|
||||
export async function acquireQvac() {
|
||||
ownerCount += 1;
|
||||
if (!loadPromise) {
|
||||
loadPromise = Agent.engine.load({
|
||||
model: QVAC_MASTER.model,
|
||||
tools: true,
|
||||
device: 'gpu',
|
||||
gpu_layers: QVAC_MASTER.gpuLayers,
|
||||
mmprojUseGpu: true,
|
||||
}).then((loaded) => {
|
||||
if (loaded.device !== 'gpu') {
|
||||
throw new Error(`Jarvis requires GPU QVAC inference; loaded device was ${loaded.device}`);
|
||||
}
|
||||
return loaded;
|
||||
}).catch((error) => {
|
||||
loadPromise = null;
|
||||
ownerCount = Math.max(0, ownerCount - 1);
|
||||
throw error;
|
||||
});
|
||||
}
|
||||
return loadPromise;
|
||||
}
|
||||
|
||||
export function releaseQvac() { ownerCount = Math.max(0, ownerCount - 1); }
|
||||
|
||||
export async function closeQvac() {
|
||||
if (ownerCount > 0) return;
|
||||
loadPromise = null;
|
||||
await Agent.engine.close();
|
||||
}
|
||||
|
||||
export function qvacStatus() {
|
||||
return { ...QVAC_MASTER, owners: ownerCount, loaded: Agent.engine.getLoaded() };
|
||||
}
|
||||
|
||||
export { Agent };
|
||||
Reference in New Issue
Block a user