Open-source platform for 3D AI agents. Turn text or a photo into a rigged, animated GLB avatar, give it an LLM brain, memory and a wallet, and embed it anywhere with one web component. Remote MCP server, x402 payments, Three.js, browser-native.
JavaScript 3d-generationai-agentsanimationavatardigital-humangenerative-aiglbgltfimage-to-3dllmmcpmcp-servermodel-context-protocolsolanatext-to-3dthreejsweb-componentswebglwebxrx402
/* @three-ws/assistant, https://three.ws/assistant */
"use strict";(()=>{var h="three-assistant",u=["avatar","agent","bg","mode","accent","name","greeting","context","voice","badge","targetOrigin"];var y="#f97316";function b(n){return typeof n=="string"&&/^#(?:[0-9a-f]{3}|[0-9a-f]{6}|[0-9a-f]{8})$/i.test(n)}function x(n,e,t){let o=new URLSearchParams;for(let a of u){let s=n[a];s==null||s===""||o.set(a,String(s))}if(!o.has("targetOrigin")){let a=t??(typeof location<"u"?location.origin:"");a&&o.set("targetOrigin",a)}let i=o.toString();return`${e}/assistant-frame${i?`?${i}`:""}`}var w='<svg class="ta-icon-spark" viewBox="0 0 24 24" fill="currentColor" aria-hidden="true"><path d="M12 2l1.9 6.1L20 10l-6.1 1.9L12 18l-1.9-6.1L4 10l6.1-1.9L12 2z"/><path d="M19 15l.9 2.6 2.6.9-2.6.9L19 22l-.9-2.6-2.6-.9 2.6-.9L19 15z" opacity=".7"/></svg>',v='<svg class="ta-icon-close" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.4" stroke-linecap="round" aria-hidden="true"><path d="M18 6L6 18M6 6l12 12"/></svg>';function _(n){if(document.getElementById("three-assistant-style"))return;let e=`.three-assistant-launcher{position:fixed;bottom:20px;width:56px;height:56px;border-radius:50%;border:0;cursor:pointer;z-index:2147483000;background:${n};color:#fff;display:flex;align-items:center;justify-content:center;box-shadow:0 6px 24px rgba(0,0,0,.32),0 2px 6px rgba(0,0,0,.24);padding:0;transition:transform .18s ease,box-shadow .18s ease,filter .18s ease;}.three-assistant-launcher:hover{transform:translateY(-2px);filter:brightness(1.08);box-shadow:0 10px 30px rgba(0,0,0,.38),0 3px 8px rgba(0,0,0,.26);}.three-assistant-launcher:active{transform:scale(.94);}.three-assistant-launcher:focus-visible{outline:3px solid #fff;outline-offset:2px;}.three-assistant-launcher svg{width:24px;height:24px;transition:transform .22s ease,opacity .18s ease;position:absolute;}.three-assistant-launcher .ta-icon-close{opacity:0;transform:rotate(-45deg) scale(.6);}.three-assistant-launcher[data-open="true"] .ta-icon-spark{opacity:0;transform:rotate(45deg) scale(.6);}.three-assistant-launcher[data-open="true"] .ta-icon-close{opacity:1;transform:rotate(0) scale(1);}.three-assistant-panel{position:fixed;bottom:90px;width:380px;max-width:calc(100vw - 24px);height:640px;max-height:calc(100dvh - 110px);z-index:2147483000;border-radius:20px;overflow:hidden;opacity:0;visibility:hidden;transform:translateY(14px) scale(.98);pointer-events:none;transition:opacity .22s ease,transform .22s ease,visibility 0s linear .22s;transform-origin:bottom right;}.three-assistant-panel[data-pos="left"]{transform-origin:bottom left;}.three-assistant-panel[data-open="true"]{opacity:1;visibility:visible;transform:translateY(0) scale(1);pointer-events:auto;transition:opacity .22s ease,transform .22s ease,visibility 0s;}.three-assistant-panel[data-chrome="solid"]{background:#0a0a0c;border:1px solid rgba(255,255,255,.1);box-shadow:0 24px 64px rgba(0,0,0,.5);}.three-assistant-panel iframe{width:100%;height:100%;border:0;display:block;background:transparent;color-scheme:normal;}@media (max-width:480px){.three-assistant-panel{width:calc(100vw - 24px);height:calc(100dvh - 110px);}}@media (prefers-reduced-motion:reduce){.three-assistant-launcher,.three-assistant-panel,.three-assistant-launcher svg{transition:none;}}`,t=document.createElement("style");t.id="three-assistant-style",t.textContent=e,document.head.appendChild(t)}var d=class{constructor(e,t){this.config=e||{},this.origin=t.origin,this._onDestroy=t.onDestroy,this.isOpen=!1,this._queuedSays=[],this._ready=!1;let o=b(this.config.accent)?this.config.accent:y,i=this.config.position==="left"?"left":"right";_(o);let a=document.createElement("button");a.type="button",a.className="three-assistant-launcher",a.style[i]="20px",a.dataset.open="false",a.setAttribute("aria-label",`Open ${this.config.name||"assistant"}`),a.setAttribute("aria-expanded","false"),a.setAttribute("aria-haspopup","dialog"),a.innerHTML=w+v;let s=document.createElement("div");s.className="three-assistant-panel",s.style[i]="12px",s.dataset.open="false",s.dataset.pos=i;let p=String(this.config.bg==null?"":this.config.bg).toLowerCase();s.dataset.chrome=!p||p==="transparent"?"clear":"solid",s.setAttribute("role","dialog"),s.setAttribute("aria-label",this.config.name||"Assistant"),s.inert=!0;let r=document.createElement("iframe");r.title=`${this.config.name||"Assistant"} 3D avatar assistant`,r.allow="autoplay",r.setAttribute("allowtransparency","true"),r.loading="lazy",r.src=x(this.config,this.origin),s.appendChild(r),a.addEventListener("click",()=>this.toggle()),this._onMessage=l=>{if(l.origin!==this.origin||l.source!==r.contentWindow)return;let c=l.data;if(!(!c||typeof c!="object"||c.channel!==h)){if(c.type==="close"){this.close();return}if(c.type==="ready"){this._ready=!0;for(let m of this._queuedSays)this._post("say",m);this._queuedSays.length=0}this._emit(c.type,c.payload)}},window.addEventListener("message",this._onMessage),this._onKeydown=l=>{l.key==="Escape"&&this.isOpen&&this.close()},window.addEventListener("keydown",this._onKeydown),this.launcher=a,this.panel=s,this.iframe=r,document.body.appendChild(s),document.body.appendChild(a),this.config.open&&this.open()}_emit(e,t){try{window.dispatchEvent(new CustomEvent(h,{detail:{type:e,payload:t||{}}}))}catch{}}_post(e,t){try{this.iframe.contentWindow.postMessage({channel:h,v:1,type:e,payload:t||{}},this.origin)}catch{}}open(){if(this.isOpen)return;this.isOpen=!0,this.panel.inert=!1,this.panel.dataset.open="true",this.launcher.dataset.open="true",this.launcher.setAttribute("aria-expanded","true"),this.launcher.setAttribute("aria-label",`Close ${this.config.name||"assistant"}`);let e=this.iframe;setTimeout(()=>{try{e.focus()}catch{}},240),this._emit("open",{})}close(){if(this.isOpen){this.isOpen=!1,this.panel.inert=!0,this.panel.dataset.open="false",this.launcher.dataset.open="false",this.launcher.setAttribute("aria-expanded","false"),this.launcher.setAttribute("aria-label",`Open ${this.config.name||"assistant"}`);try{this.launcher.focus()}catch{}this._emit("close",{})}}toggle(){this.isOpen?this.close():this.open()}say(e){let t=String(e??"").slice(0,600);t&&(this.open(),this._ready?this._post("say",{text:t}):this._queuedSays.push({text:t}))}setMode(e){this._post("setMode",{mode:e})}destroy(){window.removeEventListener("message",this._onMessage),window.removeEventListener("keydown",this._onKeydown),this.panel.remove(),this.launcher.remove(),this._onDestroy?.(this)}};function f(n={}){let e=n.origin||"https://three.ws",t=null;return{version:"1.0.0",get origin(){return e},get instance(){return t},init(i={}){t&&t.destroy();let a=i.origin||e;return t=new d(i,{origin:a,onDestroy:s=>{t===s&&(t=null)}}),t},open(){t?.open()},close(){t?.close()},toggle(){t?.toggle()},say(i){t?.say(i)},setMode(i){t?.setMode(i)},destroy(){t?.destroy()}}}function g(n){let e={};if(!n)return e;for(let o of u){let i=n.getAttribute(`data-${o.toLowerCase()}`);i!==null&&(e[o]=i)}let t=n.getAttribute("data-position");return t&&(e.position=t),n.hasAttribute("data-open")&&(e.open=!0),e}(function(){if(typeof window>"u"||window.__threeWsAssistantV1)return;window.__threeWsAssistantV1=!0;let n=document.currentScript,e="https://three.ws";try{e=new URL(n.src).origin}catch{}let t=f({origin:e});if(window.ThreeAssistant=t,n&&!n.hasAttribute("data-manual")){let o=g(n),i=()=>t.init(o);document.body?i():document.addEventListener("DOMContentLoaded",i)}})();})();