apteva 0.4.53 → 0.4.56
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/ActivityPage.kxzzb4yc.js +3 -0
- package/dist/ApiDocsPage.zq998hbm.js +4 -0
- package/dist/App.55rea8mn.js +61 -0
- package/dist/App.5ywb23z4.js +53 -0
- package/dist/App.6thds120.js +4 -0
- package/dist/{App.jhb45d7r.js → App.9tctxzqm.js} +3 -3
- package/dist/App.a8r8ttaz.js +4 -0
- package/dist/App.agsv5bje.js +4 -0
- package/dist/App.cepapqmx.js +4 -0
- package/dist/App.dp041gb3.js +221 -0
- package/dist/App.fds72zb5.js +4 -0
- package/dist/App.fg9qj2dq.js +4 -0
- package/dist/App.ndfejbm9.js +4 -0
- package/dist/App.nxmfmq1h.js +13 -0
- package/dist/App.qdfyt8ba.js +4 -0
- package/dist/{App.9sryp183.js → App.x2d0ygt6.js} +2 -2
- package/dist/App.yt9p4nr3.js +20 -0
- package/dist/{App.wghtdzsk.js → App.zn4mw16t.js} +1 -1
- package/dist/ConnectionsPage.8r96ryw7.js +3 -0
- package/dist/McpPage.3cwh0gnd.js +3 -0
- package/dist/SettingsPage.ykgdh5ev.js +3 -0
- package/dist/SkillsPage.4np1s65b.js +3 -0
- package/dist/TasksPage.4g08t7p6.js +3 -0
- package/dist/TelemetryPage.72w9pwcp.js +3 -0
- package/dist/TestsPage.z4fk3r7r.js +3 -0
- package/dist/ThreadsPage.63tcajeh.js +3 -0
- package/dist/apteva-kit.css +1 -1
- package/dist/index.html +1 -1
- package/dist/styles.css +1 -1
- package/package.json +2 -2
- package/src/crypto.ts +25 -4
- package/src/db.ts +24 -1
- package/src/mcp-platform.ts +273 -44
- package/src/providers.ts +125 -5
- package/src/routes/api/agent-utils.ts +105 -8
- package/src/routes/api/providers.ts +64 -0
- package/src/routes/api/telemetry.ts +0 -7
- package/src/routes/share.ts +3 -2
- package/src/server.ts +53 -7
- package/src/test-runner.ts +1 -1
- package/src/web/App.tsx +37 -22
- package/src/web/components/agents/AgentCard.tsx +12 -9
- package/src/web/components/agents/AgentPanel.tsx +126 -7
- package/src/web/components/agents/AgentsView.tsx +30 -8
- package/src/web/components/agents/CreateAgentModal.tsx +155 -5
- package/src/web/components/dashboard/Dashboard.tsx +9 -7
- package/src/web/components/layout/Sidebar.tsx +43 -32
- package/src/web/components/meta-agent/MetaAgent.tsx +6 -2
- package/src/web/components/settings/SettingsPage.tsx +172 -43
- package/src/web/components/telemetry/TelemetryPage.tsx +54 -46
- package/src/web/components/tests/TestsPage.tsx +91 -76
- package/src/web/context/TelemetryContext.tsx +4 -1
- package/src/web/context/UIModeContext.tsx +49 -0
- package/src/web/context/index.ts +3 -0
- package/src/web/types.ts +67 -3
- package/dist/ActivityPage.sw9p594m.js +0 -3
- package/dist/ApiDocsPage.90e03bz7.js +0 -4
- package/dist/App.3vnrera5.js +0 -4
- package/dist/App.94x6mh7f.js +0 -20
- package/dist/App.9t1zc5r7.js +0 -53
- package/dist/App.p7jjw1zf.js +0 -4
- package/dist/App.pfbdzrhh.js +0 -4
- package/dist/App.pse0pzar.js +0 -4
- package/dist/App.r43t58w6.js +0 -221
- package/dist/App.stgng5bx.js +0 -13
- package/dist/App.tm3k7h4b.js +0 -4
- package/dist/App.vkg121c6.js +0 -4
- package/dist/App.xva0tfzh.js +0 -4
- package/dist/App.ysxy7akk.js +0 -61
- package/dist/App.yzkh4gq2.js +0 -4
- package/dist/ConnectionsPage.q5f9fd37.js +0 -3
- package/dist/McpPage.f3ccrezb.js +0 -3
- package/dist/SettingsPage.zmzm1pp6.js +0 -3
- package/dist/SkillsPage.whxnez67.js +0 -3
- package/dist/TasksPage.zp4jfevw.js +0 -3
- package/dist/TelemetryPage.an0ky78c.js +0 -3
- package/dist/TestsPage.18krj0d1.js +0 -3
- package/dist/ThreadsPage.nnphgy98.js +0 -3
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import{W as eQ,X as g$}from"./App.9tctxzqm.js";import{Y as k,Z as sQ,aa as L0,ba as qQ,da as KQ,fa as OQ,ka as UQ,na as VQ,pa as _Q}from"./App.yt9p4nr3.js";var d=sQ((tQ)=>{var AX=k(L0());(function(){function X(q){if(q==null)return null;if(typeof q==="function")return q.$$typeof===P?null:q.displayName||q.name||null;if(typeof q==="string")return q;switch(q){case A:return"Fragment";case M:return"Profiler";case I:return"StrictMode";case e:return"Suspense";case R:return"SuspenseList";case f:return"Activity"}if(typeof q==="object")switch(typeof q.tag==="number"&&console.error("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),q.$$typeof){case B:return"Portal";case i:return q.displayName||"Context";case h:return(q._context.displayName||"Context")+".Consumer";case o:var N=q.render;return q=q.displayName,q||(q=N.displayName||N.name||"",q=q!==""?"ForwardRef("+q+")":"ForwardRef"),q;case j:return N=q.displayName||null,N!==null?N:X(q.type)||"Memo";case T:N=q._payload,q=q._init;try{return X(q(N))}catch(L){}}return null}function $(q){return""+q}function Q(q){try{$(q);var N=!1}catch(Q0){N=!0}if(N){N=console;var L=N.error,S=typeof Symbol==="function"&&Symbol.toStringTag&&q[Symbol.toStringTag]||q.constructor.name||"Object";return L.call(N,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",S),$(q)}}function Z(q){if(q===A)return"<>";if(typeof q==="object"&&q!==null&&q.$$typeof===T)return"<...>";try{var N=X(q);return N?"<"+N+">":"<...>"}catch(L){return"<...>"}}function z(){var q=b.A;return q===null?null:q.getOwner()}function H(){return Error("react-stack-top-frame")}function G(q){if(F.call(q,"key")){var N=Object.getOwnPropertyDescriptor(q,"key").get;if(N&&N.isReactWarning)return!1}return q.key!==void 0}function J(q,N){function L(){y0||(y0=!0,console.error("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",N))}L.isReactWarning=!0,Object.defineProperty(q,"key",{get:L,configurable:!0})}function U(){var q=X(this.type);return S0[q]||(S0[q]=!0,console.error("Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release.")),q=this.props.ref,q!==void 0?q:null}function K(q,N,L,S,Q0,K0){var O0=L.ref;return q={$$typeof:_,type:q,key:N,props:L,_owner:S},(O0!==void 0?O0:null)!==null?Object.defineProperty(q,"ref",{enumerable:!1,get:U}):Object.defineProperty(q,"ref",{enumerable:!1,value:null}),q._store={},Object.defineProperty(q._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:0}),Object.defineProperty(q,"_debugInfo",{configurable:!1,enumerable:!1,writable:!0,value:null}),Object.defineProperty(q,"_debugStack",{configurable:!1,enumerable:!1,writable:!0,value:Q0}),Object.defineProperty(q,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:K0}),Object.freeze&&(Object.freeze(q.props),Object.freeze(q)),q}function O(q,N,L,S,Q0,K0){var O0=N.children;if(O0!==void 0)if(S)if(A0(O0)){for(S=0;S<O0.length;S++)Y(O0[S]);Object.freeze&&Object.freeze(O0)}else console.error("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else Y(O0);if(F.call(N,"key")){O0=X(q);var x0=Object.keys(N).filter(function(FX){return FX!=="key"});S=0<x0.length?"{key: someKey, "+x0.join(": ..., ")+": ...}":"{key: someKey}",a[O0+S]||(x0=0<x0.length?"{"+x0.join(": ..., ")+": ...}":"{}",console.error(`A props object containing a "key" prop is being spread into JSX:
|
|
2
|
+
let props = %s;
|
|
3
|
+
<%s {...props} />
|
|
4
|
+
React keys must be passed directly to JSX without using spread:
|
|
5
|
+
let props = %s;
|
|
6
|
+
<%s key={someKey} {...props} />`,S,O0,x0,O0),a[O0+S]=!0)}if(O0=null,L!==void 0&&(Q(L),O0=""+L),G(N)&&(Q(N.key),O0=""+N.key),"key"in N){L={};for(var qX in N)qX!=="key"&&(L[qX]=N[qX])}else L=N;return O0&&J(L,typeof q==="function"?q.displayName||q.name||"Unknown":q),K(q,O0,L,z(),Q0,K0)}function Y(q){V(q)?q._store&&(q._store.validated=1):typeof q==="object"&&q!==null&&q.$$typeof===T&&(q._payload.status==="fulfilled"?V(q._payload.value)&&q._payload.value._store&&(q._payload.value._store.validated=1):q._store&&(q._store.validated=1))}function V(q){return typeof q==="object"&&q!==null&&q.$$typeof===_}var _=Symbol.for("react.transitional.element"),B=Symbol.for("react.portal"),A=Symbol.for("react.fragment"),I=Symbol.for("react.strict_mode"),M=Symbol.for("react.profiler"),h=Symbol.for("react.consumer"),i=Symbol.for("react.context"),o=Symbol.for("react.forward_ref"),e=Symbol.for("react.suspense"),R=Symbol.for("react.suspense_list"),j=Symbol.for("react.memo"),T=Symbol.for("react.lazy"),f=Symbol.for("react.activity"),P=Symbol.for("react.client.reference"),b=AX.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,F=Object.prototype.hasOwnProperty,A0=Array.isArray,$0=console.createTask?console.createTask:function(){return null};AX={react_stack_bottom_frame:function(q){return q()}};var y0,S0={},y=AX.react_stack_bottom_frame.bind(AX,H)(),g=$0(Z(H)),a={};tQ.Fragment=A,tQ.jsx=function(q,N,L){var S=1e4>b.recentlyCreatedOwnerStacks++;return O(q,N,L,!1,S?Error("react-stack-top-frame"):y,S?$0(Z(q)):g)},tQ.jsxs=function(q,N,L){var S=1e4>b.recentlyCreatedOwnerStacks++;return O(q,N,L,!0,S?Error("react-stack-top-frame"):y,S?$0(Z(q)):g)}})()});var R0=k(L0(),1);var t=k(L0(),1),vX=k(L0(),1),EX=k(L0(),1);var NQ=(X)=>{let $=PQ(X),{conflictingClassGroups:Q,conflictingClassGroupModifiers:Z}=X;return{getClassGroupId:(G)=>{let J=G.split("-");if(J[0]===""&&J.length!==1)J.shift();return b$(J,$)||AQ(G)},getConflictingClassGroupIds:(G,J)=>{let U=Q[G]||[];if(J&&Z[G])return[...U,...Z[G]];return U}}},b$=(X,$)=>{if(X.length===0)return $.classGroupId;let Q=X[0],Z=$.nextPart.get(Q),z=Z?b$(X.slice(1),Z):void 0;if(z)return z;if($.validators.length===0)return;let H=X.join("-");return $.validators.find(({validator:G})=>G(H))?.classGroupId},I$=/^\[(.+)\]$/,AQ=(X)=>{if(I$.test(X)){let $=I$.exec(X)[1],Q=$?.substring(0,$.indexOf(":"));if(Q)return"arbitrary.."+Q}},PQ=(X)=>{let{theme:$,prefix:Q}=X,Z={nextPart:new Map,validators:[]};return MQ(Object.entries(X.classGroups),Q).forEach(([H,G])=>{O$(G,Z,H,$)}),Z},O$=(X,$,Q,Z)=>{X.forEach((z)=>{if(typeof z==="string"){let H=z===""?$:R$($,z);H.classGroupId=Q;return}if(typeof z==="function"){if(EQ(z)){O$(z(Z),$,Q,Z);return}$.validators.push({validator:z,classGroupId:Q});return}Object.entries(z).forEach(([H,G])=>{O$(G,R$($,H),Q,Z)})})},R$=(X,$)=>{let Q=X;return $.split("-").forEach((Z)=>{if(!Q.nextPart.has(Z))Q.nextPart.set(Z,{nextPart:new Map,validators:[]});Q=Q.nextPart.get(Z)}),Q},EQ=(X)=>X.isThemeGetter,MQ=(X,$)=>{if(!$)return X;return X.map(([Q,Z])=>{let z=Z.map((H)=>{if(typeof H==="string")return $+H;if(typeof H==="object")return Object.fromEntries(Object.entries(H).map(([G,J])=>[$+G,J]));return H});return[Q,z]})},TQ=(X)=>{if(X<1)return{get:()=>{return},set:()=>{}};let $=0,Q=new Map,Z=new Map,z=(H,G)=>{if(Q.set(H,G),$++,$>X)$=0,Z=Q,Q=new Map};return{get(H){let G=Q.get(H);if(G!==void 0)return G;if((G=Z.get(H))!==void 0)return z(H,G),G},set(H,G){if(Q.has(H))Q.set(H,G);else z(H,G)}}};var IQ=(X)=>{let{separator:$,experimentalParseClassName:Q}=X,Z=$.length===1,z=$[0],H=$.length,G=(J)=>{let U=[],K=0,O=0,Y;for(let I=0;I<J.length;I++){let M=J[I];if(K===0){if(M===z&&(Z||J.slice(I,I+H)===$)){U.push(J.slice(O,I)),O=I+H;continue}if(M==="/"){Y=I;continue}}if(M==="[")K++;else if(M==="]")K--}let V=U.length===0?J:J.substring(O),_=V.startsWith("!"),B=_?V.substring(1):V,A=Y&&Y>O?Y-O:void 0;return{modifiers:U,hasImportantModifier:_,baseClassName:B,maybePostfixModifierPosition:A}};if(Q)return(J)=>Q({className:J,parseClassName:G});return G},RQ=(X)=>{if(X.length<=1)return X;let $=[],Q=[];return X.forEach((Z)=>{if(Z[0]==="[")$.push(...Q.sort(),Z),Q=[];else Q.push(Z)}),$.push(...Q.sort()),$},bQ=(X)=>({cache:TQ(X.cacheSize),parseClassName:IQ(X),...NQ(X)}),kQ=/\s+/,vQ=(X,$)=>{let{parseClassName:Q,getClassGroupId:Z,getConflictingClassGroupIds:z}=$,H=[],G=X.trim().split(kQ),J="";for(let U=G.length-1;U>=0;U-=1){let K=G[U],{modifiers:O,hasImportantModifier:Y,baseClassName:V,maybePostfixModifierPosition:_}=Q(K),B=Boolean(_),A=Z(B?V.substring(0,_):V);if(!A){if(!B){J=K+(J.length>0?" "+J:J);continue}if(A=Z(V),!A){J=K+(J.length>0?" "+J:J);continue}B=!1}let I=RQ(O).join(":"),M=Y?I+"!":I,h=M+A;if(H.includes(h))continue;H.push(h);let i=z(A,B);for(let o=0;o<i.length;++o){let e=i[o];H.push(M+e)}J=K+(J.length>0?" "+J:J)}return J};function wQ(){let X=0,$,Q,Z="";while(X<arguments.length)if($=arguments[X++]){if(Q=k$($))Z&&(Z+=" "),Z+=Q}return Z}var k$=(X)=>{if(typeof X==="string")return X;let $,Q="";for(let Z=0;Z<X.length;Z++)if(X[Z]){if($=k$(X[Z]))Q&&(Q+=" "),Q+=$}return Q};function SQ(X,...$){let Q,Z,z,H=G;function G(U){let K=$.reduce((O,Y)=>Y(O),X());return Q=bQ(K),Z=Q.cache.get,z=Q.cache.set,H=J,J(U)}function J(U){let K=Z(U);if(K)return K;let O=vQ(U,Q);return z(U,O),O}return function(){return H(wQ.apply(null,arguments))}}var W0=(X)=>{let $=(Q)=>Q[X]||[];return $.isThemeGetter=!0,$},v$=/^\[(?:([a-z-]+):)?(.+)\]$/i,yQ=/^\d+\/\d+$/,CQ=new Set(["px","full","screen"]),jQ=/^(\d+(\.\d+)?)?(xs|sm|md|lg|xl)$/,fQ=/\d+(%|px|r?em|[sdl]?v([hwib]|min|max)|pt|pc|in|cm|mm|cap|ch|ex|r?lh|cq(w|h|i|b|min|max))|\b(calc|min|max|clamp)\(.+\)|^0$/,hQ=/^(rgba?|hsla?|hwb|(ok)?(lab|lch))\(.+\)$/,xQ=/^(inset_)?-?((\d+)?\.?(\d+)[a-z]+|0)_-?((\d+)?\.?(\d+)[a-z]+|0)/,gQ=/^(url|image|image-set|cross-fade|element|(repeating-)?(linear|radial|conic)-gradient)\(.+\)$/,zX=(X)=>RX(X)||CQ.has(X)||yQ.test(X),LX=(X)=>bX(X,"length",oQ),RX=(X)=>Boolean(X)&&!Number.isNaN(Number(X)),K$=(X)=>bX(X,"number",RX),mX=(X)=>Boolean(X)&&Number.isInteger(Number(X)),uQ=(X)=>X.endsWith("%")&&RX(X.slice(0,-1)),n=(X)=>v$.test(X),DX=(X)=>jQ.test(X),mQ=new Set(["length","size","percentage"]),pQ=(X)=>bX(X,mQ,w$),cQ=(X)=>bX(X,"position",w$),lQ=new Set(["image","url"]),dQ=(X)=>bX(X,lQ,nQ),iQ=(X)=>bX(X,"",rQ),pX=()=>!0,bX=(X,$,Q)=>{let Z=v$.exec(X);if(Z){if(Z[1])return typeof $==="string"?Z[1]===$:$.has(Z[1]);return Q(Z[2])}return!1},oQ=(X)=>fQ.test(X)&&!hQ.test(X),w$=()=>!1,rQ=(X)=>xQ.test(X),nQ=(X)=>gQ.test(X);var aQ=()=>{let X=W0("colors"),$=W0("spacing"),Q=W0("blur"),Z=W0("brightness"),z=W0("borderColor"),H=W0("borderRadius"),G=W0("borderSpacing"),J=W0("borderWidth"),U=W0("contrast"),K=W0("grayscale"),O=W0("hueRotate"),Y=W0("invert"),V=W0("gap"),_=W0("gradientColorStops"),B=W0("gradientColorStopPositions"),A=W0("inset"),I=W0("margin"),M=W0("opacity"),h=W0("padding"),i=W0("saturate"),o=W0("scale"),e=W0("sepia"),R=W0("skew"),j=W0("space"),T=W0("translate"),f=()=>["auto","contain","none"],P=()=>["auto","hidden","clip","visible","scroll"],b=()=>["auto",n,$],F=()=>[n,$],A0=()=>["",zX,LX],$0=()=>["auto",RX,n],y0=()=>["bottom","center","left","left-bottom","left-top","right","right-bottom","right-top","top"],S0=()=>["solid","dashed","dotted","double","none"],y=()=>["normal","multiply","screen","overlay","darken","lighten","color-dodge","color-burn","hard-light","soft-light","difference","exclusion","hue","saturation","color","luminosity"],g=()=>["start","end","center","between","around","evenly","stretch"],a=()=>["","0",n],q=()=>["auto","avoid","all","avoid-page","page","left","right","column"],N=()=>[RX,n];return{cacheSize:500,separator:":",theme:{colors:[pX],spacing:[zX,LX],blur:["none","",DX,n],brightness:N(),borderColor:[X],borderRadius:["none","","full",DX,n],borderSpacing:F(),borderWidth:A0(),contrast:N(),grayscale:a(),hueRotate:N(),invert:a(),gap:F(),gradientColorStops:[X],gradientColorStopPositions:[uQ,LX],inset:b(),margin:b(),opacity:N(),padding:F(),saturate:N(),scale:N(),sepia:a(),skew:N(),space:F(),translate:F()},classGroups:{aspect:[{aspect:["auto","square","video",n]}],container:["container"],columns:[{columns:[DX]}],"break-after":[{"break-after":q()}],"break-before":[{"break-before":q()}],"break-inside":[{"break-inside":["auto","avoid","avoid-page","avoid-column"]}],"box-decoration":[{"box-decoration":["slice","clone"]}],box:[{box:["border","content"]}],display:["block","inline-block","inline","flex","inline-flex","table","inline-table","table-caption","table-cell","table-column","table-column-group","table-footer-group","table-header-group","table-row-group","table-row","flow-root","grid","inline-grid","contents","list-item","hidden"],float:[{float:["right","left","none","start","end"]}],clear:[{clear:["left","right","both","none","start","end"]}],isolation:["isolate","isolation-auto"],"object-fit":[{object:["contain","cover","fill","none","scale-down"]}],"object-position":[{object:[...y0(),n]}],overflow:[{overflow:P()}],"overflow-x":[{"overflow-x":P()}],"overflow-y":[{"overflow-y":P()}],overscroll:[{overscroll:f()}],"overscroll-x":[{"overscroll-x":f()}],"overscroll-y":[{"overscroll-y":f()}],position:["static","fixed","absolute","relative","sticky"],inset:[{inset:[A]}],"inset-x":[{"inset-x":[A]}],"inset-y":[{"inset-y":[A]}],start:[{start:[A]}],end:[{end:[A]}],top:[{top:[A]}],right:[{right:[A]}],bottom:[{bottom:[A]}],left:[{left:[A]}],visibility:["visible","invisible","collapse"],z:[{z:["auto",mX,n]}],basis:[{basis:b()}],"flex-direction":[{flex:["row","row-reverse","col","col-reverse"]}],"flex-wrap":[{flex:["wrap","wrap-reverse","nowrap"]}],flex:[{flex:["1","auto","initial","none",n]}],grow:[{grow:a()}],shrink:[{shrink:a()}],order:[{order:["first","last","none",mX,n]}],"grid-cols":[{"grid-cols":[pX]}],"col-start-end":[{col:["auto",{span:["full",mX,n]},n]}],"col-start":[{"col-start":$0()}],"col-end":[{"col-end":$0()}],"grid-rows":[{"grid-rows":[pX]}],"row-start-end":[{row:["auto",{span:[mX,n]},n]}],"row-start":[{"row-start":$0()}],"row-end":[{"row-end":$0()}],"grid-flow":[{"grid-flow":["row","col","dense","row-dense","col-dense"]}],"auto-cols":[{"auto-cols":["auto","min","max","fr",n]}],"auto-rows":[{"auto-rows":["auto","min","max","fr",n]}],gap:[{gap:[V]}],"gap-x":[{"gap-x":[V]}],"gap-y":[{"gap-y":[V]}],"justify-content":[{justify:["normal",...g()]}],"justify-items":[{"justify-items":["start","end","center","stretch"]}],"justify-self":[{"justify-self":["auto","start","end","center","stretch"]}],"align-content":[{content:["normal",...g(),"baseline"]}],"align-items":[{items:["start","end","center","baseline","stretch"]}],"align-self":[{self:["auto","start","end","center","stretch","baseline"]}],"place-content":[{"place-content":[...g(),"baseline"]}],"place-items":[{"place-items":["start","end","center","baseline","stretch"]}],"place-self":[{"place-self":["auto","start","end","center","stretch"]}],p:[{p:[h]}],px:[{px:[h]}],py:[{py:[h]}],ps:[{ps:[h]}],pe:[{pe:[h]}],pt:[{pt:[h]}],pr:[{pr:[h]}],pb:[{pb:[h]}],pl:[{pl:[h]}],m:[{m:[I]}],mx:[{mx:[I]}],my:[{my:[I]}],ms:[{ms:[I]}],me:[{me:[I]}],mt:[{mt:[I]}],mr:[{mr:[I]}],mb:[{mb:[I]}],ml:[{ml:[I]}],"space-x":[{"space-x":[j]}],"space-x-reverse":["space-x-reverse"],"space-y":[{"space-y":[j]}],"space-y-reverse":["space-y-reverse"],w:[{w:["auto","min","max","fit","svw","lvw","dvw",n,$]}],"min-w":[{"min-w":[n,$,"min","max","fit"]}],"max-w":[{"max-w":[n,$,"none","full","min","max","fit","prose",{screen:[DX]},DX]}],h:[{h:[n,$,"auto","min","max","fit","svh","lvh","dvh"]}],"min-h":[{"min-h":[n,$,"min","max","fit","svh","lvh","dvh"]}],"max-h":[{"max-h":[n,$,"min","max","fit","svh","lvh","dvh"]}],size:[{size:[n,$,"auto","min","max","fit"]}],"font-size":[{text:["base",DX,LX]}],"font-smoothing":["antialiased","subpixel-antialiased"],"font-style":["italic","not-italic"],"font-weight":[{font:["thin","extralight","light","normal","medium","semibold","bold","extrabold","black",K$]}],"font-family":[{font:[pX]}],"fvn-normal":["normal-nums"],"fvn-ordinal":["ordinal"],"fvn-slashed-zero":["slashed-zero"],"fvn-figure":["lining-nums","oldstyle-nums"],"fvn-spacing":["proportional-nums","tabular-nums"],"fvn-fraction":["diagonal-fractions","stacked-fractions"],tracking:[{tracking:["tighter","tight","normal","wide","wider","widest",n]}],"line-clamp":[{"line-clamp":["none",RX,K$]}],leading:[{leading:["none","tight","snug","normal","relaxed","loose",zX,n]}],"list-image":[{"list-image":["none",n]}],"list-style-type":[{list:["none","disc","decimal",n]}],"list-style-position":[{list:["inside","outside"]}],"placeholder-color":[{placeholder:[X]}],"placeholder-opacity":[{"placeholder-opacity":[M]}],"text-alignment":[{text:["left","center","right","justify","start","end"]}],"text-color":[{text:[X]}],"text-opacity":[{"text-opacity":[M]}],"text-decoration":["underline","overline","line-through","no-underline"],"text-decoration-style":[{decoration:[...S0(),"wavy"]}],"text-decoration-thickness":[{decoration:["auto","from-font",zX,LX]}],"underline-offset":[{"underline-offset":["auto",zX,n]}],"text-decoration-color":[{decoration:[X]}],"text-transform":["uppercase","lowercase","capitalize","normal-case"],"text-overflow":["truncate","text-ellipsis","text-clip"],"text-wrap":[{text:["wrap","nowrap","balance","pretty"]}],indent:[{indent:F()}],"vertical-align":[{align:["baseline","top","middle","bottom","text-top","text-bottom","sub","super",n]}],whitespace:[{whitespace:["normal","nowrap","pre","pre-line","pre-wrap","break-spaces"]}],break:[{break:["normal","words","all","keep"]}],hyphens:[{hyphens:["none","manual","auto"]}],content:[{content:["none",n]}],"bg-attachment":[{bg:["fixed","local","scroll"]}],"bg-clip":[{"bg-clip":["border","padding","content","text"]}],"bg-opacity":[{"bg-opacity":[M]}],"bg-origin":[{"bg-origin":["border","padding","content"]}],"bg-position":[{bg:[...y0(),cQ]}],"bg-repeat":[{bg:["no-repeat",{repeat:["","x","y","round","space"]}]}],"bg-size":[{bg:["auto","cover","contain",pQ]}],"bg-image":[{bg:["none",{"gradient-to":["t","tr","r","br","b","bl","l","tl"]},dQ]}],"bg-color":[{bg:[X]}],"gradient-from-pos":[{from:[B]}],"gradient-via-pos":[{via:[B]}],"gradient-to-pos":[{to:[B]}],"gradient-from":[{from:[_]}],"gradient-via":[{via:[_]}],"gradient-to":[{to:[_]}],rounded:[{rounded:[H]}],"rounded-s":[{"rounded-s":[H]}],"rounded-e":[{"rounded-e":[H]}],"rounded-t":[{"rounded-t":[H]}],"rounded-r":[{"rounded-r":[H]}],"rounded-b":[{"rounded-b":[H]}],"rounded-l":[{"rounded-l":[H]}],"rounded-ss":[{"rounded-ss":[H]}],"rounded-se":[{"rounded-se":[H]}],"rounded-ee":[{"rounded-ee":[H]}],"rounded-es":[{"rounded-es":[H]}],"rounded-tl":[{"rounded-tl":[H]}],"rounded-tr":[{"rounded-tr":[H]}],"rounded-br":[{"rounded-br":[H]}],"rounded-bl":[{"rounded-bl":[H]}],"border-w":[{border:[J]}],"border-w-x":[{"border-x":[J]}],"border-w-y":[{"border-y":[J]}],"border-w-s":[{"border-s":[J]}],"border-w-e":[{"border-e":[J]}],"border-w-t":[{"border-t":[J]}],"border-w-r":[{"border-r":[J]}],"border-w-b":[{"border-b":[J]}],"border-w-l":[{"border-l":[J]}],"border-opacity":[{"border-opacity":[M]}],"border-style":[{border:[...S0(),"hidden"]}],"divide-x":[{"divide-x":[J]}],"divide-x-reverse":["divide-x-reverse"],"divide-y":[{"divide-y":[J]}],"divide-y-reverse":["divide-y-reverse"],"divide-opacity":[{"divide-opacity":[M]}],"divide-style":[{divide:S0()}],"border-color":[{border:[z]}],"border-color-x":[{"border-x":[z]}],"border-color-y":[{"border-y":[z]}],"border-color-s":[{"border-s":[z]}],"border-color-e":[{"border-e":[z]}],"border-color-t":[{"border-t":[z]}],"border-color-r":[{"border-r":[z]}],"border-color-b":[{"border-b":[z]}],"border-color-l":[{"border-l":[z]}],"divide-color":[{divide:[z]}],"outline-style":[{outline:["",...S0()]}],"outline-offset":[{"outline-offset":[zX,n]}],"outline-w":[{outline:[zX,LX]}],"outline-color":[{outline:[X]}],"ring-w":[{ring:A0()}],"ring-w-inset":["ring-inset"],"ring-color":[{ring:[X]}],"ring-opacity":[{"ring-opacity":[M]}],"ring-offset-w":[{"ring-offset":[zX,LX]}],"ring-offset-color":[{"ring-offset":[X]}],shadow:[{shadow:["","inner","none",DX,iQ]}],"shadow-color":[{shadow:[pX]}],opacity:[{opacity:[M]}],"mix-blend":[{"mix-blend":[...y(),"plus-lighter","plus-darker"]}],"bg-blend":[{"bg-blend":y()}],filter:[{filter:["","none"]}],blur:[{blur:[Q]}],brightness:[{brightness:[Z]}],contrast:[{contrast:[U]}],"drop-shadow":[{"drop-shadow":["","none",DX,n]}],grayscale:[{grayscale:[K]}],"hue-rotate":[{"hue-rotate":[O]}],invert:[{invert:[Y]}],saturate:[{saturate:[i]}],sepia:[{sepia:[e]}],"backdrop-filter":[{"backdrop-filter":["","none"]}],"backdrop-blur":[{"backdrop-blur":[Q]}],"backdrop-brightness":[{"backdrop-brightness":[Z]}],"backdrop-contrast":[{"backdrop-contrast":[U]}],"backdrop-grayscale":[{"backdrop-grayscale":[K]}],"backdrop-hue-rotate":[{"backdrop-hue-rotate":[O]}],"backdrop-invert":[{"backdrop-invert":[Y]}],"backdrop-opacity":[{"backdrop-opacity":[M]}],"backdrop-saturate":[{"backdrop-saturate":[i]}],"backdrop-sepia":[{"backdrop-sepia":[e]}],"border-collapse":[{border:["collapse","separate"]}],"border-spacing":[{"border-spacing":[G]}],"border-spacing-x":[{"border-spacing-x":[G]}],"border-spacing-y":[{"border-spacing-y":[G]}],"table-layout":[{table:["auto","fixed"]}],caption:[{caption:["top","bottom"]}],transition:[{transition:["none","all","","colors","opacity","shadow","transform",n]}],duration:[{duration:N()}],ease:[{ease:["linear","in","out","in-out",n]}],delay:[{delay:N()}],animate:[{animate:["none","spin","ping","pulse","bounce",n]}],transform:[{transform:["","gpu","none"]}],scale:[{scale:[o]}],"scale-x":[{"scale-x":[o]}],"scale-y":[{"scale-y":[o]}],rotate:[{rotate:[mX,n]}],"translate-x":[{"translate-x":[T]}],"translate-y":[{"translate-y":[T]}],"skew-x":[{"skew-x":[R]}],"skew-y":[{"skew-y":[R]}],"transform-origin":[{origin:["center","top","top-right","right","bottom-right","bottom","bottom-left","left","top-left",n]}],accent:[{accent:["auto",X]}],appearance:[{appearance:["none","auto"]}],cursor:[{cursor:["auto","default","pointer","wait","text","move","help","not-allowed","none","context-menu","progress","cell","crosshair","vertical-text","alias","copy","no-drop","grab","grabbing","all-scroll","col-resize","row-resize","n-resize","e-resize","s-resize","w-resize","ne-resize","nw-resize","se-resize","sw-resize","ew-resize","ns-resize","nesw-resize","nwse-resize","zoom-in","zoom-out",n]}],"caret-color":[{caret:[X]}],"pointer-events":[{"pointer-events":["none","auto"]}],resize:[{resize:["none","y","x",""]}],"scroll-behavior":[{scroll:["auto","smooth"]}],"scroll-m":[{"scroll-m":F()}],"scroll-mx":[{"scroll-mx":F()}],"scroll-my":[{"scroll-my":F()}],"scroll-ms":[{"scroll-ms":F()}],"scroll-me":[{"scroll-me":F()}],"scroll-mt":[{"scroll-mt":F()}],"scroll-mr":[{"scroll-mr":F()}],"scroll-mb":[{"scroll-mb":F()}],"scroll-ml":[{"scroll-ml":F()}],"scroll-p":[{"scroll-p":F()}],"scroll-px":[{"scroll-px":F()}],"scroll-py":[{"scroll-py":F()}],"scroll-ps":[{"scroll-ps":F()}],"scroll-pe":[{"scroll-pe":F()}],"scroll-pt":[{"scroll-pt":F()}],"scroll-pr":[{"scroll-pr":F()}],"scroll-pb":[{"scroll-pb":F()}],"scroll-pl":[{"scroll-pl":F()}],"snap-align":[{snap:["start","end","center","align-none"]}],"snap-stop":[{snap:["normal","always"]}],"snap-type":[{snap:["none","x","y","both"]}],"snap-strictness":[{snap:["mandatory","proximity"]}],touch:[{touch:["auto","none","manipulation"]}],"touch-x":[{"touch-pan":["x","left","right"]}],"touch-y":[{"touch-pan":["y","up","down"]}],"touch-pz":["touch-pinch-zoom"],select:[{select:["none","text","all","auto"]}],"will-change":[{"will-change":["auto","scroll","contents","transform",n]}],fill:[{fill:[X,"none"]}],"stroke-w":[{stroke:[zX,LX,K$]}],stroke:[{stroke:[X,"none"]}],sr:["sr-only","not-sr-only"],"forced-color-adjust":[{"forced-color-adjust":["auto","none"]}]},conflictingClassGroups:{overflow:["overflow-x","overflow-y"],overscroll:["overscroll-x","overscroll-y"],inset:["inset-x","inset-y","start","end","top","right","bottom","left"],"inset-x":["right","left"],"inset-y":["top","bottom"],flex:["basis","grow","shrink"],gap:["gap-x","gap-y"],p:["px","py","ps","pe","pt","pr","pb","pl"],px:["pr","pl"],py:["pt","pb"],m:["mx","my","ms","me","mt","mr","mb","ml"],mx:["mr","ml"],my:["mt","mb"],size:["w","h"],"font-size":["leading"],"fvn-normal":["fvn-ordinal","fvn-slashed-zero","fvn-figure","fvn-spacing","fvn-fraction"],"fvn-ordinal":["fvn-normal"],"fvn-slashed-zero":["fvn-normal"],"fvn-figure":["fvn-normal"],"fvn-spacing":["fvn-normal"],"fvn-fraction":["fvn-normal"],"line-clamp":["display","overflow"],rounded:["rounded-s","rounded-e","rounded-t","rounded-r","rounded-b","rounded-l","rounded-ss","rounded-se","rounded-ee","rounded-es","rounded-tl","rounded-tr","rounded-br","rounded-bl"],"rounded-s":["rounded-ss","rounded-es"],"rounded-e":["rounded-se","rounded-ee"],"rounded-t":["rounded-tl","rounded-tr"],"rounded-r":["rounded-tr","rounded-br"],"rounded-b":["rounded-br","rounded-bl"],"rounded-l":["rounded-tl","rounded-bl"],"border-spacing":["border-spacing-x","border-spacing-y"],"border-w":["border-w-s","border-w-e","border-w-t","border-w-r","border-w-b","border-w-l"],"border-w-x":["border-w-r","border-w-l"],"border-w-y":["border-w-t","border-w-b"],"border-color":["border-color-s","border-color-e","border-color-t","border-color-r","border-color-b","border-color-l"],"border-color-x":["border-color-r","border-color-l"],"border-color-y":["border-color-t","border-color-b"],"scroll-m":["scroll-mx","scroll-my","scroll-ms","scroll-me","scroll-mt","scroll-mr","scroll-mb","scroll-ml"],"scroll-mx":["scroll-mr","scroll-ml"],"scroll-my":["scroll-mt","scroll-mb"],"scroll-p":["scroll-px","scroll-py","scroll-ps","scroll-pe","scroll-pt","scroll-pr","scroll-pb","scroll-pl"],"scroll-px":["scroll-pr","scroll-pl"],"scroll-py":["scroll-pt","scroll-pb"],touch:["touch-x","touch-y","touch-pz"],"touch-x":["touch"],"touch-y":["touch"],"touch-pz":["touch"]},conflictingClassGroupModifiers:{"font-size":["leading"]}}};var S$=SQ(aQ);var c$=k(L0(),1),s0=k(d(),1),SX=k(L0(),1),j0=k(d(),1),l$=k(d(),1),B$=k(d(),1),yX=k(L0(),1),I0=k(d(),1),T0=k(L0(),1),d$=k(eQ(),1),w=k(d(),1),lX=k(d(),1),W=k(d(),1),u0=k(d(),1),g0=k(d(),1),tX=k(d(),1),o0=k(L0(),1),U0=k(d(),1),C0=k(d(),1),L$=k(d(),1),C=k(d(),1),M0=k(d(),1),l=k(d(),1),o$=k(L0(),1),D0=k(d(),1),wX=k(d(),1),E=k(d(),1),c=k(d(),1),cX=k(d(),1),G0=k(L0(),1),D=k(d(),1),HX=k(L0(),1),v=k(d(),1),r$=k(L0(),1),i0=k(d(),1),J0=k(L0(),1),w0=k(d(),1),eZ=k(L0(),1),s$=k(d(),1),m0=k(L0(),1),ZX=k(d(),1),$$=k(L0(),1),GX=k(d(),1),N0=k(d(),1),JX=k(d(),1),F$=k(L0(),1),W$=k(d(),1),zz=k(L0(),1),t$=k(d(),1),e$=k(L0(),1),XQ=k(d(),1),Yz=k(L0(),1),$Q=k(d(),1),QQ=k(d(),1),ZQ=k(d(),1),Q$=k(L0(),1),Jz=k(L0(),1),N$=k(d(),1),zQ=k(d(),1),YQ=k(d(),1),JQ=k(d(),1),HQ=k(L0(),1),GQ=k(L0(),1),XZ=Object.defineProperty,$Z=(X,$,Q)=>($ in X)?XZ(X,$,{enumerable:!0,configurable:!0,writable:!0,value:Q}):X[$]=Q,QZ=(X,$,Q)=>$Z(X,typeof $!=="symbol"?$+"":$,Q);function q0(...X){return S$(g$(X))}var Fz=[{id:"msg-1",role:"assistant",content:"Hello! I'm your AI assistant. How can I help you today?",timestamp:new Date(Date.now()-3600000)},{id:"msg-2",role:"user",content:"I want to plan a trip to Europe",timestamp:new Date(Date.now()-3500000)},{id:"msg-3",role:"assistant",content:"Great choice! Europe has amazing destinations. What's your budget and how many days do you have?",timestamp:new Date(Date.now()-3400000)},{id:"msg-4",role:"user",content:"Around $2000 for 5 days",timestamp:new Date(Date.now()-3300000)},{id:"msg-5",role:"assistant",content:"Perfect! I found some great destinations that fit your budget:",widgets:[{type:"list",id:"destinations-1",props:{items:[{id:"paris",title:"Paris, France",subtitle:"5 days • $1,850",description:"The City of Light with iconic landmarks",metadata:{city:"Paris",country:"France",lat:48.8566,lng:2.3522,price:1850,days:5}},{id:"rome",title:"Rome, Italy",subtitle:"5 days • $1,650",description:"Ancient history meets modern culture",metadata:{city:"Rome",country:"Italy",lat:41.9028,lng:12.4964,price:1650,days:5}},{id:"barcelona",title:"Barcelona, Spain",subtitle:"5 days • $1,450",description:"Beautiful beaches and Gaudí architecture",metadata:{city:"Barcelona",country:"Spain",lat:41.3851,lng:2.1734,price:1450,days:5}}]},actions:[{type:"select_destination",label:"Select",handler:"client",payload:{}},{type:"view_details",label:"Details",handler:"server",payload:{}}]}],timestamp:new Date(Date.now()-3200000)}],Wz=[{id:"thread-1",title:"Trip to Europe",preview:"Planning a 5-day trip...",createdAt:new Date(Date.now()-86400000),updatedAt:new Date(Date.now()-3600000),messageCount:12},{id:"thread-2",title:"Restaurant Recommendations",preview:"Looking for good places...",createdAt:new Date(Date.now()-172800000),updatedAt:new Date(Date.now()-86400000),messageCount:8},{id:"thread-3",title:"Budget Planning",preview:"Help with monthly budget",createdAt:new Date(Date.now()-259200000),updatedAt:new Date(Date.now()-172800000),messageCount:15}];function ZZ(X=1000){return new Promise(($)=>{setTimeout(()=>{$({id:`msg-${Date.now()}`,role:"assistant",content:"This is a mock response. In production, this would come from your AI agent API.",timestamp:new Date})},X)})}function zZ(X){let $=X.toLowerCase();if($.includes("analyze")||$.includes("analysis"))return`Analysis complete for "${X}". Found 247 records with an average value of $1,234. The data shows a 23% increase compared to last quarter. Key insights: Revenue is up, customer satisfaction improved by 15%, and operational costs decreased by 8%.`;if($.includes("sales")||$.includes("revenue"))return"Sales data processed: Q4 2024 revenue reached $2.4M, representing 18% growth year-over-year. Top performing products: Enterprise Plan (+45%), Pro Plan (+32%), Basic Plan (+12%). Regional breakdown: North America (52%), Europe (31%), APAC (17%).";if($.includes("report")||$.includes("summary"))return"Report generated successfully. Executive Summary: Overall performance exceeded targets by 12%. Marketing ROI improved to 3.2x, customer acquisition cost reduced by 18%, and lifetime value increased by 24%. Detailed breakdown available in attached widgets.";if($.includes("data")||$.includes("metrics"))return"Data metrics retrieved: 1,847 active users, 12,394 sessions this month, 94.2% uptime, average response time 127ms. Performance is within acceptable parameters. No critical issues detected.";if($.includes("customer")||$.includes("user"))return"Customer analysis complete: 523 new customers this month, 89% retention rate, average satisfaction score 4.6/5. Top feedback themes: excellent support (87%), easy to use (72%), good value (68%). 3 support tickets pending review.";return"This is a mock response showing how your agent would process and respond to commands. The actual response would be generated by your AI agent based on real data and context."}function YZ(X){let $=zZ(X),Q=X.toLowerCase(),Z=[],z;if(Q.includes("sales")||Q.includes("revenue")||Q.includes("analyze"))Z.push({type:"card",id:`widget-${Date.now()}-1`,props:{title:"Q4 2024 Performance",description:"Revenue: $2.4M (+18% YoY)",footer:"Updated: "+new Date().toLocaleDateString()},actions:[{type:"view_details",label:"View Details",handler:"client",payload:{reportId:"q4-2024"}}]});if(Q.includes("customer")||Q.includes("user"))Z.push({type:"list",id:`widget-${Date.now()}-2`,props:{items:[{id:"metric-1",title:"Active Users",subtitle:"1,847 users",description:"+12% from last month"},{id:"metric-2",title:"Retention Rate",subtitle:"89%",description:"Above industry average"},{id:"metric-3",title:"Satisfaction Score",subtitle:"4.6/5",description:"Based on 234 reviews"}]}});if(Q.includes("task")||Q.includes("todo")||Q.includes("work")||Q.includes("completed"))Z.push({type:"list",id:`widget-${Date.now()}-tasks`,props:{items:[{id:"task-1",title:"Implement user authentication",subtitle:"Created just now",description:"Added OAuth 2.0 support with Google and GitHub providers",backgroundColor:"rgba(59, 130, 246, 0.15)",metadata:{status:"created",priority:"high",tags:["backend","security"]}},{id:"task-2",title:"Update API documentation",subtitle:"Modified 2 minutes ago",description:"Changed endpoint descriptions and added new examples",backgroundColor:"rgba(234, 179, 8, 0.15)",metadata:{status:"modified",priority:"medium",tags:["docs"]}},{id:"task-3",title:"Fix login redirect bug",subtitle:"Completed 5 minutes ago",description:"Users now properly redirected after successful login",backgroundColor:"rgba(34, 197, 94, 0.15)",metadata:{status:"completed",priority:"urgent",tags:["bugfix","auth"]}}]},actions:[{type:"view_task",label:"View",handler:"client",payload:{}},{type:"undo",label:"Undo",handler:"server",payload:{}}]}),z={type:"update_database",payload:{table:"tasks",operation:"mark_as_viewed",taskIds:["task-1","task-2","task-3"],timestamp:new Date().toISOString()}};if(Q.includes("analyze")||Q.includes("analysis"))z={type:"send_notification",payload:{recipient:"team@company.com",subject:"Analysis Complete",message:"Your requested analysis has been completed and is ready for review."}};return{message:$,widgets:Z,action:z}}function JZ(X,$,Q,Z,z=30){let{message:H,widgets:G}=YZ(X),J=H.split(" "),U=0,K=setInterval(()=>{try{if(U<J.length)$({type:"token",content:J[U]+" "}),U++;else{clearInterval(K),G.forEach((Y)=>{$({type:"widget",widget:Y})});let O=`mock_thread_${Date.now()}`;$({type:"complete"}),Q(O)}}catch(O){clearInterval(K),Z(O instanceof Error?O:Error("Mock streaming error"))}},z)}function HZ(X){return new Promise(($,Q)=>{let Z=new FileReader;Z.onload=()=>{let H=Z.result.split(",")[1];$(H)},Z.onerror=()=>Q(Error("Failed to read file")),Z.readAsDataURL(X)})}function GZ(X){if(X.startsWith("image/"))return"image";return"document"}function qZ(X){return["image/jpeg","image/png","image/gif","image/webp","application/pdf","text/plain","application/msword","application/vnd.openxmlformats-officedocument.wordprocessingml.document"].includes(X.type)}async function KZ(X){let $=await HZ(X);return{type:GZ(X.type),source:{type:"base64",media_type:X.type,data:$}}}async function OZ(X){let $=Array.from(X);return await Promise.all($.map((Z)=>KZ(Z)))}async function y$(X,$){if(!$||$.length===0)return X;let Q=[];if(X.trim())Q.push({type:"text",text:X.trim()});let Z=await OZ($);return Q.push(...Z),Q}function eX(X){if(X<1024)return`${X} B`;if(X<1048576)return`${(X/1024).toFixed(1)} KB`;return`${(X/1048576).toFixed(1)} MB`}var C$=10485760;function u$(X){if(!qZ(X))return{valid:!1,error:`Unsupported file type: ${X.type}`};if(X.size>C$)return{valid:!1,error:`File too large: ${eX(X.size)} (max ${eX(C$)})`};return{valid:!0}}var UZ=["list","table"];function VZ(X){let $=[],Q=!1,Z=X.match(/"items"\s*:\s*\[/);if(!Z)return{items:$,isStreaming:!1};let z=X.indexOf("[",Z.index);if(z===-1)return{items:$,isStreaming:!0};let H=0,G=!1,J=!1,U=-1;for(let Y=z+1;Y<X.length;Y++){let V=X[Y];if(J){J=!1;continue}if(V==="\\"&&G){J=!0;continue}if(V==='"'){G=!G;continue}if(G)continue;if(V==="{"){if(H===0)U=Y;H++}else if(V==="}"){if(H--,H===0&&U!==-1){let _=X.slice(U,Y+1);try{let B=JSON.parse(_);if(!B.id)B.id=`item-${$.length}-${V$(_)}`;$.push(B)}catch(B){}U=-1}}else if(V==="]"&&H===0){Q=!1;break}}if(H>0||U!==-1)Q=!0;let K=X.slice(z);if(_$(K,0)===-1)Q=!0;return{items:$,isStreaming:Q}}function V$(X){let $=0;for(let Q=0;Q<X.length;Q++){let Z=X.charCodeAt(Q);$=($<<5)-$+Z,$=$&$}return Math.abs($).toString(36)}function _$(X,$){let Q=0,Z=!1,z=!1;for(let H=$;H<X.length;H++){let G=X[H];if(z){z=!1;continue}if(G==="\\"&&Z){z=!0;continue}if(G==='"'){Z=!Z;continue}if(Z)continue;if(G==="["||G==="{")Q++;else if(G==="]"||G==="}"){if(Q--,Q===0)return H}}return-1}function aX(X){let $=[],Q=!1,Z=!1,z=0,H=null,G=X.replace(/<\/?ui\s*\/?>/gi,""),J=X.lastIndexOf("@ui:");if(J!==-1){let O=X.slice(J),Y=O.match(/^@ui:(\w+)/);if(Y){let V=Y[1],_=O.indexOf("[");if(_===-1)G=X.slice(0,J),H=V,Z=!0;else{let B=J+_;if(_$(X,B)===-1)if(UZ.includes(V)){let I=X.slice(B+1),{items:M,isStreaming:h}=VZ(I);if(M.length>0){G=X.slice(0,J);let i=`widget-${V}-streaming-${V$(I)}`,o=G.replace(/[\s:;\-–—\.]+$/g,"").trim();if(o)$.push({type:"text",content:o});$.push({type:"widget",widget:{type:V,id:i,props:V==="table"?{rows:M,columns:[]}:{items:M},isStreaming:h}}),Q=!0,Z=!1,G=""}else G=X.slice(0,J),H=V,Z=!0}else G=X.slice(0,J),H=V,Z=!0}}}if(Z)G=G.replace(/[\s:;\-–—\.]+$/g,"");let U=/@ui:(\w+)\[/g,K;while((K=U.exec(G))!==null){let O=K[1],Y=K.index+K[0].length-1,V=_$(G,Y);if(V===-1)continue;let _=G.slice(Y+1,V);if(K.index>z){let B=G.slice(z,K.index).trim();if(B)$.push({type:"text",content:B})}try{let B=_.trim(),A=JSON.parse(B),I=`widget-${O}-${V$(B)}`,{metadata:M,actions:h,...i}=A;$.push({type:"widget",widget:{type:O,id:I,props:i,...h&&{actions:h},...M&&{metadata:M}}}),Q=!0}catch(B){}z=V+1,U.lastIndex=z}if(z<G.length){let O=G.slice(z).trim();if(O)$.push({type:"text",content:O})}if($.length===0&&G.trim())$.push({type:"text",content:G.trim()});if(H)$.push({type:"widget_pending",pendingType:H});return{segments:$,hasWidgets:Q,hasPendingWidget:Z}}var D$={card:{schema:"title, description?, image?(url), footer?, actions?: [{type, label}]",example:'@ui:card[{"title": "Summary", "description": "Details here"}]'},list:{schema:"items: [{id, title, subtitle?, description?, image?(url), metadata?: {…}}], actions?: [{type, label}]",example:'@ui:list[{"items": [{"id": "1", "title": "Item", "subtitle": "Info", "metadata": {"key": "value"}}]}]'},button_group:{schema:'buttons: [{id, label, variant?: "default"|"primary"|"danger"}]',example:'@ui:button_group[{"buttons": [{"id": "ok", "label": "OK"}]}]'},form:{schema:'title?, fields: [{name, type: "text"|"password"|"number"|"select"|"checkbox"|"textarea"|"date", label, required?, placeholder?, options?: [{label, value}]}], submitLabel?: string',example:'@ui:form[{"title": "Settings", "fields": [{"name": "key", "type": "password", "label": "API Key", "required": true}]}]'},table:{schema:"columns: [{key, label}], rows: [{key: value, …}], striped?, compact?",example:'@ui:table[{"columns": [{"key": "name", "label": "Name"}], "rows": [{"name": "Alice"}]}]'},image:{schema:"src(url), alt, caption?",example:'@ui:image[{"src": "https://example.com/img.png", "alt": "Photo"}]'},chart:{schema:'chartType: "line"|"bar"|"pie", data: {labels: [...], datasets: [{label, data: [numbers]}]}',example:'@ui:chart[{"chartType": "bar", "data": {"labels": ["Q1", "Q2"], "datasets": [{"label": "Revenue", "data": [100, 150]}]}}]'},flow:{schema:'title, subtitle?, icon?: "research"|"schedule"|"analyze"|"deploy"|"recurring"|"automation"|"data", steps: [{id, label, color?: "blue"|"purple"|"cyan"|"amber"|"emerald"|"rose"|"indigo"|"orange", status?: "pending"|"active"|"completed"|"error"|"skipped"}]',example:'@ui:flow[{"title": "Pipeline", "steps": [{"id": "1", "label": "Test", "color": "cyan"}, {"id": "2", "label": "Deploy", "color": "rose"}]}]'}},_Z=Object.keys(D$),BZ=["flow"],m$=_Z.filter((X)=>!BZ.includes(X));function LZ(X){let $=X||m$,Q=`
|
|
7
|
+
## UI Widgets
|
|
8
|
+
|
|
9
|
+
You can render interactive UI widgets inline in your responses. Use them when structured display is clearer than plain text (showing data, forms, actions, images). You may include normal text before or after a widget.
|
|
10
|
+
|
|
11
|
+
**Syntax:** \`@ui:type[{json}]\` — the JSON object MUST be wrapped in square brackets \`[]\`.
|
|
12
|
+
|
|
13
|
+
Example:
|
|
14
|
+
@ui:list[{"items": [{"id": "1", "title": "First item"}]}]
|
|
15
|
+
|
|
16
|
+
Do NOT wrap widgets in code blocks or backticks. Write them directly in your response text.
|
|
17
|
+
|
|
18
|
+
### Available widgets
|
|
19
|
+
|
|
20
|
+
`;for(let Z of $){let z=D$[Z];if(!z)continue;Q+=`**${Z}** — ${z.schema}
|
|
21
|
+
`,Q+=` ${z.example}
|
|
22
|
+
|
|
23
|
+
`}return Q+='### Notes\n- **actions**: the `type` field is a custom string you choose (e.g. "edit", "delete"). It is returned to the app when the user clicks the button.\n- **metadata** on list items: any extra data attached to an item. Returned as the action payload when the user clicks that item.\n- **form**: always has a submit button (label defaults to "Submit"). When clicked, the form data is sent as a chat message automatically. Do NOT add a separate button_group for form submission.\n- **select fields**: `options` is an array of `{label, value}` objects.\n',Q}function DZ(X){let $=X||m$,Q=`
|
|
24
|
+
## UI Widgets
|
|
25
|
+
Render widgets inline: \`@ui:type[{json}]\` (square brackets required, no code blocks).
|
|
26
|
+
Use when structured display is clearer than plain text. Normal text can surround widgets.
|
|
27
|
+
|
|
28
|
+
`;for(let Z of $){let z=D$[Z];if(!z)continue;Q+=`**${Z}**: ${z.schema}
|
|
29
|
+
`}return Q+=`
|
|
30
|
+
actions.type = custom string returned on click. list metadata = payload on item click. form submit sends data as chat message automatically, no button_group needed.
|
|
31
|
+
`,Q}function p$(X){let $=[],Q=null;for(let Z=0;Z<X.length;Z++){let z=X[Z],H=z.created_at||z.timestamp?new Date(z.created_at||z.timestamp):new Date;if(typeof z.content==="string"){let G={id:z.id||`thread-msg-${Z}`,role:z.role,content:z.content,timestamp:H};$.push(G),Q=null}else if(Array.isArray(z.content)){if(z.role==="assistant"){let G=[],J="";for(let K of z.content)if(K.type==="text"&&K.text)G.push({type:"text",content:K.text}),J+=K.text;else if(K.type==="tool_use")G.push({type:"tool",id:K.id||`tool-${Z}-${G.length}`,name:K.name||"unknown",status:"completed"});let U={id:z.id||`thread-msg-${Z}`,role:"assistant",content:J,timestamp:H,metadata:G.length>0?{content_segments:G}:void 0};$.push(U),Q=G}else if(z.role==="user")if(z.content.some((J)=>J.type==="tool_result")&&Q){for(let J of z.content)if(J.type==="tool_result"&&J.tool_use_id){let U=Q.find((K)=>K.type==="tool"&&K.id===J.tool_use_id);if(U&&U.type==="tool")U.result=typeof J.content==="string"?J.content:Array.isArray(J.content)?J.content.map((K)=>K.text||"").join(""):void 0,U.status=J.is_error?"error":"completed"}}else{let J=z.content.filter((U)=>U.type==="text").map((U)=>U.text||"").join("");if(J)$.push({id:z.id||`thread-msg-${Z}`,role:"user",content:J,timestamp:H});Q=null}}}return $}function FZ({widget:X,onAction:$}){let{title:Q,description:Z,image:z,footer:H}=X.props;return s0.jsxs("div",{className:"border border-neutral-200 dark:border-neutral-700 rounded-xl bg-white dark:bg-neutral-900 overflow-hidden",children:[z&&s0.jsx("img",{src:z,alt:Q,className:"w-full h-48 object-cover"}),s0.jsxs("div",{className:"p-4",children:[s0.jsx("h3",{className:"!text-lg font-semibold !text-neutral-900 dark:!text-white",children:Q}),Z&&s0.jsx("p",{className:"!text-neutral-600 dark:!text-neutral-400 mt-2",children:Z})]}),(H||X.actions&&X.actions.length>0)&&s0.jsxs("div",{className:"border-t border-neutral-200 dark:border-neutral-700 p-4 flex justify-between items-center",children:[H&&s0.jsx("span",{className:"!text-sm !text-neutral-600 dark:!text-neutral-400",children:H}),X.actions&&X.actions.length>0&&s0.jsx("div",{className:"flex gap-2",children:X.actions.map((G,J)=>s0.jsx("button",{onClick:()=>$?.({type:G.type,payload:G.payload,widgetId:X.id,timestamp:new Date}),className:"px-3 py-1.5 !text-sm rounded-lg font-medium transition-colors bg-blue-500 !text-white hover:bg-blue-600",children:G.label},J))})]})]})}function WZ({widget:X,onAction:$}){let{items:Q}=X.props,Z=X.isStreaming??!1,z=SX.useRef(new Set),[H,G]=SX.useState(new Set);return SX.useEffect(()=>{let J=new Set(Q.map((K)=>K.id)),U=new Set;if(Q.forEach((K)=>{if(!z.current.has(K.id))U.add(K.id)}),Q.forEach((K)=>z.current.add(K.id)),U.size>0){G(U);let K=setTimeout(()=>{G(new Set)},500);return()=>clearTimeout(K)}},[Q]),j0.jsxs("div",{className:"border border-neutral-200 dark:border-neutral-700 rounded-xl bg-white dark:bg-neutral-900 overflow-hidden",children:[Q.map((J,U)=>{let K=H.has(J.id),O=U===Q.length-1;return j0.jsxs("div",{className:`apteva-list-item flex items-center p-4 transition-colors ${!O||Z?"border-b border-neutral-200 dark:border-neutral-700":""} ${!J.backgroundColor?"hover:bg-neutral-50 dark:hover:bg-neutral-800":""} ${K?"apteva-list-item-new":""}`,style:J.backgroundColor?{backgroundColor:J.backgroundColor}:void 0,children:[J.image&&j0.jsx("img",{src:J.image,alt:J.title,className:"w-16 h-16 rounded object-cover"}),j0.jsxs("div",{className:`flex-1 ${J.image?"ml-4":""}`,children:[j0.jsx("h4",{className:"font-semibold !text-neutral-900 dark:!text-white",children:J.title}),J.subtitle&&j0.jsx("p",{className:"!text-sm !text-neutral-600 dark:!text-neutral-400",children:J.subtitle}),J.description&&j0.jsx("p",{className:"!text-xs !text-neutral-500 dark:!text-neutral-500 mt-1",children:J.description})]}),X.actions&&X.actions.length>0&&j0.jsx("div",{className:"flex gap-2",children:X.actions.map((Y,V)=>j0.jsx("button",{onClick:()=>$?.({type:Y.type,payload:J.metadata||J,widgetId:X.id,timestamp:new Date}),className:"px-3 py-1.5 !text-sm rounded-lg font-medium transition-colors bg-blue-500 !text-white hover:bg-blue-600",children:Y.label},V))})]},J.id)}),Z&&j0.jsxs("div",{className:"apteva-list-streaming flex items-center gap-3 p-4 text-neutral-500 dark:text-neutral-400",children:[j0.jsxs("div",{className:"apteva-streaming-dots flex gap-1",children:[j0.jsx("span",{className:"w-2 h-2 bg-current rounded-full animate-pulse",style:{animationDelay:"0ms"}}),j0.jsx("span",{className:"w-2 h-2 bg-current rounded-full animate-pulse",style:{animationDelay:"150ms"}}),j0.jsx("span",{className:"w-2 h-2 bg-current rounded-full animate-pulse",style:{animationDelay:"300ms"}})]}),j0.jsx("span",{className:"text-sm",children:"Loading more..."})]})]})}function NZ({widget:X,onAction:$}){let{label:Q,variant:Z="primary",disabled:z=!1}=X.props;return l$.jsx("button",{onClick:()=>X.actions?.[0]&&$?.({type:X.actions[0].type,payload:X.actions[0].payload,widgetId:X.id,timestamp:new Date}),disabled:z,className:q0("px-4 py-2 rounded-lg font-medium transition-colors",{primary:"bg-blue-500 !text-white hover:bg-blue-600",secondary:"bg-neutral-500 !text-white hover:bg-neutral-600",outline:"border-2 border-blue-500 !text-blue-500 hover:bg-blue-50 dark:hover:bg-blue-900",ghost:"!text-blue-500 hover:bg-blue-50 dark:hover:bg-blue-900"}[Z],{"opacity-50 cursor-not-allowed":z}),children:Q})}function AZ({widget:X,onAction:$}){let{layout:Q="horizontal",buttons:Z}=X.props,z={primary:"bg-blue-500 !text-white hover:bg-blue-600",secondary:"bg-neutral-200 dark:bg-neutral-700 !text-neutral-800 dark:!text-neutral-200 hover:bg-neutral-300 dark:hover:bg-neutral-600",outline:"border border-neutral-300 dark:border-neutral-600 !text-neutral-700 dark:!text-neutral-300 hover:bg-neutral-100 dark:hover:bg-neutral-800"},H=(G)=>{return X.actions?.find((J)=>J.payload?.buttonId===G)||X.actions?.[0]};return B$.jsx("div",{className:q0("flex gap-2",Q==="vertical"?"flex-col":"flex-row flex-wrap"),children:Z.map((G)=>{let J=H(G.id);return B$.jsx("button",{onClick:()=>{if(J)$?.({type:J.type,payload:{...J.payload,buttonId:G.id},widgetId:X.id,timestamp:new Date})},className:q0("px-4 py-2 rounded-lg font-medium transition-colors text-sm",z[G.variant||"secondary"]),children:G.label},G.id)})})}function PZ({widget:X,onAction:$}){let{columns:Q,rows:Z,caption:z,compact:H=!1,striped:G=!1}=X.props,J=X.isStreaming??!1,U=yX.useRef(new Set),[K,O]=yX.useState(new Set);yX.useEffect(()=>{let V=new Set;if(Z.forEach((_,B)=>{let A=_.id||`row-${B}`;if(!U.current.has(A))V.add(A)}),Z.forEach((_,B)=>{let A=_.id||`row-${B}`;U.current.add(A)}),V.size>0){O(V);let _=setTimeout(()=>{O(new Set)},500);return()=>clearTimeout(_)}},[Z]);let Y=(V)=>{switch(V){case"center":return"text-center";case"right":return"text-right";default:return"text-left"}};return I0.jsx("div",{className:"border border-neutral-200 dark:border-neutral-700 rounded-xl bg-white dark:bg-neutral-900 overflow-hidden",children:I0.jsx("div",{className:"overflow-x-auto",children:I0.jsxs("table",{className:"w-full",children:[z&&I0.jsx("caption",{className:"px-4 py-2 text-sm text-neutral-600 dark:text-neutral-400 text-left bg-neutral-50 dark:bg-neutral-800 border-b border-neutral-200 dark:border-neutral-700",children:z}),I0.jsx("thead",{children:I0.jsx("tr",{className:"bg-neutral-50 dark:bg-neutral-800 border-b border-neutral-200 dark:border-neutral-700",children:Q.map((V)=>I0.jsx("th",{className:q0("font-semibold text-neutral-900 dark:text-white",H?"px-3 py-2 text-xs":"px-4 py-3 text-sm",Y(V.align)),style:V.width?{width:V.width}:void 0,children:V.label},V.key))})}),I0.jsxs("tbody",{children:[Z.map((V,_)=>{let B=V.id||`row-${_}`,A=K.has(B);return I0.jsx("tr",{className:q0("apteva-table-row border-b border-neutral-200 dark:border-neutral-700 last:border-b-0","transition-colors hover:bg-neutral-50 dark:hover:bg-neutral-800",G&&_%2===1&&"bg-neutral-50/50 dark:bg-neutral-800/50",A&&"apteva-table-row-new"),onClick:()=>{if(X.actions&&X.actions.length>0)$?.({type:X.actions[0].type,payload:V,widgetId:X.id,timestamp:new Date})},style:{cursor:X.actions?.length?"pointer":"default"},children:Q.map((I)=>I0.jsx("td",{className:q0("text-neutral-700 dark:text-neutral-300",H?"px-3 py-2 text-xs":"px-4 py-3 text-sm",Y(I.align)),children:V[I.key]??"—"},I.key))},B)}),Z.length===0&&!J&&I0.jsx("tr",{children:I0.jsx("td",{colSpan:Q.length||1,className:"px-4 py-8 text-center text-sm text-neutral-500 dark:text-neutral-400",children:"No data available"})}),J&&I0.jsx("tr",{className:"apteva-table-streaming",children:I0.jsx("td",{colSpan:Q.length||1,className:"px-4 py-3 text-center",children:I0.jsxs("div",{className:"flex items-center justify-center gap-3 text-neutral-500 dark:text-neutral-400",children:[I0.jsxs("div",{className:"flex gap-1",children:[I0.jsx("span",{className:"w-2 h-2 bg-current rounded-full animate-pulse",style:{animationDelay:"0ms"}}),I0.jsx("span",{className:"w-2 h-2 bg-current rounded-full animate-pulse",style:{animationDelay:"150ms"}}),I0.jsx("span",{className:"w-2 h-2 bg-current rounded-full animate-pulse",style:{animationDelay:"300ms"}})]}),I0.jsx("span",{className:"text-sm",children:"Loading more..."})]})})})]})]})})})}function i$({anchorRef:X,open:$,onClose:Q,width:Z,children:z}){let H=T0.useRef(null),[G,J]=T0.useState(null),[U,K]=T0.useState("");if(T0.useEffect(()=>{if(!$||!X.current)return;let O=X.current.closest(".apteva-chat");if(O)if(O.classList.contains("apteva-force-light"))K("apteva-force-light");else if(O.classList.contains("apteva-force-dark"))K("apteva-force-dark");else K("")},[$,X]),T0.useEffect(()=>{if(!$||!X.current){J(null);return}let O=()=>{let Y=X.current.getBoundingClientRect();J({top:Y.bottom+window.scrollY+4,left:Y.left+window.scrollX,width:Y.width})};return O(),window.addEventListener("scroll",O,!0),window.addEventListener("resize",O),()=>{window.removeEventListener("scroll",O,!0),window.removeEventListener("resize",O)}},[$,X]),T0.useEffect(()=>{if(!$)return;let O=(Y)=>{let V=Y.target;if(H.current&&!H.current.contains(V)&&X.current&&!X.current.contains(V))Q()};return document.addEventListener("mousedown",O),()=>document.removeEventListener("mousedown",O)},[$,Q,X]),T0.useEffect(()=>{if(!$)return;let O=(Y)=>{if(Y.key==="Escape")Q()};return document.addEventListener("keydown",O),()=>document.removeEventListener("keydown",O)},[$,Q]),!$||!G)return null;return d$.createPortal(w.jsx("div",{ref:H,className:`apteva-widget ${U}`,style:{position:"absolute",top:G.top,left:G.left,width:Z==="match"?G.width:void 0,zIndex:99999},children:z}),document.body)}function EZ({name:X,value:$,options:Q,placeholder:Z,required:z,onChange:H}){let[G,J]=T0.useState(!1),U=T0.useRef(null),K=Q?.find((Y)=>Y.label===$||Y.value===$),O=T0.useCallback(()=>J(!1),[]);return w.jsxs("div",{className:"apteva-select relative",children:[w.jsxs("select",{name:X,value:$,required:z,onChange:()=>{},tabIndex:-1,className:"absolute inset-0 opacity-0 pointer-events-none","aria-hidden":!0,children:[w.jsx("option",{value:""}),Q?.map((Y)=>w.jsx("option",{value:Y.label,children:Y.label},Y.value))]}),w.jsxs("button",{ref:U,type:"button",onClick:()=>J(!G),className:"apteva-select-trigger w-full flex items-center justify-between px-3 py-2 rounded-lg border transition-colors text-left",children:[w.jsx("span",{className:K?"apteva-select-value":"apteva-select-placeholder",children:K?K.label:Z||"Select..."}),w.jsx("svg",{className:`apteva-select-chevron w-4 h-4 flex-shrink-0 transition-transform ${G?"rotate-180":""}`,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:w.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})})]}),w.jsx(i$,{anchorRef:U,open:G,onClose:O,width:"match",children:w.jsx("div",{className:"apteva-select-dropdown rounded-lg border shadow-lg overflow-hidden",children:w.jsxs("div",{className:"max-h-48 overflow-y-auto py-1",children:[Q?.map((Y)=>w.jsx("button",{type:"button",onClick:()=>{H(Y.label),O()},className:`apteva-select-option w-full text-left px-3 py-2 text-sm transition-colors ${$===Y.label?"apteva-select-option-active":""}`,children:Y.label},Y.value)),(!Q||Q.length===0)&&w.jsx("div",{className:"px-3 py-2 text-sm apteva-select-placeholder",children:"No options"})]})})})]})}function MZ({name:X,value:$,placeholder:Q,required:Z,onChange:z}){let[H,G]=T0.useState(!1),J=T0.useRef(null),U=T0.useCallback(()=>G(!1),[]),K=(P)=>{if(P){let[F,A0,$0]=P.split("-").map(Number);return{year:F,month:A0-1,day:$0}}let b=new Date;return{year:b.getFullYear(),month:b.getMonth(),day:0}},O=K($),[Y,V]=T0.useState(O.year),[_,B]=T0.useState(O.month);T0.useEffect(()=>{if($){let P=K($);V(P.year),B(P.month)}},[$]);let A=new Date(Y,_+1,0).getDate(),M=(new Date(Y,_,1).getDay()+6)%7,h=()=>{if(_===0)B(11),V(Y-1);else B(_-1)},i=()=>{if(_===11)B(0),V(Y+1);else B(_+1)},o=(P)=>{let b=String(_+1).padStart(2,"0"),F=String(P).padStart(2,"0");z(`${Y}-${b}-${F}`),U()},e=(P)=>{if(!P)return"";let[b,F,A0]=P.split("-");return`${A0}/${F}/${b}`},R=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],j=["Mo","Tu","We","Th","Fr","Sa","Su"],T=(P)=>{if(!$)return!1;let b=K($);return b.year===Y&&b.month===_&&b.day===P},f=(P)=>{let b=new Date;return b.getFullYear()===Y&&b.getMonth()===_&&b.getDate()===P};return w.jsxs("div",{className:"apteva-datepicker relative",children:[w.jsx("input",{type:"text",name:X,value:$,required:Z,onChange:()=>{},tabIndex:-1,className:"absolute inset-0 opacity-0 pointer-events-none","aria-hidden":!0}),w.jsxs("button",{ref:J,type:"button",onClick:()=>G(!H),className:"apteva-datepicker-trigger w-full flex items-center justify-between px-3 py-2 rounded-lg border transition-colors text-left",children:[w.jsx("span",{className:$?"apteva-datepicker-value":"apteva-select-placeholder",children:$?e($):Q||"Select date..."}),w.jsx("svg",{className:"apteva-select-chevron w-4 h-4 flex-shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:w.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 7V3m8 4V3m-9 8h10M5 21h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v12a2 2 0 002 2z"})})]}),w.jsx(i$,{anchorRef:J,open:H,onClose:U,width:"auto",children:w.jsxs("div",{className:"apteva-datepicker-dropdown rounded-lg border shadow-lg overflow-hidden",children:[w.jsxs("div",{className:"apteva-datepicker-header flex items-center justify-between px-3 py-2",children:[w.jsx("button",{type:"button",onClick:h,className:"apteva-datepicker-nav p-1 rounded transition-colors",children:w.jsx("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:w.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M15 19l-7-7 7-7"})})}),w.jsxs("span",{className:"apteva-datepicker-title text-sm font-semibold",children:[R[_]," ",Y]}),w.jsx("button",{type:"button",onClick:i,className:"apteva-datepicker-nav p-1 rounded transition-colors",children:w.jsx("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:w.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 5l7 7-7 7"})})})]}),w.jsx("div",{className:"grid grid-cols-7 px-2",children:j.map((P)=>w.jsx("div",{className:"apteva-datepicker-daylabel text-center text-xs font-medium py-1",children:P},P))}),w.jsxs("div",{className:"grid grid-cols-7 px-2 pb-2",children:[Array.from({length:M}).map((P,b)=>w.jsx("div",{},`empty-${b}`)),Array.from({length:A}).map((P,b)=>{let F=b+1,A0=T(F),$0=f(F);return w.jsx("button",{type:"button",onClick:()=>o(F),className:["apteva-datepicker-day text-center text-sm py-1 rounded transition-colors",A0?"apteva-datepicker-day-selected":"",$0&&!A0?"apteva-datepicker-day-today":""].join(" "),children:F},F)})]})]})})]})}function TZ({widget:X,onAction:$}){let{title:Q,fields:Z}=X.props,z=T0.useRef({}),[H,G]=T0.useState(()=>{let Y={};return Z.forEach((V)=>{if(V.type==="file")Y[V.name]=[];else Y[V.name]=V.defaultValue??(V.type==="checkbox"?!1:"")}),Y}),J=T0.useCallback((Y,V)=>{G((_)=>({..._,[Y]:V}))},[]),U=(Y)=>{if(Y.preventDefault(),$)$({type:"submit",payload:{formData:H},widgetId:X.id,timestamp:new Date})},K=(Y)=>{switch(Y.type){case"text":case"password":case"number":return w.jsx("input",{type:Y.type,name:Y.name,value:H[Y.name]||"",onChange:(_)=>J(Y.name,Y.type==="number"?Number(_.target.value):_.target.value),placeholder:Y.placeholder,required:Y.required,className:"apteva-input w-full px-3 py-2 rounded-lg border transition-colors focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent"});case"date":return w.jsx(MZ,{name:Y.name,value:H[Y.name]||"",placeholder:Y.placeholder,required:Y.required,onChange:(_)=>J(Y.name,_)});case"textarea":return w.jsx("textarea",{name:Y.name,value:H[Y.name]||"",onChange:(_)=>J(Y.name,_.target.value),placeholder:Y.placeholder,required:Y.required,rows:3,className:"apteva-input w-full px-3 py-2 rounded-lg border transition-colors focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent"});case"select":return w.jsx(EZ,{name:Y.name,value:H[Y.name]||"",options:Y.options,placeholder:Y.placeholder,required:Y.required,onChange:(_)=>J(Y.name,_)});case"checkbox":return w.jsxs("label",{className:"apteva-checkbox flex items-center gap-2 cursor-pointer",children:[w.jsx("input",{type:"checkbox",name:Y.name,checked:H[Y.name]||!1,onChange:(_)=>J(Y.name,_.target.checked),className:"w-4 h-4 rounded"}),w.jsx("span",{children:Y.label})]});case"file":{let _=H[Y.name]||[];return w.jsxs("div",{className:"space-y-2",children:[w.jsx("input",{ref:(B)=>{z.current[Y.name]=B},type:"file",name:Y.name,multiple:Y.multiple??!0,accept:Y.accept,onChange:(B)=>{let A=Array.from(B.target.files||[]);if(Y.multiple!==!1)J(Y.name,[..._,...A]);else J(Y.name,A);if(z.current[Y.name])z.current[Y.name].value=""},className:"hidden"}),w.jsx("button",{type:"button",onClick:()=>z.current[Y.name]?.click(),className:"apteva-file-drop w-full px-3 py-3 rounded-lg border-2 border-dashed transition-colors cursor-pointer !text-sm",children:Y.placeholder||"Click to add files"}),_.length>0&&w.jsx("ul",{className:"space-y-1",children:_.map((B,A)=>w.jsxs("li",{className:"apteva-file-item-row flex items-center justify-between px-2 py-1.5 rounded-lg !text-sm",children:[w.jsxs("span",{className:"truncate mr-2",children:[B.name,w.jsxs("span",{className:"ml-1",style:{opacity:0.6},children:["(",(B.size/1024).toFixed(0)," KB)"]})]}),w.jsx("button",{type:"button",onClick:()=>J(Y.name,_.filter((I,M)=>M!==A)),className:"apteva-file-remove-btn transition-colors flex-shrink-0",children:"✕"})]},`${B.name}-${A}`))})]})}default:return null}},O=X.props.submitLabel||X.actions?.find((Y)=>Y.type==="submit")?.label||X.actions?.[0]?.label||"Submit";return w.jsxs("form",{onSubmit:U,className:"border rounded-xl overflow-hidden",children:[w.jsxs("div",{className:"p-4",children:[Q&&w.jsx("h3",{className:"!text-lg font-semibold mb-4",children:Q}),w.jsx("div",{className:"space-y-3",children:Z.map((Y)=>w.jsxs("div",{className:Y.type==="checkbox"?"":"space-y-1",children:[Y.type!=="checkbox"&&w.jsxs("label",{className:"apteva-field-label block !text-sm font-medium",children:[Y.label,Y.required&&w.jsx("span",{style:{color:"var(--aw-danger)"},className:"ml-1",children:"*"})]}),K(Y)]},Y.name))})]}),w.jsx("div",{className:"px-4 pb-4",children:w.jsx("button",{type:"submit",className:"px-3 py-1.5 !text-sm rounded-lg font-medium transition-colors",children:O})})]})}function IZ({widget:X}){let{src:$,alt:Q,caption:Z}=X.props;return lX.jsxs("figure",{className:"overflow-hidden rounded-xl",children:[lX.jsx("img",{src:$,alt:Q,className:"w-full h-auto object-contain bg-neutral-100 dark:bg-neutral-800",loading:"lazy"}),Z&&lX.jsx("figcaption",{className:"mt-2 text-center text-sm text-neutral-600 dark:text-neutral-400",children:Z})]})}function RZ({type:X,status:$}){if($==="completed")return W.jsx("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:W.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2.5,d:"M5 13l4 4L19 7"})});if($==="error")return W.jsx("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:W.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2.5,d:"M6 18L18 6M6 6l12 12"})});if($==="active")return W.jsx("div",{className:"w-3.5 h-3.5 rounded-full bg-current animate-pulse"});let Q="w-4 h-4";if(X==="time"||X==="schedule"||X==="clock")return W.jsx("svg",{className:Q,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:W.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z"})});if(X==="recurring"||X==="repeat")return W.jsx("svg",{className:Q,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:W.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"})});if(X==="agent"||X?.startsWith("@"))return W.jsx("svg",{className:Q,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:W.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M17 20h5v-2a3 3 0 00-5.356-1.857M17 20H7m10 0v-2c0-.656-.126-1.283-.356-1.857M7 20H2v-2a3 3 0 015.356-1.857M7 20v-2c0-.656.126-1.283.356-1.857m0 0a5.002 5.002 0 019.288 0M15 7a3 3 0 11-6 0 3 3 0 016 0z"})});if(X==="email"||X==="mail")return W.jsx("svg",{className:Q,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:W.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M3 8l7.89 5.26a2 2 0 002.22 0L21 8M5 19h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v10a2 2 0 002 2z"})});if(X==="slack"||X==="message"||X==="chat")return W.jsx("svg",{className:Q,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:W.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 12h.01M12 12h.01M16 12h.01M21 12c0 4.418-4.03 8-9 8a9.863 9.863 0 01-4.255-.949L3 20l1.395-3.72C3.512 15.042 3 13.574 3 12c0-4.418 4.03-8 9-8s9 3.582 9 8z"})});if(X==="webhook"||X==="api")return W.jsx("svg",{className:Q,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:W.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M13.828 10.172a4 4 0 00-5.656 0l-4 4a4 4 0 105.656 5.656l1.102-1.101m-.758-4.899a4 4 0 005.656 0l4-4a4 4 0 00-5.656-5.656l-1.1 1.1"})});if(X==="build"||X==="compile"||X==="package")return W.jsx("svg",{className:Q,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:W.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M20 7l-8-4-8 4m16 0l-8 4m8-4v10l-8 4m0-10L4 7m8 4v10M4 7v10l8 4"})});if(X==="test"||X==="check"||X==="verify")return W.jsx("svg",{className:Q,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:W.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"})});if(X==="deploy"||X==="rocket"||X==="launch")return W.jsx("svg",{className:Q,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:W.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M13 10V3L4 14h7v7l9-11h-7z"})});if(X==="push"||X==="upload"||X==="cloud")return W.jsx("svg",{className:Q,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:W.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M7 16a4 4 0 01-.88-7.903A5 5 0 1115.9 6L16 6a5 5 0 011 9.9M15 13l-3-3m0 0l-3 3m3-3v12"})});if(X==="generate"||X==="create"||X==="document"||X==="file")return W.jsx("svg",{className:Q,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:W.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"})});if(X==="review"||X==="inspect"||X==="eye")return W.jsxs("svg",{className:Q,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:[W.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M15 12a3 3 0 11-6 0 3 3 0 016 0z"}),W.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M2.458 12C3.732 7.943 7.523 5 12 5c4.478 0 8.268 2.943 9.542 7-1.274 4.057-5.064 7-9.542 7-4.477 0-8.268-2.943-9.542-7z"})]});if(X==="analyze"||X==="research"||X==="chart")return W.jsx("svg",{className:Q,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:W.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 19v-6a2 2 0 00-2-2H5a2 2 0 00-2 2v6a2 2 0 002 2h2a2 2 0 002-2zm0 0V9a2 2 0 012-2h2a2 2 0 012 2v10m-6 0a2 2 0 002 2h2a2 2 0 002-2m0 0V5a2 2 0 012-2h2a2 2 0 012 2v14a2 2 0 01-2 2h-2a2 2 0 01-2-2z"})});if(X==="scrape"||X==="crawl"||X==="spider")return W.jsx("svg",{className:Q,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:W.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M21 12a9 9 0 01-9 9m9-9a9 9 0 00-9-9m9 9H3m9 9a9 9 0 01-9-9m9 9c1.657 0 3-4.03 3-9s-1.343-9-3-9m0 18c-1.657 0-3-4.03-3-9s1.343-9 3-9m-9 9a9 9 0 019-9"})});if(X==="data"||X==="database"||X==="storage")return W.jsx("svg",{className:Q,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:W.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 7v10c0 2.21 3.582 4 8 4s8-1.79 8-4V7M4 7c0 2.21 3.582 4 8 4s8-1.79 8-4M4 7c0-2.21 3.582-4 8-4s8 1.79 8 4m0 5c0 2.21-3.582 4-8 4s-8-1.79-8-4"})});if(X==="notification"||X==="bell"||X==="alert")return W.jsx("svg",{className:Q,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:W.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M15 17h5l-1.405-1.405A2.032 2.032 0 0118 14.158V11a6.002 6.002 0 00-4-5.659V5a2 2 0 10-4 0v.341C7.67 6.165 6 8.388 6 11v3.159c0 .538-.214 1.055-.595 1.436L4 17h5m6 0v1a3 3 0 11-6 0v-1m6 0H9"})});if(X==="transform"||X==="process"||X==="convert")return W.jsx("svg",{className:Q,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:W.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 7h12m0 0l-4-4m4 4l-4 4m0 6H4m0 0l4 4m-4-4l4-4"})});return W.jsx("div",{className:"w-2 h-2 rounded-full bg-current opacity-50"})}function bZ({icon:X}){if(X==="research"||X==="multi-agent"||X==="agents")return W.jsx("div",{className:"w-10 h-10 rounded-lg bg-purple-100 dark:bg-purple-500/20 flex items-center justify-center",children:W.jsx("svg",{className:"w-6 h-6 text-purple-600 dark:text-purple-400",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:W.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M13 10V3L4 14h7v7l9-11h-7z"})})});if(X==="schedule"||X==="report"||X==="calendar")return W.jsx("div",{className:"w-10 h-10 rounded-lg bg-amber-100 dark:bg-amber-500/20 flex items-center justify-center",children:W.jsx("svg",{className:"w-6 h-6 text-amber-600 dark:text-amber-400",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:W.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 7V3m8 4V3m-9 8h10M5 21h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v12a2 2 0 002 2z"})})});if(X==="recurring"||X==="repeat"||X==="sync")return W.jsx("div",{className:"w-10 h-10 rounded-lg bg-cyan-100 dark:bg-cyan-500/20 flex items-center justify-center",children:W.jsx("svg",{className:"w-6 h-6 text-cyan-600 dark:text-cyan-400",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:W.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"})})});if(X==="analyze"||X==="analysis"||X==="chart")return W.jsx("div",{className:"w-10 h-10 rounded-lg bg-cyan-100 dark:bg-cyan-500/20 flex items-center justify-center",children:W.jsx("svg",{className:"w-6 h-6 text-cyan-600 dark:text-cyan-400",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:W.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 19v-6a2 2 0 00-2-2H5a2 2 0 00-2 2v6a2 2 0 002 2h2a2 2 0 002-2zm0 0V9a2 2 0 012-2h2a2 2 0 012 2v10m-6 0a2 2 0 002 2h2a2 2 0 002-2m0 0V5a2 2 0 012-2h2a2 2 0 012 2v14a2 2 0 01-2 2h-2a2 2 0 01-2-2z"})})});if(X==="deploy"||X==="rocket"||X==="launch")return W.jsx("div",{className:"w-10 h-10 rounded-lg bg-blue-100 dark:bg-blue-500/20 flex items-center justify-center",children:W.jsx("svg",{className:"w-6 h-6 text-blue-600 dark:text-blue-400",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:W.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M13 10V3L4 14h7v7l9-11h-7z"})})});if(X==="automation"||X==="workflow"||X==="process")return W.jsx("div",{className:"w-10 h-10 rounded-lg bg-indigo-100 dark:bg-indigo-500/20 flex items-center justify-center",children:W.jsx("svg",{className:"w-6 h-6 text-indigo-600 dark:text-indigo-400",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:W.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 5a1 1 0 011-1h14a1 1 0 011 1v2a1 1 0 01-1 1H5a1 1 0 01-1-1V5zM4 13a1 1 0 011-1h6a1 1 0 011 1v6a1 1 0 01-1 1H5a1 1 0 01-1-1v-6zM16 13a1 1 0 011-1h2a1 1 0 011 1v6a1 1 0 01-1 1h-2a1 1 0 01-1-1v-6z"})})});if(X==="data"||X==="pipeline"||X==="etl")return W.jsx("div",{className:"w-10 h-10 rounded-lg bg-emerald-100 dark:bg-emerald-500/20 flex items-center justify-center",children:W.jsx("svg",{className:"w-6 h-6 text-emerald-600 dark:text-emerald-400",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:W.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 7v10c0 2.21 3.582 4 8 4s8-1.79 8-4V7M4 7c0 2.21 3.582 4 8 4s8-1.79 8-4M4 7c0-2.21 3.582-4 8-4s8 1.79 8 4"})})});return W.jsx("div",{className:"w-10 h-10 rounded-lg bg-neutral-100 dark:bg-neutral-700 flex items-center justify-center",children:W.jsx("svg",{className:"w-6 h-6 text-neutral-600 dark:text-neutral-300",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:W.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"})})})}function kZ(){return W.jsx("svg",{className:"w-4 h-4 text-neutral-400 dark:text-neutral-500 flex-shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:W.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 5l7 7-7 7"})})}var a0={blue:"bg-blue-100 dark:bg-blue-900/40 !text-blue-700 dark:!text-blue-300 border-blue-300 dark:border-blue-500",purple:"bg-purple-100 dark:bg-purple-900/40 !text-purple-700 dark:!text-purple-300 border-purple-300 dark:border-purple-500",cyan:"bg-cyan-100 dark:bg-cyan-900/40 !text-cyan-700 dark:!text-cyan-300 border-cyan-300 dark:border-cyan-500",amber:"bg-amber-100 dark:bg-amber-900/40 !text-amber-700 dark:!text-amber-300 border-amber-300 dark:border-amber-500",emerald:"bg-emerald-100 dark:bg-emerald-900/40 !text-emerald-700 dark:!text-emerald-300 border-emerald-300 dark:border-emerald-500",rose:"bg-rose-100 dark:bg-rose-900/40 !text-rose-700 dark:!text-rose-300 border-rose-300 dark:border-rose-500",indigo:"bg-indigo-100 dark:bg-indigo-900/40 !text-indigo-700 dark:!text-indigo-300 border-indigo-300 dark:border-indigo-500",orange:"bg-orange-100 dark:bg-orange-900/40 !text-orange-700 dark:!text-orange-300 border-orange-300 dark:border-orange-500",neutral:"bg-neutral-100 dark:bg-neutral-800 !text-neutral-600 dark:!text-neutral-300 border-neutral-300 dark:border-neutral-600"};function vZ(X,$){if(X.color&&a0[X.color])return a0[X.color];if($==="time"||$==="schedule"||$==="clock")return a0.blue;if($==="agent"||$?.startsWith("@"))return a0.purple;if($==="email"||$==="slack"||$==="message"||$==="notification")return a0.cyan;if($==="generate"||$==="document"||$==="create")return a0.amber;if($==="deploy"||$==="rocket"||$==="launch")return a0.rose;if($==="build"||$==="compile"||$==="package")return a0.indigo;if($==="test"||$==="check"||$==="verify")return a0.emerald;if($==="data"||$==="database"||$==="storage")return a0.orange;return a0.blue}function wZ({widget:X}){let{title:$,subtitle:Q,icon:Z,steps:z}=X.props;return W.jsxs("div",{className:"rounded-xl bg-white dark:bg-neutral-900 border border-neutral-200 dark:border-neutral-700 overflow-hidden",children:[W.jsxs("div",{className:"px-4 py-4 flex items-center gap-4",children:[W.jsx(bZ,{icon:Z}),W.jsxs("div",{className:"flex-1 min-w-0",children:[W.jsx("h3",{className:"font-semibold text-base text-neutral-900 dark:text-white truncate",children:$}),Q&&W.jsx("p",{className:"text-sm text-neutral-500 dark:text-neutral-400 truncate mt-0.5",children:Q})]})]}),W.jsx("div",{className:"px-4 pb-4",children:W.jsx("div",{className:"flex flex-wrap items-center gap-2",children:z.map((H,G)=>{let J=G===z.length-1,U=H.status==="active",K=H.status==="completed",O=H.status==="error",Y=H.status==="skipped",V=H.label,_=H.type;if(!_)if(V.startsWith("@"))_="agent";else if(/^\d+[ap]m$/i.test(V)||/^(mon|tue|wed|thu|fri|sat|sun)/i.test(V))_="time";else{let I=V.toLowerCase();_={test:"test",build:"build",push:"push",deploy:"deploy",email:"email",slack:"slack",generate:"generate",review:"review",analyze:"analyze",scrape:"scrape",transform:"transform",notify:"notification",alert:"notification",webhook:"webhook",api:"api",data:"data",process:"process"}[I]}let B,A="";if(U)B="bg-blue-100 dark:bg-blue-900/40 !text-blue-700 dark:!text-blue-300 border-blue-400 dark:border-blue-400 ring-2 ring-blue-400";else if(K)B="bg-emerald-100 dark:bg-emerald-900/40 !text-emerald-700 dark:!text-emerald-300 border-emerald-400 dark:border-emerald-400";else if(O)B="bg-red-100 dark:bg-red-900/40 !text-red-700 dark:!text-red-300 border-red-400 dark:border-red-400";else if(Y)B="bg-neutral-100 dark:bg-neutral-800 !text-neutral-400 dark:!text-neutral-500 border-neutral-300 dark:border-neutral-600",A="line-through";else B=vZ(H,_);return W.jsxs("div",{className:"flex items-center gap-2",children:[W.jsxs("span",{className:`inline-flex items-center gap-2 px-4 py-2 rounded-lg text-sm font-medium border transition-colors ${B} ${A}`,children:[W.jsx(RZ,{type:_,status:H.status}),V]}),!J&&W.jsx(kZ,{})]},H.id)})})})]})}var SZ={up:{symbol:"↑",color:"text-emerald-500"},down:{symbol:"↓",color:"text-red-500"},flat:{symbol:"→",color:"text-neutral-400"}};function yZ({widget:X,onAction:$}){let{title:Q,label:Z="",value:z="",change:H,trend:G}=X.props||{},J=G?SZ[G]:null;return u0.jsxs("div",{className:"border border-neutral-200 dark:border-neutral-700 rounded-xl bg-white dark:bg-neutral-900 p-5",children:[Q&&u0.jsx("h3",{className:"!text-base font-semibold !text-neutral-900 dark:!text-white mb-3",children:Q}),u0.jsx("div",{className:"!text-sm font-medium !text-neutral-500 dark:!text-neutral-400 mb-1",children:Z}),u0.jsxs("div",{className:"flex items-end gap-2",children:[u0.jsx("div",{className:"apteva-kpi-value !text-2xl font-bold !text-neutral-900 dark:!text-white",children:z}),H&&J&&u0.jsxs("div",{className:`flex items-center gap-0.5 !text-sm font-medium ${J.color} mb-0.5`,children:[u0.jsx("span",{children:J.symbol}),u0.jsx("span",{children:H})]}),H&&!J&&u0.jsx("div",{className:"!text-sm font-medium !text-neutral-400 mb-0.5",children:H})]}),X.actions&&X.actions.length>0&&u0.jsx("div",{className:"flex gap-2 mt-3 pt-3 border-t border-neutral-200 dark:border-neutral-700",children:X.actions.map((U,K)=>u0.jsx("button",{onClick:()=>$?.({type:U.type,payload:U.payload,widgetId:X.id,timestamp:new Date}),className:"px-2 py-1 !text-xs rounded font-medium transition-colors bg-neutral-100 dark:bg-neutral-800 !text-neutral-600 dark:!text-neutral-300 hover:bg-neutral-200 dark:hover:bg-neutral-700",children:U.label},K))})]})}function CZ({widget:X}){let{content:$="",variant:Q="body"}=X.props||{},Z={heading:"!text-xl font-bold !text-neutral-900 dark:!text-white",body:"!text-sm !text-neutral-700 dark:!text-neutral-300 leading-relaxed",caption:"!text-xs !text-neutral-500 dark:!text-neutral-400"},z=(G)=>{let J=G.split(`
|
|
32
|
+
`),U=[],K=0;while(K<J.length){let O=J[K];if(O.startsWith("### "))U.push(g0.jsx("h3",{className:"!text-base font-semibold !text-neutral-900 dark:!text-white mt-3 mb-1",children:H(O.slice(4))},K));else if(O.startsWith("## "))U.push(g0.jsx("h2",{className:"!text-lg font-bold !text-neutral-900 dark:!text-white mt-4 mb-1",children:H(O.slice(3))},K));else if(/^[-*+]\s/.test(O)){let Y=[];while(K<J.length&&/^[-*+]\s/.test(J[K]))Y.push(g0.jsx("li",{className:"ml-4 list-disc",children:H(J[K].slice(2))},K)),K++;U.push(g0.jsx("ul",{className:"my-1 space-y-0.5",children:Y},`list-${K}`));continue}else if(O.trim()==="")U.push(g0.jsx("div",{className:"h-2"},K));else U.push(g0.jsx("p",{className:"my-0.5",children:H(O)},K));K++}return U},H=(G)=>{let J=[],U=G,K=0;while(U.length>0){let O=U.match(/\*\*(.+?)\*\*/),Y=U.match(/`(.+?)`/),V=U.match(/\[(.+?)\]\((.+?)\)/),_=[O?{type:"bold",index:O.index,match:O}:null,Y?{type:"code",index:Y.index,match:Y}:null,V?{type:"link",index:V.index,match:V}:null].filter(Boolean).sort((A,I)=>A.index-I.index);if(_.length===0){J.push(U);break}let B=_[0];if(B.index>0)J.push(U.slice(0,B.index));if(B.type==="bold")J.push(g0.jsx("strong",{className:"font-semibold",children:B.match[1]},K++)),U=U.slice(B.index+B.match[0].length);else if(B.type==="code")J.push(g0.jsx("code",{className:"px-1 py-0.5 bg-neutral-100 dark:bg-neutral-800 rounded text-xs font-mono",children:B.match[1]},K++)),U=U.slice(B.index+B.match[0].length);else if(B.type==="link")J.push(g0.jsx("a",{href:B.match[2],className:"text-blue-500 hover:underline",target:"_blank",rel:"noopener noreferrer",children:B.match[1]},K++)),U=U.slice(B.index+B.match[0].length)}return J.length===1?J[0]:g0.jsx(g0.Fragment,{children:J})};return g0.jsx("div",{className:Z[Q]||Z.body,children:z($)})}var sX={sm:"h-2",md:"h-4",lg:"h-8"};function jZ({widget:X}){let{height:$="md",variant:Q="space"}=X.props||{};if(Q==="line")return tX.jsx("div",{className:sX[$]||sX.md+" flex items-center",children:tX.jsx("hr",{className:"w-full border-neutral-200 dark:border-neutral-700"})});return tX.jsx("div",{className:sX[$]||sX.md})}function fZ({widget:X}){let{src:$,title:Q,height:Z,aspectRatio:z="16/9",allowFullscreen:H=!0,sandbox:G,allow:J,refreshInterval:U,showToolbar:K=!0}=X.props,O=o0.useRef(null),[Y,V]=o0.useState(!0),[_,B]=o0.useState(!1),[A,I]=o0.useState(0),M=o0.useCallback(()=>{V(!0),B(!1),I((R)=>R+1)},[]),h=o0.useCallback(()=>{O.current?.requestFullscreen?.()},[]),i=o0.useCallback(()=>{window.open($,"_blank","noopener,noreferrer")},[$]);o0.useEffect(()=>{if(!U||U<=0)return;let R=setInterval(M,U*1000);return()=>clearInterval(R)},[U,M]);let o={"16/9":"56.25%","4/3":"75%","1/1":"100%"},e=!!Z;return U0.jsxs("div",{className:"rounded-xl overflow-hidden border border-neutral-200 dark:border-neutral-700 bg-neutral-50 dark:bg-neutral-900",children:[K&&U0.jsxs("div",{className:"flex items-center justify-between px-3 py-2 bg-neutral-100 dark:bg-neutral-800 border-b border-neutral-200 dark:border-neutral-700",children:[U0.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[U0.jsx("div",{className:q0("w-2 h-2 rounded-full flex-shrink-0",_?"bg-red-500":Y?"bg-amber-500 animate-pulse":"bg-emerald-500")}),U0.jsx("span",{className:"text-sm font-medium text-neutral-700 dark:text-neutral-300 truncate",children:Q||"Live View"})]}),U0.jsxs("div",{className:"flex items-center gap-1 flex-shrink-0",children:[U0.jsx("button",{onClick:M,className:"p-1.5 rounded-md text-neutral-500 hover:text-neutral-700 dark:hover:text-neutral-300 hover:bg-neutral-200 dark:hover:bg-neutral-700 transition-colors",title:"Refresh",children:U0.jsx("svg",{className:"w-3.5 h-3.5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:U0.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"})})}),U0.jsx("button",{onClick:i,className:"p-1.5 rounded-md text-neutral-500 hover:text-neutral-700 dark:hover:text-neutral-300 hover:bg-neutral-200 dark:hover:bg-neutral-700 transition-colors",title:"Open in new tab",children:U0.jsx("svg",{className:"w-3.5 h-3.5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:U0.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M10 6H6a2 2 0 00-2 2v10a2 2 0 002 2h10a2 2 0 002-2v-4M14 4h6m0 0v6m0-6L10 14"})})}),H&&U0.jsx("button",{onClick:h,className:"p-1.5 rounded-md text-neutral-500 hover:text-neutral-700 dark:hover:text-neutral-300 hover:bg-neutral-200 dark:hover:bg-neutral-700 transition-colors",title:"Fullscreen",children:U0.jsx("svg",{className:"w-3.5 h-3.5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:U0.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M4 8V4m0 0h4M4 4l5 5m11-1V4m0 0h-4m4 0l-5 5M4 16v4m0 0h4m-4 0l5-5m11 5v-4m0 4h-4m4 0l-5-5"})})})]})]}),U0.jsxs("div",{className:"relative bg-white dark:bg-neutral-950",style:e?{height:Z}:{paddingBottom:o[z]||o["16/9"]},children:[Y&&U0.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-neutral-100 dark:bg-neutral-900 z-10",children:U0.jsxs("div",{className:"flex flex-col items-center gap-2",children:[U0.jsx("div",{className:"w-6 h-6 border-2 border-neutral-300 dark:border-neutral-600 border-t-blue-500 rounded-full animate-spin"}),U0.jsx("span",{className:"text-xs text-neutral-500",children:"Loading..."})]})}),_&&U0.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-neutral-100 dark:bg-neutral-900 z-10",children:U0.jsxs("div",{className:"flex flex-col items-center gap-2 text-center px-4",children:[U0.jsx("svg",{className:"w-8 h-8 text-neutral-400",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:1.5,children:U0.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M12 9v3.75m9-.75a9 9 0 11-18 0 9 9 0 0118 0zm-9 3.75h.008v.008H12v-.008z"})}),U0.jsx("span",{className:"text-sm text-neutral-500",children:"Failed to load"}),U0.jsx("button",{onClick:M,className:"text-xs text-blue-500 hover:text-blue-600 underline",children:"Try again"})]})}),U0.jsx("iframe",{ref:O,src:$,title:Q||"Live View",className:q0("border-0 bg-white dark:bg-neutral-950",e?"w-full h-full":"absolute inset-0 w-full h-full"),allowFullScreen:H,sandbox:G,allow:J,onLoad:()=>V(!1),onError:()=>{V(!1),B(!0)}},A)]})]})}function X$({widget:X,onAction:$}){return C0.jsx("div",{className:"apteva-widget",children:(()=>{switch(X.type){case"card":return C0.jsx(FZ,{widget:X,onAction:$});case"list":return C0.jsx(WZ,{widget:X,onAction:$});case"button":return C0.jsx(NZ,{widget:X,onAction:$});case"button_group":return C0.jsx(AZ,{widget:X,onAction:$});case"table":return C0.jsx(PZ,{widget:X,onAction:$});case"form":return C0.jsx(TZ,{widget:X,onAction:$});case"image":return C0.jsx(IZ,{widget:X});case"flow":return C0.jsx(wZ,{widget:X});case"kpi":return C0.jsx(yZ,{widget:X,onAction:$});case"text_block":return C0.jsx(CZ,{widget:X});case"spacer":return C0.jsx(jZ,{widget:X});case"live_view":return C0.jsx(fZ,{widget:X});default:return C0.jsxs("div",{className:"p-4 border border-yellow-300 bg-yellow-50 rounded-lg",children:[C0.jsxs("p",{className:"text-sm text-yellow-800",children:["Unknown widget type: ",X.type]}),C0.jsx("pre",{className:"text-xs mt-2 overflow-auto",children:JSON.stringify(X,null,2)})]})}})()})}function hZ({widgets:X,onAction:$,onWidgetMount:Q,layout:Z="stack",spacing:z="normal",columns:H=3,className:G}){c$.useEffect(()=>{X.forEach((K)=>{Q?.(K.id)})},[X,Q]);let J={stack:"flex flex-col",grid:`grid grid-cols-1 md:grid-cols-${H}`,masonry:"columns-1 md:columns-2 lg:columns-3"},U={tight:"gap-2",normal:"gap-4",loose:"gap-6"};return L$.jsx("div",{className:q0(J[Z],U[z],G),children:X.map((K)=>L$.jsx(X$,{widget:K,onAction:$},K.id))})}function j$({type:X,className:$}){switch(X){case"card":return C.jsx("div",{className:q0("apteva-widget-skeleton animate-pulse rounded-lg border border-neutral-200 dark:border-neutral-800 overflow-hidden",$),children:C.jsxs("div",{className:"p-4 space-y-3",children:[C.jsx("div",{className:"h-4 bg-neutral-200 dark:bg-neutral-700 rounded w-3/4"}),C.jsx("div",{className:"h-3 bg-neutral-200 dark:bg-neutral-700 rounded w-full"}),C.jsx("div",{className:"h-3 bg-neutral-200 dark:bg-neutral-700 rounded w-5/6"})]})});case"list":return C.jsx("div",{className:q0("apteva-widget-skeleton animate-pulse space-y-2",$),children:[1,2,3].map((Q)=>C.jsxs("div",{className:"flex items-center gap-3 p-3 rounded-lg border border-neutral-200 dark:border-neutral-800",children:[C.jsx("div",{className:"w-10 h-10 bg-neutral-200 dark:bg-neutral-700 rounded-full flex-shrink-0"}),C.jsxs("div",{className:"flex-1 space-y-2",children:[C.jsx("div",{className:"h-3 bg-neutral-200 dark:bg-neutral-700 rounded w-1/2"}),C.jsx("div",{className:"h-2 bg-neutral-200 dark:bg-neutral-700 rounded w-3/4"})]})]},Q))});case"button_group":return C.jsxs("div",{className:q0("apteva-widget-skeleton animate-pulse flex gap-2",$),children:[C.jsx("div",{className:"h-9 bg-neutral-200 dark:bg-neutral-700 rounded-lg w-20"}),C.jsx("div",{className:"h-9 bg-neutral-200 dark:bg-neutral-700 rounded-lg w-20"}),C.jsx("div",{className:"h-9 bg-neutral-200 dark:bg-neutral-700 rounded-lg w-20"})]});case"form":return C.jsxs("div",{className:q0("apteva-widget-skeleton animate-pulse rounded-lg border border-neutral-200 dark:border-neutral-800 p-4 space-y-4",$),children:[C.jsx("div",{className:"h-4 bg-neutral-200 dark:bg-neutral-700 rounded w-1/3"}),C.jsxs("div",{className:"space-y-3",children:[C.jsx("div",{className:"h-10 bg-neutral-200 dark:bg-neutral-700 rounded"}),C.jsx("div",{className:"h-10 bg-neutral-200 dark:bg-neutral-700 rounded"})]}),C.jsx("div",{className:"h-9 bg-neutral-200 dark:bg-neutral-700 rounded w-24"})]});case"chart":return C.jsxs("div",{className:q0("apteva-widget-skeleton animate-pulse rounded-lg border border-neutral-200 dark:border-neutral-800 p-4",$),children:[C.jsx("div",{className:"h-4 bg-neutral-200 dark:bg-neutral-700 rounded w-1/4 mb-4"}),C.jsxs("div",{className:"flex items-end gap-2 h-32",children:[C.jsx("div",{className:"flex-1 bg-neutral-200 dark:bg-neutral-700 rounded-t h-1/2"}),C.jsx("div",{className:"flex-1 bg-neutral-200 dark:bg-neutral-700 rounded-t h-3/4"}),C.jsx("div",{className:"flex-1 bg-neutral-200 dark:bg-neutral-700 rounded-t h-1/3"}),C.jsx("div",{className:"flex-1 bg-neutral-200 dark:bg-neutral-700 rounded-t h-full"}),C.jsx("div",{className:"flex-1 bg-neutral-200 dark:bg-neutral-700 rounded-t h-2/3"})]})]});case"image":return C.jsx("div",{className:q0("apteva-widget-skeleton animate-pulse",$),children:C.jsx("div",{className:"aspect-video bg-neutral-200 dark:bg-neutral-700 rounded-lg"})});case"gallery":return C.jsx("div",{className:q0("apteva-widget-skeleton animate-pulse grid grid-cols-3 gap-2",$),children:[1,2,3].map((Q)=>C.jsx("div",{className:"aspect-square bg-neutral-200 dark:bg-neutral-700 rounded-lg"},Q))});case"map":return C.jsx("div",{className:q0("apteva-widget-skeleton animate-pulse",$),children:C.jsx("div",{className:"h-48 bg-neutral-200 dark:bg-neutral-700 rounded-lg flex items-center justify-center",children:C.jsxs("svg",{className:"w-8 h-8 text-neutral-400 dark:text-neutral-500",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:[C.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M17.657 16.657L13.414 20.9a1.998 1.998 0 01-2.827 0l-4.244-4.243a8 8 0 1111.314 0z"}),C.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M15 11a3 3 0 11-6 0 3 3 0 016 0z"})]})})});case"table":return C.jsxs("div",{className:q0("apteva-widget-skeleton animate-pulse rounded-lg border border-neutral-200 dark:border-neutral-800 overflow-hidden",$),children:[C.jsxs("div",{className:"flex bg-neutral-100 dark:bg-neutral-800 border-b border-neutral-200 dark:border-neutral-700",children:[C.jsx("div",{className:"flex-1 px-4 py-3",children:C.jsx("div",{className:"h-3 bg-neutral-300 dark:bg-neutral-600 rounded w-16"})}),C.jsx("div",{className:"flex-1 px-4 py-3",children:C.jsx("div",{className:"h-3 bg-neutral-300 dark:bg-neutral-600 rounded w-20"})}),C.jsx("div",{className:"flex-1 px-4 py-3",children:C.jsx("div",{className:"h-3 bg-neutral-300 dark:bg-neutral-600 rounded w-14"})})]}),[1,2,3].map((Q)=>C.jsxs("div",{className:"flex border-b border-neutral-200 dark:border-neutral-800 last:border-b-0",children:[C.jsx("div",{className:"flex-1 px-4 py-3",children:C.jsx("div",{className:"h-3 bg-neutral-200 dark:bg-neutral-700 rounded w-24"})}),C.jsx("div",{className:"flex-1 px-4 py-3",children:C.jsx("div",{className:"h-3 bg-neutral-200 dark:bg-neutral-700 rounded w-16"})}),C.jsx("div",{className:"flex-1 px-4 py-3",children:C.jsx("div",{className:"h-3 bg-neutral-200 dark:bg-neutral-700 rounded w-20"})})]},Q))]});default:return C.jsxs("div",{className:q0("apteva-widget-skeleton animate-pulse rounded-lg border border-neutral-200 dark:border-neutral-800 p-4",$),children:[C.jsx("div",{className:"h-4 bg-neutral-200 dark:bg-neutral-700 rounded w-1/2 mb-2"}),C.jsx("div",{className:"h-3 bg-neutral-200 dark:bg-neutral-700 rounded w-full"})]})}}function xZ(X){return/\.(jpg|jpeg|png|gif|webp|svg|bmp|ico)(\?.*)?$/i.test(X)}function PX(X,$=""){let Q=[],Z=/!\[([^\]]*)\]\(([^)]+)\)|\[([^\]]+)\]\(([^)]+)\)|(\*\*|__)(.+?)\5|`([^`]+)`/g,z=0,H,G=0;while((H=Z.exec(X))!==null){if(H.index>z)Q.push(X.slice(z,H.index));if(H[1]!==void 0||H[2]!==void 0){let J=H[1]||"",U=H[2];Q.push(M0.jsx("img",{src:U,alt:J,className:"apteva-md-img"},`${$}img${G++}`))}else if(H[3]!==void 0||H[4]!==void 0){let J=H[3],U=H[4];if(xZ(U))Q.push(M0.jsx("img",{src:U,alt:J,className:"apteva-md-img"},`${$}img${G++}`));else Q.push(M0.jsx("a",{href:U,target:"_blank",rel:"noopener noreferrer",className:"apteva-md-link",children:J},`${$}a${G++}`))}else if(H[5]!==void 0)Q.push(M0.jsx("strong",{children:H[6]},`${$}b${G++}`));else if(H[7]!==void 0)Q.push(M0.jsx("code",{className:"apteva-md-inline-code",children:H[7]},`${$}code${G++}`));z=H.index+H[0].length}if(z<X.length)Q.push(X.slice(z));return Q.length>0?Q:[X]}function gZ(X){let $=X.split(`
|
|
33
|
+
`),Q=[],Z=0,z=0;while(z<$.length){let H=$[z],G=H.match(/^##\s+(.*)$/);if(G){Q.push(M0.jsx("h2",{className:"apteva-md-h2",children:PX(G[1],`${Z}`)},`h2${Z++}`)),z++;continue}let J=H.match(/^###\s+(.*)$/);if(J){Q.push(M0.jsx("h3",{className:"apteva-md-h3",children:PX(J[1],`${Z}`)},`h3${Z++}`)),z++;continue}let U=H.match(/^(\s*)([-*+])\s+(.*)$/);if(U){let Y=[],V=U[1].length;while(z<$.length){let _=$[z].match(/^(\s*)([-*+])\s+(.*)$/);if(_&&_[1].length===V)Y.push(M0.jsx("li",{className:"apteva-md-li",children:PX(_[3],`${Z}`)},`li${Z++}`)),z++;else break}Q.push(M0.jsx("ul",{className:"apteva-md-ul",children:Y},`ul${Z++}`));continue}let K=H.match(/^(\s*)(\d+)\.\s+(.*)$/);if(K){let Y=[],V=K[1].length;while(z<$.length){let _=$[z].match(/^(\s*)(\d+)\.\s+(.*)$/);if(_&&_[1].length===V)Y.push(M0.jsx("li",{className:"apteva-md-li",children:PX(_[3],`${Z}`)},`li${Z++}`)),z++;else break}Q.push(M0.jsx("ol",{className:"apteva-md-ol",children:Y},`ol${Z++}`));continue}if(H.match(/^\|(.+)\|$/)&&z+1<$.length){if($[z+1].match(/^\|([\s:-]+\|)+$/)){let _=H.split("|").filter((A)=>A.trim()!=="").map((A)=>A.trim());z+=2;let B=[];while(z<$.length)if($[z].match(/^\|(.+)\|$/)){let I=$[z].split("|").filter((M)=>M.trim()!=="").map((M)=>M.trim());B.push(I),z++}else break;Q.push(M0.jsx("div",{className:"apteva-md-table-wrapper",children:M0.jsxs("table",{className:"apteva-md-table",children:[M0.jsx("thead",{children:M0.jsx("tr",{children:_.map((A,I)=>M0.jsx("th",{className:"apteva-md-th",children:PX(A,`th${Z}${I}`)},`th${I}`))})}),M0.jsx("tbody",{children:B.map((A,I)=>M0.jsx("tr",{children:A.map((M,h)=>M0.jsx("td",{className:"apteva-md-td",children:PX(M,`td${Z}${I}${h}`)},`td${h}`))},`tr${I}`))})]})},`table-wrapper${Z++}`));continue}}if(H==="")Q.push(M0.jsx("br",{},`br${Z++}`));else Q.push(M0.jsxs("span",{children:[PX(H,`${Z}`),z<$.length-1?`
|
|
34
|
+
`:""]},`p${Z++}`));z++}return Q}function YX({content:X,className:$=""}){let Q=X.replace(/<\/?ui\s*\/?>/gi,"");return M0.jsx("div",{className:`apteva-md ${$}`,children:gZ(Q)})}function f$({name:X,status:$,isReceiving:Q=!1,inputLength:Z=0,streamOutput:z,variant:H="card"}){if(H==="inline"){let G=$==="preparing"?`${X} preparing...`:$==="running"?z?`${X} · ${z}`:`${X}...`:$==="error"?`${X} failed`:X;return l.jsxs("div",{className:"apteva-tool-inline",children:[l.jsx("div",{className:"apteva-tool-inline-line"}),l.jsxs("div",{className:"apteva-tool-inline-content",children:[$==="running"||$==="preparing"?l.jsxs("svg",{className:"apteva-tool-inline-icon apteva-tool-icon-spin",width:"14",height:"14",fill:"none",viewBox:"0 0 24 24",children:[l.jsx("circle",{className:"apteva-tool-spinner-track",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),l.jsx("path",{className:"apteva-tool-spinner-fill",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]}):l.jsx("svg",{className:"apteva-tool-inline-icon",width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",children:l.jsx("path",{d:"M13 2L3 14h9l-1 8 10-12h-9l1-8z",fill:"currentColor"})}),l.jsx("span",{className:"apteva-tool-inline-text",children:G})]}),l.jsx("div",{className:"apteva-tool-inline-line"})]})}if($==="preparing")return l.jsxs("div",{className:"apteva-tool-card apteva-tool-card-preparing",children:[l.jsxs("svg",{className:"apteva-tool-icon apteva-tool-icon-spin",fill:"none",viewBox:"0 0 24 24",children:[l.jsx("circle",{className:"apteva-tool-spinner-track",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),l.jsx("path",{className:"apteva-tool-spinner-fill",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]}),l.jsxs("span",{className:"apteva-tool-label",children:[l.jsx("strong",{children:X}),l.jsx("span",{className:"apteva-tool-status-text",children:" preparing..."})]})]});if($==="running")return l.jsxs("div",{className:"apteva-tool-card apteva-tool-card-running",children:[l.jsxs("svg",{className:"apteva-tool-icon apteva-tool-icon-spin",fill:"none",viewBox:"0 0 24 24",children:[l.jsx("circle",{className:"apteva-tool-spinner-track",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),l.jsx("path",{className:"apteva-tool-spinner-fill",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]}),l.jsxs("span",{className:"apteva-tool-label",children:[l.jsx("strong",{children:X}),z?l.jsx("span",{className:"apteva-tool-stream-separator",children:" · "}):null,z?l.jsx("span",{className:"apteva-tool-stream-output",children:z}):l.jsxs(l.Fragment,{children:[l.jsx("span",{className:"apteva-tool-status-text",children:" running"}),l.jsxs("span",{className:"apteva-tool-dots",children:[l.jsx("span",{children:"."}),l.jsx("span",{children:"."}),l.jsx("span",{children:"."})]})]})]})]});if($==="completed")return l.jsxs("div",{className:"apteva-tool-card apteva-tool-card-completed",children:[l.jsx("svg",{className:"apteva-tool-icon",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:l.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 13l4 4L19 7"})}),l.jsx("span",{className:"apteva-tool-label",children:X})]});return l.jsxs("div",{className:"apteva-tool-card apteva-tool-card-error",children:[l.jsx("svg",{className:"apteva-tool-icon",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:l.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})}),l.jsxs("span",{className:"apteva-tool-label",children:[X," failed"]})]})}function uZ(X){if(X==null)return"";let Q=(typeof X==="string"?X:JSON.stringify(X)).replace(/\s+/g," ").trim();return Q.length>120?Q.slice(0,117)+"...":Q}function mZ({tools:X}){let $=X.filter((Y)=>Y.status==="completed").length,Q=X.filter((Y)=>Y.status==="error").length,Z=X.length,z=$+Q===Z,[H,G]=o$.useState(!1),J=H,U=X.find((Y)=>Y.status==="running")||X.find((Y)=>Y.status==="preparing"),K;if(z)if(Q>0)K=`Used ${Z} tools · ${Q} failed`;else K=`Used ${Z} tools`;else{let Y=[`Using ${Z} tools`];if($>0)Y.push(`${$} done`);if(U){let V=U.streamOutput||(U.status==="preparing"?"preparing":"running");Y.push(`${U.name} ${V==="preparing"||V==="running"?V+"...":"· "+V}`)}K=Y.join(" · ")}let O=z?Q>0?"apteva-tool-group apteva-tool-group-error":"apteva-tool-group apteva-tool-group-completed":"apteva-tool-group apteva-tool-group-running";return D0.jsxs("div",{className:O,children:[D0.jsxs("button",{className:"apteva-tool-group-header",onClick:()=>G(!H),children:[D0.jsxs("div",{className:"apteva-tool-group-header-left",children:[z?D0.jsx("svg",{className:"apteva-tool-group-icon",width:"14",height:"14",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:D0.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 13l4 4L19 7"})}):D0.jsxs("svg",{className:"apteva-tool-group-icon apteva-tool-icon-spin",width:"14",height:"14",fill:"none",viewBox:"0 0 24 24",children:[D0.jsx("circle",{className:"apteva-tool-spinner-track",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),D0.jsx("path",{className:"apteva-tool-spinner-fill",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]}),D0.jsx("span",{className:"apteva-tool-group-status",children:K})]}),D0.jsx("svg",{className:`apteva-tool-group-chevron ${J?"apteva-tool-group-chevron-open":""}`,width:"14",height:"14",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:D0.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})})]}),J&&D0.jsx("div",{className:"apteva-tool-group-list",children:X.map((Y)=>{let V=Y.status==="completed"&&Y.result?uZ(Y.result):"",_=Y.status==="running"&&Y.streamOutput||V;return D0.jsxs("div",{className:`apteva-tool-group-item ${_?"apteva-tool-group-item-has-detail":""}`,children:[D0.jsxs("div",{className:"apteva-tool-group-item-row",children:[Y.status==="completed"?D0.jsx("svg",{className:"apteva-tool-group-item-icon apteva-tool-group-item-done",width:"12",height:"12",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:D0.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:3,d:"M5 13l4 4L19 7"})}):Y.status==="error"?D0.jsx("svg",{className:"apteva-tool-group-item-icon apteva-tool-group-item-error",width:"12",height:"12",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:D0.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:3,d:"M6 18L18 6M6 6l12 12"})}):D0.jsx("div",{className:"apteva-tool-group-item-icon apteva-tool-group-item-spinner"}),D0.jsx("span",{className:"apteva-tool-group-item-name",children:Y.name}),Y.status==="running"&&!Y.streamOutput&&D0.jsx("span",{className:"apteva-tool-group-item-running-label",children:"running..."}),Y.status==="preparing"&&D0.jsx("span",{className:"apteva-tool-group-item-running-label",children:"preparing..."})]}),Y.status==="running"&&Y.streamOutput&&D0.jsx("div",{className:"apteva-tool-group-item-detail",children:Y.streamOutput}),V&&D0.jsx("div",{className:"apteva-tool-group-item-detail apteva-tool-group-item-result-text",children:V})]},Y.id)})})]})}function pZ({widget:X}){let $=X.props.title||X.type.replace(/_/g," ");return wX.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 rounded-lg bg-neutral-100 dark:bg-neutral-800 border border-neutral-200 dark:border-neutral-700 text-sm",children:[wX.jsx("div",{className:"w-2 h-2 rounded-full bg-emerald-500 animate-pulse flex-shrink-0"}),wX.jsx("span",{className:"text-neutral-600 dark:text-neutral-400 capitalize",children:$}),wX.jsx("span",{className:"text-neutral-400 dark:text-neutral-500 text-xs ml-auto",children:"pinned above"})]})}function cZ({message:X,onAction:$,enableWidgets:Q,onWidgetRender:Z,persistentWidgetIds:z,toolCallStyle:H="card"}){let G=X.role==="user",J=X.metadata?.content_segments,U=X.metadata?.isStreaming===!0,K=X.content||J&&J.length>0,O=EX.useRef(new Set),Y=EX.useMemo(()=>{if(!Q||G||!X.content)return[];return aX(X.content).segments.filter((j)=>j.type==="widget"&&!!j.widget).map((j)=>j.widget)},[Q,G,X.content]);EX.useEffect(()=>{if(Z&&X.widgets){for(let R of X.widgets)if(!O.current.has(R.id))O.current.add(R.id),Z(R)}},[X.widgets,Z]),EX.useEffect(()=>{if(Z&&Y.length>0){for(let R of Y)if(!O.current.has(R.id))O.current.add(R.id),Z(R)}},[Y,Z]);let V=(R)=>{if(!Q||G)return E.jsx(YX,{content:R});let T=aX(R).segments.filter((f)=>f.type==="text"&&f.content).map((f)=>f.content).join("");if(!T.trim())return null;return E.jsx(YX,{content:T})},_=()=>{if(!Q||G||!X.content)return null;let R=aX(X.content),j=[],T="";if(R.segments.forEach((f,P)=>{if(f.type==="text"&&f.content)T+=f.content;else if(f.type==="widget"&&f.widget){if(T.trim())j.push(E.jsx("div",{className:"apteva-message-bubble apteva-message-assistant",children:E.jsx("div",{className:"apteva-message-content-assistant",children:E.jsx(YX,{content:T})})},`text-${P}`)),T="";j.push(E.jsx("div",{className:"apteva-widget-standalone",children:E.jsx(X$,{widget:f.widget,onAction:$})},`widget-${P}`))}else if(f.type==="widget_pending"&&f.pendingType){if(T.trim())j.push(E.jsx("div",{className:"apteva-message-bubble apteva-message-assistant",children:E.jsx("div",{className:"apteva-message-content-assistant",children:E.jsx(YX,{content:T})})},`text-${P}`)),T="";j.push(E.jsx("div",{className:"apteva-widget-standalone",children:E.jsx(j$,{type:f.pendingType})},`pending-${P}`))}}),T.trim())j.push(E.jsx("div",{className:"apteva-message-bubble apteva-message-assistant",children:E.jsx("div",{className:"apteva-message-content-assistant",children:E.jsx(YX,{content:T})})},"text-final"));return j.length>0?j:null},B=X.metadata?.attachments||[],A=B.length>0,I=()=>{if(!A)return null;return E.jsx("div",{className:"apteva-message-attachments flex flex-wrap gap-2 mb-2 justify-end",children:B.map((R,j)=>{let T=R.type.startsWith("image/"),f=R.type==="application/pdf";if(T&&R.preview)return E.jsx("div",{className:"apteva-attachment-image relative rounded-lg overflow-hidden shadow-sm",children:E.jsx("img",{src:R.preview,alt:R.name,className:"max-w-[150px] max-h-[150px] object-cover"})},j);return E.jsxs("div",{className:"apteva-attachment-doc flex items-center gap-3 px-4 py-3 bg-neutral-100 dark:bg-neutral-800 border border-neutral-200 dark:border-neutral-700 rounded-xl shadow-sm",children:[E.jsx("div",{className:"w-10 h-10 flex items-center justify-center bg-red-100 dark:bg-red-900/30 rounded-lg text-red-600 dark:text-red-400",children:f?E.jsx("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:E.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M7 21h10a2 2 0 002-2V9.414a1 1 0 00-.293-.707l-5.414-5.414A1 1 0 0012.586 3H7a2 2 0 00-2 2v14a2 2 0 002 2z"})}):E.jsx("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:E.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"})})}),E.jsxs("div",{className:"flex flex-col min-w-0",children:[E.jsx("span",{className:"text-sm font-medium text-neutral-800 dark:text-neutral-200 truncate max-w-[180px]",children:R.name}),E.jsxs("span",{className:"text-xs text-neutral-500 dark:text-neutral-400",children:[f?"PDF":"Document"," · ",eX(R.size)]})]})]},j)})})},M=()=>{if(G)return E.jsx("div",{className:"apteva-message-text",children:X.content});if(U&&!K)return E.jsxs("div",{className:"apteva-typing-indicator",children:[E.jsx("span",{}),E.jsx("span",{}),E.jsx("span",{})]});if(J&&J.length>0)return null;return V(X.content)},h=(R,j)=>{if(!Q)return E.jsx("div",{className:"apteva-message-bubble apteva-message-assistant",children:E.jsx("div",{className:"apteva-message-content-assistant",children:E.jsx(YX,{content:R})})},j);let T=aX(R),f=[],P="";if(T.segments.forEach((b,F)=>{if(b.type==="text"&&b.content)P+=b.content;else if(b.type==="widget"&&b.widget){if(P.trim())f.push(E.jsx("div",{className:"apteva-message-bubble apteva-message-assistant",children:E.jsx("div",{className:"apteva-message-content-assistant",children:E.jsx(YX,{content:P})})},`${j}-text-${F}`)),P="";f.push(E.jsx("div",{className:"apteva-widget-standalone",children:E.jsx(X$,{widget:b.widget,onAction:$})},`${j}-widget-${F}`))}else if(b.type==="widget_pending"&&b.pendingType){if(P.trim())f.push(E.jsx("div",{className:"apteva-message-bubble apteva-message-assistant",children:E.jsx("div",{className:"apteva-message-content-assistant",children:E.jsx(YX,{content:P})})},`${j}-text-${F}`)),P="";f.push(E.jsx("div",{className:"apteva-widget-standalone",children:E.jsx(j$,{type:b.pendingType})},`${j}-pending-${F}`))}}),P.trim())f.push(E.jsx("div",{className:"apteva-message-bubble apteva-message-assistant",children:E.jsx("div",{className:"apteva-message-content-assistant",children:E.jsx(YX,{content:P})})},`${j}-text-final`));return f},i=()=>{if(!J||J.length===0)return null;let R=[],j=[],T=()=>{if(j.length>0)R.push({type:"tools",tools:[...j]}),j=[]};J.forEach((P,b)=>{if(P.type==="tool")j.push(P);else if(T(),P.type==="text"&&P.content)R.push({type:"text",content:P.content,index:b})}),T();let f=[];return R.forEach((P,b)=>{if(P.type==="text"){let F=h(P.content,`seg-${P.index}`);if(Array.isArray(F))f.push(...F);else f.push(F)}else if(P.type==="tools")if(H==="inline")P.tools.forEach((F)=>{if(F.type==="tool")f.push(E.jsx("div",{className:"apteva-tool-call-standalone",children:E.jsx(f$,{name:F.name,status:F.status||(F.result!==void 0?"completed":"running"),isReceiving:F.isReceiving,inputLength:F.inputLength,streamOutput:F.streamOutput,variant:"inline"})},F.id))});else if(P.tools.length>=3){let F=P.tools.map((A0)=>{let $0=A0;return{id:$0.id,name:$0.name,status:$0.status||($0.result!==void 0?"completed":"running"),isReceiving:$0.isReceiving,streamOutput:$0.streamOutput,result:$0.result}});f.push(E.jsx("div",{className:"apteva-tool-call-standalone",children:E.jsx(mZ,{tools:F})},`tool-group-${b}`))}else P.tools.forEach((F)=>{if(F.type==="tool")f.push(E.jsx("div",{className:"apteva-tool-call-standalone",children:E.jsx(f$,{name:F.name,status:F.status||(F.result!==void 0?"completed":"running"),isReceiving:F.isReceiving,inputLength:F.inputLength,streamOutput:F.streamOutput})},F.id))})}),f},o=()=>{if(!X.widgets||X.widgets.length===0)return null;let R=X.widgets.filter((T)=>!z?.has(T.id)),j=X.widgets.filter((T)=>z?.has(T.id));return E.jsxs(E.Fragment,{children:[j.map((T)=>E.jsx("div",{className:"apteva-widget-standalone",children:E.jsx(pZ,{widget:T})},`ref-${T.id}`)),R.length>0&&E.jsx("div",{className:"apteva-widget-standalone",children:E.jsx(hZ,{widgets:R,onAction:$,layout:"stack"})})]})};if(!G&&(J&&J.length>0))return E.jsxs("div",{className:"apteva-message-segmented",children:[i(),o(),E.jsx("div",{className:"apteva-message-timestamp apteva-message-timestamp-assistant",suppressHydrationWarning:!0,children:X.timestamp.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})})]});let e=_();if(!G&&Q&&e)return E.jsxs("div",{className:"apteva-message-segmented",children:[e,o(),E.jsx("div",{className:"apteva-message-timestamp apteva-message-timestamp-assistant",suppressHydrationWarning:!0,children:X.timestamp.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})})]});if(G&&A)return E.jsxs("div",{className:"apteva-message-segmented apteva-message-user-with-attachments flex flex-col items-end",children:[I(),X.content&&E.jsx("div",{className:"apteva-message-bubble apteva-message-user",children:E.jsx("div",{className:"apteva-message-content-user",children:E.jsx("div",{className:"apteva-message-text",children:X.content})})}),E.jsx("div",{className:"apteva-message-timestamp apteva-message-timestamp-user",suppressHydrationWarning:!0,children:X.timestamp.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})})]});return E.jsxs("div",{className:q0("apteva-message-bubble",G?"apteva-message-user":"apteva-message-assistant"),children:[E.jsx("div",{className:G?"apteva-message-content-user":"apteva-message-content-assistant",children:M()}),o(),E.jsx("div",{className:q0("apteva-message-timestamp",G?"apteva-message-timestamp-user":"apteva-message-timestamp-assistant"),suppressHydrationWarning:!0,children:X.timestamp.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})})]})}var h$=()=>c.jsx("svg",{className:"w-12 h-12 sm:w-16 sm:h-16",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:c.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M8 12h.01M12 12h.01M16 12h.01M21 12c0 4.418-4.03 8-9 8a9.863 9.863 0 01-4.255-.949L3 20l1.395-3.72C3.512 15.042 3 13.574 3 12c0-4.418 4.03-8 9-8s9 3.582 9 8z"})}),U$=()=>c.jsx("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:c.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M13 7l5 5m0 0l-5 5m5-5H6"})});function lZ({title:X,subtitle:$,icon:Q,prompts:Z,variant:z="centered",chatVariant:H="default",onPromptClick:G}){let J=(Z||[]).map((O)=>typeof O==="string"?{text:O}:O),U=J.length>0,K=X||$||Q;if(!K&&!U)return c.jsx("div",{className:"apteva-welcome-empty flex items-center justify-center h-full",children:c.jsxs("div",{className:"text-center space-y-2",children:[c.jsx("div",{className:"flex justify-center",children:c.jsx(h$,{})}),c.jsx("p",{className:"text-sm",children:"No messages yet. Start a conversation!"})]})});if(z==="minimal")return c.jsxs("div",{className:"flex flex-col h-full px-4 py-4",children:[K&&c.jsxs("div",{className:"mb-4",children:[X&&c.jsx("h2",{className:"apteva-welcome-title text-lg font-semibold",children:X}),$&&c.jsx("p",{className:"apteva-welcome-subtitle text-sm mt-1",children:$})]}),U&&c.jsx("div",{className:"flex-1 space-y-2",children:J.map((O,Y)=>c.jsx("button",{onClick:()=>G(O.text),className:q0("apteva-prompt-card w-full text-left px-4 py-3 rounded-xl","border transition-all duration-200","group"),children:c.jsxs("div",{className:"flex items-center gap-3",children:[c.jsx("div",{className:"apteva-prompt-icon flex-shrink-0 transition-colors",children:O.icon||c.jsx(U$,{})}),c.jsxs("div",{className:"flex-1 min-w-0",children:[c.jsx("p",{className:"apteva-prompt-text text-sm font-medium truncate",children:O.text}),O.description&&c.jsx("p",{className:"apteva-prompt-desc text-xs mt-0.5 truncate",children:O.description})]})]})},Y))})]});return c.jsxs("div",{className:"flex flex-col items-center justify-center h-full px-4 py-6 sm:py-8",children:[c.jsxs("div",{className:"text-center mb-6 sm:mb-8 max-w-md",children:[c.jsx("div",{className:"apteva-welcome-icon mb-4 flex justify-center",children:Q||c.jsx(h$,{})}),X&&c.jsx("h1",{className:"apteva-welcome-title text-xl sm:text-2xl font-semibold mb-2",children:X}),$&&c.jsx("p",{className:"apteva-welcome-subtitle text-sm sm:text-base",children:$})]}),U&&c.jsxs("div",{className:"w-full max-w-2xl",children:[c.jsx("div",{className:"sm:hidden space-y-2",children:J.map((O,Y)=>c.jsx("button",{onClick:()=>G(O.text),className:q0("apteva-prompt-card w-full text-left px-4 py-3 rounded-xl","border transition-all duration-200","active:scale-[0.98]","shadow-sm hover:shadow","group"),children:c.jsxs("div",{className:"flex items-center gap-3",children:[c.jsx("div",{className:"apteva-prompt-icon-box flex-shrink-0 w-8 h-8 rounded-lg flex items-center justify-center transition-colors",children:O.icon||c.jsx(U$,{})}),c.jsxs("div",{className:"flex-1 min-w-0",children:[c.jsx("p",{className:"apteva-prompt-text text-sm font-medium",children:O.text}),O.description&&c.jsx("p",{className:"apteva-prompt-desc text-xs mt-0.5 line-clamp-1",children:O.description})]}),c.jsx("svg",{className:"apteva-prompt-chevron w-4 h-4 transition-colors flex-shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:c.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 5l7 7-7 7"})})]})},Y))}),c.jsx("div",{className:"hidden sm:grid sm:grid-cols-2 gap-3",children:J.map((O,Y)=>c.jsx("button",{onClick:()=>G(O.text),className:q0("apteva-prompt-card text-left p-4 rounded-xl","border transition-all duration-200","hover:shadow-md","active:scale-[0.98]","group"),children:c.jsxs("div",{className:"flex items-start gap-3",children:[c.jsx("div",{className:"apteva-prompt-icon-box flex-shrink-0 w-9 h-9 rounded-lg flex items-center justify-center transition-colors",children:O.icon||c.jsx(U$,{})}),c.jsxs("div",{className:"flex-1 min-w-0",children:[c.jsx("p",{className:"apteva-prompt-text text-sm font-medium leading-snug",children:O.text}),O.description&&c.jsx("p",{className:"apteva-prompt-desc text-xs mt-1 line-clamp-2",children:O.description})]})]})},Y))})]})]})}function dZ({messages:X,onAction:$,welcomeTitle:Q,welcomeSubtitle:Z,welcomeIcon:z,suggestedPrompts:H,welcomeVariant:G,chatVariant:J,onPromptClick:U,enableWidgets:K,onWidgetRender:O,persistentWidgetIds:Y,toolCallStyle:V}){let _=vX.useRef(null),B=vX.useRef(!0),A=vX.useRef(0),I=()=>{if(_.current){let{scrollTop:M,scrollHeight:h,clientHeight:i}=_.current;B.current=h-M-i<100}};return vX.useEffect(()=>{if(_.current&&B.current){let M=_.current.scrollHeight;if(M!==A.current)_.current.scrollTop=M,A.current=M}},[X]),cX.jsx("div",{ref:_,className:"apteva-message-list apteva-scrollbar-hidden",onScroll:I,children:X.length===0?cX.jsx(lZ,{title:Q,subtitle:Z,icon:z,prompts:H,variant:G,chatVariant:J,onPromptClick:U||(()=>{})}):X.map((M)=>cX.jsx("div",{className:M.role==="user"?"apteva-message-row-user":"apteva-message-row-assistant",children:cX.jsx(cZ,{message:M,onAction:$,enableWidgets:K,onWidgetRender:O,persistentWidgetIds:Y,toolCallStyle:V})},M.id))})}var x$=()=>{if(typeof window>"u")return null;return window.SpeechRecognition||window.webkitSpeechRecognition||null};function iZ({onSendMessage:X,placeholder:$="Type a message...",disabled:Q=!1,isLoading:Z=!1,onStop:z,onFileUpload:H,onSwitchMode:G,speechToText:J,enableVoice:U=!1,voiceState:K="idle",voicePartialTranscript:O="",voiceDuration:Y=0,onVoiceStart:V,onVoiceStop:_}){let[B,A]=G0.useState(""),[I,M]=G0.useState(!1),[h,i]=G0.useState([]),[o,e]=G0.useState(null),[R,j]=G0.useState(!1),T=G0.useRef(null),f=G0.useRef(null),P=G0.useRef(null),[b,F]=G0.useState(!1),[A0,$0]=G0.useState(0),[y0,S0]=G0.useState(null),y=G0.useRef(null),g=G0.useRef(null),a=G0.useRef(null),q=G0.useRef(null),N=G0.useRef(null),L=G0.useRef(0),S=G0.useRef(null),Q0=G0.useRef(null),K0=G0.useRef(""),O0=G0.useRef(!1),x0=J?typeof J==="object"?J:{}:null,qX=!!x0&&!!x$(),FX=x0?.silenceTimeout??2000,dX=x0?.autoSend!==!1;G0.useEffect(()=>{return()=>{r0(!0)}},[]);let KX=G0.useCallback(()=>{let x=N.current,X0=q.current;if(!x||!X0)return;let B0=window.devicePixelRatio||1,k0=x.getBoundingClientRect();x.width=k0.width*B0,x.height=k0.height*B0;let F0=x.getContext("2d");if(!F0)return;F0.scale(B0,B0);let v0=X0.frequencyBinCount,f0=new Uint8Array(v0),h0=new Float32Array(40).fill(2),NX=()=>{L.current=requestAnimationFrame(NX),X0.getByteTimeDomainData(f0);let{width:l0,height:e0}=k0;F0.clearRect(0,0,l0,e0);let XX=40,oX=2,hX=Math.max(2,(l0-(XX-1)*oX)/XX),TX=Math.floor(v0/XX);for(let $X=0;$X<XX;$X++){let Y$=0;for(let xX=0;xX<TX;xX++){let QX=(f0[$X*TX+xX]-128)/128;Y$+=QX*QX}let J$=Math.sqrt(Y$/TX),d0=Math.max(2,J$*e0*3);h0[$X]+=(d0-h0[$X])*(d0>h0[$X]?0.4:0.15);let VX=Math.min(h0[$X],e0-2),H$=$X*(hX+oX),rX=(e0-VX)/2,nX=Math.min(hX/2,VX/2);F0.fillStyle="#3b82f6",F0.beginPath(),F0.roundRect(H$,rX,hX,VX,nX),F0.fill()}};NX()},[]);G0.useEffect(()=>{if(b&&N.current&&q.current)KX()},[b,KX]);let t0=G0.useCallback(async()=>{let x=x$();if(!x)return;try{let X0=await navigator.mediaDevices.getUserMedia({audio:!0});g.current=X0;let B0=new AudioContext;a.current=B0;let k0=B0.createMediaStreamSource(X0),F0=B0.createAnalyser();F0.fftSize=256,k0.connect(F0),q.current=F0;let v0=new x;v0.continuous=!0,v0.interimResults=!0,v0.lang=x0?.language||navigator.language||"en-US",y.current=v0,K0.current="",O0.current=!1,v0.onresult=(f0)=>{let h0="",NX="";for(let l0=0;l0<f0.results.length;l0++){let e0=f0.results[l0];if(e0.isFinal)h0+=e0[0].transcript;else NX+=e0[0].transcript}if(K0.current=h0,S.current)clearTimeout(S.current);S.current=setTimeout(()=>{r0(!1)},FX)},v0.onerror=(f0)=>{if(f0.error!=="aborted")console.warn("Speech recognition error:",f0.error);r0(!0)},v0.onend=()=>{if(!O0.current&&b)OX()},v0.start(),F(!0),$0(0),Q0.current=setInterval(()=>{$0((f0)=>f0+1)},1000),S.current=setTimeout(()=>{r0(!1)},FX+1000)}catch(X0){console.warn("Microphone access denied or error:",X0),e("Microphone access denied"),setTimeout(()=>e(null),3000)}},[x0?.language,FX]),OX=G0.useCallback(()=>{let x=K0.current.trim();if(F(!1),$0(0),x)if(dX)S0(x),setTimeout(()=>{S0(null),X(x)},600);else A((X0)=>X0?`${X0} ${x}`:x)},[dX,X]),r0=G0.useCallback((x)=>{if(O0.current=!0,S.current)clearTimeout(S.current),S.current=null;if(Q0.current)clearInterval(Q0.current),Q0.current=null;if(L.current)cancelAnimationFrame(L.current),L.current=0;if(y.current){try{y.current.stop()}catch(X0){}y.current=null}if(g.current)g.current.getTracks().forEach((X0)=>X0.stop()),g.current=null;if(a.current){try{a.current.close()}catch(X0){}a.current=null}if(q.current=null,!x)OX();else F(!1),$0(0)},[OX]),p0=(x)=>{let X0=Math.floor(x/60),B0=x%60;return`${X0.toString().padStart(2,"0")}:${B0.toString().padStart(2,"0")}`},CX=(x)=>{if(x.key==="Enter"&&!x.shiftKey)x.preventDefault(),WX()},WX=()=>{let x=B.trim(),X0=h.length>0;if((x||X0)&&!Q){let B0=h.map((k0)=>k0.file);if(X(B.trim(),B0.length>0?B0:void 0),A(""),i([]),e(null),j(!1),T.current)T.current.style.height="auto"}},Z$=(x)=>{A(x.target.value),x.target.style.height="auto";let X0=x.target.scrollHeight;x.target.style.height=`${X0}px`;let B0=x.target.value.includes(`
|
|
35
|
+
`),F0=X0>36;if(!R&&(B0||F0))j(!0);else if(R&&!B0&&!F0&&x.target.value.length<20)j(!1)},jX=(x)=>{if(x.target.files&&x.target.files.length>0){let X0=Array.from(x.target.files),B0=[],k0=[];if(X0.forEach((F0)=>{let v0=u$(F0);if(v0.valid){let f0={file:F0};if(F0.type.startsWith("image/"))f0.preview=URL.createObjectURL(F0);B0.push(f0)}else k0.push(v0.error||"Invalid file")}),B0.length>0)i((F0)=>[...F0,...B0]);if(k0.length>0)e(k0.join(", ")),setTimeout(()=>e(null),5000);H?.(x.target.files),M(!1),x.target.value=""}},MX=(x)=>{i((X0)=>{let B0=X0[x];if(B0.preview)URL.revokeObjectURL(B0.preview);return X0.filter((k0,F0)=>F0!==x)})},fX=(x)=>{if(x.startsWith("image/"))return D.jsx("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:D.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 16l4.586-4.586a2 2 0 012.828 0L16 16m-2-2l1.586-1.586a2 2 0 012.828 0L20 14m-6-6h.01M6 20h12a2 2 0 002-2V6a2 2 0 00-2-2H6a2 2 0 00-2 2v12a2 2 0 002 2z"})});if(x==="application/pdf")return D.jsx("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:D.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M7 21h10a2 2 0 002-2V9.414a1 1 0 00-.293-.707l-5.414-5.414A1 1 0 0012.586 3H7a2 2 0 00-2 2v14a2 2 0 002 2z"})});return D.jsx("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:D.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"})})},b0=qX&&!b,iX=b0?"auto 1fr auto auto":"auto 1fr auto",UX=b?'"plus waveform waveform stop"':R?b0?'"textarea textarea textarea textarea" "plus . mic send"':'"textarea textarea textarea" "plus . send"':b0?'"plus textarea mic send"':'"plus textarea send"',z$="auto 1fr auto",c0=K==="active"||K==="connecting",A$=(x)=>{let X0=Math.floor(x/60),B0=x%60;return`${X0}:${B0.toString().padStart(2,"0")}`},n0=U&&!B.trim()&&h.length===0&&!Z&&!c0;if(c0)return D.jsx("div",{className:"px-4 py-3 relative",children:D.jsxs("div",{className:"apteva-voice-overlay",children:[D.jsx("div",{className:"apteva-voice-transcript-area",children:O?D.jsx("span",{className:"apteva-voice-partial",children:O}):K==="connecting"?D.jsx("span",{className:"apteva-voice-connecting",children:"Connecting..."}):D.jsx("span",{className:"apteva-voice-listening",children:"Listening..."})}),D.jsxs("div",{className:"apteva-voice-controls",children:[D.jsx("span",{className:"apteva-voice-duration",children:A$(Y)}),D.jsx("button",{onClick:_,className:"apteva-voice-stop-btn",title:"Stop voice mode",children:D.jsx("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:D.jsx("rect",{x:"3",y:"3",width:"10",height:"10",rx:"1",fill:"currentColor"})})})]}),D.jsx("div",{className:"apteva-voice-indicator",children:D.jsx("div",{className:`apteva-voice-pulse ${K==="active"?"apteva-voice-pulse-active":""}`})})]})});return D.jsxs("div",{className:"px-4 py-3 relative",children:[o&&D.jsx("div",{className:"apteva-file-error",children:D.jsxs("div",{className:"apteva-file-error-content",children:[D.jsx("svg",{fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:D.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})}),D.jsx("span",{children:o})]})}),y0&&D.jsx("div",{className:"apteva-transcript-flash",children:D.jsx("span",{children:y0})}),h.length>0&&!b&&D.jsx("div",{className:"apteva-file-preview",children:h.map((x,X0)=>D.jsxs("div",{className:"apteva-file-item",children:[x.preview?D.jsx("img",{src:x.preview,alt:x.file.name,className:"apteva-file-thumb"}):D.jsx("div",{className:"apteva-file-icon",children:fX(x.file.type)}),D.jsxs("div",{className:"apteva-file-info",children:[D.jsx("span",{className:"apteva-file-name",children:x.file.name}),D.jsx("span",{className:"apteva-file-size",children:eX(x.file.size)})]}),D.jsx("button",{onClick:()=>MX(X0),className:"apteva-file-remove",title:"Remove file",children:D.jsx("svg",{fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:D.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]},X0))}),D.jsxs("div",{className:"apteva-composer",style:{gridTemplateColumns:b?z$:iX,gridTemplateAreas:b?'"plus waveform stop"':UX,alignItems:b?"center":"end"},children:[D.jsx("div",{className:"relative flex-shrink-0",style:{gridArea:"plus",alignSelf:b?"center":"end"},children:b?D.jsx("div",{className:"apteva-composer-rec-dot",title:"Recording...",children:D.jsx("span",{})}):D.jsxs(D.Fragment,{children:[D.jsx("button",{ref:P,onClick:()=>M(!I),className:"apteva-composer-menu-btn w-8 h-8 rounded-lg flex items-center justify-center transition-all",title:"More options",children:D.jsx("svg",{width:"20",height:"20",viewBox:"0 0 20 20",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:D.jsx("path",{d:"M10 5v10M5 10h10",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})}),I&&D.jsxs(D.Fragment,{children:[D.jsx("div",{className:"fixed inset-0 z-[9998]",onClick:()=>M(!1)}),D.jsxs("div",{className:"apteva-composer-menu fixed rounded-xl shadow-lg overflow-hidden z-[9999] min-w-[200px]",style:{left:P.current?.getBoundingClientRect().left??0,bottom:window.innerHeight-(P.current?.getBoundingClientRect().top??0)+8},children:[D.jsxs("button",{onClick:()=>{f.current?.click(),M(!1)},className:"apteva-composer-menu-item w-full flex items-center gap-3 px-4 py-3 transition-colors text-left",children:[D.jsx("svg",{width:"18",height:"18",viewBox:"0 0 20 20",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:D.jsx("path",{d:"M10.5 3.5L5.5 8.5C4.67157 9.32843 4.67157 10.6716 5.5 11.5C6.32843 12.3284 7.67157 12.3284 8.5 11.5L14.5 5.5C15.8807 4.11929 15.8807 1.88071 14.5 0.5C13.1193 -0.880711 10.8807 -0.880711 9.5 0.5L3.5 6.5C1.56846 8.43154 1.56846 11.5685 3.5 13.5C5.43154 15.4315 8.56846 15.4315 10.5 13.5L15.5 8.5",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",transform:"translate(2, 3)"})}),D.jsx("span",{className:"!text-sm font-medium",children:"Add photos & files"})]}),G&&D.jsxs("button",{onClick:()=>{G(),M(!1)},className:"apteva-composer-menu-item w-full flex items-center gap-3 px-4 py-3 transition-colors text-left apteva-composer-menu-item-border",children:[D.jsx("svg",{className:"w-4.5 h-4.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:D.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M13 10V3L4 14h7v7l9-11h-7z"})}),D.jsx("span",{className:"!text-sm font-medium",children:"Switch to command mode"})]})]})]})]})}),b?D.jsxs(D.Fragment,{children:[D.jsxs("div",{className:"apteva-composer-waveform",style:{gridArea:"waveform"},children:[D.jsx("canvas",{ref:N,className:"apteva-composer-waveform-canvas"}),D.jsx("span",{className:"apteva-composer-recording-timer",children:p0(A0)})]}),D.jsx("div",{className:"self-center",style:{gridArea:"stop"},children:D.jsx("button",{onClick:()=>r0(!1),className:"apteva-composer-stop-btn",title:"Stop recording",children:D.jsx("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:D.jsx("rect",{x:"2",y:"2",width:"10",height:"10",rx:"1",fill:"currentColor"})})})})]}):D.jsxs(D.Fragment,{children:[D.jsx("textarea",{ref:T,value:B,onChange:Z$,onKeyDown:CX,placeholder:$,className:"apteva-composer-textarea resize-none bg-transparent border-none focus:outline-none !text-neutral-900 dark:!text-neutral-100 placeholder-neutral-400 dark:placeholder-neutral-500 py-1 overflow-y-auto max-h-[200px]",style:{gridArea:"textarea"},rows:1}),qX&&D.jsx("div",{className:"self-end",style:{gridArea:"mic"},children:D.jsx("button",{onClick:t0,disabled:Q||Z,className:"apteva-composer-mic-btn",title:"Voice input",children:D.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[D.jsx("path",{d:"M12 1a3 3 0 00-3 3v8a3 3 0 006 0V4a3 3 0 00-3-3z",fill:"currentColor"}),D.jsx("path",{d:"M19 10v2a7 7 0 01-14 0v-2",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"}),D.jsx("path",{d:"M12 19v4M8 23h8",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})]})})}),D.jsx("div",{className:"self-end",style:{gridArea:"send"},children:Z&&z?D.jsx("button",{onClick:z,className:"apteva-composer-stop-btn",title:"Stop generation",children:D.jsx("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:D.jsx("rect",{x:"2",y:"2",width:"10",height:"10",rx:"1",fill:"currentColor"})})}):n0?D.jsx("button",{onClick:V,className:"apteva-composer-voice-btn w-8 h-8 rounded-lg flex items-center justify-center transition-all flex-shrink-0",title:"Start voice mode",children:D.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[D.jsx("path",{d:"M12 1a3 3 0 00-3 3v8a3 3 0 006 0V4a3 3 0 00-3-3z",fill:"currentColor"}),D.jsx("path",{d:"M19 10v2a7 7 0 01-14 0v-2",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"}),D.jsx("path",{d:"M12 19v4M8 23h8",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})]})}):D.jsx("button",{onClick:WX,disabled:!B.trim()&&h.length===0||Q,className:"apteva-composer-send-btn w-8 h-8 rounded-lg flex items-center justify-center font-bold transition-all flex-shrink-0 border border-neutral-300 dark:border-neutral-600 bg-white dark:bg-neutral-800 !text-neutral-700 dark:!text-neutral-300 hover:bg-neutral-50 dark:hover:bg-neutral-700 disabled:opacity-30 disabled:cursor-not-allowed !text-lg",title:"Send message",children:D.jsx("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:D.jsx("path",{d:"M8 3L8 13M8 3L4 7M8 3L12 7",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})})})]})]}),D.jsx("input",{ref:f,type:"file",multiple:!0,onChange:jX,className:"hidden",accept:"image/*,application/pdf,.doc,.docx,.txt"})]})}function oZ({onExecute:X,state:$,response:Q,error:Z,plan:z,streamedContent:H,toolName:G,onApprove:J,onReject:U,onReset:K,onStop:O,onExpand:Y,placeholder:V="Enter your command...",disabled:_=!1}){let[B,A]=HX.useState(""),[I,M]=HX.useState([]),[h,i]=HX.useState(null),[o,e]=HX.useState(!1),R=HX.useRef(null),j=HX.useRef(null),T=HX.useRef(null),f=()=>{let q=B.trim(),N=I.length>0;if((q||N)&&!_&&$==="idle"){let L=I.map((S)=>S.file);X(B.trim(),L.length>0?L:void 0),A(""),M([])}},P=(q)=>{if(q.key==="Enter"&&!q.shiftKey)q.preventDefault(),f()},b=()=>{K?.(),R.current?.focus()},F=(q)=>{if(A(q),R.current)R.current.style.height="auto",R.current.style.height=`${Math.min(R.current.scrollHeight,120)}px`},A0=(q)=>{if(q.target.files&&q.target.files.length>0){let N=Array.from(q.target.files),L=[],S=[];if(N.forEach((Q0)=>{let K0=u$(Q0);if(K0.valid){let O0={file:Q0};if(Q0.type.startsWith("image/"))O0.preview=URL.createObjectURL(Q0);L.push(O0)}else S.push(K0.error||"Invalid file")}),L.length>0)M((Q0)=>[...Q0,...L]);if(S.length>0)i(S.join(", ")),setTimeout(()=>i(null),5000);e(!1),q.target.value=""}},$0=(q)=>{M((N)=>{let L=N[q];if(L.preview)URL.revokeObjectURL(L.preview);return N.filter((S,Q0)=>Q0!==q)})},y0=(q)=>{if(q.startsWith("image/"))return v.jsx("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:v.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 16l4.586-4.586a2 2 0 012.828 0L16 16m-2-2l1.586-1.586a2 2 0 012.828 0L20 14m-6-6h.01M6 20h12a2 2 0 002-2V6a2 2 0 00-2-2H6a2 2 0 00-2 2v12a2 2 0 002 2z"})});if(q==="application/pdf")return v.jsx("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:v.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M7 21h10a2 2 0 002-2V9.414a1 1 0 00-.293-.707l-5.414-5.414A1 1 0 0012.586 3H7a2 2 0 00-2 2v14a2 2 0 002 2z"})});return v.jsx("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:v.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"})})},S0=()=>{if($==="loading"){if(G)return{text:G,isToolCall:!0};if(H)return{text:H,isToolCall:!1};return{text:"Processing...",isToolCall:!1}}if($==="success"&&Q)return{text:Q,isToolCall:!1};if($==="error"&&Z)return{text:Z,isToolCall:!1};if($==="plan-pending"&&z)return{text:z,isToolCall:!1};return{text:"",isToolCall:!1}},y=$!=="idle",{text:g,isToolCall:a}=S0();return v.jsxs("div",{className:"w-full relative",children:[h&&v.jsx("div",{className:"apteva-file-error",style:{top:"-3rem",bottom:"auto"},children:v.jsxs("div",{className:"apteva-file-error-content",children:[v.jsx("svg",{fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:v.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})}),v.jsx("span",{children:h})]})}),v.jsxs("div",{className:q0("apteva-composer flex items-center gap-2 px-3 py-2 border-2 bg-white dark:bg-neutral-900 transition-all duration-200",$==="idle"&&"border-neutral-200 dark:border-neutral-700",$==="loading"&&"border-blue-400 dark:border-blue-500",$==="plan-pending"&&"border-amber-400 dark:border-amber-500",$==="success"&&"border-green-400 dark:border-green-500",$==="error"&&"border-red-400 dark:border-red-500"),children:[v.jsxs("div",{className:"w-8 h-8 flex items-center justify-center flex-shrink-0",children:[$==="idle"&&v.jsxs("div",{className:"relative",children:[v.jsx("button",{ref:T,onClick:()=>e(!o),className:"apteva-composer-menu-btn w-8 h-8 rounded-lg flex items-center justify-center transition-all !text-neutral-500 dark:!text-neutral-400 hover:!text-neutral-700 dark:hover:!text-neutral-200 hover:bg-neutral-100 dark:hover:bg-neutral-800",title:"More options",children:v.jsx("svg",{width:"18",height:"18",viewBox:"0 0 20 20",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:v.jsx("path",{d:"M10 5v10M5 10h10",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})}),o&&v.jsxs(v.Fragment,{children:[v.jsx("div",{className:"fixed inset-0 z-[9998]",onClick:()=>e(!1)}),v.jsxs("div",{className:"apteva-composer-menu fixed bg-neutral-800 dark:bg-neutral-800 rounded-xl shadow-lg overflow-hidden z-[9999] min-w-[200px]",style:{left:T.current?.getBoundingClientRect().left??0,top:(T.current?.getBoundingClientRect().bottom??0)+8},children:[v.jsxs("button",{onClick:()=>{j.current?.click(),e(!1)},className:"w-full flex items-center gap-3 px-4 py-3 hover:bg-neutral-700 dark:hover:bg-neutral-700 transition-colors !text-white text-left",children:[v.jsx("svg",{width:"18",height:"18",viewBox:"0 0 20 20",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:v.jsx("path",{d:"M10.5 3.5L5.5 8.5C4.67157 9.32843 4.67157 10.6716 5.5 11.5C6.32843 12.3284 7.67157 12.3284 8.5 11.5L14.5 5.5C15.8807 4.11929 15.8807 1.88071 14.5 0.5C13.1193 -0.880711 10.8807 -0.880711 9.5 0.5L3.5 6.5C1.56846 8.43154 1.56846 11.5685 3.5 13.5C5.43154 15.4315 8.56846 15.4315 10.5 13.5L15.5 8.5",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",transform:"translate(2, 3)"})}),v.jsx("span",{className:"!text-sm font-medium",children:"Add photos & files"})]}),Y&&v.jsxs("button",{onClick:()=>{Y(),e(!1)},className:"w-full flex items-center gap-3 px-4 py-3 hover:bg-neutral-700 dark:hover:bg-neutral-700 transition-colors !text-white text-left border-t border-neutral-700 dark:border-neutral-700",children:[v.jsx("svg",{className:"w-4.5 h-4.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:v.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 12h.01M12 12h.01M16 12h.01M21 12c0 4.418-4.03 8-9 8a9.863 9.863 0 01-4.255-.949L3 20l1.395-3.72C3.512 15.042 3 13.574 3 12c0-4.418 4.03-8 9-8s9 3.582 9 8z"})}),v.jsx("span",{className:"!text-sm font-medium",children:"Expand to chat"})]})]})]})]}),$==="loading"&&!G&&v.jsx("div",{className:"w-4 h-4 border-2 border-blue-200 border-t-blue-500 rounded-full animate-spin"}),$==="loading"&&G&&v.jsx("div",{className:"w-2 h-2 rounded-full bg-blue-500 animate-pulse"})]}),I.length>0&&$==="idle"&&v.jsx("div",{className:"apteva-file-badges",children:I.map((q,N)=>v.jsxs("div",{className:"apteva-file-badge",title:q.file.name,children:[q.preview?v.jsx("img",{src:q.preview,alt:q.file.name,className:"apteva-file-badge-img"}):v.jsx("span",{className:"apteva-file-badge-icon",children:y0(q.file.type)}),v.jsx("button",{onClick:()=>$0(N),className:"apteva-file-badge-remove",title:"Remove",children:v.jsx("svg",{fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:v.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]},N))}),$==="idle"?v.jsx("textarea",{ref:R,value:B,onChange:(q)=>F(q.target.value),onKeyDown:P,placeholder:I.length>0?"Add a message...":V,disabled:_,rows:1,className:q0("flex-1 resize-none bg-transparent border-none focus:outline-none","!text-neutral-900 dark:!text-neutral-100 placeholder-neutral-400 dark:placeholder-neutral-500","text-sm leading-relaxed py-1","disabled:opacity-50"),style:{minHeight:"24px",maxHeight:"120px"}}):v.jsx("div",{className:q0("flex-1 text-sm py-1 truncate flex items-center gap-2",$==="loading"&&!a&&"!text-neutral-600 dark:!text-neutral-400",$==="loading"&&a&&"!text-blue-600 dark:!text-blue-400",$==="success"&&"!text-neutral-900 dark:!text-neutral-100",$==="error"&&"!text-red-600 dark:!text-red-400",$==="plan-pending"&&"!text-amber-700 dark:!text-amber-300"),children:a?v.jsxs(v.Fragment,{children:[v.jsx("span",{className:"font-mono",children:g}),v.jsx("span",{className:"text-neutral-400 dark:text-neutral-500",children:"Running..."})]}):g}),v.jsx("div",{className:"w-8 h-8 flex items-center justify-center flex-shrink-0",children:$==="plan-pending"?v.jsxs("div",{className:"flex items-center gap-1",children:[v.jsx("button",{onClick:J,className:"px-2 py-1 bg-amber-500 text-white rounded-lg hover:bg-amber-600 transition-colors text-xs font-medium",children:"Approve"}),v.jsx("button",{onClick:U,className:"px-2 py-1 bg-neutral-200 dark:bg-neutral-700 text-neutral-700 dark:text-neutral-300 rounded-lg hover:bg-neutral-300 dark:hover:bg-neutral-600 transition-colors text-xs font-medium",children:"Modify"})]}):v.jsxs(v.Fragment,{children:[$==="loading"&&O&&v.jsx("button",{onClick:O,className:"apteva-composer-stop-btn",title:"Stop generation",children:v.jsx("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:v.jsx("rect",{x:"2",y:"2",width:"10",height:"10",rx:"1",fill:"currentColor"})})}),($==="success"||$==="error")&&v.jsx("button",{onClick:b,className:"w-8 h-8 rounded-lg flex items-center justify-center !text-neutral-400 hover:!text-neutral-600 dark:hover:!text-neutral-300 hover:bg-neutral-100 dark:hover:bg-neutral-800 transition-colors",title:"New command",children:v.jsx("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:v.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})}),$==="idle"&&v.jsx("button",{onClick:f,disabled:!B.trim()&&I.length===0||_,className:q0("apteva-composer-send-btn w-8 h-8 rounded-lg flex items-center justify-center transition-all","border border-neutral-200 dark:border-neutral-700","disabled:opacity-30 disabled:cursor-not-allowed",B.trim()||I.length>0?"bg-neutral-900 dark:bg-white !text-white dark:!text-neutral-900 border-neutral-900 dark:border-white":"bg-white dark:bg-neutral-800 !text-neutral-400"),title:"Execute command",children:v.jsx("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:v.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 12h14M12 5l7 7-7 7"})})})]})})]}),v.jsx("input",{ref:j,type:"file",multiple:!0,onChange:A0,className:"hidden",accept:"image/*,application/pdf,.doc,.docx,.txt"})]})}var rZ=class{constructor(X){QZ(this,"config"),this.config={apiUrl:X?.apiUrl??"",apiKey:X?.apiKey??""}}configure(X){if(X.apiUrl!==void 0)this.config.apiUrl=X.apiUrl;if(X.apiKey!==void 0)this.config.apiKey=X.apiKey}getConfig(){return{...this.config}}async chat(X){try{console.log("[AptevaClient] Chat request:",{agent_id:X.agent_id,message:typeof X.message==="string"?X.message.substring(0,100)+"...":"[multi-part message]",system:X.system,stream:X.stream});let $=await fetch(`${this.config.apiUrl}/chat`,{method:"POST",headers:{"Content-Type":"application/json","X-API-Key":this.config.apiKey},body:JSON.stringify(X)});if(!$.ok){let Z=await $.json().catch(()=>({error:"Request failed"}));throw Error(Z.error||`Request failed with status ${$.status}`)}let Q=await $.json();return{message:Q.response||Q.message||"",thread_id:Q.thread_id,widgets:Q.widgets}}catch($){throw console.error("Chat API error:",$),$}}async chatStream(X,$,Q,Z){try{console.log("[AptevaClient] Chat stream request:",{agent_id:X.agent_id,message:typeof X.message==="string"?X.message.substring(0,100)+"...":"[multi-part message]",system:X.system,stream:X.stream});let z=await fetch(`${this.config.apiUrl}/chat`,{method:"POST",headers:{"Content-Type":"application/json","X-API-Key":this.config.apiKey,Accept:"text/event-stream"},body:JSON.stringify({...X,stream:!0})});if(!z.ok){let K=await z.json().catch(()=>({error:"Request failed"}));throw Error(K.error||`Request failed with status ${z.status}`)}let H=z.body?.getReader();if(!H)throw Error("Response body is not readable");let G=new TextDecoder,J="",U="";while(!0){let{done:K,value:O}=await H.read();if(K)break;J+=G.decode(O,{stream:!0});let Y=J.split(`
|
|
36
|
+
`);J=Y.pop()||"";for(let V of Y){if(!V.trim()||V.startsWith(":"))continue;if(V.startsWith("data: ")){let _=V.slice(6);if(_==="[DONE]"){Q?.(U);return}try{let B=JSON.parse(_);if(B.thread_id)U=B.thread_id;$(B)}catch(B){console.warn("[AptevaClient] Failed to parse SSE data:",_)}}}}Q?.(U)}catch(z){let H=z instanceof Error?z:Error("Unknown error");throw Z?.(H),H}}async createThread(X,$){let Q=await fetch(`${this.config.apiUrl}/agents/${X}/threads`,{method:"POST",headers:{"Content-Type":"application/json","X-API-Key":this.config.apiKey},body:JSON.stringify({metadata:$})});if(!Q.ok){let z=await Q.json().catch(()=>({error:"Request failed"}));throw Error(z.error||`Request failed with status ${Q.status}`)}return(await Q.json()).thread_id}async getThreadMessages(X){let $=await fetch(`${this.config.apiUrl}/threads/${X}/messages`,{method:"GET",headers:{"X-API-Key":this.config.apiKey}});if(!$.ok){let Z=await $.json().catch(()=>({error:"Request failed"}));throw Error(Z.error||`Request failed with status ${$.status}`)}return(await $.json()).messages}async cancelRequest(X,$){try{let Q=await fetch(`${this.config.apiUrl}/agents/${X}/requests/${$}/cancel`,{method:"POST",headers:{"Content-Type":"application/json","X-API-Key":this.config.apiKey}});if(!Q.ok){let Z=await Q.json().catch(()=>({error:"Cancel request failed"}));throw Error(Z.error||`Cancel request failed with status ${Q.status}`)}}catch(Q){throw console.error("[AptevaClient] Cancel request error:",Q),Q}}},kX=new rZ;function nZ({widgets:X,onAction:$}){let[Q,Z]=r$.useState(!1);if(X.length===0)return null;return i0.jsxs("div",{className:"apteva-persistent-panel border-b border-neutral-200 dark:border-neutral-700 bg-neutral-50 dark:bg-neutral-900",children:[i0.jsxs("div",{className:"flex items-center justify-between px-3 py-1.5",children:[i0.jsxs("div",{className:"flex items-center gap-2",children:[i0.jsx("div",{className:"w-1.5 h-1.5 rounded-full bg-emerald-500 animate-pulse"}),i0.jsx("span",{className:"text-xs font-medium text-neutral-500 dark:text-neutral-400 uppercase tracking-wider",children:"Live"})]}),i0.jsx("button",{onClick:()=>Z((z)=>!z),className:"p-1 rounded text-neutral-400 hover:text-neutral-600 dark:hover:text-neutral-300 hover:bg-neutral-200 dark:hover:bg-neutral-700 transition-colors",children:i0.jsx("svg",{className:q0("w-3.5 h-3.5 transition-transform",Q&&"rotate-180"),fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:i0.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M19 9l-7 7-7-7"})})})]}),!Q&&i0.jsx("div",{className:"px-3 pb-3 flex flex-col gap-3",children:X.map((z)=>i0.jsx(X$,{widget:z,onAction:$},z.id))})]})}function aZ(X){let $=new Int16Array(X.length);for(let Q=0;Q<X.length;Q++){let Z=Math.max(-1,Math.min(1,X[Q]));$[Q]=Z<0?Z*32768:Z*32767}return $}function sZ(X){let $=new Uint8Array(X.buffer),Q="";for(let Z=0;Z<$.length;Z++)Q+=String.fromCharCode($[Z]);return btoa(Q)}function tZ(X){let $=atob(X),Q=new Int16Array($.length/2);for(let z=0;z<Q.length;z++)Q[z]=$.charCodeAt(z*2+1)<<8|$.charCodeAt(z*2);let Z=new Float32Array(Q.length);for(let z=0;z<Q.length;z++)Z[z]=Q[z]/(Q[z]<0?32768:32767);return Z}function n$(X){let[$,Q]=J0.useState("idle"),[Z,z]=J0.useState(""),[H,G]=J0.useState(0),[J,U]=J0.useState(!1),K=J0.useRef(null),O=J0.useRef(null),Y=J0.useRef(null),V=J0.useRef(null),_=J0.useRef(null),B=J0.useRef(0),A=J0.useRef(null),I=J0.useRef(0),M=J0.useRef(!1),h=J0.useRef(X);h.current=X;let i=J0.useRef([]),o=J0.useRef(0),e=J0.useRef(0),R=J0.useRef(!1),j=J0.useCallback(()=>{if(A.current)clearInterval(A.current),A.current=null;if(_.current)_.current.disconnect(),_.current=null;if(V.current)V.current.getTracks().forEach((y)=>y.stop()),V.current=null;if(O.current){try{O.current.close()}catch(y){}O.current=null}if(Y.current){try{Y.current.close()}catch(y){}Y.current=null}if(K.current){try{K.current.close()}catch(y){}K.current=null}B.current=0,M.current=!1,i.current=[],o.current=0,e.current=0,R.current=!1,U(!1),z(""),G(0)},[]),T=J0.useCallback(()=>{i.current.forEach((y)=>{try{y.stop()}catch(g){}}),i.current=[],B.current=0,o.current=0,e.current=0},[]);J0.useEffect(()=>{return()=>{j()}},[j]);let f=J0.useCallback((y)=>{if(!Y.current)Y.current=new AudioContext({sampleRate:24000});let g=Y.current;if(g.state==="suspended")g.resume();let a=tZ(y),q=g.createBuffer(1,a.length,24000);q.getChannelData(0).set(a);let N=g.createBufferSource();N.buffer=q,N.connect(g.destination),i.current.push(N),N.onended=()=>{i.current=i.current.filter((Q0)=>Q0!==N)};let L=g.currentTime,S=Math.max(L,B.current);if(N.start(S),B.current=S+q.duration,o.current===0)o.current=S;e.current+=Math.floor(q.duration*1000)},[]),P=J0.useRef(()=>{}),b=J0.useCallback((y)=>{let g=h.current;switch(y.type){case"session_created":Q("active"),I.current=Date.now(),A.current=setInterval(()=>{G(Math.floor((Date.now()-I.current)/1000))},1000),P.current();break;case"audio_delta":if(R.current)break;if(y.data?.chunk)f(y.data.chunk);break;case"audio_complete":R.current=!1;break;case"audio_interrupt":{if(i.current.length===0)break;let a=0;if(Y.current&&o.current>0){let S=Math.max(0,Math.floor((Y.current.currentTime-o.current)*1000));a=Math.min(S,e.current)}let q=y.data?.item_id,N=y.data?.content_index||0;if(T(),q)R.current=!0;let L=K.current;if(L&&L.readyState===WebSocket.OPEN&&q)L.send(JSON.stringify({type:"control",data:{action:"truncate",item_id:q,content_index:N,audio_end_ms:a}}));break}case"transcript":if(y.data)if(y.data.partial)z(y.data.content);else z(""),g.onTranscript?.({id:`vt-${Date.now()}-${Math.random().toString(36).slice(2,6)}`,role:y.data.role,content:y.data.content,partial:!1,timestamp:new Date});break;case"tool_call":if(y.data)T(),g.onTranscript?.({id:`vt-tool-${Date.now()}`,role:"system",content:`Using ${y.data.name}...`,partial:!1,timestamp:new Date});break;case"tool_result":if(y.data){let a=y.data.error?"failed":"completed";g.onTranscript?.({id:`vt-toolresult-${Date.now()}`,role:"system",content:`Tool ${a}: ${y.data.name||y.data.call_id}`,partial:!1,timestamp:new Date})}break;case"turn_end":R.current=!1;break;case"error":Q("error"),g.onError?.(Error(y.data?.message||"Voice session error"));break}},[f,T]),F=J0.useCallback(async()=>{let y=K.current;if(!y)return;if(_.current)_.current.disconnect(),_.current=null;if(V.current)V.current.getTracks().forEach((g)=>g.stop()),V.current=null;if(O.current){try{O.current.close()}catch(g){}O.current=null}try{if(O.current=new AudioContext({sampleRate:24000}),O.current.state==="suspended")await O.current.resume();V.current=await navigator.mediaDevices.getUserMedia({audio:{echoCancellation:!0,noiseSuppression:!0,autoGainControl:!0}});let g=O.current.createMediaStreamSource(V.current);_.current=O.current.createScriptProcessor(4096,1,1),_.current.onaudioprocess=(q)=>{if(!y||y.readyState!==WebSocket.OPEN)return;if(M.current)return;let N=q.inputBuffer.getChannelData(0),L=aZ(N),S=sZ(L);y.send(JSON.stringify({type:"audio",data:{chunk:S,sample_rate:24000}}))},g.connect(_.current);let a=O.current.createGain();a.gain.value=0,_.current.connect(a),a.connect(O.current.destination)}catch(g){console.warn("Microphone access denied:",g),h.current.onError?.(Error("Microphone access denied"))}},[]);P.current=F;let A0=J0.useCallback(()=>{if($!=="idle")return;Q("connecting");let y;if(/^https?:\/\//.test(X.apiUrl))y=X.apiUrl.replace(/^http/,"ws")+"/voice";else y=`${window.location.protocol==="https:"?"wss:":"ws:"}//${window.location.host}${X.apiUrl}/voice`;if(X.apiKey)y+=`${y.includes("?")?"&":"?"}token=${encodeURIComponent(X.apiKey)}`;let g=new WebSocket(y);if(K.current=g,!Y.current)Y.current=new AudioContext({sampleRate:24000});if(Y.current.state==="suspended")Y.current.resume();g.onopen=()=>{let a=h.current.provider||"openai",q=h.current.voice||"ash";g.send(JSON.stringify({type:"start",data:{provider:a,voice:q}}))},g.onmessage=(a)=>{try{let q=JSON.parse(a.data);b(q)}catch(q){}},g.onerror=()=>{Q("error"),h.current.onError?.(Error("WebSocket connection failed"))},g.onclose=()=>{j(),Q("idle")}},[$,X.apiUrl,X.apiKey,b,j]),$0=J0.useCallback(()=>{j(),Q("idle")},[j]),y0=J0.useCallback(()=>{let y=!M.current;if(M.current=y,U(y),V.current){let g=V.current.getAudioTracks()[0];if(g)g.enabled=!y}},[]),S0=J0.useCallback((y)=>{let g=K.current;if(!g||g.readyState!==WebSocket.OPEN)return;g.send(JSON.stringify({type:"text",data:{content:y}}))},[]);return{state:$,partialTranscript:Z,duration:H,muted:J,start:A0,stop:$0,sendText:S0,toggleMute:y0}}var a$=t.forwardRef(function({agentId:$,threadId:Q,initialMessages:Z=[],context:z,apiUrl:H,apiKey:G,useMock:J=!1,initialMode:U="chat",showModeToggle:K=!1,onModeChange:O,commandVariant:Y="default",planMode:V=!1,onPlanModeChange:_,enableStreaming:B=!0,showProgress:A=!0,loadingText:I="Processing...",welcomeTitle:M,welcomeSubtitle:h,welcomeIcon:i,suggestedPrompts:o,welcomeVariant:e,onThreadChange:R,onMessageSent:j,onAction:T,onFileUpload:f,onComplete:P,onError:b,onToolCall:F,onToolResult:A0,variant:$0="default",theme:y0,placeholder:S0,showHeader:y=!0,headerTitle:g="Chat",onHeaderBack:a,toolCallStyle:q="card",enableWidgets:N=!1,availableWidgets:L,compactWidgetContext:S=!1,onWidgetRender:Q0,speechToText:K0,enableVoice:O0=!1,voiceProvider:x0,voiceId:qX,className:FX},dX){let[KX,t0]=t.useState(Z),[OX,r0]=t.useState(!1),[p0,CX]=t.useState(Q||null),[WX,Z$]=t.useState(U),[jX,MX]=t.useState(null),[fX,b0]=t.useState("idle"),[iX,UX]=t.useState(null),[z$,c0]=t.useState(null),[A$,n0]=t.useState(0),[x,X0]=t.useState(""),[B0,k0]=t.useState(""),[F0,v0]=t.useState(null),[f0,h0]=t.useState(null),[NX,l0]=t.useState(""),[e0,XX]=t.useState(""),[oX,hX]=t.useState(V),[TX,$X]=t.useState(!1),Y$=t.useRef(null),J$=t.useCallback((r)=>{let P0={id:r.id,role:r.role==="system"?"assistant":r.role,content:r.content,timestamp:r.timestamp,metadata:r.role==="system"?{isVoiceSystem:!0}:{isVoice:!0}};t0((E0)=>[...E0,P0])},[]),d0=n$({apiUrl:H||"",apiKey:G,provider:x0,voice:qX,onTranscript:J$,onError:b}),[VX,H$]=t.useState(new Map),rX=t.useCallback((r)=>{H$((P0)=>{let E0=new Map(P0),H0=!1;for(let s of r){if(!s.widgets)continue;for(let z0 of s.widgets){if(!z0.persistent)continue;let Z0=E0.get(z0.id);if(!Z0||Z0!==z0)E0.set(z0.id,z0),H0=!0}}return H0?E0:P0})},[]);t.useEffect(()=>{rX(KX)},[KX,rX]);let nX=t.useMemo(()=>Array.from(VX.values()),[VX]),xX=t.useMemo(()=>new Set(VX.keys()),[VX]),QX=t.useRef(null);t.useImperativeHandle(dX,()=>({sendMessage:async(r)=>{if(QX.current)await QX.current(r)},sendSystemMessage:async(r)=>{if(QX.current)await QX.current(r,void 0,!0)},getMessages:()=>KX,clearMessages:()=>t0([])}),[KX]);let IX=t.useMemo(()=>{if(!N)return z;let r=S?DZ(L):LZ(L);return z?`${z}
|
|
37
|
+
${r}`:r},[z,N,L,S]);t.useEffect(()=>{if(H||G)kX.configure({...H&&{apiUrl:H},...G&&{apiKey:G}})},[H,G]),t.useEffect(()=>{if(Q)R?.(Q)},[Q,R]),t.useEffect(()=>{hX(V)},[V]),t.useEffect(()=>{let r=(P0)=>{let E0=P0.target;if(TX&&!E0.closest(".settings-menu-container"))$X(!1)};return document.addEventListener("mousedown",r),()=>document.removeEventListener("mousedown",r)},[TX]);let P$=(r)=>{if(Z$(r),O?.(r),r==="command")b0("idle"),UX(null),c0(null)},BQ=WX==="chat"?"Type a message...":"Enter your command...",E$=t.useCallback((r)=>{if(T?.(r),r.type==="submit"&&r.payload?.formData){let P0=r.payload.formData,E0=[];for(let[H0,s]of Object.entries(P0))if(Array.isArray(s)&&s.length>0&&s[0]instanceof File){let z0=s.map((Z0)=>Z0.name).join(", ");E0.push(`${H0}: ${z0}`)}else if(s!==""&&s!==!1&&s!=null)E0.push(`${H0}: ${s}`);if(E0.length>0&&QX.current){let H0=[];for(let s of Object.values(P0))if(Array.isArray(s)&&s.length>0&&s[0]instanceof File)H0.push(...s);QX.current(E0.join(`
|
|
38
|
+
`),H0.length>0?H0:void 0)}}},[T]),G$=async(r,P0,E0)=>{let H0=P0&&P0.length>0,s=H0?P0.map((z0)=>({name:z0.name,type:z0.type,size:z0.size,preview:z0.type.startsWith("image/")?URL.createObjectURL(z0):void 0})):[];if(!E0){let z0={id:`msg-${Date.now()}`,role:"user",content:r,timestamp:new Date,metadata:H0?{attachments:s}:void 0};t0((Z0)=>[...Z0,z0]),j?.(z0)}r0(!0);try{let z0=await y$(r,P0);if(J){let Z0=await ZZ(1000);t0((V0)=>[...V0,Z0])}else{let Z0=[],V0="",Y0=[],_X=p0,gX={},q$={},WQ=`msg-${Date.now()}-res`,BX=()=>{let u=[...Z0];if(V0){let m=u[u.length-1];if(m&&m.type==="text")m.content=V0;else u.push({type:"text",content:V0})}t0((m)=>{let _0=m[m.length-1];if(_0&&_0.role==="assistant")return[...m.slice(0,-1),{..._0,content:V0,widgets:Y0.length>0?Y0:void 0,metadata:{..._0.metadata,content_segments:u,isStreaming:!0}}];else return[...m,{id:WQ,role:"assistant",content:V0,widgets:Y0.length>0?Y0:void 0,timestamp:new Date,metadata:{content_segments:u,isStreaming:!0}}]})};await kX.chatStream({agent_id:$,message:z0,stream:!0,...p0&&{thread_id:p0},...IX&&{system:IX}},(u)=>{switch(u.type){case"thread_id":if(u.thread_id){if(_X=u.thread_id,!p0)CX(u.thread_id),R?.(u.thread_id)}break;case"request_id":if(u.request_id)h0(u.request_id);break;case"content":case"token":if(u.content){if(!V0)V0=u.content.trimStart();else V0+=u.content;if(V0)BX()}break;case"tool_call":if(u.tool_id&&u.tool_name){let m=u.tool_display_name||u.tool_name;if(V0)Z0.push({type:"text",content:V0.trimEnd()}),V0="";Z0.push({type:"tool",id:u.tool_id,name:m,status:"preparing"}),gX[u.tool_id]="",MX(m),F?.(u.tool_name,u.tool_id),BX()}break;case"tool_input_delta":if(u.tool_id&&u.content){let m=u.tool_id;if(gX[m]===void 0)gX[m]="";gX[m]+=u.content;let _0=Z0.find((uX)=>uX.type==="tool"&&uX.id===m);if(_0){if(_0.isReceiving=!0,_0.inputLength=gX[m].length,BX(),q$[m])clearTimeout(q$[m]);q$[m]=setTimeout(()=>{if(_0.status==="preparing")_0.isReceiving=!1,BX()},150)}}break;case"tool_use":if(u.tool_id){let m=Z0.find((_0)=>_0.type==="tool"&&_0.id===u.tool_id);if(m&&m.status==="preparing")m.status="running",m.isReceiving=!1,BX()}break;case"tool_stream":if(u.tool_id){let m=Z0.find((_0)=>_0.type==="tool"&&_0.id===u.tool_id);if(m){if(u.event==="chunk"&&u.content){if(m.pendingReset)m.streamOutput="",m.pendingReset=!1;m.streamOutput=(m.streamOutput||"")+u.content,BX()}else if(u.event==="log"||u.event==="progress")m.pendingReset=!0}}break;case"tool_result":if(u.tool_id){let m=Z0.find((_0)=>_0.type==="tool"&&_0.id===u.tool_id);if(m)m.result=u.content,m.status="completed",m.isReceiving=!1,A0?.(m.name,u.content);MX(null),BX()}break;case"widget":if(u.widget)Y0.push(u.widget),BX();break;case"error":throw Error(u.message||"Stream error")}},(u)=>{if(V0=V0.trimEnd(),V0){let m=Z0[Z0.length-1];if(m&&m.type==="text")m.content=V0;else Z0.push({type:"text",content:V0})}if(t0((m)=>{let _0=m[m.length-1];if(_0&&_0.role==="assistant")return[...m.slice(0,-1),{..._0,content:V0||"Response received",widgets:Y0.length>0?Y0:void 0,metadata:{thread_id:u,content_segments:Z0,isStreaming:!1}}];return m}),u&&u!==p0)CX(u),R?.(u);r0(!1),h0(null),MX(null)},(u)=>{let m={id:`msg-${Date.now()}-error`,role:"assistant",content:`Error: ${u.message}`,timestamp:new Date,metadata:{error:!0}};t0((_0)=>{let uX=_0[_0.length-1];if(uX&&uX.id.includes("streaming"))return[..._0.slice(0,-1),m];return[..._0,m]}),r0(!1),h0(null),MX(null),b?.(u)})}}catch(z0){let Z0={id:`msg-${Date.now()}-error`,role:"assistant",content:z0 instanceof Error?`Error: ${z0.message}`:"An error occurred",timestamp:new Date,metadata:{error:!0}};t0((V0)=>[...V0,Z0]),b?.(z0 instanceof Error?z0:Error("Unknown error"))}finally{r0(!1)}};QX.current=G$;let M$=async(r,P0)=>{let E0=r||x;if(!E0.trim()&&(!P0||P0.length===0)){c0(Error("Please enter a command")),b0("error");return}if(oX&&fX!=="plan-pending"){if(b0("loading"),c0(null),X0(""),J)setTimeout(()=>{let H0=`1. Analyze the request: "${E0}"
|
|
39
|
+
2. Process the data
|
|
40
|
+
3. Generate response
|
|
41
|
+
4. Return results`;l0(H0),XX(E0),b0("plan-pending")},800);else try{let s=IX?`${IX}
|
|
42
|
+
|
|
43
|
+
CRITICAL PLANNING MODE: You are ONLY creating a plan. Write a numbered list of steps describing what WOULD be done. DO NOT execute anything.`:"CRITICAL PLANNING MODE: You are ONLY creating a plan. Write a numbered list of steps describing what WOULD be done. DO NOT execute anything.",z0=await kX.chat({agent_id:$,message:E0,stream:!1,system:s});l0(z0.message),XX(E0),b0("plan-pending")}catch(H0){let s=H0 instanceof Error?H0:Error("Failed to generate plan");c0(s),b0("error"),b?.(s)}return}b0("loading"),c0(null),n0(0),k0(""),X0("");try{if(J)if(B){let H0="";JZ(E0,(s)=>{if(s.type==="token"&&s.content){H0+=s.content,k0(H0);let z0=Math.min(Math.round(H0.length/10),90);n0(z0)}},(s)=>{let z0={success:!0,data:{summary:H0,thread_id:s},message:H0||"Command executed successfully"};UX(z0),b0("success"),n0(100),P?.(z0)},(s)=>{c0(s),b0("error"),b?.(s)})}else{await new Promise((s)=>setTimeout(s,1500));let H0={success:!0,data:{summary:`Executed: ${E0}`},message:"Command executed successfully"};UX(H0),b0("success"),n0(100),P?.(H0)}else{let s=IX?`${IX}
|
|
44
|
+
|
|
45
|
+
CRITICAL COMMAND MODE: Maximum 10 words per response. Execute the command immediately. Make reasonable assumptions based on context. Use sensible defaults for missing details. DO NOT ask questions unless something is truly impossible without user input (e.g., missing required password). State what you're doing or the result. Examples: "Analyzing customer data from last quarter..." or "Created 5 new database entries successfully" or "Search complete: found 12 matching results". NO greetings, NO filler words, NO clarification requests. Action/result only.`:`CRITICAL COMMAND MODE: Maximum 10 words per response. Execute the command immediately. Make reasonable assumptions based on context. Use sensible defaults for missing details. DO NOT ask questions unless something is truly impossible without user input (e.g., missing required password). State what you're doing or the result. Examples: "Analyzing customer data from last quarter..." or "Created 5 new database entries successfully" or "Search complete: found 12 matching results". NO greetings, NO filler words, NO clarification requests. Action/result only.`,z0=P0&&P0.length>0?await y$(E0,P0):E0;if(B){let Z0="",V0="";await kX.chatStream({agent_id:$,message:z0,stream:!0,...p0&&{thread_id:p0},system:s},(Y0)=>{if((Y0.type==="token"||Y0.type==="content")&&Y0.content){Z0+=Y0.content,k0(Z0),v0(null);let _X=Math.min(Math.round(Z0.length/10),90);n0(_X)}else if(Y0.type==="tool_call"&&Y0.tool_name){let _X=Y0.tool_display_name||Y0.tool_name;V0=Y0.tool_name,v0(_X),F?.(Y0.tool_name,Y0.tool_id||""),Z0="",k0("")}else if(Y0.type==="tool_result")A0?.(V0,Y0.content),v0(null);else if(Y0.type==="thread_id"&&Y0.thread_id){if(!p0)CX(Y0.thread_id),R?.(Y0.thread_id)}else if(Y0.type==="request_id"&&Y0.request_id)h0(Y0.request_id)},(Y0)=>{let _X={success:!0,data:{summary:Z0,thread_id:Y0},message:Z0||"Command executed successfully"};UX(_X),b0("success"),n0(100),h0(null),P?.(_X)},(Y0)=>{c0(Y0),b0("error"),h0(null),b?.(Y0)})}else{let Z0=await kX.chat({agent_id:$,message:z0,stream:!1,...p0&&{thread_id:p0},system:s}),V0={success:!0,data:{summary:Z0.message,thread_id:Z0.thread_id},widgets:Z0.widgets,message:Z0.message};UX(V0),b0("success"),n0(100),P?.(V0)}}}catch(H0){let s=H0 instanceof Error?H0:Error("Unknown error");c0(s),b0("error"),b?.(s)}},LQ=()=>{b0("idle"),UX(null),c0(null),n0(0),X0(""),l0(""),XX(""),k0(""),v0(null)},DQ=()=>{let r=NX;l0(""),XX("");let P0=`Execute this plan now:
|
|
46
|
+
|
|
47
|
+
${r}`;M$(P0)},FQ=()=>{X0(e0),l0(""),XX(""),b0("idle")},T$=async()=>{if(f0&&$)try{await kX.cancelRequest($,f0)}catch(r){console.error("Failed to cancel request:",r)}if(r0(!1),fX==="loading")b0("idle"),k0(""),v0(null),n0(0);h0(null)},qz=Y==="compact";return w0.jsxs("div",{className:q0("apteva-chat flex flex-col h-full",$0!=="default"&&`apteva-chat-${$0}`,y0==="dark"&&"apteva-force-dark",y0==="light"&&"apteva-force-light",FX),children:[y&&WX==="chat"&&w0.jsx("div",{className:"apteva-chat-header px-4 py-3",children:w0.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"0.5rem"},children:[a&&w0.jsx("button",{onClick:a,className:"apteva-chat-back",style:{flexShrink:0},children:w0.jsx("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:w0.jsx("path",{d:"M10 12L6 8l4-4"})})}),w0.jsxs("div",{children:[w0.jsx("div",{className:"apteva-chat-title",children:g}),w0.jsx("div",{className:q0("apteva-chat-status",d0.state==="active"?"apteva-chat-status-voice":d0.state==="connecting"?"apteva-chat-status-thinking":OX?jX?"apteva-chat-status-tool":"apteva-chat-status-thinking":"apteva-chat-status-ready"),children:d0.state==="active"?"Voice active":d0.state==="connecting"?"Connecting voice...":OX?jX?`Using ${jX}...`:"Thinking...":"Ready"})]})]})}),WX==="chat"&&w0.jsxs(w0.Fragment,{children:[nX.length>0&&w0.jsx(nZ,{widgets:nX,onAction:E$}),w0.jsx(dZ,{messages:KX,onAction:E$,welcomeTitle:M,welcomeSubtitle:h,welcomeIcon:i,suggestedPrompts:o,welcomeVariant:e,chatVariant:$0,onPromptClick:(r)=>G$(r),enableWidgets:N,onWidgetRender:Q0,persistentWidgetIds:xX,toolCallStyle:q}),w0.jsx(iZ,{onSendMessage:G$,placeholder:S0||BQ,disabled:OX,isLoading:OX,onStop:T$,onFileUpload:f,onSwitchMode:K?()=>P$("command"):void 0,speechToText:K0,enableVoice:O0,voiceState:d0.state,voicePartialTranscript:d0.partialTranscript,voiceDuration:d0.duration,onVoiceStart:d0.start,onVoiceStop:d0.stop})]}),WX==="command"&&w0.jsx("div",{className:"w-full",children:w0.jsx(oZ,{onExecute:(r,P0)=>{X0(r),M$(r,P0)},state:fX,response:iX?.data?.summary||iX?.message,error:z$?.message,plan:NX,streamedContent:B0,toolName:F0,onApprove:DQ,onReject:FQ,onReset:LQ,onStop:T$,onExpand:K?()=>P$("chat"):void 0,placeholder:S0||"Enter your command..."})}),w0.jsx("style",{dangerouslySetInnerHTML:{__html:`
|
|
48
|
+
@keyframes pulse-border {
|
|
49
|
+
0%, 100% { border-color: rgb(59, 130, 246); }
|
|
50
|
+
50% { border-color: rgb(147, 197, 253); }
|
|
51
|
+
}
|
|
52
|
+
.animate-pulse-border {
|
|
53
|
+
animation: pulse-border 2s ease-in-out infinite;
|
|
54
|
+
}
|
|
55
|
+
.apteva-composer {
|
|
56
|
+
border-radius: var(--apteva-border-radius, 1rem) !important;
|
|
57
|
+
}
|
|
58
|
+
`}})]})});function Xz(X){let $=Math.floor(X/60),Q=X%60;return`${$.toString().padStart(2,"0")}:${Q.toString().padStart(2,"0")}`}function $z({agentName:X="Agent",agentAvatarUrl:$,state:Q,duration:Z}){let z=X.charAt(0).toUpperCase();return ZX.jsxs("div",{className:"apteva-call-agent",children:[ZX.jsxs("div",{className:"apteva-call-avatar-wrap",children:[$?ZX.jsx("img",{src:$,alt:X,className:"apteva-call-avatar"}):ZX.jsx("div",{className:"apteva-call-avatar-placeholder",children:z}),Q==="active"&&ZX.jsx("div",{className:"apteva-call-pulse-ring"})]}),ZX.jsx("div",{className:"apteva-call-agent-name",children:X}),ZX.jsxs("div",{className:`apteva-call-status ${Q==="active"?"apteva-call-status-active":Q==="connecting"?"apteva-call-status-connecting":Q==="error"?"apteva-call-status-error":""}`,children:[Q==="idle"&&"Ready",Q==="connecting"&&"Connecting...",Q==="active"&&"Connected",Q==="error"&&"Error"]}),(Q==="active"||Q==="connecting")&&ZX.jsx("div",{className:"apteva-call-duration",children:Xz(Z)})]})}function Qz({entries:X,partialTranscript:$}){let Q=$$.useRef(null);if($$.useEffect(()=>{if(Q.current)Q.current.scrollTop=Q.current.scrollHeight},[X.length,$]),X.length===0&&!$)return null;return GX.jsxs("div",{className:"apteva-call-transcript",ref:Q,children:[X.map((Z)=>GX.jsxs("div",{className:"apteva-call-transcript-entry",children:[GX.jsx("span",{className:`apteva-call-transcript-role apteva-call-transcript-role-${Z.role}`,children:Z.role==="user"?"You":Z.role==="assistant"?"Agent":"System"}),GX.jsx("span",{className:"apteva-call-transcript-content",children:Z.content})]},Z.id)),$&&GX.jsxs("div",{className:"apteva-call-transcript-entry",children:[GX.jsx("span",{className:"apteva-call-transcript-role apteva-call-transcript-role-user",children:"You"}),GX.jsx("span",{className:"apteva-call-transcript-partial",children:$})]})]})}function Zz({state:X,muted:$,mediaMode:Q,onStart:Z,onEnd:z,onToggleMute:H}){return N0.jsx("div",{className:"apteva-call-controls",children:X==="active"||X==="connecting"?N0.jsxs(N0.Fragment,{children:[N0.jsx("button",{onClick:H,className:`apteva-call-btn apteva-call-btn-mute ${$?"apteva-call-btn-mute-active":""}`,title:$?"Unmute":"Mute",children:$?N0.jsxs("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[N0.jsx("line",{x1:"1",y1:"1",x2:"23",y2:"23"}),N0.jsx("path",{d:"M9 9v3a3 3 0 0 0 5.12 2.12M15 9.34V4a3 3 0 0 0-5.94-.6"}),N0.jsx("path",{d:"M17 16.95A7 7 0 0 1 5 12v-2m14 0v2c0 .76-.13 1.49-.35 2.17"}),N0.jsx("line",{x1:"12",y1:"19",x2:"12",y2:"23"}),N0.jsx("line",{x1:"8",y1:"23",x2:"16",y2:"23"})]}):N0.jsxs("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[N0.jsx("path",{d:"M12 1a3 3 0 0 0-3 3v8a3 3 0 0 0 6 0V4a3 3 0 0 0-3-3z"}),N0.jsx("path",{d:"M19 10v2a7 7 0 0 1-14 0v-2"}),N0.jsx("line",{x1:"12",y1:"19",x2:"12",y2:"23"}),N0.jsx("line",{x1:"8",y1:"23",x2:"16",y2:"23"})]})}),N0.jsx("button",{onClick:z,className:"apteva-call-btn apteva-call-btn-end",title:"End call",children:N0.jsxs("svg",{width:"22",height:"22",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[N0.jsx("path",{d:"M10.68 13.31a16 16 0 0 0 3.41 2.6l1.27-1.27a2 2 0 0 1 2.11-.45 12.84 12.84 0 0 0 2.81.7 2 2 0 0 1 1.72 2v3a2 2 0 0 1-2.18 2 19.79 19.79 0 0 1-8.63-3.07 19.5 19.5 0 0 1-6-6 19.79 19.79 0 0 1-3.07-8.67A2 2 0 0 1 4.11 2h3a2 2 0 0 1 2 1.72 12.84 12.84 0 0 0 .7 2.81 2 2 0 0 1-.45 2.11L8.09 9.91"}),N0.jsx("line",{x1:"23",y1:"1",x2:"1",y2:"23"})]})})]}):N0.jsx("button",{onClick:Z,className:"apteva-call-btn apteva-call-btn-start",title:"Start call",disabled:X==="error",children:N0.jsx("svg",{width:"22",height:"22",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:N0.jsx("path",{d:"M22 16.92v3a2 2 0 0 1-2.18 2 19.79 19.79 0 0 1-8.63-3.07 19.5 19.5 0 0 1-6-6 19.79 19.79 0 0 1-3.07-8.67A2 2 0 0 1 4.11 2h3a2 2 0 0 1 2 1.72 12.84 12.84 0 0 0 .7 2.81 2 2 0 0 1-.45 2.11L8.09 9.91a16 16 0 0 0 6 6l1.27-1.27a2 2 0 0 1 2.11-.45 12.84 12.84 0 0 0 2.81.7A2 2 0 0 1 22 16.92z"})})})})}function Nz({agentName:X="Agent",agentAvatarUrl:$,apiUrl:Q,apiKey:Z,voiceProvider:z,voiceId:H,mediaMode:G="voice",autoStart:J=!1,showTranscript:U=!1,maxTranscriptEntries:K=50,onCallStart:O,onCallEnd:Y,onTranscript:V,onError:_,onMuteChange:B,variant:A="default",theme:I,className:M}){let[h,i]=m0.useState([]),o=m0.useRef("idle"),e=m0.useRef(0),R=m0.useRef(!1),j=m0.useCallback((P)=>{i((b)=>{let F=[...b,P];return F.length>K?F.slice(F.length-K):F}),V?.(P)},[K,V]),T=n$({apiUrl:Q,apiKey:Z,provider:z,voice:H,onTranscript:j,onError:_});m0.useEffect(()=>{e.current=T.duration},[T.duration]),m0.useEffect(()=>{let P=o.current;if(P!=="active"&&T.state==="active")O?.();if(P==="active"&&T.state==="idle")Y?.({duration:e.current,transcripts:h});o.current=T.state},[T.state,O,Y,h]),m0.useEffect(()=>{if(J&&!R.current&&T.state==="idle")R.current=!0,T.start()},[J,T.state,T.start]),m0.useEffect(()=>{B?.(T.muted)},[T.muted,B]);let f=["apteva-call",A!=="default"&&`apteva-call-${A}`,I==="dark"&&"apteva-force-dark",I==="light"&&"apteva-force-light",M].filter(Boolean).join(" ");return JX.jsxs("div",{className:f,children:[JX.jsx($z,{agentName:X,agentAvatarUrl:$,state:T.state,duration:T.duration}),G==="video"&&JX.jsx("div",{className:"apteva-call-video-area",children:JX.jsx("svg",{width:"32",height:"32",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",opacity:"0.4",children:JX.jsx("path",{d:"M16.24 7.76a6 6 0 0 1 0 8.49m-8.48-.01a6 6 0 0 1 0-8.49m11.31-2.82a10 10 0 0 1 0 14.14m-14.14 0a10 10 0 0 1 0-14.14"})})}),U&&JX.jsx(Qz,{entries:h,partialTranscript:T.partialTranscript}),JX.jsx(Zz,{state:T.state,muted:T.muted,mediaMode:G,onStart:T.start,onEnd:T.stop,onToggleMute:T.toggleMute})]})}var p=k(qQ(),1);function Iz({agents:X,onNavigate:$}){let{theme:Q}=_Q(),{authFetch:Z}=UQ(),{currentProjectId:z}=VQ(),{events:H,statusChangeCounter:G}=KQ(),[J,U]=R0.useState([]),[K,O]=R0.useState(null),[Y,V]=R0.useState(null),[_,B]=R0.useState([]),[A,I]=R0.useState(!0),[M,h]=R0.useState(!1),[i,o]=R0.useState([]),[e,R]=R0.useState(!1),[j,T]=R0.useState(0),f=R0.useMemo(()=>{if(z===null)return X;if(z==="unassigned")return X.filter((L)=>!L.projectId);return X.filter((L)=>L.projectId===z)},[X,z]),P=R0.useMemo(()=>f.filter((L)=>L.status==="running"),[f]),b=R0.useMemo(()=>new Set(f.map((L)=>L.id)),[f]),F=R0.useCallback(async()=>{try{let L=z?`?project_id=${encodeURIComponent(z)}`:"",[S,Q0]=await Promise.all([Z(`/api/threads${L}`).catch(()=>null),Z(`/api/telemetry/events?type=thread_activity&limit=100${L?`&${L}`:""}`).catch(()=>null)]);if(S?.ok){let K0=await S.json();U(K0.threads||[])}if(Q0?.ok){let K0=await Q0.json();o(K0.events||[])}}catch(L){console.error("Failed to fetch threads:",L)}finally{I(!1)}},[Z,z]);R0.useEffect(()=>{F()},[F,G]),R0.useEffect(()=>{let L=setInterval(F,15000);return()=>clearInterval(L)},[F]);let A0=R0.useCallback(async(L)=>{V(null),h(!0),O(L);try{let S=await Z(`/api/agents/${L.agent_id}/threads/${L.id}/messages`);if(S.ok){let Q0=await S.json();B(p$(Q0.messages||[]))}else B([])}catch{B([])}h(!1)},[Z]),$0=(L)=>{O(null),B([]),V(L),T((S)=>S+1),R(!1)},y0=R0.useMemo(()=>{let L=H.filter((K0)=>K0.type==="thread_activity"&&!K0.data?.parent_id),S=new Set(L.map((K0)=>K0.id)),Q0=[...L];for(let K0 of i)if(!S.has(K0.id)&&!K0.data?.parent_id)Q0.push(K0),S.add(K0.id);return Q0.filter((K0)=>b.has(K0.agent_id)).sort((K0,O0)=>new Date(O0.timestamp).getTime()-new Date(K0.timestamp).getTime()).slice(0,100)},[H,i,b]),S0=R0.useMemo(()=>{let L=new Map;for(let S of y0){let Q0=S.thread_id||S.data?.thread_id;if(Q0){if(!L.has(Q0))L.set(Q0,[]);L.get(Q0).push(S)}}return L},[y0]),y=P.length,g=K?.agent_id||Y?.id,a=K?.agent_name||Y?.name,q=K?.id,N=K?`${K.agent_id}-${K.id}`:Y?`new-${Y.id}-${j}`:null;return p.jsxDEV("div",{className:"flex-1 flex flex-col overflow-hidden",children:[p.jsxDEV("div",{className:"px-6 pt-6 pb-4 shrink-0",children:p.jsxDEV("div",{className:"flex items-center justify-between",children:[p.jsxDEV("h1",{className:"text-xl font-semibold",children:"Threads"},void 0,!1,void 0,this),p.jsxDEV("span",{className:"text-sm text-[var(--color-text-muted)]",children:[J.length," threads from ",y," running agents"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),p.jsxDEV("div",{className:"flex-1 flex min-h-0 overflow-hidden",children:[p.jsxDEV("div",{className:"w-1/4 min-w-[260px] max-w-[360px] flex flex-col overflow-hidden",children:[p.jsxDEV("div",{className:"p-2 shrink-0",children:p.jsxDEV("div",{className:"relative",children:[p.jsxDEV("button",{onClick:()=>R(!e),disabled:P.length===0,className:"w-full flex items-center justify-center gap-2 px-3 py-2 btn bg-[var(--color-accent-10)] text-[var(--color-accent)] text-sm font-medium hover:bg-[var(--color-accent-20)] transition disabled:opacity-30 disabled:cursor-not-allowed",children:[p.jsxDEV("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:p.jsxDEV("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 4v16m8-8H4"},void 0,!1,void 0,this)},void 0,!1,void 0,this),"New conversation"]},void 0,!0,void 0,this),e&&p.jsxDEV(p.Fragment,{children:[p.jsxDEV("div",{className:"fixed inset-0 z-40",onClick:()=>R(!1)},void 0,!1,void 0,this),p.jsxDEV("div",{className:"absolute top-full left-0 right-0 mt-1 bg-[var(--color-surface)] card shadow-xl z-50 max-h-60 overflow-auto",children:P.map((L)=>p.jsxDEV("button",{onClick:()=>$0(L),className:"w-full text-left px-3 py-2.5 hover:bg-[var(--color-surface-raised)] transition",children:[p.jsxDEV("p",{className:"text-sm font-medium truncate",children:L.name},void 0,!1,void 0,this),p.jsxDEV("p",{className:"text-[10px] text-[var(--color-text-faint)]",children:[L.provider," · ",L.model]},void 0,!0,void 0,this)]},L.id,!0,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),p.jsxDEV("div",{className:"flex-1 overflow-auto px-2 pb-2",children:A?p.jsxDEV("div",{className:"p-6 text-center text-[var(--color-text-faint)] text-sm",children:"Loading threads..."},void 0,!1,void 0,this):J.length===0?p.jsxDEV("div",{className:"p-6 text-center text-[var(--color-text-faint)] text-sm",children:[p.jsxDEV("p",{children:"No threads yet"},void 0,!1,void 0,this),p.jsxDEV("p",{className:"mt-1 text-[var(--color-text-faint)]",children:"Start a conversation or wait for agents"},void 0,!1,void 0,this)]},void 0,!0,void 0,this):p.jsxDEV("div",{className:"space-y-0.5",children:J.map((L)=>p.jsxDEV(Hz,{thread:L,selected:K?.id===L.id&&K?.agent_id===L.agent_id,activities:S0.get(L.id)||[],onSelect:()=>A0(L)},`${L.agent_id}-${L.id}`,!1,void 0,this))},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),p.jsxDEV("div",{className:"flex-1 flex flex-col min-h-0 overflow-hidden",children:g&&N?M?p.jsxDEV("div",{className:"flex-1 flex items-center justify-center text-[var(--color-text-muted)]",children:"Loading messages..."},void 0,!1,void 0,this):p.jsxDEV(a$,{agentId:"default",apiUrl:`/api/agents/${g}`,threadId:q,initialMessages:_,placeholder:`Message ${a}...`,headerTitle:a,variant:"terminal",theme:Q.id,showHeader:!0},N,!1,void 0,this):p.jsxDEV("div",{className:"flex-1 flex items-center justify-center",children:p.jsxDEV("div",{className:"text-center text-[var(--color-text-faint)]",children:[p.jsxDEV("svg",{className:"w-12 h-12 mx-auto mb-3 text-[var(--color-border-light)]",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:p.jsxDEV("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M8 12h.01M12 12h.01M16 12h.01M21 12c0 4.418-4.03 8-9 8a9.863 9.863 0 01-4.255-.949L3 20l1.395-3.72C3.512 15.042 3 13.574 3 12c0-4.418 4.03-8 9-8s9 3.582 9 8z"},void 0,!1,void 0,this)},void 0,!1,void 0,this),p.jsxDEV("p",{className:"text-sm",children:"Select a thread or start a new conversation"},void 0,!1,void 0,this),p.jsxDEV("p",{className:"text-xs text-[var(--color-text-faint)] mt-1",children:"Chat with any running agent"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function Hz({thread:X,selected:$,activities:Q,onSelect:Z}){let{isActive:z}=OQ(X.agent_id),G=Q[0]?.data?.activity;return p.jsxDEV("button",{onClick:Z,className:`w-full text-left px-3 py-2.5 rounded-lg transition ${$?"bg-[var(--color-accent-10)]":"hover:bg-[var(--color-bg-secondary)]"}`,children:[p.jsxDEV("div",{className:"flex items-center justify-between gap-2 mb-1",children:[p.jsxDEV("span",{className:"text-sm font-medium truncate",children:X.title||`Thread ${X.id.slice(0,8)}`},void 0,!1,void 0,this),p.jsxDEV("span",{className:"text-[10px] text-[var(--color-text-faint)] shrink-0",children:Gz(X.updated_at)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),p.jsxDEV("div",{className:"flex items-center gap-1.5",children:[p.jsxDEV("span",{className:`w-1.5 h-1.5 rounded-full shrink-0 ${z?"bg-green-400 animate-pulse":"bg-[var(--color-scrollbar)]"}`},void 0,!1,void 0,this),p.jsxDEV("span",{className:"text-[11px] text-[var(--color-accent)]",children:X.agent_name},void 0,!1,void 0,this),X.message_count!=null&&p.jsxDEV(p.Fragment,{children:[p.jsxDEV("span",{className:"text-[var(--color-border-light)]",children:"·"},void 0,!1,void 0,this),p.jsxDEV("span",{className:"text-[10px] text-[var(--color-text-faint)]",children:[X.message_count," msgs"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),G&&p.jsxDEV("p",{className:"text-[11px] text-[var(--color-text-faint)] truncate mt-1",children:G},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function Gz(X){let $=Math.floor((Date.now()-new Date(X).getTime())/1000);if($<5)return"just now";if($<60)return`${$}s ago`;let Q=Math.floor($/60);if(Q<60)return`${Q}m ago`;let Z=Math.floor(Q/60);if(Z<24)return`${Z}h ago`;return`${Math.floor(Z/24)}d ago`}
|
|
59
|
+
export{p$ as Q,a$ as R,Nz as S,Iz as T};
|
|
60
|
+
|
|
61
|
+
//# debugId=123AF347E43CE79B64756E2164756E21
|