-
Notifications
You must be signed in to change notification settings - Fork 122
Add ACP backend router for WeChat switching #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -1,10 +1,14 @@ | ||||||||
| #!/usr/bin/env node | ||||||||
|
|
||||||||
| import fs from "node:fs"; | ||||||||
| import path from "node:path"; | ||||||||
|
|
||||||||
| /** | ||||||||
| * WeChat + ACP (Agent Client Protocol) adapter. | ||||||||
| * | ||||||||
| * Usage: | ||||||||
| * npx weixin-acp login # QR-code login | ||||||||
| * npx weixin-acp start --router-config file.json # Start bot with multi-backend router | ||||||||
| * npx weixin-acp start -- <command> [args...] # Start bot | ||||||||
| * | ||||||||
| * Examples: | ||||||||
|
|
@@ -15,9 +19,27 @@ | |||||||
| import { login, start } from "weixin-agent-sdk"; | ||||||||
|
|
||||||||
| import { AcpAgent } from "./src/acp-agent.js"; | ||||||||
| import type { AcpRouterConfig } from "./src/types.js"; | ||||||||
|
|
||||||||
| const command = process.argv[2]; | ||||||||
|
|
||||||||
| function resolveRouterConfigPath(input: string): string { | ||||||||
| return path.isAbsolute(input) ? input : path.resolve(process.cwd(), input); | ||||||||
| } | ||||||||
|
|
||||||||
| function loadRouterConfig(configPath: string): AcpRouterConfig { | ||||||||
| const resolvedPath = resolveRouterConfigPath(configPath); | ||||||||
| const raw = fs.readFileSync(resolvedPath, "utf8"); | ||||||||
| const parsed = JSON.parse(raw) as AcpRouterConfig; | ||||||||
| if (!parsed.defaultBackend?.trim()) { | ||||||||
| throw new Error("router config 缺少 defaultBackend"); | ||||||||
| } | ||||||||
| if (!parsed.backends || Object.keys(parsed.backends).length === 0) { | ||||||||
| throw new Error("router config 缺少 backends"); | ||||||||
| } | ||||||||
| return parsed; | ||||||||
| } | ||||||||
|
|
||||||||
| async function main() { | ||||||||
| switch (command) { | ||||||||
| case "login": { | ||||||||
|
|
@@ -26,10 +48,39 @@ async function main() { | |||||||
| } | ||||||||
|
|
||||||||
| case "start": { | ||||||||
| const routerArgIndex = process.argv.indexOf("--router-config"); | ||||||||
| if (routerArgIndex !== -1) { | ||||||||
| const configPath = process.argv[routerArgIndex + 1]; | ||||||||
| if (!configPath) { | ||||||||
| console.error("错误: --router-config 后必须跟 JSON 文件路径"); | ||||||||
| process.exit(1); | ||||||||
| } | ||||||||
|
|
||||||||
| const agent = new AcpAgent({ | ||||||||
| command: "", | ||||||||
|
||||||||
| command: "", | |
| // In router-config mode, no external command is spawned; this placeholder satisfies the type. | |
| command: "__ROUTER_MODE_NO_COMMAND__", |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| { | ||
| "defaultBackend": "claude", | ||
| "backends": { | ||
| "claude": { | ||
| "command": "claude-agent-acp" | ||
| }, | ||
| "codex": { | ||
| "command": "codex-acp" | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This example uses
./packages/agent-acp/router.example.json, which only exists when running from this monorepo checkout. For users following the README vianpx weixin-acp ..., that path won’t exist. Consider adjusting the docs to instruct users to create their ownrouter.json(and optionally reference the example file on GitHub) rather than pointing to a workspace-relative path.