mirror of
https://github.com/Alishahryar1/free-claude-code.git
synced 2026-04-28 03:20:01 +00:00
- OpenRouter: native Anthropic only; remove chat_request and OPENROUTER_TRANSPORT - Drop OpenAICompatibleProvider alias, api.request_utils, voice_pipeline facade - Simplify OpenRouter SSE, generic reasoning in conversion, messaging dispatch - Shared markdown table helpers; API optimization response helper; contract guards - Restore PLAN.md; update docs and tests
38 lines
1.1 KiB
Python
38 lines
1.1 KiB
Python
"""Command parsing and dispatch for messaging handlers."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from typing import Any
|
|
|
|
from .commands import handle_clear_command, handle_stats_command, handle_stop_command
|
|
from .models import IncomingMessage
|
|
|
|
|
|
def parse_command_base(text: str | None) -> str:
|
|
"""Return the slash command without bot mention suffix."""
|
|
parts = (text or "").strip().split()
|
|
cmd = parts[0] if parts else ""
|
|
return cmd.split("@", 1)[0] if cmd else ""
|
|
|
|
|
|
def message_kind_for_command(command_base: str) -> str:
|
|
"""Return the persistence kind for an incoming message."""
|
|
return "command" if command_base.startswith("/") else "content"
|
|
|
|
|
|
async def dispatch_command(
|
|
handler: Any,
|
|
incoming: IncomingMessage,
|
|
command_base: str,
|
|
) -> bool:
|
|
"""Dispatch a known command and return whether it was handled."""
|
|
commands = {
|
|
"/clear": handle_clear_command,
|
|
"/stop": handle_stop_command,
|
|
"/stats": handle_stats_command,
|
|
}
|
|
command = commands.get(command_base)
|
|
if command is None:
|
|
return False
|
|
await command(handler, incoming)
|
|
return True
|