openrouter

This commit is contained in:
2026-02-17 09:30:35 +00:00
parent e8492c3fa9
commit 95bd651377
4 changed files with 167 additions and 17 deletions

56
cli.py
View File

@@ -580,6 +580,51 @@ def cmd_whatsapp(args):
_whatsapp_qr()
def cmd_openrouter(args):
"""Handle openrouter subcommand."""
semaphore = PROJECT_ROOT / ".use_openrouter"
if args.openrouter_action == "on":
env_file = Path.home() / ".claude-env.sh"
if not env_file.exists():
print(f"Error: {env_file} not found")
sys.exit(1)
# Verify required vars exist in file
text = env_file.read_text()
if "ANTHROPIC_BASE_URL" not in text or "OPENROUTER_API_KEY" not in text:
print(f"Warning: {env_file} may be missing ANTHROPIC_BASE_URL or OPENROUTER_API_KEY")
semaphore.write_text("# OpenRouter mode enabled\n")
print("OpenRouter mode: ENABLED")
print("Restart echo-core for changes to take effect:")
print(" systemctl --user restart echo-core")
elif args.openrouter_action == "off":
if semaphore.exists():
semaphore.unlink()
print("OpenRouter mode: DISABLED")
print("Restart echo-core to use Anthropic API:")
print(" systemctl --user restart echo-core")
else:
print("OpenRouter mode: already disabled")
elif args.openrouter_action == "status":
status = "ENABLED" if semaphore.exists() else "DISABLED"
print(f"OpenRouter mode: {status}")
if semaphore.exists():
print(f"Semafor: {semaphore}")
env_file = Path.home() / ".claude-env.sh"
if env_file.exists():
# Show which vars will be loaded
print(f"Env file: {env_file}")
text = env_file.read_text()
for line in text.splitlines():
if line.strip().startswith("export ") and not line.strip().startswith("#"):
var_name = line.strip()[7:].split("=")[0] if "=" in line else "?"
if any(x in var_name for x in ["ANTHROPIC", "OPENROUTER"]):
print(f" {var_name}=***")
def _whatsapp_status():
"""Check WhatsApp bridge connection status."""
import urllib.request
@@ -806,6 +851,14 @@ def main():
whatsapp_sub.add_parser("status", help="Check bridge connection status")
whatsapp_sub.add_parser("qr", help="Show QR code instructions")
# openrouter
openrouter_parser = sub.add_parser("openrouter", help="Toggle OpenRouter mode")
openrouter_sub = openrouter_parser.add_subparsers(dest="openrouter_action")
openrouter_sub.add_parser("on", help="Enable OpenRouter mode")
openrouter_sub.add_parser("off", help="Disable OpenRouter mode")
openrouter_sub.add_parser("status", help="Check OpenRouter status")
# Parse and dispatch
args = parser.parse_args()
@@ -839,6 +892,9 @@ def main():
"whatsapp": lambda a: (
cmd_whatsapp(a) if a.whatsapp_action else (whatsapp_parser.print_help() or sys.exit(0))
),
"openrouter": lambda a: (
cmd_openrouter(a) if a.openrouter_action else (openrouter_parser.print_help() or sys.exit(0))
),
}
handler = dispatch.get(args.command)