profoundjs 7.10.1 → 7.11.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.
@@ -1,27 +1,31 @@
1
1
  if(!window.profound)window.profound={};window.profound.ai||(window.profound.ai={});
2
- profound.ai.Chat=function(){function h(){if(window.pui&&window.pui.ide&&window.pui.ide.designerId)return true;return false}function o(){var a=Ext.e("centerPanel").d(),d={};if(a.isAIAgent&&a.aiAgent)d.aiAgent=a.aiAgent;if(a.isAIAgent&&a.dataAccess)d.dataAccess=a.dataAccess;Object.assign(d,Object.fromEntries(Object.entries(a.pjsModule).filter(function(c){return typeof c[1]!=="function"})));return d}function l(){function a(){var c=j.lastChild.querySelectorAll(".pai-chart");if(c.length!==0)if(profound.ai.a){for(var e=
3
- 0;e<c.length;e++){var f=c[e],n=JSON.parse(f.getAttribute("data-config"));f.removeAttribute("data-config");f.chart=new window.Chart(f.querySelector("canvas"),n);f=f.querySelector("span");f.parentNode.removeChild(f)}j.scrollTop=j.scrollHeight}else{d++;d<20&&setTimeout(a,1E3)}}var d=0;a()}function m(a){function d(){a.read().then(function(n){var i=n.value;if(n.done){b.hideLoader();l()}else{n=c.decode(i).split("\n");for(i=0;i<n.length-1;i++){var g=n[i];if(g){g=JSON.parse(g);if(g.threadId)u=g.threadId;
4
- if(g.status==="error"){b.hideLoader();b.add({message:"Error: "+g.message,type:"error"});return}if(g.status==="calling"){var p=j.lastChild;g=p.innerHTML.replace(v,"")+'<p>Calling <span class="pai-function-name">'+g["function"]+"</span>.</p>";b.add({message:g+v,type:"agent-response",replace:true})}else if(g.status==="calls completed"){p=j.lastChild;var s="<p>";s+=g.count===1?"Call completed.":g.count+" calls completed.";s+="</p>";s=p.innerHTML.replace(v,"")+s;b.add({message:s+v,type:"agent-response",
5
- replace:true})}else{if(g.status==="file")e=e.replace(g.placeholderUrl,g.fileUrl);e+=g.text;if(g.charts){if(!profound.ai.a){var N=window.define;window.define=undefined;profound.ai.b(J,function(){window.define=N;profound.ai.a=true})}f=g.charts}if(f)for(var K in f)e=e.replace(K,'<div class="pai-chart" data-config="'+JSON.stringify(f[K]).replace(/"/g,"&quot;")+'"><span>Loading chart...</span><canvas></canvas></div>');p=e&&typeof window.marked==="function"?window.marked(e+v):e+v;g.status==="citation"&&
6
- C.push(g);for(g=0;g<C.length;g++){s=C[g];p=p.replace(s.citationPlaceholder,s.citationContent)}b.add({message:p,type:"agent-response",replace:true})}}}d()}})}var c=new TextDecoder("utf-8"),e="",f;d()}function y(a){var d=a.status;if(a.threadId)u=a.threadId;if(a.runId)D=a.runId;if(a.modelKey)H=a.modelKey;if(a.message){var c=a.message,e="agent-response";if(a.status==="error"){c="Error: "+c;e="error"}if(a.status==="failed"){c="Failed: "+c;e="error"}if(a.status==="cancelled"){c="Cancelled";e="error"}if(a.status===
7
- "expired"){c="Chat Expired";e="error"}if(a.charts){if(!profound.ai.a){var f=window.define;window.define=undefined;profound.ai.b(J,function(){window.define=f;profound.ai.a=true})}var n=a.charts;for(var i in n)c=c.replace(i,'<div class="pai-chart" data-config="'+JSON.stringify(n[i]).replace(/"/g,"&quot;")+'"><span>Loading chart...</span><canvas></canvas></div>')}b.add({message:c,type:e});a.charts&&l()}d==="queued"||d==="in_progress"?setTimeout(function(){b.poll()},L):b.hideLoader()}function E(){k.value===
8
- ""||b.isLoading()?q.classList.remove("pai-send-button-active"):q.classList.add("pai-send-button-active")}function F(){k.style.height="1px";var a=k.scrollHeight==0?21:k.scrollHeight;if(a>100)a=100;j.style.height="calc(100% - "+(a+54+(b.heading?74:0))+"px)";k.style.height=a+"px"}function O(a,d){if(typeof a!=="string")return a;if(a.length!==7)return a;if(a.substring(0,1)!=="#")return a;var c=parseInt(a.substring(1,3),16),e=parseInt(a.substring(3,5),16),f=parseInt(a.substring(5,7),16);c=parseInt(c*(100+
9
- d)/100);e=parseInt(e*(100+d)/100);f=parseInt(f*(100+d)/100);c=c<255?c:255;e=e<255?e:255;f=f<255?f:255;return"#"+(c.toString(16).length==1?"0"+c.toString(16):c.toString(16))+(e.toString(16).length==1?"0"+e.toString(16):e.toString(16))+(f.toString(16).length==1?"0"+f.toString(16):f.toString(16))}var b=this,r=null,j=null,z=null,k=null,q=null,u=null,D=null,H=null,L=1E3,w=null,G=null,M="Thinking",A="",B="light",x=null,t=false,v='<span class="pai-loader-dot pai-inline-loader"></span>',J="https://cdn.jsdelivr.net/npm/chart.js@4/dist/chart.umd.min.js",
10
- I=null,C=[];this.init=function(a){a||(a={});if(!a.container)a.container=document.body;a.closeButton||(a.closeButton=true);a.closeTitle||(a.closeTitle="Close this conversation");a.sendTitle||(a.sendTitle="Send this message");a.promptPlaceHolder||(a.promptPlaceHolder="Send a message...");if(a.heading)b.heading=a.heading;if(a.greeting)b.greeting=a.greeting;if(a.agent)b.agent=a.agent;if(a.pollInterval)L=a.pollInterval;if(a.loaderMessage)M=a.defaultLoaderMessage;if(a.server)A=a.server;if(a.data)b.data=
11
- a.data;if(a.stream)t=a.stream;if(a.jwt)I=a.jwt;b.dom=document.createElement("div");b.dom.classList.add("pai-chat");b.dom.classList.add("pai-hidden");a.container.appendChild(b.dom);if(a.closeButton){r=document.createElement("div");r.classList.add("pai-close-button");r.title=a.closeTitle;r.innerHTML='<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 0 24 24" width="24px" fill="#000000"><path d="M0 0h24v24H0z" fill="none"/><path d="M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z"/></svg>';
12
- r.addEventListener("click",function(){b.onClose&&b.onClose();h()?b.clear():b.hide()});b.dom.appendChild(r)}j=document.createElement("div");j.classList.add("pai-messages");b.dom.appendChild(j);z=document.createElement("div");z.classList.add("pai-prompt-area");k=document.createElement("textarea");k.classList.add("pai-prompt-box");k.setAttribute("placeholder",a.promptPlaceHolder);k.addEventListener("keydown",function(e){if(e.key==="Enter"){e.shiftKey||e.preventDefault();e.stopPropagation();e.shiftKey||
13
- b.send()}E()});k.addEventListener("input",function(){F();E()});z.appendChild(k);q=document.createElement("div");q.classList.add("pai-send-button");q.title=a.sendTitle;q.innerHTML='<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 0 24 24" width="24px" fill="#000000"><path d="M0 0h24v24H0V0z" fill="none"/><path d="M4 12l1.41 1.41L11 7.83V20h2V7.83l5.58 5.59L20 12l-8-8-8 8z"/></svg>';q.addEventListener("click",function(){b.send()});z.appendChild(q);b.dom.appendChild(z);w=document.createElement("div");
14
- w.classList.add("pai-loader");G=document.createElement("span");G.classList.add("pai-loader-message");w.appendChild(G);for(var d=1;d<=3;d++){var c=document.createElement("div");c.classList.add("pai-loader-dot");w.appendChild(c)}b.clear();a.theme&&b.setTheme(a.theme);a.brandColor&&b.setBrandColor(a.brandColor)};this.show=function(){b.dom.classList.remove("pai-hidden");k.focus()};this.hide=function(){b.dom.classList.add("pai-hidden")};this.add=function(a){var d=a.message,c=document.createElement("div");
15
- c.classList.add("pai-message");var e=a.type;e||(e="user-message");c.classList.add("pai-"+e);if(e==="agent-response"){c.classList.add("markdown-body");if(A)d=d.replace(/<img src="\/profound-ai\/image\?file=/g,'<img src="'+A+"/profound-ai/image?file=");c.innerHTML=d;c.querySelectorAll("a").forEach(function(f){f.addEventListener("click",function(){pui.skipConfirm=true;setTimeout(function(){pui.skipConfirm=false},250)})});c.querySelectorAll("span.pai-citation").forEach(function(f){function n(){if(i&&
16
- !i.matches(":hover")){f.removeChild(i);i=null}}var i,g;f.addEventListener("mouseenter",function(){if(!i)if(f.getAttribute("data-citation")){i=document.createElement("div");i.classList.add("pai-tooltip-content");i.innerHTML=f.getAttribute("data-citation");f.appendChild(i);var p=f.getBoundingClientRect();i.style.left=p.left+"px";i.style.top=p.top-i.offsetHeight-5+"px";i.addEventListener("mouseenter",function(){clearTimeout(g)});i.addEventListener("mouseleave",function(){n()})}});f.addEventListener("mouseleave",
17
- function(){g=setTimeout(n,100)})});if(a.replace)(a=j.lastChild)&&a.classList.contains("pai-agent-response")&&a.parentNode.removeChild(a)}else c.innerText=d;j.appendChild(c);j.scrollTop=j.scrollHeight};this.clear=function(){j.innerHTML="";b.greeting&&b.add({message:b.greeting,type:"greeting"});b.setHeading(b.heading);b.setBrandColor(x);D=u=null};this.setTheme=function(a){B=a;B=typeof B!=="string"?"light":B.toLowerCase();B==="dark"?b.dom.classList.add("pai-dark"):b.dom.classList.remove("pai-dark")};
18
- this.setBrandColor=function(a){x=a;if(a=b.dom.querySelector(".pai-heading")){a.style.backgroundColor=null;a.style.backgroundImage=null;a.classList.remove("pai-branded")}r&&r.classList.remove("pai-branded");q.style.backgroundColor=null;if(x){var d=O(x,-30);if(a){a.style.backgroundColor=x;a.style.backgroundImage="linear-gradient(to right, "+x+", "+d+")";a.classList.add("pai-branded")}r&&a&&r.classList.add("pai-branded");q.style.backgroundColor=x}};this.setHeading=function(a){var d=b.dom.querySelector(".pai-heading");
19
- if(a){if(d===null){d=document.createElement("div");d.classList.add("pai-heading");b.dom.prepend(d);F()}d.innerText=a}else if(d!==null){d.remove();F()}};this.send=function(){if(k.value!=="")if(!b.isLoading()){b.onSend&&b.onSend(k.value);b.add({message:k.value});C=[];var a={};a.message=k.value;if(u)a.threadId=u;var d="/profound-ai/chat";if(h()){a.agentData=o();a.agentFile=Ext.e("centerPanel").d().title.replace(/\*/g,"").trim();t=pui.streamingModelList.includes(a.agentData.aiAgent.model);d="/ide/profound-ai/chat"}else a.agent=
20
- b.agent;var c=b.data;if(typeof c==="function")c=c();if(b.data)a.data=c;k.value="";F();k.focus();b.showLoader();c={"Content-Type":"application/json"};if(t){c.Connection="keep-alive";c["Response-Type"]="stream"}if(I){var e=I;if(typeof e==="function")e=e();c.Authorization="Bearer "+e}fetch(A+d,{method:"POST",headers:c,body:JSON.stringify(a)}).then(function(f){return t?f.body.getReader():f.json()}).then(function(f){t?m(f):y(f)})["catch"](function(f){b.hideLoader();b.add({message:"Error: "+f.message,type:"error"})})}};
21
- this.poll=function(){if(!(!u||!D||!H)){var a={};a.threadId=u;a.runId=D;a.modelKey=H;var d="/profound-ai/poll";if(h())d="/ide/profound-ai/poll";fetch(A+d,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(a)}).then(function(c){return c.json()}).then(function(c){y(c)})["catch"](function(c){b.hideLoader();b.add({message:"Error: "+c.message,type:"error"})})}};this.showLoader=function(a){a||(a=M);G.innerText=a;if(!b.isLoading()){t?b.add({message:v,type:"agent-response"}):j.appendChild(w);
22
- E()}j.scrollTop=j.scrollHeight};this.hideLoader=function(){if(b.isLoading()){if(t)for(var a=j.querySelectorAll(".pai-inline-loader"),d=a.length-1;d>=0;d--)a[d].parentNode.removeChild(a[d]);else j.removeChild(w);E()}};this.isLoading=function(){if(t)return j.querySelectorAll(".pai-inline-loader").length>0;return w.parentNode===j};this.destroy=function(){if(b.dom){b.dom.parentNode.removeChild(b.dom);b.dom=null}};this.removeEmbedIcon=function(){profound.ai.removeEmbedIcon()}};
23
- profound.ai.c=function(h){if(!document.querySelector('link[href="'+h+'"]')){var o=document.createElement("link");o.rel="stylesheet";o.href=h;document.head.appendChild(o)}};profound.ai.b=function(h,o){if(document.querySelector('script[src="'+h+'"]'))typeof o==="function"&&o();else{var l=document.createElement("script");l.type="text/javascript";l.src=h;l.onload=function(){typeof o==="function"&&o()};document.head.appendChild(l)}};
24
- profound.ai.startAgent=function(h,o){h||(h={});var l="";if(h.server)l=h.server;if(!o&&h.agent)fetch(l+"/profound-ai/attributes",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({agent:h.agent})}).then(function(m){return m.json()}).then(function(m){if(m.status==="error")throw Error(m.message);m=m.attributes;for(var y in m)if(h[y]===undefined)h[y]=m[y];profound.ai.startAgent(h,true)})["catch"](function(m){throw Error("Unable to start AI Agent: "+m.message);});else{if(!h.container)h.container=
25
- document.body;h.stream&&profound.ai.b(l+"/marked/marked.min.js");profound.ai.c(l+"/profoundui/proddata/css/markdown.css");profound.ai.c(l+"/profoundui/proddata/css/profoundai.css");profound.ai.agent&&profound.ai.agent.destroy();if(h.embed){if(!profound.ai.embedIcon){profound.ai.embedIcon=document.createElement("div");profound.ai.embedIcon.classList.add("pai-embed-icon");profound.ai.embedIcon.innerHTML='<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 0 24 24" width="24px" fill="#000000"><path d="M0 0h24v24H0z" fill="none"/><path d="M21 6h-2v9H6v2c0 .55.45 1 1 1h11l4 4V7c0-.55-.45-1-1-1zm-4 6V3c0-.55-.45-1-1-1H3c-.55 0-1 .45-1 1v14l4-4h10c.55 0 1-.45 1-1z"/></svg>';
26
- h.container.appendChild(profound.ai.embedIcon);l="Ask AI Agent";if(h.embedIconTitle)l=h.embedIconTitle;profound.ai.embedIcon.title=l;profound.ai.embedIcon.addEventListener("click",function(){var m=Object.assign({},h);delete m.embed;profound.ai.startAgent(m)})}}else{profound.ai.agent=new profound.ai.Chat;profound.ai.agent.init(h);profound.ai.agent.show();return profound.ai.agent}}};
2
+ profound.ai.Chat=function(){function g(){if(window.pui&&window.pui.ide&&window.pui.ide.designerId)return true;return false}function p(){var a=Ext.c("centerPanel").e(),d={};if(a.isAIAgent&&a.aiAgent)d.aiAgent=a.aiAgent;if(a.isAIAgent&&a.dataAccess)d.dataAccess=a.dataAccess;Object.assign(d,Object.fromEntries(Object.entries(a.pjsModule).filter(function(c){return typeof c[1]!=="function"})));return d}function m(){function a(){var c=k.lastChild.querySelectorAll(".pai-chart");if(c.length!==0)if(profound.ai.a){for(var e=
3
+ 0;e<c.length;e++){var f=c[e],l=JSON.parse(f.getAttribute("data-config"));f.removeAttribute("data-config");f.chart=new window.Chart(f.querySelector("canvas"),l);f=f.querySelector("span");f.parentNode.removeChild(f)}k.scrollTop=k.scrollHeight}else{d++;d<20&&setTimeout(a,1E3)}}var d=0;a()}function n(a){function d(){a.read().then(function(l){var j=l.value;if(l.done){b.hideLoader();m()}else{l=c.decode(j).split("\n");for(j=0;j<l.length-1;j++){var h=l[j];if(h){h=JSON.parse(h);if(h.threadId)x=h.threadId;
4
+ if(h.status==="error"){b.hideLoader();b.add({message:"Error: "+h.message,type:"error"});return}if(h.status==="calling"){var r=k.lastChild;h=r.innerHTML.replace(y,"")+'<p>Calling <span class="pai-function-name">'+h["function"]+"</span>.</p>";b.add({message:h+y,type:"agent-response",replace:true})}else if(h.status==="calls completed"){r=k.lastChild;var u="<p>";u+=h.count===1?"Call completed.":h.count+" calls completed.";u+="</p>";u=r.innerHTML.replace(y,"")+u;b.add({message:u+y,type:"agent-response",
5
+ replace:true})}else{if(h.status==="file")e=e.replace(h.placeholderUrl,h.fileUrl);e+=h.text;if(h.charts){if(!profound.ai.a){var R=window.define;window.define=undefined;profound.ai.b(M,function(){window.define=R;profound.ai.a=true})}f=h.charts}if(f)for(var N in f)e=e.replace(N,'<div class="pai-chart" data-config="'+JSON.stringify(f[N]).replace(/"/g,"&quot;")+'"><span>Loading chart...</span><canvas></canvas></div>');r=e&&typeof window.marked==="function"?window.marked(e+y):e+y;h.status==="citation"&&
6
+ H.push(h);for(h=0;h<H.length;h++){u=H[h];r=r.replace(u.citationPlaceholder,u.citationContent)}b.add({message:r,type:"agent-response",replace:true})}}}d()}})}var c=new TextDecoder("utf-8"),e="",f;d()}function C(a){var d=a.status;if(a.threadId)x=a.threadId;if(a.runId)I=a.runId;if(a.modelKey)K=a.modelKey;if(a.message){var c=a.message,e="agent-response";if(a.status==="error"){c="Error: "+c;e="error"}if(a.status==="failed"){c="Failed: "+c;e="error"}if(a.status==="cancelled"){c="Cancelled";e="error"}if(a.status===
7
+ "expired"){c="Chat Expired";e="error"}if(a.charts){if(!profound.ai.a){var f=window.define;window.define=undefined;profound.ai.b(M,function(){window.define=f;profound.ai.a=true})}var l=a.charts;for(var j in l)c=c.replace(j,'<div class="pai-chart" data-config="'+JSON.stringify(l[j]).replace(/"/g,"&quot;")+'"><span>Loading chart...</span><canvas></canvas></div>')}b.add({message:c,type:e});a.charts&&m()}d==="queued"||d==="in_progress"?setTimeout(function(){b.poll()},O):b.hideLoader()}function v(){i.value===
8
+ ""||b.isLoading()?s.classList.remove("pai-send-button-active"):s.classList.add("pai-send-button-active");var a="webkitSpeechRecognition"in window||"SpeechRecognition"in window;if(g()){var d=Ext.c("aiAgentModel").getValue();if(pui.modelVoiceSettings)z=pui.modelVoiceSettings[d];z||(z={})}if(a&&z.enabled===false)a=false;if(a){i.classList.add("pai-with-voice");o.classList.remove("pai-hidden")}else{i.classList.remove("pai-with-voice");o.classList.add("pai-hidden")}}function E(){i.style.height="1px";var a=
9
+ i.scrollHeight==0?21:i.scrollHeight;if(a<21)a=21;if(a>100)a=100;k.style.height="calc(100% - "+(a+54+(b.heading?74:0))+"px)";i.style.height=a+"px"}function S(a,d){if(typeof a!=="string")return a;if(a.length!==7)return a;if(a.substring(0,1)!=="#")return a;var c=parseInt(a.substring(1,3),16),e=parseInt(a.substring(3,5),16),f=parseInt(a.substring(5,7),16);c=parseInt(c*(100+d)/100);e=parseInt(e*(100+d)/100);f=parseInt(f*(100+d)/100);c=c<255?c:255;e=e<255?e:255;f=f<255?f:255;return"#"+(c.toString(16).length==
10
+ 1?"0"+c.toString(16):c.toString(16))+(e.toString(16).length==1?"0"+e.toString(16):e.toString(16))+(f.toString(16).length==1?"0"+f.toString(16):f.toString(16))}var b=this,t=null,k=null,D=null,i=null,s=null,o=null,x=null,I=null,K=null,O=1E3,A=null,J=null,P="Thinking",F="",G="light",B=null,w=false,z={},y='<span class="pai-loader-dot pai-inline-loader"></span>',M="https://cdn.jsdelivr.net/npm/chart.js@4/dist/chart.umd.min.js",L=null,H=[],Q,q;this.init=function(a){a||(a={});if(!a.container)a.container=
11
+ document.body;a.closeButton||(a.closeButton=true);a.closeTitle||(a.closeTitle="Close this conversation");a.sendTitle||(a.sendTitle="Send this message");a.voiceTitle||(a.voiceTitle="Use voice");a.promptPlaceHolder||(a.promptPlaceHolder="Send a message...");if(a.heading)b.heading=a.heading;if(a.greeting)b.greeting=a.greeting;if(a.agent)b.agent=a.agent;if(a.pollInterval)O=a.pollInterval;if(a.loaderMessage)P=a.defaultLoaderMessage;if(a.server)F=a.server;if(a.data)b.data=a.data;if(a.stream)w=a.stream;
12
+ if(typeof a.voice==="object")z=a.voice;if(a.jwt)L=a.jwt;b.dom=document.createElement("div");b.dom.classList.add("pai-chat");b.dom.classList.add("pai-hidden");a.container.appendChild(b.dom);if(a.closeButton){t=document.createElement("div");t.classList.add("pai-close-button");t.title=a.closeTitle;t.innerHTML='<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 0 24 24" width="24px" fill="#000000"><path d="M0 0h24v24H0z" fill="none"/><path d="M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z"/></svg>';
13
+ t.addEventListener("click",function(){b.onClose&&b.onClose();g()?b.clear():b.hide()});b.dom.appendChild(t)}k=document.createElement("div");k.classList.add("pai-messages");b.dom.appendChild(k);D=document.createElement("div");D.classList.add("pai-prompt-area");i=document.createElement("textarea");i.classList.add("pai-prompt-box");i.setAttribute("placeholder",a.promptPlaceHolder);i.addEventListener("keydown",function(e){if(e.key==="Enter"){e.shiftKey||e.preventDefault();e.stopPropagation();e.shiftKey||
14
+ b.send()}v()});i.addEventListener("input",function(){E();v()});D.appendChild(i);o=document.createElement("div");o.classList.add("pai-voice-button");o.title=a.voiceTitle;o.innerHTML='<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 0 24 24" width="24px" fill="#000000"><path d="M0 0h24v24H0V0z" fill="none"/><path d="M12 14c1.66 0 3-1.34 3-3V5c0-1.66-1.34-3-3-3S9 3.34 9 5v6c0 1.66 1.34 3 3 3zm4.5-3c0 2.5-2 4.5-4.5 4.5S7.5 13.5 7.5 11H6c0 3.07 2.13 5.64 5 6.32V21h2v-3.68c2.87-.68 5-3.25 5-6.32h-1.5z"/></svg>';
15
+ D.appendChild(o);if("webkitSpeechRecognition"in window||"SpeechRecognition"in window){Q=window.SpeechRecognition||window.webkitSpeechRecognition;q=new Q;q.continuous=true;q.interimResults=true;o.addEventListener("click",function(){q.lang=z.lang?z.lang:"en-US";o.classList.contains("pai-recording")?q.stop():q.start();o.classList.toggle("pai-recording")});q.onresult=function(e){if(o.classList.contains("pai-recording")){for(var f=[],l=0;l<e.results.length;l++)f.push(e.results[l][0].transcript);i.value=
16
+ f.join("");E();i.scrollTop=i.scrollHeight;i.focus();v()}};q.onend=function(){o.classList.remove("pai-recording");i.select();v()};q.onerror=function(e){b.add({message:"Speech recognition error: "+e.error,type:"error"})}}s=document.createElement("div");s.classList.add("pai-send-button");s.title=a.sendTitle;s.innerHTML='<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 0 24 24" width="24px" fill="#000000"><path d="M0 0h24v24H0V0z" fill="none"/><path d="M4 12l1.41 1.41L11 7.83V20h2V7.83l5.58 5.59L20 12l-8-8-8 8z"/></svg>';
17
+ s.addEventListener("click",function(){b.send()});D.appendChild(s);b.dom.appendChild(D);A=document.createElement("div");A.classList.add("pai-loader");J=document.createElement("span");J.classList.add("pai-loader-message");A.appendChild(J);for(var d=1;d<=3;d++){var c=document.createElement("div");c.classList.add("pai-loader-dot");A.appendChild(c)}b.clear();a.theme&&b.setTheme(a.theme);a.brandColor&&b.setBrandColor(a.brandColor);v()};this.show=function(){b.dom.classList.remove("pai-hidden");i.focus()};
18
+ this.hide=function(){b.dom.classList.add("pai-hidden")};this.add=function(a){var d=a.message,c=document.createElement("div");c.classList.add("pai-message");var e=a.type;e||(e="user-message");c.classList.add("pai-"+e);if(e==="agent-response"){c.classList.add("markdown-body");if(F)d=d.replace(/<img src="\/profound-ai\/image\?file=/g,'<img src="'+F+"/profound-ai/image?file=");c.innerHTML=d;c.querySelectorAll("a").forEach(function(f){f.addEventListener("click",function(){pui.skipConfirm=true;setTimeout(function(){pui.skipConfirm=
19
+ false},250)})});c.querySelectorAll("span.pai-citation").forEach(function(f){function l(){if(j&&!j.matches(":hover")){f.removeChild(j);j=null}}var j,h;f.addEventListener("mouseenter",function(){if(!j)if(f.getAttribute("data-citation")){j=document.createElement("div");j.classList.add("pai-tooltip-content");j.innerHTML=f.getAttribute("data-citation");f.appendChild(j);var r=f.getBoundingClientRect();j.style.left=r.left+"px";j.style.top=r.top-j.offsetHeight-5+"px";j.addEventListener("mouseenter",function(){clearTimeout(h)});
20
+ j.addEventListener("mouseleave",function(){l()})}});f.addEventListener("mouseleave",function(){h=setTimeout(l,100)})});if(a.replace)(a=k.lastChild)&&a.classList.contains("pai-agent-response")&&a.parentNode.removeChild(a)}else c.innerText=d;k.appendChild(c);k.scrollTop=k.scrollHeight};this.clear=function(){o.classList.contains("pai-recording")&&q.stop();i.value="";k.innerHTML="";b.greeting&&b.add({message:b.greeting,type:"greeting"});b.setHeading(b.heading);b.setBrandColor(B);v();I=x=null};this.setTheme=
21
+ function(a){G=a;G=typeof G!=="string"?"light":G.toLowerCase();G==="dark"?b.dom.classList.add("pai-dark"):b.dom.classList.remove("pai-dark")};this.setBrandColor=function(a){B=a;if(a=b.dom.querySelector(".pai-heading")){a.style.backgroundColor=null;a.style.backgroundImage=null;a.classList.remove("pai-branded")}t&&t.classList.remove("pai-branded");s.style.backgroundColor=null;if(B){var d=S(B,-30);if(a){a.style.backgroundColor=B;a.style.backgroundImage="linear-gradient(to right, "+B+", "+d+")";a.classList.add("pai-branded")}t&&
22
+ a&&t.classList.add("pai-branded");s.style.backgroundColor=B}};this.setHeading=function(a){var d=b.dom.querySelector(".pai-heading");if(a){if(d===null){d=document.createElement("div");d.classList.add("pai-heading");b.dom.prepend(d);E()}d.innerText=a}else if(d!==null){d.remove();E()}};this.send=function(){if(i.value!=="")if(!b.isLoading()){if(o.classList.contains("pai-recording")){q.stop();o.classList.toggle("pai-recording")}b.onSend&&b.onSend(i.value);b.add({message:i.value});H=[];var a={};a.message=
23
+ i.value;if(x)a.threadId=x;var d="/profound-ai/chat";if(g()){a.agentData=p();a.agentFile=Ext.c("centerPanel").e().title.replace(/\*/g,"").trim();w=pui.streamingModelList.includes(a.agentData.aiAgent.model);d="/ide/profound-ai/chat"}else a.agent=b.agent;var c=b.data;if(typeof c==="function")c=c();if(b.data)a.data=c;i.value="";E();i.focus();b.showLoader();c={"Content-Type":"application/json"};if(w){c.Connection="keep-alive";c["Response-Type"]="stream"}if(L){var e=L;if(typeof e==="function")e=e();c.Authorization=
24
+ "Bearer "+e}fetch(F+d,{method:"POST",headers:c,body:JSON.stringify(a)}).then(function(f){return w?f.body.getReader():f.json()}).then(function(f){w?n(f):C(f)})["catch"](function(f){b.hideLoader();b.add({message:"Error: "+f.message,type:"error"})})}};this.poll=function(){if(!(!x||!I||!K)){var a={};a.threadId=x;a.runId=I;a.modelKey=K;var d="/profound-ai/poll";if(g())d="/ide/profound-ai/poll";fetch(F+d,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(a)}).then(function(c){return c.json()}).then(function(c){C(c)})["catch"](function(c){b.hideLoader();
25
+ b.add({message:"Error: "+c.message,type:"error"})})}};this.showLoader=function(a){a||(a=P);J.innerText=a;if(!b.isLoading()){w?b.add({message:y,type:"agent-response"}):k.appendChild(A);v()}k.scrollTop=k.scrollHeight};this.hideLoader=function(){if(b.isLoading()){if(w)for(var a=k.querySelectorAll(".pai-inline-loader"),d=a.length-1;d>=0;d--)a[d].parentNode.removeChild(a[d]);else k.removeChild(A);v()}};this.isLoading=function(){if(w)return k.querySelectorAll(".pai-inline-loader").length>0;return A.parentNode===
26
+ k};this.destroy=function(){if(b.dom){b.dom.parentNode.removeChild(b.dom);b.dom=null}};this.removeEmbedIcon=function(){profound.ai.removeEmbedIcon()}};profound.ai.d=function(g){if(!document.querySelector('link[href="'+g+'"]')){var p=document.createElement("link");p.rel="stylesheet";p.href=g;document.head.appendChild(p)}};
27
+ profound.ai.b=function(g,p){if(document.querySelector('script[src="'+g+'"]'))typeof p==="function"&&p();else{var m=document.createElement("script");m.type="text/javascript";m.src=g;m.onload=function(){typeof p==="function"&&p()};document.head.appendChild(m)}};
28
+ profound.ai.startAgent=function(g,p){g||(g={});var m="";if(g.server)m=g.server;if(!p&&g.agent)fetch(m+"/profound-ai/attributes",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({agent:g.agent})}).then(function(n){return n.json()}).then(function(n){if(n.status==="error")throw Error(n.message);n=n.attributes;for(var C in n)if(g[C]===undefined)g[C]=n[C];profound.ai.startAgent(g,true)})["catch"](function(n){throw Error("Unable to start AI Agent: "+n.message);});else{if(!g.container)g.container=
29
+ document.body;g.stream&&profound.ai.b(m+"/marked/marked.min.js");profound.ai.d(m+"/profoundui/proddata/css/markdown.css");profound.ai.d(m+"/profoundui/proddata/css/profoundai.css");profound.ai.agent&&profound.ai.agent.destroy();if(g.embed){if(!profound.ai.embedIcon){profound.ai.embedIcon=document.createElement("div");profound.ai.embedIcon.classList.add("pai-embed-icon");profound.ai.embedIcon.innerHTML='<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 0 24 24" width="24px" fill="#000000"><path d="M0 0h24v24H0z" fill="none"/><path d="M21 6h-2v9H6v2c0 .55.45 1 1 1h11l4 4V7c0-.55-.45-1-1-1zm-4 6V3c0-.55-.45-1-1-1H3c-.55 0-1 .45-1 1v14l4-4h10c.55 0 1-.45 1-1z"/></svg>';
30
+ g.container.appendChild(profound.ai.embedIcon);m="Ask AI Agent";if(g.embedIconTitle)m=g.embedIconTitle;profound.ai.embedIcon.title=m;profound.ai.embedIcon.addEventListener("click",function(){var n=Object.assign({},g);delete n.embed;profound.ai.startAgent(n)})}}else{profound.ai.agent=new profound.ai.Chat;profound.ai.agent.init(g);profound.ai.agent.show();return profound.ai.agent}}};
27
31
  profound.ai.removeEmbedIcon=function(){if(profound.ai.embedIcon){profound.ai.embedIcon.parentNode.removeChild(profound.ai.embedIcon);profound.ai.embedIcon=null}};