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 | * 更新 Awesome 命令 |
| #4 | * 用于更新 README 文件中的 Agent 列表 |
| #5 | */ |
| #6 | import { readJSONSync } from 'fs-extra'; |
| #7 | import { readFileSync, writeFileSync } from 'node:fs'; |
| #8 | import { resolve } from 'node:path'; |
| #9 | import pMap from 'p-map'; |
| #10 | |
| #11 | import { |
| #12 | config, |
| #13 | indexCnPath, |
| #14 | indexPath, |
| #15 | publicDir, |
| #16 | readmeCnPath, |
| #17 | readmePath, |
| #18 | } from '../core/constants'; |
| #19 | import { updateAwesomeReadme } from '../utils/common'; |
| #20 | import { Logger } from '../utils/logger'; |
| #21 | |
| #22 | /** |
| #23 | * 更新指定语言的 README 文件 |
| #24 | * @param filePath README 文件路径 |
| #25 | * @param md 原始 Markdown 内容 |
| #26 | * @param agents Agent 列表 |
| #27 | * @param locale 语言代码 |
| #28 | */ |
| #29 | const updateAwesome = async (filePath: string, md: string, agents: any[], locale?: string) => { |
| #30 | const lang = locale === 'zh-CN' ? '中文' : '英文'; |
| #31 | Logger.start(`处理${lang} README`, `${agents.length} 个 Agents`); |
| #32 | |
| #33 | // 并行处理所有 Agent 条目生成 |
| #34 | const data = await pMap( |
| #35 | agents, |
| #36 | async ({ identifier, author, createdAt, homepage }, i) => { |
| #37 | const agentConfigPath = resolve( |
| #38 | publicDir, |
| #39 | [identifier, locale, 'json'].filter(Boolean).join('.'), |
| #40 | ); |
| #41 | |
| #42 | try { |
| #43 | const { meta } = readJSONSync(agentConfigPath); |
| #44 | |
| #45 | // 构建 Agent 条目 |
| #46 | const header = `### [${meta.title.replaceAll('[', '').replaceAll(']', '')}](https://os.clawd.io/crypto/agents/${identifier})`; |
| #47 | const subHeader = `<sup>By **[@${author}](${homepage})** on **${createdAt}**</sup>`; |
| #48 | const desc = [ |
| #49 | `${meta.description}`, |
| #50 | `${meta.tags |
| #51 | .filter(Boolean) |
| #52 | .map((tag) => `\`${tag}\``) |
| #53 | .join(' ')}`, |
| #54 | ].join('\n\n'); |
| #55 | |
| #56 | return [i === 0 ? false : '---', header, subHeader, desc].filter(Boolean).join('\n\n'); |
| #57 | } catch (error) { |
| #58 | Logger.warn('Agent 配置读取失败', `${identifier}: ${error}`); |
| #59 | return ''; |
| #60 | } |
| #61 | }, |
| #62 | { concurrency: config.concurrency }, // 使用配置中的并发数控制 |
| #63 | ); |
| #64 | |
| #65 | // 更新 README 内容 |
| #66 | const newMd = updateAwesomeReadme(md, data.filter(Boolean).join('\n\n')); |
| #67 | writeFileSync(filePath, newMd, 'utf8'); |
| #68 | Logger.file('write', filePath); |
| #69 | Logger.success(`${lang} README 更新完成`); |
| #70 | }; |
| #71 | |
| #72 | /** |
| #73 | * 执行更新流程 |
| #74 | */ |
| #75 | const runUpdateAwesome = async () => { |
| #76 | Logger.split('更新 README 文件'); |
| #77 | const startTime = Date.now(); |
| #78 | |
| #79 | // 读取文件内容 |
| #80 | Logger.start('读取文件内容'); |
| #81 | const readmeCn = readFileSync(readmeCnPath, 'utf8'); |
| #82 | const readme = readFileSync(readmePath, 'utf8'); |
| #83 | const index = readJSONSync(indexPath); |
| #84 | const indexCn = readJSONSync(indexCnPath); |
| #85 | |
| #86 | Logger.info('文件读取完成'); |
| #87 | Logger.stats({ |
| #88 | '中文 Agents': indexCn.agents.length, |
| #89 | '英文 Agents': index.agents.length, |
| #90 | }); |
| #91 | |
| #92 | // 并行更新英文和中文 README |
| #93 | Logger.start('更新 README 内容'); |
| #94 | await Promise.all([ |
| #95 | updateAwesome(readmePath, readme, index.agents), |
| #96 | updateAwesome(readmeCnPath, readmeCn, indexCn.agents, 'zh-CN'), |
| #97 | ]); |
| #98 | |
| #99 | const duration = Date.now() - startTime; |
| #100 | Logger.success('README 更新完成', '', `耗时 ${duration}ms`); |
| #101 | }; |
| #102 | |
| #103 | // 执行更新 |
| #104 | await runUpdateAwesome(); |
| #105 | |
| #106 | |
| #107 |