hypervibes 0.4.0-beta → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/.build/client/assets/{_authenticated-Cv9zLaQf.js → _authenticated-C87LKvH0.js} +1 -1
  2. package/.build/client/assets/{_authenticated.account-BUQIEX6U.js → _authenticated.account-D-nTh_fC.js} +1 -1
  3. package/.build/client/assets/_authenticated.agents-HwcveLyB.js +1 -0
  4. package/.build/client/assets/{_authenticated.agents._agentId-M6WEcZ08.js → _authenticated.agents._agentId-DuE8Lv62.js} +1 -1
  5. package/.build/client/assets/{_authenticated.agents._agentId.chart-C7d7IrdC.js → _authenticated.agents._agentId.chart-Bb_XkvQx.js} +1 -1
  6. package/.build/client/assets/{_authenticated.agents._agentId.chat-ByZuIqSb.js → _authenticated.agents._agentId.chat-ClMMKw_N.js} +1 -1
  7. package/.build/client/assets/{_authenticated.agents._agentId.index-BWIZd3vd.js → _authenticated.agents._agentId.index-DNJwBwn9.js} +1 -1
  8. package/.build/client/assets/{_authenticated.agents._agentId.indicators-CjCgrxqH.js → _authenticated.agents._agentId.indicators-BmVjLtRI.js} +1 -1
  9. package/.build/client/assets/{_authenticated.agents._agentId.indicators_._indicatorId-B45wotiz.js → _authenticated.agents._agentId.indicators_._indicatorId-CMqaaFQf.js} +2 -2
  10. package/.build/client/assets/{_authenticated.agents._agentId.indicators_._indicatorId-Beoq1vKK.js → _authenticated.agents._agentId.indicators_._indicatorId-DtgkoNV5.js} +1 -1
  11. package/.build/client/assets/{_authenticated.agents._agentId.memories-BmofNWcJ.js → _authenticated.agents._agentId.memories-O-4f6a4G.js} +1 -1
  12. package/.build/client/assets/{_authenticated.agents._agentId.memories_._memoryRef-CGnpq7sv.js → _authenticated.agents._agentId.memories_._memoryRef-BUPtUcj3.js} +1 -1
  13. package/.build/client/assets/{_authenticated.agents._agentId.notifications-Z1TVoGbh.js → _authenticated.agents._agentId.notifications-2lyhXCSk.js} +1 -1
  14. package/.build/client/assets/{_authenticated.agents._agentId.notifications_._notificationId-BU2I1Fui.js → _authenticated.agents._agentId.notifications_._notificationId-Da3ZVT4v.js} +1 -1
  15. package/.build/client/assets/{_authenticated.agents._agentId.settings-CUai-n8m.js → _authenticated.agents._agentId.settings-C5cWHoYw.js} +1 -1
  16. package/.build/client/assets/_authenticated.agents._agentId.sub-agents-HwcveLyB.js +1 -0
  17. package/.build/client/assets/{_authenticated.agents._agentId.sub-agents._subagentId-CEYRqW8Q.js → _authenticated.agents._agentId.sub-agents._subagentId-CZ4MeRy4.js} +1 -1
  18. package/.build/client/assets/{_authenticated.agents._agentId.sub-agents._subagentId_.runs._runId-Cr7yrAJz.js → _authenticated.agents._agentId.sub-agents._subagentId_.runs._runId-dVbo5kMU.js} +1 -1
  19. package/.build/client/assets/{_authenticated.agents._agentId.sub-agents.index-xTEjRPdW.js → _authenticated.agents._agentId.sub-agents.index-DeWTOYJD.js} +1 -1
  20. package/.build/client/assets/{_authenticated.agents._agentId.sub-agents.new-B9ZR8zIn.js → _authenticated.agents._agentId.sub-agents.new-D02TflCE.js} +1 -1
  21. package/.build/client/assets/{_authenticated.agents._agentId.transactions-a1xzSbFO.js → _authenticated.agents._agentId.transactions-D3a8Glgj.js} +1 -1
  22. package/.build/client/assets/{_authenticated.agents.new-COOjMCtg.js → _authenticated.agents.new-DLRWK5Uk.js} +1 -1
  23. package/.build/client/assets/{_authenticated.providers-8wsMG9f-.js → _authenticated.providers-D0iPLXra.js} +1 -1
  24. package/.build/client/assets/{agent-chat-page-vKrkXdzr.js → agent-chat-page-C5eYFgxw.js} +1 -1
  25. package/.build/client/assets/{agent-enablement-control-BMJ6jULr.js → agent-enablement-control-CUzOp9ce.js} +1 -1
  26. package/.build/client/assets/app-DjmsvbUC.css +2 -0
  27. package/.build/client/assets/{index-fu66g8fn.js → index-B4hvjMmI.js} +3 -3
  28. package/.build/client/assets/{useMutation-Dni_73Pp.js → useMutation-DrF53EQG.js} +1 -1
  29. package/.build/server/assets/{_tanstack-start-manifest_v-BAHfxLOo.js → _tanstack-start-manifest_v-Baw5u9sk.js} +54 -54
  30. package/.build/server/assets/{router-CpYyLRfb.js → router-Hkr5TH_I.js} +1 -1
  31. package/.build/server/server.js +2 -2
  32. package/README.md +9 -11
  33. package/dist/agents/agent-service.js +2 -0
  34. package/dist/agents/run-inspection.js +7 -5
  35. package/dist/agents/subagent-extension.js +3 -2
  36. package/dist/agents/subagent-service.js +2 -1
  37. package/dist/agents/time-guidance.js +29 -0
  38. package/dist/indicators/result-schema.js +14 -11
  39. package/dist/research/contracts.js +18 -14
  40. package/dist/research/research-service.js +1 -1
  41. package/package.json +27 -24
  42. package/.build/client/assets/_authenticated.agents-dJY4sHg9.js +0 -1
  43. package/.build/client/assets/_authenticated.agents._agentId.sub-agents-dJY4sHg9.js +0 -1
  44. package/.build/client/assets/app-DcRTuyby.css +0 -2
