Skip to content

Build your personal knowledge base with Trilium Notes

fix(llm): use of crypto.randomUUID

Elian Doranfa7ec0132910
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(),