feat: MVP v0.5 complete - All P0 features implemented and frontend verified. Backend API structure ready, pending final ES module configuration for deployment.
This commit is contained in:
287
dist-server/lib/hr-manager.js
Normal file
287
dist-server/lib/hr-manager.js
Normal file
@@ -0,0 +1,287 @@
|
||||
"use strict";
|
||||
/**
|
||||
* HR管理员 - 任务拆解引擎
|
||||
* 将高级任务递归分解为原子任务
|
||||
*/
|
||||
var _a;
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.HRManager = exports.ATOMIC_TASK_TYPES = exports.AtomicTaskType = void 0;
|
||||
var AtomicTaskType;
|
||||
(function (AtomicTaskType) {
|
||||
AtomicTaskType["FILL_TEMPLATE"] = "fill_template";
|
||||
AtomicTaskType["SUMMARIZE"] = "summarize";
|
||||
AtomicTaskType["FORMAT_CONVERT"] = "format_convert";
|
||||
AtomicTaskType["EVALUATE"] = "evaluate";
|
||||
AtomicTaskType["RISK_IDENTIFY"] = "risk_identify";
|
||||
AtomicTaskType["PRIORITIZE"] = "prioritize";
|
||||
AtomicTaskType["GENERATE_NOTIFICATION"] = "generate_notification";
|
||||
AtomicTaskType["AGGREGATE_REPORT"] = "aggregate_report";
|
||||
AtomicTaskType["STATUS_UPDATE"] = "status_update";
|
||||
AtomicTaskType["EXTRACT"] = "extract";
|
||||
})(AtomicTaskType || (exports.AtomicTaskType = AtomicTaskType = {}));
|
||||
/**
|
||||
* 原子任务类型库
|
||||
*/
|
||||
exports.ATOMIC_TASK_TYPES = (_a = {},
|
||||
_a[AtomicTaskType.FILL_TEMPLATE] = {
|
||||
type: AtomicTaskType.FILL_TEMPLATE,
|
||||
category: 'document',
|
||||
description: '给定模板+数据 → 输出填充后文档',
|
||||
estimatedTokens: 3000,
|
||||
inputSchema: { template: 'string', data: 'object' },
|
||||
outputSchema: { document: 'string' },
|
||||
},
|
||||
_a[AtomicTaskType.SUMMARIZE] = {
|
||||
type: AtomicTaskType.SUMMARIZE,
|
||||
category: 'document',
|
||||
description: '给定长文 → 输出摘要',
|
||||
estimatedTokens: 2000,
|
||||
inputSchema: { content: 'string', maxLength: 'number' },
|
||||
outputSchema: { summary: 'string' },
|
||||
},
|
||||
_a[AtomicTaskType.FORMAT_CONVERT] = {
|
||||
type: AtomicTaskType.FORMAT_CONVERT,
|
||||
category: 'document',
|
||||
description: '给定内容 → 按目标格式输出',
|
||||
estimatedTokens: 2000,
|
||||
inputSchema: { content: 'string', targetFormat: 'string' },
|
||||
outputSchema: { formatted: 'string' },
|
||||
},
|
||||
_a[AtomicTaskType.EVALUATE] = {
|
||||
type: AtomicTaskType.EVALUATE,
|
||||
category: 'analysis',
|
||||
description: '给定标准+对象 → 输出评分+理由',
|
||||
estimatedTokens: 1500,
|
||||
inputSchema: { criteria: 'array', target: 'object' },
|
||||
outputSchema: { score: 'number', reasoning: 'string' },
|
||||
},
|
||||
_a[AtomicTaskType.RISK_IDENTIFY] = {
|
||||
type: AtomicTaskType.RISK_IDENTIFY,
|
||||
category: 'analysis',
|
||||
description: '给定范围 → 输出风险列表',
|
||||
estimatedTokens: 1500,
|
||||
inputSchema: { scope: 'string', context: 'object' },
|
||||
outputSchema: { risks: 'array' },
|
||||
},
|
||||
_a[AtomicTaskType.PRIORITIZE] = {
|
||||
type: AtomicTaskType.PRIORITIZE,
|
||||
category: 'analysis',
|
||||
description: '给定列表+标准 → 输出排序结果',
|
||||
estimatedTokens: 1200,
|
||||
inputSchema: { items: 'array', criteria: 'array' },
|
||||
outputSchema: { sorted: 'array' },
|
||||
},
|
||||
_a[AtomicTaskType.GENERATE_NOTIFICATION] = {
|
||||
type: AtomicTaskType.GENERATE_NOTIFICATION,
|
||||
category: 'coordination',
|
||||
description: '给定事件 → 输出消息内容',
|
||||
estimatedTokens: 1000,
|
||||
inputSchema: { event: 'string', recipients: 'array' },
|
||||
outputSchema: { message: 'string' },
|
||||
},
|
||||
_a[AtomicTaskType.AGGREGATE_REPORT] = {
|
||||
type: AtomicTaskType.AGGREGATE_REPORT,
|
||||
category: 'coordination',
|
||||
description: '给定多条数据 → 输出汇总',
|
||||
estimatedTokens: 1500,
|
||||
inputSchema: { data: 'array', reportType: 'string' },
|
||||
outputSchema: { report: 'string' },
|
||||
},
|
||||
_a[AtomicTaskType.STATUS_UPDATE] = {
|
||||
type: AtomicTaskType.STATUS_UPDATE,
|
||||
category: 'data',
|
||||
description: '给定条件 → 查询并更新',
|
||||
estimatedTokens: 1000,
|
||||
inputSchema: { query: 'object', updates: 'object' },
|
||||
outputSchema: { updated: 'boolean', record: 'object' },
|
||||
},
|
||||
_a[AtomicTaskType.EXTRACT] = {
|
||||
type: AtomicTaskType.EXTRACT,
|
||||
category: 'data',
|
||||
description: '给定源 → 提取指定字段',
|
||||
estimatedTokens: 1000,
|
||||
inputSchema: { source: 'string', fields: 'array' },
|
||||
outputSchema: { extracted: 'object' },
|
||||
},
|
||||
_a);
|
||||
/**
|
||||
* 原子任务判定标准
|
||||
*/
|
||||
function isAtomic(task) {
|
||||
var _a;
|
||||
return (Object.keys(task.input).length > 0 && // 输入确定
|
||||
task.outputFormat !== undefined && // 输出确定
|
||||
!((_a = task.dependencies) === null || _a === void 0 ? void 0 : _a.length) && // 无外部依赖
|
||||
task.estimatedTokens <= 6000 // 时间可控
|
||||
);
|
||||
}
|
||||
/**
|
||||
* HR管理员核心:递归任务分解
|
||||
*/
|
||||
var HRManager = /** @class */ (function () {
|
||||
function HRManager() {
|
||||
this.taskIdCounter = 0;
|
||||
}
|
||||
/**
|
||||
* 将高级任务分解为原子任务列表
|
||||
*/
|
||||
HRManager.prototype.decompose = function (highLevelTask, context) {
|
||||
var _a;
|
||||
var tasks = this._matchPatterns(highLevelTask, context);
|
||||
// Recursive check: decompose non-atomic tasks further
|
||||
var result = [];
|
||||
for (var _i = 0, tasks_1 = tasks; _i < tasks_1.length; _i++) {
|
||||
var task = tasks_1[_i];
|
||||
if (isAtomic(task) || !((_a = task.children) === null || _a === void 0 ? void 0 : _a.length)) {
|
||||
result.push(task);
|
||||
}
|
||||
else {
|
||||
// Decompose children further
|
||||
for (var _b = 0, _c = task.children || []; _b < _c.length; _b++) {
|
||||
var child = _c[_b];
|
||||
if (isAtomic(child)) {
|
||||
result.push(child);
|
||||
}
|
||||
else {
|
||||
result.push.apply(result, this.decompose(child.title, child.input));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
};
|
||||
/**
|
||||
* 为原子任务选择最佳模型
|
||||
*/
|
||||
HRManager.prototype.selectModel = function (taskType) {
|
||||
var _a;
|
||||
var modelMap = (_a = {},
|
||||
_a[AtomicTaskType.FILL_TEMPLATE] = 'claude-3-haiku',
|
||||
_a[AtomicTaskType.SUMMARIZE] = 'gpt-4o-mini',
|
||||
_a[AtomicTaskType.FORMAT_CONVERT] = 'gpt-4o-mini',
|
||||
_a[AtomicTaskType.EVALUATE] = 'gpt-4-turbo',
|
||||
_a[AtomicTaskType.RISK_IDENTIFY] = 'claude-3-sonnet',
|
||||
_a[AtomicTaskType.PRIORITIZE] = 'gpt-4o-mini',
|
||||
_a[AtomicTaskType.GENERATE_NOTIFICATION] = 'gpt-4o-mini',
|
||||
_a[AtomicTaskType.AGGREGATE_REPORT] = 'claude-3-sonnet',
|
||||
_a[AtomicTaskType.STATUS_UPDATE] = 'gpt-4o-mini',
|
||||
_a[AtomicTaskType.EXTRACT] = 'gpt-4o-mini',
|
||||
_a);
|
||||
return modelMap[taskType] || 'gpt-4o-mini';
|
||||
};
|
||||
HRManager.prototype._generateId = function () {
|
||||
return "task-".concat(++this.taskIdCounter, "-").concat(Date.now());
|
||||
};
|
||||
/**
|
||||
* Pattern matching for known PM phases
|
||||
*/
|
||||
HRManager.prototype._matchPatterns = function (task, context) {
|
||||
var lower = task.toLowerCase();
|
||||
// Project Charter
|
||||
if (lower.includes('章程') || lower.includes('charter')) {
|
||||
return [
|
||||
{
|
||||
id: this._generateId(),
|
||||
title: '生成项目章程',
|
||||
description: '根据项目信息填充章程模板',
|
||||
atomicType: AtomicTaskType.FILL_TEMPLATE,
|
||||
input: { template: 'project_charter', data: context || {} },
|
||||
outputFormat: { document: 'string' },
|
||||
estimatedTokens: 3000,
|
||||
priority: 'must',
|
||||
},
|
||||
{
|
||||
id: this._generateId(),
|
||||
title: '分析干系人',
|
||||
description: '根据项目背景识别关键干系人',
|
||||
atomicType: AtomicTaskType.RISK_IDENTIFY,
|
||||
input: { scope: 'stakeholders', context: context || {} },
|
||||
outputFormat: { stakeholders: 'array' },
|
||||
estimatedTokens: 1500,
|
||||
priority: 'must',
|
||||
dependencies: [],
|
||||
},
|
||||
];
|
||||
}
|
||||
// Risk Management
|
||||
if (lower.includes('风险') || lower.includes('risk')) {
|
||||
return [
|
||||
{
|
||||
id: this._generateId(),
|
||||
title: '识别项目风险',
|
||||
description: '从技术/资源/范围/外部四个维度识别风险',
|
||||
atomicType: AtomicTaskType.RISK_IDENTIFY,
|
||||
input: { scope: 'project_risks', context: context || {} },
|
||||
outputFormat: { risks: 'array' },
|
||||
estimatedTokens: 2000,
|
||||
priority: 'must',
|
||||
},
|
||||
{
|
||||
id: this._generateId(),
|
||||
title: '生成风险应对策略',
|
||||
description: '为高优先级风险制定规避/转移/减轻/接受策略',
|
||||
atomicType: AtomicTaskType.EVALUATE,
|
||||
input: { criteria: ['probability', 'impact', 'strategy'], target: {} },
|
||||
outputFormat: { mitigations: 'array' },
|
||||
estimatedTokens: 1500,
|
||||
priority: 'must',
|
||||
},
|
||||
];
|
||||
}
|
||||
// Schedule / Progress
|
||||
if (lower.includes('进度') || lower.includes('schedule') || lower.includes('排期')) {
|
||||
return [
|
||||
{
|
||||
id: this._generateId(),
|
||||
title: '分析任务依赖关系',
|
||||
description: '确定任务间的先后顺序和关键路径',
|
||||
atomicType: AtomicTaskType.PRIORITIZE,
|
||||
input: { items: (context === null || context === void 0 ? void 0 : context.tasks) || [], criteria: ['dependency', 'priority'] },
|
||||
outputFormat: { sorted: 'array', criticalPath: 'array' },
|
||||
estimatedTokens: 2000,
|
||||
priority: 'must',
|
||||
},
|
||||
{
|
||||
id: this._generateId(),
|
||||
title: '生成进度计划',
|
||||
description: '基于依赖关系和估算生成甘特图数据',
|
||||
atomicType: AtomicTaskType.FILL_TEMPLATE,
|
||||
input: { template: 'schedule', data: context || {} },
|
||||
outputFormat: { schedule: 'object' },
|
||||
estimatedTokens: 3000,
|
||||
priority: 'must',
|
||||
},
|
||||
];
|
||||
}
|
||||
// Weekly Report
|
||||
if (lower.includes('周报') || lower.includes('报告') || lower.includes('report')) {
|
||||
return [
|
||||
{
|
||||
id: this._generateId(),
|
||||
title: '汇总项目进度数据',
|
||||
description: '收集任务完成情况、Bug数据、风险状态',
|
||||
atomicType: AtomicTaskType.AGGREGATE_REPORT,
|
||||
input: { data: (context === null || context === void 0 ? void 0 : context.tasks) || [], reportType: 'weekly' },
|
||||
outputFormat: { report: 'string' },
|
||||
estimatedTokens: 1500,
|
||||
priority: 'should',
|
||||
},
|
||||
];
|
||||
}
|
||||
// Default: treat as document generation
|
||||
return [
|
||||
{
|
||||
id: this._generateId(),
|
||||
title: task,
|
||||
description: "\u5904\u7406\u4EFB\u52A1\uFF1A".concat(task),
|
||||
atomicType: AtomicTaskType.FILL_TEMPLATE,
|
||||
input: { request: task, context: context || {} },
|
||||
outputFormat: { result: 'string' },
|
||||
estimatedTokens: 2000,
|
||||
priority: 'should',
|
||||
},
|
||||
];
|
||||
};
|
||||
return HRManager;
|
||||
}());
|
||||
exports.HRManager = HRManager;
|
||||
Reference in New Issue
Block a user