refactor(agent): 将 tools 模块拆分为独立文件并优化导入路径
将 `tools.ts` 拆分为按功能划分的独立文件,并存放于 `tools/` 目录下,同时更新导入路径;优化 agent 系统提示语,移除冗余的「美图 Agent」前缀。
This commit is contained in:
46
web/server/agent/tools/generate-images.ts
Normal file
46
web/server/agent/tools/generate-images.ts
Normal file
@@ -0,0 +1,46 @@
|
||||
import { execSync } from 'child_process';
|
||||
import { runInit, loadJSON, PIPELINE_SCRIPT, PROJECT_ROOT } from './shared';
|
||||
import type { ToolDefinition } from './types';
|
||||
|
||||
export const generateImages: ToolDefinition = {
|
||||
name: 'generate_images',
|
||||
description: '文生图:根据文本提示词生成图片。内部创建临时 manifest 并调用 pipeline images 阶段,支持批量生成。生成结果写入 output 目录,返回图片文件路径列表。',
|
||||
input_schema: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
accountId: { type: 'string', description: '账号ID,用于继承模型、参考图等配置' },
|
||||
prompt: { type: 'string', description: '图片提示词(imagePrompt),描述要生成的图片内容' },
|
||||
count: { type: 'number', description: '生成图片数量,默认 1' },
|
||||
imageModel: { type: 'string', description: '生图模型(可选,默认继承账号配置): gemini, mj, gpt-image, kling' },
|
||||
},
|
||||
required: ['accountId', 'prompt'],
|
||||
},
|
||||
execute: async (params) => {
|
||||
const { accountId, prompt, count, imageModel } = params as Record<string, unknown>;
|
||||
const num = Math.max(1, Number(count) || 1);
|
||||
const items = Array.from({ length: num }, (_, i) => ({
|
||||
id: i + 1,
|
||||
shotDesc: prompt as string,
|
||||
script: '',
|
||||
imagePrompt: prompt as string,
|
||||
keyword: 'generated',
|
||||
}));
|
||||
const manifestPath = runInit({
|
||||
account: accountId as string,
|
||||
mode: 'single',
|
||||
items,
|
||||
imageModel: imageModel as string | undefined,
|
||||
});
|
||||
execSync(`node "${PIPELINE_SCRIPT}" run --manifest "${manifestPath}" --phase images`, {
|
||||
cwd: PROJECT_ROOT, encoding: 'utf-8',
|
||||
});
|
||||
const manifest = loadJSON(manifestPath) as { items?: Array<{ id: number; file?: string; candidates?: string[]; status?: string }> };
|
||||
const results = (manifest.items || []).map((item) => ({
|
||||
id: item.id,
|
||||
file: item.file || null,
|
||||
candidates: item.candidates || [],
|
||||
status: item.status,
|
||||
}));
|
||||
return JSON.stringify({ manifestPath, images: results }, null, 2);
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user