UNPKG

@xenara/xena-sdk

Version:

A powerful SDK to embed AI agents into any web platform. Enable conversational experiences, automate workflows, and provide intelligent assistance through a customizable chat interface.

2 lines (1 loc) 1.68 kB
!function(){"use strict";window.Xena={init:async function({containerId:e="xena-root",apiKey:t,user_id:n,name:a,email:i,created_at:o}){const r=document.getElementById(e);if(!r)return void console.error(`[XENA] Container "${e}" not found.`);const d=r.shadowRoot||r.attachShadow({mode:"open"}),c=await async function(e){try{const t=await fetch(`https://backend.xenara.ai/api/widget/settings?apiKey=${e}`,{headers:{"Content-Type":"application/json"}});return t.ok?(await t.json()).settings:(console.error("[XENA] Invalid API Key or unauthorized domain"),null)}catch(e){return console.error("[XENA] Failed to fetch widget settings:",e),null}}(t);if(!c)return void console.error("[XENA] Failed to load settings. Check API Key and domain.");const s=await(c?.workspace_id);try{const e=await fetch("https://widget.xenara.ai/widget.html"),t=await e.text();d.innerHTML=t;const r=document.createElement("link");r.rel="stylesheet",r.href="https://widget.xenara.ai/widget.css",d.appendChild(r),requestAnimationFrame((()=>{Array.from(d.querySelectorAll("script")).forEach((e=>{const t=document.createElement("script");Array.from(e.attributes).forEach((e=>t.setAttribute(e.name,e.value))),t.textContent=e.textContent,d.appendChild(t)}));const e=document.createElement("script");e.src="https://widget.xenara.ai/widget-runtime.js",e.onload=()=>{window.XenaRuntime?.init?window.XenaRuntime.init(d,{user_id:n,name:a,email:i,created_at:o,workspace_id:s}):console.error("[XENA] Failed to initialize runtime.")},document.head.appendChild(e)}))}catch(e){console.error("[XENA] Failed to load widget assets:",e),d.innerHTML='<div style="color: red;">[XENA] Error loading widget content.</div>'}}}}();