UNPKG

@revrag-ai/embed-react-native

Version:

A powerful React Native library for integrating AI-powered voice agents into mobile applications. Features real-time voice communication, intelligent speech processing, customizable UI components, and comprehensive event handling for building conversation

101 lines (96 loc) 2.95 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.SDK_VERSION = exports.SDK_PLATFORM = exports.SDK_NAME = exports.DEFAULT_EMBED_URL = void 0; exports.buildEventPayload = buildEventPayload; exports.generateEventId = generateEventId; var _package = _interopRequireDefault(require("../../package.json")); function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; } // SDK Constants const SDK_NAME = exports.SDK_NAME = 'embed_react_native'; const SDK_VERSION = exports.SDK_VERSION = _package.default.version; const SDK_PLATFORM = exports.SDK_PLATFORM = 'react_native'; const DEFAULT_EMBED_URL = exports.DEFAULT_EMBED_URL = 'https://embed.revrag.ai'; /** * Generate a random event ID */ function generateEventId() { return `event_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`; } /** * Build a standardized event payload for the SDK */ function buildEventPayload(params) { const { eventKey, app_user_id, appUserId, eventData, data: incomingData, sessionId, session_id, context, screen, flow, app_version, event_name, ...rest } = params; const resolvedAppUserId = typeof app_user_id === 'string' && app_user_id || typeof appUserId === 'string' && appUserId; if (!resolvedAppUserId) { throw new Error('app_user_id is required to build event payload'); } // Start with any explicit data objects and merge remaining unknown keys const data = { ...(incomingData ?? {}), ...(eventData ?? {}) }; // Extract event_name if present in data, remove it from data object let resolvedEventName = ''; if (typeof event_name === 'string' && event_name) { resolvedEventName = event_name; } else if (typeof data.event_name === 'string' && data.event_name) { resolvedEventName = data.event_name; delete data.event_name; } Object.entries(rest).forEach(([key, value]) => { if (value !== undefined) { data[key] = value; } }); const payload = { event_id: generateEventId(), type: eventKey, app_user_id: resolvedAppUserId, timestamp: new Date().toISOString(), event_name: resolvedEventName, sdk: { sdk_name: SDK_NAME, sdk_version: SDK_VERSION, platform: SDK_PLATFORM }, data }; const resolvedSessionId = typeof sessionId === 'string' && sessionId || typeof session_id === 'string' && session_id; const resolvedAppVersion = typeof app_version === 'string' ? app_version : undefined; if (resolvedSessionId) { payload.session_id = resolvedSessionId; } if (context || screen || flow || resolvedAppVersion) { payload.context = { ...(context ?? {}), ...(screen ? { screen } : {}), ...(flow ? { flow } : {}), ...(resolvedAppVersion ? { app_version: resolvedAppVersion } : {}) }; } return payload; } //# sourceMappingURL=constant.js.map