@@ -47,6 +47,19 @@ export interface AgentSource {
4747 name : string
4848}
4949
50+ // Generate UUID with fallback for browsers without crypto.randomUUID
51+ function generateUUID ( ) : string {
52+ if ( typeof crypto !== "undefined" && crypto . randomUUID ) {
53+ return crypto . randomUUID ( )
54+ }
55+ // Fallback: generate a simple UUID v4
56+ return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx" . replace ( / [ x y ] / g, ( c ) => {
57+ const r = ( Math . random ( ) * 16 ) | 0
58+ const v = c === "x" ? r : ( r & 0x3 ) | 0x8
59+ return v . toString ( 16 )
60+ } )
61+ }
62+
5063export function createFileAttachment (
5164 path : string ,
5265 filename : string ,
@@ -63,7 +76,7 @@ export function createFileAttachment(
6376 }
6477
6578 return {
66- id : crypto . randomUUID ( ) ,
79+ id : generateUUID ( ) ,
6780 type : "file" ,
6881 display : `@${ filename } ` ,
6982 url : fileUrl ,
@@ -81,7 +94,7 @@ export function createFileAttachment(
8194export function createTextAttachment ( value : string , display : string , filename : string ) : Attachment {
8295 const base64 = encodeTextAsBase64 ( value )
8396 return {
84- id : crypto . randomUUID ( ) ,
97+ id : generateUUID ( ) ,
8598 type : "text" ,
8699 display,
87100 url : `data:text/plain;base64,${ base64 } ` ,
@@ -114,7 +127,7 @@ function encodeTextAsBase64(value: string): string {
114127
115128export function createAgentAttachment ( agentName : string ) : Attachment {
116129 return {
117- id : crypto . randomUUID ( ) ,
130+ id : generateUUID ( ) ,
118131 type : "agent" ,
119132 display : `@${ agentName } ` ,
120133 url : "" ,
0 commit comments