Files
video-create/web/server/agent/tools/list-accounts.ts
sion123 2ab5396461 refactor(agent): 将 tools 模块拆分为独立文件并优化导入路径
将 `tools.ts` 拆分为按功能划分的独立文件,并存放于 `tools/` 目录下,同时更新导入路径;优化 agent 系统提示语,移除冗余的「美图 Agent」前缀。
2026-05-08 01:05:37 +08:00

29 lines
1.1 KiB
TypeScript

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') || '暂无账号';
},
};