@action-llama/action-llama 0.26.2 → 0.26.4
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/build-info.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"gitSha":"
|
|
1
|
+
{"gitSha":"ad8da87e"}
|
|
@@ -10,4 +10,4 @@ Error generating stack: `+e.message+`
|
|
|
10
10
|
|
|
11
11
|
Please change the parent <Route path="${e}"> to <Route path="${e===`/`?`*`:`${e}/*`}">.`)}let u=it(),d;if(t){let e=typeof t==`string`?re(t):t;T(c===`/`||e.pathname?.startsWith(c),`When overriding the location using \`<Routes location>\` or \`useRoutes(routes, location)\`, the location pathname must begin with the portion of the URL pathname that was matched by all parent routes. The current pathname base is "${c}" but pathname "${e.pathname}" was given in the \`location\` prop.`),d=e}else d=u;let f=d.pathname||`/`,p=f;if(c!==`/`){let e=c.replace(/^\//,``).split(`/`);p=`/`+f.replace(/^\//,``).split(`/`).slice(e.length).join(`/`)}let m=oe(e,{pathname:p});E(l||m!=null,`No routes matched location "${d.pathname}${d.search}${d.hash}" `),E(m==null||m[m.length-1].route.element!==void 0||m[m.length-1].route.Component!==void 0||m[m.length-1].route.lazy!==void 0,`Matched leaf route at location "${d.pathname}${d.search}${d.hash}" does not have an element or Component. This means it will render an <Outlet /> with a null value by default resulting in an "empty" page.`);let h=xt(m&&m.map(e=>Object.assign({},e,{params:Object.assign({},o,e.params),pathname:Ae([c,r.encodeLocation?r.encodeLocation(e.pathname.replace(/%/g,`%25`).replace(/\?/g,`%3F`).replace(/#/g,`%23`)).pathname:e.pathname]),pathnameBase:e.pathnameBase===`/`?c:Ae([c,r.encodeLocation?r.encodeLocation(e.pathnameBase.replace(/%/g,`%25`).replace(/\?/g,`%3F`).replace(/#/g,`%23`)).pathname:e.pathnameBase])})),i,n);return t&&h?x.createElement(Je.Provider,{value:{location:{pathname:`/`,search:``,hash:``,state:null,key:`default`,unstable_mask:void 0,...d},navigationType:`POP`}},h):h}function ht(){let e=At(),t=Fe(e)?`${e.status} ${e.statusText}`:e instanceof Error?e.message:JSON.stringify(e),n=e instanceof Error?e.stack:null,r=`rgba(200,200,200, 0.5)`,i={padding:`0.5rem`,backgroundColor:r},a={padding:`2px 4px`,backgroundColor:r},o=null;return console.error(`Error handled by React Router default ErrorBoundary:`,e),o=x.createElement(x.Fragment,null,x.createElement(`p`,null,`💿 Hey developer 👋`),x.createElement(`p`,null,`You can provide a way better UX than this when your app throws errors by providing your own `,x.createElement(`code`,{style:a},`ErrorBoundary`),` or`,` `,x.createElement(`code`,{style:a},`errorElement`),` prop on your route.`)),x.createElement(x.Fragment,null,x.createElement(`h2`,null,`Unexpected Application Error!`),x.createElement(`h3`,{style:{fontStyle:`italic`}},t),n?x.createElement(`pre`,{style:i},n):null,o)}var gt=x.createElement(ht,null),_t=class extends x.Component{constructor(e){super(e),this.state={location:e.location,revalidation:e.revalidation,error:e.error}}static getDerivedStateFromError(e){return{error:e}}static getDerivedStateFromProps(e,t){return t.location!==e.location||t.revalidation!==`idle`&&e.revalidation===`idle`?{error:e.error,location:e.location,revalidation:e.revalidation}:{error:e.error===void 0?t.error:e.error,location:t.location,revalidation:e.revalidation||t.revalidation}}componentDidCatch(e,t){this.props.onError?this.props.onError(e,t):console.error(`React Router caught the following error during render`,e)}render(){let e=this.state.error;if(this.context&&typeof e==`object`&&e&&`digest`in e&&typeof e.digest==`string`){let t=tt(e.digest);t&&(e=t)}let t=e===void 0?this.props.children:x.createElement(Ye.Provider,{value:this.props.routeContext},x.createElement(Xe.Provider,{value:e,children:this.props.component}));return this.context?x.createElement(yt,{error:e},t):t}};_t.contextType=Ue;var vt=new WeakMap;function yt({children:e,error:t}){let{basename:n}=x.useContext(qe);if(typeof t==`object`&&t&&`digest`in t&&typeof t.digest==`string`){let e=et(t.digest);if(e){let r=vt.get(t);if(r)throw r;let i=Re(e.location,n);if(Le&&!vt.get(t))if(i.isExternal||e.reloadDocument)window.location.href=i.absoluteURL||i.to;else{let n=Promise.resolve().then(()=>window.__reactRouterDataRouter.navigate(i.to,{replace:e.replace}));throw vt.set(t,n),n}return x.createElement(`meta`,{httpEquiv:`refresh`,content:`0;url=${i.absoluteURL||i.to}`})}}return e}function bt({routeContext:e,match:t,children:n}){let r=x.useContext(Ve);return r&&r.static&&r.staticContext&&(t.route.errorElement||t.route.ErrorBoundary)&&(r.staticContext._deepestRenderedBoundaryId=t.route.id),x.createElement(Ye.Provider,{value:e},n)}function xt(e,t=[],n){let r=n?.state;if(e==null){if(!r)return null;if(r.errors)e=r.matches;else if(t.length===0&&!r.initialized&&r.matches.length>0)e=r.matches;else return null}let i=e,a=r?.errors;if(a!=null){let e=i.findIndex(e=>e.route.id&&a?.[e.route.id]!==void 0);T(e>=0,`Could not find a matching route for errors on route IDs: ${Object.keys(a).join(`,`)}`),i=i.slice(0,Math.min(i.length,e+1))}let o=!1,s=-1;if(n&&r){o=r.renderFallback;for(let e=0;e<i.length;e++){let t=i[e];if((t.route.HydrateFallback||t.route.hydrateFallbackElement)&&(s=e),t.route.id){let{loaderData:e,errors:a}=r,c=t.route.loader&&!e.hasOwnProperty(t.route.id)&&(!a||a[t.route.id]===void 0);if(t.route.lazy||c){n.isStatic&&(o=!0),i=s>=0?i.slice(0,s+1):[i[0]];break}}}}let c=n?.onError,l=r&&c?(e,t)=>{c(e,{location:r.location,params:r.matches?.[0]?.params??{},unstable_pattern:Ie(r.matches),errorInfo:t})}:void 0;return i.reduceRight((e,n,c)=>{let u,d=!1,f=null,p=null;r&&(u=a&&n.route.id?a[n.route.id]:void 0,f=n.route.errorElement||gt,o&&(s<0&&c===0?(Nt(`route-fallback`,!1,"No `HydrateFallback` element provided to render during initial hydration"),d=!0,p=null):s===c&&(d=!0,p=n.route.hydrateFallbackElement||null)));let m=t.concat(i.slice(0,c+1)),h=()=>{let t;return t=u?f:d?p:n.route.Component?x.createElement(n.route.Component,null):n.route.element?n.route.element:e,x.createElement(bt,{match:n,routeContext:{outlet:e,matches:m,isDataRoute:r!=null},children:t})};return r&&(n.route.ErrorBoundary||n.route.errorElement||c===0)?x.createElement(_t,{location:r.location,revalidation:r.revalidation,component:f,error:u,children:h(),routeContext:{outlet:null,matches:m,isDataRoute:!0},onError:l}):h()},null)}function St(e){return`${e} must be used within a data router. See https://reactrouter.com/en/main/routers/picking-a-router.`}function Ct(e){let t=x.useContext(Ve);return T(t,St(e)),t}function wt(e){let t=x.useContext(He);return T(t,St(e)),t}function Tt(e){let t=x.useContext(Ye);return T(t,St(e)),t}function Et(e){let t=Tt(e),n=t.matches[t.matches.length-1];return T(n.route.id,`${e} can only be used on routes that contain a unique "id"`),n.route.id}function Dt(){return Et(`useRouteId`)}function Ot(){return wt(`useNavigation`).navigation}function kt(){let{matches:e,loaderData:t}=wt(`useMatches`);return x.useMemo(()=>e.map(e=>O(e,t)),[e,t])}function At(){let e=x.useContext(Xe),t=wt(`useRouteError`),n=Et(`useRouteError`);return e===void 0?t.errors?.[n]:e}function jt(){let{router:e}=Ct(`useNavigate`),t=Et(`useNavigate`),n=x.useRef(!1);return ot(()=>{n.current=!0}),x.useCallback(async(r,i={})=>{E(n.current,at),n.current&&(typeof r==`number`?await e.navigate(r):await e.navigate(r,{fromRouteId:t,...i}))},[e,t])}var Mt={};function Nt(e,t,n){!t&&!Mt[e]&&(Mt[e]=!0,E(!1,n))}x.useOptimistic,x.memo(Pt);function Pt({routes:e,future:t,state:n,isStatic:r,onError:i}){return mt(e,void 0,{state:n,isStatic:r,onError:i,future:t})}function Ft({to:e,replace:t,state:n,relative:r}){T(rt(),`<Navigate> may be used only in the context of a <Router> component.`);let{static:i}=x.useContext(qe);E(!i,`<Navigate> must not be used on the initial render in a <StaticRouter>. This is a no-op, but you should modify your code so the <Navigate> is only ever rendered in response to some user interaction or state change.`);let{matches:a}=x.useContext(Ye),{pathname:o}=it(),s=st(),c=ke(e,Oe(a),o,r===`path`),l=JSON.stringify(c);return x.useEffect(()=>{s(JSON.parse(l),{replace:t,state:n,relative:r})},[s,l,r,t,n]),null}function It(e){return ut(e.context)}function j(e){T(!1,`A <Route> is only ever to be used as the child of <Routes> element, never rendered directly. Please wrap your <Route> in a <Routes>.`)}function Lt({basename:e=`/`,children:t=null,location:n,navigationType:r=`POP`,navigator:i,static:a=!1,unstable_useTransitions:o}){T(!rt(),`You cannot render a <Router> inside another <Router>. You should never have more than one in your app.`);let s=e.replace(/^\/*/,`/`),c=x.useMemo(()=>({basename:s,navigator:i,static:a,unstable_useTransitions:o,future:{}}),[s,i,a,o]);typeof n==`string`&&(n=re(n));let{pathname:l=`/`,search:u=``,hash:d=``,state:f=null,key:p=`default`,unstable_mask:m}=n,h=x.useMemo(()=>{let e=Se(l,s);return e==null?null:{location:{pathname:e,search:u,hash:d,state:f,key:p,unstable_mask:m},navigationType:r}},[s,l,u,d,f,p,r,m]);return E(h!=null,`<Router basename="${s}"> is not able to match the URL "${l}${u}${d}" because it does not start with the basename, so the <Router> won't render anything.`),h==null?null:x.createElement(qe.Provider,{value:c},x.createElement(Je.Provider,{children:t,value:h}))}function Rt({children:e,location:t}){return pt(zt(e),t)}function zt(e,t=[]){let n=[];return x.Children.forEach(e,(e,r)=>{if(!x.isValidElement(e))return;let i=[...t,r];if(e.type===x.Fragment){n.push.apply(n,zt(e.props.children,i));return}T(e.type===j,`[${typeof e.type==`string`?e.type:e.type.name}] is not a <Route> component. All component children of <Routes> must be a <Route> or <React.Fragment>`),T(!e.props.index||!e.props.children,`An index route cannot have child routes.`);let a={id:e.props.id||i.join(`-`),caseSensitive:e.props.caseSensitive,element:e.props.element,Component:e.props.Component,index:e.props.index,path:e.props.path,middleware:e.props.middleware,loader:e.props.loader,action:e.props.action,hydrateFallbackElement:e.props.hydrateFallbackElement,HydrateFallback:e.props.HydrateFallback,errorElement:e.props.errorElement,ErrorBoundary:e.props.ErrorBoundary,hasErrorBoundary:e.props.hasErrorBoundary===!0||e.props.ErrorBoundary!=null||e.props.errorElement!=null,shouldRevalidate:e.props.shouldRevalidate,handle:e.props.handle,lazy:e.props.lazy};e.props.children&&(a.children=zt(e.props.children,i)),n.push(a)}),n}var Bt=`get`,Vt=`application/x-www-form-urlencoded`;function Ht(e){return typeof HTMLElement<`u`&&e instanceof HTMLElement}function Ut(e){return Ht(e)&&e.tagName.toLowerCase()===`button`}function Wt(e){return Ht(e)&&e.tagName.toLowerCase()===`form`}function Gt(e){return Ht(e)&&e.tagName.toLowerCase()===`input`}function Kt(e){return!!(e.metaKey||e.altKey||e.ctrlKey||e.shiftKey)}function qt(e,t){return e.button===0&&(!t||t===`_self`)&&!Kt(e)}function Jt(e=``){return new URLSearchParams(typeof e==`string`||Array.isArray(e)||e instanceof URLSearchParams?e:Object.keys(e).reduce((t,n)=>{let r=e[n];return t.concat(Array.isArray(r)?r.map(e=>[n,e]):[[n,r]])},[]))}function Yt(e,t){let n=Jt(e);return t&&t.forEach((e,r)=>{n.has(r)||t.getAll(r).forEach(e=>{n.append(r,e)})}),n}var Xt=null;function Zt(){if(Xt===null)try{new FormData(document.createElement(`form`),0),Xt=!1}catch{Xt=!0}return Xt}var Qt=new Set([`application/x-www-form-urlencoded`,`multipart/form-data`,`text/plain`]);function $t(e){return e!=null&&!Qt.has(e)?(E(!1,`"${e}" is not a valid \`encType\` for \`<Form>\`/\`<fetcher.Form>\` and will default to "${Vt}"`),null):e}function en(e,t){let n,r,i,a,o;if(Wt(e)){let o=e.getAttribute(`action`);r=o?Se(o,t):null,n=e.getAttribute(`method`)||Bt,i=$t(e.getAttribute(`enctype`))||Vt,a=new FormData(e)}else if(Ut(e)||Gt(e)&&(e.type===`submit`||e.type===`image`)){let o=e.form;if(o==null)throw Error(`Cannot submit a <button> or <input type="submit"> without a <form>`);let s=e.getAttribute(`formaction`)||o.getAttribute(`action`);if(r=s?Se(s,t):null,n=e.getAttribute(`formmethod`)||o.getAttribute(`method`)||Bt,i=$t(e.getAttribute(`formenctype`))||$t(o.getAttribute(`enctype`))||Vt,a=new FormData(o,e),!Zt()){let{name:t,type:n,value:r}=e;if(n===`image`){let e=t?`${t}.`:``;a.append(`${e}x`,`0`),a.append(`${e}y`,`0`)}else t&&a.append(t,r)}}else if(Ht(e))throw Error(`Cannot submit element that is not <form>, <button>, or <input type="submit|image">`);else n=Bt,r=null,i=Vt,o=e;return a&&i===`text/plain`&&(o=a,a=void 0),{action:r,method:n.toLowerCase(),encType:i,formData:a,body:o}}Object.getOwnPropertyNames(Object.prototype).sort().join(`\0`);var tn={"&":`\\u0026`,">":`\\u003e`,"<":`\\u003c`,"\u2028":`\\u2028`,"\u2029":`\\u2029`},nn=/[&><\u2028\u2029]/g;function rn(e){return e.replace(nn,e=>tn[e])}function an(e,t){if(e===!1||e==null)throw Error(t)}function on(e,t,n,r){let i=typeof e==`string`?new URL(e,typeof window>`u`?`server://singlefetch/`:window.location.origin):e;return n?i.pathname.endsWith(`/`)?i.pathname=`${i.pathname}_.${r}`:i.pathname=`${i.pathname}.${r}`:i.pathname===`/`?i.pathname=`_root.${r}`:t&&Se(i.pathname,t)===`/`?i.pathname=`${t.replace(/\/$/,``)}/_root.${r}`:i.pathname=`${i.pathname.replace(/\/$/,``)}.${r}`,i}async function sn(e,t){if(e.id in t)return t[e.id];try{let n=await b(()=>import(e.module),[]);return t[e.id]=n,n}catch(t){return console.error(`Error loading route module \`${e.module}\`, reloading page...`),console.error(t),window.__reactRouterContext&&window.__reactRouterContext.isSpaMode,window.location.reload(),new Promise(()=>{})}}function cn(e){return e!=null&&typeof e.page==`string`}function ln(e){return e==null?!1:e.href==null?e.rel===`preload`&&typeof e.imageSrcSet==`string`&&typeof e.imageSizes==`string`:typeof e.rel==`string`&&typeof e.href==`string`}async function un(e,t,n){return hn((await Promise.all(e.map(async e=>{let r=t.routes[e.route.id];if(r){let e=await sn(r,n);return e.links?e.links():[]}return[]}))).flat(1).filter(ln).filter(e=>e.rel===`stylesheet`||e.rel===`preload`).map(e=>e.rel===`stylesheet`?{...e,rel:`prefetch`,as:`style`}:{...e,rel:`prefetch`}))}function dn(e,t,n,r,i,a){let o=(e,t)=>n[t]?e.route.id!==n[t].route.id:!0,s=(e,t)=>n[t].pathname!==e.pathname||n[t].route.path?.endsWith(`*`)&&n[t].params[`*`]!==e.params[`*`];return a===`assets`?t.filter((e,t)=>o(e,t)||s(e,t)):a===`data`?t.filter((t,a)=>{let c=r.routes[t.route.id];if(!c||!c.hasLoader)return!1;if(o(t,a)||s(t,a))return!0;if(t.route.shouldRevalidate){let r=t.route.shouldRevalidate({currentUrl:new URL(i.pathname+i.search+i.hash,window.origin),currentParams:n[0]?.params||{},nextUrl:new URL(e,window.origin),nextParams:t.params,defaultShouldRevalidate:!0});if(typeof r==`boolean`)return r}return!0}):[]}function fn(e,t,{includeHydrateFallback:n}={}){return pn(e.map(e=>{let r=t.routes[e.route.id];if(!r)return[];let i=[r.module];return r.clientActionModule&&(i=i.concat(r.clientActionModule)),r.clientLoaderModule&&(i=i.concat(r.clientLoaderModule)),n&&r.hydrateFallbackModule&&(i=i.concat(r.hydrateFallbackModule)),r.imports&&(i=i.concat(r.imports)),i}).flat(1))}function pn(e){return[...new Set(e)]}function mn(e){let t={},n=Object.keys(e).sort();for(let r of n)t[r]=e[r];return t}function hn(e,t){let n=new Set,r=new Set(t);return e.reduce((e,i)=>{if(t&&!cn(i)&&i.as===`script`&&i.href&&r.has(i.href))return e;let a=JSON.stringify(mn(i));return n.has(a)||(n.add(a),e.push({key:a,link:i})),e},[])}function gn(){let e=x.useContext(Ve);return an(e,`You must render this element inside a <DataRouterContext.Provider> element`),e}function _n(){let e=x.useContext(He);return an(e,`You must render this element inside a <DataRouterStateContext.Provider> element`),e}var vn=x.createContext(void 0);vn.displayName=`FrameworkContext`;function yn(){let e=x.useContext(vn);return an(e,`You must render this element inside a <HydratedRouter> element`),e}function bn(e,t){let n=x.useContext(vn),[r,i]=x.useState(!1),[a,o]=x.useState(!1),{onFocus:s,onBlur:c,onMouseEnter:l,onMouseLeave:u,onTouchStart:d}=t,f=x.useRef(null);x.useEffect(()=>{if(e===`render`&&o(!0),e===`viewport`){let e=new IntersectionObserver(e=>{e.forEach(e=>{o(e.isIntersecting)})},{threshold:.5});return f.current&&e.observe(f.current),()=>{e.disconnect()}}},[e]),x.useEffect(()=>{if(r){let e=setTimeout(()=>{o(!0)},100);return()=>{clearTimeout(e)}}},[r]);let p=()=>{i(!0)},m=()=>{i(!1),o(!1)};return n?e===`intent`?[a,f,{onFocus:xn(s,p),onBlur:xn(c,m),onMouseEnter:xn(l,p),onMouseLeave:xn(u,m),onTouchStart:xn(d,p)}]:[a,f,{}]:[!1,f,{}]}function xn(e,t){return n=>{e&&e(n),n.defaultPrevented||t(n)}}function Sn({page:e,...t}){let{router:n}=gn(),r=x.useMemo(()=>oe(n.routes,e,n.basename),[n.routes,e,n.basename]);return r?x.createElement(wn,{page:e,matches:r,...t}):null}function Cn(e){let{manifest:t,routeModules:n}=yn(),[r,i]=x.useState([]);return x.useEffect(()=>{let r=!1;return un(e,t,n).then(e=>{r||i(e)}),()=>{r=!0}},[e,t,n]),r}function wn({page:e,matches:t,...n}){let r=it(),{future:i,manifest:a,routeModules:o}=yn(),{basename:s}=gn(),{loaderData:c,matches:l}=_n(),u=x.useMemo(()=>dn(e,t,l,a,r,`data`),[e,t,l,a,r]),d=x.useMemo(()=>dn(e,t,l,a,r,`assets`),[e,t,l,a,r]),f=x.useMemo(()=>{if(e===r.pathname+r.search+r.hash)return[];let n=new Set,l=!1;if(t.forEach(e=>{let t=a.routes[e.route.id];!t||!t.hasLoader||(!u.some(t=>t.route.id===e.route.id)&&e.route.id in c&&o[e.route.id]?.shouldRevalidate||t.hasClientLoader?l=!0:n.add(e.route.id))}),n.size===0)return[];let d=on(e,s,i.unstable_trailingSlashAwareDataRequests,`data`);return l&&n.size>0&&d.searchParams.set(`_routes`,t.filter(e=>n.has(e.route.id)).map(e=>e.route.id).join(`,`)),[d.pathname+d.search]},[s,i.unstable_trailingSlashAwareDataRequests,c,r,a,u,t,e,o]),p=x.useMemo(()=>fn(d,a),[d,a]),m=Cn(d);return x.createElement(x.Fragment,null,f.map(e=>x.createElement(`link`,{key:e,rel:`prefetch`,as:`fetch`,href:e,...n})),p.map(e=>x.createElement(`link`,{key:e,rel:`modulepreload`,href:e,...n})),m.map(({key:e,link:t})=>x.createElement(`link`,{key:e,nonce:n.nonce,...t,crossOrigin:t.crossOrigin??n.crossOrigin})))}function Tn(...e){return t=>{e.forEach(e=>{typeof e==`function`?e(t):e!=null&&(e.current=t)})}}var En=typeof window<`u`&&window.document!==void 0&&window.document.createElement!==void 0;try{En&&(window.__reactRouterVersion=`7.13.2`)}catch{}function Dn({basename:e,children:t,unstable_useTransitions:n,window:r}){let i=x.useRef();i.current??=w({window:r,v5Compat:!0});let a=i.current,[o,s]=x.useState({action:a.action,location:a.location}),c=x.useCallback(e=>{n===!1?s(e):x.startTransition(()=>s(e))},[n]);return x.useLayoutEffect(()=>a.listen(c),[a,c]),x.createElement(Lt,{basename:e,children:t,location:o.location,navigationType:o.action,navigator:a,unstable_useTransitions:n})}function On({basename:e,children:t,history:n,unstable_useTransitions:r}){let[i,a]=x.useState({action:n.action,location:n.location}),o=x.useCallback(e=>{r===!1?a(e):x.startTransition(()=>a(e))},[r]);return x.useLayoutEffect(()=>n.listen(o),[n,o]),x.createElement(Lt,{basename:e,children:t,location:i.location,navigationType:i.action,navigator:n,unstable_useTransitions:r})}On.displayName=`unstable_HistoryRouter`;var kn=/^(?:[a-z][a-z0-9+.-]*:|\/\/)/i,M=x.forwardRef(function({onClick:e,discover:t=`render`,prefetch:n=`none`,relative:r,reloadDocument:i,replace:a,unstable_mask:o,state:s,target:c,to:l,preventScrollReset:u,viewTransition:d,unstable_defaultShouldRevalidate:f,...p},m){let{basename:h,navigator:g,unstable_useTransitions:_}=x.useContext(qe),v=typeof l==`string`&&kn.test(l),y=Re(l,h);l=y.to;let b=nt(l,{relative:r}),S=it(),C=null;if(o){let e=ke(o,[],S.unstable_mask?S.unstable_mask.pathname:`/`,!0);h!==`/`&&(e.pathname=e.pathname===`/`?h:Ae([h,e.pathname])),C=g.createHref(e)}let[w,T,E]=bn(n,p),ee=In(l,{replace:a,unstable_mask:o,state:s,target:c,preventScrollReset:u,relative:r,viewTransition:d,unstable_defaultShouldRevalidate:f,unstable_useTransitions:_});function D(t){e&&e(t),t.defaultPrevented||ee(t)}let te=!(y.isExternal||i),ne=x.createElement(`a`,{...p,...E,href:(te?C:void 0)||y.absoluteURL||b,onClick:te?D:e,ref:Tn(m,T),target:c,"data-discover":!v&&t===`render`?`true`:void 0});return w&&!v?x.createElement(x.Fragment,null,ne,x.createElement(Sn,{page:b})):ne});M.displayName=`Link`;var An=x.forwardRef(function({"aria-current":e=`page`,caseSensitive:t=!1,className:n=``,end:r=!1,style:i,to:a,viewTransition:o,children:s,...c},l){let u=ft(a,{relative:c.relative}),d=it(),f=x.useContext(He),{navigator:p,basename:m}=x.useContext(qe),h=f!=null&&qn(u)&&o===!0,g=p.encodeLocation?p.encodeLocation(u).pathname:u.pathname,_=d.pathname,v=f&&f.navigation&&f.navigation.location?f.navigation.location.pathname:null;t||(_=_.toLowerCase(),v=v?v.toLowerCase():null,g=g.toLowerCase()),v&&m&&(v=Se(v,m)||v);let y=g!==`/`&&g.endsWith(`/`)?g.length-1:g.length,b=_===g||!r&&_.startsWith(g)&&_.charAt(y)===`/`,S=v!=null&&(v===g||!r&&v.startsWith(g)&&v.charAt(g.length)===`/`),C={isActive:b,isPending:S,isTransitioning:h},w=b?e:void 0,T;T=typeof n==`function`?n(C):[n,b?`active`:null,S?`pending`:null,h?`transitioning`:null].filter(Boolean).join(` `);let E=typeof i==`function`?i(C):i;return x.createElement(M,{...c,"aria-current":w,className:T,ref:l,style:E,to:a,viewTransition:o},typeof s==`function`?s(C):s)});An.displayName=`NavLink`;var jn=x.forwardRef(({discover:e=`render`,fetcherKey:t,navigate:n,reloadDocument:r,replace:i,state:a,method:o=Bt,action:s,onSubmit:c,relative:l,preventScrollReset:u,viewTransition:d,unstable_defaultShouldRevalidate:f,...p},m)=>{let{unstable_useTransitions:h}=x.useContext(qe),g=Bn(),_=Vn(s,{relative:l}),v=o.toLowerCase()===`get`?`get`:`post`,y=typeof s==`string`&&kn.test(s);return x.createElement(`form`,{ref:m,method:v,action:_,onSubmit:r?c:e=>{if(c&&c(e),e.defaultPrevented)return;e.preventDefault();let r=e.nativeEvent.submitter,s=r?.getAttribute(`formmethod`)||o,p=()=>g(r||e.currentTarget,{fetcherKey:t,method:s,navigate:n,replace:i,state:a,relative:l,preventScrollReset:u,viewTransition:d,unstable_defaultShouldRevalidate:f});h&&n!==!1?x.startTransition(()=>p()):p()},...p,"data-discover":!y&&e===`render`?`true`:void 0})});jn.displayName=`Form`;function Mn({getKey:e,storageKey:t,...n}){let r=x.useContext(vn),{basename:i}=x.useContext(qe),a=it(),o=kt();Gn({getKey:e,storageKey:t});let s=x.useMemo(()=>{if(!r||!e)return null;let t=Wn(a,o,i,e);return t===a.key?null:t},[]);if(!r||r.isSpaMode)return null;let c=((e,t)=>{if(!window.history.state||!window.history.state.key){let e=Math.random().toString(32).slice(2);window.history.replaceState({key:e},``)}try{let n=JSON.parse(sessionStorage.getItem(e)||`{}`)[t||window.history.state.key];typeof n==`number`&&window.scrollTo(0,n)}catch(t){console.error(t),sessionStorage.removeItem(e)}}).toString();return x.createElement(`script`,{...n,suppressHydrationWarning:!0,dangerouslySetInnerHTML:{__html:`(${c})(${rn(JSON.stringify(t||Hn))}, ${rn(JSON.stringify(s))})`}})}Mn.displayName=`ScrollRestoration`;function Nn(e){return`${e} must be used within a data router. See https://reactrouter.com/en/main/routers/picking-a-router.`}function Pn(e){let t=x.useContext(Ve);return T(t,Nn(e)),t}function Fn(e){let t=x.useContext(He);return T(t,Nn(e)),t}function In(e,{target:t,replace:n,unstable_mask:r,state:i,preventScrollReset:a,relative:o,viewTransition:s,unstable_defaultShouldRevalidate:c,unstable_useTransitions:l}={}){let u=st(),d=it(),f=ft(e,{relative:o});return x.useCallback(p=>{if(qt(p,t)){p.preventDefault();let t=n===void 0?ne(d)===ne(f):n,m=()=>u(e,{replace:t,unstable_mask:r,state:i,preventScrollReset:a,relative:o,viewTransition:s,unstable_defaultShouldRevalidate:c});l?x.startTransition(()=>m()):m()}},[d,u,f,n,r,i,t,e,a,o,s,c,l])}function Ln(e){E(typeof URLSearchParams<`u`,"You cannot use the `useSearchParams` hook in a browser that does not support the URLSearchParams API. If you need to support Internet Explorer 11, we recommend you load a polyfill such as https://github.com/ungap/url-search-params.");let t=x.useRef(Jt(e)),n=x.useRef(!1),r=it(),i=x.useMemo(()=>Yt(r.search,n.current?null:t.current),[r.search]),a=st();return[i,x.useCallback((e,t)=>{let r=Jt(typeof e==`function`?e(new URLSearchParams(i)):e);n.current=!0,a(`?`+r,t)},[a,i])]}var Rn=0,zn=()=>`__${String(++Rn)}__`;function Bn(){let{router:e}=Pn(`useSubmit`),{basename:t}=x.useContext(qe),n=Dt(),r=e.fetch,i=e.navigate;return x.useCallback(async(e,a={})=>{let{action:o,method:s,encType:c,formData:l,body:u}=en(e,t);a.navigate===!1?await r(a.fetcherKey||zn(),n,a.action||o,{unstable_defaultShouldRevalidate:a.unstable_defaultShouldRevalidate,preventScrollReset:a.preventScrollReset,formData:l,body:u,formMethod:a.method||s,formEncType:a.encType||c,flushSync:a.flushSync}):await i(a.action||o,{unstable_defaultShouldRevalidate:a.unstable_defaultShouldRevalidate,preventScrollReset:a.preventScrollReset,formData:l,body:u,formMethod:a.method||s,formEncType:a.encType||c,replace:a.replace,state:a.state,fromRouteId:n,flushSync:a.flushSync,viewTransition:a.viewTransition})},[r,i,t,n])}function Vn(e,{relative:t}={}){let{basename:n}=x.useContext(qe),r=x.useContext(Ye);T(r,`useFormAction must be used inside a RouteContext`);let[i]=r.matches.slice(-1),a={...ft(e||`.`,{relative:t})},o=it();if(e==null){a.search=o.search;let e=new URLSearchParams(a.search),t=e.getAll(`index`);if(t.some(e=>e===``)){e.delete(`index`),t.filter(e=>e).forEach(t=>e.append(`index`,t));let n=e.toString();a.search=n?`?${n}`:``}}return(!e||e===`.`)&&i.route.index&&(a.search=a.search?a.search.replace(/^\?/,`?index&`):`?index`),n!==`/`&&(a.pathname=a.pathname===`/`?n:Ae([n,a.pathname])),ne(a)}var Hn=`react-router-scroll-positions`,Un={};function Wn(e,t,n,r){let i=null;return r&&(i=r(n===`/`?e:{...e,pathname:Se(e.pathname,n)||e.pathname},t)),i??=e.key,i}function Gn({getKey:e,storageKey:t}={}){let{router:n}=Pn(`useScrollRestoration`),{restoreScrollPosition:r,preventScrollReset:i}=Fn(`useScrollRestoration`),{basename:a}=x.useContext(qe),o=it(),s=kt(),c=Ot();x.useEffect(()=>(window.history.scrollRestoration=`manual`,()=>{window.history.scrollRestoration=`auto`}),[]),Kn(x.useCallback(()=>{if(c.state===`idle`){let t=Wn(o,s,a,e);Un[t]=window.scrollY}try{sessionStorage.setItem(t||Hn,JSON.stringify(Un))}catch(e){E(!1,`Failed to save scroll positions in sessionStorage, <ScrollRestoration /> will not work properly (${e}).`)}window.history.scrollRestoration=`auto`},[c.state,e,a,o,s,t])),typeof document<`u`&&(x.useLayoutEffect(()=>{try{let e=sessionStorage.getItem(t||Hn);e&&(Un=JSON.parse(e))}catch{}},[t]),x.useLayoutEffect(()=>{let t=n?.enableScrollRestoration(Un,()=>window.scrollY,e?(t,n)=>Wn(t,n,a,e):void 0);return()=>t&&t()},[n,a,e]),x.useLayoutEffect(()=>{if(r!==!1){if(typeof r==`number`){window.scrollTo(0,r);return}try{if(o.hash){let e=document.getElementById(decodeURIComponent(o.hash.slice(1)));if(e){e.scrollIntoView();return}}}catch{E(!1,`"${o.hash.slice(1)}" is not a decodable element ID. The view will not scroll to it.`)}i!==!0&&window.scrollTo(0,0)}},[o,r,i]))}function Kn(e,t){let{capture:n}=t||{};x.useEffect(()=>{let t=n==null?void 0:{capture:n};return window.addEventListener(`pagehide`,e,t),()=>{window.removeEventListener(`pagehide`,e,t)}},[e,n])}function qn(e,{relative:t}={}){let n=x.useContext(We);T(n!=null,"`useViewTransitionState` must be used within `react-router-dom`'s `RouterProvider`. Did you accidentally import `RouterProvider` from `react-router`?");let{basename:r}=Pn(`useViewTransitionState`),i=ft(e,{relative:t});if(!n.isTransitioning)return!1;let a=Se(n.currentLocation.pathname,r)||n.currentLocation.pathname,o=Se(n.nextLocation.pathname,r)||n.nextLocation.pathname;return ye(i.pathname,o)!=null||ye(i.pathname,a)!=null}var Jn=g(),Yn=``;async function Xn(e,t){for(let n=0;;n++){let r=await fetch(`${Yn}${e}`,{credentials:`same-origin`,...t});if(r.status===401)throw window.location.href=`/login`,Error(`Unauthorized`);if(r.status===429&&n<2){let e=r.headers.get(`Retry-After`),t=(e?parseFloat(e)*1e3:1e3)*2**n;await new Promise(e=>setTimeout(e,t));continue}if(!r.ok){let e=await r.text(),t=e||`HTTP ${r.status}`;try{let n=JSON.parse(e);typeof n.error==`string`?t=n.error:typeof n.message==`string`&&(t=n.message)}catch{}throw Error(t)}return r.json()}}function Zn(e,t){return Xn(e,{method:`POST`,headers:t?{"Content-Type":`application/json`}:void 0,body:t?JSON.stringify(t):void 0})}function Qn(e,t){return Xn(`/api/dashboard/agents/${encodeURIComponent(e)}`,t?{signal:t}:void 0)}function $n(e,t){return Xn(`/api/dashboard/agents/${encodeURIComponent(e)}/skill`,t?{signal:t}:void 0)}function er(e){return Xn(`/api/dashboard/config`,e?{signal:e}:void 0)}function tr(e,t){return Xn(`/api/stats/webhooks/${encodeURIComponent(e)}`,t?{signal:t}:void 0)}function nr(e){return Zn(`/api/webhooks/${encodeURIComponent(e)}/replay`)}function rr(e,t,n,r,i,a){let o=`/api/stats/activity?limit=${e}&offset=${t}`;return n&&(o+=`&agent=${encodeURIComponent(n)}`),r&&(o+=`&triggerType=${encodeURIComponent(r)}`),i&&i.length>0&&(o+=`&status=${i.map(encodeURIComponent).join(`,`)}`),Xn(o,a?{signal:a}:void 0)}function ir(e,t){return Xn(`/api/dashboard/triggers/${encodeURIComponent(e)}`,t?{signal:t}:void 0)}function ar(e,t,n){return Xn(`/api/dashboard/agents/${encodeURIComponent(e)}/instances/${encodeURIComponent(t)}`,n?{signal:n}:void 0)}function or(e){return Xn(`/dashboard/api/locks`,e?{signal:e}:void 0)}function sr(e,t,n,r){let i=new URLSearchParams(n).toString();return Xn(`/api/logs/agents/${encodeURIComponent(e)}/${encodeURIComponent(t)}${i?`?${i}`:``}`,r?{signal:r}:void 0)}function cr(e,t){return Zn(`/control/trigger/${encodeURIComponent(e)}`,t?{prompt:t}:void 0)}function lr(e){return Zn(`/control/agents/${encodeURIComponent(e)}/kill`)}function ur(e){return Zn(`/control/kill/${encodeURIComponent(e)}`)}function dr(e){return Zn(`/control/agents/${encodeURIComponent(e)}/enable`)}function fr(e){return Zn(`/control/agents/${encodeURIComponent(e)}/disable`)}function pr(){return Zn(`/control/pause`)}function mr(){return Zn(`/control/resume`)}function hr(e){return Zn(`/control/project/scale`,{scale:e})}function gr(e,t){return Zn(`/control/agents/${encodeURIComponent(e)}/scale`,{scale:t})}async function _r(e){return(await fetch(`/api/auth/login`,{method:`POST`,credentials:`same-origin`,headers:{"Content-Type":`application/json`},body:JSON.stringify({key:e})})).ok}async function vr(){await fetch(`/api/auth/logout`,{method:`POST`,credentials:`same-origin`})}function yr(e,t,n){return Xn(`/api/logs/agents/${encodeURIComponent(e)}/${encodeURIComponent(t)}/summarize`,{method:`POST`,signal:n})}var br=class{es=null;backoff=1e3;maxBackoff=3e4;reconnectTimer=null;destroyed=!1;callbacks;constructor(e){this.callbacks=e}connect(){if(this.destroyed)return;this.cleanup(),this.callbacks.onConnectionChange(`connecting`);let e=new EventSource(`/dashboard/api/status-stream`);this.es=e,e.onopen=()=>{this.backoff=1e3,this.callbacks.onConnectionChange(`connected`)},e.onerror=()=>{this.callbacks.onConnectionChange(`disconnected`),this.cleanup(),this.scheduleReconnect()},e.onmessage=e=>{try{let t=JSON.parse(e.data);this.callbacks.onMessage(t)}catch{}}}disconnect(){this.destroyed=!0,this.cleanup(),this.reconnectTimer&&=(clearTimeout(this.reconnectTimer),null)}cleanup(){this.es&&=(this.es.onopen=null,this.es.onerror=null,this.es.onmessage=null,this.es.close(),null)}scheduleReconnect(){this.destroyed||(this.reconnectTimer=setTimeout(()=>{this.reconnectTimer=null,this.connect()},this.backoff),this.backoff=Math.min(this.backoff*2,this.maxBackoff))}},xr=new Set;function Sr(e,t,n,r=500){let i={types:e,agent:t,callback:n,debounceMs:r,timer:null};return xr.add(i),()=>{i.timer&&clearTimeout(i.timer),xr.delete(i)}}function Cr(e){for(let t of xr)e.some(e=>t.types.includes(e.type)&&(t.agent===void 0||e.agent===t.agent))&&!t.timer&&(t.timer=setTimeout(()=>{t.timer=null,t.callback()},t.debounceMs))}var wr={agents:[],schedulerInfo:null,recentLogs:[],instances:[],connected:!1},Tr=new Set,Er=null,Dr=[];function Or(){for(let e of Tr)e()}function kr(e){return Tr.add(e),()=>{Tr.delete(e)}}function Ar(){return wr}function jr(){return Dr}function Mr(){return Er?()=>{}:(Er=new br({onMessage:e=>{wr={agents:e.agents??wr.agents,schedulerInfo:e.schedulerInfo===void 0?wr.schedulerInfo:e.schedulerInfo,recentLogs:e.recentLogs??wr.recentLogs,instances:e.instances??wr.instances,connected:wr.connected},Dr=e.invalidated??[],Or(),e.invalidated&&e.invalidated.length>0&&Cr(e.invalidated)},onConnectionChange:e=>{let t=e===`connected`;t!==wr.connected&&(wr={...wr,connected:t},Or())}}),Er.connect(),()=>{Er?.disconnect(),Er=null})}function Nr(){return(0,x.useSyncExternalStore)(kr,()=>Ar().agents)}function Pr(){return(0,x.useSyncExternalStore)(kr,()=>Ar().schedulerInfo)}function Fr(){return(0,x.useSyncExternalStore)(kr,()=>Ar().recentLogs)}function Ir(){return(0,x.useSyncExternalStore)(kr,()=>Ar().instances)}function Lr(){return(0,x.useSyncExternalStore)(kr,()=>Ar().connected)}var Rr=o((e=>{var t=Symbol.for(`react.transitional.element`),n=Symbol.for(`react.fragment`);function r(e,n,r){var i=null;if(r!==void 0&&(i=``+r),n.key!==void 0&&(i=``+n.key),`key`in n)for(var a in r={},n)a!==`key`&&(r[a]=n[a]);else r=n;return n=r.ref,{$$typeof:t,type:e,key:i,ref:n===void 0?null:n,props:r}}e.Fragment=n,e.jsx=r,e.jsxs=r})),N=o(((e,t)=>{t.exports=Rr()}))();function zr({children:e}){return(0,x.useEffect)(()=>Mr(),[]),(0,N.jsx)(N.Fragment,{children:e})}function Br(){return{agents:Nr(),schedulerInfo:Pr(),recentLogs:Fr(),instances:Ir(),connected:Lr(),invalidated:jr()}}function Vr(){return localStorage.getItem(`al-theme`)||`dark`}function Hr(e){document.documentElement.classList.toggle(`dark`,e===`dark`),localStorage.setItem(`al-theme`,e)}function Ur(){let e=st(),t=it(),n=Lr(),[r,i]=(0,x.useState)(Vr);(0,x.useEffect)(()=>{Hr(r)},[r]);let a=(0,x.useCallback)(()=>{i(e=>e===`dark`?`light`:`dark`)},[]),o=(0,x.useCallback)(async()=>{await vr(),e(`/login`)},[e]),s=t.pathname===`/dashboard/config`,c=t.pathname===`/dashboard`||t.pathname.startsWith(`/dashboard/agents`),l=t.pathname===`/activity`,u=t.pathname===`/stats`;return(0,N.jsx)(`header`,{className:`border-b border-slate-200 dark:border-slate-800 px-4 sm:px-6 py-3`,children:(0,N.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,N.jsxs)(`div`,{className:`flex items-center gap-4`,children:[(0,N.jsxs)(M,{to:`/dashboard`,className:`text-lg font-bold text-slate-900 dark:text-white hover:text-blue-600 dark:hover:text-blue-400 transition-colors`,children:[(0,N.jsx)(`span`,{className:`hidden sm:inline`,children:`Action Llama`}),(0,N.jsx)(`span`,{className:`sm:hidden`,children:`AL`})]}),(0,N.jsxs)(M,{to:`/dashboard`,className:`flex items-center gap-1.5 text-sm transition-colors ${c?`text-blue-600 dark:text-blue-400`:`text-slate-500 hover:text-slate-700 dark:hover:text-slate-300`}`,children:[(0,N.jsxs)(`svg`,{className:`w-5 h-5 sm:w-4 sm:h-4`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:[(0,N.jsx)(`rect`,{x:`3`,y:`4`,width:`18`,height:`12`,rx:`2`,strokeWidth:2,strokeLinecap:`round`,strokeLinejoin:`round`}),(0,N.jsx)(`circle`,{cx:`9`,cy:`10`,r:`1.5`,fill:`currentColor`,stroke:`none`}),(0,N.jsx)(`circle`,{cx:`15`,cy:`10`,r:`1.5`,fill:`currentColor`,stroke:`none`}),(0,N.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M8 20h8M12 16v4`})]}),(0,N.jsx)(`span`,{className:`hidden sm:inline`,children:`Agents`})]}),(0,N.jsxs)(M,{to:`/activity`,className:`flex items-center gap-1.5 text-sm transition-colors ${l?`text-blue-600 dark:text-blue-400`:`text-slate-500 hover:text-slate-700 dark:hover:text-slate-300`}`,children:[(0,N.jsx)(`svg`,{className:`w-5 h-5 sm:w-4 sm:h-4`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,N.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M13 10V3L4 14h7v7l9-11h-7z`})}),(0,N.jsx)(`span`,{className:`hidden sm:inline`,children:`Activity`})]}),(0,N.jsxs)(M,{to:`/stats`,className:`flex items-center gap-1.5 text-sm transition-colors ${u?`text-blue-600 dark:text-blue-400`:`text-slate-500 hover:text-slate-700 dark:hover:text-slate-300`}`,children:[(0,N.jsx)(`svg`,{className:`w-5 h-5 sm:w-4 sm:h-4`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,N.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`})}),(0,N.jsx)(`span`,{className:`hidden sm:inline`,children:`Stats`})]}),(0,N.jsxs)(M,{to:`/dashboard/config`,className:`flex items-center gap-1.5 text-sm transition-colors ${s?`text-blue-600 dark:text-blue-400`:`text-slate-500 hover:text-slate-700 dark:hover:text-slate-300`}`,children:[(0,N.jsxs)(`svg`,{className:`w-5 h-5 sm:w-4 sm:h-4`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:[(0,N.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M10.325 4.317c.426-1.756 2.924-1.756 3.35 0a1.724 1.724 0 002.573 1.066c1.543-.94 3.31.826 2.37 2.37a1.724 1.724 0 001.066 2.573c1.756.426 1.756 2.924 0 3.35a1.724 1.724 0 00-1.066 2.573c.94 1.543-.826 3.31-2.37 2.37a1.724 1.724 0 00-2.573 1.066c-.426 1.756-2.924 1.756-3.35 0a1.724 1.724 0 00-2.573-1.066c-1.543.94-3.31-.826-2.37-2.37a1.724 1.724 0 00-1.066-2.573c-1.756-.426-1.756-2.924 0-3.35a1.724 1.724 0 001.066-2.573c-.94-1.543.826-3.31 2.37-2.37.996.608 2.296.07 2.572-1.065z`}),(0,N.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M15 12a3 3 0 11-6 0 3 3 0 016 0z`})]}),(0,N.jsx)(`span`,{className:`hidden sm:inline`,children:`Settings`})]})]}),(0,N.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,N.jsx)(`span`,{className:`w-2 h-2 rounded-full ${n?`bg-green-500`:`bg-red-500`}`,title:n?`Connected`:`Disconnected`}),(0,N.jsx)(`button`,{onClick:a,className:`p-1.5 rounded-md text-slate-500 hover:text-slate-700 dark:hover:text-slate-300 hover:bg-slate-100 dark:hover:bg-slate-800 transition-colors`,title:`Toggle theme`,children:r===`dark`?(0,N.jsx)(`svg`,{className:`w-4 h-4`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,N.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M12 3v1m0 16v1m9-9h-1M4 12H3m15.364 6.364l-.707-.707M6.343 6.343l-.707-.707m12.728 0l-.707.707M6.343 17.657l-.707.707M16 12a4 4 0 11-8 0 4 4 0 018 0z`})}):(0,N.jsx)(`svg`,{className:`w-4 h-4`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,N.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M20.354 15.354A9 9 0 018.646 3.646 9.003 9.003 0 0012 21a9.003 9.003 0 008.354-5.646z`})})}),(0,N.jsx)(`button`,{onClick:o,className:`text-sm text-slate-500 hover:text-slate-700 dark:hover:text-slate-300 transition-colors`,children:`Logout`})]})]})})}function Wr(){return(0,N.jsxs)(zr,{children:[(0,N.jsx)(Ur,{}),(0,N.jsx)(`main`,{className:`px-4 sm:px-6 py-4 max-w-7xl mx-auto`,children:(0,N.jsx)(It,{})})]})}function Gr({disabled:e,onQuickRun:t,onRunWithPrompt:n,onChat:r}){let[i,a]=(0,x.useState)(!1),o=(0,x.useRef)(null);return(0,x.useEffect)(()=>{if(!i)return;function e(e){o.current&&!o.current.contains(e.target)&&a(!1)}return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[i]),(0,N.jsxs)(`div`,{className:`relative inline-flex`,ref:o,children:[(0,N.jsx)(`button`,{onClick:t,disabled:e,className:`px-3 py-1.5 text-xs font-medium rounded-l-md bg-green-600 hover:bg-green-700 disabled:opacity-40 disabled:cursor-not-allowed text-white transition-colors`,children:`Run`}),(0,N.jsx)(`button`,{onClick:()=>a(e=>!e),disabled:e,className:`px-1.5 py-1.5 text-xs font-medium rounded-r-md bg-green-600 hover:bg-green-700 disabled:opacity-40 disabled:cursor-not-allowed text-white transition-colors border-l border-green-700`,"aria-label":`More run options`,children:(0,N.jsx)(`svg`,{className:`w-3 h-3`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,N.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M19 9l-7 7-7-7`})})}),i&&(0,N.jsxs)(`div`,{className:`absolute right-0 mt-8 w-40 bg-white dark:bg-slate-800 border border-slate-200 dark:border-slate-700 rounded-md shadow-lg z-10 py-1`,children:[(0,N.jsx)(`button`,{onClick:()=>{a(!1),n()},className:`w-full text-left px-3 py-1.5 text-xs text-slate-700 dark:text-slate-200 hover:bg-slate-100 dark:hover:bg-slate-700 transition-colors`,children:`Run with Prompt`}),(0,N.jsx)(`button`,{onClick:()=>{a(!1),r()},className:`w-full text-left px-3 py-1.5 text-xs text-slate-700 dark:text-slate-200 hover:bg-slate-100 dark:hover:bg-slate-700 transition-colors`,children:`Chat`})]})]})}function Kr({agentName:e,onClose:t,onRun:n}){let[r,i]=(0,x.useState)(``),a=(0,x.useRef)(null);(0,x.useEffect)(()=>{a.current?.focus();let e=e=>{e.key===`Escape`&&t()};return document.addEventListener(`keydown`,e),()=>document.removeEventListener(`keydown`,e)},[t]);let o=()=>{n(r.trim()||void 0),t()};return(0,N.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/50`,onClick:e=>{e.target===e.currentTarget&&t()},children:(0,N.jsxs)(`div`,{className:`bg-white dark:bg-slate-900 shadow-xl border-slate-200 dark:border-slate-700 w-full h-full sm:h-auto sm:max-w-md sm:mx-4 sm:rounded-lg sm:border p-5 flex flex-col`,children:[(0,N.jsxs)(`h2`,{className:`text-sm font-semibold text-slate-900 dark:text-white mb-3`,children:[`Run `,e]}),(0,N.jsx)(`textarea`,{ref:a,value:r,onChange:e=>i(e.target.value),placeholder:`Optional: describe a specific task...`,rows:3,className:`w-full px-3 py-2 text-base bg-slate-50 dark:bg-slate-950 border border-slate-300 dark:border-slate-700 rounded-md text-slate-900 dark:text-slate-200 placeholder-slate-400 dark:placeholder-slate-500 focus:outline-none focus:ring-2 focus:ring-blue-500 resize-none flex-1 sm:flex-none`,onKeyDown:e=>{e.key===`Enter`&&(e.metaKey||e.ctrlKey)&&o()}}),(0,N.jsxs)(`div`,{className:`flex items-center justify-end gap-2 mt-3`,children:[(0,N.jsx)(`button`,{onClick:t,className:`px-3 py-1.5 text-xs font-medium rounded-md bg-slate-200 dark:bg-slate-800 text-slate-700 dark:text-slate-300 hover:bg-slate-300 dark:hover:bg-slate-700 transition-colors`,children:`Cancel`}),(0,N.jsx)(`button`,{onClick:o,className:`px-3 py-1.5 text-xs font-medium rounded-md bg-green-600 hover:bg-green-700 text-white transition-colors`,children:`Run`})]})]})})}function qr(){let{name:e}=dt(),t=st(),n=it(),{agents:r}=Br(),[i,a]=(0,x.useState)(null),[o,s]=(0,x.useState)(null),[c,l]=(0,x.useState)(!1),[u,d]=(0,x.useState)(!1),f=r.find(t=>t.name===e)??i?.agent??null;if((0,x.useEffect)(()=>{e&&Qn(e).then(e=>a(e)).catch(()=>{})},[e]),(0,x.useCallback)(async e=>{s(null);try{await e()}catch(e){s(e instanceof Error?e.message:`Action failed`)}},[]),!e)return null;let p=`/dashboard/agents/${encodeURIComponent(e)}`,m=n.pathname===p||n.pathname===p+`/`,h=n.pathname.endsWith(`/stats`),g=n.pathname.endsWith(`/settings`)||n.pathname.endsWith(`/admin`),_=e=>`pb-2 text-sm font-medium transition-colors ${e?`text-blue-600 dark:text-blue-400 border-b-2 border-blue-600 dark:border-blue-400`:`text-slate-500 hover:text-slate-700 dark:hover:text-slate-300`}`;return(0,N.jsxs)(`div`,{className:`space-y-4`,children:[(0,N.jsxs)(`div`,{className:`space-y-1`,children:[(0,N.jsxs)(`nav`,{className:`flex items-center gap-1 text-xs text-slate-500 dark:text-slate-400`,children:[(0,N.jsx)(M,{to:`/dashboard`,className:`hover:text-slate-700 dark:hover:text-slate-300 transition-colors`,children:`Agents`}),(0,N.jsx)(`span`,{children:`›`})]}),(0,N.jsxs)(`div`,{className:`flex items-center justify-between flex-wrap gap-3`,children:[(0,N.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,N.jsx)(`h1`,{className:`text-xl font-bold text-slate-900 dark:text-white`,children:e}),f&&!f.enabled&&(0,N.jsx)(`span`,{className:`text-xs text-slate-500 italic`,children:`(disabled)`})]}),(0,N.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,N.jsx)(Gr,{disabled:f?!f.enabled:!1,onQuickRun:async()=>{try{let n=await cr(e,void 0);n?.instanceId&&t(`/dashboard/agents/${encodeURIComponent(e)}/instances/${encodeURIComponent(n.instanceId)}`)}catch(e){s(e instanceof Error?e.message:`Action failed`)}},onRunWithPrompt:()=>d(!0),onChat:()=>t(`/chat/${encodeURIComponent(e)}`)}),(0,N.jsx)(`button`,{id:`agent-kill-btn`,onClick:async()=>{l(!0),s(null);try{await lr(e)}catch(e){s(e instanceof Error?e.message:`Action failed`)}finally{l(!1)}},disabled:!f||f.runningCount===0||c,className:`px-3 py-1.5 text-xs font-medium rounded-md bg-red-600 hover:bg-red-700 disabled:opacity-40 disabled:cursor-not-allowed text-white transition-colors`,children:c?(0,N.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,N.jsxs)(`svg`,{className:`w-3 h-3 animate-spin`,viewBox:`0 0 24 24`,fill:`none`,children:[(0,N.jsx)(`circle`,{className:`opacity-25`,cx:`12`,cy:`12`,r:`10`,stroke:`currentColor`,strokeWidth:`4`}),(0,N.jsx)(`path`,{className:`opacity-75`,fill:`currentColor`,d:`M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z`})]}),`Killing…`]}):`Kill`})]})]})]}),(0,N.jsxs)(`div`,{className:`flex gap-6 border-b border-slate-200 dark:border-slate-800`,children:[(0,N.jsx)(M,{to:p,className:_(m),children:`Activity`}),(0,N.jsx)(M,{to:`${p}/stats`,className:_(h),children:`Stats`}),(0,N.jsx)(M,{to:`${p}/settings`,className:_(g),children:`Settings`})]}),o&&(0,N.jsx)(`div`,{className:`bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 rounded-lg p-3 text-sm text-red-700 dark:text-red-400`,children:o}),(0,N.jsx)(It,{}),u&&e&&(0,N.jsx)(Kr,{agentName:e,onClose:()=>d(!1),onRun:async n=>{try{let r=await cr(e,n);r?.instanceId&&t(`/dashboard/agents/${encodeURIComponent(e)}/instances/${encodeURIComponent(r.instanceId)}`)}catch(e){s(e instanceof Error?e.message:`Action failed`)}}})]})}var Jr=new Map;function Yr(e){let t=Jr.get(e);if(t)for(let e of t.listeners)e()}function Xr(e,t){let n=Jr.get(e);if(n){n.refCount++,n.fetcher=t.fetcher;return}let r={data:null,error:null,status:`idle`,refCount:1,fetcher:t.fetcher,abortController:null,inFlight:!1,dirty:!1,pollTimer:null,signalUnsubscribe:null,listeners:new Set,lastSnapshot:null};Jr.set(e,r),t.invalidateOn&&t.invalidateOn.length>0&&(r.signalUnsubscribe=Sr(t.invalidateOn,t.invalidateAgent,()=>Qr(e),t.debounceMs??500)),t.pollIntervalMs&&t.enabled!==!1&&(r.pollTimer=setInterval(()=>Qr(e),t.pollIntervalMs)),t.enabled!==!1&&Qr(e)}function Zr(e){let t=Jr.get(e);t&&(t.refCount--,t.refCount<=0&&(t.abortController&&t.abortController.abort(),t.pollTimer&&clearInterval(t.pollTimer),t.signalUnsubscribe&&t.signalUnsubscribe(),Jr.delete(e)))}function Qr(e){let t=Jr.get(e);if(!t||!t.fetcher)return;if(t.inFlight){t.dirty=!0;return}t.inFlight=!0,t.dirty=!1;let n=new AbortController;t.abortController=n,t.status===`idle`&&(t.status=`loading`,Yr(e)),t.fetcher(n.signal).then(e=>{n.signal.aborted||(t.data=e,t.error=null,t.status=`success`)}).catch(e=>{n.signal.aborted||(t.error=e instanceof Error?e:Error(String(e)),t.status=`error`)}).finally(()=>{n.signal.aborted||(t.inFlight=!1,t.abortController=null,Yr(e),t.dirty&&Qr(e))})}function $r(e,t){let n=Jr.get(e);return n?(n.listeners.add(t),()=>{n.listeners.delete(t)}):()=>{}}var ei={data:null,error:null,isLoading:!1};function ti(e){let t=Jr.get(e);if(!t)return ei;let n=t.status===`loading`||t.status===`idle`&&t.inFlight,r=t.lastSnapshot;if(r&&r.data===t.data&&r.error===t.error&&r.isLoading===n)return r;let i={data:t.data,error:t.error,isLoading:n};return t.lastSnapshot=i,i}function ni(e){let{key:t,fetcher:n,invalidateOn:r,invalidateAgent:i,pollIntervalMs:a,debounceMs:o,enabled:s=!0,keyChangeDebounceMs:c}=e,l=(0,x.useRef)(n);l.current=n;let u=(0,x.useCallback)(e=>l.current(e),[]),d=(0,x.useRef)(t),[f,p]=(0,x.useState)(t);(0,x.useEffect)(()=>{if(t===d.current)return;if(d.current=t,!c){p(t);return}let e=setTimeout(()=>p(t),c);return()=>clearTimeout(e)},[t,c]);let m=r?.join(`,`);(0,x.useEffect)(()=>(Xr(f,{fetcher:u,invalidateOn:r,invalidateAgent:i,pollIntervalMs:a,debounceMs:o,enabled:s}),()=>Zr(f)),[f,u,m,i,a,o,s]);let h=(0,x.useSyncExternalStore)((0,x.useCallback)(e=>$r(f,e),[f]),(0,x.useCallback)(()=>ti(f),[f])),g=(0,x.useCallback)(()=>Qr(f),[f]);return{data:h.data,error:h.error,isLoading:h.isLoading,refetch:g}}function ri({label:e}){return(0,N.jsx)(`span`,{className:`inline-block px-1.5 py-0 text-[10px] leading-4 font-medium rounded ${{schedule:`bg-blue-50 text-blue-600 dark:bg-blue-900/30 dark:text-blue-400`,github:`bg-purple-50 text-purple-600 dark:bg-purple-900/30 dark:text-purple-400`,sentry:`bg-orange-50 text-orange-600 dark:bg-orange-900/30 dark:text-orange-400`,linear:`bg-indigo-50 text-indigo-600 dark:bg-indigo-900/30 dark:text-indigo-400`,slack:`bg-green-50 text-green-600 dark:bg-green-900/30 dark:text-green-400`,discord:`bg-violet-50 text-violet-600 dark:bg-violet-900/30 dark:text-violet-400`,twitter:`bg-sky-50 text-sky-600 dark:bg-sky-900/30 dark:text-sky-400`,mintlify:`bg-teal-50 text-teal-600 dark:bg-teal-900/30 dark:text-teal-400`,manual:`bg-slate-100 text-slate-600 dark:bg-slate-800/50 dark:text-slate-400`,agent:`bg-amber-50 text-amber-600 dark:bg-amber-900/30 dark:text-amber-400`}[e.split(` `)[0]]??`bg-slate-50 text-slate-500 dark:bg-slate-800/50 dark:text-slate-400`}`,children:e})}var ii={schedule:`bg-blue-100 text-blue-700 dark:bg-blue-900/40 dark:text-blue-300`,webhook:`bg-purple-100 text-purple-700 dark:bg-purple-900/40 dark:text-purple-300`,agent:`bg-amber-100 text-amber-700 dark:bg-amber-900/40 dark:text-amber-300`};function ai({type:e}){return(0,N.jsx)(`span`,{className:`px-1.5 py-0.5 text-xs font-medium rounded ${ii[e]??`bg-slate-100 text-slate-600 dark:bg-slate-800 dark:text-slate-300`}`,children:e})}function oi({result:e,deadLetterReason:t}){return e===`pending`?(0,N.jsx)(`span`,{className:`inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium bg-amber-100 text-amber-700 dark:bg-amber-900/40 dark:text-amber-400`,children:`pending`}):e===`completed`||e===`rerun`?(0,N.jsx)(`span`,{className:`text-green-600 dark:text-green-400 text-xs font-medium`,children:e}):e===`dead-letter`?(0,N.jsx)(`span`,{className:`px-1.5 py-0.5 text-xs font-medium rounded bg-red-100 text-red-700 dark:bg-red-900/40 dark:text-red-300`,children:t?{no_match:`No Match`,validation_failed:`Validation Failed`,parse_error:`Parse Error`}[t]??t:`Dead Letter`}):e===`error`?(0,N.jsx)(`span`,{className:`text-red-600 dark:text-red-400 text-xs font-medium`,children:`error`}):e===`running`?(0,N.jsxs)(`span`,{className:`flex items-center gap-1 text-blue-600 dark:text-blue-400 text-xs font-medium`,children:[(0,N.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full bg-blue-500 animate-pulse`}),`running`]}):(0,N.jsx)(`span`,{className:`text-slate-500 text-xs`,children:e})}var si=x.createContext(null);function ci(){let{name:e,id:t}=dt(),n=it(),[r,i]=(0,x.useState)(!1),[a,o]=(0,x.useState)(null),[s,c]=(0,x.useState)(!1),{data:l}=ni({key:`instance-detail:${e}:${t}`,fetcher:n=>ar(e,t,n),invalidateOn:[`instance`],invalidateAgent:e,enabled:!!e&&!!t}),u=l?.runningInstance!=null,d=(0,x.useCallback)(async()=>{if(t){i(!0),o(null);try{await ur(t)}catch(e){o(e instanceof Error?e.message:`Action failed`)}finally{i(!1)}}},[t]);if(!e||!t)return null;let f=`/dashboard/agents/${encodeURIComponent(e)}/instances/${encodeURIComponent(t)}`,p=n.pathname===f||n.pathname===f+`/`,m=n.pathname.endsWith(`/trigger`),h=n.pathname.endsWith(`/telemetry`),g=e=>`pb-2 text-sm font-medium transition-colors flex items-center gap-1.5 ${e?`text-blue-600 dark:text-blue-400 border-b-2 border-blue-600 dark:border-blue-400`:`text-slate-500 hover:text-slate-700 dark:hover:text-slate-300`}`,_=l?.run,v={detail:l??null,name:e,id:t,isRunning:u};return(0,N.jsx)(si.Provider,{value:v,children:(0,N.jsxs)(`div`,{className:`space-y-4`,children:[(0,N.jsxs)(`div`,{className:`space-y-1`,children:[(0,N.jsxs)(`nav`,{className:`flex items-center gap-1 text-xs text-slate-500 dark:text-slate-400`,children:[(0,N.jsx)(M,{to:`/dashboard`,className:`hover:text-slate-700 dark:hover:text-slate-300 transition-colors`,children:`Agents`}),(0,N.jsx)(`span`,{children:`›`}),(0,N.jsx)(M,{to:`/dashboard/agents/${encodeURIComponent(e)}`,className:`hover:text-slate-700 dark:hover:text-slate-300 transition-colors`,children:e}),(0,N.jsx)(`span`,{children:`›`})]}),(0,N.jsxs)(`div`,{className:`flex items-center justify-between flex-wrap gap-3`,children:[(0,N.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,N.jsx)(`div`,{children:(0,N.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,N.jsx)(`h1`,{className:`text-xl font-bold text-slate-900 dark:text-white font-mono break-all`,children:t}),(0,N.jsx)(`button`,{onClick:()=>{navigator.clipboard.writeText(t),c(!0),setTimeout(()=>c(!1),2e3)},className:`text-slate-400 hover:text-slate-600 dark:hover:text-slate-300 transition-colors`,title:`Copy instance ID`,children:s?(0,N.jsx)(`svg`,{className:`w-4 h-4 text-green-500`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,N.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M5 13l4 4L19 7`})}):(0,N.jsx)(`svg`,{className:`w-4 h-4`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,N.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z`})})})]})}),_&&(0,N.jsx)(oi,{result:_.result}),u&&!_&&(0,N.jsx)(`span`,{className:`text-xs text-blue-600 dark:text-blue-400 font-medium`,children:`running`})]}),u&&(0,N.jsx)(`button`,{onClick:d,disabled:r,className:`px-3 py-1.5 text-xs font-medium rounded-md bg-red-600 hover:bg-red-700 disabled:opacity-40 disabled:cursor-not-allowed text-white transition-colors`,children:r?(0,N.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,N.jsxs)(`svg`,{className:`w-3 h-3 animate-spin`,viewBox:`0 0 24 24`,fill:`none`,children:[(0,N.jsx)(`circle`,{className:`opacity-25`,cx:`12`,cy:`12`,r:`10`,stroke:`currentColor`,strokeWidth:`4`}),(0,N.jsx)(`path`,{className:`opacity-75`,fill:`currentColor`,d:`M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z`})]}),`Killing…`]}):`Kill`})]})]}),(0,N.jsxs)(`div`,{className:`flex gap-6 border-b border-slate-200 dark:border-slate-800`,children:[(0,N.jsxs)(M,{to:f,className:g(p),children:[(0,N.jsx)(`svg`,{className:`w-4 h-4`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,N.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`})}),`Logs`]}),(0,N.jsxs)(M,{to:`${f}/trigger`,className:g(m),children:[(0,N.jsx)(`svg`,{className:`w-4 h-4`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,N.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M13 10V3L4 14h7v7l9-11h-7z`})}),`Trigger`]}),(0,N.jsxs)(M,{to:`${f}/telemetry`,className:g(h),children:[(0,N.jsx)(`svg`,{className:`w-4 h-4`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,N.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`})}),`Telemetry`]})]}),a&&(0,N.jsx)(`div`,{className:`bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 rounded-lg p-3 text-sm text-red-700 dark:text-red-400`,children:a}),(0,N.jsx)(It,{})]})})}function li(){let[e,t]=(0,x.useState)(``),[n,r]=(0,x.useState)(null),[i,a]=(0,x.useState)(!1),o=st(),s=(0,x.useCallback)(async t=>{t.preventDefault(),r(null),a(!0);try{await _r(e)?o(`/dashboard`):r(`Invalid API key`)}catch{r(`Login failed`)}finally{a(!1)}},[e,o]);return(0,N.jsx)(`div`,{className:`flex items-center justify-center min-h-screen`,children:(0,N.jsxs)(`div`,{className:`bg-slate-50 dark:bg-slate-900 border border-slate-200 dark:border-slate-800 rounded-xl p-8 w-full max-w-sm mx-4`,children:[(0,N.jsx)(`h1`,{className:`text-2xl font-bold text-slate-900 dark:text-white text-center mb-2`,children:`Action Llama`}),(0,N.jsx)(`p`,{className:`text-slate-500 dark:text-slate-400 text-sm text-center mb-6`,children:`Enter your API key to access the dashboard`}),n&&(0,N.jsx)(`div`,{className:`bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 rounded-lg p-3 mb-4 text-sm text-red-700 dark:text-red-400 text-center`,children:n}),(0,N.jsxs)(`form`,{onSubmit:s,children:[(0,N.jsx)(`label`,{htmlFor:`key`,className:`block text-sm text-slate-500 dark:text-slate-400 mb-1.5`,children:`API Key`}),(0,N.jsx)(`input`,{type:`password`,id:`key`,value:e,onChange:e=>t(e.target.value),placeholder:`Paste your gateway API key`,autoFocus:!0,required:!0,className:`w-full px-3 py-2.5 bg-white dark:bg-slate-950 border border-slate-300 dark:border-slate-700 rounded-lg text-slate-900 dark:text-slate-200 text-base outline-none focus:border-blue-500 dark:focus:border-blue-400 transition-colors`}),(0,N.jsx)(`button`,{type:`submit`,disabled:i,className:`w-full mt-4 px-4 py-2.5 bg-blue-600 hover:bg-blue-700 disabled:opacity-50 text-white rounded-lg text-sm font-medium transition-colors`,children:i?`Logging in...`:`Log in`})]}),(0,N.jsx)(`p`,{className:`text-slate-400 dark:text-slate-500 text-xs text-center mt-4`,children:`Key is stored at ~/.action-llama/credentials/gateway_api_key/default/key`})]})})}function ui(e){let t=0;for(let n=0;n<e.length;n++)t=t*31+e.charCodeAt(n)|0;return Math.abs(t)}function di(e){return ui(e)%360}function fi(e,t){if(t.length===0)return di(e);let n=[...t].sort(),r=n.indexOf(e);return r===-1?di(e):r/n.length*360}function P(e,t){let n=t&&t.length>0?fi(e,t):di(e);return{"--agent-hue":n}}var pi={running:`border-l-2 border-l-blue-500 dark:border-l-blue-400 bg-blue-50/40 dark:bg-blue-950/20`,building:`border-l-2 border-l-yellow-500 dark:border-l-yellow-400 bg-yellow-50/40 dark:bg-yellow-950/20`,error:`border-l-2 border-l-red-500 dark:border-l-red-400 bg-red-50/30 dark:bg-red-950/20`,idle:``},mi={running:`bg-blue-500`,building:`bg-yellow-500`,error:`bg-red-500`,idle:`bg-slate-400`};function hi({agent:e}){return(0,N.jsx)(`span`,{className:`inline-block w-2 h-2 rounded-full ${mi[e.state]??`bg-slate-400`}`,title:e.state})}function gi(){return(0,N.jsxs)(`svg`,{className:`w-3 h-3 animate-spin`,viewBox:`0 0 24 24`,fill:`none`,children:[(0,N.jsx)(`circle`,{className:`opacity-25`,cx:`12`,cy:`12`,r:`10`,stroke:`currentColor`,strokeWidth:`4`}),(0,N.jsx)(`path`,{className:`opacity-75`,fill:`currentColor`,d:`M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z`})]})}function _i({agent:e,isPaused:t,onAction:n,onRunClick:r,killingAgents:i,onKillAgent:a}){let[o,s]=(0,x.useState)(!1),c=(0,x.useRef)(null);return(0,x.useEffect)(()=>{if(!o)return;let e=e=>{c.current&&!c.current.contains(e.target)&&s(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[o]),(0,N.jsxs)(`div`,{className:`relative`,ref:c,children:[(0,N.jsxs)(`button`,{onClick:()=>s(e=>!e),className:`px-2 py-1 text-xs rounded bg-slate-200 dark:bg-slate-700 text-slate-700 dark:text-slate-300 hover:bg-slate-300 dark:hover:bg-slate-600 transition-colors`,children:[`Actions`,(0,N.jsx)(`svg`,{className:`w-3 h-3 ml-1 inline-block`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,N.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M19 9l-7 7-7-7`})})]}),o&&(0,N.jsxs)(`div`,{className:`absolute right-0 mt-1 z-10 bg-white dark:bg-slate-800 border border-slate-200 dark:border-slate-700 rounded-md shadow-lg py-1 min-w-[100px]`,children:[(0,N.jsx)(`button`,{onClick:()=>{r(),s(!1)},disabled:!e.enabled||t,className:`w-full text-left px-3 py-1.5 text-xs text-green-700 dark:text-green-400 hover:bg-slate-100 dark:hover:bg-slate-700 disabled:opacity-40 disabled:cursor-not-allowed`,children:`Run`}),(0,N.jsx)(`button`,{onClick:()=>{a(e.name),s(!1)},disabled:e.runningCount===0||i.has(e.name),className:`w-full text-left px-3 py-1.5 text-xs text-red-700 dark:text-red-400 hover:bg-slate-100 dark:hover:bg-slate-700 disabled:opacity-40 disabled:cursor-not-allowed`,children:i.has(e.name)?(0,N.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,N.jsx)(gi,{}),`Killing…`]}):`Kill`}),(0,N.jsx)(`button`,{onClick:()=>{n(()=>e.enabled?fr(e.name):dr(e.name)),s(!1)},className:`w-full text-left px-3 py-1.5 text-xs text-slate-700 dark:text-slate-300 hover:bg-slate-100 dark:hover:bg-slate-700`,children:e.enabled?`Disable`:`Enable`})]})]})}function vi(){let e=st(),{agents:t,schedulerInfo:n}=Br(),r=t.map(e=>e.name),[i,a]=(0,x.useState)(null),[o,s]=(0,x.useState)(new Set),[c,l]=(0,x.useState)(null),[u,d]=(0,x.useState)(``),[f,p]=(0,x.useState)(``),m=(0,x.useRef)(void 0);(0,x.useEffect)(()=>(clearTimeout(m.current),m.current=setTimeout(()=>{p(u)},150),()=>clearTimeout(m.current)),[u]);let h=(0,x.useCallback)(async e=>{a(null);try{await e()}catch(e){a(e instanceof Error?e.message:`Action failed`)}},[]),g=(0,x.useCallback)(async e=>{s(t=>new Set(t).add(e)),a(null);try{await lr(e)}catch(e){a(e instanceof Error?e.message:`Action failed`)}finally{s(t=>{let n=new Set(t);return n.delete(e),n})}},[]),_=n?.paused??!1,v=f?t.filter(e=>{let t=f.toLowerCase();return e.name.toLowerCase().includes(t)||(e.description?.toLowerCase().includes(t)??!1)}):t;return(0,N.jsxs)(`div`,{className:`space-y-6`,children:[i&&(0,N.jsx)(`div`,{className:`bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 rounded-lg p-3 text-sm text-red-700 dark:text-red-400`,children:i}),_&&(0,N.jsx)(`div`,{className:`bg-yellow-50 dark:bg-yellow-900/20 border border-yellow-200 dark:border-yellow-800 rounded-lg p-3 text-sm text-yellow-700 dark:text-yellow-400 font-medium`,children:`Scheduler is paused`}),(0,N.jsx)(`div`,{className:`flex items-center justify-between flex-wrap gap-3`,children:(0,N.jsx)(`h1`,{className:`text-xl font-bold text-slate-900 dark:text-white`,children:`Agents`})}),(0,N.jsxs)(`div`,{className:`bg-slate-50 dark:bg-slate-900 rounded-lg border border-slate-200 dark:border-slate-800 overflow-hidden`,children:[(0,N.jsx)(`div`,{className:`flex items-center justify-end px-4 py-2.5 border-b border-slate-200 dark:border-slate-800`,children:(0,N.jsxs)(`div`,{className:`relative`,children:[(0,N.jsx)(`input`,{type:`text`,value:u,onChange:e=>d(e.target.value),placeholder:`Search agents…`,className:`pl-3 pr-7 py-1 text-base rounded-md border border-slate-300 dark:border-slate-700 bg-white dark:bg-slate-800 text-slate-900 dark:text-white placeholder-slate-400 focus:outline-none focus:ring-1 focus:ring-blue-500 w-48`}),u&&(0,N.jsx)(`button`,{onClick:()=>d(``),className:`absolute right-1.5 top-1/2 -translate-y-1/2 text-slate-400 hover:text-slate-600 dark:hover:text-slate-300`,"aria-label":`Clear search`,children:(0,N.jsx)(`svg`,{className:`w-3.5 h-3.5`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,N.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M6 18L18 6M6 6l12 12`})})})]})}),(0,N.jsx)(`div`,{className:`overflow-x-auto`,children:(0,N.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,N.jsx)(`thead`,{children:(0,N.jsxs)(`tr`,{className:`border-b border-slate-200 dark:border-slate-800`,children:[(0,N.jsx)(`th`,{className:`w-10 px-2 py-2.5`}),(0,N.jsx)(`th`,{className:`text-left px-4 py-2.5 text-xs font-medium text-slate-500 dark:text-slate-400 uppercase tracking-wide`,children:`Agent`}),(0,N.jsx)(`th`,{className:`hidden lg:table-cell text-left px-4 py-2.5 text-xs font-medium text-slate-500 dark:text-slate-400 uppercase tracking-wide`,children:`Description`}),(0,N.jsx)(`th`,{className:`text-right px-4 py-2.5 text-xs font-medium text-slate-500 dark:text-slate-400 uppercase tracking-wide`,children:`Actions`})]})}),(0,N.jsxs)(`tbody`,{children:[v.map(e=>(0,N.jsxs)(`tr`,{className:`border-b border-slate-100 dark:border-slate-800/50 last:border-0 hover:bg-slate-100/50 dark:hover:bg-slate-800/30 ${pi[e.state]??``}`,children:[(0,N.jsx)(`td`,{className:`w-10 px-2 py-2.5 align-middle text-center`,children:(0,N.jsx)(hi,{agent:e})}),(0,N.jsxs)(`td`,{className:`px-4 py-2.5 min-w-0 max-w-[240px]`,children:[(0,N.jsx)(M,{to:`/dashboard/agents/${encodeURIComponent(e.name)}`,className:`font-medium hover:underline truncate block`,title:e.name,children:(0,N.jsx)(`span`,{className:`agent-color-text truncate`,style:{fontSize:`16px`,...P(e.name,r)},children:e.name})}),!e.enabled&&(0,N.jsx)(`span`,{className:`ml-1 text-xs text-slate-500 italic`,children:`(disabled)`}),(e.triggers?.length??0)>0&&(0,N.jsx)(`div`,{className:`flex flex-wrap gap-1 mt-0.5`,children:e.triggers.map(e=>(0,N.jsx)(ri,{label:e},e))}),e.description&&(0,N.jsx)(`div`,{className:`lg:hidden text-xs text-slate-500 dark:text-slate-400 mt-0.5 truncate`,children:e.description})]}),(0,N.jsx)(`td`,{className:`hidden lg:table-cell px-4 py-2.5 text-xs text-slate-500 dark:text-slate-400 min-w-0 max-w-[300px] truncate`,children:e.description??`—`}),(0,N.jsxs)(`td`,{className:`px-4 py-2.5 text-right`,children:[(0,N.jsxs)(`div`,{className:`hidden sm:flex items-center justify-end gap-1.5`,children:[(0,N.jsx)(`button`,{onClick:()=>l(e.name),disabled:!e.enabled||_,className:`px-2 py-1 text-xs rounded bg-green-600 hover:bg-green-700 disabled:opacity-40 disabled:cursor-not-allowed text-white transition-colors`,title:`Trigger run`,children:`Run`}),(0,N.jsx)(`button`,{onClick:()=>g(e.name),disabled:e.runningCount===0||o.has(e.name),className:`px-2 py-1 text-xs rounded bg-red-600 hover:bg-red-700 disabled:opacity-40 disabled:cursor-not-allowed text-white transition-colors`,title:`Kill all instances`,children:o.has(e.name)?(0,N.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,N.jsx)(gi,{}),`Killing…`]}):`Kill`}),(0,N.jsx)(`button`,{onClick:()=>h(()=>e.enabled?fr(e.name):dr(e.name)),className:`px-2 py-1 text-xs rounded transition-colors ${e.enabled?`bg-slate-200 dark:bg-slate-700 text-slate-700 dark:text-slate-300 hover:bg-slate-300 dark:hover:bg-slate-600`:`bg-blue-600 hover:bg-blue-700 text-white`}`,children:e.enabled?`Disable`:`Enable`})]}),(0,N.jsx)(`div`,{className:`sm:hidden`,children:(0,N.jsx)(_i,{agent:e,isPaused:_,onAction:h,onRunClick:()=>l(e.name),killingAgents:o,onKillAgent:g})})]})]},e.name)),v.length===0&&f&&(0,N.jsx)(`tr`,{children:(0,N.jsxs)(`td`,{colSpan:4,className:`px-4 py-8 text-center text-slate-500 dark:text-slate-400`,children:[`No agents matching ‘`,f,`’`]})}),v.length===0&&!f&&(0,N.jsx)(`tr`,{children:(0,N.jsx)(`td`,{colSpan:4,className:`px-4 py-8 text-center text-slate-500 dark:text-slate-400`,children:`No agents found`})})]})]})})]}),c&&(0,N.jsx)(Kr,{agentName:c,onClose:()=>l(null),onRun:async t=>{let n=c;try{let r=await cr(n,t);r?.instanceId&&e(`/dashboard/agents/${encodeURIComponent(n)}/instances/${encodeURIComponent(r.instanceId)}`)}catch(e){a(e instanceof Error?e.message:`Action failed`)}}})]})}function yi(e){if(e<1e3)return`${e}ms`;let t=Math.floor(e/1e3);if(t<60)return`${t}s`;let n=Math.floor(t/60);return n<60?`${n}m ${t%60}s`:`${Math.floor(n/60)}h ${n%60}m`}function bi(e){return!e||e===0?`$0.00`:e<.01?`$${e.toFixed(4)}`:`$${e.toFixed(2)}`}function xi(e){return!e||e===0?`0`:e<1e3?`${e}`:e<1e6?`${(e/1e3).toFixed(1)}k`:`${(e/1e6).toFixed(2)}M`}function Si(e){return e.length<=9?e:`${e.slice(0,4)}\u2026${e.slice(-4)}`}function Ci(e){return new Date(e).toLocaleString()}function wi(e){let t=Date.now()-new Date(e).getTime();if(t<0)return``;let n=Math.floor(t/36e5);return n<1?`last ${Math.floor(t/6e4)}m`:n<24?`last ${n}h`:`last ${Math.floor(n/24)}d`}function Ti(e,t=6){let n=Date.now()-new Date(e).getTime();if(n<0||n>=t*36e5)return new Date(e).toLocaleString();let r=Math.floor(n/1e3);if(r<60)return`${r}s ago`;let i=Math.floor(r/60);return i<60?`${i} min ago`:`${Math.floor(i/60)}h ago`}var Ei={pending:`bg-amber-400`,running:`bg-blue-500 animate-pulse`,completed:`bg-green-500`,error:`bg-red-500`,"dead-letter":`bg-red-300 dark:bg-red-800`,rerun:`bg-green-500`},Di={pending:`Pending`,running:`Running`,completed:`Completed`,error:`Error`,"dead-letter":`Dead Letter`,rerun:`Rerun`},Oi={pending:`border-l-2 border-l-amber-400 dark:border-l-amber-500 bg-amber-50/40 dark:bg-amber-950/20`,running:`border-l-2 border-l-blue-500 dark:border-l-blue-400 bg-blue-50/40 dark:bg-blue-950/20`,completed:`border-l-2 border-l-green-500 dark:border-l-green-400`,error:`border-l-2 border-l-red-500 dark:border-l-red-400 bg-red-50/30 dark:bg-red-950/20`,"dead-letter":`border-l-2 border-l-red-300 dark:border-l-red-700 bg-red-50/20 dark:bg-red-950/10`,rerun:`border-l-2 border-l-green-500 dark:border-l-green-400`};function ki(e){return e.triggerType===`webhook`&&e.triggerSource?e.eventSummary&&e.eventSummary!==e.triggerSource?`${e.triggerSource} ${e.eventSummary}`:e.triggerSource:e.triggerType}function Ai(e){return!!(e.agentName&&e.instanceId)&&e.result!==`pending`&&e.result!==`running`&&e.result!==`dead-letter`}function ji({rows:e,agentNames:t,loading:n=!1,emptyMessage:r=`No activity found`}){let[i,a]=(0,x.useState)(new Set),[o,s]=(0,x.useState)(new Map),[c,l]=(0,x.useState)(new Set),[u,d]=(0,x.useState)(new Set),f=async(e,t)=>{a(e=>new Set(e).add(t));try{let n=await yr(e,t);n.summary&&s(e=>new Map(e).set(t,n.summary))}catch{}finally{a(e=>{let n=new Set(e);return n.delete(t),n})}},p=e=>{l(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},m=e=>{d(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})};return(0,N.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,N.jsx)(`thead`,{children:(0,N.jsxs)(`tr`,{className:`border-b border-slate-200 dark:border-slate-800`,children:[(0,N.jsx)(`th`,{className:`text-left pl-6 pr-1 py-2.5 text-xs font-medium text-slate-500 dark:text-slate-400 uppercase tracking-wide w-[1%] whitespace-nowrap`,children:`Time`}),(0,N.jsx)(`th`,{className:`text-left pl-2 pr-2 py-2.5 text-xs font-medium text-slate-500 dark:text-slate-400 uppercase tracking-wide w-[1%] whitespace-nowrap`,children:`Instance`}),(0,N.jsx)(`th`,{className:`text-left pl-0 pr-2 py-2.5 text-xs font-medium text-slate-500 dark:text-slate-400 uppercase tracking-wide hidden md:table-cell w-full`,children:`Summary`})]})}),(0,N.jsxs)(`tbody`,{children:[e.map((e,n)=>{let r=e.result===`dead-letter`,a=ki(e),s=e.instanceId??``,l=s?o.get(s)??e.summary??null:null,d=s?i.has(s):!1,h=s?!c.has(s):!0,g=s?u.has(s):!1,_=Ai(e),v=e.instanceId?`/dashboard/triggers/${encodeURIComponent(e.instanceId)}`:e.webhookReceiptId?`/dashboard/webhooks/${encodeURIComponent(e.webhookReceiptId)}`:null,y=v?(0,N.jsxs)(M,{to:v,className:`inline-flex items-center gap-1 hover:underline`,children:[(0,N.jsx)(ri,{label:a}),e.triggerType!==`webhook`&&e.triggerSource&&(0,N.jsx)(`span`,{className:`text-xs text-slate-500 dark:text-slate-400`,children:e.triggerSource})]}):(0,N.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,N.jsx)(ri,{label:a}),e.triggerType!==`webhook`&&e.triggerSource&&(0,N.jsx)(`span`,{className:`text-xs text-slate-500 dark:text-slate-400`,children:e.triggerSource})]}),b=!r&&e.agentName&&e.instanceId?(0,N.jsx)(M,{to:`/dashboard/agents/${encodeURIComponent(e.agentName)}/instances/${encodeURIComponent(e.instanceId)}`,className:`font-medium hover:underline truncate block`,children:(0,N.jsx)(`span`,{className:`agent-color-text truncate text-sm md:text-base`,style:P(e.agentName,t),children:e.instanceId})}):!r&&e.agentName?(0,N.jsx)(M,{to:`/dashboard/agents/${encodeURIComponent(e.agentName)}`,className:`font-medium hover:underline truncate block`,children:(0,N.jsx)(`span`,{className:`agent-color-text truncate text-sm md:text-base`,style:P(e.agentName,t),children:e.agentName})}):null,x=(0,N.jsx)(`td`,{className:`pl-0 pr-2 py-2.5 hidden md:table-cell align-top`,children:d?(0,N.jsx)(`span`,{className:`text-xs text-slate-400 dark:text-slate-500 animate-pulse`,children:`Generating…`}):l?(0,N.jsxs)(`div`,{className:`flex items-start gap-1.5`,children:[(0,N.jsx)(`button`,{onClick:()=>s&&p(s),className:`text-xs text-slate-600 dark:text-slate-300 text-left hover:text-slate-900 dark:hover:text-white transition-colors`,title:h?`Collapse`:`Click to expand`,children:h?(0,N.jsx)(`span`,{children:l}):(0,N.jsx)(`span`,{className:`line-clamp-2`,children:l})}),_&&(0,N.jsx)(`button`,{onClick:()=>e.agentName&&s&&f(e.agentName,s),className:`shrink-0 text-slate-400 hover:text-slate-600 dark:text-slate-500 dark:hover:text-slate-300 transition-colors`,title:`Regenerate summary`,children:`↻`})]}):_?(0,N.jsx)(`button`,{onClick:()=>e.agentName&&s&&f(e.agentName,s),className:`text-xs text-blue-500 hover:text-blue-700 dark:text-blue-400 dark:hover:text-blue-300 transition-colors`,children:`Generate`}):(0,N.jsx)(`span`,{className:`text-xs text-slate-300 dark:text-slate-600`,children:`—`})});return(0,N.jsxs)(`tr`,{className:`border-b border-slate-100 dark:border-slate-800/50 last:border-b-0 hover:bg-slate-100/60 dark:hover:bg-slate-800/40 transition-colors ${Oi[e.result]??``}`,children:[(0,N.jsx)(`td`,{className:`pl-4 pr-1 py-2.5 text-slate-600 dark:text-slate-400 text-xs whitespace-nowrap align-top w-[1%]`,title:new Date(e.ts).toLocaleString(),children:(0,N.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,N.jsx)(`span`,{className:`w-2 h-2 rounded-full shrink-0 ${Ei[e.result]??`bg-slate-400`}`,title:Di[e.result]??e.result}),Ti(e.ts)]})}),(0,N.jsx)(`td`,{className:`pl-2 pr-2 py-2.5 whitespace-nowrap max-w-[200px]`,children:(0,N.jsxs)(`div`,{className:`flex flex-col gap-0.5`,children:[b,(0,N.jsx)(`div`,{className:`mt-0.5`,children:y}),r&&e.deadLetterReason&&(0,N.jsx)(`span`,{className:`text-xs text-red-500 dark:text-red-400`,children:e.deadLetterReason.replace(/_/g,` `)}),_&&(0,N.jsx)(`div`,{className:`md:hidden mt-1`,children:d?(0,N.jsx)(`span`,{className:`text-xs text-slate-400 dark:text-slate-500 animate-pulse`,children:`Generating…`}):l?(0,N.jsxs)(`div`,{children:[(0,N.jsx)(`button`,{onClick:()=>s&&m(s),className:`text-xs text-slate-500 dark:text-slate-400 text-left hover:text-slate-700 dark:hover:text-slate-200 transition-colors`,children:g?(0,N.jsx)(`span`,{children:l}):(0,N.jsx)(`span`,{children:l.length>60?`${l.slice(0,60)}…`:l})}),g&&(0,N.jsx)(`button`,{onClick:()=>e.agentName&&s&&f(e.agentName,s),className:`ml-2 text-xs text-slate-400 hover:text-slate-600 dark:text-slate-500 dark:hover:text-slate-300 transition-colors`,title:`Regenerate summary`,children:`↻ Regenerate`})]}):(0,N.jsx)(`button`,{onClick:()=>e.agentName&&s&&f(e.agentName,s),className:`text-xs text-blue-500 hover:text-blue-700 dark:text-blue-400 dark:hover:text-blue-300 transition-colors`,children:`Generate summary`})})]})}),x]},`${e.ts}-${n}`)}),e.length===0&&n&&(0,N.jsx)(`tr`,{children:(0,N.jsx)(`td`,{colSpan:3,className:`px-4 py-8 text-center text-slate-500 dark:text-slate-400`,children:`Loading...`})}),e.length===0&&!n&&(0,N.jsx)(`tr`,{children:(0,N.jsx)(`td`,{colSpan:3,className:`px-4 py-8 text-center text-slate-500 dark:text-slate-400`,children:r})})]})]})}function Mi(){let{name:e}=dt(),t=Nr(),n=t.find(t=>t.name===e)??null,r=t.map(e=>e.name),{data:i}=ni({key:`agent-activity:${e}`,fetcher:t=>rr(5,0,e,void 0,void 0,t),invalidateOn:[`runs`],invalidateAgent:e,enabled:!!e}),a=i?.rows??[];return e?(0,N.jsx)(`div`,{className:`space-y-6`,children:(0,N.jsxs)(`div`,{className:`bg-slate-50 dark:bg-slate-900 rounded-lg border border-slate-200 dark:border-slate-800 overflow-hidden`,children:[(0,N.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-2.5 border-b border-slate-200 dark:border-slate-800`,children:[(0,N.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,N.jsx)(`h2`,{className:`text-sm font-medium text-slate-900 dark:text-white`,children:`Activity`}),n&&(0,N.jsxs)(`span`,{id:`agent-state`,className:`text-sm ${n.runningCount>0?`text-blue-600 dark:text-blue-400`:`text-slate-500 dark:text-slate-400`}`,children:[(0,N.jsx)(`span`,{className:`inline-block w-1.5 h-1.5 rounded-full mr-1.5 ${n.runningCount>0?`bg-blue-500`:`bg-slate-400`}`}),n.runningCount>0?n.scale>1?`running ${n.runningCount}/${n.scale}`:`running`:`idle`,n.scale>1&&n.runningCount===0&&(0,N.jsxs)(`span`,{className:`text-xs text-slate-400 ml-1`,children:[`×`,n.scale]})]}),(n?.queuedWebhooks??0)>0&&(0,N.jsxs)(`span`,{className:`inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium bg-amber-100 text-amber-700 dark:bg-amber-900/40 dark:text-amber-400`,children:[n.queuedWebhooks,` pending`]})]}),(0,N.jsx)(M,{to:`/activity?agent=${encodeURIComponent(e)}`,className:`text-xs text-blue-600 dark:text-blue-400 hover:underline`,children:`View all`})]}),(0,N.jsx)(`div`,{className:`overflow-x-auto`,children:(0,N.jsx)(ji,{rows:a,agentNames:r,emptyMessage:`No activity yet`})})]})}):null}function Ni(e){return e.replace(/&/g,`&`).replace(/</g,`<`).replace(/>/g,`>`).replace(/"/g,`"`).replace(/'/g,`'`)}function Pi(e){let t=Ni(e);return t=t.replace(/`([^`]+)`/g,`<code class="bg-slate-200 dark:bg-slate-800 px-1 py-0.5 rounded text-sm font-mono">$1</code>`),t=t.replace(/\[([^\]]+)\]\(([^)]+)\)/g,`<a href="$2" class="text-blue-600 dark:text-blue-400 hover:underline" target="_blank" rel="noopener noreferrer">$1</a>`),t=t.replace(/\*\*([^*]+)\*\*/g,`<strong class="font-semibold">$1</strong>`),t=t.replace(/\*([^*]+)\*/g,`<em class="italic">$1</em>`),t}function Fi(e){if(!e)return``;let t=e.split(`
|
|
12
12
|
`),n=[],r=!1,i=``,a=null;function o(){if(a){let e=a.type===`ul`?`list-disc list-inside mb-4 space-y-1`:`list-decimal list-inside mb-4 space-y-1`;n.push(`<${a.type} class="${e}">`);for(let e of a.items)n.push(`<li class="ml-2">${Pi(e)}</li>`);n.push(`</${a.type}>`),a=null}}for(let e=0;e<t.length;e++){let s=t[e],c=s.trim();if(c.startsWith("```")){if(r)n.push(`</code></pre>`),r=!1,i=``;else{o(),i=c.slice(3).trim();let e=i?` language-${Ni(i)}`:``;n.push(`<pre class="bg-slate-100 dark:bg-slate-900 rounded-lg p-4 overflow-x-auto text-sm"><code${e?` class="${e}"`:``}>`),r=!0}continue}if(r){n.push(Ni(s));continue}if(!c){o(),n.push(`<br>`);continue}if(c.startsWith(`#`)){o();let e=c.match(/^(#+)\s+(.+)$/);if(e){let t=Math.min(e[1].length,6),r=e[2],i=t===1?`text-2xl`:t===2?`text-xl`:t===3?`text-lg`:`text-base`;n.push(`<h${t} class="${i} font-bold text-slate-900 dark:text-white mt-6 mb-3">${Pi(r)}</h${t}>`)}continue}let l=c.match(/^[-*+]\s+(.+)$/),u=c.match(/^\d+\.\s+(.+)$/);if(l){(!a||a.type!==`ul`)&&(o(),a={type:`ul`,items:[]}),a.items.push(l[1]);continue}if(u){(!a||a.type!==`ol`)&&(o(),a={type:`ol`,items:[]}),a.items.push(u[1]);continue}o(),c&&n.push(`<p class="mb-4 leading-relaxed">${Pi(c)}</p>`)}return r&&n.push(`</code></pre>`),o(),n.join(`
|
|
13
|
-
`)}function Ii(){let{name:e}=dt(),{agents:t}=Br(),[n,r]=(0,x.useState)(null),[i,a]=(0,x.useState)(``),[o,s]=(0,x.useState)(null),[c,l]=(0,x.useState)(null),[u,d]=(0,x.useState)(null),[f,p]=(0,x.useState)(null),m=t.find(t=>t.name===e)??n?.agent??null,h=(0,x.useCallback)(()=>{e&&Qn(e).then(e=>{r(e),e.agent&&a(String(e.agent.scale))}).catch(()=>{})},[e]);(0,x.useEffect)(()=>{h()},[h]),(0,x.useEffect)(()=>{m&&a(String(m.scale))},[m?.scale]),(0,x.useEffect)(()=>{e&&$n(e).then(e=>{s(e.body),l(e.agentConfig)}).catch(e=>d(e instanceof Error?e.message:`Failed to load skill`))},[e]);let g=(0,x.useCallback)(async e=>{p(null);try{await e()}catch(e){p(e instanceof Error?e.message:`Action failed`)}},[]),_=(0,x.useCallback)(()=>{if(!e)return;let t=parseInt(i,10);isNaN(t)||t<1||g(()=>gr(e,t))},[e,i,g]);return e?(0,N.jsxs)(`div`,{className:`space-y-6`,children:[f&&(0,N.jsx)(`div`,{className:`bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 rounded-lg p-3 text-sm text-red-700 dark:text-red-400`,children:f}),(0,N.jsxs)(`div`,{className:`bg-slate-50 dark:bg-slate-900 rounded-lg border border-slate-200 dark:border-slate-800 overflow-hidden`,children:[(0,N.jsx)(`div`,{className:`px-4 py-2.5 border-b border-slate-200 dark:border-slate-800`,children:(0,N.jsx)(`h2`,{className:`text-sm font-medium text-slate-900 dark:text-white`,children:`Controls`})}),(0,N.jsxs)(`div`,{className:`p-4 flex items-center gap-4 flex-wrap`,children:[(0,N.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,N.jsx)(`span`,{className:`text-xs text-slate-500 dark:text-slate-400`,children:`Scale:`}),(0,N.jsx)(`input`,{id:`agent-scale-input`,type:`number`,min:1,value:i,onChange:e=>a(e.target.value),className:`w-16 px-2 py-1 bg-white dark:bg-slate-950 border border-slate-300 dark:border-slate-700 rounded text-base text-slate-900 dark:text-slate-200`}),(0,N.jsx)(`button`,{id:`update-agent-scale-btn`,onClick:_,className:`px-2 py-1.5 text-xs font-medium rounded-md bg-blue-600 hover:bg-blue-700 text-white transition-colors`,children:`Set`})]}),m&&(0,N.jsx)(`button`,{id:`toggle-btn`,onClick:()=>g(()=>m.enabled?fr(e):dr(e)),className:`px-3 py-1.5 text-xs font-medium rounded-md transition-colors ${m.enabled?`bg-slate-200 dark:bg-slate-700 text-slate-700 dark:text-slate-300 hover:bg-slate-300 dark:hover:bg-slate-600`:`bg-blue-600 hover:bg-blue-700 text-white`}`,children:m.enabled?`Disable`:`Enable`})]})]}),c&&(0,N.jsxs)(`div`,{className:`bg-slate-50 dark:bg-slate-900 rounded-lg border border-slate-200 dark:border-slate-800 overflow-hidden`,children:[(0,N.jsx)(`div`,{className:`px-4 py-2.5 border-b border-slate-200 dark:border-slate-800`,children:(0,N.jsx)(`h2`,{className:`text-sm font-medium text-slate-900 dark:text-white`,children:`Configuration`})}),(0,N.jsxs)(`div`,{className:`p-4 space-y-4 text-sm`,children:[c.description&&(0,N.jsx)(`p`,{className:`text-slate-700 dark:text-slate-300`,children:c.description}),(0,N.jsxs)(`dl`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-x-6 gap-y-3`,children:[c.schedule&&(0,N.jsxs)(`div`,{children:[(0,N.jsx)(`dt`,{className:`text-xs text-slate-500 dark:text-slate-400 uppercase tracking-wide`,children:`Schedule`}),(0,N.jsx)(`dd`,{className:`mt-0.5`,children:(0,N.jsx)(`code`,{className:`text-xs bg-slate-200 dark:bg-slate-800 px-1.5 py-0.5 rounded font-mono`,children:c.schedule})})]}),c.models&&c.models.length>0&&(0,N.jsxs)(`div`,{children:[(0,N.jsx)(`dt`,{className:`text-xs text-slate-500 dark:text-slate-400 uppercase tracking-wide`,children:`Models`}),(0,N.jsx)(`dd`,{className:`mt-0.5 space-y-0.5`,children:c.models.map((e,t)=>(0,N.jsxs)(`div`,{className:`text-xs text-slate-700 dark:text-slate-300`,children:[e.provider,`/`,e.model,e.thinkingLevel?` (${e.thinkingLevel})`:``,(0,N.jsxs)(`span`,{className:`text-slate-400 dark:text-slate-500 ml-1`,children:[`[`,e.authType,`]`]})]},t))})]}),c.credentials&&c.credentials.length>0&&(0,N.jsxs)(`div`,{children:[(0,N.jsx)(`dt`,{className:`text-xs text-slate-500 dark:text-slate-400 uppercase tracking-wide`,children:`Credentials`}),(0,N.jsx)(`dd`,{className:`mt-0.5 flex flex-wrap gap-1`,children:c.credentials.map(e=>(0,N.jsx)(`span`,{className:`px-1.5 py-0.5 text-xs bg-slate-200 dark:bg-slate-800 rounded font-mono`,children:e},e))})]}),c.hooks&&(c.hooks.pre?.length||c.hooks.post?.length)&&(0,N.jsxs)(`div`,{children:[(0,N.jsx)(`dt`,{className:`text-xs text-slate-500 dark:text-slate-400 uppercase tracking-wide`,children:`Hooks`}),(0,N.jsxs)(`dd`,{className:`mt-0.5 text-xs text-slate-700 dark:text-slate-300`,children:[c.hooks.pre&&c.hooks.pre.length>0&&(0,N.jsxs)(`div`,{children:[`Pre: `,c.hooks.pre.join(`, `)]}),c.hooks.post&&c.hooks.post.length>0&&(0,N.jsxs)(`div`,{children:[`Post: `,c.hooks.post.join(`, `)]})]})]}),c.params&&Object.keys(c.params).length>0&&(0,N.jsxs)(`div`,{className:`sm:col-span-2`,children:[(0,N.jsx)(`dt`,{className:`text-xs text-slate-500 dark:text-slate-400 uppercase tracking-wide`,children:`Params`}),(0,N.jsx)(`dd`,{className:`mt-0.5`,children:(0,N.jsx)(`pre`,{className:`text-xs bg-slate-200 dark:bg-slate-800 p-2 rounded overflow-x-auto`,children:JSON.stringify(c.params,null,2)})})]})]}),c.webhooks&&c.webhooks.length>0&&(0,N.jsxs)(`div`,{children:[(0,N.jsx)(`h3`,{className:`text-xs text-slate-500 dark:text-slate-400 uppercase tracking-wide mb-2`,children:`Webhook Filters`}),(0,N.jsx)(`div`,{className:`space-y-3`,children:c.webhooks.map((e,t)=>(0,N.jsxs)(`div`,{className:`bg-slate-100 dark:bg-slate-800 rounded p-3 text-xs space-y-1`,children:[(0,N.jsx)(`div`,{className:`font-medium text-slate-700 dark:text-slate-300`,children:e.source??`unknown`}),e.events&&e.events.length>0&&(0,N.jsxs)(`div`,{className:`text-slate-600 dark:text-slate-400`,children:[(0,N.jsx)(`span`,{className:`text-slate-500`,children:`events:`}),` `,e.events.map(e=>(0,N.jsx)(`span`,{className:`inline-block mr-1 px-1.5 py-0.5 bg-slate-200 dark:bg-slate-700 rounded font-mono`,children:e},e))]}),e.actions&&e.actions.length>0&&(0,N.jsxs)(`div`,{className:`text-slate-600 dark:text-slate-400`,children:[(0,N.jsx)(`span`,{className:`text-slate-500`,children:`actions:`}),` `,e.actions.join(`, `)]}),e.repos&&e.repos.length>0&&(0,N.jsxs)(`div`,{className:`text-slate-600 dark:text-slate-400`,children:[(0,N.jsx)(`span`,{className:`text-slate-500`,children:`repos:`}),` `,e.repos.join(`, `)]}),(e.org||e.orgs&&e.orgs.length>0)&&(0,N.jsxs)(`div`,{className:`text-slate-600 dark:text-slate-400`,children:[(0,N.jsx)(`span`,{className:`text-slate-500`,children:`orgs:`}),` `,e.org??e.orgs?.join(`, `)]}),e.branches&&e.branches.length>0&&(0,N.jsxs)(`div`,{className:`text-slate-600 dark:text-slate-400`,children:[(0,N.jsx)(`span`,{className:`text-slate-500`,children:`branches:`}),` `,e.branches.join(`, `)]}),e.labels&&e.labels.length>0&&(0,N.jsxs)(`div`,{className:`text-slate-600 dark:text-slate-400`,children:[(0,N.jsx)(`span`,{className:`text-slate-500`,children:`labels:`}),` `,e.labels.join(`, `)]}),e.assignee&&(0,N.jsxs)(`div`,{className:`text-slate-600 dark:text-slate-400`,children:[(0,N.jsx)(`span`,{className:`text-slate-500`,children:`assignee:`}),` `,e.assignee]}),e.author&&(0,N.jsxs)(`div`,{className:`text-slate-600 dark:text-slate-400`,children:[(0,N.jsx)(`span`,{className:`text-slate-500`,children:`author:`}),` `,e.author]})]},t))})]})]})]}),u?(0,N.jsx)(`div`,{className:`bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 rounded-lg p-4 text-sm text-red-700 dark:text-red-400`,children:u}):o===null?(0,N.jsx)(`div`,{className:`bg-slate-50 dark:bg-slate-900 rounded-lg border border-slate-200 dark:border-slate-800 p-8 text-center text-slate-500 dark:text-slate-400`,children:`Loading...`}):(0,N.jsxs)(`div`,{className:`bg-slate-50 dark:bg-slate-900 rounded-lg border border-slate-200 dark:border-slate-800 overflow-hidden`,children:[(0,N.jsx)(`div`,{className:`px-4 py-2.5 border-b border-slate-200 dark:border-slate-800`,children:(0,N.jsx)(`h2`,{className:`text-sm font-medium text-slate-900 dark:text-white`,children:`Skill`})}),(0,N.jsx)(`div`,{className:`p-6`,children:(0,N.jsx)(`div`,{className:`prose prose-slate dark:prose-invert max-w-none text-sm text-slate-700 dark:text-slate-300`,dangerouslySetInnerHTML:{__html:Fi(o)}})})]})]}):null}function Li(e,t,n=[]){let r=(0,x.useRef)(e);r.current=e;let{intervalMs:i,enabled:a=!0}=t;(0,x.useEffect)(()=>{if(!a)return;let e=new AbortController,t=!1,n=()=>{t||(t=!0,r.current(e.signal).catch(()=>{}).finally(()=>{t=!1}))};n();let o=setInterval(n,i);return()=>{clearInterval(o),e.abort()}},[i,a,...n])}function F(e){let t=e.msg||``;return e.text&&(t.includes(`assistant`)||t.includes(`response`))?{text:`${t}: ${e.text}`,className:`text-white font-bold`}:e.cmd||t.includes(`bash`)||t.includes(`command`)?{text:e.cmd?`$ ${e.cmd}`:t,className:`text-cyan-400`}:e.tool||t.includes(`tool`)?{text:e.tool?`[tool] ${e.tool}: ${e.result??``}`:t,className:`text-blue-400`}:e.level>=50||e.err?{text:t,className:`text-red-400`}:e.level>=40?{text:t,className:`text-yellow-400`}:{text:t,className:`text-slate-300`}}function I(){let e=(0,x.useContext)(si),[t,n]=(0,x.useState)([]),[r,i]=(0,x.useState)(!0),[a,o]=(0,x.useState)(!1),s=(0,x.useRef)(null),c=(0,x.useRef)(null),l=e?.name??``,u=e?.id??``,d=e?.isRunning??!1,[f,p]=(0,x.useState)(!1),[m,h]=(0,x.useState)(!0),[g,_]=(0,x.useState)(null),[v,y]=(0,x.useState)(!1),[b,S]=(0,x.useState)(null),{data:C}=ni({key:`instance-locks:${u}`,fetcher:e=>or(e),pollIntervalMs:5e3,enabled:d&&!!e}),w=(C?.locks??[]).filter(e=>e.holder===u||!e.holder&&e.agentName===l);Li(async e=>{if(!l||!u)return;let t={lines:`100`};s.current&&(t.cursor=s.current);try{let r=await sr(l,u,t,e);o(!0),r.entries.length>0&&(n(e=>[...e,...r.entries]),r.cursor&&(s.current=r.cursor))}catch{throw o(!1),void 0}},{intervalMs:d?3e3:1e4,enabled:!!l&&!!u&&!!e},[l,u,d]);let T=(0,x.useRef)(!1);(0,x.useEffect)(()=>{t.length>0&&!T.current&&m&&(T.current=!0,ee())},[t.length,m,ee]),(0,x.useEffect)(()=>{r&&c.current&&(c.current.scrollTop=c.current.scrollHeight)},[t,r]);let E=(0,x.useCallback)(async()=>{if(!(!l||!u)){y(!0),S(null);try{let e=await yr(l,u);e.error?S(e.error):_(e.summary)}catch(e){S(e instanceof Error?e.message:`Failed to summarize`)}finally{y(!1)}}},[l,u]),ee=(0,x.useCallback)(async()=>{if(!(!l||!u||f||!m||t.length===0)){p(!0);try{let e=t[0].time,r=await sr(l,u,{lines:`100`,before:String(e)});if(r.entries.length>0){let e=c.current,t=e?.scrollHeight??0,i=e?.scrollTop??0;n(e=>[...r.entries,...e]),requestAnimationFrame(()=>{e&&(e.scrollTop=i+(e.scrollHeight-t))})}r.entries.length<100&&h(!1)}catch{}finally{p(!1)}}},[l,u,f,m,t]),D=(0,x.useCallback)(()=>{if(!c.current)return;let e=c.current;i(e.scrollHeight-e.scrollTop-e.clientHeight<40),e.scrollTop<100&&m&&!f&&t.length>0&&ee()},[m,f,t.length,ee]);return e?(0,N.jsxs)(`div`,{className:`space-y-4`,children:[w.length>0&&(0,N.jsxs)(`div`,{className:`bg-slate-50 dark:bg-slate-900 rounded-lg border border-slate-200 dark:border-slate-800 overflow-hidden`,children:[(0,N.jsx)(`div`,{className:`px-4 py-2.5 border-b border-slate-200 dark:border-slate-800`,children:(0,N.jsxs)(`h2`,{className:`text-sm font-medium text-slate-900 dark:text-white`,children:[`Resource Locks (`,w.length,`)`]})}),(0,N.jsx)(`div`,{className:`divide-y divide-slate-100 dark:divide-slate-800/50`,children:w.map(e=>(0,N.jsxs)(`div`,{className:`px-4 py-2.5 flex items-center justify-between`,children:[(0,N.jsx)(`span`,{className:`text-sm font-mono text-slate-700 dark:text-slate-300`,children:e.resourceKey}),e.heldSince&&(0,N.jsxs)(`span`,{className:`text-xs text-slate-500 dark:text-slate-400`,children:[`since `,new Date(e.heldSince).toLocaleTimeString()]})]},e.resourceKey))})]}),(0,N.jsxs)(`div`,{className:`bg-slate-50 dark:bg-slate-900 rounded-lg border border-slate-200 dark:border-slate-800 overflow-hidden`,children:[(0,N.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-2.5 border-b border-slate-200 dark:border-slate-800`,children:[(0,N.jsx)(`h2`,{className:`text-sm font-medium text-slate-900 dark:text-white`,children:`Logs`}),(0,N.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,N.jsxs)(`span`,{className:`hidden sm:inline text-xs text-slate-500 dark:text-slate-400`,children:[t.length,` lines`]}),(0,N.jsx)(`span`,{className:`text-xs ${a?`text-green-500`:`text-red-500`}`,children:a?`Connected`:`Disconnected`}),(0,N.jsx)(`button`,{onClick:E,disabled:v||t.length===0,className:`px-2 py-1 text-xs rounded bg-purple-600 hover:bg-purple-700 disabled:opacity-40 disabled:cursor-not-allowed text-white transition-colors`,children:v?(0,N.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,N.jsxs)(`svg`,{className:`w-3 h-3 animate-spin`,viewBox:`0 0 24 24`,fill:`none`,children:[(0,N.jsx)(`circle`,{className:`opacity-25`,cx:`12`,cy:`12`,r:`10`,stroke:`currentColor`,strokeWidth:`4`}),(0,N.jsx)(`path`,{className:`opacity-75`,fill:`currentColor`,d:`M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z`})]}),`Summarizing…`]}):`Summarize`}),(0,N.jsx)(`button`,{onClick:()=>i(e=>!e),className:`px-2 py-1 text-xs rounded transition-colors ${r?`bg-blue-600 text-white`:`bg-slate-200 dark:bg-slate-800 text-slate-700 dark:text-slate-300`}`,children:`Follow`}),(0,N.jsx)(`button`,{onClick:()=>{n([]),s.current=null,h(!0)},className:`px-2 py-1 text-xs rounded bg-slate-200 dark:bg-slate-800 text-slate-700 dark:text-slate-300 hover:bg-slate-300 dark:hover:bg-slate-700 transition-colors`,children:`Clear`})]})]}),(0,N.jsxs)(`div`,{className:`relative`,children:[(g||b)&&(0,N.jsx)(`div`,{className:`absolute inset-x-0 top-0 z-10 p-3 pointer-events-none`,children:(0,N.jsxs)(`div`,{className:`pointer-events-auto`,children:[g&&(0,N.jsx)(`div`,{className:`bg-purple-900/95 border border-purple-700 rounded-lg p-4 text-sm text-purple-100 shadow-lg backdrop-blur-sm`,children:(0,N.jsxs)(`div`,{className:`flex items-start justify-between gap-2`,children:[(0,N.jsxs)(`div`,{children:[(0,N.jsx)(`div`,{className:`text-xs font-medium text-purple-300 mb-1`,children:`Summary`}),(0,N.jsx)(`p`,{className:`leading-relaxed`,children:g})]}),(0,N.jsx)(`button`,{onClick:()=>_(null),className:`text-purple-400 hover:text-purple-200 flex-shrink-0`,children:(0,N.jsx)(`svg`,{className:`w-4 h-4`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,N.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M6 18L18 6M6 6l12 12`})})})]})}),b&&(0,N.jsxs)(`div`,{className:`mt-2 bg-red-900/95 border border-red-700 rounded-lg p-3 text-sm text-red-200 flex items-center justify-between shadow-lg backdrop-blur-sm`,children:[(0,N.jsx)(`span`,{children:b}),(0,N.jsx)(`button`,{onClick:()=>S(null),className:`text-red-400 hover:text-red-200 ml-2`,children:(0,N.jsx)(`svg`,{className:`w-4 h-4`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,N.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M6 18L18 6M6 6l12 12`})})})]})]})}),(0,N.jsxs)(`div`,{ref:c,onScroll:D,className:`min-h-[32rem] max-h-[calc(100vh-16rem)] overflow-y-auto scrollbar-thin bg-slate-950 p-3`,children:[f&&(0,N.jsx)(`div`,{className:`text-xs text-slate-500 text-center py-2`,children:(0,N.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,N.jsxs)(`svg`,{className:`w-3 h-3 animate-spin`,viewBox:`0 0 24 24`,fill:`none`,children:[(0,N.jsx)(`circle`,{className:`opacity-25`,cx:`12`,cy:`12`,r:`10`,stroke:`currentColor`,strokeWidth:`4`}),(0,N.jsx)(`path`,{className:`opacity-75`,fill:`currentColor`,d:`M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z`})]}),`Loading older logs…`]})}),!m&&t.length>0&&(0,N.jsx)(`div`,{className:`text-xs text-slate-600 text-center py-2 border-b border-slate-800 mb-2`,children:`— Beginning of logs —`}),m&&!f&&t.length>0&&(0,N.jsx)(`button`,{className:`w-full text-xs text-blue-400 hover:text-blue-300 text-center py-2 border-b border-slate-800 mb-2 transition-colors`,onClick:ee,children:`↑ Load older logs`}),t.length>0?t.map((e,t)=>{let{text:n,className:r}=F(e);return(0,N.jsxs)(`div`,{className:`text-xs font-mono leading-5`,children:[(0,N.jsx)(`span`,{className:`text-slate-600`,children:new Date(e.time).toLocaleTimeString()}),` `,(0,N.jsx)(`span`,{className:r,children:n})]},t)}):(0,N.jsx)(`div`,{className:`text-xs text-slate-500 text-center py-4`,children:`No log entries`})]})]})]})]}):null}function Ri(e){if(e)try{let t=JSON.parse(e);return t[`content-type`]??t[`Content-Type`]}catch{return}}function zi(e,t){if(!e)return null;let n=Ri(t)?.toLowerCase()??``;if(n.includes(`application/x-www-form-urlencoded`))try{let t=new URLSearchParams(e),n={};for(let[e,r]of t.entries())try{n[e]=JSON.parse(r)}catch{n[e]=r}return{label:`Decoded Body (form-urlencoded)`,content:JSON.stringify(n,null,2)}}catch{}if(n.includes(`application/json`))return null;try{return JSON.parse(e),null}catch{if(/^[A-Za-z0-9+/\n\r]+=*$/.test(e.trim())&&e.trim().length>20)try{let t=atob(e.trim().replace(/\s/g,``));if(/^[\x20-\x7E\t\n\r]*$/.test(t))try{let e=JSON.parse(t);return{label:`Decoded Body (base64)`,content:JSON.stringify(e,null,2)}}catch{return{label:`Decoded Body (base64)`,content:t}}}catch{}}return null}function Bi(e){if(!e)return`—`;try{return JSON.stringify(JSON.parse(e),null,2)}catch{return e}}function Vi(){let e=(0,x.useContext)(si),{agents:t}=Br(),n=t.map(e=>e.name),[r,i]=(0,x.useState)(void 0),a=e?.id,o=e?.detail;if((0,x.useEffect)(()=>{a&&ir(a).then(e=>i(e.trigger)).catch(()=>i(null))},[a]),!e)return null;if(r===void 0)return(0,N.jsx)(`div`,{className:`text-center py-12 text-slate-500 dark:text-slate-400`,children:`Loading...`});if(r===null){let e=o?.run;return e?(0,N.jsx)(`div`,{className:`space-y-4`,children:(0,N.jsxs)(`div`,{className:`bg-slate-50 dark:bg-slate-900 rounded-lg border border-slate-200 dark:border-slate-800 overflow-hidden`,children:[(0,N.jsx)(`div`,{className:`px-4 py-2.5 border-b border-slate-200 dark:border-slate-800`,children:(0,N.jsx)(`h2`,{className:`text-sm font-medium text-slate-900 dark:text-white`,children:`Overview`})}),(0,N.jsxs)(`div`,{className:`divide-y divide-slate-100 dark:divide-slate-800/50 max-w-2xl`,children:[(0,N.jsxs)(`div`,{className:`px-4 py-3 grid grid-cols-[8rem_1fr] gap-x-4 items-center`,children:[(0,N.jsx)(`span`,{className:`text-xs text-slate-500 dark:text-slate-400`,children:`Trigger Type`}),(0,N.jsx)(ai,{type:e.trigger_type})]}),e.trigger_source&&(0,N.jsxs)(`div`,{className:`px-4 py-3 grid grid-cols-[8rem_1fr] gap-x-4 items-center`,children:[(0,N.jsx)(`span`,{className:`text-xs text-slate-500 dark:text-slate-400`,children:`Source`}),(0,N.jsx)(`span`,{className:`text-xs text-slate-700 dark:text-slate-300`,children:e.trigger_source})]})]})]})}):(0,N.jsx)(`div`,{className:`text-center py-12 text-slate-500 dark:text-slate-400`,children:`Trigger details not available.`})}return(0,N.jsxs)(`div`,{className:`space-y-4`,children:[(0,N.jsxs)(`div`,{className:`bg-slate-50 dark:bg-slate-900 rounded-lg border border-slate-200 dark:border-slate-800 overflow-hidden`,children:[(0,N.jsx)(`div`,{className:`px-4 py-2.5 border-b border-slate-200 dark:border-slate-800`,children:(0,N.jsx)(`h2`,{className:`text-sm font-medium text-slate-900 dark:text-white`,children:`Overview`})}),(0,N.jsxs)(`div`,{className:`divide-y divide-slate-100 dark:divide-slate-800/50 max-w-2xl`,children:[(0,N.jsxs)(`div`,{className:`px-4 py-3 grid grid-cols-[8rem_1fr] gap-x-4 items-center`,children:[(0,N.jsx)(`span`,{className:`text-xs text-slate-500 dark:text-slate-400`,children:`Trigger Type`}),(0,N.jsx)(ai,{type:r.triggerType})]}),(0,N.jsxs)(`div`,{className:`px-4 py-3 grid grid-cols-[8rem_1fr] gap-x-4 items-center`,children:[(0,N.jsx)(`span`,{className:`text-xs text-slate-500 dark:text-slate-400`,children:`Agent`}),(0,N.jsx)(M,{to:`/dashboard/agents/${encodeURIComponent(r.agentName)}`,className:`hover:underline text-xs flex items-center gap-1.5`,children:(0,N.jsx)(`span`,{className:`agent-color-text`,style:P(r.agentName,n),children:r.agentName})})]}),(0,N.jsxs)(`div`,{className:`px-4 py-3 grid grid-cols-[8rem_1fr] gap-x-4 items-center`,children:[(0,N.jsx)(`span`,{className:`text-xs text-slate-500 dark:text-slate-400`,children:`Instance`}),(0,N.jsx)(`span`,{className:`font-mono text-xs text-slate-700 dark:text-slate-300`,children:r.instanceId})]}),(0,N.jsxs)(`div`,{className:`px-4 py-3 grid grid-cols-[8rem_1fr] gap-x-4 items-center`,children:[(0,N.jsx)(`span`,{className:`text-xs text-slate-500 dark:text-slate-400`,children:`Time`}),(0,N.jsx)(`span`,{className:`text-xs text-slate-700 dark:text-slate-300`,children:Ci(r.startedAt)})]}),r.triggerSource&&(0,N.jsxs)(`div`,{className:`px-4 py-3 grid grid-cols-[8rem_1fr] gap-x-4 items-center`,children:[(0,N.jsx)(`span`,{className:`text-xs text-slate-500 dark:text-slate-400`,children:`Source`}),(0,N.jsx)(`span`,{className:`text-xs text-slate-700 dark:text-slate-300`,children:r.triggerSource})]})]})]}),r.triggerType===`webhook`&&r.webhook&&(0,N.jsxs)(`div`,{className:`bg-slate-50 dark:bg-slate-900 rounded-lg border border-slate-200 dark:border-slate-800 overflow-hidden`,children:[(0,N.jsx)(`div`,{className:`px-4 py-2.5 border-b border-slate-200 dark:border-slate-800`,children:(0,N.jsx)(`h2`,{className:`text-sm font-medium text-slate-900 dark:text-white`,children:`Webhook Details`})}),(0,N.jsxs)(`div`,{className:`divide-y divide-slate-100 dark:divide-slate-800/50 max-w-2xl`,children:[(0,N.jsxs)(`div`,{className:`px-4 py-3 grid grid-cols-[8rem_1fr] gap-x-4 items-center`,children:[(0,N.jsx)(`span`,{className:`text-xs text-slate-500 dark:text-slate-400`,children:`Receipt ID`}),(0,N.jsx)(M,{to:`/dashboard/webhooks/${encodeURIComponent(r.webhook.receiptId)}`,className:`font-mono text-xs text-blue-600 dark:text-blue-400 hover:underline`,children:Si(r.webhook.receiptId)})]}),(0,N.jsxs)(`div`,{className:`px-4 py-3 grid grid-cols-[8rem_1fr] gap-x-4 items-center`,children:[(0,N.jsx)(`span`,{className:`text-xs text-slate-500 dark:text-slate-400`,children:`Source`}),(0,N.jsx)(`span`,{className:`text-xs text-slate-700 dark:text-slate-300`,children:r.webhook.source})]}),r.webhook.eventSummary&&(0,N.jsxs)(`div`,{className:`px-4 py-3 grid grid-cols-[8rem_1fr] gap-x-4 items-center`,children:[(0,N.jsx)(`span`,{className:`text-xs text-slate-500 dark:text-slate-400`,children:`Event`}),(0,N.jsx)(`span`,{className:`text-xs text-slate-700 dark:text-slate-300`,children:r.webhook.eventSummary})]}),r.webhook.deliveryId&&(0,N.jsxs)(`div`,{className:`px-4 py-3 grid grid-cols-[8rem_1fr] gap-x-4 items-center`,children:[(0,N.jsx)(`span`,{className:`text-xs text-slate-500 dark:text-slate-400`,children:`Delivery ID`}),(0,N.jsx)(`span`,{className:`font-mono text-xs text-slate-700 dark:text-slate-300`,children:r.webhook.deliveryId})]}),(0,N.jsxs)(`div`,{className:`px-4 py-3 grid grid-cols-[8rem_1fr] gap-x-4 items-center`,children:[(0,N.jsx)(`span`,{className:`text-xs text-slate-500 dark:text-slate-400`,children:`Status`}),(0,N.jsx)(oi,{result:r.webhook.status===`processed`?`completed`:`dead-letter`})]}),(0,N.jsxs)(`div`,{className:`px-4 py-3 grid grid-cols-[8rem_1fr] gap-x-4 items-center`,children:[(0,N.jsx)(`span`,{className:`text-xs text-slate-500 dark:text-slate-400`,children:`Matched Agents`}),(0,N.jsx)(`span`,{className:`text-xs text-slate-700 dark:text-slate-300`,children:r.webhook.matchedAgents})]})]}),r.webhook.headers&&(0,N.jsxs)(`div`,{className:`border-t border-slate-200 dark:border-slate-800`,children:[(0,N.jsx)(`div`,{className:`px-4 py-2.5 border-b border-slate-100 dark:border-slate-800/50`,children:(0,N.jsx)(`h3`,{className:`text-xs font-medium text-slate-500 dark:text-slate-400 uppercase tracking-wide`,children:`Headers`})}),(0,N.jsx)(`pre`,{className:`px-4 py-3 text-xs font-mono text-slate-700 dark:text-slate-300 overflow-x-auto whitespace-pre-wrap break-all`,children:Bi(r.webhook.headers)})]}),(()=>{let e=zi(r.webhook.body,r.webhook.headers);return(0,N.jsxs)(N.Fragment,{children:[e&&(0,N.jsxs)(`div`,{className:`border-t border-slate-200 dark:border-slate-800`,children:[(0,N.jsx)(`div`,{className:`px-4 py-2.5 border-b border-slate-100 dark:border-slate-800/50`,children:(0,N.jsx)(`h3`,{className:`text-xs font-medium text-slate-500 dark:text-slate-400 uppercase tracking-wide`,children:e.label})}),(0,N.jsx)(`pre`,{className:`px-4 py-3 text-xs font-mono text-slate-700 dark:text-slate-300 overflow-x-auto whitespace-pre-wrap break-all max-h-96 overflow-y-auto`,children:e.content})]}),r.webhook.body&&(0,N.jsxs)(`div`,{className:`border-t border-slate-200 dark:border-slate-800`,children:[(0,N.jsx)(`div`,{className:`px-4 py-2.5 border-b border-slate-100 dark:border-slate-800/50`,children:(0,N.jsx)(`h3`,{className:`text-xs font-medium text-slate-500 dark:text-slate-400 uppercase tracking-wide`,children:e?`Raw Body`:`Body`})}),(0,N.jsx)(`pre`,{className:`px-4 py-3 text-xs font-mono text-slate-700 dark:text-slate-300 overflow-x-auto whitespace-pre-wrap break-all`,children:Bi(r.webhook.body)})]})]})})()]}),r.triggerType===`agent`&&(0,N.jsxs)(`div`,{className:`bg-slate-50 dark:bg-slate-900 rounded-lg border border-slate-200 dark:border-slate-800 overflow-hidden`,children:[(0,N.jsx)(`div`,{className:`px-4 py-2.5 border-b border-slate-200 dark:border-slate-800`,children:(0,N.jsx)(`h2`,{className:`text-sm font-medium text-slate-900 dark:text-white`,children:`Agent Trigger Details`})}),(0,N.jsx)(`div`,{className:`divide-y divide-slate-100 dark:divide-slate-800/50 max-w-2xl`,children:r.callerAgent?(0,N.jsxs)(N.Fragment,{children:[(0,N.jsxs)(`div`,{className:`px-4 py-3 grid grid-cols-[8rem_1fr] gap-x-4 items-center`,children:[(0,N.jsx)(`span`,{className:`text-xs text-slate-500 dark:text-slate-400`,children:`Called by`}),(0,N.jsx)(M,{to:`/dashboard/agents/${encodeURIComponent(r.callerAgent)}`,className:`hover:underline text-xs flex items-center gap-1.5`,children:(0,N.jsx)(`span`,{className:`agent-color-text`,style:P(r.callerAgent,n),children:r.callerAgent})})]}),r.callerInstance&&(0,N.jsxs)(`div`,{className:`px-4 py-3 grid grid-cols-[8rem_1fr] gap-x-4 items-center`,children:[(0,N.jsx)(`span`,{className:`text-xs text-slate-500 dark:text-slate-400`,children:`Caller Instance`}),(0,N.jsx)(M,{to:`/dashboard/agents/${encodeURIComponent(r.callerAgent)}/instances/${encodeURIComponent(r.callerInstance)}`,className:`font-mono text-xs text-blue-600 dark:text-blue-400 hover:underline`,children:Si(r.callerInstance)})]}),r.callDepth!==void 0&&(0,N.jsxs)(`div`,{className:`px-4 py-3 grid grid-cols-[8rem_1fr] gap-x-4 items-center`,children:[(0,N.jsx)(`span`,{className:`text-xs text-slate-500 dark:text-slate-400`,children:`Call Depth`}),(0,N.jsx)(`span`,{className:`text-xs text-slate-700 dark:text-slate-300`,children:r.callDepth})]})]}):(0,N.jsx)(`div`,{className:`px-4 py-3`,children:(0,N.jsx)(`span`,{className:`text-xs text-slate-500 dark:text-slate-400`,children:`Caller information not available`})})}),r.triggerContext&&(0,N.jsxs)(`div`,{className:`border-t border-slate-200 dark:border-slate-800`,children:[(0,N.jsx)(`div`,{className:`px-4 py-2.5 border-b border-slate-100 dark:border-slate-800/50`,children:(0,N.jsx)(`h3`,{className:`text-xs font-medium text-slate-500 dark:text-slate-400 uppercase tracking-wide`,children:`Trigger Context`})}),(0,N.jsx)(`pre`,{className:`px-4 py-3 text-xs font-mono text-slate-700 dark:text-slate-300 overflow-x-auto whitespace-pre-wrap break-all`,children:r.triggerContext})]})]}),r.triggerType===`manual`&&(0,N.jsxs)(`div`,{className:`bg-slate-50 dark:bg-slate-900 rounded-lg border border-slate-200 dark:border-slate-800 overflow-hidden`,children:[(0,N.jsx)(`div`,{className:`px-4 py-2.5 border-b border-slate-200 dark:border-slate-800`,children:(0,N.jsx)(`h2`,{className:`text-sm font-medium text-slate-900 dark:text-white`,children:`Manual Trigger Details`})}),r.triggerContext?(0,N.jsxs)(`div`,{children:[(0,N.jsx)(`div`,{className:`px-4 py-2.5 border-b border-slate-100 dark:border-slate-800/50`,children:(0,N.jsx)(`h3`,{className:`text-xs font-medium text-slate-500 dark:text-slate-400 uppercase tracking-wide`,children:`Prompt`})}),(0,N.jsx)(`pre`,{className:`px-4 py-3 text-xs font-mono text-slate-700 dark:text-slate-300 overflow-x-auto whitespace-pre-wrap break-all`,children:r.triggerContext})]}):(0,N.jsx)(`div`,{className:`px-4 py-3`,children:(0,N.jsx)(`span`,{className:`text-xs text-slate-500 dark:text-slate-400`,children:`Prompt not available (run predates context tracking)`})})]}),r.triggerType===`schedule`&&(0,N.jsxs)(`div`,{className:`bg-slate-50 dark:bg-slate-900 rounded-lg border border-slate-200 dark:border-slate-800 overflow-hidden`,children:[(0,N.jsx)(`div`,{className:`px-4 py-2.5 border-b border-slate-200 dark:border-slate-800`,children:(0,N.jsx)(`h2`,{className:`text-sm font-medium text-slate-900 dark:text-white`,children:`Schedule Trigger Details`})}),(0,N.jsx)(`div`,{className:`px-4 py-3`,children:(0,N.jsxs)(`span`,{className:`text-xs text-slate-500 dark:text-slate-400`,children:[`Scheduled run at `,Ci(r.startedAt)]})})]})]})}function Hi(){let e=(0,x.useContext)(si);if(!e)return null;let{detail:t,isRunning:n}=e,r=t?.run;return!r&&n?(0,N.jsx)(`div`,{className:`bg-slate-50 dark:bg-slate-900 rounded-lg border border-slate-200 dark:border-slate-800 p-6 text-center`,children:(0,N.jsx)(`p`,{className:`text-sm text-slate-500 dark:text-slate-400`,children:`Instance is currently running. Telemetry data will be available once the run completes.`})}):r?(0,N.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-4`,children:[(0,N.jsxs)(`div`,{className:`bg-slate-50 dark:bg-slate-900 rounded-lg border border-slate-200 dark:border-slate-800 p-4`,children:[(0,N.jsx)(`h2`,{className:`text-sm font-medium text-slate-900 dark:text-white mb-3`,children:`Run Info`}),(0,N.jsxs)(`dl`,{className:`space-y-2 text-sm`,children:[(0,N.jsxs)(`div`,{className:`flex justify-between`,children:[(0,N.jsx)(`dt`,{className:`text-slate-500 dark:text-slate-400`,children:`Status`}),(0,N.jsx)(`dd`,{children:(0,N.jsx)(oi,{result:r.result})})]}),r.exit_code!=null&&(0,N.jsxs)(`div`,{className:`flex justify-between`,children:[(0,N.jsx)(`dt`,{className:`text-slate-500 dark:text-slate-400`,children:`Exit Code`}),(0,N.jsx)(`dd`,{className:r.exit_code===0?`text-green-600 dark:text-green-400`:`text-red-600 dark:text-red-400`,children:r.exit_code})]}),(0,N.jsxs)(`div`,{className:`flex justify-between`,children:[(0,N.jsx)(`dt`,{className:`text-slate-500 dark:text-slate-400`,children:`Started`}),(0,N.jsx)(`dd`,{className:`text-slate-700 dark:text-slate-300`,children:Ci(r.started_at)})]}),(0,N.jsxs)(`div`,{className:`flex justify-between`,children:[(0,N.jsx)(`dt`,{className:`text-slate-500 dark:text-slate-400`,children:`Ended`}),(0,N.jsx)(`dd`,{className:`text-slate-700 dark:text-slate-300`,children:Ci(r.started_at+r.duration_ms)})]}),(0,N.jsxs)(`div`,{className:`flex justify-between`,children:[(0,N.jsx)(`dt`,{className:`text-slate-500 dark:text-slate-400`,children:`Duration`}),(0,N.jsx)(`dd`,{className:`text-slate-700 dark:text-slate-300`,children:yi(r.duration_ms)})]}),(0,N.jsxs)(`div`,{className:`flex justify-between`,children:[(0,N.jsx)(`dt`,{className:`text-slate-500 dark:text-slate-400`,children:`Turns`}),(0,N.jsx)(`dd`,{className:`text-slate-700 dark:text-slate-300`,children:r.turn_count})]}),r.error_message&&(0,N.jsxs)(`div`,{children:[(0,N.jsx)(`dt`,{className:`text-slate-500 dark:text-slate-400 mb-1`,children:`Error`}),(0,N.jsx)(`dd`,{className:`text-red-600 dark:text-red-400 text-xs bg-red-50 dark:bg-red-900/20 rounded p-2 font-mono break-all`,children:r.error_message})]})]})]}),(0,N.jsxs)(`div`,{className:`bg-slate-50 dark:bg-slate-900 rounded-lg border border-slate-200 dark:border-slate-800 p-4`,children:[(0,N.jsx)(`h2`,{className:`text-sm font-medium text-slate-900 dark:text-white mb-3`,children:`Token Usage`}),(0,N.jsxs)(`dl`,{className:`space-y-2 text-sm`,children:[(0,N.jsxs)(`div`,{className:`flex justify-between`,children:[(0,N.jsx)(`dt`,{className:`text-slate-500 dark:text-slate-400`,children:`Input`}),(0,N.jsx)(`dd`,{className:`text-slate-700 dark:text-slate-300`,children:xi(r.input_tokens)})]}),(0,N.jsxs)(`div`,{className:`flex justify-between`,children:[(0,N.jsx)(`dt`,{className:`text-slate-500 dark:text-slate-400`,children:`Output`}),(0,N.jsx)(`dd`,{className:`text-slate-700 dark:text-slate-300`,children:xi(r.output_tokens)})]}),(0,N.jsxs)(`div`,{className:`flex justify-between`,children:[(0,N.jsx)(`dt`,{className:`text-slate-500 dark:text-slate-400`,children:`Cache Read`}),(0,N.jsx)(`dd`,{className:`text-slate-700 dark:text-slate-300`,children:xi(r.cache_read_tokens)})]}),(0,N.jsxs)(`div`,{className:`flex justify-between`,children:[(0,N.jsx)(`dt`,{className:`text-slate-500 dark:text-slate-400`,children:`Cache Write`}),(0,N.jsx)(`dd`,{className:`text-slate-700 dark:text-slate-300`,children:xi(r.cache_write_tokens)})]}),(0,N.jsxs)(`div`,{className:`flex justify-between border-t border-slate-200 dark:border-slate-800 pt-2 mt-2`,children:[(0,N.jsx)(`dt`,{className:`text-slate-500 dark:text-slate-400 font-medium`,children:`Total`}),(0,N.jsx)(`dd`,{className:`text-slate-700 dark:text-slate-300 font-medium`,children:xi(r.total_tokens)})]}),(0,N.jsxs)(`div`,{className:`flex justify-between`,children:[(0,N.jsx)(`dt`,{className:`text-slate-500 dark:text-slate-400 font-medium`,children:`Cost`}),(0,N.jsx)(`dd`,{className:`text-slate-700 dark:text-slate-300 font-medium`,children:bi(r.cost_usd)})]})]})]})]}):null}function Ui({options:e,value:t,onChange:n,placeholder:r}){let[i,a]=(0,x.useState)(!1),o=(0,x.useRef)(null);return(0,x.useEffect)(()=>{let e=e=>{o.current&&!o.current.contains(e.target)&&a(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[]),(0,N.jsxs)(`div`,{ref:o,className:`relative`,children:[(0,N.jsxs)(`button`,{type:`button`,onClick:()=>a(!i),className:`inline-flex items-center gap-1.5 text-sm rounded-lg border border-slate-200 dark:border-slate-700 bg-white dark:bg-slate-800 text-slate-700 dark:text-slate-200 pl-3 pr-2 py-1.5 hover:border-slate-300 dark:hover:border-slate-600 transition-colors shadow-sm`,children:[(0,N.jsx)(`span`,{children:e.find(e=>e.value===t)?.label||r}),(0,N.jsx)(Gi,{})]}),i&&(0,N.jsx)(`div`,{className:`absolute z-50 mt-1 min-w-[160px] rounded-lg border border-slate-200 dark:border-slate-700 bg-white dark:bg-slate-800 shadow-lg py-1 max-h-64 overflow-y-auto`,children:e.map(e=>(0,N.jsx)(`button`,{type:`button`,onClick:()=>{n(e.value),a(!1)},className:`w-full text-left px-3 py-1.5 text-sm transition-colors ${e.value===t?`bg-blue-50 dark:bg-blue-900/30 text-blue-700 dark:text-blue-300 font-medium`:`text-slate-700 dark:text-slate-300 hover:bg-slate-50 dark:hover:bg-slate-700/50`}`,children:e.label},e.value))})]})}function Wi({options:e,selected:t,onChange:n,label:r}){let[i,a]=(0,x.useState)(!1),o=(0,x.useRef)(null);(0,x.useEffect)(()=>{let e=e=>{o.current&&!o.current.contains(e.target)&&a(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[]);let s=t.length===e.length,c=t.length===0,l=e=>{t.includes(e)?n(t.filter(t=>t!==e)):n([...t,e])},u=()=>{n(s?[]:e.map(e=>e.value))},d=s||c?r:t.length===1?e.find(e=>e.value===t[0])?.label??r:`${t.length} selected`;return(0,N.jsxs)(`div`,{ref:o,className:`relative`,children:[(0,N.jsxs)(`button`,{type:`button`,onClick:()=>a(!i),className:`inline-flex items-center gap-1.5 text-sm rounded-lg border border-slate-200 dark:border-slate-700 bg-white dark:bg-slate-800 text-slate-700 dark:text-slate-200 pl-3 pr-2 py-1.5 hover:border-slate-300 dark:hover:border-slate-600 transition-colors shadow-sm`,children:[!s&&!c&&(0,N.jsx)(`span`,{className:`inline-flex items-center justify-center w-4 h-4 rounded-full bg-blue-600 text-white text-[10px] font-bold leading-none`,children:t.length}),(0,N.jsx)(`span`,{children:d}),(0,N.jsx)(Gi,{})]}),i&&(0,N.jsxs)(`div`,{className:`absolute z-50 mt-1 min-w-[180px] rounded-lg border border-slate-200 dark:border-slate-700 bg-white dark:bg-slate-800 shadow-lg py-1 max-h-64 overflow-y-auto`,children:[(0,N.jsx)(`button`,{type:`button`,onClick:u,className:`w-full text-left px-3 py-1.5 text-xs font-medium text-slate-500 dark:text-slate-400 hover:bg-slate-50 dark:hover:bg-slate-700/50 transition-colors border-b border-slate-100 dark:border-slate-700`,children:s?`Deselect all`:`Select all`}),e.map(e=>{let n=t.includes(e.value);return(0,N.jsxs)(`button`,{type:`button`,onClick:()=>l(e.value),className:`w-full text-left px-3 py-1.5 text-sm flex items-center gap-2 transition-colors ${n?`text-slate-900 dark:text-white`:`text-slate-500 dark:text-slate-400 hover:bg-slate-50 dark:hover:bg-slate-700/50`}`,children:[(0,N.jsx)(`span`,{className:`flex items-center justify-center w-3.5 h-3.5 rounded border transition-colors ${n?`bg-blue-600 border-blue-600`:`border-slate-300 dark:border-slate-600`}`,children:n&&(0,N.jsx)(`svg`,{className:`w-2.5 h-2.5 text-white`,viewBox:`0 0 12 12`,fill:`none`,children:(0,N.jsx)(`path`,{d:`M2 6l3 3 5-5`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`})})}),e.dot&&(0,N.jsx)(`span`,{className:`w-2 h-2 rounded-full shrink-0 ${e.dot}`}),(0,N.jsx)(`span`,{children:e.label})]},e.value)})]})]})}function Gi(){return(0,N.jsx)(`svg`,{className:`w-4 h-4 text-slate-400`,viewBox:`0 0 20 20`,fill:`currentColor`,children:(0,N.jsx)(`path`,{fillRule:`evenodd`,d:`M5.23 7.21a.75.75 0 011.06.02L10 11.168l3.71-3.938a.75.75 0 111.08 1.04l-4.25 4.5a.75.75 0 01-1.08 0l-4.25-4.5a.75.75 0 01.02-1.06z`,clipRule:`evenodd`})})}var Ki=50,qi=[`pending`,`running`,`completed`],Ji=[{value:`pending`,label:`Pending`,dot:`bg-amber-400`},{value:`running`,label:`Running`,dot:`bg-blue-500`},{value:`completed`,label:`Completed`,dot:`bg-green-500`},{value:`error`,label:`Error`,dot:`bg-red-500`},{value:`dead-letter`,label:`Dead Letter`,dot:`bg-red-300 dark:bg-red-800`}],Yi=[{value:``,label:`All Types`},{value:`schedule`,label:`Schedule`},{value:`webhook`,label:`Webhook`},{value:`manual`,label:`Manual`},{value:`agent`,label:`Agent`}];function Xi(e){if(!e)return qi;let t=e.split(`,`).filter(Boolean);return t.length>0?t:qi}function Zi(){let[e,t]=Ln(),n=e.get(`agent`)||void 0,r=e.get(`type`)||void 0,i=e.get(`status`),a=(0,x.useMemo)(()=>Xi(i),[i]),[o,s]=(0,x.useState)(0),c=Nr(),l=c.map(e=>e.name),u=a.join(`,`),d=a.length===Ji.length?void 0:a,{data:f,isLoading:p}=ni({key:`activity:${o}:${n??``}:${r??``}:${u}`,fetcher:e=>rr(Ki,o,n,r,d,e),invalidateOn:[`runs`,`triggers`],keyChangeDebounceMs:150}),m=f?.rows??[],h=f?.total??0,g=f?.pendingCount??0;(0,x.useEffect)(()=>{s(0)},[n,r,u]);let _=(0,x.useCallback)((e,n)=>{t(t=>{let r=new URLSearchParams(t);return n?r.set(e,n):r.delete(e),r.delete(`offset`),r})},[t]),v=(0,x.useCallback)(e=>{t(t=>{let n=new URLSearchParams(t);return e.length===0||e.length===Ji.length?n.delete(`status`):n.set(`status`,e.join(`,`)),n.delete(`offset`),n})},[t]),y=Math.floor(o/Ki)+1,b=Math.max(1,Math.ceil(h/Ki)),S=[{value:``,label:`All Agents`},...c.map(e=>({value:e.name,label:e.name}))];return(0,N.jsxs)(`div`,{className:`space-y-6`,children:[(0,N.jsxs)(`div`,{className:`flex items-center justify-between flex-wrap gap-3`,children:[(0,N.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,N.jsx)(`h1`,{className:`text-xl font-bold text-slate-900 dark:text-white`,children:`Activity`}),g>0&&(0,N.jsxs)(`span`,{className:`inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium bg-amber-100 text-amber-700 dark:bg-amber-900/40 dark:text-amber-400`,children:[g,` pending`]})]}),(0,N.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,N.jsx)(Ui,{options:S,value:n||``,onChange:e=>_(`agent`,e||void 0),placeholder:`All Agents`}),(0,N.jsx)(Ui,{options:Yi,value:r||``,onChange:e=>_(`type`,e||void 0),placeholder:`All Types`}),(0,N.jsx)(Wi,{options:Ji,selected:a,onChange:v,label:`All Statuses`})]})]}),(0,N.jsxs)(`div`,{className:`bg-slate-50 dark:bg-slate-900 rounded-lg border border-slate-200 dark:border-slate-800 overflow-hidden`,children:[(0,N.jsx)(`div`,{className:`overflow-x-auto`,children:(0,N.jsx)(ji,{rows:m,agentNames:l,loading:p&&m.length===0})}),b>1&&(0,N.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-2.5 border-t border-slate-200 dark:border-slate-800`,children:[(0,N.jsx)(`button`,{onClick:()=>s(Math.max(0,o-Ki)),disabled:o===0,className:`px-3 py-1 text-xs rounded bg-slate-200 dark:bg-slate-800 text-slate-700 dark:text-slate-300 hover:bg-slate-300 dark:hover:bg-slate-700 disabled:opacity-40 transition-colors`,children:`Previous`}),(0,N.jsxs)(`span`,{className:`text-xs text-slate-500 dark:text-slate-400`,children:[`Page `,y,` of `,b,` (`,h,` total)`]}),(0,N.jsx)(`button`,{onClick:()=>s(o+Ki),disabled:o+Ki>=h,className:`px-3 py-1 text-xs rounded bg-slate-200 dark:bg-slate-800 text-slate-700 dark:text-slate-300 hover:bg-slate-300 dark:hover:bg-slate-700 disabled:opacity-40 transition-colors`,children:`Next`})]})]})]})}function Qi(e){if(!e)return`—`;try{return JSON.stringify(JSON.parse(e),null,2)}catch{return e}}function $i(){let{instanceId:e}=dt(),{agents:t}=Br(),n=t.map(e=>e.name),[r,i]=(0,x.useState)(void 0),[a,o]=(0,x.useState)(null),[s,c]=(0,x.useState)(null),[l,u]=(0,x.useState)(!1);(0,x.useEffect)(()=>{e&&ir(e).then(e=>i(e.trigger)).catch(()=>i(null))},[e]);let d=(0,x.useCallback)(async()=>{if(r?.webhook?.receiptId){o(null),c(null),u(!0);try{let e=await nr(r.webhook.receiptId);o(`Replayed: ${e.matched} matched, ${e.skipped} skipped`)}catch(e){c(e instanceof Error?e.message:`Replay failed`)}finally{u(!1)}}},[r]);if(!e)return null;if(r===void 0)return(0,N.jsx)(`div`,{className:`text-center py-12 text-slate-500 dark:text-slate-400`,children:`Loading...`});if(r===null)return(0,N.jsx)(`div`,{className:`space-y-6`,children:(0,N.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,N.jsx)(M,{to:`/jobs`,className:`text-slate-500 hover:text-slate-700 dark:hover:text-slate-300`,children:(0,N.jsx)(`svg`,{className:`w-5 h-5`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,N.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M15 19l-7-7 7-7`})})}),(0,N.jsx)(`h1`,{className:`text-xl font-bold text-slate-900 dark:text-white`,children:`Trigger not found`})]})});let f=!!(r.webhook?.receiptId&&(r.webhook.headers||r.webhook.body));return(0,N.jsxs)(`div`,{className:`space-y-6`,children:[(0,N.jsxs)(`div`,{className:`flex items-center justify-between flex-wrap gap-3`,children:[(0,N.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,N.jsx)(M,{to:`/jobs`,className:`text-slate-500 hover:text-slate-700 dark:hover:text-slate-300`,children:(0,N.jsx)(`svg`,{className:`w-5 h-5`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,N.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M15 19l-7-7 7-7`})})}),(0,N.jsxs)(`div`,{children:[(0,N.jsx)(`h1`,{className:`text-xl font-bold text-slate-900 dark:text-white font-mono`,children:r.instanceId}),(0,N.jsx)(`div`,{className:`text-xs text-slate-500 dark:text-slate-400`,children:`Trigger Detail`})]}),(0,N.jsx)(ai,{type:r.triggerType})]}),r.triggerType===`webhook`&&f&&(0,N.jsxs)(`div`,{className:`flex items-center gap-2`,children:[a&&(0,N.jsx)(`span`,{className:`text-xs text-green-600 dark:text-green-400`,children:a}),s&&(0,N.jsx)(`span`,{className:`text-xs text-red-600 dark:text-red-400`,children:s}),(0,N.jsx)(`button`,{onClick:d,disabled:l,className:`px-3 py-1.5 text-xs font-medium rounded-md bg-blue-600 hover:bg-blue-700 disabled:opacity-40 text-white transition-colors`,children:l?`Replaying...`:`Replay`})]})]}),(0,N.jsxs)(`div`,{className:`bg-slate-50 dark:bg-slate-900 rounded-lg border border-slate-200 dark:border-slate-800 overflow-hidden`,children:[(0,N.jsx)(`div`,{className:`px-4 py-2.5 border-b border-slate-200 dark:border-slate-800`,children:(0,N.jsx)(`h2`,{className:`text-sm font-medium text-slate-900 dark:text-white`,children:`Overview`})}),(0,N.jsxs)(`div`,{className:`divide-y divide-slate-100 dark:divide-slate-800/50 max-w-2xl`,children:[(0,N.jsxs)(`div`,{className:`px-4 py-3 grid grid-cols-[8rem_1fr] gap-x-4 items-center`,children:[(0,N.jsx)(`span`,{className:`text-xs text-slate-500 dark:text-slate-400`,children:`Trigger Type`}),(0,N.jsx)(ai,{type:r.triggerType})]}),(0,N.jsxs)(`div`,{className:`px-4 py-3 grid grid-cols-[8rem_1fr] gap-x-4 items-center`,children:[(0,N.jsx)(`span`,{className:`text-xs text-slate-500 dark:text-slate-400`,children:`Agent`}),(0,N.jsx)(M,{to:`/dashboard/agents/${encodeURIComponent(r.agentName)}`,className:`hover:underline text-xs flex items-center gap-1.5`,children:(0,N.jsx)(`span`,{className:`agent-color-text`,style:P(r.agentName,n),children:r.agentName})})]}),(0,N.jsxs)(`div`,{className:`px-4 py-3 grid grid-cols-[8rem_1fr] gap-x-4 items-center`,children:[(0,N.jsx)(`span`,{className:`text-xs text-slate-500 dark:text-slate-400`,children:`Instance`}),(0,N.jsx)(M,{to:`/dashboard/agents/${encodeURIComponent(r.agentName)}/instances/${encodeURIComponent(r.instanceId)}`,className:`font-mono text-xs text-blue-600 dark:text-blue-400 hover:underline`,children:r.instanceId})]}),(0,N.jsxs)(`div`,{className:`px-4 py-3 grid grid-cols-[8rem_1fr] gap-x-4 items-center`,children:[(0,N.jsx)(`span`,{className:`text-xs text-slate-500 dark:text-slate-400`,children:`Time`}),(0,N.jsx)(`span`,{className:`text-xs text-slate-700 dark:text-slate-300`,children:Ci(r.startedAt)})]}),r.triggerSource&&(0,N.jsxs)(`div`,{className:`px-4 py-3 grid grid-cols-[8rem_1fr] gap-x-4 items-center`,children:[(0,N.jsx)(`span`,{className:`text-xs text-slate-500 dark:text-slate-400`,children:`Source`}),(0,N.jsx)(`span`,{className:`text-xs text-slate-700 dark:text-slate-300`,children:r.triggerSource})]})]})]}),r.triggerType===`webhook`&&r.webhook&&(0,N.jsxs)(`div`,{className:`bg-slate-50 dark:bg-slate-900 rounded-lg border border-slate-200 dark:border-slate-800 overflow-hidden`,children:[(0,N.jsx)(`div`,{className:`px-4 py-2.5 border-b border-slate-200 dark:border-slate-800`,children:(0,N.jsx)(`h2`,{className:`text-sm font-medium text-slate-900 dark:text-white`,children:`Webhook Details`})}),(0,N.jsxs)(`div`,{className:`divide-y divide-slate-100 dark:divide-slate-800/50 max-w-2xl`,children:[(0,N.jsxs)(`div`,{className:`px-4 py-3 grid grid-cols-[8rem_1fr] gap-x-4 items-center`,children:[(0,N.jsx)(`span`,{className:`text-xs text-slate-500 dark:text-slate-400`,children:`Receipt ID`}),(0,N.jsx)(M,{to:`/dashboard/webhooks/${encodeURIComponent(r.webhook.receiptId)}`,className:`font-mono text-xs text-blue-600 dark:text-blue-400 hover:underline`,children:Si(r.webhook.receiptId)})]}),(0,N.jsxs)(`div`,{className:`px-4 py-3 grid grid-cols-[8rem_1fr] gap-x-4 items-center`,children:[(0,N.jsx)(`span`,{className:`text-xs text-slate-500 dark:text-slate-400`,children:`Source`}),(0,N.jsx)(`span`,{className:`text-xs text-slate-700 dark:text-slate-300`,children:r.webhook.source})]}),r.webhook.eventSummary&&(0,N.jsxs)(`div`,{className:`px-4 py-3 grid grid-cols-[8rem_1fr] gap-x-4 items-center`,children:[(0,N.jsx)(`span`,{className:`text-xs text-slate-500 dark:text-slate-400`,children:`Event`}),(0,N.jsx)(`span`,{className:`text-xs text-slate-700 dark:text-slate-300`,children:r.webhook.eventSummary})]}),r.webhook.deliveryId&&(0,N.jsxs)(`div`,{className:`px-4 py-3 grid grid-cols-[8rem_1fr] gap-x-4 items-center`,children:[(0,N.jsx)(`span`,{className:`text-xs text-slate-500 dark:text-slate-400`,children:`Delivery ID`}),(0,N.jsx)(`span`,{className:`font-mono text-xs text-slate-700 dark:text-slate-300`,children:r.webhook.deliveryId})]}),(0,N.jsxs)(`div`,{className:`px-4 py-3 grid grid-cols-[8rem_1fr] gap-x-4 items-center`,children:[(0,N.jsx)(`span`,{className:`text-xs text-slate-500 dark:text-slate-400`,children:`Status`}),(0,N.jsx)(oi,{result:r.webhook.status===`processed`?`completed`:`dead-letter`})]}),(0,N.jsxs)(`div`,{className:`px-4 py-3 grid grid-cols-[8rem_1fr] gap-x-4 items-center`,children:[(0,N.jsx)(`span`,{className:`text-xs text-slate-500 dark:text-slate-400`,children:`Matched Agents`}),(0,N.jsx)(`span`,{className:`text-xs text-slate-700 dark:text-slate-300`,children:r.webhook.matchedAgents})]})]}),r.webhook.headers&&(0,N.jsxs)(`div`,{className:`border-t border-slate-200 dark:border-slate-800`,children:[(0,N.jsx)(`div`,{className:`px-4 py-2.5 border-b border-slate-100 dark:border-slate-800/50`,children:(0,N.jsx)(`h3`,{className:`text-xs font-medium text-slate-500 dark:text-slate-400 uppercase tracking-wide`,children:`Headers`})}),(0,N.jsx)(`pre`,{className:`px-4 py-3 text-xs font-mono text-slate-700 dark:text-slate-300 overflow-x-auto whitespace-pre-wrap break-all`,children:Qi(r.webhook.headers)})]}),(()=>{let e=zi(r.webhook.body,r.webhook.headers);return(0,N.jsxs)(N.Fragment,{children:[e&&(0,N.jsxs)(`div`,{className:`border-t border-slate-200 dark:border-slate-800`,children:[(0,N.jsx)(`div`,{className:`px-4 py-2.5 border-b border-slate-100 dark:border-slate-800/50`,children:(0,N.jsx)(`h3`,{className:`text-xs font-medium text-slate-500 dark:text-slate-400 uppercase tracking-wide`,children:e.label})}),(0,N.jsx)(`pre`,{className:`px-4 py-3 text-xs font-mono text-slate-700 dark:text-slate-300 overflow-x-auto whitespace-pre-wrap break-all max-h-96 overflow-y-auto`,children:e.content})]}),r.webhook.body&&(0,N.jsxs)(`div`,{className:`border-t border-slate-200 dark:border-slate-800`,children:[(0,N.jsx)(`div`,{className:`px-4 py-2.5 border-b border-slate-100 dark:border-slate-800/50`,children:(0,N.jsx)(`h3`,{className:`text-xs font-medium text-slate-500 dark:text-slate-400 uppercase tracking-wide`,children:e?`Raw Body`:`Body`})}),(0,N.jsx)(`pre`,{className:`px-4 py-3 text-xs font-mono text-slate-700 dark:text-slate-300 overflow-x-auto whitespace-pre-wrap break-all`,children:Qi(r.webhook.body)})]})]})})()]}),r.triggerType===`agent`&&(0,N.jsxs)(`div`,{className:`bg-slate-50 dark:bg-slate-900 rounded-lg border border-slate-200 dark:border-slate-800 overflow-hidden`,children:[(0,N.jsx)(`div`,{className:`px-4 py-2.5 border-b border-slate-200 dark:border-slate-800`,children:(0,N.jsx)(`h2`,{className:`text-sm font-medium text-slate-900 dark:text-white`,children:`Agent Trigger Details`})}),(0,N.jsx)(`div`,{className:`divide-y divide-slate-100 dark:divide-slate-800/50 max-w-2xl`,children:r.callerAgent?(0,N.jsxs)(N.Fragment,{children:[(0,N.jsxs)(`div`,{className:`px-4 py-3 grid grid-cols-[8rem_1fr] gap-x-4 items-center`,children:[(0,N.jsx)(`span`,{className:`text-xs text-slate-500 dark:text-slate-400`,children:`Called by`}),(0,N.jsx)(M,{to:`/dashboard/agents/${encodeURIComponent(r.callerAgent)}`,className:`hover:underline text-xs flex items-center gap-1.5`,children:(0,N.jsx)(`span`,{className:`agent-color-text`,style:P(r.callerAgent,n),children:r.callerAgent})})]}),r.callerInstance&&(0,N.jsxs)(`div`,{className:`px-4 py-3 grid grid-cols-[8rem_1fr] gap-x-4 items-center`,children:[(0,N.jsx)(`span`,{className:`text-xs text-slate-500 dark:text-slate-400`,children:`Caller Instance`}),(0,N.jsx)(M,{to:`/dashboard/agents/${encodeURIComponent(r.callerAgent)}/instances/${encodeURIComponent(r.callerInstance)}`,className:`font-mono text-xs text-blue-600 dark:text-blue-400 hover:underline`,children:Si(r.callerInstance)})]}),r.callDepth!==void 0&&(0,N.jsxs)(`div`,{className:`px-4 py-3 grid grid-cols-[8rem_1fr] gap-x-4 items-center`,children:[(0,N.jsx)(`span`,{className:`text-xs text-slate-500 dark:text-slate-400`,children:`Call Depth`}),(0,N.jsx)(`span`,{className:`text-xs text-slate-700 dark:text-slate-300`,children:r.callDepth})]})]}):(0,N.jsx)(`div`,{className:`px-4 py-3`,children:(0,N.jsx)(`span`,{className:`text-xs text-slate-500 dark:text-slate-400`,children:`Caller information not available`})})}),r.triggerContext&&(0,N.jsxs)(`div`,{className:`border-t border-slate-200 dark:border-slate-800`,children:[(0,N.jsx)(`div`,{className:`px-4 py-2.5 border-b border-slate-100 dark:border-slate-800/50`,children:(0,N.jsx)(`h3`,{className:`text-xs font-medium text-slate-500 dark:text-slate-400 uppercase tracking-wide`,children:`Trigger Context`})}),(0,N.jsx)(`pre`,{className:`px-4 py-3 text-xs font-mono text-slate-700 dark:text-slate-300 overflow-x-auto whitespace-pre-wrap break-all`,children:r.triggerContext})]})]}),r.triggerType===`manual`&&(0,N.jsxs)(`div`,{className:`bg-slate-50 dark:bg-slate-900 rounded-lg border border-slate-200 dark:border-slate-800 overflow-hidden`,children:[(0,N.jsx)(`div`,{className:`px-4 py-2.5 border-b border-slate-200 dark:border-slate-800`,children:(0,N.jsx)(`h2`,{className:`text-sm font-medium text-slate-900 dark:text-white`,children:`Manual Trigger Details`})}),r.triggerContext?(0,N.jsxs)(`div`,{children:[(0,N.jsx)(`div`,{className:`px-4 py-2.5 border-b border-slate-100 dark:border-slate-800/50`,children:(0,N.jsx)(`h3`,{className:`text-xs font-medium text-slate-500 dark:text-slate-400 uppercase tracking-wide`,children:`Prompt`})}),(0,N.jsx)(`pre`,{className:`px-4 py-3 text-xs font-mono text-slate-700 dark:text-slate-300 overflow-x-auto whitespace-pre-wrap break-all`,children:r.triggerContext})]}):(0,N.jsx)(`div`,{className:`px-4 py-3`,children:(0,N.jsx)(`span`,{className:`text-xs text-slate-500 dark:text-slate-400`,children:`Prompt not available (run predates context tracking)`})})]}),r.triggerType===`schedule`&&(0,N.jsxs)(`div`,{className:`bg-slate-50 dark:bg-slate-900 rounded-lg border border-slate-200 dark:border-slate-800 overflow-hidden`,children:[(0,N.jsx)(`div`,{className:`px-4 py-2.5 border-b border-slate-200 dark:border-slate-800`,children:(0,N.jsx)(`h2`,{className:`text-sm font-medium text-slate-900 dark:text-white`,children:`Schedule Trigger Details`})}),(0,N.jsx)(`div`,{className:`px-4 py-3`,children:(0,N.jsxs)(`span`,{className:`text-xs text-slate-500 dark:text-slate-400`,children:[`Scheduled run at `,Ci(r.startedAt)]})})]}),(0,N.jsx)(`div`,{className:`flex justify-end`,children:(0,N.jsx)(M,{to:`/dashboard/agents/${encodeURIComponent(r.agentName)}/instances/${encodeURIComponent(r.instanceId)}`,className:`text-sm text-blue-600 dark:text-blue-400 hover:underline`,children:`View run details →`})})]})}function ea(){let e=Pr(),{data:t}=ni({key:`project-config`,fetcher:e=>er(e),invalidateOn:[`config`]}),[n,r]=(0,x.useState)(``),[i,a]=(0,x.useState)(null),[o,s]=(0,x.useState)(null);(0,x.useEffect)(()=>{t&&r(String(t.projectScale))},[t]);let c=(0,x.useCallback)(async(e,t)=>{a(null),s(null);try{await e(),t&&s(t)}catch(e){a(e instanceof Error?e.message:`Action failed`)}},[]),l=(0,x.useCallback)(()=>{let e=parseInt(n,10);isNaN(e)||e<1||c(()=>hr(e),`Scale updated`)},[n,c]);return(0,N.jsxs)(`div`,{className:`space-y-6`,children:[(0,N.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,N.jsx)(M,{to:`/dashboard`,className:`text-slate-500 hover:text-slate-700 dark:hover:text-slate-300`,children:(0,N.jsx)(`svg`,{className:`w-5 h-5`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,N.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M15 19l-7-7 7-7`})})}),(0,N.jsx)(`h1`,{className:`text-xl font-bold text-slate-900 dark:text-white`,children:`Project Configuration`})]}),i&&(0,N.jsx)(`div`,{className:`bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 rounded-lg p-3 text-sm text-red-700 dark:text-red-400`,children:i}),o&&(0,N.jsx)(`div`,{className:`bg-green-50 dark:bg-green-900/20 border border-green-200 dark:border-green-800 rounded-lg p-3 text-sm text-green-700 dark:text-green-400`,children:o}),(0,N.jsxs)(`div`,{className:`bg-slate-50 dark:bg-slate-900 rounded-lg border border-slate-200 dark:border-slate-800 p-4`,children:[(0,N.jsx)(`h2`,{className:`text-sm font-medium text-slate-900 dark:text-white mb-3`,children:`Project Scale`}),(0,N.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,N.jsx)(`label`,{htmlFor:`project-scale`,className:`text-sm text-slate-500 dark:text-slate-400`,children:`Default scale:`}),(0,N.jsx)(`input`,{id:`project-scale`,type:`number`,min:1,value:n,onChange:e=>r(e.target.value),className:`w-20 px-2 py-1.5 bg-white dark:bg-slate-950 border border-slate-300 dark:border-slate-700 rounded text-base text-slate-900 dark:text-slate-200`}),(0,N.jsx)(`button`,{onClick:l,className:`px-3 py-1.5 text-xs font-medium rounded-md bg-blue-600 hover:bg-blue-700 text-white transition-colors`,children:`Update`})]}),(0,N.jsx)(`p`,{className:`text-xs text-slate-500 dark:text-slate-400 mt-2`,children:`The default number of concurrent instances per agent. Individual agents can override this in their SKILL.md config.`})]}),(0,N.jsxs)(`div`,{className:`bg-slate-50 dark:bg-slate-900 rounded-lg border border-slate-200 dark:border-slate-800 p-4`,children:[(0,N.jsx)(`h2`,{className:`text-sm font-medium text-slate-900 dark:text-white mb-3`,children:`Gateway Status`}),t?(0,N.jsxs)(`dl`,{className:`space-y-2 text-sm`,children:[t.projectName&&(0,N.jsxs)(`div`,{className:`flex justify-between`,children:[(0,N.jsx)(`dt`,{className:`text-slate-500 dark:text-slate-400`,children:`Project`}),(0,N.jsx)(`dd`,{className:`text-slate-700 dark:text-slate-300`,children:t.projectName})]}),t.gatewayPort!=null&&(0,N.jsxs)(`div`,{className:`flex justify-between`,children:[(0,N.jsx)(`dt`,{className:`text-slate-500 dark:text-slate-400`,children:`Port`}),(0,N.jsx)(`dd`,{className:`text-slate-700 dark:text-slate-300 font-mono`,children:t.gatewayPort})]}),(0,N.jsxs)(`div`,{className:`flex justify-between`,children:[(0,N.jsx)(`dt`,{className:`text-slate-500 dark:text-slate-400`,children:`Webhooks`}),(0,N.jsx)(`dd`,{children:t.webhooksActive?(0,N.jsx)(`span`,{className:`text-green-600 dark:text-green-400 text-xs font-medium`,children:`Active`}):(0,N.jsx)(`span`,{className:`text-slate-500 text-xs`,children:`Inactive`})})]})]}):(0,N.jsx)(`p`,{className:`text-sm text-slate-500 dark:text-slate-400`,children:`Loading...`})]}),(0,N.jsxs)(`div`,{className:`bg-slate-50 dark:bg-slate-900 rounded-lg border border-slate-200 dark:border-slate-800 p-4`,children:[(0,N.jsx)(`h2`,{className:`text-sm font-medium text-slate-900 dark:text-white mb-3`,children:`Scheduler Control`}),e?(0,N.jsxs)(`div`,{className:`space-y-3`,children:[(0,N.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,N.jsx)(`span`,{className:`text-slate-500 dark:text-slate-400`,children:`Status:`}),e.paused?(0,N.jsx)(`span`,{className:`text-yellow-600 dark:text-yellow-400 font-medium`,children:`Paused`}):(0,N.jsx)(`span`,{className:`text-green-600 dark:text-green-400 font-medium`,children:`Running`})]}),(0,N.jsx)(`div`,{className:`flex items-center gap-2`,children:e.paused?(0,N.jsx)(`button`,{onClick:()=>c(mr,`Scheduler resumed`),className:`px-4 py-2 text-sm font-medium rounded-md bg-green-600 hover:bg-green-700 text-white transition-colors`,children:`Resume All`}):(0,N.jsx)(`button`,{onClick:()=>c(pr,`Scheduler paused`),className:`px-4 py-2 text-sm font-medium rounded-md bg-yellow-600 hover:bg-yellow-700 text-white transition-colors`,children:`Pause All`})}),(0,N.jsx)(`p`,{className:`text-xs text-slate-500 dark:text-slate-400`,children:`Pausing prevents new scheduled and webhook-triggered runs from starting. Running instances are not affected.`})]}):(0,N.jsx)(`p`,{className:`text-sm text-slate-500 dark:text-slate-400`,children:`Connecting to scheduler...`})]})]})}function ta({label:e,value:t,id:n}){return(0,N.jsxs)(`div`,{className:`bg-slate-50 dark:bg-slate-900 rounded-lg border border-slate-200 dark:border-slate-800 p-3 sm:p-4`,children:[(0,N.jsx)(`div`,{className:`text-xs text-slate-500 dark:text-slate-400 uppercase tracking-wide mb-1`,children:e}),(0,N.jsx)(`div`,{className:`text-lg sm:text-xl font-semibold text-slate-900 dark:text-white`,id:n,children:t})]})}function na(){let{name:e}=dt(),{data:t}=ni({key:`agent-stats:${e}`,fetcher:t=>Qn(e,t),invalidateOn:[`stats`],invalidateAgent:e,enabled:!!e});if(!e)return null;let n=t?.summary;return(0,N.jsx)(`div`,{className:`space-y-6`,children:n&&(0,N.jsxs)(`div`,{className:`grid grid-cols-2 sm:grid-cols-3 lg:grid-cols-6 gap-3`,children:[(0,N.jsx)(ta,{label:`Total Runs`,value:`${n.totalRuns}`}),(0,N.jsx)(ta,{label:`Success`,value:`${n.okRuns}`}),(0,N.jsx)(ta,{label:`Errors`,value:`${n.errorRuns}`}),(0,N.jsx)(ta,{label:`Avg Duration`,value:n.avgDurationMs?yi(n.avgDurationMs):`—`}),(0,N.jsx)(ta,{label:`Total Tokens`,value:xi(n.totalTokens)}),(0,N.jsx)(ta,{label:`Total Cost`,value:bi(n.totalCost)})]})})}function ra(){let{agents:e,schedulerInfo:t}=Br(),n=e.map(e=>e.name),r=e.reduce((e,t)=>e+(t.cumulativeUsage?.totalTokens??0),0),i=e.filter(e=>(e.cumulativeUsage?.totalTokens??0)>0).sort((e,t)=>(t.cumulativeUsage?.totalTokens??0)-(e.cumulativeUsage?.totalTokens??0));return(0,N.jsxs)(`div`,{className:`space-y-6`,children:[(0,N.jsx)(`div`,{className:`flex items-center justify-between flex-wrap gap-3`,children:(0,N.jsx)(`h1`,{className:`text-xl font-bold text-slate-900 dark:text-white`,children:`Stats`})}),(0,N.jsx)(`div`,{className:`flex gap-6 border-b border-slate-200 dark:border-slate-800`,children:(0,N.jsx)(`span`,{className:`pb-2 text-sm font-medium text-blue-600 dark:text-blue-400 border-b-2 border-blue-600 dark:border-blue-400`,children:`Token Usage`})}),t?.startedAt&&(0,N.jsxs)(`div`,{className:`text-sm text-slate-500 dark:text-slate-400`,children:[`Session: `,wi(t.startedAt)]}),(0,N.jsx)(`div`,{className:`bg-slate-50 dark:bg-slate-900 rounded-lg border border-slate-200 dark:border-slate-800`,children:r===0?(0,N.jsx)(`div`,{className:`px-4 py-8 text-center text-slate-500 dark:text-slate-400`,children:`No token usage recorded yet`}):i.map(e=>{let t=e.cumulativeUsage?.totalTokens??0,i=t/r*100;return(0,N.jsxs)(`div`,{className:`px-4 py-3 border-b border-slate-100 dark:border-slate-800/50 last:border-0`,children:[(0,N.jsxs)(`div`,{className:`flex items-center justify-between mb-1.5`,children:[(0,N.jsx)(M,{to:`/dashboard/agents/${encodeURIComponent(e.name)}`,className:`agent-color-text text-sm font-medium hover:underline`,style:P(e.name,n),children:e.name}),(0,N.jsxs)(`span`,{className:`text-xs text-slate-500 dark:text-slate-400`,children:[xi(t),` (`,i.toFixed(1),`%)`]})]}),(0,N.jsx)(`div`,{className:`h-2 rounded-full overflow-hidden bg-slate-200 dark:bg-slate-800`,children:(0,N.jsx)(`div`,{className:`h-full rounded-full agent-color-bg transition-all`,style:{width:`${i}%`,...P(e.name,n)}})})]},e.name)})})]})}var ia=``;async function aa(e,t){let n=await fetch(`${ia}${e}`,{credentials:`same-origin`,...t});if(n.status===401)throw window.location.href=`/login`,Error(`Unauthorized`);if(!n.ok){let e=await n.text();throw Error(e||`HTTP ${n.status}`)}return n.json()}function oa(e){return aa(`/api/chat/sessions`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({agentName:e})})}function sa(e){return aa(`/api/chat/sessions/${encodeURIComponent(e)}/clear`,{method:`POST`})}function ca(e){return aa(`/api/chat/sessions/${encodeURIComponent(e)}`,{method:`DELETE`})}var la=0;function L(){return`msg-${++la}-${Date.now()}`}function ua(e){let t=(0,x.useRef)(null),[n,r]=(0,x.useState)([]),[i,a]=(0,x.useState)(!1),[o,s]=(0,x.useState)(!1),c=(0,x.useRef)(!1);return(0,x.useEffect)(()=>{if(!e)return;let n=`${window.location.protocol===`https:`?`wss:`:`ws:`}//${window.location.host}/chat/ws/${e}`,i=new WebSocket(n);return t.current=i,i.onopen=()=>{a(!0)},i.onmessage=e=>{let t;try{t=JSON.parse(e.data)}catch{return}switch(t.type){case`assistant_message`:t.done?(c.current=!1,r(e=>{let t=e[e.length-1];return t?.role===`assistant`&&!t.done?[...e.slice(0,-1),{...t,done:!0}]:e})):(o||s(!0),c.current=!0,r(e=>{let n=e[e.length-1];return n?.role===`assistant`&&!n.done?[...e.slice(0,-1),{...n,text:n.text+(t.text||``)}]:[...e,{id:L(),role:`assistant`,text:t.text||``,done:!1}]}));break;case`tool_start`:o||s(!0),r(e=>[...e,{id:L(),role:`tool_start`,text:t.input||``,toolName:t.tool,toolCallId:t.toolCallId}]);break;case`tool_result`:r(e=>[...e,{id:L(),role:`tool_result`,text:t.output||``,toolName:t.tool,toolCallId:t.toolCallId,error:!!t.error}]);break;case`error`:r(e=>[...e,{id:L(),role:`error`,text:t.message||`Unknown error`}]),c.current=!1;break;case`heartbeat`:break}},i.onclose=()=>{a(!1)},i.onerror=()=>{a(!1)},()=>{i.close(),t.current=null}},[e]),{messages:n,connected:i,containerReady:o,sendMessage:(0,x.useCallback)(e=>{if(!t.current||t.current.readyState!==WebSocket.OPEN)return;let n={id:L(),role:`user`,text:e,done:!0};r(e=>[...e,n]),t.current.send(JSON.stringify({type:`user_message`,text:e}))},[]),cancel:(0,x.useCallback)(()=>{!t.current||t.current.readyState!==WebSocket.OPEN||t.current.send(JSON.stringify({type:`cancel`}))},[]),resetMessages:(0,x.useCallback)(()=>{r([]),c.current=!1},[])}}function da({message:e}){return e.role===`user`?(0,N.jsx)(`div`,{className:`flex justify-end mb-3`,children:(0,N.jsx)(`div`,{className:`max-w-[80%] bg-blue-600 text-white rounded-2xl rounded-br-sm px-4 py-2 text-sm whitespace-pre-wrap`,children:e.text})}):e.role===`assistant`?(0,N.jsx)(`div`,{className:`flex justify-start mb-3`,children:(0,N.jsxs)(`div`,{className:`max-w-[80%] bg-slate-700 text-slate-100 rounded-2xl rounded-bl-sm px-4 py-2 text-sm whitespace-pre-wrap`,children:[e.text,!e.done&&(0,N.jsx)(`span`,{className:`inline-block w-2 h-4 bg-slate-400 animate-pulse ml-0.5 align-text-bottom`})]})}):e.role===`error`?(0,N.jsx)(`div`,{className:`flex justify-start mb-3`,children:(0,N.jsx)(`div`,{className:`max-w-[80%] bg-red-900/50 border border-red-700 text-red-200 rounded-lg px-4 py-2 text-sm`,children:e.text})}):null}function fa({message:e}){let[t,n]=(0,x.useState)(!1),r=e.role===`tool_result`,i=e.error;return(0,N.jsxs)(`div`,{className:`mb-2 ml-2`,children:[(0,N.jsxs)(`button`,{onClick:()=>n(!t),className:`flex items-center gap-2 text-xs font-mono px-3 py-1.5 rounded-md w-full text-left transition-colors ${i?`bg-red-900/30 border border-red-800 text-red-300 hover:bg-red-900/50`:`bg-slate-800 border border-slate-700 text-slate-400 hover:bg-slate-750`}`,children:[(0,N.jsx)(`span`,{className:`transition-transform ${t?`rotate-90`:``}`,children:`▸`}),(0,N.jsx)(`span`,{className:`font-semibold text-slate-300`,children:e.toolName||`tool`}),(0,N.jsx)(`span`,{className:`text-slate-500`,children:r?i?`error`:`done`:`running...`})]}),t&&(0,N.jsx)(`pre`,{className:`mt-1 ml-5 p-2 bg-slate-900 border border-slate-800 rounded text-xs text-slate-400 overflow-x-auto max-h-60 overflow-y-auto whitespace-pre-wrap`,children:e.text.slice(0,5e3)})]})}function pa(){let{agent:e}=dt(),t=st(),[n,r]=(0,x.useState)(null),[i,a]=(0,x.useState)(null),[o,s]=(0,x.useState)(``),c=(0,x.useRef)(null),l=(0,x.useRef)(null),{messages:u,connected:d,containerReady:f,sendMessage:p,cancel:m,resetMessages:h}=ua(n);(0,x.useEffect)(()=>{if(!e)return;let t=!1;return oa(e).then(({sessionId:e})=>{t||r(e)}).catch(e=>{t||a(e.message)}),()=>{t=!0}},[e]),(0,x.useEffect)(()=>{c.current?.scrollIntoView({behavior:`smooth`})},[u]),(0,x.useEffect)(()=>{l.current&&(l.current.style.height=`auto`,l.current.style.height=`${Math.min(l.current.scrollHeight,150)}px`)},[o]);let g=(0,x.useCallback)(()=>{let e=o.trim();e&&(p(e),s(``))},[o,p]),_=(0,x.useCallback)(e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),g())},[g]),v=(0,x.useCallback)(async()=>{if(n)try{let{sessionId:e}=await sa(n);h(),r(e)}catch(e){a(e.message)}},[n,h]),y=(0,x.useCallback)(async()=>{if(n)try{await ca(n),t(`/dashboard/agents/${encodeURIComponent(e||``)}`)}catch(e){a(e.message)}},[n,e,t]),b=u.some(e=>e.role===`assistant`&&!e.done);return i?(0,N.jsx)(`div`,{className:`min-h-screen bg-slate-900 text-white flex items-center justify-center`,children:(0,N.jsxs)(`div`,{className:`text-center`,children:[(0,N.jsx)(`p`,{className:`text-red-400 mb-4`,children:i}),(0,N.jsx)(M,{to:`/dashboard`,className:`text-blue-400 hover:underline`,children:`Back to Dashboard`})]})}):(0,N.jsxs)(`div`,{className:`flex flex-col h-screen bg-slate-900 text-white`,children:[(0,N.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-3 border-b border-slate-700 bg-slate-800`,children:[(0,N.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,N.jsx)(M,{to:`/dashboard/agents/${encodeURIComponent(e||``)}`,className:`text-slate-400 hover:text-white transition-colors`,children:`←`}),(0,N.jsxs)(`h1`,{className:`text-lg font-semibold`,children:[`Chat: `,e]})]}),(0,N.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,N.jsx)(`span`,{className:`inline-block w-2 h-2 rounded-full ${d?f?`bg-green-400`:`bg-yellow-400`:`bg-red-400`}`}),(0,N.jsx)(`span`,{className:`text-xs text-slate-400`,children:d?f?`Connected`:`Waiting for agent...`:`Disconnected`}),(0,N.jsx)(`button`,{onClick:v,disabled:!n,className:`px-3 py-1.5 text-xs font-medium rounded-md bg-yellow-600 hover:bg-yellow-700 disabled:opacity-40 text-white transition-colors`,children:`Clear Context`}),(0,N.jsx)(`button`,{onClick:y,disabled:!n,className:`px-3 py-1.5 text-xs font-medium rounded-md bg-red-600 hover:bg-red-700 disabled:opacity-40 text-white transition-colors`,children:`Shutdown`})]})]}),(0,N.jsxs)(`div`,{className:`flex-1 overflow-y-auto px-4 py-4`,children:[u.length===0&&!b&&(0,N.jsx)(`div`,{className:`text-center text-slate-500 mt-20`,children:f?`Send a message to start chatting.`:`Waiting for agent container to start...`}),u.map(e=>e.role===`tool_start`||e.role===`tool_result`?(0,N.jsx)(fa,{message:e},e.id):(0,N.jsx)(da,{message:e},e.id)),(0,N.jsx)(`div`,{ref:c})]}),(0,N.jsxs)(`div`,{className:`border-t border-slate-700 bg-slate-800 px-4 py-3`,children:[(0,N.jsxs)(`div`,{className:`flex items-end gap-2 max-w-4xl mx-auto`,children:[(0,N.jsx)(`textarea`,{ref:l,value:o,onChange:e=>s(e.target.value),onKeyDown:_,placeholder:b?`Agent is responding...`:`Type a message...`,disabled:!d,rows:1,className:`flex-1 bg-slate-700 border border-slate-600 rounded-lg px-3 py-2 text-base text-white placeholder-slate-400 resize-none focus:outline-none focus:border-blue-500 disabled:opacity-50`}),b?(0,N.jsx)(`button`,{onClick:m,className:`px-4 py-2 bg-red-600 hover:bg-red-700 text-white rounded-lg text-sm font-medium transition-colors`,children:`Cancel`}):(0,N.jsx)(`button`,{onClick:g,disabled:!o.trim()||!d,className:`px-4 py-2 bg-blue-600 hover:bg-blue-700 disabled:bg-slate-600 disabled:cursor-not-allowed text-white rounded-lg text-sm font-medium transition-colors`,children:`Send`})]}),(0,N.jsx)(`p`,{className:`text-xs text-slate-500 mt-1 text-center`,children:`Enter to send, Shift+Enter for newline`})]})]})}function ma(e){if(!e)return`—`;try{return JSON.stringify(JSON.parse(e),null,2)}catch{return e}}function ha(){let{receiptId:e}=dt(),[t,n]=(0,x.useState)(void 0),[r,i]=(0,x.useState)(null),[a,o]=(0,x.useState)(null),[s,c]=(0,x.useState)(!1);(0,x.useEffect)(()=>{e&&tr(e).then(e=>n(e.receipt)).catch(()=>n(null))},[e]);let l=(0,x.useCallback)(async()=>{if(e){i(null),o(null),c(!0);try{let t=await nr(e);i(`Replayed: ${t.matched} matched, ${t.skipped} skipped`)}catch(e){o(e instanceof Error?e.message:`Replay failed`)}finally{c(!1)}}},[e]);if(!e)return null;if(t===void 0)return(0,N.jsx)(`div`,{className:`text-center py-12 text-slate-500 dark:text-slate-400`,children:`Loading...`});if(t===null)return(0,N.jsx)(`div`,{className:`space-y-6`,children:(0,N.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,N.jsx)(M,{to:`/dashboard/triggers`,className:`text-slate-500 hover:text-slate-700 dark:hover:text-slate-300`,children:(0,N.jsx)(`svg`,{className:`w-5 h-5`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,N.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M15 19l-7-7 7-7`})})}),(0,N.jsx)(`h1`,{className:`text-xl font-bold text-slate-900 dark:text-white`,children:`Receipt not found`})]})});let u=!!(t.headers||t.body),d=t.status===`processed`?`completed`:`dead-letter`,f=zi(t.body,t.headers);return(0,N.jsxs)(`div`,{className:`space-y-6`,children:[(0,N.jsxs)(`div`,{className:`flex items-center justify-between flex-wrap gap-3`,children:[(0,N.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,N.jsx)(M,{to:`/dashboard/triggers`,className:`text-slate-500 hover:text-slate-700 dark:hover:text-slate-300`,children:(0,N.jsx)(`svg`,{className:`w-5 h-5`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,N.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M15 19l-7-7 7-7`})})}),(0,N.jsxs)(`div`,{children:[(0,N.jsx)(`h1`,{className:`text-xl font-bold text-slate-900 dark:text-white font-mono`,children:Si(t.id)}),(0,N.jsx)(`div`,{className:`text-xs text-slate-500 dark:text-slate-400`,children:`Webhook Receipt`})]}),(0,N.jsx)(oi,{result:d})]}),(0,N.jsxs)(`div`,{className:`flex items-center gap-2`,children:[r&&(0,N.jsx)(`span`,{className:`text-xs text-green-600 dark:text-green-400`,children:r}),a&&(0,N.jsx)(`span`,{className:`text-xs text-red-600 dark:text-red-400`,children:a}),(0,N.jsx)(`button`,{onClick:l,disabled:!u||s,className:`px-3 py-1.5 text-xs font-medium rounded-md bg-blue-600 hover:bg-blue-700 disabled:opacity-40 text-white transition-colors`,children:s?`Replaying...`:`Replay`})]})]}),(0,N.jsx)(`div`,{className:`max-w-2xl`,children:(0,N.jsxs)(`div`,{className:`bg-slate-50 dark:bg-slate-900 rounded-lg border border-slate-200 dark:border-slate-800 p-4`,children:[(0,N.jsx)(`h2`,{className:`text-sm font-medium text-slate-900 dark:text-white mb-3`,children:`Receipt Info`}),(0,N.jsxs)(`dl`,{className:`text-sm`,children:[(0,N.jsxs)(`div`,{className:`grid grid-cols-[8rem_1fr] gap-x-4 py-1 items-center`,children:[(0,N.jsx)(`dt`,{className:`text-slate-500 dark:text-slate-400`,children:`Source`}),(0,N.jsx)(`dd`,{className:`text-slate-700 dark:text-slate-300`,children:t.source})]}),t.eventSummary&&(0,N.jsxs)(`div`,{className:`grid grid-cols-[8rem_1fr] gap-x-4 py-1 items-center`,children:[(0,N.jsx)(`dt`,{className:`text-slate-500 dark:text-slate-400`,children:`Event`}),(0,N.jsx)(`dd`,{className:`text-slate-700 dark:text-slate-300`,children:t.eventSummary})]}),t.deliveryId&&(0,N.jsxs)(`div`,{className:`grid grid-cols-[8rem_1fr] gap-x-4 py-1 items-center`,children:[(0,N.jsx)(`dt`,{className:`text-slate-500 dark:text-slate-400`,children:`Delivery ID`}),(0,N.jsx)(`dd`,{className:`text-slate-700 dark:text-slate-300 font-mono text-xs`,children:t.deliveryId})]}),(0,N.jsxs)(`div`,{className:`grid grid-cols-[8rem_1fr] gap-x-4 py-1 items-center`,children:[(0,N.jsx)(`dt`,{className:`text-slate-500 dark:text-slate-400`,children:`Timestamp`}),(0,N.jsx)(`dd`,{className:`text-slate-700 dark:text-slate-300`,children:Ci(t.timestamp)})]}),(0,N.jsxs)(`div`,{className:`grid grid-cols-[8rem_1fr] gap-x-4 py-1 items-center`,children:[(0,N.jsx)(`dt`,{className:`text-slate-500 dark:text-slate-400`,children:`Status`}),(0,N.jsx)(`dd`,{children:(0,N.jsx)(oi,{result:d})})]}),(0,N.jsxs)(`div`,{className:`grid grid-cols-[8rem_1fr] gap-x-4 py-1 items-center`,children:[(0,N.jsx)(`dt`,{className:`text-slate-500 dark:text-slate-400`,children:`Matched Agents`}),(0,N.jsx)(`dd`,{className:`text-slate-700 dark:text-slate-300`,children:t.matchedAgents})]}),t.deadLetterReason&&(0,N.jsxs)(`div`,{className:`grid grid-cols-[8rem_1fr] gap-x-4 py-1 items-center`,children:[(0,N.jsx)(`dt`,{className:`text-slate-500 dark:text-slate-400`,children:`Dead Letter Reason`}),(0,N.jsx)(`dd`,{className:`text-red-600 dark:text-red-400 text-xs`,children:t.deadLetterReason})]}),(0,N.jsxs)(`div`,{className:`grid grid-cols-[8rem_1fr] gap-x-4 py-1 items-start pt-2 mt-1 border-t border-slate-200 dark:border-slate-800`,children:[(0,N.jsx)(`dt`,{className:`text-slate-500 dark:text-slate-400`,children:`Receipt ID`}),(0,N.jsx)(`dd`,{className:`text-slate-700 dark:text-slate-300 font-mono text-xs break-all`,children:t.id})]})]})]})}),(0,N.jsxs)(`div`,{className:`bg-slate-50 dark:bg-slate-900 rounded-lg border border-slate-200 dark:border-slate-800 overflow-hidden`,children:[(0,N.jsx)(`div`,{className:`px-4 py-2.5 border-b border-slate-200 dark:border-slate-800`,children:(0,N.jsx)(`h2`,{className:`text-sm font-medium text-slate-900 dark:text-white`,children:`Headers`})}),(0,N.jsx)(`div`,{className:`p-3 bg-slate-950`,children:(0,N.jsx)(`pre`,{className:`text-xs font-mono text-slate-300 whitespace-pre-wrap break-all`,children:t.headers?ma(t.headers):`—`})})]}),f&&(0,N.jsxs)(`div`,{className:`bg-slate-50 dark:bg-slate-900 rounded-lg border border-slate-200 dark:border-slate-800 overflow-hidden`,children:[(0,N.jsx)(`div`,{className:`px-4 py-2.5 border-b border-slate-200 dark:border-slate-800`,children:(0,N.jsx)(`h2`,{className:`text-sm font-medium text-slate-900 dark:text-white`,children:f.label})}),(0,N.jsx)(`div`,{className:`bg-slate-950 p-3 max-h-96 overflow-y-auto`,children:(0,N.jsx)(`pre`,{className:`text-xs font-mono text-slate-300 whitespace-pre-wrap break-all`,children:f.content})})]}),(0,N.jsxs)(`div`,{className:`bg-slate-50 dark:bg-slate-900 rounded-lg border border-slate-200 dark:border-slate-800 overflow-hidden`,children:[(0,N.jsx)(`div`,{className:`px-4 py-2.5 border-b border-slate-200 dark:border-slate-800`,children:(0,N.jsx)(`h2`,{className:`text-sm font-medium text-slate-900 dark:text-white`,children:f?`Raw Body`:`Body`})}),(0,N.jsx)(`div`,{className:`bg-slate-950 p-3 max-h-96 overflow-y-auto`,children:(0,N.jsx)(`pre`,{className:`text-xs font-mono text-slate-300 whitespace-pre-wrap break-all`,children:t.body?ma(t.body):`—`})})]})]})}function ga(){let{name:e}=dt();return(0,N.jsx)(Ft,{to:`/activity?agent=${encodeURIComponent(e??``)}`,replace:!0})}function _a(){let{name:e}=dt();return(0,N.jsx)(Ft,{to:`/dashboard/agents/${encodeURIComponent(e??``)}/settings`,replace:!0})}function va(){return(0,N.jsxs)(Rt,{children:[(0,N.jsx)(j,{path:`/login`,element:(0,N.jsx)(li,{})}),(0,N.jsx)(j,{path:`/chat/:agent`,element:(0,N.jsx)(pa,{})}),(0,N.jsxs)(j,{element:(0,N.jsx)(Wr,{}),children:[(0,N.jsx)(j,{path:`/dashboard`,element:(0,N.jsx)(vi,{})}),(0,N.jsxs)(j,{path:`/dashboard/agents/:name`,element:(0,N.jsx)(qr,{}),children:[(0,N.jsx)(j,{index:!0,element:(0,N.jsx)(Mi,{})}),(0,N.jsx)(j,{path:`stats`,element:(0,N.jsx)(na,{})}),(0,N.jsx)(j,{path:`settings`,element:(0,N.jsx)(Ii,{})}),(0,N.jsx)(j,{path:`admin`,element:(0,N.jsx)(Ft,{to:`settings`,replace:!0})}),(0,N.jsx)(j,{path:`skill`,element:(0,N.jsx)(_a,{})}),(0,N.jsx)(j,{path:`triggers`,element:(0,N.jsx)(ga,{})})]}),(0,N.jsxs)(j,{path:`/dashboard/agents/:name/instances/:id`,element:(0,N.jsx)(ci,{}),children:[(0,N.jsx)(j,{index:!0,element:(0,N.jsx)(I,{})}),(0,N.jsx)(j,{path:`trigger`,element:(0,N.jsx)(Vi,{})}),(0,N.jsx)(j,{path:`telemetry`,element:(0,N.jsx)(Hi,{})})]}),(0,N.jsx)(j,{path:`/dashboard/triggers`,element:(0,N.jsx)(Ft,{to:`/activity`,replace:!0})}),(0,N.jsx)(j,{path:`/activity`,element:(0,N.jsx)(Zi,{})}),(0,N.jsx)(j,{path:`/stats`,element:(0,N.jsx)(ra,{})}),(0,N.jsx)(j,{path:`/triggers`,element:(0,N.jsx)(Ft,{to:`/activity`,replace:!0})}),(0,N.jsx)(j,{path:`/jobs`,element:(0,N.jsx)(Ft,{to:`/activity`,replace:!0})}),(0,N.jsx)(j,{path:`/dashboard/triggers/:instanceId`,element:(0,N.jsx)($i,{})}),(0,N.jsx)(j,{path:`/dashboard/webhooks/:receiptId`,element:(0,N.jsx)(ha,{})}),(0,N.jsx)(j,{path:`/dashboard/config`,element:(0,N.jsx)(ea,{})})]}),(0,N.jsx)(j,{path:`/`,element:(0,N.jsx)(Ft,{to:`/dashboard`,replace:!0})})]})}var ya=localStorage.getItem(`al-theme`)||`dark`;document.documentElement.classList.toggle(`dark`,ya===`dark`),(0,Jn.createRoot)(document.getElementById(`root`)).render((0,N.jsx)(x.StrictMode,{children:(0,N.jsx)(Dn,{children:(0,N.jsx)(va,{})})}));
|
|
13
|
+
`)}function Ii(){let{name:e}=dt(),{agents:t}=Br(),[n,r]=(0,x.useState)(null),[i,a]=(0,x.useState)(``),[o,s]=(0,x.useState)(null),[c,l]=(0,x.useState)(null),[u,d]=(0,x.useState)(null),[f,p]=(0,x.useState)(null),m=t.find(t=>t.name===e)??n?.agent??null,h=(0,x.useCallback)(()=>{e&&Qn(e).then(e=>{r(e),e.agent&&a(String(e.agent.scale))}).catch(()=>{})},[e]);(0,x.useEffect)(()=>{h()},[h]),(0,x.useEffect)(()=>{m&&a(String(m.scale))},[m?.scale]),(0,x.useEffect)(()=>{e&&$n(e).then(e=>{s(e.body),l(e.agentConfig)}).catch(e=>d(e instanceof Error?e.message:`Failed to load skill`))},[e]);let g=(0,x.useCallback)(async e=>{p(null);try{await e()}catch(e){p(e instanceof Error?e.message:`Action failed`)}},[]),_=(0,x.useCallback)(()=>{if(!e)return;let t=parseInt(i,10);isNaN(t)||t<1||g(()=>gr(e,t))},[e,i,g]);return e?(0,N.jsxs)(`div`,{className:`space-y-6`,children:[f&&(0,N.jsx)(`div`,{className:`bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 rounded-lg p-3 text-sm text-red-700 dark:text-red-400`,children:f}),(0,N.jsxs)(`div`,{className:`bg-slate-50 dark:bg-slate-900 rounded-lg border border-slate-200 dark:border-slate-800 overflow-hidden`,children:[(0,N.jsx)(`div`,{className:`px-4 py-2.5 border-b border-slate-200 dark:border-slate-800`,children:(0,N.jsx)(`h2`,{className:`text-sm font-medium text-slate-900 dark:text-white`,children:`Controls`})}),(0,N.jsxs)(`div`,{className:`p-4 flex items-center gap-4 flex-wrap`,children:[(0,N.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,N.jsx)(`span`,{className:`text-xs text-slate-500 dark:text-slate-400`,children:`Scale:`}),(0,N.jsx)(`input`,{id:`agent-scale-input`,type:`number`,min:1,value:i,onChange:e=>a(e.target.value),className:`w-16 px-2 py-1 bg-white dark:bg-slate-950 border border-slate-300 dark:border-slate-700 rounded text-base text-slate-900 dark:text-slate-200`}),(0,N.jsx)(`button`,{id:`update-agent-scale-btn`,onClick:_,className:`px-2 py-1.5 text-xs font-medium rounded-md bg-blue-600 hover:bg-blue-700 text-white transition-colors`,children:`Set`})]}),m&&(0,N.jsx)(`button`,{id:`toggle-btn`,onClick:()=>g(()=>m.enabled?fr(e):dr(e)),className:`px-3 py-1.5 text-xs font-medium rounded-md transition-colors ${m.enabled?`bg-slate-200 dark:bg-slate-700 text-slate-700 dark:text-slate-300 hover:bg-slate-300 dark:hover:bg-slate-600`:`bg-blue-600 hover:bg-blue-700 text-white`}`,children:m.enabled?`Disable`:`Enable`})]})]}),c&&(0,N.jsxs)(`div`,{className:`bg-slate-50 dark:bg-slate-900 rounded-lg border border-slate-200 dark:border-slate-800 overflow-hidden`,children:[(0,N.jsx)(`div`,{className:`px-4 py-2.5 border-b border-slate-200 dark:border-slate-800`,children:(0,N.jsx)(`h2`,{className:`text-sm font-medium text-slate-900 dark:text-white`,children:`Configuration`})}),(0,N.jsxs)(`div`,{className:`p-4 space-y-4 text-sm`,children:[c.description&&(0,N.jsx)(`p`,{className:`text-slate-700 dark:text-slate-300`,children:c.description}),(0,N.jsxs)(`dl`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-x-6 gap-y-3`,children:[c.schedule&&(0,N.jsxs)(`div`,{children:[(0,N.jsx)(`dt`,{className:`text-xs text-slate-500 dark:text-slate-400 uppercase tracking-wide`,children:`Schedule`}),(0,N.jsx)(`dd`,{className:`mt-0.5`,children:(0,N.jsx)(`code`,{className:`text-xs bg-slate-200 dark:bg-slate-800 px-1.5 py-0.5 rounded font-mono`,children:c.schedule})})]}),c.models&&c.models.length>0&&(0,N.jsxs)(`div`,{children:[(0,N.jsx)(`dt`,{className:`text-xs text-slate-500 dark:text-slate-400 uppercase tracking-wide`,children:`Models`}),(0,N.jsx)(`dd`,{className:`mt-0.5 space-y-0.5`,children:c.models.map((e,t)=>(0,N.jsxs)(`div`,{className:`text-xs text-slate-700 dark:text-slate-300`,children:[e.provider,`/`,e.model,e.thinkingLevel?` (${e.thinkingLevel})`:``,(0,N.jsxs)(`span`,{className:`text-slate-400 dark:text-slate-500 ml-1`,children:[`[`,e.authType,`]`]})]},t))})]}),c.credentials&&c.credentials.length>0&&(0,N.jsxs)(`div`,{children:[(0,N.jsx)(`dt`,{className:`text-xs text-slate-500 dark:text-slate-400 uppercase tracking-wide`,children:`Credentials`}),(0,N.jsx)(`dd`,{className:`mt-0.5 flex flex-wrap gap-1`,children:c.credentials.map(e=>(0,N.jsx)(`span`,{className:`px-1.5 py-0.5 text-xs bg-slate-200 dark:bg-slate-800 rounded font-mono`,children:e},e))})]}),c.hooks&&(c.hooks.pre?.length||c.hooks.post?.length)&&(0,N.jsxs)(`div`,{children:[(0,N.jsx)(`dt`,{className:`text-xs text-slate-500 dark:text-slate-400 uppercase tracking-wide`,children:`Hooks`}),(0,N.jsxs)(`dd`,{className:`mt-0.5 text-xs text-slate-700 dark:text-slate-300`,children:[c.hooks.pre&&c.hooks.pre.length>0&&(0,N.jsxs)(`div`,{children:[`Pre: `,c.hooks.pre.join(`, `)]}),c.hooks.post&&c.hooks.post.length>0&&(0,N.jsxs)(`div`,{children:[`Post: `,c.hooks.post.join(`, `)]})]})]}),c.params&&Object.keys(c.params).length>0&&(0,N.jsxs)(`div`,{className:`sm:col-span-2`,children:[(0,N.jsx)(`dt`,{className:`text-xs text-slate-500 dark:text-slate-400 uppercase tracking-wide`,children:`Params`}),(0,N.jsx)(`dd`,{className:`mt-0.5`,children:(0,N.jsx)(`pre`,{className:`text-xs bg-slate-200 dark:bg-slate-800 p-2 rounded overflow-x-auto`,children:JSON.stringify(c.params,null,2)})})]})]}),c.webhooks&&c.webhooks.length>0&&(0,N.jsxs)(`div`,{children:[(0,N.jsx)(`h3`,{className:`text-xs text-slate-500 dark:text-slate-400 uppercase tracking-wide mb-2`,children:`Webhook Filters`}),(0,N.jsx)(`div`,{className:`space-y-3`,children:c.webhooks.map((e,t)=>(0,N.jsxs)(`div`,{className:`bg-slate-100 dark:bg-slate-800 rounded p-3 text-xs space-y-1`,children:[(0,N.jsx)(`div`,{className:`font-medium text-slate-700 dark:text-slate-300`,children:e.source??`unknown`}),e.events&&e.events.length>0&&(0,N.jsxs)(`div`,{className:`text-slate-600 dark:text-slate-400`,children:[(0,N.jsx)(`span`,{className:`text-slate-500`,children:`events:`}),` `,e.events.map(e=>(0,N.jsx)(`span`,{className:`inline-block mr-1 px-1.5 py-0.5 bg-slate-200 dark:bg-slate-700 rounded font-mono`,children:e},e))]}),e.actions&&e.actions.length>0&&(0,N.jsxs)(`div`,{className:`text-slate-600 dark:text-slate-400`,children:[(0,N.jsx)(`span`,{className:`text-slate-500`,children:`actions:`}),` `,e.actions.join(`, `)]}),e.repos&&e.repos.length>0&&(0,N.jsxs)(`div`,{className:`text-slate-600 dark:text-slate-400`,children:[(0,N.jsx)(`span`,{className:`text-slate-500`,children:`repos:`}),` `,e.repos.join(`, `)]}),(e.org||e.orgs&&e.orgs.length>0)&&(0,N.jsxs)(`div`,{className:`text-slate-600 dark:text-slate-400`,children:[(0,N.jsx)(`span`,{className:`text-slate-500`,children:`orgs:`}),` `,e.org??e.orgs?.join(`, `)]}),e.branches&&e.branches.length>0&&(0,N.jsxs)(`div`,{className:`text-slate-600 dark:text-slate-400`,children:[(0,N.jsx)(`span`,{className:`text-slate-500`,children:`branches:`}),` `,e.branches.join(`, `)]}),e.labels&&e.labels.length>0&&(0,N.jsxs)(`div`,{className:`text-slate-600 dark:text-slate-400`,children:[(0,N.jsx)(`span`,{className:`text-slate-500`,children:`labels:`}),` `,e.labels.join(`, `)]}),e.assignee&&(0,N.jsxs)(`div`,{className:`text-slate-600 dark:text-slate-400`,children:[(0,N.jsx)(`span`,{className:`text-slate-500`,children:`assignee:`}),` `,e.assignee]}),e.author&&(0,N.jsxs)(`div`,{className:`text-slate-600 dark:text-slate-400`,children:[(0,N.jsx)(`span`,{className:`text-slate-500`,children:`author:`}),` `,e.author]})]},t))})]})]})]}),u?(0,N.jsx)(`div`,{className:`bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 rounded-lg p-4 text-sm text-red-700 dark:text-red-400`,children:u}):o===null?(0,N.jsx)(`div`,{className:`bg-slate-50 dark:bg-slate-900 rounded-lg border border-slate-200 dark:border-slate-800 p-8 text-center text-slate-500 dark:text-slate-400`,children:`Loading...`}):(0,N.jsxs)(`div`,{className:`bg-slate-50 dark:bg-slate-900 rounded-lg border border-slate-200 dark:border-slate-800 overflow-hidden`,children:[(0,N.jsx)(`div`,{className:`px-4 py-2.5 border-b border-slate-200 dark:border-slate-800`,children:(0,N.jsx)(`h2`,{className:`text-sm font-medium text-slate-900 dark:text-white`,children:`Skill`})}),(0,N.jsx)(`div`,{className:`p-6`,children:(0,N.jsx)(`div`,{className:`prose prose-slate dark:prose-invert max-w-none text-sm text-slate-700 dark:text-slate-300`,dangerouslySetInnerHTML:{__html:Fi(o)}})})]})]}):null}function Li(e,t,n=[]){let r=(0,x.useRef)(e);r.current=e;let{intervalMs:i,enabled:a=!0}=t;(0,x.useEffect)(()=>{if(!a)return;let e=new AbortController,t=!1,n=()=>{t||(t=!0,r.current(e.signal).catch(()=>{}).finally(()=>{t=!1}))};n();let o=setInterval(n,i);return()=>{clearInterval(o),e.abort()}},[i,a,...n])}function F(e){let t=e.msg||``;return e.text&&(t.includes(`assistant`)||t.includes(`response`))?{text:`${t}: ${e.text}`,className:`text-white font-bold`}:e.cmd||t.includes(`bash`)||t.includes(`command`)?{text:e.cmd?`$ ${e.cmd}`:t,className:`text-cyan-400`}:e.tool||t.includes(`tool`)?{text:e.tool?`[tool] ${e.tool}: ${e.result??``}`:t,className:`text-blue-400`}:e.level>=50||e.err?{text:t,className:`text-red-400`}:e.level>=40?{text:t,className:`text-yellow-400`}:{text:t,className:`text-slate-300`}}function I(){let e=(0,x.useContext)(si),[t,n]=(0,x.useState)([]),[r,i]=(0,x.useState)(!0),[a,o]=(0,x.useState)(!1),s=(0,x.useRef)(null),c=(0,x.useRef)(null),l=e?.name??``,u=e?.id??``,d=e?.isRunning??!1,[f,p]=(0,x.useState)(!1),[m,h]=(0,x.useState)(!0),[g,_]=(0,x.useState)(null),[v,y]=(0,x.useState)(!1),[b,S]=(0,x.useState)(null),{data:C}=ni({key:`instance-locks:${u}`,fetcher:e=>or(e),pollIntervalMs:5e3,enabled:d&&!!e}),w=(C?.locks??[]).filter(e=>e.holder===u||!e.holder&&e.agentName===l);Li(async e=>{if(!l||!u)return;let t={lines:`100`};s.current&&(t.cursor=s.current);try{let r=await sr(l,u,t,e);o(!0),r.entries.length>0&&(n(e=>[...e,...r.entries]),r.cursor&&(s.current=r.cursor))}catch{throw o(!1),void 0}},{intervalMs:d?3e3:1e4,enabled:!!l&&!!u&&!!e},[l,u,d]),(0,x.useEffect)(()=>{r&&c.current&&(c.current.scrollTop=c.current.scrollHeight)},[t,r]);let T=(0,x.useCallback)(async()=>{if(!(!l||!u)){y(!0),S(null);try{let e=await yr(l,u);e.error?S(e.error):_(e.summary)}catch(e){S(e instanceof Error?e.message:`Failed to summarize`)}finally{y(!1)}}},[l,u]),E=(0,x.useCallback)(async()=>{if(!(!l||!u||f||!m||t.length===0)){p(!0);try{let e=t[0].time,r=await sr(l,u,{lines:`100`,before:String(e)});if(r.entries.length>0){let e=c.current,t=e?.scrollHeight??0,i=e?.scrollTop??0;n(e=>[...r.entries,...e]),requestAnimationFrame(()=>{e&&(e.scrollTop=i+(e.scrollHeight-t))})}r.entries.length<100&&h(!1)}catch{}finally{p(!1)}}},[l,u,f,m,t]),ee=(0,x.useRef)(!1);(0,x.useEffect)(()=>{t.length>0&&!ee.current&&m&&(ee.current=!0,E())},[t.length,m,E]);let D=(0,x.useCallback)(()=>{if(!c.current)return;let e=c.current;i(e.scrollHeight-e.scrollTop-e.clientHeight<40),e.scrollTop<100&&m&&!f&&t.length>0&&E()},[m,f,t.length,E]);return e?(0,N.jsxs)(`div`,{className:`space-y-4`,children:[w.length>0&&(0,N.jsxs)(`div`,{className:`bg-slate-50 dark:bg-slate-900 rounded-lg border border-slate-200 dark:border-slate-800 overflow-hidden`,children:[(0,N.jsx)(`div`,{className:`px-4 py-2.5 border-b border-slate-200 dark:border-slate-800`,children:(0,N.jsxs)(`h2`,{className:`text-sm font-medium text-slate-900 dark:text-white`,children:[`Resource Locks (`,w.length,`)`]})}),(0,N.jsx)(`div`,{className:`divide-y divide-slate-100 dark:divide-slate-800/50`,children:w.map(e=>(0,N.jsxs)(`div`,{className:`px-4 py-2.5 flex items-center justify-between`,children:[(0,N.jsx)(`span`,{className:`text-sm font-mono text-slate-700 dark:text-slate-300`,children:e.resourceKey}),e.heldSince&&(0,N.jsxs)(`span`,{className:`text-xs text-slate-500 dark:text-slate-400`,children:[`since `,new Date(e.heldSince).toLocaleTimeString()]})]},e.resourceKey))})]}),(0,N.jsxs)(`div`,{className:`bg-slate-50 dark:bg-slate-900 rounded-lg border border-slate-200 dark:border-slate-800 overflow-hidden`,children:[(0,N.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-2.5 border-b border-slate-200 dark:border-slate-800`,children:[(0,N.jsx)(`h2`,{className:`text-sm font-medium text-slate-900 dark:text-white`,children:`Logs`}),(0,N.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,N.jsxs)(`span`,{className:`hidden sm:inline text-xs text-slate-500 dark:text-slate-400`,children:[t.length,` lines`]}),(0,N.jsx)(`span`,{className:`text-xs ${a?`text-green-500`:`text-red-500`}`,children:a?`Connected`:`Disconnected`}),(0,N.jsx)(`button`,{onClick:T,disabled:v||t.length===0,className:`px-2 py-1 text-xs rounded bg-purple-600 hover:bg-purple-700 disabled:opacity-40 disabled:cursor-not-allowed text-white transition-colors`,children:v?(0,N.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,N.jsxs)(`svg`,{className:`w-3 h-3 animate-spin`,viewBox:`0 0 24 24`,fill:`none`,children:[(0,N.jsx)(`circle`,{className:`opacity-25`,cx:`12`,cy:`12`,r:`10`,stroke:`currentColor`,strokeWidth:`4`}),(0,N.jsx)(`path`,{className:`opacity-75`,fill:`currentColor`,d:`M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z`})]}),`Summarizing…`]}):`Summarize`}),(0,N.jsx)(`button`,{onClick:()=>i(e=>!e),className:`px-2 py-1 text-xs rounded transition-colors ${r?`bg-blue-600 text-white`:`bg-slate-200 dark:bg-slate-800 text-slate-700 dark:text-slate-300`}`,children:`Follow`}),(0,N.jsx)(`button`,{onClick:()=>{n([]),s.current=null,h(!0)},className:`px-2 py-1 text-xs rounded bg-slate-200 dark:bg-slate-800 text-slate-700 dark:text-slate-300 hover:bg-slate-300 dark:hover:bg-slate-700 transition-colors`,children:`Clear`})]})]}),(0,N.jsxs)(`div`,{className:`relative`,children:[(g||b)&&(0,N.jsx)(`div`,{className:`absolute inset-x-0 top-0 z-10 p-3 pointer-events-none`,children:(0,N.jsxs)(`div`,{className:`pointer-events-auto`,children:[g&&(0,N.jsx)(`div`,{className:`bg-purple-900/95 border border-purple-700 rounded-lg p-4 text-sm text-purple-100 shadow-lg backdrop-blur-sm`,children:(0,N.jsxs)(`div`,{className:`flex items-start justify-between gap-2`,children:[(0,N.jsxs)(`div`,{children:[(0,N.jsx)(`div`,{className:`text-xs font-medium text-purple-300 mb-1`,children:`Summary`}),(0,N.jsx)(`p`,{className:`leading-relaxed`,children:g})]}),(0,N.jsx)(`button`,{onClick:()=>_(null),className:`text-purple-400 hover:text-purple-200 flex-shrink-0`,children:(0,N.jsx)(`svg`,{className:`w-4 h-4`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,N.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M6 18L18 6M6 6l12 12`})})})]})}),b&&(0,N.jsxs)(`div`,{className:`mt-2 bg-red-900/95 border border-red-700 rounded-lg p-3 text-sm text-red-200 flex items-center justify-between shadow-lg backdrop-blur-sm`,children:[(0,N.jsx)(`span`,{children:b}),(0,N.jsx)(`button`,{onClick:()=>S(null),className:`text-red-400 hover:text-red-200 ml-2`,children:(0,N.jsx)(`svg`,{className:`w-4 h-4`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,N.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M6 18L18 6M6 6l12 12`})})})]})]})}),(0,N.jsxs)(`div`,{ref:c,onScroll:D,className:`min-h-[32rem] max-h-[calc(100vh-16rem)] overflow-y-auto scrollbar-thin bg-slate-950 p-3`,children:[f&&(0,N.jsx)(`div`,{className:`text-xs text-slate-500 text-center py-2`,children:(0,N.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,N.jsxs)(`svg`,{className:`w-3 h-3 animate-spin`,viewBox:`0 0 24 24`,fill:`none`,children:[(0,N.jsx)(`circle`,{className:`opacity-25`,cx:`12`,cy:`12`,r:`10`,stroke:`currentColor`,strokeWidth:`4`}),(0,N.jsx)(`path`,{className:`opacity-75`,fill:`currentColor`,d:`M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z`})]}),`Loading older logs…`]})}),!m&&t.length>0&&(0,N.jsx)(`div`,{className:`text-xs text-slate-600 text-center py-2 border-b border-slate-800 mb-2`,children:`— Beginning of logs —`}),m&&!f&&t.length>0&&(0,N.jsx)(`button`,{className:`w-full text-xs text-blue-400 hover:text-blue-300 text-center py-2 border-b border-slate-800 mb-2 transition-colors`,onClick:E,children:`↑ Load older logs`}),t.length>0?t.map((e,t)=>{let{text:n,className:r}=F(e);return(0,N.jsxs)(`div`,{className:`text-xs font-mono leading-5`,children:[(0,N.jsx)(`span`,{className:`text-slate-600`,children:new Date(e.time).toLocaleTimeString()}),` `,(0,N.jsx)(`span`,{className:r,children:n})]},t)}):(0,N.jsx)(`div`,{className:`text-xs text-slate-500 text-center py-4`,children:`No log entries`})]})]})]})]}):null}function Ri(e){if(e)try{let t=JSON.parse(e);return t[`content-type`]??t[`Content-Type`]}catch{return}}function zi(e,t){if(!e)return null;let n=Ri(t)?.toLowerCase()??``;if(n.includes(`application/x-www-form-urlencoded`))try{let t=new URLSearchParams(e),n={};for(let[e,r]of t.entries())try{n[e]=JSON.parse(r)}catch{n[e]=r}return{label:`Decoded Body (form-urlencoded)`,content:JSON.stringify(n,null,2)}}catch{}if(n.includes(`application/json`))return null;try{return JSON.parse(e),null}catch{if(/^[A-Za-z0-9+/\n\r]+=*$/.test(e.trim())&&e.trim().length>20)try{let t=atob(e.trim().replace(/\s/g,``));if(/^[\x20-\x7E\t\n\r]*$/.test(t))try{let e=JSON.parse(t);return{label:`Decoded Body (base64)`,content:JSON.stringify(e,null,2)}}catch{return{label:`Decoded Body (base64)`,content:t}}}catch{}}return null}function Bi(e){if(!e)return`—`;try{return JSON.stringify(JSON.parse(e),null,2)}catch{return e}}function Vi(){let e=(0,x.useContext)(si),{agents:t}=Br(),n=t.map(e=>e.name),[r,i]=(0,x.useState)(void 0),a=e?.id,o=e?.detail;if((0,x.useEffect)(()=>{a&&ir(a).then(e=>i(e.trigger)).catch(()=>i(null))},[a]),!e)return null;if(r===void 0)return(0,N.jsx)(`div`,{className:`text-center py-12 text-slate-500 dark:text-slate-400`,children:`Loading...`});if(r===null){let e=o?.run;return e?(0,N.jsx)(`div`,{className:`space-y-4`,children:(0,N.jsxs)(`div`,{className:`bg-slate-50 dark:bg-slate-900 rounded-lg border border-slate-200 dark:border-slate-800 overflow-hidden`,children:[(0,N.jsx)(`div`,{className:`px-4 py-2.5 border-b border-slate-200 dark:border-slate-800`,children:(0,N.jsx)(`h2`,{className:`text-sm font-medium text-slate-900 dark:text-white`,children:`Overview`})}),(0,N.jsxs)(`div`,{className:`divide-y divide-slate-100 dark:divide-slate-800/50 max-w-2xl`,children:[(0,N.jsxs)(`div`,{className:`px-4 py-3 grid grid-cols-[8rem_1fr] gap-x-4 items-center`,children:[(0,N.jsx)(`span`,{className:`text-xs text-slate-500 dark:text-slate-400`,children:`Trigger Type`}),(0,N.jsx)(ai,{type:e.trigger_type})]}),e.trigger_source&&(0,N.jsxs)(`div`,{className:`px-4 py-3 grid grid-cols-[8rem_1fr] gap-x-4 items-center`,children:[(0,N.jsx)(`span`,{className:`text-xs text-slate-500 dark:text-slate-400`,children:`Source`}),(0,N.jsx)(`span`,{className:`text-xs text-slate-700 dark:text-slate-300`,children:e.trigger_source})]})]})]})}):(0,N.jsx)(`div`,{className:`text-center py-12 text-slate-500 dark:text-slate-400`,children:`Trigger details not available.`})}return(0,N.jsxs)(`div`,{className:`space-y-4`,children:[(0,N.jsxs)(`div`,{className:`bg-slate-50 dark:bg-slate-900 rounded-lg border border-slate-200 dark:border-slate-800 overflow-hidden`,children:[(0,N.jsx)(`div`,{className:`px-4 py-2.5 border-b border-slate-200 dark:border-slate-800`,children:(0,N.jsx)(`h2`,{className:`text-sm font-medium text-slate-900 dark:text-white`,children:`Overview`})}),(0,N.jsxs)(`div`,{className:`divide-y divide-slate-100 dark:divide-slate-800/50 max-w-2xl`,children:[(0,N.jsxs)(`div`,{className:`px-4 py-3 grid grid-cols-[8rem_1fr] gap-x-4 items-center`,children:[(0,N.jsx)(`span`,{className:`text-xs text-slate-500 dark:text-slate-400`,children:`Trigger Type`}),(0,N.jsx)(ai,{type:r.triggerType})]}),(0,N.jsxs)(`div`,{className:`px-4 py-3 grid grid-cols-[8rem_1fr] gap-x-4 items-center`,children:[(0,N.jsx)(`span`,{className:`text-xs text-slate-500 dark:text-slate-400`,children:`Agent`}),(0,N.jsx)(M,{to:`/dashboard/agents/${encodeURIComponent(r.agentName)}`,className:`hover:underline text-xs flex items-center gap-1.5`,children:(0,N.jsx)(`span`,{className:`agent-color-text`,style:P(r.agentName,n),children:r.agentName})})]}),(0,N.jsxs)(`div`,{className:`px-4 py-3 grid grid-cols-[8rem_1fr] gap-x-4 items-center`,children:[(0,N.jsx)(`span`,{className:`text-xs text-slate-500 dark:text-slate-400`,children:`Instance`}),(0,N.jsx)(`span`,{className:`font-mono text-xs text-slate-700 dark:text-slate-300`,children:r.instanceId})]}),(0,N.jsxs)(`div`,{className:`px-4 py-3 grid grid-cols-[8rem_1fr] gap-x-4 items-center`,children:[(0,N.jsx)(`span`,{className:`text-xs text-slate-500 dark:text-slate-400`,children:`Time`}),(0,N.jsx)(`span`,{className:`text-xs text-slate-700 dark:text-slate-300`,children:Ci(r.startedAt)})]}),r.triggerSource&&(0,N.jsxs)(`div`,{className:`px-4 py-3 grid grid-cols-[8rem_1fr] gap-x-4 items-center`,children:[(0,N.jsx)(`span`,{className:`text-xs text-slate-500 dark:text-slate-400`,children:`Source`}),(0,N.jsx)(`span`,{className:`text-xs text-slate-700 dark:text-slate-300`,children:r.triggerSource})]})]})]}),r.triggerType===`webhook`&&r.webhook&&(0,N.jsxs)(`div`,{className:`bg-slate-50 dark:bg-slate-900 rounded-lg border border-slate-200 dark:border-slate-800 overflow-hidden`,children:[(0,N.jsx)(`div`,{className:`px-4 py-2.5 border-b border-slate-200 dark:border-slate-800`,children:(0,N.jsx)(`h2`,{className:`text-sm font-medium text-slate-900 dark:text-white`,children:`Webhook Details`})}),(0,N.jsxs)(`div`,{className:`divide-y divide-slate-100 dark:divide-slate-800/50 max-w-2xl`,children:[(0,N.jsxs)(`div`,{className:`px-4 py-3 grid grid-cols-[8rem_1fr] gap-x-4 items-center`,children:[(0,N.jsx)(`span`,{className:`text-xs text-slate-500 dark:text-slate-400`,children:`Receipt ID`}),(0,N.jsx)(M,{to:`/dashboard/webhooks/${encodeURIComponent(r.webhook.receiptId)}`,className:`font-mono text-xs text-blue-600 dark:text-blue-400 hover:underline`,children:Si(r.webhook.receiptId)})]}),(0,N.jsxs)(`div`,{className:`px-4 py-3 grid grid-cols-[8rem_1fr] gap-x-4 items-center`,children:[(0,N.jsx)(`span`,{className:`text-xs text-slate-500 dark:text-slate-400`,children:`Source`}),(0,N.jsx)(`span`,{className:`text-xs text-slate-700 dark:text-slate-300`,children:r.webhook.source})]}),r.webhook.eventSummary&&(0,N.jsxs)(`div`,{className:`px-4 py-3 grid grid-cols-[8rem_1fr] gap-x-4 items-center`,children:[(0,N.jsx)(`span`,{className:`text-xs text-slate-500 dark:text-slate-400`,children:`Event`}),(0,N.jsx)(`span`,{className:`text-xs text-slate-700 dark:text-slate-300`,children:r.webhook.eventSummary})]}),r.webhook.deliveryId&&(0,N.jsxs)(`div`,{className:`px-4 py-3 grid grid-cols-[8rem_1fr] gap-x-4 items-center`,children:[(0,N.jsx)(`span`,{className:`text-xs text-slate-500 dark:text-slate-400`,children:`Delivery ID`}),(0,N.jsx)(`span`,{className:`font-mono text-xs text-slate-700 dark:text-slate-300`,children:r.webhook.deliveryId})]}),(0,N.jsxs)(`div`,{className:`px-4 py-3 grid grid-cols-[8rem_1fr] gap-x-4 items-center`,children:[(0,N.jsx)(`span`,{className:`text-xs text-slate-500 dark:text-slate-400`,children:`Status`}),(0,N.jsx)(oi,{result:r.webhook.status===`processed`?`completed`:`dead-letter`})]}),(0,N.jsxs)(`div`,{className:`px-4 py-3 grid grid-cols-[8rem_1fr] gap-x-4 items-center`,children:[(0,N.jsx)(`span`,{className:`text-xs text-slate-500 dark:text-slate-400`,children:`Matched Agents`}),(0,N.jsx)(`span`,{className:`text-xs text-slate-700 dark:text-slate-300`,children:r.webhook.matchedAgents})]})]}),r.webhook.headers&&(0,N.jsxs)(`div`,{className:`border-t border-slate-200 dark:border-slate-800`,children:[(0,N.jsx)(`div`,{className:`px-4 py-2.5 border-b border-slate-100 dark:border-slate-800/50`,children:(0,N.jsx)(`h3`,{className:`text-xs font-medium text-slate-500 dark:text-slate-400 uppercase tracking-wide`,children:`Headers`})}),(0,N.jsx)(`pre`,{className:`px-4 py-3 text-xs font-mono text-slate-700 dark:text-slate-300 overflow-x-auto whitespace-pre-wrap break-all`,children:Bi(r.webhook.headers)})]}),(()=>{let e=zi(r.webhook.body,r.webhook.headers);return(0,N.jsxs)(N.Fragment,{children:[e&&(0,N.jsxs)(`div`,{className:`border-t border-slate-200 dark:border-slate-800`,children:[(0,N.jsx)(`div`,{className:`px-4 py-2.5 border-b border-slate-100 dark:border-slate-800/50`,children:(0,N.jsx)(`h3`,{className:`text-xs font-medium text-slate-500 dark:text-slate-400 uppercase tracking-wide`,children:e.label})}),(0,N.jsx)(`pre`,{className:`px-4 py-3 text-xs font-mono text-slate-700 dark:text-slate-300 overflow-x-auto whitespace-pre-wrap break-all max-h-96 overflow-y-auto`,children:e.content})]}),r.webhook.body&&(0,N.jsxs)(`div`,{className:`border-t border-slate-200 dark:border-slate-800`,children:[(0,N.jsx)(`div`,{className:`px-4 py-2.5 border-b border-slate-100 dark:border-slate-800/50`,children:(0,N.jsx)(`h3`,{className:`text-xs font-medium text-slate-500 dark:text-slate-400 uppercase tracking-wide`,children:e?`Raw Body`:`Body`})}),(0,N.jsx)(`pre`,{className:`px-4 py-3 text-xs font-mono text-slate-700 dark:text-slate-300 overflow-x-auto whitespace-pre-wrap break-all`,children:Bi(r.webhook.body)})]})]})})()]}),r.triggerType===`agent`&&(0,N.jsxs)(`div`,{className:`bg-slate-50 dark:bg-slate-900 rounded-lg border border-slate-200 dark:border-slate-800 overflow-hidden`,children:[(0,N.jsx)(`div`,{className:`px-4 py-2.5 border-b border-slate-200 dark:border-slate-800`,children:(0,N.jsx)(`h2`,{className:`text-sm font-medium text-slate-900 dark:text-white`,children:`Agent Trigger Details`})}),(0,N.jsx)(`div`,{className:`divide-y divide-slate-100 dark:divide-slate-800/50 max-w-2xl`,children:r.callerAgent?(0,N.jsxs)(N.Fragment,{children:[(0,N.jsxs)(`div`,{className:`px-4 py-3 grid grid-cols-[8rem_1fr] gap-x-4 items-center`,children:[(0,N.jsx)(`span`,{className:`text-xs text-slate-500 dark:text-slate-400`,children:`Called by`}),(0,N.jsx)(M,{to:`/dashboard/agents/${encodeURIComponent(r.callerAgent)}`,className:`hover:underline text-xs flex items-center gap-1.5`,children:(0,N.jsx)(`span`,{className:`agent-color-text`,style:P(r.callerAgent,n),children:r.callerAgent})})]}),r.callerInstance&&(0,N.jsxs)(`div`,{className:`px-4 py-3 grid grid-cols-[8rem_1fr] gap-x-4 items-center`,children:[(0,N.jsx)(`span`,{className:`text-xs text-slate-500 dark:text-slate-400`,children:`Caller Instance`}),(0,N.jsx)(M,{to:`/dashboard/agents/${encodeURIComponent(r.callerAgent)}/instances/${encodeURIComponent(r.callerInstance)}`,className:`font-mono text-xs text-blue-600 dark:text-blue-400 hover:underline`,children:Si(r.callerInstance)})]}),r.callDepth!==void 0&&(0,N.jsxs)(`div`,{className:`px-4 py-3 grid grid-cols-[8rem_1fr] gap-x-4 items-center`,children:[(0,N.jsx)(`span`,{className:`text-xs text-slate-500 dark:text-slate-400`,children:`Call Depth`}),(0,N.jsx)(`span`,{className:`text-xs text-slate-700 dark:text-slate-300`,children:r.callDepth})]})]}):(0,N.jsx)(`div`,{className:`px-4 py-3`,children:(0,N.jsx)(`span`,{className:`text-xs text-slate-500 dark:text-slate-400`,children:`Caller information not available`})})}),r.triggerContext&&(0,N.jsxs)(`div`,{className:`border-t border-slate-200 dark:border-slate-800`,children:[(0,N.jsx)(`div`,{className:`px-4 py-2.5 border-b border-slate-100 dark:border-slate-800/50`,children:(0,N.jsx)(`h3`,{className:`text-xs font-medium text-slate-500 dark:text-slate-400 uppercase tracking-wide`,children:`Trigger Context`})}),(0,N.jsx)(`pre`,{className:`px-4 py-3 text-xs font-mono text-slate-700 dark:text-slate-300 overflow-x-auto whitespace-pre-wrap break-all`,children:r.triggerContext})]})]}),r.triggerType===`manual`&&(0,N.jsxs)(`div`,{className:`bg-slate-50 dark:bg-slate-900 rounded-lg border border-slate-200 dark:border-slate-800 overflow-hidden`,children:[(0,N.jsx)(`div`,{className:`px-4 py-2.5 border-b border-slate-200 dark:border-slate-800`,children:(0,N.jsx)(`h2`,{className:`text-sm font-medium text-slate-900 dark:text-white`,children:`Manual Trigger Details`})}),r.triggerContext?(0,N.jsxs)(`div`,{children:[(0,N.jsx)(`div`,{className:`px-4 py-2.5 border-b border-slate-100 dark:border-slate-800/50`,children:(0,N.jsx)(`h3`,{className:`text-xs font-medium text-slate-500 dark:text-slate-400 uppercase tracking-wide`,children:`Prompt`})}),(0,N.jsx)(`pre`,{className:`px-4 py-3 text-xs font-mono text-slate-700 dark:text-slate-300 overflow-x-auto whitespace-pre-wrap break-all`,children:r.triggerContext})]}):(0,N.jsx)(`div`,{className:`px-4 py-3`,children:(0,N.jsx)(`span`,{className:`text-xs text-slate-500 dark:text-slate-400`,children:`Prompt not available (run predates context tracking)`})})]}),r.triggerType===`schedule`&&(0,N.jsxs)(`div`,{className:`bg-slate-50 dark:bg-slate-900 rounded-lg border border-slate-200 dark:border-slate-800 overflow-hidden`,children:[(0,N.jsx)(`div`,{className:`px-4 py-2.5 border-b border-slate-200 dark:border-slate-800`,children:(0,N.jsx)(`h2`,{className:`text-sm font-medium text-slate-900 dark:text-white`,children:`Schedule Trigger Details`})}),(0,N.jsx)(`div`,{className:`px-4 py-3`,children:(0,N.jsxs)(`span`,{className:`text-xs text-slate-500 dark:text-slate-400`,children:[`Scheduled run at `,Ci(r.startedAt)]})})]})]})}function Hi(){let e=(0,x.useContext)(si);if(!e)return null;let{detail:t,isRunning:n}=e,r=t?.run;return!r&&n?(0,N.jsx)(`div`,{className:`bg-slate-50 dark:bg-slate-900 rounded-lg border border-slate-200 dark:border-slate-800 p-6 text-center`,children:(0,N.jsx)(`p`,{className:`text-sm text-slate-500 dark:text-slate-400`,children:`Instance is currently running. Telemetry data will be available once the run completes.`})}):r?(0,N.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-4`,children:[(0,N.jsxs)(`div`,{className:`bg-slate-50 dark:bg-slate-900 rounded-lg border border-slate-200 dark:border-slate-800 p-4`,children:[(0,N.jsx)(`h2`,{className:`text-sm font-medium text-slate-900 dark:text-white mb-3`,children:`Run Info`}),(0,N.jsxs)(`dl`,{className:`space-y-2 text-sm`,children:[(0,N.jsxs)(`div`,{className:`flex justify-between`,children:[(0,N.jsx)(`dt`,{className:`text-slate-500 dark:text-slate-400`,children:`Status`}),(0,N.jsx)(`dd`,{children:(0,N.jsx)(oi,{result:r.result})})]}),r.exit_code!=null&&(0,N.jsxs)(`div`,{className:`flex justify-between`,children:[(0,N.jsx)(`dt`,{className:`text-slate-500 dark:text-slate-400`,children:`Exit Code`}),(0,N.jsx)(`dd`,{className:r.exit_code===0?`text-green-600 dark:text-green-400`:`text-red-600 dark:text-red-400`,children:r.exit_code})]}),(0,N.jsxs)(`div`,{className:`flex justify-between`,children:[(0,N.jsx)(`dt`,{className:`text-slate-500 dark:text-slate-400`,children:`Started`}),(0,N.jsx)(`dd`,{className:`text-slate-700 dark:text-slate-300`,children:Ci(r.started_at)})]}),(0,N.jsxs)(`div`,{className:`flex justify-between`,children:[(0,N.jsx)(`dt`,{className:`text-slate-500 dark:text-slate-400`,children:`Ended`}),(0,N.jsx)(`dd`,{className:`text-slate-700 dark:text-slate-300`,children:Ci(r.started_at+r.duration_ms)})]}),(0,N.jsxs)(`div`,{className:`flex justify-between`,children:[(0,N.jsx)(`dt`,{className:`text-slate-500 dark:text-slate-400`,children:`Duration`}),(0,N.jsx)(`dd`,{className:`text-slate-700 dark:text-slate-300`,children:yi(r.duration_ms)})]}),(0,N.jsxs)(`div`,{className:`flex justify-between`,children:[(0,N.jsx)(`dt`,{className:`text-slate-500 dark:text-slate-400`,children:`Turns`}),(0,N.jsx)(`dd`,{className:`text-slate-700 dark:text-slate-300`,children:r.turn_count})]}),r.error_message&&(0,N.jsxs)(`div`,{children:[(0,N.jsx)(`dt`,{className:`text-slate-500 dark:text-slate-400 mb-1`,children:`Error`}),(0,N.jsx)(`dd`,{className:`text-red-600 dark:text-red-400 text-xs bg-red-50 dark:bg-red-900/20 rounded p-2 font-mono break-all`,children:r.error_message})]})]})]}),(0,N.jsxs)(`div`,{className:`bg-slate-50 dark:bg-slate-900 rounded-lg border border-slate-200 dark:border-slate-800 p-4`,children:[(0,N.jsx)(`h2`,{className:`text-sm font-medium text-slate-900 dark:text-white mb-3`,children:`Token Usage`}),(0,N.jsxs)(`dl`,{className:`space-y-2 text-sm`,children:[(0,N.jsxs)(`div`,{className:`flex justify-between`,children:[(0,N.jsx)(`dt`,{className:`text-slate-500 dark:text-slate-400`,children:`Input`}),(0,N.jsx)(`dd`,{className:`text-slate-700 dark:text-slate-300`,children:xi(r.input_tokens)})]}),(0,N.jsxs)(`div`,{className:`flex justify-between`,children:[(0,N.jsx)(`dt`,{className:`text-slate-500 dark:text-slate-400`,children:`Output`}),(0,N.jsx)(`dd`,{className:`text-slate-700 dark:text-slate-300`,children:xi(r.output_tokens)})]}),(0,N.jsxs)(`div`,{className:`flex justify-between`,children:[(0,N.jsx)(`dt`,{className:`text-slate-500 dark:text-slate-400`,children:`Cache Read`}),(0,N.jsx)(`dd`,{className:`text-slate-700 dark:text-slate-300`,children:xi(r.cache_read_tokens)})]}),(0,N.jsxs)(`div`,{className:`flex justify-between`,children:[(0,N.jsx)(`dt`,{className:`text-slate-500 dark:text-slate-400`,children:`Cache Write`}),(0,N.jsx)(`dd`,{className:`text-slate-700 dark:text-slate-300`,children:xi(r.cache_write_tokens)})]}),(0,N.jsxs)(`div`,{className:`flex justify-between border-t border-slate-200 dark:border-slate-800 pt-2 mt-2`,children:[(0,N.jsx)(`dt`,{className:`text-slate-500 dark:text-slate-400 font-medium`,children:`Total`}),(0,N.jsx)(`dd`,{className:`text-slate-700 dark:text-slate-300 font-medium`,children:xi(r.total_tokens)})]}),(0,N.jsxs)(`div`,{className:`flex justify-between`,children:[(0,N.jsx)(`dt`,{className:`text-slate-500 dark:text-slate-400 font-medium`,children:`Cost`}),(0,N.jsx)(`dd`,{className:`text-slate-700 dark:text-slate-300 font-medium`,children:bi(r.cost_usd)})]})]})]})]}):null}function Ui({options:e,value:t,onChange:n,placeholder:r}){let[i,a]=(0,x.useState)(!1),o=(0,x.useRef)(null);return(0,x.useEffect)(()=>{let e=e=>{o.current&&!o.current.contains(e.target)&&a(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[]),(0,N.jsxs)(`div`,{ref:o,className:`relative`,children:[(0,N.jsxs)(`button`,{type:`button`,onClick:()=>a(!i),className:`inline-flex items-center gap-1.5 text-sm rounded-lg border border-slate-200 dark:border-slate-700 bg-white dark:bg-slate-800 text-slate-700 dark:text-slate-200 pl-3 pr-2 py-1.5 hover:border-slate-300 dark:hover:border-slate-600 transition-colors shadow-sm`,children:[(0,N.jsx)(`span`,{children:e.find(e=>e.value===t)?.label||r}),(0,N.jsx)(Gi,{})]}),i&&(0,N.jsx)(`div`,{className:`absolute z-50 mt-1 min-w-[160px] rounded-lg border border-slate-200 dark:border-slate-700 bg-white dark:bg-slate-800 shadow-lg py-1 max-h-64 overflow-y-auto`,children:e.map(e=>(0,N.jsx)(`button`,{type:`button`,onClick:()=>{n(e.value),a(!1)},className:`w-full text-left px-3 py-1.5 text-sm transition-colors ${e.value===t?`bg-blue-50 dark:bg-blue-900/30 text-blue-700 dark:text-blue-300 font-medium`:`text-slate-700 dark:text-slate-300 hover:bg-slate-50 dark:hover:bg-slate-700/50`}`,children:e.label},e.value))})]})}function Wi({options:e,selected:t,onChange:n,label:r}){let[i,a]=(0,x.useState)(!1),o=(0,x.useRef)(null);(0,x.useEffect)(()=>{let e=e=>{o.current&&!o.current.contains(e.target)&&a(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[]);let s=t.length===e.length,c=t.length===0,l=e=>{t.includes(e)?n(t.filter(t=>t!==e)):n([...t,e])},u=()=>{n(s?[]:e.map(e=>e.value))},d=s||c?r:t.length===1?e.find(e=>e.value===t[0])?.label??r:`${t.length} selected`;return(0,N.jsxs)(`div`,{ref:o,className:`relative`,children:[(0,N.jsxs)(`button`,{type:`button`,onClick:()=>a(!i),className:`inline-flex items-center gap-1.5 text-sm rounded-lg border border-slate-200 dark:border-slate-700 bg-white dark:bg-slate-800 text-slate-700 dark:text-slate-200 pl-3 pr-2 py-1.5 hover:border-slate-300 dark:hover:border-slate-600 transition-colors shadow-sm`,children:[!s&&!c&&(0,N.jsx)(`span`,{className:`inline-flex items-center justify-center w-4 h-4 rounded-full bg-blue-600 text-white text-[10px] font-bold leading-none`,children:t.length}),(0,N.jsx)(`span`,{children:d}),(0,N.jsx)(Gi,{})]}),i&&(0,N.jsxs)(`div`,{className:`absolute z-50 mt-1 min-w-[180px] rounded-lg border border-slate-200 dark:border-slate-700 bg-white dark:bg-slate-800 shadow-lg py-1 max-h-64 overflow-y-auto`,children:[(0,N.jsx)(`button`,{type:`button`,onClick:u,className:`w-full text-left px-3 py-1.5 text-xs font-medium text-slate-500 dark:text-slate-400 hover:bg-slate-50 dark:hover:bg-slate-700/50 transition-colors border-b border-slate-100 dark:border-slate-700`,children:s?`Deselect all`:`Select all`}),e.map(e=>{let n=t.includes(e.value);return(0,N.jsxs)(`button`,{type:`button`,onClick:()=>l(e.value),className:`w-full text-left px-3 py-1.5 text-sm flex items-center gap-2 transition-colors ${n?`text-slate-900 dark:text-white`:`text-slate-500 dark:text-slate-400 hover:bg-slate-50 dark:hover:bg-slate-700/50`}`,children:[(0,N.jsx)(`span`,{className:`flex items-center justify-center w-3.5 h-3.5 rounded border transition-colors ${n?`bg-blue-600 border-blue-600`:`border-slate-300 dark:border-slate-600`}`,children:n&&(0,N.jsx)(`svg`,{className:`w-2.5 h-2.5 text-white`,viewBox:`0 0 12 12`,fill:`none`,children:(0,N.jsx)(`path`,{d:`M2 6l3 3 5-5`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`})})}),e.dot&&(0,N.jsx)(`span`,{className:`w-2 h-2 rounded-full shrink-0 ${e.dot}`}),(0,N.jsx)(`span`,{children:e.label})]},e.value)})]})]})}function Gi(){return(0,N.jsx)(`svg`,{className:`w-4 h-4 text-slate-400`,viewBox:`0 0 20 20`,fill:`currentColor`,children:(0,N.jsx)(`path`,{fillRule:`evenodd`,d:`M5.23 7.21a.75.75 0 011.06.02L10 11.168l3.71-3.938a.75.75 0 111.08 1.04l-4.25 4.5a.75.75 0 01-1.08 0l-4.25-4.5a.75.75 0 01.02-1.06z`,clipRule:`evenodd`})})}var Ki=50,qi=[`pending`,`running`,`completed`],Ji=[{value:`pending`,label:`Pending`,dot:`bg-amber-400`},{value:`running`,label:`Running`,dot:`bg-blue-500`},{value:`completed`,label:`Completed`,dot:`bg-green-500`},{value:`error`,label:`Error`,dot:`bg-red-500`},{value:`dead-letter`,label:`Dead Letter`,dot:`bg-red-300 dark:bg-red-800`}],Yi=[{value:``,label:`All Types`},{value:`schedule`,label:`Schedule`},{value:`webhook`,label:`Webhook`},{value:`manual`,label:`Manual`},{value:`agent`,label:`Agent`}];function Xi(e){if(!e)return qi;let t=e.split(`,`).filter(Boolean);return t.length>0?t:qi}function Zi(){let[e,t]=Ln(),n=e.get(`agent`)||void 0,r=e.get(`type`)||void 0,i=e.get(`status`),a=(0,x.useMemo)(()=>Xi(i),[i]),[o,s]=(0,x.useState)(0),c=Nr(),l=c.map(e=>e.name),u=a.join(`,`),d=a.length===Ji.length?void 0:a,{data:f,isLoading:p}=ni({key:`activity:${o}:${n??``}:${r??``}:${u}`,fetcher:e=>rr(Ki,o,n,r,d,e),invalidateOn:[`runs`,`triggers`],keyChangeDebounceMs:150}),m=f?.rows??[],h=f?.total??0,g=f?.pendingCount??0;(0,x.useEffect)(()=>{s(0)},[n,r,u]);let _=(0,x.useCallback)((e,n)=>{t(t=>{let r=new URLSearchParams(t);return n?r.set(e,n):r.delete(e),r.delete(`offset`),r})},[t]),v=(0,x.useCallback)(e=>{t(t=>{let n=new URLSearchParams(t);return e.length===0||e.length===Ji.length?n.delete(`status`):n.set(`status`,e.join(`,`)),n.delete(`offset`),n})},[t]),y=Math.floor(o/Ki)+1,b=Math.max(1,Math.ceil(h/Ki)),S=[{value:``,label:`All Agents`},...c.map(e=>({value:e.name,label:e.name}))];return(0,N.jsxs)(`div`,{className:`space-y-6`,children:[(0,N.jsxs)(`div`,{className:`flex items-center justify-between flex-wrap gap-3`,children:[(0,N.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,N.jsx)(`h1`,{className:`text-xl font-bold text-slate-900 dark:text-white`,children:`Activity`}),g>0&&(0,N.jsxs)(`span`,{className:`inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium bg-amber-100 text-amber-700 dark:bg-amber-900/40 dark:text-amber-400`,children:[g,` pending`]})]}),(0,N.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,N.jsx)(Ui,{options:S,value:n||``,onChange:e=>_(`agent`,e||void 0),placeholder:`All Agents`}),(0,N.jsx)(Ui,{options:Yi,value:r||``,onChange:e=>_(`type`,e||void 0),placeholder:`All Types`}),(0,N.jsx)(Wi,{options:Ji,selected:a,onChange:v,label:`All Statuses`})]})]}),(0,N.jsxs)(`div`,{className:`bg-slate-50 dark:bg-slate-900 rounded-lg border border-slate-200 dark:border-slate-800 overflow-hidden`,children:[(0,N.jsx)(`div`,{className:`overflow-x-auto`,children:(0,N.jsx)(ji,{rows:m,agentNames:l,loading:p&&m.length===0})}),b>1&&(0,N.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-2.5 border-t border-slate-200 dark:border-slate-800`,children:[(0,N.jsx)(`button`,{onClick:()=>s(Math.max(0,o-Ki)),disabled:o===0,className:`px-3 py-1 text-xs rounded bg-slate-200 dark:bg-slate-800 text-slate-700 dark:text-slate-300 hover:bg-slate-300 dark:hover:bg-slate-700 disabled:opacity-40 transition-colors`,children:`Previous`}),(0,N.jsxs)(`span`,{className:`text-xs text-slate-500 dark:text-slate-400`,children:[`Page `,y,` of `,b,` (`,h,` total)`]}),(0,N.jsx)(`button`,{onClick:()=>s(o+Ki),disabled:o+Ki>=h,className:`px-3 py-1 text-xs rounded bg-slate-200 dark:bg-slate-800 text-slate-700 dark:text-slate-300 hover:bg-slate-300 dark:hover:bg-slate-700 disabled:opacity-40 transition-colors`,children:`Next`})]})]})]})}function Qi(e){if(!e)return`—`;try{return JSON.stringify(JSON.parse(e),null,2)}catch{return e}}function $i(){let{instanceId:e}=dt(),{agents:t}=Br(),n=t.map(e=>e.name),[r,i]=(0,x.useState)(void 0),[a,o]=(0,x.useState)(null),[s,c]=(0,x.useState)(null),[l,u]=(0,x.useState)(!1);(0,x.useEffect)(()=>{e&&ir(e).then(e=>i(e.trigger)).catch(()=>i(null))},[e]);let d=(0,x.useCallback)(async()=>{if(r?.webhook?.receiptId){o(null),c(null),u(!0);try{let e=await nr(r.webhook.receiptId);o(`Replayed: ${e.matched} matched, ${e.skipped} skipped`)}catch(e){c(e instanceof Error?e.message:`Replay failed`)}finally{u(!1)}}},[r]);if(!e)return null;if(r===void 0)return(0,N.jsx)(`div`,{className:`text-center py-12 text-slate-500 dark:text-slate-400`,children:`Loading...`});if(r===null)return(0,N.jsx)(`div`,{className:`space-y-6`,children:(0,N.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,N.jsx)(M,{to:`/jobs`,className:`text-slate-500 hover:text-slate-700 dark:hover:text-slate-300`,children:(0,N.jsx)(`svg`,{className:`w-5 h-5`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,N.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M15 19l-7-7 7-7`})})}),(0,N.jsx)(`h1`,{className:`text-xl font-bold text-slate-900 dark:text-white`,children:`Trigger not found`})]})});let f=!!(r.webhook?.receiptId&&(r.webhook.headers||r.webhook.body));return(0,N.jsxs)(`div`,{className:`space-y-6`,children:[(0,N.jsxs)(`div`,{className:`flex items-center justify-between flex-wrap gap-3`,children:[(0,N.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,N.jsx)(M,{to:`/jobs`,className:`text-slate-500 hover:text-slate-700 dark:hover:text-slate-300`,children:(0,N.jsx)(`svg`,{className:`w-5 h-5`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,N.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M15 19l-7-7 7-7`})})}),(0,N.jsxs)(`div`,{children:[(0,N.jsx)(`h1`,{className:`text-xl font-bold text-slate-900 dark:text-white font-mono`,children:r.instanceId}),(0,N.jsx)(`div`,{className:`text-xs text-slate-500 dark:text-slate-400`,children:`Trigger Detail`})]}),(0,N.jsx)(ai,{type:r.triggerType})]}),r.triggerType===`webhook`&&f&&(0,N.jsxs)(`div`,{className:`flex items-center gap-2`,children:[a&&(0,N.jsx)(`span`,{className:`text-xs text-green-600 dark:text-green-400`,children:a}),s&&(0,N.jsx)(`span`,{className:`text-xs text-red-600 dark:text-red-400`,children:s}),(0,N.jsx)(`button`,{onClick:d,disabled:l,className:`px-3 py-1.5 text-xs font-medium rounded-md bg-blue-600 hover:bg-blue-700 disabled:opacity-40 text-white transition-colors`,children:l?`Replaying...`:`Replay`})]})]}),(0,N.jsxs)(`div`,{className:`bg-slate-50 dark:bg-slate-900 rounded-lg border border-slate-200 dark:border-slate-800 overflow-hidden`,children:[(0,N.jsx)(`div`,{className:`px-4 py-2.5 border-b border-slate-200 dark:border-slate-800`,children:(0,N.jsx)(`h2`,{className:`text-sm font-medium text-slate-900 dark:text-white`,children:`Overview`})}),(0,N.jsxs)(`div`,{className:`divide-y divide-slate-100 dark:divide-slate-800/50 max-w-2xl`,children:[(0,N.jsxs)(`div`,{className:`px-4 py-3 grid grid-cols-[8rem_1fr] gap-x-4 items-center`,children:[(0,N.jsx)(`span`,{className:`text-xs text-slate-500 dark:text-slate-400`,children:`Trigger Type`}),(0,N.jsx)(ai,{type:r.triggerType})]}),(0,N.jsxs)(`div`,{className:`px-4 py-3 grid grid-cols-[8rem_1fr] gap-x-4 items-center`,children:[(0,N.jsx)(`span`,{className:`text-xs text-slate-500 dark:text-slate-400`,children:`Agent`}),(0,N.jsx)(M,{to:`/dashboard/agents/${encodeURIComponent(r.agentName)}`,className:`hover:underline text-xs flex items-center gap-1.5`,children:(0,N.jsx)(`span`,{className:`agent-color-text`,style:P(r.agentName,n),children:r.agentName})})]}),(0,N.jsxs)(`div`,{className:`px-4 py-3 grid grid-cols-[8rem_1fr] gap-x-4 items-center`,children:[(0,N.jsx)(`span`,{className:`text-xs text-slate-500 dark:text-slate-400`,children:`Instance`}),(0,N.jsx)(M,{to:`/dashboard/agents/${encodeURIComponent(r.agentName)}/instances/${encodeURIComponent(r.instanceId)}`,className:`font-mono text-xs text-blue-600 dark:text-blue-400 hover:underline`,children:r.instanceId})]}),(0,N.jsxs)(`div`,{className:`px-4 py-3 grid grid-cols-[8rem_1fr] gap-x-4 items-center`,children:[(0,N.jsx)(`span`,{className:`text-xs text-slate-500 dark:text-slate-400`,children:`Time`}),(0,N.jsx)(`span`,{className:`text-xs text-slate-700 dark:text-slate-300`,children:Ci(r.startedAt)})]}),r.triggerSource&&(0,N.jsxs)(`div`,{className:`px-4 py-3 grid grid-cols-[8rem_1fr] gap-x-4 items-center`,children:[(0,N.jsx)(`span`,{className:`text-xs text-slate-500 dark:text-slate-400`,children:`Source`}),(0,N.jsx)(`span`,{className:`text-xs text-slate-700 dark:text-slate-300`,children:r.triggerSource})]})]})]}),r.triggerType===`webhook`&&r.webhook&&(0,N.jsxs)(`div`,{className:`bg-slate-50 dark:bg-slate-900 rounded-lg border border-slate-200 dark:border-slate-800 overflow-hidden`,children:[(0,N.jsx)(`div`,{className:`px-4 py-2.5 border-b border-slate-200 dark:border-slate-800`,children:(0,N.jsx)(`h2`,{className:`text-sm font-medium text-slate-900 dark:text-white`,children:`Webhook Details`})}),(0,N.jsxs)(`div`,{className:`divide-y divide-slate-100 dark:divide-slate-800/50 max-w-2xl`,children:[(0,N.jsxs)(`div`,{className:`px-4 py-3 grid grid-cols-[8rem_1fr] gap-x-4 items-center`,children:[(0,N.jsx)(`span`,{className:`text-xs text-slate-500 dark:text-slate-400`,children:`Receipt ID`}),(0,N.jsx)(M,{to:`/dashboard/webhooks/${encodeURIComponent(r.webhook.receiptId)}`,className:`font-mono text-xs text-blue-600 dark:text-blue-400 hover:underline`,children:Si(r.webhook.receiptId)})]}),(0,N.jsxs)(`div`,{className:`px-4 py-3 grid grid-cols-[8rem_1fr] gap-x-4 items-center`,children:[(0,N.jsx)(`span`,{className:`text-xs text-slate-500 dark:text-slate-400`,children:`Source`}),(0,N.jsx)(`span`,{className:`text-xs text-slate-700 dark:text-slate-300`,children:r.webhook.source})]}),r.webhook.eventSummary&&(0,N.jsxs)(`div`,{className:`px-4 py-3 grid grid-cols-[8rem_1fr] gap-x-4 items-center`,children:[(0,N.jsx)(`span`,{className:`text-xs text-slate-500 dark:text-slate-400`,children:`Event`}),(0,N.jsx)(`span`,{className:`text-xs text-slate-700 dark:text-slate-300`,children:r.webhook.eventSummary})]}),r.webhook.deliveryId&&(0,N.jsxs)(`div`,{className:`px-4 py-3 grid grid-cols-[8rem_1fr] gap-x-4 items-center`,children:[(0,N.jsx)(`span`,{className:`text-xs text-slate-500 dark:text-slate-400`,children:`Delivery ID`}),(0,N.jsx)(`span`,{className:`font-mono text-xs text-slate-700 dark:text-slate-300`,children:r.webhook.deliveryId})]}),(0,N.jsxs)(`div`,{className:`px-4 py-3 grid grid-cols-[8rem_1fr] gap-x-4 items-center`,children:[(0,N.jsx)(`span`,{className:`text-xs text-slate-500 dark:text-slate-400`,children:`Status`}),(0,N.jsx)(oi,{result:r.webhook.status===`processed`?`completed`:`dead-letter`})]}),(0,N.jsxs)(`div`,{className:`px-4 py-3 grid grid-cols-[8rem_1fr] gap-x-4 items-center`,children:[(0,N.jsx)(`span`,{className:`text-xs text-slate-500 dark:text-slate-400`,children:`Matched Agents`}),(0,N.jsx)(`span`,{className:`text-xs text-slate-700 dark:text-slate-300`,children:r.webhook.matchedAgents})]})]}),r.webhook.headers&&(0,N.jsxs)(`div`,{className:`border-t border-slate-200 dark:border-slate-800`,children:[(0,N.jsx)(`div`,{className:`px-4 py-2.5 border-b border-slate-100 dark:border-slate-800/50`,children:(0,N.jsx)(`h3`,{className:`text-xs font-medium text-slate-500 dark:text-slate-400 uppercase tracking-wide`,children:`Headers`})}),(0,N.jsx)(`pre`,{className:`px-4 py-3 text-xs font-mono text-slate-700 dark:text-slate-300 overflow-x-auto whitespace-pre-wrap break-all`,children:Qi(r.webhook.headers)})]}),(()=>{let e=zi(r.webhook.body,r.webhook.headers);return(0,N.jsxs)(N.Fragment,{children:[e&&(0,N.jsxs)(`div`,{className:`border-t border-slate-200 dark:border-slate-800`,children:[(0,N.jsx)(`div`,{className:`px-4 py-2.5 border-b border-slate-100 dark:border-slate-800/50`,children:(0,N.jsx)(`h3`,{className:`text-xs font-medium text-slate-500 dark:text-slate-400 uppercase tracking-wide`,children:e.label})}),(0,N.jsx)(`pre`,{className:`px-4 py-3 text-xs font-mono text-slate-700 dark:text-slate-300 overflow-x-auto whitespace-pre-wrap break-all max-h-96 overflow-y-auto`,children:e.content})]}),r.webhook.body&&(0,N.jsxs)(`div`,{className:`border-t border-slate-200 dark:border-slate-800`,children:[(0,N.jsx)(`div`,{className:`px-4 py-2.5 border-b border-slate-100 dark:border-slate-800/50`,children:(0,N.jsx)(`h3`,{className:`text-xs font-medium text-slate-500 dark:text-slate-400 uppercase tracking-wide`,children:e?`Raw Body`:`Body`})}),(0,N.jsx)(`pre`,{className:`px-4 py-3 text-xs font-mono text-slate-700 dark:text-slate-300 overflow-x-auto whitespace-pre-wrap break-all`,children:Qi(r.webhook.body)})]})]})})()]}),r.triggerType===`agent`&&(0,N.jsxs)(`div`,{className:`bg-slate-50 dark:bg-slate-900 rounded-lg border border-slate-200 dark:border-slate-800 overflow-hidden`,children:[(0,N.jsx)(`div`,{className:`px-4 py-2.5 border-b border-slate-200 dark:border-slate-800`,children:(0,N.jsx)(`h2`,{className:`text-sm font-medium text-slate-900 dark:text-white`,children:`Agent Trigger Details`})}),(0,N.jsx)(`div`,{className:`divide-y divide-slate-100 dark:divide-slate-800/50 max-w-2xl`,children:r.callerAgent?(0,N.jsxs)(N.Fragment,{children:[(0,N.jsxs)(`div`,{className:`px-4 py-3 grid grid-cols-[8rem_1fr] gap-x-4 items-center`,children:[(0,N.jsx)(`span`,{className:`text-xs text-slate-500 dark:text-slate-400`,children:`Called by`}),(0,N.jsx)(M,{to:`/dashboard/agents/${encodeURIComponent(r.callerAgent)}`,className:`hover:underline text-xs flex items-center gap-1.5`,children:(0,N.jsx)(`span`,{className:`agent-color-text`,style:P(r.callerAgent,n),children:r.callerAgent})})]}),r.callerInstance&&(0,N.jsxs)(`div`,{className:`px-4 py-3 grid grid-cols-[8rem_1fr] gap-x-4 items-center`,children:[(0,N.jsx)(`span`,{className:`text-xs text-slate-500 dark:text-slate-400`,children:`Caller Instance`}),(0,N.jsx)(M,{to:`/dashboard/agents/${encodeURIComponent(r.callerAgent)}/instances/${encodeURIComponent(r.callerInstance)}`,className:`font-mono text-xs text-blue-600 dark:text-blue-400 hover:underline`,children:Si(r.callerInstance)})]}),r.callDepth!==void 0&&(0,N.jsxs)(`div`,{className:`px-4 py-3 grid grid-cols-[8rem_1fr] gap-x-4 items-center`,children:[(0,N.jsx)(`span`,{className:`text-xs text-slate-500 dark:text-slate-400`,children:`Call Depth`}),(0,N.jsx)(`span`,{className:`text-xs text-slate-700 dark:text-slate-300`,children:r.callDepth})]})]}):(0,N.jsx)(`div`,{className:`px-4 py-3`,children:(0,N.jsx)(`span`,{className:`text-xs text-slate-500 dark:text-slate-400`,children:`Caller information not available`})})}),r.triggerContext&&(0,N.jsxs)(`div`,{className:`border-t border-slate-200 dark:border-slate-800`,children:[(0,N.jsx)(`div`,{className:`px-4 py-2.5 border-b border-slate-100 dark:border-slate-800/50`,children:(0,N.jsx)(`h3`,{className:`text-xs font-medium text-slate-500 dark:text-slate-400 uppercase tracking-wide`,children:`Trigger Context`})}),(0,N.jsx)(`pre`,{className:`px-4 py-3 text-xs font-mono text-slate-700 dark:text-slate-300 overflow-x-auto whitespace-pre-wrap break-all`,children:r.triggerContext})]})]}),r.triggerType===`manual`&&(0,N.jsxs)(`div`,{className:`bg-slate-50 dark:bg-slate-900 rounded-lg border border-slate-200 dark:border-slate-800 overflow-hidden`,children:[(0,N.jsx)(`div`,{className:`px-4 py-2.5 border-b border-slate-200 dark:border-slate-800`,children:(0,N.jsx)(`h2`,{className:`text-sm font-medium text-slate-900 dark:text-white`,children:`Manual Trigger Details`})}),r.triggerContext?(0,N.jsxs)(`div`,{children:[(0,N.jsx)(`div`,{className:`px-4 py-2.5 border-b border-slate-100 dark:border-slate-800/50`,children:(0,N.jsx)(`h3`,{className:`text-xs font-medium text-slate-500 dark:text-slate-400 uppercase tracking-wide`,children:`Prompt`})}),(0,N.jsx)(`pre`,{className:`px-4 py-3 text-xs font-mono text-slate-700 dark:text-slate-300 overflow-x-auto whitespace-pre-wrap break-all`,children:r.triggerContext})]}):(0,N.jsx)(`div`,{className:`px-4 py-3`,children:(0,N.jsx)(`span`,{className:`text-xs text-slate-500 dark:text-slate-400`,children:`Prompt not available (run predates context tracking)`})})]}),r.triggerType===`schedule`&&(0,N.jsxs)(`div`,{className:`bg-slate-50 dark:bg-slate-900 rounded-lg border border-slate-200 dark:border-slate-800 overflow-hidden`,children:[(0,N.jsx)(`div`,{className:`px-4 py-2.5 border-b border-slate-200 dark:border-slate-800`,children:(0,N.jsx)(`h2`,{className:`text-sm font-medium text-slate-900 dark:text-white`,children:`Schedule Trigger Details`})}),(0,N.jsx)(`div`,{className:`px-4 py-3`,children:(0,N.jsxs)(`span`,{className:`text-xs text-slate-500 dark:text-slate-400`,children:[`Scheduled run at `,Ci(r.startedAt)]})})]}),(0,N.jsx)(`div`,{className:`flex justify-end`,children:(0,N.jsx)(M,{to:`/dashboard/agents/${encodeURIComponent(r.agentName)}/instances/${encodeURIComponent(r.instanceId)}`,className:`text-sm text-blue-600 dark:text-blue-400 hover:underline`,children:`View run details →`})})]})}function ea(){let e=Pr(),{data:t}=ni({key:`project-config`,fetcher:e=>er(e),invalidateOn:[`config`]}),[n,r]=(0,x.useState)(``),[i,a]=(0,x.useState)(null),[o,s]=(0,x.useState)(null);(0,x.useEffect)(()=>{t&&r(String(t.projectScale))},[t]);let c=(0,x.useCallback)(async(e,t)=>{a(null),s(null);try{await e(),t&&s(t)}catch(e){a(e instanceof Error?e.message:`Action failed`)}},[]),l=(0,x.useCallback)(()=>{let e=parseInt(n,10);isNaN(e)||e<1||c(()=>hr(e),`Scale updated`)},[n,c]);return(0,N.jsxs)(`div`,{className:`space-y-6`,children:[(0,N.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,N.jsx)(M,{to:`/dashboard`,className:`text-slate-500 hover:text-slate-700 dark:hover:text-slate-300`,children:(0,N.jsx)(`svg`,{className:`w-5 h-5`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,N.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M15 19l-7-7 7-7`})})}),(0,N.jsx)(`h1`,{className:`text-xl font-bold text-slate-900 dark:text-white`,children:`Project Configuration`})]}),i&&(0,N.jsx)(`div`,{className:`bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 rounded-lg p-3 text-sm text-red-700 dark:text-red-400`,children:i}),o&&(0,N.jsx)(`div`,{className:`bg-green-50 dark:bg-green-900/20 border border-green-200 dark:border-green-800 rounded-lg p-3 text-sm text-green-700 dark:text-green-400`,children:o}),(0,N.jsxs)(`div`,{className:`bg-slate-50 dark:bg-slate-900 rounded-lg border border-slate-200 dark:border-slate-800 p-4`,children:[(0,N.jsx)(`h2`,{className:`text-sm font-medium text-slate-900 dark:text-white mb-3`,children:`Project Scale`}),(0,N.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,N.jsx)(`label`,{htmlFor:`project-scale`,className:`text-sm text-slate-500 dark:text-slate-400`,children:`Default scale:`}),(0,N.jsx)(`input`,{id:`project-scale`,type:`number`,min:1,value:n,onChange:e=>r(e.target.value),className:`w-20 px-2 py-1.5 bg-white dark:bg-slate-950 border border-slate-300 dark:border-slate-700 rounded text-base text-slate-900 dark:text-slate-200`}),(0,N.jsx)(`button`,{onClick:l,className:`px-3 py-1.5 text-xs font-medium rounded-md bg-blue-600 hover:bg-blue-700 text-white transition-colors`,children:`Update`})]}),(0,N.jsx)(`p`,{className:`text-xs text-slate-500 dark:text-slate-400 mt-2`,children:`The default number of concurrent instances per agent. Individual agents can override this in their SKILL.md config.`})]}),(0,N.jsxs)(`div`,{className:`bg-slate-50 dark:bg-slate-900 rounded-lg border border-slate-200 dark:border-slate-800 p-4`,children:[(0,N.jsx)(`h2`,{className:`text-sm font-medium text-slate-900 dark:text-white mb-3`,children:`Gateway Status`}),t?(0,N.jsxs)(`dl`,{className:`space-y-2 text-sm`,children:[t.projectName&&(0,N.jsxs)(`div`,{className:`flex justify-between`,children:[(0,N.jsx)(`dt`,{className:`text-slate-500 dark:text-slate-400`,children:`Project`}),(0,N.jsx)(`dd`,{className:`text-slate-700 dark:text-slate-300`,children:t.projectName})]}),t.gatewayPort!=null&&(0,N.jsxs)(`div`,{className:`flex justify-between`,children:[(0,N.jsx)(`dt`,{className:`text-slate-500 dark:text-slate-400`,children:`Port`}),(0,N.jsx)(`dd`,{className:`text-slate-700 dark:text-slate-300 font-mono`,children:t.gatewayPort})]}),(0,N.jsxs)(`div`,{className:`flex justify-between`,children:[(0,N.jsx)(`dt`,{className:`text-slate-500 dark:text-slate-400`,children:`Webhooks`}),(0,N.jsx)(`dd`,{children:t.webhooksActive?(0,N.jsx)(`span`,{className:`text-green-600 dark:text-green-400 text-xs font-medium`,children:`Active`}):(0,N.jsx)(`span`,{className:`text-slate-500 text-xs`,children:`Inactive`})})]})]}):(0,N.jsx)(`p`,{className:`text-sm text-slate-500 dark:text-slate-400`,children:`Loading...`})]}),(0,N.jsxs)(`div`,{className:`bg-slate-50 dark:bg-slate-900 rounded-lg border border-slate-200 dark:border-slate-800 p-4`,children:[(0,N.jsx)(`h2`,{className:`text-sm font-medium text-slate-900 dark:text-white mb-3`,children:`Scheduler Control`}),e?(0,N.jsxs)(`div`,{className:`space-y-3`,children:[(0,N.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,N.jsx)(`span`,{className:`text-slate-500 dark:text-slate-400`,children:`Status:`}),e.paused?(0,N.jsx)(`span`,{className:`text-yellow-600 dark:text-yellow-400 font-medium`,children:`Paused`}):(0,N.jsx)(`span`,{className:`text-green-600 dark:text-green-400 font-medium`,children:`Running`})]}),(0,N.jsx)(`div`,{className:`flex items-center gap-2`,children:e.paused?(0,N.jsx)(`button`,{onClick:()=>c(mr,`Scheduler resumed`),className:`px-4 py-2 text-sm font-medium rounded-md bg-green-600 hover:bg-green-700 text-white transition-colors`,children:`Resume All`}):(0,N.jsx)(`button`,{onClick:()=>c(pr,`Scheduler paused`),className:`px-4 py-2 text-sm font-medium rounded-md bg-yellow-600 hover:bg-yellow-700 text-white transition-colors`,children:`Pause All`})}),(0,N.jsx)(`p`,{className:`text-xs text-slate-500 dark:text-slate-400`,children:`Pausing prevents new scheduled and webhook-triggered runs from starting. Running instances are not affected.`})]}):(0,N.jsx)(`p`,{className:`text-sm text-slate-500 dark:text-slate-400`,children:`Connecting to scheduler...`})]})]})}function ta({label:e,value:t,id:n}){return(0,N.jsxs)(`div`,{className:`bg-slate-50 dark:bg-slate-900 rounded-lg border border-slate-200 dark:border-slate-800 p-3 sm:p-4`,children:[(0,N.jsx)(`div`,{className:`text-xs text-slate-500 dark:text-slate-400 uppercase tracking-wide mb-1`,children:e}),(0,N.jsx)(`div`,{className:`text-lg sm:text-xl font-semibold text-slate-900 dark:text-white`,id:n,children:t})]})}function na(){let{name:e}=dt(),{data:t}=ni({key:`agent-stats:${e}`,fetcher:t=>Qn(e,t),invalidateOn:[`stats`],invalidateAgent:e,enabled:!!e});if(!e)return null;let n=t?.summary;return(0,N.jsx)(`div`,{className:`space-y-6`,children:n&&(0,N.jsxs)(`div`,{className:`grid grid-cols-2 sm:grid-cols-3 lg:grid-cols-6 gap-3`,children:[(0,N.jsx)(ta,{label:`Total Runs`,value:`${n.totalRuns}`}),(0,N.jsx)(ta,{label:`Success`,value:`${n.okRuns}`}),(0,N.jsx)(ta,{label:`Errors`,value:`${n.errorRuns}`}),(0,N.jsx)(ta,{label:`Avg Duration`,value:n.avgDurationMs?yi(n.avgDurationMs):`—`}),(0,N.jsx)(ta,{label:`Total Tokens`,value:xi(n.totalTokens)}),(0,N.jsx)(ta,{label:`Total Cost`,value:bi(n.totalCost)})]})})}function ra(){let{agents:e,schedulerInfo:t}=Br(),n=e.map(e=>e.name),r=e.reduce((e,t)=>e+(t.cumulativeUsage?.totalTokens??0),0),i=e.filter(e=>(e.cumulativeUsage?.totalTokens??0)>0).sort((e,t)=>(t.cumulativeUsage?.totalTokens??0)-(e.cumulativeUsage?.totalTokens??0));return(0,N.jsxs)(`div`,{className:`space-y-6`,children:[(0,N.jsx)(`div`,{className:`flex items-center justify-between flex-wrap gap-3`,children:(0,N.jsx)(`h1`,{className:`text-xl font-bold text-slate-900 dark:text-white`,children:`Stats`})}),(0,N.jsx)(`div`,{className:`flex gap-6 border-b border-slate-200 dark:border-slate-800`,children:(0,N.jsx)(`span`,{className:`pb-2 text-sm font-medium text-blue-600 dark:text-blue-400 border-b-2 border-blue-600 dark:border-blue-400`,children:`Token Usage`})}),t?.startedAt&&(0,N.jsxs)(`div`,{className:`text-sm text-slate-500 dark:text-slate-400`,children:[`Session: `,wi(t.startedAt)]}),(0,N.jsx)(`div`,{className:`bg-slate-50 dark:bg-slate-900 rounded-lg border border-slate-200 dark:border-slate-800`,children:r===0?(0,N.jsx)(`div`,{className:`px-4 py-8 text-center text-slate-500 dark:text-slate-400`,children:`No token usage recorded yet`}):i.map(e=>{let t=e.cumulativeUsage?.totalTokens??0,i=t/r*100;return(0,N.jsxs)(`div`,{className:`px-4 py-3 border-b border-slate-100 dark:border-slate-800/50 last:border-0`,children:[(0,N.jsxs)(`div`,{className:`flex items-center justify-between mb-1.5`,children:[(0,N.jsx)(M,{to:`/dashboard/agents/${encodeURIComponent(e.name)}`,className:`agent-color-text text-sm font-medium hover:underline`,style:P(e.name,n),children:e.name}),(0,N.jsxs)(`span`,{className:`text-xs text-slate-500 dark:text-slate-400`,children:[xi(t),` (`,i.toFixed(1),`%)`]})]}),(0,N.jsx)(`div`,{className:`h-2 rounded-full overflow-hidden bg-slate-200 dark:bg-slate-800`,children:(0,N.jsx)(`div`,{className:`h-full rounded-full agent-color-bg transition-all`,style:{width:`${i}%`,...P(e.name,n)}})})]},e.name)})})]})}var ia=``;async function aa(e,t){let n=await fetch(`${ia}${e}`,{credentials:`same-origin`,...t});if(n.status===401)throw window.location.href=`/login`,Error(`Unauthorized`);if(!n.ok){let e=await n.text();throw Error(e||`HTTP ${n.status}`)}return n.json()}function oa(e){return aa(`/api/chat/sessions`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({agentName:e})})}function sa(e){return aa(`/api/chat/sessions/${encodeURIComponent(e)}/clear`,{method:`POST`})}function ca(e){return aa(`/api/chat/sessions/${encodeURIComponent(e)}`,{method:`DELETE`})}var la=0;function L(){return`msg-${++la}-${Date.now()}`}function ua(e){let t=(0,x.useRef)(null),[n,r]=(0,x.useState)([]),[i,a]=(0,x.useState)(!1),[o,s]=(0,x.useState)(!1),c=(0,x.useRef)(!1);return(0,x.useEffect)(()=>{if(!e)return;let n=`${window.location.protocol===`https:`?`wss:`:`ws:`}//${window.location.host}/chat/ws/${e}`,i=new WebSocket(n);return t.current=i,i.onopen=()=>{a(!0)},i.onmessage=e=>{let t;try{t=JSON.parse(e.data)}catch{return}switch(t.type){case`assistant_message`:t.done?(c.current=!1,r(e=>{let t=e[e.length-1];return t?.role===`assistant`&&!t.done?[...e.slice(0,-1),{...t,done:!0}]:e})):(o||s(!0),c.current=!0,r(e=>{let n=e[e.length-1];return n?.role===`assistant`&&!n.done?[...e.slice(0,-1),{...n,text:n.text+(t.text||``)}]:[...e,{id:L(),role:`assistant`,text:t.text||``,done:!1}]}));break;case`tool_start`:o||s(!0),r(e=>[...e,{id:L(),role:`tool_start`,text:t.input||``,toolName:t.tool,toolCallId:t.toolCallId}]);break;case`tool_result`:r(e=>[...e,{id:L(),role:`tool_result`,text:t.output||``,toolName:t.tool,toolCallId:t.toolCallId,error:!!t.error}]);break;case`error`:r(e=>[...e,{id:L(),role:`error`,text:t.message||`Unknown error`}]),c.current=!1;break;case`heartbeat`:break}},i.onclose=()=>{a(!1)},i.onerror=()=>{a(!1)},()=>{i.close(),t.current=null}},[e]),{messages:n,connected:i,containerReady:o,sendMessage:(0,x.useCallback)(e=>{if(!t.current||t.current.readyState!==WebSocket.OPEN)return;let n={id:L(),role:`user`,text:e,done:!0};r(e=>[...e,n]),t.current.send(JSON.stringify({type:`user_message`,text:e}))},[]),cancel:(0,x.useCallback)(()=>{!t.current||t.current.readyState!==WebSocket.OPEN||t.current.send(JSON.stringify({type:`cancel`}))},[]),resetMessages:(0,x.useCallback)(()=>{r([]),c.current=!1},[])}}function da({message:e}){return e.role===`user`?(0,N.jsx)(`div`,{className:`flex justify-end mb-3`,children:(0,N.jsx)(`div`,{className:`max-w-[80%] bg-blue-600 text-white rounded-2xl rounded-br-sm px-4 py-2 text-sm whitespace-pre-wrap`,children:e.text})}):e.role===`assistant`?(0,N.jsx)(`div`,{className:`flex justify-start mb-3`,children:(0,N.jsxs)(`div`,{className:`max-w-[80%] bg-slate-700 text-slate-100 rounded-2xl rounded-bl-sm px-4 py-2 text-sm whitespace-pre-wrap`,children:[e.text,!e.done&&(0,N.jsx)(`span`,{className:`inline-block w-2 h-4 bg-slate-400 animate-pulse ml-0.5 align-text-bottom`})]})}):e.role===`error`?(0,N.jsx)(`div`,{className:`flex justify-start mb-3`,children:(0,N.jsx)(`div`,{className:`max-w-[80%] bg-red-900/50 border border-red-700 text-red-200 rounded-lg px-4 py-2 text-sm`,children:e.text})}):null}function fa({message:e}){let[t,n]=(0,x.useState)(!1),r=e.role===`tool_result`,i=e.error;return(0,N.jsxs)(`div`,{className:`mb-2 ml-2`,children:[(0,N.jsxs)(`button`,{onClick:()=>n(!t),className:`flex items-center gap-2 text-xs font-mono px-3 py-1.5 rounded-md w-full text-left transition-colors ${i?`bg-red-900/30 border border-red-800 text-red-300 hover:bg-red-900/50`:`bg-slate-800 border border-slate-700 text-slate-400 hover:bg-slate-750`}`,children:[(0,N.jsx)(`span`,{className:`transition-transform ${t?`rotate-90`:``}`,children:`▸`}),(0,N.jsx)(`span`,{className:`font-semibold text-slate-300`,children:e.toolName||`tool`}),(0,N.jsx)(`span`,{className:`text-slate-500`,children:r?i?`error`:`done`:`running...`})]}),t&&(0,N.jsx)(`pre`,{className:`mt-1 ml-5 p-2 bg-slate-900 border border-slate-800 rounded text-xs text-slate-400 overflow-x-auto max-h-60 overflow-y-auto whitespace-pre-wrap`,children:e.text.slice(0,5e3)})]})}function pa(){let{agent:e}=dt(),t=st(),[n,r]=(0,x.useState)(null),[i,a]=(0,x.useState)(null),[o,s]=(0,x.useState)(``),c=(0,x.useRef)(null),l=(0,x.useRef)(null),{messages:u,connected:d,containerReady:f,sendMessage:p,cancel:m,resetMessages:h}=ua(n);(0,x.useEffect)(()=>{if(!e)return;let t=!1;return oa(e).then(({sessionId:e})=>{t||r(e)}).catch(e=>{t||a(e.message)}),()=>{t=!0}},[e]),(0,x.useEffect)(()=>{c.current?.scrollIntoView({behavior:`smooth`})},[u]),(0,x.useEffect)(()=>{l.current&&(l.current.style.height=`auto`,l.current.style.height=`${Math.min(l.current.scrollHeight,150)}px`)},[o]);let g=(0,x.useCallback)(()=>{let e=o.trim();e&&(p(e),s(``))},[o,p]),_=(0,x.useCallback)(e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),g())},[g]),v=(0,x.useCallback)(async()=>{if(n)try{let{sessionId:e}=await sa(n);h(),r(e)}catch(e){a(e.message)}},[n,h]),y=(0,x.useCallback)(async()=>{if(n)try{await ca(n),t(`/dashboard/agents/${encodeURIComponent(e||``)}`)}catch(e){a(e.message)}},[n,e,t]),b=u.some(e=>e.role===`assistant`&&!e.done);return i?(0,N.jsx)(`div`,{className:`min-h-screen bg-slate-900 text-white flex items-center justify-center`,children:(0,N.jsxs)(`div`,{className:`text-center`,children:[(0,N.jsx)(`p`,{className:`text-red-400 mb-4`,children:i}),(0,N.jsx)(M,{to:`/dashboard`,className:`text-blue-400 hover:underline`,children:`Back to Dashboard`})]})}):(0,N.jsxs)(`div`,{className:`flex flex-col h-screen bg-slate-900 text-white`,children:[(0,N.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-3 border-b border-slate-700 bg-slate-800`,children:[(0,N.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,N.jsx)(M,{to:`/dashboard/agents/${encodeURIComponent(e||``)}`,className:`text-slate-400 hover:text-white transition-colors`,children:`←`}),(0,N.jsxs)(`h1`,{className:`text-lg font-semibold`,children:[`Chat: `,e]})]}),(0,N.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,N.jsx)(`span`,{className:`inline-block w-2 h-2 rounded-full ${d?f?`bg-green-400`:`bg-yellow-400`:`bg-red-400`}`}),(0,N.jsx)(`span`,{className:`text-xs text-slate-400`,children:d?f?`Connected`:`Waiting for agent...`:`Disconnected`}),(0,N.jsx)(`button`,{onClick:v,disabled:!n,className:`px-3 py-1.5 text-xs font-medium rounded-md bg-yellow-600 hover:bg-yellow-700 disabled:opacity-40 text-white transition-colors`,children:`Clear Context`}),(0,N.jsx)(`button`,{onClick:y,disabled:!n,className:`px-3 py-1.5 text-xs font-medium rounded-md bg-red-600 hover:bg-red-700 disabled:opacity-40 text-white transition-colors`,children:`Shutdown`})]})]}),(0,N.jsxs)(`div`,{className:`flex-1 overflow-y-auto px-4 py-4`,children:[u.length===0&&!b&&(0,N.jsx)(`div`,{className:`text-center text-slate-500 mt-20`,children:f?`Send a message to start chatting.`:`Waiting for agent container to start...`}),u.map(e=>e.role===`tool_start`||e.role===`tool_result`?(0,N.jsx)(fa,{message:e},e.id):(0,N.jsx)(da,{message:e},e.id)),(0,N.jsx)(`div`,{ref:c})]}),(0,N.jsxs)(`div`,{className:`border-t border-slate-700 bg-slate-800 px-4 py-3`,children:[(0,N.jsxs)(`div`,{className:`flex items-end gap-2 max-w-4xl mx-auto`,children:[(0,N.jsx)(`textarea`,{ref:l,value:o,onChange:e=>s(e.target.value),onKeyDown:_,placeholder:b?`Agent is responding...`:`Type a message...`,disabled:!d,rows:1,className:`flex-1 bg-slate-700 border border-slate-600 rounded-lg px-3 py-2 text-base text-white placeholder-slate-400 resize-none focus:outline-none focus:border-blue-500 disabled:opacity-50`}),b?(0,N.jsx)(`button`,{onClick:m,className:`px-4 py-2 bg-red-600 hover:bg-red-700 text-white rounded-lg text-sm font-medium transition-colors`,children:`Cancel`}):(0,N.jsx)(`button`,{onClick:g,disabled:!o.trim()||!d,className:`px-4 py-2 bg-blue-600 hover:bg-blue-700 disabled:bg-slate-600 disabled:cursor-not-allowed text-white rounded-lg text-sm font-medium transition-colors`,children:`Send`})]}),(0,N.jsx)(`p`,{className:`text-xs text-slate-500 mt-1 text-center`,children:`Enter to send, Shift+Enter for newline`})]})]})}function ma(e){if(!e)return`—`;try{return JSON.stringify(JSON.parse(e),null,2)}catch{return e}}function ha(){let{receiptId:e}=dt(),[t,n]=(0,x.useState)(void 0),[r,i]=(0,x.useState)(null),[a,o]=(0,x.useState)(null),[s,c]=(0,x.useState)(!1);(0,x.useEffect)(()=>{e&&tr(e).then(e=>n(e.receipt)).catch(()=>n(null))},[e]);let l=(0,x.useCallback)(async()=>{if(e){i(null),o(null),c(!0);try{let t=await nr(e);i(`Replayed: ${t.matched} matched, ${t.skipped} skipped`)}catch(e){o(e instanceof Error?e.message:`Replay failed`)}finally{c(!1)}}},[e]);if(!e)return null;if(t===void 0)return(0,N.jsx)(`div`,{className:`text-center py-12 text-slate-500 dark:text-slate-400`,children:`Loading...`});if(t===null)return(0,N.jsx)(`div`,{className:`space-y-6`,children:(0,N.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,N.jsx)(M,{to:`/dashboard/triggers`,className:`text-slate-500 hover:text-slate-700 dark:hover:text-slate-300`,children:(0,N.jsx)(`svg`,{className:`w-5 h-5`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,N.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M15 19l-7-7 7-7`})})}),(0,N.jsx)(`h1`,{className:`text-xl font-bold text-slate-900 dark:text-white`,children:`Receipt not found`})]})});let u=!!(t.headers||t.body),d=t.status===`processed`?`completed`:`dead-letter`,f=zi(t.body,t.headers);return(0,N.jsxs)(`div`,{className:`space-y-6`,children:[(0,N.jsxs)(`div`,{className:`flex items-center justify-between flex-wrap gap-3`,children:[(0,N.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,N.jsx)(M,{to:`/dashboard/triggers`,className:`text-slate-500 hover:text-slate-700 dark:hover:text-slate-300`,children:(0,N.jsx)(`svg`,{className:`w-5 h-5`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,N.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M15 19l-7-7 7-7`})})}),(0,N.jsxs)(`div`,{children:[(0,N.jsx)(`h1`,{className:`text-xl font-bold text-slate-900 dark:text-white font-mono`,children:Si(t.id)}),(0,N.jsx)(`div`,{className:`text-xs text-slate-500 dark:text-slate-400`,children:`Webhook Receipt`})]}),(0,N.jsx)(oi,{result:d})]}),(0,N.jsxs)(`div`,{className:`flex items-center gap-2`,children:[r&&(0,N.jsx)(`span`,{className:`text-xs text-green-600 dark:text-green-400`,children:r}),a&&(0,N.jsx)(`span`,{className:`text-xs text-red-600 dark:text-red-400`,children:a}),(0,N.jsx)(`button`,{onClick:l,disabled:!u||s,className:`px-3 py-1.5 text-xs font-medium rounded-md bg-blue-600 hover:bg-blue-700 disabled:opacity-40 text-white transition-colors`,children:s?`Replaying...`:`Replay`})]})]}),(0,N.jsx)(`div`,{className:`max-w-2xl`,children:(0,N.jsxs)(`div`,{className:`bg-slate-50 dark:bg-slate-900 rounded-lg border border-slate-200 dark:border-slate-800 p-4`,children:[(0,N.jsx)(`h2`,{className:`text-sm font-medium text-slate-900 dark:text-white mb-3`,children:`Receipt Info`}),(0,N.jsxs)(`dl`,{className:`text-sm`,children:[(0,N.jsxs)(`div`,{className:`grid grid-cols-[8rem_1fr] gap-x-4 py-1 items-center`,children:[(0,N.jsx)(`dt`,{className:`text-slate-500 dark:text-slate-400`,children:`Source`}),(0,N.jsx)(`dd`,{className:`text-slate-700 dark:text-slate-300`,children:t.source})]}),t.eventSummary&&(0,N.jsxs)(`div`,{className:`grid grid-cols-[8rem_1fr] gap-x-4 py-1 items-center`,children:[(0,N.jsx)(`dt`,{className:`text-slate-500 dark:text-slate-400`,children:`Event`}),(0,N.jsx)(`dd`,{className:`text-slate-700 dark:text-slate-300`,children:t.eventSummary})]}),t.deliveryId&&(0,N.jsxs)(`div`,{className:`grid grid-cols-[8rem_1fr] gap-x-4 py-1 items-center`,children:[(0,N.jsx)(`dt`,{className:`text-slate-500 dark:text-slate-400`,children:`Delivery ID`}),(0,N.jsx)(`dd`,{className:`text-slate-700 dark:text-slate-300 font-mono text-xs`,children:t.deliveryId})]}),(0,N.jsxs)(`div`,{className:`grid grid-cols-[8rem_1fr] gap-x-4 py-1 items-center`,children:[(0,N.jsx)(`dt`,{className:`text-slate-500 dark:text-slate-400`,children:`Timestamp`}),(0,N.jsx)(`dd`,{className:`text-slate-700 dark:text-slate-300`,children:Ci(t.timestamp)})]}),(0,N.jsxs)(`div`,{className:`grid grid-cols-[8rem_1fr] gap-x-4 py-1 items-center`,children:[(0,N.jsx)(`dt`,{className:`text-slate-500 dark:text-slate-400`,children:`Status`}),(0,N.jsx)(`dd`,{children:(0,N.jsx)(oi,{result:d})})]}),(0,N.jsxs)(`div`,{className:`grid grid-cols-[8rem_1fr] gap-x-4 py-1 items-center`,children:[(0,N.jsx)(`dt`,{className:`text-slate-500 dark:text-slate-400`,children:`Matched Agents`}),(0,N.jsx)(`dd`,{className:`text-slate-700 dark:text-slate-300`,children:t.matchedAgents})]}),t.deadLetterReason&&(0,N.jsxs)(`div`,{className:`grid grid-cols-[8rem_1fr] gap-x-4 py-1 items-center`,children:[(0,N.jsx)(`dt`,{className:`text-slate-500 dark:text-slate-400`,children:`Dead Letter Reason`}),(0,N.jsx)(`dd`,{className:`text-red-600 dark:text-red-400 text-xs`,children:t.deadLetterReason})]}),(0,N.jsxs)(`div`,{className:`grid grid-cols-[8rem_1fr] gap-x-4 py-1 items-start pt-2 mt-1 border-t border-slate-200 dark:border-slate-800`,children:[(0,N.jsx)(`dt`,{className:`text-slate-500 dark:text-slate-400`,children:`Receipt ID`}),(0,N.jsx)(`dd`,{className:`text-slate-700 dark:text-slate-300 font-mono text-xs break-all`,children:t.id})]})]})]})}),(0,N.jsxs)(`div`,{className:`bg-slate-50 dark:bg-slate-900 rounded-lg border border-slate-200 dark:border-slate-800 overflow-hidden`,children:[(0,N.jsx)(`div`,{className:`px-4 py-2.5 border-b border-slate-200 dark:border-slate-800`,children:(0,N.jsx)(`h2`,{className:`text-sm font-medium text-slate-900 dark:text-white`,children:`Headers`})}),(0,N.jsx)(`div`,{className:`p-3 bg-slate-950`,children:(0,N.jsx)(`pre`,{className:`text-xs font-mono text-slate-300 whitespace-pre-wrap break-all`,children:t.headers?ma(t.headers):`—`})})]}),f&&(0,N.jsxs)(`div`,{className:`bg-slate-50 dark:bg-slate-900 rounded-lg border border-slate-200 dark:border-slate-800 overflow-hidden`,children:[(0,N.jsx)(`div`,{className:`px-4 py-2.5 border-b border-slate-200 dark:border-slate-800`,children:(0,N.jsx)(`h2`,{className:`text-sm font-medium text-slate-900 dark:text-white`,children:f.label})}),(0,N.jsx)(`div`,{className:`bg-slate-950 p-3 max-h-96 overflow-y-auto`,children:(0,N.jsx)(`pre`,{className:`text-xs font-mono text-slate-300 whitespace-pre-wrap break-all`,children:f.content})})]}),(0,N.jsxs)(`div`,{className:`bg-slate-50 dark:bg-slate-900 rounded-lg border border-slate-200 dark:border-slate-800 overflow-hidden`,children:[(0,N.jsx)(`div`,{className:`px-4 py-2.5 border-b border-slate-200 dark:border-slate-800`,children:(0,N.jsx)(`h2`,{className:`text-sm font-medium text-slate-900 dark:text-white`,children:f?`Raw Body`:`Body`})}),(0,N.jsx)(`div`,{className:`bg-slate-950 p-3 max-h-96 overflow-y-auto`,children:(0,N.jsx)(`pre`,{className:`text-xs font-mono text-slate-300 whitespace-pre-wrap break-all`,children:t.body?ma(t.body):`—`})})]})]})}function ga(){let{name:e}=dt();return(0,N.jsx)(Ft,{to:`/activity?agent=${encodeURIComponent(e??``)}`,replace:!0})}function _a(){let{name:e}=dt();return(0,N.jsx)(Ft,{to:`/dashboard/agents/${encodeURIComponent(e??``)}/settings`,replace:!0})}function va(){return(0,N.jsxs)(Rt,{children:[(0,N.jsx)(j,{path:`/login`,element:(0,N.jsx)(li,{})}),(0,N.jsx)(j,{path:`/chat/:agent`,element:(0,N.jsx)(pa,{})}),(0,N.jsxs)(j,{element:(0,N.jsx)(Wr,{}),children:[(0,N.jsx)(j,{path:`/dashboard`,element:(0,N.jsx)(vi,{})}),(0,N.jsxs)(j,{path:`/dashboard/agents/:name`,element:(0,N.jsx)(qr,{}),children:[(0,N.jsx)(j,{index:!0,element:(0,N.jsx)(Mi,{})}),(0,N.jsx)(j,{path:`stats`,element:(0,N.jsx)(na,{})}),(0,N.jsx)(j,{path:`settings`,element:(0,N.jsx)(Ii,{})}),(0,N.jsx)(j,{path:`admin`,element:(0,N.jsx)(Ft,{to:`settings`,replace:!0})}),(0,N.jsx)(j,{path:`skill`,element:(0,N.jsx)(_a,{})}),(0,N.jsx)(j,{path:`triggers`,element:(0,N.jsx)(ga,{})})]}),(0,N.jsxs)(j,{path:`/dashboard/agents/:name/instances/:id`,element:(0,N.jsx)(ci,{}),children:[(0,N.jsx)(j,{index:!0,element:(0,N.jsx)(I,{})}),(0,N.jsx)(j,{path:`trigger`,element:(0,N.jsx)(Vi,{})}),(0,N.jsx)(j,{path:`telemetry`,element:(0,N.jsx)(Hi,{})})]}),(0,N.jsx)(j,{path:`/dashboard/triggers`,element:(0,N.jsx)(Ft,{to:`/activity`,replace:!0})}),(0,N.jsx)(j,{path:`/activity`,element:(0,N.jsx)(Zi,{})}),(0,N.jsx)(j,{path:`/stats`,element:(0,N.jsx)(ra,{})}),(0,N.jsx)(j,{path:`/triggers`,element:(0,N.jsx)(Ft,{to:`/activity`,replace:!0})}),(0,N.jsx)(j,{path:`/jobs`,element:(0,N.jsx)(Ft,{to:`/activity`,replace:!0})}),(0,N.jsx)(j,{path:`/dashboard/triggers/:instanceId`,element:(0,N.jsx)($i,{})}),(0,N.jsx)(j,{path:`/dashboard/webhooks/:receiptId`,element:(0,N.jsx)(ha,{})}),(0,N.jsx)(j,{path:`/dashboard/config`,element:(0,N.jsx)(ea,{})})]}),(0,N.jsx)(j,{path:`/`,element:(0,N.jsx)(Ft,{to:`/dashboard`,replace:!0})})]})}var ya=localStorage.getItem(`al-theme`)||`dark`;document.documentElement.classList.toggle(`dark`,ya===`dark`),(0,Jn.createRoot)(document.getElementById(`root`)).render((0,N.jsx)(x.StrictMode,{children:(0,N.jsx)(Dn,{children:(0,N.jsx)(va,{})})}));
|