profoundjs 7.24.1 → 7.26.0

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,36 +1,38 @@
1
1
  window.profound||(window.profound={});window.profound.ai||(window.profound.ai={});window.pui||(window.pui={});
2
- profound.ai.Chat=function(){function h(){return window.pui&&window.pui.ide&&window.pui.ide.designerId?!0:!1}function p(){clearTimeout(T);B=J=null;b.hideLoader();t.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>';t.title=b.config.o||"Send this message";b.abortController=null}function v(){var a=Ext.i("centerPanel").l(),
3
- c={};a.isAIAgent&&a.aiAgent&&(c.aiAgent=a.aiAgent);a.isAIAgent&&a.dataAccess&&(c.dataAccess=a.dataAccess);Object.assign(c,Object.fromEntries(Object.entries(a.pjsModule).filter(function(d){return"function"!==typeof d[1]})));return c}function q(){function a(){var d=m.lastChild.querySelectorAll(".pai-chart");if(0!==d.length)if(profound.ai.g){for(var e=0;e<d.length;e++){var g=d[e],n=JSON.parse(g.getAttribute("data-config"));g.removeAttribute("data-config");g.chart=new window.Chart(g.querySelector("canvas"),
4
- n);g=g.querySelector("span");g.parentNode.removeChild(g)}m.scrollTop=m.scrollHeight}else c++,20>c&&setTimeout(a,1E3)}var c=0;a()}function K(a){function c(){a.read().then(function(n){var l=n.value;if(n.done)p(),q();else{n=d.decode(l).split("\n");for(l=0;l<n.length-1;l++){var k=n[l];if(k){k=JSON.parse(k);k.threadId&&(B=k.threadId);if("error"===k.status){b.hideLoader();b.add({message:"Error: "+k.message,type:"error"});return}if("calling"===k.status){var x=m.lastChild;k=x.innerHTML.replace('<span class="pai-loader-dot pai-inline-loader"></span>',
5
- "")+'<p>Calling <span class="pai-function-name">'+k["function"]+"</span>.</p>";b.add({message:k+'<span class="pai-loader-dot pai-inline-loader"></span>',type:"agent-response",replace:!0})}else if("calls completed"===k.status){x=m.lastChild;var y="<p>";y=1===k.count?y+"Call completed.":y+(k.count+" calls completed.");y+="</p>";y=x.innerHTML.replace('<span class="pai-loader-dot pai-inline-loader"></span>',"")+y;b.add({message:y+'<span class="pai-loader-dot pai-inline-loader"></span>',type:"agent-response",
6
- replace:!0})}else{"file"===k.status&&(e=e.replace(k.placeholderUrl,k.fileUrl));e+=k.text;if(k.charts){if(!profound.ai.g){var ba=window.define;window.define=void 0;profound.ai.h("https://cdn.jsdelivr.net/npm/chart.js@4/dist/chart.umd.min.js",function(){window.define=ba;profound.ai.g=!0})}g=k.charts}if(g)for(var U in g)e=e.replace(U,'<div class="pai-chart" data-config="'+JSON.stringify(g[U]).replace(/"/g,"&quot;")+'"><span>Loading chart...</span><canvas></canvas></div>');x=e&&"function"===typeof window.marked?
7
- window.marked(e+'<span class="pai-loader-dot pai-inline-loader"></span>'):e+'<span class="pai-loader-dot pai-inline-loader"></span>';"citation"===k.status&&O.push(k);for(k=0;k<O.length;k++)y=O[k],x=x.replace(y.citationPlaceholder,y.citationContent);b.add({message:x,type:"agent-response",replace:!0})}}}c()}})["catch"](function(n){"AbortError"===n.name?p():(b.hideLoader(),b.add({message:"Error: "+n.message,type:"error"}))})}var d=new TextDecoder("utf-8"),e="",g;c()}function V(a){var c=a.status;a.threadId&&
8
- (B=a.threadId);a.runId&&(J=a.runId);a.modelKey&&(R=a.modelKey);if(a.message){var d=a.message,e="agent-response";"error"===a.status&&(d="Error: "+d,e="error");"failed"===a.status&&(d="Failed: "+d,e="error");"cancelled"===a.status&&(d="Cancelled",e="error");"expired"===a.status&&(d="Chat Expired",e="error");if(a.charts){if(!profound.ai.g){var g=window.define;window.define=void 0;profound.ai.h("https://cdn.jsdelivr.net/npm/chart.js@4/dist/chart.umd.min.js",function(){window.define=g;profound.ai.g=!0})}var n=
9
- a.charts,l;for(l in n)d=d.replace(l,'<div class="pai-chart" data-config="'+JSON.stringify(n[l]).replace(/"/g,"&quot;")+'"><span>Loading chart...</span><canvas></canvas></div>')}b.add({message:d,type:e});a.charts&&q()}"queued"===c||"in_progress"===c?T=setTimeout(function(){b.poll()},W):p()}function C(){""===f.value||b.isLoading()?t.classList.remove("pai-send-button-active"):t.classList.add("pai-send-button-active");var a="webkitSpeechRecognition"in window||"SpeechRecognition"in window;if(h()){var c=
10
- Ext.i("aiAgentModel").getValue();pui.modelVoiceSettings&&(F=pui.modelVoiceSettings[c]);F||={}}a&&!1===F.enabled&&(a=!1);a?(f.classList.add("pai-with-voice"),r.classList.remove("pai-hidden")):(f.classList.remove("pai-with-voice"),r.classList.add("pai-hidden"))}function P(){if(A){L=window.matchMedia("(orientation: landscape)").matches;var a=b.dom.querySelector(".pai-heading");L?a&&a.classList.add("pai-heading-landscape"):a&&a.classList.remove("pai-heading-landscape");G()}}function X(){A?L!=window.matchMedia("(orientation: landscape)").matches&&
11
- P():700>=window.innerWidth&&!M?(M=!0,L=window.matchMedia("(orientation: landscape)").matches,P()):M&&(M=!1,P())}function G(){var a=A?40:20;f.style.height="1px";a=f.scrollHeight<=a?21:f.scrollHeight;21>a&&(a=21);100<a&&(a=100);m.style.height="calc(100% - "+(a+((A||M)&&L&&b.heading?24:54)+(b.heading?74:0))+"px)";f.style.height=a+"px"}var b=this,z=b.abortController=null,m=null,H=null,f=null,t=null,r=null,B=null,J=null,R=null,W=1E3,E=null,Q=null,Y="Thinking",I="",N="light",u=null,D=!1,F={},S=null,O=[],
12
- Z,w,aa=!1,T=null,A=!1,L=!1,M=!1;window.matchMedia("(orientation: landscape)").addEventListener("change",P);window.addEventListener("resize",X);this.init=function(a){a||={};b.config=a;a.container||(a.container=document.body);void 0===a.closeButton&&(a.closeButton=!0);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...");a.heading&&(b.heading=a.heading);
13
- a.greeting&&(b.greeting=a.greeting);a.agent&&(b.agent=a.agent);a.pollInterval&&(W=a.pollInterval);a.loaderMessage&&(Y=a.loaderMessage,aa=!0);a.server&&(I=a.server);a.data&&(b.data=a.data);a.stream&&(D=a.stream);"object"===typeof a.voice&&(F=a.voice);a.jwt&&(S=a.jwt);A=/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)&&("ontouchstart"in window||1<navigator.maxTouchPoints);b.dom=document.createElement("div");b.dom.classList.add("pai-chat");b.dom.classList.add("pai-hidden");
14
- a.container.appendChild(b.dom);a.closeButton&&(z=document.createElement("div"),z.classList.add("pai-close-button"),z.title=a.closeTitle,z.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>',z.addEventListener("click",function(){if(b.onClose)b.onClose();h()?b.clear():b.hide()}),b.dom.appendChild(z));
15
- m=document.createElement("div");m.classList.add("pai-messages");b.dom.appendChild(m);H=document.createElement("div");H.classList.add("pai-prompt-area");f=document.createElement("textarea");f.classList.add("pai-prompt-box");f.setAttribute("placeholder",a.promptPlaceholder);f.addEventListener("keydown",function(e){"Enter"!==e.key||A||(e.shiftKey||e.preventDefault(),e.stopPropagation(),e.shiftKey||b.send());C()});f.addEventListener("input",function(){G();C()});H.appendChild(f);r=document.createElement("div");
16
- r.classList.add("pai-voice-button");r.title=a.voiceTitle;r.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>';H.appendChild(r);if("webkitSpeechRecognition"in window||"SpeechRecognition"in window)Z=
17
- window.SpeechRecognition||window.webkitSpeechRecognition,w=new Z,w.continuous=!0,w.interimResults=!0,r.addEventListener("click",function(){w.lang=F.lang?F.lang:"en-US";r.classList.contains("pai-recording")?w.stop():w.start();r.classList.toggle("pai-recording")}),w.onresult=function(e){if(r.classList.contains("pai-recording")){for(var g=[],n=0;n<e.results.length;n++)g.push(e.results[n][0].transcript);f.value=g.join("");G();f.scrollTop=f.scrollHeight;f.focus();C()}},w.onend=function(){r.classList.remove("pai-recording");
18
- f.select();C()},w.onerror=function(e){b.add({message:"Speech recognition error: "+e.error,type:"error"})};t=document.createElement("div");t.classList.add("pai-send-button");t.title=a.sendTitle;t.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>';t.addEventListener("click",function(){b.isLoading()&&b.abortController?b.abortController.abort():
19
- b.send()});H.appendChild(t);b.dom.appendChild(H);E=document.createElement("div");E.classList.add("pai-loader");Q=document.createElement("span");Q.classList.add("pai-loader-message");E.appendChild(Q);for(var c=1;3>=c;c++){var d=document.createElement("div");d.classList.add("pai-loader-dot");E.appendChild(d)}b.clear();a.theme&&b.setTheme(a.theme);a.brandColor&&b.setBrandColor(a.brandColor);C()};this.setElementInlineProps=function(a){a?f&&(f.style.padding="0",f.style.lineHeight="0px",f.style.fontSize=
20
- "0px",f.style.minHeight="0",f.style.height="0px",f.style.boxSizing="content-box",f.style.border="none"):f&&(f.style.removeProperty("padding"),f.style.removeProperty("line-height"),f.style.removeProperty("min-height"),f.style.removeProperty("box-sizing"),f.style.removeProperty("border"),f.style.removeProperty("font-size"))};this.show=function(){b.dom.classList.remove("pai-hidden");h()||b.setElementInlineProps();X();A||setTimeout(function(){f.focus()},1E3)};this.hide=function(){b.dom.classList.add("pai-hidden")};
21
- this.add=function(a){var c=a.message,d=document.createElement("div");d.classList.add("pai-message");A&&d.classList.add("pai-message-mobile");var e=a.type;e||="user-message";d.classList.add("pai-"+e);"agent-response"===e?(d.classList.add("markdown-body"),I&&(c=c.replace(/<img src="\/profound-ai\/image\?file=/g,'<img src="'+I+"/profound-ai/image?file="),c=c.replace(/="\/profound-ai\/file\?file=/g,'="'+I+"/profound-ai/file?file=")),d.innerHTML=c,d.querySelectorAll("a").forEach(function(g){g.addEventListener("click",
22
- function(){pui.skipConfirm=!0;setTimeout(function(){pui.skipConfirm=!1},250)})}),d.querySelectorAll("span.pai-citation").forEach(function(g){function n(){l&&!l.matches(":hover")&&(g.removeChild(l),l=null)}var l,k;g.addEventListener("mouseenter",function(){if(!l&&g.getAttribute("data-citation")){l=document.createElement("div");l.classList.add("pai-tooltip-content");l.innerHTML=g.getAttribute("data-citation");g.appendChild(l);var x=g.getBoundingClientRect();l.style.left=x.left+"px";l.style.top=x.top-
23
- l.offsetHeight-5+"px";l.addEventListener("mouseenter",function(){clearTimeout(k)});l.addEventListener("mouseleave",function(){n()})}});g.addEventListener("mouseleave",function(){k=setTimeout(n,100)})}),a.replace&&(a=m.lastChild)&&a.classList.contains("pai-agent-response")&&a.parentNode.removeChild(a)):d.innerText=c;m.appendChild(d);m.scrollTop=m.scrollHeight};this.clear=function(){r.classList.contains("pai-recording")&&w.stop();f.value="";m.innerHTML="";b.greeting&&b.add({message:b.greeting,type:"greeting"});
24
- b.setHeading(b.heading);b.setBrandColor(u);C();J=B=null};this.setTheme=function(a){N=a;N="string"!==typeof N?"light":N.toLowerCase();"dark"===N?b.dom.classList.add("pai-dark"):b.dom.classList.remove("pai-dark")};this.setBrandColor=function(a){u=a;if(a=b.dom.querySelector(".pai-heading"))a.style.backgroundColor=null,a.style.backgroundImage=null,a.classList.remove("pai-branded");z&&z.classList.remove("pai-branded");t.style.backgroundColor=null;if(u){if("string"!==typeof u||7!==u.length||"#"!==u.substring(0,
25
- 1))var c=u;else{var d=parseInt(u.substring(1,3),16),e=parseInt(u.substring(3,5),16);c=parseInt(u.substring(5,7),16);d=parseInt(70*d/100);e=parseInt(70*e/100);c=parseInt(70*c/100);d=255>d?d:255;e=255>e?e:255;c=255>c?c:255;d=1==d.toString(16).length?"0"+d.toString(16):d.toString(16);e=1==e.toString(16).length?"0"+e.toString(16):e.toString(16);c=1==c.toString(16).length?"0"+c.toString(16):c.toString(16);c="#"+d+e+c}a&&(a.style.backgroundColor=u,a.style.backgroundImage="linear-gradient(to right, "+u+
26
- ", "+c+")",a.classList.add("pai-branded"));z&&a&&z.classList.add("pai-branded");t.style.backgroundColor=u}};this.setHeading=function(a){var c=b.dom.querySelector(".pai-heading");a?(h()||b.setElementInlineProps(!0),null===c&&(c=document.createElement("div"),c.classList.add("pai-heading"),b.dom.prepend(c),G()),c.innerText=a):null!==c&&(c.remove(),G())};this.send=function(){if(""!==f.value&&!b.isLoading()){r.classList.contains("pai-recording")&&(w.stop(),r.classList.toggle("pai-recording"));if(b.onSend)b.onSend(f.value);
27
- b.add({message:f.value});O=[];var a={};a.message=f.value;B&&(a.threadId=B);var c="/profound-ai/chat";h()?(a.agentData=v(),(c=(a.agentData.dataAccess||[]).flatMap(g=>(g.m||[]).map(n=>n.column)).join(", "))&&(a.message="SYSTEM: Only these columns are allowed: "+c+".\n"+a.message),a.agentFile=Ext.i("centerPanel").l().title.replace(/\*/g,"").trim(),D=pui.streamingModelList.includes(a.agentData.aiAgent.model),c="/ide/profound-ai/chat"):a.agent=b.agent;var d=b.data;"function"===typeof d&&(d=d());b.data&&
28
- (a.data=d);f.value="";G();A?m.focus():f.focus();b.abortController=new AbortController;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="M6 6h12v12H6z"/></svg>';t.title="Stop";b.showLoader();d={"Content-Type":"application/json"};D&&(d.Connection="keep-alive",d["Response-Type"]="stream");if(pui.appJob&&pui.appJob.authToken)d.Authorization="Bearer "+pui.appJob.authToken;else if(S){var e=S;"function"===
29
- typeof e&&(e=e());d.Authorization="Bearer "+e}fetch(I+c,{method:"POST",headers:d,body:JSON.stringify(a),signal:b.abortController.signal}).then(function(g){return D?g.body.getReader():g.json()}).then(function(g){D?K(g):V(g)})["catch"](function(g){"AbortError"===g.name?p():(b.hideLoader(),b.add({message:"Error: "+g.message,type:"error"}))})}};this.poll=function(){if(B&&J&&R){var a={};a.threadId=B;a.runId=J;a.modelKey=R;var c="/profound-ai/poll";h()&&(c="/ide/profound-ai/poll");fetch(I+c,{method:"POST",
30
- headers:{"Content-Type":"application/json"},body:JSON.stringify(a),signal:b.abortController.signal}).then(function(d){return d.json()}).then(function(d){V(d)})["catch"](function(d){"AbortError"===d.name?p():(b.hideLoader(),b.add({message:"Error: "+d.message,type:"error"}))})}};this.showLoader=function(a){a||=b.config.loaderMessage||Y;Q.innerText=a;b.isLoading()||(D?b.add({message:aa?a:'<span class="pai-loader-dot pai-inline-loader"></span>',type:"agent-response"}):m.appendChild(E),C(),m.scrollTop=
31
- m.scrollHeight)};this.hideLoader=function(){if(b.isLoading()){if(D)for(var a=m.querySelectorAll(".pai-inline-loader"),c=a.length-1;0<=c;c--)a[c].parentNode.removeChild(a[c]);else m.removeChild(E);C()}};this.isLoading=function(){return D?0<m.querySelectorAll(".pai-inline-loader").length:E.parentNode===m};this.destroy=function(){b.dom&&(b.dom.parentNode.removeChild(b.dom),b.dom=null)};this.removeEmbedIcon=function(){profound.ai.removeEmbedIcon()}};
32
- profound.ai.j=function(h){if(!document.querySelector('link[href="'+h+'"]')){var p=document.createElement("link");p.rel="stylesheet";p.href=h;document.head.appendChild(p)}};profound.ai.h=function(h,p){if(document.querySelector('script[src="'+h+'"]'))"function"===typeof p&&p();else{var v=document.createElement("script");v.type="text/javascript";v.src=h;v.onload=function(){"function"===typeof p&&p()};document.head.appendChild(v)}};
33
- profound.ai.startAgent=function(h,p){h||={};var v="";h.server&&(v=h.server);if(!p&&h.agent)profound.ai.j(v+"/profoundui/proddata/css/markdown.css"),profound.ai.j(v+"/profoundui/proddata/css/profoundai.css"),fetch(v+"/profound-ai/attributes",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({agent:h.agent})}).then(function(q){return q.json()}).then(function(q){if("error"===q.status)throw Error(q.message);q=q.attributes;for(var K in q)void 0===h[K]&&(h[K]=q[K]);profound.ai.startAgent(h,
34
- !0)})["catch"](function(q){throw Error("Unable to start AI Agent: "+q.message);});else if(h.container||(h.container=document.body),h.stream&&profound.ai.h(v+"/marked/marked.min.js"),profound.ai.agent&&profound.ai.agent.destroy(),h.embed)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>',
35
- h.container.appendChild(profound.ai.embedIcon)),profound.ai.embedIcon.title=h.embedIconTitle||"Ask AI Agent",p=profound.ai.embedIcon.cloneNode(!0),p.addEventListener("click",function(){var q=Object.assign({},h);delete q.embed;profound.ai.startAgent(q)}),profound.ai.embedIcon.parentNode.replaceChild(p,profound.ai.embedIcon),profound.ai.embedIcon=p;else return profound.ai.agent=new profound.ai.Chat,profound.ai.agent.init(h),profound.ai.agent.show(),profound.ai.agent};
2
+ profound.ai.Chat=function(){function l(){return window.pui&&window.pui.ide&&window.pui.ide.designerId?!0:!1}function p(){clearTimeout(U);K=null;b.hideLoader();u.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>';u.title=b.config.C||"Send this message";b.abortController=null}function x(){var a=Ext.j("centerPanel").v(),e=
3
+ {};a.isAIAgent&&a.aiAgent&&(e.aiAgent=a.aiAgent);a.isAIAgent&&a.dataAccess&&(e.dataAccess=(a.dataAccess||[]).map(function(c){var d=Array.isArray(c.h)?c.h:[];d=(d.some(function(f){return!0===f.active||!0===f.selected||!0===f.checked||!0===f.A})?d.filter(function(f){return!0===f.active||!0===f.selected||!0===f.checked||!0===f.A}):d.slice()).map(function(f){return Object.assign({},f,{column:f.column||f.name||f.o||f.s||f.m})});return Object.assign({},c,{h:d})}));Object.assign(e,Object.fromEntries(Object.entries(a.pjsModule).filter(function(c){return"function"!==
4
+ typeof c[1]})));return e}function r(){function a(){var c=n.lastChild.querySelectorAll(".pai-chart");if(0!==c.length)if(profound.ai.g){for(var d=0;d<c.length;d++){var f=c[d],m=JSON.parse(f.getAttribute("data-config"));f.removeAttribute("data-config");f.chart=new window.Chart(f.querySelector("canvas"),m);f=f.querySelector("span");f.parentNode.removeChild(f)}n.scrollTop=n.scrollHeight}else e++,20>e&&setTimeout(a,1E3)}var e=0;a()}function L(a){function e(){a.read().then(function(h){var q=h.value;if(h.done)p(),
5
+ r();else{m+=c.decode(q,{stream:!0});h=m.split("\n");m=h.pop();for(q=0;q<h.length;q++){var k=h[q];if(k){k=JSON.parse(k);k.threadId&&(E=k.threadId);if("error"===k.status){b.hideLoader();b.add({message:"Error: "+k.message,type:"error"});return}if("calling"===k.status){var z=n.lastChild;k=z.innerHTML.replace('<span class="pai-loader-dot pai-inline-loader"></span>',"")+'<p>Calling <span class="pai-function-name">'+k["function"]+"</span>.</p>";b.add({message:k+'<span class="pai-loader-dot pai-inline-loader"></span>',
6
+ type:"agent-response",replace:!0})}else if("calls completed"===k.status){z=n.lastChild;var v="<p>";v=1===k.count?v+"Call completed.":v+(k.count+" calls completed.");v+="</p>";v=z.innerHTML.replace('<span class="pai-loader-dot pai-inline-loader"></span>',"")+v;b.add({message:v+'<span class="pai-loader-dot pai-inline-loader"></span>',type:"agent-response",replace:!0})}else if("file"===k.status)k.placeholderUrl&&(d=d.replace(k.placeholderUrl,k.fileUrl));else{k.text&&(d+=k.text);if(k.charts){if(!profound.ai.g){var ca=
7
+ window.define;window.define=void 0;profound.ai.i("https://cdn.jsdelivr.net/npm/chart.js@4/dist/chart.umd.min.js",function(){window.define=ca;profound.ai.g=!0})}f=k.charts}if(f)for(var V in f)d=d.replace(V,'<div class="pai-chart" data-config="'+JSON.stringify(f[V]).replace(/"/g,"&quot;")+'"><span>Loading chart...</span><canvas></canvas></div>');z=d&&"function"===typeof window.marked?window.marked(d+'<span class="pai-loader-dot pai-inline-loader"></span>'):d+'<span class="pai-loader-dot pai-inline-loader"></span>';
8
+ "citation"===k.status&&P.push(k);for(k=0;k<P.length;k++)v=P[k],z.includes(v.citationPlaceholder)?z=z.replace(v.citationPlaceholder,v.citationContent):z.endsWith(v.citationContent)||(z+=v.citationContent);b.add({message:z,type:"agent-response",replace:!0})}}}e()}})["catch"](function(h){"AbortError"===h.name?p():(b.hideLoader(),b.add({message:"Error: "+h.message,type:"error"}))})}var c=new TextDecoder("utf-8"),d="",f,m="";e()}function W(a){var e=a.status;a.threadId&&(E=a.threadId);a.runId&&(K=a.runId);
9
+ a.modelKey&&(S=a.modelKey);if(a.message){var c=a.message,d="agent-response";"error"===a.status&&(c="Error: "+c,d="error");"failed"===a.status&&(c="Failed: "+c,d="error");"cancelled"===a.status&&(c="Cancelled",d="error");"expired"===a.status&&(c="Chat Expired",d="error");if(a.charts){if(!profound.ai.g){var f=window.define;window.define=void 0;profound.ai.i("https://cdn.jsdelivr.net/npm/chart.js@4/dist/chart.umd.min.js",function(){window.define=f;profound.ai.g=!0})}var m=a.charts,h;for(h in m)c=c.replace(h,
10
+ '<div class="pai-chart" data-config="'+JSON.stringify(m[h]).replace(/"/g,"&quot;")+'"><span>Loading chart...</span><canvas></canvas></div>')}b.add({message:c,type:d});a.charts&&r()}"queued"===e||"in_progress"===e?U=setTimeout(function(){b.poll()},X):p()}function C(){""===g.value||b.isLoading()?u.classList.remove("pai-send-button-active"):u.classList.add("pai-send-button-active");var a="webkitSpeechRecognition"in window||"SpeechRecognition"in window;if(l()){var e=Ext.j("aiAgentModel").getValue();pui.modelVoiceSettings&&
11
+ (G=pui.modelVoiceSettings[e]);G||={}}a&&!1===G.enabled&&(a=!1);a?(g.classList.add("pai-with-voice"),t.classList.remove("pai-hidden")):(g.classList.remove("pai-with-voice"),t.classList.add("pai-hidden"))}function Q(){if(B){M=window.matchMedia("(orientation: landscape)").matches;var a=b.dom.querySelector(".pai-heading");M?a&&a.classList.add("pai-heading-landscape"):a&&a.classList.remove("pai-heading-landscape");H()}}function Y(){B?M!=window.matchMedia("(orientation: landscape)").matches&&Q():700>=window.innerWidth&&
12
+ !N?(N=!0,M=window.matchMedia("(orientation: landscape)").matches,Q()):N&&(N=!1,Q())}function H(){var a=B?40:20;g.style.height="1px";a=g.scrollHeight<=a?21:g.scrollHeight;21>a&&(a=21);100<a&&(a=100);n.style.height="calc(100% - "+(a+((B||N)&&M&&b.heading?24:54)+(b.heading?74:0))+"px)";g.style.height=a+"px"}function da(a,e){e=new Set(e.map(function(m){return String(m).toLowerCase()}));var c=String(a||"").split(/[^A-Za-z0-9_]+/).filter(Boolean);a=[];for(var d=0;d<c.length;d++){var f=c[d];/^[A-Za-z_][A-Za-z0-9_]*$/.test(f)&&
13
+ a.push(f)}c=[];d=[];for(f=0;f<a.length;f++)e.has(a[f].toLowerCase())?c.push(a[f]):d.push(a[f]);return{B:c,u:d}}var b=this,A=b.abortController=null,n=null,I=null,g=null,u=null,t=null,E=null,K=null,S=null,X=1E3,F=null,R=null,Z="Thinking",J="",O="light",w=null,D=!1,G={},T=null,P=[],aa,y,ba=!1,U=null,B=!1,M=!1,N=!1;window.matchMedia("(orientation: landscape)").addEventListener("change",Q);window.addEventListener("resize",Y);this.init=function(a){a||={};b.config=a;a.container||(a.container=document.body);
14
+ void 0===a.closeButton&&(a.closeButton=!0);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...");a.heading&&(b.heading=a.heading);a.greeting&&(b.greeting=a.greeting);a.agent&&(b.agent=a.agent);a.pollInterval&&(X=a.pollInterval);a.loaderMessage&&(Z=a.loaderMessage,ba=!0);a.server&&(J=a.server);a.data&&(b.data=a.data);a.stream&&(D=a.stream);"object"===
15
+ typeof a.voice&&(G=a.voice);a.jwt&&(T=a.jwt);B=/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)&&("ontouchstart"in window||1<navigator.maxTouchPoints);b.dom=document.createElement("div");b.dom.classList.add("pai-chat");b.dom.classList.add("pai-hidden");a.container.appendChild(b.dom);a.closeButton&&(A=document.createElement("div"),A.classList.add("pai-close-button"),A.title=a.closeTitle,A.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>',
16
+ A.addEventListener("click",function(){if(b.onClose)b.onClose();l()?b.clear():b.hide()}),b.dom.appendChild(A));n=document.createElement("div");n.classList.add("pai-messages");b.dom.appendChild(n);I=document.createElement("div");I.classList.add("pai-prompt-area");g=document.createElement("textarea");g.classList.add("pai-prompt-box");g.setAttribute("placeholder",a.promptPlaceholder);g.addEventListener("keydown",function(d){"Enter"!==d.key||B||(d.shiftKey||d.preventDefault(),d.stopPropagation(),d.shiftKey||
17
+ b.send());C()});g.addEventListener("input",function(){H();C()});I.appendChild(g);t=document.createElement("div");t.classList.add("pai-voice-button");t.title=a.voiceTitle;t.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>';
18
+ I.appendChild(t);if("webkitSpeechRecognition"in window||"SpeechRecognition"in window)aa=window.SpeechRecognition||window.webkitSpeechRecognition,y=new aa,y.continuous=!0,y.interimResults=!0,t.addEventListener("click",function(){y.lang=G.lang?G.lang:"en-US";t.classList.contains("pai-recording")?y.stop():y.start();t.classList.toggle("pai-recording")}),y.onresult=function(d){if(t.classList.contains("pai-recording")){for(var f=[],m=0;m<d.results.length;m++)f.push(d.results[m][0].transcript);g.value=f.join("");
19
+ H();g.scrollTop=g.scrollHeight;g.focus();C()}},y.onend=function(){t.classList.remove("pai-recording");g.select();C()},y.onerror=function(d){b.add({message:"Speech recognition error: "+d.error,type:"error"})};u=document.createElement("div");u.classList.add("pai-send-button");u.title=a.sendTitle;u.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>';
20
+ u.addEventListener("click",function(){b.isLoading()&&b.abortController?b.abortController.abort():b.send()});I.appendChild(u);b.dom.appendChild(I);F=document.createElement("div");F.classList.add("pai-loader");R=document.createElement("span");R.classList.add("pai-loader-message");F.appendChild(R);for(var e=1;3>=e;e++){var c=document.createElement("div");c.classList.add("pai-loader-dot");F.appendChild(c)}b.clear();a.theme&&b.setTheme(a.theme);a.brandColor&&b.setBrandColor(a.brandColor);C()};this.setElementInlineProps=
21
+ function(a){a?g&&(g.style.padding="0",g.style.lineHeight="0px",g.style.fontSize="0px",g.style.minHeight="0",g.style.height="0px",g.style.boxSizing="content-box",g.style.border="none"):g&&(g.style.removeProperty("padding"),g.style.removeProperty("line-height"),g.style.removeProperty("min-height"),g.style.removeProperty("box-sizing"),g.style.removeProperty("border"),g.style.removeProperty("font-size"))};this.show=function(){b.dom.classList.remove("pai-hidden");l()||b.setElementInlineProps();Y();B||
22
+ setTimeout(function(){g.focus()},1E3)};this.hide=function(){b.dom.classList.add("pai-hidden")};this.add=function(a){var e=a.message,c=document.createElement("div");c.classList.add("pai-message");B&&c.classList.add("pai-message-mobile");var d=a.type;d||="user-message";c.classList.add("pai-"+d);"agent-response"===d?(c.classList.add("markdown-body"),J&&(e=e.replace(/<img src="\/profound-ai\/image\?file=/g,'<img src="'+J+"/profound-ai/image?file="),e=e.replace(/="\/profound-ai\/file\?file=/g,'="'+J+"/profound-ai/file?file=")),
23
+ c.innerHTML=e,c.querySelectorAll("a").forEach(function(f){f.addEventListener("click",function(){pui.skipConfirm=!0;setTimeout(function(){pui.skipConfirm=!1},250)})}),c.querySelectorAll("span.pai-citation").forEach(function(f){function m(){h&&!h.matches(":hover")&&(f.removeChild(h),h=null)}var h,q;f.addEventListener("mouseenter",function(){if(!h&&f.getAttribute("data-citation")){h=document.createElement("div");h.classList.add("pai-tooltip-content");h.innerHTML=f.getAttribute("data-citation");f.appendChild(h);
24
+ var k=f.getBoundingClientRect();h.style.left=k.left+"px";h.style.top=k.top-h.offsetHeight-5+"px";h.addEventListener("mouseenter",function(){clearTimeout(q)});h.addEventListener("mouseleave",function(){m()})}});f.addEventListener("mouseleave",function(){q=setTimeout(m,100)})}),a.replace&&(a=n.lastChild)&&a.classList.contains("pai-agent-response")&&a.parentNode.removeChild(a)):c.innerText=e;n.appendChild(c);n.scrollTop=n.scrollHeight};this.clear=function(){t.classList.contains("pai-recording")&&y.stop();
25
+ g.value="";n.innerHTML="";b.greeting&&b.add({message:b.greeting,type:"greeting"});b.setHeading(b.heading);b.setBrandColor(w);C();K=E=null};this.setTheme=function(a){O=a;O="string"!==typeof O?"light":O.toLowerCase();"dark"===O?b.dom.classList.add("pai-dark"):b.dom.classList.remove("pai-dark")};this.setBrandColor=function(a){w=a;if(a=b.dom.querySelector(".pai-heading"))a.style.backgroundColor=null,a.style.backgroundImage=null,a.classList.remove("pai-branded");A&&A.classList.remove("pai-branded");u.style.backgroundColor=
26
+ null;if(w){if("string"!==typeof w||7!==w.length||"#"!==w.substring(0,1))var e=w;else{var c=parseInt(w.substring(1,3),16),d=parseInt(w.substring(3,5),16);e=parseInt(w.substring(5,7),16);c=parseInt(70*c/100);d=parseInt(70*d/100);e=parseInt(70*e/100);c=255>c?c:255;d=255>d?d:255;e=255>e?e:255;c=1==c.toString(16).length?"0"+c.toString(16):c.toString(16);d=1==d.toString(16).length?"0"+d.toString(16):d.toString(16);e=1==e.toString(16).length?"0"+e.toString(16):e.toString(16);e="#"+c+d+e}a&&(a.style.backgroundColor=
27
+ w,a.style.backgroundImage="linear-gradient(to right, "+w+", "+e+")",a.classList.add("pai-branded"));A&&a&&A.classList.add("pai-branded");u.style.backgroundColor=w}};this.setHeading=function(a){var e=b.dom.querySelector(".pai-heading");a?(l()||b.setElementInlineProps(!0),null===e&&(e=document.createElement("div"),e.classList.add("pai-heading"),b.dom.prepend(e),H()),e.innerText=a):null!==e&&(e.remove(),H())};this.send=function(){if(""!==g.value&&!b.isLoading()){t.classList.contains("pai-recording")&&
28
+ (y.stop(),t.classList.toggle("pai-recording"));if(b.onSend)b.onSend(g.value);b.add({message:g.value});P=[];var a={};a.message=g.value;E&&(a.threadId=E);var e="/profound-ai/chat";if(l()){a.agentData=x();var c=a.agentData&&Array.isArray(a.agentData.dataAccess)?a.agentData.dataAccess:[];e=[];for(var d=0;d<c.length;d++)for(var f=c[d].h||[],m=0;m<f.length;m++){var h=f[m]&&(f[m].column||f[m].name||f[m].o||f[m].s||f[m].m);h&&(h=String(h).trim())&&-1===e.indexOf(h)&&e.push(h)}c=e.join(", ");d=a.message;0<
29
+ e.length&&(0<da(d,e).u.length?a.message="SYSTEM: Only these columns are allowed: "+c+". If the user requests other columns, do not use them; instead, inform the user which columns are allowed and proceed using only allowed columns.\n\n"+d:a.message=d);a.agentFile=Ext.j("centerPanel").v().title.replace(/\*/g,"").trim();D=pui.streamingModelList.includes(a.agentData.aiAgent.model);e="/ide/profound-ai/chat"}else a.agent=b.agent;c=b.data;"function"===typeof c&&(c=c());b.data&&(a.data=c);g.value="";H();
30
+ B?n.focus():g.focus();b.abortController=new AbortController;u.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="M6 6h12v12H6z"/></svg>';u.title="Stop";b.showLoader();c={"Content-Type":"application/json"};D&&(c.Connection="keep-alive",c["Response-Type"]="stream");pui.appJob&&pui.appJob.authToken?c.Authorization="Bearer "+pui.appJob.authToken:T&&(d=T,"function"===typeof d&&(d=d()),c.Authorization=
31
+ "Bearer "+d);fetch(J+e,{method:"POST",headers:c,body:JSON.stringify(a),signal:b.abortController.signal}).then(function(q){return D?q.body.getReader():q.json()}).then(function(q){D?L(q):W(q)})["catch"](function(q){"AbortError"===q.name?p():(b.hideLoader(),b.add({message:"Error: "+q.message,type:"error"}))})}};this.poll=function(){if(E&&K&&S){var a={};a.threadId=E;a.runId=K;a.modelKey=S;var e="/profound-ai/poll";l()&&(e="/ide/profound-ai/poll");fetch(J+e,{method:"POST",headers:{"Content-Type":"application/json"},
32
+ body:JSON.stringify(a),signal:b.abortController.signal}).then(function(c){return c.json()}).then(function(c){W(c)})["catch"](function(c){"AbortError"===c.name?p():(b.hideLoader(),b.add({message:"Error: "+c.message,type:"error"}))})}};this.showLoader=function(a){a||=b.config.loaderMessage||Z;R.innerText=a;b.isLoading()||(D?b.add({message:ba?a:'<span class="pai-loader-dot pai-inline-loader"></span>',type:"agent-response"}):n.appendChild(F),C(),n.scrollTop=n.scrollHeight)};this.hideLoader=function(){if(b.isLoading()){if(D)for(var a=
33
+ n.querySelectorAll(".pai-inline-loader"),e=a.length-1;0<=e;e--)a[e].parentNode.removeChild(a[e]);else n.removeChild(F);C()}};this.isLoading=function(){return D?0<n.querySelectorAll(".pai-inline-loader").length:F.parentNode===n};this.destroy=function(){b.dom&&(b.dom.parentNode.removeChild(b.dom),b.dom=null)};this.removeEmbedIcon=function(){profound.ai.removeEmbedIcon()}};
34
+ profound.ai.l=function(l){if(!document.querySelector('link[href="'+l+'"]')){var p=document.createElement("link");p.rel="stylesheet";p.href=l;document.head.appendChild(p)}};profound.ai.i=function(l,p){if(document.querySelector('script[src="'+l+'"]'))"function"===typeof p&&p();else{var x=document.createElement("script");x.type="text/javascript";x.src=l;x.onload=function(){"function"===typeof p&&p()};document.head.appendChild(x)}};
35
+ profound.ai.startAgent=function(l,p){l||={};var x="";l.server&&(x=l.server);if(!p&&l.agent)profound.ai.l(x+"/profoundui/proddata/css/markdown.css"),profound.ai.l(x+"/profoundui/proddata/css/profoundai.css"),fetch(x+"/profound-ai/attributes",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({agent:l.agent})}).then(function(r){return r.json()}).then(function(r){if("error"===r.status)throw Error(r.message);r=r.attributes;for(var L in r)void 0===l[L]&&(l[L]=r[L]);profound.ai.startAgent(l,
36
+ !0)})["catch"](function(r){throw Error("Unable to start AI Agent: "+r.message);});else if(l.container||(l.container=document.body),l.stream&&profound.ai.i(x+"/marked/marked.min.js"),profound.ai.agent&&profound.ai.agent.destroy(),l.embed)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>',
37
+ l.container.appendChild(profound.ai.embedIcon)),profound.ai.embedIcon.title=l.embedIconTitle||"Ask AI Agent",p=profound.ai.embedIcon.cloneNode(!0),p.addEventListener("click",function(){var r=Object.assign({},l);delete r.embed;profound.ai.startAgent(r)}),profound.ai.embedIcon.parentNode.replaceChild(p,profound.ai.embedIcon),profound.ai.embedIcon=p;else return profound.ai.agent=new profound.ai.Chat,profound.ai.agent.init(l),profound.ai.agent.show(),profound.ai.agent};
36
38
  profound.ai.removeEmbedIcon=function(){profound.ai.embedIcon&&(profound.ai.embedIcon.parentNode.removeChild(profound.ai.embedIcon),profound.ai.embedIcon=null)};