1import{r as h,j as e}from"./index-LWm_tIko.js";import{q as Mt,h as ye,K as Dt,W as Ft,n as Ht,R as Gt,p as Jt}from"./lightweight-charts.production-DkCppKnm.js";import{t as ve}from"./track-CNU_HUOU.js";let $e=null;function Yt(t){return fetch(t,{cache:"no-cache"}).then(async s=>{if(!s.ok)throw new Error(`HTTP ${s.status}`);return await s.json()})}function Xt(){return $e||($e=Yt("/alpha-agents-config.json").catch(t=>{throw $e=null,t}),$e)}function Qt(){const[t,s]=h.useState(null),[n,r]=h.useState(null),[l,c]=h.useState(!0);return h.useEffect(()=>{let b=!1;return Xt().then(u=>{b||(s(u),c(!1))}).catch(u=>{b||(r(u instanceof Error?u.message:"Failed to load the tracker."),c(!1))}),()=>{b=!0}},[]),{config:t,error:n,loading:l}}const Ee={agents:[],trades:[],runs:[]};async function de(t,s,n){return fetch(s,{...n,cache:"no-store",headers:{...n?.headers??{},Authorization:`Bearer ${t}`,...n?.body?{"Content-Type":"application/json"}:{}}})}async function he(t){return await t.json().catch(()=>({}))}async function Zt(t,s){if(!t)return{...Ee,error:"no_session"};try{const n=s?`?since=${encodeURIComponent(s)}`:"",r=await de(t,`/api/alpha-agents-state${n}`),l=await he(r);return!r.ok||l.error?(console.warn("alpha-agents-state failed",r.status,l.error),{...Ee,error:l.error??`http_${r.status}`}):l.unchanged?{...Ee,etag:l.etag,unchanged:!0}:{agents:Array.isArray(l.agents)?l.agents:[],trades:Array.isArray(l.trades)?l.trades:[],runs:Array.isArray(l.runs)?l.runs:[],etag:l.etag}}catch(n){return console.warn("alpha-agents-state threw",n),{...Ee,error:"network"}}}async function es(t,s){if(!t)return{error:"no_session"};try{const n=await de(t,`/api/alpha-agents-trade?id=${encodeURIComponent(s)}`),r=await he(n);return!n.ok||r.error||!r.trade?(console.warn("alpha-agents-trade failed",n.status,r.error),{error:r.error??`http_${n.status}`}):{trade:r.trade,events:Array.isArray(r.events)?r.events:[]}}catch(n){return console.warn("alpha-agents-trade threw",n),{error:"network"}}}async function ts(t,s){if(!t)return{error:"no_session"};try{const n=await de(t,`/api/alpha-agents-run?id=${encodeURIComponent(s)}`),r=await he(n);return!n.ok||r.error||!r.run?(console.warn("alpha-agents-run failed",n.status,r.error),{error:r.error??`http_${n.status}`}):{run:r.run,created:Array.isArray(r.created)?r.created:[],updated:Array.isArray(r.updated)?r.updated:[]}}catch(n){return console.warn("alpha-agents-run threw",n),{error:"network"}}}async function ss(t,s){if(!t)return{error:"no_session"};try{const n=await de(t,`/api/alpha-agents-agent-documents?id=${encodeURIComponent(s)}`),r=await he(n);if(!n.ok||r.error)return console.warn("alpha-agents-agent-documents failed",n.status,r.error),{error:r.error??`http_${n.status}`};const l=r.documents;return{documents:l&&typeof l=="object"?l:null}}catch(n){return console.warn("alpha-agents-agent-documents threw",n),{error:"network"}}}async function ns(t,s,n){if(!t)return{error:"no_session"};try{const r=await de(t,`/api/alpha-agents-agent?id=${encodeURIComponent(s)}`,{method:"PATCH",body:JSON.stringify(n)}),l=await he(r);return!r.ok||l.error||!l.agent?(console.error("alpha-agents-agent patch failed",r.status,l.error),{error:l.error??`http_${r.status}`,missing:l.missing}):{agent:l.agent}}catch(r){return console.error("alpha-agents-agent patch threw",r),{error:"network"}}}async function rs(t,s){if(!t)return{error:"no_session"};try{const n=await de(t,`/api/alpha-agents-agent?id=${encodeURIComponent(s)}`,{method:"POST",body:JSON.stringify({action:"run_now"})}),r=await he(n);return!n.ok||r.error||!r.agent?(console.error("alpha-agents-agent run_now failed",n.status,r.error,r.message),{error:r.error??`http_${n.status}`,message:r.message}):{agent:r.agent}}catch(n){return console.error("alpha-agents-agent run_now threw",n),{error:"network"}}}async function pt(t){if(!t)return{keys:[],error:"no_session"};try{const s=await de(t,"/api/alpha-agents-keys"),n=await s.json().catch(()=>null);if(!s.ok||!n||!Array.isArray(n)){const r=n&&!Array.isArray(n)&&n.error||`http_${s.status}`;return console.warn("alpha-agents-keys failed",s.status,r),{keys:[],error:r}}return{keys:n}}
1catch(s){return console.warn("alpha-agents-keys threw",s),{keys:[],error:"network"}}}async function ls(t,s){if(!t)return{error:"no_session"};try{const n=await de(t,"/api/alpha-agents-keys",{method:"POST",body:JSON.stringify({label:s})}),r=await he(n);return!n.ok||r.error||!r.key||!r.id?(console.error("alpha-agents-keys create failed",n.status,r.error),{error:r.error??`http_${n.status}`}):{id:r.id,key:r.key}}catch(n){return console.error("alpha-agents-keys create threw",n),{error:"network"}}}async function as(t,s){if(!t)return!1;try{const n=await de(t,`/api/alpha-agents-keys?id=${encodeURIComponent(s)}`,{method:"DELETE"}),r=await he(n);return!n.ok||r.error?(console.error("alpha-agents-keys revoke failed",n.status,r.error),!1):!0}catch(n){return console.error("alpha-agents-keys revoke threw",n),!1}}const is=/^(https?:|mailto:)/i;function be(t,s){const n=[],r=/(`[^`]+`)|(\*\*[^*]+\*\*)|(\*[^*]+\*)|(\[[^\]]+\]\([^)\s]+\))/g;let l=0,c,b=0;for(;(c=r.exec(t))!==null;){c.index>l&&n.push(t.slice(l,c.index));const u=c[0],m=`${s}-i${b++}`;if(u.startsWith("`"))n.push(e.jsx("code",{className:"rounded bg-slate-800/80 px-1.5 py-px font-mono text-[12.5px] text-slate-200",children:u.slice(1,-1)},m));else if(u.startsWith("**"))n.push(e.jsx("strong",{className:"font-semibold text-slate-100",children:u.slice(2,-2)},m));else if(u.startsWith("*"))n.push(e.jsx("em",{className:"italic",children:u.slice(1,-1)},m));else{const v=u.indexOf("]("),_=u.slice(1,v),o=u.slice(v+2,-1);n.push(is.test(o)?e.jsx("a",{href:o,target:"_blank",rel:"noreferrer noopener",className:"text-[#A78BFA] underline-offset-2 hover:underline",children:_},m):e.jsx("span",{children:u},m))}l=c.index+u.length}return l<t.length&&n.push(t.slice(l)),n}const os=["mt-5 mb-2 text-[22px] font-bold tracking-tight text-white","mt-6 mb-2 text-[18px] font-bold tracking-tight text-white","mt-5 mb-1.5 text-[15px] font-semibold text-slate-100","mt-4 mb-1.5 text-[14px] font-semibold text-slate-200","mt-4 mb-1 text-[13px] font-semibold text-slate-300","mt-4 mb-1 text-[13px] font-semibold text-slate-400"];function mt(t){return t.replace(/^\s*\|/,"").replace(/\|\s*$/,"").split("|").map(s=>s.trim())}const cs=t=>/^\s*\|?[\s:|-]+\|[\s:|-]*$/.test(t)&&t.includes("-");function Rt({source:t}){const s=t.replace(/\r\n?/g,` 2`).split(` 3`),n=[];let r=0,l=0;const c=[],b=()=>{if(!c.length)return;const u=c.join(" ");c.length=0,n.push(e.jsx("p",{className:"my-2 text-[13.5px] leading-relaxed text-slate-300",children:be(u,`p${l}`)},`p${l++}`))};for(;r<s.length;){const u=s[r];if(/^\s*```/.test(u)){b();const o=[];for(r++;r<s.length&&!/^\s*```/.test(s[r]);)o.push(s[r++]);r++,n.push(e.jsx("pre",{className:"my-3 overflow-x-auto rounded-lg border border-slate-800 bg-[#0B0B12] p-3 font-mono text-[12.5px] leading-relaxed text-slate-300",children:o.join(` 4`)},`c${l++}`));continue}if(!u.trim()){b(),r++;continue}if(/^\s*([-*_])\s*\1\s*\1[\s\-*_]*$/.test(u)){b(),n.push(e.jsx("hr",{className:"my-5 border-slate-800"},`h${l++}`)),r++;continue}const m=/^(#{1,6})\s+(.*)$/.exec(u);if(m){b();const o=m[1].length,N=`h${Math.min(o+1,6)}`;n.push(e.jsx(N,{className:os[o-1],children:be(m[2],`t${l}`)},`t${l++}`)),r++;continue}if(u.includes("|")&&r+1<s.length&&cs(s[r+1])){b();const o=mt(u);r+=2;const N=[];for(;r<s.length&&s[r].includes("|")&&s[r].trim();)N.push(mt(s[r++]));n.push(e.jsx("div",{className:"my-3 overflow-x-auto",children:e.jsxs("table",{className:"border-collapse text-[12.5px]",children:[e.jsx("thead",{children:e.jsx("tr",{children:o.map((x,j)=>e.jsx("th",{className:"border border-slate-800 px-2 py-1 text-left font-medium text-slate-400",children:be(x,`th${j}`)},j))})}),e.jsx("tbody",{children:N.map((x,j)=>e.jsx("tr",{children:x.map((a,k)=>e.jsx("td",{className:"border border-slate-800 px-2 py-1 text-slate-300",children:be(a,`td${j}-${k}`)},k))},j))})]})},`tb${l++}`));continue}if(/^\s*>/.test(u)){b();const o=[];for(;r<s.length&&/^\s*>/.test(s[r]);)o.push(s[r++].replace(/^\s*>\s?/,""));n.push(e.jsx("blockquote",{className:"my-3 border-l-2 border-slate-700 pl-3 text-[13.5px] leading-relaxed text-slate-400",children:be(o.join(" "),`q${l}`)},`q${l++}`));continue}const v=/^\s*[-*+]\s+/,_=/^\s*\d+[.)]\s+/;if(v.test(u)||_.test(u)){b();const o=_.test(u),N=[];for(;r<s.length&&(o?_:v).test(s[r]);)N.push(s[r++].replace(o?_:v,""));const x="my-2 space-y-1 pl-5 text-[13.5px] leading-relaxed text-slate-300";n.push(o?e.jsx("ol",{className:`list-decimal ${x}`,children:N.map((j,a)=>e.jsx("li",{children:be(j,`li${a}`)},a))},`l${l++}`):e.jsx("ul",{className:`list-disc ${x}
4`,children:N.map((j,a)=>e.jsx("li",{children:be(j,`li${a}`)},a))},`l${l++}`));continue}c.push(u.trim()),r++}return b(),e.jsx("article",{className:"max-w-[860px]",children:n})}const Q="â";function T(t,s=2){return t==null||typeof t=="string"&&t===""?Q:Number(t).toLocaleString(void 0,{minimumFractionDigits:s,maximumFractionDigits:s})}function ae(t){return t==null?Q:Math.abs(t)<5e-5?"0.00%":`${t>0?"+":""}${(t*100).toFixed(2)}%`}function Y(t){return t==null?Q:Math.abs(t)<.005?"0.00R":`${t>0?"+":""}${t.toFixed(2)}R`}function Bt(t){return t==null?"":`${t}%`}function ot(t){return t.slice(-6)}function tt(t){return t.slice(0,8)}const ht=new Map;function It(t,s){const n=t+JSON.stringify(s);let r=ht.get(n);return r||(r=new Intl.DateTimeFormat("en-CA",{timeZone:t,...s}),ht.set(n,r)),r}function te(t,s){if(!t)return Q;const n=Date.parse(t);return Number.isNaN(n)?String(t).slice(0,10):It(s,{year:"numeric",month:"2-digit",day:"2-digit"}).format(n)}function ke(t,s){if(!t)return null;const n=Date.parse(t);return Number.isNaN(n)?String(t).replace("T"," ").slice(0,16):It(s,{year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",hour12:!1}).format(n).replace(",","")}function Se(t,s){const n=ke(t,s);return n?n.slice(5):Q}function st(t,s,n,r,l){const c=[];return t&&c.push(`${l} ${Se(t,r)}`),s!=null&&c.push(`>${T(s)}`),n!=null&&c.push(`<${T(n)}`),c}function ft(t){return t==="open"||t==="watching"}function Ve(t,s,n){return t==null||n==null||s==null||s===t?null:(n-t)/(t-s)}function we(t,s){return t?s.status_labels[t]??null:null}const Me={A:"green",B:"green",C:"amber",D:"amber",F:"red"};function Ae(t){return t.r!=null?t.r:t.pct??null}function bt(t){const s=t.filter(n=>n!=null&&Number.isFinite(n));return s.length?s.reduce((n,r)=>n+r,0)/s.length:null}const Ye="1d";function ct(t){const s={bars:{},keys:[],fallbackDefault:null};if(!t)return s;if(Array.isArray(t))return t.length?{bars:{[Ye]:t},keys:[Ye],fallbackDefault:null}:s;if("timeframes"in t){const l={},c=[];for(const[u,m]of Object.entries(t.timeframes??{})){const v=m&&Array.isArray(m.bars)?m.bars:[];v.length&&(l[u]=v,c.push(u))}const b=t.default;return{bars:l,keys:c,fallbackDefault:b&&l[b]?b:null}}const n=Array.isArray(t.bars)?t.bars:[];if(!n.length)return s;const r=t.timeframe??t.tf??Ye;return{bars:{[r]:n},keys:[r],fallbackDefault:null}}function Lt(t,s=[]){const{bars:n,keys:r}=ct(t),l=s.filter(c=>n[c]);return[...l,...r.filter(c=>!l.includes(c))]}function ds(t,s){return s?ct(t).bars[s]??[]:[]}function xs(t,s=[]){const{fallbackDefault:n}=ct(t);return n||(Lt(t,s)[0]??null)}function Tt(t,s){return s?.length?s:t??[]}function X(t,s){return t.replace(/\{(\w+)\}/g,(n,r)=>r in s?String(s[r]):n)}function Le(t){return t.updated_at??t.documented_at??t.decided_at}function De(t){return t.entered_at??t.decided_at}function We(t){return t.entry_price??(t.order_type==="limit"?t.limit_price??null:null)}function zt(t,s,n){return t?n[t].replace("{price}",T(s)):Q}function us(t,s){const n=s.filter(l=>l.agent_id===t&&l.status==="closed"&&(l.r!=null||l.pct!=null)).slice().sort((l,c)=>Le(l)<Le(c)?-1:Le(l)>Le(c)?1:0);let r=0;return n.map(l=>r+=l.r??l.pct??0)}function ps(t,s,n){const r=s.filter(c=>c.agent_id===t.id),l=dt(n,t.id);return{runs:l.filter(c=>c.status==="finished").length,failedRuns:l.filter(c=>c.status==="failed").length,trades:r.length,avgPct:bt(r.map(c=>c.pct)),avgR:bt(r.map(c=>c.r))}}function dt(t,s){return t.filter(n=>n.agent_id===s&&!n.trade_id)}function Pt(t){return t.length?t.reduce((s,n)=>(s.started_at??"")>=(n.started_at??"")?s:n):null}function nt(t,s){return Pt(dt(t,s).filter(n=>n.status==="started"))}function gt(t,s){return Pt(t.filter(n=>n.trade_id===s&&n.status==="started"))}function xt(t){const s=t??[];return{done:s.filter(n=>n.passes).length,total:s.length,current:s.find(n=>!n.passes)?.id??null}}function Ue(t){const s=(t??"").replace(/_/g," ").trim();return s?s.charAt(0).toUpperCase()+s.slice(1):""}function ms(t,s){const n=ke(t,s);return n?n.slice(-5):""}function rt(t){return`inline-flex ${t==="header"?"h-[22px] px-2.5 text-[12.5px]":"h-[18px] px-2 text-[11.5px]"} shrink-0 items-center gap-1 rounded-full border bg-transparent leading-none`}function lt({run:t,subject:s,config:n,size:r="row",onOpen:l}){const{done:c,total:b,current:u}=xt(t.gates),m=b?X(n.progress.running_title,{name:s,done:c,total:b,current:Ue(u)}):X(n.progress.running_title_unknown,{name:s}),v="border-[#22C55E]/40 bg-[#22C55E]/10 text-[#22C55E] align-middle",_=e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:"relative inline-flex h-[6px] w-[6px] shrink-0",children:[e.jsx("span",{className:"absolute inline-flex h-full w-full animate-ping rounded-full bg-[#22C55E] opacity-60"}),e.jsx("span",{className:"relative inline-flex h-[6px] w-[6px] rounded-full bg-[#22C55E]"})]}),e.jsx("span",{children:n.progress.running_label}),!!b&&e.jsxs("span",{className:"tabular-nums opacity-80",children:[c,"/",b]})]});return l?e.jsx("button",{type:"button",onClick:o=>{o.stopPropagation(),l(t.id)},className:`${rt(r)} ${v} transition-colors hover:bg-[#22C55E]/20`,title:m,"aria-label":m,"aria-live":"polite",children:_}):e.jsx("span",{className:`${rt(r)} cursor-default ${v}`,title:m,"aria-label":m,"aria-live":"polite",children:_})}function at({agent:t,config:s,onRequestRun:n,size:r="row",run:l=null,onOpenRun:c}){const[b,u]=h.useState(!1),[m,v]=h.useState(null),_=h.useRef(void 0);h.useEffect(()=>()=>window.clearTimeout(_.current),[]);
4const o=!!t.run_requested_at,N=ms(t.run_requested_at,s.timezone.tz),x=h.useCallback(async B=>{if(B.stopPropagation(),b||o)return;u(!0),v(null);const $=await n(t.id);u(!1),$&&(v($.message??s.home.run_failed),window.clearTimeout(_.current),_.current=window.setTimeout(()=>v(null),8e3))},[t.id,b,o,n,s.home.run_failed]),j=rt(r);if(l)return e.jsx(lt,{run:l,subject:t.name,config:s,size:r,onOpen:c});const a=o?X(s.home.run_requested_title,{time:N}):X(s.home.run_now_title,{name:t.name}),k=o?"cursor-default border-[#22C55E]/40 bg-[#22C55E]/10 text-[#22C55E]":b?"border-[#4ADE80]/40 text-[#4ADE80]":"border-slate-800 text-slate-500 hover:border-[#4ADE80]/50 hover:bg-[#4ADE80]/10 hover:text-[#4ADE80] focus-visible:border-[#4ADE80]/50 focus-visible:text-[#4ADE80]",M=o?N:s.home.run_now_label.split(" ")[0];return e.jsxs("span",{className:"inline-flex items-center gap-1.5 align-middle",children:[e.jsxs("button",{type:"button",onClick:x,disabled:o||b,title:a,"aria-label":a,className:`${j} relative transition-colors ${k} disabled:opacity-100 max-md:before:absolute max-md:before:-inset-2 max-md:before:content-['']`,children:[e.jsx("svg",{viewBox:"0 0 10 10","aria-hidden":"true",className:"h-[8px] w-[8px] fill-current",children:e.jsx("path",{d:"M2 1v8l7-4z"})}),e.jsx("span",{className:"tabular-nums",children:M})]}),m&&e.jsx("span",{role:"alert",title:m,className:`${r==="header"?"text-[12px]":"text-[11px]"} cursor-help whitespace-nowrap text-rose-400/80`,children:s.home.run_failed})]})}const Fe="#7C3AED",ie="text-emerald-400",oe="text-rose-400";function it({u:t,title:s}){const n=t?t.r??t.pct:null;return n==null?null:e.jsx("span",{title:s,className:`${n>=0?ie:oe} opacity-70 italic`,children:t.r!=null?Y(t.r):ae(t.pct)})}const _e="180ms cubic-bezier(.2,.7,.2,1)",hs={grey:"bg-slate-800 text-slate-300",green:"bg-emerald-500/15 text-emerald-300",amber:"bg-amber-500/15 text-amber-300",red:"bg-rose-500/15 text-rose-300",accent:"bg-[#7C3AED]/20 text-[#C4B5FD]"};function ne({children:t,tone:s="grey"}){return e.jsx("span",{className:`inline-block rounded px-1.5 py-px text-[13px] font-medium uppercase leading-[18px] tracking-[0.01em] ${hs[s]}`,children:t})}function P(){return e.jsx("span",{className:"text-slate-600",children:"â"})}function L({children:t,className:s="",title:n}){return e.jsx("span",{title:n,className:`font-mono tabular-nums ${s}`,style:{fontVariantNumeric:"tabular-nums"},children:t})}function qe({label:t}){return e.jsx("div",{className:"flex h-full items-center justify-center bg-[#0B0B12]",children:e.jsx("p",{className:"text-[13px] text-slate-500",children:t})})}const Be="h-3.5 w-3.5 shrink-0 align-[-2px] fill-none stroke-current",se={strokeWidth:1.4,strokeLinecap:"round",strokeLinejoin:"round"};function fs({className:t=Be}){return e.jsx("svg",{viewBox:"0 0 16 16",className:t,...se,children:e.jsx("path",{d:"M2 8.5 8 3l6 5.5M3.5 7.5V13h3V9.5h3V13h3V7.5"})})}function bs({className:t=Be}){return e.jsxs("svg",{viewBox:"0 0 16 16",className:t,...se,children:[e.jsx("path",{d:"M8 2v2.5M6.5 2h3"}),e.jsx("rect",{x:"2.5",y:"4.5",width:"11",height:"8.5",rx:"2.5"}),e.jsx("circle",{cx:"6",cy:"8.75",r:".9",fill:"currentColor",stroke:"none"}),e.jsx("circle",{cx:"10",cy:"8.75",r:".9",fill:"currentColor",stroke:"none"}),e.jsx("path",{d:"M1 8v2M15 8v2"})]})}function Ot({className:t=Be}){return e.jsxs("svg",{viewBox:"0 0 16 16",className:t,...se,children:[e.jsx("rect",{x:"1.5",y:"2.5",width:"13",height:"11",rx:"2"}),e.jsx("path",{d:"M10 2.5v11"})]})}function gs({className:t=Be}){return e.jsx("svg",{viewBox:"0 0 16 16",className:t,...se,children:e.jsx("path",{d:"M4 3l5 5-5 5M8.5 3l5 5-5 5"})})}function js({className:t=Be}){return e.jsxs("svg",{viewBox:"0 0 16 16",className:t,...se,children:[e.jsx("circle",{cx:"5",cy:"8",r:"3"}),e.jsx("path",{d:"M8 8h6M12 8v2.5M14 8v2"})]})}function le({kind:t}){const s="mr-1.5 inline-block h-3 w-3 shrink-0 align-[-2px] fill-none stroke-current text-slate-600";switch(t){case"select":return e.jsxs("svg",{viewBox:"0 0 16 16",className:s,...se,children:[e.jsx("circle",{cx:"8",cy:"8",r:"5.5"}),e.jsx("path",{d:"M5.5 8.5 7.5 10 11 6.5"})]});case"text":return e.jsx("svg",{viewBox:"0 0 16 16",className:s,...se,children:e.jsx("path",{d:"M2 13 6 3l4 10M3.5 9.5h5M11 13V7.5M11 7.5c1.5-1.5 3.5-.5 3.5 1V13"})});case"date":return e.jsxs("svg",{viewBox:"0 0 16 16",className:s,...se,children:[e.jsx("rect",{x:"2",y:"3",width:"12",height:"11",rx:"1.5"}),e.jsx("path",{d:"M2 7h12M5 1.5v3M11 1.5v3"})]});case"sum":return e.jsx("svg",{viewBox:"0 0 16 16",className:s,...se,children:e.jsx("path",{d:"M12 3H4l4.5 5L4 13h8"})});case"lines":return e.jsx("svg",{viewBox:"0 0 16 16",className:s,...se,children:e.jsx("path",{d:"M3 4.5h10M3 8h10M3 11.5h7"})});default:return e.jsx("svg",{viewBox:"0 0 16 16",className:s,...se,children:e.jsx("path",{d:"M6 2 4.5 14M11.5 2 10 14M2.5 6h11M2 10.5h11"})})}}const U={asset:"text",date:"date",grade:"select",entry:"number",stop:"number",time_alert:"date",price_alert:"number",target:"number",target_r:"number",status:"select",run:"select",session:"text",result:"sum",id:"number"};function Ce(t){return t==null||t===""?!1:Array.isArray(t)?t.length>0:typeof t=="object"?!!(t.from||t.to):!0}function jt(t,s,n,r){switch(t){case"asset":return s.symbol;case"status":return s.status??Q;case"grade":return s.grade??Q;case"run":return n(s.run_id);case"date":return te(De(s),r)}}function ys({field:t,value:s,options:n,config:r,onChange:l,onRemove:c,onClose:b}){const u=h.useRef(null),[m,v]=h.useState(""),_=r.filters;h.useEffect(()=>{const j=a=>
4{if(!u.current)return;const k=a.target;!u.current.contains(k)&&!k.closest?.("[data-filter-chip]")&&b()};return document.addEventListener("mousedown",j),()=>document.removeEventListener("mousedown",j)},[b]);const o=Array.isArray(s)?s:[],N=s&&typeof s=="object"&&!Array.isArray(s)?s:{from:null,to:null},x=n.filter(j=>j.toLowerCase().includes(m.toLowerCase()));return e.jsxs("div",{ref:u,className:"absolute left-0 top-full z-30 mt-1.5 min-w-[260px] rounded-lg border border-slate-800 bg-[#12121A] p-2 shadow-[0_8px_24px_rgba(0,0,0,.55)]",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 whitespace-nowrap px-1 pb-2 text-[12px] text-slate-500",children:[e.jsxs("span",{children:[t.label," ",e.jsx("b",{className:"font-medium text-slate-300",children:_.verbs[t.kind]})]}),e.jsx("button",{type:"button",onClick:c,title:_.remove_label,"aria-label":_.remove_label,className:"rounded px-1.5 text-[14px] leading-none text-slate-600 hover:bg-slate-800 hover:text-slate-200",children:"Ã"})]}),t.kind==="select"&&e.jsxs(e.Fragment,{children:[e.jsx("input",{autoFocus:!0,value:m,onChange:j=>v(j.target.value),placeholder:_.select_placeholder,className:"mb-1.5 w-full rounded-md border border-[#7C3AED]/70 bg-[#0B0B12] px-2 py-1.5 text-[14px] text-slate-200 outline-none placeholder:text-slate-600"}),e.jsxs("div",{className:"max-h-[300px] overflow-y-auto",children:[x.map(j=>{const a=o.includes(j);return e.jsxs("label",{className:"flex cursor-pointer items-center gap-2 rounded px-1.5 py-1 text-[14px] hover:bg-slate-800/70",children:[e.jsx("input",{type:"checkbox",checked:a,onChange:()=>l(a?o.filter(k=>k!==j):[...o,j]),className:"h-3.5 w-3.5 accent-[#7C3AED]"}),e.jsx(ne,{tone:t.key==="grade"&&j in Me?Me[j]:"grey",children:t.key==="status"?we(j,r)??j:j})]},j)}),!x.length&&e.jsx("p",{className:"px-1.5 py-2 text-[12px] text-slate-600",children:"No options."})]})]}),t.kind==="text"&&e.jsx("input",{autoFocus:!0,value:typeof s=="string"?s:"",onChange:j=>l(j.target.value),placeholder:_.text_placeholder,className:"w-full rounded-md border border-[#7C3AED]/70 bg-[#0B0B12] px-2 py-1.5 text-[14px] text-slate-200 outline-none placeholder:text-slate-600"}),t.kind==="date"&&e.jsx("div",{className:"space-y-1.5",children:["from","to"].map(j=>e.jsxs("label",{className:"flex items-center justify-between gap-3 px-1 text-[12px] text-slate-500",children:[j==="from"?_.from_label:_.to_label,e.jsx("input",{type:"date",value:N[j]??"",onChange:a=>l({...N,[j]:a.target.value||null}),style:{colorScheme:"dark"},className:"rounded border border-slate-800 bg-[#0B0B12] px-1.5 py-1 text-[12px] text-slate-200"})]},j))})]})}function K({label:t,type:s,align:n="left"}){return e.jsxs("th",{className:`whitespace-nowrap border-b border-slate-800 px-2.5 py-1.5 text-[11.5px] font-normal text-slate-500 ${n==="right"?"text-right":"text-left"}`,children:[e.jsx(le,{kind:s}),t]})}function Ns({rows:t,runs:s,details:n,config:r,selectedId:l,onOpen:c,onOpenRun:b}){const[u,m]=h.useState({}),[v,_]=h.useState(null),o=r.timezone.tz,N=r.columns.trades,x=h.useMemo(()=>{const i=new Map(s.map(f=>[f.id,f.name]));return f=>f&&i.get(f)||Q},[s]),j=h.useMemo(()=>t.filter(i=>Object.entries(u).every(([f,w])=>{if(!Ce(w))return!0;const d=jt(f,i,x,o);return f==="date"&&typeof w=="object"&&!Array.isArray(w)?(!w.from||d>=w.from)&&(!w.to||d<=w.to):Array.isArray(w)?w.includes(d):d.toLowerCase().includes(String(w).toLowerCase())})),[t,u,x,o]),a=h.useMemo(()=>{const i=j.filter(p=>Ae(p)!=null),f=i.filter(p=>(Ae(p)??0)>0).length,w=i.map(p=>p.r).filter(p=>p!=null),d=i.map(p=>p.pct).filter(p=>p!=null);return{n:j.length,closed:i.length,wins:f,losses:i.filter(p=>(Ae(p)??0)<0).length,open:j.filter(p=>p.status==="open").length,netR:w.length?w.reduce((p,g)=>p+g,0):null,avgPct:d.length?d.reduce((p,g)=>p+g,0)/d.length:null}},[j]),k=h.useMemo(()=>new Map(r.filters.fields.map(i=>[i.key,i])),[r.filters.fields]),M=i=>[...new Set(t.map(f=>jt(i,f,x,o)))].sort(),B=(i,f)=>{const w=k.get(i);return w?Ce(f)?Array.isArray(f)?`${w.label}: ${f.map(d=>i==="status"?we(d,r)??d:d).join(", ")}`:typeof f=="object"?`${w.label}: ${f.from??"â¦"} â ${f.to??"â¦"}`:`${w.label} ${r.filters.verbs.text} "${f}"`:w.label:i},$=r.filters.fields.filter(i=>Ce(u[i.key])||v===i.key),D=r.filters.fields.filter(i=>!Ce(u[i.key])&&v!==i.key),A=i=>`relative inline-flex items-center gap-1.5 whitespace-nowrap rounded-full border px-2.5 py-0.5 text-[12.5px] transition ${i?"border-[#7C3AED] bg-[#7C3AED]/15 text-[#C4B5FD]":"border-slate-800 text-slate-500 hover:border-slate-600 hover:text-slate-300"}`;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"relative mb-1 mt-3.5 flex flex-wrap items-center gap-1.5",children:[$.map(i=>e.jsxs("div",{className:"relative",children:[e.jsxs("button",{type:"button","data-filter-chip":!0,onClick:()=>_(v===i.key?null:i.key),className:A(Ce(u[i.key])),children:[B(i.key,u[i.key]??"")," â¾"]}),v===i.key&&e.jsx(ys,{field:i,value:u[i.key],options:M(i.key),config:r,onChange:f=>m(w=>({...w,[i.key]:f})),onRemove:()=>{m(f=>{const w={...f};return delete w[i.key],w}),_(null)},onClose:()=>_(null)})]},i.key)),e.jsxs("div",{className:"relative",children:[e.jsx("button",{type:"button","data-filter-chip":!0,onClick:()=>_(v==="+"?null:"+"),className:A(!1),children:r.filters.add_label}),v==="+"&&e.jsxs("div",{className:"absolute left-0 top-full z-30 mt-1.5 min-w-[140px] rounded-lg border border-slate-800 bg-[#12121A] p-1 shadow-[0_8px_24px_rgba(0,0,0,.55)]",children:[D.map(i=>e.jsx("button",{type:"button",onClick:()=>{m(f=>({...f,[i.key]:i.kind==="select"?[]:i.kind==="date"?{from:null,to:null}:""})),_(i.key)},className:"block w-full rounded px-2.5 py-1.5 text-left text-[14px] text-slate-300 hover:bg-slate-800 hover:text-white",children:i.label},i.key)),!D.length&&e.jsx("p",{className:"px-2.5 py-1.5 text-[12px] text-slate-600",children:"All columns filtered."})]})]}),e.jsxs("span",{className:"ml-auto text-[12px] text-slate-500",children:[j.length===t.length?t.length:`${j.length} of ${t.length}`," ",r.totals.rows_suffix]})]}),e.jsxs("div",{className:"mt-1 flex flex-col gap-2 md:hidden",children:[j.map(i=>{const d=(n.get(i.id)?.plan?.targets??[])[0]?.price??i.first_target??null,p=ft(i.status),g=p&&i.alert_time?Se(i.alert_time,o):null,E=p?st(null,i.alert_above,i.alert_below,o,""):[],C=we(i.status,r),F=Ae(i),R=gt(s,i.id),S=l===i.id;return e.jsxs("div",{onClick:()=>c(i.id),className:`rounded-xl border px-3 py-2.5 ${S?"border-[#7C3AED] bg-[#7C3AED]/10":"border-slate-800 bg-[#12121A]"}`,children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"min-w-0 flex-1 truncate text-[15px] font-semibold text-slate-100",children:i.symbol}),i.grade&&e.jsx(ne,{tone:Me[i.grade],children:i.grade}),C&&e.jsx(ne,{children:C}),R&&e.jsx(lt,{run:R,subject:i.symbol,config:r,onOpen:b}),F!=null?e.jsx(L,{className:`text-[13px] ${F>=0?ie:oe}`,children:i.r!=null?Y(i.r):ae(i.pct)}):e.jsx(L,{className:"text-[13px]",children:e.jsx(it,{u:i.unrealized,title:r.peek.unrealized_label})})]}),e.jsxs("p",{className:"mt-1.5 flex flex-wrap items-center gap-x-3 gap-y-1 text-[12px] text-slate-500",children:[e.jsx(L,{className:"text-slate-400",children:te(De(i),o)}),e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx("span",{className:"text-slate-600",children:N.entry}),e.jsx(L,{className:"text-slate-300",children:T(i.entry_price)})]}),e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx("span",{className:"text-slate-600",children:N.stop}),e.jsx(L,{className:"text-slate-300",children:T(i.stop)})]}),d!=null&&e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx("span",{className:"text-slate-600",children:N.target}),e.jsx(L,{className:"text-slate-300",children:T(d)})]})]}),(!!g||E.length>0)&&e.jsxs("p",{className:"mt-1 flex flex-wrap items-center gap-x-3 text-[12px] text-slate-500",children:[g&&e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx("span",{className:"text-slate-600",children:N.time_alert}),e.jsx(L,{className:"text-slate-400",children:g})]}),!!E.length&&e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx("span",{className:"text-slate-600",children:N.price_alert}),e.jsx(L,{className:"text-slate-400",children:E.join(" · ")})]})]})]},i.id)}),!j.length&&e.jsx("p",{className:"py-10 text-[14px] text-slate-600",children:t.length?r.empty_states.no_trades_filtered:r.empty_states.no_trades}),!!j.length&&e.jsxs("p",{className:"flex flex-wrap items-center gap-x-3 px-1 text-[12px] text-slate-500",children:[e.jsxs("span",{children:[e.jsx("span",{className:"mr-1 text-slate-600",children:"Σ"}),a.n," ",r.totals.rows_suffix]}),!!a.closed&&e.jsxs("span",{children:[a.wins,"W ",a.losses,"L"]}),!!a.open&&e.jsxs("span",{className:"text-slate-600",children:[a.open," ",r.totals.open_suffix]}),a.netR!=null&&e.jsx(L,{className:a.netR>=0?ie:oe,children:Y(a.netR)}),a.avgPct!=null&&e.jsxs("span",{className:"text-slate-600",children:[r.totals.avg_prefix," ",ae(a.avgPct)]})]})]}),e.jsx("div",{className:"hidden overflow-x-auto md:block",children:e.jsxs("table",{className:"w-full border-collapse text-[13.5px]",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx(K,{label:N.asset,type:U.asset}),e.jsx(K,{label:N.date,type:U.date}),e.jsx(K,{label:N.grade,type:U.grade}),e.jsx(K,{label:N.entry,type:U.entry,align:"right"}),e.jsx(K,{label:N.stop,type:U.stop,align:"right"}),e.jsx(K,{label:N.target,type:U.target,align:"right"}),e.jsx(K,{label:N.target_r,type:U.target_r,align:"right"}),e.jsx(K,{label:N.time_alert,type:U.time_alert,align:"right"}),e.jsx(K,{label:N.price_alert,type:U.price_alert}),e.jsx(K,{label:N.status,type:U.status}),e.jsx(K,{label:N.run,type:U.run}),e.jsx(K,{label:N.session,type:U.session}),e.jsx(K,{label:N.result,type:U.result,align:"right"}),e.jsx(K,{label:N.id,type:U.id,align:"right"})]})}),e.jsxs("tbody",{children:[j.map(i=>{const w=n.get(i.id)?.plan?.targets??[],d=w[0]?.price??i.first_target??null,p=w.length||i.target_count||0,g=d!=null?Ve(We(i),i.stop,d):null,E=ft(i.status),C=E&&i.alert_time?Se(i.alert_time,o):null,F=E?
4st(null,i.alert_above,i.alert_below,o,""):[],R=we(i.status,r),S=Ae(i),z=gt(s,i.id),J=l===i.id,O="h-[37px] whitespace-nowrap border-b border-slate-800 px-2.5 align-middle",W=`${O} text-right font-mono tabular-nums`;return e.jsxs("tr",{onClick:()=>c(i.id),className:`group cursor-pointer transition-colors ${J?"bg-[#7C3AED]/10":"hover:bg-slate-800/40"}`,style:J?{boxShadow:`inset 0 0 0 1px ${Fe}`}:void 0,children:[e.jsxs("td",{className:`${O} relative min-w-[150px] pr-[76px] font-semibold text-slate-100`,children:[i.symbol,e.jsxs("button",{type:"button",title:r.peek.open_tooltip,onClick:re=>{re.stopPropagation(),c(i.id)},className:"absolute right-2 top-1/2 hidden -translate-y-1/2 items-center gap-1 rounded border border-slate-700 bg-[#1A1A25] px-1.5 py-0.5 text-[11px] font-normal uppercase text-slate-400 group-hover:inline-flex hover:border-slate-500 hover:text-slate-100",children:[e.jsx(Ot,{className:"h-2.5 w-2.5 fill-none stroke-current"}),r.peek.open_chip]})]}),e.jsx("td",{className:`${O} text-slate-400`,children:te(De(i),o)}),e.jsx("td",{className:O,children:i.grade?e.jsx(ne,{tone:Me[i.grade],children:i.grade}):e.jsx(P,{})}),e.jsx("td",{className:`${W} text-slate-200`,children:T(i.entry_price)}),e.jsx("td",{className:`${W} text-slate-200`,children:T(i.stop)}),e.jsxs("td",{className:`${W} text-slate-200`,children:[d!=null?T(d):e.jsx(P,{}),p>1&&e.jsxs("span",{className:"ml-1 text-slate-600",children:["+",p-1]})]}),e.jsx("td",{className:`${W} text-slate-500`,children:g!=null?`${g.toFixed(1)}R`:e.jsx(P,{})}),e.jsx("td",{className:`${W} w-[1%] text-slate-400`,children:C??e.jsx(P,{})}),e.jsx("td",{className:`${W} w-[1%] text-left text-slate-400`,children:F.length?F.join(" · "):e.jsx(P,{})}),e.jsx("td",{className:O,children:R?e.jsx(ne,{children:R}):null}),e.jsx("td",{className:`${O} w-[1%]`,children:z?e.jsx(lt,{run:z,subject:i.symbol,config:r,onOpen:b}):e.jsx(P,{})}),e.jsx("td",{className:`${O} w-[1%] font-mono text-[11px] text-slate-600`,children:i.session_id?e.jsx("span",{title:i.session_id,children:tt(i.session_id)}):e.jsx(P,{})}),e.jsx("td",{className:W,children:S==null?i.unrealized&&(i.unrealized.r??i.unrealized.pct)!=null?e.jsx(it,{u:i.unrealized,title:r.peek.unrealized_label}):e.jsx(P,{}):e.jsx("span",{className:S>=0?ie:oe,children:i.r!=null?Y(i.r):ae(i.pct)})}),e.jsx("td",{className:`${O} w-[1%] text-right font-mono text-[11px] text-slate-600`,children:ot(i.id)})]},i.id)}),!j.length&&e.jsx("tr",{children:e.jsx("td",{colSpan:14,className:"py-10 text-[14px] text-slate-600",children:t.length?r.empty_states.no_trades_filtered:r.empty_states.no_trades})})]}),!!j.length&&e.jsx("tfoot",{children:e.jsxs("tr",{className:"text-[12px] text-slate-500",children:[e.jsxs("td",{className:"h-[34px] border-t border-slate-800 px-2.5",children:[e.jsx("span",{className:"mr-1 text-slate-600",children:"Σ"}),a.n," ",r.totals.rows_suffix]}),e.jsx("td",{className:"border-t border-slate-800",colSpan:8}),e.jsxs("td",{className:"border-t border-slate-800 px-2.5",children:[a.closed?`${a.wins}W ${a.losses}L`:"",a.open?e.jsxs("span",{className:"text-slate-600",children:[a.closed?" · ":"",a.open," ",r.totals.open_suffix]}):null]}),e.jsx("td",{className:"border-t border-slate-800"}),e.jsx("td",{className:"border-t border-slate-800"}),e.jsx("td",{className:"whitespace-nowrap border-t border-slate-800 px-2.5 text-right font-mono tabular-nums",children:a.netR!=null&&e.jsx("span",{className:a.netR>=0?ie:oe,children:Y(a.netR)})}),e.jsx("td",{className:"whitespace-nowrap border-t border-slate-800 px-2.5 text-right text-[11px] text-slate-600",children:a.avgPct!=null&&`${r.totals.avg_prefix} ${ae(a.avgPct)}`})]})})]})})]})}function _s(t,s){const n=new Map(s.map(l=>[l.id,l.name])),r=new Map;for(const l of t){const c=(l.run_id&&n.get(l.run_id))??l.run_id??"",b=r.get(c);b?b.push(l):r.set(c,[l])}return[...r.keys()].sort().reverse().flatMap(l=>r.get(l))}function vs({gates:t,config:s,running:n}){const{current:r}=xt(t);return e.jsxs("div",{className:"px-2.5 pb-3 pt-1",children:[e.jsx("p",{className:"mb-1.5 text-[11.5px] uppercase tracking-wide text-slate-500",children:s.progress.steps_heading}),e.jsx("ol",{className:"flex flex-wrap gap-x-5 gap-y-1.5",children:t.map((l,c)=>{const b=n&&l.id===r,u=l.passes?s.progress.step_passed_label:b?s.progress.step_current_label:s.progress.step_waiting_label;return e.jsxs("li",{title:`${Ue(l.id)} â ${u}`,className:`flex items-center gap-1.5 text-[12.5px] ${l.passes?"text-slate-300":b?"text-[#4ADE80]":"text-slate-600"}`,children:[l.passes?e.jsx("svg",{viewBox:"0 0 16 16","aria-label":u,className:"h-3 w-3 shrink-0 fill-none stroke-current text-emerald-400",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",children:e.jsx("path",{d:"M3.5 8.5 6.5 11.5 12.5 5"})}):e.jsxs("span",{className:"relative inline-flex h-3 w-3 shrink-0 items-center justify-center",children:[b&&e.jsx("span",{className:"absolute h-[7px] w-[7px] animate-ping rounded-full bg-[#4ADE80] opacity-60"}),e.jsx("span",{"aria-label":u,className:`relative h-[6px] w-[6px] rounded-full ${b?"bg-[#4ADE80]":"bg-slate-700"}`})]}),e.jsx("span",{className:"text-[12.5px]",children:Ue(l.id)})]},`${l.id}-${c}`)})})]})}function ws({runs:t,trades:s,config:n,onOpenRun:r}){const l=n.columns.runs,c=n.timezone.tz,b=h.useMemo(()=>{const o=new Map;for(const N of s)N.run_id&&o.set(N.run_id,(o.get(N.run_id)??0)+1);return o},[s]),u="whitespace-nowrap border-b border-slate-800 px-2.5 py-1.5 text-left text-[11.5px] font-normal text-slate-500",m="h-[37px] whitespace-nowrap border-b border-slate-800 px-2.5 align-middle",v=o=>{if(o.status==="started")return e.jsx(P,{});const N=n.run_status_labels[o.status];return N?e.jsx(ne,{tone:o.status==="failed"?"red":"grey",children:N}):e.jsx(P,{})},_=o=>{const N=o.gates??[],{done:x,total:j,current:a}=xt(N);return o.status==="started"?e.jsxs("span",{className:"inline-flex items-center gap-1.5 text-[12.5px] text-[#4ADE80]","aria-live":"polite",children:[e.jsxs("span",{className:"relative inline-flex h-[6px] w-[6px] shrink-0",children:[e.jsx("span",{className:"absolute inline-flex h-full w-full animate-ping rounded-full bg-[#4ADE80] opacity-60"}),e.jsx("span",{className:"relative inline-flex h-[6px] w-[6px] rounded-full bg-[#4ADE80]"})]}),j?X(n.progress.gates_running,{done:x,total:j,current:Ue(a)}):n.progress.gates_running_unknown]}):N.length?e.jsxs(L,{className:"text-slate-300",children:[x,"/",j]}):e.jsx(P,{})};return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"mt-3.5 flex flex-col gap-2 md:hidden",children:[t.map(o=>{const N=b.get(o.id)??0;return e.jsxs("div",{onClick:()=>r(o.id),className:"rounded-xl border border-slate-800 bg-[#12121A] px-3 py-2.5",children:[e.jsxs("div",{className:"flex items-baseline gap-3",children:[e.jsx("span",{className:"min-w-0 flex-1 truncate text-[14px] font-semibold text-slate-100",children:o.name}),v(o),o.has_report!==!1&&e.jsx(ne,{tone:"accent",children:l.report})]}),e.jsxs("p",{className:"mt-1.5 flex flex-wrap items-center gap-x-3 gap-y-1 text-[12px] text-slate-500",children:[e.jsx(L,{className:"text-slate-400",children:te(o.started_at,c)}),e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx("span",{className:"text-slate-600",children:l.gates}),_(o)]}),!!N&&e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx("span",{className:"text-slate-600",children:l.created}),e.jsx(L,{className:"text-slate-300",children:N})]}),!!o.updated_count&&e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx("span",{className:"text-slate-600",children:l.updated}),e.jsx(L,{className:"text-slate-300",children:o.updated_count})]}),o.session_id&&e.jsx("span",{title:o.session_id,className:"font-mono text-[11px] text-slate-600",children:tt(o.session_id)})]})]},o.id)}),!t.length&&e.jsx("p",{className:"py-10 text-[13px] text-slate-600",children:n.empty_states.no_runs})]}),e.jsx("div",{className:"mt-3.5 hidden overflow-x-auto md:block",children:e.jsxs("table",{className:"w-full border-collapse text-[13.5px]",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsxs("th",{className:u,children:[e.jsx(le,{
4kind:"text"}),l.run]}),e.jsxs("th",{className:u,children:[e.jsx(le,{kind:"date"}),l.date]}),e.jsxs("th",{className:u,children:[e.jsx(le,{kind:"select"}),l.gates]}),e.jsxs("th",{className:u,children:[e.jsx(le,{kind:"select"}),l.status]}),e.jsxs("th",{className:`${u} text-right`,children:[e.jsx(le,{kind:"number"}),l.created]}),e.jsxs("th",{className:`${u} text-right`,children:[e.jsx(le,{kind:"number"}),l.updated]}),e.jsxs("th",{className:`${u} w-[1%] whitespace-nowrap`,children:[e.jsx(le,{kind:"text"}),l.session]}),e.jsxs("th",{className:u,children:[e.jsx(le,{kind:"lines"}),l.report]})]})}),e.jsxs("tbody",{children:[t.map(o=>{const N=b.get(o.id)??0;return e.jsx(h.Fragment,{children:e.jsxs("tr",{onClick:()=>r(o.id),className:"group cursor-pointer transition-colors hover:bg-slate-800/40",children:[e.jsxs("td",{className:`${m} relative min-w-[150px] pr-[76px] font-semibold text-slate-100`,children:[o.name,e.jsxs("button",{type:"button",title:n.peek.open_tooltip,onClick:x=>{x.stopPropagation(),r(o.id)},className:"absolute right-2 top-1/2 hidden -translate-y-1/2 items-center gap-1 rounded border border-slate-700 bg-[#1A1A25] px-1.5 py-0.5 text-[11px] font-normal uppercase text-slate-400 group-hover:inline-flex hover:border-slate-500 hover:text-slate-100",children:[e.jsx(Ot,{className:"h-2.5 w-2.5 fill-none stroke-current"}),n.peek.open_chip]})]}),e.jsx("td",{className:`${m} text-slate-400`,children:te(o.started_at,c)}),e.jsx("td",{className:m,children:_(o)}),e.jsx("td",{className:m,children:v(o)}),e.jsx("td",{className:`${m} text-right font-mono tabular-nums text-slate-200`,children:N||e.jsx(P,{})}),e.jsx("td",{className:`${m} text-right font-mono tabular-nums text-slate-200`,children:o.updated_count?o.updated_count:e.jsx(P,{})}),e.jsx("td",{className:`${m} w-[1%] whitespace-nowrap font-mono text-[11px] text-slate-600`,children:o.session_id?e.jsx("span",{title:o.session_id,children:tt(o.session_id)}):e.jsx(P,{})}),e.jsx("td",{className:m,children:o.has_report===!1?e.jsx(P,{}):e.jsx(ne,{tone:"accent",children:l.report})})]})},o.id)}),!t.length&&e.jsx("tr",{children:e.jsx("td",{colSpan:8,className:"py-10 text-[13px] text-slate-600",children:n.empty_states.no_runs})})]})]})})]})}const ks="config/criteria.json",$s="templates/process.json",As="AGENT.md";function Ke(t){return!!t&&typeof t=="object"&&!Array.isArray(t)}function yt(t,s){return t.startsWith("_")&&typeof s=="string"}function Vt({children:t}){return e.jsx("p",{className:"mb-1.5 max-w-[70ch] text-[12.5px] leading-relaxed text-slate-500",children:t})}function Te({children:t}){return e.jsx("span",{className:"font-mono text-[12px] text-slate-500",children:t})}function Cs({value:t}){return t==null?e.jsx(P,{}):typeof t=="number"||typeof t=="boolean"?e.jsx(L,{className:"text-slate-200",children:String(t)}):e.jsx("span",{className:"text-[13px] text-slate-300",children:String(t)})}function Nt({children:t}){return e.jsx("div",{className:"ml-1 border-l border-slate-800 pl-3",children:t})}function Es({name:t,value:s}){if(Array.isArray(s)){const n=s.filter(Ke);return n.length===s.length&&s.length?e.jsxs("div",{className:"mt-2",children:[e.jsx(Te,{children:t}),e.jsx(Nt,{children:n.map((r,l)=>e.jsx("div",{className:"mt-2.5 first:mt-1",children:e.jsx(Re,{value:r})},l))})]}):e.jsxs("div",{className:"mt-1 flex flex-wrap items-baseline gap-x-2",children:[e.jsx(Te,{children:t}),e.jsx("span",{className:"text-[13px] text-slate-300",children:s.length?s.map(r=>String(r)).join(", "):e.jsx(P,{})})]})}return Ke(s)?e.jsxs("div",{className:"mt-2",children:[e.jsx(Te,{children:t}),e.jsx(Nt,{children:e.jsx(Re,{value:s})})]}):e.jsxs("div",{className:"mt-1 flex flex-wrap items-baseline gap-x-2",children:[e.jsx(Te,{children:t}),e.jsx(Cs,{value:s})]})}function Re({value:t}){const s=Object.entries(t);return e.jsxs(e.Fragment,{children:[s.filter(([n,r])=>yt(n,r)).map(([n,r])=>e.jsx(Vt,{children:r},n)),s.filter(([n,r])=>!yt(n,r)).map(([n,r])=>e.jsx(Es,{name:n,value:r},n))]})}function Ss({data:t}){const s=Array.isArray(t.steps)?t.steps.filter(Ke):[],n=Object.fromEntries(Object.entries(t).filter(([r])=>r!=="steps"&&r!=="name"));return e.jsxs("div",{children:[typeof t.name=="string"&&e.jsx("p",{className:"mb-1 text-[13.5px] font-semibold text-slate-100",children:t.name}),e.jsx(Re,{value:n}),e.jsx("ol",{className:"mt-2.5 space-y-2.5",children:s.map((r,l)=>{const c=typeof r.id=="string"?r.id:`step ${l+1}`,b=typeof r.what=="string"?r.what:"",u=typeof r._gate_note=="string"?r._gate_note:null,m=r.check,v=Object.fromEntries(Object.entries(r).filter(([_])=>!["id","what","check","_gate_note"].includes(_)));return e.jsxs("li",{className:"flex gap-2.5",children:[e.jsx(L,{className:"pt-px text-[12px] text-slate-600",children:String(l+1).padStart(2,"0")}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("p",{className:"text-[13.5px] text-slate-200",children:[e.jsx(L,{className:"text-[12.5px] text-[#A78BFA]",children:c}),b&&e.jsx("span",{className:"text-slate-600",children:" â "}),b]}),u&&e.jsx(Vt,{children:u}),e.jsx(Re,{value:v}),m!=null&&e.jsxs("details",{className:"mt-1",children:[e.jsx("summary",{className:"cursor-pointer text-[12px] text-slate-500 hover:text-slate-300",children:"check"}),e.jsx("pre",{className:"mt-1 overflow-x-auto whitespace-pre-wrap break-words rounded border border-slate-800 bg-[#0B0B12] px-2 py-1.5 font-mono text-[12px] leading-relaxed text-slate-400",children:typeof m=="string"?m:JSON.stringify(m,null,2)})]})]})]},c)})})]})}function _t({text:t,process:s}){let n;try{n=JSON.parse(t)}catch{return e.jsx("pre",{className:"overflow-x-auto whitespace-pre-wrap break-words font-mono text-[12px] leading-relaxed text-slate-400",children:t})}return Ke(n)?s?e.jsx(Ss,{data:n}):e.jsx(Re,{value:n}):e.jsx("pre",{className:"overflow-x-auto whitespace-pre-wrap break-words font-mono text-[12px] leading-relaxed text-slate-400",children:JSON.stringify(n,null,2)})}function Ms({agent:t,trades:s,runs:n,details:r,config:l,tab:c,onTab:b,selectedTradeId:u,onOpenTrade:m,onOpenRun:v,loadDocuments:_,onRequestRun:o}){const N=h.useMemo(()=>s.filter(C=>C.agent_id===t.id),[s,t.id]),x=h.useMemo(()=>dt(n,t.id).slice().sort((C,F)=>C.started_at<F.started_at?1:-1),[n,t.id]),j=h.useMemo(()=>_s(N,n),[N,n]),[a,k]=h.useState(!1),[M,B]=h.useState("about"),[$,D]=h.useState(null),[A,i]=h.useState(!1),f=h.useRef(null);h.useEffect(()=>{k(!1),B("about"),D(null),i(!1),f.current=null},[t.id]),h.useEffect(()=>{if(!a||f.current===t.id)return;f.current=t.id;let C=!1;return i(!0),_(t.id).then(F=>{C||(D(F),i(!1))}),()=>{C=!0}},[a,t.id,_]);const w=$?.[ks]??null,d=$?.[$s]??null,p=t.agent_md??$?.[As]??null,g=[{id:"about",label:l.agent.documents.about},...w?[{id:"criteria",label:l.agent.documents.criteria}]:[],...d?[{id:"process",label:l.agent.documents.process}
4]:[]],E=C=>`-mb-px border-b-2 px-2.5 py-1.5 text-[13px] transition ${C?"border-[#7C3AED] text-[#C4B5FD]":"border-transparent text-slate-500 hover:text-slate-300"}`;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"mb-1.5 mt-6 flex flex-wrap items-baseline gap-x-4 gap-y-2",children:[e.jsx("h1",{className:"text-[26px] font-bold tracking-tight text-white sm:text-[34px] md:text-[40px]",children:t.name}),e.jsx(at,{agent:t,config:l,onRequestRun:o,size:"header",run:nt(n,t.id),onOpenRun:v})]}),t.tagline&&e.jsx("p",{className:"mb-2 text-[14px] text-slate-500",children:t.tagline}),t.agent_md&&e.jsxs("div",{className:"mt-1",children:[e.jsxs("button",{type:"button",onClick:()=>k(C=>!C),"aria-expanded":a,className:"text-[12px] text-slate-500 hover:text-slate-300",children:[a?"â¾":"â¸"," ",l.section.about_label]}),a&&e.jsxs("div",{className:"mt-2 rounded-xl border border-slate-800 bg-[#12121A] px-4 py-3",children:[g.length>1&&e.jsx("div",{className:"mb-2.5 flex gap-1",children:g.map(C=>e.jsx("button",{type:"button",onClick:()=>B(C.id),"aria-pressed":M===C.id,className:`rounded-full border px-2.5 py-0.5 text-[12px] transition ${M===C.id?"border-[#7C3AED] bg-[#7C3AED]/15 text-[#A78BFA]":"border-slate-800 text-slate-500 hover:text-slate-300"}`,children:C.label},C.id))}),A&&!$?e.jsx(qe,{label:l.empty_states.loading}):M==="criteria"&&w?e.jsx(_t,{text:w}):M==="process"&&d?e.jsx(_t,{text:d,process:!0}):p?e.jsx(Rt,{source:p}):null]})]}),e.jsxs("div",{className:"mt-3 flex gap-0.5 border-b border-slate-800",children:[e.jsx("button",{type:"button",onClick:()=>b("trades"),className:E(c==="trades"),children:l.views.trades}),e.jsx("button",{type:"button",onClick:()=>b("journal"),className:E(c==="journal"),children:l.views.journal})]}),c==="trades"?e.jsx(Ns,{rows:j,runs:n,details:r,config:l,selectedId:u,onOpen:m,onOpenRun:v}):e.jsx(ws,{runs:x,trades:N,config:l,onOpenRun:v})]})}const Ds=30,vt=.8,Fs=3.5,wt=-1.5,Rs=.4,Bs=.2;function Is(t){return new Date(t).toISOString().slice(0,10)}const Ls=864e5;function Ts(t,s){const n=Date.UTC(new Date(s).getUTCFullYear(),new Date(s).getUTCMonth(),new Date(s).getUTCDate()),r=[];for(let l=t-1;l>=0;l-=1)r.push(Is(n-l*Ls));return r}function zs(t){let s=2166136261;for(let n=0;n<t.length;n+=1)s^=t.charCodeAt(n),s=Math.imul(s,16777619);return s>>>0}function Ps(t){let s=t>>>0;return()=>{s=s+1831565813>>>0;let n=s;return n=Math.imul(n^n>>>15,n|1),n^=n+Math.imul(n^n>>>7,n|61),((n^n>>>14)>>>0)/4294967296}}function Os(t,s){const n=s.length;if(n===0)return[];const r=Ps(zs(t)),l=n-1;if(l<=0)return[{time:s[0],value:0}];const c=vt+r()*(Fs-vt),b=.07+r()*(Rs-.07),u=Math.max(0,l-c/Bs),m=.4+r()*.8,v=Math.max(1,Math.round(u*(.3+r()*.7)/(1+m))),_=1+Math.floor(r()*Math.max(1,l-v-1)),o=[],N=[];let x=0;for(let $=0;$<l;$+=1){o.push((r()*2-1)*b);const A=$>=_&&$<_+v?-m:1;N.push(A),x+=A}const j=o.reduce(($,D)=>$+D,0),a=x===0?0:(c-j)/x,k=[0];let M=0;for(let $=0;$<l;$+=1){let D=M+a*N[$]+o[$];D<wt&&(D=M+a*N[$]+Math.abs(o[$])),D<wt&&(D=M),k.push(D),M=D}const B=c-k[l];return k.map(($,D)=>({time:s[D],value:Wt($+B*D/l)}))}function Wt(t){return Math.round(t*100)/100}function Vs(t){return(t.outcome?.exit?.at??t.entered_at??"").slice(0,10)}const Ws=new Set(["closed","stopped","target_hit","expired"]);function qs(t,s,n){const r=n[0],l=n[n.length-1],c=new Map;for(const m of s){if(m.agent_id!==t.id||!Ws.has(m.status)||m.r==null)continue;const v=Vs(m);!v||v<r||v>l||c.set(v,(c.get(v)??0)+m.r)}let b=0;const u=[];for(const m of[...c.keys()].sort())b+=c.get(m),u.push({time:m,value:Wt(b)});return u}function Us(t,s,n,r=Date.now()){const l=n.home?.curve,c=Ts(Math.max(2,l?.days??Ds),r);return t.map(b=>({agentId:b.id,name:b.name,points:l?.demo?Os(b.slug||b.id,c):qs(b,s,c)}))}const Xe="#94A3B8",ze="__portfolio";function Ks(t){const s=[...new Set(t.flatMap(l=>l.points.map(c=>c.time)))].sort(),n=new Map,r=t.map(l=>new Map(l.points.map(c=>[c.time,c.value])));return s.map(l=>{let c=0;return t.forEach((b,u)=>{const m=r[u].get(l);m!=null&&n.set(b.agentId,m),c+=n.get(b.agentId)??0}),{time:l,value:Math.round(c*100)/100}})}function Hs(t){const s=t.map(r=>{const l=new Map;for(let c=1;c<r.points.length;c+=1)l.set(r.points[c].time,r.points[c].value-r.points[c-1].value);return l}),n=(r,l)=>{const c=[...r.keys()].filter(x=>l.has(x));if(c.length<3)return 0;const b=c.map(x=>r.get(x)),u=c.map(x=>l.get(x)),m=b.reduce((x,j)=>x+j,0)/b.length,v=u.reduce((x,j)=>x+j,0)/u.length;let _=0,o=0,N=0;for(let x=0;x<b.length;x+=1){const j=b[x]-m,a=u[x]-v;_+=j*a,o+=j*j,N+=a*a}return o&&N?_/Math.sqrt(o*N):0};return s.map(r=>s.map(l=>r===l?1:n(r,l)))}function Gs({agents:t,trades:s,config:n}){const r=h.useRef(null),l=h.useMemo(()=>Us(t,s,n),[t,s,n]),c=n.home.curve,b=c.palette,[u,m]=h.useState(null),[v,_]=h.useState([]),o=h.useMemo(()=>{const f=w=>w.points.length?w.points[w.points.length-1].value:Number.NEGATIVE_INFINITY;return[...l].sort((w,d)=>f(d)-f(w))},[l]),N=h.useMemo(()=>new Map(o.map((f,w)=>[f.agentId,w])),[o]),x=f=>b[f%b.length]??Xe,j=c.portfolio,a=f=>f===ze?j.colour:x(N.get(f)??0),[k,M]=h.useState([]),B=f=>M(w=>w.includes(f)?w.filter(d=>d!==f):[...w,f]),$=h.useMemo(()=>o.filter(f=>k.includes(f.agentId)),[o,k]),D=h.useMemo(()=>$.length?$.length<2?$:[...$,{agentId:ze,name:j.combined_label,points:Ks($)}]:o,[o,$,j.combined_label]),A=h.useMemo(()=>$.length>=2?Hs($):null,[$]);h.useEffect(()=>{const f=r.current;if(!f)return;const w=D.filter(S=>S.points.length>0);if(!w.length)return;const d=new Map(l.map(S=>[S.agentId,a(S.agentId)])),p=Mt(f,{layout:{background:{type:Ft.Solid,color:"transparent"},textColor:"#64748B",fontSize:11},grid:{vertLines:{visible:!1},horzLines:{color:"rgba(255,255,255,0.035)"}},crosshair:{mode:Dt.Normal,vertLine:{color:"rgba(255,255,255,0.18)",width:1,style:ye.Dotted,labelVisible:!0},horzLine:{visible:!1,labelVisible:!1}},localization:{priceFormatter:tn},rightPriceScale:{borderColor:"rgba(255,255,255,0.08)",scaleMargins:{top:.12,bottom:.12}},timeScale:{borderColor:"rgba(255,255,255,0.08)",timeVisible:!1,rightOffset:4},handleScroll:!0,handleScale:!0,autoSize:!0}),g=new Map;
4w.forEach(S=>{const z=d.get(S.agentId)??Xe,J=p.addSeries(Ht,{color:z,lineWidth:S.agentId===ze?3:2,priceLineVisible:!1,priceLineColor:z,priceLineWidth:1,priceLineStyle:ye.Dotted,lastValueVisible:!1,crosshairMarkerVisible:!0,crosshairMarkerRadius:3});J.setData(S.points.map(O=>({time:O.time,value:O.value}))),g.set(S.agentId,J)}),g.get(w[0].agentId)?.createPriceLine({price:0,color:"rgba(255,255,255,0.22)",lineWidth:1,lineStyle:ye.Dotted,axisLabelVisible:!1,title:""});const C=()=>{const S=p.timeScale(),z=f.clientWidth,J=[];for(const O of w){const W=g.get(O.agentId),re=O.points[O.points.length-1];if(!W||!re)continue;const Ne=S.timeToCoordinate(re.time),fe=W.priceToCoordinate(re.value);Ne==null||fe==null||J.push({agentId:O.agentId,initial:Qs(O.name),colour:d.get(O.agentId)??Xe,x:Math.min(Ne+Xs,z-Ys),y:fe,text:Y(re.value)})}_(Zs(J))};p.subscribeCrosshairMove(S=>{if(!S.time||!S.point){m(null);return}const z={};for(const[J,O]of g){const W=S.seriesData.get(O);W&&typeof W.value=="number"&&(z[J]=W.value)}m(z)}),p.timeScale().fitContent();let F=requestAnimationFrame(C);p.timeScale().subscribeVisibleLogicalRangeChange(C);const R=new ResizeObserver(()=>{try{p.timeScale().fitContent(),cancelAnimationFrame(F),F=requestAnimationFrame(C)}catch{}});return R.observe(f),()=>{R.disconnect(),cancelAnimationFrame(F),m(null),_([]);try{p.timeScale().unsubscribeVisibleLogicalRangeChange(C),p.remove()}catch{}}},[D,b,k]);const i=l.some(f=>f.points.length>0);return e.jsxs("div",{className:"mt-4",children:[e.jsxs("div",{className:"mb-2 flex items-center gap-2",children:[e.jsx("span",{className:"text-[12.5px] text-slate-500",children:c.label}),c.demo&&e.jsx("span",{className:"rounded-full border border-slate-800 bg-[#12121A] px-2 py-[1px] text-[11px] leading-[16px] text-slate-500",children:c.demo_note})]}),i?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"relative",children:[e.jsx("div",{ref:r,className:"h-[calc(100vh-300px)] min-h-[380px] w-full overflow-hidden rounded-lg border border-slate-800 bg-[#12121A]"}),e.jsx("div",{className:"pointer-events-none absolute inset-0 overflow-hidden rounded-lg",children:v.map(f=>e.jsxs("div",{className:"absolute flex -translate-y-1/2 items-center gap-1",style:{left:f.x,top:f.y},children:[e.jsx("span",{"aria-hidden":!0,className:"flex h-[18px] w-[18px] items-center justify-center rounded-full text-[10px] font-semibold leading-none text-white",style:{background:f.colour,boxShadow:`0 0 0 1.5px ${Js}`},children:f.initial}),e.jsx("span",{className:"rounded-full px-1.5 py-[1px] font-mono text-[10.5px] leading-[14px] tabular-nums",style:{color:f.colour,background:"rgba(18,18,26,0.82)"},children:f.text})]},f.agentId))})]}),e.jsxs("div",{className:"mt-2.5 flex flex-wrap items-center gap-x-4 gap-y-1",children:[e.jsx("span",{className:"text-[11.5px] uppercase tracking-wide text-slate-600",children:j.label}),o.map(f=>{const w=f.points.length?f.points[f.points.length-1].value:null,d=u?.[f.agentId]??w,p=k.includes(f.agentId),g=k.length>0&&!p;return e.jsxs("button",{type:"button","aria-pressed":p,onClick:()=>B(f.agentId),className:`inline-flex items-center gap-1.5 rounded-full border px-2 py-0.5 text-[12px] transition ${p?"border-slate-600 bg-[#161620]":"border-transparent hover:border-slate-700"} ${g?"opacity-40":""}`,children:[e.jsx("span",{"aria-hidden":!0,className:"inline-block h-[2px] w-3 rounded-full",style:{background:a(f.agentId)}}),e.jsx("span",{style:{color:a(f.agentId)},children:f.name}),e.jsx("span",{className:"font-mono tabular-nums text-slate-400",children:d==null?n.home.unset_option:Y(d)})]},f.agentId)}),$.length>=2&&(()=>{const f=D.find(d=>d.agentId===ze),w=f?.points.length?f.points[f.points.length-1].value:null;return e.jsxs("span",{className:"inline-flex items-center gap-1.5 rounded-full border border-slate-700 px-2 py-0.5 text-[12px]",children:[e.jsx("span",{"aria-hidden":!0,className:"inline-block h-[3px] w-3 rounded-full",style:{background:j.colour}}),e.jsx("span",{style:{color:j.colour},children:j.combined_label}),e.jsx("span",{className:"font-mono tabular-nums text-slate-400",children:w==null?n.home.unset_option:Y(w)})]})})(),k.length?e.jsx("button",{type:"button",onClick:()=>M([]),className:"text-[12px] text-slate-500 hover:text-slate-300",children:j.clear_label}):e.jsx("span",{className:"text-[12px] text-slate-600",children:j.hint})]}),A&&e.jsxs("div",{className:"mt-4",children:[e.jsx("div",{className:"mb-1.5 text-[12.5px] text-slate-500",children:j.correlation_label}),e.jsxs("table",{className:"border-collapse text-[12px]",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{}),$.map(f=>e.jsx("th",{className:"px-2 pb-1 text-left font-normal",style:{color:a(f.agentId)},children:f.name},f.agentId))]})}),e.jsx("tbody",{children:$.map((f,w)=>e.jsxs("tr",{children:[e.jsx("td",{className:"pr-2 text-right",style:{color:a(f.agentId)},children:f.name}),$.map((d,p)=>{const g=A[w][p],E=Math.min(1,Math.abs(g));return e.jsx("td",{className:"h-9 w-20 text-center font-mono tabular-nums",style:{background:g>=0?`rgba(124,58,237,${.08+E*.5})`:`rgba(148,163,184,${.08+E*.35})`,color:E>.55?"#F8FAFC":"#CBD5E1"},children:g.toFixed(2)},d.agentId)})]},f.agentId))})]})]})]}):e.jsx("div",{className:"flex h-[calc(100vh-300px)] min-h-[380px] items-center justify-center rounded-lg border border-slate-800 bg-[#12121A] text-[13px] text-slate-600",children:n.empty_states.no_trades})]})}const Js="#12121A",Ys=74,Xs=7;function Qs(t){return(Array.from(t.trim())[0]??"?").toUpperCase()}function Zs(t){const s=[...t].sort((r,l)=>r.y-l.y);let n=-1/0;for(const r of s)r.y<n&&(r.y=n),n=r.y+en;return s}const en=20;function tn(t){return Math.abs(t)<.05?"0.0R":`${t>0?"+":""}${t.toFixed(1)}R`}const qt="alpha-agents.home.view";function sn(){try{const t=window.localStorage.getItem(qt);return t==="curve"||t==="table"?t:null}catch{return null}}function nn(t){try{window.localStorage.setItem(qt,t)}catch{}}const Z={agent:"text",enabled:"select",run:"select",runtime:"date",frequency:"select",tz:"select",runs:"number",trades:"number",avg_return:"sum",avg_r:"sum",curve:"lines"},me="h-[37px] whitespace-nowrap border-b border-slate-800 px-2.5 align-middle",Pe=`${me} text-right font-mono tabular-nums text-slate-200`;function ee({label:t,type:s,align:n="left"}){return e.jsxs("th",{className:`whitespace-nowrap border-b border-slate-800 px-2.5 py-1.5 text-[11.5px] font-normal text-slate-500 ${n==="right"?"text-right":"text-left"}
4`,children:[e.jsx(le,{kind:s}),t]})}function kt({on:t,label:s}){return e.jsx("span",{"aria-hidden":!t,"aria-label":s,title:t?s:void 0,className:"pointer-events-none inline-flex w-3.5 shrink-0 items-center text-emerald-400 transition-opacity duration-500",style:{opacity:t?1:0},children:e.jsx("svg",{viewBox:"0 0 16 16",className:"h-3 w-3 fill-none stroke-current",strokeWidth:1.8,strokeLinecap:"round",strokeLinejoin:"round",children:e.jsx("path",{d:"M3.5 8.5 6.5 11.5 12.5 5"})})})}function $t({on:t,busy:s,label:n,onChange:r}){return e.jsx("button",{type:"button",role:"switch","aria-checked":t,"aria-label":n,title:n,disabled:s,onClick:l=>{l.stopPropagation(),r(!t)},className:"relative inline-flex h-[18px] w-[32px] shrink-0 items-center rounded-full align-middle transition-colors disabled:opacity-60 max-md:before:absolute max-md:before:-inset-2 max-md:before:content-['']",style:{background:t?Fe:"#262634"},children:e.jsx("span",{className:"absolute h-3.5 w-3.5 rounded-full bg-white transition-all",style:{left:t?16:2}})})}function Qe(t){return t?t.split(",").map(s=>s.trim().slice(0,5)).join(", "):""}const Ze="font-mono tabular-nums text-[13px] text-slate-400",ge=110,je=24,ue=3;function rn({points:t,label:s}){const n=je/2;if(t.length<2)return e.jsx("svg",{viewBox:`0 0 ${ge} ${je}`,width:ge,height:je,className:"block",role:"img","aria-label":s,children:e.jsx("line",{x1:ue,y1:n,x2:ge-ue,y2:n,stroke:"#334155",strokeWidth:1})});const r=Math.min(0,...t),l=Math.max(0,...t),c=l-r||1,b=o=>ue+o*(ge-2*ue)/(t.length-1),u=o=>je-ue-(o-r)/c*(je-2*ue),m=t.map((o,N)=>`${N?"L":"M"}${b(N).toFixed(1)} ${u(o).toFixed(1)}`).join(" "),v=t[t.length-1],_=v>=0?"#34D399":"#FB7185";return e.jsxs("svg",{viewBox:`0 0 ${ge} ${je}`,width:ge,height:je,className:"block",role:"img","aria-label":s,children:[r<0&&l>0&&e.jsx("line",{x1:ue,y1:u(0),x2:ge-ue,y2:u(0),stroke:"#1E293B",strokeWidth:1}),e.jsx("path",{d:m,fill:"none",stroke:_,strokeWidth:1.3,strokeLinecap:"round",strokeLinejoin:"round"}),e.jsx("circle",{cx:b(t.length-1),cy:u(v),r:1.6,fill:_})]})}function ln({agents:t,trades:s,runs:n,config:r,onOpenAgent:l,onSaveAgent:c,onRequestRun:b,onOpenRun:u}){const m=h.useMemo(()=>new Map(t.map(d=>[d.id,ps(d,s,n)])),[t,s,n]),v=h.useMemo(()=>new Map(t.map(d=>[d.id,us(d.id,s)])),[t,s]),_=r.home.columns,[o,N]=h.useState({}),[x,j]=h.useState({}),a=h.useRef({});h.useEffect(()=>{const d=a.current;return()=>{for(const p of Object.values(d))window.clearTimeout(p)}},[]);const[k,M]=h.useState(()=>sn()??r.home.default_view),B=h.useCallback(d=>{M(d),nn(d)},[]),[$,D]=h.useState({}),A=h.useCallback(d=>{const p=d.map(g=>_[g]??g).map(g=>g.toLowerCase());return p.length>1?`${p.slice(0,-1).join(", ")} ${r.home.and_word} ${p[p.length-1]}`:p[0]??""},[_,r.home.and_word]),i=h.useCallback((d,p)=>{D(g=>({...g,[d]:p})),window.clearTimeout(a.current[`${d}:problem`]),a.current[`${d}:problem`]=window.setTimeout(()=>D(g=>({...g,[d]:""})),5e3)},[]),f=h.useCallback(async(d,p,g,E)=>{const C=`${d}:${p}`;if(g.enabled===!0){const R=t.find(z=>z.id===d),S=["runtime","frequency","tz"].filter(z=>!R?.[z]);if(S.length){i(C,X(r.home.schedule_incomplete,{missing:A(S)}));return}}N(R=>({...R,[C]:!0}));const F=await c(d,g,E);if(N(R=>({...R,[C]:!1})),F){i(C,F.missing?.length?X(r.home.schedule_incomplete,{missing:A(F.missing)}):r.home.save_failed);return}j(R=>({...R,[C]:!0})),window.clearTimeout(a.current[C]),a.current[C]=window.setTimeout(()=>j(R=>({...R,[C]:!1})),1600)},[c,t,r.home.schedule_incomplete,r.home.save_failed,i,A]),w=(d,p)=>({busy:!!o[`${d}:${p}`],saved:!!x[`${d}:${p}`]});return e.jsxs(e.Fragment,{children:[e.jsx("h1",{className:"mb-1.5 mt-6 text-[28px] font-bold tracking-tight text-white sm:text-[34px] md:text-[40px]",children:r.home.title}),r.home.subtitle&&e.jsx("p",{className:"mb-5 text-[14px] text-slate-500",children:r.home.subtitle}),!!t.length&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"flex flex-wrap items-center gap-1",children:["table","curve"].map(d=>e.jsx("button",{type:"button","aria-pressed":k===d,onClick:()=>B(d),className:`rounded-full border px-2.5 py-0.5 text-[12.5px] leading-[18px] transition ${k===d?"border-[#A78BFA] bg-[#7C3AED]/15 text-[#A78BFA]":"border-slate-800 bg-[#12121A]/80 text-slate-500 hover:border-slate-600 hover:text-slate-300"}`,children:r.home.views[d]},d))}),k==="curve"&&e.jsx(Gs,{agents:t,trades:s,config:r})]}),t.length?k==="curve"?null:e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"mt-4 flex flex-col gap-2 md:hidden",children:t.map(d=>{const p=m.get(d.id),g={name:d.name},E=w(d.id,"enabled"),C=r.home.tz_options.find(S=>S.value===d.tz)?.label??d.tz,F=[Qe(d.runtime),d.frequency,d.tz?C:""].filter(
4Boolean).join(" · "),R=[];return p.runs&&R.push([_.runs,e.jsx(e.Fragment,{children:p.runs})]),p.trades&&R.push([_.trades,e.jsx(e.Fragment,{children:p.trades})]),p.avgPct!=null&&R.push([_.avg_return,e.jsx("span",{className:p.avgPct>=0?ie:oe,children:ae(p.avgPct)})]),p.avgR!=null&&R.push([_.avg_r,e.jsx("span",{className:p.avgR>=0?ie:oe,children:Y(p.avgR)})]),e.jsxs("div",{onClick:()=>l(d.id),className:"rounded-xl border border-slate-800 bg-[#12121A] px-3 py-2.5",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("button",{type:"button",onClick:S=>{S.stopPropagation(),l(d.id)},className:"min-w-0 flex-1 truncate py-1 text-left text-[15px] font-semibold text-slate-100",title:d.tagline??void 0,children:d.name}),e.jsxs("span",{className:"flex shrink-0 items-center gap-1.5",children:[e.jsx($t,{on:d.enabled,busy:E.busy,label:X(r.home.enabled_label,g),onChange:S=>f(d.id,"enabled",{enabled:S},{enabled:d.enabled})}),e.jsx(kt,{on:E.saved,label:r.home.saved_label})]}),e.jsx(at,{agent:d,config:r,onRequestRun:b,onOpenRun:u,run:nt(n,d.id)})]}),$[`${d.id}:enabled`]&&e.jsx("p",{role:"alert",className:"mt-1 text-[12.5px] text-rose-300",children:$[`${d.id}:enabled`]}),e.jsx("p",{className:"mt-1.5 font-mono text-[12px] tabular-nums text-slate-500",children:F||e.jsx(P,{})}),!!R.length&&e.jsx("p",{className:"mt-1 flex flex-wrap items-center gap-x-3 gap-y-0.5 font-mono text-[12px] tabular-nums text-slate-400",children:R.map(([S,z])=>e.jsxs("span",{children:[e.jsxs("span",{className:"font-sans text-slate-600",children:[S," "]}),z]},S))})]},d.id)})}),e.jsx("div",{className:"mt-4 hidden overflow-x-auto md:block",children:e.jsxs("table",{className:"w-auto border-collapse text-[13.5px]",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx(ee,{label:_.agent,type:Z.agent}),e.jsx(ee,{label:_.enabled,type:Z.enabled}),e.jsx(ee,{label:_.run,type:Z.run}),e.jsx(ee,{label:_.runtime,type:Z.runtime}),e.jsx(ee,{label:_.frequency,type:Z.frequency}),e.jsx(ee,{label:_.tz,type:Z.tz}),e.jsx(ee,{label:_.runs,type:Z.runs,align:"right"}),e.jsx(ee,{label:_.trades,type:Z.trades,align:"right"}),e.jsx(ee,{label:_.avg_return,type:Z.avg_return,align:"right"}),e.jsx(ee,{label:_.avg_r,type:Z.avg_r,align:"right"}),e.jsx(ee,{label:_.curve,type:Z.curve,align:"right"})]})}),e.jsx("tbody",{children:t.map(d=>{const p=m.get(d.id),g=v.get(d.id)??[],E={name:d.name},C=w(d.id,"enabled");return e.jsxs("tr",{onClick:()=>l(d.id),className:"group cursor-pointer transition-colors hover:bg-slate-800/40",children:[e.jsx("td",{className:`${me} w-[1%] pr-6 font-semibold text-slate-100`,children:e.jsx("span",{className:"group-hover:text-white",title:d.tagline??void 0,children:d.name})}),e.jsx("td",{className:`${me} w-[1%]`,children:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx($t,{on:d.enabled,busy:C.busy,label:X(r.home.enabled_label,E),onChange:F=>f(d.id,"enabled",{enabled:F},{enabled:d.enabled})}),e.jsx(kt,{on:C.saved,label:r.home.saved_label}),$[`${d.id}:enabled`]&&e.jsx("span",{role:"alert",className:"whitespace-nowrap text-[12.5px] text-rose-300",children:$[`${d.id}:enabled`]})]})}),e.jsx("td",{className:`${me} w-[1%]`,children:e.jsx(at,{agent:d,config:r,onRequestRun:b,onOpenRun:u,run:nt(n,d.id)})}),e.jsx("td",{className:`${me} w-[1%]`,children:e.jsx("span",{className:Ze,title:Qe(d.runtime)||void 0,children:Qe(d.runtime)||e.jsx(P,{})})}),e.jsx("td",{className:`${me} w-[1%]`,children:e.jsx("span",{className:Ze,children:d.frequency||e.jsx(P,{})})}),e.jsx("td",{className:`${me} w-[1%]`,children:e.jsx("span",{className:Ze,children:r.home.tz_options.find(F=>F.value===d.tz)?.label??d.tz})}),e.jsx("td",{className:Pe,children:p.runs||e.jsx(P,{})}),e.jsx("td",{className:Pe,children:p.trades||e.jsx(P,{})}),e.jsx("td",{className:Pe,children:p.avgPct==null?e.jsx(P,{}):e.jsx("span",{className:p.avgPct>=0?ie:oe,children:ae(p.avgPct)})}),e.jsx("td",{className:Pe,children:p.avgR==null?e.jsx(P,{}):e.jsx("span",{className:p.avgR>=0?ie:oe,children:Y(p.avgR)})}),e.jsx("td",{className:`${me} w-[1%] text-right`,children:e.jsx("span",{className:"inline-flex justify-end align-middle",children:e.jsx(rn,{points:g,label:`${_.curve}: ${g.length?Y(g[g.length-1]):r.home.unset_option}`})})})]},d.id)})})]})})]}):e.jsx("p",{className:"py-10 text-[13px] text-slate-600",children:r.empty_states.no_agents})]})}function an({token:t,config:s}){const n=s.keys,r=s.timezone.tz,[l,c]=h.useState(null),[b,u]=h.useState(null),[m,v]=h.useState(""),[_,o]=h.useState(!1),[N,x]=h.useState(null),[j,a]=h.useState(!1),k=!1,M=async()=>{const A=await pt(t);c(A.keys),u(A.error&&A.error!=="no_session"?A.error:null)};h.useEffect(()=>{let A=!1;return(async()=>{const i=await pt(t);A||(c(i.keys),u(i.error&&i.error!=="no_session"?i.error:null))})(),()=>{A=!0}},[t,k]);const B=async()=>
4{if(_)return;o(!0);const A=await ls(t,m.trim());if(o(!1),"error"in A){u(A.error);return}u(null),x(A),a(!1),v(""),ve("alpha_agents_key_created","alpha-agents"),await M()},$=async A=>{if(!await as(t,A)){u("revoke_failed");return}await M()},D=async()=>{if(N)try{await navigator.clipboard.writeText(N.key),a(!0)}catch{}};return e.jsxs(e.Fragment,{children:[e.jsx("h1",{className:"mb-1.5 mt-6 text-[30px] font-bold tracking-tight text-white md:text-[36px]",children:n.title}),n.subtitle&&e.jsx("p",{className:"mb-5 text-[14px] text-slate-500",children:n.subtitle}),N&&e.jsxs("div",{className:"mt-4 rounded-xl border border-[#7C3AED]/50 bg-[#7C3AED]/10 p-4",children:[e.jsx("p",{className:"text-[12.5px] font-semibold text-amber-300",children:n.once_warning}),e.jsxs("div",{className:"mt-3 flex flex-wrap items-center gap-2",children:[e.jsx(L,{className:"select-all break-all rounded border border-slate-800 bg-[#0B0B12] px-2.5 py-1.5 text-[13px] text-slate-100",children:N.key}),e.jsx("button",{type:"button",onClick:D,className:"rounded-lg px-3 py-1.5 text-[12.5px] font-semibold text-white",style:{background:Fe},children:j?n.copied_label:n.copy_label}),e.jsx("button",{type:"button",onClick:()=>x(null),className:"rounded-lg border border-slate-700 px-3 py-1.5 text-[12.5px] text-slate-300 hover:border-slate-500",children:n.dismiss_label})]})]}),e.jsxs("div",{className:"mt-5 flex flex-wrap items-center gap-2",children:[e.jsx("input",{value:m,onChange:A=>v(A.target.value),placeholder:n.label_placeholder,className:"min-w-[220px] flex-1 rounded-lg border border-slate-800 bg-[#0B0B12] px-3 py-2 text-[13px] text-slate-200 outline-none placeholder:text-slate-600 focus:border-[#7C3AED]"}),e.jsx("button",{type:"button",onClick:B,disabled:_,className:"rounded-lg px-4 py-2 text-[13px] font-semibold text-white disabled:opacity-60",style:{background:Fe},children:n.create_label})]}),b&&e.jsx("p",{className:"mt-3 rounded-lg border border-slate-800 bg-[#12121A] px-3 py-2 text-[12.5px] text-amber-300/90",children:s.empty_states.load_failed}),e.jsx("div",{className:"mt-5 overflow-x-auto",children:e.jsx("table",{className:"w-full border-collapse text-[13.5px]",children:e.jsxs("tbody",{children:[(l??[]).map(A=>e.jsxs("tr",{className:"border-b border-slate-800",children:[e.jsx("td",{className:"h-[37px] px-2.5 align-middle text-slate-200",children:A.label||e.jsx("span",{className:"text-slate-600",children:A.id.slice(0,8)})}),e.jsxs("td",{className:"px-2.5 text-[12px] text-slate-500",children:[ke(A.created_at,r)," ",s.timezone.label]}),e.jsx("td",{className:"px-2.5 text-[12px] text-slate-500",children:A.last_used_at?`${ke(A.last_used_at,r)} ${s.timezone.label}`:e.jsx("span",{className:"text-slate-600",children:n.never_used_label})}),e.jsx("td",{className:"px-2.5 text-right",children:A.revoked_at?e.jsx("span",{className:"text-[12px] text-slate-600",children:n.revoked_label}):e.jsx("button",{type:"button",onClick:()=>$(A.id),className:"text-[12px] text-slate-500 hover:text-rose-300",children:n.revoke_label})})]},A.id)),l&&!l.length&&e.jsx("tr",{children:e.jsx("td",{className:"py-10 text-[13px] text-slate-600",children:s.empty_states.no_keys})}),!l&&e.jsx("tr",{children:e.jsxs("td",{className:"py-10 text-[13px] text-slate-600",children:[s.empty_states.loading," ",e.jsx(P,{})]})})]})})})]})}function on(t,s){switch(t.kind){case"filled":return`filled @ ${T(t.price)}${t.order_type?` (${t.order_type})`:""}`;case"stop_moved":return`stop â ${T(t.to_price)}`;case"targets_set":return`targets â ${(t.targets??[]).map(n=>`${T(n.price)} Ã${n.take_pct}%`).join(", ")}`;case"partial_exit":return`${Bt(t.pct)} off @ ${T(t.price)}`;case"exit":return`closed @ ${T(t.price)}${t.reason?` · ${s.exit_reasons[t.reason]??t.reason}`:""}`;case"dropped":return`dropped${t.reason?` · ${t.reason}`:""}`;default:return t.note??s.event_kinds.note??"note"}}function cn({detail:t,loading:s,error:n,trades:r,config:l,agentName:c,onOpenTrade:b,onBack:u}){const m=h.useMemo(()=>new Map(r.map(a=>[a.id,a])),[r]);if(s||!t)return e.jsx("p",{className:"py-10 text-[13px] text-slate-600",children:n?l.empty_states.load_failed:l.empty_states.loading});const v=t.run,_=v.gates??[],o=_.filter(a=>a.passes).length,N=v.trade_id?m.get(v.trade_id)??null:null,x=a=>{const k=m.get(a);return e.jsx("button",{type:"button",onClick:()=>b(a),className:"text-[#A78BFA] underline-offset-2 hover:underline",children:k?k.symbol:ot(a)},a)},j=t.created.filter(a=>m.has(a));return e.jsxs(e.Fragment,{children:[e.jsxs("button",{type:"button",onClick:()=>N?b(N.id):u(),className:"mt-6 text-[12px] text-slate-500 hover:text-slate-300",children:["â ",N?`${l.run.back_to_trade_label} ${N.symbol}`:l.run.back_label]}),e.jsx("h1",{className:"mb-1.5 mt-2 text-[24px] font-bold tracking-tight text-white sm:text-[30px] md:text-[36px]",children:v.name}),e.jsxs("p",{className:"mb-2 text-[14px] text-slate-500",children:[c,N&&e.jsxs(e.Fragment,{children:[" · ",l.run.managing_label," ",e.jsx("button",{type:"button",onClick:()=>b(N.id),className:"text-[#A78BFA] underline-offset-2 hover:underline",children:N.symbol})]})]}),v.session_id&&e.jsxs("p",{className:"mb-2 text-[12px] text-slate-500",children:[l.run.session_label," ",e.jsx("span",{className:"select-all break-all font-mono text-slate-400",children:v.session_id})]}),!!_.length&&e.jsxs("div",{className:"mb-3 mt-2",children:[e.jsxs("p",{className:"mb-1 text-[12px] text-slate-500",children:[o,"/",_.length," ",l.run.gates_suffix]}),e.jsx(vs,{gates:_,config:l,running:v.status==="started"})]}),(j.length>0||t.updated.length>0)&&e.jsxs(e.Fragment,{children:[e.jsx("h3",{className:"mb-2 mt-5 text-[16px] font-semibold text-white",children:l.run.decisions_heading}),e.jsxs("ul",{className:"list-disc space-y-1.5 pl-5 text-[13.5px] leading-relaxed text-slate-300",children:[!!j.length&&e.jsxs("li",{children:[l.run.created_prefix," ",j.length,":"," ",j.map((a,k)=>e.jsxs("span",{children:[k>0&&" · ",x(a)," ",e.jsx("span",{className:"text-slate-600",children:we(m.get(a)?.status,l)??""})]},a))]}),t.updated.map(a=>e.jsxs("li",{children:[x(a.trade_id)," â ",on(a,l),a.note&&a.kind!=="note"&&e.jsxs("span",{className:"text-slate-500",children:[" â ",a.note]})]},a.id))]})]}),e.jsx("hr",{className:"my-5 border-slate-800"}),v.report_md?e.jsx(Rt,{source:v.report_md}):e.jsx("p",{className:"text-[13px] text-slate-600",children:l.run.no_report})]})}const At="#34D399",Ct="#FB7185",et="#60A5FA",Et="#6B7280",dn="#E6C068",St="#FB7185",xn="#34D399";function Ut(t){if(/^\d{4}-\d{2}-\d{2}$/.test(t))return t;const s=/([+-])(\d\d):(\d\d)$/.exec(t),n=s?(s[1]==="-"?-1:1)*(Number(s[2])*3600+Number(s[3])*60):0,r=Date.parse(t);return Number.isNaN(r)?t.slice(0,10):Math.floor(r/1e3)+n}function Oe(t,s){if(!s||!t.length)return null;if(/^\d{4}-\d{2}-\d{2}$/.test(t[0].t)){const c=s.slice(0,10);let b=null;for(const u of t)if(u.t.slice(0,10)<=c)b=u.t.slice(0,10);else break;return b}const r=Date.parse(s);if(Number.isNaN(r))return null;let l=null;for(const c of t){const b=Date.parse(c.t);if(!Number.isNaN(b))if(b<=r)l=Ut(c.t);else break}return l}function un({trade:t,emptyLabel:s,config:n}){const r=h.useRef(null),l=h.useRef(null),c=t.snapshot??null,b=(n.chart?.timeframes??[]).join(","),u=h.useMemo(()=>b?b.split(","):[],[b]),m=h.useMemo(()=>Lt(c,u),[c,u]),v=h.useMemo(()=>xs(c,u),[c,u]),[_,o]=h.useState(null);h.useEffect(()=>o(null),[t.id]);const N=_&&m.includes(_)?_:v,x=h.useMemo(()=>ds(c,N),[c,N]);if(h.useEffect(()=>{const a=r.current;if(!a||!x.length)return;const k=Mt(a,{layout:{background:{type:Ft.Solid,color:"transparent"},textColor:"#64748B",fontSize:11},grid:{vertLines:{color:"rgba(255,255,255,0.035)"},horzLines:{color:"rgba(255,255,255,0.035)"}},crosshair:{mode:Dt.Normal},rightPriceScale:{borderColor:"rgba(255,255,255,0.08)"},timeScale:{borderColor:"rgba(255,255,255,0.08)",timeVisible:!/^\d{4}-\d{2}-\d{2}$/.test(x[0].t),rightOffset:12},handleScroll:!0,handleScale:!0,autoSize:!0});l.current=k;const M=k.addSeries(Gt,{upColor:At,downColor:Ct,wickUpColor:At,wickDownColor:Ct,borderVisible:!1,priceLineVisible:!1,lastValueVisible:!1});M.setData(x.map(p=>({time:Ut(p.t),open:p.o,high:p.h,low:p.l,close:p.c})));const B=(p,g,E,C)=>
4{p!=null&&M.createPriceLine({price:p,color:E,lineWidth:1,lineStyle:C,axisLabelVisible:!0,title:g})},$=t.outcome??{},D=$.position??null,A=t.entered_at!=null&&t.entry_price!=null;!A&&t.order_type==="limit"&&B(t.limit_price,"limit",Et,ye.Dashed),A&&B(t.entry_price,"entry",et,ye.Solid),B(D?.stop??t.stop,"stop",St,ye.Dashed),Tt(t.plan?.targets,D?.targets??void 0).forEach((p,g)=>B(p.price,`T${g+1}`,xn,ye.Dashed));const f=[];if(A){const p=Oe(x,t.entered_at);p&&f.push({time:p,position:"belowBar",color:et,shape:"arrowUp",text:"entry"})}if(t.status==="no_fill"){const p=Oe(x,$.exit?.at??t.valid_until);p&&f.push({time:p,position:"aboveBar",color:Et,shape:"circle",text:"no fill"})}const w=A?Oe(x,$.exit?.at):null;if(w){const p=$.exit?.reason==="stop";f.push({time:w,position:"aboveBar",color:p?St:et,shape:"arrowDown",text:p?"stopped":"exit"})}for(const p of D?.fills??[]){const g=Oe(x,p.at);g&&g!==w&&f.push({time:g,position:"aboveBar",color:dn,shape:"circle",text:`${p.pct}% off`})}f.sort((p,g)=>p.time>g.time?1:-1),f.length&&Jt(M,f),k.timeScale().fitContent();const d=new ResizeObserver(()=>{try{k.timeScale().fitContent()}catch{}});return d.observe(a),()=>{d.disconnect();try{k.remove()}catch{}l.current=null}},[x,t]),!x.length)return e.jsx("div",{className:"flex h-[300px] items-center justify-center rounded-lg border border-slate-800 bg-[#12121A] text-[13px] text-slate-600",children:s});const j=n.chart?.timeframe_labels??{};return e.jsxs("div",{className:"relative",children:[m.length>1&&e.jsx("div",{className:"absolute left-2 top-2 z-10 flex flex-wrap items-center gap-1",children:m.map(a=>{const k=a===N;return e.jsx("button",{type:"button","aria-pressed":k,onClick:()=>o(a),className:`rounded-full border px-2.5 py-0.5 text-[12.5px] leading-[18px] transition ${k?"border-[#A78BFA] bg-[#7C3AED]/15 text-[#A78BFA]":"border-slate-800 bg-[#12121A]/80 text-slate-500 hover:border-slate-600 hover:text-slate-300"}`,children:j[a]??a},a)})}),e.jsx("div",{ref:r,className:"h-[340px] w-full overflow-hidden rounded-lg border border-slate-800 bg-[#12121A]"})]})}function G({label:t,children:s}){return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"flex min-h-[30px] items-center text-[14px] text-slate-500",children:t}),e.jsx("div",{className:"flex min-h-[30px] flex-wrap items-center gap-2 text-[13.5px] text-slate-200",children:s})]})}function pe({label:t}){return e.jsx("span",{className:"text-slate-600",children:t})}function q({children:t}){return e.jsx("span",{className:"text-[13px] text-slate-600",children:t})}function pn(t,s){if(t.kind==="stop_moved")return`â ${T(t.to_price)}`;if(t.kind==="targets_set")return(t.targets??[]).map(n=>`${T(n.price)} Ã${n.take_pct}%`).join(", ");if(t.kind==="alert_set"){const n=st(t.alerts?.time,t.alerts?.above,t.alerts?.below,s.timezone.tz,s.peek.alert_time_label);return n.length?n.join(" · "):s.peek.empty_value}return t.kind==="order_set"?zt(t.order_type,t.limit_price,s.peek.order_labels):t.price!=null?`${T(t.price)}${t.pct!=null?` à ${Bt(t.pct)}`:""}`:""}function mn({detail:t,loading:s,error:n,runs:r,config:l,onClose:c,onOpenRun:b}){const[u,m]=h.useState(!1),[v,_]=h.useState(!1),o=l.timezone.tz,N=l.timezone.label,x=l.peek,j=e.jsx("div",{className:"sticky top-0 z-10 flex gap-1 bg-[#0E0E16]/95 px-2.5 py-2 backdrop-blur",children:e.jsx("button",{type:"button",onClick:c,title:x.close_label,"aria-label":x.close_label,className:"rounded p-1 text-slate-500 hover:bg-slate-800 hover:text-slate-200",children:e.jsx(gs,{className:"h-4 w-4 fill-none stroke-current"})})});if(s||n||!t)return e.jsxs("div",{className:"h-full overflow-y-auto",children:[j,e.jsx("p",{className:"px-6 py-10 text-[14px] text-slate-600 text-[15px] leading-[1.65] max-w-[72ch]",children:n?l.empty_states.load_failed:l.empty_states.loading})]});const a=t.trade,k=a.outcome??{},M=k.position??null,B=a.plan??{},$=a.reasoning??{},D=Tt(B.targets,M?.targets??void 0),A=D[0],i=we(a.status,l),f=r.find(g=>g.id===a.run_id)??null,w=M?.stop??a.stop,d=(t?.events??[]).filter(g=>g.kind==="stop_moved"&&g.to_price!=null).sort((g,E)=>g.at<E.at?-1:1),p=typeof B.size=="string"?B.size:null;return e.jsxs("div",{className:"h-full overflow-y-auto",children:[j,e.jsxs("div",{className:"px-6 pb-20 pt-2 md:px-12",children:[e.jsxs("h2",{className:"mb-3.5 mt-5 text-[28px] font-bold tracking-tight text-white",children:[a.symbol," ",e.jsx("span",{className:"font-normal text-slate-500",children:te(De(a),o)})]}),e.jsxs("div",{className:"grid grid-cols-[110px_1fr] gap-y-0.5 md:grid-cols-[170px_1fr]",children:[e.jsx(G,{label:x.props.id,children:e.jsx(L,{className:"text-slate-300",title:a.id,children:ot(a.id)})}),a.grade&&e.jsx(G,{label:x.props.grade,children:e.jsx(ne,{tone:Me[a.grade],children:a.grade})}),e.jsxs(G,{label:x.props.status,children:[i?e.jsx(ne,{children:i}):e.jsx(pe,{label:x.empty_value}),M?.remaining_pct!=null&&M.remaining_pct>0&&M.remaining_pct<100&&e.jsxs(q,{children:[M.remaining_pct,"% ",x.remaining_label]})]}),e.jsx(G,{label:x.props.result,children:a.r!=null||a.pct!=null?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:(a.r??a.pct??0)>=0?ie:oe,children:a.r!=null?Y(a.r):ae(a.pct)}),a.r!=null&&a.pct!=null&&e.jsx(q,{children:ae(a.pct)})]}):k.mark?.price!=null?e.jsxs(e.Fragment,{children:[k.unrealized&&(k.unrealized.r??k.unrealized.pct)!=null&&e.jsxs(e.Fragment,{children:[e.jsx(it,{u:k.unrealized,title:x.unrealized_label}),k.unrealized.r!=null&&k.unrealized.pct!=null&&e.jsx(q,{children:ae(k.unrealized.pct)}),e.jsx(q,{children:x.unrealized_label})]}),e.jsx(L,{children:T(k.mark.price)}),e.jsxs(q,{children:[x.mark_label," ",te(k.mark.at,o)]})]}):e.jsx(pe,{label:x.empty_value})}),e.jsx(G,{label:x.props.entry,children:a.entered_at!=null?e.jsxs(e.Fragment,{children:[e.jsx(L,{children:T(a.entry_price)}),e.jsx(q,{children:te(a.entered_at,o)})]}):e.jsx(q,{children:zt(a.order_type,a.limit_price,x.order_labels)})}),e.jsx(G,{label:x.props.stop,children:w==null?e.jsx(pe,{label:x.empty_value}):e.jsxs(e.Fragment,{children:[e.jsx(L,{children:T(w)}),d.length>0&&e.jsxs("button",{type:"button",onClick:()=>_(g=>
4!g),"aria-expanded":v,className:"ml-2 rounded-full border border-slate-800 px-2.5 py-0.5 text-[12.5px] text-slate-400 hover:border-slate-600 hover:text-slate-200",children:[X(x.stop_history_toggle,{n:d.length})," â¾"]})]})}),e.jsx(G,{label:x.props.targets,children:D.length?e.jsxs(e.Fragment,{children:[e.jsxs("button",{type:"button",onClick:()=>m(g=>!g),"aria-expanded":u,className:"rounded-full border border-slate-800 px-2.5 py-0.5 text-[12.5px] text-slate-400 hover:border-slate-600 hover:text-slate-200",children:[D.length===1?x.targets_toggle_one:X(x.targets_toggle_many,{n:D.length})," ","â¾"]}),A&&e.jsxs(q,{children:[T(A.price),Ve(We(a),w,A.price)!=null&&` · ${Ve(We(a),w,A.price).toFixed(1)}R`]})]}):e.jsx(pe,{label:x.empty_value})}),e.jsx(G,{label:x.props.alerts,children:a.alert_time==null&&a.alert_above==null&&a.alert_below==null?e.jsx(pe,{label:x.empty_value}):e.jsxs("div",{className:"flex w-full flex-col gap-0.5 py-1",children:[a.alert_time!=null&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(q,{children:x.alert_time_label}),e.jsx(L,{className:"text-slate-300",children:ke(a.alert_time,o)??Q}),e.jsx(q,{children:N})]}),a.alert_above!=null&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(q,{children:x.alert_above_label}),e.jsx(L,{children:T(a.alert_above)})]}),a.alert_below!=null&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(q,{children:x.alert_below_label}),e.jsx(L,{children:T(a.alert_below)})]})]})}),e.jsx(G,{label:x.props.session,children:a.session_id?e.jsx(L,{className:"select-all text-slate-300",children:a.session_id}):e.jsx(pe,{label:x.empty_value})}),e.jsx(G,{label:x.props.exit,children:k.exit?.price==null?e.jsx(pe,{label:x.empty_value}):e.jsxs(e.Fragment,{children:[e.jsx(L,{children:T(k.exit.price)}),e.jsxs(q,{children:[k.exit.at?`${te(k.exit.at,o)} · `:"",l.exit_reasons[k.exit.reason??""]??k.exit.reason??""]})]})}),p&&e.jsxs(G,{label:x.props.size,children:[e.jsx(L,{children:l.size_labels?.[p]??p}),e.jsx(q,{children:x.size_sub})]}),e.jsxs(G,{label:x.props.decided,children:[e.jsx(L,{className:"text-slate-300",children:ke(a.decided_at,o)??Q}),e.jsx(q,{children:N})]}),e.jsx(G,{label:x.props.journal,children:f?e.jsx("button",{type:"button",onClick:()=>b(f.id),className:"font-mono text-[14px] text-[#A78BFA] underline-offset-2 hover:underline",children:f.name}):e.jsx(pe,{label:x.empty_value})})]}),v&&d.length>0&&e.jsxs("div",{className:"mt-2 overflow-hidden rounded-lg border border-slate-800 text-[12.5px]",children:[e.jsxs("div",{className:"flex items-center gap-3 px-2.5 py-1.5 text-slate-500",children:[e.jsx(L,{className:"w-20 text-slate-500",children:T(a.stop)}),e.jsx("span",{children:x.stop_initial}),e.jsx("span",{className:"font-mono text-slate-600",children:te(De(a),o)})]}),d.map((g,E)=>{const C=E===d.length-1,F=r.find(R=>R.id===g.run_id)??null;return e.jsxs("div",{className:`flex items-center gap-3 border-t border-slate-800 px-2.5 py-1.5 ${C?"text-slate-200":"text-slate-500"}`,children:[e.jsx(L,{className:`w-20 ${C?"text-slate-100":"text-slate-500"}`,children:T(g.to_price)}),e.jsx("span",{children:x.stop_moved}),e.jsx("span",{className:"font-mono text-slate-600",children:Se(g.at,o)}),F&&e.jsx("button",{type:"button",onClick:()=>b(F.id),className:"font-mono text-[#A78BFA] underline-offset-2 hover:underline",children:F.name}),g.note&&e.jsxs("span",{className:"text-slate-500",children:["· ",g.note]})]},g.id)})]}),u&&!!D.length&&e.jsx("div",{className:"mt-2 overflow-hidden rounded-lg border border-slate-800 text-[12.5px]",children:D.map((g,E)=>{const C=Ve(We(a),w,g.price),F=M?.rung!=null&&E<M.rung,R=!F&&M?.next_target!=null&&M.next_target.price===g.price,S=F?M?.fills?.[E]??null:null,z=S?S.source==="journal"?x.ladder.fill_journal:x.ladder.fill_auto:"";return e.jsxs("div",{className:`flex flex-wrap items-center gap-x-3 gap-y-0.5 ${E?"border-t border-slate-800":""} px-2.5 py-1.5 ${R?"text-slate-200":F?"text-slate-500":"text-slate-400"}`,children:[e.jsx("span",{className:"w-4 text-slate-600",children:E+1}),e.jsx(L,{className:`w-20 ${R?"text-slate-100":""}`,children:T(g.price)}),e.jsxs("span",{children:[x.ladder.take," ",g.take_pct,"%"]}),e.jsx("span",{className:"font-mono",children:C!=null?`${C.toFixed(2)}R`:Q}),F&&S?e.jsxs("span",{className:"text-slate-500",children:[x.ladder.filled," ",T(S.price)," · ",te(S.at,o)," · ",z]}):R?e.jsx("span",{className:"text-emerald-400",children:x.ladder.next}):e.jsx("span",{className:"text-slate-600",children:x.ladder.waiting})]},`${g.price}-${E}`)})}),e.jsx("hr",{className:"my-5 border-slate-800"}),!!$.why?.length&&e.jsxs(e.Fragment,{children:[e.jsx("h3",{className:"mb-2 mt-5 text-[18px] font-semibold text-white",children:x.sections.why}
4),e.jsx("ul",{className:"list-disc space-y-1.5 pl-5 text-[13.5px] leading-relaxed text-slate-300 text-[15px] leading-[1.65] max-w-[72ch]",children:$.why.map((g,E)=>e.jsx("li",{children:g},E))})]}),$.conclusion&&e.jsxs(e.Fragment,{children:[e.jsx("h3",{className:"mb-2 mt-5 text-[18px] font-semibold text-white",children:x.sections.conclusion}),e.jsx("p",{className:"text-[13.5px] leading-relaxed text-slate-300",children:$.conclusion})]}),e.jsx("hr",{className:"my-5 border-slate-800"}),e.jsx("h3",{className:"mb-2 mt-5 text-[18px] font-semibold text-white",children:x.sections.chart}),e.jsx(un,{trade:a,emptyLabel:x.chart_empty,config:l}),e.jsxs("p",{className:"mt-2 text-[13px] text-slate-600",children:[B.basis??$.basis??"",B.void?.length?` · void â ${B.void.join("; ")}`:"",B.basis||$.basis||B.void?.length?" · ":"","times in ",N]}),e.jsx("hr",{className:"my-5 border-slate-800"}),e.jsxs("h3",{className:"mb-2 mt-5 text-[18px] font-semibold text-white",children:[x.sections.journal,!!t.events.length&&e.jsx("span",{className:"ml-2 text-[13px] font-normal text-slate-500",children:t.events.length})]}),t.events.length?e.jsx("div",{className:"space-y-1",children:[...t.events].sort((g,E)=>g.at<E.at?-1:1).map(g=>{const E=r.find(C=>C.id===g.run_id)??null;return e.jsxs("div",{className:"grid grid-cols-[14px_1fr] gap-2.5 py-1",children:[e.jsx("div",{className:"mt-[7px] h-2 w-2 rounded-full bg-slate-600"}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("span",{className:"font-mono text-[13px] text-slate-500",children:Se(g.at,o)}),e.jsx(ne,{children:l.event_kinds[g.kind]??g.kind}),e.jsx(L,{className:"text-[14px] text-slate-200",children:pn(g,l)}),g.reason&&e.jsxs("span",{className:"text-[12.5px] text-slate-500",children:["· ",g.reason]}),E&&e.jsx("button",{type:"button",onClick:()=>b(E.id),className:"font-mono text-[13px] text-[#A78BFA] underline-offset-2 hover:underline",children:E.name})]}),g.note&&e.jsx("p",{className:"mt-0.5 whitespace-pre-line text-[12.5px] leading-relaxed text-slate-400",children:g.note})]})]},g.id)})}):e.jsx("p",{className:"text-[14px] leading-relaxed text-slate-600",children:x.journal_empty})]})]})}function hn(){const[t,s]=h.useState(()=>typeof window>"u"?1400:window.innerWidth);return h.useEffect(()=>{const n=()=>s(window.innerWidth);return window.addEventListener("resize",n),()=>window.removeEventListener("resize",n)},[]),t<768?"100%":t<1100?"72%":"62%"}function jn({token:t}){const{config:s,error:n,loading:r}=Qt(),[l,c]=h.useState(Ee),[b,u]=h.useState(!1),[m,v]=h.useState({kind:"home"}),[_,o]=h.useState(null),[N,x]=h.useState(new Map),[j,a]=h.useState(null),[k,M]=h.useState(null),[B,$]=h.useState(null),[D,A]=h.useState(null),i=hn(),f=h.useRef(null),w=!1;h.useEffect(()=>{ve("alpha_agents_opened","alpha-agents")},[]);const d=h.useRef(void 0),[p,g]=h.useState(null),E=h.useCallback(async()=>{const y=await Zt(t,d.current);if(y.error){d.current||c(y);return}y.unchanged||(d.current=y.etag,c({agents:y.agents,trades:y.trades,runs:y.runs})),g(new Date)},[t,w]);h.useEffect(()=>{let y=!1;return u(!1),d.current=void 0,E().then(()=>{y||u(!0)}),()=>{y=!0}},[E]);const C=m.kind+":"+("agentId"in m?m.agentId??"":"")+":"+("runId"in m?m.runId:""),F=h.useRef(!0);h.useEffect(()=>{if(F.current){F.current=!1;return}E()},[C,E]);const R=l.runs.some(y=>y.status==="started"),S=s?.progress.poll_seconds??20;h.useEffect(()=>{if(!R||!S)return;const y=window.setInterval(()=>{document.visibilityState==="visible"&&E()},S*1e3);return()=>window.clearInterval(y)},[R,S,E]),h.useEffect(()=>{const y=()=>{document.visibilityState==="visible"&&E()};return document.addEventListener("visibilitychange",y),window.addEventListener("focus",y),()=>{document.removeEventListener("visibilitychange",y),window.removeEventListener("focus",y)}},[E]),h.useEffect(()=>{if(!_){a(null),M(null);return}let y=!1;return a(null),M(null),(async()=>{const I=await es(t,_);if(!y){if("error"in I){M(I.error);return}a(I),x(V=>new Map(V).set(I.trade.id,I.trade))}})(),()=>{y=!0}},[_,t,w]),h.useEffect(()=>{if(m.kind!=="run")return;let y=!1;$(null),A(null);const I=m.runId;return(async()=>{const V=await ts(t,I);if(!y){if("error"in V){A(V.error);return}$(V)}})(),()=>{y=!0}},[m,t,w]);const z=h.useCallback((y,I)=>{c(V=>({...V,agents:V.agents.map(H=>H.id===y?{...H,...I}:H)}))},[]),J=h.useCallback(async(y,I,V)=>{z(y,I);const H=await ns(t,y,I);return"error"in H?(z(y,V),{error:H.error,missing:H.missing}):(z(y,H.agent),ve("alpha_agents_agent_saved",Object.keys(I).join(",")),null)},[z,t,w]),O=h.useCallback(async y=>{const I=l.agents.find(H=>H.id===y)?.run_requested_at??null;z(y,{run_requested_at:new Date().toISOString()});const V=await rs(t,y);return"error"in V?(z(y,{run_requested_at:I}),{error:V.error,message:V.message}):(z(y,V.agent),ve("alpha_agents_run_requested",y),null)},[z,l.agents,t,w]),W=h.useCallback(async y=>{const I=await ss(t,y);return"error"in I?null:I.documents},[t,w]),re=h.useRef(null),Ne=h.useCallback(()=>{const y=re.current;y&&(y.dataset.more=y.scrollWidth-y.clientWidth-y.scrollLeft>8?"true":"false")},[]);h.useEffect(()=>{const y=re.current;if(!y)return;Ne();const I=new ResizeObserver(Ne);return I.observe(y),()=>I.disconnect()});const fe=h.useCallback(()=>o(null),[]),ut=h.useCallback(y=>{o(y),ve("alpha_agents_trade_opened",y)},[]),He=h.useCallback(y=>{const I=l.runs.find(V=>V.id===y)??null;o(null),v({kind:"run",runId:y,agentId:I?.agent_id??null}),ve("alpha_agents_run_opened",y)},[l.runs]);h.useEffect(()=>{if(!_)return;const y=V=>{V.key==="Escape"&&fe()},I=V=>{const H=V.target;f.current?.contains(H)||H.closest("tr, a, button, input, label, [data-filter-chip]")||fe()};return document.addEventListener("keydown",y),document.addEventListener("dblclick",I),()=>{document.removeEventListener("keydown",y),document.removeEventListener("dblclick",I)}},[_,fe]);const Kt=h.useMemo(()=>{const y=new Map;for(const I of l.trades)y.set(I.agent_id,(y.get(I.agent_id)??0)+1);return y},[l.trades]),Ge=m.kind==="agent"||m.kind==="run"?m.agentId:null,ce=l.agents.find(y=>y.id===Ge)??null;if(r||!b)return e.jsx(qe,{label:"Loadingâ¦"});if(n||!s)return e.jsx(qe,{label:n??"Could not load the tracker."});if(l.error&&l.error!=="no_session")return e.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-[#0B0B12] px-6",children:e.jsxs("div",{className:"max-w-sm text-center",children:[e.jsx("p",{className:"text-[13.5px] leading-relaxed text-slate-400",children:s.empty_states.load_failed}),e.jsx("button",{type:"button",onClick:()=>window.location.reload(),className:"mt-4 rounded-lg px-4 py-2.5 text-[13.5px] font-bold text-white",style:{background:Fe},children:"Refresh"})]})});if(l.error==="no_session"&&!w)return e.jsx(qe,{label:s.empty_states.signed_out});const xe=_!=null,Je=y=>`flex w-full items-center gap-2 rounded-lg px-2.5 py-1.5 text-left text-[13px] transition ${y?"bg-[#7C3AED]/15 text-[#C4B5FD]":"text-slate-300 hover:bg-slate-800/50"}`,Ie=[{text:s.section.title,go:()=>v({kind:"home"})}];return ce&&Ie.push({text:ce.name,go:()=>v({kind:"agent",agentId:ce.id,tab:"trades"})}),m.kind==="run"&&Ie.push({text:B?.run.name??"â¦"}),m.kind==="keys"&&Ie.push({text:s.keys.title}),e.jsxs("div",{className:"aa-surface absolute inset-0 flex bg-[#0B0B12]",children:[e.jsx("aside",{"aria-label":s.section.title,className:"hidden shrink-0 flex-col overflow-hidden border-slate-800 bg-[#0E0E16] md:flex",style:{width:xe?
40:270,borderRightWidth:xe?0:1,transition:`width ${_e}, border-right-width ${_e}`},children:e.jsxs("div",{className:"flex w-[270px] min-w-[270px] flex-1 flex-col overflow-hidden",children:[e.jsxs("nav",{className:"flex-1 overflow-y-auto p-2",children:[e.jsxs("button",{type:"button",onClick:()=>v({kind:"home"}),className:Je(m.kind==="home"),children:[e.jsx(fs,{className:"h-3.5 w-3.5 shrink-0 fill-none stroke-current text-slate-500"}),s.section.home_label]}),e.jsx("p",{className:"mb-1 ml-2.5 mt-3.5 text-[11.5px] uppercase tracking-wide text-slate-500",children:s.section.agents_label}),l.agents.map(y=>e.jsxs("button",{type:"button",onClick:()=>v({kind:"agent",agentId:y.id,tab:"trades"}),className:Je(Ge===y.id),children:[e.jsx(bs,{className:"h-3.5 w-3.5 shrink-0 fill-none stroke-current text-slate-500"}),e.jsx("span",{className:"truncate",children:y.name}),e.jsx("span",{className:"ml-auto text-[11.5px] text-slate-600",children:Kt.get(y.id)??0})]},y.id)),!l.agents.length&&e.jsx("p",{className:"px-2.5 py-2 text-[12px] leading-relaxed text-slate-600",children:s.empty_states.no_agents})]}),e.jsxs("div",{className:"border-t border-slate-800 p-2",children:[e.jsxs("button",{type:"button",onClick:()=>v({kind:"keys"}),className:Je(m.kind==="keys"),children:[e.jsx(js,{className:"h-3.5 w-3.5 shrink-0 fill-none stroke-current text-slate-500"}),s.keys.rail_label]}),p&&e.jsx("button",{type:"button",onClick:()=>{E()},title:s.section.refresh_title,className:"mt-1 w-full px-2 py-1 text-left font-mono text-[11px] text-slate-600 hover:text-slate-400",children:X(s.section.updated_label,{time:p.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})})})]})]})}),e.jsxs("main",{className:"min-w-0 flex-1 overflow-y-auto",style:{overscrollBehavior:"contain"},children:[e.jsx("div",{className:"sticky top-0 z-20 flex items-center gap-1.5 bg-[#0B0B12]/90 px-4 py-2 text-[12px] text-slate-500 backdrop-blur md:px-8",children:Ie.map((y,I)=>e.jsxs("span",{className:"flex items-center gap-1.5",children:[I>0&&e.jsx("span",{className:"text-slate-700",children:"/"}
4),y.go?e.jsx("button",{type:"button",onClick:y.go,className:"uppercase hover:text-slate-300",children:y.text}):e.jsx("span",{className:"uppercase",children:y.text})]},I))}),e.jsxs("div",{className:"px-4 pb-24 md:px-8 lg:px-14",children:[e.jsx("div",{ref:re,onScroll:Ne,"data-more":"false",className:"aa-nav mb-2 flex gap-2 overflow-x-auto pt-2 md:hidden",children:[{id:"home",label:s.section.home_label,on:m.kind==="home",go:()=>v({kind:"home"})},...l.agents.map(y=>({id:y.id,label:y.name,on:Ge===y.id,go:()=>v({kind:"agent",agentId:y.id,tab:"trades"})})),{id:"keys",label:s.keys.rail_label,on:m.kind==="keys",go:()=>v({kind:"keys"})}].map(y=>e.jsx("button",{type:"button",onClick:y.go,className:`shrink-0 rounded-full border px-3.5 py-2 text-[12px] font-bold ${y.on?"border-[#7C3AED] bg-[#7C3AED]/15 text-[#A78BFA]":"border-slate-800 text-slate-400"}`,children:y.label},y.id))}),m.kind==="home"&&e.jsx(ln,{agents:l.agents,trades:l.trades,runs:l.runs,config:s,onOpenAgent:y=>v({kind:"agent",agentId:y,tab:"trades"}),onSaveAgent:J,onRequestRun:O,onOpenRun:He}),m.kind==="agent"&&(ce?e.jsx(Ms,{agent:ce,trades:l.trades,runs:l.runs,details:N,config:s,tab:m.tab,onTab:y=>v({kind:"agent",agentId:ce.id,tab:y}),selectedTradeId:_,onOpenTrade:ut,onOpenRun:He,loadDocuments:W,onRequestRun:O}):e.jsx("p",{className:"py-10 text-[13px] text-slate-600",children:s.empty_states.no_agents})),m.kind==="run"&&e.jsx(cn,{detail:B,loading:!B&&!D,error:D,trades:l.trades,config:s,agentName:ce?.name??"",onOpenTrade:ut,onBack:()=>v(ce?{kind:"agent",agentId:ce.id,tab:"journal"}:{kind:"home"})}),m.kind==="keys"&&e.jsx(an,{token:t,config:s})]})]}),e.jsx("aside",{ref:f,"aria-label":"Trade detail","aria-hidden":!xe,className:"shrink-0 overflow-hidden border-slate-800 bg-[#0E0E16]",style:{width:xe?i:0,borderLeftWidth:xe?1:0,transition:`width ${_e}, border-left-width ${_e}`},children:e.jsx("div",{className:"h-full",style:{transform:xe?"none":"translateX(24px)",opacity:xe?1:0,transition:`transform ${_e}, opacity ${_e}`},children:xe&&e.jsx(mn,{detail:j,loading:!j&&!k,error:k,runs:l.runs,config:s,onClose:fe,onOpenRun:He})})})]})}export{jn as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.