@eka-care/medassist-widget-embed 0.2.52 → 0.2.54
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/dist/eka-agents.html +11 -4
- package/dist/iframe-helper.js +2 -2
- package/dist/iframe.html +3 -1
- package/dist/iframe.js +1 -1
- package/package.json +1 -1
package/dist/eka-agents.html
CHANGED
|
@@ -10,10 +10,12 @@
|
|
|
10
10
|
<link rel="preconnect" href="https://cdn.jsdelivr.net" crossorigin />
|
|
11
11
|
<link rel="preconnect" href="https://matrix.eka.care" crossorigin />
|
|
12
12
|
|
|
13
|
-
<!-- Start widget JS download immediately during head parse (high priority).
|
|
13
|
+
<!-- Start widget JS download immediately during head parse (high priority).
|
|
14
|
+
modulepreload (not preload as=script): the widget entry is an ES module,
|
|
15
|
+
and classic preload's no-CORS fetch mode mismatches the module loader's
|
|
16
|
+
CORS mode — the browser would download it twice. -->
|
|
14
17
|
<link
|
|
15
|
-
rel="
|
|
16
|
-
as="script"
|
|
18
|
+
rel="modulepreload"
|
|
17
19
|
href="https://cdn.jsdelivr.net/npm/@eka-care/medassist-widget@0.1.82/dist/medassist-widget.js"
|
|
18
20
|
fetchpriority="high"
|
|
19
21
|
crossorigin
|
|
@@ -60,8 +62,13 @@
|
|
|
60
62
|
<body>
|
|
61
63
|
<div id="root"><div class="loader" aria-hidden="true"></div></div>
|
|
62
64
|
|
|
63
|
-
<!-- Production: served from jsDelivr (brotli + multi-CDN). For local dev swap with: <script src="./src/medassist-widget.js" onload="init()" async></script> -->
|
|
65
|
+
<!-- Production: served from jsDelivr (brotli + multi-CDN). For local dev swap with: <script type="module" src="./src/medassist-widget.js" onload="init()" async></script> -->
|
|
66
|
+
<!-- type="module" is required: the widget entry is an ES module (static
|
|
67
|
+
import/export of the main chunk) — a classic script would throw
|
|
68
|
+
"Cannot use import statement outside a module" and
|
|
69
|
+
window.renderMedAssist would never be set. -->
|
|
64
70
|
<script
|
|
71
|
+
type="module"
|
|
65
72
|
src="https://cdn.jsdelivr.net/npm/@eka-care/medassist-widget@0.1.82/dist/medassist-widget.js"
|
|
66
73
|
onload="init()"
|
|
67
74
|
fetchpriority="high"
|
package/dist/iframe-helper.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const h="https://
|
|
1
|
+
const h="https://unpkg.com/@eka-care/medassist-widget-embed@latest/dist/",w=()=>{if(typeof document=="undefined")return null;const{currentScript:e}=document;if(e instanceof HTMLScriptElement)return e;const t=document.getElementsByTagName("script");return t.length?t[t.length-1]:null},p=e=>e||h;export const openMedAssistIframe=e=>{const{agentId:t,title:i,iconUrl:a,environment:o,iframeBaseUrl:f,context:m}=e;if(!t){console.error("Agent ID is required");return}const c=document.getElementById("medassist-iframe");c&&c.remove();const u=p(f),n=new URL(`${u}iframe.html`);n.searchParams.set("agentId",t),i&&n.searchParams.set("title",i),a&&n.searchParams.set("iconUrl",a),o&&n.searchParams.set("environment",o),m&&n.searchParams.set("context",JSON.stringify(m));const s=document.createElement("iframe");s.id="medassist-iframe",s.src=n.toString(),s.setAttribute("allow","microphone; camera"),s.style.cssText=`
|
|
2
2
|
width: 100vw;
|
|
3
3
|
height: 100vh;
|
|
4
4
|
height: 100dvh;
|
|
@@ -9,4 +9,4 @@ const h="https://cdn.jsdelivr.net/npm/@eka-care/medassist-widget-embed@latest/di
|
|
|
9
9
|
left: 0;
|
|
10
10
|
z-index: 9999;
|
|
11
11
|
background: white;
|
|
12
|
-
`,document.body.appendChild(s);const
|
|
12
|
+
`,document.body.appendChild(s);const d=g=>{var r;if(((r=g.data)===null||r===void 0?void 0:r.type)==="WIDGET_CLOSE"){const l=document.getElementById("medassist-iframe");l&&l.remove(),window.removeEventListener("message",d)}};window.addEventListener("message",d)};typeof window!="undefined"&&(window.openMedAssistIframe=openMedAssistIframe);
|
package/dist/iframe.html
CHANGED
|
@@ -5,9 +5,11 @@
|
|
|
5
5
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
6
6
|
<title>MedAssist Widget</title>
|
|
7
7
|
|
|
8
|
-
<!--
|
|
8
|
+
<!-- Resource hints for faster loading (iframe.js adds modulepreload/preload
|
|
9
|
+
for the widget JS/CSS dynamically once it resolves the asset base URL) -->
|
|
9
10
|
<link rel="preconnect" href="https://cdn.jsdelivr.net" crossorigin/>
|
|
10
11
|
<link rel="dns-prefetch" href="https://cdn.jsdelivr.net"/>
|
|
12
|
+
<link rel="preconnect" href="https://matrix.eka.care" crossorigin/>
|
|
11
13
|
<style>
|
|
12
14
|
* {
|
|
13
15
|
margin: 0;
|
package/dist/iframe.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";(function(){const
|
|
1
|
+
"use strict";(function(){const F=()=>{if(typeof document=="undefined")return null;const{currentScript:e}=document;if(e instanceof HTMLScriptElement)return e;const t=document.getElementsByTagName("script");return t.length?t[t.length-1]:null},R=e=>{if(e==="production"||e==="development"||e==="staging")return e};function B(e){if(!e)return;const t=e.mode==="dark"?"white":e.mode==="light"?"black":void 0;return{...e.background&&{background:e.background},...e.background_img&&{backgroundImage:e.background_img},...e.accent&&{primary:e.accent},...t&&{textColor:t},...e.mode&&{mode:e.mode},...e.header_tinted!==void 0&&{headerTinted:e.header_tinted},...e.title_img&&{titleImg:e.title_img},...e.tagline&&{tagline:e.tagline}}}function _(e){if(!(!e||typeof document=="undefined"))try{const t=document.createElement("link");t.rel="preload",t.as="image",t.href=e,document.head.appendChild(t)}catch{const t=new Image;t.src=e}}async function D(e,t){const r=`${e.replace(/\/$/,"")}/med-assist/agent-config/${t}`,n=new AbortController,i=setTimeout(()=>n.abort(),1e4);try{const s=await fetch(r,{signal:n.signal,headers:{"ngrok-skip-browser-warning":"69420"}});if(!s.ok)return;const c=await s.json();return c!=null&&c.success&&(c!=null&&c.data)?c.data:void 0}catch{return}finally{clearTimeout(i)}}const C="https://cdn.jsdelivr.net/npm/@eka-care/medassist-widget@0.1.82/dist/",a=F(),S=(()=>{if(!a)return"";try{return new URL(".",a.src||window.location.href).href}catch{return""}})(),m=(()=>{if(!a)return C;const e=a.dataset.widgetAssets;if(e==="local")return`${S}src/`;if(e&&e.length>0)try{return new URL(e,S).href}catch{return e.endsWith("/")?e:`${e}/`}return C})(),l=`${m}medassist-widget.js`,g=`${m}medassist-widget.css`;let f=null,w=null;const d=new URLSearchParams(typeof window!="undefined"?window.location.search:""),b=d.get("agentId"),h=d.get("baseUrl")||"https://matrix.eka.care/reloaded";if(typeof document!="undefined"&&document.head){try{const e=new URL(m).origin,t=new URL(h).origin,r=document.createElement("link");if(r.rel="preconnect",r.href=e,r.crossOrigin="anonymous",document.head.appendChild(r),e!==t){const s=document.createElement("link");s.rel="preconnect",s.href=t,s.crossOrigin="anonymous",document.head.appendChild(s)}const n=document.createElement("link");n.rel="modulepreload",n.href=l,document.head.appendChild(n);const i=document.createElement("link");i.rel="preload",i.as="style",i.href=g,document.head.appendChild(i)}catch{}U(),L()}const A=b&&h?D(h,b):Promise.resolve(void 0);if(typeof document!="undefined"&&document.head){const e=d.get("theme");if(e)try{const t=JSON.parse(e);t.backgroundImage&&_(t.backgroundImage)}catch{}A.then(t=>{var r;const n=(r=t==null?void 0:t.theme)===null||r===void 0?void 0:r.background_img;n&&_(n)})}const I=async()=>{var e,t,r,n,i,s,c;const M=d.get("agentId");if(!M){console.error("Agent ID is required in URL parameters");return}let p=d.get("title")||"Medi Clinic",v=d.get("iconUrl")||void 0;const P=d.get("context"),z=d.get("baseUrl")||"https://matrix.eka.care/reloaded",T=d.get("auth-token")||void 0;let y=d.get("resize")==="true"?!0:void 0;const G=(e=R(d.get("environment")))!==null&&e!==void 0?e:"production",k=d.get("connectivity"),J=k==="sse"||k==="socket"?k:void 0,E=d.get("theme")?(()=>{try{return JSON.parse(d.get("theme")||"{}")}catch{return}})():void 0,N=document.getElementById("root")||document.body;try{const[,,o]=await Promise.all([U(),L(),A]);if(!(window!=null&&window.renderMedAssist)||typeof(window==null?void 0:window.renderMedAssist)!="function")throw new Error("renderMedAssist is not available on window");let u,O,x,$,W=!1;o&&(p=(t=o==null?void 0:o.name)!==null&&t!==void 0?t:p,v=(n=(r=o==null?void 0:o.theme)===null||r===void 0?void 0:r.icon_img)!==null&&n!==void 0?n:v,u=B((i=o==null?void 0:o.theme)!==null&&i!==void 0?i:void 0),O=o==null?void 0:o.allowed,x=o==null?void 0:o.connectivity,$=o==null?void 0:o.initial_message,W=(c=(s=o==null?void 0:o.theme)===null||s===void 0?void 0:s.hide_watermark)!==null&&c!==void 0?c:!1,y=y||(o==null?void 0:o.resize)||void 0);const q={title:p,iconUrl:v,environment:G,connectionType:x||J||"socket",onClose:()=>{window.parent!==window&&window.parent.postMessage({type:"WIDGET_CLOSE"},"*")},context:P?JSON.parse(P):void 0,baseUrl:z,displayMode:"full",allowed:O,showCloseButton:!1,resize:y,initialMessage:$,hideWatermark:W,...T&&{authToken:T},theme:{...u!=null?u:{},...E!=null?E:{}}};window.renderMedAssist(N,M,q)}catch(o){throw console.error("Failed to initialize MedAssist widget",o),o}};async function U(){document.querySelector("link[data-medassist-style='true']")||(w||(w=new Promise((t,r)=>{const n=document.createElement("link");n.rel="stylesheet",n.href=g,n.setAttribute("data-medassist-style","true"),n.onload=()=>{t("")},n.onerror=()=>{r(new Error(`Failed to load ${g}`))},document.head.appendChild(n)})),await w)}function L(){return f||(f=new Promise((e,t)=>{const r=document.querySelector(`script[src="${l}"]`);if(r){if(r.dataset.loaded==="true"){e();return}r.addEventListener("load",()=>e()),r.addEventListener("error",i=>t(i.error||new Error("Unknown script loading error")));return}const n=document.createElement("script");n.src=l,n.type="module",n.async=!0,n.dataset.widget="medassist",n.onload=()=>{n.dataset.loaded="true",e()},n.onerror=i=>{if(i instanceof ErrorEvent&&i.error){t(i.error);return}t(new Error(`Failed to load ${l}`))},document.head.appendChild(n)})),f}if(typeof document!="undefined")if(document.readyState==="loading")document.addEventListener("DOMContentLoaded",I);else try{I()}catch(e){console.error("Failed to initialize MedAssist widget",e)}})();
|