@@ -1 +1 @@
1
- import{f as e,l as t,t as n}from"./jsx-runtime-CIazjfqY.js";import{i as r,o as i}from"./lazyRouteComponent-CJgUa7_r.js";import{t as a}from"./useSuspenseQuery-vODFwDb8.js";import{a as o}from"./agent-queries-CNMBImun.js";import{A as s,M as c}from"./index-fu66g8fn.js";import{t as l}from"./identicon-Lb9pS4O1.js";import{t as u}from"./agent-enablement-control-BMJ6jULr.js";import{t as d}from"./auth-client-K13li9H1.js";var f=e(t(),1),p=n();function m({agentEnabled:e,tradingEnabled:t}){let n=e&&t,r=e?t?`Trading enabled`:`Trading disabled`:`Agent disabled`;return(0,p.jsx)(`span`,{role:`img`,"aria-label":r,title:r,className:`h-2 w-2 shrink-0 rounded-full ${n?`bg-emerald-400`:`bg-amber-400`}`})}function h({agents:e,selectedAgentId:t}){let n=(0,f.useRef)(null),i=(0,f.useRef)(null),a=e.find(e=>e.id===t);function o(){n.current&&(n.current.open=!1)}return(0,f.useEffect)(()=>{o()},[t]),(0,f.useEffect)(()=>{let e=e=>{n.current?.contains(e.target)||o()},t=e=>{e.key===`Escape`&&n.current?.open&&(o(),i.current?.focus())};return document.addEventListener(`click`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`click`,e),document.removeEventListener(`keydown`,t)}},[]),(0,p.jsxs)(`details`,{ref:n,className:`relative h-full min-w-0 max-w-[45vw] sm:max-w-64`,"data-agent-selector":!0,children:[(0,p.jsxs)(`summary`,{ref:i,"aria-label":`Switch Agent`,className:`flex h-full cursor-pointer list-none items-center gap-2 px-4 text-sm text-zinc-300 hover:bg-zinc-800 hover:text-white [&::-webkit-details-marker]:hidden`,children:[a&&(0,p.jsx)(m,{agentEnabled:a.enabled,tradingEnabled:a.tradingEnabled}),(0,p.jsx)(`span`,{className:`truncate`,children:a?.name??`Agents`}),(0,p.jsx)(`svg`,{className:`h-4 w-4 shrink-0 text-zinc-500`,viewBox:`0 0 20 20`,fill:`currentColor`,"aria-hidden":`true`,children:(0,p.jsx)(`path`,{fillRule:`evenodd`,clipRule:`evenodd`,d:`M5.23 7.21a.75.75 0 0 1 1.06.02L10 11.17l3.71-3.94a.75.75 0 1 1 1.09 1.04l-4.25 4.5a.75.75 0 0 1-1.09 0l-4.25-4.5a.75.75 0 0 1 .02-1.06Z`})})]}),(0,p.jsxs)(`div`,{className:`absolute left-0 top-full mt-2 max-h-[calc(100dvh-5rem)] w-64 overflow-y-auto rounded-lg border border-zinc-700 bg-[#1b1d20] p-1 shadow-2xl`,children:[e.map(e=>(0,p.jsxs)(r,{to:`/agents/$agentId`,params:{agentId:e.id},onClick:o,"aria-current":e.id===t?`page`:void 0,className:`flex cursor-pointer items-center gap-2 rounded-md px-3 py-2 text-sm text-zinc-300 hover:bg-zinc-800 hover:text-white`,children:[(0,p.jsx)(m,{agentEnabled:e.enabled,tradingEnabled:e.tradingEnabled}),(0,p.jsx)(`span`,{className:`truncate`,children:e.name})]},e.id)),e.length>0&&(0,p.jsx)(`div`,{className:`my-1 border-t border-zinc-700`}),(0,p.jsx)(r,{to:`/agents/new`,onClick:o,className:`block cursor-pointer rounded-md px-3 py-2 text-sm font-medium text-sky-300 hover:bg-zinc-800 hover:text-sky-200`,children:`Create new agent`})]})]})}function g({walletAddress:e,agents:t=[],selectedAgentId:n}){let i=t.find(e=>e.id===n),[a,o]=(0,f.useState)(!1),[s,c]=(0,f.useState)(``),m=(0,f.useRef)(!1);async function g(){if(!m.current){m.current=!0,o(!0),c(``);try{if((await d.signOut()).error)throw Error(`Unable to log out. Please try again.`);window.location.assign(`/login`)}catch{c(`Unable to log out. Please try again.`),m.current=!1,o(!1)}}}return(0,p.jsxs)(`div`,{className:`relative flex h-full items-center pr-4`,children:[(0,p.jsx)(h,{agents:t,selectedAgentId:n}),i&&!i.tradingEnabled&&(0,p.jsx)(r,{to:`/agents/$agentId/settings`,params:{agentId:i.id},hash:`risk-management`,title:`New exposure is disabled. Reduce-only orders and cancellation remain available. Open risk management settings.`,className:`shrink-0 cursor-pointer whitespace-nowrap rounded-lg px-2 py-1 text-xs text-amber-300 hover:bg-amber-950/50 hover:text-amber-200 sm:text-sm`,children:`Trading disabled`}),(0,p.jsx)(r,{to:`/agents`,className:`absolute left-1/2 hidden h-full -translate-x-1/2 cursor-pointer items-center px-4 hover:bg-zinc-800 lg:flex`,children:(0,p.jsx)(`img`,{src:`/static/hypervibes.png`,alt:`HyperVibes`,width:`2172`,height:`724`,className:`h-12 w-auto object-contain`})}),(0,p.jsxs)(`div`,{className:`ml-auto flex items-center gap-2 sm:gap-3`,children:[i&&(0,p.jsx)(u,{id:i.id,name:i.name,enabled:i.enabled},i.id),(0,p.jsx)(r,{to:`/providers`,title:`Provider connections`,"aria-label":`Provider connections`,className:`inline-flex h-9 w-9 cursor-pointer items-center justify-center rounded-lg text-zinc-400 hover:bg-zinc-800 hover:text-white`,children:(0,p.jsx)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 24 24`,strokeWidth:`1.5`,stroke:`currentColor`,className:`size-6`,"aria-hidden":`true`,children:(0,p.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M5.25 14.25h13.5m-13.5 0a3 3 0 0 1-3-3m3 3a3 3 0 1 0 0 6h13.5a3 3 0 1 0 0-6m-16.5-3a3 3 0 0 1 3-3h13.5a3 3 0 0 1 3 3m-19.5 0a4.5 4.5 0 0 1 .9-2.7L5.737 5.1a3.375 3.375 0 0 1 2.7-1.35h7.126c1.062 0 2.062.5 2.7 1.35l2.587 3.45a4.5 4.5 0 0 1 .9 2.7m0 0a3 3 0 0 1-3 3m0 3h.008v.008h-.008v-.008Zm0-6h.008v.008h-.008v-.008Zm-3 6h.008v.008h-.008v-.008Zm0-6h.008v.008h-.008v-.008Z`})})}),(0,p.jsxs)(r,{to:`/account`,title:e,className:`flex cursor-pointer items-center gap-2 rounded-lg px-2 py-1 hover:bg-zinc-800`,children:[(0,p.jsx)(l,{address:e,className:`h-5 w-5 rounded-full`}),(0,p.jsxs)(`span`,{className:`hidden font-mono text-sm text-zinc-200 sm:inline`,children:[e.slice(0,6),`…`,e.slice(-4)]})]}),(0,p.jsx)(`button`,{type:`button`,title:`Logout`,"aria-label":`Logout`,disabled:a,onClick:()=>{g()},className:`inline-flex h-9 w-9 cursor-pointer items-center justify-center rounded-lg text-zinc-400 hover:bg-zinc-800 hover:text-white disabled:cursor-wait disabled:opacity-60`,children:(0,p.jsx)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 24 24`,strokeWidth:1.5,stroke:`currentColor`,className:`size-6`,"aria-hidden":`true`,children:(0,p.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M15.75 9V5.25A2.25 2.25 0 0 0 13.5 3h-6a2.25 2.25 0 0 0-2.25 2.25v13.5A2.25 2.25 0 0 0 7.5 21h6a2.25 2.25 0 0 0 2.25-2.25V15m3 0 3-3m0 0-3-3m3 3H9`})})}),a&&s&&(0,p.jsx)(`span`,{role:`alert`,className:`text-xs text-red-300`,children:s}),(0,p.jsx)(`a`,{href:`https://github.com/idft/hypervibes`,target:`_blank`,rel:`noopener noreferrer`,"aria-label":`HyperVibes on GitHub`,className:`hidden h-9 w-9 cursor-pointer items-center justify-center rounded-lg text-zinc-400 hover:bg-zinc-800 hover:text-white sm:inline-flex`,children:(0,p.jsx)(`span`,{className:`github-icon h-5 w-5`,"aria-hidden":`true`})})]})]})}function _(){let{user:e}=s.useRouteContext(),{data:t}=a(o()),{agentId:n}=i({strict:!1});return(0,p.jsxs)(p.Fragment,{children:[(0,p.jsx)(`header`,{className:`fixed inset-x-0 top-0 z-40 h-14 border-b border-zinc-800 bg-[#17191c]`,children:(0,p.jsx)(g,{walletAddress:e.walletAddress,agents:t,selectedAgentId:n})}),(0,p.jsx)(`div`,{className:`app-shell fixed inset-x-0 bottom-0 top-14 overflow-y-auto`,children:(0,p.jsx)(`main`,{className:`app-content min-w-0 ${n?`p-2 sm:p-3`:`px-4 py-6 sm:px-6 lg:px-8`}`,children:(0,p.jsx)(c,{})})})]})}export{_ as component};
1
+ import{f as e,l as t,t as n}from"./jsx-runtime-CIazjfqY.js";import{i as r,o as i}from"./lazyRouteComponent-CJgUa7_r.js";import{t as a}from"./useSuspenseQuery-vODFwDb8.js";import{a as o}from"./agent-queries-CNMBImun.js";import{A as s,M as c}from"./index-B4hvjMmI.js";import{t as l}from"./identicon-Lb9pS4O1.js";import{t as u}from"./agent-enablement-control-CUzOp9ce.js";import{t as d}from"./auth-client-K13li9H1.js";var f=e(t(),1),p=n();function m({agentEnabled:e,tradingEnabled:t}){let n=e&&t,r=e?t?`Trading enabled`:`Trading disabled`:`Agent disabled`;return(0,p.jsx)(`span`,{role:`img`,"aria-label":r,title:r,className:`h-2 w-2 shrink-0 rounded-full ${n?`bg-emerald-400`:`bg-amber-400`}`})}function h({agents:e,selectedAgentId:t}){let n=(0,f.useRef)(null),i=(0,f.useRef)(null),a=e.find(e=>e.id===t);function o(){n.current&&(n.current.open=!1)}return(0,f.useEffect)(()=>{o()},[t]),(0,f.useEffect)(()=>{let e=e=>{n.current?.contains(e.target)||o()},t=e=>{e.key===`Escape`&&n.current?.open&&(o(),i.current?.focus())};return document.addEventListener(`click`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`click`,e),document.removeEventListener(`keydown`,t)}},[]),(0,p.jsxs)(`details`,{ref:n,className:`relative h-full min-w-0 max-w-[45vw] sm:max-w-64`,"data-agent-selector":!0,children:[(0,p.jsxs)(`summary`,{ref:i,"aria-label":`Switch Agent`,className:`flex h-full cursor-pointer list-none items-center gap-2 px-4 text-sm text-zinc-300 hover:bg-zinc-800 hover:text-white [&::-webkit-details-marker]:hidden`,children:[a&&(0,p.jsx)(m,{agentEnabled:a.enabled,tradingEnabled:a.tradingEnabled}),(0,p.jsx)(`span`,{className:`truncate`,children:a?.name??`Agents`}),(0,p.jsx)(`svg`,{className:`h-4 w-4 shrink-0 text-zinc-500`,viewBox:`0 0 20 20`,fill:`currentColor`,"aria-hidden":`true`,children:(0,p.jsx)(`path`,{fillRule:`evenodd`,clipRule:`evenodd`,d:`M5.23 7.21a.75.75 0 0 1 1.06.02L10 11.17l3.71-3.94a.75.75 0 1 1 1.09 1.04l-4.25 4.5a.75.75 0 0 1-1.09 0l-4.25-4.5a.75.75 0 0 1 .02-1.06Z`})})]}),(0,p.jsxs)(`div`,{className:`absolute left-0 top-full mt-2 max-h-[calc(100dvh-5rem)] w-64 overflow-y-auto rounded-lg border border-zinc-700 bg-[#1b1d20] p-1 shadow-2xl`,children:[e.map(e=>(0,p.jsxs)(r,{to:`/agents/$agentId`,params:{agentId:e.id},onClick:o,"aria-current":e.id===t?`page`:void 0,className:`flex cursor-pointer items-center gap-2 rounded-md px-3 py-2 text-sm text-zinc-300 hover:bg-zinc-800 hover:text-white`,children:[(0,p.jsx)(m,{agentEnabled:e.enabled,tradingEnabled:e.tradingEnabled}),(0,p.jsx)(`span`,{className:`truncate`,children:e.name})]},e.id)),e.length>0&&(0,p.jsx)(`div`,{className:`my-1 border-t border-zinc-700`}),(0,p.jsx)(r,{to:`/agents/new`,onClick:o,className:`block cursor-pointer rounded-md px-3 py-2 text-sm font-medium text-sky-300 hover:bg-zinc-800 hover:text-sky-200`,children:`Create new agent`})]})]})}function g({walletAddress:e,agents:t=[],selectedAgentId:n}){let i=t.find(e=>e.id===n),[a,o]=(0,f.useState)(!1),[s,c]=(0,f.useState)(``),m=(0,f.useRef)(!1);async function g(){if(!m.current){m.current=!0,o(!0),c(``);try{if((await d.signOut()).error)throw Error(`Unable to log out. Please try again.`);window.location.assign(`/login`)}catch{c(`Unable to log out. Please try again.`),m.current=!1,o(!1)}}}return(0,p.jsxs)(`div`,{className:`relative flex h-full items-center pr-4`,children:[(0,p.jsx)(h,{agents:t,selectedAgentId:n}),i&&!i.tradingEnabled&&(0,p.jsx)(r,{to:`/agents/$agentId/settings`,params:{agentId:i.id},hash:`risk-management`,title:`New exposure is disabled. Reduce-only orders and cancellation remain available. Open risk management settings.`,className:`shrink-0 cursor-pointer whitespace-nowrap rounded-lg px-2 py-1 text-xs text-amber-300 hover:bg-amber-950/50 hover:text-amber-200 sm:text-sm`,children:`Trading disabled`}),(0,p.jsx)(r,{to:`/agents`,className:`absolute left-1/2 hidden h-full -translate-x-1/2 cursor-pointer items-center px-4 hover:bg-zinc-800 lg:flex`,children:(0,p.jsx)(`img`,{src:`/static/hypervibes.png`,alt:`HyperVibes`,width:`2172`,height:`724`,className:`h-12 w-auto object-contain`})}),(0,p.jsxs)(`div`,{className:`ml-auto flex items-center gap-2 sm:gap-3`,children:[i&&(0,p.jsx)(u,{id:i.id,name:i.name,enabled:i.enabled},i.id),(0,p.jsx)(r,{to:`/providers`,title:`Provider connections`,"aria-label":`Provider connections`,className:`inline-flex h-9 w-9 cursor-pointer items-center justify-center rounded-lg text-zinc-400 hover:bg-zinc-800 hover:text-white`,children:(0,p.jsx)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 24 24`,strokeWidth:`1.5`,stroke:`currentColor`,className:`size-6`,"aria-hidden":`true`,children:(0,p.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M5.25 14.25h13.5m-13.5 0a3 3 0 0 1-3-3m3 3a3 3 0 1 0 0 6h13.5a3 3 0 1 0 0-6m-16.5-3a3 3 0 0 1 3-3h13.5a3 3 0 0 1 3 3m-19.5 0a4.5 4.5 0 0 1 .9-2.7L5.737 5.1a3.375 3.375 0 0 1 2.7-1.35h7.126c1.062 0 2.062.5 2.7 1.35l2.587 3.45a4.5 4.5 0 0 1 .9 2.7m0 0a3 3 0 0 1-3 3m0 3h.008v.008h-.008v-.008Zm0-6h.008v.008h-.008v-.008Zm-3 6h.008v.008h-.008v-.008Zm0-6h.008v.008h-.008v-.008Z`})})}),(0,p.jsxs)(r,{to:`/account`,title:e,className:`flex cursor-pointer items-center gap-2 rounded-lg px-2 py-1 hover:bg-zinc-800`,children:[(0,p.jsx)(l,{address:e,className:`h-5 w-5 rounded-full`}),(0,p.jsxs)(`span`,{className:`hidden font-mono text-sm text-zinc-200 sm:inline`,children:[e.slice(0,6),`…`,e.slice(-4)]})]}),(0,p.jsx)(`button`,{type:`button`,title:`Logout`,"aria-label":`Logout`,disabled:a,onClick:()=>{g()},className:`inline-flex h-9 w-9 cursor-pointer items-center justify-center rounded-lg text-zinc-400 hover:bg-zinc-800 hover:text-white disabled:cursor-wait disabled:opacity-60`,children:(0,p.jsx)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 24 24`,strokeWidth:1.5,stroke:`currentColor`,className:`size-6`,"aria-hidden":`true`,children:(0,p.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M15.75 9V5.25A2.25 2.25 0 0 0 13.5 3h-6a2.25 2.25 0 0 0-2.25 2.25v13.5A2.25 2.25 0 0 0 7.5 21h6a2.25 2.25 0 0 0 2.25-2.25V15m3 0 3-3m0 0-3-3m3 3H9`})})}),a&&s&&(0,p.jsx)(`span`,{role:`alert`,className:`text-xs text-red-300`,children:s}),(0,p.jsx)(`a`,{href:`https://github.com/idft/hypervibes`,target:`_blank`,rel:`noopener noreferrer`,"aria-label":`HyperVibes on GitHub`,className:`hidden h-9 w-9 cursor-pointer items-center justify-center rounded-lg text-zinc-400 hover:bg-zinc-800 hover:text-white sm:inline-flex`,children:(0,p.jsx)(`span`,{className:`github-icon h-5 w-5`,"aria-hidden":`true`})})]})]})}function _(){let{user:e}=s.useRouteContext(),{data:t}=a(o()),{agentId:n}=i({strict:!1});return(0,p.jsxs)(p.Fragment,{children:[(0,p.jsx)(`header`,{className:`fixed inset-x-0 top-0 z-40 h-14 border-b border-zinc-800 bg-[#17191c]`,children:(0,p.jsx)(g,{walletAddress:e.walletAddress,agents:t,selectedAgentId:n})}),(0,p.jsx)(`div`,{className:`app-shell fixed inset-x-0 bottom-0 top-14 overflow-y-auto`,children:(0,p.jsx)(`main`,{className:`app-content min-w-0 ${n?`p-2 sm:p-3`:`px-4 py-6 sm:px-6 lg:px-8`}`,children:(0,p.jsx)(c,{})})})]})}export{_ as component};
@@ -1 +1 @@
1
- import{f as e,l as t,t as n}from"./jsx-runtime-CIazjfqY.js";import{i as r}from"./createServerFn-DfZIp2Fu.js";import{t as i}from"./useMutation-Dni_73Pp.js";import{t as a}from"./useSuspenseQuery-vODFwDb8.js";import{a as o}from"./provider-queries-DxPwhDOU.js";import{a as s,o as c}from"./agent-queries-CNMBImun.js";import{D as l,E as u,O as d,T as f,k as p}from"./index-fu66g8fn.js";import{n as m,t as h}from"./custom-BeqXuIIS.js";import{a as g,i as _}from"./decimal-B0DEG-1V.js";import{t as v}from"./identicon-Lb9pS4O1.js";import{t as y}from"./setup-checklist-CUW-K484.js";var b=e(t(),1),x=`0x2ebba955c61116e1c249efb1e39d25cb4a79ea05`,S=42161,C=`0xa4b1`;async function w(e){try{await e.request({method:`wallet_switchEthereumChain`,params:[{chainId:C}]})}catch(t){if(!(typeof t==`object`&&t&&`code`in t&&t.code===4902))throw Error(`Switch your wallet to Arbitrum Mainnet to sign Hyperliquid approvals.`,{cause:t});await e.request({method:`wallet_addEthereumChain`,params:[{chainId:C,chainName:`Arbitrum One`,nativeCurrency:{name:`Ether`,symbol:`ETH`,decimals:18},rpcUrls:[`https://arb1.arbitrum.io/rpc`],blockExplorerUrls:[`https://arbiscan.io`]}]}),await e.request({method:`wallet_switchEthereumChain`,params:[{chainId:C}]})}}async function T({provider:e},t,n,r){if(!e)throw Error(`No Ethereum wallet found. Open this page in a browser with a wallet extension.`);let i=m({transport:h(e)});await w(e);let[a]=await i.requestAddresses();if(!a)throw Error(`No wallet account selected.`);return{action:r,signature:await i.signTypedData({account:a,domain:{name:`HyperliquidSignTransaction`,version:`1`,chainId:S,verifyingContract:`0x0000000000000000000000000000000000000000`},types:n,primaryType:t,message:r})}}function E(){return{hyperliquidChain:`Mainnet`,signatureChainId:C,nonce:Date.now()}}function D(){return globalThis.window?.ethereum}var O={"HyperliquidTransaction:ApproveAgent":[{name:`hyperliquidChain`,type:`string`},{name:`agentAddress`,type:`address`},{name:`agentName`,type:`string`},{name:`nonce`,type:`uint64`}]},k={"HyperliquidTransaction:ApproveBuilderFee":[{name:`hyperliquidChain`,type:`string`},{name:`maxFeeRate`,type:`string`},{name:`builder`,type:`address`},{name:`nonce`,type:`uint64`}]},A=n();function j(){return(0,A.jsx)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 24 24`,strokeWidth:`1.5`,stroke:`currentColor`,className:`h-4 w-4`,"aria-hidden":`true`,children:(0,A.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M13.5 6H5.25A2.25 2.25 0 0 0 3 8.25v10.5A2.25 2.25 0 0 0 5.25 21h10.5A2.25 2.25 0 0 0 18 18.75V10.5m-10.5 6L21 3m0 0h-5.25M21 3v5.25`})})}function M(e){if(!e)return`text-zinc-400`;let t=(e-Date.now())/864e5;return t>=150?`text-emerald-400`:t<30?`text-amber-400`:`text-zinc-400`}function N({balance:e}){if(!e)return(0,A.jsx)(`span`,{className:`text-amber-300`,children:`Unavailable`});let{whole:t,decimals:n}=g(_(e));return(0,A.jsxs)(A.Fragment,{children:[(0,A.jsx)(`span`,{className:/^0(\.0+)?$/.test(e)?`text-zinc-500`:`text-zinc-200`,children:t}),n&&(0,A.jsxs)(`span`,{className:`text-zinc-500`,children:[`.`,n]}),(0,A.jsx)(`span`,{className:`text-zinc-500`,children:` USDC`})]})}function P({view:e,actions:t,setup:n}){let a=r(),[o,s]=(0,b.useState)(``),[l,u]=(0,b.useState)(!1),[d,f]=(0,b.useState)(``),[p,m]=(0,b.useState)(e.builderFee.feeBps),[h,g]=(0,b.useState)(``),_=(0,b.useRef)(!1),S=(0,b.useRef)(!1),C=i({mutationFn:async({source:n,force:r})=>{let i=e.apiWallet?.address??null;(r||!i)&&(s(r?`Re-generating trading signer…`:`Generating trading signer…`),i=await t.setupApiWallet(n,n===`import`?d:``),f(``)),s(`Awaiting wallet signature…`);let a=await T({provider:D()},`HyperliquidTransaction:ApproveAgent`,O,{type:`approveAgent`,...E(),agentAddress:i,agentName:`HyperVibes`});s(`Approving trading signer…`),await t.approveApiWallet(a),s(``)},onSettled:()=>c(a)}),w=i({mutationFn:async e=>{let n=Math.min(Math.max(Math.round(p),1),10),r=e?`0.00%`:`${(n/100).toFixed(2)}%`;g(`Awaiting wallet signature…`);let i=await T({provider:D()},`HyperliquidTransaction:ApproveBuilderFee`,k,{type:`approveBuilderFee`,...E(),maxFeeRate:r,builder:x});e?await t.cancelBuilderFee(i):await t.approveBuilderFee(i,n),g(``)},onSettled:()=>c(a)}),P=C.isPending,F=C.error?.message??o,I=w.isPending,L=w.error?.message??h;async function R(e,t){if(!_.current){_.current=!0;try{await C.mutateAsync({source:e,force:t})}catch{}finally{_.current=!1}}}async function z(e){if(!S.current){S.current=!0;try{await w.mutateAsync(e)}catch{}finally{S.current=!1}}}let B=e.apiWallet;return(0,A.jsxs)(`div`,{className:`mx-auto max-w-3xl space-y-4`,children:[(0,A.jsx)(`header`,{className:`flex items-start justify-between gap-4`,children:(0,A.jsxs)(`h1`,{className:`flex min-w-0 items-center gap-3 text-2xl font-semibold text-white sm:text-3xl`,children:[(0,A.jsx)(v,{address:e.walletAddress,className:`h-8 w-8 shrink-0 rounded-full`}),(0,A.jsx)(`span`,{className:`min-w-0 break-all font-mono text-lg sm:text-3xl`,children:e.walletAddress}),(0,A.jsx)(`a`,{href:`https://arbiscan.io/address/${e.walletAddress}`,target:`_blank`,rel:`noopener noreferrer`,title:`View on Arbiscan`,"aria-label":`View on Arbiscan`,className:`inline-flex h-6 w-6 shrink-0 cursor-pointer items-center justify-center rounded text-zinc-400 hover:text-zinc-200`,children:(0,A.jsx)(j,{})})]})}),(0,A.jsx)(y,{agentCount:n.agentCount,state:{providerConnected:n.providerConnected,apiKeyApproved:e.apiWallet?.state===`approved`,builderFeeApproved:e.builderFee.approved}}),e.accountModeMessage&&(0,A.jsx)(`p`,{role:`status`,className:`rounded-2xl border px-4 py-3 text-sm ${e.accountMode===`unregistered`?`border-violet-900/70 bg-violet-950/20 text-zinc-300`:`border-amber-800/70 bg-amber-950/30 text-amber-200`}`,children:e.accountModeMessage}),!e.encryptionConfigured&&(0,A.jsx)(`p`,{role:`status`,className:`rounded-2xl border border-amber-800/70 bg-amber-950/30 px-4 py-3 text-sm text-amber-200`,children:`Trading signer storage is not configured on the server. Set AGENTS_ENCRYPTION_KEY to enable API keys.`}),e.accountMode===`unregistered`?(0,A.jsxs)(`section`,{className:`rounded-2xl border border-violet-900/70 bg-violet-950/20 p-6 sm:p-8`,children:[(0,A.jsx)(`p`,{className:`text-sm font-medium uppercase tracking-[0.18em] text-violet-300`,children:`Hyperliquid setup`}),(0,A.jsx)(`h2`,{className:`mt-3 text-2xl font-semibold text-white`,children:`Enable trading on Hyperliquid`}),(0,A.jsxs)(`p`,{className:`mt-3 max-w-2xl text-sm leading-6 text-zinc-300`,children:[`Open Hyperliquid with this same wallet, then choose `,(0,A.jsx)(`span`,{className:`font-medium text-white`,children:`Enable Trading`}),` and sign its gas-less transaction. Complete the first deposit Hyperliquid requests to activate the new account, then return here and refresh the page to set up your trading signer, builder-fee approval, and agents.`]}),(0,A.jsxs)(`a`,{href:`https://app.hyperliquid.xyz/trade`,target:`_blank`,rel:`noopener noreferrer`,className:`mt-6 inline-flex cursor-pointer items-center gap-2 rounded-full bg-violet-600 px-5 py-2.5 text-sm font-medium text-white hover:bg-violet-500`,children:[`Open Hyperliquid`,(0,A.jsx)(j,{})]})]}):(0,A.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,A.jsxs)(`section`,{className:`flex flex-col rounded-2xl border border-zinc-800 bg-[#0d0d10] p-6`,children:[(0,A.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,A.jsxs)(`h2`,{className:`flex items-center gap-2 text-lg font-medium text-white`,children:[`Hyperliquid API Key`,(0,A.jsx)(`a`,{href:`https://app.hyperliquid.xyz/API`,target:`_blank`,rel:`noopener noreferrer`,title:`Open Hyperliquid API page`,"aria-label":`Open Hyperliquid API page`,className:`inline-flex h-4 w-4 cursor-pointer items-center justify-center rounded text-zinc-400 hover:text-zinc-200`,children:(0,A.jsx)(j,{})})]}),B?.state===`approved`?(0,A.jsxs)(`span`,{className:`flex items-center gap-2`,children:[B.expiresAt&&(0,A.jsxs)(`span`,{className:`shrink-0 text-sm ${M(B.expiresAt)}`,children:[`Expires `,new Date(B.expiresAt).toLocaleDateString()]}),(0,A.jsx)(`span`,{title:`API key is approved`,"aria-label":`API key is approved`,className:`inline-flex h-6 w-6 shrink-0 items-center justify-center text-emerald-400`,children:(0,A.jsx)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 24 24`,strokeWidth:`1.5`,stroke:`currentColor`,className:`h-5 w-5`,"aria-hidden":`true`,children:(0,A.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`m4.5 12.75 6 6 9-13.5`})})})]}):(0,A.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 text-sm font-medium text-amber-400`,children:[(0,A.jsx)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 24 24`,strokeWidth:`1.5`,stroke:`currentColor`,className:`h-5 w-5`,"aria-hidden":`true`,children:(0,A.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M12 9v3.75m-9.303 3.376c-.866 1.5.217 3.374 1.948 3.374h14.71c1.73 0 2.813-1.874 1.948-3.374L13.949 3.378c-.866-1.5-3.032-1.5-3.898 0L2.697 16.126ZM12 15.75h.007v.008H12v-.008Z`})}),`Required`]})]}),B&&(B.state===`approved`||B.showExpired)&&B.address&&(0,A.jsxs)(`div`,{className:`mt-3 space-y-1`,children:[(0,A.jsx)(`p`,{className:`break-all font-mono text-base text-zinc-200`,children:B.address}),B.showExpired&&(0,A.jsx)(`p`,{className:`text-sm font-semibold text-red-400`,children:`Expired`})]}),B?.state===`approval-required`&&B.address&&(0,A.jsxs)(`p`,{className:`mt-3 break-all font-mono text-sm text-zinc-400`,children:[B.address,` — approval required`]}),(0,A.jsx)(`p`,{"aria-live":`polite`,className:`mt-3 text-sm text-zinc-400`,children:F}),(0,A.jsx)(`div`,{className:`mt-auto space-y-3 pt-4`,children:!B||B.state!==`approved`?(0,A.jsxs)(`div`,{className:`flex items-center gap-4`,children:[l&&(0,A.jsx)(`input`,{type:`password`,autoComplete:`off`,placeholder:`Private key`,value:d,onChange:e=>f(e.target.value),className:`w-full rounded-lg border border-zinc-700 bg-zinc-900 px-3 py-2 text-white`,"aria-label":`Private key`}),B?.state===`approval-required`?(0,A.jsx)(`button`,{type:`button`,disabled:P,onClick:()=>{R(`generate`,!1)},className:`cursor-pointer rounded-full bg-violet-600 px-5 py-2 text-sm font-medium text-white hover:bg-violet-500 disabled:cursor-wait disabled:opacity-50`,children:P?`Working…`:`Approve API Key`}):(0,A.jsx)(`button`,{type:`button`,disabled:P||l&&!d.trim(),onClick:()=>{R(l?`import`:`generate`,!1)},className:`cursor-pointer rounded-full bg-violet-600 px-5 py-2 text-sm font-medium text-white hover:bg-violet-500 disabled:cursor-wait disabled:opacity-50`,children:P?`Working…`:l?`Import API Key`:`Generate API Key`}),(0,A.jsx)(`button`,{type:`button`,"aria-expanded":l,onClick:()=>{u(!l),f(``)},className:`cursor-pointer text-sm text-zinc-400 underline hover:text-zinc-200`,children:l?`Generate a new API key`:`Import existing API key`})]}):(0,A.jsx)(`button`,{type:`button`,disabled:P,onClick:()=>{R(`generate`,!0)},className:`cursor-pointer rounded-full border border-violet-500 px-5 py-2 text-sm font-medium text-violet-300 hover:border-violet-400 hover:bg-violet-950/30 disabled:cursor-wait disabled:opacity-50`,children:P?`Working…`:`Re-generate API key`})})]}),(0,A.jsxs)(`section`,{className:`flex flex-col rounded-2xl border border-zinc-800 bg-[#0d0d10] p-6`,children:[(0,A.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,A.jsxs)(`h2`,{className:`flex items-center gap-2 text-lg font-medium text-white`,children:[`Builder fee approval`,(0,A.jsx)(`a`,{href:`https://app.hyperliquid.xyz/builderCodes`,target:`_blank`,rel:`noopener noreferrer`,title:`Open Hyperliquid builder codes page`,"aria-label":`Open Hyperliquid builder codes page`,className:`inline-flex h-4 w-4 cursor-pointer items-center justify-center rounded text-zinc-400 hover:text-zinc-200`,children:(0,A.jsx)(j,{})})]}),e.builderFee.approved?(0,A.jsx)(`span`,{title:`Builder fee is approved`,"aria-label":`Builder fee is approved`,className:`inline-flex h-6 w-6 shrink-0 items-center justify-center text-emerald-400`,children:(0,A.jsx)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 24 24`,strokeWidth:`1.5`,stroke:`currentColor`,className:`h-5 w-5`,"aria-hidden":`true`,children:(0,A.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`m4.5 12.75 6 6 9-13.5`})})}):(0,A.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 text-sm font-medium text-amber-400`,children:[(0,A.jsx)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 24 24`,strokeWidth:`1.5`,stroke:`currentColor`,className:`h-5 w-5`,"aria-hidden":`true`,children:(0,A.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M12 9v3.75m-9.303 3.376c-.866 1.5.217 3.374 1.948 3.374h14.71c1.73 0 2.813-1.874 1.948-3.374L13.949 3.378c-.866-1.5-3.032-1.5-3.898 0L2.697 16.126ZM12 15.75h.007v.008H12v-.008Z`})}),`Required`]})]}),(0,A.jsxs)(`div`,{className:`mt-6 flex items-center gap-3`,children:[(0,A.jsx)(`label`,{className:`sr-only`,htmlFor:`builder-fee-input`,children:`Builder fee percent`}),(0,A.jsx)(`input`,{id:`builder-fee-input`,type:`number`,min:`0.01`,max:`0.1`,step:`0.01`,value:(p/100).toFixed(2),onChange:e=>{let t=Number(e.target.value);Number.isFinite(t)&&m(Math.round(t*100))},className:`w-20 shrink-0 rounded-lg border border-zinc-700 bg-zinc-900 px-2 py-1 text-right text-sm font-medium text-zinc-300 [appearance:textfield] [&::-webkit-inner-spin-button]:appearance-none [&::-webkit-outer-spin-button]:appearance-none`}),(0,A.jsx)(`span`,{"aria-hidden":`true`,className:`w-6 shrink-0 text-left text-sm text-zinc-300`,children:`%`}),(0,A.jsx)(`label`,{className:`sr-only`,htmlFor:`builder-fee-range`,children:`Builder fee basis points`}),(0,A.jsx)(`input`,{id:`builder-fee-range`,type:`range`,min:`1`,max:`10`,value:p,onChange:e=>m(Number(e.target.value)),className:`flex-1 cursor-pointer`})]}),(0,A.jsx)(`p`,{"aria-live":`polite`,className:`mt-3 text-sm text-zinc-400`,children:L}),(0,A.jsxs)(`div`,{className:`mt-auto flex items-center gap-3 pt-4`,children:[(0,A.jsx)(`button`,{type:`button`,disabled:I,onClick:()=>{z(!1)},className:`cursor-pointer rounded-full bg-violet-600 px-5 py-2 text-sm font-medium text-white hover:bg-violet-500 disabled:cursor-wait disabled:opacity-50`,children:I?`Working…`:e.builderFee.approved?`Change approval`:`Approve`}),e.builderFee.approved&&(0,A.jsx)(`button`,{type:`button`,disabled:I,onClick:()=>{z(!0)},className:`cursor-pointer rounded-full border border-zinc-600 px-5 py-2 text-sm font-medium text-zinc-300 hover:border-zinc-500 hover:bg-zinc-800/50 disabled:cursor-wait disabled:opacity-50`,children:`Cancel Approval`})]})]})]}),(0,A.jsxs)(`section`,{className:`rounded-2xl border border-zinc-800 bg-[#0d0d10] p-6`,children:[(0,A.jsx)(`h2`,{className:`text-lg font-medium text-white`,children:`Accounts`}),e.lookupError&&(0,A.jsx)(`p`,{className:`mt-2 text-sm text-amber-300`,children:e.lookupError}),(0,A.jsx)(`div`,{className:`mt-4 overflow-x-auto sm:overflow-visible`,children:(0,A.jsxs)(`table`,{className:`w-full min-w-[42rem] text-left text-sm`,children:[(0,A.jsx)(`thead`,{className:`border-b border-zinc-800 text-zinc-500`,children:(0,A.jsxs)(`tr`,{children:[(0,A.jsx)(`th`,{className:`px-3 py-3 font-medium`,children:`Name`}),(0,A.jsx)(`th`,{className:`px-3 py-3 font-medium`,children:`Address`}),(0,A.jsx)(`th`,{className:`px-3 py-3 font-medium`,children:`Agent`}),(0,A.jsx)(`th`,{className:`px-3 py-3 text-right font-medium`,children:`Balance`})]})}),(0,A.jsxs)(`tbody`,{className:`divide-y divide-zinc-800`,children:[e.accounts.map(e=>(0,A.jsxs)(`tr`,{children:[(0,A.jsx)(`td`,{className:`px-3 py-3 text-white`,children:e.name}),(0,A.jsx)(`td`,{className:`break-all px-3 py-3 font-mono text-xs text-zinc-400`,children:e.address}),(0,A.jsx)(`td`,{className:`px-3 py-3`,children:e.agentId?(0,A.jsx)(`a`,{href:`/agents/${e.agentId}`,className:`cursor-pointer text-violet-300 underline`,children:e.agentName}):(0,A.jsx)(`span`,{className:`text-zinc-500`,children:`—`})}),(0,A.jsx)(`td`,{className:`px-3 py-3 text-right`,children:(0,A.jsx)(N,{balance:e.balance})})]},e.address)),e.totalBalance!==null&&(0,A.jsxs)(`tr`,{className:`font-bold`,children:[(0,A.jsx)(`td`,{}),(0,A.jsx)(`td`,{}),(0,A.jsx)(`td`,{className:`px-3 py-3`,children:`Total`}),(0,A.jsx)(`td`,{className:`px-3 py-3 text-right`,children:(0,A.jsx)(N,{balance:e.totalBalance})})]})]})]})})]})]})}function F(){let{data:e,error:t}=a(f()),{data:n}=a(s()),{data:r}=a(o()),i={agentCount:n.length,providerConnected:r.providers.some(e=>e.connected)};return(0,A.jsxs)(A.Fragment,{children:[t&&(0,A.jsx)(`p`,{role:`alert`,className:`mb-4 text-sm text-red-300`,children:t.message}),(0,A.jsx)(P,{view:e,setup:i,actions:{setupApiWallet:(e,t)=>p({data:{source:e,privateKey:t}}),approveApiWallet:e=>u({data:e}),approveBuilderFee:(e,t)=>l({data:{...e,feeBps:t}}),cancelBuilderFee:e=>d({data:e})}})]})}export{F as component};
1
+ import{f as e,l as t,t as n}from"./jsx-runtime-CIazjfqY.js";import{i as r}from"./createServerFn-DfZIp2Fu.js";import{t as i}from"./useMutation-DrF53EQG.js";import{t as a}from"./useSuspenseQuery-vODFwDb8.js";import{a as o}from"./provider-queries-DxPwhDOU.js";import{a as s,o as c}from"./agent-queries-CNMBImun.js";import{D as l,E as u,O as d,T as f,k as p}from"./index-B4hvjMmI.js";import{n as m,t as h}from"./custom-BeqXuIIS.js";import{a as g,i as _}from"./decimal-B0DEG-1V.js";import{t as v}from"./identicon-Lb9pS4O1.js";import{t as y}from"./setup-checklist-CUW-K484.js";var b=e(t(),1),x=`0x2ebba955c61116e1c249efb1e39d25cb4a79ea05`,S=42161,C=`0xa4b1`;async function w(e){try{await e.request({method:`wallet_switchEthereumChain`,params:[{chainId:C}]})}catch(t){if(!(typeof t==`object`&&t&&`code`in t&&t.code===4902))throw Error(`Switch your wallet to Arbitrum Mainnet to sign Hyperliquid approvals.`,{cause:t});await e.request({method:`wallet_addEthereumChain`,params:[{chainId:C,chainName:`Arbitrum One`,nativeCurrency:{name:`Ether`,symbol:`ETH`,decimals:18},rpcUrls:[`https://arb1.arbitrum.io/rpc`],blockExplorerUrls:[`https://arbiscan.io`]}]}),await e.request({method:`wallet_switchEthereumChain`,params:[{chainId:C}]})}}async function T({provider:e},t,n,r){if(!e)throw Error(`No Ethereum wallet found. Open this page in a browser with a wallet extension.`);let i=m({transport:h(e)});await w(e);let[a]=await i.requestAddresses();if(!a)throw Error(`No wallet account selected.`);return{action:r,signature:await i.signTypedData({account:a,domain:{name:`HyperliquidSignTransaction`,version:`1`,chainId:S,verifyingContract:`0x0000000000000000000000000000000000000000`},types:n,primaryType:t,message:r})}}function E(){return{hyperliquidChain:`Mainnet`,signatureChainId:C,nonce:Date.now()}}function D(){return globalThis.window?.ethereum}var O={"HyperliquidTransaction:ApproveAgent":[{name:`hyperliquidChain`,type:`string`},{name:`agentAddress`,type:`address`},{name:`agentName`,type:`string`},{name:`nonce`,type:`uint64`}]},k={"HyperliquidTransaction:ApproveBuilderFee":[{name:`hyperliquidChain`,type:`string`},{name:`maxFeeRate`,type:`string`},{name:`builder`,type:`address`},{name:`nonce`,type:`uint64`}]},A=n();function j(){return(0,A.jsx)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 24 24`,strokeWidth:`1.5`,stroke:`currentColor`,className:`h-4 w-4`,"aria-hidden":`true`,children:(0,A.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M13.5 6H5.25A2.25 2.25 0 0 0 3 8.25v10.5A2.25 2.25 0 0 0 5.25 21h10.5A2.25 2.25 0 0 0 18 18.75V10.5m-10.5 6L21 3m0 0h-5.25M21 3v5.25`})})}function M(e){if(!e)return`text-zinc-400`;let t=(e-Date.now())/864e5;return t>=150?`text-emerald-400`:t<30?`text-amber-400`:`text-zinc-400`}function N({balance:e}){if(!e)return(0,A.jsx)(`span`,{className:`text-amber-300`,children:`Unavailable`});let{whole:t,decimals:n}=g(_(e));return(0,A.jsxs)(A.Fragment,{children:[(0,A.jsx)(`span`,{className:/^0(\.0+)?$/.test(e)?`text-zinc-500`:`text-zinc-200`,children:t}),n&&(0,A.jsxs)(`span`,{className:`text-zinc-500`,children:[`.`,n]}),(0,A.jsx)(`span`,{className:`text-zinc-500`,children:` USDC`})]})}function P({view:e,actions:t,setup:n}){let a=r(),[o,s]=(0,b.useState)(``),[l,u]=(0,b.useState)(!1),[d,f]=(0,b.useState)(``),[p,m]=(0,b.useState)(e.builderFee.feeBps),[h,g]=(0,b.useState)(``),_=(0,b.useRef)(!1),S=(0,b.useRef)(!1),C=i({mutationFn:async({source:n,force:r})=>{let i=e.apiWallet?.address??null;(r||!i)&&(s(r?`Re-generating trading signer…`:`Generating trading signer…`),i=await t.setupApiWallet(n,n===`import`?d:``),f(``)),s(`Awaiting wallet signature…`);let a=await T({provider:D()},`HyperliquidTransaction:ApproveAgent`,O,{type:`approveAgent`,...E(),agentAddress:i,agentName:`HyperVibes`});s(`Approving trading signer…`),await t.approveApiWallet(a),s(``)},onSettled:()=>c(a)}),w=i({mutationFn:async e=>{let n=Math.min(Math.max(Math.round(p),1),10),r=e?`0.00%`:`${(n/100).toFixed(2)}%`;g(`Awaiting wallet signature…`);let i=await T({provider:D()},`HyperliquidTransaction:ApproveBuilderFee`,k,{type:`approveBuilderFee`,...E(),maxFeeRate:r,builder:x});e?await t.cancelBuilderFee(i):await t.approveBuilderFee(i,n),g(``)},onSettled:()=>c(a)}),P=C.isPending,F=C.error?.message??o,I=w.isPending,L=w.error?.message??h;async function R(e,t){if(!_.current){_.current=!0;try{await C.mutateAsync({source:e,force:t})}catch{}finally{_.current=!1}}}async function z(e){if(!S.current){S.current=!0;try{await w.mutateAsync(e)}catch{}finally{S.current=!1}}}let B=e.apiWallet;return(0,A.jsxs)(`div`,{className:`mx-auto max-w-3xl space-y-4`,children:[(0,A.jsx)(`header`,{className:`flex items-start justify-between gap-4`,children:(0,A.jsxs)(`h1`,{className:`flex min-w-0 items-center gap-3 text-2xl font-semibold text-white sm:text-3xl`,children:[(0,A.jsx)(v,{address:e.walletAddress,className:`h-8 w-8 shrink-0 rounded-full`}),(0,A.jsx)(`span`,{className:`min-w-0 break-all font-mono text-lg sm:text-3xl`,children:e.walletAddress}),(0,A.jsx)(`a`,{href:`https://arbiscan.io/address/${e.walletAddress}`,target:`_blank`,rel:`noopener noreferrer`,title:`View on Arbiscan`,"aria-label":`View on Arbiscan`,className:`inline-flex h-6 w-6 shrink-0 cursor-pointer items-center justify-center rounded text-zinc-400 hover:text-zinc-200`,children:(0,A.jsx)(j,{})})]})}),(0,A.jsx)(y,{agentCount:n.agentCount,state:{providerConnected:n.providerConnected,apiKeyApproved:e.apiWallet?.state===`approved`,builderFeeApproved:e.builderFee.approved}}),e.accountModeMessage&&(0,A.jsx)(`p`,{role:`status`,className:`rounded-2xl border px-4 py-3 text-sm ${e.accountMode===`unregistered`?`border-violet-900/70 bg-violet-950/20 text-zinc-300`:`border-amber-800/70 bg-amber-950/30 text-amber-200`}`,children:e.accountModeMessage}),!e.encryptionConfigured&&(0,A.jsx)(`p`,{role:`status`,className:`rounded-2xl border border-amber-800/70 bg-amber-950/30 px-4 py-3 text-sm text-amber-200`,children:`Trading signer storage is not configured on the server. Set AGENTS_ENCRYPTION_KEY to enable API keys.`}),e.accountMode===`unregistered`?(0,A.jsxs)(`section`,{className:`rounded-2xl border border-violet-900/70 bg-violet-950/20 p-6 sm:p-8`,children:[(0,A.jsx)(`p`,{className:`text-sm font-medium uppercase tracking-[0.18em] text-violet-300`,children:`Hyperliquid setup`}),(0,A.jsx)(`h2`,{className:`mt-3 text-2xl font-semibold text-white`,children:`Enable trading on Hyperliquid`}),(0,A.jsxs)(`p`,{className:`mt-3 max-w-2xl text-sm leading-6 text-zinc-300`,children:[`Open Hyperliquid with this same wallet, then choose `,(0,A.jsx)(`span`,{className:`font-medium text-white`,children:`Enable Trading`}),` and sign its gas-less transaction. Complete the first deposit Hyperliquid requests to activate the new account, then return here and refresh the page to set up your trading signer, builder-fee approval, and agents.`]}),(0,A.jsxs)(`a`,{href:`https://app.hyperliquid.xyz/trade`,target:`_blank`,rel:`noopener noreferrer`,className:`mt-6 inline-flex cursor-pointer items-center gap-2 rounded-full bg-violet-600 px-5 py-2.5 text-sm font-medium text-white hover:bg-violet-500`,children:[`Open Hyperliquid`,(0,A.jsx)(j,{})]})]}):(0,A.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,A.jsxs)(`section`,{className:`flex flex-col rounded-2xl border border-zinc-800 bg-[#0d0d10] p-6`,children:[(0,A.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,A.jsxs)(`h2`,{className:`flex items-center gap-2 text-lg font-medium text-white`,children:[`Hyperliquid API Key`,(0,A.jsx)(`a`,{href:`https://app.hyperliquid.xyz/API`,target:`_blank`,rel:`noopener noreferrer`,title:`Open Hyperliquid API page`,"aria-label":`Open Hyperliquid API page`,className:`inline-flex h-4 w-4 cursor-pointer items-center justify-center rounded text-zinc-400 hover:text-zinc-200`,children:(0,A.jsx)(j,{})})]}),B?.state===`approved`?(0,A.jsxs)(`span`,{className:`flex items-center gap-2`,children:[B.expiresAt&&(0,A.jsxs)(`span`,{className:`shrink-0 text-sm ${M(B.expiresAt)}`,children:[`Expires `,new Date(B.expiresAt).toLocaleDateString()]}),(0,A.jsx)(`span`,{title:`API key is approved`,"aria-label":`API key is approved`,className:`inline-flex h-6 w-6 shrink-0 items-center justify-center text-emerald-400`,children:(0,A.jsx)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 24 24`,strokeWidth:`1.5`,stroke:`currentColor`,className:`h-5 w-5`,"aria-hidden":`true`,children:(0,A.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`m4.5 12.75 6 6 9-13.5`})})})]}):(0,A.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 text-sm font-medium text-amber-400`,children:[(0,A.jsx)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 24 24`,strokeWidth:`1.5`,stroke:`currentColor`,className:`h-5 w-5`,"aria-hidden":`true`,children:(0,A.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M12 9v3.75m-9.303 3.376c-.866 1.5.217 3.374 1.948 3.374h14.71c1.73 0 2.813-1.874 1.948-3.374L13.949 3.378c-.866-1.5-3.032-1.5-3.898 0L2.697 16.126ZM12 15.75h.007v.008H12v-.008Z`})}),`Required`]})]}),B&&(B.state===`approved`||B.showExpired)&&B.address&&(0,A.jsxs)(`div`,{className:`mt-3 space-y-1`,children:[(0,A.jsx)(`p`,{className:`break-all font-mono text-base text-zinc-200`,children:B.address}),B.showExpired&&(0,A.jsx)(`p`,{className:`text-sm font-semibold text-red-400`,children:`Expired`})]}),B?.state===`approval-required`&&B.address&&(0,A.jsxs)(`p`,{className:`mt-3 break-all font-mono text-sm text-zinc-400`,children:[B.address,` — approval required`]}),(0,A.jsx)(`p`,{"aria-live":`polite`,className:`mt-3 text-sm text-zinc-400`,children:F}),(0,A.jsx)(`div`,{className:`mt-auto space-y-3 pt-4`,children:!B||B.state!==`approved`?(0,A.jsxs)(`div`,{className:`flex items-center gap-4`,children:[l&&(0,A.jsx)(`input`,{type:`password`,autoComplete:`off`,placeholder:`Private key`,value:d,onChange:e=>f(e.target.value),className:`w-full rounded-lg border border-zinc-700 bg-zinc-900 px-3 py-2 text-white`,"aria-label":`Private key`}),B?.state===`approval-required`?(0,A.jsx)(`button`,{type:`button`,disabled:P,onClick:()=>{R(`generate`,!1)},className:`cursor-pointer rounded-full bg-violet-600 px-5 py-2 text-sm font-medium text-white hover:bg-violet-500 disabled:cursor-wait disabled:opacity-50`,children:P?`Working…`:`Approve API Key`}):(0,A.jsx)(`button`,{type:`button`,disabled:P||l&&!d.trim(),onClick:()=>{R(l?`import`:`generate`,!1)},className:`cursor-pointer rounded-full bg-violet-600 px-5 py-2 text-sm font-medium text-white hover:bg-violet-500 disabled:cursor-wait disabled:opacity-50`,children:P?`Working…`:l?`Import API Key`:`Generate API Key`}),(0,A.jsx)(`button`,{type:`button`,"aria-expanded":l,onClick:()=>{u(!l),f(``)},className:`cursor-pointer text-sm text-zinc-400 underline hover:text-zinc-200`,children:l?`Generate a new API key`:`Import existing API key`})]}):(0,A.jsx)(`button`,{type:`button`,disabled:P,onClick:()=>{R(`generate`,!0)},className:`cursor-pointer rounded-full border border-violet-500 px-5 py-2 text-sm font-medium text-violet-300 hover:border-violet-400 hover:bg-violet-950/30 disabled:cursor-wait disabled:opacity-50`,children:P?`Working…`:`Re-generate API key`})})]}),(0,A.jsxs)(`section`,{className:`flex flex-col rounded-2xl border border-zinc-800 bg-[#0d0d10] p-6`,children:[(0,A.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,A.jsxs)(`h2`,{className:`flex items-center gap-2 text-lg font-medium text-white`,children:[`Builder fee approval`,(0,A.jsx)(`a`,{href:`https://app.hyperliquid.xyz/builderCodes`,target:`_blank`,rel:`noopener noreferrer`,title:`Open Hyperliquid builder codes page`,"aria-label":`Open Hyperliquid builder codes page`,className:`inline-flex h-4 w-4 cursor-pointer items-center justify-center rounded text-zinc-400 hover:text-zinc-200`,children:(0,A.jsx)(j,{})})]}),e.builderFee.approved?(0,A.jsx)(`span`,{title:`Builder fee is approved`,"aria-label":`Builder fee is approved`,className:`inline-flex h-6 w-6 shrink-0 items-center justify-center text-emerald-400`,children:(0,A.jsx)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 24 24`,strokeWidth:`1.5`,stroke:`currentColor`,className:`h-5 w-5`,"aria-hidden":`true`,children:(0,A.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`m4.5 12.75 6 6 9-13.5`})})}):(0,A.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 text-sm font-medium text-amber-400`,children:[(0,A.jsx)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 24 24`,strokeWidth:`1.5`,stroke:`currentColor`,className:`h-5 w-5`,"aria-hidden":`true`,children:(0,A.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M12 9v3.75m-9.303 3.376c-.866 1.5.217 3.374 1.948 3.374h14.71c1.73 0 2.813-1.874 1.948-3.374L13.949 3.378c-.866-1.5-3.032-1.5-3.898 0L2.697 16.126ZM12 15.75h.007v.008H12v-.008Z`})}),`Required`]})]}),(0,A.jsxs)(`div`,{className:`mt-6 flex items-center gap-3`,children:[(0,A.jsx)(`label`,{className:`sr-only`,htmlFor:`builder-fee-input`,children:`Builder fee percent`}),(0,A.jsx)(`input`,{id:`builder-fee-input`,type:`number`,min:`0.01`,max:`0.1`,step:`0.01`,value:(p/100).toFixed(2),onChange:e=>{let t=Number(e.target.value);Number.isFinite(t)&&m(Math.round(t*100))},className:`w-20 shrink-0 rounded-lg border border-zinc-700 bg-zinc-900 px-2 py-1 text-right text-sm font-medium text-zinc-300 [appearance:textfield] [&::-webkit-inner-spin-button]:appearance-none [&::-webkit-outer-spin-button]:appearance-none`}),(0,A.jsx)(`span`,{"aria-hidden":`true`,className:`w-6 shrink-0 text-left text-sm text-zinc-300`,children:`%`}),(0,A.jsx)(`label`,{className:`sr-only`,htmlFor:`builder-fee-range`,children:`Builder fee basis points`}),(0,A.jsx)(`input`,{id:`builder-fee-range`,type:`range`,min:`1`,max:`10`,value:p,onChange:e=>m(Number(e.target.value)),className:`flex-1 cursor-pointer`})]}),(0,A.jsx)(`p`,{"aria-live":`polite`,className:`mt-3 text-sm text-zinc-400`,children:L}),(0,A.jsxs)(`div`,{className:`mt-auto flex items-center gap-3 pt-4`,children:[(0,A.jsx)(`button`,{type:`button`,disabled:I,onClick:()=>{z(!1)},className:`cursor-pointer rounded-full bg-violet-600 px-5 py-2 text-sm font-medium text-white hover:bg-violet-500 disabled:cursor-wait disabled:opacity-50`,children:I?`Working…`:e.builderFee.approved?`Change approval`:`Approve`}),e.builderFee.approved&&(0,A.jsx)(`button`,{type:`button`,disabled:I,onClick:()=>{z(!0)},className:`cursor-pointer rounded-full border border-zinc-600 px-5 py-2 text-sm font-medium text-zinc-300 hover:border-zinc-500 hover:bg-zinc-800/50 disabled:cursor-wait disabled:opacity-50`,children:`Cancel Approval`})]})]})]}),(0,A.jsxs)(`section`,{className:`rounded-2xl border border-zinc-800 bg-[#0d0d10] p-6`,children:[(0,A.jsx)(`h2`,{className:`text-lg font-medium text-white`,children:`Accounts`}),e.lookupError&&(0,A.jsx)(`p`,{className:`mt-2 text-sm text-amber-300`,children:e.lookupError}),(0,A.jsx)(`div`,{className:`mt-4 overflow-x-auto sm:overflow-visible`,children:(0,A.jsxs)(`table`,{className:`w-full min-w-[42rem] text-left text-sm`,children:[(0,A.jsx)(`thead`,{className:`border-b border-zinc-800 text-zinc-500`,children:(0,A.jsxs)(`tr`,{children:[(0,A.jsx)(`th`,{className:`px-3 py-3 font-medium`,children:`Name`}),(0,A.jsx)(`th`,{className:`px-3 py-3 font-medium`,children:`Address`}),(0,A.jsx)(`th`,{className:`px-3 py-3 font-medium`,children:`Agent`}),(0,A.jsx)(`th`,{className:`px-3 py-3 text-right font-medium`,children:`Balance`})]})}),(0,A.jsxs)(`tbody`,{className:`divide-y divide-zinc-800`,children:[e.accounts.map(e=>(0,A.jsxs)(`tr`,{children:[(0,A.jsx)(`td`,{className:`px-3 py-3 text-white`,children:e.name}),(0,A.jsx)(`td`,{className:`break-all px-3 py-3 font-mono text-xs text-zinc-400`,children:e.address}),(0,A.jsx)(`td`,{className:`px-3 py-3`,children:e.agentId?(0,A.jsx)(`a`,{href:`/agents/${e.agentId}`,className:`cursor-pointer text-violet-300 underline`,children:e.agentName}):(0,A.jsx)(`span`,{className:`text-zinc-500`,children:`—`})}),(0,A.jsx)(`td`,{className:`px-3 py-3 text-right`,children:(0,A.jsx)(N,{balance:e.balance})})]},e.address)),e.totalBalance!==null&&(0,A.jsxs)(`tr`,{className:`font-bold`,children:[(0,A.jsx)(`td`,{}),(0,A.jsx)(`td`,{}),(0,A.jsx)(`td`,{className:`px-3 py-3`,children:`Total`}),(0,A.jsx)(`td`,{className:`px-3 py-3 text-right`,children:(0,A.jsx)(N,{balance:e.totalBalance})})]})]})]})})]})]})}function F(){let{data:e,error:t}=a(f()),{data:n}=a(s()),{data:r}=a(o()),i={agentCount:n.length,providerConnected:r.providers.some(e=>e.connected)};return(0,A.jsxs)(A.Fragment,{children:[t&&(0,A.jsx)(`p`,{role:`alert`,className:`mb-4 text-sm text-red-300`,children:t.message}),(0,A.jsx)(P,{view:e,setup:i,actions:{setupApiWallet:(e,t)=>p({data:{source:e,privateKey:t}}),approveApiWallet:e=>u({data:e}),approveBuilderFee:(e,t)=>l({data:{...e,feeBps:t}}),cancelBuilderFee:e=>d({data:e})}})]})}export{F as component};
@@ -0,0 +1 @@
1
+ import{M as e}from"./index-B4hvjMmI.js";var t=e;export{t as component};
@@ -1 +1 @@
1
- import{f as e,l as t,t as n}from"./jsx-runtime-CIazjfqY.js";import{i as r}from"./createServerFn-DfZIp2Fu.js";import{i}from"./lazyRouteComponent-CJgUa7_r.js";import{t as a}from"./useSuspenseQuery-vODFwDb8.js";import{a as o,i as s}from"./agent-queries-CNMBImun.js";import{t as c}from"./risk-queries-D_6PHwus.js";import{n as l}from"./indicator-queries-CzZ6u1Mh.js";import{M as u,w as d}from"./index-fu66g8fn.js";import{i as f,r as p,t as m}from"./agent-events-DC8eDZf3.js";var h=e(t(),1);function g({agentId:e}){let t=r();return p(`agent`,n=>{let r=JSON.parse(n.data);r.id===e&&(t.invalidateQueries({queryKey:c(e).queryKey}),t.setQueryData(s(e).queryKey,r),t.setQueryData(o().queryKey,t=>t?.map(t=>t.id===e?{...t,...r}:t)),t.setQueryData([`agent-chat`,e],e=>e&&{...e,agent:r}))}),null}function _(e){let t=r(),{interrupted:n,controlMessage:i,streamErrors:a}=f(),[o,s]=(0,h.useState)(``);return p(`indicators`,()=>{s(``),t.invalidateQueries({queryKey:l.all(e)})}),(0,h.useEffect)(()=>{a.indicators?s(`Indicator updates unavailable. Reload to retry (check open-tab connection limits).`):n&&s(i||`Indicator updates disconnected. Latest versions may be stale; reconnecting…`)},[n,i,a]),o}var v=n(),y=[{label:`Dashboard`,to:`/agents/$agentId`,icon:`M3 3h6v6H3zM13 3h6v6h-6zM3 13h6v6H3zM13 13h6v6h-6z`},{label:`Charts`,to:`/agents/$agentId/chart`,icon:`M3 3v18h18M6 15l5-6 4 3 5-7`},{label:`Transactions`,to:`/agents/$agentId/transactions`,icon:`M3 7h17m-4-4 4 4-4 4M21 17H4m4-4-4 4 4 4`},{label:`Chat`,to:`/agents/$agentId/chat`,icon:`M4 4h16v12H9l-5 4z`},{label:`Sub-Agents`,to:`/agents/$agentId/sub-agents`,icon:`M9 3h6v6H9zM3 16h6v6H3zM15 16h6v6h-6zM12 9v4M6 16v-3h12v3`},{label:`Notifications`,to:`/agents/$agentId/notifications`,icon:`M6 8a6 6 0 0 1 12 0c0 7 3 7 3 9H3c0-2 3-2 3-9M9 21h6`},{label:`Settings`,to:`/agents/$agentId/settings`,icon:`M4 6h16M4 12h16M4 18h16M8 3v6M16 9v6M10 15v6`}],b=[{label:`Indicators`,to:`/agents/$agentId/indicators`,icon:`M3 12h18M3 18l5-12 5 10 4-8 4 10`}],x=[{label:`Insights`,to:`/agents/$agentId/memories`,search:{scope:``},icon:`M4 4h16v16H4zM8 8h8M8 12h8M8 16h5`}];function S({agentId:e}){return _(e),null}function C({agent:e,initialExpanded:t}){let[n,r]=(0,h.useState)(t),[a,o]=(0,h.useState)(!0),[s,c]=(0,h.useState)(!0);function l(){r(e=>(document.cookie=`hv-agent-nav-expanded=${!e}; Max-Age=31536000; Path=/; SameSite=Strict`,!e))}let d=t=>(0,v.jsxs)(i,{to:t.to,params:{agentId:e.id},search:`search`in t?t.search:void 0,activeOptions:{exact:!0},title:t.label,"aria-label":t.label,onClick:t.label===`Charts`?()=>c(!0):void 0,"aria-expanded":t.label===`Charts`?s:void 0,"aria-controls":t.label===`Charts`?`agent-chart-sections`:void 0,className:`flex h-10 cursor-pointer items-center gap-3 rounded-lg px-3 text-zinc-400 hover:bg-zinc-800 hover:text-white`,activeProps:{className:`bg-zinc-800 text-white`,"aria-current":`page`},children:[(0,v.jsx)(`svg`,{className:`h-5 w-5 shrink-0`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.5`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,children:(0,v.jsx)(`path`,{d:t.icon})}),n&&(0,v.jsxs)(v.Fragment,{children:[(0,v.jsx)(`span`,{className:`text-sm`,children:t.label}),t.label===`Charts`&&(0,v.jsx)(`span`,{className:`ml-auto text-xs`,"aria-hidden":`true`,children:s?`▾`:`▸`})]})]},t.label);return(0,v.jsxs)(`div`,{className:n?`pl-48`:`pl-14 sm:pl-16`,children:[(0,v.jsxs)(`nav`,{"aria-label":`Agent sections`,className:`fixed bottom-0 left-0 top-14 z-30 flex flex-col border-r border-zinc-800 bg-[#111214] p-1.5 ${n?`w-48`:`w-14 sm:w-16`}`,children:[(0,v.jsxs)(`div`,{className:`flex min-h-0 flex-col gap-1 overflow-y-auto`,children:[d(y[0]),d(y[1]),(0,v.jsx)(`div`,{id:`agent-chart-sections`,hidden:!s,className:n?`ml-4 space-y-1 border-l border-zinc-800 pl-1`:`space-y-1`,children:s&&b.map(d)}),d(y[2]),(0,v.jsx)(`hr`,{className:`my-2 border-zinc-800`}),y.slice(3,-2).map(d),(0,v.jsxs)(i,{to:`/agents/$agentId/memories`,params:{agentId:e.id},search:{},onClick:()=>o(!0),activeOptions:{exact:!0,includeSearch:!0},activeProps:{className:`bg-zinc-800 text-white`,"aria-current":`page`},"aria-expanded":a,"aria-controls":`agent-memory-sections`,"aria-label":`Memories`,title:`Memories`,className:`flex h-10 shrink-0 cursor-pointer items-center gap-3 rounded-lg px-3 text-zinc-400 hover:bg-zinc-800 hover:text-white`,children:[(0,v.jsx)(`svg`,{className:`h-5 w-5 shrink-0`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.5`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,children:(0,v.jsx)(`path`,{d:`M4 4h16v16H4zM8 8h8M8 12h8M8 16h5`})}),n&&(0,v.jsxs)(v.Fragment,{children:[(0,v.jsx)(`span`,{className:`text-sm`,children:`Memories`}),(0,v.jsx)(`span`,{className:`ml-auto text-xs`,"aria-hidden":`true`,children:a?`▾`:`▸`})]})]}),(0,v.jsx)(`div`,{id:`agent-memory-sections`,hidden:!a,className:n?`ml-4 space-y-1 border-l border-zinc-800 pl-1`:`space-y-1`,children:a&&x.map(d)})]}),(0,v.jsxs)(`div`,{className:`mt-auto space-y-2`,children:[(0,v.jsxs)(`button`,{type:`button`,onClick:l,"aria-expanded":n,"aria-label":n?`Collapse agent navigation`:`Expand agent navigation`,title:n?`Collapse agent navigation`:`Expand agent navigation`,className:`flex h-10 w-full cursor-pointer items-center gap-3 rounded-lg px-3 text-zinc-400 hover:bg-zinc-800 hover:text-white`,children:[(0,v.jsx)(`span`,{className:`flex h-5 w-5 shrink-0 items-center justify-center`,"aria-hidden":`true`,children:n?`«`:`»`}),n&&(0,v.jsx)(`span`,{className:`text-sm`,children:`Collapse`})]}),(0,v.jsx)(`div`,{className:`space-y-1 border-t border-zinc-800 pt-2`,children:y.slice(-2).map(d)})]})]}),(0,v.jsx)(`div`,{className:`flex min-h-[calc(100dvh-5rem)] w-full min-w-0 flex-col`,children:(0,v.jsxs)(m,{agentId:e.id,children:[(0,v.jsx)(g,{agentId:e.id}),(0,v.jsx)(S,{agentId:e.id}),(0,v.jsx)(u,{})]})})]})}function w(){let{navExpanded:e}=d.useLoaderData(),{agentId:t}=d.useParams(),{data:n}=a(s(t));return(0,v.jsx)(C,{agent:n,initialExpanded:e},n.id)}export{w as component};
1
+ import{f as e,l as t,t as n}from"./jsx-runtime-CIazjfqY.js";import{i as r}from"./createServerFn-DfZIp2Fu.js";import{i}from"./lazyRouteComponent-CJgUa7_r.js";import{t as a}from"./useSuspenseQuery-vODFwDb8.js";import{a as o,i as s}from"./agent-queries-CNMBImun.js";import{t as c}from"./risk-queries-D_6PHwus.js";import{n as l}from"./indicator-queries-CzZ6u1Mh.js";import{M as u,w as d}from"./index-B4hvjMmI.js";import{i as f,r as p,t as m}from"./agent-events-DC8eDZf3.js";var h=e(t(),1);function g({agentId:e}){let t=r();return p(`agent`,n=>{let r=JSON.parse(n.data);r.id===e&&(t.invalidateQueries({queryKey:c(e).queryKey}),t.setQueryData(s(e).queryKey,r),t.setQueryData(o().queryKey,t=>t?.map(t=>t.id===e?{...t,...r}:t)),t.setQueryData([`agent-chat`,e],e=>e&&{...e,agent:r}))}),null}function _(e){let t=r(),{interrupted:n,controlMessage:i,streamErrors:a}=f(),[o,s]=(0,h.useState)(``);return p(`indicators`,()=>{s(``),t.invalidateQueries({queryKey:l.all(e)})}),(0,h.useEffect)(()=>{a.indicators?s(`Indicator updates unavailable. Reload to retry (check open-tab connection limits).`):n&&s(i||`Indicator updates disconnected. Latest versions may be stale; reconnecting…`)},[n,i,a]),o}var v=n(),y=[{label:`Dashboard`,to:`/agents/$agentId`,icon:`M3 3h6v6H3zM13 3h6v6h-6zM3 13h6v6H3zM13 13h6v6h-6z`},{label:`Charts`,to:`/agents/$agentId/chart`,icon:`M3 3v18h18M6 15l5-6 4 3 5-7`},{label:`Transactions`,to:`/agents/$agentId/transactions`,icon:`M3 7h17m-4-4 4 4-4 4M21 17H4m4-4-4 4 4 4`},{label:`Chat`,to:`/agents/$agentId/chat`,icon:`M4 4h16v12H9l-5 4z`},{label:`Sub-Agents`,to:`/agents/$agentId/sub-agents`,icon:`M9 3h6v6H9zM3 16h6v6H3zM15 16h6v6h-6zM12 9v4M6 16v-3h12v3`},{label:`Notifications`,to:`/agents/$agentId/notifications`,icon:`M6 8a6 6 0 0 1 12 0c0 7 3 7 3 9H3c0-2 3-2 3-9M9 21h6`},{label:`Settings`,to:`/agents/$agentId/settings`,icon:`M4 6h16M4 12h16M4 18h16M8 3v6M16 9v6M10 15v6`}],b=[{label:`Indicators`,to:`/agents/$agentId/indicators`,icon:`M3 12h18M3 18l5-12 5 10 4-8 4 10`}],x=[{label:`Insights`,to:`/agents/$agentId/memories`,search:{scope:``},icon:`M4 4h16v16H4zM8 8h8M8 12h8M8 16h5`}];function S({agentId:e}){return _(e),null}function C({agent:e,initialExpanded:t}){let[n,r]=(0,h.useState)(t),[a,o]=(0,h.useState)(!0),[s,c]=(0,h.useState)(!0);function l(){r(e=>(document.cookie=`hv-agent-nav-expanded=${!e}; Max-Age=31536000; Path=/; SameSite=Strict`,!e))}let d=t=>(0,v.jsxs)(i,{to:t.to,params:{agentId:e.id},search:`search`in t?t.search:void 0,activeOptions:{exact:!0},title:t.label,"aria-label":t.label,onClick:t.label===`Charts`?()=>c(!0):void 0,"aria-expanded":t.label===`Charts`?s:void 0,"aria-controls":t.label===`Charts`?`agent-chart-sections`:void 0,className:`flex h-10 cursor-pointer items-center gap-3 rounded-lg px-3 text-zinc-400 hover:bg-zinc-800 hover:text-white`,activeProps:{className:`bg-zinc-800 text-white`,"aria-current":`page`},children:[(0,v.jsx)(`svg`,{className:`h-5 w-5 shrink-0`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.5`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,children:(0,v.jsx)(`path`,{d:t.icon})}),n&&(0,v.jsxs)(v.Fragment,{children:[(0,v.jsx)(`span`,{className:`text-sm`,children:t.label}),t.label===`Charts`&&(0,v.jsx)(`span`,{className:`ml-auto text-xs`,"aria-hidden":`true`,children:s?`▾`:`▸`})]})]},t.label);return(0,v.jsxs)(`div`,{className:n?`pl-48`:`pl-14 sm:pl-16`,children:[(0,v.jsxs)(`nav`,{"aria-label":`Agent sections`,className:`fixed bottom-0 left-0 top-14 z-30 flex flex-col border-r border-zinc-800 bg-[#111214] p-1.5 ${n?`w-48`:`w-14 sm:w-16`}`,children:[(0,v.jsxs)(`div`,{className:`flex min-h-0 flex-col gap-1 overflow-y-auto`,children:[d(y[0]),d(y[1]),(0,v.jsx)(`div`,{id:`agent-chart-sections`,hidden:!s,className:n?`ml-4 space-y-1 border-l border-zinc-800 pl-1`:`space-y-1`,children:s&&b.map(d)}),d(y[2]),(0,v.jsx)(`hr`,{className:`my-2 border-zinc-800`}),y.slice(3,-2).map(d),(0,v.jsxs)(i,{to:`/agents/$agentId/memories`,params:{agentId:e.id},search:{},onClick:()=>o(!0),activeOptions:{exact:!0,includeSearch:!0},activeProps:{className:`bg-zinc-800 text-white`,"aria-current":`page`},"aria-expanded":a,"aria-controls":`agent-memory-sections`,"aria-label":`Memories`,title:`Memories`,className:`flex h-10 shrink-0 cursor-pointer items-center gap-3 rounded-lg px-3 text-zinc-400 hover:bg-zinc-800 hover:text-white`,children:[(0,v.jsx)(`svg`,{className:`h-5 w-5 shrink-0`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.5`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,children:(0,v.jsx)(`path`,{d:`M4 4h16v16H4zM8 8h8M8 12h8M8 16h5`})}),n&&(0,v.jsxs)(v.Fragment,{children:[(0,v.jsx)(`span`,{className:`text-sm`,children:`Memories`}),(0,v.jsx)(`span`,{className:`ml-auto text-xs`,"aria-hidden":`true`,children:a?`▾`:`▸`})]})]}),(0,v.jsx)(`div`,{id:`agent-memory-sections`,hidden:!a,className:n?`ml-4 space-y-1 border-l border-zinc-800 pl-1`:`space-y-1`,children:a&&x.map(d)})]}),(0,v.jsxs)(`div`,{className:`mt-auto space-y-2`,children:[(0,v.jsxs)(`button`,{type:`button`,onClick:l,"aria-expanded":n,"aria-label":n?`Collapse agent navigation`:`Expand agent navigation`,title:n?`Collapse agent navigation`:`Expand agent navigation`,className:`flex h-10 w-full cursor-pointer items-center gap-3 rounded-lg px-3 text-zinc-400 hover:bg-zinc-800 hover:text-white`,children:[(0,v.jsx)(`span`,{className:`flex h-5 w-5 shrink-0 items-center justify-center`,"aria-hidden":`true`,children:n?`«`:`»`}),n&&(0,v.jsx)(`span`,{className:`text-sm`,children:`Collapse`})]}),(0,v.jsx)(`div`,{className:`space-y-1 border-t border-zinc-800 pt-2`,children:y.slice(-2).map(d)})]})]}),(0,v.jsx)(`div`,{className:`flex min-h-[calc(100dvh-5rem)] w-full min-w-0 flex-col`,children:(0,v.jsxs)(m,{agentId:e.id,children:[(0,v.jsx)(g,{agentId:e.id}),(0,v.jsx)(S,{agentId:e.id}),(0,v.jsx)(u,{})]})})]})}function w(){let{navExpanded:e}=d.useLoaderData(),{agentId:t}=d.useParams(),{data:n}=a(s(t));return(0,v.jsx)(C,{agent:n,initialExpanded:e},n.id)}export{w as component};
@@ -1,4 +1,4 @@
1
- import{f as e,l as t,t as n}from"./jsx-runtime-CIazjfqY.js";import{t as r}from"./react-dom-C6bOPxes.js";import{i}from"./createServerFn-DfZIp2Fu.js";import{S as a,c as o,i as s,r as c,u as l,w as u,y as d}from"./query-nvK_95Jo.js";import{a as f,c as p,d as m,i as h,l as g,o as _,r as v,s as y,t as b,u as x}from"./useBaseQuery-Bxruo_mV.js";import{t as S}from"./useMutation-Dni_73Pp.js";import{t as C}from"./useQuery-BMSU16jY.js";import{t as w}from"./useSuspenseQuery-vODFwDb8.js";import{a as T,i as E,n as D,o as O,r as k,s as A,t as j}from"./chart-queries-Bpvrgd0-.js";import{r as M}from"./provider-queries-DxPwhDOU.js";import{t as N}from"./agent-queries-CNMBImun.js";import{i as P,r as F,t as I}from"./indicator-queries-CzZ6u1Mh.js";import{S as L}from"./index-fu66g8fn.js";import{a as ee,i as R,n as te,r as ne,s as re,t as z}from"./lightweight-charts.production-BiBiFZSH.js";import{r as B,t as V}from"./indicator-renderer-CfccsIt2.js";import{i as H,n as ie}from"./decimal-B0DEG-1V.js";import{t as U}from"./random-uuid-DJR3ygJS.js";import{i as ae,n as W,r as oe,t as se}from"./chart-contracts-Cr5SFCbE.js";import{a as G,i as K,n as q,r as ce}from"./contracts-HhAL7Tt7.js";import{n as J,r as Y,t as X}from"./config-dialog-C9x9gKW9.js";import{i as le,n as ue,r as de}from"./agent-events-DC8eDZf3.js";import{t as fe}from"./agent-chat-page-vKrkXdzr.js";import{n as pe}from"./instrument-picker-DLPpryOm.js";import{t as me}from"./indicator-input-fields-CtmrfVfS.js";var he=class extends m{constructor(e,t){super(e,t)}bindMethods(){super.bindMethods(),this.fetchNextPage=this.fetchNextPage.bind(this),this.fetchPreviousPage=this.fetchPreviousPage.bind(this)}setOptions(e){e._type=`infinite`,super.setOptions(e)}getOptimisticResult(e){return e._type=`infinite`,super.getOptimisticResult(e)}fetchNextPage(e){return this.fetch({...e,meta:{fetchMore:{direction:`forward`}}})}fetchPreviousPage(e){return this.fetch({...e,meta:{fetchMore:{direction:`backward`}}})}createResult(e,t){let{state:n}=e,r=super.createResult(e,t),{isFetching:i,isRefetching:a,isError:o,isRefetchError:l}=r,u=n.fetchMeta?.fetchMore?.direction,d=o&&u===`forward`,f=i&&u===`forward`,p=o&&u===`backward`,m=i&&u===`backward`;return{...r,fetchNextPage:this.fetchNextPage,fetchPreviousPage:this.fetchPreviousPage,hasNextPage:c(t,n.data),hasPreviousPage:s(t,n.data),isFetchNextPageError:d,isFetchingNextPage:f,isFetchPreviousPageError:p,isFetchingPreviousPage:m,isRefetchError:l&&!d&&!p,isRefetching:a&&!f&&!m}}};function ge(e,t){let n=new Set(t);return e.filter(e=>!n.has(e))}var _e=class extends l{#e;#t;#n;#r;#i;#a;#o;#s;#c;#l=[];constructor(e,t,n){super(),this.#e=e,this.#r=n,this.#n=[],this.#i=[],this.#t=[],this.setQueries(t)}onSubscribe(){this.listeners.size===1&&this.#i.forEach(e=>{e.subscribe(t=>{this.#m(e,t)})})}onUnsubscribe(){this.listeners.size||this.destroy()}destroy(){this.listeners=new Set,this.#i.forEach(e=>{e.destroy()})}setQueries(e,t){this.#n=e,this.#r=t,o.batch(()=>{let e=this.#i,t=this.#p(this.#n);t.forEach(e=>e.observer.setOptions(e.defaultedQueryOptions));let n=t.map(e=>e.observer),r=n.map(e=>e.getCurrentResult()),i=e.length!==n.length,a=n.some((t,n)=>t!==e[n]),o=i||a,s=o?!0:r.some((e,t)=>{let n=this.#t[t];return!n||!u(e,n)});!o&&!s||(o&&(this.#l=t,this.#i=n),this.#t=r,this.hasListeners()&&(o&&(ge(e,n).forEach(e=>{e.destroy()}),ge(n,e).forEach(e=>{e.subscribe(t=>{this.#m(e,t)})})),this.#h()))})}getCurrentResult(){return this.#t}getQueries(){return this.#i.map(e=>e.getCurrentQuery())}getObservers(){return this.#i}getOptimisticResult(e,t){let n=this.#p(e),r=n.map(e=>e.observer.getOptimisticResult(e.defaultedQueryOptions)),i=n.map(e=>e.defaultedQueryOptions.queryHash);return[r,e=>this.#d(e??r,t,i),()=>this.#u(r,n)]}#u(e,t){let n=new Set;return t.map((r,i)=>{let a=e[i];return r.defaultedQueryOptions.notifyOnChangeProps?a:r.observer.trackResult(a,e=>{n.has(e)||(n.add(e),t.forEach(t=>{t.observer.trackProp(e)}))})})}#d(e,t,n){if(t){let r=this.#c,i=n!==void 0&&r!==void 0&&(r.length!==n.length||n.some((e,t)=>e!==r[t]));return(this.#t!==this.#s||i||t!==this.#o)&&(this.#o=t,this.#s=this.#t,n!==void 0&&(this.#c=n),this.#a=a(this.#a,t(e))),this.#a}return e}#f(){return!this.#r?.combine||this.#i.some((e,t)=>e.options.suspense&&this.#t[t]?.data===void 0)}#p(e){let t=new Map;this.#i.forEach(e=>{let n=e.options.queryHash;if(!n)return;let r=t.get(n);r?r.push(e):t.set(n,[e])});let n=[];return e.forEach(e=>{let r=this.#e.defaultQueryOptions(e),i=t.get(r.queryHash)?.shift()??new m(this.#e,r);n.push({defaultedQueryOptions:r,observer:i})}),n}#m(e,t){let n=this.#i.indexOf(e);n!==-1&&(this.#t=this.#t.slice(),this.#t[n]=t,this.#h())}#h(){if(this.hasListeners()){let e=this.#f(),t=this.#a,n=e?t:this.#d(this.#u(this.#t,this.#l),this.#r?.combine);(e||t!==n)&&o.batch(()=>{this.listeners.forEach(e=>{e(this.#t)})})}}},Z=e(t(),1);function ve({queries:e,...t},n){let r=i(n),a=x(),s=g(),c=t.subscribed!==!1,l=Z.useMemo(()=>e.map(e=>{let t=r.defaultQueryOptions(e);return t._optimisticResults=a?`isRestoring`:c?`optimistic`:void 0,t}),[e,r,a,c]);l.forEach(e=>{v(e);let t=r.getQueryCache().get(e.queryHash);_(e,s,t)}),p(s);let[u]=Z.useState(()=>new _e(r,l,t)),[b,S,C]=u.getOptimisticResult(l,t.combine),w=!a&&c;Z.useSyncExternalStore(Z.useCallback(e=>w?u.subscribe(o.batchCalls(e)):d,[u,w]),()=>u.getCurrentResult(),()=>u.getCurrentResult()),Z.useEffect(()=>{u.setQueries(l,t)},[l,t,u]);let T=b.some((e,t)=>f(l[t],e))?b.flatMap((e,t)=>{let n=l[t];return n&&f(n,e)?h(n,new m(r,n),s):[]}):[];if(T.length>0)throw Promise.all(T);let E=b.find((e,t)=>{let n=l[t];return n&&y({result:e,errorResetBoundary:s,throwOnError:n.throwOnError,query:r.getQueryCache().get(n.queryHash),suspense:n.suspense})});if(E)throw E.error;return S(C())}function ye(e,t){return b(e,he,t)}var be=e(r(),1),Q=n();function xe({document:e,revision:t,projection:n,tool:r,selected:i,disabled:a,svgRef:o,onSelect:s,onSave:c,onDrawn:l,onEdit:u}){let[d,f]=(0,Z.useState)(``),[p,m]=(0,Z.useState)(null),[h,g]=(0,Z.useState)(null),[_,v]=(0,Z.useState)(null),y=(0,Z.useRef)(null),b=_?.revision,x=a||b!=null&&t<b;(0,Z.useEffect)(()=>{b!=null&&t>=b&&v(e=>e?.revision===b?null:e)},[t,b]);let S=e=>{let t=n.x(e.time),r=n.y(e.price);return t===null||r===null?null:{x:t,y:r}};function C(t){let r=o.current.getBoundingClientRect();return n.point(Math.max(0,Math.min(n.width,t.clientX-r.left)),Math.max(0,Math.min(n.height,t.clientY-r.top)),e.magnet!==(t.ctrlKey||t.metaKey))}function w(e,t,n){if(r!==`select`||e.button!==0||(e.preventDefault(),e.stopPropagation(),x||y.current)||(s(t.id),t.locked))return;let i=C(e);i&&(o.current.setPointerCapture(e.pointerId),y.current={drawing:t,handle:n,start:i,draft:null,pointerId:e.pointerId})}function T(e){if(y.current&&y.current.pointerId!==e.pointerId)return;let t=C(e);if(!t)return;p&&g(t);let n=y.current;if(!n)return;let r=n.drawing.points.map((e,r)=>n.handle===r?t:n.handle===null?{time:Math.max(0,e.time+t.time-n.start.time),price:Math.max(1e-12,e.price+t.price-n.start.price)}:e);n.draft={...n.drawing,points:r},v({drawing:n.draft,revision:null})}async function E(e){let t;try{t=await c(e)}catch{}v(n=>n?.drawing===e?t===void 0?null:{drawing:e,revision:t}:n)}function D(e){let t=y.current;!t||t.pointerId!==e.pointerId||(y.current=null,e.currentTarget.hasPointerCapture(e.pointerId)&&e.currentTarget.releasePointerCapture(e.pointerId),t.draft&&E(t.draft))}function O(e){!y.current||y.current.pointerId!==e.pointerId||(y.current=null,v(null),e.currentTarget.hasPointerCapture(e.pointerId)&&e.currentTarget.releasePointerCapture(e.pointerId))}function k(t){if(x||t.button!==0)return;let n=C(t);if(!n)return;if(r===`select`){s(``);return}let i=[`horizontal`,`horizontal-ray`,`vertical`,`text`].includes(r);if(!i&&!p){m(n),g(n);return}try{let t=K(r,e.coin,i?[n]:[p,n]);f(``),[`text`,`callout`].includes(r)&&(t.text=`Note`),c(t),s(t.id),m(null),g(null),l()}catch(e){f(e instanceof Error?e.message:`Unable to prepare the drawing`)}}let A=_&&(_.revision===null||t<_.revision)?_.drawing:null,j=e.drawings.filter(t=>G(t,e)).map(e=>A?.id===e.id?A:e);return p&&h&&r!==`select`&&j.push({...K(r,e.coin,[p,h],`preview`),color:`#71717a`}),(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(`svg`,{ref:o,xmlns:`http://www.w3.org/2000/svg`,width:n.width,height:n.height,viewBox:`0 0 ${n.width} ${n.height}`,"aria-label":`Chart drawings`,className:`absolute left-0 top-0 z-10 overflow-hidden`,style:{pointerEvents:r===`select`||x?`none`:`auto`,cursor:r===`select`?`default`:`crosshair`,touchAction:`none`},onPointerDown:k,onPointerMove:T,onPointerUp:D,onPointerCancel:O,onLostPointerCapture:O,children:[r!==`select`&&!x&&(0,Q.jsx)(`rect`,{"data-drawing-surface":`true`,width:n.width,height:n.height,fill:`transparent`,style:{pointerEvents:`all`}}),j.map(e=>{let t=S(e.points[0]),a=S(e.points[1]??e.points[0]);if(!t||!a)return null;let[o,c]=B(e.kind,t,a,n.width),l={stroke:e.color,strokeWidth:e.width,strokeDasharray:e.dashed?`6 4`:void 0,fill:`none`},d=e.kind===`vertical`?`M ${t.x} 0 L ${t.x} ${n.height}`:`M ${o.x} ${o.y} L ${c.x} ${c.y}`,f=e.kind===`rectangle`,p=e.kind===`text`,m=e.kind===`callout`?a:t,h=i===e.id;return(0,Q.jsxs)(`g`,{"aria-label":e.name,onDoubleClick:t=>{r===`select`&&!e.locked&&!x&&(t.stopPropagation(),s(e.id),u())},children:[(0,Q.jsxs)(`title`,{children:[e.name,e.locked?` (locked)`:``,` · `,e.author===`agent`?`Agent`:`You`]}),f?(0,Q.jsx)(`rect`,{x:Math.min(t.x,a.x),y:Math.min(t.y,a.y),width:Math.abs(a.x-t.x),height:Math.abs(a.y-t.y),...l,fill:e.color,fillOpacity:e.fillOpacity}):p?null:(0,Q.jsx)(`path`,{d,...l}),e.kind===`arrow`&&(0,Q.jsx)(`path`,{d:`M ${a.x-12*Math.cos(Math.atan2(a.y-t.y,a.x-t.x)-.45)} ${a.y-12*Math.sin(Math.atan2(a.y-t.y,a.x-t.x)-.45)} L ${a.x} ${a.y} L ${a.x-12*Math.cos(Math.atan2(a.y-t.y,a.x-t.x)+.45)} ${a.y-12*Math.sin(Math.atan2(a.y-t.y,a.x-t.x)+.45)}`,...l}),(e.kind===`horizontal`||e.kind===`horizontal-ray`)&&(0,Q.jsx)(`text`,{x:n.width-6,y:t.y-5,textAnchor:`end`,fill:e.color,fontSize:`11`,fontFamily:`sans-serif`,stroke:`#0d0d10`,strokeWidth:`3`,paintOrder:`stroke`,children:e.points[0].price.toLocaleString(`en`,{maximumSignificantDigits:10})}),e.text&&(0,Q.jsx)(`text`,{x:m.x+6,y:m.y-8,fill:e.color,fontSize:`13`,fontFamily:`sans-serif`,stroke:`#0d0d10`,strokeWidth:`3`,paintOrder:`stroke`,children:e.text.split(`
1
+ import{f as e,l as t,t as n}from"./jsx-runtime-CIazjfqY.js";import{t as r}from"./react-dom-C6bOPxes.js";import{i}from"./createServerFn-DfZIp2Fu.js";import{S as a,c as o,i as s,r as c,u as l,w as u,y as d}from"./query-nvK_95Jo.js";import{a as f,c as p,d as m,i as h,l as g,o as _,r as v,s as y,t as b,u as x}from"./useBaseQuery-Bxruo_mV.js";import{t as S}from"./useMutation-DrF53EQG.js";import{t as C}from"./useQuery-BMSU16jY.js";import{t as w}from"./useSuspenseQuery-vODFwDb8.js";import{a as T,i as E,n as D,o as O,r as k,s as A,t as j}from"./chart-queries-Bpvrgd0-.js";import{r as M}from"./provider-queries-DxPwhDOU.js";import{t as N}from"./agent-queries-CNMBImun.js";import{i as P,r as F,t as I}from"./indicator-queries-CzZ6u1Mh.js";import{S as L}from"./index-B4hvjMmI.js";import{a as ee,i as R,n as te,r as ne,s as re,t as z}from"./lightweight-charts.production-BiBiFZSH.js";import{r as B,t as V}from"./indicator-renderer-CfccsIt2.js";import{i as H,n as ie}from"./decimal-B0DEG-1V.js";import{t as U}from"./random-uuid-DJR3ygJS.js";import{i as ae,n as W,r as oe,t as se}from"./chart-contracts-Cr5SFCbE.js";import{a as G,i as K,n as q,r as ce}from"./contracts-HhAL7Tt7.js";import{n as J,r as Y,t as X}from"./config-dialog-C9x9gKW9.js";import{i as le,n as ue,r as de}from"./agent-events-DC8eDZf3.js";import{t as fe}from"./agent-chat-page-C5eYFgxw.js";import{n as pe}from"./instrument-picker-DLPpryOm.js";import{t as me}from"./indicator-input-fields-CtmrfVfS.js";var he=class extends m{constructor(e,t){super(e,t)}bindMethods(){super.bindMethods(),this.fetchNextPage=this.fetchNextPage.bind(this),this.fetchPreviousPage=this.fetchPreviousPage.bind(this)}setOptions(e){e._type=`infinite`,super.setOptions(e)}getOptimisticResult(e){return e._type=`infinite`,super.getOptimisticResult(e)}fetchNextPage(e){return this.fetch({...e,meta:{fetchMore:{direction:`forward`}}})}fetchPreviousPage(e){return this.fetch({...e,meta:{fetchMore:{direction:`backward`}}})}createResult(e,t){let{state:n}=e,r=super.createResult(e,t),{isFetching:i,isRefetching:a,isError:o,isRefetchError:l}=r,u=n.fetchMeta?.fetchMore?.direction,d=o&&u===`forward`,f=i&&u===`forward`,p=o&&u===`backward`,m=i&&u===`backward`;return{...r,fetchNextPage:this.fetchNextPage,fetchPreviousPage:this.fetchPreviousPage,hasNextPage:c(t,n.data),hasPreviousPage:s(t,n.data),isFetchNextPageError:d,isFetchingNextPage:f,isFetchPreviousPageError:p,isFetchingPreviousPage:m,isRefetchError:l&&!d&&!p,isRefetching:a&&!f&&!m}}};function ge(e,t){let n=new Set(t);return e.filter(e=>!n.has(e))}var _e=class extends l{#e;#t;#n;#r;#i;#a;#o;#s;#c;#l=[];constructor(e,t,n){super(),this.#e=e,this.#r=n,this.#n=[],this.#i=[],this.#t=[],this.setQueries(t)}onSubscribe(){this.listeners.size===1&&this.#i.forEach(e=>{e.subscribe(t=>{this.#m(e,t)})})}onUnsubscribe(){this.listeners.size||this.destroy()}destroy(){this.listeners=new Set,this.#i.forEach(e=>{e.destroy()})}setQueries(e,t){this.#n=e,this.#r=t,o.batch(()=>{let e=this.#i,t=this.#p(this.#n);t.forEach(e=>e.observer.setOptions(e.defaultedQueryOptions));let n=t.map(e=>e.observer),r=n.map(e=>e.getCurrentResult()),i=e.length!==n.length,a=n.some((t,n)=>t!==e[n]),o=i||a,s=o?!0:r.some((e,t)=>{let n=this.#t[t];return!n||!u(e,n)});!o&&!s||(o&&(this.#l=t,this.#i=n),this.#t=r,this.hasListeners()&&(o&&(ge(e,n).forEach(e=>{e.destroy()}),ge(n,e).forEach(e=>{e.subscribe(t=>{this.#m(e,t)})})),this.#h()))})}getCurrentResult(){return this.#t}getQueries(){return this.#i.map(e=>e.getCurrentQuery())}getObservers(){return this.#i}getOptimisticResult(e,t){let n=this.#p(e),r=n.map(e=>e.observer.getOptimisticResult(e.defaultedQueryOptions)),i=n.map(e=>e.defaultedQueryOptions.queryHash);return[r,e=>this.#d(e??r,t,i),()=>this.#u(r,n)]}#u(e,t){let n=new Set;return t.map((r,i)=>{let a=e[i];return r.defaultedQueryOptions.notifyOnChangeProps?a:r.observer.trackResult(a,e=>{n.has(e)||(n.add(e),t.forEach(t=>{t.observer.trackProp(e)}))})})}#d(e,t,n){if(t){let r=this.#c,i=n!==void 0&&r!==void 0&&(r.length!==n.length||n.some((e,t)=>e!==r[t]));return(this.#t!==this.#s||i||t!==this.#o)&&(this.#o=t,this.#s=this.#t,n!==void 0&&(this.#c=n),this.#a=a(this.#a,t(e))),this.#a}return e}#f(){return!this.#r?.combine||this.#i.some((e,t)=>e.options.suspense&&this.#t[t]?.data===void 0)}#p(e){let t=new Map;this.#i.forEach(e=>{let n=e.options.queryHash;if(!n)return;let r=t.get(n);r?r.push(e):t.set(n,[e])});let n=[];return e.forEach(e=>{let r=this.#e.defaultQueryOptions(e),i=t.get(r.queryHash)?.shift()??new m(this.#e,r);n.push({defaultedQueryOptions:r,observer:i})}),n}#m(e,t){let n=this.#i.indexOf(e);n!==-1&&(this.#t=this.#t.slice(),this.#t[n]=t,this.#h())}#h(){if(this.hasListeners()){let e=this.#f(),t=this.#a,n=e?t:this.#d(this.#u(this.#t,this.#l),this.#r?.combine);(e||t!==n)&&o.batch(()=>{this.listeners.forEach(e=>{e(this.#t)})})}}},Z=e(t(),1);function ve({queries:e,...t},n){let r=i(n),a=x(),s=g(),c=t.subscribed!==!1,l=Z.useMemo(()=>e.map(e=>{let t=r.defaultQueryOptions(e);return t._optimisticResults=a?`isRestoring`:c?`optimistic`:void 0,t}),[e,r,a,c]);l.forEach(e=>{v(e);let t=r.getQueryCache().get(e.queryHash);_(e,s,t)}),p(s);let[u]=Z.useState(()=>new _e(r,l,t)),[b,S,C]=u.getOptimisticResult(l,t.combine),w=!a&&c;Z.useSyncExternalStore(Z.useCallback(e=>w?u.subscribe(o.batchCalls(e)):d,[u,w]),()=>u.getCurrentResult(),()=>u.getCurrentResult()),Z.useEffect(()=>{u.setQueries(l,t)},[l,t,u]);let T=b.some((e,t)=>f(l[t],e))?b.flatMap((e,t)=>{let n=l[t];return n&&f(n,e)?h(n,new m(r,n),s):[]}):[];if(T.length>0)throw Promise.all(T);let E=b.find((e,t)=>{let n=l[t];return n&&y({result:e,errorResetBoundary:s,throwOnError:n.throwOnError,query:r.getQueryCache().get(n.queryHash),suspense:n.suspense})});if(E)throw E.error;return S(C())}function ye(e,t){return b(e,he,t)}var be=e(r(),1),Q=n();function xe({document:e,revision:t,projection:n,tool:r,selected:i,disabled:a,svgRef:o,onSelect:s,onSave:c,onDrawn:l,onEdit:u}){let[d,f]=(0,Z.useState)(``),[p,m]=(0,Z.useState)(null),[h,g]=(0,Z.useState)(null),[_,v]=(0,Z.useState)(null),y=(0,Z.useRef)(null),b=_?.revision,x=a||b!=null&&t<b;(0,Z.useEffect)(()=>{b!=null&&t>=b&&v(e=>e?.revision===b?null:e)},[t,b]);let S=e=>{let t=n.x(e.time),r=n.y(e.price);return t===null||r===null?null:{x:t,y:r}};function C(t){let r=o.current.getBoundingClientRect();return n.point(Math.max(0,Math.min(n.width,t.clientX-r.left)),Math.max(0,Math.min(n.height,t.clientY-r.top)),e.magnet!==(t.ctrlKey||t.metaKey))}function w(e,t,n){if(r!==`select`||e.button!==0||(e.preventDefault(),e.stopPropagation(),x||y.current)||(s(t.id),t.locked))return;let i=C(e);i&&(o.current.setPointerCapture(e.pointerId),y.current={drawing:t,handle:n,start:i,draft:null,pointerId:e.pointerId})}function T(e){if(y.current&&y.current.pointerId!==e.pointerId)return;let t=C(e);if(!t)return;p&&g(t);let n=y.current;if(!n)return;let r=n.drawing.points.map((e,r)=>n.handle===r?t:n.handle===null?{time:Math.max(0,e.time+t.time-n.start.time),price:Math.max(1e-12,e.price+t.price-n.start.price)}:e);n.draft={...n.drawing,points:r},v({drawing:n.draft,revision:null})}async function E(e){let t;try{t=await c(e)}catch{}v(n=>n?.drawing===e?t===void 0?null:{drawing:e,revision:t}:n)}function D(e){let t=y.current;!t||t.pointerId!==e.pointerId||(y.current=null,e.currentTarget.hasPointerCapture(e.pointerId)&&e.currentTarget.releasePointerCapture(e.pointerId),t.draft&&E(t.draft))}function O(e){!y.current||y.current.pointerId!==e.pointerId||(y.current=null,v(null),e.currentTarget.hasPointerCapture(e.pointerId)&&e.currentTarget.releasePointerCapture(e.pointerId))}function k(t){if(x||t.button!==0)return;let n=C(t);if(!n)return;if(r===`select`){s(``);return}let i=[`horizontal`,`horizontal-ray`,`vertical`,`text`].includes(r);if(!i&&!p){m(n),g(n);return}try{let t=K(r,e.coin,i?[n]:[p,n]);f(``),[`text`,`callout`].includes(r)&&(t.text=`Note`),c(t),s(t.id),m(null),g(null),l()}catch(e){f(e instanceof Error?e.message:`Unable to prepare the drawing`)}}let A=_&&(_.revision===null||t<_.revision)?_.drawing:null,j=e.drawings.filter(t=>G(t,e)).map(e=>A?.id===e.id?A:e);return p&&h&&r!==`select`&&j.push({...K(r,e.coin,[p,h],`preview`),color:`#71717a`}),(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(`svg`,{ref:o,xmlns:`http://www.w3.org/2000/svg`,width:n.width,height:n.height,viewBox:`0 0 ${n.width} ${n.height}`,"aria-label":`Chart drawings`,className:`absolute left-0 top-0 z-10 overflow-hidden`,style:{pointerEvents:r===`select`||x?`none`:`auto`,cursor:r===`select`?`default`:`crosshair`,touchAction:`none`},onPointerDown:k,onPointerMove:T,onPointerUp:D,onPointerCancel:O,onLostPointerCapture:O,children:[r!==`select`&&!x&&(0,Q.jsx)(`rect`,{"data-drawing-surface":`true`,width:n.width,height:n.height,fill:`transparent`,style:{pointerEvents:`all`}}),j.map(e=>{let t=S(e.points[0]),a=S(e.points[1]??e.points[0]);if(!t||!a)return null;let[o,c]=B(e.kind,t,a,n.width),l={stroke:e.color,strokeWidth:e.width,strokeDasharray:e.dashed?`6 4`:void 0,fill:`none`},d=e.kind===`vertical`?`M ${t.x} 0 L ${t.x} ${n.height}`:`M ${o.x} ${o.y} L ${c.x} ${c.y}`,f=e.kind===`rectangle`,p=e.kind===`text`,m=e.kind===`callout`?a:t,h=i===e.id;return(0,Q.jsxs)(`g`,{"aria-label":e.name,onDoubleClick:t=>{r===`select`&&!e.locked&&!x&&(t.stopPropagation(),s(e.id),u())},children:[(0,Q.jsxs)(`title`,{children:[e.name,e.locked?` (locked)`:``,` · `,e.author===`agent`?`Agent`:`You`]}),f?(0,Q.jsx)(`rect`,{x:Math.min(t.x,a.x),y:Math.min(t.y,a.y),width:Math.abs(a.x-t.x),height:Math.abs(a.y-t.y),...l,fill:e.color,fillOpacity:e.fillOpacity}):p?null:(0,Q.jsx)(`path`,{d,...l}),e.kind===`arrow`&&(0,Q.jsx)(`path`,{d:`M ${a.x-12*Math.cos(Math.atan2(a.y-t.y,a.x-t.x)-.45)} ${a.y-12*Math.sin(Math.atan2(a.y-t.y,a.x-t.x)-.45)} L ${a.x} ${a.y} L ${a.x-12*Math.cos(Math.atan2(a.y-t.y,a.x-t.x)+.45)} ${a.y-12*Math.sin(Math.atan2(a.y-t.y,a.x-t.x)+.45)}`,...l}),(e.kind===`horizontal`||e.kind===`horizontal-ray`)&&(0,Q.jsx)(`text`,{x:n.width-6,y:t.y-5,textAnchor:`end`,fill:e.color,fontSize:`11`,fontFamily:`sans-serif`,stroke:`#0d0d10`,strokeWidth:`3`,paintOrder:`stroke`,children:e.points[0].price.toLocaleString(`en`,{maximumSignificantDigits:10})}),e.text&&(0,Q.jsx)(`text`,{x:m.x+6,y:m.y-8,fill:e.color,fontSize:`13`,fontFamily:`sans-serif`,stroke:`#0d0d10`,strokeWidth:`3`,paintOrder:`stroke`,children:e.text.split(`
2
2
  `).map((e,t)=>(0,Q.jsx)(`tspan`,{x:m.x+6,dy:t?`1.2em`:0,children:e},t))}),r===`select`&&(f?(0,Q.jsx)(`rect`,{x:Math.min(t.x,a.x),y:Math.min(t.y,a.y),width:Math.abs(a.x-t.x),height:Math.abs(a.y-t.y),fill:`transparent`,stroke:`transparent`,strokeWidth:`12`,style:{pointerEvents:`all`,cursor:x?`progress`:e.locked?`pointer`:`move`},onPointerDown:t=>w(t,e,null)}):p?(0,Q.jsx)(`rect`,{x:t.x,y:t.y-24,width:Math.max(60,e.text.length*8),height:`30`,fill:`transparent`,style:{pointerEvents:`all`,cursor:x?`progress`:e.locked?`pointer`:`move`},onPointerDown:t=>w(t,e,null)}):(0,Q.jsx)(`path`,{d,fill:`none`,stroke:`transparent`,strokeWidth:`14`,style:{pointerEvents:`stroke`,cursor:x?`progress`:e.locked?`pointer`:`move`},onPointerDown:t=>w(t,e,null)})),h&&e.points.map((t,n)=>{let i=S(t);return i?(0,Q.jsx)(`circle`,{"data-handle":`true`,cx:i.x,cy:i.y,r:`5`,fill:`#0d0d10`,stroke:e.color,strokeWidth:`2`,style:{pointerEvents:r===`select`?`all`:`none`,cursor:x?`progress`:e.locked?`not-allowed`:`grab`},onPointerDown:t=>w(t,e,n)},n):null})]},e.id)})]}),d&&(0,Q.jsx)(`p`,{role:`alert`,className:`absolute left-2 top-2 z-20 text-sm text-red-300`,children:d})]})}var Se={trades:!0,position:!0,orders:!0},Ce=`#34d399`,we=`#f87171`,Te=e=>{let t=Number(e);return Number.isFinite(t)&&t>0?t:null};function Ee(e,t,n){return!n&&e?.live?.status===`connected`&&e.live.sections[t].fresh}function De(e,t,n){let r=new Set(t.map(e=>e.time));return e.flatMap(e=>{let t=Math.floor(e.time/1e3/n)*n,i=Te(e.price);if(!r.has(t)||i===null)return[];let a=e.side===`Buy`;return[{id:e.id,time:t,price:i,position:a?`atPriceBottom`:`atPriceTop`,shape:a?`arrowUp`:`arrowDown`,color:a?Ce:we}]}).sort((e,t)=>e.time-t.time||String(e.id).localeCompare(String(t.id)))}function Oe(e,t,n,r){let i=new Map,a=t?.positions?.find(t=>t.coin===e),o=a?.size.replace(/^-/,``),s=a?ie(a.size,`0`):null;if(n.position&&a&&s!==null&&s!==0){let n=Te(a.entryPrice),c=!Ee(t,`perps`,r);n!==null&&i.set(`position`,{price:n,color:c?`#a1a1aa`:s>0?Ce:we,lineWidth:2,lineStyle:R.Solid,axisLabelVisible:!0,title:`${c?`STALE · `:``}${s>0?`Long`:`Short`} · ${o} ${e} · P&L ${ie(a.unrealizedPnl,`0`)===1?`+`:``}${H(a.unrealizedPnl)} USDC`})}let c=new Map((t?.orders??[]).map(e=>[e.id,{order:e,pending:!1}])),l=e=>{for(let t of e.children??[])c.has(t.id)||c.set(t.id,{order:t,pending:!0}),l(t)};if(n.orders)for(let e of t?.orders??[])l(e);if(n.orders)for(let{order:n,pending:a}of c.values()){if(n.coin!==e)continue;let o=Te(n.triggerPrice??n.price);if(o===null)continue;let s=!Ee(t,`orders`,r),c=n.positionTpsl?`Entire position`:`${n.size} ${e}`;i.set(`order:${n.id}`,{price:o,color:s?`#a1a1aa`:n.side===`Buy`?Ce:we,lineWidth:1,lineStyle:n.triggerPrice===void 0?R.Dashed:R.Dotted,axisLabelVisible:!0,title:`${s?`STALE · `:``}${a?`Pending · `:``}${n.side} ${n.type}${n.triggerPrice===void 0?``:` trigger`} · ${c}`})}return i}function ke(e,t,n){let r=te(t,[],{autoScale:!1}),i=new Map,a=new Map,o=e=>{let t=e.hoveredInfo?.objectId,r=typeof t==`string`?a.get(t):void 0;n(r&&e.point?{fill:r,x:e.point.x,y:e.point.y}:null)};return e.subscribeCrosshairMove(o),{trades(e,t,i){a=new Map(e.map(e=>[e.id,e])),r.setMarkers(De(e,t,i)),n(null)},account(e,n,r,a){let o=Oe(e,n,r,a);for(let[e,n]of i)o.has(e)||(t.removePriceLine(n),i.delete(e));for(let[e,n]of o){let r=i.get(e);r?r.applyOptions(n):i.set(e,t.createPriceLine(n))}},close(){e.unsubscribeCrosshairMove(o),r.detach();for(let e of i.values())t.removePriceLine(e);i.clear()}}}var Ae=[];function je(e,t,n,r,i){let[a,o]=(0,Z.useState)({id:e,snapshot:null,interrupted:!1}),[s,c]=(0,Z.useState)(0),l=i.position||i.orders,{interrupted:u,streamErrors:d,reconnect:f}=le();de(`dashboard`,t=>{o({id:e,snapshot:JSON.parse(t.data),interrupted:!1})},l),(0,Z.useEffect)(()=>{o({id:e,snapshot:null,interrupted:!1})},[e,l,s]),(0,Z.useEffect)(()=>{l&&(d.dashboard||u)&&o(e=>e.interrupted?e:{...e,interrupted:!0})},[l,u,d]);let p=ye({...j(e,t,n,r),enabled:i.trades&&r>n}),{hasNextPage:m,isFetching:h,isError:g,fetchNextPage:_}=p;(0,Z.useEffect)(()=>{i.trades&&m&&!h&&!g&&_()},[i.trades,m,h,g,_]);let v=(0,Z.useMemo)(()=>{if(!p.data)return Ae;let e=new Map;for(let t of p.data.pages)for(let n of t.fills)e.set(n.id,n);return[...e.values()]},[p.data]),y=a.id===e?a.snapshot:null,b=[];if(l&&(y?(i.position&&!Ee(y,`perps`,a.interrupted)&&b.push(`Position data stale`),i.orders&&!Ee(y,`orders`,a.interrupted)&&b.push(`Order data stale`)):b.push(a.interrupted?`Account unavailable · Retry to reconnect`:`Connecting account…`)),i.trades&&r>n){g?b.push(`Trade history unavailable · displayed markers may be stale`):(p.isPending||m)&&b.push(`Loading trade history…`);let e=p.data?.pages[0];e&&(!e.sync?.updatedAt||e.sync.error)&&b.push(`Trade journal syncing or unavailable · history may be incomplete`),e?.historyLimited&&b.push(`Exchange history is limited · showing available journal fills`)}return{snapshot:y,interrupted:a.interrupted,fills:v,messages:b,canRetry:l&&a.interrupted||i.trades&&g,retry:()=>{c(e=>e+1),f(),i.trades&&p.refetch()}}}function Me(e,t){let n=W[t.document.interval],[r,i]=(0,Z.useState)(()=>Date.now());(0,Z.useEffect)(()=>{let e,t=()=>{i(Date.now()),e=setTimeout(t,n-Date.now()%n+1e3)};return t(),()=>clearTimeout(e)},[n]);let a=Math.floor(r/n)*n,o=C({...I(e,t.id,t.revision,t.document.coin,t.document.interval,a),enabled:t.document.indicators.some(e=>!e.hidden)}),s=JSON.stringify([t.id,t.document.coin,t.document.interval,t.document.indicators]),c=(0,Z.useRef)(void 0);(0,Z.useEffect)(()=>{o.data&&(c.current={identity:s,data:o.data})},[s,o.data]);let l=o.data??(c.current?.identity===s?c.current.data:void 0);return{data:l,status:o.isError?`error`:o.isFetching||l?.end!==a?l?`stale`:`loading`:`current`,error:o.error?.message,retry:()=>{o.refetch()}}}function Ne({id:e,layout:t,tool:n,selected:r,disabled:a,statusHost:o,overlayVisibility:s=Se,onSelect:c,onSave:l,onDrawn:u,onEdit:d,ref:f}){let p=i(),m=Me(e,t),[h,g]=(0,Z.useState)(null),_=(0,Z.useRef)(null),v=(0,Z.useRef)(null),y=(0,Z.useRef)(null),[b,x]=(0,Z.useState)(`connecting`),[S,C]=(0,Z.useState)(``),[w,T]=(0,Z.useState)(`Loading candles…`),[E,O]=(0,Z.useState)(0),[k,A]=(0,Z.useState)(0),[j,M]=(0,Z.useState)(null),{coin:N,interval:P}=t.document,{interrupted:F,streamErrors:I,reconnect:L}=le(),R=I.chart,te=(0,Z.useRef)(()=>{});ue(N,P,e=>{te.current(JSON.parse(e.data))}),(0,Z.useEffect)(()=>{if(R){let e=y.current;e&&(e.status=`reconnecting`),x(`reconnecting`)}else if(F){let e=y.current;e&&(e.status=`reconnecting`),x(`reconnecting`)}},[R,F]),(0,Z.useEffect)(()=>{let t=_.current;if(!t)return;let n=!1,r=!1,i=!1,a=!0,o=!1,s=0,c=ee(t,{autoSize:!0,layout:{background:{type:z.Solid,color:`#0d0d10`},textColor:`#a1a1aa`,attributionLogo:!0},grid:{vertLines:{color:`#1c1c22`},horzLines:{color:`#1c1c22`}},rightPriceScale:{borderColor:`#27272a`},timeScale:{timeVisible:!0,secondsVisible:!1,borderColor:`#27272a`}}),l=c.addSeries(ne,{upColor:`#34d399`,downColor:`#f87171`,borderVisible:!1,wickUpColor:`#34d399`,wickDownColor:`#f87171`});l.priceScale().applyOptions({scaleMargins:{top:.06,bottom:.25}});let u=c.addSeries(re,{priceFormat:{type:`volume`},priceScaleId:`volume`});u.priceScale().applyOptions({scaleMargins:{top:.8,bottom:0},visible:!1});let d=ke(c,l,M),f=V(c,l),m={chart:c,price:l,candles:[],status:`connecting`,overlays:d,indicators:f,evidence:[]},h=e=>{let t=e.hoveredInfo?.objectId,n=typeof t==`string`?f.describe(t):void 0;g(typeof t==`string`&&n!==void 0?{id:t,text:n}:null)};c.subscribeCrosshairMove(h),y.current=m;let v=()=>{s||n||(s=requestAnimationFrame(()=>{s=0,n||A(e=>e+1)}))},b=()=>{let e=m.candles.at(-1)?.close;if(e&&e>0){let t=Math.min(12,Math.max(2,5-Math.floor(Math.log10(e))));l.applyOptions({priceFormat:{type:`price`,precision:t,minMove:10**-t}})}l.setData(m.candles.map(e=>({...e,time:e.time}))),u.setData(m.candles.map(e=>({time:e.time,value:e.volume,color:e.close>=e.open?`#34d39960`:`#f8717160`}))),v()},S=async t=>{if(!(n||r||!a)){r=!0,T(`Loading candles…`);try{let r=await p.fetchQuery(D(e,N,P,t));if(n)return;let s=c.timeScale().getVisibleLogicalRange(),l=m.candles[0]?.time;m.candles=ae(r.candles,m.candles);let u=l===void 0?0:m.candles.filter(e=>e.time<l).length;a=r.hasMore&&(t===void 0||u>0),b(),!i&&m.candles.length?c.timeScale().setVisibleLogicalRange({from:Math.max(0,m.candles.length-120),to:m.candles.length+3}):s&&u&&c.timeScale().setVisibleLogicalRange({from:s.from+u,to:s.to+u}),i=!0,o=!1,T(a?``:`No older candles available from Hyperliquid.`)}catch(e){n||(o=!0,C(e instanceof Error?e.message:`Candle history is unavailable.`),T(`History unavailable. Retry to reload.`))}finally{r=!1}}},w=e=>{v(),e&&e.from<50&&i&&!o&&m.candles.length&&S(m.candles[0].time*1e3)};return c.timeScale().subscribeVisibleLogicalRangeChange(w),c.timeScale().subscribeSizeChange(v),c.subscribeCrosshairMove(v),t.addEventListener(`pointermove`,v,{passive:!0}),t.addEventListener(`wheel`,v,{passive:!0}),te.current=e=>{if(n)return;m.status=e.status,x(e.status);let t=m.candles.length;if(m.candles=ae(m.candles,e.candles),!i||m.candles.length!==t)b();else{for(let t of e.candles)l.update({...t,time:t.time},!0),u.update({time:t.time,value:t.volume,color:t.close>=t.open?`#34d39960`:`#f8717160`},!0);v()}},C(``),S(),()=>{n=!0,y.current=null,te.current=()=>{},cancelAnimationFrame(s),t.removeEventListener(`pointermove`,v),t.removeEventListener(`wheel`,v),c.timeScale().unsubscribeVisibleLogicalRangeChange(w),c.timeScale().unsubscribeSizeChange(v),c.unsubscribeCrosshairMove(v),c.unsubscribeCrosshairMove(h),f.close(),d.close(),c.remove()}},[p,e,N,P,E]);let B=y.current,H=B?.candles,ie=W[P]/1e3,U=je(e,N,(H?.[0]?.time??0)*1e3,H?.length?(H.at(-1).time+ie)*1e3:0,s);(0,Z.useEffect)(()=>{B&&B===y.current&&H&&B.overlays.trades(s.trades?U.fills:[],H,ie)},[B,H,ie,U.fills,s.trades]),(0,Z.useEffect)(()=>{B&&B===y.current&&B.overlays.account(N,U.snapshot,s,U.interrupted)},[B,N,U.snapshot,U.interrupted,s]),(0,Z.useEffect)(()=>{if(!B||B!==y.current||!H?.length)return;let e=t.document.indicators;for(let t of B.evidence)e.some(e=>e.id===t.configuration.id&&!e.hidden)||B.indicators.remove(t.configuration.id);B.evidence=e.filter(e=>!e.hidden).map(e=>{let t=m.data?.instances.find(t=>t.instanceId===e.id);if(t?.result)try{B.indicators.apply(e,t.result,H)}catch(t){return B.indicators.remove(e.id),{configuration:e,status:`error`,error:t instanceof Error?t.message:`Unable to render indicator`}}else B.indicators.remove(e.id);return{configuration:e,result:t?.result,status:t?.error?`error`:m.status,error:t?.error??m.error}})},[B,H,t.document.indicators,m.data,m.status,m.error]);let oe=B?Ie(B,W[P]/1e3):null,se={capture:async(e,t,n)=>{let r=y.current;if(!r?.candles.length)throw Error(`Wait for chart candles before sending chart context.`);let i=r.chart.timeScale().getVisibleLogicalRange();if(!i)throw Error(`Chart viewport is not ready.`);let a=W[e.document.interval]/1e3,o=Pe(r.candles,i.from,a),s=Pe(r.candles,i.to,a),c=r.candles.filter(e=>e.time>=o&&e.time<=s);if(c.length>1500)throw Error(`Zoom in to at most 1,500 visible candles before sending chart context.`);let l={layoutId:e.id,revision:e.revision,capturedAt:Date.now(),status:r.status,range:{from:Math.max(0,o),to:s},candles:c,indicators:r.evidence.map(({configuration:e,result:t,status:n,error:r})=>({instanceId:e.id,indicatorId:e.indicatorId,configuration:e,status:n,...r?{error:r.slice(0,1e3)}:{},...t?{result:{version:t.version,sourceHash:t.sourceHash,engine:t.engine,wrapperVersion:t.wrapperVersion,resultHash:t.resultHash,resolvedInputs:t.resolvedInputs,inputSchemaHash:t.inputSchemaHash,computedAt:t.computedAt,end:t.end,dataset:t.dataset,coverage:t.coverage,sampleScope:`partial-visible`,sample:t.values.filter(e=>e.time>=o&&e.time<=s).slice(-20),objects:[...t.markers.filter(e=>e.displayTime>=o&&e.displayTime<=s).map(e=>({id:e.id,kind:e.kind,time:e.time,text:e.text??e.character})),...t.drawings.map(e=>({id:e.id,kind:e.kind,time:e.kind===`label`?e.at.time:e.from.time,text:e.kind===`line`?void 0:e.text})).filter(e=>e.time>=o&&e.time<=s)].slice(-20)}}:{}})),...h?{selectedGeneratedObjectId:h.id}:{},...t?{selectedDrawingId:t}:{}};if(n&&(l.image=await Le(r.chart.takeScreenshot(),v.current)),new TextEncoder().encode(JSON.stringify(l)).byteLength>9e5)throw Error(`Chart context is too large. Zoom in or disable Include chart image.`);return l}};(0,Z.useEffect)(()=>{if(typeof f==`function`)return f(se),()=>{f(null)};if(f)return f.current=se,()=>{f.current=null}});let G=t.document.indicators.some(e=>!e.hidden)?[m.status===`current`?``:`Indicators: ${m.status===`stale`?`waiting for closed candle`:m.status}`,m.error,...m.data?.instances.flatMap(e=>e.error?[e.error]:[])??[]].filter(e=>!!e):[],K=[b===`reconnecting`?`Reconnecting… Data may be stale.`:``,w,S,R??``,...G,...U.messages].filter(Boolean),q=G.length>0&&!!(m.error||m.data?.instances.some(e=>e.error)),ce=!!(S||q||U.canRetry),J=b!==`live`||ce||G.length>0||U.messages.length>0||w===`Loading candles…`,Y=b===`reconnecting`,X=Y?`Disconnected`:J?`Loading`:`Connected`;return(0,Q.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col gap-2`,"data-frame":k,children:[o&&(0,be.createPortal)((0,Q.jsxs)(`details`,{className:`relative`,children:[(0,Q.jsx)(`summary`,{className:`flex cursor-pointer list-none items-center gap-2 whitespace-nowrap text-xs text-zinc-400 [&::-webkit-details-marker]:hidden`,title:K.join(`
3
3
  `)||`All chart data is up to date. Click for details.`,children:(0,Q.jsxs)(`span`,{role:`status`,"aria-label":`Chart connection`,title:K.join(`
4
4
  `)||void 0,className:`inline-flex items-center gap-2`,children:[(0,Q.jsx)(`span`,{"aria-hidden":`true`,className:`inline-block h-2 w-2 rounded-full ${Y?`bg-red-400`:J?`bg-amber-400`:`bg-emerald-400`}`}),X,K.length>0&&(0,Q.jsxs)(`span`,{className:`sr-only`,children:[` · `,K.join(` · `)]})]})}),(0,Q.jsxs)(`div`,{"aria-label":`Chart data status`,className:`absolute right-0 top-full z-50 mt-2 w-80 max-w-[calc(100vw-2rem)] space-y-3 rounded-xl border border-zinc-700 bg-zinc-950 p-4 text-sm text-zinc-300 shadow-xl`,children:[(0,Q.jsx)(`h3`,{className:`font-medium text-white`,children:`Chart status`}),(0,Q.jsxs)(`p`,{children:[`Market stream: `,b===`live`?`Connected`:b===`connecting`?`Connecting…`:`Disconnected`]}),K.length?(0,Q.jsx)(`ul`,{className:`space-y-2`,children:K.map((e,t)=>(0,Q.jsx)(`li`,{children:e},t))}):(0,Q.jsx)(`p`,{children:`All chart data is up to date.`}),(0,Q.jsxs)(`div`,{className:`flex flex-wrap gap-3`,children:[(S||b===`reconnecting`)&&(0,Q.jsx)(`button`,{type:`button`,className:`cursor-pointer underline`,onClick:()=>{x(`connecting`),O(e=>e+1),L()},children:`Retry chart`}),G.length>0&&(0,Q.jsx)(`button`,{type:`button`,className:`cursor-pointer underline`,onClick:m.retry,children:`Retry indicators`}),U.canRetry&&(0,Q.jsx)(`button`,{type:`button`,className:`cursor-pointer underline`,onClick:U.retry,children:`Retry account data`})]})]})]}),o),(0,Q.jsxs)(`div`,{className:`relative min-h-64 flex-1 overflow-hidden rounded-xl border border-zinc-800`,"aria-label":`${N} ${P} candlestick and volume chart`,children:[(0,Q.jsx)(`div`,{ref:_,className:`absolute inset-0 z-0`}),h&&(0,Q.jsxs)(`div`,{role:`tooltip`,className:`pointer-events-none absolute left-2 top-2 z-20 max-w-[calc(100%-5rem)] rounded bg-zinc-950/85 px-2 py-1 text-xs text-zinc-300`,children:[`Read-only Pine object: `,h.text]}),j&&s.trades&&(0,Q.jsxs)(`div`,{role:`tooltip`,"aria-label":`Trade fill`,className:`pointer-events-none absolute z-20 max-w-72 rounded-lg border border-zinc-700 bg-zinc-950 px-3 py-2 text-xs text-zinc-200 shadow-xl`,style:{left:Math.max(0,Math.min(j.x+12,(oe?.width??300)-280)),top:Math.max(0,Math.min(j.y+12,(oe?.height??100)-70))},children:[(0,Q.jsxs)(`p`,{className:j.fill.side===`Buy`?`text-emerald-400`:`text-red-400`,children:[j.fill.side,` · `,j.fill.size,` `,N,` @ `,j.fill.price]}),(0,Q.jsx)(`time`,{dateTime:new Date(j.fill.time).toISOString(),children:new Date(j.fill.time).toLocaleString()})]}),oe&&(0,Q.jsx)(xe,{document:t.document,revision:t.revision,projection:oe,tool:n,selected:r,disabled:a,svgRef:v,onSelect:c,onSave:l,onDrawn:u,onEdit:d},`${t.id}/${N}/${P}/${n}`)]})]})}function Pe(e,t,n){if(!e.length)return 0;let r=Math.floor(t),i=e[Math.max(0,Math.min(e.length-1,r))];return t<0?e[0].time+t*n:r>=e.length-1?i.time+(t-e.length+1)*n:i.time+(e[r+1].time-i.time)*(t-r)}function Fe(e,t,n){if(!e.length)return 0;if(t<e[0].time)return(t-e[0].time)/n;let r=0,i=e.length-1;for(;r<i;){let n=Math.ceil((r+i)/2);e[n].time<=t?r=n:i=n-1}return r+(t-e[r].time)/(e[r+1]?e[r+1].time-e[r].time:n)}function Ie(e,t){let{chart:n,price:r,candles:i}=e,a=n.timeScale(),o=e=>{let t=Math.floor(e),n=e-t,r=a.logicalToCoordinate(t);if(r===null||n===0)return r;let i=a.logicalToCoordinate(t+1);return i===null?null:r+(i-r)*n};return{width:Math.max(0,n.chartElement().clientWidth-n.priceScale(`right`).width()),height:Math.max(0,n.panes()[0]?.getHeight()??n.chartElement().clientHeight-a.height()),x:e=>o(Fe(i,e,t)),y:e=>r.priceToCoordinate(e),point:(e,n,s)=>{let c=a.coordinateToLogical(e),l=r.coordinateToPrice(n);if(c===null||l===null||l<=0)return null;let u=Math.floor(c),d=o(u),f=o(u+1);if(d===null||f===null||d===f)return null;let p=u+(e-d)/(f-d),m=i[Math.round(p)];if(s&&m){let e=[m.open,m.high,m.low,m.close].reduce((e,t)=>Math.abs(e-l)<Math.abs(t-l)?e:t);return{time:m.time,price:e}}return{time:Math.max(0,Pe(i,p,t)),price:l}}}}async function Le(e,t){let n=e.getContext(`2d`);if(!n)throw Error(`Chart screenshot is unavailable in this browser.`);if(t){let r=t.cloneNode(!0);r.querySelectorAll(`[data-handle]`).forEach(e=>e.remove());let i=URL.createObjectURL(new Blob([new XMLSerializer().serializeToString(r)],{type:`image/svg+xml`}));try{let r=new Image;r.src=i,await r.decode();let a=e.width/Math.max(1,e.clientWidth||e.width/window.devicePixelRatio);n.drawImage(r,0,0,Number(t.getAttribute(`width`))*a,Number(t.getAttribute(`height`))*a)}finally{URL.revokeObjectURL(i)}}let r=document.createElement(`canvas`);for(let t of[1600,1e3,700]){let n=Math.min(1,t/e.width,1e3/e.height);r.width=Math.round(e.width*n),r.height=Math.round(e.height*n),r.getContext(`2d`).drawImage(e,0,0,r.width,r.height);let i=r.toDataURL(`image/png`).split(`,`)[1];if(i.length<=7e5)return i}throw Error(`Chart image is too large. Zoom in or disable Include chart image.`)}function Re(e,t){let n=i(),{data:r}=w(E(e)),[a,o]=(0,Z.useState)(r[0]?.id??``),s=S({mutationFn:e=>e()}),c=s.isPending,l=s.error?.message,[u,d]=(0,Z.useState)(``),[f,p]=(0,Z.useState)(!1),m=(0,Z.useRef)(!1),h=(0,Z.useRef)(!0),g=(0,Z.useRef)(0),_=`hypervibes:chart-layout:${e}`,v=(0,Z.useEffectEvent)(()=>{try{let e=localStorage.getItem(_);e&&r.some(t=>t.id===e)&&o(e)}catch{}}),{interrupted:y,controlMessage:b,streamErrors:x}=le();de(`chart-layouts`,t=>{g.current++;let r=JSON.parse(t.data);n.setQueryData(E(e).queryKey,(e=[])=>{let t=new Map(e.map(e=>[e.id,e]));return r.map(e=>{let n=t.get(e.id);return n&&n.revision>e.revision?n:e})}),p(!0),d(``)}),(0,Z.useEffect)(()=>{let e=x[`chart-layouts`];e?d(e):y&&d(b||`Chart layout connection interrupted. Reconnecting…`)},[y,b,x]),(0,Z.useEffect)(()=>(h.current=!0,v(),()=>{h.current=!1,g.current++}),[n,e]);async function C(e){if(m.current)return;m.current=!0;let t=g.current;try{return await s.mutateAsync(()=>e(t))}catch{return}finally{m.current=!1}}function D(e){o(e);try{localStorage.setItem(_,e)}catch{}}function k(t,r=!1){h.current&&n.setQueryData(E(e).queryKey,(e=[])=>{let n=e.find(e=>e.id===t.id);return r&&!n||n&&n.revision>=t.revision?e:[t,...e.filter(e=>e.id!==t.id)]})}let j=r.find(e=>e.id===a)??r[0];async function M(n,r=!1,i){let a=i;return C(async i=>{a??=U();let o=await O({data:{id:e,layoutId:a,settings:{name:n,...r?{}:{coin:t.includes(`BTC`)?`BTC`:t[0]??`BTC`,interval:`1h`}},...r&&j?{sourceId:j.id}:{}}});return g.current===i&&k(o),h.current&&D(o.id),o})}let N=(0,Z.useRef)(!1),P=(0,Z.useEffectEvent)(()=>{M(`My chart`)});(0,Z.useEffect)(()=>{!f||N.current||!t.length||(N.current=!0,r.length||P())},[f,r.length,t.length]);async function F(t,n){if(!j)return;let r;return C(async i=>{r??=U();let a=await T({data:{id:e,layoutId:j.id,revision:j.revision,requestId:r,action:t,edit:n}});return k(a,g.current!==i),a})}async function I(){j&&await C(async t=>{await A({data:{id:e,layoutId:j.id,revision:j.revision}}),h.current&&(g.current===t&&n.setQueryData(E(e).queryKey,e=>e?.filter(e=>e.id!==j.id)),o(``))})}return{layouts:r,layout:j,pending:c,error:l||u,ready:f,choose:D,create:M,remove:I,change:F}}function ze({value:e,pending:t,saveError:n,onCancel:r,onApply:i}){let[a,o]=(0,Z.useState)(e),[s,c]=(0,Z.useState)(``);async function l(){try{await i(q(a))&&r()}catch(e){c(e instanceof Error?e.message:`Invalid drawing settings`)}}return(0,Q.jsxs)(X,{title:`Drawing settings`,onCancel:r,onApply:()=>{l()},applyDisabled:t||e.locked,children:[(0,Q.jsxs)(`fieldset`,{disabled:t||e.locked,className:`space-y-4 disabled:opacity-50`,children:[(0,Q.jsxs)(`label`,{className:`block space-y-1 text-sm`,children:[`Name`,(0,Q.jsx)(`input`,{autoFocus:!0,className:Y,value:a.name,maxLength:100,onChange:e=>o({...a,name:e.target.value})})]}),(0,Q.jsxs)(`label`,{className:`block space-y-1 text-sm`,children:[`Text`,(0,Q.jsx)(`textarea`,{className:Y,value:a.text,rows:3,maxLength:1e3,onChange:e=>o({...a,text:e.target.value})})]}),(0,Q.jsxs)(`label`,{className:`block space-y-1 text-sm`,children:[`Group`,(0,Q.jsx)(`input`,{className:Y,value:a.group,maxLength:80,onChange:e=>o({...a,group:e.target.value})})]}),(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-4`,children:[(0,Q.jsxs)(`label`,{className:`flex items-center gap-2 text-sm`,children:[`Color`,(0,Q.jsx)(`input`,{type:`color`,className:`cursor-pointer`,value:a.color,onChange:e=>o({...a,color:e.target.value})})]}),(0,Q.jsxs)(`label`,{className:`flex items-center gap-2 text-sm`,children:[`Width`,(0,Q.jsx)(`select`,{className:`cursor-pointer rounded bg-zinc-900 p-2`,value:a.width,onChange:e=>o({...a,width:Number(e.target.value)}),children:[1,2,3,4,5].map(e=>(0,Q.jsx)(`option`,{children:e},e))})]}),(0,Q.jsxs)(`label`,{className:`cursor-pointer text-sm`,children:[(0,Q.jsx)(`input`,{type:`checkbox`,className:`mr-2 cursor-pointer`,checked:a.dashed,onChange:e=>o({...a,dashed:e.target.checked})}),`Dashed`]})]}),a.kind===`rectangle`&&(0,Q.jsxs)(`label`,{className:`block text-sm`,children:[`Fill opacity`,(0,Q.jsx)(`input`,{type:`range`,className:`ml-3 cursor-pointer`,min:`0`,max:`0.6`,step:`0.05`,value:a.fillOpacity,onChange:e=>o({...a,fillOpacity:Number(e.target.value)})})]}),(0,Q.jsxs)(`fieldset`,{className:`space-y-2`,children:[(0,Q.jsx)(`legend`,{className:`mb-2 text-sm`,children:`Coordinates · UTC seconds / price`}),a.points.map((e,t)=>(0,Q.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,Q.jsxs)(`label`,{className:`text-xs text-zinc-400`,children:[`Anchor `,t+1,` time`,(0,Q.jsx)(`input`,{type:`number`,step:`any`,className:Y,value:e.time,onChange:e=>o({...a,points:a.points.map((n,r)=>r===t?{...n,time:Number(e.target.value)}:n)})})]}),(0,Q.jsxs)(`label`,{className:`text-xs text-zinc-400`,children:[`Anchor `,t+1,` price`,(0,Q.jsx)(`input`,{type:`number`,step:`any`,className:Y,value:e.price,onChange:e=>o({...a,points:a.points.map((n,r)=>r===t?{...n,price:Number(e.target.value)}:n)})})]})]},t))]}),(0,Q.jsxs)(`fieldset`,{children:[(0,Q.jsx)(`legend`,{className:`mb-2 text-sm`,children:`Visible timeframes · none selected means all`}),(0,Q.jsx)(`div`,{className:`flex flex-wrap gap-3`,children:se.map(e=>(0,Q.jsxs)(`label`,{className:`cursor-pointer text-xs`,children:[(0,Q.jsx)(`input`,{type:`checkbox`,className:`mr-1 cursor-pointer`,checked:a.intervals.includes(e),onChange:t=>o({...a,intervals:t.target.checked?[...a.intervals,e]:a.intervals.filter(t=>t!==e)})}),e]},e))})]})]}),(s||n)&&(0,Q.jsx)(`p`,{role:`alert`,className:`mt-3 text-sm text-red-300`,children:s||n})]})}var Be=[{action:`new`,label:`New`},{action:`duplicate`,label:`Duplicate`},{action:`rename`,label:`Rename`},{action:`delete`,label:`Delete`},{action:`notes`,label:`Layout notes`}];function Ve({pending:e,hasLayout:t,onAction:n}){let[r,i]=(0,Z.useState)(!1),[a,o]=(0,Z.useState)({left:0,top:0}),s=(0,Z.useRef)(null),c=(0,Z.useRef)(null),l=(0,Z.useId)();return(0,Z.useLayoutEffect)(()=>{if(!r)return;let e=()=>{let e=s.current.getBoundingClientRect(),t=c.current.getBoundingClientRect();o({left:Math.max(8,Math.min(e.left,window.innerWidth-t.width-8)),top:Math.max(8,Math.min(e.bottom+6,window.innerHeight-t.height-8))})};return e(),c.current.querySelector(`button:not(:disabled)`)?.focus(),window.addEventListener(`resize`,e),window.addEventListener(`scroll`,e,!0),()=>{window.removeEventListener(`resize`,e),window.removeEventListener(`scroll`,e,!0)}},[r]),(0,Z.useEffect)(()=>{if(!r)return;let e=e=>{e.target instanceof Node&&!c.current?.contains(e.target)&&!s.current?.contains(e.target)&&i(!1)},t=e=>{e.key===`Escape`&&(e.preventDefault(),e.stopPropagation(),i(!1),s.current?.focus())};return document.addEventListener(`pointerdown`,e),document.addEventListener(`focusin`,e),document.addEventListener(`keydown`,t,!0),()=>{document.removeEventListener(`pointerdown`,e),document.removeEventListener(`focusin`,e),document.removeEventListener(`keydown`,t,!0)}},[r]),(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`button`,{ref:s,type:`button`,"aria-label":`Layout settings`,title:`Layout settings`,"aria-haspopup":`dialog`,"aria-expanded":r,"aria-controls":r?l:void 0,onClick:()=>i(!r),className:`flex size-8 shrink-0 cursor-pointer items-center justify-center rounded-lg border border-zinc-700 text-zinc-300 hover:bg-zinc-800 aria-expanded:bg-zinc-800`,children:(0,Q.jsxs)(`svg`,{"aria-hidden":`true`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:1.5,strokeLinecap:`round`,strokeLinejoin:`round`,className:`size-4`,children:[(0,Q.jsx)(`path`,{d:`m9 3-.7 2.4-2 .9-2.3-.6-2 3.5 1.6 1.8v2l-1.6 1.8 2 3.5 2.3-.6 2 .9L9 21h6l.7-2.4 2-.9 2.3.6 2-3.5-1.6-1.8v-2L22 9.2l-2-3.5-2.3.6-2-.9L15 3Z`}),(0,Q.jsx)(`circle`,{cx:`12`,cy:`12`,r:`3`})]})}),r&&(0,be.createPortal)((0,Q.jsx)(`div`,{ref:c,id:l,role:`dialog`,"aria-label":`Layout settings`,className:`fixed z-40 max-h-[calc(100dvh-1rem)] w-52 max-w-[calc(100vw-1rem)] overflow-y-auto rounded-xl border border-zinc-700 bg-zinc-950 p-1.5 shadow-2xl`,style:a,children:Be.map(({action:r,label:a})=>(0,Q.jsx)(`button`,{type:`button`,disabled:e||!t&&r!==`new`,"aria-label":r===`delete`?`Delete layout`:void 0,className:`block w-full cursor-pointer rounded-lg px-3 py-2 text-left text-sm hover:bg-zinc-800 disabled:cursor-not-allowed disabled:opacity-40 ${r===`delete`?`text-red-300`:`text-zinc-200`} ${r===`notes`?`mt-1 border-t border-zinc-800`:``}`,onClick:()=>{i(!1),s.current?.focus(),n(r)},children:a},r))}),document.body)]})}var He=`inline-flex h-8 w-8 cursor-pointer items-center justify-center rounded-lg text-zinc-400 hover:bg-zinc-800 hover:text-white disabled:cursor-not-allowed disabled:opacity-40`;function Ue({name:e}){return(0,Q.jsx)(`svg`,{"aria-hidden":`true`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:1.5,strokeLinecap:`round`,strokeLinejoin:`round`,className:`h-4 w-4`,children:(0,Q.jsx)(`path`,{d:{eye:`M2 12s3.5-7 10-7 10 7 10 7-3.5 7-10 7S2 12 2 12Z M15 12a3 3 0 1 1-6 0 3 3 0 0 1 6 0`,"eye-off":`m3 3 18 18 M10.6 5.1A12 12 0 0 1 12 5c6.5 0 10 7 10 7a17 17 0 0 1-3 4 M6.5 6.5A22 22 0 0 0 2 12s3.5 7 10 7a12 12 0 0 0 5.5-1.5 M10 10a3 3 0 0 0 4 4`,gear:`m9 3-.5 3-2 1-3-.5-2 3 2 2v2l-2 2 2 3 3-.5 2 1 .5 3h4l.5-3 2-1 3 .5 2-3-2-2v-2l2-2-2-3-3 .5-2-1L13 3Z M15 12a3 3 0 1 1-6 0 3 3 0 0 1 6 0`,trash:`M3 6h18 M9 6V3h6v3 M5 6l1 15h12l1-15 M10 10v7 M14 10v7`,up:`m6 12 6-6 6 6 M12 6v14`}[e]})})}function We({agentId:e,instances:t,disabled:n,onChange:r}){let[i,a]=(0,Z.useState)(!1),[o,s]=(0,Z.useState)(null),[c,l]=(0,Z.useState)(!1),[u,d]=(0,Z.useState)(``),[f,p]=(0,Z.useState)(``),[m,h]=(0,Z.useState)(0),g=C({...F(e,{query:f,offset:m,limit:20}),enabled:i}),_=[...new Set(t.map(e=>e.indicatorId))],v=ve({queries:_.map(t=>({...P(e,t),enabled:i}))});return(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(`button`,{type:`button`,className:J,"aria-label":`Indicators`,disabled:n,onClick:()=>a(!0),children:[`Indicators (`,t.length,`)`]}),i&&!o&&(0,Q.jsxs)(X,{title:`Chart indicators`,onCancel:()=>a(!1),onApply:()=>a(!1),applyLabel:`Done`,children:[t.length>0&&(0,Q.jsx)(`div`,{className:`overflow-x-auto rounded-xl border border-zinc-800`,children:(0,Q.jsxs)(`table`,{"aria-label":`Indicators on chart`,className:`w-full text-left text-sm`,children:[(0,Q.jsx)(`thead`,{className:`border-b border-zinc-800 text-zinc-400`,children:(0,Q.jsxs)(`tr`,{children:[(0,Q.jsx)(`th`,{scope:`col`,className:`px-4 py-3 font-medium`,children:`Indicator`}),(0,Q.jsx)(`th`,{scope:`col`,className:`px-4 py-3 text-right font-medium`,children:`Actions`})]})}),(0,Q.jsx)(`tbody`,{className:`divide-y divide-zinc-800`,children:t.map((e,i)=>{let a=v[_.indexOf(e.indicatorId)],o=a?.data?.descriptor.name??(a?.isError?`Unavailable indicator`:`Loading indicator…`),c=`${e.hidden?`Show`:`Hide`} ${o}`;return(0,Q.jsxs)(`tr`,{children:[(0,Q.jsx)(`td`,{className:`px-4 py-3 ${e.hidden?`text-zinc-500`:`text-zinc-200`}`,children:o}),(0,Q.jsx)(`td`,{className:`px-4 py-2`,children:(0,Q.jsxs)(`div`,{className:`flex justify-end gap-1`,children:[(0,Q.jsx)(`button`,{type:`button`,className:He,"aria-label":c,title:c,disabled:n,onClick:()=>{r(t.map(t=>t.id===e.id?{...t,hidden:!t.hidden}:t))},children:(0,Q.jsx)(Ue,{name:e.hidden?`eye-off`:`eye`})}),(0,Q.jsx)(`button`,{type:`button`,className:He,"aria-label":`Configure ${o}`,title:`Configure ${o}`,disabled:n,onClick:()=>{l(!1),s(e)},children:(0,Q.jsx)(Ue,{name:`gear`})}),(0,Q.jsx)(`button`,{type:`button`,className:He,"aria-label":`Move ${o} up`,title:`Move ${o} up`,disabled:n||i===0,onClick:()=>{let e=[...t];[e[i-1],e[i]]=[e[i],e[i-1]],r(e)},children:(0,Q.jsx)(Ue,{name:`up`})}),(0,Q.jsx)(`button`,{type:`button`,className:`${He} hover:text-red-300`,"aria-label":`Remove ${o}`,title:`Remove ${o}`,disabled:n,onClick:()=>{r(t.filter(t=>t.id!==e.id))},children:(0,Q.jsx)(Ue,{name:`trash`})})]})})]},e.id)})})]})}),(0,Q.jsxs)(`label`,{className:`my-3 block text-sm`,children:[`Search`,(0,Q.jsx)(`input`,{className:`block w-full rounded-xl border border-zinc-700 bg-zinc-950 p-3 text-sm text-white`,value:f,onChange:e=>{p(e.target.value),h(0)}})]}),(u||g.error)&&(0,Q.jsx)(`p`,{role:`alert`,children:u||g.error?.message}),(0,Q.jsx)(`ul`,{className:`space-y-2`,children:g.data?.indicators.map(e=>(0,Q.jsxs)(`li`,{className:`flex items-center justify-between gap-2 text-sm`,children:[(0,Q.jsxs)(`span`,{children:[e.name,` · `,e.builtIn?`Built-in`:`Custom · v${e.version}`]}),(0,Q.jsx)(`button`,{type:`button`,className:`cursor-pointer rounded-full border border-zinc-700 px-4 py-2 text-sm text-zinc-200 hover:bg-zinc-800 disabled:cursor-not-allowed disabled:opacity-50`,disabled:n||t.length>=10,onClick:()=>{try{let t=U();d(``),l(!0),s({id:t,indicatorId:e.id,configuredVersion:e.version,inputs:{},pane:`auto`,hidden:!1,styles:{}})}catch(e){d(e instanceof Error?e.message:`Unable to prepare the indicator`)}},children:`Add`})]},e.id))}),(0,Q.jsxs)(`div`,{className:`mt-3 flex gap-2`,children:[(0,Q.jsx)(`button`,{type:`button`,className:`cursor-pointer rounded-full border border-zinc-700 px-4 py-2 text-sm text-zinc-200 hover:bg-zinc-800 disabled:cursor-not-allowed disabled:opacity-50`,disabled:!m,onClick:()=>h(Math.max(0,m-20)),children:`Previous`}),(0,Q.jsx)(`button`,{type:`button`,className:`cursor-pointer rounded-full border border-zinc-700 px-4 py-2 text-sm text-zinc-200 hover:bg-zinc-800 disabled:cursor-not-allowed disabled:opacity-50`,disabled:g.data?.nextOffset==null,onClick:()=>h(g.data.nextOffset),children:`Next`})]})]}),o&&(0,Q.jsx)(Ge,{agentId:e,initial:o,adding:c,disabled:n||c&&t.length>=10,onCancel:()=>s(null),onApply:async e=>{await r(c?[...t,e]:t.map(t=>t.id===e.id?e:t))&&(s(null),c&&a(!1))}},o.id)]})}function Ge({agentId:e,initial:t,adding:n,disabled:r,onCancel:i,onApply:a}){let[o,s]=(0,Z.useState)(t),[c,l]=(0,Z.useState)(JSON.stringify(t.styles)),[u,d]=(0,Z.useState)(``),f=C(P(e,t.indicatorId));return(0,Q.jsxs)(X,{title:n?`Add indicator`:`Configure indicator`,applyLabel:n?`Add to chart`:`Apply`,onCancel:i,applyDisabled:r||!f.data,onApply:()=>{try{let e=JSON.parse(c);if(!e||typeof e!=`object`||Array.isArray(e))throw Error(`Styles must be an object keyed by output ID`);a({...o,configuredVersion:f.data.descriptor.version,styles:e}).catch(e=>d(e instanceof Error?e.message:`Unable to save settings`))}catch(e){d(e instanceof Error?e.message:`Invalid styles`)}},children:[f.data&&(0,Q.jsx)(me,{schema:f.data.descriptor.inputs,value:o.inputs,onChange:e=>s({...o,inputs:e}),disabled:r}),(0,Q.jsxs)(`details`,{className:`rounded-xl border border-zinc-800 p-3`,children:[(0,Q.jsx)(`summary`,{className:`cursor-pointer text-sm text-zinc-400 hover:text-white`,children:`Advanced options`}),(0,Q.jsxs)(`label`,{className:`my-3 block text-sm`,children:[`Pane`,(0,Q.jsxs)(`select`,{className:`${Y} cursor-pointer`,value:o.pane,onChange:e=>s({...o,pane:e.target.value}),children:[(0,Q.jsx)(`option`,{value:`auto`,children:`Default`}),(0,Q.jsx)(`option`,{value:`price`,children:`Price pane`}),(0,Q.jsx)(`option`,{value:`separate`,children:`Separate pane`})]})]}),(0,Q.jsxs)(`label`,{className:`block text-sm`,children:[`Output styles (JSON keyed by exact output ID)`,(0,Q.jsx)(`textarea`,{rows:4,className:`${Y} font-mono`,value:c,onChange:e=>l(e.target.value)})]}),(0,Q.jsxs)(`p`,{className:`text-xs text-zinc-500`,children:[`Example: `,`{"EMA":{"color":"#ff9900","width":2,"hidden":false}}`,`. display.none cannot be overridden.`]})]}),(u||f.error)&&(0,Q.jsx)(`p`,{role:`alert`,className:`text-red-300`,children:u||f.error?.message})]})}var Ke=`cursor-pointer rounded-lg border border-zinc-700 text-xs text-zinc-300 hover:bg-zinc-800 disabled:cursor-not-allowed disabled:opacity-40`,$=`${Ke} px-2.5 py-1.5`,qe=`${Ke} flex size-8 shrink-0 items-center justify-center aria-pressed:border-violet-700 aria-pressed:bg-violet-950/50 aria-pressed:text-violet-200`,Je={select:`Select`,horizontal:`Horizontal line`,"horizontal-ray":`Horizontal ray`,vertical:`Vertical line`,trend:`Trend line`,ray:`Ray`,extended:`Extended line`,rectangle:`Rectangle zone`,text:`Text`,callout:`Callout`,arrow:`Arrow`},Ye={select:`↖`,horizontal:`━`,"horizontal-ray":`╶`,vertical:`│`,trend:`╱`,ray:`↗`,extended:`⤢`,rectangle:`▭`,text:`T`,callout:`☷`,arrow:`➜`},Xe={magnet:`M5 3v10a7 7 0 0 0 14 0V3h-4v10a3 3 0 0 1-6 0V3ZM5 7h4m6 0h4`,eye:`M2 12s3-7 10-7 10 7 10 7-3 7-10 7S2 12 2 12Zm7 0a3 3 0 1 0 6 0 3 3 0 0 0-6 0`,hidden:`m3 3 18 18M10 5.2a12 12 0 0 1 2-.2c7 0 10 7 10 7a19 19 0 0 1-3 4M6 6.5A19 19 0 0 0 2 12s3 7 10 7a13 13 0 0 0 5-1`,tools:`m4 20 4-1L20 7l-4-4L4 15Zm10-15 4 4M4 15l4 4M14 16l5 5 3-3-5-5`,lock:`M6 10h12v11H6ZM8 10V6a4 4 0 0 1 8 0v4m-4 5v2`,unlock:`M6 10h12v11H6ZM8 10V6a4 4 0 0 1 8 0m-4 9v2`,account:`M3 6h18M3 12h18M3 18h18M7 3v6m10 0v6m-7 0v6`,chat:`M3 4h18v16H3ZM15 4v16m3-10 2 2-2 2`,chatHidden:`M3 4h18v16H3ZM15 4v16m-4-10-2 2 2 2`};function Ze({name:e}){return(0,Q.jsx)(`svg`,{"aria-hidden":`true`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:1.5,strokeLinecap:`round`,strokeLinejoin:`round`,className:`size-4`,children:(0,Q.jsx)(`path`,{d:Xe[e]})})}var Qe=240,$e=560;function et({id:e,instruments:t,initialChat:n,choices:r}){let{layouts:i,layout:a,pending:o,error:s,ready:c,choose:l,create:u,remove:d,change:f}=Re(e,t),[p,m]=(0,Z.useState)(`select`),[h,g]=(0,Z.useState)(``),[_,v]=(0,Z.useState)(!0),[y,b]=(0,Z.useState)(360),[x,S]=(0,Z.useState)(!1),[C,w]=(0,Z.useState)(!1),[T,E]=(0,Z.useState)(!1),[D,O]=(0,Z.useState)(null),[k,A]=(0,Z.useState)(!1),[j,M]=(0,Z.useState)(!1),[N,P]=(0,Z.useState)(Se),F=`hypervibes:chart-overlays:v1:${e}`;(0,Z.useEffect)(()=>{let e=Se;try{let t=JSON.parse(localStorage.getItem(F)??`null`);t&&typeof t==`object`&&`trades`in t&&typeof t.trades==`boolean`&&`position`in t&&typeof t.position==`boolean`&&`orders`in t&&typeof t.orders==`boolean`&&(e={trades:t.trades,position:t.position,orders:t.orders})}catch{}P(e)},[F]);let I=(0,Z.useRef)(null),L=(0,Z.useRef)(null),ee=(0,Z.useRef)(null),[R,te]=(0,Z.useState)($e),[ne,re]=(0,Z.useState)(null),z=Math.min(y,R),B=e=>Math.max(Qe,Math.min(R,e));(0,Z.useEffect)(()=>{if(!L.current||typeof ResizeObserver>`u`)return;let e=new ResizeObserver(([e])=>{e&&te(Math.max(Qe,Math.min($e,Math.floor(e.contentRect.width-292))))});return e.observe(L.current),()=>e.disconnect()},[]);let V=(0,Z.useRef)(null),H=`hypervibes:chart-panel:${e}`,[ie,U]=(0,Z.useState)(null);(0,Z.useEffect)(()=>{try{let e=JSON.parse(localStorage.getItem(H)??`null`);e&&typeof e==`object`&&(`open`in e&&typeof e.open==`boolean`&&v(e.open),`width`in e&&typeof e.width==`number`&&Number.isFinite(e.width)&&b(Math.max(Qe,Math.min($e,e.width))))}catch{}U(H)},[H]);function ae(e,t){v(e),b(t);try{localStorage.setItem(H,JSON.stringify({open:e,width:t}))}catch{}}let W=a?.document.drawings.find(e=>e.id===h&&e.coin===a.document.coin),G=a?.document.drawings.filter(e=>e.coin===a.document.coin)??[],K=G.length>0&&G.every(e=>e.locked),q=a?G.filter(e=>!e.hidden&&e.intervals.length>0&&!e.intervals.includes(a.document.interval)):[];async function J(e){return(await f(`edit`,{label:`Edit ${e.name}`,upsert:[e]}))?.revision}function Y(e){l(e),g(``),m(`select`),S(!1)}function X(e){e===`notes`?A(!0):e===`delete`?a&&window.confirm(`Delete saved layout “${a.document.name}”? Its chat messages remain available.`)&&d():O(e)}function le(e){if(e.target instanceof HTMLElement&&(e.target.matches(`input,textarea,select`)||e.target.isContentEditable)||document.querySelector(`dialog[open]`))return;if(e.key===`Escape`&&p!==`select`){e.preventDefault(),e.stopPropagation(),m(`select`);return}let t=e.key.toLowerCase();if((e.ctrlKey||e.metaKey)&&(t===`z`||t===`y`)){e.preventDefault();let n=t===`y`||e.shiftKey;!o&&(n?a?.canRedo:a?.canUndo)&&f(n?`redo`:`undo`)}(e.key===`Delete`||e.key===`Backspace`)&&W&&!W.locked&&!o&&(e.preventDefault(),f(`edit`,{label:`Delete ${W.name}`,remove:[W.id]}))}return t.length?ie!==H||!a&&!c?(0,Q.jsx)(`section`,{ref:L,"aria-label":`Trading chart`,"aria-busy":`true`,className:`flex h-[calc(100dvh-6rem)] min-h-[480px] w-full items-center justify-center rounded-xl border border-zinc-800 bg-[#0d0d10]`,children:(0,Q.jsx)(`p`,{role:`status`,className:`text-sm text-zinc-500`,children:`Loading chart workspace…`})}):(0,Q.jsxs)(`section`,{ref:L,"aria-label":`Trading chart`,onKeyDown:le,className:`flex h-[calc(100dvh-6rem)] min-h-[480px] w-full min-w-0 flex-col gap-2`,children:[(0,Q.jsx)(`h2`,{className:`sr-only`,children:`Chart workspace`}),(0,Q.jsxs)(`div`,{role:`toolbar`,"aria-label":`Chart controls`,className:`flex shrink-0 flex-nowrap items-center gap-1.5 overflow-x-auto pb-1`,children:[(0,Q.jsxs)(`select`,{"aria-label":`Layout`,value:a?.id??``,disabled:o,onChange:e=>Y(e.target.value),className:`${$} h-8 w-40 shrink-0 truncate bg-zinc-950`,children:[!i.length&&(0,Q.jsx)(`option`,{value:``,children:`No layouts`}),i.map(e=>(0,Q.jsx)(`option`,{value:e.id,children:e.document.name},e.id))]}),(0,Q.jsx)(Ve,{pending:o,hasLayout:!!a,onAction:X}),(0,Q.jsx)(pe,{instruments:t,value:a?.document.coin??null,disabled:o||!a,saveError:s,className:`${Ke} h-8 shrink-0 px-2`,onChange:async e=>a?e===a.document.coin?!0:await f(`edit`,{label:`Change instrument`,settings:{coin:e}})?(g(``),m(`select`),S(!1),!0):!1:!1},a?.id),(0,Q.jsxs)(`select`,{"aria-label":`Timeframe`,value:a?.document.interval??``,disabled:o||!a,onChange:e=>{oe(e.target.value)&&(m(`select`),f(`edit`,{label:`Change timeframe`,settings:{interval:e.target.value}}))},className:`${$} h-8 w-20 shrink-0 bg-zinc-950`,children:[!a&&(0,Q.jsx)(`option`,{value:``,children:`Timeframe`}),se.map(e=>(0,Q.jsx)(`option`,{children:e},e))]}),a&&(0,Q.jsx)(We,{agentId:e,instances:a.document.indicators,disabled:o,onChange:async e=>!!await f(`edit`,{label:`Configure indicators`,settings:{indicators:e}})}),(0,Q.jsx)(`button`,{type:`button`,className:qe,"aria-label":`Account overlays`,title:`Account overlays · Trades, position and orders (read-only)`,disabled:!a,onClick:()=>M(!0),children:(0,Q.jsx)(Ze,{name:`account`})}),(0,Q.jsx)(`button`,{type:`button`,className:qe,"aria-label":`Magnet`,"aria-pressed":a?.document.magnet??!1,disabled:o||!a,title:`${a?.document.magnet?`Magnet on`:`Magnet off`} · Snap to candle OHLC · Ctrl/Cmd temporarily inverts snapping`,onClick:()=>{a&&f(`edit`,{label:`Toggle magnet`,settings:{magnet:!a.document.magnet}})},children:(0,Q.jsx)(Ze,{name:`magnet`})}),(0,Q.jsx)(`button`,{type:`button`,className:qe,"aria-label":a?.document.hideDrawings?`Show drawings`:`Hide drawings`,"aria-pressed":!!(a&&!a.document.hideDrawings),disabled:o||!a,title:a?.document.hideDrawings?`Show drawings`:`Hide drawings`,onClick:()=>{a&&f(`edit`,{label:`Toggle drawings`,settings:{hideDrawings:!a.document.hideDrawings}})},children:(0,Q.jsx)(Ze,{name:a?.document.hideDrawings?`hidden`:`eye`})}),(0,Q.jsx)(`button`,{type:`button`,className:qe,"aria-label":T?`Hide annotation tools`:`Show annotation tools`,"aria-pressed":T,"aria-expanded":T,disabled:!a,title:T?`Hide annotation tools`:`Show annotation tools`,onClick:()=>{E(!T),m(`select`)},children:(0,Q.jsx)(Ze,{name:`tools`})}),(0,Q.jsx)(`button`,{type:`button`,className:qe,"aria-label":K?`Unlock objects`:`Lock objects`,"aria-pressed":K,disabled:o||!G.length,title:`${K?`Unlock`:`Lock`} all annotations for ${a?.document.coin??`this instrument`}`,onClick:()=>{f(`edit`,{label:K?`Unlock drawings`:`Lock drawings`,upsert:G.filter(e=>e.locked===K).map(e=>({...e,locked:!K}))})},children:(0,Q.jsx)(Ze,{name:K?`lock`:`unlock`})}),(0,Q.jsx)(`button`,{type:`button`,className:qe,"aria-label":_?`Hide chat`:`Show chat`,"aria-pressed":_,"aria-expanded":_,title:_?`Hide chat`:`Show chat`,onClick:()=>ae(!_,z),children:(0,Q.jsx)(Ze,{name:_?`chat`:`chatHidden`})}),(0,Q.jsx)(`div`,{ref:re,"aria-label":`Chart status`,className:`ml-auto flex h-8 shrink-0 items-center pl-2`})]}),(0,Q.jsx)(`span`,{role:`status`,className:`sr-only`,children:o?`Saving…`:s?`Not saved · see error`:a?`Saved`:c?`Create a layout to begin`:`Loading…`}),s&&(0,Q.jsx)(`p`,{role:`alert`,className:`text-sm text-amber-200`,children:s}),a&&!a.document.hideDrawings&&q.length>0&&(0,Q.jsxs)(`p`,{role:`status`,className:`flex flex-wrap items-center gap-2 text-xs text-amber-200`,children:[(0,Q.jsxs)(`span`,{children:[q.length,` `,q.length===1?`drawing`:`drawings`,` hidden on `,a.document.interval,` by timeframe settings.`]}),(0,Q.jsx)(`button`,{type:`button`,className:$,disabled:o||q.every(e=>e.locked),title:`Remove timeframe restrictions from these unlocked drawings. Locked drawings are unchanged.`,onClick:()=>{f(`edit`,{label:`Show drawings on all timeframes`,upsert:q.filter(e=>!e.locked).map(e=>({...e,intervals:[]}))})},children:`Show on all timeframes`})]}),(0,Q.jsxs)(`div`,{"aria-label":`Chart and chat workspace`,className:`flex min-h-0 flex-1 overflow-x-auto`,children:[(0,Q.jsxs)(`div`,{className:`flex min-w-[280px] flex-1 gap-2`,children:[a&&T&&(0,Q.jsxs)(`div`,{role:`toolbar`,"aria-label":`Drawing tools`,className:`flex w-11 shrink-0 flex-col gap-1 overflow-y-auto`,children:[[`select`,...ce].map(e=>(0,Q.jsx)(`button`,{type:`button`,"aria-label":Je[e],title:`${Je[e]}${e===`select`?``:` · click to place anchors`}`,"aria-pressed":p===e,disabled:o,onClick:()=>{m(e),g(``)},className:`${Ke} py-1.5 text-lg ${p===e?`border-violet-500 bg-violet-950/50 text-violet-200`:``}`,children:Ye[e]},e)),(0,Q.jsx)(`button`,{type:`button`,className:`${Ke} py-1.5`,"aria-label":`Keep drawing`,"aria-pressed":C,title:`Keep drawing after placing an object`,onClick:()=>w(!C),children:`∞`})]}),a?(0,Q.jsxs)(`div`,{ref:ee,tabIndex:0,"aria-label":`Chart canvas`,onPointerDown:e=>{(!(e.target instanceof Element)||!e.target.closest(`button,input,textarea,select`))&&e.currentTarget.focus()},className:`flex min-w-0 flex-1 flex-col outline-none focus-visible:ring-1 focus-visible:ring-violet-500`,children:[(0,Q.jsx)(Ne,{ref:I,id:e,layout:a,tool:p,selected:h,disabled:o,statusHost:ne,overlayVisibility:N,onSelect:e=>{g(e),ee.current?.focus({preventScroll:!0})},onSave:J,onDrawn:()=>{C||m(`select`)},onEdit:()=>S(!0)},`${a.id}/${a.document.coin}/${a.document.interval}`),(T||W)&&(0,Q.jsxs)(`div`,{className:`flex min-h-8 flex-wrap items-center gap-2 py-1 text-xs text-zinc-500`,children:[T&&(0,Q.jsxs)(`span`,{children:[Je[p],p===`select`?` · Select an object or draw from the toolbar`:` · Click anchors · Esc cancels`]}),W&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`span`,{className:`text-violet-300`,children:W.name}),(0,Q.jsx)(`button`,{className:$,disabled:o||W.locked,onClick:()=>S(!0),children:`Settings`}),(0,Q.jsx)(`button`,{className:$,disabled:o,onClick:()=>{J({...W,locked:!W.locked})},children:W.locked?`Unlock`:`Lock`}),(0,Q.jsx)(`button`,{className:$,disabled:o||W.locked,onClick:()=>{f(`edit`,{label:`Delete ${W.name}`,remove:[W.id]})},children:`Delete`})]})]})]}):(0,Q.jsx)(`p`,{className:`p-4 text-sm text-zinc-500`,children:`Create a layout from the layout settings to begin.`})]}),(0,Q.jsx)(`aside`,{hidden:!_,"aria-label":`Chart chat panel`,className:`min-h-0 shrink-0`,style:{width:z+12},children:(0,Q.jsxs)(`div`,{className:`flex h-full min-h-0`,children:[(0,Q.jsx)(`div`,{role:`separator`,"aria-label":`Resize chart chat`,"aria-orientation":`vertical`,"aria-valuemin":Qe,"aria-valuemax":R,"aria-valuenow":z,"aria-valuetext":`${z}px chat width`,tabIndex:0,className:`flex w-3 shrink-0 cursor-col-resize touch-none items-center justify-center rounded hover:bg-zinc-800 focus-visible:ring-1 focus-visible:ring-violet-500`,onKeyDown:e=>{let t=e.key===`ArrowLeft`?20:e.key===`ArrowRight`?-20:0;(t||e.key===`Home`||e.key===`End`)&&(e.preventDefault(),ae(!0,e.key===`Home`?Qe:e.key===`End`?R:B(z+t)))},onPointerDown:e=>{e.button===0&&(e.preventDefault(),V.current={x:e.clientX,width:z,pointerId:e.pointerId},e.currentTarget.setPointerCapture(e.pointerId))},onPointerMove:e=>{let t=V.current;t&&t.pointerId===e.pointerId&&b(B(t.width+t.x-e.clientX))},onPointerUp:e=>{let t=V.current;!t||t.pointerId!==e.pointerId||(V.current=null,e.currentTarget.hasPointerCapture(e.pointerId)&&e.currentTarget.releasePointerCapture(e.pointerId),ae(!0,B(t.width+t.x-e.clientX)))},onPointerCancel:e=>{let t=V.current;t&&t.pointerId===e.pointerId&&(b(t.width),V.current=null,e.currentTarget.hasPointerCapture(e.pointerId)&&e.currentTarget.releasePointerCapture(e.pointerId))},onLostPointerCapture:e=>{let t=V.current;t&&t.pointerId===e.pointerId&&(b(t.width),V.current=null)},children:(0,Q.jsx)(`span`,{className:`h-12 w-1 rounded bg-zinc-700`})}),(0,Q.jsx)(`div`,{className:`min-h-0 min-w-0 flex-1`,children:(0,Q.jsx)(fe,{initial:n,choices:r,embedded:!0,visible:_,chartContext:a?{label:`${a.document.name} · ${a.document.coin} · ${a.document.interval}${p===`select`?``:` · Finish drawing or choose Select before sending`}`,disabled:o||p!==`select`,capture:async e=>{if(!I.current)throw Error(`Chart is not ready`);return I.current.capture(a,W?.id??``,e)}}:void 0})})]})})]}),x&&W&&a&&(0,Q.jsx)(ze,{value:W,pending:o,saveError:s,onCancel:()=>S(!1),onApply:async e=>await J(e)!==void 0},`${a.id}/${a.revision}/${h}`),j&&(0,Q.jsx)(tt,{value:N,onCancel:()=>M(!1),onApply:e=>{P(e),M(!1);try{localStorage.setItem(F,JSON.stringify(e))}catch{}}}),k&&a&&(0,Q.jsx)(nt,{notes:a.document.notes,pending:o,error:s,onCancel:()=>A(!1),onApply:async e=>{await f(`edit`,{label:`Update layout notes`,settings:{notes:e}})&&A(!1)}},a.id),D&&(0,Q.jsx)(rt,{title:D===`new`?`New layout`:D===`duplicate`?`Duplicate layout`:`Rename layout`,initial:D===`new`?`My chart`:`${a?.document.name??`Chart`}${D===`duplicate`?` copy`:``}`,pending:o,error:s,onCancel:()=>O(null),onApply:async(e,t)=>{(D===`rename`?await f(`edit`,{label:`Rename layout`,settings:{name:e}}):await u(e,D===`duplicate`,t))&&(O(null),g(``))}},D)]}):(0,Q.jsx)(`p`,{role:`alert`,className:`text-amber-200`,children:`No perpetual instruments are available.`})}function tt({value:e,onApply:t,onCancel:n}){let[r,i]=(0,Z.useState)(e);return(0,Q.jsxs)(X,{title:`Account overlays`,onCancel:n,onApply:()=>t(r),children:[(0,Q.jsx)(`div`,{className:`space-y-3 text-sm`,children:[[`trades`,`Historical buys & sells`],[`position`,`Current position`],[`orders`,`Open orders & TP/SL triggers`]].map(([e,t])=>(0,Q.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-3`,children:[(0,Q.jsx)(`input`,{type:`checkbox`,checked:r[e],onChange:t=>i({...r,[e]:t.target.checked}),className:`cursor-pointer accent-violet-500`}),t]},e))}),(0,Q.jsx)(`p`,{className:`mt-4 text-xs text-zinc-500`,children:`Read-only data from this Agent’s linked Hyperliquid account, including manual trades. History follows the journal. Visibility is saved on this device, independently of layouts and annotations.`})]})}function nt({notes:e,pending:t,error:n,onApply:r,onCancel:i}){let[a,o]=(0,Z.useState)(e);return(0,Q.jsxs)(X,{title:`Layout notes`,applyLabel:`Save notes`,applyDisabled:t,onCancel:i,onApply:()=>{r(a)},children:[(0,Q.jsxs)(`label`,{className:`block space-y-2 text-sm`,children:[`Notes`,(0,Q.jsx)(`textarea`,{autoFocus:!0,rows:6,maxLength:8e3,className:Y,value:a,disabled:t,onChange:e=>o(e.target.value)})]}),(0,Q.jsx)(`p`,{className:`text-xs text-zinc-500`,children:`Local to this layout. Not published research or Agent-wide insights.`}),n&&(0,Q.jsx)(`p`,{role:`alert`,className:`text-sm text-red-300`,children:n})]})}function rt({title:e,initial:t,pending:n,error:r,onApply:i,onCancel:a}){let[o,s]=(0,Z.useState)(t),c=(0,Z.useRef)(null),[l,u]=(0,Z.useState)(``);async function d(){try{u(``),c.current?.name!==o.trim()&&(c.current={name:o.trim(),id:U()}),await i(o.trim(),c.current.id)}catch(e){u(e instanceof Error?e.message:`Unable to prepare the layout`)}}return(0,Q.jsxs)(X,{title:e,onCancel:a,onApply:()=>{d()},applyDisabled:n||!o.trim(),children:[(0,Q.jsxs)(`label`,{className:`block space-y-2 text-sm`,children:[`Name`,(0,Q.jsx)(`input`,{autoFocus:!0,maxLength:80,value:o,disabled:n,onChange:e=>s(e.target.value),className:Y})]}),(0,Q.jsx)(`p`,{className:`mt-3 text-xs text-zinc-500`,children:`Layouts autosave instrument, timeframe, objects, styles and notes. Reopening follows the latest candles.`}),(l||r)&&(0,Q.jsx)(`p`,{role:`alert`,className:`text-sm text-red-300`,children:l||r})]})}function it(){let{agentId:e}=L.useParams(),{data:t,error:n}=w(k(e)),{data:r}=w(M()),{data:i}=w(N(e));return(0,Q.jsxs)(Q.Fragment,{children:[n&&(0,Q.jsx)(`p`,{role:`alert`,className:`text-sm text-amber-200`,children:n.message}),(0,Q.jsx)(et,{id:e,instruments:t,initialChat:i,choices:r},e)]})}export{it as component};
@@ -1 +1 @@
1
- import{t as e}from"./jsx-runtime-CIazjfqY.js";import{t}from"./useSuspenseQuery-vODFwDb8.js";import{r as n}from"./provider-queries-DxPwhDOU.js";import{t as r}from"./agent-queries-CNMBImun.js";import{x as i}from"./index-fu66g8fn.js";import{t as a}from"./agent-chat-page-vKrkXdzr.js";var o=e();function s(){let{agentId:e}=i.useParams(),{data:s}=t(r(e)),{data:c}=t(n());return(0,o.jsx)(a,{initial:s,choices:c},e)}export{s as component};
1
+ import{t as e}from"./jsx-runtime-CIazjfqY.js";import{t}from"./useSuspenseQuery-vODFwDb8.js";import{r as n}from"./provider-queries-DxPwhDOU.js";import{t as r}from"./agent-queries-CNMBImun.js";import{x as i}from"./index-B4hvjMmI.js";import{t as a}from"./agent-chat-page-C5eYFgxw.js";var o=e();function s(){let{agentId:e}=i.useParams(),{data:s}=t(r(e)),{data:c}=t(n());return(0,o.jsx)(a,{initial:s,choices:c},e)}export{s as component};
@@ -1 +1 @@
1
- import{f as e,l as t,t as n}from"./jsx-runtime-CIazjfqY.js";import{i as r}from"./createServerFn-DfZIp2Fu.js";import{t as i}from"./useMutation-Dni_73Pp.js";import{t as a}from"./useQuery-BMSU16jY.js";import{t as o}from"./useSuspenseQuery-vODFwDb8.js";import{t as s}from"./useRouter-c0I1aURm.js";import{c,g as l,i as u,l as d,n as f}from"./agent-queries-CNMBImun.js";import{n as p}from"./subagent-queries-DVv5JCfs.js";import{t as m}from"./risk-queries-D_6PHwus.js";import{C as h,j as g}from"./index-fu66g8fn.js";import{i as _,n as v,r as y,t as b}from"./decimal-B0DEG-1V.js";import{t as x}from"./random-uuid-DJR3ygJS.js";import{t as S}from"./subagent-mutations-DfsDbmFu.js";import{i as C,r as w}from"./agent-events-DC8eDZf3.js";import{t as T}from"./instrument-label-BZYlWXR5.js";import{t as E}from"./esm-BTb2nBdW.js";import{t as D}from"./subagent-enabled-toggle-Bk5wfScg.js";import{t as O}from"./run-subagent-dialog-B4yQe9T9.js";import{i as k,n as A,t as j}from"./subagent-run-history-D55Uh5VK.js";import{t as M}from"./journal-decimal-DBvd_Ibi.js";import{t as N}from"./toggle-timestamp-B50FTPmA.js";var P=e(t(),1);function F(e){let t=e.live;if(t&&(t.status!==`connected`||!t.sections.mode.fresh||!t.sections.spot.fresh))return null;switch(e.accountAbstraction){case`unifiedAccount`:return e.spotUsdc;case`disabled`:case`default`:return t&&!t.sections.perps.fresh||e.perpEquity===null||e.spotUsdc===null?null:b(e.perpEquity,e.spotUsdc);default:return null}}var I=n();function L({agentId:e,subagents:t,agentEnabled:n,error:r}){let[i,a]=(0,P.useState)(null),o=t,s=r,[c,l]=(0,P.useState)(``);(0,P.useEffect)(()=>{n||a(null)},[n]);let{interrupted:u,controlMessage:d,streamErrors:f}=C();(0,P.useEffect)(()=>{let e=f.subagents;l(e||(u?d||`Live sub-agent updates interrupted. Reconnecting… Activity may be out of date.`:``))},[u,d,f]);let p=`/agents/${encodeURIComponent(e)}/sub-agents`;return(0,I.jsxs)(`section`,{"aria-label":`Sub-agents`,className:`flex min-h-0 flex-1 flex-col rounded-2xl border border-zinc-800 bg-[#0d0d10] p-4`,children:[(0,I.jsx)(`header`,{className:`mb-3 shrink-0`,children:(0,I.jsx)(`h3`,{className:`text-lg font-medium text-white`,children:`Sub-agents`})}),s?(0,I.jsxs)(`p`,{role:`alert`,className:`text-sm text-amber-200`,children:[`Sub-agents unavailable: `,s]}):o.length?(0,I.jsx)(`ul`,{className:`min-h-0 overflow-y-auto overscroll-contain space-y-2`,children:o.map(t=>(0,I.jsxs)(`li`,{className:`overflow-hidden rounded-xl border border-zinc-800`,children:[(0,I.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 bg-zinc-900/50 px-3 py-2`,children:[(0,I.jsx)(`h4`,{className:`min-w-0`,children:(0,I.jsx)(`a`,{href:`${p}/${encodeURIComponent(t.id)}`,className:`cursor-pointer font-medium text-zinc-100 hover:text-violet-300`,children:t.name})}),(0,I.jsx)(z,{agentId:e,agentEnabled:n,definition:t,onRun:()=>a(t.id)})]}),t.runs.length?(0,I.jsx)(`ul`,{className:`divide-y divide-zinc-800/60`,children:t.runs.slice(0,t.runs[0]?.status===`running`||t.runs[0]?.status===`queued`?2:1).map(n=>(0,I.jsx)(`li`,{children:(0,I.jsxs)(`a`,{href:k(e,t.id,n.id),className:`flex cursor-pointer items-center gap-3 px-3 py-2 text-sm hover:bg-zinc-900 focus-visible:outline-violet-400`,children:[(0,I.jsx)(A,{status:n.status}),(0,I.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-zinc-300`,children:n.result||(n.status===`running`?`Running…`:n.status===`queued`?`Waiting to run…`:`No result message.`)}),(0,I.jsx)(`span`,{className:`shrink-0 text-xs text-zinc-500`,children:(0,I.jsx)(j,{timestamp:n.createdAt})})]})},n.id))}):(0,I.jsx)(`p`,{className:`px-3 py-2 text-sm text-zinc-500`,children:`No runs yet.`})]},t.id))}):(0,I.jsxs)(`p`,{className:`text-sm text-zinc-500`,children:[`No sub-agents yet. `,(0,I.jsx)(`a`,{href:`${p}/new`,className:`cursor-pointer text-violet-400 hover:text-violet-300 hover:underline`,children:`Create a new sub-agent`}),` to get started.`]}),c&&(0,I.jsx)(`p`,{role:`alert`,className:`mt-3 shrink-0 text-sm text-amber-200`,children:c}),n&&i&&(0,I.jsx)(B,{agentId:e,subagentId:i,onClose:()=>a(null)},`${e}:${i}`)]})}function R({timestamp:e}){let[,t]=(0,P.useState)(0);(0,P.useEffect)(()=>{let e=setInterval(()=>t(e=>e+1),1e3);return()=>clearInterval(e)},[]);let n=new Date(e).toISOString();return(0,I.jsxs)(`span`,{className:`text-xs text-zinc-400`,children:[`Next run: `,(0,I.jsx)(`time`,{dateTime:n,title:n,suppressHydrationWarning:!0,children:e>Date.now()?E(e):`due now`})]})}function z({agentId:e,definition:t,agentEnabled:n,onRun:a}){let[o,s]=(0,P.useState)(t),c=i({mutationFn:S(r(),e).saveSection,onSuccess:e=>{s(t=>({...t,enabled:e.enabled,schedule:e.schedule,nextRunAt:e.nextRunAt})),g.success(e.enabled?`Sub-agent enabled`:`Sub-agent paused`)}}),l=c.isPending,u=c.error?.message;return(0,P.useEffect)(()=>{s(t)},[t]),(0,I.jsxs)(`div`,{className:`flex flex-1 flex-wrap items-center gap-2`,children:[n&&o.enabled&&o.schedule&&o.nextRunAt!==null&&(0,I.jsx)(R,{timestamp:o.nextRunAt}),(0,I.jsxs)(`div`,{className:`ml-auto flex items-center gap-2`,children:[(0,I.jsx)(`button`,{type:`button`,"aria-label":`Run now: ${t.name}`,title:n?`Run now`:`Enable the agent to run workers`,disabled:!n,"aria-haspopup":`dialog`,onClick:a,className:`inline-flex shrink-0 cursor-pointer items-center justify-center rounded-full p-1.5 text-violet-300 hover:bg-violet-950 disabled:cursor-not-allowed disabled:opacity-50`,children:(0,I.jsx)(`svg`,{"aria-hidden":`true`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:1.5,strokeLinecap:`round`,strokeLinejoin:`round`,className:`size-4`,children:(0,I.jsx)(`path`,{d:`m13 2-9 12h7l-1 8 10-12h-7z`})})}),n?(0,I.jsx)(D,{enabled:o.enabled,disabled:l,onClick:()=>c.mutate({id:t.id,section:`enabled`,settings:{enabled:!o.enabled}})}):(0,I.jsx)(`span`,{role:`status`,className:`text-xs text-amber-300`,children:`Agent disabled`}),u&&(0,I.jsx)(`p`,{role:`alert`,className:`text-xs text-red-300`,children:u})]})]})}function B({agentId:e,subagentId:t,onClose:n}){let a=s(),[o,c]=(0,P.useState)(``),l=(0,P.useRef)(null),u=r(),d=i({mutationFn:async()=>{l.current?.task!==o&&(l.current={task:o,id:x()});try{return await S(u,e).run({id:t,task:o,requestId:l.current.id})}catch(e){throw Error(`${e instanceof Error?e.message:`Unable to confirm the assignment.`} Retry with the same task to reuse its request ID.`,{cause:e})}},onSuccess:async r=>{g.success(`Assignment started`),await a.navigate({to:`/agents/$agentId/sub-agents/$subagentId/runs/$runId`,params:{agentId:e,subagentId:t,runId:r.id}}),n()}});async function f(){await d.mutateAsync()}return(0,I.jsx)(O,{task:o,onTaskChange:c,onCancel:n,onRun:f})}function V({label:e,points:t}){let n=t?.map(e=>M(e.balance))??[],r=n[0],i=n.at(-1),a=r&&i?i.sub(r):null,o=``;if(t&&n.length>1){let e=n[0],r=e;for(let t of n)t.cmp(e)<0&&(e=t),t.cmp(r)>0&&(r=t);let i=r.sub(e),a=t[0].time,s=t.at(-1).time-a;o=n.map((n,r)=>{let o=s?(t[r].time-a)/s*240:120,c=i.zero?24:44-Number(n.sub(e).div(i).toString())*40;return`${o.toFixed(2)},${c.toFixed(2)}`}).join(` `)}let s=a&&a.sign!==0?a.sign<0?`text-red-400`:`text-emerald-400`:`text-zinc-400`;return(0,I.jsxs)(`div`,{className:`min-w-0 p-1`,children:[(0,I.jsxs)(`dt`,{className:`text-xs uppercase tracking-[0.16em] text-zinc-500`,children:[e,` balance`]}),(0,I.jsx)(`dd`,{className:`mt-2`,title:`Realized USDC balance, including transfers, fees and funding. Excludes unrealized P&L.`,children:o?(0,I.jsxs)(I.Fragment,{children:[(0,I.jsxs)(`span`,{className:`font-mono text-sm tabular-nums ${s}`,children:[a.sign>0?`+`:``,_(a.toString()),` USDC`]}),(0,I.jsxs)(`svg`,{role:`img`,"aria-label":`${e} realized account balance`,viewBox:`0 0 240 48`,className:`mt-2 h-12 w-full ${s}`,preserveAspectRatio:`none`,children:[(0,I.jsx)(`title`,{children:`${e} realized account balance (USDC)`}),(0,I.jsx)(`polyline`,{points:o,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,vectorEffect:`non-scaling-stroke`})]})]}):(0,I.jsx)(`span`,{className:`text-sm text-zinc-500`,children:`Balance history unavailable`})})]})}function H({agentId:e,symbol:t}){let n=(0,P.useRef)(null),a=(0,P.useRef)(!1),o=(0,P.useRef)(null),[s,c]=(0,P.useState)(null),l=s!==null&&s.agentId===e&&s.symbol===t;(0,P.useEffect)(()=>{if(!s)return;if(!l){c(null);return}let e=window.setTimeout(()=>c(null),8e3),t=e=>{e.key===`Escape`&&(e.preventDefault(),c(null),o.current?.focus())};return document.addEventListener(`keydown`,t),()=>{window.clearTimeout(e),document.removeEventListener(`keydown`,t)}},[s,l]);let u=r(),f=i({mutationFn:async()=>(n.current??=x(),d({data:{id:e,symbol:t,requestId:n.current}})),onSettled:async()=>{await u.invalidateQueries({queryKey:[`agent-dashboard`,e]})}});async function p(){if(!a.current){if(!l){c({agentId:e,symbol:t});return}c(null),a.current=!0;try{let e=await f.mutateAsync();!e.cancel.uncertain&&!e.close.uncertain&&e.remainingSize!==null&&(n.current=null)}catch{}finally{a.current=!1}}}let m=f.data,h=f.isPending?`Closing ${t}…`:l?`Confirm close ${t} at market`:n.current?`Check / retry ${t} close`:`Close ${t} at market`;return(0,I.jsxs)(`div`,{className:`w-36 whitespace-normal`,children:[(0,I.jsx)(`div`,{role:`group`,"aria-label":`Close ${t} position`,className:`inline-flex h-9 w-36`,children:(0,I.jsxs)(`button`,{ref:o,type:`button`,title:h,"aria-label":h,"aria-busy":f.isPending,disabled:f.isPending,onClick:()=>{p()},className:`inline-flex h-full cursor-pointer items-center justify-start gap-2 overflow-hidden rounded-full border bg-transparent pl-1.5 text-xs text-red-300 transition-[width,border-color] duration-150 hover:text-red-200 disabled:cursor-wait disabled:opacity-50 ${l?`w-36 border-red-900/60 hover:border-red-500`:`w-9 border-transparent`}`,children:[(0,I.jsx)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,"aria-hidden":`true`,fill:`none`,viewBox:`0 0 24 24`,strokeWidth:`1.5`,stroke:`currentColor`,className:`size-6 shrink-0`,children:(0,I.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`m9.75 9.75 4.5 4.5m0-4.5-4.5 4.5M21 12a9 9 0 1 1-18 0 9 9 0 0 1 18 0Z`})}),l&&(0,I.jsx)(`span`,{className:`shrink-0 whitespace-nowrap`,children:`Confirm close`})]})}),f.error&&(0,I.jsxs)(`p`,{role:`alert`,className:`mt-2 text-xs text-red-300`,children:[f.error.message,` Retry uses the same request ID.`]}),m&&(0,I.jsxs)(`div`,{role:`status`,className:`mt-2 text-xs ${m.complete?`text-emerald-300`:`text-amber-200`}`,children:[(0,I.jsx)(`p`,{children:m.complete?`Position closed; no market orders remain.`:`Close incomplete or unconfirmed. Remaining size: ${m.remainingSize??`unknown`}; orders: ${m.remainingOrders??`unknown`}.`}),!m.complete&&(0,I.jsxs)(`p`,{className:`break-all`,children:[`Close request: `,m.close.requestId]}),[...m.cancel.results,...m.close.results].filter(e=>e.error).map(e=>(0,I.jsx)(`p`,{children:e.error},e.id)),m.warnings.map(e=>(0,I.jsx)(`p`,{children:e},e))]})]})}function U({agentId:e,symbol:t,oid:n}){let a=(0,P.useRef)(null),o=(0,P.useRef)(!1),s=(0,P.useRef)(null),[l,u]=(0,P.useState)(!1);(0,P.useEffect)(()=>{if(!l)return;let e=window.setTimeout(()=>u(!1),8e3),t=e=>{e.key===`Escape`&&(e.preventDefault(),u(!1),s.current?.focus())};return document.addEventListener(`keydown`,t),()=>{window.clearTimeout(e),document.removeEventListener(`keydown`,t)}},[l]);let d=r(),f=i({mutationFn:async()=>(a.current??=x(),c({data:{id:e,symbol:t,oid:n,requestId:a.current}})),onSettled:async()=>{await d.invalidateQueries({queryKey:[`agent-dashboard`,e]})}});async function p(){if(!o.current){if(!l){u(!0);return}u(!1),o.current=!0;try{await f.mutateAsync()}catch{}finally{o.current=!1}}}let m=f.data,h=m&&!m.uncertain&&m.results.length>0&&m.results.every(e=>e.orderStatus===`canceled`),g=f.isPending?`Canceling ${t} order ${n}…`:l?`Confirm cancel ${t} order ${n}`:a.current?`Check / retry ${t} order ${n} cancellation`:`Cancel ${t} order ${n}`;return(0,I.jsxs)(`div`,{className:`w-36 whitespace-normal`,children:[(0,I.jsx)(`div`,{role:`group`,"aria-label":`Cancel ${t} order ${n}`,className:`inline-flex h-9 w-36`,children:(0,I.jsxs)(`button`,{ref:s,type:`button`,title:g,"aria-label":g,"aria-busy":f.isPending,disabled:f.isPending||!!h,onClick:()=>{p()},className:`inline-flex h-full cursor-pointer items-center justify-start gap-2 overflow-hidden rounded-full border bg-transparent pl-1.5 text-xs text-red-300 transition-[width,border-color] duration-150 hover:text-red-200 disabled:cursor-not-allowed disabled:opacity-50 ${l?`w-36 border-red-900/60 hover:border-red-500`:`w-9 border-transparent`}`,children:[(0,I.jsx)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,"aria-hidden":`true`,fill:`none`,viewBox:`0 0 24 24`,strokeWidth:`1.5`,stroke:`currentColor`,className:`size-6 shrink-0`,children:(0,I.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`m9.75 9.75 4.5 4.5m0-4.5-4.5 4.5M21 12a9 9 0 1 1-18 0 9 9 0 0 1 18 0Z`})}),l&&(0,I.jsx)(`span`,{className:`shrink-0 whitespace-nowrap`,children:`Confirm cancel`})]})}),f.error&&(0,I.jsxs)(`p`,{role:`alert`,className:`mt-2 text-xs text-red-300`,children:[f.error.message,` Retry uses the same request ID.`]}),m&&(0,I.jsxs)(`div`,{role:`status`,className:`mt-2 text-xs ${h?`text-emerald-300`:`text-amber-200`}`,children:[(0,I.jsx)(`p`,{children:h?`Order canceled.`:`Cancellation incomplete or unconfirmed. Check the order before issuing another request.`}),!h&&(0,I.jsxs)(`p`,{className:`break-all`,children:[`Cancel request: `,m.requestId]}),m.results.filter(e=>e.error).map(e=>(0,I.jsx)(`p`,{children:e.error},e.id)),m.warnings.map(e=>(0,I.jsx)(`p`,{children:e},e))]})]})}function W({agentId:e,enabled:t=!0}){let n=s(),[r,a]=(0,P.useState)(``),o=i({mutationFn:async()=>(f.current?.message!==r&&(f.current={message:r,id:x()}),l({data:{id:e,message:r,requestId:f.current.id}})),onSuccess:async()=>{await n.navigate({to:`/agents/$agentId/chat`,params:{agentId:e}})}}),c=o.isPending,u=o.error?`${o.error.message} Retry with the same message to avoid submitting it twice.`:``,d=(0,P.useRef)(!1),f=(0,P.useRef)(null);async function p(){if(!(!t||d.current||!r.trim())){d.current=!0;try{await o.mutateAsync()}catch{}finally{d.current=!1}}}return(0,I.jsxs)(`section`,{"aria-label":`Chat`,className:`shrink-0 rounded-2xl border border-zinc-800 bg-[#0d0d10] p-6`,children:[(0,I.jsx)(`h3`,{className:`mb-4 text-lg font-medium text-white`,children:`Chat`}),!t&&(0,I.jsx)(`p`,{role:`status`,className:`mb-3 text-sm text-amber-200`,children:`Agent disabled. Enable it to chat or run workers. Exchange orders and positions remain unchanged.`}),(0,I.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),p()},children:[(0,I.jsxs)(`div`,{className:`flex items-end gap-3`,children:[(0,I.jsx)(`textarea`,{"aria-label":`Message to orchestrator`,placeholder:`Message the orchestrator…`,value:r,onChange:e=>a(e.target.value),rows:2,maxLength:16e3,disabled:c||!t,onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey&&!e.nativeEvent.isComposing&&(e.preventDefault(),p())},className:`min-w-0 flex-1 resize-none rounded-xl border border-zinc-700 bg-zinc-950 px-4 py-3 text-sm text-zinc-100 outline-none focus:border-violet-500 disabled:opacity-50`}),(0,I.jsx)(`button`,{type:`submit`,disabled:c||!t||!r.trim(),className:`shrink-0 cursor-pointer rounded-full bg-violet-600 px-5 py-2.5 text-sm font-medium text-white hover:bg-violet-500 disabled:cursor-not-allowed disabled:opacity-50`,children:c?`Sending…`:`Send`})]}),u&&(0,I.jsx)(`p`,{role:`alert`,className:`mt-3 text-sm text-red-300`,children:u})]})]})}function G({agentId:e,tradingEnabled:t,subagents:n}){let r=n.some(e=>e.enabled);if(t&&r||n.some(e=>e.runs.length>0))return null;let i=`/agents/${encodeURIComponent(e)}`,a=[{label:`Enable Trading`,href:`${i}/settings#risk-management`,complete:t},n.length>0?{label:`Enable sub-agents`,href:`${i}/sub-agents`,complete:r}:{label:`Create a new sub-agent`,href:`${i}/sub-agents/new`,complete:!1}],o=a.findIndex(e=>!e.complete);return(0,I.jsxs)(`section`,{"aria-label":`Agent setup`,className:`shrink-0 rounded-xl border border-violet-800 bg-violet-950/30 p-4 text-sm text-violet-200`,children:[(0,I.jsx)(`h2`,{className:`font-semibold`,children:`Finish setting up your agent`}),(0,I.jsx)(`ol`,{className:`mt-3 flex flex-wrap gap-x-6 gap-y-3`,children:a.map((e,t)=>(0,I.jsxs)(`li`,{"aria-current":t===o?`step`:void 0,className:e.complete?`text-zinc-400`:t===o?`font-semibold text-violet-100`:`text-violet-300/70`,children:[(0,I.jsx)(`span`,{"aria-hidden":`true`,className:`mr-2`,children:e.complete?`✓`:`${t+1}.`}),(0,I.jsx)(`span`,{className:`sr-only`,children:e.complete?`Completed: `:t===o?`Next: `:``}),(0,I.jsx)(`a`,{href:e.href,className:`cursor-pointer underline underline-offset-4 hover:text-white`,children:e.label})]},e.href))})]})}function K({title:e,children:t}){return(0,I.jsxs)(`section`,{className:`rounded-2xl border border-zinc-800 bg-[#0d0d10] p-6`,children:[(0,I.jsx)(`h3`,{className:`mb-4 text-lg font-medium text-white`,children:e}),t]})}function q(e){let t=e===null?null:v(e,`0`);return t===null||t===0?null:t<0?`text-red-400`:`text-emerald-400`}function J(e){let t=v(e,`0`);return t===null||t===0?y(e):`${t<0?`Short`:`Long`} ${y(e.replace(/^-/,``))}`}function Y({label:e,value:t,pnl:n=!1}){let r=(n?q(t):null)??`text-zinc-100`;return(0,I.jsxs)(`div`,{className:`p-1`,children:[(0,I.jsx)(`dt`,{className:`text-xs uppercase tracking-[0.16em] text-zinc-500`,children:e}),(0,I.jsx)(`dd`,{className:`mt-1 flex items-baseline gap-2`,children:t===null?(0,I.jsx)(`span`,{className:`text-base italic text-zinc-500`,children:`Unavailable`}):(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(`span`,{className:`font-mono text-2xl font-semibold tabular-nums ${r}`,children:_(t)}),(0,I.jsx)(`span`,{className:`text-xs text-zinc-500`,children:`USDC`})]})})]})}var X=`whitespace-nowrap px-3 py-3 text-left`,Z=[];function Q({id:e,initial:t,enabled:n=!0,tradingEnabled:r,subagents:i,subagentsError:a}){let[o,s]=(0,P.useState)(t),[c,l]=(0,P.useState)(i),[u,d]=(0,P.useState)(a),[f,p]=(0,P.useState)(!0);(0,P.useEffect)(()=>{l(i),d(a),p(!0)},[e,i,a]),w(`subagents`,e=>{l(JSON.parse(e.data)),d(void 0),p(!0)});let[m,h]=(0,P.useState)(``),{interrupted:g,controlMessage:v,streamErrors:x}=C();(0,P.useEffect)(()=>{(g||x.subagents)&&p(!1)},[g,x.subagents]);let S=!!t.address;w(`dashboard`,e=>{s(JSON.parse(e.data)),h(``)},S),(0,P.useEffect)(()=>{s(t),h(``)},[e,t]),(0,P.useEffect)(()=>{if(!S)return;let e=x.dashboard;e?h(e):g&&h(v||`Live connection interrupted. Reconnecting… Displayed data is from the last snapshot, not current.`)},[S,g,v,x]);let E=!m&&o.live?.status===`connected`,D=E&&Object.values(o.live.sections).every(e=>e.fresh)&&o.errors.length===0,O=D?`Connected`:E?`Connected · Data stale`:`Disconnected`,k=D?`bg-emerald-400`:E?`bg-amber-400`:`bg-red-400`,A=F(o),j=o.positions?.reduce((e,t)=>e===null?null:b(e,t.unrealizedPnl),`0`)??null;return(0,I.jsxs)(`div`,{className:`flex h-[calc(100dvh-4.5rem)] min-h-0 w-full flex-col gap-2 overflow-hidden sm:h-[calc(100dvh-5rem)]`,children:[(0,I.jsx)(`h2`,{className:`sr-only`,children:`Dashboard`}),(0,I.jsxs)(`div`,{className:`max-h-[55%] shrink-0 space-y-2 overflow-y-auto`,children:[r!==void 0&&c&&f&&!u&&!x.subagents&&!g&&(0,I.jsx)(G,{agentId:e,tradingEnabled:r,subagents:c}),o.address?(0,I.jsxs)(I.Fragment,{children:[(0,I.jsxs)(`section`,{"aria-label":`Account overview`,className:`rounded-2xl border border-zinc-800 bg-[#0d0d10] p-6`,children:[(0,I.jsxs)(`p`,{role:`status`,className:`mb-5 flex items-center gap-2 text-xs text-zinc-400`,children:[(0,I.jsx)(`span`,{"aria-hidden":`true`,className:`h-2 w-2 rounded-full ${k}`}),O]}),m&&(0,I.jsx)(`p`,{role:`alert`,className:`mb-4 rounded-xl border border-amber-900 p-3 text-sm text-amber-200`,children:m}),o.errors.length>0&&(0,I.jsx)(`div`,{role:`status`,className:`mb-4 rounded-xl border border-amber-900 p-3 text-sm text-amber-200`,children:o.errors.map(e=>(0,I.jsx)(`p`,{children:e},e))}),(0,I.jsxs)(`dl`,{className:`grid grid-cols-1 gap-6 sm:grid-cols-2 xl:grid-cols-4`,children:[(0,I.jsx)(Y,{label:`Total equity`,value:A}),(0,I.jsx)(Y,{label:`Unrealized`,value:j,pnl:!0}),(0,I.jsx)(V,{label:`24h`,points:o.balanceHistory?.day}),(0,I.jsx)(V,{label:`30d`,points:o.balanceHistory?.month})]})]}),(0,I.jsx)(K,{title:`Positions`,children:o.positions===null?(0,I.jsx)(`p`,{className:`text-sm text-amber-200`,children:`Positions unavailable.`}):o.positions.length===0?(0,I.jsx)(`p`,{className:`text-sm text-zinc-500`,children:`No open positions.`}):(0,I.jsx)(`div`,{className:`overflow-x-auto`,children:(0,I.jsxs)(`table`,{className:`w-full text-sm text-zinc-300`,children:[(0,I.jsx)(`thead`,{className:`text-xs text-zinc-500`,children:(0,I.jsx)(`tr`,{children:[`Market`,`Size`,`Leverage`,`Entry price`,`Unrealized P&L`,`Liquidation price`,`Actions`].map(e=>(0,I.jsx)(`th`,{className:X,children:e},e))})}),(0,I.jsx)(`tbody`,{className:`divide-y divide-zinc-800`,children:o.positions.map(t=>(0,I.jsxs)(`tr`,{children:[(0,I.jsx)(`td`,{className:X,children:(0,I.jsx)(T,{symbol:t.coin})}),(0,I.jsx)(`td`,{className:X,children:(0,I.jsx)(`span`,{className:`font-mono tabular-nums`,children:J(t.size)})}),(0,I.jsxs)(`td`,{className:X,children:[t.leverage,`×`]}),(0,I.jsx)(`td`,{className:X,children:(0,I.jsx)(`span`,{className:`font-mono tabular-nums`,children:y(t.entryPrice)})}),(0,I.jsx)(`td`,{className:X,children:(0,I.jsx)(`span`,{className:`font-mono tabular-nums ${q(t.unrealizedPnl)??`text-zinc-300`}`,children:_(t.unrealizedPnl)})}),(0,I.jsx)(`td`,{className:X,children:(0,I.jsx)(`span`,{className:`font-mono tabular-nums`,children:_(t.liquidationPrice,2)})}),(0,I.jsx)(`td`,{className:X,children:(0,I.jsx)(H,{agentId:e,symbol:t.coin})})]},t.coin))})]})})}),(0,I.jsx)(K,{title:`Open orders`,children:o.orders===null?(0,I.jsx)(`p`,{className:`text-sm text-amber-200`,children:`Orders unavailable.`}):o.orders.length===0?(0,I.jsx)(`p`,{className:`text-sm text-zinc-500`,children:`No open orders.`}):(0,I.jsx)(`div`,{className:`overflow-x-auto`,children:(0,I.jsxs)(`table`,{className:`w-full text-sm text-zinc-300`,children:[(0,I.jsx)(`thead`,{className:`text-xs text-zinc-500`,children:(0,I.jsx)(`tr`,{children:[`Market`,`Timestamp`,`Side`,`Type`,`Size`,`Price / trigger`,`Actions`].map(e=>(0,I.jsx)(`th`,{className:X,children:e},e))})}),(0,I.jsx)(`tbody`,{className:`divide-y divide-zinc-800`,children:o.orders.map(t=>(0,I.jsxs)(`tr`,{children:[(0,I.jsx)(`td`,{className:X,children:(0,I.jsx)(T,{symbol:t.coin})}),(0,I.jsx)(`td`,{className:`${X} text-xs text-zinc-400`,children:t.timestamp===void 0?`—`:(0,I.jsx)(N,{timestamp:t.timestamp,label:`order`})}),(0,I.jsx)(`td`,{className:X,children:t.side}),(0,I.jsx)(`td`,{className:X,children:t.type}),(0,I.jsx)(`td`,{className:X,children:(0,I.jsx)(`span`,{className:`font-mono tabular-nums`,children:y(t.size)})}),(0,I.jsx)(`td`,{className:X,children:(0,I.jsx)(`span`,{className:`font-mono tabular-nums`,children:y(t.triggerPrice??t.price)})}),(0,I.jsx)(`td`,{className:X,children:(0,I.jsx)(U,{agentId:e,symbol:t.coin,oid:String(t.id)},`${e}:${t.coin}:${t.id}`)})]},t.id))})]})})})]}):(0,I.jsx)(K,{title:`Trading account`,children:(0,I.jsx)(`p`,{className:`text-sm text-zinc-400`,children:`This agent is missing its required Hyperliquid account. Create a new agent with a linked account.`})})]}),(0,I.jsx)(L,{agentId:e,agentEnabled:n,subagents:c??Z,error:u}),(0,I.jsx)(W,{agentId:e,enabled:n},e)]})}function $(){let{agentId:e}=h.useParams(),{data:t}=o(u(e)),{data:n}=o(f(e)),{data:r,error:i}=a(p(e)),{data:s,error:c}=a(m(e));return(0,I.jsx)(Q,{id:e,enabled:t.enabled,tradingEnabled:c?void 0:s?.tradingEnabled,initial:n,subagents:r,subagentsError:i?.message},e)}export{$ as component};
1
+ import{f as e,l as t,t as n}from"./jsx-runtime-CIazjfqY.js";import{i as r}from"./createServerFn-DfZIp2Fu.js";import{t as i}from"./useMutation-DrF53EQG.js";import{t as a}from"./useQuery-BMSU16jY.js";import{t as o}from"./useSuspenseQuery-vODFwDb8.js";import{t as s}from"./useRouter-c0I1aURm.js";import{c,g as l,i as u,l as d,n as f}from"./agent-queries-CNMBImun.js";import{n as p}from"./subagent-queries-DVv5JCfs.js";import{t as m}from"./risk-queries-D_6PHwus.js";import{C as h,j as g}from"./index-B4hvjMmI.js";import{i as _,n as v,r as y,t as b}from"./decimal-B0DEG-1V.js";import{t as x}from"./random-uuid-DJR3ygJS.js";import{t as S}from"./subagent-mutations-DfsDbmFu.js";import{i as C,r as w}from"./agent-events-DC8eDZf3.js";import{t as T}from"./instrument-label-BZYlWXR5.js";import{t as E}from"./esm-BTb2nBdW.js";import{t as D}from"./subagent-enabled-toggle-Bk5wfScg.js";import{t as O}from"./run-subagent-dialog-B4yQe9T9.js";import{i as k,n as A,t as j}from"./subagent-run-history-D55Uh5VK.js";import{t as M}from"./journal-decimal-DBvd_Ibi.js";import{t as N}from"./toggle-timestamp-B50FTPmA.js";var P=e(t(),1);function F(e){let t=e.live;if(t&&(t.status!==`connected`||!t.sections.mode.fresh||!t.sections.spot.fresh))return null;switch(e.accountAbstraction){case`unifiedAccount`:return e.spotUsdc;case`disabled`:case`default`:return t&&!t.sections.perps.fresh||e.perpEquity===null||e.spotUsdc===null?null:b(e.perpEquity,e.spotUsdc);default:return null}}var I=n();function L({agentId:e,subagents:t,agentEnabled:n,error:r}){let[i,a]=(0,P.useState)(null),o=t,s=r,[c,l]=(0,P.useState)(``);(0,P.useEffect)(()=>{n||a(null)},[n]);let{interrupted:u,controlMessage:d,streamErrors:f}=C();(0,P.useEffect)(()=>{let e=f.subagents;l(e||(u?d||`Live sub-agent updates interrupted. Reconnecting… Activity may be out of date.`:``))},[u,d,f]);let p=`/agents/${encodeURIComponent(e)}/sub-agents`;return(0,I.jsxs)(`section`,{"aria-label":`Sub-agents`,className:`flex min-h-0 flex-1 flex-col rounded-2xl border border-zinc-800 bg-[#0d0d10] p-4`,children:[(0,I.jsx)(`header`,{className:`mb-3 shrink-0`,children:(0,I.jsx)(`h3`,{className:`text-lg font-medium text-white`,children:`Sub-agents`})}),s?(0,I.jsxs)(`p`,{role:`alert`,className:`text-sm text-amber-200`,children:[`Sub-agents unavailable: `,s]}):o.length?(0,I.jsx)(`ul`,{className:`min-h-0 overflow-y-auto overscroll-contain space-y-2`,children:o.map(t=>(0,I.jsxs)(`li`,{className:`overflow-hidden rounded-xl border border-zinc-800`,children:[(0,I.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 bg-zinc-900/50 px-3 py-2`,children:[(0,I.jsx)(`h4`,{className:`min-w-0`,children:(0,I.jsx)(`a`,{href:`${p}/${encodeURIComponent(t.id)}`,className:`cursor-pointer font-medium text-zinc-100 hover:text-violet-300`,children:t.name})}),(0,I.jsx)(z,{agentId:e,agentEnabled:n,definition:t,onRun:()=>a(t.id)})]}),t.runs.length?(0,I.jsx)(`ul`,{className:`divide-y divide-zinc-800/60`,children:t.runs.slice(0,t.runs[0]?.status===`running`||t.runs[0]?.status===`queued`?2:1).map(n=>(0,I.jsx)(`li`,{children:(0,I.jsxs)(`a`,{href:k(e,t.id,n.id),className:`flex cursor-pointer items-center gap-3 px-3 py-2 text-sm hover:bg-zinc-900 focus-visible:outline-violet-400`,children:[(0,I.jsx)(A,{status:n.status}),(0,I.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-zinc-300`,children:n.result||(n.status===`running`?`Running…`:n.status===`queued`?`Waiting to run…`:`No result message.`)}),(0,I.jsx)(`span`,{className:`shrink-0 text-xs text-zinc-500`,children:(0,I.jsx)(j,{timestamp:n.createdAt})})]})},n.id))}):(0,I.jsx)(`p`,{className:`px-3 py-2 text-sm text-zinc-500`,children:`No runs yet.`})]},t.id))}):(0,I.jsxs)(`p`,{className:`text-sm text-zinc-500`,children:[`No sub-agents yet. `,(0,I.jsx)(`a`,{href:`${p}/new`,className:`cursor-pointer text-violet-400 hover:text-violet-300 hover:underline`,children:`Create a new sub-agent`}),` to get started.`]}),c&&(0,I.jsx)(`p`,{role:`alert`,className:`mt-3 shrink-0 text-sm text-amber-200`,children:c}),n&&i&&(0,I.jsx)(B,{agentId:e,subagentId:i,onClose:()=>a(null)},`${e}:${i}`)]})}function R({timestamp:e}){let[,t]=(0,P.useState)(0);(0,P.useEffect)(()=>{let e=setInterval(()=>t(e=>e+1),1e3);return()=>clearInterval(e)},[]);let n=new Date(e).toISOString();return(0,I.jsxs)(`span`,{className:`text-xs text-zinc-400`,children:[`Next run: `,(0,I.jsx)(`time`,{dateTime:n,title:n,suppressHydrationWarning:!0,children:e>Date.now()?E(e):`due now`})]})}function z({agentId:e,definition:t,agentEnabled:n,onRun:a}){let[o,s]=(0,P.useState)(t),c=i({mutationFn:S(r(),e).saveSection,onSuccess:e=>{s(t=>({...t,enabled:e.enabled,schedule:e.schedule,nextRunAt:e.nextRunAt})),g.success(e.enabled?`Sub-agent enabled`:`Sub-agent paused`)}}),l=c.isPending,u=c.error?.message;return(0,P.useEffect)(()=>{s(t)},[t]),(0,I.jsxs)(`div`,{className:`flex flex-1 flex-wrap items-center gap-2`,children:[n&&o.enabled&&o.schedule&&o.nextRunAt!==null&&(0,I.jsx)(R,{timestamp:o.nextRunAt}),(0,I.jsxs)(`div`,{className:`ml-auto flex items-center gap-2`,children:[(0,I.jsx)(`button`,{type:`button`,"aria-label":`Run now: ${t.name}`,title:n?`Run now`:`Enable the agent to run workers`,disabled:!n,"aria-haspopup":`dialog`,onClick:a,className:`inline-flex shrink-0 cursor-pointer items-center justify-center rounded-full p-1.5 text-violet-300 hover:bg-violet-950 disabled:cursor-not-allowed disabled:opacity-50`,children:(0,I.jsx)(`svg`,{"aria-hidden":`true`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:1.5,strokeLinecap:`round`,strokeLinejoin:`round`,className:`size-4`,children:(0,I.jsx)(`path`,{d:`m13 2-9 12h7l-1 8 10-12h-7z`})})}),n?(0,I.jsx)(D,{enabled:o.enabled,disabled:l,onClick:()=>c.mutate({id:t.id,section:`enabled`,settings:{enabled:!o.enabled}})}):(0,I.jsx)(`span`,{role:`status`,className:`text-xs text-amber-300`,children:`Agent disabled`}),u&&(0,I.jsx)(`p`,{role:`alert`,className:`text-xs text-red-300`,children:u})]})]})}function B({agentId:e,subagentId:t,onClose:n}){let a=s(),[o,c]=(0,P.useState)(``),l=(0,P.useRef)(null),u=r(),d=i({mutationFn:async()=>{l.current?.task!==o&&(l.current={task:o,id:x()});try{return await S(u,e).run({id:t,task:o,requestId:l.current.id})}catch(e){throw Error(`${e instanceof Error?e.message:`Unable to confirm the assignment.`} Retry with the same task to reuse its request ID.`,{cause:e})}},onSuccess:async r=>{g.success(`Assignment started`),await a.navigate({to:`/agents/$agentId/sub-agents/$subagentId/runs/$runId`,params:{agentId:e,subagentId:t,runId:r.id}}),n()}});async function f(){await d.mutateAsync()}return(0,I.jsx)(O,{task:o,onTaskChange:c,onCancel:n,onRun:f})}function V({label:e,points:t}){let n=t?.map(e=>M(e.balance))??[],r=n[0],i=n.at(-1),a=r&&i?i.sub(r):null,o=``;if(t&&n.length>1){let e=n[0],r=e;for(let t of n)t.cmp(e)<0&&(e=t),t.cmp(r)>0&&(r=t);let i=r.sub(e),a=t[0].time,s=t.at(-1).time-a;o=n.map((n,r)=>{let o=s?(t[r].time-a)/s*240:120,c=i.zero?24:44-Number(n.sub(e).div(i).toString())*40;return`${o.toFixed(2)},${c.toFixed(2)}`}).join(` `)}let s=a&&a.sign!==0?a.sign<0?`text-red-400`:`text-emerald-400`:`text-zinc-400`;return(0,I.jsxs)(`div`,{className:`min-w-0 p-1`,children:[(0,I.jsxs)(`dt`,{className:`text-xs uppercase tracking-[0.16em] text-zinc-500`,children:[e,` balance`]}),(0,I.jsx)(`dd`,{className:`mt-2`,title:`Realized USDC balance, including transfers, fees and funding. Excludes unrealized P&L.`,children:o?(0,I.jsxs)(I.Fragment,{children:[(0,I.jsxs)(`span`,{className:`font-mono text-sm tabular-nums ${s}`,children:[a.sign>0?`+`:``,_(a.toString()),` USDC`]}),(0,I.jsxs)(`svg`,{role:`img`,"aria-label":`${e} realized account balance`,viewBox:`0 0 240 48`,className:`mt-2 h-12 w-full ${s}`,preserveAspectRatio:`none`,children:[(0,I.jsx)(`title`,{children:`${e} realized account balance (USDC)`}),(0,I.jsx)(`polyline`,{points:o,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,vectorEffect:`non-scaling-stroke`})]})]}):(0,I.jsx)(`span`,{className:`text-sm text-zinc-500`,children:`Balance history unavailable`})})]})}function H({agentId:e,symbol:t}){let n=(0,P.useRef)(null),a=(0,P.useRef)(!1),o=(0,P.useRef)(null),[s,c]=(0,P.useState)(null),l=s!==null&&s.agentId===e&&s.symbol===t;(0,P.useEffect)(()=>{if(!s)return;if(!l){c(null);return}let e=window.setTimeout(()=>c(null),8e3),t=e=>{e.key===`Escape`&&(e.preventDefault(),c(null),o.current?.focus())};return document.addEventListener(`keydown`,t),()=>{window.clearTimeout(e),document.removeEventListener(`keydown`,t)}},[s,l]);let u=r(),f=i({mutationFn:async()=>(n.current??=x(),d({data:{id:e,symbol:t,requestId:n.current}})),onSettled:async()=>{await u.invalidateQueries({queryKey:[`agent-dashboard`,e]})}});async function p(){if(!a.current){if(!l){c({agentId:e,symbol:t});return}c(null),a.current=!0;try{let e=await f.mutateAsync();!e.cancel.uncertain&&!e.close.uncertain&&e.remainingSize!==null&&(n.current=null)}catch{}finally{a.current=!1}}}let m=f.data,h=f.isPending?`Closing ${t}…`:l?`Confirm close ${t} at market`:n.current?`Check / retry ${t} close`:`Close ${t} at market`;return(0,I.jsxs)(`div`,{className:`w-36 whitespace-normal`,children:[(0,I.jsx)(`div`,{role:`group`,"aria-label":`Close ${t} position`,className:`inline-flex h-9 w-36`,children:(0,I.jsxs)(`button`,{ref:o,type:`button`,title:h,"aria-label":h,"aria-busy":f.isPending,disabled:f.isPending,onClick:()=>{p()},className:`inline-flex h-full cursor-pointer items-center justify-start gap-2 overflow-hidden rounded-full border bg-transparent pl-1.5 text-xs text-red-300 transition-[width,border-color] duration-150 hover:text-red-200 disabled:cursor-wait disabled:opacity-50 ${l?`w-36 border-red-900/60 hover:border-red-500`:`w-9 border-transparent`}`,children:[(0,I.jsx)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,"aria-hidden":`true`,fill:`none`,viewBox:`0 0 24 24`,strokeWidth:`1.5`,stroke:`currentColor`,className:`size-6 shrink-0`,children:(0,I.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`m9.75 9.75 4.5 4.5m0-4.5-4.5 4.5M21 12a9 9 0 1 1-18 0 9 9 0 0 1 18 0Z`})}),l&&(0,I.jsx)(`span`,{className:`shrink-0 whitespace-nowrap`,children:`Confirm close`})]})}),f.error&&(0,I.jsxs)(`p`,{role:`alert`,className:`mt-2 text-xs text-red-300`,children:[f.error.message,` Retry uses the same request ID.`]}),m&&(0,I.jsxs)(`div`,{role:`status`,className:`mt-2 text-xs ${m.complete?`text-emerald-300`:`text-amber-200`}`,children:[(0,I.jsx)(`p`,{children:m.complete?`Position closed; no market orders remain.`:`Close incomplete or unconfirmed. Remaining size: ${m.remainingSize??`unknown`}; orders: ${m.remainingOrders??`unknown`}.`}),!m.complete&&(0,I.jsxs)(`p`,{className:`break-all`,children:[`Close request: `,m.close.requestId]}),[...m.cancel.results,...m.close.results].filter(e=>e.error).map(e=>(0,I.jsx)(`p`,{children:e.error},e.id)),m.warnings.map(e=>(0,I.jsx)(`p`,{children:e},e))]})]})}function U({agentId:e,symbol:t,oid:n}){let a=(0,P.useRef)(null),o=(0,P.useRef)(!1),s=(0,P.useRef)(null),[l,u]=(0,P.useState)(!1);(0,P.useEffect)(()=>{if(!l)return;let e=window.setTimeout(()=>u(!1),8e3),t=e=>{e.key===`Escape`&&(e.preventDefault(),u(!1),s.current?.focus())};return document.addEventListener(`keydown`,t),()=>{window.clearTimeout(e),document.removeEventListener(`keydown`,t)}},[l]);let d=r(),f=i({mutationFn:async()=>(a.current??=x(),c({data:{id:e,symbol:t,oid:n,requestId:a.current}})),onSettled:async()=>{await d.invalidateQueries({queryKey:[`agent-dashboard`,e]})}});async function p(){if(!o.current){if(!l){u(!0);return}u(!1),o.current=!0;try{await f.mutateAsync()}catch{}finally{o.current=!1}}}let m=f.data,h=m&&!m.uncertain&&m.results.length>0&&m.results.every(e=>e.orderStatus===`canceled`),g=f.isPending?`Canceling ${t} order ${n}…`:l?`Confirm cancel ${t} order ${n}`:a.current?`Check / retry ${t} order ${n} cancellation`:`Cancel ${t} order ${n}`;return(0,I.jsxs)(`div`,{className:`w-36 whitespace-normal`,children:[(0,I.jsx)(`div`,{role:`group`,"aria-label":`Cancel ${t} order ${n}`,className:`inline-flex h-9 w-36`,children:(0,I.jsxs)(`button`,{ref:s,type:`button`,title:g,"aria-label":g,"aria-busy":f.isPending,disabled:f.isPending||!!h,onClick:()=>{p()},className:`inline-flex h-full cursor-pointer items-center justify-start gap-2 overflow-hidden rounded-full border bg-transparent pl-1.5 text-xs text-red-300 transition-[width,border-color] duration-150 hover:text-red-200 disabled:cursor-not-allowed disabled:opacity-50 ${l?`w-36 border-red-900/60 hover:border-red-500`:`w-9 border-transparent`}`,children:[(0,I.jsx)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,"aria-hidden":`true`,fill:`none`,viewBox:`0 0 24 24`,strokeWidth:`1.5`,stroke:`currentColor`,className:`size-6 shrink-0`,children:(0,I.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`m9.75 9.75 4.5 4.5m0-4.5-4.5 4.5M21 12a9 9 0 1 1-18 0 9 9 0 0 1 18 0Z`})}),l&&(0,I.jsx)(`span`,{className:`shrink-0 whitespace-nowrap`,children:`Confirm cancel`})]})}),f.error&&(0,I.jsxs)(`p`,{role:`alert`,className:`mt-2 text-xs text-red-300`,children:[f.error.message,` Retry uses the same request ID.`]}),m&&(0,I.jsxs)(`div`,{role:`status`,className:`mt-2 text-xs ${h?`text-emerald-300`:`text-amber-200`}`,children:[(0,I.jsx)(`p`,{children:h?`Order canceled.`:`Cancellation incomplete or unconfirmed. Check the order before issuing another request.`}),!h&&(0,I.jsxs)(`p`,{className:`break-all`,children:[`Cancel request: `,m.requestId]}),m.results.filter(e=>e.error).map(e=>(0,I.jsx)(`p`,{children:e.error},e.id)),m.warnings.map(e=>(0,I.jsx)(`p`,{children:e},e))]})]})}function W({agentId:e,enabled:t=!0}){let n=s(),[r,a]=(0,P.useState)(``),o=i({mutationFn:async()=>(f.current?.message!==r&&(f.current={message:r,id:x()}),l({data:{id:e,message:r,requestId:f.current.id}})),onSuccess:async()=>{await n.navigate({to:`/agents/$agentId/chat`,params:{agentId:e}})}}),c=o.isPending,u=o.error?`${o.error.message} Retry with the same message to avoid submitting it twice.`:``,d=(0,P.useRef)(!1),f=(0,P.useRef)(null);async function p(){if(!(!t||d.current||!r.trim())){d.current=!0;try{await o.mutateAsync()}catch{}finally{d.current=!1}}}return(0,I.jsxs)(`section`,{"aria-label":`Chat`,className:`shrink-0 rounded-2xl border border-zinc-800 bg-[#0d0d10] p-6`,children:[(0,I.jsx)(`h3`,{className:`mb-4 text-lg font-medium text-white`,children:`Chat`}),!t&&(0,I.jsx)(`p`,{role:`status`,className:`mb-3 text-sm text-amber-200`,children:`Agent disabled. Enable it to chat or run workers. Exchange orders and positions remain unchanged.`}),(0,I.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),p()},children:[(0,I.jsxs)(`div`,{className:`flex items-end gap-3`,children:[(0,I.jsx)(`textarea`,{"aria-label":`Message to orchestrator`,placeholder:`Message the orchestrator…`,value:r,onChange:e=>a(e.target.value),rows:2,maxLength:16e3,disabled:c||!t,onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey&&!e.nativeEvent.isComposing&&(e.preventDefault(),p())},className:`min-w-0 flex-1 resize-none rounded-xl border border-zinc-700 bg-zinc-950 px-4 py-3 text-sm text-zinc-100 outline-none focus:border-violet-500 disabled:opacity-50`}),(0,I.jsx)(`button`,{type:`submit`,disabled:c||!t||!r.trim(),className:`shrink-0 cursor-pointer rounded-full bg-violet-600 px-5 py-2.5 text-sm font-medium text-white hover:bg-violet-500 disabled:cursor-not-allowed disabled:opacity-50`,children:c?`Sending…`:`Send`})]}),u&&(0,I.jsx)(`p`,{role:`alert`,className:`mt-3 text-sm text-red-300`,children:u})]})]})}function G({agentId:e,tradingEnabled:t,subagents:n}){let r=n.some(e=>e.enabled);if(t&&r||n.some(e=>e.runs.length>0))return null;let i=`/agents/${encodeURIComponent(e)}`,a=[{label:`Enable Trading`,href:`${i}/settings#risk-management`,complete:t},n.length>0?{label:`Enable sub-agents`,href:`${i}/sub-agents`,complete:r}:{label:`Create a new sub-agent`,href:`${i}/sub-agents/new`,complete:!1}],o=a.findIndex(e=>!e.complete);return(0,I.jsxs)(`section`,{"aria-label":`Agent setup`,className:`shrink-0 rounded-xl border border-violet-800 bg-violet-950/30 p-4 text-sm text-violet-200`,children:[(0,I.jsx)(`h2`,{className:`font-semibold`,children:`Finish setting up your agent`}),(0,I.jsx)(`ol`,{className:`mt-3 flex flex-wrap gap-x-6 gap-y-3`,children:a.map((e,t)=>(0,I.jsxs)(`li`,{"aria-current":t===o?`step`:void 0,className:e.complete?`text-zinc-400`:t===o?`font-semibold text-violet-100`:`text-violet-300/70`,children:[(0,I.jsx)(`span`,{"aria-hidden":`true`,className:`mr-2`,children:e.complete?`✓`:`${t+1}.`}),(0,I.jsx)(`span`,{className:`sr-only`,children:e.complete?`Completed: `:t===o?`Next: `:``}),(0,I.jsx)(`a`,{href:e.href,className:`cursor-pointer underline underline-offset-4 hover:text-white`,children:e.label})]},e.href))})]})}function K({title:e,children:t}){return(0,I.jsxs)(`section`,{className:`rounded-2xl border border-zinc-800 bg-[#0d0d10] p-6`,children:[(0,I.jsx)(`h3`,{className:`mb-4 text-lg font-medium text-white`,children:e}),t]})}function q(e){let t=e===null?null:v(e,`0`);return t===null||t===0?null:t<0?`text-red-400`:`text-emerald-400`}function J(e){let t=v(e,`0`);return t===null||t===0?y(e):`${t<0?`Short`:`Long`} ${y(e.replace(/^-/,``))}`}function Y({label:e,value:t,pnl:n=!1}){let r=(n?q(t):null)??`text-zinc-100`;return(0,I.jsxs)(`div`,{className:`p-1`,children:[(0,I.jsx)(`dt`,{className:`text-xs uppercase tracking-[0.16em] text-zinc-500`,children:e}),(0,I.jsx)(`dd`,{className:`mt-1 flex items-baseline gap-2`,children:t===null?(0,I.jsx)(`span`,{className:`text-base italic text-zinc-500`,children:`Unavailable`}):(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(`span`,{className:`font-mono text-2xl font-semibold tabular-nums ${r}`,children:_(t)}),(0,I.jsx)(`span`,{className:`text-xs text-zinc-500`,children:`USDC`})]})})]})}var X=`whitespace-nowrap px-3 py-3 text-left`,Z=[];function Q({id:e,initial:t,enabled:n=!0,tradingEnabled:r,subagents:i,subagentsError:a}){let[o,s]=(0,P.useState)(t),[c,l]=(0,P.useState)(i),[u,d]=(0,P.useState)(a),[f,p]=(0,P.useState)(!0);(0,P.useEffect)(()=>{l(i),d(a),p(!0)},[e,i,a]),w(`subagents`,e=>{l(JSON.parse(e.data)),d(void 0),p(!0)});let[m,h]=(0,P.useState)(``),{interrupted:g,controlMessage:v,streamErrors:x}=C();(0,P.useEffect)(()=>{(g||x.subagents)&&p(!1)},[g,x.subagents]);let S=!!t.address;w(`dashboard`,e=>{s(JSON.parse(e.data)),h(``)},S),(0,P.useEffect)(()=>{s(t),h(``)},[e,t]),(0,P.useEffect)(()=>{if(!S)return;let e=x.dashboard;e?h(e):g&&h(v||`Live connection interrupted. Reconnecting… Displayed data is from the last snapshot, not current.`)},[S,g,v,x]);let E=!m&&o.live?.status===`connected`,D=E&&Object.values(o.live.sections).every(e=>e.fresh)&&o.errors.length===0,O=D?`Connected`:E?`Connected · Data stale`:`Disconnected`,k=D?`bg-emerald-400`:E?`bg-amber-400`:`bg-red-400`,A=F(o),j=o.positions?.reduce((e,t)=>e===null?null:b(e,t.unrealizedPnl),`0`)??null;return(0,I.jsxs)(`div`,{className:`flex h-[calc(100dvh-4.5rem)] min-h-0 w-full flex-col gap-2 overflow-hidden sm:h-[calc(100dvh-5rem)]`,children:[(0,I.jsx)(`h2`,{className:`sr-only`,children:`Dashboard`}),(0,I.jsxs)(`div`,{className:`max-h-[55%] shrink-0 space-y-2 overflow-y-auto`,children:[r!==void 0&&c&&f&&!u&&!x.subagents&&!g&&(0,I.jsx)(G,{agentId:e,tradingEnabled:r,subagents:c}),o.address?(0,I.jsxs)(I.Fragment,{children:[(0,I.jsxs)(`section`,{"aria-label":`Account overview`,className:`rounded-2xl border border-zinc-800 bg-[#0d0d10] p-6`,children:[(0,I.jsxs)(`p`,{role:`status`,className:`mb-5 flex items-center gap-2 text-xs text-zinc-400`,children:[(0,I.jsx)(`span`,{"aria-hidden":`true`,className:`h-2 w-2 rounded-full ${k}`}),O]}),m&&(0,I.jsx)(`p`,{role:`alert`,className:`mb-4 rounded-xl border border-amber-900 p-3 text-sm text-amber-200`,children:m}),o.errors.length>0&&(0,I.jsx)(`div`,{role:`status`,className:`mb-4 rounded-xl border border-amber-900 p-3 text-sm text-amber-200`,children:o.errors.map(e=>(0,I.jsx)(`p`,{children:e},e))}),(0,I.jsxs)(`dl`,{className:`grid grid-cols-1 gap-6 sm:grid-cols-2 xl:grid-cols-4`,children:[(0,I.jsx)(Y,{label:`Total equity`,value:A}),(0,I.jsx)(Y,{label:`Unrealized`,value:j,pnl:!0}),(0,I.jsx)(V,{label:`24h`,points:o.balanceHistory?.day}),(0,I.jsx)(V,{label:`30d`,points:o.balanceHistory?.month})]})]}),(0,I.jsx)(K,{title:`Positions`,children:o.positions===null?(0,I.jsx)(`p`,{className:`text-sm text-amber-200`,children:`Positions unavailable.`}):o.positions.length===0?(0,I.jsx)(`p`,{className:`text-sm text-zinc-500`,children:`No open positions.`}):(0,I.jsx)(`div`,{className:`overflow-x-auto`,children:(0,I.jsxs)(`table`,{className:`w-full text-sm text-zinc-300`,children:[(0,I.jsx)(`thead`,{className:`text-xs text-zinc-500`,children:(0,I.jsx)(`tr`,{children:[`Market`,`Size`,`Leverage`,`Entry price`,`Unrealized P&L`,`Liquidation price`,`Actions`].map(e=>(0,I.jsx)(`th`,{className:X,children:e},e))})}),(0,I.jsx)(`tbody`,{className:`divide-y divide-zinc-800`,children:o.positions.map(t=>(0,I.jsxs)(`tr`,{children:[(0,I.jsx)(`td`,{className:X,children:(0,I.jsx)(T,{symbol:t.coin})}),(0,I.jsx)(`td`,{className:X,children:(0,I.jsx)(`span`,{className:`font-mono tabular-nums`,children:J(t.size)})}),(0,I.jsxs)(`td`,{className:X,children:[t.leverage,`×`]}),(0,I.jsx)(`td`,{className:X,children:(0,I.jsx)(`span`,{className:`font-mono tabular-nums`,children:y(t.entryPrice)})}),(0,I.jsx)(`td`,{className:X,children:(0,I.jsx)(`span`,{className:`font-mono tabular-nums ${q(t.unrealizedPnl)??`text-zinc-300`}`,children:_(t.unrealizedPnl)})}),(0,I.jsx)(`td`,{className:X,children:(0,I.jsx)(`span`,{className:`font-mono tabular-nums`,children:_(t.liquidationPrice,2)})}),(0,I.jsx)(`td`,{className:X,children:(0,I.jsx)(H,{agentId:e,symbol:t.coin})})]},t.coin))})]})})}),(0,I.jsx)(K,{title:`Open orders`,children:o.orders===null?(0,I.jsx)(`p`,{className:`text-sm text-amber-200`,children:`Orders unavailable.`}):o.orders.length===0?(0,I.jsx)(`p`,{className:`text-sm text-zinc-500`,children:`No open orders.`}):(0,I.jsx)(`div`,{className:`overflow-x-auto`,children:(0,I.jsxs)(`table`,{className:`w-full text-sm text-zinc-300`,children:[(0,I.jsx)(`thead`,{className:`text-xs text-zinc-500`,children:(0,I.jsx)(`tr`,{children:[`Market`,`Timestamp`,`Side`,`Type`,`Size`,`Price / trigger`,`Actions`].map(e=>(0,I.jsx)(`th`,{className:X,children:e},e))})}),(0,I.jsx)(`tbody`,{className:`divide-y divide-zinc-800`,children:o.orders.map(t=>(0,I.jsxs)(`tr`,{children:[(0,I.jsx)(`td`,{className:X,children:(0,I.jsx)(T,{symbol:t.coin})}),(0,I.jsx)(`td`,{className:`${X} text-xs text-zinc-400`,children:t.timestamp===void 0?`—`:(0,I.jsx)(N,{timestamp:t.timestamp,label:`order`})}),(0,I.jsx)(`td`,{className:X,children:t.side}),(0,I.jsx)(`td`,{className:X,children:t.type}),(0,I.jsx)(`td`,{className:X,children:(0,I.jsx)(`span`,{className:`font-mono tabular-nums`,children:y(t.size)})}),(0,I.jsx)(`td`,{className:X,children:(0,I.jsx)(`span`,{className:`font-mono tabular-nums`,children:y(t.triggerPrice??t.price)})}),(0,I.jsx)(`td`,{className:X,children:(0,I.jsx)(U,{agentId:e,symbol:t.coin,oid:String(t.id)},`${e}:${t.coin}:${t.id}`)})]},t.id))})]})})})]}):(0,I.jsx)(K,{title:`Trading account`,children:(0,I.jsx)(`p`,{className:`text-sm text-zinc-400`,children:`This agent is missing its required Hyperliquid account. Create a new agent with a linked account.`})})]}),(0,I.jsx)(L,{agentId:e,agentEnabled:n,subagents:c??Z,error:u}),(0,I.jsx)(W,{agentId:e,enabled:n},e)]})}function $(){let{agentId:e}=h.useParams(),{data:t}=o(u(e)),{data:n}=o(f(e)),{data:r,error:i}=a(p(e)),{data:s,error:c}=a(m(e));return(0,I.jsx)(Q,{id:e,enabled:t.enabled,tradingEnabled:c?void 0:s?.tradingEnabled,initial:n,subagents:r,subagentsError:i?.message},e)}export{$ as component};
@@ -1 +1 @@
1
- import{t as e}from"./jsx-runtime-CIazjfqY.js";import{i as t}from"./lazyRouteComponent-CJgUa7_r.js";import{t as n}from"./useQuery-BMSU16jY.js";import{r}from"./indicator-queries-CzZ6u1Mh.js";import{b as i}from"./index-fu66g8fn.js";import{n as a,r as o}from"./config-dialog-C9x9gKW9.js";var s=e();function c({agentId:e,search:i,onSearch:c}){let l=n(r(e,i));return(0,s.jsxs)(`section`,{className:`w-full space-y-5 rounded-2xl border border-zinc-800 bg-[#0d0d10] p-6`,children:[(0,s.jsxs)(`header`,{className:`flex flex-wrap items-center justify-between gap-4`,children:[(0,s.jsx)(`h2`,{className:`text-lg font-medium text-white`,children:`Indicators`}),(0,s.jsx)(t,{className:`cursor-pointer rounded-full border border-violet-500 px-4 py-2 text-sm text-violet-300 hover:bg-violet-950`,to:`/agents/$agentId/indicators/$indicatorId`,params:{agentId:e,indicatorId:`new`},search:{},children:`New indicator`})]}),(0,s.jsxs)(`div`,{className:`flex flex-wrap gap-3`,children:[(0,s.jsxs)(`label`,{className:`min-w-0 flex-1 text-sm text-zinc-300`,children:[`Search`,(0,s.jsx)(`input`,{className:o,value:i.query,onChange:e=>c({...i,query:e.target.value,offset:0})})]}),(0,s.jsxs)(`label`,{className:`text-sm text-zinc-300`,children:[`Kind`,(0,s.jsxs)(`select`,{className:`${o} cursor-pointer`,value:i.kind,onChange:e=>c({...i,kind:e.target.value,offset:0}),children:[(0,s.jsx)(`option`,{value:`all`,children:`All`}),(0,s.jsx)(`option`,{value:`builtin`,children:`Built-in`}),(0,s.jsx)(`option`,{value:`custom`,children:`Custom`})]})]})]}),l.isPending&&(0,s.jsx)(`p`,{role:`status`,children:`Loading indicators…`}),l.error&&(0,s.jsx)(`p`,{role:`alert`,className:`text-red-300`,children:l.error.message}),(0,s.jsxs)(`div`,{className:`overflow-x-auto rounded-xl border border-zinc-800`,children:[(0,s.jsxs)(`table`,{className:`w-full text-left text-sm`,children:[(0,s.jsx)(`thead`,{className:`border-b border-zinc-800 text-zinc-400`,children:(0,s.jsxs)(`tr`,{children:[(0,s.jsx)(`th`,{scope:`col`,className:`px-4 py-3 font-medium`,children:`Name`}),(0,s.jsx)(`th`,{scope:`col`,className:`px-4 py-3 font-medium`,children:`Kind`}),(0,s.jsx)(`th`,{scope:`col`,className:`px-4 py-3 font-medium`,children:`Description`})]})}),(0,s.jsx)(`tbody`,{className:`divide-y divide-zinc-800`,children:l.data?.indicators.map(n=>(0,s.jsxs)(`tr`,{className:`hover:bg-zinc-900`,children:[(0,s.jsx)(`td`,{className:`px-4 py-3`,children:(0,s.jsx)(t,{className:`cursor-pointer font-medium text-white hover:text-violet-300`,to:`/agents/$agentId/indicators/$indicatorId`,params:{agentId:e,indicatorId:n.id},search:{},children:n.name})}),(0,s.jsx)(`td`,{className:`whitespace-nowrap px-4 py-3 text-zinc-400`,children:n.builtIn?`Built-in · read-only`:`Custom`}),(0,s.jsx)(`td`,{className:`px-4 py-3 text-zinc-400`,children:(0,s.jsx)(t,{className:`block cursor-pointer hover:text-white`,to:`/agents/$agentId/indicators/$indicatorId`,params:{agentId:e,indicatorId:n.id},search:{},children:n.description})})]},n.id))})]}),l.data?.indicators.length===0&&(0,s.jsx)(`p`,{className:`p-4 text-sm text-zinc-400`,children:`No indicators found.`})]}),(0,s.jsxs)(`div`,{className:`flex justify-end gap-3`,children:[(0,s.jsx)(`button`,{className:a,disabled:!i.offset,onClick:()=>c({...i,offset:Math.max(0,i.offset-20)}),children:`Previous`}),(0,s.jsx)(`button`,{className:a,disabled:l.data?.nextOffset==null,onClick:()=>c({...i,offset:l.data.nextOffset}),children:`Next`})]})]})}function l(){let{agentId:e}=i.useParams(),t=i.useSearch(),n=i.useNavigate();return(0,s.jsx)(c,{agentId:e,search:t,onSearch:e=>{n({search:e,replace:!0})}})}export{l as component};
1
+ import{t as e}from"./jsx-runtime-CIazjfqY.js";import{i as t}from"./lazyRouteComponent-CJgUa7_r.js";import{t as n}from"./useQuery-BMSU16jY.js";import{r}from"./indicator-queries-CzZ6u1Mh.js";import{b as i}from"./index-B4hvjMmI.js";import{n as a,r as o}from"./config-dialog-C9x9gKW9.js";var s=e();function c({agentId:e,search:i,onSearch:c}){let l=n(r(e,i));return(0,s.jsxs)(`section`,{className:`w-full space-y-5 rounded-2xl border border-zinc-800 bg-[#0d0d10] p-6`,children:[(0,s.jsxs)(`header`,{className:`flex flex-wrap items-center justify-between gap-4`,children:[(0,s.jsx)(`h2`,{className:`text-lg font-medium text-white`,children:`Indicators`}),(0,s.jsx)(t,{className:`cursor-pointer rounded-full border border-violet-500 px-4 py-2 text-sm text-violet-300 hover:bg-violet-950`,to:`/agents/$agentId/indicators/$indicatorId`,params:{agentId:e,indicatorId:`new`},search:{},children:`New indicator`})]}),(0,s.jsxs)(`div`,{className:`flex flex-wrap gap-3`,children:[(0,s.jsxs)(`label`,{className:`min-w-0 flex-1 text-sm text-zinc-300`,children:[`Search`,(0,s.jsx)(`input`,{className:o,value:i.query,onChange:e=>c({...i,query:e.target.value,offset:0})})]}),(0,s.jsxs)(`label`,{className:`text-sm text-zinc-300`,children:[`Kind`,(0,s.jsxs)(`select`,{className:`${o} cursor-pointer`,value:i.kind,onChange:e=>c({...i,kind:e.target.value,offset:0}),children:[(0,s.jsx)(`option`,{value:`all`,children:`All`}),(0,s.jsx)(`option`,{value:`builtin`,children:`Built-in`}),(0,s.jsx)(`option`,{value:`custom`,children:`Custom`})]})]})]}),l.isPending&&(0,s.jsx)(`p`,{role:`status`,children:`Loading indicators…`}),l.error&&(0,s.jsx)(`p`,{role:`alert`,className:`text-red-300`,children:l.error.message}),(0,s.jsxs)(`div`,{className:`overflow-x-auto rounded-xl border border-zinc-800`,children:[(0,s.jsxs)(`table`,{className:`w-full text-left text-sm`,children:[(0,s.jsx)(`thead`,{className:`border-b border-zinc-800 text-zinc-400`,children:(0,s.jsxs)(`tr`,{children:[(0,s.jsx)(`th`,{scope:`col`,className:`px-4 py-3 font-medium`,children:`Name`}),(0,s.jsx)(`th`,{scope:`col`,className:`px-4 py-3 font-medium`,children:`Kind`}),(0,s.jsx)(`th`,{scope:`col`,className:`px-4 py-3 font-medium`,children:`Description`})]})}),(0,s.jsx)(`tbody`,{className:`divide-y divide-zinc-800`,children:l.data?.indicators.map(n=>(0,s.jsxs)(`tr`,{className:`hover:bg-zinc-900`,children:[(0,s.jsx)(`td`,{className:`px-4 py-3`,children:(0,s.jsx)(t,{className:`cursor-pointer font-medium text-white hover:text-violet-300`,to:`/agents/$agentId/indicators/$indicatorId`,params:{agentId:e,indicatorId:n.id},search:{},children:n.name})}),(0,s.jsx)(`td`,{className:`whitespace-nowrap px-4 py-3 text-zinc-400`,children:n.builtIn?`Built-in · read-only`:`Custom`}),(0,s.jsx)(`td`,{className:`px-4 py-3 text-zinc-400`,children:(0,s.jsx)(t,{className:`block cursor-pointer hover:text-white`,to:`/agents/$agentId/indicators/$indicatorId`,params:{agentId:e,indicatorId:n.id},search:{},children:n.description})})]},n.id))})]}),l.data?.indicators.length===0&&(0,s.jsx)(`p`,{className:`p-4 text-sm text-zinc-400`,children:`No indicators found.`})]}),(0,s.jsxs)(`div`,{className:`flex justify-end gap-3`,children:[(0,s.jsx)(`button`,{className:a,disabled:!i.offset,onClick:()=>c({...i,offset:Math.max(0,i.offset-20)}),children:`Previous`}),(0,s.jsx)(`button`,{className:a,disabled:l.data?.nextOffset==null,onClick:()=>c({...i,offset:l.data.nextOffset}),children:`Next`})]})]})}function l(){let{agentId:e}=i.useParams(),t=i.useSearch(),n=i.useNavigate();return(0,s.jsx)(c,{agentId:e,search:t,onSearch:e=>{n({search:e,replace:!0})}})}export{l as component};
@@ -1,2 +1,2 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/_authenticated.agents._agentId.indicators_._indicatorId-Beoq1vKK.js","assets/jsx-runtime-CIazjfqY.js","assets/createServerFn-DfZIp2Fu.js","assets/lazyRouteComponent-CJgUa7_r.js","assets/useSelector-ERD9RroG.js","assets/useRouter-c0I1aURm.js","assets/useMutation-Dni_73Pp.js","assets/query-nvK_95Jo.js","assets/index-fu66g8fn.js","assets/react-dom-C6bOPxes.js","assets/chart-queries-Bpvrgd0-.js","assets/provider-queries-DxPwhDOU.js","assets/agent-queries-CNMBImun.js","assets/preload-helper-Czpn1I53.js","assets/subagent-queries-DVv5JCfs.js","assets/risk-queries-D_6PHwus.js","assets/indicator-queries-CzZ6u1Mh.js","assets/memory-queries-BttL580R.js","assets/notification-queries-B12DG3aS.js","assets/memory-contracts-Doi_Q1XJ.js","assets/agent-input-aolvZ47U.js","assets/useQuery-BMSU16jY.js","assets/useBaseQuery-Bxruo_mV.js","assets/random-uuid-DJR3ygJS.js","assets/chart-contracts-Cr5SFCbE.js","assets/config-dialog-C9x9gKW9.js","assets/indicator-input-fields-CtmrfVfS.js"])))=>i.map(i=>d[i]);
2
- import{n as e,t}from"./lazyRouteComponent-CJgUa7_r.js";import{t as n}from"./preload-helper-Czpn1I53.js";import{i as r}from"./indicator-queries-CzZ6u1Mh.js";var i=[`sma`,`ema`,`rsi`,`macd`,`bollinger`,`atr`,`adx`],a=class extends Error{status;code;constructor(e,t=400,n=`indicator_invalid`){super(e),this.status=t,this.code=n,this.name=`IndicatorError`}};function o(e){if(typeof e!=`string`)throw new a(`Invalid indicator ID`);if(e.startsWith(`builtin:`)){let t=i.find(t=>e===`builtin:${t}`);if(t)return{kind:`builtin`,name:t}}if(/^custom:[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(e))return{kind:`custom`,uuid:e.slice(7).toLowerCase()};throw new a(`Invalid indicator ID`)}var s=e(`/_authenticated/agents/$agentId/indicators_/$indicatorId`)({validateSearch:e=>typeof e.copy==`string`?(o(e.copy),{copy:e.copy}):{},loaderDeps:({search:e})=>e,loader:async({context:e,params:t,deps:n})=>{let i=t.indicatorId===`new`?n.copy:t.indicatorId;i&&(o(i),await e.queryClient.ensureQueryData(r(t.agentId,i)))},component:t(()=>n(()=>import(`./_authenticated.agents._agentId.indicators_._indicatorId-Beoq1vKK.js`),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26])),`component`)});export{s as t};
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/_authenticated.agents._agentId.indicators_._indicatorId-DtgkoNV5.js","assets/jsx-runtime-CIazjfqY.js","assets/createServerFn-DfZIp2Fu.js","assets/lazyRouteComponent-CJgUa7_r.js","assets/useSelector-ERD9RroG.js","assets/useRouter-c0I1aURm.js","assets/useMutation-DrF53EQG.js","assets/query-nvK_95Jo.js","assets/index-B4hvjMmI.js","assets/react-dom-C6bOPxes.js","assets/chart-queries-Bpvrgd0-.js","assets/provider-queries-DxPwhDOU.js","assets/agent-queries-CNMBImun.js","assets/preload-helper-Czpn1I53.js","assets/subagent-queries-DVv5JCfs.js","assets/risk-queries-D_6PHwus.js","assets/indicator-queries-CzZ6u1Mh.js","assets/memory-queries-BttL580R.js","assets/notification-queries-B12DG3aS.js","assets/memory-contracts-Doi_Q1XJ.js","assets/agent-input-aolvZ47U.js","assets/useQuery-BMSU16jY.js","assets/useBaseQuery-Bxruo_mV.js","assets/random-uuid-DJR3ygJS.js","assets/chart-contracts-Cr5SFCbE.js","assets/config-dialog-C9x9gKW9.js","assets/indicator-input-fields-CtmrfVfS.js"])))=>i.map(i=>d[i]);
2
+ import{n as e,t}from"./lazyRouteComponent-CJgUa7_r.js";import{t as n}from"./preload-helper-Czpn1I53.js";import{i as r}from"./indicator-queries-CzZ6u1Mh.js";var i=[`sma`,`ema`,`rsi`,`macd`,`bollinger`,`atr`,`adx`],a=class extends Error{status;code;constructor(e,t=400,n=`indicator_invalid`){super(e),this.status=t,this.code=n,this.name=`IndicatorError`}};function o(e){if(typeof e!=`string`)throw new a(`Invalid indicator ID`);if(e.startsWith(`builtin:`)){let t=i.find(t=>e===`builtin:${t}`);if(t)return{kind:`builtin`,name:t}}if(/^custom:[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(e))return{kind:`custom`,uuid:e.slice(7).toLowerCase()};throw new a(`Invalid indicator ID`)}var s=e(`/_authenticated/agents/$agentId/indicators_/$indicatorId`)({validateSearch:e=>typeof e.copy==`string`?(o(e.copy),{copy:e.copy}):{},loaderDeps:({search:e})=>e,loader:async({context:e,params:t,deps:n})=>{let i=t.indicatorId===`new`?n.copy:t.indicatorId;i&&(o(i),await e.queryClient.ensureQueryData(r(t.agentId,i)))},component:t(()=>n(()=>import(`./_authenticated.agents._agentId.indicators_._indicatorId-DtgkoNV5.js`),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26])),`component`)});export{s as t};
@@ -1,5 +1,5 @@
1
1
  const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/lightweight-charts.production-BiBiFZSH.js","assets/jsx-runtime-CIazjfqY.js","assets/indicator-renderer-CfccsIt2.js"])))=>i.map(i=>d[i]);
