37 lines
1021 B
TypeScript
37 lines
1021 B
TypeScript
/**
|
|
* S-08 — slash-command registry route.
|
|
*
|
|
* GET /sessions/:id/commands → [{ name, description, args }]
|
|
*
|
|
* Returns the list of slash commands available in the current pi session.
|
|
* Delegates to pi/commands.ts (T-1.4).
|
|
*
|
|
* Owner: T-1.6
|
|
*/
|
|
|
|
import type { IncomingMessage, ServerResponse } from "node:http";
|
|
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
import { getCommands } from "../../pi/commands.js";
|
|
import { getSession } from "../../tmux/manager.js";
|
|
import { sendJson } from "../util.js";
|
|
|
|
export async function handleCommands(
|
|
_req: IncomingMessage,
|
|
res: ServerResponse,
|
|
sessionId: string,
|
|
pi: ExtensionAPI,
|
|
): Promise<void> {
|
|
const session = await getSession(sessionId).catch(() => null);
|
|
if (!session) {
|
|
sendJson(res, 404, { error: "session_not_found" });
|
|
return;
|
|
}
|
|
|
|
try {
|
|
const commands = await getCommands(pi);
|
|
sendJson(res, 200, commands);
|
|
} catch (err) {
|
|
sendJson(res, 500, { error: "internal_error", message: String(err) });
|
|
}
|
|
}
|