refactor(agent): 将 tools 模块拆分为独立文件并优化导入路径
将 `tools.ts` 拆分为按功能划分的独立文件,并存放于 `tools/` 目录下,同时更新导入路径;优化 agent 系统提示语,移除冗余的「美图 Agent」前缀。
This commit is contained in:
46
web/server/agent/tools/shared.ts
Normal file
46
web/server/agent/tools/shared.ts
Normal file
@@ -0,0 +1,46 @@
|
||||
import path from 'path';
|
||||
import fs from 'fs';
|
||||
import { fileURLToPath } from 'url';
|
||||
import os from 'os';
|
||||
import { execSync } from 'child_process';
|
||||
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = path.dirname(__filename);
|
||||
|
||||
export const PROJECT_ROOT = path.resolve(__dirname, '..', '..', '..', '..');
|
||||
export const PIPELINE_SCRIPT = path.join(PROJECT_ROOT, '.claude', 'skills', 'video-from-script', 'scripts', 'pipeline.js');
|
||||
export const ACCOUNTS_DIR = path.join(PROJECT_ROOT, 'accounts');
|
||||
export const OUTPUT_DIR = path.join(PROJECT_ROOT, 'output');
|
||||
|
||||
export function loadJSON(filePath: string): unknown {
|
||||
return JSON.parse(fs.readFileSync(filePath, 'utf-8'));
|
||||
}
|
||||
|
||||
export function runInit(params: {
|
||||
account: string;
|
||||
mode: string;
|
||||
items: unknown[];
|
||||
imageModel?: string;
|
||||
videoModel?: string;
|
||||
format?: string;
|
||||
}): string {
|
||||
const tmpFile = path.join(os.tmpdir(), `pipeline-items-${Date.now()}.json`);
|
||||
fs.writeFileSync(tmpFile, JSON.stringify(params.items), 'utf-8');
|
||||
try {
|
||||
const args = [
|
||||
`"${PIPELINE_SCRIPT}"`, 'init',
|
||||
`--account "${params.account}"`,
|
||||
`--mode ${params.mode}`,
|
||||
`--items-file "${tmpFile}"`,
|
||||
params.imageModel ? `--image-model ${params.imageModel}` : '',
|
||||
params.videoModel ? `--video-model ${params.videoModel}` : '',
|
||||
params.format ? `--format ${params.format}` : '',
|
||||
].filter(Boolean).join(' ');
|
||||
const output = execSync(`node ${args}`, { cwd: PROJECT_ROOT, encoding: 'utf-8' });
|
||||
const match = output.match(/Manifest 已创建: (.+)/);
|
||||
if (!match) throw new Error(`Failed to parse manifest path from init output: ${output}`);
|
||||
return match[1].trim();
|
||||
} finally {
|
||||
try { fs.unlinkSync(tmpFile); } catch { /* ignore */ }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user