2
- import{f as e,l as t,t as n}from"./jsx-runtime-CIazjfqY.js";import{i as r}from"./createServerFn-DfZIp2Fu.js";import{a as i,i as a}from"./lazyRouteComponent-CJgUa7_r.js";import{t as o}from"./useMutation-Dni_73Pp.js";import{t as s}from"./useQuery-BMSU16jY.js";import{t as c}from"./_authenticated.agents._agentId.indicators_._indicatorId-B45wotiz.js";import{t as l}from"./preload-helper-Czpn1I53.js";import{a as u,c as d,i as f,l as p,n as m,o as h,s as g}from"./indicator-queries-CzZ6u1Mh.js";import{t as _}from"./random-uuid-DJR3ygJS.js";import{t as v}from"./chart-contracts-Cr5SFCbE.js";import{n as y,r as b}from"./config-dialog-C9x9gKW9.js";import{t as x}from"./indicator-input-fields-CtmrfVfS.js";var S=e(t(),1),C=n();function w({result:e,candles:t}){let n=(0,S.useRef)(null),[r,i]=(0,S.useState)(``);return(0,S.useEffect)(()=>{let r=!1,a;return Promise.all([l(()=>import(`./lightweight-charts.production-BiBiFZSH.js`).then(e=>e.o),__vite__mapDeps([0,1])),l(()=>import(`./indicator-renderer-CfccsIt2.js`).then(e=>e.n),__vite__mapDeps([2,1,0]))]).then(([i,{createIndicatorRenderer:o}])=>{if(r||!n.current)return;let s=i.createChart(n.current,{autoSize:!0,layout:{background:{type:i.ColorType.Solid,color:`#0d0d10`},textColor:`#a1a1aa`},timeScale:{timeVisible:!0}}),c=s.addSeries(i.CandlestickSeries);c.setData(t.map(e=>({...e,time:e.time})));let l=o(s,c);a=()=>{l.close(),s.remove()},l.apply({id:`preview`,indicatorId:e.indicatorId,inputs:{},configuredVersion:e.version,hidden:!1,pane:`auto`,styles:{}},e,t),s.timeScale().fitContent()}).catch(e=>{a?.(),a=void 0,r||i(e instanceof Error?e.message:`Preview chart unavailable`)}),()=>{r=!0,a?.()}},[e,t]),(0,C.jsxs)(C.Fragment,{children:[(0,C.jsx)(`div`,{ref:n,className:`h-[480px] w-full`,"aria-label":`Read-only indicator preview chart`}),r&&(0,C.jsx)(`p`,{role:`alert`,children:r}),(0,C.jsx)(`p`,{className:`text-xs text-zinc-500`,children:`Read-only Pine visuals; marker/label glyphs are approximate. Time, direction, text and numerical values are retained.`})]})}var T=`//@version=6
2
+ import{f as e,l as t,t as n}from"./jsx-runtime-CIazjfqY.js";import{i as r}from"./createServerFn-DfZIp2Fu.js";import{a as i,i as a}from"./lazyRouteComponent-CJgUa7_r.js";import{t as o}from"./useMutation-DrF53EQG.js";import{t as s}from"./useQuery-BMSU16jY.js";import{t as c}from"./_authenticated.agents._agentId.indicators_._indicatorId-CMqaaFQf.js";import{t as l}from"./preload-helper-Czpn1I53.js";import{a as u,c as d,i as f,l as p,n as m,o as h,s as g}from"./indicator-queries-CzZ6u1Mh.js";import{t as _}from"./random-uuid-DJR3ygJS.js";import{t as v}from"./chart-contracts-Cr5SFCbE.js";import{n as y,r as b}from"./config-dialog-C9x9gKW9.js";import{t as x}from"./indicator-input-fields-CtmrfVfS.js";var S=e(t(),1),C=n();function w({result:e,candles:t}){let n=(0,S.useRef)(null),[r,i]=(0,S.useState)(``);return(0,S.useEffect)(()=>{let r=!1,a;return Promise.all([l(()=>import(`./lightweight-charts.production-BiBiFZSH.js`).then(e=>e.o),__vite__mapDeps([0,1])),l(()=>import(`./indicator-renderer-CfccsIt2.js`).then(e=>e.n),__vite__mapDeps([2,1,0]))]).then(([i,{createIndicatorRenderer:o}])=>{if(r||!n.current)return;let s=i.createChart(n.current,{autoSize:!0,layout:{background:{type:i.ColorType.Solid,color:`#0d0d10`},textColor:`#a1a1aa`},timeScale:{timeVisible:!0}}),c=s.addSeries(i.CandlestickSeries);c.setData(t.map(e=>({...e,time:e.time})));let l=o(s,c);a=()=>{l.close(),s.remove()},l.apply({id:`preview`,indicatorId:e.indicatorId,inputs:{},configuredVersion:e.version,hidden:!1,pane:`auto`,styles:{}},e,t),s.timeScale().fitContent()}).catch(e=>{a?.(),a=void 0,r||i(e instanceof Error?e.message:`Preview chart unavailable`)}),()=>{r=!0,a?.()}},[e,t]),(0,C.jsxs)(C.Fragment,{children:[(0,C.jsx)(`div`,{ref:n,className:`h-[480px] w-full`,"aria-label":`Read-only indicator preview chart`}),r&&(0,C.jsx)(`p`,{role:`alert`,children:r}),(0,C.jsx)(`p`,{className:`text-xs text-zinc-500`,children:`Read-only Pine visuals; marker/label glyphs are approximate. Time, direction, text and numerical values are retained.`})]})}var T=`//@version=6
3
3
  indicator("My indicator", overlay=true)
