web: approval cards for chat permission requests (C10)

Completes the item the pipeline could not land: the C10 diff its own
implementer and probe assertions already verified is committed as-is.
The resource block is a padding-free six-line clamp inside a padded frame
(the app's maxLines = 6 + ellipsis) and the primary control is filled.
This commit is contained in:
2026-10-19 11:08:53 +01:00
parent 27a1605127
commit 5eb13968e3
9 changed files with 1148 additions and 15 deletions
+39
View File
@@ -3,10 +3,18 @@
// divergent field names. Mirrors android/.../data/PipelinesRepository.kt.
import { ChatKeys, Protocol } from "./protocol.js";
import { ProtocolError } from "./client.js";
import { DECISIONS } from "./chat.js";
/** The server default history page the app asks for (CHAT_HISTORY_LIMIT, 200). */
export const CHAT_HISTORY_LIMIT = 200;
/**
* The label this browser client records with a permission answer, so every other
* watching client can see which device resolved the request (the Android analogue
* is the device name). It is always sent; the server records it with the outcome.
*/
export const WEB_CHAT_CLIENT = "Web";
export class PipelinesRepository {
#client;
@@ -334,6 +342,37 @@ export class PipelinesRepository {
}
return session;
}
/**
* Answers one pending permission request (C10). Sends exactly
* `{type:'chat_reply', chat_reply:{session_id,request_id,decision,client}}` —
* `message` rides only when non-blank (mirrors ChatReplyRequest's omitempty).
* A blank session/request/decision, or a decision outside `once`/`always`/
* `reject`, is refused here before anything is sent, so an unaccepted decision
* can never reach the server. The server pushes the shared resolution back to
* every watching client once the first answer is recorded.
*/
async chatReply(sessionId, requestId, decision, { message = "", client = WEB_CHAT_CLIENT } = {}) {
const session = String(sessionId ?? "").trim();
const request = String(requestId ?? "").trim();
const chosen = String(decision ?? "").trim();
if (session === "") throw new ProtocolError("Select a chat session first.");
if (request === "") {
throw new ProtocolError("This approval request is no longer available.");
}
if (!DECISIONS.includes(chosen)) {
throw new ProtocolError("Choose once, always or reject.");
}
const body = {
session_id: session,
request_id: request,
decision: chosen,
client: String(client ?? "").trim() || WEB_CHAT_CLIENT,
};
const trimmed = String(message ?? "").trim();
if (trimmed !== "") body.message = trimmed;
await this.#client.call({ type: Protocol.CHAT_REPLY, [ChatKeys.REPLY]: body });
}
}
/**