Files
video-create/web/server/agent/tools/list-accounts.ts

29 lines
1.1 KiB
TypeScript
Raw Normal View History

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