Initial gori agent gateway

This commit is contained in:
zenord
2026-08-14 23:06:31 +08:00
commit 00325efb50
26 changed files with 2779 additions and 0 deletions
+57
View File
@@ -0,0 +1,57 @@
import { AgentRegistry } from "../agents/agent-registry.js";
import { SessionStore } from "./session-store.js";
import type { IncomingMessage } from "./types.js";
export interface CommandResult {
handled: boolean;
text?: string;
}
export class CommandRouter {
constructor(
private readonly agents: AgentRegistry,
private readonly sessions: SessionStore
) {}
route(message: IncomingMessage, sessionId: string): CommandResult {
const text = message.text.trim();
if (!text.startsWith("/")) return { handled: false };
const [command, ...args] = text.split(/\s+/);
switch (command) {
case "/help":
return {
handled: true,
text: [
"Commands:",
"/help - show this help",
"/status - show gateway/session status",
"/agents - list available agents",
"/agent <name> - select an agent for this chat",
"/new - reset this chat session"
].join("\n")
};
case "/status": {
const session = this.sessions.getSession(sessionId);
return {
handled: true,
text: `OK\nplatform=${message.platform}\nchat=${message.chatId}\nagent=${session.selectedAgent || this.agents.defaultName()}`
};
}
case "/agents":
return { handled: true, text: `Available agents: ${this.agents.list().join(", ")}` };
case "/agent": {
const agentName = args[0];
if (!agentName) return { handled: true, text: "Usage: /agent <name>" };
if (!this.agents.has(agentName)) return { handled: true, text: `Unknown agent: ${agentName}` };
this.sessions.setSelectedAgent(sessionId, agentName);
return { handled: true, text: `Selected agent: ${agentName}` };
}
case "/new":
this.sessions.reset(sessionId);
return { handled: true, text: "Started a new session for this chat." };
default:
return { handled: false };
}
}
}