Guanghu Domestic Migration d1e47f4565
Some checks are pending
自动更新代码和重启 / update-and-restart (push) Waiting to run
CI检查 + 自动部署 / check (push) Waiting to run
CI检查 + 自动部署 / deploy (push) Blocked by required conditions
重启聊天服务 / restart (push) Waiting to run
chore: import sanitized domestic snapshot for REPO-002
Source snapshot: ca48d3ddf926d79aa138306164169baf764bb829
2026-07-17 15:54:41 +08:00

97 lines
2.8 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* Agent Engine · 模块入口(更新版)
* GH-GMP-005 · M3 · Agent搬迁工程
*
* 工单调度 · 回执生成 · 半体人格加载
* 依赖notion-sync · llm-router
*/
'use strict';
const fs = require('fs');
const path = require('path');
const MODULE_NAME = 'agent-engine';
const MODULE_VERSION = '1.0.0';
// TODO M3: 实现以下模块
// const Dispatcher = require('./dispatcher');
// const ReceiptGenerator = require('./receipt-gen');
// const PersonaLoader = require('./persona-loader');
// const TaskRunner = require('./task-runner');
let notionSync = null;
let llmRouter = null;
let agentRegistry = null;
let logger = console;
module.exports = {
name: MODULE_NAME,
version: MODULE_VERSION,
type: 'service',
depends: ['notion-sync', 'llm-router'],
async init(context) {
logger = (context && context.logger) || console;
logger.info(`[${MODULE_NAME}] 初始化中 v${MODULE_VERSION}...`);
// 获取依赖模块引用
notionSync = context && context.modules && context.modules['notion-sync'];
llmRouter = context && context.modules && context.modules['llm-router'];
// 加载Agent注册表
try {
const configPath = path.join(__dirname, '..', 'config', 'agents.json');
agentRegistry = JSON.parse(fs.readFileSync(configPath, 'utf-8'));
const agentCount = Object.keys(agentRegistry.agents || {}).length;
logger.info(`[${MODULE_NAME}] Agent注册表加载完成 · ${agentCount} 个半体`);
} catch (err) {
logger.warn(`[${MODULE_NAME}] Agent注册表加载失败: ${err.message}`);
agentRegistry = { agents: {} };
}
logger.info(`[${MODULE_NAME}] 初始化完成 v${MODULE_VERSION}`);
return {
status: 'ok',
agentCount: Object.keys(agentRegistry.agents || {}).length,
hasNotionSync: !!notionSync,
hasLlmRouter: !!llmRouter,
};
},
async start(context) {
logger.info(`[${MODULE_NAME}] 启动Agent引擎...`);
// 连接notion-sync的轮询器注入工单处理回调
if (notionSync && notionSync.getPoller) {
// TODO M3: 注入dispatcher回调
logger.info(`[${MODULE_NAME}] 已连接notion-sync轮询器`);
} else {
logger.warn(`[${MODULE_NAME}] notion-sync未就绪工单处理暂不可用`);
}
return { status: 'running' };
},
async stop() {
logger.info(`[${MODULE_NAME}] 停止Agent引擎`);
return { status: 'stopped' };
},
async healthCheck() {
return {
status: 'ok',
module: MODULE_NAME,
version: MODULE_VERSION,
agentCount: Object.keys((agentRegistry && agentRegistry.agents) || {}).length,
dependencies: {
'notion-sync': !!notionSync,
'llm-router': !!llmRouter,
},
};
},
// ─── 对外接口 ───
getAgentRegistry: () => agentRegistry,
};