Files
sproutclaw/.pi/agent/extensions/webui/backend/routes/extension-ui.ts
shumengya d51a055d78
Some checks failed
CI / build-check-test (push) Has been cancelled
npm audit / audit (push) Has been cancelled
feat: update webui extensions, models, and agent config
2026-06-10 21:45:53 +08:00

26 lines
845 B
TypeScript

import type { IncomingMessage, ServerResponse } from "node:http";
import type { WebUiContext } from "../types/context.ts";
import { json, readBody } from "../http/request.ts";
export function handleExtensionUiRoute(
req: IncomingMessage,
res: ServerResponse,
ctx: WebUiContext,
pathname: string,
): boolean {
if (req.method !== "POST" || pathname !== "/api/extension-ui-response") {
return false;
}
void readBody(req)
.then(({ id, response }) => {
if (typeof id !== "string" || !id.trim()) throw new Error("缺少 extension UI 响应 id");
if (!response || typeof response !== "object") throw new Error("缺少 extension UI 响应内容");
ctx.rpc.sendExtensionUiResponse(id, response as Record<string, unknown>);
json(res, { ok: true });
})
.catch((err) => json(res, { error: err.message }, 500));
return true;
}