Self-evolving Context Database for AI Agents. Unify Agent Memory, Knowledge RAG and Skills.
Python agent-contextagent-memoryagent-pluginsagentic-ragcontext-databasedsh-pluginknowledge-basememorymemory-managementself-evolvingvector-database
fix: handle Studio random UUID fallback (#2338)
yufengba973cc62683
diff --git a/web-studio/index.html b/web-studio/index.htmlindex b17fc5644..00d396b44 100644--- a/web-studio/index.html+++ b/web-studio/index.html@@ -20,6 +20,52 @@<meta name="apple-mobile-web-app-capable" content="yes" /><meta name="apple-mobile-web-app-title" content="OpenViking" /><meta name="apple-mobile-web-app-status-bar-style" content="default" />+ <!-- Runs before Vite's module graph so dependencies can safely call crypto.randomUUID. -->+ <script>+ ;(() => {+ const cryptoObject = globalThis.crypto+ if (!cryptoObject || typeof cryptoObject.randomUUID === 'function') {+ return+ }++ const createUuid = () => {+ const bytes = new Uint8Array(16)+ if (typeof cryptoObject.getRandomValues === 'function') {+ cryptoObject.getRandomValues(bytes)+ } else {+ for (let index = 0; index < bytes.length; index += 1) {+ bytes[index] = Math.floor(Math.random() * 256)+ }+ }++ bytes[6] = (bytes[6] & 0x0f) | 0x40+ bytes[8] = (bytes[8] & 0x3f) | 0x80++ const hex = Array.from(bytes, (byte) =>+ byte.toString(16).padStart(2, '0'),+ )++ return `${hex.slice(0, 4).join('')}-${hex+ .slice(4, 6)+ .join('')}-${hex.slice(6, 8).join('')}-${hex+ .slice(8, 10)+ .join('')}-${hex.slice(10, 16).join('')}`+ }++ try {+ Object.defineProperty(cryptoObject, 'randomUUID', {+ configurable: true,+ value: createUuid,+ })+ } catch {+ try {+ cryptoObject.randomUUID = createUuid+ } catch {+ // Ignore browsers that expose a non-extensible Crypto object.+ }+ }+ })()+ </script><title>OpenViking Studio</title></head><body>diff --git a/web-studio/src/lib/browser-crypto.ts b/web-studio/src/lib/browser-crypto.tsnew file mode 100644index 000000000..f712c4ec8--- /dev/null+++ b/web-studio/src/lib/browser-crypto.ts@@ -0,0 +1,43 @@+type RandomUuid = ReturnType<Crypto['randomUUID']>++function randomByte(): number {+ return Math.floor(Math.random() * 256)+}++function createFallbackRandomUuid(): RandomUuid {+ const browserCrypto =+ typeof globalThis.crypto !== 'undefined' ? globalThis.crypto : undefined++ const bytes = new Uint8Array(16)+ if (typeof browserCrypto?.getRandomValues === 'function') {+ browserCrypto.getRandomValues(bytes)+ } else {+ for (let index = 0; index < bytes.length; index += 1) {+ bytes[index] = randomByte()+ }+ }++ bytes[6] = (bytes[6] & 0x0f) | 0x40+ bytes[8] = (bytes[8] & 0x3f) | 0x80++ const hex = Array.from(bytes, (byte) => byte.toString(16).padStart(2, '0'))++ return `${hex.slice(0, 4).join('')}-${hex.slice(4, 6).join('')}-${hex+ .slice(6, 8)+ .join('')}-${hex.slice(8, 10).join('')}-${hex.slice(10, 16).join('')}`+}++export function createRandomUuid(): RandomUuid {+ const browserCrypto =+ typeof globalThis.crypto !== 'undefined' ? globalThis.crypto : undefined++ if (typeof browserCrypto?.randomUUID === 'function') {+ return browserCrypto.randomUUID()+ }++ return createFallbackRandomUuid()+}++export function createBrowserId(prefix: string): string {+ return `${prefix}_${createRandomUuid().replace(/-/g, '')}`+}diff --git a/web-studio/src/lib/sessions/use-chat.ts b/web-studio/src/lib/sessions/use-chat.tsindex 7ff24b240..2d58939ea 100644--- a/web-studio/src/lib/sessions/use-chat.ts+++ b/web-studio/src/lib/sessions/use-chat.ts@@ -6,14 +6,11 @@ import { addMessage, sendChatStream, serializeParts } from './api'import { generateTitle } from './generate-title'import { parseSseStream, streamEventDataToText } from './sse'import { setSessionTitle } from './use-session-titles'--function generateId(): string {- return `msg_${crypto.randomUUID().replace(/-/g, '')}`-}+import { createBrowserId } from '../browser-crypto'function createUserMessage(content: string): Message {return {- id: generateId(),+ id: createBrowserId('msg'),role: 'user',parts: [{ type: 'text', text: content }],created_at: new Date().toISOString(),@@ -51,7 +48,7 @@ function buildAssistantMessage(}return {- id: generateId(),+ id: createBrowserId('msg'),role: 'assistant',parts,created_at: new Date().toISOString(),