From cde3ce9b250fd70a1e288139aa089cab23732a62 Mon Sep 17 00:00:00 2001 From: Autumn-27 <53844290+Autumn-27@users.noreply.github.com> Date: Fri, 11 Sep 2026 11:13:21 -0400 Subject: [PATCH] =?UTF-8?q?fix(btw):=20=E9=9D=9E=E5=AE=89=E5=85=A8?= =?UTF-8?q?=E4=B8=8A=E4=B8=8B=E6=96=87=E9=99=8D=E7=BA=A7=E7=94=9F=E6=88=90?= =?UTF-8?q?=E6=97=81=E8=B7=AF=E8=AF=B7=E6=B1=82=20ID?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit crypto.randomUUID 仅在 https/localhost 可用,经 IP+http 访问 Web UI 时 为 undefined,导致 /btw 提问抛 "crypto.randomUUID is not a function"。 改用与 sessions-tab / tasks 页面一致的降级写法。 --- web/src/hooks/use-side-questions.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/web/src/hooks/use-side-questions.ts b/web/src/hooks/use-side-questions.ts index 8672ca6..ef530d2 100644 --- a/web/src/hooks/use-side-questions.ts +++ b/web/src/hooks/use-side-questions.ts @@ -7,6 +7,13 @@ import { toast } from "sonner"; import { sseUrl } from "@/lib/api"; import { isBtwCommand, type SideExchange, type SideHistory, sideAPI } from "@/lib/side-questions"; +// crypto.randomUUID 仅在安全上下文可用(https/localhost);经 IP+http 访问时降级。 +function newSideRequestID(): string { + return ( + globalThis.crypto?.randomUUID?.() ?? `btw-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 12)}` + ); +} + function merge(old: SideExchange[], incoming: SideExchange[]) { const byID = new Map(old.map((item) => [item.id, item])); for (const item of incoming) { @@ -150,7 +157,7 @@ export function useSideQuestions(parent: string | null) { setError(""); setDraft(question); setOpen(true); - if (retry.current?.question !== question) retry.current = { question, id: crypto.randomUUID() }; + if (retry.current?.question !== question) retry.current = { question, id: newSideRequestID() }; try { const item = await sideAPI.ask(parent, question, retry.current.id); if (version !== epoch.current) return;