4
4
  period = input.int(20, "Period", minval=2, maxval=500)
5
5
  plot(ta.ema(close, period), "EMA", color=color.orange)
@@ -1 +1 @@
1
- import{f as e,l as t,t as n}from"./jsx-runtime-CIazjfqY.js";import{i as r}from"./createServerFn-DfZIp2Fu.js";import{i}from"./lazyRouteComponent-CJgUa7_r.js";import{g as a}from"./query-nvK_95Jo.js";import{t as o}from"./useQuery-BMSU16jY.js";import{t as s}from"./useSuspenseQuery-vODFwDb8.js";import{o as c}from"./subagent-queries-DVv5JCfs.js";import{n as l,t as u}from"./memory-queries-BttL580R.js";import{y as d}from"./index-fu66g8fn.js";import{t as f}from"./instrument-label-BZYlWXR5.js";import{t as p}from"./toggle-timestamp-B50FTPmA.js";import{n as m,r as h,t as g}from"./memory-badge-BbN-DJQi.js";var _=e(t(),1),v=n(),y=`cursor-pointer rounded-lg border border-zinc-700 px-3 py-2 text-sm text-zinc-200 hover:bg-zinc-800 disabled:cursor-not-allowed disabled:opacity-50`,b=`rounded-lg border border-zinc-700 bg-zinc-950 p-2 text-sm text-white`;function x({agentId:e,workers:t,scopeId:n=``,version:s,initialTab:c}){let d=c??(n||s?`insights`:`memories`),x=r(),[S,C]=(0,_.useState)({}),[w,T]=(0,_.useState)(``),[E,D]=(0,_.useState)(``),[O,k]=(0,_.useState)(``),[A,j]=(0,_.useState)(``),[M,N]=(0,_.useState)(``),[P,F]=(0,_.useState)(``),[I,L]=(0,_.useState)(``),[R,z]=(0,_.useState)(``),[B,V]=(0,_.useState)(n),[H,U]=(0,_.useState)(),W=o({...l(e,S),enabled:d===`memories`,placeholderData:a}),G=o({...u(e,B,H),enabled:d===`insights`}),K=W.data?.items??[],q=W.data?.nextCursor,J=G.data,Y=d===`insights`?G.isPending||G.isFetching:W.isPending||W.isFetching,X=(d===`insights`?G.error:W.error)?.message;function Z(){let t={...w?{kind:w}:{},...E?{instrument:E}:{},...O?{topic:O}:{},...A?{producerSubagentId:A}:{},...M?{status:M}:{},...P?{query:P}:{},...I?{start:Date.parse(`${I}T00:00:00Z`)}:{},...R?{end:Date.parse(`${R}T00:00:00Z`)}:{}};C(t),x.invalidateQueries({queryKey:l(e,t).queryKey,exact:!0})}function Q(e){Y||e===B||(V(e),U(void 0))}return(0,v.jsxs)(`section`,{className:`w-full min-w-0 space-y-4 rounded-2xl border border-zinc-800 bg-[#0d0d10] p-6 text-zinc-200`,children:[(0,v.jsx)(`header`,{children:(0,v.jsx)(`h1`,{className:`text-lg font-medium text-white`,children:d===`memories`?`Memories`:`Insights`})}),X&&(0,v.jsx)(`p`,{role:`alert`,className:`text-sm text-red-300`,children:X}),d===`memories`?(0,v.jsxs)(v.Fragment,{children:[(0,v.jsxs)(`details`,{children:[(0,v.jsx)(`summary`,{className:`w-fit cursor-pointer text-sm text-zinc-400 hover:text-white`,children:`Filter`}),(0,v.jsxs)(`form`,{className:`mt-3 flex flex-wrap items-end gap-3 text-sm`,onSubmit:e=>{e.preventDefault(),Y||Z()},children:[(0,v.jsxs)(`label`,{children:[`Kind`,(0,v.jsxs)(`select`,{"aria-label":`Memory kind`,className:`${b} ml-2 cursor-pointer`,value:w,onChange:e=>T(e.target.value),children:[(0,v.jsx)(`option`,{value:``,children:`All`}),[`research`,`decision`,`review`].map(e=>(0,v.jsx)(`option`,{children:e},e))]})]}),(0,v.jsxs)(`label`,{children:[`Instrument`,(0,v.jsx)(`input`,{className:`${b} ml-2 w-24`,maxLength:32,value:E,onChange:e=>D(e.target.value)})]}),(0,v.jsxs)(`label`,{children:[`Topic`,(0,v.jsx)(`input`,{className:`${b} ml-2 w-40`,maxLength:64,value:O,onChange:e=>k(e.target.value)})]}),(0,v.jsxs)(`label`,{children:[`Producer`,(0,v.jsxs)(`select`,{className:`${b} ml-2 cursor-pointer`,value:A,onChange:e=>j(e.target.value),children:[(0,v.jsx)(`option`,{value:``,children:`All`}),t.filter(e=>!e.archived).map(e=>(0,v.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]}),(0,v.jsxs)(`label`,{children:[`Status`,(0,v.jsxs)(`select`,{className:`${b} ml-2 cursor-pointer`,value:M,onChange:e=>N(e.target.value),children:[(0,v.jsx)(`option`,{value:``,children:`All`}),[`fresh`,`stale`,`retracted`,`invalid_evidence`,`durable`].map(e=>(0,v.jsx)(`option`,{children:e},e))]})]}),(0,v.jsxs)(`label`,{children:[`From (UTC)`,(0,v.jsx)(`input`,{type:`date`,className:`${b} ml-2`,value:I,onChange:e=>L(e.target.value)})]}),(0,v.jsxs)(`label`,{children:[`Until exclusive (UTC)`,(0,v.jsx)(`input`,{type:`date`,className:`${b} ml-2`,value:R,onChange:e=>z(e.target.value)})]}),(0,v.jsx)(`input`,{"aria-label":`Search memory summaries`,placeholder:`Search summaries`,className:b,maxLength:200,value:P,onChange:e=>F(e.target.value)}),(0,v.jsx)(`button`,{className:y,disabled:Y,children:`Apply filters`})]})]}),(0,v.jsx)(`div`,{className:`space-y-4`,children:(0,v.jsxs)(`section`,{className:`min-w-0 space-y-4`,"aria-label":`Memory publications`,children:[(0,v.jsx)(`div`,{className:`overflow-x-auto rounded-xl border border-zinc-800`,children:(0,v.jsxs)(`table`,{className:`w-full text-left text-sm`,"aria-label":`Memories`,"aria-busy":Y,children:[(0,v.jsx)(`thead`,{className:`border-b border-zinc-800 bg-zinc-900/50 text-xs text-zinc-400`,children:(0,v.jsx)(`tr`,{children:[`Memory`,`Kind`,`Instrument`,`Topic / interval`,`Status`,`Producer`,`Created`].map(e=>(0,v.jsx)(`th`,{scope:`col`,className:`whitespace-nowrap px-4 py-3 font-medium`,children:e},e))})}),(0,v.jsxs)(`tbody`,{className:`divide-y divide-zinc-800`,children:[K.map(n=>(0,v.jsxs)(`tr`,{className:`hover:bg-zinc-900/50`,children:[(0,v.jsx)(`td`,{className:`min-w-64 px-4 py-3`,children:(0,v.jsxs)(i,{to:`/agents/$agentId/memories/$memoryRef`,params:{agentId:e,memoryRef:n.ref},className:`block w-full cursor-pointer space-y-1 text-left hover:text-violet-300`,children:[(0,v.jsx)(`span`,{className:`block font-medium text-violet-300`,children:n.ref}),(0,v.jsx)(`span`,{className:`block break-words`,children:n.summary})]})}),(0,v.jsx)(`td`,{className:`px-4 py-3 align-top`,children:(0,v.jsx)(g,{value:n.kind})}),(0,v.jsx)(`td`,{className:`whitespace-nowrap px-4 py-3 align-top`,children:n.instrument?(0,v.jsx)(f,{symbol:n.instrument,iconOnly:!0}):`Agent-wide`}),(0,v.jsxs)(`td`,{className:`px-4 py-3 align-top`,children:[(0,v.jsx)(g,{value:n.topic}),(0,v.jsx)(`span`,{className:`mt-1 block text-xs text-zinc-500`,children:n.interval??`—`})]}),(0,v.jsxs)(`td`,{className:`px-4 py-3 align-top`,children:[(0,v.jsx)(h,{status:n.status}),(0,v.jsx)(m,{agentId:e,memory:{correctedBy:n.correctedBy,supersededBy:null}})]}),(0,v.jsx)(`td`,{className:`px-4 py-3 align-top`,children:t.find(e=>e.id===n.producerSubagentId)?.name??`Root`}),(0,v.jsx)(`td`,{className:`whitespace-nowrap px-4 py-3 align-top text-xs text-zinc-400`,children:(0,v.jsx)(p,{timestamp:n.createdAt})})]},n.ref)),!K.length&&(0,v.jsx)(`tr`,{children:(0,v.jsx)(`td`,{colSpan:7,className:`px-4 py-8 text-center text-zinc-400`,children:`No memories found. Try different filters, or configure an analysis/review worker and its memory tools.`})})]})]})}),(0,v.jsx)(`button`,{className:y,disabled:Y||W.isPlaceholderData||!!W.error||!q,onClick:()=>{q&&C(e=>({...e,cursor:q}))},children:`Next page`})]})})]}):(0,v.jsxs)(`section`,{className:`space-y-4`,children:[(0,v.jsx)(`p`,{className:`text-sm text-zinc-400`,children:`Insights are read-only, managed by a Review sub-agent`}),(0,v.jsxs)(`div`,{className:`grid min-h-80 grid-cols-1 overflow-hidden rounded-xl border border-zinc-800 md:grid-cols-[14rem_minmax(0,1fr)]`,children:[(0,v.jsx)(`nav`,{"aria-label":`Insights scope`,className:`space-y-1 border-b border-zinc-800 bg-zinc-900/30 p-3 md:border-r md:border-b-0`,children:[{id:``,name:`Global`},...t.filter(e=>e.kind===`worker`&&!e.archived)].map(e=>(0,v.jsx)(`button`,{type:`button`,"aria-current":B===e.id?`true`:void 0,disabled:Y,onClick:()=>Q(e.id),className:`block w-full cursor-pointer rounded-lg px-3 py-2 text-left text-sm disabled:cursor-not-allowed ${B===e.id?`bg-violet-500/10 text-violet-300`:`text-zinc-400 hover:bg-zinc-800 hover:text-white`}`,children:e.name},e.id))}),(0,v.jsxs)(`article`,{"aria-label":`Latest insights`,"aria-busy":Y,className:`min-w-0 space-y-5 p-5`,children:[(0,v.jsxs)(`header`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[(0,v.jsx)(`h2`,{className:`font-medium text-white`,children:B?t.find(e=>e.id===B)?.name??`Sub-agent`:`Global`}),J&&(0,v.jsxs)(`span`,{className:`text-xs text-zinc-500`,children:[`Latest · v`,J.current.version]})]}),J?(0,v.jsxs)(v.Fragment,{children:[(0,v.jsx)(`pre`,{className:`min-h-40 whitespace-pre-wrap break-words font-sans text-sm leading-relaxed`,children:J.current.content||`No insights yet.`}),J.head&&(0,v.jsxs)(`p`,{className:`text-xs text-zinc-500`,children:[`Updated `,new Date(J.head.createdAt).toISOString()]}),(0,v.jsxs)(`details`,{className:`border-t border-zinc-800 pt-4`,children:[(0,v.jsx)(`summary`,{className:`cursor-pointer text-sm text-zinc-400 hover:text-white`,children:`Revision history`}),(0,v.jsx)(`ul`,{className:`mt-3 space-y-3 text-xs text-zinc-400`,children:J.history?.items.map(e=>(0,v.jsxs)(`li`,{children:[(0,v.jsxs)(`span`,{className:`text-zinc-200`,children:[`v`,e.version]}),` · `,new Date(e.createdAt).toISOString(),(0,v.jsx)(`p`,{className:`mt-1`,children:e.reason})]},e.version))}),!J.history?.items.length&&(0,v.jsx)(`p`,{className:`mt-3 text-sm text-zinc-500`,children:`No revisions yet.`}),J.history?.nextBeforeVersion&&(0,v.jsx)(`button`,{className:`${y} mt-3`,disabled:Y,onClick:()=>U(J.history.nextBeforeVersion),children:`Older revisions`})]},B)]}):(0,v.jsx)(`p`,{className:`text-sm text-zinc-500`,children:Y?`Loading insights…`:`Insights unavailable.`})]})]})]})]})}function S(){let{agentId:e}=d.useParams(),{scope:t,version:n}=d.useSearch(),{data:r}=s(c(e));return(0,v.jsx)(x,{agentId:e,workers:r,scopeId:t,version:n,initialTab:t!==void 0||n!==void 0?`insights`:`memories`},`${e}:${t===void 0?`publications`:t}:${n??``}`)}export{S as component};
1
+ import{f as e,l as t,t as n}from"./jsx-runtime-CIazjfqY.js";import{i as r}from"./createServerFn-DfZIp2Fu.js";import{i}from"./lazyRouteComponent-CJgUa7_r.js";import{g as a}from"./query-nvK_95Jo.js";import{t as o}from"./useQuery-BMSU16jY.js";import{t as s}from"./useSuspenseQuery-vODFwDb8.js";import{o as c}from"./subagent-queries-DVv5JCfs.js";import{n as l,t as u}from"./memory-queries-BttL580R.js";import{y as d}from"./index-B4hvjMmI.js";import{t as f}from"./instrument-label-BZYlWXR5.js";import{t as p}from"./toggle-timestamp-B50FTPmA.js";import{n as m,r as h,t as g}from"./memory-badge-BbN-DJQi.js";var _=e(t(),1),v=n(),y=`cursor-pointer rounded-lg border border-zinc-700 px-3 py-2 text-sm text-zinc-200 hover:bg-zinc-800 disabled:cursor-not-allowed disabled:opacity-50`,b=`rounded-lg border border-zinc-700 bg-zinc-950 p-2 text-sm text-white`;function x({agentId:e,workers:t,scopeId:n=``,version:s,initialTab:c}){let d=c??(n||s?`insights`:`memories`),x=r(),[S,C]=(0,_.useState)({}),[w,T]=(0,_.useState)(``),[E,D]=(0,_.useState)(``),[O,k]=(0,_.useState)(``),[A,j]=(0,_.useState)(``),[M,N]=(0,_.useState)(``),[P,F]=(0,_.useState)(``),[I,L]=(0,_.useState)(``),[R,z]=(0,_.useState)(``),[B,V]=(0,_.useState)(n),[H,U]=(0,_.useState)(),W=o({...l(e,S),enabled:d===`memories`,placeholderData:a}),G=o({...u(e,B,H),enabled:d===`insights`}),K=W.data?.items??[],q=W.data?.nextCursor,J=G.data,Y=d===`insights`?G.isPending||G.isFetching:W.isPending||W.isFetching,X=(d===`insights`?G.error:W.error)?.message;function Z(){let t={...w?{kind:w}:{},...E?{instrument:E}:{},...O?{topic:O}:{},...A?{producerSubagentId:A}:{},...M?{status:M}:{},...P?{query:P}:{},...I?{start:Date.parse(`${I}T00:00:00Z`)}:{},...R?{end:Date.parse(`${R}T00:00:00Z`)}:{}};C(t),x.invalidateQueries({queryKey:l(e,t).queryKey,exact:!0})}function Q(e){Y||e===B||(V(e),U(void 0))}return(0,v.jsxs)(`section`,{className:`w-full min-w-0 space-y-4 rounded-2xl border border-zinc-800 bg-[#0d0d10] p-6 text-zinc-200`,children:[(0,v.jsx)(`header`,{children:(0,v.jsx)(`h1`,{className:`text-lg font-medium text-white`,children:d===`memories`?`Memories`:`Insights`})}),X&&(0,v.jsx)(`p`,{role:`alert`,className:`text-sm text-red-300`,children:X}),d===`memories`?(0,v.jsxs)(v.Fragment,{children:[(0,v.jsxs)(`details`,{children:[(0,v.jsx)(`summary`,{className:`w-fit cursor-pointer text-sm text-zinc-400 hover:text-white`,children:`Filter`}),(0,v.jsxs)(`form`,{className:`mt-3 flex flex-wrap items-end gap-3 text-sm`,onSubmit:e=>{e.preventDefault(),Y||Z()},children:[(0,v.jsxs)(`label`,{children:[`Kind`,(0,v.jsxs)(`select`,{"aria-label":`Memory kind`,className:`${b} ml-2 cursor-pointer`,value:w,onChange:e=>T(e.target.value),children:[(0,v.jsx)(`option`,{value:``,children:`All`}),[`research`,`decision`,`review`].map(e=>(0,v.jsx)(`option`,{children:e},e))]})]}),(0,v.jsxs)(`label`,{children:[`Instrument`,(0,v.jsx)(`input`,{className:`${b} ml-2 w-24`,maxLength:32,value:E,onChange:e=>D(e.target.value)})]}),(0,v.jsxs)(`label`,{children:[`Topic`,(0,v.jsx)(`input`,{className:`${b} ml-2 w-40`,maxLength:64,value:O,onChange:e=>k(e.target.value)})]}),(0,v.jsxs)(`label`,{children:[`Producer`,(0,v.jsxs)(`select`,{className:`${b} ml-2 cursor-pointer`,value:A,onChange:e=>j(e.target.value),children:[(0,v.jsx)(`option`,{value:``,children:`All`}),t.filter(e=>!e.archived).map(e=>(0,v.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]}),(0,v.jsxs)(`label`,{children:[`Status`,(0,v.jsxs)(`select`,{className:`${b} ml-2 cursor-pointer`,value:M,onChange:e=>N(e.target.value),children:[(0,v.jsx)(`option`,{value:``,children:`All`}),[`fresh`,`stale`,`retracted`,`invalid_evidence`,`durable`].map(e=>(0,v.jsx)(`option`,{children:e},e))]})]}),(0,v.jsxs)(`label`,{children:[`From (UTC)`,(0,v.jsx)(`input`,{type:`date`,className:`${b} ml-2`,value:I,onChange:e=>L(e.target.value)})]}),(0,v.jsxs)(`label`,{children:[`Until exclusive (UTC)`,(0,v.jsx)(`input`,{type:`date`,className:`${b} ml-2`,value:R,onChange:e=>z(e.target.value)})]}),(0,v.jsx)(`input`,{"aria-label":`Search memory summaries`,placeholder:`Search summaries`,className:b,maxLength:200,value:P,onChange:e=>F(e.target.value)}),(0,v.jsx)(`button`,{className:y,disabled:Y,children:`Apply filters`})]})]}),(0,v.jsx)(`div`,{className:`space-y-4`,children:(0,v.jsxs)(`section`,{className:`min-w-0 space-y-4`,"aria-label":`Memory publications`,children:[(0,v.jsx)(`div`,{className:`overflow-x-auto rounded-xl border border-zinc-800`,children:(0,v.jsxs)(`table`,{className:`w-full text-left text-sm`,"aria-label":`Memories`,"aria-busy":Y,children:[(0,v.jsx)(`thead`,{className:`border-b border-zinc-800 bg-zinc-900/50 text-xs text-zinc-400`,children:(0,v.jsx)(`tr`,{children:[`Memory`,`Kind`,`Instrument`,`Topic / interval`,`Status`,`Producer`,`Created`].map(e=>(0,v.jsx)(`th`,{scope:`col`,className:`whitespace-nowrap px-4 py-3 font-medium`,children:e},e))})}),(0,v.jsxs)(`tbody`,{className:`divide-y divide-zinc-800`,children:[K.map(n=>(0,v.jsxs)(`tr`,{className:`hover:bg-zinc-900/50`,children:[(0,v.jsx)(`td`,{className:`min-w-64 px-4 py-3`,children:(0,v.jsxs)(i,{to:`/agents/$agentId/memories/$memoryRef`,params:{agentId:e,memoryRef:n.ref},className:`block w-full cursor-pointer space-y-1 text-left hover:text-violet-300`,children:[(0,v.jsx)(`span`,{className:`block font-medium text-violet-300`,children:n.ref}),(0,v.jsx)(`span`,{className:`block break-words`,children:n.summary})]})}),(0,v.jsx)(`td`,{className:`px-4 py-3 align-top`,children:(0,v.jsx)(g,{value:n.kind})}),(0,v.jsx)(`td`,{className:`whitespace-nowrap px-4 py-3 align-top`,children:n.instrument?(0,v.jsx)(f,{symbol:n.instrument,iconOnly:!0}):`Agent-wide`}),(0,v.jsxs)(`td`,{className:`px-4 py-3 align-top`,children:[(0,v.jsx)(g,{value:n.topic}),(0,v.jsx)(`span`,{className:`mt-1 block text-xs text-zinc-500`,children:n.interval??`—`})]}),(0,v.jsxs)(`td`,{className:`px-4 py-3 align-top`,children:[(0,v.jsx)(h,{status:n.status}),(0,v.jsx)(m,{agentId:e,memory:{correctedBy:n.correctedBy,supersededBy:null}})]}),(0,v.jsx)(`td`,{className:`px-4 py-3 align-top`,children:t.find(e=>e.id===n.producerSubagentId)?.name??`Root`}),(0,v.jsx)(`td`,{className:`whitespace-nowrap px-4 py-3 align-top text-xs text-zinc-400`,children:(0,v.jsx)(p,{timestamp:n.createdAt})})]},n.ref)),!K.length&&(0,v.jsx)(`tr`,{children:(0,v.jsx)(`td`,{colSpan:7,className:`px-4 py-8 text-center text-zinc-400`,children:`No memories found. Try different filters, or configure an analysis/review worker and its memory tools.`})})]})]})}),(0,v.jsx)(`button`,{className:y,disabled:Y||W.isPlaceholderData||!!W.error||!q,onClick:()=>{q&&C(e=>({...e,cursor:q}))},children:`Next page`})]})})]}):(0,v.jsxs)(`section`,{className:`space-y-4`,children:[(0,v.jsx)(`p`,{className:`text-sm text-zinc-400`,children:`Insights are read-only, managed by a Review sub-agent`}),(0,v.jsxs)(`div`,{className:`grid min-h-80 grid-cols-1 overflow-hidden rounded-xl border border-zinc-800 md:grid-cols-[14rem_minmax(0,1fr)]`,children:[(0,v.jsx)(`nav`,{"aria-label":`Insights scope`,className:`space-y-1 border-b border-zinc-800 bg-zinc-900/30 p-3 md:border-r md:border-b-0`,children:[{id:``,name:`Global`},...t.filter(e=>e.kind===`worker`&&!e.archived)].map(e=>(0,v.jsx)(`button`,{type:`button`,"aria-current":B===e.id?`true`:void 0,disabled:Y,onClick:()=>Q(e.id),className:`block w-full cursor-pointer rounded-lg px-3 py-2 text-left text-sm disabled:cursor-not-allowed ${B===e.id?`bg-violet-500/10 text-violet-300`:`text-zinc-400 hover:bg-zinc-800 hover:text-white`}`,children:e.name},e.id))}),(0,v.jsxs)(`article`,{"aria-label":`Latest insights`,"aria-busy":Y,className:`min-w-0 space-y-5 p-5`,children:[(0,v.jsxs)(`header`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[(0,v.jsx)(`h2`,{className:`font-medium text-white`,children:B?t.find(e=>e.id===B)?.name??`Sub-agent`:`Global`}),J&&(0,v.jsxs)(`span`,{className:`text-xs text-zinc-500`,children:[`Latest · v`,J.current.version]})]}),J?(0,v.jsxs)(v.Fragment,{children:[(0,v.jsx)(`pre`,{className:`min-h-40 whitespace-pre-wrap break-words font-sans text-sm leading-relaxed`,children:J.current.content||`No insights yet.`}),J.head&&(0,v.jsxs)(`p`,{className:`text-xs text-zinc-500`,children:[`Updated `,new Date(J.head.createdAt).toISOString()]}),(0,v.jsxs)(`details`,{className:`border-t border-zinc-800 pt-4`,children:[(0,v.jsx)(`summary`,{className:`cursor-pointer text-sm text-zinc-400 hover:text-white`,children:`Revision history`}),(0,v.jsx)(`ul`,{className:`mt-3 space-y-3 text-xs text-zinc-400`,children:J.history?.items.map(e=>(0,v.jsxs)(`li`,{children:[(0,v.jsxs)(`span`,{className:`text-zinc-200`,children:[`v`,e.version]}),` · `,new Date(e.createdAt).toISOString(),(0,v.jsx)(`p`,{className:`mt-1`,children:e.reason})]},e.version))}),!J.history?.items.length&&(0,v.jsx)(`p`,{className:`mt-3 text-sm text-zinc-500`,children:`No revisions yet.`}),J.history?.nextBeforeVersion&&(0,v.jsx)(`button`,{className:`${y} mt-3`,disabled:Y,onClick:()=>U(J.history.nextBeforeVersion),children:`Older revisions`})]},B)]}):(0,v.jsx)(`p`,{className:`text-sm text-zinc-500`,children:Y?`Loading insights…`:`Insights unavailable.`})]})]})]})]})}function S(){let{agentId:e}=d.useParams(),{scope:t,version:n}=d.useSearch(),{data:r}=s(c(e));return(0,v.jsx)(x,{agentId:e,workers:r,scopeId:t,version:n,initialTab:t!==void 0||n!==void 0?`insights`:`memories`},`${e}:${t===void 0?`publications`:t}:${n??``}`)}export{S as component};