29 lines
1.8 KiB
JavaScript
29 lines
1.8 KiB
JavaScript
/**
|
|
* hal/deps.mjs — HAL 의존성 묶음(deps) 만들기. index.mjs(운영)와 테스트가 같은 함수를 쓴다.
|
|
* deps = { store, vault, config, jobs, ai, log, version, instanceId, serviceauth, notifyLib, fetch, emergencyRunner, jobsRunning, stopping }
|
|
*/
|
|
import { openDb } from '../lib/db.mjs';
|
|
import { openVault } from '../lib/vault.mjs';
|
|
import { createJobEngine } from '../lib/jobs.mjs';
|
|
import * as serviceauth from '../lib/serviceauth.mjs';
|
|
import * as notifyLib from '../lib/notify.mjs';
|
|
import { newId } from '../lib/crypto.mjs';
|
|
import { MIGRATIONS } from './schema.mjs';
|
|
import { registerKinds } from './jobs.mjs';
|
|
import { createEngine } from './ai/engine.mjs'; // 0.3.0 AI 채팅룸 엔진
|
|
import { createShellManager } from './ai/shell.mjs'; // 0.3.2 CLI 로그인용 텍스트 셸
|
|
import { readFileSync } from 'node:fs';
|
|
import { join } from 'node:path';
|
|
|
|
export const VERSION = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8')).version;
|
|
export function createHalDeps({ config, dbFile = null, log = () => {}, fetchImpl = null, version = VERSION, concurrency = 64 } = {}) {
|
|
const store = openDb(dbFile || join(config.dataDir, 'hal.sqlite'), MIGRATIONS);
|
|
const vault = openVault(config.dataDir);
|
|
const d = { store, vault, config, log, version, instanceId: newId('hal_'), serviceauth, notifyLib, fetch: fetchImpl, emergencyRunner: null, jobsRunning: false, stopping: false };
|
|
d.jobs = createJobEngine(store, { log, workerId: `hal@${process.pid}`, concurrency, pollMs: 500 });
|
|
registerKinds(d.jobs, d);
|
|
d.ai = createEngine(d); // 0.3.0: 연결·방·제안은 DB, 진행 중 턴은 프로세스 안
|
|
d.shell = createShellManager(d); // 0.3.2: 허용 명령(login 등)만 PTY 로, 세션은 프로세스 안
|
|
return d;
|
|
}
|