diff --git a/packages/redrob/src/desk/forward.ts b/packages/redrob/src/desk/forward.ts index 09869aa026..2f5cc082f2 100644 --- a/packages/redrob/src/desk/forward.ts +++ b/packages/redrob/src/desk/forward.ts @@ -167,6 +167,22 @@ export const ROUTES: readonly Route[] = [ return reply === "once" || reply === "reject" }, }, + // The agent's questions (the `question` tool): the device lists, answers or dismisses them, or the + // turn waits on an answer nobody can give. + { method: "GET", path: new RegExp(`^/api/session/${ID}/question$`) }, + { + method: "POST", + path: new RegExp(`^/api/session/${ID}/question/${ID}/reply$`), + body: (body) => { + const answers = (body as { answers?: unknown } | undefined)?.answers + return ( + Array.isArray(answers) && + answers.length <= 20 && + answers.every((a) => Array.isArray(a) && a.length <= 20 && a.every((v) => typeof v === "string" && v.length <= 2000)) + ) + }, + }, + { method: "POST", path: new RegExp(`^/api/session/${ID}/question/${ID}/reject$`) }, { method: "GET", path: /^\/v1\/apps$/ }, // AI 방화벽 "strong": the web reads and sets the PC's masking, and masks a message on the PC first. { method: "GET", path: /^\/api\/privacy$/ }, @@ -1093,7 +1109,8 @@ export class Forwarder { return } const sessionID = typeof event.data?.sessionID === "string" ? event.data.sessionID : undefined - const permission = event.type.startsWith("permission.") + // Permission and question requests reach every device, like the approval count. + const permission = event.type.startsWith("permission.") || event.type.startsWith("question.") if (event.type === "session.next.attachment" && isAttachment(event.data)) this.remember(event.data) if (event.type === "permission.v2.asked" && typeof event.data?.id === "string") this.asked.add(event.data.id) if (event.type === "permission.v2.replied" && typeof event.data?.requestID === "string") diff --git a/packages/redrob/test/desk/forward-question.test.ts b/packages/redrob/test/desk/forward-question.test.ts new file mode 100644 index 0000000000..85cd6af693 --- /dev/null +++ b/packages/redrob/test/desk/forward-question.test.ts @@ -0,0 +1,19 @@ +import { describe, expect, test } from "bun:test" +import { match } from "../../src/desk/forward" + +describe("desk question routes", () => { + test("a device lists, answers and dismisses the agent's questions", () => { + expect(match({ method: "GET", path: "/api/session/ses_a/question" })).toMatchObject({ sessionID: "ses_a" }) + expect( + match({ method: "POST", path: "/api/session/ses_a/question/que_1/reply", body: { answers: [["예"], ["A", "B"]] } }), + ).toBeDefined() + expect(match({ method: "POST", path: "/api/session/ses_a/question/que_1/reject" })).toBeDefined() + }) + + test("bad answers and paths are refused", () => { + expect(match({ method: "POST", path: "/api/session/ses_a/question/que_1/reply", body: { answers: "예" } })).toBeUndefined() + expect(match({ method: "POST", path: "/api/session/ses_a/question/que_1/reply", body: { answers: [[1]] } })).toBeUndefined() + expect(match({ method: "POST", path: "/api/session/ses_a/question/../reply", body: { answers: [] } })).toBeUndefined() + expect(match({ method: "GET", path: "/api/question/request" })).toBeUndefined() + }) +})