|
|
|
@@ -44,7 +44,11 @@ export function collaborationInput(input, config) {
|
|
|
|
|
maxDurationMs: bounded(raw.maxDurationMs, config.maxRunDurationMs ?? 600000, 1000, Math.min(3600000, config.maxRunDurationMs ?? 600000), '总时限'),
|
|
|
|
|
};
|
|
|
|
|
const children = input.children.map((item, index) => {
|
|
|
|
|
if (!item || typeof item !== 'object' || Array.isArray(item) || Object.keys(item).some(key => !['label', 'goal', 'paths', 'budget'].includes(key))) throw workerConflict('子任务字段无效。');
|
|
|
|
|
if (!item || typeof item !== 'object' || Array.isArray(item) || Object.keys(item).some(key => !['label', 'goal', 'paths', 'budget', 'role', 'requirements', 'modelSelection'].includes(key))) throw workerConflict('子任务字段无效。');
|
|
|
|
|
const selection = item.modelSelection;
|
|
|
|
|
if (selection !== undefined && (!selection || Array.isArray(selection) || Object.keys(selection).some(key => !['type', 'id'].includes(key))
|
|
|
|
|
|| !['connection', 'pool'].includes(selection.type) || typeof selection.id !== 'string' || !selection.id)) throw workerConflict('请选择模型中心已保存的连接或模型池。');
|
|
|
|
|
if (item.requirements !== undefined && !Array.isArray(item.requirements)) throw workerConflict('子任务要求需要逐项列出。');
|
|
|
|
|
if (!Array.isArray(item.paths) || !item.paths.length || !unrestricted(config) && item.paths.length > 16) throw workerConflict('每个子任务需要1到16个修改范围。');
|
|
|
|
|
const paths = item.paths.map(workerPath).sort();
|
|
|
|
|
if (new Set(paths.map(workerPathKey)).size !== paths.length) throw workerConflict('子任务范围不能重复。');
|
|
|
|
@@ -52,6 +56,8 @@ export function collaborationInput(input, config) {
|
|
|
|
|
if (!part || Array.isArray(part) || Object.keys(part).some(key => !['maxTokens', 'maxSteps', 'maxToolCalls'].includes(key))) throw workerConflict('子预算字段无效。');
|
|
|
|
|
const allocate = key => engine ? budget[key] : index === 0 ? Math.floor(budget[key] / 2) : budget[key] - Math.floor(budget[key] / 2);
|
|
|
|
|
return { label: text(item.label, ceiling(config, 64), '子任务名称'), goal: text(item.goal, ceiling(config, 8000), '子目标'), paths,
|
|
|
|
|
role: text(item.role ?? '工程实现', ceiling(config, 128), '子任务职责'), requirements: (item.requirements ?? []).map(value => text(value, ceiling(config, 8000), '子任务要求')),
|
|
|
|
|
...(selection ? { modelSelection: structuredClone(selection) } : {}),
|
|
|
|
|
budget: Object.fromEntries(['maxTokens', 'maxSteps', 'maxToolCalls'].map(key => [key, unrestricted(config) ? 0 : bounded(part[key], allocate(key), key === 'maxTokens' ? 500 : 1, budget[key], key)])) };
|
|
|
|
|
});
|
|
|
|
|
for (const key of ['maxTokens', 'maxSteps', 'maxToolCalls']) if (children.reduce((sum, child) => sum + child.budget[key], 0) > budget[key]) throw workerConflict('子任务预算之和不能超过父预算:' + key);
|
|
|
|
@@ -69,7 +75,8 @@ export function workerSeal(worker) {
|
|
|
|
|
projectId: worker.projectId, sessionId: worker.sessionId, taskId: worker.taskId, workspaceId: worker.workspaceId,
|
|
|
|
|
label: worker.label, goal: worker.goal, paths: worker.paths, budget: worker.budget, model: worker.model, baseCommit: worker.baseCommit,
|
|
|
|
|
baselineArtifactId: worker.baselineArtifactId, baselineSha256: worker.baselineSha256, baselineRunId: worker.baselineRunId,
|
|
|
|
|
...(worker.engine ? { engine: worker.engine } : {}), ...(worker.evaluation ? { evaluation: worker.evaluation } : {}) };
|
|
|
|
|
...(worker.engine ? { engine: worker.engine } : {}), ...(worker.evaluation ? { evaluation: worker.evaluation } : {}),
|
|
|
|
|
...(worker.assignment ? { assignment: worker.assignment } : {}) };
|
|
|
|
|
}
|
|
|
|
|
export function workerForProject(store, projectId) {
|
|
|
|
|
return [...(store.core.worker?.values() ?? [])].find(value => value.projectId === projectId) ?? null;
|
|
|
|
@@ -84,11 +91,13 @@ export function workerForSession(store, session) {
|
|
|
|
|
|| definition.taskId !== worker.taskId || definition.projectId !== worker.projectId || definition.sessionId !== worker.sessionId
|
|
|
|
|
|| definition.workspaceId !== worker.workspaceId || JSON.stringify(definition.paths) !== JSON.stringify(worker.paths)
|
|
|
|
|
|| JSON.stringify(definition.budget) !== JSON.stringify(worker.budget) || definition.goal !== worker.goal
|
|
|
|
|
|| JSON.stringify(group.model) !== JSON.stringify(worker.model)
|
|
|
|
|
|| JSON.stringify(definition.assignment?.model ?? group.model) !== JSON.stringify(worker.model)
|
|
|
|
|
|| JSON.stringify(definition.assignment) !== JSON.stringify(worker.assignment)
|
|
|
|
|
|| JSON.stringify(definition.engine) !== JSON.stringify(worker.engine)
|
|
|
|
|
|| JSON.stringify(definition.evaluation) !== JSON.stringify(worker.evaluation)) throw workerConflict('子任务与父任务的封存分工不一致。');
|
|
|
|
|
const task = store.core.task.get(worker.taskId);
|
|
|
|
|
if (!task || task.goal !== worker.goal || task.workerId !== worker.id || task.budget.maxTokens !== worker.budget.maxTokens) throw workerConflict('子任务目标、身份或累计预算已变化。');
|
|
|
|
|
if (worker.assignment && JSON.stringify(task.acceptance) !== JSON.stringify(worker.assignment.requirements)) throw workerConflict('子任务原要求与封存分工不一致。');
|
|
|
|
|
const original = store.owned('artifact', worker.contractArtifactId, session.id);
|
|
|
|
|
if (original.kind !== 'worker-contract' || original.taskId !== worker.taskId || original.sha256 !== worker.contractSha256
|
|
|
|
|
|| store.artifactStore.read(original) !== JSON.stringify(workerSeal(worker))) throw workerConflict('受限子任务契约与原工件不一致。');
|
|
|
|
|