@agentica/chat 0.16.1 → 0.16.2

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.
@@ -4817,4 +4817,4 @@ Licensed under The MIT License (http://opensource.org/licenses/MIT)
4817
4817
  }
4818
4818
  `}},Symbol.toStringTag,{value:"Module"}));return Ow})})(Zmt,Zmt.exports);var CWn=Zmt.exports,AWn=vw&&vw.__importDefault||function(o){return o&&o.__esModule?o:{default:o}};Object.defineProperty(zNe,"__esModule",{value:!0});var OWn=IWn,HAe=AWn(CWn),NWn=function(h){var b=h===void 0?{}:h,k=b.theme,O=k===void 0?"default":k;return function(P){var B=[];if((0,OWn.visit)(P,{type:"code",lang:"mermaid"},function(J,U,nt){B.push([J.value,U,nt])}),!B.length)return P;var G=B.map(function(J){var U=J[0],nt="mermaid"+Math.random().toString(36).slice(2);HAe.default.initialize({theme:O});var at=document.createElement("div");return at.innerHTML='<pre><code class="hljs language-mermaid">'.concat(HAe.default.render(nt,U),"</code></pre>"),at.innerHTML});B.forEach(function(J,U){var nt=J[1],at=J[2],it=G[U];at.children.splice(nt,1,{type:"html",value:it})})}},PWn=zNe.default=NWn;function J8(o){return De.jsx(GHn,{remarkPlugins:[PWn],rehypePlugins:[gqn,yWn],components:{img:({...h})=>De.jsx("img",{...h,style:{display:"block",maxWidth:"100%",height:"auto"}})},children:o.children})}function LWn({execute:o}){return De.jsxs(zN.Fragment,{children:[De.jsxs(x3,{variant:"h5",children:[" ",MWn(o)," "]}),De.jsx("hr",{}),De.jsx(x3,{variant:"h6",children:" Description "}),De.jsx(J8,{children:o.operation.function.description}),De.jsx("br",{}),De.jsx(x3,{variant:"h6",children:" Arguments "}),De.jsx(J8,{children:["```json",JSON.stringify(o.arguments,null,2),"```"].join(`
4819
4819
  `)}),De.jsx("br",{}),De.jsx(x3,{variant:"h6",children:" Return Value "}),De.jsx(J8,{children:["```json",JSON.stringify(o.value,null,2),"```"].join(`
