bstp-agent-widget 0.2.123 → 0.2.124
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/angular.cjs +1 -1
- package/dist/angular.css +1 -1
- package/dist/angular.mjs +63 -62
- package/dist/element.cjs +1 -1
- package/dist/element.css +1 -1
- package/dist/element.mjs +63 -62
- package/dist/index.cjs +1 -1
- package/dist/index.mjs +63 -62
- package/dist/shadow.cjs +1 -1
- package/dist/shadow.css +1 -1
- package/dist/shadow.mjs +63 -62
- package/dist/styles.css +1 -1
- package/dist/styles.layer.css +1 -1
- package/package.json +1 -1
package/dist/angular.cjs
CHANGED
|
@@ -399,7 +399,7 @@ Please report this to https://github.com/markedjs/marked.`,e){let e=`<p>An error
|
|
|
399
399
|
`+t+`]`}return r.pop(),i=t,c}}}}))}));function nH(e){let t=e.indexOf(`{`),n=e.indexOf(`[`);return t===-1?n:n===-1?t:Math.min(t,n)}function rH(e){return e===`{`||e===`[`}function iH(e){return e===`}`||e===`]`}function aH(e){return e===`}`?`{`:`[`}function oH(e,t){let n=[],r=!1,i=!1;for(let a=t;a<e.length;a++){let t=e[a]??``;if(r){if(i){i=!1;continue}if(t===`\\`){i=!0;continue}if(t===`"`){r=!1;continue}continue}if(!(t===`"`&&e[a-1]===`\\`)){if(t===`"`){r=!0;continue}if(rH(t)){n.push(t);continue}if(iH(t)&&(n[n.length-1]===aH(t)&&n.pop(),n.length===0))return{end:a+1,openStack:[],inString:!1}}}return{end:null,openStack:n,inString:r}}function sH(e){let t=nH(e);if(t<0)return e;let{end:n,openStack:r,inString:i}=oH(e,t);if(n!==null)return e;let a=``;return i&&(a+=`"`),r.length>0&&(a+=r.reverse().map(e=>e===`{`?`}`:`]`).join(``)),a?`${e}${a}`:e}function cH(e,t){return oH(e,t).end}var lH=l(tH());function uH(e){try{return JSON.parse(e)}catch{return null}}function dH(e){return uH(e)??(()=>{try{return lH.default.parse(e)}catch{return null}})()}function fH(e){return e.replace(/\\r\\n/g,`
|
|
400
400
|
`).replace(/\\n/g,`
|
|
401
401
|
`).replace(/\\t/g,` `).replace(/\\"/g,`"`).replace(/\\\//g,`/`).replace(/\\\\/g,`\\`)}function pH(e){return e&&e.replace(/([{\s,])([A-Za-z0-9_@$-]+)\s*:/g,(e,t,n)=>`${t}"${n}":`)}function mH(e){let t=e.trim();t=t.replace(/[""]/g,`"`).replace(/['']/g,`'`),t=t.replace(/,\s*([}\]])/g,`$1`);try{t=pH(t)}catch{}return t=sH(t),dH(t)}function hH(e){if(!e||typeof e!=`string`)return null;let t=uH(e);if(t!=null)return t;try{let t=lH.default.parse(e);if(t!=null)return t}catch{}if(e.includes(`\\"`)||e.includes(`\\n`)||e.includes(`\\r`)||e.includes(`\\\\`)){let t=dH(fH(e));if(t!=null)return t}try{return mH(e)}catch{return null}}function gH(e){let t=nH(e);if(t<0)return null;let n=cH(e,t);if(n!==null)return{start:t,json:e.slice(t,n).trim(),consumed:n-t};let r=e.slice(t),i=r.search(/\r?\n\r?\n/);return i>20&&(r=r.slice(0,i).trimEnd()),{start:t,json:sH(r).trim(),consumed:r.length}}var _H=`"structuredData":`,vH=`\\"structuredData\\":`;function yH(e){let t=e.indexOf(_H);if(t<0&&(t=e.indexOf(vH)),t<0)return null;let n=t+17,r=e.indexOf(`{`,n);if(r<0||r>n+10)return null;let i=cH(e,r),a,o;i===null?(a=e.slice(t,r).trim()+sH(e.slice(r)).trim(),o=e.length-t):(a=e.slice(t,i).trim(),o=i-t),t===e.indexOf(vH)&&(a=a.replace(/\\"/g,`"`));let s=`{`+a+`}`;return{start:t,fullJson:s,consumed:o}}function bH(e){let t=e.trim();if(!t||t.length<10)return!1;let n=nH(t);return n>=0&&cH(t,n)===null&&t.length-n>10}function xH(e){let t=/^\s*(?:\r?\n)?\s*(?:'{3}|"{3}|`{3})(?:\s*json\s*)?(?:'{3}|"{3}|`{3})?\s*(?:\r?\n)?/i.exec(e);return!t||!/'{3}|"{3}|`{3}/i.test(t[0])?0:t[0].length}function SH(e){return/^\s*(?:[\]}]+\s*)+/.exec(e)?.[0].length??0}function CH(e){return e&&typeof e==`object`?e:null}function wH(e){return Array.isArray(e)?e:[]}function TH(e){if(typeof e==`number`)return Number.isFinite(e)?e:null;if(typeof e==`string`){let t=Number(e);return Number.isFinite(t)?t:null}return null}function EH(e,t,n){let r=TH(e.used)??TH(e.currentValueRaw)??0,i=TH(e.allowance),a=TH(e.remaining),o=i??TH(e.total)??(r!=null&&a!=null?r+a:null)??TH(e.valueRaw)??(r>0?r:0),s=typeof e.unit==`string`?e.unit:``,c=typeof e.name==`string`?e.name:t.toUpperCase();if(o<=0)return null;let l=n?TH(e.percentUsed)??void 0:void 0,u={key:t,label:c,used:r,total:o,unit:s};return l!=null&&(u.percentUsed=l),u}function DH(e){let t=[],n=wH(e?.responseList);for(let e of n){let n=EH(e,typeof e.type==`string`?e.type:`usage`,!0);n&&t.push(n)}return t.length>0?t:null}function OH(e){let t=e.items;if(Array.isArray(t)&&t.length>0){let e=CH(t[0]);if(e)return e}return e}function kH(e){let t=CH(e),n=CH(CH(t?.structuredData)?.data??t?.data);if(!n)return null;let r=DH(n);if(r)return r;let i=wH(n?.usageTypes);if(i.length===0)return null;let a=[];for(let e of i){let t=typeof e.type==`string`?e.type:`usage`,n=OH(e);if(!n)continue;let r=EH(n,t);r&&a.push(r)}return a.length>0?a:null}function AH(e){if(typeof e!=`string`)return null;let t=e.trim();return t.length>0?t:null}function jH(e){if(!e||typeof e!=`object`)return null;let t=e,n=AH(t.buttonText);if(!n)return null;let r=AH(t.targetAgent)??void 0;return{buttonText:n,agentMessage:AH(t.agentMessage)??r??n,...r?{targetAgent:r}:{}}}function MH(e){if(!e||typeof e!=`object`)return null;let t=e;if(!Array.isArray(t.actions))return null;let n=t.actions.map(jH).filter(e=>e!==null);return n.length===0?null:{actions:n}}function NH(e){return e&&typeof e==`object`?e:null}function PH(e){if(typeof e!=`string`)return null;switch(e){case`card`:case`link`:case`chart`:case`highlightBox`:return e;default:return null}}function FH(e){let t=NH(e);if(!t)return null;let n=NH(t.structuredData),r=[NH(n?.visualization)?.type,NH(n?.visualizationConfig)?.visualizationType,n?.visualizationType,NH(t.visualization)?.type,NH(t.visualizationConfig)?.visualizationType,t.visualizationType];for(let e of r)if(typeof e==`string`)return PH(e)??e;return null}function IH(e){if(typeof e!=`string`)return null;let t=e.trim();switch(t){case`accountOverview`:case`customerProfile`:case`offerRecommendation`:case`basket`:case`usageAnalysis`:case`twinInsight`:return t;default:return`unknown`}}function LH(e){let t=NH(e);if(!t)return null;let n=NH(t.structuredData),r=n?.data??t.data,i=NH(n?.visualization),a=NH(t.visualization);return{data:r,visualizationConfig:i?.config??a?.config??t.visualizationConfig,responseType:IH(n?.responseType??t.responseType)}}function RH(e){let t=NH(e);return!t||NH(t.structuredData)?e:typeof t.responseType==`string`||NH(t.visualization)||NH(t.visualizationConfig)||typeof t.visualizationType==`string`||t.data!==void 0?{structuredData:t}:e}function zH(e){let t=NH(e);return t?NH(t.structuredData)||NH(t.visualization)||NH(t.visualizationConfig)||Array.isArray(t.actions)?!0:typeof t.visualizationType==`string`||typeof t.responseType==`string`:!1}var BH=new gE(`widget-config-builder`);function VH(e){let t=MH(e);if(t)return{type:`widget`,config:{type:`actions`,actions:t.actions}};let n=FH(e),r=LH(e),i={visualizationConfig:r?.visualizationConfig,responseType:r?.responseType??void 0};if(!n){let t=r?.data??e;return PV(t)?{type:`widget`,config:{type:`card`,data:t,...i}}:null}if(n===`chart`){let t=e?kH(e):null;return!t||t.length===0?null:{type:`widget`,config:{type:n,items:t,...i}}}if(n===`card`||n===`link`||n===`highlightBox`){let e=r?.data;if(!PV(e))return null;let t=n;if(n===`card`){let e=r?.responseType;e===`accountOverview`?t=`account-overview`:e===`offerRecommendation`&&(t=`offer-card`)}let a={type:t,data:e,...i};return BH.debug(`Creating widget`,{visualizationType:n,responseType:r?.responseType,widgetType:t,config:a}),{type:`widget`,config:a}}return{type:`widget`,config:{type:n}}}var HH=new gE(`useAgentMarkdownRendererElements`),UH={async:!1,breaks:!0,gfm:!0};function WH(e){return AF.parse(e,UH)}function GH(e,t,n){let r=WH(t);return r.trim()?(e.push({type:`markdown`,key:`md-${n}`,content:r}),n+1):n}function KH(e){return["```json",JSON.stringify(e,null,2),"```"].join(`
|
|
402
|
-
`)}function qH(e){let t=e.trim();return!t||!/^[{\[]/.test(t)?null:hH(t)}function JH(e,t){return(0,H.useMemo)(()=>{let n=eH(e),r=qH(n);if(r)return[{type:`markdown`,key:`json-0`,content:WH(KH(r))}];let i=GV(n),a=[],o=0;for(let e of i){if(e.type===`markdown`){o=GH(a,e.content,o);continue}try{let n=KV(e.dsl);if(!n){let t=qH(e.dsl);o=GH(a,t?KH(t):e.raw,o);continue}let r=MV(n,t);if(r.kind===`widget`){a.push({type:`widget`,key:`widget-${o++}`,widget:r.widget});continue}o=GH(a,KH(r.payload),o)}catch(t){HH.error(`Failed to parse widget`,{error:t instanceof Error?t.message:String(t)}),o=GH(a,e.raw,o)}}return a},[e,t])}var YH={agentChatMdRenderer:`_agentChatMdRenderer_5jigp_1`},XH=(0,H.memo)(({content:e,onWidgetEvent:t})=>{let n=JH(e,t);return(0,U.jsx)(q,{className:YH.agentChatMdRenderer,children:n.map(e=>e.type===`markdown`?(0,U.jsx)(ZN,{html:e.content},e.key):(0,U.jsx)(q,{children:e.widget},e.key))})});XH.displayName=`AgentMarkdownRenderer`;var ZH={body:`_body_1vtnd_1`,messageBubble:`_messageBubble_1vtnd_21`,messageBubbleUser:`_messageBubbleUser_1vtnd_33`,userText:`_userText_1vtnd_54`,messageBubbleAssistant:`_messageBubbleAssistant_1vtnd_62`,messageList:`_messageList_1vtnd_84`};function QH({messages:e,isLoading:t,error:n,scrollViewportRef:r,onWidgetEvent:i}){return(0,U.jsx)(Vy,{className:ZH.body,gap:0,children:(0,U.jsx)(sl,{h:`100%`,type:`always`,scrollbarSize:8,offsetScrollbars:!0,viewportRef:r,children:(0,U.jsxs)(Vy,{className:ZH.messageList,gap:0,children:[n&&(0,U.jsx)(Gf,{color:`red`,variant:`light`,radius:`md`,children:n}),e.map(e=>(0,U.jsx)(q,{className:`${ZH.messageBubble} ${e.sentBy===`user`?ZH.messageBubbleUser:ZH.messageBubbleAssistant}`,children:e.sentBy===`assistant`?(0,U.jsx)(XH,{content:e.text,onWidgetEvent:i}):(0,U.jsx)(Xf,{className:ZH.userText,children:e.text})},e.id)),t&&(0,U.jsx)(q,{className:`${ZH.messageBubble} ${ZH.messageBubbleAssistant}`,children:(0,U.jsx)(UM,{messages:[`Thinking`,`Analyzing your request`,`Searching for information`,`Processing data`,`Preparing response`,`Almost there`]})})]})})})}var $H={root:`_root_h7hgt_1`,input:`_input_h7hgt_6`,section:`_section_h7hgt_34`};function eU({composerText:e,onComposerTextChange:t,isLoading:n,isListening:r,onSubmit:i,rightSection:a,rightSectionWidth:o}){return(0,U.jsx)(zb,{placeholder:r?`Listening...`:`Ask me anything...`,value:e,onChange:e=>t(e.currentTarget.value),disabled:n,radius:`md`,size:`md`,rightSection:a,rightSectionWidth:o,rightSectionPointerEvents:`all`,classNames:{root:$H.root,input:$H.input,section:$H.section},styles:{input:{minHeight:`100%`}},onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),i())}})}function tU({size:e,...t}){return(0,U.jsxs)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:2,strokeLinecap:`round`,strokeLinejoin:`round`,...KF(e),...t,children:[(0,U.jsx)(`path`,{d:`M12 2a3 3 0 0 0-3 3v7a3 3 0 0 0 6 0V5a3 3 0 0 0-3-3Z`}),(0,U.jsx)(`path`,{d:`M19 10v2a7 7 0 0 1-14 0v-2`}),(0,U.jsx)(`line`,{x1:`12`,x2:`12`,y1:`19`,y2:`22`})]})}function nU({size:e,...t}){return(0,U.jsx)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:2,strokeLinecap:`round`,strokeLinejoin:`round`,...KF(e),...t,children:(0,U.jsx)(`rect`,{x:`6`,y:`6`,width:`12`,height:`12`,rx:`2`})})}function rU({isListening:e,isLoading:t,onToggleVoice:n,size:r}){let i=Hj();return(0,U.jsx)(dy,{label:e?`Stop recording`:`Voice input`,children:(0,U.jsx)(gu,{onClick:n,disabled:t,size:r??`lg`,radius:`md`,variant:e?`filled`:`subtle`,color:e?`red`:`accent`,"aria-label":e?`Stop voice recording`:`Start voice recording`,styles:{root:e?void 0:{color:i.other.color[`secondary-default`],backgroundColor:`transparent`,boxShadow:`inset 0 0 0 1px ${i.other.color[`secondary-light`]}33`}},children:e?(0,U.jsx)(nU,{size:`sm`}):(0,U.jsx)(tU,{size:`sm`})})})}function iU({size:e,...t}){return(0,U.jsxs)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:2,strokeLinecap:`round`,strokeLinejoin:`round`,...KF(e),...t,children:[(0,U.jsx)(`path`,{d:`m22 2-7 20-4-9-9-4Z`}),(0,U.jsx)(`path`,{d:`M22 2 11 13`})]})}var aU={footer:`_footer_zlzuq_1`,actionGroup:`_actionGroup_zlzuq_8`,poweredBy:`_poweredBy_zlzuq_12`,sendButton:`_sendButton_zlzuq_18`};function oU({composerText:e,onComposerTextChange:t,isLoading:n,isListening:r,isVoiceSupported:i,canSend:a,onSubmit:o,onToggleVoice:s}){let c=i?74:40;return(0,U.jsxs)(Vy,{className:aU.footer,gap:`sm`,children:[(0,U.jsx)(eU,{composerText:e,onComposerTextChange:t,isLoading:n,isListening:r,onSubmit:o,rightSectionWidth:c,rightSection:(0,U.jsxs)(Eu,{className:aU.actionGroup,wrap:`nowrap`,gap:4,align:`center`,children:[i&&(0,U.jsx)(rU,{isListening:r,isLoading:n,onToggleVoice:s,size:30}),(0,U.jsx)(gu,{onClick:o,disabled:!a||n,size:30,radius:`md`,variant:`filled`,color:`accent`,className:aU.sendButton,"aria-label":`Send message`,children:(0,U.jsx)(iU,{size:`sm`})})]})}),(0,U.jsx)(Xf,{ta:`center`,size:`xs`,c:`dimmed`,className:aU.poweredBy,pt:2,children:`Powered by Exceeder · Etiya`})]})}function sU({size:e,...t}){return(0,U.jsxs)(`svg`,{viewBox:`0 0 22 22`,fill:`none`,...KF(e),...t,children:[(0,U.jsx)(`rect`,{x:`4`,y:`4`,width:`14`,height:`2.5`,rx:`1.2`,fill:`currentColor`}),(0,U.jsx)(`rect`,{x:`4`,y:`9.75`,width:`10`,height:`2.5`,rx:`1.2`,fill:`currentColor`,opacity:`0.88`}),(0,U.jsx)(`rect`,{x:`4`,y:`15.5`,width:`14`,height:`2.5`,rx:`1.2`,fill:`currentColor`})]})}function cU({size:e,...t}){return(0,U.jsx)(`svg`,{viewBox:`0 0 15 15`,fill:`none`,xmlns:`http://www.w3.org/2000/svg`,...KF(e),...t,children:(0,U.jsx)(`path`,{d:`M11.7816 4.03157C12.0062 3.80702 12.0062 3.44295 11.7816 3.2184C11.5571 2.99385 11.193 2.99385 10.9685 3.2184L7.50005 6.68682L4.03164 3.2184C3.80708 2.99385 3.44301 2.99385 3.21846 3.2184C2.99391 3.44295 2.99391 3.80702 3.21846 4.03157L6.68688 7.49999L3.21846 10.9684C2.99391 11.193 2.99391 11.557 3.21846 11.7816C3.44301 12.0061 3.80708 12.0061 4.03164 11.7816L7.50005 8.31316L10.9685 11.7816C11.193 12.0061 11.5571 12.0061 11.7816 11.7816C12.0062 11.557 12.0062 11.193 11.7816 10.9684L8.31322 7.49999L11.7816 4.03157Z`,fill:`currentColor`,fillRule:`evenodd`,clipRule:`evenodd`})})}var lU={header:`_header_5x292_19`,headerLeft:`_headerLeft_5x292_31`,headerInfo:`_headerInfo_5x292_36`,orbContainer:`_orbContainer_5x292_40`,orbOuter:`_orbOuter_5x292_54`,orbPulse:`_orbPulse_5x292_1`,orbMiddle:`_orbMiddle_5x292_63`,orbInner:`_orbInner_5x292_72`,orbFloat:`_orbFloat_5x292_1`,headerMeta:`_headerMeta_5x292_85`,statusDot:`_statusDot_5x292_89`,statusText:`_statusText_5x292_103`,closeButton:`_closeButton_5x292_112`,title:`_title_5x292_123`,topSubHeader:`_topSubHeader_5x292_135`,subHeaderLeft:`_subHeaderLeft_5x292_145`,subHeaderIcon:`_subHeaderIcon_5x292_151`,subHeaderTitle:`_subHeaderTitle_5x292_162`,subHeaderStatus:`_subHeaderStatus_5x292_168`};function uU({panelTitle:e,isLoading:t,isOnline:n,onClose:r}){let i=Hj();return(0,U.jsxs)(Ef,{className:lU.header,align:`center`,justify:`space-between`,children:[(0,U.jsxs)(Eu,{className:lU.headerLeft,wrap:`nowrap`,gap:`sm`,align:`center`,children:[(0,U.jsxs)(q,{className:lU.orbContainer,"data-loading":t||void 0,children:[(0,U.jsx)(q,{className:lU.orbOuter}),(0,U.jsx)(q,{className:lU.orbMiddle}),(0,U.jsx)(q,{className:lU.orbInner,children:(0,U.jsx)(sU,{size:`sm`,color:i.other.color[`text-white`]})})]}),(0,U.jsxs)(Vy,{className:lU.headerInfo,gap:2,justify:`center`,children:[(0,U.jsx)(Xf,{className:lU.title,fw:800,children:e}),(0,U.jsxs)(Eu,{className:lU.headerMeta,wrap:`nowrap`,gap:6,align:`center`,children:[(0,U.jsx)(q,{className:lU.statusDot,"data-loading":t||void 0,"data-online":n||void 0}),(0,U.jsx)(Xf,{className:lU.statusText,span:!0,children:t?`Typing…`:n?`Online`:`Offline`})]})]})]}),(0,U.jsx)(gu,{variant:`subtle`,size:`lg`,radius:`md`,onClick:r,className:lU.closeButton,"aria-label":`Close agent chat`,children:(0,U.jsx)(cU,{size:`sm`})})]})}var dU={root:`_root_nkl8r_1`,surface:`_surface_nkl8r_9`,resizeHandle:`_resizeHandle_nkl8r_22`};function fU({visible:e,onClose:t,messages:n,composerText:r,onComposerTextChange:i,isLoading:a,error:o,canSend:s,onSubmit:c,isListening:l,isVoiceSupported:u,onToggleVoice:d,actions:f,onActionClick:p,panelTitle:m,runtimeInfo:h,scrollViewportRef:g,actualWidth:_=420,floatingTop:v=`var(--mantine-custom-space-150)`,floatingHeight:y=`100%`,floatingMaxHeight:b=`calc(100vh - var(--mantine-custom-space-150) - var(--mantine-custom-space-150))`,shellGap:x=`var(--mantine-custom-space-150)`,panelHeaderHeight:S=56,panelResizableWidth:C,panelBorder:w,panelBorderRadius:T,zIndex:E}){let D=h.hasCustomerToken&&h.hasGenaiToken,O=e=>{if(e.type===`action-click`&&e.data){let t=f.find(t=>t.buttonText===e.data?.buttonText);t&&p(t)}};if(!e)return null;let k=typeof T==`number`?`${T}px`:T;return(0,U.jsxs)(q,{className:dU.root,style:{width:_,maxWidth:`calc(100vw - var(--mantine-custom-space-400) - var(--mantine-custom-space-400))`,height:y,maxHeight:b,top:v,right:x,zIndex:E,"--agent-widget-panel-header-height":`${S}px`,"--agent-widget-shell-gap":x,"--agent-widget-panel-border":w,"--agent-widget-panel-radius":k},children:[C&&(0,U.jsx)(q,{onPointerDown:C.handlePointerDown,className:dU.resizeHandle,style:C.style}),(0,U.jsxs)(q,{className:dU.surface,children:[(0,U.jsx)(uU,{panelTitle:m,isLoading:a,isOnline:D,onClose:t}),(0,U.jsx)(QH,{messages:n,isLoading:a,error:o,scrollViewportRef:g,onWidgetEvent:O}),(0,U.jsx)(oU,{composerText:r,onComposerTextChange:i,isLoading:a,isListening:l,isVoiceSupported:u,canSend:s,onSubmit:c,onToggleVoice:d})]})]})}function pU(e){return(0,H.useMemo)(()=>{let t=e===`MULTI`?`MULTI`:`SINGLE`;return{agentType:t,isMultiAgent:t===`MULTI`}},[e])}function mU(e){return typeof e==`object`&&!!e}function hU(e){let t=Number(e);return Number.isFinite(t)&&t>0?t:null}function gU(e){if(Array.isArray(e))return e.filter(mU);if(!mU(e))return[];for(let t of[`data`,`items`,`results`,`content`,`rows`,`list`,`response`]){let n=e[t];if(Array.isArray(n))return n.filter(mU);if(mU(n)){let e=gU(n);if(e.length>0)return e}}for(let t of Object.values(e))if(Array.isArray(t)){let e=t.filter(mU);if(e.length>0)return e}return[]}function _U(e){let t=hU(e.assistantId??e.assistant_id??e.id??e.agentId??e.agent_id??e.appId??e.app_id);if(!t)return null;let n=e.description??e.appDescription??e.app_description??e.label??e.name??e.assistantName??e.assistant_name??e.agentName??e.agent_name??e.title,r=typeof n==`string`&&n.trim().length>0?n.trim():`Agent ${t}`,i=e.assistantKey??e.assistant_key??e.key??e.agentKey??e.agent_key??e.code,a=typeof i==`string`&&i.trim().length>0?i.trim():r.toLowerCase().replace(/\s+/g,`-`),o=e.initialMessage??e.initial_message??e.welcomeMessage??e.welcome_message,s=typeof o==`string`&&o.trim().length>0?o.trim():void 0;return{assistantId:t,label:r,assistantKey:a,...s?{initialMessage:s}:{}}}function vU(e){let t=hU(e.appId??e.app_id??e.id??e.assistantId??e.assistant_id);if(!t)return null;let n=e.description??e.name??e.label??e.title??e.appName??e.app_name,r=typeof n==`string`&&n.trim().length>0?n.trim():`Agent ${t}`,i=e.assistantKey??e.assistant_key??e.key??e.code,a=typeof i==`string`&&i.trim().length>0?i.trim():r.toLowerCase().replace(/\s+/g,`-`),o=e.initialMessage??e.initial_message??e.welcomeMessage??e.welcome_message,s=typeof o==`string`&&o.trim().length>0?o.trim():void 0;return{assistantId:t,label:r,assistantKey:a,...s?{initialMessage:s}:{}}}function yU(e){if(Array.isArray(e.apps)&&e.apps.length>0){let t=e.apps.map(e=>vU(e)).filter(e=>e!==null);if(t.length>0)return t}let t=_U(e);return t?[t]:[]}function bU(e){return gU(e).flatMap(e=>yU(e))}var xU={runtimeInfo:{customerId:null,hasCustomerToken:!1,hasGenaiToken:!1}},SU=fE(e=>({...xU,setRuntimeInfo:t=>e({runtimeInfo:t}),updateCustomerId:t=>e(e=>({runtimeInfo:{...e.runtimeInfo,customerId:t}})),updateCustomerToken:t=>e(e=>({runtimeInfo:{...e.runtimeInfo,hasCustomerToken:t}})),updateGenaiToken:t=>e(e=>({runtimeInfo:{...e.runtimeInfo,hasGenaiToken:t}})),resetRuntimeInfo:()=>e({runtimeInfo:xU.runtimeInfo})}));async function CU(e,t){try{let n=new URLSearchParams;n.set(`username`,atob(e)),n.set(`password`,atob(t));let r=await EE.post(`/login`,n,{anonymous:!0,headers:{"Content-Type":`application/x-www-form-urlencoded`}});return r.data?.access_token&&(vT(r.data.access_token),ST(!1)),r.data}catch(e){throw e}}async function wU(e,t){try{let n=await EE.post(`/tenants/switch`,{tenant_id:e},{anonymous:!0,headers:{Authorization:`Bearer ${t}`}});return n.data?.data?.access_token&&vT(n.data.data.access_token),bT(n.data?.data?.tenant_id??e),ST(!0),n.data}catch(e){throw e}}async function TU(e){try{return(await EE.post(`/agent-message`,e,{anonymous:!0})).data}catch(e){throw e}}async function EU(e){try{return(await EE.post(`/agentic-app-chat`,e,{anonymous:!0})).data}catch(e){throw e}}async function DU(e){let{customerToken:t,tenantId:n,...r}=e;try{return(await EE.post(`/assistant`,r,{anonymous:!0,headers:{Authorization:`Bearer ${t}`,"x-tenant-id":String(n)}})).data}catch(e){throw e}}async function OU(e){let{customerToken:t,tenantId:n,...r}=e;try{return(await EE.post(`/fetch-agentic-app`,r,{anonymous:!0,headers:{Authorization:`Bearer ${t}`,"x-tenant-id":String(n)}})).data}catch(e){throw e}}var kU={loginToGenai:CU,switchTenant:wU,sendAgentMessage:TU,sendAgenticAppChat:EU,fetchAssistants:DU,fetchAgenticApps:OU};function AU({mutationKey:e,mutationFn:t,defaultOptions:n={}}){return function(r){return tS({...n,...r,meta:{...n?.meta,...r?.meta},mutationKey:e,mutationFn:t})}}var jU=AU({mutationKey:[`genai`,`agentic-apps`],mutationFn:async e=>kU.fetchAgenticApps(e)}),MU=AU({mutationKey:[`genai`,`assistants`],mutationFn:async e=>kU.fetchAssistants(e)});function NU(e,t){return e&&t.includes(e)?e:t[0]}function PU(e,t,n){let{mutateAsync:r}=MU(),{mutateAsync:i}=jU(),{isMultiAgent:a}=pU(e),[o,s]=(0,H.useState)(null),c=(0,H.useRef)(null),l=(0,H.useRef)(null),u=_T(),d=yT(),f=d?Number(d):null,p=xT();(0,H.useEffect)(()=>{if(!n){s(null);return}if(!u||!f||Number.isNaN(f)||f<=0||!p){s(null),c.current=null,l.current=null;return}let e=`${a?`multi`:`single`}:${f}:${u}`;if(c.current===e||l.current===e)return;l.current=e;let t=!0;return(async()=>{try{let n=a?await i({page:1,limit:10,customerToken:u,tenantId:f}):await r({page:1,limit:20,agent_type:`SINGLE`,customerToken:u,tenantId:f});if(!t)return;s(bU(n)),c.current=e}catch{t&&(s([]),c.current=null)}finally{l.current===e&&(l.current=null)}})(),()=>{t=!1}},[n,i,r,u,f,a,p]);let m=o??[],h=NU(t,m.map(e=>e.assistantId));return{availableAssistants:m,selectedAssistantId:h,selectedAssistant:m.find(e=>e.assistantId===h)}}function FU(){let e=(0,H.useContext)(kM),{agentType:t}=pU(e?.agentType),{selectedAssistantId:n,selectedAssistant:r}=PU(e?.agentType,e?.assistantId,!!e),i=(0,H.useMemo)(()=>e?{...e,assistantId:n,agentType:t,assistantLabel:r?.label,assistantInitialMessage:r?.initialMessage}:null,[e,t,r,n]);if(!i)throw Error(`AgentConfigContext is missing.`);return i}function IU(){let e=(0,H.useContext)(AM);if(!e)throw Error(`AgentRuntimeContext is missing.`);return e}function LU(){let e=IU();return(0,H.useMemo)(()=>{let t=e?.customerToken;return typeof t!=`string`||t.trim().length===0?null:t},[e?.customerToken])}var RU=AU({mutationKey:[`genai`,`agent-message`],mutationFn:async({payload:e})=>kU.sendAgentMessage(e)}),zU=AU({mutationKey:[`genai`,`agentic-app-chat`],mutationFn:async({payload:e})=>kU.sendAgenticAppChat(e)});function BU(){let e=RU(),t=zU();return{sendChatMessage:(0,H.useCallback)(async n=>{let{agentType:r,message:i,selectedAgentId:a,customerId:o,customerToken:s,chatId:c}=n;return r===`MULTI`?t.mutateAsync({payload:{message:i,app_id:a,...o?{unique_user_id:o}:{}}}):e.mutateAsync({payload:{message:i,chat_id:c,assistant_id:a,is_sync:!0,...o?{unique_user_id:o}:{},tool_headers:{_default:{Authorization:`Bearer ${s}`}}}})},[e,t])}}function VU(e){return e.assistantId??null}function HU(e){return VU(e)?e.assistantInitialMessage??null:null}function UU(e){return e.customerId}function WU(e){return e.customerToken}function GU(e){return e.language??null}function KU(e){if(!e||typeof e!=`object`)return null;let t=e,n=t.message??(Array.isArray(t.messages)?t.messages[0]:null);if(!n||typeof n!=`object`)return null;let r=n.chat_id,i=typeof r==`number`&&Number.isFinite(r)?r:null,a=typeof n.message==`string`?n.message:``,o=typeof n.created_at==`string`?n.created_at:new Date().toISOString();return a?{chatId:i,text:a,createdAt:o}:null}function qU(){let e=globalThis.crypto;return e?.randomUUID?e.randomUUID():`${Date.now()}-${Math.random().toString(16).slice(2)}`}function JU(){let e=IU(),t=LU(),n=FU(),{agentType:r,isMultiAgent:i}=pU(n.agentType),{sendChatMessage:a}=BU(),[o,s]=(0,H.useState)([]),[c,l]=(0,H.useState)(``),[u,d]=(0,H.useState)(null),[f,p]=(0,H.useState)(!1),[m,h]=(0,H.useState)(null),g=(0,H.useRef)(!1),_=VU(n),v=i?n.assistantLabel??`Assistant`:`Assistant`,y=(0,H.useCallback)(e=>{let t={id:qU(),sentBy:`user`,text:e};s(e=>[...e,t])},[]),b=(0,H.useCallback)((e,t)=>{let n={id:qU(),sentBy:`assistant`,text:e,createdAt:t};s(e=>[...e,n])},[]),x=(0,H.useCallback)(async(o,s)=>{if(!o.trim())return;if(l(``),s?.showUserBubble!==!1&&y(o),!e||!n){h(`Chat is not configured.`);return}if(!_){h(`Chat configuration is missing.`);return}let c=UU(e),f=i?null:t;if(!i&&!f){h(`Missing customer token.`);return}p(!0),h(null);try{let e=KU(await a({agentType:r,message:o,selectedAgentId:_,customerId:c||void 0,customerToken:f??``,chatId:u}));if(!e)return;e.chatId!==null&&d(e.chatId),b(e.text,e.createdAt)}catch{h(`Something went wrong. Please try again.`)}finally{p(!1)}},[e,n,u,y,b,a,t,r,i]);return{messages:o,composerText:c,setComposerText:l,isLoading:f,error:m,sendMessage:x,sendInitialMessage:(0,H.useCallback)(async()=>{if(g.current||f||o.length>0||!e||!n||!VU(n))return!1;let t=UU(e),r=HU(n)?.trim(),i=null;return i=r?t?`${r} ${t}`.trim():r:t?`Hello, my customer id is ${t}`:`Hello`,i.trim()?(g.current=!0,await x(i,{showUserBubble:!1}),!0):!1},[e,n,f,o.length,x]),resetChat:(0,H.useCallback)(()=>{s([]),l(``),d(null),h(null),g.current=!1},[]),agentDisplayName:v,canSend:c.trim().length>0}}function YU(e,t){let n=(0,H.useRef)([]);return{actions:(0,H.useMemo)(()=>{let t=[...e].reverse().find(e=>e.sentBy===`assistant`);if(!t)return n.current;let r=QV(t.text).find(e=>e.type===`widget`&&e.config.type===`actions`),i=r?.type===`widget`?r.config.actions??[]:[];return i.length>0&&(n.current=i),n.current},[e]),handleActionClick:(0,H.useCallback)(e=>{t(e.buttonText)},[t])}}function XU(e={}){let{axis:t=`y`,direction:n=1,onResizeChange:r}=e,[i,a]=(0,H.useState)(0),o=(0,H.useRef)({startPos:0,startOffset:0}),{startInteraction:s}=IM(),c=t===`y`?`ns-resize`:t===`x`?`ew-resize`:`nwse-resize`;return{offset:i,handlePointerDown:(0,H.useCallback)(e=>{e.preventDefault(),e.stopPropagation();let l=t===`y`?e.clientY:e.clientX,u=i;o.current={startPos:l,startOffset:u},s({cursor:c,onMove:e=>{let i;i=t===`y`?-(e.clientY-l):(e.clientX-l)*n;let o=u+i;a(o),r?.(o)}})},[i,t,n,c,r,s]),style:{cursor:c,touchAction:`none`}}}var ZU=[`#root main`,`#root`,`main`,`.main-content`,`#app`,`body`];function QU(e,t,n,r,i){let a=(0,H.useRef)(Math.max(280,t??420)),o=(0,H.useRef)(n??!1),s=(0,H.useRef)(null),c=e?.reserveLayoutSpace??!0,l=(0,H.useCallback)(()=>{let t=e?.hostContainerSelector,n=[...t?t.split(`,`).map(e=>e.trim()).filter(Boolean):[],...ZU];for(let e of n){let t=document.querySelector(e);if(t)return t}return document.body},[e?.hostContainerSelector]),u=(0,H.useCallback)(e=>{let t=document.documentElement;if(!c){if(t.style.removeProperty(`--agent-widget-panel-width`),s.current){let{element:e,inlinePaddingBefore:t}=s.current;e.style.paddingRight=t,s.current=null}return}if(e===null?t.style.removeProperty(`--agent-widget-panel-width`):t.style.setProperty(`--agent-widget-panel-width`,`${e}px`),e===null){if(s.current){let{element:e,inlinePaddingBefore:t}=s.current;e.style.paddingRight=t,s.current=null}return}if(!s.current||!document.contains(s.current.element)){let e=l();if(!e)return;s.current={element:e,inlinePaddingBefore:e.style.paddingRight,widthApplied:0}}let{element:n,inlinePaddingBefore:r,widthApplied:i}=s.current;e!==i&&(n.style.paddingRight=r,n.style.paddingRight=`calc(${r||`0px`} + ${e}px)`,s.current.widthApplied=e)},[l,c]),d=XU({axis:`x`,direction:-1,onResizeChange:(0,H.useCallback)(e=>{let n=Math.max(280,(t??420)+e);a.current=n,u(n)},[t,u])});(0,H.useEffect)(()=>{o.current=n??!1},[n]),(0,H.useEffect)(()=>{let e=Math.max(280,t??420);a.current=e,o.current&&u(e)},[t,u]),(0,H.useEffect)(()=>{if(!n){u(null),document.documentElement.removeAttribute(`data-agent-widget-open`);return}return u(a.current),document.documentElement.setAttribute(`data-agent-widget-open`,`true`),()=>{u(null),document.documentElement.removeAttribute(`data-agent-widget-open`)}},[n,u]);let f=d?Math.max(280,(t??420)+d.offset):t??420,p=r===`100%`||r===`100vh`,m=typeof e?.panelGap==`number`?`${e.panelGap}px`:e?.panelGap??`var(--mantine-custom-space-150)`,h=i??0;return{panelResizableWidth:d,actualWidth:f,shellGap:m,floatingTop:h?`calc(${h}px + ${m})`:m,floatingHeight:p?`calc(100vh - ${h}px - ${m} - ${m})`:typeof r==`number`?`${r}px`:r??`100%`,floatingMaxHeight:`calc(100vh - ${h}px - ${m} - ${m})`}}function $U(){let e=IU(),{runtimeInfo:t,setRuntimeInfo:n}=SU(),r=(0,H.useCallback)(async()=>{if(!e){n({customerId:null,hasCustomerToken:!1,hasGenaiToken:!1});return}let t=UU(e),r=await WU(e),i=_T();n({customerId:t,hasCustomerToken:!!r,hasGenaiToken:!!i})},[e,n]);return(0,H.useEffect)(()=>{r()},[e,r]),{runtimeInfo:t,refreshRuntimeInfo:r}}function eW(){let e=IU();return(0,H.useMemo)(()=>e&&GU(e)||`en-US`,[e])}function tW(e={}){let{lang:t=`en-EN`,continuous:n=!0,interimResults:r=!0,onResult:i,onError:a,onTextChange:o,pauseOnSubmit:s=!1}=e,[c,l]=(0,H.useState)(!1),[u,d]=(0,H.useState)(``),[f,p]=(0,H.useState)(!1),m=(0,H.useRef)(null),h=(0,H.useRef)(``),g=(0,H.useRef)(!1),_=(0,H.useRef)(!1),v=(0,H.useRef)(``),y=(0,H.useRef)(``),b=(0,H.useRef)(null),x=(0,H.useRef)(!1),S=(0,H.useRef)(o),C=(0,H.useRef)(c);(0,H.useEffect)(()=>{S.current=o,C.current=c}),(0,H.useEffect)(()=>{let e=window.SpeechRecognition||window.webkitSpeechRecognition;if(typeof e!=`function`){p(!1);return}let o;try{o=new e,p(!0)}catch(e){console.log(`useAgentSpeechToText: Speech recognition is present but not constructable`,e),p(!1);return}return o.lang=t,o.continuous=n,o.interimResults=r,o.onresult=e=>{if(x.current)return;_.current=!0;let t=``,n=``;for(let r=e.resultIndex;r<e.results.length;r++){let i=e.results[r],a=i[0].transcript;i.isFinal?t+=a+` `:n+=a}t&&(h.current=(h.current+` `+t).trim());let r=(h.current+` `+n).trim();if(d(r),i?.(r,!!t),S.current)if(t){b.current!=null&&(cancelAnimationFrame(b.current),b.current=null);let e=v.current.trim(),t=[e,r.replace(e,``).trim()].filter(Boolean).join(` `).trim();v.current=t,S.current(t)}else y.current=r,b.current??=requestAnimationFrame(()=>{b.current=null;let e=y.current;S.current?.(e)})},o.onerror=e=>{console.log(`useAgentSpeechToText: Speech recognition error`,e.error),l(!1),a?.(e.error)},o.onend=()=>{if(g.current||!C.current){l(!1);return}queueMicrotask(()=>{if(!g.current)try{m.current?.start()}catch{l(!1)}})},m.current=o,()=>{m.current&&m.current.stop()}},[t,n,r,i,a]);let w=(0,H.useCallback)(()=>{if(!(!m.current||!f))try{d(``),h.current=``,g.current=!1,_.current=!1,x.current=!1,v.current=``,y.current=``,b.current!=null&&(cancelAnimationFrame(b.current),b.current=null),m.current.start(),l(!0)}catch(e){console.log(`useAgentSpeechToText: Failed to start speech recognition`,e),a?.(`Failed to start speech recognition`)}},[f,a]),T=(0,H.useCallback)(()=>{if(m.current)try{g.current=!0,m.current.stop(),l(!1)}catch(e){console.log(`useAgentSpeechToText: Failed to stop speech recognition`,e)}},[]);return{isListening:c,transcript:u,isSupported:f,startListening:w,stopListening:T,toggleListening:(0,H.useCallback)(()=>{c?T():w()},[c,w,T]),reset:(0,H.useCallback)(()=>{x.current=!0,v.current=``,y.current=``,b.current!=null&&(cancelAnimationFrame(b.current),b.current=null),s&&setTimeout(()=>{x.current=!1},500)},[s])}}var nW={bottom:24,right:24},rW=1e4;function iW(e){return{panelWidth:e?.panelWidth??420,panelHeight:e?.panelHeight??`100%`,panelHeaderHeight:e?.panelHeaderHeight??56,panelTopOffset:e?.panelTopOffset,panelGap:e?.panelGap,panelBorder:e?.panelBorder,panelBorderRadius:e?.panelBorderRadius,zIndex:e?.zIndex??rW,fabPosition:{...typeof e?.fabTopOffset==`number`?{top:e.fabTopOffset}:{bottom:e?.fabBottomOffset??nW.bottom},...typeof e?.fabLeftOffset==`number`?{left:e.fabLeftOffset}:{right:e?.fabRightOffset??nW.right}}}}function aW({isListening:e,stopListening:t,reset:n,sendMessage:r,composerText:i,setComposerText:a,startListening:o,close:s}){return{handleSubmit:()=>{e&&t(),n(),r(i)},handleToggleVoice:()=>{e?t():(a(``),o())},handleClose:()=>{e&&t(),s()}}}var oW=64;function sW(e,t={}){let{enabled:n=!0,behavior:r=`smooth`}=t,i=(0,H.useRef)(null),a=(0,H.useRef)(!0);return(0,H.useEffect)(()=>{let e=i.current;if(!e)return;let t=()=>{a.current=e.scrollHeight-e.scrollTop-e.clientHeight<=oW},n=()=>{t()};return e.addEventListener(`scroll`,n),()=>e.removeEventListener(`scroll`,n)},[]),(0,H.useEffect)(()=>{if(!n||!a.current)return;let e=i.current;if(!e)return;let t=()=>{let t=globalThis.matchMedia?.(`(prefers-reduced-motion: reduce)`)?.matches?`auto`:r;requestAnimationFrame(()=>{let n=Math.max(0,e.scrollHeight-e.clientHeight);e.scrollTo({top:n,behavior:t})})};requestAnimationFrame(()=>requestAnimationFrame(t))},e),i}var cW=AU({mutationKey:[`genai`,`login`],mutationFn:async({serviceAccount:e,serviceKey:t})=>kU.loginToGenai(e,t)}),lW=new gE(`useGenaiLogin`),uW=null,dW=null;function fW(e=!1){let t=(0,H.useContext)(kM),{mutateAsync:n}=cW(),[r,i]=(0,H.useState)(!1),[a,o]=(0,H.useState)(null),[s,c]=(0,H.useState)(null),[l,u]=(0,H.useState)(null);return(0,H.useEffect)(()=>{(async()=>{let r=_T();if(r&&!e){c(r);return}let a=t?.serviceAccount&&t?.serviceKey&&t?.tenantId?{serviceAccount:t.serviceAccount,serviceKey:t.serviceKey,tenantId:t.tenantId}:null;if(!a)return;u(a);let s=`${a.serviceAccount}::${a.serviceKey}`;if(uW===s&&!e){dW&&c(await dW);return}e&&(uW=null,dW=null),uW=s,i(!0),o(null),dW=(async()=>(await n({serviceAccount:a.serviceAccount,serviceKey:a.serviceKey})).access_token??null)();try{c(await dW)}catch(e){lW.error(`GenAI login failed`,{error:e instanceof Error?e.message:String(e)}),o(`Failed to authenticate with GenAI service`)}finally{dW=null,i(!1)}})()},[t,n,e]),{isLoggingIn:r,loginError:a,loginToken:s,genaiInit:l}}var pW=AU({mutationKey:[`genai`,`tenant-switch`],mutationFn:async({tenant_id:e,token:t})=>kU.switchTenant(e,t)}),mW=new gE(`useGenaiTenantSwitch`),hW=null,gW=null;function _W(e,t,n=!1){let{mutateAsync:r}=pW(),[i,a]=(0,H.useState)(!1),[o,s]=(0,H.useState)(null),[c,l]=(0,H.useState)(!1);return(0,H.useEffect)(()=>{(async()=>{if(!e||!t)return;let i=_T();if(i&&i!==e&&!n){l(!0);return}if(gW===e&&!n){hW&&(await hW,l(!!_T()));return}n&&(gW=null,hW=null),gW=e,a(!0),s(null),hW=(async()=>{await r({tenant_id:t,token:e})})();try{await hW,l(!0)}catch(e){mW.error(`GenAI tenant switch failed`,{error:e instanceof Error?e.message:String(e)}),s(`Failed to switch tenant`)}finally{hW=null,a(!1)}})()},[e,t,r,n]),{isSwitching:i,switchError:o,hasToken:c}}function vW(e=!1){let{isLoggingIn:t,loginError:n,loginToken:r,genaiInit:i}=fW(e),{isSwitching:a,switchError:o,hasToken:s}=_W(r,i?.tenantId,e);return{isAuthenticating:t||a,authError:n??o,hasToken:s}}function yW(e={}){let{defaultOpen:t=!1,persist:n=!0}=e,[r,i]=Gt({key:n?zT.PANEL_OPEN:`panel-state-${Date.now()}`,defaultValue:t,getInitialValueInEffect:!1}),a=(0,H.useRef)(!1);return(0,H.useEffect)(()=>{r&&!a.current&&e.onOpen&&(a.current=!0,e.onOpen())},[r,e.onOpen]),(0,H.useEffect)(()=>{let e=document.querySelector(`main`)||document.querySelector(`.main-content`)||document.body;return r?e?.classList.add(`panel-open`):(e?.classList.remove(`panel-open`),e?.style.removeProperty(`margin-right`)),()=>{e?.classList.remove(`panel-open`),e?.style.removeProperty(`margin-right`)}},[r]),{isOpen:r,open:(0,H.useCallback)(async()=>{i(!0),e.onOpen&&!a.current&&(a.current=!0,await e.onOpen())},[i,e.onOpen]),close:(0,H.useCallback)(()=>{i(!1)},[i]),toggle:(0,H.useCallback)(()=>{i(e=>!e)},[i]),setOpen:(0,H.useCallback)(e=>{i(e)},[i])}}function bW({runtime:e,uiOptions:t}){let n=e.forceReAuth,{isAuthenticating:r,hasToken:i}=vW(n),{panelWidth:a,panelHeight:o,panelHeaderHeight:s,panelTopOffset:c,panelBorder:l,panelBorderRadius:u,zIndex:d,fabPosition:f}=iW(t),p=(0,H.useRef)(!1),{messages:m,composerText:h,setComposerText:g,isLoading:_,error:v,sendMessage:y,sendInitialMessage:b,agentDisplayName:x,canSend:S}=JU(),{actions:C,handleActionClick:w}=YU(m,g),{runtimeInfo:T,refreshRuntimeInfo:E}=$U(),{isOpen:D,open:O,close:k}=yW({defaultOpen:!1,persist:!0,onOpen:async()=>{p.current||(p.current=!0,await E())}});(0,H.useEffect)(()=>{(async()=>{p.current&&D&&!r&&i&&await b()&&(p.current=!1)})()},[D,r,i,b]);let A=sW([m.length,_]),{isListening:j,isSupported:M,startListening:N,stopListening:P,reset:ee}=tW({lang:eW(),continuous:!0,pauseOnSubmit:!0,onTextChange:g}),{panelResizableWidth:F,actualWidth:I,shellGap:te,floatingTop:ne,floatingHeight:re,floatingMaxHeight:ie}=QU(t,a,D,o,c),{handleSubmit:L,handleToggleVoice:ae,handleClose:oe}=aW({isListening:j,stopListening:P,reset:ee,sendMessage:y,composerText:h,setComposerText:g,startListening:N,close:k});return(0,U.jsxs)(U.Fragment,{children:[!D&&(0,U.jsx)(VM,{onClick:()=>void O(),zIndex:d,position:f,label:x}),D&&(0,U.jsx)(fU,{visible:!0,onClose:oe,messages:m,composerText:h,onComposerTextChange:g,isLoading:_,error:v,canSend:S,onSubmit:L,actions:C,onActionClick:w,isListening:j,isVoiceSupported:M,onToggleVoice:ae,panelTitle:x,runtimeInfo:T,scrollViewportRef:A,actualWidth:I,floatingTop:ne,floatingHeight:re,floatingMaxHeight:ie,shellGap:te,panelHeaderHeight:s,panelResizableWidth:F,panelBorder:l,panelBorderRadius:u,zIndex:d})]})}function xW(e){return(0,U.jsx)(bW,{...e})}function SW(e,t){if(typeof e==`function`){e(t);return}e&&(e.current=t)}function CW(e){return{url:{app:e.app??``,api:e.api??``,apiPaths:{crm:``,uiAuthz:``}},keycloak:{url:``,realm:``,clientId:``},features:{enableThemeManager:!0}}}var wW=(0,H.forwardRef)((e,t)=>{let{config:n,runtime:r,uiOptions:i,className:a,style:o,rootElement:s}=e,c=(0,H.useRef)(null),l=CW(n);Fe.locale||Fe.activate(`en`),DE(l,n);let u=(0,H.useMemo)(()=>wM({themeName:i?.themeName}),[i?.themeName]);return(0,U.jsx)(FM,{appConfig:l,config:n,runtime:r,theme:(0,H.useMemo)(()=>i?.theme?Hr(u,i.theme):u,[i?.theme,u]),rootElement:s??c.current,children:(0,U.jsx)(`div`,{className:a,ref:e=>{c.current=e,SW(t,e)},style:o,children:(0,U.jsx)(xW,{config:n,runtime:r,uiOptions:i})})})});wW.displayName=`Widget`;var TW=`:root,
|
|
402
|
+
`)}function qH(e){let t=e.trim();return!t||!/^[{\[]/.test(t)?null:hH(t)}function JH(e,t){return(0,H.useMemo)(()=>{let n=eH(e),r=qH(n);if(r)return[{type:`markdown`,key:`json-0`,content:WH(KH(r))}];let i=GV(n),a=[],o=0;for(let e of i){if(e.type===`markdown`){o=GH(a,e.content,o);continue}try{let n=KV(e.dsl);if(!n){let t=qH(e.dsl);o=GH(a,t?KH(t):e.raw,o);continue}let r=MV(n,t);if(r.kind===`widget`){a.push({type:`widget`,key:`widget-${o++}`,widget:r.widget});continue}o=GH(a,KH(r.payload),o)}catch(t){HH.error(`Failed to parse widget`,{error:t instanceof Error?t.message:String(t)}),o=GH(a,e.raw,o)}}return a},[e,t])}var YH={agentChatMdRenderer:`_agentChatMdRenderer_5jigp_1`},XH=(0,H.memo)(({content:e,onWidgetEvent:t})=>{let n=JH(e,t);return(0,U.jsx)(q,{className:YH.agentChatMdRenderer,children:n.map(e=>e.type===`markdown`?(0,U.jsx)(ZN,{html:e.content},e.key):(0,U.jsx)(q,{children:e.widget},e.key))})});XH.displayName=`AgentMarkdownRenderer`;var ZH={body:`_body_1vtnd_1`,messageBubble:`_messageBubble_1vtnd_21`,messageBubbleUser:`_messageBubbleUser_1vtnd_33`,userText:`_userText_1vtnd_54`,messageBubbleAssistant:`_messageBubbleAssistant_1vtnd_62`,messageList:`_messageList_1vtnd_84`};function QH({messages:e,isLoading:t,error:n,scrollViewportRef:r,onWidgetEvent:i}){return(0,U.jsx)(Vy,{className:ZH.body,gap:0,children:(0,U.jsx)(sl,{h:`100%`,type:`always`,scrollbarSize:8,offsetScrollbars:!0,viewportRef:r,children:(0,U.jsxs)(Vy,{className:ZH.messageList,gap:0,children:[n&&(0,U.jsx)(Gf,{color:`red`,variant:`light`,radius:`md`,children:n}),e.map(e=>(0,U.jsx)(q,{className:`${ZH.messageBubble} ${e.sentBy===`user`?ZH.messageBubbleUser:ZH.messageBubbleAssistant}`,children:e.sentBy===`assistant`?(0,U.jsx)(XH,{content:e.text,onWidgetEvent:i}):(0,U.jsx)(Xf,{className:ZH.userText,children:e.text})},e.id)),t&&(0,U.jsx)(q,{className:`${ZH.messageBubble} ${ZH.messageBubbleAssistant}`,children:(0,U.jsx)(UM,{messages:[`Thinking`,`Analyzing your request`,`Searching for information`,`Processing data`,`Preparing response`,`Almost there`]})})]})})})}var $H={root:`_root_h7hgt_1`,input:`_input_h7hgt_6`,section:`_section_h7hgt_34`};function eU({composerText:e,onComposerTextChange:t,isLoading:n,isListening:r,onSubmit:i,rightSection:a,rightSectionWidth:o}){return(0,U.jsx)(zb,{placeholder:r?`Listening...`:`Ask me anything...`,value:e,onChange:e=>t(e.currentTarget.value),disabled:n,radius:`md`,size:`md`,rightSection:a,rightSectionWidth:o,rightSectionPointerEvents:`all`,classNames:{root:$H.root,input:$H.input,section:$H.section},styles:{input:{minHeight:`100%`}},onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),i())}})}function tU({size:e,...t}){return(0,U.jsxs)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:2,strokeLinecap:`round`,strokeLinejoin:`round`,...KF(e),...t,children:[(0,U.jsx)(`path`,{d:`M12 2a3 3 0 0 0-3 3v7a3 3 0 0 0 6 0V5a3 3 0 0 0-3-3Z`}),(0,U.jsx)(`path`,{d:`M19 10v2a7 7 0 0 1-14 0v-2`}),(0,U.jsx)(`line`,{x1:`12`,x2:`12`,y1:`19`,y2:`22`})]})}function nU({size:e,...t}){return(0,U.jsx)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:2,strokeLinecap:`round`,strokeLinejoin:`round`,...KF(e),...t,children:(0,U.jsx)(`rect`,{x:`6`,y:`6`,width:`12`,height:`12`,rx:`2`})})}function rU({isListening:e,isLoading:t,onToggleVoice:n,size:r}){let i=Hj();return(0,U.jsx)(dy,{label:e?`Stop recording`:`Voice input`,children:(0,U.jsx)(gu,{onClick:n,disabled:t,size:r??`lg`,radius:`md`,variant:e?`filled`:`subtle`,color:e?`red`:`accent`,"aria-label":e?`Stop voice recording`:`Start voice recording`,styles:{root:e?void 0:{color:i.other.color[`secondary-default`],backgroundColor:`transparent`,boxShadow:`inset 0 0 0 1px ${i.other.color[`secondary-light`]}33`}},children:e?(0,U.jsx)(nU,{size:`sm`}):(0,U.jsx)(tU,{size:`sm`})})})}function iU({size:e,...t}){return(0,U.jsxs)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:2,strokeLinecap:`round`,strokeLinejoin:`round`,...KF(e),...t,children:[(0,U.jsx)(`path`,{d:`m22 2-7 20-4-9-9-4Z`}),(0,U.jsx)(`path`,{d:`M22 2 11 13`})]})}var aU={footer:`_footer_zlzuq_1`,actionGroup:`_actionGroup_zlzuq_8`,poweredBy:`_poweredBy_zlzuq_12`,sendButton:`_sendButton_zlzuq_18`};function oU({composerText:e,onComposerTextChange:t,isLoading:n,isListening:r,isVoiceSupported:i,canSend:a,onSubmit:o,onToggleVoice:s}){let c=i?74:40;return(0,U.jsxs)(Vy,{className:aU.footer,gap:`sm`,children:[(0,U.jsx)(eU,{composerText:e,onComposerTextChange:t,isLoading:n,isListening:r,onSubmit:o,rightSectionWidth:c,rightSection:(0,U.jsxs)(Eu,{className:aU.actionGroup,wrap:`nowrap`,gap:4,align:`center`,children:[i&&(0,U.jsx)(rU,{isListening:r,isLoading:n,onToggleVoice:s,size:30}),(0,U.jsx)(gu,{onClick:o,disabled:!a||n,size:30,radius:`md`,variant:`filled`,color:`accent`,className:aU.sendButton,"aria-label":`Send message`,children:(0,U.jsx)(iU,{size:`sm`})})]})}),(0,U.jsx)(Xf,{ta:`center`,size:`xs`,c:`dimmed`,className:aU.poweredBy,pt:2,children:`Powered by Exceeder · Etiya`})]})}function sU({size:e,...t}){return(0,U.jsxs)(`svg`,{viewBox:`0 0 22 22`,fill:`none`,...KF(e),...t,children:[(0,U.jsx)(`rect`,{x:`4`,y:`4`,width:`14`,height:`2.5`,rx:`1.2`,fill:`currentColor`}),(0,U.jsx)(`rect`,{x:`4`,y:`9.75`,width:`10`,height:`2.5`,rx:`1.2`,fill:`currentColor`,opacity:`0.88`}),(0,U.jsx)(`rect`,{x:`4`,y:`15.5`,width:`14`,height:`2.5`,rx:`1.2`,fill:`currentColor`})]})}function cU({size:e,...t}){return(0,U.jsx)(`svg`,{viewBox:`0 0 15 15`,fill:`none`,xmlns:`http://www.w3.org/2000/svg`,...KF(e),...t,children:(0,U.jsx)(`path`,{d:`M11.7816 4.03157C12.0062 3.80702 12.0062 3.44295 11.7816 3.2184C11.5571 2.99385 11.193 2.99385 10.9685 3.2184L7.50005 6.68682L4.03164 3.2184C3.80708 2.99385 3.44301 2.99385 3.21846 3.2184C2.99391 3.44295 2.99391 3.80702 3.21846 4.03157L6.68688 7.49999L3.21846 10.9684C2.99391 11.193 2.99391 11.557 3.21846 11.7816C3.44301 12.0061 3.80708 12.0061 4.03164 11.7816L7.50005 8.31316L10.9685 11.7816C11.193 12.0061 11.5571 12.0061 11.7816 11.7816C12.0062 11.557 12.0062 11.193 11.7816 10.9684L8.31322 7.49999L11.7816 4.03157Z`,fill:`currentColor`,fillRule:`evenodd`,clipRule:`evenodd`})})}var lU={header:`_header_8tb8q_19`,headerLeft:`_headerLeft_8tb8q_31`,headerInfo:`_headerInfo_8tb8q_36`,orbContainer:`_orbContainer_8tb8q_40`,orbOuter:`_orbOuter_8tb8q_54`,orbPulse:`_orbPulse_8tb8q_1`,orbMiddle:`_orbMiddle_8tb8q_63`,orbInner:`_orbInner_8tb8q_72`,orbFloat:`_orbFloat_8tb8q_1`,headerMeta:`_headerMeta_8tb8q_85`,statusDot:`_statusDot_8tb8q_89`,statusText:`_statusText_8tb8q_103`,closeButton:`_closeButton_8tb8q_112`,title:`_title_8tb8q_123`,topSubHeader:`_topSubHeader_8tb8q_135`,subHeaderLeft:`_subHeaderLeft_8tb8q_145`,subHeaderIcon:`_subHeaderIcon_8tb8q_151`,subHeaderTitle:`_subHeaderTitle_8tb8q_162`,subHeaderStatus:`_subHeaderStatus_8tb8q_168`};function uU({panelTitle:e,isLoading:t,isOnline:n,onClose:r}){let i=Hj();return(0,U.jsxs)(Ef,{className:lU.header,align:`center`,justify:`space-between`,children:[(0,U.jsxs)(Eu,{className:lU.headerLeft,wrap:`nowrap`,gap:`sm`,align:`center`,children:[(0,U.jsxs)(q,{className:lU.orbContainer,"data-loading":t||void 0,children:[(0,U.jsx)(q,{className:lU.orbOuter}),(0,U.jsx)(q,{className:lU.orbMiddle}),(0,U.jsx)(q,{className:lU.orbInner,children:(0,U.jsx)(sU,{size:`sm`,color:i.other.color[`text-white`]})})]}),(0,U.jsxs)(Vy,{className:lU.headerInfo,gap:2,justify:`center`,children:[(0,U.jsx)(Xf,{className:lU.title,fw:800,children:e}),(0,U.jsxs)(Eu,{className:lU.headerMeta,wrap:`nowrap`,gap:6,align:`center`,children:[(0,U.jsx)(q,{className:lU.statusDot,"data-loading":t||void 0,"data-online":n||void 0}),(0,U.jsx)(Xf,{className:lU.statusText,span:!0,children:t?`Typing…`:n?`Online`:`Offline`})]})]})]}),(0,U.jsx)(gu,{variant:`subtle`,size:`lg`,radius:`md`,onClick:r,className:lU.closeButton,"aria-label":`Close agent chat`,children:(0,U.jsx)(cU,{size:`sm`})})]})}var dU={root:`_root_nkl8r_1`,surface:`_surface_nkl8r_9`,resizeHandle:`_resizeHandle_nkl8r_22`};function fU({visible:e,onClose:t,messages:n,composerText:r,onComposerTextChange:i,isLoading:a,error:o,canSend:s,onSubmit:c,isListening:l,isVoiceSupported:u,onToggleVoice:d,actions:f,onActionClick:p,panelTitle:m,runtimeInfo:h,scrollViewportRef:g,actualWidth:_=420,floatingTop:v=`var(--mantine-custom-space-150)`,floatingHeight:y=`100%`,floatingMaxHeight:b=`calc(100vh - var(--mantine-custom-space-150) - var(--mantine-custom-space-150))`,shellGap:x=`var(--mantine-custom-space-150)`,panelHeaderHeight:S=56,panelResizableWidth:C,panelBorder:w,panelBorderRadius:T,zIndex:E}){let D=h.hasCustomerToken&&h.hasGenaiToken,O=e=>{if(e.type===`action-click`&&e.data){let t=f.find(t=>t.buttonText===e.data?.buttonText);t&&p(t)}};if(!e)return null;let k=typeof T==`number`?`${T}px`:T;return(0,U.jsxs)(q,{className:dU.root,style:{width:_,maxWidth:`calc(100vw - var(--mantine-custom-space-400) - var(--mantine-custom-space-400))`,height:y,maxHeight:b,top:v,right:x,zIndex:E,"--agent-widget-panel-header-height":`${S}px`,"--agent-widget-shell-gap":x,"--agent-widget-panel-border":w,"--agent-widget-panel-radius":k},children:[C&&(0,U.jsx)(q,{onPointerDown:C.handlePointerDown,className:dU.resizeHandle,style:C.style}),(0,U.jsxs)(q,{className:dU.surface,children:[(0,U.jsx)(uU,{panelTitle:m,isLoading:a,isOnline:D,onClose:t}),(0,U.jsx)(QH,{messages:n,isLoading:a,error:o,scrollViewportRef:g,onWidgetEvent:O}),(0,U.jsx)(oU,{composerText:r,onComposerTextChange:i,isLoading:a,isListening:l,isVoiceSupported:u,canSend:s,onSubmit:c,onToggleVoice:d})]})]})}function pU(e){return(0,H.useMemo)(()=>{let t=e===`MULTI`?`MULTI`:`SINGLE`;return{agentType:t,isMultiAgent:t===`MULTI`}},[e])}function mU(e){return typeof e==`object`&&!!e}function hU(e){let t=Number(e);return Number.isFinite(t)&&t>0?t:null}function gU(e){if(Array.isArray(e))return e.filter(mU);if(!mU(e))return[];for(let t of[`data`,`items`,`results`,`content`,`rows`,`list`,`response`]){let n=e[t];if(Array.isArray(n))return n.filter(mU);if(mU(n)){let e=gU(n);if(e.length>0)return e}}for(let t of Object.values(e))if(Array.isArray(t)){let e=t.filter(mU);if(e.length>0)return e}return[]}function _U(e){let t=hU(e.assistantId??e.assistant_id??e.id??e.agentId??e.agent_id??e.appId??e.app_id);if(!t)return null;let n=e.description??e.appDescription??e.app_description??e.label??e.name??e.assistantName??e.assistant_name??e.agentName??e.agent_name??e.title,r=typeof n==`string`&&n.trim().length>0?n.trim():`Agent ${t}`,i=e.assistantKey??e.assistant_key??e.key??e.agentKey??e.agent_key??e.code,a=typeof i==`string`&&i.trim().length>0?i.trim():r.toLowerCase().replace(/\s+/g,`-`),o=e.initialMessage??e.initial_message??e.welcomeMessage??e.welcome_message,s=typeof o==`string`&&o.trim().length>0?o.trim():void 0;return{assistantId:t,label:r,assistantKey:a,...s?{initialMessage:s}:{}}}function vU(e){let t=hU(e.appId??e.app_id??e.id??e.assistantId??e.assistant_id);if(!t)return null;let n=e.description??e.name??e.label??e.title??e.appName??e.app_name,r=typeof n==`string`&&n.trim().length>0?n.trim():`Agent ${t}`,i=e.assistantKey??e.assistant_key??e.key??e.code,a=typeof i==`string`&&i.trim().length>0?i.trim():r.toLowerCase().replace(/\s+/g,`-`),o=e.initialMessage??e.initial_message??e.welcomeMessage??e.welcome_message,s=typeof o==`string`&&o.trim().length>0?o.trim():void 0;return{assistantId:t,label:r,assistantKey:a,...s?{initialMessage:s}:{}}}function yU(e){if(Array.isArray(e.apps)&&e.apps.length>0){let t=e.apps.map(e=>vU(e)).filter(e=>e!==null);if(t.length>0)return t}let t=_U(e);return t?[t]:[]}function bU(e){return gU(e).flatMap(e=>yU(e))}var xU={runtimeInfo:{customerId:null,hasCustomerToken:!1,hasGenaiToken:!1}},SU=fE(e=>({...xU,setRuntimeInfo:t=>e({runtimeInfo:t}),updateCustomerId:t=>e(e=>({runtimeInfo:{...e.runtimeInfo,customerId:t}})),updateCustomerToken:t=>e(e=>({runtimeInfo:{...e.runtimeInfo,hasCustomerToken:t}})),updateGenaiToken:t=>e(e=>({runtimeInfo:{...e.runtimeInfo,hasGenaiToken:t}})),resetRuntimeInfo:()=>e({runtimeInfo:xU.runtimeInfo})}));async function CU(e,t){try{let n=new URLSearchParams;n.set(`username`,atob(e)),n.set(`password`,atob(t));let r=await EE.post(`/login`,n,{anonymous:!0,headers:{"Content-Type":`application/x-www-form-urlencoded`}});return r.data?.access_token&&(vT(r.data.access_token),ST(!1)),r.data}catch(e){throw e}}async function wU(e,t){try{let n=await EE.post(`/tenants/switch`,{tenant_id:e},{anonymous:!0,headers:{Authorization:`Bearer ${t}`}});return n.data?.data?.access_token&&vT(n.data.data.access_token),bT(n.data?.data?.tenant_id??e),ST(!0),n.data}catch(e){throw e}}async function TU(e){try{return(await EE.post(`/agent-message`,e,{anonymous:!0})).data}catch(e){throw e}}async function EU(e){try{return(await EE.post(`/agentic-app-chat`,e,{anonymous:!0})).data}catch(e){throw e}}async function DU(e){let{customerToken:t,tenantId:n,...r}=e;try{return(await EE.post(`/assistant`,r,{anonymous:!0,headers:{Authorization:`Bearer ${t}`,"x-tenant-id":String(n)}})).data}catch(e){throw e}}async function OU(e){let{customerToken:t,tenantId:n,...r}=e;try{return(await EE.post(`/fetch-agentic-app`,r,{anonymous:!0,headers:{Authorization:`Bearer ${t}`,"x-tenant-id":String(n)}})).data}catch(e){throw e}}var kU={loginToGenai:CU,switchTenant:wU,sendAgentMessage:TU,sendAgenticAppChat:EU,fetchAssistants:DU,fetchAgenticApps:OU};function AU({mutationKey:e,mutationFn:t,defaultOptions:n={}}){return function(r){return tS({...n,...r,meta:{...n?.meta,...r?.meta},mutationKey:e,mutationFn:t})}}var jU=AU({mutationKey:[`genai`,`agentic-apps`],mutationFn:async e=>kU.fetchAgenticApps(e)}),MU=AU({mutationKey:[`genai`,`assistants`],mutationFn:async e=>kU.fetchAssistants(e)});function NU(e,t){return e&&t.includes(e)?e:t[0]}function PU(e,t,n){let{mutateAsync:r}=MU(),{mutateAsync:i}=jU(),{isMultiAgent:a}=pU(e),[o,s]=(0,H.useState)(null),c=(0,H.useRef)(null),l=(0,H.useRef)(null),u=_T(),d=yT(),f=d?Number(d):null,p=xT();(0,H.useEffect)(()=>{if(!n){s(null);return}if(!u||!f||Number.isNaN(f)||f<=0||!p){s(null),c.current=null,l.current=null;return}let e=`${a?`multi`:`single`}:${f}:${u}`;if(c.current===e||l.current===e)return;l.current=e;let t=!0;return(async()=>{try{let n=a?await i({page:1,limit:10,customerToken:u,tenantId:f}):await r({page:1,limit:20,agent_type:`SINGLE`,customerToken:u,tenantId:f});if(!t)return;s(bU(n)),c.current=e}catch{t&&(s([]),c.current=null)}finally{l.current===e&&(l.current=null)}})(),()=>{t=!1}},[n,i,r,u,f,a,p]);let m=o??[],h=NU(t,m.map(e=>e.assistantId));return{availableAssistants:m,selectedAssistantId:h,selectedAssistant:m.find(e=>e.assistantId===h)}}function FU(){let e=(0,H.useContext)(kM),{agentType:t}=pU(e?.agentType),{selectedAssistantId:n,selectedAssistant:r}=PU(e?.agentType,e?.assistantId,!!e),i=(0,H.useMemo)(()=>e?{...e,assistantId:n,agentType:t,assistantLabel:r?.label,assistantInitialMessage:r?.initialMessage}:null,[e,t,r,n]);if(!i)throw Error(`AgentConfigContext is missing.`);return i}function IU(){let e=(0,H.useContext)(AM);if(!e)throw Error(`AgentRuntimeContext is missing.`);return e}function LU(){let e=IU();return(0,H.useMemo)(()=>{let t=e?.customerToken;return typeof t!=`string`||t.trim().length===0?null:t},[e?.customerToken])}var RU=AU({mutationKey:[`genai`,`agent-message`],mutationFn:async({payload:e})=>kU.sendAgentMessage(e)}),zU=AU({mutationKey:[`genai`,`agentic-app-chat`],mutationFn:async({payload:e})=>kU.sendAgenticAppChat(e)});function BU(){let e=RU(),t=zU();return{sendChatMessage:(0,H.useCallback)(async n=>{let{agentType:r,message:i,selectedAgentId:a,customerId:o,customerToken:s,chatId:c}=n;return r===`MULTI`?t.mutateAsync({payload:{message:i,app_id:a,...o?{unique_user_id:o}:{}}}):e.mutateAsync({payload:{message:i,chat_id:c,assistant_id:a,is_sync:!0,...o?{unique_user_id:o}:{},tool_headers:{_default:{Authorization:`Bearer ${s}`}}}})},[e,t])}}function VU(e){return e.assistantId??null}function HU(e){return VU(e)?e.assistantInitialMessage??null:null}function UU(e){return e.customerId}function WU(e){return e.customerToken}function GU(e){return e.language??null}function KU(e){if(!e||typeof e!=`object`)return null;let t=e,n=t.message??(Array.isArray(t.messages)?t.messages[0]:null);if(!n||typeof n!=`object`)return null;let r=n.chat_id,i=typeof r==`number`&&Number.isFinite(r)?r:null,a=typeof n.message==`string`?n.message:``,o=typeof n.created_at==`string`?n.created_at:new Date().toISOString();return a?{chatId:i,text:a,createdAt:o}:null}function qU(){let e=globalThis.crypto;return e?.randomUUID?e.randomUUID():`${Date.now()}-${Math.random().toString(16).slice(2)}`}function JU(){let e=IU(),t=LU(),n=FU(),{agentType:r,isMultiAgent:i}=pU(n.agentType),{sendChatMessage:a}=BU(),[o,s]=(0,H.useState)([]),[c,l]=(0,H.useState)(``),[u,d]=(0,H.useState)(null),[f,p]=(0,H.useState)(!1),[m,h]=(0,H.useState)(null),g=(0,H.useRef)(!1),_=VU(n),v=i?n.assistantLabel??`Assistant`:`Assistant`,y=(0,H.useCallback)(e=>{let t={id:qU(),sentBy:`user`,text:e};s(e=>[...e,t])},[]),b=(0,H.useCallback)((e,t)=>{let n={id:qU(),sentBy:`assistant`,text:e,createdAt:t};s(e=>[...e,n])},[]),x=(0,H.useCallback)(async(o,s)=>{if(!o.trim())return;if(l(``),s?.showUserBubble!==!1&&y(o),!e||!n){h(`Chat is not configured.`);return}if(!_){h(`Chat configuration is missing.`);return}let c=UU(e),f=i?null:t;if(!i&&!f){h(`Missing customer token.`);return}p(!0),h(null);try{let e=KU(await a({agentType:r,message:o,selectedAgentId:_,customerId:c||void 0,customerToken:f??``,chatId:u}));if(!e)return;e.chatId!==null&&d(e.chatId),b(e.text,e.createdAt)}catch{h(`Something went wrong. Please try again.`)}finally{p(!1)}},[e,n,u,y,b,a,t,r,i]);return{messages:o,composerText:c,setComposerText:l,isLoading:f,error:m,sendMessage:x,sendInitialMessage:(0,H.useCallback)(async()=>{if(g.current||f||o.length>0||!e||!n||!VU(n))return!1;let t=UU(e),r=HU(n)?.trim(),i=null;return i=r?t?`${r} ${t}`.trim():r:t?`Hello, my customer id is ${t}`:`Hello`,i.trim()?(g.current=!0,await x(i,{showUserBubble:!1}),!0):!1},[e,n,f,o.length,x]),resetChat:(0,H.useCallback)(()=>{s([]),l(``),d(null),h(null),g.current=!1},[]),agentDisplayName:v,canSend:c.trim().length>0}}function YU(e,t){let n=(0,H.useRef)([]);return{actions:(0,H.useMemo)(()=>{let t=[...e].reverse().find(e=>e.sentBy===`assistant`);if(!t)return n.current;let r=QV(t.text).find(e=>e.type===`widget`&&e.config.type===`actions`),i=r?.type===`widget`?r.config.actions??[]:[];return i.length>0&&(n.current=i),n.current},[e]),handleActionClick:(0,H.useCallback)(e=>{t(e.buttonText)},[t])}}function XU(e={}){let{axis:t=`y`,direction:n=1,onResizeChange:r}=e,[i,a]=(0,H.useState)(0),o=(0,H.useRef)({startPos:0,startOffset:0}),{startInteraction:s}=IM(),c=t===`y`?`ns-resize`:t===`x`?`ew-resize`:`nwse-resize`;return{offset:i,handlePointerDown:(0,H.useCallback)(e=>{e.preventDefault(),e.stopPropagation();let l=t===`y`?e.clientY:e.clientX,u=i;o.current={startPos:l,startOffset:u},s({cursor:c,onMove:e=>{let i;i=t===`y`?-(e.clientY-l):(e.clientX-l)*n;let o=u+i;a(o),r?.(o)}})},[i,t,n,c,r,s]),style:{cursor:c,touchAction:`none`}}}var ZU=[`#root main`,`#root`,`main`,`.main-content`,`#app`,`body`];function QU(e,t,n,r,i){let a=(0,H.useRef)(Math.max(280,t??420)),o=(0,H.useRef)(n??!1),s=(0,H.useRef)(null),c=e?.reserveLayoutSpace??!0,l=(0,H.useCallback)(()=>{let t=e?.hostContainerSelector,n=[...t?t.split(`,`).map(e=>e.trim()).filter(Boolean):[],...ZU];for(let e of n){let t=document.querySelector(e);if(t)return t}return document.body},[e?.hostContainerSelector]),u=(0,H.useCallback)(e=>{let t=document.documentElement;if(!c){if(t.style.removeProperty(`--agent-widget-panel-width`),s.current){let{element:e,inlinePaddingBefore:t}=s.current;e.style.paddingRight=t,s.current=null}return}if(e===null?t.style.removeProperty(`--agent-widget-panel-width`):t.style.setProperty(`--agent-widget-panel-width`,`${e}px`),e===null){if(s.current){let{element:e,inlinePaddingBefore:t}=s.current;e.style.paddingRight=t,s.current=null}return}if(!s.current||!document.contains(s.current.element)){let e=l();if(!e)return;s.current={element:e,inlinePaddingBefore:e.style.paddingRight,widthApplied:0}}let{element:n,inlinePaddingBefore:r,widthApplied:i}=s.current;e!==i&&(n.style.paddingRight=r,n.style.paddingRight=`calc(${r||`0px`} + ${e}px)`,s.current.widthApplied=e)},[l,c]),d=XU({axis:`x`,direction:-1,onResizeChange:(0,H.useCallback)(e=>{let n=Math.max(280,(t??420)+e);a.current=n,u(n)},[t,u])});(0,H.useEffect)(()=>{o.current=n??!1},[n]),(0,H.useEffect)(()=>{let e=Math.max(280,t??420);a.current=e,o.current&&u(e)},[t,u]),(0,H.useEffect)(()=>{if(!n){u(null),document.documentElement.removeAttribute(`data-agent-widget-open`);return}return u(a.current),document.documentElement.setAttribute(`data-agent-widget-open`,`true`),()=>{u(null),document.documentElement.removeAttribute(`data-agent-widget-open`)}},[n,u]);let f=d?Math.max(280,(t??420)+d.offset):t??420,p=r===`100%`||r===`100vh`,m=typeof e?.panelGap==`number`?`${e.panelGap}px`:e?.panelGap??`var(--mantine-custom-space-150)`,h=i??0;return{panelResizableWidth:d,actualWidth:f,shellGap:m,floatingTop:h?`calc(${h}px + ${m})`:m,floatingHeight:p?`calc(100vh - ${h}px - ${m} - ${m})`:typeof r==`number`?`${r}px`:r??`100%`,floatingMaxHeight:`calc(100vh - ${h}px - ${m} - ${m})`}}function $U(){let e=IU(),{runtimeInfo:t,setRuntimeInfo:n}=SU(),r=(0,H.useCallback)(async()=>{if(!e){n({customerId:null,hasCustomerToken:!1,hasGenaiToken:!1});return}let t=UU(e),r=await WU(e),i=_T();n({customerId:t,hasCustomerToken:!!r,hasGenaiToken:!!i})},[e,n]);return(0,H.useEffect)(()=>{r()},[e,r]),{runtimeInfo:t,refreshRuntimeInfo:r}}function eW(){let e=IU();return(0,H.useMemo)(()=>e&&GU(e)||`en-US`,[e])}function tW(e={}){let{lang:t=`en-EN`,continuous:n=!0,interimResults:r=!0,onResult:i,onError:a,onTextChange:o,pauseOnSubmit:s=!1}=e,[c,l]=(0,H.useState)(!1),[u,d]=(0,H.useState)(``),[f,p]=(0,H.useState)(!1),m=(0,H.useRef)(null),h=(0,H.useRef)(``),g=(0,H.useRef)(!1),_=(0,H.useRef)(!1),v=(0,H.useRef)(``),y=(0,H.useRef)(``),b=(0,H.useRef)(null),x=(0,H.useRef)(!1),S=(0,H.useRef)(o),C=(0,H.useRef)(c);(0,H.useEffect)(()=>{S.current=o,C.current=c}),(0,H.useEffect)(()=>{let e=window.SpeechRecognition||window.webkitSpeechRecognition;if(typeof e!=`function`){p(!1);return}let o;try{o=new e,p(!0)}catch(e){console.log(`useAgentSpeechToText: Speech recognition is present but not constructable`,e),p(!1);return}return o.lang=t,o.continuous=n,o.interimResults=r,o.onresult=e=>{if(x.current)return;_.current=!0;let t=``,n=``;for(let r=e.resultIndex;r<e.results.length;r++){let i=e.results[r],a=i[0].transcript;i.isFinal?t+=a+` `:n+=a}t&&(h.current=(h.current+` `+t).trim());let r=(h.current+` `+n).trim();if(d(r),i?.(r,!!t),S.current)if(t){b.current!=null&&(cancelAnimationFrame(b.current),b.current=null);let e=v.current.trim(),t=[e,r.replace(e,``).trim()].filter(Boolean).join(` `).trim();v.current=t,S.current(t)}else y.current=r,b.current??=requestAnimationFrame(()=>{b.current=null;let e=y.current;S.current?.(e)})},o.onerror=e=>{console.log(`useAgentSpeechToText: Speech recognition error`,e.error),l(!1),a?.(e.error)},o.onend=()=>{if(g.current||!C.current){l(!1);return}queueMicrotask(()=>{if(!g.current)try{m.current?.start()}catch{l(!1)}})},m.current=o,()=>{m.current&&m.current.stop()}},[t,n,r,i,a]);let w=(0,H.useCallback)(()=>{if(!(!m.current||!f))try{d(``),h.current=``,g.current=!1,_.current=!1,x.current=!1,v.current=``,y.current=``,b.current!=null&&(cancelAnimationFrame(b.current),b.current=null),m.current.start(),l(!0)}catch(e){console.log(`useAgentSpeechToText: Failed to start speech recognition`,e),a?.(`Failed to start speech recognition`)}},[f,a]),T=(0,H.useCallback)(()=>{if(m.current)try{g.current=!0,m.current.stop(),l(!1)}catch(e){console.log(`useAgentSpeechToText: Failed to stop speech recognition`,e)}},[]);return{isListening:c,transcript:u,isSupported:f,startListening:w,stopListening:T,toggleListening:(0,H.useCallback)(()=>{c?T():w()},[c,w,T]),reset:(0,H.useCallback)(()=>{x.current=!0,v.current=``,y.current=``,b.current!=null&&(cancelAnimationFrame(b.current),b.current=null),s&&setTimeout(()=>{x.current=!1},500)},[s])}}var nW={bottom:24,right:24},rW=1e4;function iW(e){return{panelWidth:e?.panelWidth??420,panelHeight:e?.panelHeight??`100%`,panelHeaderHeight:e?.panelHeaderHeight??56,panelTopOffset:e?.panelTopOffset,panelGap:e?.panelGap,panelBorder:e?.panelBorder,panelBorderRadius:e?.panelBorderRadius,zIndex:e?.zIndex??rW,fabPosition:{...typeof e?.fabTopOffset==`number`?{top:e.fabTopOffset}:{bottom:e?.fabBottomOffset??nW.bottom},...typeof e?.fabLeftOffset==`number`?{left:e.fabLeftOffset}:{right:e?.fabRightOffset??nW.right}}}}function aW({isListening:e,stopListening:t,reset:n,sendMessage:r,composerText:i,setComposerText:a,startListening:o,close:s}){return{handleSubmit:()=>{e&&t(),n(),r(i)},handleToggleVoice:()=>{e?t():(a(``),o())},handleClose:()=>{e&&t(),s()}}}var oW=64;function sW(e,t={}){let{enabled:n=!0,behavior:r=`smooth`}=t,i=(0,H.useRef)(null),a=(0,H.useRef)(!0);return(0,H.useEffect)(()=>{let e=i.current;if(!e)return;let t=()=>{a.current=e.scrollHeight-e.scrollTop-e.clientHeight<=oW},n=()=>{t()};return e.addEventListener(`scroll`,n),()=>e.removeEventListener(`scroll`,n)},[]),(0,H.useEffect)(()=>{if(!n||!a.current)return;let e=i.current;if(!e)return;let t=()=>{let t=globalThis.matchMedia?.(`(prefers-reduced-motion: reduce)`)?.matches?`auto`:r;requestAnimationFrame(()=>{let n=Math.max(0,e.scrollHeight-e.clientHeight);e.scrollTo({top:n,behavior:t})})};requestAnimationFrame(()=>requestAnimationFrame(t))},e),i}var cW=AU({mutationKey:[`genai`,`login`],mutationFn:async({serviceAccount:e,serviceKey:t})=>kU.loginToGenai(e,t)}),lW=new gE(`useGenaiLogin`),uW=null,dW=null;function fW(e=!1){let t=(0,H.useContext)(kM),{mutateAsync:n}=cW(),[r,i]=(0,H.useState)(!1),[a,o]=(0,H.useState)(null),[s,c]=(0,H.useState)(null),[l,u]=(0,H.useState)(null);return(0,H.useEffect)(()=>{(async()=>{let r=_T();if(r&&!e){c(r);return}let a=t?.serviceAccount&&t?.serviceKey&&t?.tenantId?{serviceAccount:t.serviceAccount,serviceKey:t.serviceKey,tenantId:t.tenantId}:null;if(!a)return;u(a);let s=`${a.serviceAccount}::${a.serviceKey}`;if(uW===s&&!e){dW&&c(await dW);return}e&&(uW=null,dW=null),uW=s,i(!0),o(null),dW=(async()=>(await n({serviceAccount:a.serviceAccount,serviceKey:a.serviceKey})).access_token??null)();try{c(await dW)}catch(e){lW.error(`GenAI login failed`,{error:e instanceof Error?e.message:String(e)}),o(`Failed to authenticate with GenAI service`)}finally{dW=null,i(!1)}})()},[t,n,e]),{isLoggingIn:r,loginError:a,loginToken:s,genaiInit:l}}var pW=AU({mutationKey:[`genai`,`tenant-switch`],mutationFn:async({tenant_id:e,token:t})=>kU.switchTenant(e,t)}),mW=new gE(`useGenaiTenantSwitch`),hW=null,gW=null;function _W(e,t,n=!1){let{mutateAsync:r}=pW(),[i,a]=(0,H.useState)(!1),[o,s]=(0,H.useState)(null),[c,l]=(0,H.useState)(!1);return(0,H.useEffect)(()=>{(async()=>{if(!e||!t)return;let i=_T();if(i&&i!==e&&!n){l(!0);return}if(gW===e&&!n){hW&&(await hW,l(!!_T()));return}n&&(gW=null,hW=null),gW=e,a(!0),s(null),hW=(async()=>{await r({tenant_id:t,token:e})})();try{await hW,l(!0)}catch(e){mW.error(`GenAI tenant switch failed`,{error:e instanceof Error?e.message:String(e)}),s(`Failed to switch tenant`)}finally{hW=null,a(!1)}})()},[e,t,r,n]),{isSwitching:i,switchError:o,hasToken:c}}function vW(e=!1){let{isLoggingIn:t,loginError:n,loginToken:r,genaiInit:i}=fW(e),{isSwitching:a,switchError:o,hasToken:s}=_W(r,i?.tenantId,e);return{isAuthenticating:t||a,authError:n??o,hasToken:s}}function yW(e={}){let{defaultOpen:t=!1,persist:n=!0}=e,[r,i]=Gt({key:n?zT.PANEL_OPEN:`panel-state-${Date.now()}`,defaultValue:t,getInitialValueInEffect:!1}),a=(0,H.useRef)(!1);return(0,H.useEffect)(()=>{r&&!a.current&&e.onOpen&&(a.current=!0,e.onOpen())},[r,e.onOpen]),(0,H.useEffect)(()=>{let e=document.querySelector(`main`)||document.querySelector(`.main-content`)||document.body;return r?e?.classList.add(`panel-open`):(e?.classList.remove(`panel-open`),e?.style.removeProperty(`margin-right`)),()=>{e?.classList.remove(`panel-open`),e?.style.removeProperty(`margin-right`)}},[r]),{isOpen:r,open:(0,H.useCallback)(async()=>{i(!0),e.onOpen&&!a.current&&(a.current=!0,await e.onOpen())},[i,e.onOpen]),close:(0,H.useCallback)(()=>{i(!1)},[i]),toggle:(0,H.useCallback)(()=>{i(e=>!e)},[i]),setOpen:(0,H.useCallback)(e=>{i(e)},[i])}}function bW({runtime:e,uiOptions:t}){let n=e.forceReAuth,{isAuthenticating:r,hasToken:i}=vW(n),{panelWidth:a,panelHeight:o,panelHeaderHeight:s,panelTopOffset:c,panelBorder:l,panelBorderRadius:u,zIndex:d,fabPosition:f}=iW(t),p=(0,H.useRef)(!1),m=(0,H.useRef)(!1),[h,g]=(0,H.useState)(!1),{messages:_,composerText:v,setComposerText:y,isLoading:b,error:x,sendMessage:S,sendInitialMessage:C,agentDisplayName:w,canSend:T}=JU(),{actions:E,handleActionClick:D}=YU(_,y),{runtimeInfo:O,refreshRuntimeInfo:k}=$U(),{isOpen:A,open:j,close:M}=yW({defaultOpen:!1,persist:!0,onOpen:async()=>{p.current||(p.current=!0,await k()),m.current||g(!0)}});(0,H.useEffect)(()=>{(async()=>{h&&A&&!r&&i&&await C()&&(m.current=!0,g(!1))})()},[A,r,i,C,h]);let N=sW([_.length,b]),{isListening:P,isSupported:ee,startListening:F,stopListening:I,reset:te}=tW({lang:eW(),continuous:!0,pauseOnSubmit:!0,onTextChange:y}),{panelResizableWidth:ne,actualWidth:re,shellGap:ie,floatingTop:L,floatingHeight:ae,floatingMaxHeight:oe}=QU(t,a,A,o,c),{handleSubmit:se,handleToggleVoice:ce,handleClose:le}=aW({isListening:P,stopListening:I,reset:te,sendMessage:S,composerText:v,setComposerText:y,startListening:F,close:M});return(0,U.jsxs)(U.Fragment,{children:[!A&&(0,U.jsx)(VM,{onClick:()=>void j(),zIndex:d,position:f,label:w}),A&&(0,U.jsx)(fU,{visible:!0,onClose:le,messages:_,composerText:v,onComposerTextChange:y,isLoading:b,error:x,canSend:T,onSubmit:se,actions:E,onActionClick:D,isListening:P,isVoiceSupported:ee,onToggleVoice:ce,panelTitle:w,runtimeInfo:O,scrollViewportRef:N,actualWidth:re,floatingTop:L,floatingHeight:ae,floatingMaxHeight:oe,shellGap:ie,panelHeaderHeight:s,panelResizableWidth:ne,panelBorder:l,panelBorderRadius:u,zIndex:d})]})}function xW(e){return(0,U.jsx)(bW,{...e})}function SW(e,t){if(typeof e==`function`){e(t);return}e&&(e.current=t)}function CW(e){return{url:{app:e.app??``,api:e.api??``,apiPaths:{crm:``,uiAuthz:``}},keycloak:{url:``,realm:``,clientId:``},features:{enableThemeManager:!0}}}var wW=(0,H.forwardRef)((e,t)=>{let{config:n,runtime:r,uiOptions:i,className:a,style:o,rootElement:s}=e,c=(0,H.useRef)(null),l=CW(n);Fe.locale||Fe.activate(`en`),DE(l,n);let u=(0,H.useMemo)(()=>wM({themeName:i?.themeName}),[i?.themeName]);return(0,U.jsx)(FM,{appConfig:l,config:n,runtime:r,theme:(0,H.useMemo)(()=>i?.theme?Hr(u,i.theme):u,[i?.theme,u]),rootElement:s??c.current,children:(0,U.jsx)(`div`,{className:a,ref:e=>{c.current=e,SW(t,e)},style:o,children:(0,U.jsx)(xW,{config:n,runtime:r,uiOptions:i})})})});wW.displayName=`Widget`;var TW=`:root,
|
|
403
403
|
:host {
|
|
404
404
|
color-scheme: var(--mantine-color-scheme);
|
|
405
405
|
}
|