repositories
loading repo index
repositories
loading repo index
repository
loading code, commits, and activity
public Clawd ADK gateway launch mirror
stars
latest
clone command
git clone gitlawb://did:key:z6Mkq5mY...iFZ5/my-project-publ...git clone gitlawb://did:key:z6Mkq5mY.../my-project-publ...2fa351d6docs: add automaton and perps launch sources16d ago| #1 | #!/usr/bin/env node |
| #2 | /** |
| #3 | * 本地化测试命令 |
| #4 | * 用于验证所有语言版本的 Agent 文件是否存在 |
| #5 | */ |
| #6 | import { existsSync, readJSONSync } from 'fs-extra'; |
| #7 | import { resolve } from 'node:path'; |
| #8 | import pMap from 'p-map'; |
| #9 | |
| #10 | import { agents, agentsDir, config, publicDir, root } from '../core/constants'; |
| #11 | import { Logger } from '../utils/logger'; |
| #12 | import { formatAndCheckSchema } from '../validators/agent-validator'; |
| #13 | |
| #14 | /** |
| #15 | * 执行本地化测试流程 |
| #16 | */ |
| #17 | const runTest = async () => { |
| #18 | Logger.split('开始本地化测试'); |
| #19 | const startTime = Date.now(); |
| #20 | |
| #21 | const validFiles = agents.filter((file) => file.isFile()); |
| #22 | Logger.info('待测试文件数量', validFiles.length); |
| #23 | |
| #24 | // 并行收集所有 Agent 标识符 |
| #25 | Logger.start('收集 Agent 标识符'); |
| #26 | const identifiers = await pMap( |
| #27 | validFiles, |
| #28 | async (file, index) => { |
| #29 | const filePath = resolve(agentsDir, file.name); |
| #30 | const relativePath = filePath.replace(root, ''); |
| #31 | |
| #32 | Logger.progress(index + 1, validFiles.length, `解析 ${relativePath}`); |
| #33 | |
| #34 | try { |
| #35 | const agent = readJSONSync(filePath); |
| #36 | formatAndCheckSchema(agent); // 验证 Schema |
| #37 | return agent.identifier; |
| #38 | } catch (error) { |
| #39 | Logger.error('文件解析失败', `${file.name}: ${error}`); |
| #40 | throw error; |
| #41 | } |
| #42 | }, |
| #43 | { concurrency: config.concurrency }, // 使用配置中的并发数控制 |
| #44 | ); |
| #45 | |
| #46 | Logger.success('标识符收集完成', '', `共 ${identifiers.length} 个`); |
| #47 | |
| #48 | // 并行检查每个 Agent 的所有语言版本 |
| #49 | Logger.start('检查多语言版本文件'); |
| #50 | let totalChecked = 0; |
| #51 | |
| #52 | await pMap( |
| #53 | identifiers, |
| #54 | async (identifier, index) => { |
| #55 | Logger.progress(index + 1, identifiers.length, `检查 ${identifier}`); |
| #56 | |
| #57 | const filename = [identifier, 'json'].join('.'); |
| #58 | const isExist = existsSync(resolve(publicDir, filename)); |
| #59 | |
| #60 | if (!isExist) { |
| #61 | Logger.error('主文件不存在', filename); |
| #62 | throw `${filename} Agent 文件不存在`; |
| #63 | } |
| #64 | |
| #65 | // 并行检查所有输出语言版本 |
| #66 | const nonEntryLocales = config.outputLocales.filter( |
| #67 | (locale) => locale !== config.entryLocale, |
| #68 | ); |
| #69 | await pMap( |
| #70 | nonEntryLocales, |
| #71 | async (locale) => { |
| #72 | const localeFilename = [identifier, locale, 'json'].join('.'); |
| #73 | const isLocaleExist = existsSync(resolve(publicDir, localeFilename)); |
| #74 | |
| #75 | if (!isLocaleExist) { |
| #76 | Logger.error('本地化文件不存在', localeFilename); |
| #77 | throw `${localeFilename} Agent 文件不存在`; |
| #78 | } |
| #79 | totalChecked++; |
| #80 | }, |
| #81 | { concurrency: config.concurrency }, // 使用配置中的并发数控制 |
| #82 | ); |
| #83 | |
| #84 | Logger.success('多语言版本检查通过', identifier, `${config.outputLocales.length} 种语言`); |
| #85 | }, |
| #86 | { concurrency: config.concurrency }, // 使用配置中的并发数控制 |
| #87 | ); |
| #88 | |
| #89 | const duration = Date.now() - startTime; |
| #90 | Logger.stats({ |
| #91 | 'Agent 数量': identifiers.length, |
| #92 | '总耗时': `${duration}ms`, |
| #93 | '支持语言数': config.outputLocales.length, |
| #94 | '检查文件总数': totalChecked + identifiers.length, |
| #95 | }); |
| #96 | |
| #97 | Logger.success('本地化测试完成'); |
| #98 | }; |
| #99 | |
| #100 | // 执行测试 |
| #101 | await runTest(); |
| #102 | |
| #103 | |
| #104 |