4820
- `)})]})}function MWn(o){return o.operation.protocol==="http"?`${o.operation.function.method.toUpperCase()} ${o.operation.function.path}`:o.operation.function.name}function DWn({history:o}){const[h,b]=bn.useState(!1);return De.jsxs(VBt,{elevation:3,style:{marginTop:15,marginBottom:15,marginRight:"15%"},children:[De.jsxs(_X,{children:[De.jsx(WBt,{label:"Function Describer",variant:"outlined",color:"secondary"}),De.jsx(J8,{children:o.text})]}),De.jsx(u7e,{style:{textAlign:"right"},children:De.jsx(Bmt,{startIcon:De.jsx(sOe,{style:{transform:`rotate(${h?180:0}deg)`}}),onClick:()=>b(!h),children:h?"Hide Function Calls":"Show Function Calls"})}),De.jsx(kX,{in:h,timeout:"auto",unmountOnExit:!0,children:De.jsx(_X,{children:o.executes.map(k=>De.jsx(LWn,{execute:k}))})})]})}const RWn=V5(De.jsx("path",{d:"M4 7h16v2H4zm0 6h16v-2H4zm0 4h7v-2H4zm0 4h7v-2H4zm11.41-2.83L14 16.75l-1.41 1.41L15.41 21 20 16.42 18.58 15zM4 3v2h16V3z"}),"Grading");function BWn({selection:o}){const[h,b]=bn.useState(!1);return De.jsxs(VBt,{elevation:3,style:{marginTop:15,marginBottom:15,marginRight:"15%"},children:[De.jsxs(_X,{children:[De.jsx(WBt,{icon:De.jsx(RWn,{}),label:"Function Selector",variant:"outlined",color:"warning"}),De.jsx("br",{}),De.jsx("br",{}),"Operation:",o.operation.protocol==="http"?De.jsxs("ul",{children:[De.jsx("li",{children:o.operation.function.method.toUpperCase()}),De.jsx("li",{children:o.operation.function.path})]}):De.jsx("ul",{children:De.jsx("li",{children:o.operation.function.name})}),De.jsx(J8,{children:o.reason})]}),De.jsx(u7e,{style:{textAlign:"right"},children:De.jsx(Bmt,{onClick:()=>b(!h),children:h?"Hide Function Description":"Show Function Description"})}),De.jsx(kX,{in:h,timeout:"auto",unmountOnExit:!0,children:De.jsx(_X,{children:De.jsx(J8,{children:o.operation.function.description})})})]})}const jWn=V5(De.jsx("path",{d:"M9 11.75c-.69 0-1.25.56-1.25 1.25s.56 1.25 1.25 1.25 1.25-.56 1.25-1.25-.56-1.25-1.25-1.25m6 0c-.69 0-1.25.56-1.25 1.25s.56 1.25 1.25 1.25 1.25-.56 1.25-1.25-.56-1.25-1.25-1.25M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2m0 18c-4.41 0-8-3.59-8-8 0-.29.02-.58.05-.86 2.36-1.05 4.23-2.98 5.21-5.37C11.07 8.33 14.05 10 17.42 10c.78 0 1.53-.09 2.25-.26.21.71.33 1.47.33 2.26 0 4.41-3.59 8-8 8"}),"Face"),FWn=V5(De.jsx("path",{d:"M20 9V7c0-1.1-.9-2-2-2h-3c0-1.66-1.34-3-3-3S9 3.34 9 5H6c-1.1 0-2 .9-2 2v2c-1.66 0-3 1.34-3 3s1.34 3 3 3v4c0 1.1.9 2 2 2h12c1.1 0 2-.9 2-2v-4c1.66 0 3-1.34 3-3s-1.34-3-3-3M7.5 11.5c0-.83.67-1.5 1.5-1.5s1.5.67 1.5 1.5S9.83 13 9 13s-1.5-.67-1.5-1.5M16 17H8v-2h8zm-1-4c-.83 0-1.5-.67-1.5-1.5S14.17 10 15 10s1.5.67 1.5 1.5S15.83 13 15 13"}),"SmartToy");function $Wn({prompt:o}){return De.jsx("div",{style:{display:"flex",justifyContent:o.role==="user"?"flex-end":"flex-start"},children:De.jsx(VBt,{elevation:3,style:{marginTop:15,marginBottom:15,marginLeft:o.role==="user"?"15%":void 0,marginRight:o.role==="assistant"?"15%":void 0,textAlign:o.role==="user"?"right":"left",backgroundColor:o.role==="user"?"lightyellow":void 0},children:De.jsxs(_X,{children:[De.jsx(WBt,{icon:o.role==="user"?De.jsx(jWn,{}):De.jsx(FWn,{}),label:o.role==="user"?"User":"Assistant",variant:"outlined",color:o.role==="user"?"primary":"success"}),De.jsx(J8,{children:o.text})]})})})}function HWn({prompt:o}){return o.type==="text"?De.jsx($Wn,{prompt:o}):o.type==="select"?o.selections.map(h=>De.jsx(BWn,{selection:h})):o.type==="describe"?De.jsx(DWn,{history:o}):null}function zWn(o){return De.jsxs(zN.Fragment,{children:[De.jsx(x3,{variant:"h5",children:" Function Stack "}),De.jsx("hr",{}),o.selections.map(h=>De.jsxs(f9n,{children:[De.jsx(k9n,{expandIcon:De.jsx(sOe,{}),children:De.jsx(x3,{component:"h6",children:h.operation.protocol==="http"?`${h.operation.function.method.toUpperCase()} ${h.operation.function.path}`:h.operation.function.name})}),De.jsxs(m9n,{children:[De.jsx("hr",{}),h.reason,De.jsx("br",{}),De.jsx("br",{}),De.jsx(J8,{children:h.operation.function.description})]})]}))]})}function UWn(o){const h=GWn(o.usage);return De.jsxs(zN.Fragment,{children:[De.jsx(x3,{variant:"h5",children:" Token Usage "}),De.jsx("hr",{}),De.jsxs(DPn,{children:[De.jsx(VPn,{children:De.jsxs(omt,{children:[De.jsx(y3,{children:"Type"}),De.jsx(y3,{children:"Token Usage"}),De.jsx(y3,{children:"Price"})]})}),De.jsxs($Pn,{children:[De.jsxs(omt,{children:[De.jsx(y3,{children:"Total"}),De.jsx(y3,{children:o.usage.aggregate.total.toLocaleString()}),De.jsxs(y3,{children:["$",h.total.toLocaleString()]})]}),De.jsxs(omt,{children:[De.jsx(y3,{children:"Input"}),De.jsx(y3,{children:o.usage.aggregate.input.total.toLocaleString()}),De.jsxs(y3,{children:["$",h.prompt.toLocaleString()]})]}),De.jsxs(omt,{children:[De.jsx(y3,{children:"Output"}),De.jsx(y3,{children:o.usage.aggregate.output.total.toLocaleString()}),De.jsxs(y3,{children:["$",h.completion.toLocaleString()]})]})]})]})]})}function GWn(o){const h=(o.aggregate.input.total-o.aggregate.input.cached)*25e-7+o.aggregate.input.cached*125e-8,b=o.aggregate.output.total*(10/1e6);return{total:h+b,prompt:h,completion:b}}function qWn(o){var h,b;return De.jsxs("div",{style:{padding:25},children:[o.error!==null?De.jsxs(De.Fragment,{children:[De.jsx(x3,{variant:"h5",color:"error",children:"OpenAI Error"}),De.jsx("hr",{}),o.error.message,De.jsx("br",{}),De.jsx("br",{}),"Your OpenAI API key may not valid.",De.jsx("br",{}),De.jsx("br",{}),De.jsx("br",{})]}):null,De.jsx(x3,{variant:"h5",children:"Agent Information"}),De.jsx("hr",{}),De.jsxs("ul",{children:[De.jsxs("li",{children:[" ","Model:",o.vendor.model]}),De.jsxs("li",{children:[" ","Locale:",((h=o.config)==null?void 0:h.locale)??navigator.language]}),De.jsxs("li",{children:["Timezone:"," ",((b=o.config)==null?void 0:b.timezone)??Intl.DateTimeFormat().resolvedOptions().timeZone]})]}),De.jsx("br",{}),De.jsx("br",{}),De.jsx(UWn,{usage:o.usage}),De.jsx("br",{}),De.jsx("br",{}),De.jsx(zWn,{selections:o.selections})]})}const zAe=450;function WWn({agent:o,title:h}){const b=bn.useRef(null),k=bn.useRef(null),O=bn.useRef(null),P=bn.useRef(null),B=bn.useRef(null),[G,J]=bn.useState(null),[U,nt]=bn.useState(""),[at,it]=bn.useState(o.getHistories().slice()),[st,tt]=bn.useState(JSON.parse(JSON.stringify(o.getTokenUsage()))),[Et,Lt]=bn.useState(122),[Rt,oe]=bn.useState(!0),[qt,ke]=bn.useState([]),[mn,pe]=bn.useState(!1),Dn=async Tr=>{await Tr.join(),at.push(Tr.toHistory()),it(at)},qn=async Tr=>{await Tr.join(),at.push(Tr.toHistory()),it(at)},ar=Tr=>{at.push(Tr.toHistory()),it(at),qt.push(Tr.selection),ke(qt)},nr=Tr=>{console.error(Tr)};bn.useEffect(()=>(B.current!==null&&B.current.select(),o.on("text",Dn),o.on("describe",qn),o.on("select",ar),o.on("validate",nr),tt(o.getTokenUsage()),()=>{o.off("text",Dn),o.off("describe",qn),o.off("select",ar),o.off("validate",nr)}),[]);const Me=()=>{setTimeout(()=>{if(b.current===null||k.current===null||O.current===null)return;const Tr=b.current.clientHeight+O.current.clientHeight;Tr!==Et&&Lt(Tr)})},Kn=async()=>{nt(""),oe(!1),Me();try{await o.conversate(U)}catch(je){je instanceof Error?(alert(je.message),J(je)):J(new Error("Unknown error"));return}at.splice(0,at.length),at.push(...o.getHistories()),it(at),tt(o.getTokenUsage()),oe(!0);const Tr=o.getHistories().filter(je=>je.type==="select").map(je=>je.selections).flat();for(const je of o.getHistories().filter(Xs=>Xs.type==="cancel").map(Xs=>Xs.selections).flat()){const Xs=Tr.findIndex(nl=>nl.operation.protocol===je.operation.protocol&&nl.operation.controller.name===je.operation.controller.name&&nl.operation.function.name===je.operation.function.name);Xs!==-1&&Tr.splice(Xs,1)}ke(Tr)},Xt=async Tr=>{Tr.key==="Enter"&&Tr.shiftKey===!1&&(Rt===!1?Tr.preventDefault():await Kn())},nn=async()=>{if(P.current===null)return;const Tr=await dBn(P.current,{}),je=document.createElement("a");je.download="nestia-chat-screenshot.png",je.href=Tr,je.click(),je.remove()},Je=tP(),dr=ANn(Je.breakpoints.down("lg")),pi=()=>De.jsx("div",{style:{overflowY:"auto",height:"100%",width:dr?"100%":`calc(100% - ${zAe}px)`,margin:0,backgroundColor:"lightblue"},children:De.jsx(v8e,{style:{paddingBottom:50,width:"100%",minHeight:"100%",backgroundColor:"lightblue",margin:0},ref:P,children:at.map(Tr=>De.jsx(HWn,{prompt:Tr})).filter(Tr=>Tr!==null)})}),ia=()=>De.jsx("div",{style:{width:dr?void 0:zAe,height:"100%",overflowY:"auto",backgroundColor:"#eeeeee"},children:De.jsx(v8e,{maxWidth:!1,onClick:dr?()=>pe(!1):void 0,children:De.jsx(qWn,{vendor:o.getVendor(),config:o.getConfig(),usage:st,selections:qt,error:G})})});return De.jsxs("div",{style:{width:"100%",height:"100%"},children:[De.jsx(d8e,{ref:b,position:"relative",component:"div",children:De.jsxs(B8e,{children:[De.jsx(x3,{variant:"h6",component:"div",sx:{flexGrow:1},children:h??"Agentica Chatbot"}),dr?De.jsxs(De.Fragment,{children:[De.jsx(h8e,{onClick:void nn().catch(()=>{}),children:De.jsx(bCe,{})}),De.jsx(h8e,{onClick:()=>pe(!0),children:De.jsx(wRn,{})})]}):De.jsx(Bmt,{color:"inherit",startIcon:De.jsx(bCe,{}),onClick:void nn().catch(()=>{}),children:"Screenshot Capture"})]})}),De.jsx("div",{ref:k,style:{width:"100%",height:`calc(100% - ${Et}px)`,display:"flex",flexDirection:"row"},children:dr?De.jsxs(De.Fragment,{children:[pi(),De.jsx(rNn,{anchor:"right",open:mn,onClose:()=>pe(!1),children:ia()})]}):De.jsxs(De.Fragment,{children:[pi(),ia()]})}),De.jsx(d8e,{ref:O,position:"static",component:"div",color:"inherit",children:De.jsxs(B8e,{children:[De.jsx(ibt,{inputRef:B,fullWidth:!0,placeholder:"Conversate with AI Chatbot",value:U,multiline:!0,onKeyUp:Tr=>void Xt(Tr).catch(()=>{}),onChange:Tr=>{nt(Tr.target.value),Me()}}),De.jsx(Bmt,{variant:"contained",style:{marginLeft:10},startIcon:De.jsx(vRn,{}),disabled:!Rt,onClick:()=>void Kn().catch(()=>{}),children:"Send"})]})})]})}function hKn(o){return De.jsx(WWn,{...o})}export{j7e as A,Bmt as B,I1 as C,lNn as F,JRt as G,uBt as H,h8e as I,ALn as L,qRt as O,NX as P,XWn as R,HRt as S,QWn as T,qj as _,ANn as a,INn as b,VWn as c,JWn as d,_u as e,hKn as f,e7e as g,CLn as h,xLn as i,VRt as j,wm as k,C1 as l,Rr as m,FRt as n,$Rt as o,ja as p,tP as u,tjt as v};
4820
+ `)})]})}function MWn(o){return o.operation.protocol==="http"?`${o.operation.function.method.toUpperCase()} ${o.operation.function.path}`:o.operation.function.name}function DWn({history:o}){const[h,b]=bn.useState(!1);return De.jsxs(VBt,{elevation:3,style:{marginTop:15,marginBottom:15,marginRight:"15%"},children:[De.jsxs(_X,{children:[De.jsx(WBt,{label:"Function Describer",variant:"outlined",color:"secondary"}),De.jsx(J8,{children:o.text})]}),De.jsx(u7e,{style:{textAlign:"right"},children:De.jsx(Bmt,{startIcon:De.jsx(sOe,{style:{transform:`rotate(${h?180:0}deg)`}}),onClick:()=>b(!h),children:h?"Hide Function Calls":"Show Function Calls"})}),De.jsx(kX,{in:h,timeout:"auto",unmountOnExit:!0,children:De.jsx(_X,{children:o.executes.map(k=>De.jsx(LWn,{execute:k}))})})]})}const RWn=V5(De.jsx("path",{d:"M4 7h16v2H4zm0 6h16v-2H4zm0 4h7v-2H4zm0 4h7v-2H4zm11.41-2.83L14 16.75l-1.41 1.41L15.41 21 20 16.42 18.58 15zM4 3v2h16V3z"}),"Grading");function BWn({selection:o}){const[h,b]=bn.useState(!1);return De.jsxs(VBt,{elevation:3,style:{marginTop:15,marginBottom:15,marginRight:"15%"},children:[De.jsxs(_X,{children:[De.jsx(WBt,{icon:De.jsx(RWn,{}),label:"Function Selector",variant:"outlined",color:"warning"}),De.jsx("br",{}),De.jsx("br",{}),"Operation:",o.operation.protocol==="http"?De.jsxs("ul",{children:[De.jsx("li",{children:o.operation.function.method.toUpperCase()}),De.jsx("li",{children:o.operation.function.path})]}):De.jsx("ul",{children:De.jsx("li",{children:o.operation.function.name})}),De.jsx(J8,{children:o.reason})]}),De.jsx(u7e,{style:{textAlign:"right"},children:De.jsx(Bmt,{onClick:()=>b(!h),children:h?"Hide Function Description":"Show Function Description"})}),De.jsx(kX,{in:h,timeout:"auto",unmountOnExit:!0,children:De.jsx(_X,{children:De.jsx(J8,{children:o.operation.function.description})})})]})}const jWn=V5(De.jsx("path",{d:"M9 11.75c-.69 0-1.25.56-1.25 1.25s.56 1.25 1.25 1.25 1.25-.56 1.25-1.25-.56-1.25-1.25-1.25m6 0c-.69 0-1.25.56-1.25 1.25s.56 1.25 1.25 1.25 1.25-.56 1.25-1.25-.56-1.25-1.25-1.25M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2m0 18c-4.41 0-8-3.59-8-8 0-.29.02-.58.05-.86 2.36-1.05 4.23-2.98 5.21-5.37C11.07 8.33 14.05 10 17.42 10c.78 0 1.53-.09 2.25-.26.21.71.33 1.47.33 2.26 0 4.41-3.59 8-8 8"}),"Face"),FWn=V5(De.jsx("path",{d:"M20 9V7c0-1.1-.9-2-2-2h-3c0-1.66-1.34-3-3-3S9 3.34 9 5H6c-1.1 0-2 .9-2 2v2c-1.66 0-3 1.34-3 3s1.34 3 3 3v4c0 1.1.9 2 2 2h12c1.1 0 2-.9 2-2v-4c1.66 0 3-1.34 3-3s-1.34-3-3-3M7.5 11.5c0-.83.67-1.5 1.5-1.5s1.5.67 1.5 1.5S9.83 13 9 13s-1.5-.67-1.5-1.5M16 17H8v-2h8zm-1-4c-.83 0-1.5-.67-1.5-1.5S14.17 10 15 10s1.5.67 1.5 1.5S15.83 13 15 13"}),"SmartToy");function $Wn({prompt:o}){return De.jsx("div",{style:{display:"flex",justifyContent:o.role==="user"?"flex-end":"flex-start"},children:De.jsx(VBt,{elevation:3,style:{marginTop:15,marginBottom:15,marginLeft:o.role==="user"?"15%":void 0,marginRight:o.role==="assistant"?"15%":void 0,textAlign:o.role==="user"?"right":"left",backgroundColor:o.role==="user"?"lightyellow":void 0},children:De.jsxs(_X,{children:[De.jsx(WBt,{icon:o.role==="user"?De.jsx(jWn,{}):De.jsx(FWn,{}),label:o.role==="user"?"User":"Assistant",variant:"outlined",color:o.role==="user"?"primary":"success"}),De.jsx(J8,{children:o.text})]})})})}function HWn({prompt:o}){return o.type==="text"?De.jsx($Wn,{prompt:o}):o.type==="select"?o.selections.map(h=>De.jsx(BWn,{selection:h})):o.type==="describe"?De.jsx(DWn,{history:o}):null}function zWn(o){return De.jsxs(zN.Fragment,{children:[De.jsx(x3,{variant:"h5",children:" Function Stack "}),De.jsx("hr",{}),o.selections.map(h=>De.jsxs(f9n,{children:[De.jsx(k9n,{expandIcon:De.jsx(sOe,{}),children:De.jsx(x3,{component:"h6",children:h.operation.protocol==="http"?`${h.operation.function.method.toUpperCase()} ${h.operation.function.path}`:h.operation.function.name})}),De.jsxs(m9n,{children:[De.jsx("hr",{}),h.reason,De.jsx("br",{}),De.jsx("br",{}),De.jsx(J8,{children:h.operation.function.description})]})]}))]})}function UWn(o){const h=GWn(o.usage);return De.jsxs(zN.Fragment,{children:[De.jsx(x3,{variant:"h5",children:" Token Usage "}),De.jsx("hr",{}),De.jsxs(DPn,{children:[De.jsx(VPn,{children:De.jsxs(omt,{children:[De.jsx(y3,{children:"Type"}),De.jsx(y3,{children:"Token Usage"}),De.jsx(y3,{children:"Price"})]})}),De.jsxs($Pn,{children:[De.jsxs(omt,{children:[De.jsx(y3,{children:"Total"}),De.jsx(y3,{children:o.usage.aggregate.total.toLocaleString()}),De.jsxs(y3,{children:["$",h.total.toLocaleString()]})]}),De.jsxs(omt,{children:[De.jsx(y3,{children:"Input"}),De.jsx(y3,{children:o.usage.aggregate.input.total.toLocaleString()}),De.jsxs(y3,{children:["$",h.prompt.toLocaleString()]})]}),De.jsxs(omt,{children:[De.jsx(y3,{children:"Output"}),De.jsx(y3,{children:o.usage.aggregate.output.total.toLocaleString()}),De.jsxs(y3,{children:["$",h.completion.toLocaleString()]})]})]})]})]})}function GWn(o){const h=(o.aggregate.input.total-o.aggregate.input.cached)*25e-7+o.aggregate.input.cached*125e-8,b=o.aggregate.output.total*(10/1e6);return{total:h+b,prompt:h,completion:b}}function qWn(o){var h,b;return De.jsxs("div",{style:{padding:25},children:[o.error!==null?De.jsxs(De.Fragment,{children:[De.jsx(x3,{variant:"h5",color:"error",children:"OpenAI Error"}),De.jsx("hr",{}),o.error.message,De.jsx("br",{}),De.jsx("br",{}),"Your OpenAI API key may not valid.",De.jsx("br",{}),De.jsx("br",{}),De.jsx("br",{})]}):null,De.jsx(x3,{variant:"h5",children:"Agent Information"}),De.jsx("hr",{}),De.jsxs("ul",{children:[De.jsxs("li",{children:[" ","Model:",o.vendor.model]}),De.jsxs("li",{children:[" ","Locale:",((h=o.config)==null?void 0:h.locale)??navigator.language]}),De.jsxs("li",{children:["Timezone:"," ",((b=o.config)==null?void 0:b.timezone)??Intl.DateTimeFormat().resolvedOptions().timeZone]})]}),De.jsx("br",{}),De.jsx("br",{}),De.jsx(UWn,{usage:o.usage}),De.jsx("br",{}),De.jsx("br",{}),De.jsx(zWn,{selections:o.selections})]})}const zAe=450;function WWn({agent:o,title:h}){const b=bn.useRef(null),k=bn.useRef(null),O=bn.useRef(null),P=bn.useRef(null),B=bn.useRef(null),[G,J]=bn.useState(null),[U,nt]=bn.useState(""),[at,it]=bn.useState(o.getHistories().slice()),[st,tt]=bn.useState(JSON.parse(JSON.stringify(o.getTokenUsage()))),[Et,Lt]=bn.useState(122),[Rt,oe]=bn.useState(!0),[qt,ke]=bn.useState([]),[mn,pe]=bn.useState(!1),Dn=async Tr=>{await Tr.join(),at.push(Tr.toHistory()),it(at)},qn=async Tr=>{await Tr.join(),at.push(Tr.toHistory()),it(at)},ar=Tr=>{at.push(Tr.toHistory()),it(at),qt.push(Tr.selection),ke(qt)},nr=Tr=>{console.error(Tr)};bn.useEffect(()=>(B.current!==null&&B.current.select(),o.on("text",Dn),o.on("describe",qn),o.on("select",ar),o.on("validate",nr),tt(o.getTokenUsage()),()=>{o.off("text",Dn),o.off("describe",qn),o.off("select",ar),o.off("validate",nr)}),[]);const Me=()=>{setTimeout(()=>{if(b.current===null||k.current===null||O.current===null)return;const Tr=b.current.clientHeight+O.current.clientHeight;Tr!==Et&&Lt(Tr)})},Kn=async()=>{nt(""),oe(!1),Me();try{await o.conversate(U)}catch(je){je instanceof Error?(alert(je.message),J(je)):J(new Error("Unknown error"));return}at.splice(0,at.length),at.push(...o.getHistories()),it(at),tt(o.getTokenUsage()),oe(!0);const Tr=o.getHistories().filter(je=>je.type==="select").map(je=>je.selections).flat();for(const je of o.getHistories().filter(Xs=>Xs.type==="cancel").map(Xs=>Xs.selections).flat()){const Xs=Tr.findIndex(nl=>nl.operation.protocol===je.operation.protocol&&nl.operation.controller.name===je.operation.controller.name&&nl.operation.function.name===je.operation.function.name);Xs!==-1&&Tr.splice(Xs,1)}ke(Tr)},Xt=async Tr=>{Tr.key==="Enter"&&Tr.shiftKey===!1&&(Rt===!1?Tr.preventDefault():await Kn())},nn=async()=>{if(P.current===null)return;const Tr=await dBn(P.current,{}),je=document.createElement("a");je.download="nestia-chat-screenshot.png",je.href=Tr,je.click(),je.remove()},Je=tP(),dr=ANn(Je.breakpoints.down("lg")),pi=()=>De.jsx("div",{style:{overflowY:"auto",height:"100%",width:dr?"100%":`calc(100% - ${zAe}px)`,margin:0,backgroundColor:"lightblue"},children:De.jsx(v8e,{style:{paddingBottom:50,width:"100%",minHeight:"100%",backgroundColor:"lightblue",margin:0},ref:P,children:at.map(Tr=>De.jsx(HWn,{prompt:Tr})).filter(Tr=>Tr!==null)})}),ia=()=>De.jsx("div",{style:{width:dr?void 0:zAe,height:"100%",overflowY:"auto",backgroundColor:"#eeeeee"},children:De.jsx(v8e,{maxWidth:!1,onClick:dr?()=>pe(!1):void 0,children:De.jsx(qWn,{vendor:o.getVendor(),config:o.getConfig(),usage:st,selections:qt,error:G})})});return De.jsxs("div",{style:{width:"100%",height:"100%"},children:[De.jsx(d8e,{ref:b,position:"relative",component:"div",children:De.jsxs(B8e,{children:[De.jsx(x3,{variant:"h6",component:"div",sx:{flexGrow:1},children:h??"Agentica Chatbot"}),dr?De.jsxs(De.Fragment,{children:[De.jsx(h8e,{onClick:()=>void nn().catch(()=>{}),children:De.jsx(bCe,{})}),De.jsx(h8e,{onClick:()=>pe(!0),children:De.jsx(wRn,{})})]}):De.jsx(Bmt,{color:"inherit",startIcon:De.jsx(bCe,{}),onClick:()=>void nn().catch(()=>{}),children:"Screenshot Capture"})]})}),De.jsx("div",{ref:k,style:{width:"100%",height:`calc(100% - ${Et}px)`,display:"flex",flexDirection:"row"},children:dr?De.jsxs(De.Fragment,{children:[pi(),De.jsx(rNn,{anchor:"right",open:mn,onClose:()=>pe(!1),children:ia()})]}):De.jsxs(De.Fragment,{children:[pi(),ia()]})}),De.jsx(d8e,{ref:O,position:"static",component:"div",color:"inherit",children:De.jsxs(B8e,{children:[De.jsx(ibt,{inputRef:B,fullWidth:!0,placeholder:"Conversate with AI Chatbot",value:U,multiline:!0,onKeyUp:Tr=>void Xt(Tr).catch(()=>{}),onChange:Tr=>{nt(Tr.target.value),Me()}}),De.jsx(Bmt,{variant:"contained",style:{marginLeft:10},startIcon:De.jsx(vRn,{}),disabled:!Rt,onClick:()=>void Kn().catch(()=>{}),children:"Send"})]})})]})}function hKn(o){return De.jsx(WWn,{...o})}export{j7e as A,Bmt as B,I1 as C,lNn as F,JRt as G,uBt as H,h8e as I,ALn as L,qRt as O,NX as P,XWn as R,HRt as S,QWn as T,qj as _,ANn as a,INn as b,VWn as c,JWn as d,_u as e,hKn as f,e7e as g,CLn as h,xLn as i,VRt as j,wm as k,C1 as l,Rr as m,FRt as n,$Rt as o,ja as p,tP as u,tjt as v};
@@ -1,4 +1,4 @@
1
- import{j as a,o as B,r as y,T as g}from"../client-B3aq8qpT.js";import{v as C,A as T,e as w,_ as v,f as R,F as S,T as I,R as _,c as x,d as j,B as P}from"../AgenticaChatApplication-FutOMCcj.js";import{a as f,_ as b}from"../_isFormatUri-YqTfGpHo.js";import{D as U}from"../Divider-DX1xhf0M.js";class k{constructor(){this.articles=[]}index(){return this.articles}create(o){const l={id:C(),title:o.input.title,body:o.input.body,thumbnail:o.input.thumbnail,created_at:new Date().toISOString(),updated_at:new Date().toISOString()};return this.articles.push(l),l}update(o){const l=this.articles.find(d=>d.id===o.id);if(l===void 0)throw new Error("Unable to find the matched article.");o.input.title!==void 0&&(l.title=o.input.title),o.input.body!==void 0&&(l.body=o.input.body),o.input.thumbnail!==void 0&&(l.thumbnail=o.input.thumbnail),l.updated_at=new Date().toISOString()}erase(o){const l=this.articles.findIndex(d=>d.id===o.id);if(l===-1)throw new Error("Unable to find the matched article.");this.articles.splice(l,1)}}function D(u){const o=new k,l=new T({model:"chatgpt",vendor:{api:new w({apiKey:u.apiKey,dangerouslyAllowBrowser:!0}),model:u.model??"gpt-4o-mini"},controllers:[{protocol:"class",name:"bbs",application:{model:"chatgpt",options:{reference:!1,strict:!1,separate:null},functions:[{name:"index",parameters:{description:"",type:"object",properties:{},additionalProperties:!1,required:[],$defs:{}},output:{description:"List of every articles",type:"array",items:{description:`Description of the current {@link IBbsArticle} type:
1
+ import{j as a,o as B,r as y,T as g}from"../client-B3aq8qpT.js";import{v as C,A as T,e as w,_ as v,f as R,F as S,T as I,R as _,c as x,d as j,B as P}from"../AgenticaChatApplication-B8ENbee0.js";import{a as f,_ as b}from"../_isFormatUri-YqTfGpHo.js";import{D as U}from"../Divider-DX1xhf0M.js";class k{constructor(){this.articles=[]}index(){return this.articles}create(o){const l={id:C(),title:o.input.title,body:o.input.body,thumbnail:o.input.thumbnail,created_at:new Date().toISOString(),updated_at:new Date().toISOString()};return this.articles.push(l),l}update(o){const l=this.articles.find(d=>d.id===o.id);if(l===void 0)throw new Error("Unable to find the matched article.");o.input.title!==void 0&&(l.title=o.input.title),o.input.body!==void 0&&(l.body=o.input.body),o.input.thumbnail!==void 0&&(l.thumbnail=o.input.thumbnail),l.updated_at=new Date().toISOString()}erase(o){const l=this.articles.findIndex(d=>d.id===o.id);if(l===-1)throw new Error("Unable to find the matched article.");this.articles.splice(l,1)}}function D(u){const o=new k,l=new T({model:"chatgpt",vendor:{api:new w({apiKey:u.apiKey,dangerouslyAllowBrowser:!0}),model:u.model??"gpt-4o-mini"},controllers:[{protocol:"class",name:"bbs",application:{model:"chatgpt",options:{reference:!1,strict:!1,separate:null},functions:[{name:"index",parameters:{description:"",type:"object",properties:{},additionalProperties:!1,required:[],$defs:{}},output:{description:"List of every articles",type:"array",items:{description:`Description of the current {@link IBbsArticle} type:
2
2
 
3
3
  > Article entity.
4
4
  >