@onairosofficial/onairos-capacitor 0.1.0 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CAPACITOR_QUICK_START.md +379 -0
- package/CONNECTORS.md +122 -0
- package/LICENSE +194 -10
- package/OnairosofficialOnairosCapacitor.podspec +13 -0
- package/Package.swift +26 -0
- package/README.md +176 -25
- package/dist/onairos.capacitor.esm.js +1 -0
- package/dist/onairos.capacitor.esm.turbopack.js +1 -0
- package/docs/CAPACITOR_INTEGRATION_GUIDE.md +159 -0
- package/docs/CAPACITOR_MOCK_APP_TESTING.md +213 -0
- package/docs/CAPACITOR_SDK_FIXES_SUMMARY.md +65 -0
- package/docs/CROSS_SDK_PARITY.md +239 -0
- package/docs/DATA_FREQUENCY.md +57 -0
- package/docs/DEVELOPER_SDK_CHANGES.md +532 -0
- package/docs/INCIDENT_ENABLETRAINING_PIN_WEB_8.1.9.md +82 -0
- package/docs/ONAIROS_BUTTON_PROPS.md +152 -0
- package/docs/PLATFORM_APIS.md +559 -0
- package/docs/RAW_MEMORIES_API.md +305 -0
- package/docs/RAW_MEMORIES_SDK_UPDATE.md +54 -0
- package/docs/SDK_PARITY_ROLLUP_2026_04_24_to_05_02.md +96 -0
- package/docs/oldFixes.md +216 -0
- package/ios/Sources/OnairosNativeConnectorsPlugin/OnairosChatGPTNativePlugin.swift +993 -0
- package/ios/Sources/OnairosNativeConnectorsPlugin/OnairosNetflixNativePlugin.swift +33 -0
- package/ios/Sources/OnairosNativeConnectorsPlugin/OnairosSpotifyNativePlugin.swift +1082 -0
- package/onairos.d.ts +656 -0
- package/package.json +188 -37
- package/src/OnairosReconnectButton.jsx +272 -0
- package/src/RSA.jsx +57 -0
- package/src/assets/NewLogo.png +0 -0
- package/src/assets/OnairosNewLogo.png +0 -0
- package/src/assets/chatgpt-icon.png +0 -0
- package/src/assets/fire-horse.png +0 -0
- package/src/assets/fire-horse.transparent.png +0 -0
- package/src/assets/latest-firehorse.png +0 -0
- package/src/assets/perplexity.png +0 -0
- package/src/assets/persona.png +0 -0
- package/src/assets/persona1.png +0 -0
- package/src/assets/persona2.png +0 -0
- package/src/assets/persona3.png +0 -0
- package/src/assets/persona4.png +0 -0
- package/src/assets/persona5.png +0 -0
- package/src/capacitorConnectorCatalog.js +38 -0
- package/src/capacitorOAuthConfig.js +52 -0
- package/src/chatgptHostedImport/index.js +303 -0
- package/src/components/AuthButtons.jsx +48 -0
- package/src/components/ConnectChatGPTModal.jsx +666 -0
- package/src/components/ConnectClaudeModal.jsx +610 -0
- package/src/components/ConnectGeminiModal.jsx +639 -0
- package/src/components/ConnectGrokModal.jsx +701 -0
- package/src/components/ConnectPerplexityModal.jsx +726 -0
- package/src/components/DataExplainerScreen.jsx +349 -0
- package/src/components/DataRequest.js +885 -0
- package/src/components/DataRequest.jsx +1055 -0
- package/src/components/EmailAuth.js +1871 -0
- package/src/components/EmailAuth.jsx +2062 -0
- package/src/components/ExtensionInstallPrompt.jsx +142 -0
- package/src/components/GoogleButton.js +133 -0
- package/src/components/LLMConnectorManager.jsx +201 -0
- package/src/components/LoadingPage.jsx +19 -0
- package/src/components/LoadingScreen.jsx +81 -0
- package/src/components/LunarBirthdate.jsx +96 -0
- package/src/components/LunarLoadingPage.jsx +251 -0
- package/src/components/Notification.jsx +21 -0
- package/src/components/OnairosAppButton.jsx +85 -0
- package/src/components/OnairosSSO.jsx +645 -0
- package/src/components/OnairosTrigger.jsx +61 -0
- package/src/components/PerplexityLogo.jsx +43 -0
- package/src/components/PinSetup.js +200 -0
- package/src/components/PinSetup.jsx +228 -0
- package/src/components/SDK_PIN_INTEGRATION_REQUIRED_CHANGES.md +526 -0
- package/src/components/SdkErrorBoundary.jsx +36 -0
- package/src/components/SecuritySetup.js +81 -0
- package/src/components/SessionUserBar.jsx +83 -0
- package/src/components/SignUp.js +123 -0
- package/src/components/TestTelegramButton.js +53 -0
- package/src/components/TrainingComponent.jsx +200 -0
- package/src/components/TrainingScreen.jsx +897 -0
- package/src/components/UniversalOnboarding.js +306 -0
- package/src/components/UniversalOnboarding.jsx +4837 -0
- package/src/components/ValentineLoadingPage.jsx +502 -0
- package/src/components/ValentineModeSelector.jsx +162 -0
- package/src/components/WelcomeScreen.jsx +435 -0
- package/src/components/WrappedLoadingPage.jsx +205 -0
- package/src/components/connectors/ChatGPTConnector.js +348 -0
- package/src/components/connectors/ChatGPTConnector.jsx +348 -0
- package/src/components/connectors/ClaudeConnector.js +44 -0
- package/src/components/connectors/ClaudeConnector.jsx +44 -0
- package/src/components/connectors/GeminiConnector.js +170 -0
- package/src/components/connectors/GeminiConnector.jsx +170 -0
- package/src/components/connectors/GmailConnector.js +148 -0
- package/src/components/connectors/GmailConnector.jsx +148 -0
- package/src/components/connectors/GrokConnector.js +16 -0
- package/src/components/connectors/GrokConnector.jsx +16 -0
- package/src/components/connectors/HingeConnector.js +419 -0
- package/src/components/connectors/HingeConnector.jsx +419 -0
- package/src/components/connectors/InstagramDataConnector.js +726 -0
- package/src/components/connectors/InstagramDataConnector.jsx +726 -0
- package/src/components/connectors/LinkedInConnector.js +4 -0
- package/src/components/connectors/LinkedInConnector.jsx +296 -0
- package/src/components/connectors/PerplexityConnector.jsx +16 -0
- package/src/components/connectors/PinterestConnector.js +208 -0
- package/src/components/connectors/PinterestConnector.jsx +208 -0
- package/src/components/connectors/README.md +292 -0
- package/src/components/connectors/RedditConnector.js +229 -0
- package/src/components/connectors/RedditConnector.jsx +229 -0
- package/src/components/connectors/SephoraConnector.js +482 -0
- package/src/components/connectors/SephoraConnector.jsx +482 -0
- package/src/components/connectors/TikTokConnector.jsx +430 -0
- package/src/components/connectors/YoutubeConnector.js +361 -0
- package/src/components/connectors/YoutubeConnector.jsx +361 -0
- package/src/components/connectors/index.js +50 -0
- package/src/components/icons.jsx +46 -0
- package/src/components/icons.tsx +21 -0
- package/src/components/ui/PageLayout.jsx +1255 -0
- package/src/components/ui/PrimaryButton.jsx +162 -0
- package/src/components/ui/button.jsx +49 -0
- package/src/components/ui/card.jsx +61 -0
- package/src/components/ui/checkbox.jsx +33 -0
- package/src/components/ui/label.jsx +29 -0
- package/src/components/utils/UpdateConnections.js +45 -0
- package/src/components/utils/oauthHelper.js +97 -0
- package/src/config/api-config.js +138 -0
- package/src/deepLink.jsx +38 -0
- package/src/getPin.js +26 -0
- package/src/icons/Avatar.png +0 -0
- package/src/icons/Sentiment.png +0 -0
- package/src/icons/Trait.png +0 -0
- package/src/iframe/DataRequestPage.jsx +285 -0
- package/src/iframe/OnairosButtonIntegration.md +148 -0
- package/src/iframe/components/Box.jsx +56 -0
- package/src/iframe/components/IndividualConnection.jsx +88 -0
- package/src/iframe/dataRequestHandler.js +714 -0
- package/src/iframe/data_request_iframe.html +27 -0
- package/src/iframe/data_request_page.js +47 -0
- package/src/iframe/icons/Avatar.png +1 -0
- package/src/iframe/icons/Avatar2.png +1 -0
- package/src/iframe/icons/Sentiment.png +1 -0
- package/src/iframe/icons/Trait.png +1 -0
- package/src/iframe/icons/onairos_logo.png +0 -0
- package/src/iframe/utils/api.js +57 -0
- package/src/index.js +274 -0
- package/src/laravel/OnairosVue.vue +410 -0
- package/src/laravel/blade-helpers.js +320 -0
- package/src/laravel/vite-plugin.js +179 -0
- package/src/mobile/MobileDataRequestPage.jsx +233 -0
- package/src/mobile/components/MobileBox.jsx +71 -0
- package/src/mobile/components/MobileIndividualConnection.jsx +51 -0
- package/src/mobile/shims/browser-apis.js +78 -0
- package/src/mobile/shims/lucide-shim.js +85 -0
- package/src/nativeConnectors.js +5 -0
- package/src/newUI/EMAIL_VERIFICATION_API_SCHEMA.md +268 -0
- package/src/newUI/PlatformConnectorsStep.tsx +435 -0
- package/src/newUI/PrimaryButton.tsx +213 -0
- package/src/newUI/SignInStep.tsx +194 -0
- package/src/newUI/VerificationStep.tsx +133 -0
- package/src/newUI/WelcomeScreen.tsx +311 -0
- package/src/newUI/services/connectedAccountsService.js +129 -0
- package/src/onairos.capacitor.jsx +15 -0
- package/src/onairos.core.jsx +133 -0
- package/src/onairos.jsx +14 -0
- package/src/onairos.native.jsx +15 -0
- package/src/onairosButton.jsx +9000 -0
- package/src/overlay/CheckBox.jsx +114 -0
- package/src/overlay/IndividualConnection copy.js +86 -0
- package/src/overlay/IndividualConnection.js +191 -0
- package/src/overlay/IndividualConnectionNew.jsx +157 -0
- package/src/overlay/box.js +84 -0
- package/src/overlay/overlay.js +437 -0
- package/src/styles/onairos-scoped-preflight.css +97 -0
- package/src/styles/sdkCssRegistry.js +20 -0
- package/src/styles/styleLoaderInsertShadow.js +69 -0
- package/src/styles/tailwind.capacitor.css +395 -0
- package/src/styles/tailwind.css +395 -0
- package/src/theme/colors.js +40 -0
- package/src/utils/apiKeyValidation.js +341 -0
- package/src/utils/apiResponseLogger.js +316 -0
- package/src/utils/authHeaders.js +275 -0
- package/src/utils/biometrics.js +26 -0
- package/src/utils/bookmarkletUtils.js +28 -0
- package/src/utils/capacitorDetection.js +278 -0
- package/src/utils/capacitorLLMHelper.js +352 -0
- package/src/utils/capacitorPlugins.js +366 -0
- package/src/utils/crossDomainSSO.js +587 -0
- package/src/utils/deepLinking.js +27 -0
- package/src/utils/devLogger.js +46 -0
- package/src/utils/extensionDetection.js +418 -0
- package/src/utils/extractMemory.js +277 -0
- package/src/utils/framerBrandingOverrides.js +40 -0
- package/src/utils/googleWebClientId.js +55 -0
- package/src/utils/overlayHandler.js +224 -0
- package/src/utils/platformDisconnect.js +309 -0
- package/src/utils/pollTrainingStatus.js +200 -0
- package/src/utils/rawMemoriesAccess.js +211 -0
- package/src/utils/resolveBackendAppId.js +47 -0
- package/src/utils/responseFormatter.js +140 -0
- package/src/utils/sdkDebugStorage.js +113 -0
- package/src/utils/sdkInitialization.js +645 -0
- package/src/utils/sessionManager.js +1258 -0
- package/src/utils/startBackgroundTraining.js +100 -0
- package/src/utils/userDataFormatter.js +222 -0
- package/index.d.ts +0 -1
- package/index.js +0 -1
|
@@ -0,0 +1,726 @@
|
|
|
1
|
+
/* eslint-disable no-script-url */
|
|
2
|
+
import React, { useEffect, useRef, useState } from 'react';
|
|
3
|
+
import * as ReactDOM from 'react-dom';
|
|
4
|
+
import { getApiBaseUrl } from '../config/api-config.js';
|
|
5
|
+
import { getApiKey, getUserToken } from '../utils/authHeaders.js';
|
|
6
|
+
|
|
7
|
+
const PERPLEXITY_BOOKMARKLET_HREF = [
|
|
8
|
+
"javascript:(async function(){try{",
|
|
9
|
+
"var host=(location.hostname||'').toLowerCase();",
|
|
10
|
+
"if(!(host==='perplexity.ai'||host.endsWith('.perplexity.ai'))){alert('Please open Perplexity first.');return;}",
|
|
11
|
+
"var APP_ORIGIN='__ONAIROS_ORIGIN__';",
|
|
12
|
+
"var APP_URL='__ONAIROS_URL__';",
|
|
13
|
+
"var API_URL='__API_URL__';",
|
|
14
|
+
"var token='__ONAIROS_TOKEN__';",
|
|
15
|
+
"var notifyApp=function(msg){try{if(window.opener&&!window.opener.closed){window.opener.postMessage(msg,APP_ORIGIN);return true;}}catch(_){}try{var p=window.open(APP_URL,'_blank');if(!p)return false;var n=0;var iv=setInterval(function(){try{if(!p||p.closed||n++>30){clearInterval(iv);return;}p.postMessage(msg,APP_ORIGIN);}catch(_){}},500);return true;}catch(_){return false;}};",
|
|
16
|
+
"var syncOrigin=(function(){try{return new URL(API_URL).origin}catch(_){return API_URL}})();var syncWin=null;var openSync=function(){try{syncWin=window.open(API_URL+'/perplexity-sync?receive=1','_dpSyncWin','width=480,height=560,toolbar=0,location=0,scrollbars=1,resizable=1');return syncWin}catch(_){return null}};openSync();",
|
|
17
|
+
"var hintEl=null;",
|
|
18
|
+
"var setHint=function(m){try{if(!hintEl){hintEl=document.createElement('div');hintEl.setAttribute('data-perplexity-export-status','1');hintEl.style.cssText='position:fixed;top:16px;right:16px;z-index:2147483647;max-width:280px;padding:8px 12px;border-radius:999px;background:rgba(15,23,42,.88);color:#fff;font:12px/1.2 -apple-system,BlinkMacSystemFont,Segoe UI,system-ui,sans-serif;box-shadow:0 10px 30px rgba(0,0,0,.22);pointer-events:none;opacity:.96;letter-spacing:.01em';document.body.appendChild(hintEl);}hintEl.textContent=String(m||'Preparing export...');}catch(_){}};",
|
|
19
|
+
"var clearHint=function(){try{if(hintEl&&hintEl.parentNode)hintEl.parentNode.removeChild(hintEl);}catch(_){}hintEl=null;};",
|
|
20
|
+
"var wait=function(ms){return new Promise(function(resolve){setTimeout(resolve,ms||0)});};",
|
|
21
|
+
"var clean=function(t){return String(t||'').replace(/\\s+$/,'').replace(/^\\s+/,'').replace(/\\n{3,}/g,'\\n\\n').trim();};",
|
|
22
|
+
"var normalizeTime=function(v){if(!v)return null;var n=Number(v);if(Number.isFinite(n))return new Date((n>9999999999?n:n*1000)).toISOString();var d=Date.parse(v);return Number.isFinite(d)?new Date(d).toISOString():null;};",
|
|
23
|
+
"var pickArray=function(v){if(Array.isArray(v))return v;if(!v||typeof v!=='object')return [];return v.threads||v.entries||v.data||v.items||v.results||v.conversations||v.nodes||[];};",
|
|
24
|
+
"var idFromValue=function(v){var s=String(v||'');var m=s.match(/\\/(?:search|thread|library)\\/([a-zA-Z0-9_-]{6,160})/i)||s.match(/[?&](?:id|thread|conversation)=([a-zA-Z0-9_-]{6,160})/i)||s.match(/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/i);return m?(m[1]||m[0]):null;};",
|
|
25
|
+
"var collectThreads=async function(){var out=[];var seen={};var add=function(it){it=it||{};var id=it.uuid||it.backend_uuid||it.thread_url_slug||it.context_uuid||it.slug||it.id||idFromValue(it.url||it.href||it.link||'');if(!id||seen[id])return;seen[id]=1;var title=it.title||it.thread_title||it.query||it.query_str||it.name||'Perplexity Conversation';out.push({id:String(id),title:clean(title)||'Perplexity Conversation'});};try{setHint('Finding conversations...');var urls=['/rest/thread/list_recent?exclude_asi=false&version=2.18&source=default','/rest/thread/list_recent?source=default','/rest/thread/list','/rest/library/list'];for(var ui=0;ui<urls.length&&out.length<10;ui++){try{var res=await fetch(urls[ui],{credentials:'include',headers:{accept:'application/json'},cache:'no-store'});if(!res.ok)continue;var list=await res.json();var items=pickArray(list);for(var li=0;li<items.length&&out.length<10;li++)add(items[li]);}catch(_){}}}catch(_){}try{var cur=idFromValue(location.href);if(cur)add({id:cur,title:(document.title||'Perplexity Conversation').replace(/\\s*-\\s*Perplexity.*$/i,'')});}catch(_){}try{var links=[].slice.call(document.querySelectorAll('a[href*=\"/search/\"],a[href*=\"/thread/\"],a[href*=\"/library/\"]'));for(var ai=0;ai<links.length&&out.length<10;ai++){add({id:idFromValue(links[ai].getAttribute('href')||links[ai].href||''),title:links[ai].innerText||links[ai].textContent||''});}}catch(_){}return out.slice(0,10);};",
|
|
26
|
+
"var roleOf=function(item){var raw=String((item&&item.role)||(item&&item.author)||(item&&item.sender)||(item&&item.type)||'').toLowerCase();if(raw.indexOf('user')!==-1||raw.indexOf('human')!==-1||raw.indexOf('query')!==-1)return'user';return'assistant';};",
|
|
27
|
+
"var textOf=function(item){if(!item)return'';var text='';if(typeof item==='string')text=item;if(!text&&typeof item.text==='string')text=item.text;if(!text&&typeof item.content==='string')text=item.content;if(!text&&typeof item.answer==='string')text=item.answer;if(!text&&typeof item.query_str==='string')text=item.query_str;if(!text&&item.query_display_metadata)text=item.query_display_metadata.query||'';if(!text&&Array.isArray(item.content))text=item.content.map(function(p){return typeof p==='string'?p:(p&&p.text)||'';}).join('\\n');if(!text&&item.message)text=textOf(item.message);return clean(text);};",
|
|
28
|
+
"var extractMessages=function(detail){var entries=pickArray(detail&&detail.entries?detail.entries:detail);if(!entries.length&&detail&&detail.thread)entries=pickArray(detail.thread);var msgs=[];for(var i=0;i<entries.length;i++){var e=entries[i]||{};var text=textOf(e);if(!text)continue;var ts=normalizeTime(e.updated_datetime||e.created_at||e.createdAt||e.timestamp||e.time)||(e.created_us?normalizeTime(Math.floor(Number(e.created_us)/1000)):null);msgs.push({role:roleOf(e),content:text,timestamp:ts});}return msgs;};",
|
|
29
|
+
"var extractDomCurrent=function(){var nodes=[];var root=document.querySelector('main')||document.body;var sels=['[data-testid*=\"thread\"]','[data-testid*=\"message\"]','[class*=\"thread\"]','[class*=\"message\"]','article'];for(var si=0;si<sels.length&&!nodes.length;si++){var els=[].slice.call(root.querySelectorAll(sels[si]));for(var ei=0;ei<els.length;ei++){var el=els[ei];if(el.closest&&el.closest('nav,header,footer,aside,[role=\"navigation\"]'))continue;var text=clean(el.innerText||el.textContent||'');if(!text||text.length<8||text.length>12000)continue;var cls=String(el.className||'').toLowerCase();var test=String(el.getAttribute('data-testid')||'').toLowerCase();var role=(cls.indexOf('query')!==-1||cls.indexOf('user')!==-1||test.indexOf('query')!==-1||test.indexOf('user')!==-1)?'user':'assistant';if(nodes.length&&nodes[nodes.length-1].content===text)continue;nodes.push({role:role,content:text,timestamp:null});}}if(!nodes.length){var candidates=[].slice.call(root.querySelectorAll('h1,h2,[class*=\"query\"],[class*=\"answer\"],[class*=\"prose\"],[class*=\"markdown\"],p'));var seenText={};for(var ci=0;ci<candidates.length;ci++){var c=candidates[ci];if(c.closest&&c.closest('nav,header,footer,aside,[role=\"navigation\"],button'))continue;var tx=clean(c.innerText||c.textContent||'');if(!tx||tx.length<8||seenText[tx])continue;seenText[tx]=1;var cl=String(c.className||'').toLowerCase();nodes.push({role:(cl.indexOf('query')!==-1||c.tagName==='H1')?'user':'assistant',content:tx,timestamp:null});if(nodes.length>=20)break;}}return nodes.length?{id:idFromValue(location.href)||('current_'+Date.now()),title:(document.title||'Perplexity Conversation').replace(/\\s*-\\s*Perplexity.*$/i,'')||'Perplexity Conversation',url:location.href,model:'perplexity',messages:nodes}:null;};",
|
|
30
|
+
"setHint('Getting your Perplexity conversations...');",
|
|
31
|
+
"var threads=await collectThreads();",
|
|
32
|
+
"var convos=[];",
|
|
33
|
+
"for(var i=0;i<threads.length&&convos.length<10;i++){try{setHint((i+1)+' / '+threads.length+' conversations');var detail=null;var detailUrls=['/rest/thread/'+encodeURIComponent(threads[i].id),'/rest/thread/'+encodeURIComponent(threads[i].id)+'?version=2.18','/rest/thread/detail/'+encodeURIComponent(threads[i].id)];for(var du=0;du<detailUrls.length&&!detail;du++){try{var r=await fetch(detailUrls[du],{credentials:'include',headers:{accept:'application/json'},cache:'no-store'});if(r.ok)detail=await r.json();}catch(_){}}if(!detail)continue;var msgs=extractMessages(detail);if(msgs.length)convos.push({id:threads[i].id,title:threads[i].title,url:location.origin+'/search/'+threads[i].id,model:'perplexity',messages:msgs});if(i<threads.length-1)await wait(150);}catch(_){}}",
|
|
34
|
+
"var domConv=extractDomCurrent();if(domConv&&domConv.messages&&domConv.messages.length){var exists=false;for(var di=0;di<convos.length;di++){if(convos[di].id===domConv.id)exists=true;}if(!exists)convos.unshift(domConv);}",
|
|
35
|
+
"if(!convos.length){clearHint();alert('No Perplexity conversations found. Open a Perplexity thread, make sure you are logged in, then retry.');return;}",
|
|
36
|
+
"setHint('Uploading to Onairos...');var data={type:'perplexity-export-data',exportId:String(Date.now())+'_'+Math.random().toString(36).slice(2),convos:convos,token:token,platform:'web-perplexity'};try{notifyApp(data)}catch(_){}if(!syncWin||syncWin.closed)openSync();var sends=0;var sendIv=setInterval(function(){try{if(!syncWin||syncWin.closed||sends++>40){clearInterval(sendIv);return;}syncWin.postMessage({type:'onairos-llm-sync-payload',platform:'web-perplexity',payload:data},syncOrigin);}catch(_){}},500);setHint('Sync in progress - see popup');setTimeout(clearHint,2500);",
|
|
37
|
+
"}catch(e){try{clearHint()}catch(_){}alert('Export error: '+(e&&e.message?e.message:e));}})();",
|
|
38
|
+
].join('');
|
|
39
|
+
|
|
40
|
+
const PENDING_IMPORT_KEY = '_pending_perplexity_import';
|
|
41
|
+
const SYNC_SUCCESS_KEY = 'onairos_perplexity_sync_success';
|
|
42
|
+
|
|
43
|
+
export const getOnairosPerplexityBookmarklet = () => PERPLEXITY_BOOKMARKLET_HREF;
|
|
44
|
+
|
|
45
|
+
const encodePayload = (value) => {
|
|
46
|
+
const json = JSON.stringify(value || {});
|
|
47
|
+
try {
|
|
48
|
+
return btoa(unescape(encodeURIComponent(json)));
|
|
49
|
+
} catch (_) {
|
|
50
|
+
return btoa(json);
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
const generateDataHash = async (value) => {
|
|
55
|
+
try {
|
|
56
|
+
const encoded = new TextEncoder().encode(JSON.stringify(value || {}));
|
|
57
|
+
const digest = await crypto.subtle.digest('SHA-256', encoded);
|
|
58
|
+
return `sha256-${Array.from(new Uint8Array(digest)).map((b) => b.toString(16).padStart(2, '0')).join('')}`;
|
|
59
|
+
} catch (_) {
|
|
60
|
+
return `sha256-${Date.now()}`;
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
const getPerplexityIdentifierForAccountCheck = () => {
|
|
65
|
+
try {
|
|
66
|
+
const user = JSON.parse(localStorage.getItem('onairosUser') || '{}');
|
|
67
|
+
return (
|
|
68
|
+
user.email ||
|
|
69
|
+
user.userEmail ||
|
|
70
|
+
user.identifier ||
|
|
71
|
+
user.userName ||
|
|
72
|
+
user.username ||
|
|
73
|
+
localStorage.getItem('onairos_user_email') ||
|
|
74
|
+
null
|
|
75
|
+
);
|
|
76
|
+
} catch (_) {
|
|
77
|
+
return localStorage.getItem('onairos_user_email') || null;
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
const markPerplexityConnectedLocally = () => {
|
|
82
|
+
try {
|
|
83
|
+
const storedConnections = JSON.parse(localStorage.getItem('onairos_connected_accounts') || '{}');
|
|
84
|
+
storedConnections.Perplexity = true;
|
|
85
|
+
localStorage.setItem('onairos_connected_accounts', JSON.stringify(storedConnections));
|
|
86
|
+
} catch (_) {}
|
|
87
|
+
try {
|
|
88
|
+
const connectedAccounts = JSON.parse(localStorage.getItem('connectedAccounts') || '[]');
|
|
89
|
+
if (!connectedAccounts.includes('Perplexity')) {
|
|
90
|
+
connectedAccounts.push('Perplexity');
|
|
91
|
+
localStorage.setItem('connectedAccounts', JSON.stringify(connectedAccounts));
|
|
92
|
+
}
|
|
93
|
+
} catch (_) {}
|
|
94
|
+
try {
|
|
95
|
+
const userData = JSON.parse(localStorage.getItem('onairosUser') || '{}');
|
|
96
|
+
if (!Array.isArray(userData.connectedAccounts)) userData.connectedAccounts = [];
|
|
97
|
+
if (!userData.connectedAccounts.includes('Perplexity')) {
|
|
98
|
+
userData.connectedAccounts.push('Perplexity');
|
|
99
|
+
localStorage.setItem('onairosUser', JSON.stringify(userData));
|
|
100
|
+
}
|
|
101
|
+
} catch (_) {}
|
|
102
|
+
try {
|
|
103
|
+
window.dispatchEvent(new CustomEvent('connected-accounts-updated', { detail: { platform: 'Perplexity' } }));
|
|
104
|
+
} catch (_) {}
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
const seenPerplexityExportIds = new Set();
|
|
108
|
+
|
|
109
|
+
const notifyLlmSyncPopup = (popupId, status, detail = {}) => {
|
|
110
|
+
if (!popupId) return;
|
|
111
|
+
try {
|
|
112
|
+
const popup = window.open('', '_dpSyncWin');
|
|
113
|
+
if (popup && !popup.closed) {
|
|
114
|
+
popup.postMessage({
|
|
115
|
+
type: 'onairos-llm-sync-status',
|
|
116
|
+
popupId,
|
|
117
|
+
status,
|
|
118
|
+
...detail,
|
|
119
|
+
}, '*');
|
|
120
|
+
}
|
|
121
|
+
} catch (_) {}
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
const uploadPerplexityExportData = async (convos, exportId = '') => {
|
|
125
|
+
const dedupeKey = exportId || JSON.stringify({ count: convos?.length || 0, first: convos?.[0]?.id || '' });
|
|
126
|
+
if (seenPerplexityExportIds.has(dedupeKey)) return false;
|
|
127
|
+
seenPerplexityExportIds.add(dedupeKey);
|
|
128
|
+
|
|
129
|
+
try {
|
|
130
|
+
const userData = JSON.parse(localStorage.getItem('onairosUser') || '{}');
|
|
131
|
+
const jwt = getUserToken() || userData.token || userData.jwt || localStorage.getItem('onairos_user_token') || '';
|
|
132
|
+
if (!jwt) {
|
|
133
|
+
console.warn('[Perplexity] Cannot upload: missing Onairos user token');
|
|
134
|
+
try {
|
|
135
|
+
localStorage.setItem(PENDING_IMPORT_KEY, JSON.stringify({ convos, exportId, receivedAt: Date.now(), reason: 'missing-token' }));
|
|
136
|
+
} catch (_) {}
|
|
137
|
+
return false;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
const baseUrl = (typeof window !== 'undefined' && window.onairosBaseUrl) || getApiBaseUrl();
|
|
141
|
+
const apiKey = getApiKey();
|
|
142
|
+
const identifier = getPerplexityIdentifierForAccountCheck();
|
|
143
|
+
|
|
144
|
+
const MAX_MSG_CHARS = 4000;
|
|
145
|
+
const MAX_MSGS_PER_CONVO = 20;
|
|
146
|
+
const trimmedConvos = (Array.isArray(convos) ? convos : []).map((c) => ({
|
|
147
|
+
...c,
|
|
148
|
+
messages: (Array.isArray(c.messages) ? c.messages : [])
|
|
149
|
+
.slice(0, MAX_MSGS_PER_CONVO)
|
|
150
|
+
.map((m) => ({
|
|
151
|
+
...m,
|
|
152
|
+
content: typeof m.content === 'string' && m.content.length > MAX_MSG_CHARS
|
|
153
|
+
? m.content.slice(0, MAX_MSG_CHARS) + '…'
|
|
154
|
+
: m.content,
|
|
155
|
+
})),
|
|
156
|
+
}));
|
|
157
|
+
|
|
158
|
+
const conversationData = {
|
|
159
|
+
platform: 'perplexity',
|
|
160
|
+
conversations: trimmedConvos,
|
|
161
|
+
timestamp: new Date().toISOString(),
|
|
162
|
+
};
|
|
163
|
+
const resp = await fetch(`${baseUrl}/llm-data/store`, {
|
|
164
|
+
method: 'POST',
|
|
165
|
+
headers: {
|
|
166
|
+
'Content-Type': 'application/json',
|
|
167
|
+
Authorization: `Bearer ${jwt}`,
|
|
168
|
+
...(apiKey ? { 'x-api-key': apiKey } : {}),
|
|
169
|
+
...(identifier ? { 'X-Onairos-User': identifier } : {}),
|
|
170
|
+
},
|
|
171
|
+
body: JSON.stringify({
|
|
172
|
+
encryptedData: encodePayload(conversationData),
|
|
173
|
+
encryptionMetadata: {
|
|
174
|
+
algorithm: 'AES-GCM',
|
|
175
|
+
keyDerivation: 'PBKDF2',
|
|
176
|
+
iterations: 100000,
|
|
177
|
+
},
|
|
178
|
+
authentication: {
|
|
179
|
+
username: identifier || userData.username || userData.email || '',
|
|
180
|
+
timestamp: Date.now(),
|
|
181
|
+
},
|
|
182
|
+
integrity: {
|
|
183
|
+
hash: await generateDataHash(conversationData),
|
|
184
|
+
algorithm: 'SHA-256',
|
|
185
|
+
},
|
|
186
|
+
platform: 'perplexity',
|
|
187
|
+
source: 'web_bookmarklet',
|
|
188
|
+
metadata: {
|
|
189
|
+
importedAt: new Date().toISOString(),
|
|
190
|
+
conversationCount: trimmedConvos.length,
|
|
191
|
+
},
|
|
192
|
+
}),
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
if (!resp.ok) {
|
|
196
|
+
const body = await resp.text().catch(() => '');
|
|
197
|
+
console.warn('[Perplexity] /llm-data/store failed', resp.status, body);
|
|
198
|
+
if (resp.status >= 500) {
|
|
199
|
+
try {
|
|
200
|
+
localStorage.setItem(PENDING_IMPORT_KEY, JSON.stringify({ convos, exportId, receivedAt: Date.now(), reason: 'server-error', status: resp.status }));
|
|
201
|
+
} catch (_) {}
|
|
202
|
+
}
|
|
203
|
+
return false;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
console.info('[Perplexity] Stored export via /llm-data/store', { conversationCount: convos?.length || 0 });
|
|
207
|
+
markPerplexityConnectedLocally();
|
|
208
|
+
return true;
|
|
209
|
+
} catch (error) {
|
|
210
|
+
console.warn('[Perplexity] Upload failed before backend storage', error);
|
|
211
|
+
return false;
|
|
212
|
+
}
|
|
213
|
+
};
|
|
214
|
+
|
|
215
|
+
if (typeof window !== 'undefined') {
|
|
216
|
+
const handlePerplexityExport = (event) => {
|
|
217
|
+
if (event.data?.type !== 'perplexity-export-data') return;
|
|
218
|
+
try {
|
|
219
|
+
if (event.source) {
|
|
220
|
+
event.source.postMessage({ type: 'perplexity-export-ack' }, event.origin);
|
|
221
|
+
}
|
|
222
|
+
} catch (_) {}
|
|
223
|
+
if (!window.__onairosPerplexityModalOpen) {
|
|
224
|
+
uploadPerplexityExportData(event.data.convos, event.data.exportId).then((stored) => {
|
|
225
|
+
const statusMessage = {
|
|
226
|
+
platform: 'Perplexity',
|
|
227
|
+
count: Array.isArray(event.data.convos) ? event.data.convos.length : 0,
|
|
228
|
+
message: stored ? '' : 'Could not store Perplexity data. Check the Onairos app tab.',
|
|
229
|
+
};
|
|
230
|
+
notifyLlmSyncPopup(event.data.popupId, stored ? 'success' : 'error', statusMessage);
|
|
231
|
+
try {
|
|
232
|
+
event.source?.postMessage({
|
|
233
|
+
type: 'onairos-llm-sync-status',
|
|
234
|
+
popupId: event.data.popupId,
|
|
235
|
+
status: stored ? 'success' : 'error',
|
|
236
|
+
...statusMessage,
|
|
237
|
+
}, event.origin);
|
|
238
|
+
} catch (_) {}
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
};
|
|
242
|
+
window.addEventListener('message', handlePerplexityExport);
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
export default function ConnectPerplexityModal({ open, onClose, onConnected }) {
|
|
246
|
+
const [isMobile, setIsMobile] = useState(false);
|
|
247
|
+
const [copied, setCopied] = useState(false);
|
|
248
|
+
const [bookmarkletHrefFinal, setBookmarkletHrefFinal] = useState(() => {
|
|
249
|
+
if (typeof window === 'undefined') return '#';
|
|
250
|
+
const origin = window.location.origin;
|
|
251
|
+
const jwt = getUserToken() || '';
|
|
252
|
+
const baseUrl = (window.onairosBaseUrl) || getApiBaseUrl();
|
|
253
|
+
return PERPLEXITY_BOOKMARKLET_HREF
|
|
254
|
+
.replace(/__ONAIROS_ORIGIN__/g, origin)
|
|
255
|
+
.replace(/__ONAIROS_URL__/g, window.location.href)
|
|
256
|
+
.replace(/__API_URL__/g, baseUrl)
|
|
257
|
+
.replace(/__ONAIROS_TOKEN__/g, jwt);
|
|
258
|
+
});
|
|
259
|
+
const [mobileCodeFinal, setMobileCodeFinal] = useState('#');
|
|
260
|
+
const bookmarkletRef = useRef(null);
|
|
261
|
+
const syncTimeoutRef = useRef(null);
|
|
262
|
+
|
|
263
|
+
useEffect(() => {
|
|
264
|
+
setIsMobile(window.innerWidth <= 768);
|
|
265
|
+
const handleResize = () => setIsMobile(window.innerWidth <= 768);
|
|
266
|
+
window.addEventListener('resize', handleResize);
|
|
267
|
+
return () => window.removeEventListener('resize', handleResize);
|
|
268
|
+
}, []);
|
|
269
|
+
|
|
270
|
+
useEffect(() => {
|
|
271
|
+
if (!open) return () => {};
|
|
272
|
+
window.__onairosPerplexityModalOpen = true;
|
|
273
|
+
const origin = window.location.origin;
|
|
274
|
+
const jwt = getUserToken() || '';
|
|
275
|
+
const baseUrl = (typeof window !== 'undefined' && window.onairosBaseUrl) || getApiBaseUrl();
|
|
276
|
+
const href = PERPLEXITY_BOOKMARKLET_HREF
|
|
277
|
+
.replace(/__ONAIROS_ORIGIN__/g, origin)
|
|
278
|
+
.replace(/__ONAIROS_URL__/g, window.location.href)
|
|
279
|
+
.replace(/__API_URL__/g, baseUrl)
|
|
280
|
+
.replace(/__ONAIROS_TOKEN__/g, jwt);
|
|
281
|
+
setBookmarkletHrefFinal(href);
|
|
282
|
+
setMobileCodeFinal(href);
|
|
283
|
+
if (bookmarkletRef.current && href) {
|
|
284
|
+
bookmarkletRef.current.href = href;
|
|
285
|
+
bookmarkletRef.current.title = 'Export Perplexity';
|
|
286
|
+
}
|
|
287
|
+
return () => {
|
|
288
|
+
window.__onairosPerplexityModalOpen = false;
|
|
289
|
+
};
|
|
290
|
+
}, [open]);
|
|
291
|
+
|
|
292
|
+
useEffect(() => {
|
|
293
|
+
if (!open) return () => {};
|
|
294
|
+
const baseUrl = (typeof window !== 'undefined' && window.onairosBaseUrl) || getApiBaseUrl();
|
|
295
|
+
const apiKey = getApiKey();
|
|
296
|
+
|
|
297
|
+
const isPerplexityConnectedFromAccountStatus = (data) => {
|
|
298
|
+
try {
|
|
299
|
+
const acct = data?.AccountInfo?.accounts?.perplexity || data?.AccountInfo?.accounts?.Perplexity;
|
|
300
|
+
if (acct?.connected === true) return true;
|
|
301
|
+
const connectedPlatforms = data?.accountStatus?.connectedPlatforms;
|
|
302
|
+
if (Array.isArray(connectedPlatforms)) {
|
|
303
|
+
return connectedPlatforms.some((p) => String(p).toLowerCase().includes('perplexity'));
|
|
304
|
+
}
|
|
305
|
+
const connections = data?.AccountInfo?.connections;
|
|
306
|
+
if (Array.isArray(connections)) {
|
|
307
|
+
return connections.some((p) => String(p).toLowerCase().includes('perplexity'));
|
|
308
|
+
}
|
|
309
|
+
if (connections && typeof connections === 'object') {
|
|
310
|
+
return connections.Perplexity || connections.perplexity || false;
|
|
311
|
+
}
|
|
312
|
+
} catch (_) {
|
|
313
|
+
// Keep polling.
|
|
314
|
+
}
|
|
315
|
+
return false;
|
|
316
|
+
};
|
|
317
|
+
|
|
318
|
+
const markConnectedLocallyFromSync = () => {
|
|
319
|
+
if (syncTimeoutRef.current) {
|
|
320
|
+
window.clearTimeout(syncTimeoutRef.current);
|
|
321
|
+
syncTimeoutRef.current = null;
|
|
322
|
+
}
|
|
323
|
+
markPerplexityConnectedLocally();
|
|
324
|
+
try {
|
|
325
|
+
localStorage.removeItem(SYNC_SUCCESS_KEY);
|
|
326
|
+
} catch (_) {}
|
|
327
|
+
|
|
328
|
+
if (typeof onConnected === 'function') onConnected();
|
|
329
|
+
};
|
|
330
|
+
|
|
331
|
+
const uploadExportData = async (convos) => {
|
|
332
|
+
try {
|
|
333
|
+
const stored = await uploadPerplexityExportData(convos);
|
|
334
|
+
if (stored) {
|
|
335
|
+
markConnectedLocallyFromSync();
|
|
336
|
+
}
|
|
337
|
+
} catch (error) {
|
|
338
|
+
console.warn('[Perplexity] Upload failed before backend storage', error);
|
|
339
|
+
}
|
|
340
|
+
};
|
|
341
|
+
|
|
342
|
+
const processPendingImport = (raw) => {
|
|
343
|
+
try {
|
|
344
|
+
const { convos } = JSON.parse(raw);
|
|
345
|
+
uploadExportData(convos);
|
|
346
|
+
} catch (_) {}
|
|
347
|
+
};
|
|
348
|
+
|
|
349
|
+
const pendingRaw = localStorage.getItem(PENDING_IMPORT_KEY);
|
|
350
|
+
if (pendingRaw) {
|
|
351
|
+
localStorage.removeItem(PENDING_IMPORT_KEY);
|
|
352
|
+
processPendingImport(pendingRaw);
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
const pollInterval = setInterval(() => {
|
|
356
|
+
const raw = localStorage.getItem(PENDING_IMPORT_KEY);
|
|
357
|
+
if (raw) {
|
|
358
|
+
localStorage.removeItem(PENDING_IMPORT_KEY);
|
|
359
|
+
processPendingImport(raw);
|
|
360
|
+
}
|
|
361
|
+
}, 1000);
|
|
362
|
+
|
|
363
|
+
const connectionCheck = setInterval(() => {
|
|
364
|
+
try {
|
|
365
|
+
const storedConnections = JSON.parse(localStorage.getItem('onairos_connected_accounts') || '{}');
|
|
366
|
+
const perplexitySyncSuccess = localStorage.getItem(SYNC_SUCCESS_KEY);
|
|
367
|
+
if (storedConnections.perplexity || storedConnections.Perplexity || perplexitySyncSuccess === 'true') {
|
|
368
|
+
markConnectedLocallyFromSync();
|
|
369
|
+
clearInterval(connectionCheck);
|
|
370
|
+
clearInterval(backendPoll);
|
|
371
|
+
}
|
|
372
|
+
} catch (_) {}
|
|
373
|
+
}, 1000);
|
|
374
|
+
|
|
375
|
+
let backendPollInFlight = false;
|
|
376
|
+
const backendPoll = setInterval(async () => {
|
|
377
|
+
if (!open || backendPollInFlight) return;
|
|
378
|
+
const identifier = getPerplexityIdentifierForAccountCheck();
|
|
379
|
+
if (!identifier) return;
|
|
380
|
+
|
|
381
|
+
backendPollInFlight = true;
|
|
382
|
+
try {
|
|
383
|
+
const resp = await fetch(`${baseUrl}/getAccountInfo/email`, {
|
|
384
|
+
method: 'POST',
|
|
385
|
+
headers: {
|
|
386
|
+
'Content-Type': 'application/json',
|
|
387
|
+
...(apiKey ? { 'x-api-key': apiKey } : {}),
|
|
388
|
+
},
|
|
389
|
+
body: JSON.stringify({ Info: { identifier: String(identifier).trim().toLowerCase() } }),
|
|
390
|
+
});
|
|
391
|
+
if (resp.ok && isPerplexityConnectedFromAccountStatus(await resp.json())) {
|
|
392
|
+
clearInterval(connectionCheck);
|
|
393
|
+
clearInterval(backendPoll);
|
|
394
|
+
markConnectedLocallyFromSync();
|
|
395
|
+
}
|
|
396
|
+
} catch (_) {
|
|
397
|
+
// Keep polling.
|
|
398
|
+
} finally {
|
|
399
|
+
backendPollInFlight = false;
|
|
400
|
+
}
|
|
401
|
+
}, 2000);
|
|
402
|
+
|
|
403
|
+
const handleMessage = (event) => {
|
|
404
|
+
if (event.data?.type === 'perplexity-export-data') {
|
|
405
|
+
const { convos } = event.data;
|
|
406
|
+
localStorage.removeItem(PENDING_IMPORT_KEY);
|
|
407
|
+
if (event.source) {
|
|
408
|
+
try { event.source.postMessage({ type: 'perplexity-export-ack' }, event.origin); } catch (_) {}
|
|
409
|
+
}
|
|
410
|
+
uploadPerplexityExportData(convos, event.data.exportId).then((stored) => {
|
|
411
|
+
const statusMessage = {
|
|
412
|
+
platform: 'Perplexity',
|
|
413
|
+
count: Array.isArray(convos) ? convos.length : 0,
|
|
414
|
+
message: stored ? '' : 'Could not store Perplexity data. Check the Onairos app tab.',
|
|
415
|
+
};
|
|
416
|
+
notifyLlmSyncPopup(event.data.popupId, stored ? 'success' : 'error', statusMessage);
|
|
417
|
+
try {
|
|
418
|
+
event.source?.postMessage({
|
|
419
|
+
type: 'onairos-llm-sync-status',
|
|
420
|
+
popupId: event.data.popupId,
|
|
421
|
+
status: stored ? 'success' : 'error',
|
|
422
|
+
...statusMessage,
|
|
423
|
+
}, event.origin);
|
|
424
|
+
} catch (_) {}
|
|
425
|
+
if (stored) markConnectedLocallyFromSync();
|
|
426
|
+
});
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
if (event.data?.type === 'llm-import-success' && String(event.data.platform || '').includes('perplexity')) {
|
|
430
|
+
markConnectedLocallyFromSync();
|
|
431
|
+
clearInterval(connectionCheck);
|
|
432
|
+
clearInterval(backendPoll);
|
|
433
|
+
}
|
|
434
|
+
};
|
|
435
|
+
window.addEventListener('message', handleMessage);
|
|
436
|
+
|
|
437
|
+
return () => {
|
|
438
|
+
window.removeEventListener('message', handleMessage);
|
|
439
|
+
clearInterval(pollInterval);
|
|
440
|
+
clearInterval(connectionCheck);
|
|
441
|
+
clearInterval(backendPoll);
|
|
442
|
+
if (syncTimeoutRef.current) {
|
|
443
|
+
window.clearTimeout(syncTimeoutRef.current);
|
|
444
|
+
syncTimeoutRef.current = null;
|
|
445
|
+
}
|
|
446
|
+
};
|
|
447
|
+
}, [open, onConnected]);
|
|
448
|
+
|
|
449
|
+
const handleCopyCode = () => {
|
|
450
|
+
navigator.clipboard.writeText(mobileCodeFinal);
|
|
451
|
+
setCopied(true);
|
|
452
|
+
setTimeout(() => setCopied(false), 2000);
|
|
453
|
+
};
|
|
454
|
+
|
|
455
|
+
const handleGotIt = () => {
|
|
456
|
+
if (typeof onClose === 'function') onClose();
|
|
457
|
+
};
|
|
458
|
+
|
|
459
|
+
if (!open) return null;
|
|
460
|
+
|
|
461
|
+
return ReactDOM.createPortal(
|
|
462
|
+
<div style={{ position: 'fixed', inset: 0, zIndex: 2147483647, pointerEvents: 'auto' }}>
|
|
463
|
+
<style>{`
|
|
464
|
+
@keyframes gentlePulse {
|
|
465
|
+
0%, 100% { box-shadow: 0 0 0 0 rgba(32, 128, 141, 0.35); }
|
|
466
|
+
50% { box-shadow: 0 0 0 10px rgba(32, 128, 141, 0); }
|
|
467
|
+
}
|
|
468
|
+
.bookmarklet-button {
|
|
469
|
+
background: linear-gradient(135deg, rgba(32, 128, 141, 0.95), rgba(15, 91, 102, 0.92));
|
|
470
|
+
border-radius: 9999px;
|
|
471
|
+
border: 1px solid rgba(173, 232, 240, 0.32);
|
|
472
|
+
backdrop-filter: blur(18px);
|
|
473
|
+
box-shadow: 0 14px 32px rgba(15, 91, 102, 0.28);
|
|
474
|
+
}
|
|
475
|
+
.bookmarklet-button:hover { background: linear-gradient(135deg, rgba(45, 156, 170, 0.98), rgba(20, 116, 130, 0.95)); }
|
|
476
|
+
@keyframes fadeInScale {
|
|
477
|
+
0% { opacity: 0; transform: translateY(8px) scale(0.96); }
|
|
478
|
+
100% { opacity: 1; transform: translateY(0) scale(1); }
|
|
479
|
+
}
|
|
480
|
+
.perplexity-modal-card { animation: fadeInScale 200ms cubic-bezier(0.16, 1, 0.3, 1); }
|
|
481
|
+
.step-circle {
|
|
482
|
+
background: linear-gradient(135deg, #20808D, #0f5b66);
|
|
483
|
+
box-shadow: 0 8px 18px rgba(15, 91, 102, 0.28);
|
|
484
|
+
min-width: 28px;
|
|
485
|
+
width: 28px;
|
|
486
|
+
height: 28px;
|
|
487
|
+
}
|
|
488
|
+
.perplexity-got-it-button {
|
|
489
|
+
color: #FFFFFF !important;
|
|
490
|
+
background-color: rgba(15, 23, 42, 0.8) !important;
|
|
491
|
+
}
|
|
492
|
+
.perplexity-got-it-button:hover { background-color: rgba(15, 23, 42, 0.9) !important; }
|
|
493
|
+
.perplexity-got-it-button * { color: #FFFFFF !important; }
|
|
494
|
+
@media (max-width: 768px) {
|
|
495
|
+
.perplexity-modal-backdrop { align-items: flex-end !important; padding: 0 !important; }
|
|
496
|
+
.perplexity-modal-card {
|
|
497
|
+
max-width: 100% !important;
|
|
498
|
+
height: 90vh !important;
|
|
499
|
+
max-height: 90vh !important;
|
|
500
|
+
border-radius: 24px 24px 0 0 !important;
|
|
501
|
+
animation: slideUpFromBottom 300ms cubic-bezier(0.16, 1, 0.3, 1) !important;
|
|
502
|
+
display: flex;
|
|
503
|
+
flex-direction: column;
|
|
504
|
+
}
|
|
505
|
+
.perplexity-modal-content { overflow-y: auto; flex: 1; }
|
|
506
|
+
}
|
|
507
|
+
@keyframes slideUpFromBottom {
|
|
508
|
+
0% { transform: translateY(100%); }
|
|
509
|
+
100% { transform: translateY(0); }
|
|
510
|
+
}
|
|
511
|
+
`}</style>
|
|
512
|
+
|
|
513
|
+
<div className="perplexity-modal-backdrop fixed inset-0 flex items-center justify-center p-4 bg-black/60" style={{ zIndex: 2147483647 }}>
|
|
514
|
+
<div
|
|
515
|
+
className="perplexity-modal-card w-full max-w-md rounded-3xl shadow-2xl border border-white/10 overflow-hidden text-white relative"
|
|
516
|
+
style={{
|
|
517
|
+
background:
|
|
518
|
+
'radial-gradient(circle at top left, rgba(32, 128, 141, 0.22), transparent 34%), linear-gradient(135deg, rgba(15, 23, 42, 0.98) 0%, rgba(17, 35, 41, 0.95) 48%, rgba(15, 23, 42, 0.98) 100%)',
|
|
519
|
+
boxShadow:
|
|
520
|
+
'inset 0 1px 0 0 rgba(173, 232, 240, 0.16), 0 20px 60px rgba(0, 0, 0, 0.55), 0 0 100px rgba(32, 128, 141, 0.16)',
|
|
521
|
+
}}
|
|
522
|
+
>
|
|
523
|
+
<div className="relative px-5 py-4 border-b border-white/10 bg-white/5 flex-shrink-0">
|
|
524
|
+
<button
|
|
525
|
+
onClick={onClose}
|
|
526
|
+
aria-label="Close"
|
|
527
|
+
type="button"
|
|
528
|
+
className="onairos-close-btn absolute right-3 top-3 inline-flex items-center justify-center rounded-full transition-all hover:scale-105 z-50 cursor-pointer"
|
|
529
|
+
style={{
|
|
530
|
+
width: 28,
|
|
531
|
+
height: 28,
|
|
532
|
+
padding: 0,
|
|
533
|
+
background: 'rgba(255, 255, 255, 0.08)',
|
|
534
|
+
border: '1px solid rgba(255, 255, 255, 0.18)',
|
|
535
|
+
backdropFilter: 'blur(8px)',
|
|
536
|
+
WebkitBackdropFilter: 'blur(8px)',
|
|
537
|
+
color: '#ffffff',
|
|
538
|
+
}}
|
|
539
|
+
onMouseEnter={(e) => { e.currentTarget.style.background = 'rgba(255,255,255,0.16)'; }}
|
|
540
|
+
onMouseLeave={(e) => { e.currentTarget.style.background = 'rgba(255,255,255,0.08)'; }}
|
|
541
|
+
>
|
|
542
|
+
<svg width="12" height="12" viewBox="0 0 12 12" fill="none" aria-hidden>
|
|
543
|
+
<path d="M3 3l6 6M9 3l-6 6" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" />
|
|
544
|
+
</svg>
|
|
545
|
+
</button>
|
|
546
|
+
|
|
547
|
+
<h2 className="text-xl font-semibold pr-8 text-white">{isMobile ? 'Export Perplexity' : 'Connect Perplexity'}</h2>
|
|
548
|
+
<p className="text-sm mt-0.5 text-white">Import your recent chats.</p>
|
|
549
|
+
</div>
|
|
550
|
+
|
|
551
|
+
<div className="px-5 py-4 space-y-4 perplexity-modal-content">
|
|
552
|
+
{isMobile ? (
|
|
553
|
+
<>
|
|
554
|
+
<div className="flex gap-3">
|
|
555
|
+
<div className="flex-shrink-0">
|
|
556
|
+
<div className="step-circle rounded-full flex items-center justify-center">
|
|
557
|
+
<span className="text-white font-bold text-sm">1</span>
|
|
558
|
+
</div>
|
|
559
|
+
</div>
|
|
560
|
+
<div className="flex-1 pt-0.5">
|
|
561
|
+
<h3 className="text-sm font-semibold mb-1 text-white">Copy the bookmark code</h3>
|
|
562
|
+
<button
|
|
563
|
+
onClick={handleCopyCode}
|
|
564
|
+
className="mt-1 w-full flex items-center justify-center gap-2 py-3 bg-white/10 rounded-xl text-sm font-medium hover:bg-white/20 active:scale-95 transition-all text-teal-200 border border-teal-500/30"
|
|
565
|
+
>
|
|
566
|
+
{copied ? 'Copied' : 'Copy code'}
|
|
567
|
+
</button>
|
|
568
|
+
</div>
|
|
569
|
+
</div>
|
|
570
|
+
|
|
571
|
+
<div className="flex gap-3">
|
|
572
|
+
<div className="flex-shrink-0">
|
|
573
|
+
<div className="step-circle rounded-full flex items-center justify-center">
|
|
574
|
+
<span className="text-white font-bold text-sm">2</span>
|
|
575
|
+
</div>
|
|
576
|
+
</div>
|
|
577
|
+
<div className="flex-1 pt-0.5">
|
|
578
|
+
<h3 className="text-sm font-semibold mb-1 text-white">Add a bookmark</h3>
|
|
579
|
+
<p className="text-xs text-slate-200 leading-relaxed mb-2">
|
|
580
|
+
Add a bookmark, then paste the code into the bookmark URL.
|
|
581
|
+
</p>
|
|
582
|
+
</div>
|
|
583
|
+
</div>
|
|
584
|
+
|
|
585
|
+
<div className="flex gap-3">
|
|
586
|
+
<div className="flex-shrink-0">
|
|
587
|
+
<div className="step-circle rounded-full flex items-center justify-center">
|
|
588
|
+
<span className="text-white font-bold text-sm">3</span>
|
|
589
|
+
</div>
|
|
590
|
+
</div>
|
|
591
|
+
<div className="flex-1 pt-0.5">
|
|
592
|
+
<h3 className="text-sm font-semibold mb-1 text-white">Run it on Perplexity</h3>
|
|
593
|
+
<button
|
|
594
|
+
type="button"
|
|
595
|
+
onClick={() => window.open('https://www.perplexity.ai', '_blank')}
|
|
596
|
+
className="mt-2 text-xs text-white px-3 py-1.5 rounded-lg inline-flex items-center gap-1"
|
|
597
|
+
style={{ background: 'linear-gradient(135deg, #20808D 0%, #0f5b66 100%)' }}
|
|
598
|
+
>
|
|
599
|
+
Open Perplexity
|
|
600
|
+
</button>
|
|
601
|
+
<p className="text-xs text-slate-300 mt-2">In the address bar, search your bookmark name and tap it.</p>
|
|
602
|
+
</div>
|
|
603
|
+
</div>
|
|
604
|
+
</>
|
|
605
|
+
) : (
|
|
606
|
+
<>
|
|
607
|
+
<div className="flex gap-3">
|
|
608
|
+
<div className="flex-shrink-0">
|
|
609
|
+
<div className="step-circle rounded-full flex items-center justify-center">
|
|
610
|
+
<span className="text-white font-bold text-sm">1</span>
|
|
611
|
+
</div>
|
|
612
|
+
</div>
|
|
613
|
+
<div className="flex-1 pt-0.5">
|
|
614
|
+
<h3 className="text-sm font-semibold mb-1 text-white">Drag this button to your bookmarks bar</h3>
|
|
615
|
+
<div className="relative inline-block mt-2">
|
|
616
|
+
<div className="absolute inset-0 rounded-full" style={{ animation: 'gentlePulse 2s ease-in-out infinite' }} />
|
|
617
|
+
<a
|
|
618
|
+
ref={bookmarkletRef}
|
|
619
|
+
href={bookmarkletHrefFinal || '#'}
|
|
620
|
+
title="Export Perplexity"
|
|
621
|
+
aria-label="Export Perplexity"
|
|
622
|
+
draggable="true"
|
|
623
|
+
onDragStart={(e) => {
|
|
624
|
+
try {
|
|
625
|
+
const bookmarkTitle = 'Export Perplexity';
|
|
626
|
+
const href = bookmarkletRef.current?.href || bookmarkletHrefFinal || '#';
|
|
627
|
+
if (bookmarkletRef.current && href) bookmarkletRef.current.href = href;
|
|
628
|
+
if (bookmarkletRef.current) bookmarkletRef.current.title = bookmarkTitle;
|
|
629
|
+
|
|
630
|
+
const ua = navigator?.userAgent || '';
|
|
631
|
+
const isChromium =
|
|
632
|
+
/\bChrome\/|\bChromium\//.test(ua) && !/\bEdg\/|\bOPR\//.test(ua);
|
|
633
|
+
if (isChromium) return;
|
|
634
|
+
|
|
635
|
+
const html = `<a href="${href}">${bookmarkTitle}</a>`;
|
|
636
|
+
e.dataTransfer.setData('text/uri-list', href);
|
|
637
|
+
e.dataTransfer.setData('text/plain', href);
|
|
638
|
+
e.dataTransfer.setData('text/html', html);
|
|
639
|
+
e.dataTransfer.setData('text/x-moz-url', `${href}\n${bookmarkTitle}`);
|
|
640
|
+
e.dataTransfer.effectAllowed = 'copy';
|
|
641
|
+
} catch (err) {
|
|
642
|
+
console.warn('Drag start error:', err);
|
|
643
|
+
}
|
|
644
|
+
}}
|
|
645
|
+
onClick={(e) => {
|
|
646
|
+
e.preventDefault();
|
|
647
|
+
alert('Drag this button to your bookmarks bar.');
|
|
648
|
+
}}
|
|
649
|
+
className="bookmarklet-button relative inline-flex items-center gap-1.5 px-4 py-2 font-medium cursor-move select-none transition-all hover:scale-[1.03]"
|
|
650
|
+
suppressHydrationWarning
|
|
651
|
+
>
|
|
652
|
+
<span className="text-base">✨</span>
|
|
653
|
+
<span className="text-sm">Export Perplexity</span>
|
|
654
|
+
</a>
|
|
655
|
+
</div>
|
|
656
|
+
</div>
|
|
657
|
+
</div>
|
|
658
|
+
|
|
659
|
+
<div className="flex gap-3">
|
|
660
|
+
<div className="flex-shrink-0">
|
|
661
|
+
<div className="step-circle rounded-full flex items-center justify-center">
|
|
662
|
+
<span className="text-white font-bold text-sm">2</span>
|
|
663
|
+
</div>
|
|
664
|
+
</div>
|
|
665
|
+
<div className="flex-1 pt-0.5">
|
|
666
|
+
<h3 className="text-sm font-semibold mb-1 text-white">Open Perplexity</h3>
|
|
667
|
+
<button
|
|
668
|
+
type="button"
|
|
669
|
+
onClick={() => window.open('https://www.perplexity.ai', '_blank')}
|
|
670
|
+
className="inline-flex items-center gap-1.5 px-4 py-2 rounded-full text-xs font-medium transition-all hover:scale-[1.02] active:scale-[0.98]"
|
|
671
|
+
style={{
|
|
672
|
+
background: 'linear-gradient(135deg, #20808D 0%, #0f5b66 100%)',
|
|
673
|
+
color: '#ffffff',
|
|
674
|
+
boxShadow: '0 0 25px rgba(32, 128, 141, 0.28), inset 0 1px 0 rgba(173, 232, 240, 0.35)',
|
|
675
|
+
}}
|
|
676
|
+
>
|
|
677
|
+
<svg
|
|
678
|
+
className="w-3.5 h-3.5"
|
|
679
|
+
fill="none"
|
|
680
|
+
stroke="currentColor"
|
|
681
|
+
viewBox="0 0 24 24"
|
|
682
|
+
>
|
|
683
|
+
<path
|
|
684
|
+
strokeLinecap="round"
|
|
685
|
+
strokeLinejoin="round"
|
|
686
|
+
strokeWidth={2}
|
|
687
|
+
d="M10 6H6a2 2 0 00-2 2v10a2 2 0 002 2h10a2 2 0 002-2v-4M14 4h6m0 0v6m0-6L10 14"
|
|
688
|
+
/>
|
|
689
|
+
</svg>
|
|
690
|
+
Open Perplexity
|
|
691
|
+
</button>
|
|
692
|
+
</div>
|
|
693
|
+
</div>
|
|
694
|
+
|
|
695
|
+
<div className="flex gap-3">
|
|
696
|
+
<div className="flex-shrink-0">
|
|
697
|
+
<div className="step-circle rounded-full flex items-center justify-center">
|
|
698
|
+
<span className="text-white font-bold text-sm">3</span>
|
|
699
|
+
</div>
|
|
700
|
+
</div>
|
|
701
|
+
<div className="flex-1 pt-0.5">
|
|
702
|
+
<h3 className="text-sm font-semibold mb-1 text-white">Click the bookmark</h3>
|
|
703
|
+
<p className="text-xs text-slate-200">
|
|
704
|
+
Click <strong className="text-white">"Export Perplexity"</strong> in your bookmarks bar.
|
|
705
|
+
</p>
|
|
706
|
+
</div>
|
|
707
|
+
</div>
|
|
708
|
+
</>
|
|
709
|
+
)}
|
|
710
|
+
</div>
|
|
711
|
+
|
|
712
|
+
<div className="px-5 py-4 bg-white/5 border-t border-white/10 flex-shrink-0">
|
|
713
|
+
<button
|
|
714
|
+
type="button"
|
|
715
|
+
onClick={handleGotIt}
|
|
716
|
+
className="w-full px-4 py-2.5 rounded-full font-medium text-sm transition-all hover:scale-[1.01] active:scale-[0.99] shadow-[0_10px_30px_rgba(15,23,42,0.45)] border border-white/40 perplexity-got-it-button"
|
|
717
|
+
>
|
|
718
|
+
<span>{isMobile ? 'Close' : 'Got it!'}</span>
|
|
719
|
+
</button>
|
|
720
|
+
</div>
|
|
721
|
+
</div>
|
|
722
|
+
</div>
|
|
723
|
+
</div>,
|
|
724
|
+
document.body
|
|
725
|
+
);
|
|
726
|
+
}
|