@invergent/website-widget 2.18.0 → 2.18.1
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/surogates-widget.global.js +1 -1
- package/dist/surogates-widget.global.js.map +1 -1
- package/dist/ui.cjs +6 -0
- package/dist/ui.cjs.map +1 -1
- package/dist/ui.js +6 -0
- package/dist/ui.js.map +1 -1
- package/package.json +1 -1
|
@@ -246,7 +246,7 @@ Error: ${y}`)}}return p()}case g.MESSAGES_SNAPSHOT:{let d=await L(n,a,i,(m,h,y)=
|
|
|
246
246
|
.surg-powered a:hover { text-decoration: underline; }
|
|
247
247
|
`;var Bt,z,Hn,bs,zr=0,Cs=[],X=U,xs=X.__b,Ss=X.__r,Ts=X.diffed,ws=X.__c,As=X.unmount,Is=X.__;function $n(t,e){X.__h&&X.__h(z,t,zr||e),zr=0;var r=z.__H||(z.__H={__:[],__h:[]});return t>=r.__.length&&r.__.push({}),r.__[t]}function Ue(t){return zr=1,Mu(Rs,t)}function Mu(t,e,r){var n=$n(Bt++,2);if(n.t=t,!n.__c&&(n.__=[r?r(e):Rs(void 0,e),function(i){var c=n.__N?n.__N[0]:n.__[0],u=n.t(c,i);c!==u&&(n.__N=[u,n.__[1]],n.__c.setState({}))}],n.__c=z,!z.__f)){var o=function(i,c,u){if(!n.__c.__H)return!0;var p=n.__c.__H.__.filter(function(v){return v.__c});if(p.every(function(v){return!v.__N}))return!s||s.call(this,i,c,u);var f=n.__c.props!==i;return p.some(function(v){if(v.__N){var d=v.__[0];v.__=v.__N,v.__N=void 0,d!==v.__[0]&&(f=!0)}}),s&&s.call(this,i,c,u)||f};z.__f=!0;var s=z.shouldComponentUpdate,a=z.componentWillUpdate;z.componentWillUpdate=function(i,c,u){if(this.__e){var p=s;s=void 0,o(i,c,u),s=p}a&&a.call(this,i,c,u)},z.shouldComponentUpdate=o}return n.__N||n.__}function kt(t,e){var r=$n(Bt++,3);!X.__s&&ks(r.__H,e)&&(r.__=t,r.u=e,z.__H.__h.push(r))}function jn(t){return zr=5,Lu(function(){return{current:t}},[])}function Lu(t,e){var r=$n(Bt++,7);return ks(r.__H,e)&&(r.__=t(),r.__H=e,r.__h=t),r.__}function Du(){for(var t;t=Cs.shift();){var e=t.__H;if(t.__P&&e)try{e.__h.some(Wr),e.__h.some(Vn),e.__h=[]}catch(r){e.__h=[],X.__e(r,t.__v)}}}X.__b=function(t){z=null,xs&&xs(t)},X.__=function(t,e){t&&e.__k&&e.__k.__m&&(t.__m=e.__k.__m),Is&&Is(t,e)},X.__r=function(t){Ss&&Ss(t),Bt=0;var e=(z=t.__c).__H;e&&(Hn===z?(e.__h=[],z.__h=[],e.__.some(function(r){r.__N&&(r.__=r.__N),r.u=r.__N=void 0})):(e.__h.some(Wr),e.__h.some(Vn),e.__h=[],Bt=0)),Hn=z},X.diffed=function(t){Ts&&Ts(t);var e=t.__c;e&&e.__H&&(e.__H.__h.length&&(Cs.push(e)!==1&&bs===X.requestAnimationFrame||((bs=X.requestAnimationFrame)||Uu)(Du)),e.__H.__.some(function(r){r.u&&(r.__H=r.u),r.u=void 0})),Hn=z=null},X.__c=function(t,e){e.some(function(r){try{r.__h.some(Wr),r.__h=r.__h.filter(function(n){return!n.__||Vn(n)})}catch(n){e.some(function(o){o.__h&&(o.__h=[])}),e=[],X.__e(n,r.__v)}}),ws&&ws(t,e)},X.unmount=function(t){As&&As(t);var e,r=t.__c;r&&r.__H&&(r.__H.__.some(function(n){try{Wr(n)}catch(o){e=o}}),r.__H=void 0,e&&X.__e(e,r.__v))};var Ns=typeof requestAnimationFrame=="function";function Uu(t){var e,r=function(){clearTimeout(n),Ns&&cancelAnimationFrame(e),setTimeout(t)},n=setTimeout(r,35);Ns&&(e=requestAnimationFrame(r))}function Wr(t){var e=z,r=t.__c;typeof r=="function"&&(t.__c=void 0,r()),z=e}function Vn(t){var e=z;t.__c=t.__(),z=e}function ks(t,e){return!t||t.length!==e.length||e.some(function(r,n){return r!==t[n]})}function Rs(t,e){return typeof e=="function"?e(t):e}var Gu={"&":"&","<":"<",">":">",'"':""","'":"'"};function Bn(t){return t.replace(/[&<>"']/g,e=>Gu[e]??e)}function Fu(t){let e=t.trim();if(/^(https?:|mailto:)/i.test(e))return e}function Os(t){let e=t;return e=e.replace(/`([^`]+)`/g,(r,n)=>`<code>${n}</code>`),e=e.replace(/\[([^\]]+)\]\(([^)\s]+)\)/g,(r,n,o)=>{let s=Fu(o);return s?`<a href="${s}" target="_blank" rel="noopener noreferrer">${n}</a>`:`${n}`}),e=e.replace(/\*\*([^*]+)\*\*/g,(r,n)=>`<strong>${n}</strong>`),e=e.replace(/(^|[^*])\*([^*\n]+)\*/g,(r,n,o)=>`${n}<em>${o}</em>`),e}function Wn(t){let e=t.split(/```/),r=[];return e.forEach((n,o)=>{if(o%2===1){let i=n.replace(/^[^\n]*\n/,c=>n.includes(`
|
|
248
248
|
`)?"":c);r.push(`<pre><code>${Bn(i.replace(/\n$/,""))}</code></pre>`);return}let a=n.split(/\n{2,}/);for(let i of a){let c=i.split(`
|
|
249
|
-
`).filter(v=>v.trim().length>0);if(c.length===0)continue;let u=c.every(v=>/^\s*[-*]\s+/.test(v)),p=c.every(v=>/^\s*\d+\.\s+/.test(v));if(u||p){let v=c.map(d=>d.replace(/^\s*(?:[-*]|\d+\.)\s+/,"")).map(d=>`<li>${Os(Bn(d))}</li>`).join("");r.push(p?`<ol>${v}</ol>`:`<ul>${v}</ul>`);continue}let f=c.map(v=>Os(Bn(v))).join("<br>");r.push(`<p>${f}</p>`)}}),r.join("")}var Hu=/<next_action([^>]*)>([\s\S]*?)<\/next_action>\s*/gi,Vu=/(?:^|\n)\s*<(?:n(?:e(?:x(?:t(?:_(?:a(?:c(?:t(?:i(?:o(?:n[\s\S]*)?)?)?)?)?)?)?)?)?)?)?$/i;function Ps(t){if(!t)return t;let e=t.replace(Hu,"").trimEnd(),r=Vu.exec(e);return r?e.slice(0,r.index).trimEnd():e}var $u=0;function k(t,e,r,n,o,s){e||(e={});var a,i,c=e;if("ref"in c)for(i in c={},e)i=="ref"?a=e[i]:c[i]=e[i];var u={type:t,props:c,key:r,ref:a,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:--$u,__i:-1,__u:0,__source:o,__self:s};if(typeof t=="function"&&(a=t.defaultProps))for(i in a)c[i]===void 0&&(c[i]=a[i]);return U.vnode&&U.vnode(u),u}var ju="Typically replies instantly",Bu="Hi! \u{1F44B} How can I help you today?";function Ds(){return`u-${Math.random().toString(36).slice(2)}${Date.now().toString(36)}`}function zn(t){let e=[];for(let r of t){if(r.role!=="user"&&r.role!=="assistant")continue;let n=typeof r.content=="string"?r.content:"";e.push({id:r.id??Ds(),role:r.role,content:n})}return e}function Ms(t){return t&&/^https?:\/\//i.test(t)?t:void 0}function Wu(t){return t==="sign_in_required"?"This assistant requires an account. Get access, sign in on this site, then send your message again.":t==="subscription_required"?"This assistant requires an active subscription.":t==="insufficient_tokens"?"You\u2019re out of tokens for this assistant.":"This assistant requires paid access."}function Ls(t){if(t instanceof ce)return"This chat isn\u2019t accepting messages from this site yet. The site owner needs to allow this origin.";if(t instanceof Me)return"You\u2019re sending messages too quickly. Please wait a moment and try again.";if(t&&typeof t=="object"){let e=t.code;if(e==="auth")return"This chat isn\u2019t accepting messages from this site yet. The site owner needs to allow this origin.";if(e==="sse_closed")return"Connection lost. Please send your message again.";let r=t.message;if(r&&r.length<160)return r}return"Something went wrong. Please try again."}var zu=k("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",children:k("path",{d:"M21 11.5a8.38 8.38 0 0 1-.9 3.8 8.5 8.5 0 0 1-7.6 4.7 8.38 8.38 0 0 1-3.8-.9L3 21l1.9-5.7a8.38 8.38 0 0 1-.9-3.8 8.5 8.5 0 0 1 4.7-7.6 8.38 8.38 0 0 1 3.8-.9h.5a8.48 8.48 0 0 1 8 8v.5z"})}),Xu=k("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",children:[k("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),k("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]}),Ku=k("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",children:[k("line",{x1:"22",y1:"2",x2:"11",y2:"13"}),k("polygon",{points:"22 2 15 22 11 13 2 9 22 2"})]});function Us({agent:t,config:e,registerOpenControl:r,onOpenChange:n}){let o=!!e.inline,[s,a]=Ue(o||!!e.openByDefault),[i,c]=Ue(()=>zn(t.messages)),[u,p]=Ue(!1),[f,v]=Ue(null),[d,m]=Ue(null),[h,y]=Ue(""),[E,_]=Ue(""),I=e.title||E||"Assistant",$=jn(null),K=jn(!1);kt(()=>r(a),[r]),kt(()=>n?.(s),[s,n]),kt(()=>{let G=t.subscribe({onMessagesChanged:()=>c(zn(t.messages)),onRunStartedEvent:()=>{p(!0),v(null),m(null)},onRunFinishedEvent:()=>p(!1),onRunErrorEvent:({event:Xn})=>{if(p(!1),Xn.code==="paywall"){m(t.lastPaywall??{code:"payment_required"});return}v(Ls(Xn))}});return()=>G.unsubscribe()},[t]),kt(()=>{!s||K.current||(K.current=!0,t.ensureBootstrapped().then(G=>{G.agentName&&_(G.agentName)}).catch(G=>{K.current=!1,v(Ls(G))}))},[s,t]),kt(()=>{let G=$.current;G&&(G.scrollTop=G.scrollHeight)},[i,u]);let Ge=()=>{let G=h.trim();!G||u||(y(""),t.addMessage({id:Ds(),role:"user",content:G}),c(zn(t.messages)),t.runAgent().catch(()=>{}))},ye=G=>{G.key==="Enter"&&!G.shiftKey&&(G.preventDefault(),Ge())},lt=e.subtitle??ju,oe=e.welcomeMessage??Bu,Ie=i.some(G=>G.role==="assistant"),Hs=!!oe&&!Ie,Vs=u&&i[i.length-1]?.role!=="assistant";if(!o&&!s)return k("button",{type:"button",class:`surg-launcher surg-pos-${e.position??"bottom-right"}`,"aria-label":"Open chat",onClick:()=>a(!0),children:e.logoUrl?k("img",{class:"surg-launcher-logo",src:e.logoUrl,alt:""}):zu});let $s=o?"surg-panel surg-inline":`surg-panel surg-pos-${e.position??"bottom-right"}`;return k("div",{class:$s,role:"dialog","aria-label":I,children:[k("div",{class:"surg-header",children:[k("div",{class:"surg-header-id",children:[e.logoUrl&&k("img",{class:"surg-logo",src:e.logoUrl,alt:""}),k("div",{class:"surg-header-text",children:[k("span",{class:"surg-title",children:I}),lt&&k("span",{class:"surg-subtitle",children:lt})]})]}),!o&&k("button",{type:"button",class:"surg-close","aria-label":"Close chat",onClick:()=>a(!1),children:Xu})]}),k("div",{class:"surg-messages",ref:$,children:[Hs&&k("div",{class:"surg-bubble surg-assistant",dangerouslySetInnerHTML:{__html:Wn(oe)}}),i.map(G=>G.role==="assistant"?k("div",{class:"surg-bubble surg-assistant",dangerouslySetInnerHTML:{__html:Wn(Ps(G.content))}},G.id):k("div",{class:"surg-bubble surg-user",children:G.content},G.id)),Vs&&k("div",{class:"surg-bubble surg-assistant surg-typing",children:[k("span",{}),k("span",{}),k("span",{})]})]}),f&&k("div",{class:"surg-error",children:f}),d&&k("div",{class:"surg-paywall",children:[k("span",{children:Wu(d.code)}),Ms(d.buyUrl)&&k("a",{class:"surg-paywall-cta",href:Ms(d.buyUrl),target:"_blank",rel:"noopener noreferrer",children:"Get access"})]}),k("div",{class:"surg-composer",children:[k("textarea",{class:"surg-input",rows:1,placeholder:"Type a message\u2026",value:h,disabled:u,onInput:G=>y(G.target.value),onKeyDown:ye}),k("button",{type:"button",class:"surg-send","aria-label":"Send",disabled:u||!h.trim(),onClick:Ge,children:Ku})]}),k("div",{class:"surg-powered",children:["Powered by"," ",k("a",{href:"https://surogate.ai/",target:"_blank",rel:"noopener noreferrer",children:"Surogate"})]})]})}var Gs="#4f46e5";function Zu(t){let e=t.replace("#",""),r=e.length===3?e.split("").map(i=>i+i).join(""):e;if(r.length!==6||/[^0-9a-f]/i.test(r))return"#ffffff";let n=parseInt(r.slice(0,2),16),o=parseInt(r.slice(2,4),16),s=parseInt(r.slice(4,6),16);return(.299*n+.587*o+.114*s)/255>.62?"#0f172a":"#ffffff"}async function Fs(t){if(t?.apiUrl)return Xr(t);if(!t?.publishableKey)throw new Error('SurogatesWidget.mountWithPairing: "publishableKey" is required.');let{agentId:e,apiWebUrl:r}=await ts(t.pairingUrl??es,t.publishableKey);return Xr({...t,apiUrl:r,agentId:e})}function Xr(t){if(!t||!t.apiUrl||!t.publishableKey)throw new Error('SurogatesWidget.mount: "apiUrl" and "publishableKey" are required.');let e=t.accentColor??Gs,r=!1,n=document.createElement("div");n.setAttribute("data-surogates-widget","");let o=n.attachShadow({mode:"open"}),s=document.createElement("style");s.textContent=Es,o.appendChild(s);let a=document.createElement("div");a.className="surg-root",o.appendChild(a);let i=E=>{let _=E??Gs;a.style.setProperty("--surg-accent",_),a.style.setProperty("--surg-accent-fg",Zu(_))};i(e);let c=()=>(t.target??document.body)?.appendChild(n);t.target||document.body?c():document.addEventListener("DOMContentLoaded",()=>{r||c()},{once:!0});let u=new It(t),p,f=t.inline||!!t.openByDefault,v=E=>{p=E},d=E=>{f=E},m=t,h=()=>{Fn(k(Us,{agent:u,config:m,registerOpenControl:v,onOpenChange:d}),a)};h();let y=()=>{u.end()};return window.addEventListener("beforeunload",y),{agent:u,open:()=>p?.(!0),close:()=>p?.(!1),toggle:()=>p?.(!f),update:E=>{r||(m={...m,...E},"accentColor"in E&&i(m.accentColor),h())},destroy:()=>{r||(r=!0,window.removeEventListener("beforeunload",y),u.end(),Fn(null,a),n.remove())}}}return Xs(Yu);})();
|
|
249
|
+
`).filter(v=>v.trim().length>0);if(c.length===0)continue;let u=c.every(v=>/^\s*[-*]\s+/.test(v)),p=c.every(v=>/^\s*\d+\.\s+/.test(v));if(u||p){let v=c.map(d=>d.replace(/^\s*(?:[-*]|\d+\.)\s+/,"")).map(d=>`<li>${Os(Bn(d))}</li>`).join("");r.push(p?`<ol>${v}</ol>`:`<ul>${v}</ul>`);continue}let f=c.map(v=>Os(Bn(v))).join("<br>");r.push(`<p>${f}</p>`)}}),r.join("")}var Hu=/<next_action([^>]*)>([\s\S]*?)<\/next_action>\s*/gi,Vu=/(?:^|\n)\s*<(?:n(?:e(?:x(?:t(?:_(?:a(?:c(?:t(?:i(?:o(?:n[\s\S]*)?)?)?)?)?)?)?)?)?)?)?$/i;function Ps(t){if(!t)return t;let e=t.replace(Hu,"").trimEnd(),r=Vu.exec(e);return r?e.slice(0,r.index).trimEnd():e}var $u=0;function k(t,e,r,n,o,s){e||(e={});var a,i,c=e;if("ref"in c)for(i in c={},e)i=="ref"?a=e[i]:c[i]=e[i];var u={type:t,props:c,key:r,ref:a,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:--$u,__i:-1,__u:0,__source:o,__self:s};if(typeof t=="function"&&(a=t.defaultProps))for(i in a)c[i]===void 0&&(c[i]=a[i]);return U.vnode&&U.vnode(u),u}var ju="Typically replies instantly",Bu="Hi! \u{1F44B} How can I help you today?";function Ds(){return`u-${Math.random().toString(36).slice(2)}${Date.now().toString(36)}`}function zn(t){let e=[];for(let r of t){if(r.role!=="user"&&r.role!=="assistant")continue;let n=typeof r.content=="string"?r.content:"";e.push({id:r.id??Ds(),role:r.role,content:n})}return e}function Ms(t){return t&&/^https?:\/\//i.test(t)?t:void 0}function Wu(t){return t==="sign_in_required"?"This assistant requires an account. Get access, sign in on this site, then send your message again.":t==="subscription_required"?"This assistant requires an active subscription.":t==="free_plan_available"?"This assistant needs a plan, and there is a free one.":t==="upgrade_required"?"You have used this month\u2019s free allowance. Upgrade to keep chatting.":t==="insufficient_tokens"?"You\u2019re out of tokens for this assistant.":"This assistant requires paid access."}function Ls(t){if(t instanceof ce)return"This chat isn\u2019t accepting messages from this site yet. The site owner needs to allow this origin.";if(t instanceof Me)return"You\u2019re sending messages too quickly. Please wait a moment and try again.";if(t&&typeof t=="object"){let e=t.code;if(e==="auth")return"This chat isn\u2019t accepting messages from this site yet. The site owner needs to allow this origin.";if(e==="sse_closed")return"Connection lost. Please send your message again.";let r=t.message;if(r&&r.length<160)return r}return"Something went wrong. Please try again."}var zu=k("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",children:k("path",{d:"M21 11.5a8.38 8.38 0 0 1-.9 3.8 8.5 8.5 0 0 1-7.6 4.7 8.38 8.38 0 0 1-3.8-.9L3 21l1.9-5.7a8.38 8.38 0 0 1-.9-3.8 8.5 8.5 0 0 1 4.7-7.6 8.38 8.38 0 0 1 3.8-.9h.5a8.48 8.48 0 0 1 8 8v.5z"})}),Xu=k("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",children:[k("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),k("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]}),Ku=k("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",children:[k("line",{x1:"22",y1:"2",x2:"11",y2:"13"}),k("polygon",{points:"22 2 15 22 11 13 2 9 22 2"})]});function Us({agent:t,config:e,registerOpenControl:r,onOpenChange:n}){let o=!!e.inline,[s,a]=Ue(o||!!e.openByDefault),[i,c]=Ue(()=>zn(t.messages)),[u,p]=Ue(!1),[f,v]=Ue(null),[d,m]=Ue(null),[h,y]=Ue(""),[E,_]=Ue(""),I=e.title||E||"Assistant",$=jn(null),K=jn(!1);kt(()=>r(a),[r]),kt(()=>n?.(s),[s,n]),kt(()=>{let G=t.subscribe({onMessagesChanged:()=>c(zn(t.messages)),onRunStartedEvent:()=>{p(!0),v(null),m(null)},onRunFinishedEvent:()=>p(!1),onRunErrorEvent:({event:Xn})=>{if(p(!1),Xn.code==="paywall"){m(t.lastPaywall??{code:"payment_required"});return}v(Ls(Xn))}});return()=>G.unsubscribe()},[t]),kt(()=>{!s||K.current||(K.current=!0,t.ensureBootstrapped().then(G=>{G.agentName&&_(G.agentName)}).catch(G=>{K.current=!1,v(Ls(G))}))},[s,t]),kt(()=>{let G=$.current;G&&(G.scrollTop=G.scrollHeight)},[i,u]);let Ge=()=>{let G=h.trim();!G||u||(y(""),t.addMessage({id:Ds(),role:"user",content:G}),c(zn(t.messages)),t.runAgent().catch(()=>{}))},ye=G=>{G.key==="Enter"&&!G.shiftKey&&(G.preventDefault(),Ge())},lt=e.subtitle??ju,oe=e.welcomeMessage??Bu,Ie=i.some(G=>G.role==="assistant"),Hs=!!oe&&!Ie,Vs=u&&i[i.length-1]?.role!=="assistant";if(!o&&!s)return k("button",{type:"button",class:`surg-launcher surg-pos-${e.position??"bottom-right"}`,"aria-label":"Open chat",onClick:()=>a(!0),children:e.logoUrl?k("img",{class:"surg-launcher-logo",src:e.logoUrl,alt:""}):zu});let $s=o?"surg-panel surg-inline":`surg-panel surg-pos-${e.position??"bottom-right"}`;return k("div",{class:$s,role:"dialog","aria-label":I,children:[k("div",{class:"surg-header",children:[k("div",{class:"surg-header-id",children:[e.logoUrl&&k("img",{class:"surg-logo",src:e.logoUrl,alt:""}),k("div",{class:"surg-header-text",children:[k("span",{class:"surg-title",children:I}),lt&&k("span",{class:"surg-subtitle",children:lt})]})]}),!o&&k("button",{type:"button",class:"surg-close","aria-label":"Close chat",onClick:()=>a(!1),children:Xu})]}),k("div",{class:"surg-messages",ref:$,children:[Hs&&k("div",{class:"surg-bubble surg-assistant",dangerouslySetInnerHTML:{__html:Wn(oe)}}),i.map(G=>G.role==="assistant"?k("div",{class:"surg-bubble surg-assistant",dangerouslySetInnerHTML:{__html:Wn(Ps(G.content))}},G.id):k("div",{class:"surg-bubble surg-user",children:G.content},G.id)),Vs&&k("div",{class:"surg-bubble surg-assistant surg-typing",children:[k("span",{}),k("span",{}),k("span",{})]})]}),f&&k("div",{class:"surg-error",children:f}),d&&k("div",{class:"surg-paywall",children:[k("span",{children:Wu(d.code)}),Ms(d.buyUrl)&&k("a",{class:"surg-paywall-cta",href:Ms(d.buyUrl),target:"_blank",rel:"noopener noreferrer",children:"Get access"})]}),k("div",{class:"surg-composer",children:[k("textarea",{class:"surg-input",rows:1,placeholder:"Type a message\u2026",value:h,disabled:u,onInput:G=>y(G.target.value),onKeyDown:ye}),k("button",{type:"button",class:"surg-send","aria-label":"Send",disabled:u||!h.trim(),onClick:Ge,children:Ku})]}),k("div",{class:"surg-powered",children:["Powered by"," ",k("a",{href:"https://surogate.ai/",target:"_blank",rel:"noopener noreferrer",children:"Surogate"})]})]})}var Gs="#4f46e5";function Zu(t){let e=t.replace("#",""),r=e.length===3?e.split("").map(i=>i+i).join(""):e;if(r.length!==6||/[^0-9a-f]/i.test(r))return"#ffffff";let n=parseInt(r.slice(0,2),16),o=parseInt(r.slice(2,4),16),s=parseInt(r.slice(4,6),16);return(.299*n+.587*o+.114*s)/255>.62?"#0f172a":"#ffffff"}async function Fs(t){if(t?.apiUrl)return Xr(t);if(!t?.publishableKey)throw new Error('SurogatesWidget.mountWithPairing: "publishableKey" is required.');let{agentId:e,apiWebUrl:r}=await ts(t.pairingUrl??es,t.publishableKey);return Xr({...t,apiUrl:r,agentId:e})}function Xr(t){if(!t||!t.apiUrl||!t.publishableKey)throw new Error('SurogatesWidget.mount: "apiUrl" and "publishableKey" are required.');let e=t.accentColor??Gs,r=!1,n=document.createElement("div");n.setAttribute("data-surogates-widget","");let o=n.attachShadow({mode:"open"}),s=document.createElement("style");s.textContent=Es,o.appendChild(s);let a=document.createElement("div");a.className="surg-root",o.appendChild(a);let i=E=>{let _=E??Gs;a.style.setProperty("--surg-accent",_),a.style.setProperty("--surg-accent-fg",Zu(_))};i(e);let c=()=>(t.target??document.body)?.appendChild(n);t.target||document.body?c():document.addEventListener("DOMContentLoaded",()=>{r||c()},{once:!0});let u=new It(t),p,f=t.inline||!!t.openByDefault,v=E=>{p=E},d=E=>{f=E},m=t,h=()=>{Fn(k(Us,{agent:u,config:m,registerOpenControl:v,onOpenChange:d}),a)};h();let y=()=>{u.end()};return window.addEventListener("beforeunload",y),{agent:u,open:()=>p?.(!0),close:()=>p?.(!1),toggle:()=>p?.(!f),update:E=>{r||(m={...m,...E},"accentColor"in E&&i(m.accentColor),h())},destroy:()=>{r||(r=!0,window.removeEventListener("beforeunload",y),u.end(),Fn(null,a),n.remove())}}}return Xs(Yu);})();
|
|
250
250
|
/*! Bundled license information:
|
|
251
251
|
|
|
252
252
|
fast-json-patch/module/helpers.mjs:
|