From fa7ec0132910e6b428f9626aca7cf97bb3bb8680 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Sun, 29 Mar 2026 12:27:18 +0300 Subject: [PATCH] fix(llm): use of crypto.randomUUID --- CLAUDE.md | 4 ++++ .../client/src/widgets/type_widgets/llm_chat/LlmChat.tsx | 9 +++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/CLAUDE.md b/CLAUDE.md index 5e70898951..1cc5e198d5 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -125,6 +125,10 @@ Trilium provides powerful user scripting capabilities: - OpenID and TOTP authentication support - Sanitization of user-generated content +### Client-Side API Restrictions +- **Do not use `crypto.randomUUID()`** or other Web Crypto APIs that require secure contexts - Trilium can run over HTTP, not just HTTPS +- Use `randomString()` from `apps/client/src/services/utils.ts` for generating IDs instead + ## Common Development Tasks ### Adding New Note Types diff --git a/apps/client/src/widgets/type_widgets/llm_chat/LlmChat.tsx b/apps/client/src/widgets/type_widgets/llm_chat/LlmChat.tsx index c098499891..37d1a08b75 100644 --- a/apps/client/src/widgets/type_widgets/llm_chat/LlmChat.tsx +++ b/apps/client/src/widgets/type_widgets/llm_chat/LlmChat.tsx @@ -1,6 +1,7 @@ import { useCallback, useEffect, useRef, useState } from "preact/hooks"; import { t } from "../../../services/i18n.js"; import { streamChatCompletion, type ChatMessage as ChatMessageData, type Citation } from "../../../services/llm_chat.js"; +import { randomString } from "../../../services/utils.js"; import { useEditorSpacedUpdate } from "../../react/hooks.js"; import { TypeWidgetProps } from "../type_widget.js"; import ChatMessage from "./ChatMessage.js"; @@ -110,7 +111,7 @@ export default function LlmChat({ note, ntxId, noteContext }: TypeWidgetProps) { setPendingCitations([]); const userMessage: StoredMessage = { - id: crypto.randomUUID(), + id: randomString(), role: "user", content: input.trim(), createdAt: new Date().toISOString() @@ -160,7 +161,7 @@ export default function LlmChat({ note, ntxId, noteContext }: TypeWidgetProps) { console.error("Chat error:", errorMsg); // Persist error as an assistant message const errorMessage: StoredMessage = { - id: crypto.randomUUID(), + id: randomString(), role: "assistant", content: errorMsg, createdAt: new Date().toISOString(), @@ -179,7 +180,7 @@ export default function LlmChat({ note, ntxId, noteContext }: TypeWidgetProps) { // Save thinking as a separate message if present if (thinkingContent) { newMessages.push({ - id: crypto.randomUUID(), + id: randomString(), role: "assistant", content: thinkingContent, createdAt: new Date().toISOString(), @@ -189,7 +190,7 @@ export default function LlmChat({ note, ntxId, noteContext }: TypeWidgetProps) { if (assistantContent) { newMessages.push({ - id: crypto.randomUUID(), + id: randomString(), role: "assistant", content: assistantContent, createdAt: new Date().toISOString(),