refactor(agent): 将 tools 模块拆分为独立文件并优化导入路径
将 `tools.ts` 拆分为按功能划分的独立文件,并存放于 `tools/` 目录下,同时更新导入路径;优化 agent 系统提示语,移除冗余的「美图 Agent」前缀。
This commit is contained in:
28
web/server/agent/tools/list-accounts.ts
Normal file
28
web/server/agent/tools/list-accounts.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import { ACCOUNTS_DIR, loadJSON } from './shared';
|
||||
import type { ToolDefinition } from './types';
|
||||
|
||||
export const listAccounts: ToolDefinition = {
|
||||
name: 'list_accounts',
|
||||
description: '列出所有可用账号,返回每个账号的名称、描述、生图模型和视频模型',
|
||||
input_schema: {
|
||||
type: 'object',
|
||||
properties: {},
|
||||
required: [],
|
||||
},
|
||||
execute: async () => {
|
||||
if (!fs.existsSync(ACCOUNTS_DIR)) return '暂无账号';
|
||||
const dirs = fs.readdirSync(ACCOUNTS_DIR, { withFileTypes: true })
|
||||
.filter((d) => d.isDirectory() && !d.name.startsWith('_') && !d.name.startsWith('.'))
|
||||
.map((d) => {
|
||||
const configPath = path.join(ACCOUNTS_DIR, d.name, 'account.json');
|
||||
if (fs.existsSync(configPath)) {
|
||||
const cfg = loadJSON(configPath) as Record<string, string>;
|
||||
return `${d.name} - ${cfg.description || '无描述'} (生图:${cfg.imageModel} 视频:${cfg.videoModel} 画幅:${cfg.defaultFormat})`;
|
||||
}
|
||||
return d.name;
|
||||
});
|
||||
return dirs.join('\n') || '暂无账号';
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user