diff --git a/frontend/src/lib/components/FlowPreviewContent.svelte b/frontend/src/lib/components/FlowPreviewContent.svelte index 3c5267917d..cab32403f3 100644 --- a/frontend/src/lib/components/FlowPreviewContent.svelte +++ b/frontend/src/lib/components/FlowPreviewContent.svelte @@ -39,6 +39,7 @@ import { aiChatManager } from './copilot/chat/AIChatManager.svelte' import { stateSnapshot } from '$lib/svelte5Utils.svelte' import FlowChatInterface from './flows/conversations/FlowChatInterface.svelte' + import { randomUUID } from './flows/conversations/FlowChatManager.svelte' interface Props { previewMode: 'upTo' | 'whole' @@ -469,7 +470,7 @@ return jobId ?? '' }} createConversation={async () => { - const newConversationId = crypto.randomUUID() + const newConversationId = randomUUID() return newConversationId }} /> diff --git a/frontend/src/lib/components/flows/content/FlowInput.svelte b/frontend/src/lib/components/flows/content/FlowInput.svelte index 7eae608898..bffdd2dcf9 100644 --- a/frontend/src/lib/components/flows/content/FlowInput.svelte +++ b/frontend/src/lib/components/flows/content/FlowInput.svelte @@ -49,6 +49,7 @@ import { AI_AGENT_SCHEMA } from '../flowInfers' import { nextId } from '../flowModuleNextId' import ConfirmationModal from '$lib/components/common/confirmationModal/ConfirmationModal.svelte' + import { randomUUID } from '../conversations/FlowChatManager.svelte' interface Props { noEditor: boolean @@ -491,7 +492,7 @@ { - const newConversationId = crypto.randomUUID() + const newConversationId = randomUUID() return newConversationId }} /> diff --git a/frontend/src/lib/components/flows/conversations/FlowChatManager.svelte.ts b/frontend/src/lib/components/flows/conversations/FlowChatManager.svelte.ts index edde28bbef..8f0948f4ed 100644 --- a/frontend/src/lib/components/flows/conversations/FlowChatManager.svelte.ts +++ b/frontend/src/lib/components/flows/conversations/FlowChatManager.svelte.ts @@ -18,6 +18,15 @@ export interface FlowChatManagerOptions { path?: string } +export function randomUUID() { + // Pure JS (RFC4122 v4) UUID implementation (no external dependencies) + return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) { + const r = (Math.random() * 16) | 0 + const v = c === 'x' ? r : (r & 0x3) | 0x8 + return v.toString(16) + }) +} + class FlowChatManager { // State messages = $state([]) @@ -320,7 +329,7 @@ class FlowChatManager { delete this.#conversationsCache[currentConversationId] const userMessage: ChatMessage = { - id: crypto.randomUUID(), + id: randomUUID(), content: this.inputMessage.trim(), created_at: new Date().toISOString(), message_type: 'user', @@ -395,7 +404,6 @@ class FlowChatManager { eventSource.onmessage = async (event) => { try { const data = JSON.parse(event.data) - console.log('data', data) if (data.type === 'update') { if (data.flow_stream_job_id) { this.currentJobId = data.flow_stream_job_id @@ -423,7 +431,7 @@ class FlowChatManager { this.messages = [ ...this.messages, { - id: 'temp-' + crypto.randomUUID(), + id: 'temp-' + randomUUID(), content: newContent, created_at: new Date().toISOString(), message_type: 'tool', @@ -445,7 +453,7 @@ class FlowChatManager { assistantMessageId.length === 0 && accumulatedContent.length > 0 ) { - assistantMessageId = 'temp-' + crypto.randomUUID() + assistantMessageId = 'temp-' + randomUUID() this.messages = [ ...this.messages, { diff --git a/frontend/src/routes/(root)/(logged)/flows/get/[...path]/+page.svelte b/frontend/src/routes/(root)/(logged)/flows/get/[...path]/+page.svelte index 84ceabe2b6..444bed9496 100644 --- a/frontend/src/routes/(root)/(logged)/flows/get/[...path]/+page.svelte +++ b/frontend/src/routes/(root)/(logged)/flows/get/[...path]/+page.svelte @@ -65,6 +65,7 @@ initFlowGraphAssetsCtx } from '$lib/components/flows/FlowAssetsHandler.svelte' import { page } from '$app/state' + import { randomUUID } from '$lib/components/flows/conversations/FlowChatManager.svelte' let flow: Flow | undefined = $state() let can_write = false @@ -401,7 +402,7 @@ let path = $derived(page.params.path ?? '') async function handleNewConversation({ clearMessages = true }: { clearMessages?: boolean }) { - const newConversationId = crypto.randomUUID() + const newConversationId = randomUUID() // Add the new conversation to the sidebar (returns id of draft or new conversation) if (flowConversationsSidebar) {