Skip to content

fix(webui): add UUID fallback for legacy WebViews - #130

Merged
su-fen merged 2 commits into
Stack-Cairn:mainfrom
SinclairLin:fix/webui-random-uuid-fallback
Jul 17, 2026
Merged

fix(webui): add UUID fallback for legacy WebViews#130
su-fen merged 2 commits into
Stack-Cairn:mainfrom
SinclairLin:fix/webui-random-uuid-fallback

Conversation

@SinclairLin

@SinclairLin SinclairLin commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

概述

修复旧版或嵌入式 WebView 中 UUID 生成失败的问题,桌面端与 Gateway Web 同步使用兼容的 UUID 生成逻辑。

根因

项目中多处直接调用 crypto.randomUUID()。部分旧版 WebView 不提供该 API,或者虽然暴露了该 API,但实际调用时会抛出异常,导致会话、设置、SSH、文件上传和自动化相关流程无法继续。

改动

  • 新增统一的 createUuid() 工具,优先使用 crypto.randomUUID()。
  • 在 randomUUID() 不可用或调用失败时,回退到 crypto.getRandomValues()。
  • 在浏览器 crypto API 不可用时,使用带版本和变体标记的本地 UUID v4 回退逻辑。
  • 替换 Gateway WebUI 与桌面 GUI 中直接调用 crypto.randomUUID() 的代码。
  • 为 Gateway WebUI 和桌面 GUI 增加 UUID 生成及相关 ID 派生逻辑的浏览器测试。

用户影响

旧版或能力不完整的嵌入式 WebView 可以继续创建会话、配置供应商、SSH 主机、上传文件和自动化请求;现代浏览器仍优先使用原生 crypto.randomUUID()。

查重

未发现重复 Issue 或 PR;已检索上游仓库中与 UUID、randomUUID、WebView 相关的 Issue 和 PR。

验证

  • 桌面端 pnpm build 通过。
  • 桌面端 pnpm lint 通过。
  • 桌面端 pnpm test:frontend 通过:951 项测试全部通过。
  • git diff --check 通过。
  • Gateway Web 的 pnpm build、pnpm lint 和 pnpm test 未能在当前环境执行:pnpm 阻止 @google/genai、protobufjs 的依赖构建脚本,并要求显式 approve-builds。

@SinclairLin
SinclairLin marked this pull request as ready for review July 17, 2026 11:15
@SinclairLin SinclairLin changed the title 修复旧版 WebView 中 UUID 生成失败的问题 fix(webui): add UUID fallback for legacy WebViews Jul 17, 2026
@SinclairLin
SinclairLin marked this pull request as draft July 17, 2026 11:19
@SinclairLin
SinclairLin marked this pull request as ready for review July 17, 2026 11:19
@su-fen

su-fen commented Jul 17, 2026

Copy link
Copy Markdown
Member

感谢佬为此项目作出的贡献!

… createUuid

Follow-up to the createUuid() fallback:

- Replace the leftover `typeof crypto?.randomUUID === "function"` guard +
  hand-rolled fallback pattern at 12 call sites (GUI: compaction engine,
  uploaded-file message ids, hosted-search probe ids, right-dock writer id,
  subagent id suffix, power-activity ids, shell run ids, local gateway chat
  run ids, gateway bridge worker ids; WebUI: uploaded-file message ids,
  chat client request ids, right-dock writer id). The typeof guard survives
  a missing API but still crashes in WebViews where randomUUID exists yet
  throws when called — the exact scenario createUuid() handles.
- Register lib/shared/id.ts in scripts/mirror-manifest.json so CI enforces
  the two copies stay byte-identical.
- Document on createUuid() that the last-resort path is not
  cryptographically secure and must not be used for security tokens.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@su-fen
su-fen merged commit 1a4d568 into Stack-Cairn:main Jul 17, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants