A React Native app for the ultimate thinking partner.
at main 2.0 kB view raw
1/** 2 * Polyfills for React Native to support Web Streams API and Crypto 3 * Required for Letta SDK streaming functionality 4 */ 5 6// IMPORTANT: Import crypto polyfill FIRST before anything else 7// This provides secure random number generation required by many libraries 8import 'react-native-get-random-values'; 9 10// Manually polyfill web streams instead of using react-native-polyfill-globals/auto 11// which has compatibility issues with newer web-streams-polyfill versions 12if (typeof global !== 'undefined') { 13 // Load web-streams-polyfill 14 const webStreams = require('web-streams-polyfill'); 15 16 // Always override to ensure consistency across platforms 17 global.ReadableStream = webStreams.ReadableStream; 18 global.WritableStream = webStreams.WritableStream; 19 global.TransformStream = webStreams.TransformStream; 20 21 // Polyfill TextEncoder/TextDecoder 22 if (!global.TextEncoder || !global.TextDecoder) { 23 const encoding = require('text-encoding'); 24 global.TextEncoder = encoding.TextEncoder; 25 global.TextDecoder = encoding.TextDecoder; 26 } 27 28 // Polyfill fetch if needed (usually provided by React Native) 29 if (!global.fetch) { 30 console.warn('[Polyfill] fetch not available - some features may not work'); 31 } 32 33 // Polyfill URL and URLSearchParams if needed 34 if (!global.URL) { 35 try { 36 const { URL, URLSearchParams } = require('react-native-url-polyfill'); 37 global.URL = URL; 38 global.URLSearchParams = URLSearchParams; 39 } catch (e) { 40 console.warn('[Polyfill] URL polyfill not available:', e.message); 41 } 42 } 43 44 console.log('[Polyfill] Web Streams API polyfill loaded'); 45 console.log('[Polyfill] ReadableStream:', typeof global.ReadableStream); 46 console.log('[Polyfill] WritableStream:', typeof global.WritableStream); 47 console.log('[Polyfill] TransformStream:', typeof global.TransformStream); 48 console.log('[Polyfill] TextEncoder:', typeof global.TextEncoder); 49 console.log('[Polyfill] TextDecoder:', typeof global.TextDecoder); 50}