Skip to content

Commit f9d0111

Browse files
fix: 替换 web 端 crypto.randomUUID 为 uuid 库以支持 HTTP 环境
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 481e2a5 commit f9d0111

5 files changed

Lines changed: 8 additions & 8 deletions

File tree

packages/remote-control-server/web/src/components/EventStream.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ function AskUserPanel({
444444
const handleSubmit = () => {
445445
const mapped: Record<string, unknown> = {};
446446
for (const [qIdx, val] of Object.entries(answers)) {
447-
const q = questions[parseInt(qIdx)];
447+
const q = questions[parseInt(qIdx, 10)];
448448
if (!q) continue;
449449
if (typeof val === "number") {
450450
mapped[qIdx] = q.options?.[val]?.label || String(val);

packages/remote-control-server/web/src/components/PermissionViews.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ export function AskUserPanelView({
9797
const handleSubmit = () => {
9898
const mapped: Record<string, unknown> = {};
9999
for (const [qIdx, val] of Object.entries(answers)) {
100-
const q = questions[parseInt(qIdx)];
100+
const q = questions[parseInt(qIdx, 10)];
101101
if (!q) continue;
102102
if (typeof val === "number") mapped[qIdx] = q.options?.[val]?.label || String(val);
103103
else if (Array.isArray(val)) mapped[qIdx] = val.map((i) => q.options?.[i]?.label || String(i));

packages/remote-control-server/web/src/lib/rcs-chat-adapter.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { SetStateAction } from "react";
2+
import { v4 as uuidv4 } from "uuid";
23
import {
34
apiFetchSession,
45
apiFetchSessionHistory,
@@ -421,7 +422,7 @@ export class RCSChatAdapter {
421422
// Send to backend
422423
await apiSendEvent(this.sessionId, {
423424
type: "user",
424-
uuid: crypto.randomUUID(),
425+
uuid: uuidv4(),
425426
content: text,
426427
message: { content: text },
427428
});

packages/remote-control-server/web/src/lib/rcs-transport.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { ChatTransport, UIMessage, UIMessageChunk } from "ai";
2+
import { v4 as uuidv4 } from "uuid";
23
import { getUuid } from "../api/client";
34
import type { SessionEvent, EventPayload } from "../types";
45

@@ -112,7 +113,7 @@ export class RCSTransport implements ChatTransport<UIMessage> {
112113
headers: { "Content-Type": "application/json" },
113114
body: JSON.stringify({
114115
type: "user",
115-
uuid: crypto.randomUUID(),
116+
uuid: uuidv4(),
116117
content: text,
117118
message: { content: text },
118119
}),

packages/remote-control-server/web/src/lib/utils.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { type ClassValue, clsx } from "clsx";
22
import { twMerge } from "tailwind-merge";
3+
import { v4 as uuidv4 } from "uuid";
34

45
export function cn(...inputs: ClassValue[]) {
56
return twMerge(clsx(inputs));
@@ -42,10 +43,7 @@ export function truncate(str: string | null | undefined, max: number): string {
4243
}
4344

4445
export function generateMessageUuid(): string {
45-
if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
46-
return crypto.randomUUID();
47-
}
48-
return `msg_${Date.now()}_${Math.random().toString(16).slice(2)}`;
46+
return uuidv4();
4947
}
5048

5149
export function extractEventText(payload: Record<string, unknown> | null | undefined): string {

0 commit comments

Comments
 (0)