openagentd 0.1.0__py3-none-any.whl
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.
- app/_web_dist/assets/KaTeX_AMS-Regular-BQhdFMY1.woff2 +0 -0
- app/_web_dist/assets/KaTeX_AMS-Regular-DMm9YOAa.woff +0 -0
- app/_web_dist/assets/KaTeX_AMS-Regular-DRggAlZN.ttf +0 -0
- app/_web_dist/assets/KaTeX_Caligraphic-Bold-ATXxdsX0.ttf +0 -0
- app/_web_dist/assets/KaTeX_Caligraphic-Bold-BEiXGLvX.woff +0 -0
- app/_web_dist/assets/KaTeX_Caligraphic-Bold-Dq_IR9rO.woff2 +0 -0
- app/_web_dist/assets/KaTeX_Caligraphic-Regular-CTRA-rTL.woff +0 -0
- app/_web_dist/assets/KaTeX_Caligraphic-Regular-Di6jR-x-.woff2 +0 -0
- app/_web_dist/assets/KaTeX_Caligraphic-Regular-wX97UBjC.ttf +0 -0
- app/_web_dist/assets/KaTeX_Fraktur-Bold-BdnERNNW.ttf +0 -0
- app/_web_dist/assets/KaTeX_Fraktur-Bold-BsDP51OF.woff +0 -0
- app/_web_dist/assets/KaTeX_Fraktur-Bold-CL6g_b3V.woff2 +0 -0
- app/_web_dist/assets/KaTeX_Fraktur-Regular-CB_wures.ttf +0 -0
- app/_web_dist/assets/KaTeX_Fraktur-Regular-CTYiF6lA.woff2 +0 -0
- app/_web_dist/assets/KaTeX_Fraktur-Regular-Dxdc4cR9.woff +0 -0
- app/_web_dist/assets/KaTeX_Main-Bold-Cx986IdX.woff2 +0 -0
- app/_web_dist/assets/KaTeX_Main-Bold-Jm3AIy58.woff +0 -0
- app/_web_dist/assets/KaTeX_Main-Bold-waoOVXN0.ttf +0 -0
- app/_web_dist/assets/KaTeX_Main-BoldItalic-DxDJ3AOS.woff2 +0 -0
- app/_web_dist/assets/KaTeX_Main-BoldItalic-DzxPMmG6.ttf +0 -0
- app/_web_dist/assets/KaTeX_Main-BoldItalic-SpSLRI95.woff +0 -0
- app/_web_dist/assets/KaTeX_Main-Italic-3WenGoN9.ttf +0 -0
- app/_web_dist/assets/KaTeX_Main-Italic-BMLOBm91.woff +0 -0
- app/_web_dist/assets/KaTeX_Main-Italic-NWA7e6Wa.woff2 +0 -0
- app/_web_dist/assets/KaTeX_Main-Regular-B22Nviop.woff2 +0 -0
- app/_web_dist/assets/KaTeX_Main-Regular-Dr94JaBh.woff +0 -0
- app/_web_dist/assets/KaTeX_Main-Regular-ypZvNtVU.ttf +0 -0
- app/_web_dist/assets/KaTeX_Math-BoldItalic-B3XSjfu4.ttf +0 -0
- app/_web_dist/assets/KaTeX_Math-BoldItalic-CZnvNsCZ.woff2 +0 -0
- app/_web_dist/assets/KaTeX_Math-BoldItalic-iY-2wyZ7.woff +0 -0
- app/_web_dist/assets/KaTeX_Math-Italic-DA0__PXp.woff +0 -0
- app/_web_dist/assets/KaTeX_Math-Italic-flOr_0UB.ttf +0 -0
- app/_web_dist/assets/KaTeX_Math-Italic-t53AETM-.woff2 +0 -0
- app/_web_dist/assets/KaTeX_SansSerif-Bold-CFMepnvq.ttf +0 -0
- app/_web_dist/assets/KaTeX_SansSerif-Bold-D1sUS0GD.woff2 +0 -0
- app/_web_dist/assets/KaTeX_SansSerif-Bold-DbIhKOiC.woff +0 -0
- app/_web_dist/assets/KaTeX_SansSerif-Italic-C3H0VqGB.woff2 +0 -0
- app/_web_dist/assets/KaTeX_SansSerif-Italic-DN2j7dab.woff +0 -0
- app/_web_dist/assets/KaTeX_SansSerif-Italic-YYjJ1zSn.ttf +0 -0
- app/_web_dist/assets/KaTeX_SansSerif-Regular-BNo7hRIc.ttf +0 -0
- app/_web_dist/assets/KaTeX_SansSerif-Regular-CS6fqUqJ.woff +0 -0
- app/_web_dist/assets/KaTeX_SansSerif-Regular-DDBCnlJ7.woff2 +0 -0
- app/_web_dist/assets/KaTeX_Script-Regular-C5JkGWo-.ttf +0 -0
- app/_web_dist/assets/KaTeX_Script-Regular-D3wIWfF6.woff2 +0 -0
- app/_web_dist/assets/KaTeX_Script-Regular-D5yQViql.woff +0 -0
- app/_web_dist/assets/KaTeX_Size1-Regular-C195tn64.woff +0 -0
- app/_web_dist/assets/KaTeX_Size1-Regular-Dbsnue_I.ttf +0 -0
- app/_web_dist/assets/KaTeX_Size1-Regular-mCD8mA8B.woff2 +0 -0
- app/_web_dist/assets/KaTeX_Size2-Regular-B7gKUWhC.ttf +0 -0
- app/_web_dist/assets/KaTeX_Size2-Regular-Dy4dx90m.woff2 +0 -0
- app/_web_dist/assets/KaTeX_Size2-Regular-oD1tc_U0.woff +0 -0
- app/_web_dist/assets/KaTeX_Size3-Regular-CTq5MqoE.woff +0 -0
- app/_web_dist/assets/KaTeX_Size3-Regular-DgpXs0kz.ttf +0 -0
- app/_web_dist/assets/KaTeX_Size4-Regular-BF-4gkZK.woff +0 -0
- app/_web_dist/assets/KaTeX_Size4-Regular-DWFBv043.ttf +0 -0
- app/_web_dist/assets/KaTeX_Size4-Regular-Dl5lxZxV.woff2 +0 -0
- app/_web_dist/assets/KaTeX_Typewriter-Regular-C0xS9mPB.woff +0 -0
- app/_web_dist/assets/KaTeX_Typewriter-Regular-CO6r4hn1.woff2 +0 -0
- app/_web_dist/assets/KaTeX_Typewriter-Regular-D3Ib7_Hf.ttf +0 -0
- app/_web_dist/assets/geist-cyrillic-wght-normal-CHSlOQsW.woff2 +0 -0
- app/_web_dist/assets/geist-latin-ext-wght-normal-DMtmJ5ZE.woff2 +0 -0
- app/_web_dist/assets/geist-latin-wght-normal-Dm3htQBi.woff2 +0 -0
- app/_web_dist/assets/icons-Cve-nyhR.js +1 -0
- app/_web_dist/assets/index-DHPqqY4k.css +1 -0
- app/_web_dist/assets/index-DVbaNufb.js +114 -0
- app/_web_dist/assets/markdown-DCdXDE68.js +295 -0
- app/_web_dist/assets/motion-Dtlq51X3.js +9 -0
- app/_web_dist/assets/react-pOt6xq52.js +9 -0
- app/_web_dist/assets/state-utils-BJHjF9wM.js +39 -0
- app/_web_dist/assets/tanstack-C2OVNDqD.js +1 -0
- app/_web_dist/assets/ui-1Crwy0Ew.js +12 -0
- app/_web_dist/favicon.svg +6 -0
- app/_web_dist/index.html +43 -0
- app/agent/__init__.py +0 -0
- app/agent/agent_loop/__init__.py +32 -0
- app/agent/agent_loop/core.py +508 -0
- app/agent/agent_loop/retry.py +193 -0
- app/agent/agent_loop/streaming.py +207 -0
- app/agent/agent_loop/tool_dispatch.py +95 -0
- app/agent/agent_loop/tool_executor.py +128 -0
- app/agent/checkpointer.py +410 -0
- app/agent/drift.py +57 -0
- app/agent/errors.py +105 -0
- app/agent/hooks/__init__.py +29 -0
- app/agent/hooks/base.py +131 -0
- app/agent/hooks/dynamic_prompt.py +176 -0
- app/agent/hooks/memory_flush.py +20 -0
- app/agent/hooks/otel.py +388 -0
- app/agent/hooks/session_log.py +201 -0
- app/agent/hooks/stream_publisher.py +285 -0
- app/agent/hooks/streaming.py +143 -0
- app/agent/hooks/summarization.py +511 -0
- app/agent/hooks/telemetry.py +113 -0
- app/agent/hooks/title_generation.py +231 -0
- app/agent/hooks/tool_result_offload.py +206 -0
- app/agent/hooks/wiki_injection.py +180 -0
- app/agent/loader.py +635 -0
- app/agent/mcp/__init__.py +41 -0
- app/agent/mcp/config.py +152 -0
- app/agent/mcp/manager.py +438 -0
- app/agent/mcp/tools.py +174 -0
- app/agent/mode/team/__init__.py +14 -0
- app/agent/mode/team/hooks/__init__.py +7 -0
- app/agent/mode/team/hooks/team_inbox.py +87 -0
- app/agent/mode/team/hooks/team_prompt.py +56 -0
- app/agent/mode/team/mailbox.py +118 -0
- app/agent/mode/team/member.py +825 -0
- app/agent/mode/team/team.py +345 -0
- app/agent/mode/team/tools.py +97 -0
- app/agent/multimodal.py +117 -0
- app/agent/permission.py +379 -0
- app/agent/plugins/__init__.py +56 -0
- app/agent/plugins/events.py +56 -0
- app/agent/plugins/loader.py +346 -0
- app/agent/plugins/role.py +44 -0
- app/agent/providers/__init__.py +3 -0
- app/agent/providers/base.py +72 -0
- app/agent/providers/bedrock/__init__.py +5 -0
- app/agent/providers/bedrock/bedrock.py +511 -0
- app/agent/providers/capabilities.py +258 -0
- app/agent/providers/capabilities.yaml +192 -0
- app/agent/providers/codex/__init__.py +3 -0
- app/agent/providers/codex/codex.py +161 -0
- app/agent/providers/codex/oauth.py +383 -0
- app/agent/providers/copilot/USAGE.md +120 -0
- app/agent/providers/copilot/__init__.py +5 -0
- app/agent/providers/copilot/copilot.py +246 -0
- app/agent/providers/copilot/oauth.py +209 -0
- app/agent/providers/copilot/schemas.py +8 -0
- app/agent/providers/deepseek/__init__.py +3 -0
- app/agent/providers/deepseek/deepseek.py +70 -0
- app/agent/providers/factory.py +237 -0
- app/agent/providers/geminicli/__init__.py +3 -0
- app/agent/providers/geminicli/geminicli.py +488 -0
- app/agent/providers/googlegenai/__init__.py +4 -0
- app/agent/providers/googlegenai/googlegenai.py +521 -0
- app/agent/providers/googlegenai/schemas.py +103 -0
- app/agent/providers/openai/__init__.py +5 -0
- app/agent/providers/openai/completions.py +366 -0
- app/agent/providers/openai/openai.py +199 -0
- app/agent/providers/openai/responses.py +464 -0
- app/agent/providers/openai/schemas.py +194 -0
- app/agent/providers/streaming.py +60 -0
- app/agent/providers/vertexai/__init__.py +3 -0
- app/agent/providers/vertexai/vertexai.py +84 -0
- app/agent/providers/xai/__init__.py +3 -0
- app/agent/providers/xai/xai.py +61 -0
- app/agent/providers/zai/__init__.py +3 -0
- app/agent/providers/zai/zai.py +86 -0
- app/agent/sandbox.py +275 -0
- app/agent/sandbox_config.py +110 -0
- app/agent/schemas/agent.py +151 -0
- app/agent/schemas/chat.py +238 -0
- app/agent/schemas/events.py +164 -0
- app/agent/state.py +210 -0
- app/agent/tool_id_resolver.py +53 -0
- app/agent/tools/__init__.py +43 -0
- app/agent/tools/builtin/__init__.py +38 -0
- app/agent/tools/builtin/date.py +9 -0
- app/agent/tools/builtin/filesystem/__init__.py +19 -0
- app/agent/tools/builtin/filesystem/edit.py +267 -0
- app/agent/tools/builtin/filesystem/glob.py +87 -0
- app/agent/tools/builtin/filesystem/grep.py +97 -0
- app/agent/tools/builtin/filesystem/handlers.py +224 -0
- app/agent/tools/builtin/filesystem/ls.py +44 -0
- app/agent/tools/builtin/filesystem/read.py +123 -0
- app/agent/tools/builtin/filesystem/rm.py +65 -0
- app/agent/tools/builtin/filesystem/write.py +49 -0
- app/agent/tools/builtin/note.py +47 -0
- app/agent/tools/builtin/schedule.py +336 -0
- app/agent/tools/builtin/shell.py +518 -0
- app/agent/tools/builtin/shell_runtime.py +132 -0
- app/agent/tools/builtin/skill.py +165 -0
- app/agent/tools/builtin/todo.py +228 -0
- app/agent/tools/builtin/web.py +167 -0
- app/agent/tools/builtin/wiki_search.py +87 -0
- app/agent/tools/multimodalities/__init__.py +12 -0
- app/agent/tools/multimodalities/_config.py +131 -0
- app/agent/tools/multimodalities/_metrics.py +75 -0
- app/agent/tools/multimodalities/backends/__init__.py +69 -0
- app/agent/tools/multimodalities/backends/codex.py +318 -0
- app/agent/tools/multimodalities/backends/googlegenai.py +230 -0
- app/agent/tools/multimodalities/backends/googlegenai_video.py +426 -0
- app/agent/tools/multimodalities/backends/openai.py +167 -0
- app/agent/tools/multimodalities/image.py +433 -0
- app/agent/tools/multimodalities/video.py +513 -0
- app/agent/tools/registry.py +367 -0
- app/alembic.ini +131 -0
- app/api/__init__.py +0 -0
- app/api/app.py +207 -0
- app/api/deps.py +65 -0
- app/api/routes/__init__.py +0 -0
- app/api/routes/agents.py +329 -0
- app/api/routes/dream.py +71 -0
- app/api/routes/health.py +68 -0
- app/api/routes/mcp.py +163 -0
- app/api/routes/observability.py +61 -0
- app/api/routes/quote.py +16 -0
- app/api/routes/scheduler.py +181 -0
- app/api/routes/settings.py +44 -0
- app/api/routes/skills.py +153 -0
- app/api/routes/team/__init__.py +34 -0
- app/api/routes/team/_helpers.py +56 -0
- app/api/routes/team/chat.py +262 -0
- app/api/routes/team/files.py +189 -0
- app/api/routes/team/permissions.py +82 -0
- app/api/routes/team/todos.py +38 -0
- app/api/routes/wiki.py +136 -0
- app/api/schemas/__init__.py +37 -0
- app/api/schemas/agents.py +64 -0
- app/api/schemas/base.py +24 -0
- app/api/schemas/chat.py +59 -0
- app/api/schemas/mcp.py +80 -0
- app/api/schemas/sessions.py +67 -0
- app/api/schemas/skills.py +33 -0
- app/api/schemas/team.py +81 -0
- app/cli/__init__.py +75 -0
- app/cli/commands/__init__.py +5 -0
- app/cli/commands/auth.py +107 -0
- app/cli/commands/doctor.py +230 -0
- app/cli/commands/init.py +341 -0
- app/cli/commands/logs.py +23 -0
- app/cli/commands/start.py +133 -0
- app/cli/commands/status.py +19 -0
- app/cli/commands/stop.py +36 -0
- app/cli/commands/update.py +98 -0
- app/cli/commands/version.py +11 -0
- app/cli/firstrun.py +129 -0
- app/cli/main.py +146 -0
- app/cli/paths.py +67 -0
- app/cli/pids.py +49 -0
- app/cli/seed.py +310 -0
- app/cli/server.py +70 -0
- app/cli/ui.py +106 -0
- app/core/__init__.py +11 -0
- app/core/config.py +234 -0
- app/core/db.py +189 -0
- app/core/exception_handlers.py +112 -0
- app/core/jsonl_writer.py +227 -0
- app/core/logging_config.py +122 -0
- app/core/metrics.py +171 -0
- app/core/middlewares.py +134 -0
- app/core/otel.py +335 -0
- app/core/otel_retention.py +228 -0
- app/core/paths.py +42 -0
- app/core/version.py +8 -0
- app/core/wiki_seed.py +34 -0
- app/migrations/README +1 -0
- app/migrations/env.py +126 -0
- app/migrations/script.py.mako +29 -0
- app/migrations/versions/00000001_create_chat_sessions.py +58 -0
- app/migrations/versions/00000002_create_session_messages.py +94 -0
- app/migrations/versions/00000003_create_scheduled_task.py +67 -0
- app/migrations/versions/00000004_create_dream_log.py +60 -0
- app/models/__init__.py +3 -0
- app/models/chat.py +160 -0
- app/scheduler/__init__.py +0 -0
- app/scheduler/cron.py +97 -0
- app/scheduler/models.py +78 -0
- app/scheduler/scheduler.py +453 -0
- app/scheduler/schemas.py +143 -0
- app/server.py +28 -0
- app/services/__init__.py +0 -0
- app/services/_tool_state.py +47 -0
- app/services/agent_fs.py +204 -0
- app/services/agent_service.py +395 -0
- app/services/chat_service.py +681 -0
- app/services/dream.py +490 -0
- app/services/dream_scheduler.py +156 -0
- app/services/memory_stream_store.py +427 -0
- app/services/observability_service.py +624 -0
- app/services/quote_service.py +132 -0
- app/services/stream_envelope.py +116 -0
- app/services/team_manager.py +258 -0
- app/services/title_service.py +155 -0
- app/services/wiki.py +372 -0
- app/version.txt +1 -0
- openagentd-0.1.0.dist-info/METADATA +321 -0
- openagentd-0.1.0.dist-info/RECORD +283 -0
- openagentd-0.1.0.dist-info/WHEEL +4 -0
- openagentd-0.1.0.dist-info/entry_points.txt +2 -0
- openagentd-0.1.0.dist-info/licenses/LICENSE +218 -0
- openagentd-0.1.0.dist-info/licenses/NOTICE +5 -0
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import{j as s,r as f,b as bi,R as D,d as yi}from"./react-pOt6xq52.js";import{Q as vi,L as Te,a as ji,O as ys,u as he,b as Ve,c as wi,d as pe,e as ye,f as Ds,g as go,h as ki,i as ve,j as Ni,R as Si}from"./tanstack-C2OVNDqD.js";import{c as bo,i as yo,t as Ci,a as Ti,b as vo,s as Ft,n as Mi,_ as jo,o as wo,d as mn}from"./state-utils-BJHjF9wM.js";import{A as be,u as xr,a as Di,m as se,b as _i,c as Ei}from"./motion-Dtlq51X3.js";import{I as ko,C as Ie,a as Oi,X as Ee,H as Pi,G as $i,A as No,S as Wn,W as zi,b as ns,c as hr,F as Tt,M as pr,V as gr,d as Ri,e as _s,P as rs,f as os,g as Xe,D as Ln,h as Ai,i as Fi,j as vt,k as Lt,l as Es,m as Wi,E as So,n as Gs,o as Bs,p as br,q as Be,L as _e,r as ws,T as Os,s as Co,t as Li,u as Ii,v as To,w as ct,x as Mo,Z as Bi,y as Do,z as Yi,B as _o,J as qi,K as Hi,N as Ps,O as yr,Q as Ui,R as Qi,U as Eo,Y as Ki,_ as Gi,$ as Vi,a0 as Xi,a1 as Zi,a2 as Ji,a3 as el,a4 as tl,a5 as sl,a6 as nl,a7 as rl,a8 as ol,a9 as al,aa as il,ab as ll,ac as cl,ad as dl,ae as ul,af as Oo,ag as ml,ah as fl,ai as xl,aj as hl}from"./icons-Cve-nyhR.js";import{M as Po,r as pl,a as gl,b as $o,c as bl}from"./markdown-DCdXDE68.js";import{B as yl,P as vl,a as jl,b as wl,c as kl,d as Nl,I as Sl,S as Cl,e as Tl,f as Ml,g as Dl,h as _l,i as El,j as Ol,k as Pl,l as $l,m as zl,n as Rl,o as Al,p as Fl,q as Wl,r as Ll,T as Il,s as Bl,t as Yl,D as ql,u as Hl,v as zo,w as Ul,x as Ql,y as Kl,z as Gl,A as Vl,C as Xl,E as Zl,F as Jl,G as ec,H as tc}from"./ui-1Crwy0Ew.js";(function(){const t=document.createElement("link").relList;if(t&&t.supports&&t.supports("modulepreload"))return;for(const o of document.querySelectorAll('link[rel="modulepreload"]'))r(o);new MutationObserver(o=>{for(const a of o)if(a.type==="childList")for(const i of a.addedNodes)i.tagName==="LINK"&&i.rel==="modulepreload"&&r(i)}).observe(document,{childList:!0,subtree:!0});function n(o){const a={};return o.integrity&&(a.integrity=o.integrity),o.referrerPolicy&&(a.referrerPolicy=o.referrerPolicy),o.crossOrigin==="use-credentials"?a.credentials="include":o.crossOrigin==="anonymous"?a.credentials="omit":a.credentials="same-origin",a}function r(o){if(o.ep)return;o.ep=!0;const a=n(o);fetch(o.href,a)}})();const sc=new vi({defaultOptions:{queries:{staleTime:1e3*60*5,gcTime:1e3*60*10}}}),Ge=bo()(yo((e,t)=>({toasts:[],push:(n,r=4500)=>{const o=`t-${Date.now()}-${Math.random().toString(36).slice(2,6)}`;e(a=>{a.toasts.push({id:o,...n})}),setTimeout(()=>t().dismiss(o),r)},dismiss:n=>{e(r=>{r.toasts=r.toasts.filter(o=>o.id!==n)})}}))),nc={success:{icon:Oi,iconClass:"text-(--color-success) opacity-60"},error:{icon:Ie,iconClass:"text-(--color-error)"},info:{icon:ko,iconClass:"text-(--color-text-muted)"}},fn=60;function rc({t:e,dismiss:t}){const{icon:n,iconClass:r}=nc[e.tone],o=xr(0),a=xr(0),i=Di([o,a],([c,d])=>{const u=Math.max(Math.abs(c),Math.abs(d));return Math.max(0,1-u/(fn*1.5))});function l(){const c=o.get(),d=a.get();(c>fn||d<-fn)&&t(e.id)}return s.jsxs(se.div,{layout:!0,style:{x:o,y:a,opacity:i},variants:{enter:{opacity:0,y:-12,scale:.96,transition:{type:"spring",damping:26,stiffness:320}},visible:{opacity:1,y:0,scale:1,transition:{type:"spring",damping:26,stiffness:320}},exit:{opacity:0,x:40,scale:.96,transition:{type:"tween",duration:.15,ease:"easeIn"}}},initial:"enter",animate:"visible",exit:"exit",drag:!0,dragConstraints:{left:0,right:200,top:-200,bottom:0},dragElastic:{left:.05,right:.4,top:.4,bottom:.05},dragMomentum:!1,onDragEnd:l,whileDrag:{cursor:"grabbing"},className:"pointer-events-auto flex cursor-grab items-start gap-3 rounded-xl bg-(--color-surface-2) p-3 shadow-xl ring-1 ring-(--color-border) select-none",role:"status","aria-live":"polite",children:[s.jsx(n,{size:16,className:`mt-0.5 shrink-0 ${r}`}),s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsx("p",{className:"text-sm font-medium text-(--color-text)",children:e.title}),e.description&&s.jsx("p",{className:"mt-0.5 text-xs text-(--color-text-muted)",children:e.description})]}),s.jsx("button",{onClick:()=>t(e.id),"aria-label":"Dismiss",className:"shrink-0 rounded-md p-1 text-(--color-text-muted) transition-colors hover:bg-(--color-accent-subtle) hover:text-(--color-text)",children:s.jsx(Ee,{size:12})})]},e.id)}function oc(){const e=Ge(n=>n.toasts),t=Ge(n=>n.dismiss);return s.jsx("div",{className:"pointer-events-none fixed top-4 right-4 z-[60] flex w-full max-w-sm flex-col gap-2",children:s.jsx(be,{initial:!1,children:e.map(n=>s.jsx(rc,{t:n,dismiss:t},n.id))})})}function T(...e){return Ci(Ti(e))}function Ro({className:e,"aria-label":t="Generating…"}){return s.jsx("span",{className:T("streaming-cursor",e),role:"status","aria-label":t})}function ac({className:e,"aria-label":t="Thinking"}){return s.jsx("span",{className:T("inline-flex items-center gap-1",e),role:"status","aria-label":t,children:[0,200,400].map(n=>s.jsx("span",{className:"thinking-dot block h-1 w-1 rounded-full bg-current",style:{animationDelay:`${n}ms`}},n))})}function ic({href:e="#main",children:t="Skip to main content",className:n}){return s.jsx("a",{href:e,className:T("skip-link",n),children:t})}function lc(){return s.jsxs(ji,{client:sc,children:[s.jsx(ic,{}),s.jsx(ys,{}),s.jsx(oc,{})]})}function cc(){return s.jsxs("div",{className:"flex h-screen flex-col items-center justify-center gap-6 bg-(--color-bg)",children:[s.jsxs("div",{className:"text-center",children:[s.jsx("p",{className:"font-mono text-6xl font-bold text-(--color-text-muted)",children:"404"}),s.jsx("p",{className:"mt-3 text-sm text-(--color-text-muted)",children:"Page not found"})]}),s.jsxs(Te,{to:"/",className:"interactive-weight flex items-center gap-2 rounded-lg bg-(--color-accent-subtle) px-4 py-2 text-sm text-(--color-accent) ring-1 ring-(--color-border-strong) transition-colors hover:bg-(--color-accent-subtle)",children:[s.jsx(Pi,{size:14}),"Go home"]})]})}const In=e=>f.createElement("svg",{viewBox:"150 113 86 132",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",...e},f.createElement("path",{fill:"currentColor",d:"M184.079,145.943c-0.49-0.091-0.983,0.152-1.272,0.543l-0.064,0.107 c-0.122,0.128-0.226,0.275-0.303,0.438c-0.177,0.378-0.239,0.844-0.253,1.259c-0.012,0.358,0.018,0.716,0.075,1.069 c-0.003,0.246-0.001,0.493,0.013,0.737c0.022,0.373,0.132,0.762,0.36,1.063c0.311,0.411,0.864,0.646,1.374,0.525 c0.533-0.126,0.95-0.476,1.17-0.979c0.141-0.321,0.17-0.667,0.186-1.012c0.044-0.202,0.07-0.41,0.088-0.605 c0.065-0.723,0.033-1.602-0.299-2.265C184.933,146.385,184.578,146.036,184.079,145.943z"}),f.createElement("path",{fill:"currentColor",d:"M207.742,150.707c0.141-0.321,0.17-0.667,0.186-1.012c0.044-0.202,0.07-0.41,0.088-0.605 c0.065-0.723,0.033-1.602-0.299-2.265c-0.22-0.441-0.576-0.789-1.074-0.882c-0.491-0.091-0.983,0.152-1.272,0.543l-0.064,0.107 c-0.122,0.128-0.226,0.275-0.303,0.438c-0.177,0.378-0.239,0.844-0.253,1.259c-0.012,0.358,0.018,0.716,0.075,1.069 c-0.003,0.246-0.001,0.493,0.013,0.737c0.022,0.373,0.132,0.762,0.36,1.063c0.311,0.411,0.864,0.646,1.374,0.525 C207.106,151.56,207.522,151.21,207.742,150.707z"}),f.createElement("path",{fill:"currentColor",d:"M198.197,154.431c-0.474,0.539-0.84,1.043-1.493,1.392c-0.648,0.345-1.372,0.541-2.106,0.558 c-0.798,0.018-1.589-0.15-2.355-0.353c-0.415-0.11-0.817-0.264-1.202-0.452c-0.406-0.198-0.766-0.403-1.227-0.407 c-0.175-0.002-0.369,0.128-0.324,0.332c0.21,0.97,1.365,1.583,2.169,2.034c0.973,0.545,2.109,0.757,3.216,0.717 c0.93-0.033,1.888-0.29,2.705-0.737c0.884-0.483,1.826-1.204,2.233-2.156C200.247,154.339,198.877,153.657,198.197,154.431z"}),f.createElement("path",{fill:"currentColor",d:"M219.513,197.393l3.287-29.59h-10.145c8.853-4.757,14.731-13.052,14.731-22.474 c0-14.73-14.356-26.714-32.002-26.714c-17.646,0-32.003,11.984-32.003,26.714c0,9.423,5.878,17.718,14.731,22.474h-7.076 l1.207,10.862c-0.019,0.016-0.041,0.025-0.059,0.044c-1.279,1.354-2.291,3.006-3.413,4.492c-1.105,1.463-2.256,2.889-3.449,4.28 c-1.227,1.43-2.49,2.828-3.802,4.18c-0.97,1-2.45,2.42-1.4,3.9c0.876,1.234,3.003,1.211,4.337,1.298 c1.933,0.127,3.895,0.04,5.812-0.232c1.158-0.164,2.688-0.305,3.877-0.837l0.178,1.603h-21.982v45.345h3.651 c0.002,0.223,0.013,0.447,0.022,0.67c0.02,0.491,0.033,0.983,0.063,1.473c0.029,0.49,0.063,0.979,0.094,1.469 c0.03,0.476,0.006,1.001,0.112,1.466c0.105,0.462,0.453,0.802,0.945,0.797c0.449-0.005,0.886-0.35,0.924-0.82 c0.043-0.527-0.051-1.081-0.093-1.608c-0.039-0.488-0.078-0.977-0.117-1.465c-0.039-0.488-0.096-0.974-0.146-1.461 c-0.018-0.168-0.033-0.344-0.052-0.52h71.65c-0.008,0.057-0.017,0.117-0.025,0.171c-0.074,0.492-0.122,0.985-0.17,1.48 c-0.047,0.478-0.093,0.955-0.14,1.432c-0.061,0.617-0.276,1.426,0.321,1.848c0.233,0.164,0.563,0.237,0.83,0.102 c0.421-0.213,0.595-0.549,0.619-1.007c0.013-0.257,0.026-0.515,0.039-0.772c0.024-0.48,0.049-0.96,0.073-1.441 c0.024-0.482,0.048-0.961,0.048-1.444c0-0.121,0.001-0.246,0.001-0.37h2.82v-1.153v-44.192H219.513z M165.688,145.329 c0-13.458,13.322-24.408,29.697-24.408s29.696,10.949,29.696,24.408c0,10.09-7.492,18.763-18.141,22.474H183.83 C173.18,164.091,165.688,155.419,165.688,145.329z M220.225,170.109l-2.818,25.363h-40.975l-2.818-25.363H220.225z M173.833,193.782c-0.202,0.342-1.505,0.451-1.821,0.52c-1.225,0.269-2.469,0.44-3.719,0.542c1.238-1.051,2.815-1.71,4.457-1.637 C173.049,193.221,174.098,193.334,173.833,193.782z M169.418,192c-1.516,0.603-2.84,1.635-3.81,2.943 c-0.728-0.014-1.456-0.055-2.181-0.12c-0.416-0.037-1.266,0.01-1.637-0.262c-0.502-0.37,0.387-1.098,0.684-1.409 c1.899-1.986,3.715-4.048,5.414-6.208c0.943-1.199,1.866-2.419,2.732-3.676c0.619-0.9,1.278-1.819,1.824-2.786l1.219,10.976 C172.287,191.154,170.652,191.51,169.418,192z M154.647,199.698h76.856l0,40.734h-76.856V199.698z"}));function dc(e,t){if(!e.body){t.onError?.(new Error("No response body"));return}const n=e.body.getReader(),r=new TextDecoder;let o="",a="",i="";const l=()=>{if(i){try{const u=JSON.parse(i),m=a||u.type||"unknown";t.onEvent(m,u)}catch{t.onError?.(new Error(`SSE parse error: ${i}`))}a="",i=""}},c=u=>{if(u===""){l();return}if(u.startsWith("event:"))a=u.slice(6).trim();else if(u.startsWith("data:")){const m=u.slice(5).trim();i=i?i+`
|
|
2
|
+
`+m:m}};(async()=>{try{for(;;){const{done:u,value:m}=await n.read();if(u){const g=o.trim();g&&c(g),l(),t.onDone?.();return}o+=r.decode(m,{stream:!0});const h=o.split(`
|
|
3
|
+
`);o=h.pop()??"";for(const g of h)c(g.trimEnd())}}catch(u){t.onError?.(u instanceof Error?u:new Error(String(u)))}})()}const F="/api";async function vr(e,t,n=!1,r){const o=new FormData;if(e&&o.append("message",e),t&&o.append("session_id",t),n&&o.append("interrupt","true"),r&&r.length>0)for(const i of r)o.append("files",i);const a=await fetch(`${F}/team/chat`,{method:"POST",body:o});if(!a.ok)throw new Error(`POST /team/chat failed: ${a.status}`);return a.json()}function uc(e,t,n){fetch(`${F}/team/${encodeURIComponent(e)}/stream`,{signal:n}).then(r=>{if(!r.ok)throw new Error(`GET /team/${e}/stream failed: ${r.status}`);dc(r,t)}).catch(r=>{r.name!=="AbortError"&&t.onError?.(r)})}async function mc(){const e=await fetch(`${F}/team/agents`);if(!e.ok)throw new Error(`listTeamAgents failed: ${e.status}`);return e.json()}async function fc(e,t=20){const n=new URLSearchParams;e&&n.set("before",e),n.set("limit",String(t));const r=await fetch(`${F}/team/sessions?${n}`);if(!r.ok)throw new Error(`listTeamSessions failed: ${r.status}`);return r.json()}async function xc(e){const t=await fetch(`${F}/team/sessions/${e}`,{method:"DELETE"});if(!t.ok)throw new Error(`deleteTeamSession failed: ${t.status}`)}async function hc(e){const t=await fetch(`${F}/team/${encodeURIComponent(e)}/history`);if(!t.ok)throw new Error(`teamHistory failed: ${t.status}`);return t.json()}async function pc(e){const t=await fetch(`${F}/team/${encodeURIComponent(e)}/files`);if(!t.ok)throw new Error(`listWorkspaceFiles failed: ${t.status}`);return t.json()}function $s(e,t){const n=t.split("/").map(encodeURIComponent).join("/");return`${F}/team/${encodeURIComponent(e)}/media/${n}`}async function gc(e){const t=await fetch(`${F}/team/sessions/${encodeURIComponent(e)}/todos`);if(!t.ok)throw new Error(`getTodos failed: ${t.status}`);return t.json()}async function bc(){const e=await fetch(`${F}/health/ready`);if(!e.ok)throw new Error(`health failed: ${e.status}`);return e.json()}async function yc(e){const t=await fetch(`${F}/observability/summary?days=${e}`);if(!t.ok)throw new Error(`GET /observability/summary failed: ${t.status}`);return t.json()}async function vc(e,t=50,n=0){const r=await fetch(`${F}/observability/traces?days=${e}&limit=${t}&offset=${n}`);if(!r.ok)throw new Error(`GET /observability/traces failed: ${r.status}`);return r.json()}async function jc(e,t=30){const n=await fetch(`${F}/observability/traces/${encodeURIComponent(e)}?days=${t}`);if(n.status===404)return null;if(!n.ok)throw new Error(`GET /observability/traces/:id failed: ${n.status}`);return n.json()}async function Ao(){const e=await fetch(`${F}/team/agents`);if(e.status===404||!e.ok)return null;const n=(await e.json()).agents??[],r=n.find(o=>o.is_lead)??n[0];return r?{team:"team",lead:{name:r.name,model:r.model??"",state:"available"},members:n.filter(o=>!o.is_lead).map(o=>({name:o.name,model:o.model??"",state:"available"}))}:null}async function wc(e=!1){const t=e?`${F}/wiki/tree?unprocessed_only=true`:`${F}/wiki/tree`,n=await fetch(t);if(!n.ok)throw new Error(`GET /wiki/tree failed: ${n.status}`);return n.json()}async function kc(e){const t=await fetch(`${F}/wiki/file?path=${encodeURIComponent(e)}`);if(!t.ok)throw new Error(`GET /wiki/file failed: ${t.status}`);return t.json()}async function Nc(e,t){const n=await fetch(`${F}/wiki/file`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:e,content:t})});if(!n.ok){const r=await n.text().catch(()=>"");throw new Error(`PUT /wiki/file failed: ${n.status} ${r}`)}return n.json()}async function Sc(e){const t=await fetch(`${F}/wiki/file?path=${encodeURIComponent(e)}`,{method:"DELETE"});if(!t.ok)throw new Error(`DELETE /wiki/file failed: ${t.status}`)}async function Cc(){const e=await fetch(`${F}/dream/config`);if(!e.ok)throw new Error(`GET /dream/config failed: ${e.status}`);return e.json()}async function Tc(e){const t=await fetch(`${F}/dream/config`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({content:e})});if(!t.ok){const n=await t.text().catch(()=>"");throw new Error(`PUT /dream/config failed: ${t.status} ${n}`)}return t.json()}async function Mc(){const e=await fetch(`${F}/dream/run`,{method:"POST"});if(!e.ok){const t=await e.text().catch(()=>"");throw new Error(`POST /dream/run failed: ${e.status} ${t}`)}return e.json()}class Mt extends Error{status;constructor(t,n){super(n),this.status=t,this.name="ApiValidationError"}}async function Ne(e,t){let n=`${t} failed: ${e.status}`;try{const r=await e.json();typeof r?.detail=="string"?n=r.detail:Array.isArray(r?.detail)&&(n=r.detail.map(o=>o.msg).join("; "))}catch{}throw new Mt(e.status,n)}async function Dc(){const e=await fetch(`${F}/agents`);if(!e.ok)throw new Error(`listAgents failed: ${e.status}`);return e.json()}async function _c(e){const t=await fetch(`${F}/agents/${encodeURIComponent(e)}`);return t.ok||await Ne(t,`GET /agents/${e}`),t.json()}async function Ec(e,t){const n=await fetch(`${F}/agents`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:e,content:t})});return n.ok||await Ne(n,"POST /agents"),n.json()}async function Oc(e,t){const n=await fetch(`${F}/agents/${encodeURIComponent(e)}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:e,content:t})});return n.ok||await Ne(n,`PUT /agents/${e}`),n.json()}async function Pc(){const e=await fetch(`${F}/agents/registry`);if(!e.ok)throw new Error(`getRegistry failed: ${e.status}`);return e.json()}async function $c(){const e=await fetch(`${F}/skills`);if(!e.ok)throw new Error(`listSkills failed: ${e.status}`);return e.json()}async function zc(e){const t=await fetch(`${F}/skills/${encodeURIComponent(e)}`);return t.ok||await Ne(t,`GET /skills/${e}`),t.json()}async function Rc(e,t){const n=await fetch(`${F}/skills`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:e,content:t})});return n.ok||await Ne(n,"POST /skills"),n.json()}async function Ac(e,t){const n=await fetch(`${F}/skills/${encodeURIComponent(e)}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:e,content:t})});return n.ok||await Ne(n,`PUT /skills/${e}`),n.json()}async function Fc(){const e=await fetch(`${F}/scheduler/tasks`);if(!e.ok)throw new Error(`listScheduledTasks failed: ${e.status}`);return e.json()}async function Wc(e){const t=await fetch(`${F}/scheduler/tasks`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)});return t.ok||await Ne(t,"POST /scheduler/tasks"),t.json()}async function Lc(e,t){const n=await fetch(`${F}/scheduler/tasks/${encodeURIComponent(e)}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)});return n.ok||await Ne(n,`PUT /scheduler/tasks/${e}`),n.json()}async function Ic(e){const t=await fetch(`${F}/scheduler/tasks/${encodeURIComponent(e)}`,{method:"DELETE"});t.ok||await Ne(t,`DELETE /scheduler/tasks/${e}`)}async function Bc(e){const t=await fetch(`${F}/scheduler/tasks/${encodeURIComponent(e)}/pause`,{method:"POST"});return t.ok||await Ne(t,`POST /scheduler/tasks/${e}/pause`),t.json()}async function Yc(e){const t=await fetch(`${F}/scheduler/tasks/${encodeURIComponent(e)}/resume`,{method:"POST"});return t.ok||await Ne(t,`POST /scheduler/tasks/${e}/resume`),t.json()}async function qc(e){const t=await fetch(`${F}/scheduler/tasks/${encodeURIComponent(e)}/trigger`,{method:"POST"});return t.ok||await Ne(t,`POST /scheduler/tasks/${e}/trigger`),t.json()}async function Hc(){const e=await fetch(`${F}/mcp/servers`);if(!e.ok)throw new Error(`listMcpServers failed: ${e.status}`);return e.json()}async function Uc(e){const t=await fetch(`${F}/mcp/servers/${encodeURIComponent(e)}`);return t.ok||await Ne(t,`GET /mcp/servers/${e}`),t.json()}async function Qc(e,t){const n=await fetch(`${F}/mcp/servers`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:e,server:t})});return n.ok||await Ne(n,"POST /mcp/servers"),n.json()}async function Kc(e,t){const n=await fetch(`${F}/mcp/servers/${encodeURIComponent(e)}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({server:t})});return n.ok||await Ne(n,`PUT /mcp/servers/${e}`),n.json()}async function Gc(e){const t=await fetch(`${F}/mcp/servers/${encodeURIComponent(e)}/restart`,{method:"POST"});return t.ok||await Ne(t,`POST /mcp/servers/${e}/restart`),t.json()}async function Vc(){const e=await fetch(`${F}/settings/sandbox`);return e.ok||await Ne(e,"GET /settings/sandbox"),e.json()}async function Xc(e){const t=await fetch(`${F}/settings/sandbox`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)});return t.ok||await Ne(t,"PUT /settings/sandbox"),t.json()}const $={health:()=>["health"],agents:()=>["agents"],team:{status:()=>["team","status"],sessions:{all:()=>["team","sessions"],infinite:()=>["team","sessions","infinite"],list:(e,t)=>["team","sessions","list",e,t],detail:e=>["team","sessions",e]},files:e=>["team","files",e]},quote:()=>["quote"],wiki:{all:()=>["wiki"],tree:()=>["wiki","tree"],file:e=>["wiki","file",e]},dream:{config:()=>["dream","config"]},agentFiles:{all:()=>["agentFiles"],list:()=>["agentFiles","list"],detail:e=>["agentFiles","detail",e],registry:()=>["agentFiles","registry"]},skillFiles:{all:()=>["skillFiles"],list:()=>["skillFiles","list"],detail:e=>["skillFiles","detail",e]},observability:{summary:e=>["observability","summary",e],traces:(e,t,n)=>["observability","traces",e,t,n],trace:e=>["observability","trace",e]},scheduler:{all:()=>["scheduler"],list:()=>["scheduler","list"]},todos:e=>["todos",e],mcp:{all:()=>["mcp"],list:()=>["mcp","list"],detail:e=>["mcp","detail",e]},settings:{sandbox:()=>["settings","sandbox"]}};function Fo(){return he({queryKey:$.health(),queryFn:bc,retry:3,retryDelay:1e3,refetchInterval:3e4,refetchIntervalInBackground:!1})}function Zc(){return he({queryKey:$.team.status(),queryFn:Ao,retry:!1,staleTime:1/0})}function Jc(){const e=Ve(),t=Fo(),n=Zc(),r=t.isSuccess,o=n.isSuccess&&n.data!==null,a=t.isLoading||n.isLoading,i=t.isError;return s.jsx("div",{className:"flex h-screen flex-col items-center justify-center bg-(--color-bg) px-4",children:s.jsxs(se.div,{initial:{opacity:0,y:24},animate:{opacity:1,y:0},transition:{duration:.45,ease:"easeOut"},className:"flex w-full max-w-sm flex-col items-center gap-8",children:[s.jsxs("div",{className:"flex flex-col items-center gap-4",children:[s.jsxs("div",{className:"relative",children:[s.jsx("div",{className:"absolute inset-0 rounded-3xl bg-(--color-accent-subtle) blur-2xl"}),s.jsx("div",{className:"relative flex h-20 w-20 items-center justify-center rounded-3xl bg-(--color-accent-subtle) ring-1 ring-(--color-accent-subtle)",children:s.jsx(In,{width:40,height:40,className:"text-(--color-accent)"})})]}),s.jsxs("div",{className:"text-center",children:[s.jsx("h1",{className:"text-3xl font-bold tracking-tight text-(--color-text)",children:"OpenAgentd"}),s.jsx("p",{className:"mt-1 text-sm text-(--color-text-muted)",children:"Your on-machine AI assistant"})]})]}),s.jsxs("div",{className:"flex w-full flex-col gap-3",children:[s.jsx(xn,{icon:$i,title:"Cockpit",description:a&&!i?"Checking team…":o?`${[n.data.lead,...n.data.members].length} agents ready`:"No team configured",disabled:!r||!o,loading:a&&!i,onClick:()=>e({to:"/cockpit"})}),s.jsx(xn,{icon:No,title:"Telemetry",description:"Span aggregates & latency",disabled:!r,loading:a&&!i,onClick:()=>e({to:"/telemetry"})}),s.jsx(xn,{icon:Wn,title:"Settings",description:"Agents, skills, MCP servers, sandbox",disabled:!r,loading:a&&!i,onClick:()=>e({to:"/settings"})})]}),s.jsx("div",{className:"flex items-center gap-2 text-xs",children:a&&!i?s.jsx("span",{className:"animate-pulse text-(--color-text-muted)",children:"Connecting…"}):i?s.jsxs(s.Fragment,{children:[s.jsx(Ie,{size:12,className:"text-(--color-error)"}),s.jsx("span",{className:"text-(--color-error)",children:"Backend unreachable"})]}):s.jsxs(s.Fragment,{children:[s.jsx(zi,{size:12,className:"text-(--color-success)"}),s.jsx("span",{className:"text-(--color-text-muted)",children:"Connected"})]})})]})})}function xn({icon:e,title:t,description:n,disabled:r,loading:o,onClick:a}){return s.jsxs(se.button,{whileHover:r?{}:{scale:1.015},whileTap:r?{}:{scale:.985},onClick:r?void 0:a,disabled:r,className:`flex w-full items-center gap-4 rounded-2xl border px-5 py-4 text-left transition-all ${r?"cursor-not-allowed border-(--color-accent-dim) bg-(--color-accent-dim) opacity-40":"border-(--color-accent-subtle) bg-(--color-surface-2) hover:border-(--color-border-strong) hover:bg-(--color-accent-dim)"}`,children:[s.jsx("div",{className:`flex h-10 w-10 shrink-0 items-center justify-center rounded-xl ${r?"bg-(--color-accent-dim)":"bg-(--color-accent-subtle) ring-1 ring-(--color-border-strong)"}`,children:s.jsx(e,{size:18,className:r?"text-(--color-text-muted)":o?"animate-pulse text-(--color-accent)":"text-(--color-accent)"})}),s.jsxs("div",{className:"min-w-0",children:[s.jsx("p",{className:"text-sm font-semibold text-(--color-text)",children:t}),s.jsx("p",{className:"mt-0.5 text-xs text-(--color-text-muted)",children:n})]})]})}const ed=e=>f.createElement("svg",{viewBox:"150 113 86 132",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",...e},f.createElement("path",{fill:"currentColor",d:"M184.079,145.943c-0.49-0.091-0.983,0.152-1.272,0.543l-0.064,0.107 c-0.122,0.128-0.226,0.275-0.303,0.438c-0.177,0.378-0.239,0.844-0.253,1.259c-0.012,0.358,0.018,0.716,0.075,1.069 c-0.003,0.246-0.001,0.493,0.013,0.737c0.022,0.373,0.132,0.762,0.36,1.063c0.311,0.411,0.864,0.646,1.374,0.525 c0.533-0.126,0.95-0.476,1.17-0.979c0.141-0.321,0.17-0.667,0.186-1.012c0.044-0.202,0.07-0.41,0.088-0.605 c0.065-0.723,0.033-1.602-0.299-2.265C184.933,146.385,184.578,146.036,184.079,145.943z"}),f.createElement("path",{fill:"currentColor",d:"M207.742,150.707c0.141-0.321,0.17-0.667,0.186-1.012c0.044-0.202,0.07-0.41,0.088-0.605 c0.065-0.723,0.033-1.602-0.299-2.265c-0.22-0.441-0.576-0.789-1.074-0.882c-0.491-0.091-0.983,0.152-1.272,0.543l-0.064,0.107 c-0.122,0.128-0.226,0.275-0.303,0.438c-0.177,0.378-0.239,0.844-0.253,1.259c-0.012,0.358,0.018,0.716,0.075,1.069 c-0.003,0.246-0.001,0.493,0.013,0.737c0.022,0.373,0.132,0.762,0.36,1.063c0.311,0.411,0.864,0.646,1.374,0.525 C207.106,151.56,207.522,151.21,207.742,150.707z"}),f.createElement("path",{fill:"currentColor",d:"M198.197,154.431c-0.474,0.539-0.84,1.043-1.493,1.392c-0.648,0.345-1.372,0.541-2.106,0.558 c-0.798,0.018-1.589-0.15-2.355-0.353c-0.415-0.11-0.817-0.264-1.202-0.452c-0.406-0.198-0.766-0.403-1.227-0.407 c-0.175-0.002-0.369,0.128-0.324,0.332c0.21,0.97,1.365,1.583,2.169,2.034c0.973,0.545,2.109,0.757,3.216,0.717 c0.93-0.033,1.888-0.29,2.705-0.737c0.884-0.483,1.826-1.204,2.233-2.156C200.247,154.339,198.877,153.657,198.197,154.431z"}),f.createElement("path",{fill:"currentColor",d:"M219.513,197.393l3.287-29.59h-10.145c8.853-4.757,14.731-13.052,14.731-22.474 c0-14.73-14.356-26.714-32.002-26.714c-17.646,0-32.003,11.984-32.003,26.714c0,9.423,5.878,17.718,14.731,22.474h-7.076 l1.207,10.862c-0.019,0.016-0.041,0.025-0.059,0.044c-1.279,1.354-2.291,3.006-3.413,4.492c-1.105,1.463-2.256,2.889-3.449,4.28 c-1.227,1.43-2.49,2.828-3.802,4.18c-0.97,1-2.45,2.42-1.4,3.9c0.876,1.234,3.003,1.211,4.337,1.298 c1.933,0.127,3.895,0.04,5.812-0.232c1.158-0.164,2.688-0.305,3.877-0.837l0.178,1.603h-21.982v45.345h3.651 c0.002,0.223,0.013,0.447,0.022,0.67c0.02,0.491,0.033,0.983,0.063,1.473c0.029,0.49,0.063,0.979,0.094,1.469 c0.03,0.476,0.006,1.001,0.112,1.466c0.105,0.462,0.453,0.802,0.945,0.797c0.449-0.005,0.886-0.35,0.924-0.82 c0.043-0.527-0.051-1.081-0.093-1.608c-0.039-0.488-0.078-0.977-0.117-1.465c-0.039-0.488-0.096-0.974-0.146-1.461 c-0.018-0.168-0.033-0.344-0.052-0.52h71.65c-0.008,0.057-0.017,0.117-0.025,0.171c-0.074,0.492-0.122,0.985-0.17,1.48 c-0.047,0.478-0.093,0.955-0.14,1.432c-0.061,0.617-0.276,1.426,0.321,1.848c0.233,0.164,0.563,0.237,0.83,0.102 c0.421-0.213,0.595-0.549,0.619-1.007c0.013-0.257,0.026-0.515,0.039-0.772c0.024-0.48,0.049-0.96,0.073-1.441 c0.024-0.482,0.048-0.961,0.048-1.444c0-0.121,0.001-0.246,0.001-0.37h2.82v-1.153v-44.192H219.513z M165.688,145.329 c0-13.458,13.322-24.408,29.697-24.408s29.696,10.949,29.696,24.408c0,10.09-7.492,18.763-18.141,22.474H183.83 C173.18,164.091,165.688,155.419,165.688,145.329z M220.225,170.109l-2.818,25.363h-40.975l-2.818-25.363H220.225z M173.833,193.782c-0.202,0.342-1.505,0.451-1.821,0.52c-1.225,0.269-2.469,0.44-3.719,0.542c1.238-1.051,2.815-1.71,4.457-1.637 C173.049,193.221,174.098,193.334,173.833,193.782z M169.418,192c-1.516,0.603-2.84,1.635-3.81,2.943 c-0.728-0.014-1.456-0.055-2.181-0.12c-0.416-0.037-1.266,0.01-1.637-0.262c-0.502-0.37,0.387-1.098,0.684-1.409 c1.899-1.986,3.715-4.048,5.414-6.208c0.943-1.199,1.866-2.419,2.732-3.676c0.619-0.9,1.278-1.819,1.824-2.786l1.219,10.976 C172.287,191.154,170.652,191.51,169.418,192z M154.647,199.698h76.856l0,40.734h-76.856V199.698z"}));function Bn(){return he({queryKey:[...$.agents(),"team"],queryFn:mc,staleTime:3e4})}function Wo({status:e}){const t=e==="working"?"bg-(--color-accent) shadow-[0_0_5px_var(--color-accent)] animate-pulse":e==="error"?"bg-(--color-error)":"bg-(--color-success)";return s.jsx("span",{className:`inline-block h-2 w-2 shrink-0 rounded-full ${t}`,"aria-hidden":!0})}function td({isLead:e}){return s.jsx("span",{className:`rounded-md px-1.5 py-0.5 text-[10px] font-medium uppercase tracking-wider ${e?"bg-(--color-accent-subtle) text-(--color-accent)":"bg-(--color-accent-dim) text-(--color-text-muted)"}`,children:e?"Lead":"Member"})}function jr({chips:e}){return e.length===0?s.jsx("span",{className:"text-xs italic text-(--color-text-muted)",children:"—"}):s.jsx("div",{className:"flex flex-wrap items-center gap-1.5",children:e.map(({key:t,label:n,icon:r})=>s.jsxs("span",{className:"flex items-center gap-1 rounded-md bg-(--color-accent-subtle) px-2 py-0.5 text-xs text-(--color-text-2) ring-1 ring-(--color-border-strong)",title:n,children:[s.jsx(r,{size:11,className:"text-(--color-text-muted)"}),n]},t))})}function sd({caps:e,tools:t}){const n=e.output.image||t.some(i=>i.name==="generate_image"),r=t.some(i=>i.name==="generate_video"),o=[e.input.vision&&{key:"vision",label:"Vision",icon:hr},e.input.document_text&&{key:"docs",label:"Documents",icon:Tt},e.input.audio&&{key:"audio-in",label:"Audio",icon:pr},e.input.video&&{key:"video",label:"Video",icon:gr}].filter(Boolean),a=[e.output.text&&{key:"text-out",label:"Text",icon:Tt},n&&{key:"image-out",label:"Image",icon:hr},r&&{key:"video-out",label:"Video",icon:gr},e.output.audio&&{key:"audio-out",label:"Audio",icon:pr}].filter(Boolean);return o.length===0&&a.length===0?null:s.jsxs("section",{className:"border-t border-(--color-border) px-5 py-4",children:[s.jsx("h3",{className:"mb-2 text-[10px] font-semibold uppercase tracking-widest text-(--color-text-muted)",children:"Capabilities"}),s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx(jr,{chips:o}),o.length>0&&a.length>0&&s.jsx(Ri,{size:12,className:"text-(--color-text-subtle)","aria-hidden":!0}),s.jsx(jr,{chips:a})]})]})}function nd({name:e,description:t}){const[n,r]=f.useState(!1),o=t.trim().length>0;return s.jsxs("div",{className:"overflow-hidden rounded-lg border border-(--color-border) bg-(--color-bg) transition-colors hover:border-(--color-border-strong)",children:[s.jsxs("button",{onClick:()=>o&&r(a=>!a),className:`flex w-full items-center gap-2.5 px-3 py-2 text-left ${o?"cursor-pointer":"cursor-default"}`,children:[s.jsx(os,{size:12,className:"shrink-0 text-(--color-text-muted)"}),s.jsx("code",{className:"flex-1 truncate font-mono text-xs font-medium text-(--color-text)",children:e}),o&&s.jsx(Xe,{size:12,className:`shrink-0 text-(--color-text-muted) transition-transform duration-150 ${n?"rotate-180":""}`})]}),s.jsx(be,{initial:!1,children:n&&o&&s.jsx(se.div,{initial:{height:0,opacity:0},animate:{height:"auto",opacity:1},exit:{height:0,opacity:0},transition:{duration:.14},className:"overflow-hidden",children:s.jsx("p",{className:"border-t border-(--color-border) px-3 py-2 text-xs leading-relaxed text-(--color-text-muted)",children:t})})})]})}const rd=8;function od(e,t){const n=[...t].sort((i,l)=>l.length-i.length),r=new Map(t.map(i=>[i,[]])),o=[];for(const i of e){const l=n.find(c=>i.name.startsWith(`mcp_${c}_`));l?r.get(l).push(i):o.push(i)}const a=[];o.length>0&&a.push({server:null,tools:o});for(const i of[...t].sort())a.push({server:i,tools:r.get(i)??[]});return a}function ad({server:e,count:t}){return e===null?s.jsxs("div",{className:"flex items-center gap-2 px-5 pt-3 pb-1.5",children:[s.jsx("h4",{className:"text-[10px] font-semibold uppercase tracking-widest text-(--color-text-muted)",children:"Built-in"}),s.jsx("span",{className:"rounded-full bg-(--color-accent-dim) px-2 py-0.5 text-[10px] text-(--color-text-muted)",children:t})]}):s.jsxs("div",{className:"flex items-center gap-2 px-5 pt-3 pb-1.5",children:[s.jsx(rs,{size:11,className:"text-(--color-text-muted)","aria-hidden":!0}),s.jsxs("h4",{className:"text-[10px] font-semibold uppercase tracking-widest text-(--color-text-muted)",children:["MCP · ",e]}),s.jsx("span",{className:"rounded-full bg-(--color-accent-dim) px-2 py-0.5 text-[10px] text-(--color-text-muted)",children:t})]})}function id({tools:e,mcpServers:t}){const[n,r]=f.useState(""),o=e.length>rd,a=f.useMemo(()=>{if(!n.trim())return e;const l=n.toLowerCase();return e.filter(c=>c.name.toLowerCase().includes(l)||c.description.toLowerCase().includes(l))},[e,n]),i=f.useMemo(()=>{const l=od(a,t);return n.trim()?l.filter(c=>c.tools.length>0):l},[a,t,n]);return e.length===0&&t.length===0?null:s.jsxs("section",{className:"flex min-h-0 flex-1 flex-col border-t border-(--color-border)",children:[s.jsxs("div",{className:"flex shrink-0 items-center gap-2 px-5 pt-4 pb-2",children:[s.jsx("h3",{className:"text-[10px] font-semibold uppercase tracking-widest text-(--color-text-muted)",children:"Tools"}),s.jsx("span",{className:"rounded-full bg-(--color-accent-dim) px-2 py-0.5 text-[10px] text-(--color-text-muted)",children:e.length})]}),o&&s.jsx("div",{className:"shrink-0 px-5 pb-2",children:s.jsxs("div",{className:"flex items-center gap-2 rounded-lg border border-(--color-border) bg-(--color-bg) px-2.5 py-1.5 focus-within:border-(--color-border-strong)",children:[s.jsx(_s,{size:12,className:"shrink-0 text-(--color-text-muted)"}),s.jsx("input",{type:"text",value:n,onChange:l=>r(l.target.value),placeholder:"Filter tools…",className:"min-w-0 flex-1 bg-transparent text-xs text-(--color-text) placeholder:text-(--color-text-subtle) focus:outline-none","aria-label":"Filter tools"})]})}),s.jsx("div",{className:"flex-1 overflow-y-auto pb-5",children:a.length===0&&n.trim()?s.jsxs("p",{className:"px-5 pt-2 text-xs italic text-(--color-text-muted)",children:["No tools match “",n,"”."]}):i.map(l=>s.jsxs("div",{children:[s.jsx(ad,{server:l.server,count:l.tools.length}),s.jsx("div",{className:"space-y-1.5 px-5",children:l.tools.length===0?s.jsx("p",{className:"text-xs italic text-(--color-text-muted)",children:"Server not ready — no tools available."}):l.tools.map(c=>s.jsx(nd,{name:c.name,description:c.description},c.name))})]},l.server??"__builtin__"))})]})}function ld({skills:e}){return s.jsxs("section",{className:"border-t border-(--color-border) px-5 py-4",children:[s.jsx("h3",{className:"mb-2 text-[10px] font-semibold uppercase tracking-widest text-(--color-text-muted)",children:"Skills"}),e.length===0?s.jsx("p",{className:"text-xs italic text-(--color-text-muted)",children:"None configured."}):s.jsx("div",{className:"flex flex-wrap gap-1.5",children:e.map(t=>s.jsxs("span",{title:t.description||void 0,className:"flex cursor-default items-center gap-1 rounded-md bg-(--color-accent-subtle) px-2 py-0.5 font-mono text-xs text-(--color-text-2) ring-1 ring-(--color-border-strong)",children:[s.jsx(ns,{size:10,className:"text-(--color-text-muted)"}),t.name]},t.name))})]})}function cd({agents:e,selectedName:t,leadName:n,streams:r,onSelect:o}){return s.jsx("div",{className:"shrink-0 border-b border-(--color-border) bg-(--color-surface-2) px-3 py-2",children:s.jsx("div",{className:"flex flex-wrap items-center gap-1",children:e.map(a=>{const i=a.name===t,l=n?a.name===n:!1,c=r[a.name];return s.jsxs("button",{onClick:()=>o(a.name),className:`flex items-center gap-2 rounded-md px-2.5 py-1.5 text-xs transition-colors ${i?"bg-(--color-accent-subtle) text-(--color-text) ring-1 ring-(--color-border-strong)":"text-(--color-text-muted) hover:bg-(--color-accent-dim) hover:text-(--color-text-2)"}`,"aria-pressed":i,children:[s.jsx(Wo,{status:c?.status}),s.jsx("span",{className:`font-medium ${l?"text-(--color-accent)":""}`,children:a.name})]},a.name)})})})}function dd({open:e,agentNames:t=[],agentStreams:n={},onClose:r}){const{data:o,isLoading:a,refetch:i}=Bn();f.useEffect(()=>{e&&i()},[e]),f.useEffect(()=>{if(!e)return;const b=x=>{x.key==="Escape"&&r()};return window.addEventListener("keydown",b),()=>window.removeEventListener("keydown",b)},[e,r]);const l=o?.agents??[],c=new Map(l.map(b=>[b.name,b])),d=(()=>{if(t.length===0)return l;const b=t.map(x=>c.get(x)).filter(Boolean);return b.length>0?b:l})(),u=l.find(b=>b.is_lead),m=d.length>1?u?.name??d[0]?.name??null:null,[h,g]=f.useState(null);f.useEffect(()=>{if(d.length===0){g(null);return}(!h||!d.some(b=>b.name===h))&&g(d[0].name)},[d,h]);const p=h?c.get(h)??d[0]:d[0];return s.jsx(be,{children:e&&s.jsxs(s.Fragment,{children:[s.jsx(se.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},transition:{duration:.15},onClick:r,className:"fixed inset-0 z-40 bg-black/40"},"backdrop"),s.jsxs(se.aside,{initial:{x:"100%",opacity:0},animate:{x:0,opacity:1},exit:{x:"100%",opacity:0},transition:{duration:.22,ease:[.4,0,.2,1]},className:"fixed inset-y-0 right-0 z-50 flex w-[min(560px,90vw)] flex-col overflow-hidden border-l border-(--color-border) bg-(--color-surface) shadow-2xl",role:"dialog","aria-modal":"true","aria-label":"Agent details",children:[s.jsxs("header",{className:"flex shrink-0 items-start justify-between gap-3 border-b border-(--color-border) px-5 py-4",children:[a||!p?s.jsx("div",{className:"h-6 w-48 animate-pulse rounded bg-(--color-accent-dim)"}):s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Wo,{status:n[p.name]?.status}),s.jsx("h2",{className:"truncate text-base font-semibold text-(--color-text)",children:p.name}),s.jsx(td,{isLead:m===p.name})]}),p.model&&s.jsx("p",{className:"mt-1 truncate font-mono text-xs text-(--color-text-muted)",children:p.model})]}),s.jsx("button",{onClick:r,className:"shrink-0 rounded-md p-1.5 text-(--color-text-muted) transition-colors hover:bg-(--color-accent-subtle) hover:text-(--color-text-2)","aria-label":"Close (Esc)",title:"Close (Esc)",children:s.jsx(Ee,{size:16})})]}),d.length>1&&p&&s.jsx(cd,{agents:d,selectedName:p.name,leadName:m,streams:n,onSelect:g}),s.jsx("div",{className:"flex min-h-0 flex-1 flex-col overflow-hidden",children:a||!p?s.jsxs("div",{className:"flex-1 space-y-3 p-5",children:[s.jsx("div",{className:"h-16 animate-pulse rounded-xl bg-(--color-accent-dim)"}),s.jsx("div",{className:"h-24 animate-pulse rounded-xl bg-(--color-accent-dim)"}),s.jsx("div",{className:"h-40 animate-pulse rounded-xl bg-(--color-accent-dim)"})]}):s.jsxs(s.Fragment,{children:[s.jsxs("section",{className:"shrink-0 px-5 py-4",children:[s.jsx("h3",{className:"mb-1.5 text-[10px] font-semibold uppercase tracking-widest text-(--color-text-muted)",children:"About"}),s.jsx("p",{className:"text-sm leading-relaxed text-(--color-text-2)",children:p.description?.trim()||s.jsx("span",{className:"italic text-(--color-text-muted)",children:"No description."})})]}),s.jsx(ld,{skills:p.skills}),p.capabilities&&s.jsx(sd,{caps:p.capabilities,tools:p.tools}),s.jsx(id,{tools:p.tools,mcpServers:p.mcp_servers??[]})]})}),s.jsx("div",{className:"shrink-0 border-t border-(--color-border) px-5 py-2.5",children:s.jsx("p",{className:"text-[11px] text-(--color-text-muted)",children:"Esc or click outside to close · Ctrl+A to toggle"})})]},"drawer")]})})}const Lo=e=>f.createElement("svg",{viewBox:"37 113 86 132",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",...e},f.createElement("path",{fill:"currentColor",d:"M68.215,145.943c-0.491-0.091-0.983,0.152-1.272,0.543l-0.064,0.107 c-0.122,0.128-0.226,0.275-0.303,0.438c-0.177,0.378-0.239,0.844-0.253,1.259c-0.012,0.358,0.018,0.716,0.075,1.069 c-0.003,0.246-0.001,0.493,0.013,0.737c0.022,0.373,0.132,0.762,0.36,1.063c0.311,0.411,0.864,0.646,1.374,0.525 c0.533-0.126,0.95-0.476,1.17-0.979c0.141-0.321,0.17-0.667,0.186-1.012c0.044-0.202,0.07-0.41,0.087-0.605 c0.065-0.723,0.033-1.602-0.299-2.265C69.069,146.385,68.714,146.036,68.215,145.943z"}),f.createElement("path",{fill:"currentColor",d:"M88.975,150.097c0.022,0.373,0.132,0.762,0.36,1.063c0.311,0.411,0.864,0.646,1.374,0.525 c0.533-0.126,0.95-0.476,1.17-0.979c0.141-0.321,0.17-0.667,0.186-1.012c0.044-0.202,0.07-0.41,0.088-0.605 c0.065-0.723,0.033-1.602-0.299-2.265c-0.22-0.441-0.576-0.789-1.074-0.882c-0.491-0.091-0.983,0.152-1.272,0.543l-0.064,0.107 c-0.122,0.128-0.226,0.275-0.303,0.438c-0.177,0.378-0.239,0.844-0.253,1.259c-0.012,0.358,0.018,0.716,0.075,1.069 C88.959,149.607,88.961,149.853,88.975,150.097z"}),f.createElement("path",{fill:"currentColor",d:"M83.948,155.358c0.435-1.018-0.934-1.701-1.615-0.927c-0.474,0.539-0.84,1.043-1.493,1.392 c-0.647,0.345-1.372,0.541-2.106,0.558c-0.798,0.018-1.589-0.15-2.355-0.353c-0.415-0.11-0.817-0.264-1.202-0.452 c-0.406-0.198-0.766-0.403-1.227-0.407c-0.175-0.002-0.369,0.128-0.324,0.332c0.21,0.97,1.365,1.583,2.169,2.034 c0.973,0.545,2.109,0.757,3.216,0.717c0.93-0.033,1.887-0.29,2.705-0.737C82.598,157.031,83.541,156.31,83.948,155.358z"}),f.createElement("path",{fill:"currentColor",d:"M109.817,197.393c0.241-0.86-0.105-2.051-0.227-2.83c-0.206-1.319-0.52-2.615-0.894-3.896 c-0.79-2.71-1.905-5.32-3.164-7.844c-1.28-2.567-2.726-5.048-4.173-7.524c-1.232-2.109-2.382-4.331-3.736-6.379 c2.771-1.232,5.305-2.793,7.521-4.629c5.802-4.801,9.454-11.517,9.453-18.962c0.001-7.445-3.651-14.161-9.453-18.962 c-5.805-4.808-13.772-7.75-22.549-7.752c-8.777,0.001-16.744,2.944-22.549,7.752c-5.802,4.801-9.454,11.517-9.453,18.962 c-0.001,7.445,3.651,14.161,9.453,18.962c3.761,3.115,8.433,5.44,13.642,6.696c-0.973,0.719-1.88,1.553-2.799,2.316 c-1.364,1.133-2.711,2.287-4.064,3.432c-2.707,2.291-5.414,4.583-8.122,6.874c-1.353,1.145-2.729,2.263-4.098,3.389 c-0.684,0.563-1.383,1.111-2.053,1.689c-0.445,0.384-0.84,0.78-0.787,1.425c0.053,0.64,0.609,1.049,1.064,1.416 c0.688,0.555,1.387,1.097,2.081,1.645c1.177,0.93,2.356,1.856,3.535,2.784l-0.008-0.002c-0.967-0.287-1.596,0.796-1.064,1.436 h-17.82v45.345h3.651c0.002,0.223,0.013,0.447,0.022,0.67c0.02,0.491,0.033,0.983,0.063,1.473c0.029,0.49,0.063,0.979,0.094,1.469 c0.03,0.476,0.006,1.001,0.112,1.466c0.105,0.462,0.453,0.802,0.945,0.797c0.449-0.005,0.886-0.35,0.924-0.82 c0.043-0.527-0.051-1.081-0.093-1.608c-0.039-0.488-0.078-0.977-0.117-1.465c-0.039-0.488-0.096-0.974-0.146-1.461 c-0.017-0.168-0.033-0.344-0.052-0.52h71.65c-0.008,0.057-0.017,0.117-0.025,0.171c-0.074,0.492-0.122,0.985-0.17,1.48 c-0.047,0.478-0.094,0.955-0.14,1.432c-0.06,0.617-0.276,1.426,0.321,1.848c0.233,0.164,0.563,0.237,0.83,0.102 c0.421-0.213,0.595-0.549,0.619-1.007c0.013-0.257,0.026-0.515,0.039-0.772c0.024-0.48,0.049-0.96,0.073-1.441 c0.024-0.482,0.048-0.961,0.048-1.444c0-0.121,0.001-0.246,0.001-0.37h2.821v-1.153v-44.192H109.817z M99.928,175.72 c1.397,2.439,2.795,4.879,4.041,7.4c1.175,2.378,2.205,4.833,2.95,7.381c0.397,1.359,0.7,2.748,0.913,4.148 c0.103,0.678,0.186,1.363,0.231,2.048c0.018,0.269,0.023,0.494,0.065,0.696h-5.001c2.342-4.059-0.05-9.135-1.36-13.168 c-0.857-2.637-1.75-5.263-2.678-7.876c-0.819-2.306-1.6-4.705-2.721-6.897c0.058-0.023,0.114-0.048,0.171-0.071 C97.422,171.59,98.758,173.678,99.928,175.72z M65.46,194.012c0.014-0.011,0.024-0.027,0.037-0.039 c-0.004,0.018-0.007,0.036-0.01,0.054C65.477,194.023,65.469,194.017,65.46,194.012z M67.558,196.498 c-0.833-1.96,0.389-4.168,1.065-6.012c0.812-2.216,1.624-4.433,2.436-6.649c0.79-2.156,1.602-4.305,2.369-6.47 c0.692-1.952,1.536-3.965,1.982-6.008c2.311,0.442,4.713,0.683,7.183,0.683c4.499-0.001,8.782-0.779,12.673-2.18 c0.532,2.057,1.299,4.068,1.994,6.067c0.851,2.447,1.668,4.906,2.45,7.376c0.737,2.328,1.508,4.671,2.061,7.05 c0.473,2.035,0.821,4.387-0.407,6.229c-0.183,0.274-0.207,0.558-0.134,0.808H67.466C67.646,197.174,67.715,196.864,67.558,196.498 z M52.898,145.329c0.001-6.672,3.255-12.737,8.618-17.187c5.36-4.443,12.818-7.223,21.078-7.221 c8.26-0.001,15.718,2.778,21.078,7.221c5.363,4.45,8.617,10.514,8.618,17.187c-0.001,6.672-3.255,12.736-8.618,17.186 c-5.36,4.443-12.818,7.223-21.078,7.221c-8.26,0.001-15.718-2.778-21.078-7.221C56.153,158.065,52.9,152.001,52.898,145.329z M56.47,192.065c-0.65-0.501-1.301-1.001-1.952-1.501c-0.151-0.116-0.909-0.574-0.901-0.692c0.005-0.084,0.728-0.576,0.803-0.642 c2.334-2.049,4.67-4.094,7.031-6.111l7.081-6.047c1.156-0.987,2.317-1.97,3.463-2.969c0.334-0.291,0.677-0.578,1.022-0.868 c-0.507,1.26-0.951,2.552-1.417,3.79c-0.898,2.388-1.769,4.787-2.653,7.18c-0.862,2.333-1.725,4.667-2.587,7 c-0.157,0.424-0.323,0.871-0.475,1.329c-0.009-0.117-0.021-0.235-0.031-0.356c-0.079-0.937-0.207-1.87-0.323-2.804 c-0.028-0.224-0.071-0.445-0.113-0.668c-0.051-0.273-0.075-0.556-0.239-0.789c-0.151-0.215-0.45-0.354-0.707-0.243 c-0.275,0.119-0.407,0.406-0.418,0.69c-0.037,0.944,0.13,1.911,0.226,2.848c0.054,0.525,0.124,1.045,0.198,1.568 c0.041,0.291,0.137,0.613,0.123,0.879c-0.364-0.111-0.731-0.184-1.064-0.217c-1.403-0.138-2.792,0.232-3.911,1.055 C58.574,193.688,57.523,192.876,56.47,192.065z M64.832,196.132c-0.294,0.614-2.398,0.524-2.919,0.507 c-0.57-0.018-1.118-0.098-1.66-0.21c0.695-0.617,1.548-1.01,2.484-1.07C63.178,195.332,65.117,195.539,64.832,196.132z M41.858,199.698h76.856l0,40.734H41.858V199.698z"}));function ud(e,t){if(e.startsWith("data:")){const r=/^data:([^;,]+)/.exec(e)?.[1]?.split("/")[1]?.split("+")[0]??"png";return`${t?.trim()?t.trim().replace(/[^\w.-]+/g,"_"):`image-${Date.now()}`}.${r}`}try{const r=new URL(e,window.location.origin).pathname.split("/").filter(Boolean).pop();if(r&&r.includes("."))return r;if(r)return`${r}.png`}catch{}return`image-${Date.now()}.png`}function wr({onClick:e,icon:t,label:n,tooltip:r}){return s.jsxs("div",{className:"group relative",children:[s.jsx("button",{onClick:e,className:"flex h-10 w-10 cursor-pointer items-center justify-center rounded-lg bg-(--color-surface) text-(--color-text) transition-colors hover:bg-(--color-surface-2) focus-visible:ring-2 focus-visible:ring-(--color-text) focus-visible:outline-none","aria-label":n,children:t}),s.jsx("span",{role:"tooltip",className:"pointer-events-none absolute top-full right-0 mt-2 whitespace-nowrap rounded-md bg-(--color-surface-2) px-2 py-1 text-xs text-(--color-text) opacity-0 shadow-md transition-opacity duration-150 group-hover:opacity-100 group-focus-within:opacity-100",children:r})]})}function Yn({src:e,alt:t,isOpen:n,onClose:r}){f.useEffect(()=>{if(!n)return;const a=l=>{l.key==="Escape"&&r()},i=document.body.style.overflow;return document.body.style.overflow="hidden",document.addEventListener("keydown",a),()=>{document.removeEventListener("keydown",a),document.body.style.overflow=i}},[n,r]);const o=async()=>{const a=ud(e,t);try{const l=await(await fetch(e)).blob(),c=URL.createObjectURL(l),d=document.createElement("a");d.href=c,d.download=a,document.body.appendChild(d),d.click(),d.remove(),URL.revokeObjectURL(c)}catch{const i=document.createElement("a");i.href=e,i.download=a,i.target="_blank",i.rel="noopener noreferrer",document.body.appendChild(i),i.click(),i.remove()}};return n?bi.createPortal(s.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm transition-opacity duration-200",onClick:r,role:"dialog","aria-modal":"true","aria-label":"Image lightbox",children:[s.jsxs("div",{className:"absolute right-4 top-4 flex items-center gap-2",onClick:a=>a.stopPropagation(),children:[s.jsx(wr,{onClick:o,icon:s.jsx(Ln,{size:20}),label:"Download image",tooltip:"Download"}),s.jsx(wr,{onClick:r,icon:s.jsx(Ee,{size:20}),label:"Close lightbox",tooltip:"Close (Esc)"})]}),s.jsxs("div",{className:"flex max-h-[75vh] max-w-[75vw] flex-col items-center justify-center",onClick:a=>a.stopPropagation(),children:[s.jsx("img",{src:e,alt:t,className:"max-h-[75vh] max-w-[75vw] rounded-lg object-contain shadow-2xl"}),t&&s.jsx("p",{className:"mt-4 text-center text-sm text-(--color-text-muted)",children:t})]})]}),document.body):null}const md=[".mp4",".webm",".mov",".m4v"];function fd(e){if(!e)return!1;const t=e.split(/[?#]/,1)[0].toLowerCase();return md.some(n=>t.endsWith(n))}function xd(e){const t=e.split(`
|
|
4
|
+
`),n=[];let r=0;for(;r<t.length;){const o=t[r].match(/^(`{3,})(\w*)(.*)$/);if(o){const a=o[1],i=o[2],l=o[3],c=a.length,d=[];let u=r+1,m=1;for(;u<t.length;){const b=t[u].match(/^(`{3,})\s*(\w*).*$/);if(b&&b[1].length===c)if(b[2]===""){if(m--,m===0)break}else m++;d.push(t[u]),u++}if(m!==0||u>=t.length){n.push(t[r]),r++;continue}const g=[...d.join(`
|
|
5
|
+
`).matchAll(/`+/g)].map(b=>b[0].length),p=g.length>0?Math.max(...g):0;if(p>=c){const b="`".repeat(p+1);n.push(b+i+l),n.push(...d),n.push(b)}else n.push(t[r]),n.push(...d),n.push(t[u]);r=u+1}else n.push(t[r]),r++}return n.join(`
|
|
6
|
+
`)}function Dn(e){return typeof e=="string"?e:Array.isArray(e)?e.map(Dn).join(""):e!==null&&typeof e=="object"&&"props"in e?Dn(e.props.children):""}function hd({children:e,rawText:t}){const[n,r]=f.useState(!1),o=async()=>{try{await navigator.clipboard.writeText(t),r(!0),setTimeout(()=>r(!1),1500)}catch{}};return s.jsxs("div",{className:"surface-raised group relative my-2 overflow-hidden rounded-xl border border-(--color-border) bg-(--color-surface)",children:[s.jsx("button",{onClick:o,className:"absolute right-2 top-2 z-10 rounded-md p-1.5 text-(--color-text-muted) transition-all opacity-100 hover:bg-(--color-accent-subtle) hover:text-(--color-text-2) md:opacity-0 md:group-hover:opacity-100","aria-label":"Copy code",title:"Copy",children:n?s.jsx(vt,{size:13,className:"text-(--color-success)"}):s.jsx(Lt,{size:13})}),s.jsx("pre",{className:"overflow-x-auto p-4 font-mono text-xs leading-relaxed text-(--color-text)",children:s.jsx("code",{children:e})})]})}function pd(e,t){if(!e||/^(https?:)?\/\//i.test(e)||e.startsWith("data:")||e.startsWith("blob:")||e.startsWith("/api/")||!t)return e;const n=e.replace(/^\.\//,"").replace(/^\/+/,"");return`/api/team/${encodeURIComponent(t)}/media/${n}`}const gd=f.memo(function({src:t,alt:n,title:r}){const[o,a]=f.useState(!1);return o?s.jsxs("span",{className:"my-2 inline-flex items-center gap-2 rounded-lg border border-(--color-border) bg-(--color-surface) px-3 py-2 text-xs text-(--color-text-muted)",title:n||"Video unavailable",children:[s.jsx(Ai,{size:14}),n||"Video unavailable"]}):s.jsx("video",{src:t,title:r??n,controls:!0,preload:"metadata",playsInline:!0,onError:i=>{const l=i.currentTarget;l.networkState===l.NETWORK_NO_SOURCE&&a(!0)},className:"my-2 max-h-[80vh] max-w-full rounded-lg border border-(--color-border) bg-black",children:n||"Video content"})});function bd({src:e,alt:t,title:n}){const[r,o]=f.useState(!1),[a,i]=f.useState(!1);return!e||a?s.jsxs("span",{className:"my-2 inline-flex items-center gap-2 rounded-lg border border-(--color-border) bg-(--color-surface) px-3 py-2 text-xs text-(--color-text-muted)",title:t||"Image unavailable",children:[s.jsx(Fi,{size:14}),t||"Image unavailable"]}):fd(e)?s.jsx(gd,{src:e,alt:t,title:n}):s.jsxs(s.Fragment,{children:[s.jsx("img",{src:e,alt:t,title:n,loading:"lazy",decoding:"async",onError:()=>i(!0),onClick:()=>o(!0),className:"my-2 max-h-[80vh] max-w-full cursor-zoom-in rounded-lg border border-(--color-border) object-contain transition-opacity hover:opacity-90"}),s.jsx(Yn,{src:e,alt:t,isOpen:r,onClose:()=>o(!1)})]})}const Ys=f.memo(function({content:t,sessionId:n}){const r=f.useMemo(()=>({pre:a=>{const i=a.children,l=Dn(i?.props?.children);return s.jsx(hd,{rawText:l,children:i?.props?.children})},a:a=>s.jsx("a",{...a,target:"_blank",rel:"noopener noreferrer"}),img:({src:a,alt:i,title:l})=>s.jsx(bd,{src:pd(typeof a=="string"?a:void 0,n),alt:i??"",title:typeof l=="string"?l:void 0})}),[n]),o=f.useMemo(()=>xd(t),[t]);return s.jsx("div",{className:"oa-prose text-sm",children:s.jsx(Po,{remarkPlugins:yd,rehypePlugins:vd,components:r,children:o})})}),yd=[$o,bl],vd=[[pl,{detect:!0}],gl],Io={base:.24},Bo={out:[.16,1,.3,1]},jd=40,fs="Reasoning";function wd(e,t){if(!t||e.includes(`
|
|
7
|
+
`))return!0;const n=e.trimStart();return n.startsWith("**")?n.slice(2).includes("**"):!1}function kd(e){let t=e.trim();const n=t.match(/^\*\*(.+?)\*\*\s*$/);if(n)return n[1].trim();const r=t.match(/^[*_](.+?)[*_]\s*$/);return r?r[1].trim():(t=t.replace(/^#{1,6}\s+/,""),t=t.replace(/^(?:[>*+-]|\d+\.)\s+/,""),t.trim())}function Nd(e,t){if(!e)return{label:fs,labelFromContent:!1};if(!wd(e,!!t))return{label:fs,labelFromContent:!1};const n=e.split(`
|
|
8
|
+
`).map(o=>o.trim()).find(o=>o.length>0);if(!n)return{label:fs,labelFromContent:!1};const r=kd(n);return r?r.length>jd?{label:fs,labelFromContent:!1}:{label:r,labelFromContent:!0}:{label:fs,labelFromContent:!1}}function Sd(e){const t=e.split(`
|
|
9
|
+
`);let n=0;for(;n<t.length&&t[n].trim()==="";)n++;for(n<t.length&&n++;n<t.length&&t[n].trim()==="";)n++;return t.slice(n).join(`
|
|
10
|
+
`)}function Yo({content:e,isStreaming:t}){const[n,r]=f.useState(!1),{label:o,body:a}=f.useMemo(()=>{const{label:i,labelFromContent:l}=Nd(e,!!t),c=l?Sd(e):e;return{label:i,body:c.trim()?c:e}},[e,t]);return s.jsxs("div",{className:"my-2 border-l border-(--color-border) pl-3",children:[s.jsxs("button",{type:"button",onClick:()=>r(i=>!i),className:"group -ml-1 flex items-center gap-1.5 rounded px-1 py-0.5 text-xs text-(--color-text-muted) transition-colors duration-(--motion-fast) ease-(--ease-out) hover:text-(--color-text-2) focus-visible:outline-2 focus-visible:outline-(--color-focus-ring)","aria-expanded":n,"aria-label":n?"Collapse reasoning":"Expand reasoning",children:[s.jsx(Es,{size:12,className:`shrink-0 transition-transform duration-(--motion-fast) ease-(--ease-out) ${n?"rotate-90":""}`,"aria-hidden":!0}),s.jsxs("span",{className:"flex items-center gap-1.5 font-medium",children:[s.jsx("span",{children:o}),t&&s.jsx(ac,{className:"text-(--color-text-muted)","aria-label":`${o}…`})]})]}),s.jsx(be,{initial:!1,children:n&&s.jsx(se.div,{initial:{height:0,opacity:0},animate:{height:"auto",opacity:1},exit:{height:0,opacity:0},transition:{duration:Io.base,ease:Bo.out},className:"overflow-hidden",children:s.jsx("p",{className:"mt-1 whitespace-pre-wrap pb-1 pl-1 font-mono text-xs italic leading-relaxed text-(--color-text-muted)",children:a})},"thinking-body")})]})}function qn(e){try{return JSON.parse(e)}catch{return null}}function Cd(e,t){return e.length<=t?e:e.slice(0,t)+"…"}function Td(e){try{return new URL(e).hostname.replace(/^www\./,"")}catch{return e}}function Md({result:e}){const t=qn(e),n=Array.isArray(t)?t:typeof t=="object"&&t!==null?[t]:[];return n.length===0?s.jsx(_n,{result:e}):s.jsx("ul",{className:"space-y-2",children:n.map((r,o)=>{const a=r.href??r.url??"",i=r.title??a,l=r.body??r.snippet??"";return s.jsxs("li",{className:"group flex flex-col gap-0.5",children:[s.jsxs("div",{className:"flex items-start gap-1.5",children:[s.jsx(Wi,{size:11,className:"mt-0.5 shrink-0 text-(--color-info)"}),a?s.jsx("a",{href:a,target:"_blank",rel:"noopener noreferrer",className:"flex-1 font-mono text-xs font-semibold leading-snug text-(--color-accent) underline-offset-2 hover:underline",children:i}):s.jsx("span",{className:"flex-1 font-mono text-xs font-semibold leading-snug text-(--color-text)",children:i})]}),a&&s.jsxs("div",{className:"flex items-center gap-1 pl-5",children:[s.jsx(So,{size:9,className:"text-(--color-text-muted)"}),s.jsx("span",{className:"font-mono text-[10px] text-(--color-text-muted)",children:Td(a)})]}),l&&s.jsx("p",{className:"pl-5 font-mono text-[11px] leading-relaxed text-(--color-text-2)",children:Cd(l,200)}),o<n.length-1&&s.jsx("hr",{className:"mt-1.5 border-t border-(--color-border)"})]},o)})})}function Dd({result:e}){const t=e.indexOf(`
|
|
11
|
+
`),n=t>=0?e.slice(0,t).trim():e.trim(),r=t>=0?e.slice(t+1).trimStart():"",o=n.startsWith("[Succeeded");return s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx("span",{className:`font-mono text-[11px] font-medium ${o?"text-(--color-success)":"text-(--color-error)"}`,children:n}),r&&s.jsx("pre",{className:"max-h-64 overflow-auto whitespace-pre-wrap break-words font-mono text-[11px] leading-relaxed text-(--color-text-2)",children:r})]})}function _d({result:e}){const t=qn(e),n=Array.isArray(t)?t.map(String):e.split(`
|
|
12
|
+
`).map(r=>r.trim()).filter(Boolean);return s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsxs("span",{className:"font-mono text-[10px] text-(--color-text-muted)",children:[n.length," ",n.length===1?"entry":"entries"]}),s.jsx("ul",{className:"max-h-64 overflow-auto space-y-0.5",children:n.map((r,o)=>s.jsx("li",{className:"font-mono text-[11px] leading-relaxed text-(--color-text-2)",children:r},o))})]})}function Ed({result:e}){const t=e.match(/^\[(\d+)-(\d+)\/(\d+)\]\n([\s\S]*)$/),n=t?`lines ${t[1]}–${t[2]} of ${t[3]}`:null,r=t?t[4]:e;return s.jsxs("div",{className:"flex flex-col gap-1",children:[n&&s.jsx("span",{className:"font-mono text-[10px] text-(--color-text-muted)",children:n}),s.jsx("pre",{className:"max-h-80 overflow-auto whitespace-pre-wrap break-words font-mono text-[11px] leading-relaxed text-(--color-text-2)",children:r})]})}function Od({result:e}){const t=e.startsWith("Agent(s) not found")||e.startsWith("No valid recipients");return s.jsx("span",{className:`font-mono text-[11px] leading-relaxed ${t?"text-(--color-error)":"text-(--color-text-2)"}`,children:e})}function _n({result:e}){const t=qn(e),n=t!==null&&typeof t=="object"?JSON.stringify(t,null,2):e;return s.jsx("pre",{className:"max-h-64 overflow-auto whitespace-pre-wrap break-words font-mono text-[11px] leading-relaxed text-(--color-text-2)",children:n})}const Pd=new Set(["ls","glob","grep"]),$d=new Set(["read"]),zd=new Set(["write","edit","rm"]),Rd=new Set(["shell"]),Ad=new Set(["web_search"]);function Fd({toolName:e,result:t}){return Ad.has(e)?s.jsx(Md,{result:t}):Rd.has(e)?s.jsx(Dd,{result:t}):Pd.has(e)?s.jsx(_d,{result:t}):$d.has(e)?s.jsx(Ed,{result:t}):zd.has(e)?s.jsx(_n,{result:t}):e==="team_message"?s.jsx(Od,{result:t}):s.jsx(_n,{result:t})}function Wd({state:e}){const t=e==="pending"?"bg-(--color-text-muted)":e==="running"?"bg-(--color-accent) shadow-[0_0_5px_var(--color-accent)] animate-pulse":"bg-(--color-success)";return s.jsx("span",{className:`inline-block h-1.5 w-1.5 shrink-0 rounded-full ${t}`,"aria-hidden":!0})}function ke({children:e}){return s.jsx("em",{className:"italic",children:e})}function re(e,t){const n=e[t];return typeof n=="string"&&n.trim()?n.trim():null}function Ut(e,t=60){return e.length>t?e.slice(0,t)+"…":e}function Ld(e,t){if(e==="date")return{header:null,headerTitle:null,formattedArgs:null};if(!t)return e==="recall"?{header:"Checking memory…",headerTitle:"Checking memory…",formattedArgs:null}:{header:null,headerTitle:null,formattedArgs:null};let n;try{n=JSON.parse(t)}catch{return{header:null,headerTitle:null,formattedArgs:t}}if(e==="shell"){const r=re(n,"description");return{header:r?s.jsx(ke,{children:r}):null,headerTitle:r,formattedArgs:re(n,"command"),language:"bash"}}if(e==="web_search"){const r=re(n,"query"),o=r?Ut(r):null;return{header:o?s.jsxs(s.Fragment,{children:["Searching ",s.jsxs(ke,{children:['"',o,'"']})]}):null,headerTitle:o?`Searching "${o}"`:null,formattedArgs:r}}if(e==="web_fetch"){const r=re(n,"url");let o=null;if(r)try{o=new URL(r.startsWith("http")?r:`https://${r}`).hostname.replace(/^www\./,"")}catch{o=r}const a=o?Ut(o):null;return{header:a?s.jsxs(s.Fragment,{children:["Reading ",s.jsx(ke,{children:a})]}):null,headerTitle:a?`Reading ${a}`:null,formattedArgs:r}}if(e==="remember"){const o=(Array.isArray(n.items)?n.items:[]).map(a=>{const i=typeof a.category=="string"?a.category:"",l=typeof a.key=="string"?a.key:"",c=typeof a.value=="string"?a.value:"";return`[${i}] ${l}: ${c}`});return{header:"Saving to memory…",headerTitle:"Saving to memory…",formattedArgs:o.length>0?o.join(`
|
|
13
|
+
`):null}}if(e==="forget"){const o=(Array.isArray(n.items)?n.items:[]).map(a=>{const i=typeof a.category=="string"?a.category:"",l=typeof a.key=="string"?a.key:null;return l?`${i}: ${l}`:i});return{header:"Removing from memory…",headerTitle:"Removing from memory…",formattedArgs:o.length>0?o.join(`
|
|
14
|
+
`):null}}if(e==="recall"){const r=re(n,"category"),o=re(n,"key");return{header:"Checking memory…",headerTitle:"Checking memory…",formattedArgs:[r,o].filter(Boolean).join(": ")||null}}if(e==="bg"){const r=re(n,"action")?.toLowerCase(),o=n.pid!=null?String(n.pid):null;let a,i;switch(r){case"list":a="Listing background processes…",i="Listing background processes…";break;case"status":o?(a=s.jsxs(s.Fragment,{children:["Checking process ",s.jsx(ke,{children:o}),"…"]}),i=`Checking process ${o}…`):(a="Checking process status…",i="Checking process status…");break;case"output":o?(a=s.jsxs(s.Fragment,{children:["Reading output of process ",s.jsx(ke,{children:o}),"…"]}),i=`Reading output of process ${o}…`):(a="Reading process output…",i="Reading process output…");break;case"stop":o?(a=s.jsxs(s.Fragment,{children:["Stopping process ",s.jsx(ke,{children:o}),"…"]}),i=`Stopping process ${o}…`):(a="Stopping process…",i="Stopping process…");break;default:r?(a=s.jsxs(s.Fragment,{children:["bg: ",s.jsx(ke,{children:r})]}),i=`bg: ${r}`):(a="Managing background process…",i="Managing background process…")}return{header:a,headerTitle:i,formattedArgs:null}}if(e==="skill"){const r=re(n,"skill_name");return{header:r?s.jsxs(s.Fragment,{children:["Loading skill: ",s.jsx(ke,{children:r})]}):"Loading skill…",headerTitle:r?`Loading skill: ${r}`:"Loading skill…",formattedArgs:null}}if(e==="write"){const r=re(n,"path"),o=r?r.split("/").pop()??r:null,a=re(n,"content");return{header:o?s.jsxs(s.Fragment,{children:["Writing ",s.jsx(ke,{children:o})]}):"Writing file…",headerTitle:o?`Writing ${o}`:"Writing file…",formattedArgs:a}}if(e==="read"){const r=re(n,"path"),o=r?r.split("/").pop()??r:null,a=n.offset!=null&&n.offset!==0?Number(n.offset):null,i=n.limit!=null?Number(n.limit):null;let l="";if(a!==null||i!==null){const c=a??0,d=i!==null?c+i:"";l=` [${c}:${d}]`}return{header:o?s.jsxs(s.Fragment,{children:["Reading ",s.jsxs(ke,{children:[o,l]})]}):"Reading file…",headerTitle:o?`Reading ${o}${l}`:"Reading file…",formattedArgs:null}}if(e==="edit"){const r=re(n,"path"),o=r?r.split("/").pop()??r:null;return{header:o?s.jsxs(s.Fragment,{children:["Editing ",s.jsx(ke,{children:o})]}):"Editing file…",headerTitle:o?`Editing ${o}`:"Editing file…",formattedArgs:JSON.stringify(n,null,2)}}if(e==="rm"){const r=re(n,"path"),o=r?r.split("/").pop()??r:null;return{header:o?s.jsxs(s.Fragment,{children:["Removing ",s.jsx(ke,{children:o})]}):"Removing file…",headerTitle:o?`Removing ${o}`:"Removing file…",formattedArgs:null}}if(e==="ls"){const r=re(n,"path");if(!r||r==="."||r==="./")return{header:"Listing workspace",headerTitle:"Listing workspace",formattedArgs:null};const a=Ut(r);return{header:s.jsxs(s.Fragment,{children:["Listing ",s.jsx(ke,{children:a})]}),headerTitle:`Listing ${a}`,formattedArgs:null}}if(e==="glob"){const r=re(n,"pattern"),o=re(n,"directory"),a=re(n,"match"),i=o&&o!=="."&&o!=="./",l=i?` in ${o}`:"",c=a==="name"?" (by name)":"",d=[];r&&d.push(`pattern: ${r}`),i&&d.push(`directory: ${o}`),a==="name"&&d.push("match: name");const u=r?Ut(r):null;return{header:u?s.jsxs(s.Fragment,{children:["Finding ",s.jsx(ke,{children:u}),l,c]}):"Finding files…",headerTitle:u?`Finding ${u}${l}${c}`:"Finding files…",formattedArgs:d.length>0?d.join(`
|
|
15
|
+
`):null}}if(e==="grep"){const r=re(n,"pattern"),o=re(n,"directory"),a=re(n,"include"),i=o&&o!=="."&&o!=="./",l=i?` in ${o}`:"",c=a&&a!=="*",d=c?` (${a})`:"",u=[];r&&u.push(`pattern: ${r}`),i&&u.push(`directory: ${o}`),c&&u.push(`include: ${a}`);const m=r?Ut(r):null;return{header:m?s.jsxs(s.Fragment,{children:["Searching ",s.jsx(ke,{children:m}),l,d]}):"Searching files…",headerTitle:m?`Searching ${m}${l}${d}`:"Searching files…",formattedArgs:u.length>0?u.join(`
|
|
16
|
+
`):null}}if(e==="generate_image"){const r=re(n,"prompt"),o=re(n,"filename"),a=o?`${o.replace(/\.[^.]+$/,"")}.png`:null,i=Array.isArray(n.images)?n.images.map(String).filter(c=>c.length>0):[],l=i.length>0?`images: ${i.join(", ")}
|
|
17
|
+
|
|
18
|
+
${r}`:r;return{header:a?s.jsxs(s.Fragment,{children:["Painting ",s.jsx(ke,{children:a})]}):"Painting an image…",headerTitle:a?`Painting ${a}`:"Painting an image…",formattedArgs:l,suppressResult:!0}}if(e==="generate_video"){const r=re(n,"prompt"),o=re(n,"filename"),a=o?`${o.replace(/\.[^.]+$/,"")}.mp4`:null,i=Array.isArray(n.images)?n.images.map(String).filter(m=>m.length>0):[],l=re(n,"last_frame"),c=Array.isArray(n.reference_images)?n.reference_images.map(String).filter(m=>m.length>0):[],d=[];i.length>0&&d.push(`first_frame: ${i.join(", ")}`),l&&d.push(`last_frame: ${l}`),c.length>0&&d.push(`references: ${c.join(", ")}`);const u=d.length>0?`${d.join(`
|
|
19
|
+
`)}
|
|
20
|
+
|
|
21
|
+
${r}`:r;return{header:a?s.jsxs(s.Fragment,{children:["Filming ",s.jsx(ke,{children:a})]}):"Filming a video…",headerTitle:a?`Filming ${a}`:"Filming a video…",formattedArgs:u,suppressResult:!0}}if(e==="team_message"){const r=Array.isArray(n.to)?n.to.map(String):[],o=re(n,"content"),a=r.length>0?r.join(", "):"team",i=Ut(a);return{header:s.jsxs(s.Fragment,{children:["Messaging ",s.jsx(ke,{children:i})]}),headerTitle:`Messaging ${i}`,formattedArgs:o}}return Object.keys(n).length===0?{header:null,headerTitle:null,formattedArgs:null}:{header:null,headerTitle:null,formattedArgs:JSON.stringify(n,null,2)}}function qo({name:e,args:t,done:n,result:r}){const[o,a]=f.useState(!1),[i,l]=f.useState(!1),[c,d]=f.useState(!1),u=t==null,h=n?"done":!u&&!n?"running":"pending",{header:g,headerTitle:p,formattedArgs:b,language:x,suppressResult:y}=Ld(e,t),j=y?void 0:r,w=async C=>{C.stopPropagation();const z=b||t||"";try{await navigator.clipboard.writeText(z),l(!0),setTimeout(()=>l(!1),1500)}catch{}},N=async C=>{C.stopPropagation();const z=r||"";try{await navigator.clipboard.writeText(z),d(!0),setTimeout(()=>d(!1),1500)}catch{}},v=!!(b||j),k=e||"tool";return s.jsxs("div",{className:"tool-row-enter my-2 border-l border-(--color-border) pl-3",children:[s.jsxs("button",{type:"button",onClick:()=>v&&a(C=>!C),className:`group -ml-1 flex w-full items-center gap-1.5 rounded px-1 py-0.5 text-left text-xs transition-colors duration-(--motion-fast) ease-(--ease-out) focus-visible:outline-2 focus-visible:outline-(--color-focus-ring) ${v?"cursor-pointer hover:text-(--color-text-2)":"cursor-default"}`,"aria-expanded":o,"aria-label":v?o?`Collapse ${k} details`:`Expand ${k} details`:`${k} (no details)`,children:[v&&s.jsx(Es,{size:12,className:`shrink-0 text-(--color-text-muted) transition-transform duration-(--motion-fast) ease-(--ease-out) ${o?"rotate-90":""}`,"aria-hidden":!0}),s.jsx(Wd,{state:h}),g?s.jsx("span",{className:"flex-1 truncate text-(--color-text-2)",title:p??void 0,children:g}):s.jsx("code",{className:"flex-1 truncate font-mono font-medium text-(--color-text-2)",children:k}),u&&s.jsx("span",{className:"shrink-0 text-(--color-text-muted)",children:"pending"})]}),s.jsx(be,{initial:!1,children:o&&v&&s.jsx(se.div,{initial:{height:0,opacity:0},animate:{height:"auto",opacity:1},exit:{height:0,opacity:0},transition:{duration:Io.base,ease:Bo.out},className:"overflow-hidden",children:s.jsxs("div",{className:"mt-1.5 space-y-2 pl-1 pb-1",children:[b&&s.jsxs("section",{className:"relative",children:[s.jsxs("div",{className:"mb-1 flex items-center justify-between gap-2",children:[s.jsx("span",{className:"text-[10px] uppercase tracking-wider text-(--color-text-subtle)",children:x==="bash"?"bash":"arguments"}),s.jsx("button",{onClick:w,className:"rounded p-0.5 text-(--color-text-muted) transition-colors hover:bg-(--color-accent-subtle) hover:text-(--color-text-2) focus-visible:outline-2 focus-visible:outline-(--color-focus-ring)","aria-label":"Copy arguments",title:"Copy",children:i?s.jsx(vt,{size:12,className:"text-(--color-success)"}):s.jsx(Lt,{size:12})})]}),s.jsx("div",{className:"rounded-md border border-(--color-border) bg-(--color-surface-2) px-2.5 py-2",children:x==="bash"?s.jsxs("pre",{className:"overflow-auto whitespace-pre-wrap break-all font-mono text-xs leading-relaxed text-(--color-accent)",children:[s.jsx("span",{className:"select-none text-(--color-text-muted)",children:"$ "}),b]}):s.jsx("pre",{className:"overflow-auto whitespace-pre-wrap break-all font-mono text-xs leading-relaxed text-(--color-text-2)",children:b})})]}),j&&s.jsxs("section",{className:"relative",children:[s.jsxs("div",{className:"mb-1 flex items-center justify-between gap-2",children:[s.jsx("span",{className:"text-[10px] uppercase tracking-wider text-(--color-text-subtle)",children:"result"}),s.jsx("button",{onClick:N,className:"rounded p-0.5 text-(--color-text-muted) transition-colors hover:bg-(--color-accent-subtle) hover:text-(--color-text-2) focus-visible:outline-2 focus-visible:outline-(--color-focus-ring)","aria-label":"Copy result",title:"Copy result",children:c?s.jsx(vt,{size:12,className:"text-(--color-success)"}):s.jsx(Lt,{size:12})})]}),s.jsx("div",{className:"rounded-md border border-(--color-border) bg-(--color-surface-2) px-2.5 py-2 text-xs leading-relaxed text-(--color-text-2)",children:s.jsx(Fd,{toolName:e,result:j})})]})]})},"tool-details")})]})}const kr=5,Nr=2;function Ho({content:e,fromAgent:t,compact:n=!1}){const[r,o]=f.useState(!1),a=t,i=f.useMemo(()=>e.replace(/^\[[\w-]+\]:\s*/gm,"").trim(),[e]),l=i.split(`
|
|
22
|
+
`),c=l.length>kr,d=c&&!r?l.slice(0,kr).join(`
|
|
23
|
+
`):i,u=n?"text-xs":"text-sm",m=n?"max-w-[88%]":"max-w-[78%]",h=n?"px-3 py-2":"px-4 py-3",g=n?"text-[10px]":"text-xs",p=n?`${Nr*1.4}rem`:`${Nr*1.6}rem`;return s.jsx("div",{className:"mb-4 flex justify-start",children:s.jsxs("div",{className:[m,h,u,"relative rounded-2xl rounded-bl-sm","border border-(--color-border) bg-(--color-surface-2)","leading-relaxed text-(--color-text)","overflow-hidden"].join(" "),children:[s.jsxs("div",{className:"mb-1.5 flex items-center justify-between gap-2",children:[s.jsx("p",{className:`${g} font-semibold tracking-wide uppercase text-(--color-info) opacity-90`,children:a}),c&&s.jsx("button",{onClick:()=>o(b=>!b),"aria-expanded":r,title:r?"Collapse":"Expand",className:["flex items-center justify-center shrink-0","rounded-md border border-(--color-border)","bg-(--color-bg) text-(--color-text-muted)",n?"h-4 w-4":"h-5 w-5","transition-all duration-150","hover:border-(--color-syn-operator) hover:text-(--color-syn-operator)","focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-(--color-syn-operator)","active:scale-90"].join(" "),children:r?s.jsx(Gs,{size:n?10:12}):s.jsx(Xe,{size:n?10:12})})]}),s.jsx("div",{className:"oa-prose",children:s.jsx(Po,{remarkPlugins:[$o],components:{a:b=>s.jsx("a",{...b,target:"_blank",rel:"noopener noreferrer"})},children:d})}),c&&!r&&s.jsx("div",{className:"pointer-events-none absolute inset-x-0 bottom-0",style:{height:p,background:"linear-gradient(to bottom, transparent 0%, var(--color-surface-2) 90%)"}})]})})}function Hn({src:e,alt:t="Image",onRemove:n,removable:r,compact:o=!1}){const[a,i]=f.useState(!1),[l,c]=f.useState(!1),d=o?"max-h-[160px] max-w-[160px]":"max-h-[200px] max-w-[200px]",u=o?"h-[160px] w-[160px]":"h-[200px] w-[200px]";return a?s.jsx("div",{className:`flex ${u} items-center justify-center rounded-lg border border-(--color-border) bg-(--color-surface) text-xs text-(--color-text-muted)`,children:"Failed to load image"}):s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"group relative inline-block",children:[s.jsx("img",{src:e,alt:t,onError:()=>i(!0),onClick:()=>c(!0),className:`${d} cursor-pointer rounded-lg border border-(--color-border) object-cover shadow-sm`}),r&&n&&s.jsx("button",{onClick:m=>{m.stopPropagation(),n()},className:"absolute -right-1.5 -top-1.5 flex h-4 w-4 items-center justify-center rounded-full bg-(--color-surface-2) text-(--color-text-muted) ring-1 ring-(--color-border) shadow-sm transition-opacity opacity-100 hover:text-(--color-text) md:opacity-0 md:group-hover:opacity-100","aria-label":"Remove image",title:"Remove",children:s.jsx(Ee,{size:10})})]}),s.jsx(Yn,{src:e,alt:t,isOpen:l,onClose:()=>c(!1)})]})}function Id(e){return e?e.includes("pdf")?s.jsx(br,{size:16}):e.includes("word")||e.includes("document")?s.jsx(br,{size:16}):e.includes("text")?s.jsx(Tt,{size:16}):s.jsx(Bs,{size:16}):s.jsx(Bs,{size:16})}function Un({name:e="File",mediaType:t,url:n,onRemove:r,removable:o,clickable:a}){const i=e.length>20?`${e.substring(0,17)}…`:e,l=()=>{a&&n&&window.open(n,"_blank")};return s.jsxs("div",{className:"group relative inline-block",children:[s.jsxs("button",{onClick:l,disabled:!a,className:`surface-raised flex items-center gap-2 rounded-lg border border-(--color-border) bg-(--color-surface) px-3 py-2 text-xs text-(--color-text) transition-all ${a?"cursor-pointer hover:border-(--color-accent) hover:bg-(--color-surface-2)":""}`,title:e,children:[s.jsx("span",{className:"flex-shrink-0 text-(--color-text-muted)",children:Id(t)}),s.jsx("span",{className:"flex-shrink-0 font-medium",children:i})]}),o&&r&&s.jsx("button",{onClick:c=>{c.stopPropagation(),r()},className:"absolute -right-1.5 -top-1.5 flex h-4 w-4 items-center justify-center rounded-full bg-(--color-surface-2) text-(--color-text-muted) ring-1 ring-(--color-border) shadow-sm transition-opacity opacity-100 hover:text-(--color-text) md:opacity-0 md:group-hover:opacity-100","aria-label":"Remove file",title:"Remove",children:s.jsx(Ee,{size:10})})]})}const Uo=6048e5,Bd=864e5,Yd=6e4,qd=36e5,Hd=1e3,Sr=Symbol.for("constructDateFrom");function G(e,t){return typeof e=="function"?e(t):e&&typeof e=="object"&&Sr in e?e[Sr](t):e instanceof Date?new e.constructor(t):new Date(t)}function U(e,t){return G(t||e,e)}function zs(e,t,n){const r=U(e,n?.in);return isNaN(t)?G(n?.in||e,NaN):(t&&r.setDate(r.getDate()+t),r)}function Qo(e,t,n){const r=U(e,n?.in);if(isNaN(t))return G(e,NaN);if(!t)return r;const o=r.getDate(),a=G(e,r.getTime());a.setMonth(r.getMonth()+t+1,0);const i=a.getDate();return o>=i?a:(r.setFullYear(a.getFullYear(),a.getMonth(),o),r)}let Ud={};function qt(){return Ud}function jt(e,t){const n=qt(),r=t?.weekStartsOn??t?.locale?.options?.weekStartsOn??n.weekStartsOn??n.locale?.options?.weekStartsOn??0,o=U(e,t?.in),a=o.getDay(),i=(a<r?7:0)+a-r;return o.setDate(o.getDate()-i),o.setHours(0,0,0,0),o}function It(e,t){return jt(e,{...t,weekStartsOn:1})}function Ko(e,t){const n=U(e,t?.in),r=n.getFullYear(),o=G(n,0);o.setFullYear(r+1,0,4),o.setHours(0,0,0,0);const a=It(o),i=G(n,0);i.setFullYear(r,0,4),i.setHours(0,0,0,0);const l=It(i);return n.getTime()>=a.getTime()?r+1:n.getTime()>=l.getTime()?r:r-1}function qs(e){const t=U(e),n=new Date(Date.UTC(t.getFullYear(),t.getMonth(),t.getDate(),t.getHours(),t.getMinutes(),t.getSeconds(),t.getMilliseconds()));return n.setUTCFullYear(t.getFullYear()),+e-+n}function as(e,...t){const n=G.bind(null,t.find(r=>typeof r=="object"));return t.map(n)}function ks(e,t){const n=U(e,t?.in);return n.setHours(0,0,0,0),n}function Qn(e,t,n){const[r,o]=as(n?.in,e,t),a=ks(r),i=ks(o),l=+a-qs(a),c=+i-qs(i);return Math.round((l-c)/Bd)}function Qd(e,t){const n=Ko(e,t),r=G(e,0);return r.setFullYear(n,0,4),r.setHours(0,0,0,0),It(r)}function Kd(e,t,n){return zs(e,t*7,n)}function Gd(e,t,n){return Qo(e,t*12,n)}function Vd(e,t){let n,r=t?.in;return e.forEach(o=>{!r&&typeof o=="object"&&(r=G.bind(null,o));const a=U(o,r);(!n||n<a||isNaN(+a))&&(n=a)}),G(r,n||NaN)}function Xd(e,t){let n,r=t?.in;return e.forEach(o=>{!r&&typeof o=="object"&&(r=G.bind(null,o));const a=U(o,r);(!n||n>a||isNaN(+a))&&(n=a)}),G(r,n||NaN)}function Go(e){return G(e,Date.now())}function Kn(e,t,n){const[r,o]=as(n?.in,e,t);return+ks(r)==+ks(o)}function Vo(e){return e instanceof Date||typeof e=="object"&&Object.prototype.toString.call(e)==="[object Date]"}function Xo(e){return!(!Vo(e)&&typeof e!="number"||isNaN(+U(e)))}function Zo(e,t,n){const[r,o]=as(n?.in,e,t),a=r.getFullYear()-o.getFullYear(),i=r.getMonth()-o.getMonth();return a*12+i}function Zd(e,t){const n=U(e,t?.in),r=n.getMonth();return n.setFullYear(n.getFullYear(),r+1,0),n.setHours(23,59,59,999),n}function Jo(e,t){const[n,r]=as(e,t.start,t.end);return{start:n,end:r}}function Jd(e,t){const{start:n,end:r}=Jo(t?.in,e);let o=+n>+r;const a=o?+n:+r,i=o?r:n;i.setHours(0,0,0,0),i.setDate(1);let l=1;const c=[];for(;+i<=a;)c.push(G(n,i)),i.setMonth(i.getMonth()+l);return o?c.reverse():c}function eu(e,t){const n=U(e,t?.in);return n.setDate(1),n.setHours(0,0,0,0),n}function tu(e,t){const n=U(e,t?.in),r=n.getFullYear();return n.setFullYear(r+1,0,0),n.setHours(23,59,59,999),n}function ea(e,t){const n=U(e,t?.in);return n.setFullYear(n.getFullYear(),0,1),n.setHours(0,0,0,0),n}function su(e,t){const{start:n,end:r}=Jo(t?.in,e);let o=+n>+r;const a=o?+n:+r,i=o?r:n;i.setHours(0,0,0,0),i.setMonth(0,1);let l=1;const c=[];for(;+i<=a;)c.push(G(n,i)),i.setFullYear(i.getFullYear()+l);return o?c.reverse():c}function ta(e,t){const n=qt(),r=t?.weekStartsOn??t?.locale?.options?.weekStartsOn??n.weekStartsOn??n.locale?.options?.weekStartsOn??0,o=U(e,t?.in),a=o.getDay(),i=(a<r?-7:0)+6-(a-r);return o.setDate(o.getDate()+i),o.setHours(23,59,59,999),o}function nu(e,t){return ta(e,{...t,weekStartsOn:1})}const ru={lessThanXSeconds:{one:"less than a second",other:"less than {{count}} seconds"},xSeconds:{one:"1 second",other:"{{count}} seconds"},halfAMinute:"half a minute",lessThanXMinutes:{one:"less than a minute",other:"less than {{count}} minutes"},xMinutes:{one:"1 minute",other:"{{count}} minutes"},aboutXHours:{one:"about 1 hour",other:"about {{count}} hours"},xHours:{one:"1 hour",other:"{{count}} hours"},xDays:{one:"1 day",other:"{{count}} days"},aboutXWeeks:{one:"about 1 week",other:"about {{count}} weeks"},xWeeks:{one:"1 week",other:"{{count}} weeks"},aboutXMonths:{one:"about 1 month",other:"about {{count}} months"},xMonths:{one:"1 month",other:"{{count}} months"},aboutXYears:{one:"about 1 year",other:"about {{count}} years"},xYears:{one:"1 year",other:"{{count}} years"},overXYears:{one:"over 1 year",other:"over {{count}} years"},almostXYears:{one:"almost 1 year",other:"almost {{count}} years"}},ou=(e,t,n)=>{let r;const o=ru[e];return typeof o=="string"?r=o:t===1?r=o.one:r=o.other.replace("{{count}}",t.toString()),n?.addSuffix?n.comparison&&n.comparison>0?"in "+r:r+" ago":r};function hn(e){return(t={})=>{const n=t.width?String(t.width):e.defaultWidth;return e.formats[n]||e.formats[e.defaultWidth]}}const au={full:"EEEE, MMMM do, y",long:"MMMM do, y",medium:"MMM d, y",short:"MM/dd/yyyy"},iu={full:"h:mm:ss a zzzz",long:"h:mm:ss a z",medium:"h:mm:ss a",short:"h:mm a"},lu={full:"{{date}} 'at' {{time}}",long:"{{date}} 'at' {{time}}",medium:"{{date}}, {{time}}",short:"{{date}}, {{time}}"},cu={date:hn({formats:au,defaultWidth:"full"}),time:hn({formats:iu,defaultWidth:"full"}),dateTime:hn({formats:lu,defaultWidth:"full"})},du={lastWeek:"'last' eeee 'at' p",yesterday:"'yesterday at' p",today:"'today at' p",tomorrow:"'tomorrow at' p",nextWeek:"eeee 'at' p",other:"P"},uu=(e,t,n,r)=>du[e];function xs(e){return(t,n)=>{const r=n?.context?String(n.context):"standalone";let o;if(r==="formatting"&&e.formattingValues){const i=e.defaultFormattingWidth||e.defaultWidth,l=n?.width?String(n.width):i;o=e.formattingValues[l]||e.formattingValues[i]}else{const i=e.defaultWidth,l=n?.width?String(n.width):e.defaultWidth;o=e.values[l]||e.values[i]}const a=e.argumentCallback?e.argumentCallback(t):t;return o[a]}}const mu={narrow:["B","A"],abbreviated:["BC","AD"],wide:["Before Christ","Anno Domini"]},fu={narrow:["1","2","3","4"],abbreviated:["Q1","Q2","Q3","Q4"],wide:["1st quarter","2nd quarter","3rd quarter","4th quarter"]},xu={narrow:["J","F","M","A","M","J","J","A","S","O","N","D"],abbreviated:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],wide:["January","February","March","April","May","June","July","August","September","October","November","December"]},hu={narrow:["S","M","T","W","T","F","S"],short:["Su","Mo","Tu","We","Th","Fr","Sa"],abbreviated:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],wide:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"]},pu={narrow:{am:"a",pm:"p",midnight:"mi",noon:"n",morning:"morning",afternoon:"afternoon",evening:"evening",night:"night"},abbreviated:{am:"AM",pm:"PM",midnight:"midnight",noon:"noon",morning:"morning",afternoon:"afternoon",evening:"evening",night:"night"},wide:{am:"a.m.",pm:"p.m.",midnight:"midnight",noon:"noon",morning:"morning",afternoon:"afternoon",evening:"evening",night:"night"}},gu={narrow:{am:"a",pm:"p",midnight:"mi",noon:"n",morning:"in the morning",afternoon:"in the afternoon",evening:"in the evening",night:"at night"},abbreviated:{am:"AM",pm:"PM",midnight:"midnight",noon:"noon",morning:"in the morning",afternoon:"in the afternoon",evening:"in the evening",night:"at night"},wide:{am:"a.m.",pm:"p.m.",midnight:"midnight",noon:"noon",morning:"in the morning",afternoon:"in the afternoon",evening:"in the evening",night:"at night"}},bu=(e,t)=>{const n=Number(e),r=n%100;if(r>20||r<10)switch(r%10){case 1:return n+"st";case 2:return n+"nd";case 3:return n+"rd"}return n+"th"},yu={ordinalNumber:bu,era:xs({values:mu,defaultWidth:"wide"}),quarter:xs({values:fu,defaultWidth:"wide",argumentCallback:e=>e-1}),month:xs({values:xu,defaultWidth:"wide"}),day:xs({values:hu,defaultWidth:"wide"}),dayPeriod:xs({values:pu,defaultWidth:"wide",formattingValues:gu,defaultFormattingWidth:"wide"})};function hs(e){return(t,n={})=>{const r=n.width,o=r&&e.matchPatterns[r]||e.matchPatterns[e.defaultMatchWidth],a=t.match(o);if(!a)return null;const i=a[0],l=r&&e.parsePatterns[r]||e.parsePatterns[e.defaultParseWidth],c=Array.isArray(l)?ju(l,m=>m.test(i)):vu(l,m=>m.test(i));let d;d=e.valueCallback?e.valueCallback(c):c,d=n.valueCallback?n.valueCallback(d):d;const u=t.slice(i.length);return{value:d,rest:u}}}function vu(e,t){for(const n in e)if(Object.prototype.hasOwnProperty.call(e,n)&&t(e[n]))return n}function ju(e,t){for(let n=0;n<e.length;n++)if(t(e[n]))return n}function wu(e){return(t,n={})=>{const r=t.match(e.matchPattern);if(!r)return null;const o=r[0],a=t.match(e.parsePattern);if(!a)return null;let i=e.valueCallback?e.valueCallback(a[0]):a[0];i=n.valueCallback?n.valueCallback(i):i;const l=t.slice(o.length);return{value:i,rest:l}}}const ku=/^(\d+)(th|st|nd|rd)?/i,Nu=/\d+/i,Su={narrow:/^(b|a)/i,abbreviated:/^(b\.?\s?c\.?|b\.?\s?c\.?\s?e\.?|a\.?\s?d\.?|c\.?\s?e\.?)/i,wide:/^(before christ|before common era|anno domini|common era)/i},Cu={any:[/^b/i,/^(a|c)/i]},Tu={narrow:/^[1234]/i,abbreviated:/^q[1234]/i,wide:/^[1234](th|st|nd|rd)? quarter/i},Mu={any:[/1/i,/2/i,/3/i,/4/i]},Du={narrow:/^[jfmasond]/i,abbreviated:/^(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)/i,wide:/^(january|february|march|april|may|june|july|august|september|october|november|december)/i},_u={narrow:[/^j/i,/^f/i,/^m/i,/^a/i,/^m/i,/^j/i,/^j/i,/^a/i,/^s/i,/^o/i,/^n/i,/^d/i],any:[/^ja/i,/^f/i,/^mar/i,/^ap/i,/^may/i,/^jun/i,/^jul/i,/^au/i,/^s/i,/^o/i,/^n/i,/^d/i]},Eu={narrow:/^[smtwf]/i,short:/^(su|mo|tu|we|th|fr|sa)/i,abbreviated:/^(sun|mon|tue|wed|thu|fri|sat)/i,wide:/^(sunday|monday|tuesday|wednesday|thursday|friday|saturday)/i},Ou={narrow:[/^s/i,/^m/i,/^t/i,/^w/i,/^t/i,/^f/i,/^s/i],any:[/^su/i,/^m/i,/^tu/i,/^w/i,/^th/i,/^f/i,/^sa/i]},Pu={narrow:/^(a|p|mi|n|(in the|at) (morning|afternoon|evening|night))/i,any:/^([ap]\.?\s?m\.?|midnight|noon|(in the|at) (morning|afternoon|evening|night))/i},$u={any:{am:/^a/i,pm:/^p/i,midnight:/^mi/i,noon:/^no/i,morning:/morning/i,afternoon:/afternoon/i,evening:/evening/i,night:/night/i}},zu={ordinalNumber:wu({matchPattern:ku,parsePattern:Nu,valueCallback:e=>parseInt(e,10)}),era:hs({matchPatterns:Su,defaultMatchWidth:"wide",parsePatterns:Cu,defaultParseWidth:"any"}),quarter:hs({matchPatterns:Tu,defaultMatchWidth:"wide",parsePatterns:Mu,defaultParseWidth:"any",valueCallback:e=>e+1}),month:hs({matchPatterns:Du,defaultMatchWidth:"wide",parsePatterns:_u,defaultParseWidth:"any"}),day:hs({matchPatterns:Eu,defaultMatchWidth:"wide",parsePatterns:Ou,defaultParseWidth:"any"}),dayPeriod:hs({matchPatterns:Pu,defaultMatchWidth:"any",parsePatterns:$u,defaultParseWidth:"any"})},Rt={code:"en-US",formatDistance:ou,formatLong:cu,formatRelative:uu,localize:yu,match:zu,options:{weekStartsOn:0,firstWeekContainsDate:1}};function Ru(e,t){const n=U(e,t?.in);return Qn(n,ea(n))+1}function Vs(e,t){const n=U(e,t?.in),r=+It(n)-+Qd(n);return Math.round(r/Uo)+1}function Gn(e,t){const n=U(e,t?.in),r=n.getFullYear(),o=qt(),a=t?.firstWeekContainsDate??t?.locale?.options?.firstWeekContainsDate??o.firstWeekContainsDate??o.locale?.options?.firstWeekContainsDate??1,i=G(t?.in||e,0);i.setFullYear(r+1,0,a),i.setHours(0,0,0,0);const l=jt(i,t),c=G(t?.in||e,0);c.setFullYear(r,0,a),c.setHours(0,0,0,0);const d=jt(c,t);return+n>=+l?r+1:+n>=+d?r:r-1}function Au(e,t){const n=qt(),r=t?.firstWeekContainsDate??t?.locale?.options?.firstWeekContainsDate??n.firstWeekContainsDate??n.locale?.options?.firstWeekContainsDate??1,o=Gn(e,t),a=G(t?.in||e,0);return a.setFullYear(o,0,r),a.setHours(0,0,0,0),jt(a,t)}function Xs(e,t){const n=U(e,t?.in),r=+jt(n,t)-+Au(n,t);return Math.round(r/Uo)+1}function te(e,t){const n=e<0?"-":"",r=Math.abs(e).toString().padStart(t,"0");return n+r}const St={y(e,t){const n=e.getFullYear(),r=n>0?n:1-n;return te(t==="yy"?r%100:r,t.length)},M(e,t){const n=e.getMonth();return t==="M"?String(n+1):te(n+1,2)},d(e,t){return te(e.getDate(),t.length)},a(e,t){const n=e.getHours()/12>=1?"pm":"am";switch(t){case"a":case"aa":return n.toUpperCase();case"aaa":return n;case"aaaaa":return n[0];default:return n==="am"?"a.m.":"p.m."}},h(e,t){return te(e.getHours()%12||12,t.length)},H(e,t){return te(e.getHours(),t.length)},m(e,t){return te(e.getMinutes(),t.length)},s(e,t){return te(e.getSeconds(),t.length)},S(e,t){const n=t.length,r=e.getMilliseconds(),o=Math.trunc(r*Math.pow(10,n-3));return te(o,t.length)}},Qt={midnight:"midnight",noon:"noon",morning:"morning",afternoon:"afternoon",evening:"evening",night:"night"},Cr={G:function(e,t,n){const r=e.getFullYear()>0?1:0;switch(t){case"G":case"GG":case"GGG":return n.era(r,{width:"abbreviated"});case"GGGGG":return n.era(r,{width:"narrow"});default:return n.era(r,{width:"wide"})}},y:function(e,t,n){if(t==="yo"){const r=e.getFullYear(),o=r>0?r:1-r;return n.ordinalNumber(o,{unit:"year"})}return St.y(e,t)},Y:function(e,t,n,r){const o=Gn(e,r),a=o>0?o:1-o;if(t==="YY"){const i=a%100;return te(i,2)}return t==="Yo"?n.ordinalNumber(a,{unit:"year"}):te(a,t.length)},R:function(e,t){const n=Ko(e);return te(n,t.length)},u:function(e,t){const n=e.getFullYear();return te(n,t.length)},Q:function(e,t,n){const r=Math.ceil((e.getMonth()+1)/3);switch(t){case"Q":return String(r);case"QQ":return te(r,2);case"Qo":return n.ordinalNumber(r,{unit:"quarter"});case"QQQ":return n.quarter(r,{width:"abbreviated",context:"formatting"});case"QQQQQ":return n.quarter(r,{width:"narrow",context:"formatting"});default:return n.quarter(r,{width:"wide",context:"formatting"})}},q:function(e,t,n){const r=Math.ceil((e.getMonth()+1)/3);switch(t){case"q":return String(r);case"qq":return te(r,2);case"qo":return n.ordinalNumber(r,{unit:"quarter"});case"qqq":return n.quarter(r,{width:"abbreviated",context:"standalone"});case"qqqqq":return n.quarter(r,{width:"narrow",context:"standalone"});default:return n.quarter(r,{width:"wide",context:"standalone"})}},M:function(e,t,n){const r=e.getMonth();switch(t){case"M":case"MM":return St.M(e,t);case"Mo":return n.ordinalNumber(r+1,{unit:"month"});case"MMM":return n.month(r,{width:"abbreviated",context:"formatting"});case"MMMMM":return n.month(r,{width:"narrow",context:"formatting"});default:return n.month(r,{width:"wide",context:"formatting"})}},L:function(e,t,n){const r=e.getMonth();switch(t){case"L":return String(r+1);case"LL":return te(r+1,2);case"Lo":return n.ordinalNumber(r+1,{unit:"month"});case"LLL":return n.month(r,{width:"abbreviated",context:"standalone"});case"LLLLL":return n.month(r,{width:"narrow",context:"standalone"});default:return n.month(r,{width:"wide",context:"standalone"})}},w:function(e,t,n,r){const o=Xs(e,r);return t==="wo"?n.ordinalNumber(o,{unit:"week"}):te(o,t.length)},I:function(e,t,n){const r=Vs(e);return t==="Io"?n.ordinalNumber(r,{unit:"week"}):te(r,t.length)},d:function(e,t,n){return t==="do"?n.ordinalNumber(e.getDate(),{unit:"date"}):St.d(e,t)},D:function(e,t,n){const r=Ru(e);return t==="Do"?n.ordinalNumber(r,{unit:"dayOfYear"}):te(r,t.length)},E:function(e,t,n){const r=e.getDay();switch(t){case"E":case"EE":case"EEE":return n.day(r,{width:"abbreviated",context:"formatting"});case"EEEEE":return n.day(r,{width:"narrow",context:"formatting"});case"EEEEEE":return n.day(r,{width:"short",context:"formatting"});default:return n.day(r,{width:"wide",context:"formatting"})}},e:function(e,t,n,r){const o=e.getDay(),a=(o-r.weekStartsOn+8)%7||7;switch(t){case"e":return String(a);case"ee":return te(a,2);case"eo":return n.ordinalNumber(a,{unit:"day"});case"eee":return n.day(o,{width:"abbreviated",context:"formatting"});case"eeeee":return n.day(o,{width:"narrow",context:"formatting"});case"eeeeee":return n.day(o,{width:"short",context:"formatting"});default:return n.day(o,{width:"wide",context:"formatting"})}},c:function(e,t,n,r){const o=e.getDay(),a=(o-r.weekStartsOn+8)%7||7;switch(t){case"c":return String(a);case"cc":return te(a,t.length);case"co":return n.ordinalNumber(a,{unit:"day"});case"ccc":return n.day(o,{width:"abbreviated",context:"standalone"});case"ccccc":return n.day(o,{width:"narrow",context:"standalone"});case"cccccc":return n.day(o,{width:"short",context:"standalone"});default:return n.day(o,{width:"wide",context:"standalone"})}},i:function(e,t,n){const r=e.getDay(),o=r===0?7:r;switch(t){case"i":return String(o);case"ii":return te(o,t.length);case"io":return n.ordinalNumber(o,{unit:"day"});case"iii":return n.day(r,{width:"abbreviated",context:"formatting"});case"iiiii":return n.day(r,{width:"narrow",context:"formatting"});case"iiiiii":return n.day(r,{width:"short",context:"formatting"});default:return n.day(r,{width:"wide",context:"formatting"})}},a:function(e,t,n){const o=e.getHours()/12>=1?"pm":"am";switch(t){case"a":case"aa":return n.dayPeriod(o,{width:"abbreviated",context:"formatting"});case"aaa":return n.dayPeriod(o,{width:"abbreviated",context:"formatting"}).toLowerCase();case"aaaaa":return n.dayPeriod(o,{width:"narrow",context:"formatting"});default:return n.dayPeriod(o,{width:"wide",context:"formatting"})}},b:function(e,t,n){const r=e.getHours();let o;switch(r===12?o=Qt.noon:r===0?o=Qt.midnight:o=r/12>=1?"pm":"am",t){case"b":case"bb":return n.dayPeriod(o,{width:"abbreviated",context:"formatting"});case"bbb":return n.dayPeriod(o,{width:"abbreviated",context:"formatting"}).toLowerCase();case"bbbbb":return n.dayPeriod(o,{width:"narrow",context:"formatting"});default:return n.dayPeriod(o,{width:"wide",context:"formatting"})}},B:function(e,t,n){const r=e.getHours();let o;switch(r>=17?o=Qt.evening:r>=12?o=Qt.afternoon:r>=4?o=Qt.morning:o=Qt.night,t){case"B":case"BB":case"BBB":return n.dayPeriod(o,{width:"abbreviated",context:"formatting"});case"BBBBB":return n.dayPeriod(o,{width:"narrow",context:"formatting"});default:return n.dayPeriod(o,{width:"wide",context:"formatting"})}},h:function(e,t,n){if(t==="ho"){let r=e.getHours()%12;return r===0&&(r=12),n.ordinalNumber(r,{unit:"hour"})}return St.h(e,t)},H:function(e,t,n){return t==="Ho"?n.ordinalNumber(e.getHours(),{unit:"hour"}):St.H(e,t)},K:function(e,t,n){const r=e.getHours()%12;return t==="Ko"?n.ordinalNumber(r,{unit:"hour"}):te(r,t.length)},k:function(e,t,n){let r=e.getHours();return r===0&&(r=24),t==="ko"?n.ordinalNumber(r,{unit:"hour"}):te(r,t.length)},m:function(e,t,n){return t==="mo"?n.ordinalNumber(e.getMinutes(),{unit:"minute"}):St.m(e,t)},s:function(e,t,n){return t==="so"?n.ordinalNumber(e.getSeconds(),{unit:"second"}):St.s(e,t)},S:function(e,t){return St.S(e,t)},X:function(e,t,n){const r=e.getTimezoneOffset();if(r===0)return"Z";switch(t){case"X":return Mr(r);case"XXXX":case"XX":return zt(r);default:return zt(r,":")}},x:function(e,t,n){const r=e.getTimezoneOffset();switch(t){case"x":return Mr(r);case"xxxx":case"xx":return zt(r);default:return zt(r,":")}},O:function(e,t,n){const r=e.getTimezoneOffset();switch(t){case"O":case"OO":case"OOO":return"GMT"+Tr(r,":");default:return"GMT"+zt(r,":")}},z:function(e,t,n){const r=e.getTimezoneOffset();switch(t){case"z":case"zz":case"zzz":return"GMT"+Tr(r,":");default:return"GMT"+zt(r,":")}},t:function(e,t,n){const r=Math.trunc(+e/1e3);return te(r,t.length)},T:function(e,t,n){return te(+e,t.length)}};function Tr(e,t=""){const n=e>0?"-":"+",r=Math.abs(e),o=Math.trunc(r/60),a=r%60;return a===0?n+String(o):n+String(o)+t+te(a,2)}function Mr(e,t){return e%60===0?(e>0?"-":"+")+te(Math.abs(e)/60,2):zt(e,t)}function zt(e,t=""){const n=e>0?"-":"+",r=Math.abs(e),o=te(Math.trunc(r/60),2),a=te(r%60,2);return n+o+t+a}const Dr=(e,t)=>{switch(e){case"P":return t.date({width:"short"});case"PP":return t.date({width:"medium"});case"PPP":return t.date({width:"long"});default:return t.date({width:"full"})}},sa=(e,t)=>{switch(e){case"p":return t.time({width:"short"});case"pp":return t.time({width:"medium"});case"ppp":return t.time({width:"long"});default:return t.time({width:"full"})}},Fu=(e,t)=>{const n=e.match(/(P+)(p+)?/)||[],r=n[1],o=n[2];if(!o)return Dr(e,t);let a;switch(r){case"P":a=t.dateTime({width:"short"});break;case"PP":a=t.dateTime({width:"medium"});break;case"PPP":a=t.dateTime({width:"long"});break;default:a=t.dateTime({width:"full"});break}return a.replace("{{date}}",Dr(r,t)).replace("{{time}}",sa(o,t))},En={p:sa,P:Fu},Wu=/^D+$/,Lu=/^Y+$/,Iu=["D","DD","YY","YYYY"];function na(e){return Wu.test(e)}function ra(e){return Lu.test(e)}function On(e,t,n){const r=Bu(e,t,n);if(console.warn(r),Iu.includes(e))throw new RangeError(r)}function Bu(e,t,n){const r=e[0]==="Y"?"years":"days of the month";return`Use \`${e.toLowerCase()}\` instead of \`${e}\` (in \`${t}\`) for formatting ${r} to the input \`${n}\`; see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md`}const Yu=/[yYQqMLwIdDecihHKkms]o|(\w)\1*|''|'(''|[^'])+('|$)|./g,qu=/P+p+|P+|p+|''|'(''|[^'])+('|$)|./g,Hu=/^'([^]*?)'?$/,Uu=/''/g,Qu=/[a-zA-Z]/;function Qe(e,t,n){const r=qt(),o=n?.locale??r.locale??Rt,a=n?.firstWeekContainsDate??n?.locale?.options?.firstWeekContainsDate??r.firstWeekContainsDate??r.locale?.options?.firstWeekContainsDate??1,i=n?.weekStartsOn??n?.locale?.options?.weekStartsOn??r.weekStartsOn??r.locale?.options?.weekStartsOn??0,l=U(e,n?.in);if(!Xo(l))throw new RangeError("Invalid time value");let c=t.match(qu).map(u=>{const m=u[0];if(m==="p"||m==="P"){const h=En[m];return h(u,o.formatLong)}return u}).join("").match(Yu).map(u=>{if(u==="''")return{isToken:!1,value:"'"};const m=u[0];if(m==="'")return{isToken:!1,value:Ku(u)};if(Cr[m])return{isToken:!0,value:u};if(m.match(Qu))throw new RangeError("Format string contains an unescaped latin alphabet character `"+m+"`");return{isToken:!1,value:u}});o.localize.preprocessor&&(c=o.localize.preprocessor(l,c));const d={firstWeekContainsDate:a,weekStartsOn:i,locale:o};return c.map(u=>{if(!u.isToken)return u.value;const m=u.value;(!n?.useAdditionalWeekYearTokens&&ra(m)||!n?.useAdditionalDayOfYearTokens&&na(m))&&On(m,t,String(e));const h=Cr[m[0]];return h(l,m,o.localize,d)}).join("")}function Ku(e){const t=e.match(Hu);return t?t[1].replace(Uu,"'"):e}function Gu(e,t){const n=U(e,t?.in),r=n.getFullYear(),o=n.getMonth(),a=G(n,0);return a.setFullYear(r,o+1,0),a.setHours(0,0,0,0),a.getDate()}function Vu(){return Object.assign({},qt())}function Xu(e,t){const n=U(e,t?.in).getDay();return n===0?7:n}function Zu(e,t){return U(e,t?.in).getMonth()}function Ju(e,t){return U(e,t?.in).getFullYear()}function em(e,t){return+U(e)>+U(t)}function tm(e,t){return+U(e)<+U(t)}function sm(e,t){const n=nm(t)?new t(0):G(t,0);return n.setFullYear(e.getFullYear(),e.getMonth(),e.getDate()),n.setHours(e.getHours(),e.getMinutes(),e.getSeconds(),e.getMilliseconds()),n}function nm(e){return typeof e=="function"&&e.prototype?.constructor===e}const rm=10;class oa{subPriority=0;validate(t,n){return!0}}class om extends oa{constructor(t,n,r,o,a){super(),this.value=t,this.validateValue=n,this.setValue=r,this.priority=o,a&&(this.subPriority=a)}validate(t,n){return this.validateValue(t,this.value,n)}set(t,n,r){return this.setValue(t,n,this.value,r)}}class am extends oa{priority=rm;subPriority=-1;constructor(t,n){super(),this.context=t||(r=>G(n,r))}set(t,n){return n.timestampIsSet?t:G(t,sm(t,this.context))}}class X{run(t,n,r,o){const a=this.parse(t,n,r,o);return a?{setter:new om(a.value,this.validate,this.set,this.priority,this.subPriority),rest:a.rest}:null}validate(t,n,r){return!0}}class im extends X{priority=140;parse(t,n,r){switch(n){case"G":case"GG":case"GGG":return r.era(t,{width:"abbreviated"})||r.era(t,{width:"narrow"});case"GGGGG":return r.era(t,{width:"narrow"});default:return r.era(t,{width:"wide"})||r.era(t,{width:"abbreviated"})||r.era(t,{width:"narrow"})}}set(t,n,r){return n.era=r,t.setFullYear(r,0,1),t.setHours(0,0,0,0),t}incompatibleTokens=["R","u","t","T"]}const me={month:/^(1[0-2]|0?\d)/,date:/^(3[0-1]|[0-2]?\d)/,dayOfYear:/^(36[0-6]|3[0-5]\d|[0-2]?\d?\d)/,week:/^(5[0-3]|[0-4]?\d)/,hour23h:/^(2[0-3]|[0-1]?\d)/,hour24h:/^(2[0-4]|[0-1]?\d)/,hour11h:/^(1[0-1]|0?\d)/,hour12h:/^(1[0-2]|0?\d)/,minute:/^[0-5]?\d/,second:/^[0-5]?\d/,singleDigit:/^\d/,twoDigits:/^\d{1,2}/,threeDigits:/^\d{1,3}/,fourDigits:/^\d{1,4}/,anyDigitsSigned:/^-?\d+/,singleDigitSigned:/^-?\d/,twoDigitsSigned:/^-?\d{1,2}/,threeDigitsSigned:/^-?\d{1,3}/,fourDigitsSigned:/^-?\d{1,4}/},ot={basicOptionalMinutes:/^([+-])(\d{2})(\d{2})?|Z/,basic:/^([+-])(\d{2})(\d{2})|Z/,basicOptionalSeconds:/^([+-])(\d{2})(\d{2})((\d{2}))?|Z/,extended:/^([+-])(\d{2}):(\d{2})|Z/,extendedOptionalSeconds:/^([+-])(\d{2}):(\d{2})(:(\d{2}))?|Z/};function fe(e,t){return e&&{value:t(e.value),rest:e.rest}}function le(e,t){const n=t.match(e);return n?{value:parseInt(n[0],10),rest:t.slice(n[0].length)}:null}function at(e,t){const n=t.match(e);if(!n)return null;if(n[0]==="Z")return{value:0,rest:t.slice(1)};const r=n[1]==="+"?1:-1,o=n[2]?parseInt(n[2],10):0,a=n[3]?parseInt(n[3],10):0,i=n[5]?parseInt(n[5],10):0;return{value:r*(o*qd+a*Yd+i*Hd),rest:t.slice(n[0].length)}}function aa(e){return le(me.anyDigitsSigned,e)}function de(e,t){switch(e){case 1:return le(me.singleDigit,t);case 2:return le(me.twoDigits,t);case 3:return le(me.threeDigits,t);case 4:return le(me.fourDigits,t);default:return le(new RegExp("^\\d{1,"+e+"}"),t)}}function Hs(e,t){switch(e){case 1:return le(me.singleDigitSigned,t);case 2:return le(me.twoDigitsSigned,t);case 3:return le(me.threeDigitsSigned,t);case 4:return le(me.fourDigitsSigned,t);default:return le(new RegExp("^-?\\d{1,"+e+"}"),t)}}function Vn(e){switch(e){case"morning":return 4;case"evening":return 17;case"pm":case"noon":case"afternoon":return 12;default:return 0}}function ia(e,t){const n=t>0,r=n?t:1-t;let o;if(r<=50)o=e||100;else{const a=r+50,i=Math.trunc(a/100)*100,l=e>=a%100;o=e+i-(l?100:0)}return n?o:1-o}function la(e){return e%400===0||e%4===0&&e%100!==0}class lm extends X{priority=130;incompatibleTokens=["Y","R","u","w","I","i","e","c","t","T"];parse(t,n,r){const o=a=>({year:a,isTwoDigitYear:n==="yy"});switch(n){case"y":return fe(de(4,t),o);case"yo":return fe(r.ordinalNumber(t,{unit:"year"}),o);default:return fe(de(n.length,t),o)}}validate(t,n){return n.isTwoDigitYear||n.year>0}set(t,n,r){const o=t.getFullYear();if(r.isTwoDigitYear){const i=ia(r.year,o);return t.setFullYear(i,0,1),t.setHours(0,0,0,0),t}const a=!("era"in n)||n.era===1?r.year:1-r.year;return t.setFullYear(a,0,1),t.setHours(0,0,0,0),t}}class cm extends X{priority=130;parse(t,n,r){const o=a=>({year:a,isTwoDigitYear:n==="YY"});switch(n){case"Y":return fe(de(4,t),o);case"Yo":return fe(r.ordinalNumber(t,{unit:"year"}),o);default:return fe(de(n.length,t),o)}}validate(t,n){return n.isTwoDigitYear||n.year>0}set(t,n,r,o){const a=Gn(t,o);if(r.isTwoDigitYear){const l=ia(r.year,a);return t.setFullYear(l,0,o.firstWeekContainsDate),t.setHours(0,0,0,0),jt(t,o)}const i=!("era"in n)||n.era===1?r.year:1-r.year;return t.setFullYear(i,0,o.firstWeekContainsDate),t.setHours(0,0,0,0),jt(t,o)}incompatibleTokens=["y","R","u","Q","q","M","L","I","d","D","i","t","T"]}class dm extends X{priority=130;parse(t,n){return Hs(n==="R"?4:n.length,t)}set(t,n,r){const o=G(t,0);return o.setFullYear(r,0,4),o.setHours(0,0,0,0),It(o)}incompatibleTokens=["G","y","Y","u","Q","q","M","L","w","d","D","e","c","t","T"]}class um extends X{priority=130;parse(t,n){return Hs(n==="u"?4:n.length,t)}set(t,n,r){return t.setFullYear(r,0,1),t.setHours(0,0,0,0),t}incompatibleTokens=["G","y","Y","R","w","I","i","e","c","t","T"]}class mm extends X{priority=120;parse(t,n,r){switch(n){case"Q":case"QQ":return de(n.length,t);case"Qo":return r.ordinalNumber(t,{unit:"quarter"});case"QQQ":return r.quarter(t,{width:"abbreviated",context:"formatting"})||r.quarter(t,{width:"narrow",context:"formatting"});case"QQQQQ":return r.quarter(t,{width:"narrow",context:"formatting"});default:return r.quarter(t,{width:"wide",context:"formatting"})||r.quarter(t,{width:"abbreviated",context:"formatting"})||r.quarter(t,{width:"narrow",context:"formatting"})}}validate(t,n){return n>=1&&n<=4}set(t,n,r){return t.setMonth((r-1)*3,1),t.setHours(0,0,0,0),t}incompatibleTokens=["Y","R","q","M","L","w","I","d","D","i","e","c","t","T"]}class fm extends X{priority=120;parse(t,n,r){switch(n){case"q":case"qq":return de(n.length,t);case"qo":return r.ordinalNumber(t,{unit:"quarter"});case"qqq":return r.quarter(t,{width:"abbreviated",context:"standalone"})||r.quarter(t,{width:"narrow",context:"standalone"});case"qqqqq":return r.quarter(t,{width:"narrow",context:"standalone"});default:return r.quarter(t,{width:"wide",context:"standalone"})||r.quarter(t,{width:"abbreviated",context:"standalone"})||r.quarter(t,{width:"narrow",context:"standalone"})}}validate(t,n){return n>=1&&n<=4}set(t,n,r){return t.setMonth((r-1)*3,1),t.setHours(0,0,0,0),t}incompatibleTokens=["Y","R","Q","M","L","w","I","d","D","i","e","c","t","T"]}class xm extends X{incompatibleTokens=["Y","R","q","Q","L","w","I","D","i","e","c","t","T"];priority=110;parse(t,n,r){const o=a=>a-1;switch(n){case"M":return fe(le(me.month,t),o);case"MM":return fe(de(2,t),o);case"Mo":return fe(r.ordinalNumber(t,{unit:"month"}),o);case"MMM":return r.month(t,{width:"abbreviated",context:"formatting"})||r.month(t,{width:"narrow",context:"formatting"});case"MMMMM":return r.month(t,{width:"narrow",context:"formatting"});default:return r.month(t,{width:"wide",context:"formatting"})||r.month(t,{width:"abbreviated",context:"formatting"})||r.month(t,{width:"narrow",context:"formatting"})}}validate(t,n){return n>=0&&n<=11}set(t,n,r){return t.setMonth(r,1),t.setHours(0,0,0,0),t}}class hm extends X{priority=110;parse(t,n,r){const o=a=>a-1;switch(n){case"L":return fe(le(me.month,t),o);case"LL":return fe(de(2,t),o);case"Lo":return fe(r.ordinalNumber(t,{unit:"month"}),o);case"LLL":return r.month(t,{width:"abbreviated",context:"standalone"})||r.month(t,{width:"narrow",context:"standalone"});case"LLLLL":return r.month(t,{width:"narrow",context:"standalone"});default:return r.month(t,{width:"wide",context:"standalone"})||r.month(t,{width:"abbreviated",context:"standalone"})||r.month(t,{width:"narrow",context:"standalone"})}}validate(t,n){return n>=0&&n<=11}set(t,n,r){return t.setMonth(r,1),t.setHours(0,0,0,0),t}incompatibleTokens=["Y","R","q","Q","M","w","I","D","i","e","c","t","T"]}function pm(e,t,n){const r=U(e,n?.in),o=Xs(r,n)-t;return r.setDate(r.getDate()-o*7),U(r,n?.in)}class gm extends X{priority=100;parse(t,n,r){switch(n){case"w":return le(me.week,t);case"wo":return r.ordinalNumber(t,{unit:"week"});default:return de(n.length,t)}}validate(t,n){return n>=1&&n<=53}set(t,n,r,o){return jt(pm(t,r,o),o)}incompatibleTokens=["y","R","u","q","Q","M","L","I","d","D","i","t","T"]}function bm(e,t,n){const r=U(e,n?.in),o=Vs(r,n)-t;return r.setDate(r.getDate()-o*7),r}class ym extends X{priority=100;parse(t,n,r){switch(n){case"I":return le(me.week,t);case"Io":return r.ordinalNumber(t,{unit:"week"});default:return de(n.length,t)}}validate(t,n){return n>=1&&n<=53}set(t,n,r){return It(bm(t,r))}incompatibleTokens=["y","Y","u","q","Q","M","L","w","d","D","e","c","t","T"]}const vm=[31,28,31,30,31,30,31,31,30,31,30,31],jm=[31,29,31,30,31,30,31,31,30,31,30,31];class wm extends X{priority=90;subPriority=1;parse(t,n,r){switch(n){case"d":return le(me.date,t);case"do":return r.ordinalNumber(t,{unit:"date"});default:return de(n.length,t)}}validate(t,n){const r=t.getFullYear(),o=la(r),a=t.getMonth();return o?n>=1&&n<=jm[a]:n>=1&&n<=vm[a]}set(t,n,r){return t.setDate(r),t.setHours(0,0,0,0),t}incompatibleTokens=["Y","R","q","Q","w","I","D","i","e","c","t","T"]}class km extends X{priority=90;subpriority=1;parse(t,n,r){switch(n){case"D":case"DD":return le(me.dayOfYear,t);case"Do":return r.ordinalNumber(t,{unit:"date"});default:return de(n.length,t)}}validate(t,n){const r=t.getFullYear();return la(r)?n>=1&&n<=366:n>=1&&n<=365}set(t,n,r){return t.setMonth(0,r),t.setHours(0,0,0,0),t}incompatibleTokens=["Y","R","q","Q","M","L","w","I","d","E","i","e","c","t","T"]}function Xn(e,t,n){const r=qt(),o=n?.weekStartsOn??n?.locale?.options?.weekStartsOn??r.weekStartsOn??r.locale?.options?.weekStartsOn??0,a=U(e,n?.in),i=a.getDay(),c=(t%7+7)%7,d=7-o,u=t<0||t>6?t-(i+d)%7:(c+d)%7-(i+d)%7;return zs(a,u,n)}class Nm extends X{priority=90;parse(t,n,r){switch(n){case"E":case"EE":case"EEE":return r.day(t,{width:"abbreviated",context:"formatting"})||r.day(t,{width:"short",context:"formatting"})||r.day(t,{width:"narrow",context:"formatting"});case"EEEEE":return r.day(t,{width:"narrow",context:"formatting"});case"EEEEEE":return r.day(t,{width:"short",context:"formatting"})||r.day(t,{width:"narrow",context:"formatting"});default:return r.day(t,{width:"wide",context:"formatting"})||r.day(t,{width:"abbreviated",context:"formatting"})||r.day(t,{width:"short",context:"formatting"})||r.day(t,{width:"narrow",context:"formatting"})}}validate(t,n){return n>=0&&n<=6}set(t,n,r,o){return t=Xn(t,r,o),t.setHours(0,0,0,0),t}incompatibleTokens=["D","i","e","c","t","T"]}class Sm extends X{priority=90;parse(t,n,r,o){const a=i=>{const l=Math.floor((i-1)/7)*7;return(i+o.weekStartsOn+6)%7+l};switch(n){case"e":case"ee":return fe(de(n.length,t),a);case"eo":return fe(r.ordinalNumber(t,{unit:"day"}),a);case"eee":return r.day(t,{width:"abbreviated",context:"formatting"})||r.day(t,{width:"short",context:"formatting"})||r.day(t,{width:"narrow",context:"formatting"});case"eeeee":return r.day(t,{width:"narrow",context:"formatting"});case"eeeeee":return r.day(t,{width:"short",context:"formatting"})||r.day(t,{width:"narrow",context:"formatting"});default:return r.day(t,{width:"wide",context:"formatting"})||r.day(t,{width:"abbreviated",context:"formatting"})||r.day(t,{width:"short",context:"formatting"})||r.day(t,{width:"narrow",context:"formatting"})}}validate(t,n){return n>=0&&n<=6}set(t,n,r,o){return t=Xn(t,r,o),t.setHours(0,0,0,0),t}incompatibleTokens=["y","R","u","q","Q","M","L","I","d","D","E","i","c","t","T"]}class Cm extends X{priority=90;parse(t,n,r,o){const a=i=>{const l=Math.floor((i-1)/7)*7;return(i+o.weekStartsOn+6)%7+l};switch(n){case"c":case"cc":return fe(de(n.length,t),a);case"co":return fe(r.ordinalNumber(t,{unit:"day"}),a);case"ccc":return r.day(t,{width:"abbreviated",context:"standalone"})||r.day(t,{width:"short",context:"standalone"})||r.day(t,{width:"narrow",context:"standalone"});case"ccccc":return r.day(t,{width:"narrow",context:"standalone"});case"cccccc":return r.day(t,{width:"short",context:"standalone"})||r.day(t,{width:"narrow",context:"standalone"});default:return r.day(t,{width:"wide",context:"standalone"})||r.day(t,{width:"abbreviated",context:"standalone"})||r.day(t,{width:"short",context:"standalone"})||r.day(t,{width:"narrow",context:"standalone"})}}validate(t,n){return n>=0&&n<=6}set(t,n,r,o){return t=Xn(t,r,o),t.setHours(0,0,0,0),t}incompatibleTokens=["y","R","u","q","Q","M","L","I","d","D","E","i","e","t","T"]}function Tm(e,t,n){const r=U(e,n?.in),o=Xu(r,n),a=t-o;return zs(r,a,n)}class Mm extends X{priority=90;parse(t,n,r){const o=a=>a===0?7:a;switch(n){case"i":case"ii":return de(n.length,t);case"io":return r.ordinalNumber(t,{unit:"day"});case"iii":return fe(r.day(t,{width:"abbreviated",context:"formatting"})||r.day(t,{width:"short",context:"formatting"})||r.day(t,{width:"narrow",context:"formatting"}),o);case"iiiii":return fe(r.day(t,{width:"narrow",context:"formatting"}),o);case"iiiiii":return fe(r.day(t,{width:"short",context:"formatting"})||r.day(t,{width:"narrow",context:"formatting"}),o);default:return fe(r.day(t,{width:"wide",context:"formatting"})||r.day(t,{width:"abbreviated",context:"formatting"})||r.day(t,{width:"short",context:"formatting"})||r.day(t,{width:"narrow",context:"formatting"}),o)}}validate(t,n){return n>=1&&n<=7}set(t,n,r){return t=Tm(t,r),t.setHours(0,0,0,0),t}incompatibleTokens=["y","Y","u","q","Q","M","L","w","d","D","E","e","c","t","T"]}class Dm extends X{priority=80;parse(t,n,r){switch(n){case"a":case"aa":case"aaa":return r.dayPeriod(t,{width:"abbreviated",context:"formatting"})||r.dayPeriod(t,{width:"narrow",context:"formatting"});case"aaaaa":return r.dayPeriod(t,{width:"narrow",context:"formatting"});default:return r.dayPeriod(t,{width:"wide",context:"formatting"})||r.dayPeriod(t,{width:"abbreviated",context:"formatting"})||r.dayPeriod(t,{width:"narrow",context:"formatting"})}}set(t,n,r){return t.setHours(Vn(r),0,0,0),t}incompatibleTokens=["b","B","H","k","t","T"]}class _m extends X{priority=80;parse(t,n,r){switch(n){case"b":case"bb":case"bbb":return r.dayPeriod(t,{width:"abbreviated",context:"formatting"})||r.dayPeriod(t,{width:"narrow",context:"formatting"});case"bbbbb":return r.dayPeriod(t,{width:"narrow",context:"formatting"});default:return r.dayPeriod(t,{width:"wide",context:"formatting"})||r.dayPeriod(t,{width:"abbreviated",context:"formatting"})||r.dayPeriod(t,{width:"narrow",context:"formatting"})}}set(t,n,r){return t.setHours(Vn(r),0,0,0),t}incompatibleTokens=["a","B","H","k","t","T"]}class Em extends X{priority=80;parse(t,n,r){switch(n){case"B":case"BB":case"BBB":return r.dayPeriod(t,{width:"abbreviated",context:"formatting"})||r.dayPeriod(t,{width:"narrow",context:"formatting"});case"BBBBB":return r.dayPeriod(t,{width:"narrow",context:"formatting"});default:return r.dayPeriod(t,{width:"wide",context:"formatting"})||r.dayPeriod(t,{width:"abbreviated",context:"formatting"})||r.dayPeriod(t,{width:"narrow",context:"formatting"})}}set(t,n,r){return t.setHours(Vn(r),0,0,0),t}incompatibleTokens=["a","b","t","T"]}class Om extends X{priority=70;parse(t,n,r){switch(n){case"h":return le(me.hour12h,t);case"ho":return r.ordinalNumber(t,{unit:"hour"});default:return de(n.length,t)}}validate(t,n){return n>=1&&n<=12}set(t,n,r){const o=t.getHours()>=12;return o&&r<12?t.setHours(r+12,0,0,0):!o&&r===12?t.setHours(0,0,0,0):t.setHours(r,0,0,0),t}incompatibleTokens=["H","K","k","t","T"]}class Pm extends X{priority=70;parse(t,n,r){switch(n){case"H":return le(me.hour23h,t);case"Ho":return r.ordinalNumber(t,{unit:"hour"});default:return de(n.length,t)}}validate(t,n){return n>=0&&n<=23}set(t,n,r){return t.setHours(r,0,0,0),t}incompatibleTokens=["a","b","h","K","k","t","T"]}class $m extends X{priority=70;parse(t,n,r){switch(n){case"K":return le(me.hour11h,t);case"Ko":return r.ordinalNumber(t,{unit:"hour"});default:return de(n.length,t)}}validate(t,n){return n>=0&&n<=11}set(t,n,r){return t.getHours()>=12&&r<12?t.setHours(r+12,0,0,0):t.setHours(r,0,0,0),t}incompatibleTokens=["h","H","k","t","T"]}class zm extends X{priority=70;parse(t,n,r){switch(n){case"k":return le(me.hour24h,t);case"ko":return r.ordinalNumber(t,{unit:"hour"});default:return de(n.length,t)}}validate(t,n){return n>=1&&n<=24}set(t,n,r){const o=r<=24?r%24:r;return t.setHours(o,0,0,0),t}incompatibleTokens=["a","b","h","H","K","t","T"]}class Rm extends X{priority=60;parse(t,n,r){switch(n){case"m":return le(me.minute,t);case"mo":return r.ordinalNumber(t,{unit:"minute"});default:return de(n.length,t)}}validate(t,n){return n>=0&&n<=59}set(t,n,r){return t.setMinutes(r,0,0),t}incompatibleTokens=["t","T"]}class Am extends X{priority=50;parse(t,n,r){switch(n){case"s":return le(me.second,t);case"so":return r.ordinalNumber(t,{unit:"second"});default:return de(n.length,t)}}validate(t,n){return n>=0&&n<=59}set(t,n,r){return t.setSeconds(r,0),t}incompatibleTokens=["t","T"]}class Fm extends X{priority=30;parse(t,n){const r=o=>Math.trunc(o*Math.pow(10,-n.length+3));return fe(de(n.length,t),r)}set(t,n,r){return t.setMilliseconds(r),t}incompatibleTokens=["t","T"]}class Wm extends X{priority=10;parse(t,n){switch(n){case"X":return at(ot.basicOptionalMinutes,t);case"XX":return at(ot.basic,t);case"XXXX":return at(ot.basicOptionalSeconds,t);case"XXXXX":return at(ot.extendedOptionalSeconds,t);default:return at(ot.extended,t)}}set(t,n,r){return n.timestampIsSet?t:G(t,t.getTime()-qs(t)-r)}incompatibleTokens=["t","T","x"]}class Lm extends X{priority=10;parse(t,n){switch(n){case"x":return at(ot.basicOptionalMinutes,t);case"xx":return at(ot.basic,t);case"xxxx":return at(ot.basicOptionalSeconds,t);case"xxxxx":return at(ot.extendedOptionalSeconds,t);default:return at(ot.extended,t)}}set(t,n,r){return n.timestampIsSet?t:G(t,t.getTime()-qs(t)-r)}incompatibleTokens=["t","T","X"]}class Im extends X{priority=40;parse(t){return aa(t)}set(t,n,r){return[G(t,r*1e3),{timestampIsSet:!0}]}incompatibleTokens="*"}class Bm extends X{priority=20;parse(t){return aa(t)}set(t,n,r){return[G(t,r),{timestampIsSet:!0}]}incompatibleTokens="*"}const Ym={G:new im,y:new lm,Y:new cm,R:new dm,u:new um,Q:new mm,q:new fm,M:new xm,L:new hm,w:new gm,I:new ym,d:new wm,D:new km,E:new Nm,e:new Sm,c:new Cm,i:new Mm,a:new Dm,b:new _m,B:new Em,h:new Om,H:new Pm,K:new $m,k:new zm,m:new Rm,s:new Am,S:new Fm,X:new Wm,x:new Lm,t:new Im,T:new Bm},qm=/[yYQqMLwIdDecihHKkms]o|(\w)\1*|''|'(''|[^'])+('|$)|./g,Hm=/P+p+|P+|p+|''|'(''|[^'])+('|$)|./g,Um=/^'([^]*?)'?$/,Qm=/''/g,Km=/\S/,Gm=/[a-zA-Z]/;function Vm(e,t,n,r){const o=()=>G(n,NaN),a=Vu(),i=a.locale??Rt,l=a.firstWeekContainsDate??a.locale?.options?.firstWeekContainsDate??1,c=a.weekStartsOn??a.locale?.options?.weekStartsOn??0,d={firstWeekContainsDate:l,weekStartsOn:c,locale:i},u=[new am(r?.in,n)],m=t.match(Hm).map(x=>{const y=x[0];if(y in En){const j=En[y];return j(x,i.formatLong)}return x}).join("").match(qm),h=[];for(let x of m){ra(x)&&On(x,t,e),na(x)&&On(x,t,e);const y=x[0],j=Ym[y];if(j){const{incompatibleTokens:w}=j;if(Array.isArray(w)){const v=h.find(k=>w.includes(k.token)||k.token===y);if(v)throw new RangeError(`The format string mustn't contain \`${v.fullToken}\` and \`${x}\` at the same time`)}else if(j.incompatibleTokens==="*"&&h.length>0)throw new RangeError(`The format string mustn't contain \`${x}\` and any other token at the same time`);h.push({token:y,fullToken:x});const N=j.run(e,x,i.match,d);if(!N)return o();u.push(N.setter),e=N.rest}else{if(y.match(Gm))throw new RangeError("Format string contains an unescaped latin alphabet character `"+y+"`");if(x==="''"?x="'":y==="'"&&(x=Xm(x)),e.indexOf(x)===0)e=e.slice(x.length);else return o()}}if(e.length>0&&Km.test(e))return o();const g=u.map(x=>x.priority).sort((x,y)=>y-x).filter((x,y,j)=>j.indexOf(x)===y).map(x=>u.filter(y=>y.priority===x).sort((y,j)=>j.subPriority-y.subPriority)).map(x=>x[0]);let p=U(n,r?.in);if(isNaN(+p))return o();const b={};for(const x of g){if(!x.validate(p,d))return o();const y=x.set(p,b,d);Array.isArray(y)?(p=y[0],Object.assign(b,y[1])):p=y}return p}function Xm(e){return e.match(Um)[1].replace(Qm,"'")}function Zm(e,t,n){const[r,o]=as(n?.in,e,t);return r.getFullYear()===o.getFullYear()&&r.getMonth()===o.getMonth()}function Jm(e,t,n){const[r,o]=as(n?.in,e,t);return r.getFullYear()===o.getFullYear()}function ca(e,t){return Kn(G(e,e),Go(e))}function ef(e,t,n){return zs(e,-1,n)}function da(e,t){return Kn(G(e,e),ef(Go(e)))}function tf(e,t,n){const r=U(e,n?.in),o=r.getFullYear(),a=r.getDate(),i=G(e,0);i.setFullYear(o,t,15),i.setHours(0,0,0,0);const l=Gu(i);return r.setMonth(t,Math.min(a,l)),r}function sf(e,t,n){const r=U(e,n?.in);return isNaN(+r)?G(e,NaN):(r.setFullYear(t),r)}function Zn(e){const t=e.trimEnd();return t.endsWith("<sleep>")||t.endsWith("[sleep]")?t.slice(0,-7).trimEnd():null}function Ns(e){return e.toLocaleTimeString(void 0,{hour:"numeric",minute:"2-digit",hour12:!1})}function es(e){return e>=1e3?(e/1e3).toFixed(1).replace(/\.0$/,"")+"k":String(e)}function Bt(e){return e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(1).replace(/\.0$/,"")} KB`:e<1024*1024*1024?`${(e/(1024*1024)).toFixed(1).replace(/\.0$/,"")} MB`:`${(e/(1024*1024*1024)).toFixed(1).replace(/\.0$/,"")} GB`}function Zt(e){if(!e)return"";const t=new Date(e),n=Qe(t,"HH:mm");return ca(t)?`Today ${n}`:da(t)?`Yesterday ${n}`:`${Qe(t,"dd/MM/yyyy")} ${n}`}function nf(e){let t=0;for(let o=e.length-1;o>=0;o--)if(e[o].type==="user"){t=o+1;break}const n=e.slice(t),r=[];for(const o of n){if(o.type!=="text")continue;const a=Zn(o.content);a!==null?a.length>0&&r.push(a):r.push(o.content)}return r.join(`
|
|
24
|
+
|
|
25
|
+
`)}function rf({turnBlocks:e,size:t="compact"}){const[n,r]=f.useState(!1),o=nf(e),i=e[e.length-1]?.timestamp;if(!o&&!i)return null;const l=async()=>{try{await navigator.clipboard.writeText(o),r(!0),setTimeout(()=>r(!1),1500)}catch{}},c=t==="roomy"?"mt-1 flex items-center gap-1.5":"mt-0.5 flex items-center gap-1",d=t==="roomy"?11:10;return s.jsxs("div",{className:c,children:[o&&s.jsx("button",{onClick:l,className:"rounded p-0.5 text-(--color-text-muted) transition-colors hover:text-(--color-text-2)","aria-label":"Copy response",title:"Copy",children:n?s.jsx(vt,{size:d,className:"text-(--color-success)"}):s.jsx(Lt,{size:d})}),i&&s.jsx("span",{className:"text-(--color-text-subtle) text-xs",children:Ns(i)})]})}function ua({blocks:e,startIndex:t,finalizedCount:n,isWorking:r,isTrailingTurn:o,totalBlocks:a,renderBlock:i,size:l="compact"}){const c=r&&o;return s.jsxs("div",{className:"space-y-2",children:[e.map((d,u)=>{const m=t+u,h=r&&m>=n;return s.jsx("div",{children:i({block:d,isStreaming:h,isLast:m===a-1})},d.id)}),!c&&s.jsx(rf,{turnBlocks:e,size:l})]})}function ma(e){const t=[];let n=0;for(;n<e.length;){const r=e[n];if(r.type==="user"){t.push({kind:"user",block:r,index:n}),n++;continue}const o=n,a=[];for(;n<e.length&&e[n].type!=="user";)a.push(e[n]),n++;t.push({kind:"assistant",blocks:a,startIndex:o})}return t}function Ct(){return`block-${Date.now()}-${Math.random().toString(36).slice(2,9)}`}function of(e,t){const n=e[e.length-1];return n&&n.type==="thinking"?[...e.slice(0,-1),{...n,content:n.content+t}]:[...e,{id:Ct(),type:"thinking",content:t}]}function af(e,t){const n=e[e.length-1];return n&&n.type==="text"?[...e.slice(0,-1),{...n,content:n.content+t}]:[...e,{id:Ct(),type:"text",content:t}]}function lf(e,t,n){return n&&e.some(r=>r.type==="tool"&&r.toolCallId===n)?e:[...e,{id:Ct(),type:"tool",content:"",toolName:t,toolArgs:void 0,toolDone:!1,toolCallId:n}]}function cf(e,t,n,r){const o=[...e];for(let a=o.length-1;a>=0;a--){const i=o[a];if(i.type==="tool"&&(r&&i.toolCallId===r||!r&&i.toolName===t&&i.toolArgs===void 0))return i.toolArgs!==void 0&&i.toolArgs!==null||(o[a]={...i,toolArgs:n}),o}return[...e,{id:Ct(),type:"tool",content:"",toolName:t,toolArgs:n,toolDone:!1,toolCallId:r}]}function df(e,t,n,r){const o=[...e];if(n)for(let a=o.length-1;a>=0;a--){const i=o[a];if(i.type==="tool"&&i.toolCallId===n)return i.toolDone||(o[a]={...i,toolDone:!0,toolResult:r}),o}for(let a=o.length-1;a>=0;a--){const i=o[a];if(i.type==="tool"&&i.toolName===t&&!i.toolDone)return o[a]={...i,toolDone:!0,toolResult:r},o}return o}function fa(e){return[...e].sort((t,n)=>{const r=t.created_at?new Date(t.created_at).getTime():0,o=n.created_at?new Date(n.created_at).getTime():0;if(r!==o)return r-o;const a={user:0,assistant:1,tool:2,system:3};return(a[t.role]??9)-(a[n.role]??9)})}function uf(e,t,n){const r=[];e.reasoning_content&&r.push({id:Ct(),type:"thinking",content:e.reasoning_content,timestamp:n}),e.content&&r.push({id:Ct(),type:"text",content:e.content,timestamp:n});for(const o of(e.tool_calls??[]).filter(a=>a.function?.name!=="todo_manage")){const a=o.function?.name??o.id;let i;try{const c=JSON.parse(o.function?.arguments??"{}");i=JSON.stringify(c,null,2)}catch{i=o.function?.arguments??void 0}const l={id:Ct(),type:"tool",content:"",toolName:a,toolArgs:i,toolCallId:o.id,toolDone:!1,timestamp:n};r.push(l),o.id&&t.set(o.id,l)}return r}function _r(e){const t={promptTokens:0,completionTokens:0,totalTokens:0,cachedTokens:0};let n=0,r=0;for(const o of fa(e)){if(o.role!=="assistant")continue;const a=o.extra;if(!a?.usage)continue;const i=a.usage.input??0,l=a.usage.output??0;t.completionTokens+=l,n=i,r=a.usage.cache??0}return t.promptTokens=n,t.cachedTokens=r,t.totalTokens=n+t.completionTokens,t}function Er(e){const t=[],n=new Map;for(const r of fa(e))if(!r.is_summary){if(r.role==="user"){const o=r.extra,a=o?.from_agent??o?.routing?.from_agent??o?.from_agents?.[0]??o?.routing?.from_agents?.[0],i=a?{from_agent:a}:r.extra??void 0,l=r.created_at?new Date(r.created_at):new Date;t.push({id:r.id,type:"user",content:r.content||"",extra:i,timestamp:l,attachments:r.attachments??void 0});continue}if(r.role==="tool"&&r.tool_call_id){const o=n.get(r.tool_call_id);o&&(o.toolResult=r.content||"",o.toolDone=!0);continue}if(r.role==="assistant"){const o=r.created_at?new Date(r.created_at):new Date;t.push(...uf(r,n,o))}}return t}const He=()=>({blocks:[],currentBlocks:[],currentText:"",currentThinking:"",status:"available",usage:{promptTokens:0,completionTokens:0,totalTokens:0,cachedTokens:0},_completionBase:0,model:null,lastError:null}),xa=new Set(["write","edit","rm"]),mf=new Set(["note"]),ff=new Set(["schedule_task"]),Ls=new Set(["todo_manage"]);function xf(e,t){if(!xa.has(e)||!t)return!1;try{const n=JSON.parse(t),r=typeof n.path=="string"?n.path:"";return r.startsWith("wiki/")||r==="wiki"}catch{return t.includes('"path":"wiki/')||t.includes('"path": "wiki/')}}function Or(e){for(const t of e)if(t.attachments)for(const n of t.attachments)n.url?.startsWith("blob:")&&URL.revokeObjectURL(n.url)}function hf({set:e,get:t}){return(n,r)=>{const o=r;switch(n){case"session":{e(a=>{a.sessionId=o.session_id});break}case"title_update":{e(a=>{a.sessionTitle=o.title});break}case"thinking":{const a=o.agent;e(i=>{i.agentStreams[a]||(i.agentStreams[a]=He()),i.agentStreams[a].currentBlocks=of(i.agentStreams[a].currentBlocks,o.text)});break}case"message":{const a=o.agent;e(i=>{i.agentStreams[a]||(i.agentStreams[a]=He()),i.agentStreams[a].currentBlocks=af(i.agentStreams[a].currentBlocks,o.text)});break}case"tool_call":{if(Ls.has(o.name))break;const a=o.agent;e(i=>{i.agentStreams[a]||(i.agentStreams[a]=He()),i.agentStreams[a].currentBlocks=lf(i.agentStreams[a].currentBlocks,o.name,o.tool_call_id)});break}case"tool_start":{if(Ls.has(o.name))break;const a=o.agent;e(i=>{i.agentStreams[a]||(i.agentStreams[a]=He()),i.agentStreams[a].currentBlocks=cf(i.agentStreams[a].currentBlocks,o.name,o.arguments,o.tool_call_id)});break}case"tool_end":{const a=o.agent,i=o.name,l=o.tool_call_id;Ls.has(i)||e(d=>{d.agentStreams[a]||(d.agentStreams[a]=He()),d.agentStreams[a].currentBlocks=df(d.agentStreams[a].currentBlocks,i,l,o.result)});const c=[];if(mf.has(i)&&c.push({kind:"wiki"}),xa.has(i)){const u=t().agentStreams[a]?.currentBlocks.find(m=>m.type==="tool"&&(l?m.toolCallId===l:m.toolName===i));if(xf(i,u?.toolArgs))c.push({kind:"wiki"});else{const m=t().sessionId;m&&c.push({kind:"workspace_files",sessionId:m})}}if(ff.has(i)&&c.push({kind:"scheduler"}),Ls.has(i)){const d=t().sessionId;d&&c.push({kind:"todos",sessionId:d})}c.length>0&&e(d=>{d.cacheInvalidations.push(...c)});break}case"usage":{const a=o.metadata;if(a?.turn_total)break;const i=a?.agent??o.agent;if(!i)break;e(l=>{l.agentStreams[i]||(l.agentStreams[i]=He());const c=l.agentStreams[i],d=c.usage;d.promptTokens=o.prompt_tokens||0,d.completionTokens=c._completionBase+(o.completion_tokens||0),d.cachedTokens=o.cached_tokens??d.cachedTokens,d.totalTokens=d.promptTokens+d.completionTokens});break}case"inbox":{const a=o.agent;e(i=>{i.agentStreams[a]||(i.agentStreams[a]=He()),i.agentStreams[a].currentBlocks.push({id:Ct(),type:"user",content:o.content,extra:{from_agent:o.from_agent},timestamp:new Date})});break}case"agent_status":{const a=o.agent,i=o.status;e(l=>{l.agentStreams[a]||(l.agentStreams[a]=He()),i==="working"?(l.agentStreams[a].status="working",l.isTeamWorking=!0):i==="available"?l.agentStreams[a].status="available":i==="error"&&(l.agentStreams[a].status="error",l.agentStreams[a].lastError=o.metadata?.message??null),i!=="working"&&(l.isTeamWorking=Object.values(l.agentStreams).some(c=>c.status==="working"))});break}case"done":{e(i=>{i.isTeamWorking=!1;const l=new Date;Object.keys(i.agentStreams).forEach(c=>{const d=i.agentStreams[c];if(d.currentBlocks.length>0){const u=d.currentBlocks.map(m=>m.timestamp?m:{...m,timestamp:l});d.blocks=[...d.blocks,...u],d.currentBlocks=[]}d._completionBase=d.usage.completionTokens,d.status="available"})});const a=t()._pendingMessages;if(a.length>0){const i=a.map(c=>c.content).join(`
|
|
26
|
+
|
|
27
|
+
`),l=a.flatMap(c=>c.files??[]);e(c=>{c._pendingMessages=[]}),t().sendMessage(i,l.length>0?l:void 0)}break}case"error":{e(a=>{a.error=o.message,a.isTeamWorking=!1});break}}}}const ee=bo()(yo((e,t)=>({agentStreams:{},activeAgent:null,leadName:null,agentNames:[],sidebarOpen:!1,sessionId:null,sessionTitle:null,isTeamWorking:!1,isConnected:!1,error:null,_pendingMessages:[],_abortController:null,_sessionGeneration:0,cacheInvalidations:[],newSession:()=>{e(n=>{n.sessionId=null,n.sessionTitle=null,n.isTeamWorking=!1,n.error=null,n._pendingMessages=[],n._sessionGeneration=(n._sessionGeneration??0)+1,n.cacheInvalidations=[],n._pendingMessages=[],Object.keys(n.agentStreams).forEach(r=>{n.agentStreams[r].blocks=[],n.agentStreams[r].currentBlocks=[],n.agentStreams[r].currentText="",n.agentStreams[r].currentThinking="",n.agentStreams[r].status="available",n.agentStreams[r].lastError=null,n.agentStreams[r].usage={promptTokens:0,completionTokens:0,totalTokens:0,cachedTokens:0},n.agentStreams[r]._completionBase=0})})},sendMessage:async(n,r)=>{const{leadName:o,agentStreams:a}=t();if(o?a[o]?.status==="working":!1){e(c=>{c._pendingMessages.push({id:`pm-${Date.now()}`,content:n,files:r}),c.error=null});return}t()._abortController?.abort();const l=r?.map(c=>({original_name:c.name,media_type:c.type,category:c.type.startsWith("image/")?"image":"document",url:c.type.startsWith("image/")?URL.createObjectURL(c):void 0}));e(c=>{c.isTeamWorking=!0,c.error=null,o&&c.agentStreams[o]&&c.agentStreams[o].currentBlocks.push({id:`user-${Date.now()}`,type:"user",content:n,timestamp:new Date,attachments:l})});try{const c=await vr(n,t().sessionId,!1,r);e(d=>{d.sessionId=c.session_id}),t().connectStream()}catch(c){e(d=>{d.error=c instanceof Error?c.message:"Failed to send message",d.isTeamWorking=!1})}},removePendingMessage:n=>{e(r=>{r._pendingMessages=r._pendingMessages.filter(o=>o.id!==n)})},stopTeam:async()=>{const n=t().sessionId;if(!(!n||!t().isTeamWorking))try{await vr(null,n,!0)}catch(r){console.warn("stopTeam failed",r)}},connectStream:()=>{const n=t().sessionId;if(!n)return new AbortController;t()._abortController?.abort();const r=new AbortController;return e(o=>{o.isConnected=!0,o._abortController=r}),uc(n,{onEvent:(o,a)=>t()._handleSSEEvent(o,a),onError:o=>{e(a=>{a.error=o.message,a.isConnected=!1})},onDone:()=>{e(o=>{o.isConnected=!1})}},r.signal),r},loadTeamStatus:async()=>{try{const n=await Ao();if(n){const r=[n.lead,...n.members];e(o=>{o.leadName=n.lead.name,o.agentNames=r.map(a=>a.name),r.forEach(a=>{o.agentStreams[a.name]||(o.agentStreams[a.name]=He()),o.agentStreams[a.name].model=a.model}),!o.activeAgent&&o.agentNames.length>0&&(o.activeAgent=o.agentNames[0])})}}catch(n){e(r=>{r.error=n instanceof Error?n.message:"Failed to load team status"})}},loadSession:async n=>{const r=t()._sessionGeneration;try{const o=await hc(n);if(t()._sessionGeneration!==r)return;e(a=>{a.sessionId=n,a.isTeamWorking=!1,a.error=null;const i=o.lead.agent_name;a.leadName=i;const l=o.members.map(d=>d.name),c=i?[i,...l]:l;if(a.agentNames=c,i){a.agentStreams[i]||(a.agentStreams[i]=He()),Or(a.agentStreams[i].currentBlocks),a.agentStreams[i].blocks=Er(o.lead.messages),a.agentStreams[i].currentBlocks=[],a.agentStreams[i].currentText="",a.agentStreams[i].currentThinking="",a.agentStreams[i].status="available";const d=_r(o.lead.messages);a.agentStreams[i].usage=d,a.agentStreams[i]._completionBase=d.completionTokens}o.members.forEach(d=>{a.agentStreams[d.name]||(a.agentStreams[d.name]=He()),Or(a.agentStreams[d.name].currentBlocks),a.agentStreams[d.name].blocks=Er(d.messages),a.agentStreams[d.name].currentBlocks=[],a.agentStreams[d.name].currentText="",a.agentStreams[d.name].currentThinking="",a.agentStreams[d.name].status="available";const u=_r(d.messages);a.agentStreams[d.name].usage=u,a.agentStreams[d.name]._completionBase=u.completionTokens}),(!a.activeAgent||!c.includes(a.activeAgent))&&(a.activeAgent=i??c[0]??null)})}catch(o){if(t()._sessionGeneration!==r)return;e(a=>{a.error=o instanceof Error?o.message:"Failed to load session"})}},setActiveAgent:n=>{e(r=>{r.activeAgent=n})},cycleActiveAgent:n=>{e(r=>{const o=r.agentNames;if(o.length===0)return;const a=o.indexOf(r.activeAgent||"");r.activeAgent=n==="next"?o[(a+1)%o.length]:o[(a-1+o.length)%o.length]})},toggleSidebar:()=>{e(n=>{n.sidebarOpen=!n.sidebarOpen})},_drainCacheInvalidations:()=>{const n=t().cacheInvalidations;return n.length===0?[]:(e(r=>{r.cacheInvalidations=[]}),n)},_handleSSEEvent:hf({set:e,get:t})}))),pf=40,Pr=10;function gf({content:e,timestamp:t,attachments:n}){const[r,o]=f.useState(!1),[a,i]=f.useState(!1),[l,c]=f.useState(!1),d=async()=>{try{await navigator.clipboard.writeText(e),i(!0),setTimeout(()=>i(!1),1500)}catch{}},u=e.split(`
|
|
28
|
+
`),m=u.length>Pr,h=m&&!l?u.slice(0,Pr).join(`
|
|
29
|
+
`):e;return s.jsx("div",{className:"group mb-4 flex justify-end",onMouseEnter:()=>o(!0),onMouseLeave:()=>o(!1),children:s.jsxs("div",{className:"flex max-w-[78%] flex-col items-end gap-2",children:[n&&n.length>0&&s.jsx("div",{className:"flex flex-wrap justify-end gap-2",children:n.map((g,p)=>g.category==="image"?s.jsx(Hn,{src:g.url||"",alt:g.original_name||`Attachment ${p+1}`},p):s.jsx(Un,{name:g.original_name||g.filename||`File ${p+1}`,mediaType:g.media_type,url:g.url,clickable:!!g.url},p))}),s.jsxs("div",{className:"relative rounded-2xl rounded-br-sm bg-(--color-accent) px-4 py-2.5 text-sm leading-relaxed text-(--color-bg) overflow-hidden",children:[m&&s.jsx("button",{onClick:()=>c(g=>!g),"aria-expanded":l,title:l?"Collapse":"Expand",className:["absolute top-1.5 right-1.5","flex items-center justify-center shrink-0","rounded-md","h-5 w-5","transition-all duration-150","active:scale-90"].join(" "),style:{background:"rgba(0,0,0,0.15)",color:"var(--color-bg)"},children:l?s.jsx(Gs,{size:12}):s.jsx(Xe,{size:12})}),s.jsx("p",{className:"whitespace-pre-wrap",children:h}),m&&!l&&s.jsx("div",{className:"pointer-events-none absolute inset-x-0 bottom-0",style:{height:"2.4rem",background:"linear-gradient(to bottom, transparent 0%, var(--color-accent) 90%)"}})]}),t&&s.jsxs("div",{className:`flex items-center gap-1.5 transition-opacity duration-150 ${r?"opacity-100":"opacity-0"}`,children:[s.jsx("button",{onClick:d,className:"rounded p-0.5 text-(--color-text-muted) transition-colors hover:text-(--color-text-2)","aria-label":"Copy message",title:"Copy",children:a?s.jsx(vt,{size:11,className:"text-(--color-success)"}):s.jsx(Lt,{size:11})}),s.jsx("span",{className:"text-xs text-(--color-text-subtle)","aria-hidden":!r,title:Ns(t),children:Ns(t)})]})]})})}function $r({block:e,isStreaming:t,isLast:n,sessionId:r}){switch(e.type){case"user":{const o=e.extra?.from_agent;return o&&o!=="user"?s.jsx(Ho,{content:e.content,fromAgent:o}):s.jsx(gf,{content:e.content,timestamp:e.timestamp,attachments:e.attachments})}case"thinking":return s.jsx(Yo,{content:e.content,isStreaming:t});case"tool":return s.jsx(qo,{name:e.toolName||"",args:e.toolArgs,done:e.toolDone,result:e.toolResult});case"text":{const o=Zn(e.content);return o!==null?s.jsxs("div",{children:[o&&s.jsx(Ys,{content:o,sessionId:r}),s.jsx("p",{className:"text-xs text-(--color-text-subtle) italic",children:"— idle —"})]}):s.jsxs("div",{children:[s.jsx(Ys,{content:e.content,sessionId:r}),t&&n&&s.jsx(Ro,{className:"ml-0.5 text-(--color-accent)"})]})}default:return null}}function bf({blocks:e,currentBlocks:t,isWorking:n,isError:r,lastError:o}){const a=f.useRef(null),i=f.useRef(!0),[l,c]=f.useState(!1),d=ee(x=>x.sessionId)??void 0,u=[...e,...t],m=u.length,h=f.useCallback(()=>{const x=a.current;return x?x.scrollHeight-x.scrollTop-x.clientHeight<=pf:!0},[]),g=f.useCallback((x=!1)=>{const y=a.current;y&&(i.current=!0,c(!1),x?y.scrollTo({top:y.scrollHeight,behavior:"smooth"}):y.scrollTop=y.scrollHeight)},[]);f.useEffect(()=>{const x=a.current;if(!x)return;const y=()=>{requestAnimationFrame(()=>{const j=h();i.current=j,c(w=>w===!j?w:!j)})};return x.addEventListener("wheel",y,{passive:!0}),x.addEventListener("touchmove",y,{passive:!0}),()=>{x.removeEventListener("wheel",y),x.removeEventListener("touchmove",y)}},[h]);const p=u[u.length-1]?.content??"";f.useEffect(()=>{i.current&&g()},[m,p]);const b=m===0&&!n;return s.jsxs("div",{className:"relative flex min-h-0 flex-1 flex-col",children:[s.jsx("div",{ref:a,className:"flex-1 overflow-y-auto",children:s.jsxs("div",{className:"mx-auto max-w-3xl px-4 py-6",children:[b&&s.jsxs("div",{className:"flex flex-col items-center justify-center gap-3 py-16",children:[s.jsx(Lo,{className:"text-(--color-text-subtle) opacity-25",width:72,height:72}),s.jsx("p",{className:"text-sm text-(--color-text-subtle)",children:"Waiting for your first message…"})]}),s.jsxs("div",{className:"space-y-3",children:[(()=>{const x=ma(u);return x.map((y,j)=>{if(y.kind==="user")return s.jsx($r,{block:y.block,isStreaming:!1,isLast:y.index===u.length-1,sessionId:d},y.block.id);const w=j===x.length-1;return s.jsx(ua,{blocks:y.blocks,startIndex:y.startIndex,finalizedCount:e.length,isWorking:n,isTrailingTurn:w,totalBlocks:u.length,size:"roomy",renderBlock:({block:N,isStreaming:v,isLast:k})=>s.jsx($r,{block:N,isStreaming:v,isLast:k,sessionId:d})},`turn-${y.startIndex}-${y.blocks[0]?.id??j}`)})})(),(!n&&!r&&t.some(x=>x.type==="user")||n&&t.length>0&&t.every(x=>x.type==="user"))&&s.jsxs("div",{className:"flex items-center gap-1.5 py-1",children:[s.jsx("span",{className:"h-1.5 w-1.5 animate-bounce rounded-full bg-(--color-accent)",style:{animationDelay:"0ms"}}),s.jsx("span",{className:"h-1.5 w-1.5 animate-bounce rounded-full bg-(--color-accent)",style:{animationDelay:"150ms"}}),s.jsx("span",{className:"h-1.5 w-1.5 animate-bounce rounded-full bg-(--color-accent)",style:{animationDelay:"300ms"}})]}),r&&o&&s.jsx("div",{className:"mt-3 rounded-lg border border-(--color-error) bg-(--color-error-subtle) px-3 py-2",children:s.jsx("p",{className:"text-xs text-(--color-error)",children:o})})]})]})}),l&&s.jsx("button",{onClick:()=>g(!0),className:"absolute bottom-24 left-1/2 z-30 -translate-x-1/2 rounded-full border border-(--color-border) bg-(--color-surface) p-1.5 text-(--color-text-muted) shadow-sm transition-colors hover:text-(--color-text-2)","aria-label":"Scroll to bottom",children:s.jsx(Xe,{size:14})})]})}function ha(e){const[t,n]=f.useState(null),r=f.useRef(null);return f.useEffect(()=>{const o=e.current;if(!o)return;const a=l=>{r.current===null&&(r.current=requestAnimationFrame(()=>{r.current=null,n(l.clientY)}))},i=()=>{r.current!==null&&(cancelAnimationFrame(r.current),r.current=null),n(null)};return o.addEventListener("pointermove",a),o.addEventListener("pointerleave",i),()=>{o.removeEventListener("pointermove",a),o.removeEventListener("pointerleave",i),r.current!==null&&cancelAnimationFrame(r.current)}},[e]),t}function pa(e,t=120){const n=f.useRef(null),[r,o]=f.useState(null),a=_i();f.useLayoutEffect(()=>{const l=n.current;if(!l)return;const c=()=>{const u=l.getBoundingClientRect();o(u.top+u.height/2)};c();const d=new ResizeObserver(c);return d.observe(l),window.addEventListener("scroll",c,!0),()=>{d.disconnect(),window.removeEventListener("scroll",c,!0)}},[]);let i=0;if(!a&&e!==null&&r!==null){const l=Math.abs(e-r);l<t&&(i=1-l/t)}return{ref:n,intensity:i}}const pn=768;function Ye(){const[e,t]=f.useState(void 0);return f.useEffect(()=>{const n=window.matchMedia(`(max-width: ${pn-1}px)`),r=()=>{t(window.innerWidth<pn)};return n.addEventListener("change",r),t(window.innerWidth<pn),()=>n.removeEventListener("change",r)},[]),!!e}const yf=20;function vf(){return wi({queryKey:$.team.sessions.infinite(),queryFn:({pageParam:e})=>fc(e,yf),initialPageParam:null,getNextPageParam:e=>e.has_more?e.next_cursor:void 0})}function jf(){const e=pe();return ye({mutationFn:xc,onSuccess:()=>{e.invalidateQueries({queryKey:$.team.sessions.all()})}})}function wf(e=!1){return he({queryKey:[...$.wiki.tree(),{unprocessedOnly:e}],queryFn:()=>wc(e)})}function kf(e){return he({queryKey:$.wiki.file(e??""),queryFn:()=>kc(e),enabled:!!e})}function Nf(){const e=pe();return ye({mutationFn:({path:t,content:n})=>Nc(t,n),onSuccess:(t,{path:n})=>{e.invalidateQueries({queryKey:$.wiki.all()}),e.invalidateQueries({queryKey:$.wiki.file(n)})}})}function Sf(){const e=pe();return ye({mutationFn:t=>Sc(t),onSuccess:()=>{e.invalidateQueries({queryKey:$.wiki.all()})}})}function Cf(){return he({queryKey:$.dream.config(),queryFn:Cc})}function Tf(){const e=pe();return ye({mutationFn:t=>Tc(t),onSuccess:()=>{e.invalidateQueries({queryKey:$.dream.config()})}})}function ga(){const e=pe();return ye({mutationFn:Mc,onSuccess:()=>{e.invalidateQueries({queryKey:$.wiki.all()})}})}function Mf(e){return he({queryKey:$.team.files(e??""),queryFn:()=>pc(e),enabled:!!e,staleTime:5e3})}function ba(){return he({queryKey:$.agentFiles.list(),queryFn:Dc,staleTime:1e4})}function Df(e){return he({queryKey:$.agentFiles.detail(e??""),queryFn:()=>_c(e),enabled:!!e})}function _f(){return he({queryKey:$.agentFiles.registry(),queryFn:Pc,staleTime:6e4})}function ya(e){e.invalidateQueries({queryKey:$.agentFiles.all()}),e.invalidateQueries({queryKey:$.agents()}),e.invalidateQueries({queryKey:$.team.status()})}function Ef(){const e=pe();return ye({mutationFn:({name:t,content:n})=>Ec(t,n),onSuccess:()=>ya(e)})}function Of(){const e=pe();return ye({mutationFn:({name:t,content:n})=>Oc(t,n),onSuccess:(t,{name:n})=>{ya(e),e.invalidateQueries({queryKey:$.agentFiles.detail(n)})}})}function va(){return he({queryKey:$.skillFiles.list(),queryFn:$c,staleTime:1e4})}function Pf(e){return he({queryKey:$.skillFiles.detail(e??""),queryFn:()=>zc(e),enabled:!!e})}function ja(e){e.invalidateQueries({queryKey:$.skillFiles.all()}),e.invalidateQueries({queryKey:$.agentFiles.all()}),e.invalidateQueries({queryKey:$.agents()})}function $f(){const e=pe();return ye({mutationFn:({name:t,content:n})=>Rc(t,n),onSuccess:()=>ja(e)})}function zf(){const e=pe();return ye({mutationFn:({name:t,content:n})=>Ac(t,n),onSuccess:(t,{name:n})=>{ja(e),e.invalidateQueries({queryKey:$.skillFiles.detail(n)})}})}function Rf(e){return he({queryKey:$.observability.summary(e),queryFn:()=>yc(e),staleTime:6e4})}function Af(e,t=50,n=0){return he({queryKey:$.observability.traces(e,t,n),queryFn:()=>vc(e,t,n),staleTime:3e4})}function Ff(e){return he({queryKey:$.observability.trace(e??""),queryFn:()=>jc(e),enabled:e!==null&&e!=="",staleTime:1/0})}function Wf(){return he({queryKey:$.scheduler.list(),queryFn:Fc,staleTime:1e4})}function Lf(){const e=pe();return ye({mutationFn:t=>Wc(t),onSuccess:()=>{e.invalidateQueries({queryKey:$.scheduler.list()})}})}function If(){const e=pe();return ye({mutationFn:({id:t,body:n})=>Lc(t,n),onSuccess:()=>{e.invalidateQueries({queryKey:$.scheduler.list()})}})}function Bf(){const e=pe();return ye({mutationFn:t=>Ic(t),onSuccess:()=>{e.invalidateQueries({queryKey:$.scheduler.list()})}})}function Yf(){const e=pe();return ye({mutationFn:t=>Bc(t),onSuccess:()=>{e.invalidateQueries({queryKey:$.scheduler.list()})}})}function qf(){const e=pe();return ye({mutationFn:t=>Yc(t),onSuccess:()=>{e.invalidateQueries({queryKey:$.scheduler.list()})}})}function Hf(){const e=pe();return ye({mutationFn:t=>qc(t),onSuccess:()=>{e.invalidateQueries({queryKey:$.scheduler.list()})}})}function Jn(){return he({queryKey:$.mcp.list(),queryFn:Hc,staleTime:1e4})}function Uf(e){return he({queryKey:$.mcp.detail(e??""),queryFn:()=>Uc(e),enabled:!!e})}function wa(e){e.invalidateQueries({queryKey:$.mcp.all()})}function Qf(){const e=pe();return ye({mutationFn:({name:t,server:n})=>Qc(t,n),onSuccess:()=>wa(e)})}function Kf(){const e=pe();return ye({mutationFn:({name:t,server:n})=>Kc(t,n),onSuccess:(t,{name:n})=>{wa(e),e.invalidateQueries({queryKey:$.mcp.detail(n)})}})}function Gf(){const e=pe();return ye({mutationFn:t=>Gc(t),onSuccess:(t,n)=>{e.invalidateQueries({queryKey:$.mcp.detail(n)})}})}function ka(){return he({queryKey:$.settings.sandbox(),queryFn:Vc,staleTime:3e4})}function Vf(){const e=pe();return ye({mutationFn:t=>Xc(t),onSuccess:t=>{e.setQueryData($.settings.sandbox(),t)}})}function Xf({open:e,onClose:t}){const n=Ye(),{data:r,isLoading:o,isError:a}=wf(!0),[i,l]=f.useState(null),[c,d]=f.useState("tree"),u=g=>{l(g),n&&d("editor")},m=()=>{d("tree"),l(null)},h=[{key:"system",label:"Wiki",hint:"USER.md (injected every prompt) · INDEX.md (table of contents)",files:r?.system??[]},{key:"notes",label:"Notes",hint:"Unprocessed session notes — pending dream synthesis",files:r?.notes??[]},{key:"topics",label:"Topics",hint:"Dream-synthesised knowledge",files:r?.topics??[]}];return s.jsx(be,{children:e&&s.jsxs(s.Fragment,{children:[s.jsx(se.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},transition:{duration:.15},onClick:t,className:"fixed inset-0 z-40 bg-black/40"}),s.jsxs(se.div,{initial:{x:"-100%",opacity:0},animate:{x:0,opacity:1},exit:{x:"-100%",opacity:0},transition:{duration:.22,ease:[.4,0,.2,1]},className:"fixed inset-y-0 left-0 z-50 flex w-[min(960px,90vw)] flex-col overflow-hidden bg-(--color-surface) shadow-2xl",children:[s.jsxs("header",{className:"flex items-center justify-between border-b border-(--color-border) px-4 py-3",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[n&&c==="editor"&&s.jsx("button",{onClick:m,className:"rounded p-1 text-(--color-text-muted) transition-colors hover:bg-(--color-accent-subtle) hover:text-(--color-text)","aria-label":"Back to file list",children:s.jsx(Be,{size:16})}),s.jsxs("div",{children:[s.jsx("h2",{className:"text-sm font-semibold text-(--color-text)",children:"Wiki"}),s.jsx("p",{className:"text-xs text-(--color-text-subtle)",children:"Agent knowledge base — synthesised from past conversations"})]})]}),s.jsx("button",{onClick:t,className:"rounded p-1 text-(--color-text-muted) transition-colors hover:bg-(--color-accent-subtle) hover:text-(--color-text)","aria-label":"Close wiki panel",children:s.jsx(Ee,{size:16})})]}),n?s.jsx("div",{className:"flex min-h-0 flex-1 flex-col",children:c==="tree"?s.jsx("nav",{className:"flex-1 overflow-y-auto px-2 py-3",children:s.jsx(zr,{isLoading:o,isError:a,sections:h,selectedPath:i,onSelect:u})}):s.jsx("div",{className:"min-w-0 flex-1",children:i?s.jsx(Rr,{path:i,onDeleted:m},i):s.jsx(Ar,{})})}):s.jsxs("div",{className:"flex min-h-0 flex-1",children:[s.jsx("nav",{className:"w-[220px] shrink-0 overflow-y-auto border-r border-(--color-border) px-2 py-3",children:s.jsx(zr,{isLoading:o,isError:a,sections:h,selectedPath:i,onSelect:u})}),s.jsx("div",{className:"min-w-0 flex-1",children:i?s.jsx(Rr,{path:i,onDeleted:()=>l(null)},i):s.jsx(Ar,{})})]})]})]})})}function zr({isLoading:e,isError:t,sections:n,selectedPath:r,onSelect:o}){return e?s.jsx("div",{className:"px-2 py-6 text-center text-xs text-(--color-text-subtle)",children:s.jsx(_e,{size:14,className:"mx-auto animate-spin"})}):t?s.jsx("p",{className:"px-2 py-4 text-xs text-(--color-error)",children:"Failed to load wiki"}):s.jsx(s.Fragment,{children:n.map(a=>s.jsx(Zf,{section:a,selectedPath:r,onSelect:o},a.key))})}function Zf({section:e,selectedPath:t,onSelect:n}){return s.jsxs("div",{className:"mb-4",children:[s.jsxs("div",{className:"mb-1 flex items-center gap-1.5 px-2 py-1 text-xs font-semibold uppercase tracking-wider text-(--color-text-subtle)",children:[s.jsx(Co,{size:12}),e.label]}),s.jsx("p",{className:"mb-1 px-2 text-[10px] text-(--color-text-subtle)",children:e.hint}),e.files.length===0?s.jsx("p",{className:"px-2 py-1 text-xs italic text-(--color-text-subtle)",children:"empty"}):s.jsx("ul",{className:"space-y-0.5",children:e.files.map(r=>{const o=r.path.split("/").pop()??r.path,a=r.path===t;return s.jsx("li",{children:s.jsxs("button",{onClick:()=>n(r.path),className:T("group flex w-full items-start gap-1.5 rounded px-2 py-1.5 text-left text-xs transition-colors",a?"bg-(--color-accent-subtle) text-(--color-accent)":"text-(--color-text-2) hover:bg-(--color-accent-subtle) hover:text-(--color-text)"),title:r.description||o,children:[s.jsx(Tt,{size:12,className:"mt-0.5 shrink-0"}),s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsx("div",{className:"truncate font-medium",children:o}),r.description&&s.jsx("div",{className:"truncate text-[10px] text-(--color-text-subtle)",children:r.description})]})]})},r.path)})})]})}function Rr({path:e,onDeleted:t}){const{data:n,isLoading:r,isError:o}=kf(e),a=Nf(),i=Sf(),l=f.useRef(null),[c,d]=f.useState(!1),[u,m]=f.useState(0),h=e.startsWith("notes/"),g=e!=="USER.md"&&e!=="INDEX.md",p=()=>l.current?.value??n?.content??"",b=()=>{!c||h||a.mutate({path:e,content:p()},{onSuccess:()=>d(!1)})},x=()=>{confirm(`Delete wiki file "${e}"? This cannot be undone.`)&&i.mutate(e,{onSuccess:t})},y=w=>{!h&&(w.ctrlKey||w.metaKey)&&w.key==="s"&&(w.preventDefault(),b())};if(r)return s.jsx("div",{className:"flex h-full items-center justify-center text-(--color-text-subtle)",children:s.jsx(_e,{size:16,className:"animate-spin"})});if(o||!n)return s.jsxs("div",{className:"flex h-full items-center justify-center px-4 text-center text-xs text-(--color-error)",children:["Failed to load ",e]});const j=u||n.content.length;return s.jsxs("div",{className:"flex h-full flex-col",children:[s.jsxs("div",{className:"flex items-center justify-between border-b border-(--color-border) px-4 py-2",children:[s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsx("div",{className:"truncate font-mono text-xs text-(--color-text)",children:e}),n.description&&s.jsx("div",{className:"truncate text-[10px] text-(--color-text-subtle)",children:n.description})]}),s.jsxs("div",{className:"ml-2 flex items-center gap-1",children:[!h&&s.jsxs("button",{onClick:b,disabled:!c||a.isPending,className:T("flex items-center gap-1 rounded px-2.5 py-1 text-xs font-medium transition-colors",c?"text-(--color-success) hover:bg-(--color-success-subtle)":"cursor-not-allowed text-(--color-text-subtle)"),title:"Save (Ctrl+S)",children:[a.isPending?s.jsx(_e,{size:12,className:"animate-spin"}):s.jsx(ws,{size:12}),"Save"]}),g&&s.jsxs("button",{onClick:x,disabled:i.isPending,className:"flex items-center gap-1 rounded px-2.5 py-1 text-xs font-medium text-(--color-error) transition-colors hover:bg-(--color-error-subtle)",title:"Delete file",children:[s.jsx(Os,{size:12}),"Delete"]})]})]}),a.isError&&s.jsx("div",{className:"border-b border-(--color-border) bg-(--color-error-subtle) px-4 py-2 text-xs text-(--color-error)",children:a.error.message}),s.jsx("textarea",{ref:l,defaultValue:n.content,readOnly:h,onInput:w=>{if(h)return;const N=w.target.value;m(N.length),c||d(!0)},onKeyDown:y,spellCheck:!1,className:T("min-h-0 flex-1 resize-none p-4 font-mono text-sm text-(--color-text) focus:outline-none",h?"cursor-default bg-(--color-surface-2) text-(--color-text-muted)":"bg-(--color-bg)"),placeholder:h?"":e==="INDEX.md"?`# Index
|
|
30
|
+
|
|
31
|
+
- [topic](topics/topic.md) — description
|
|
32
|
+
`:`Frontmatter recommended:
|
|
33
|
+
---
|
|
34
|
+
description: …
|
|
35
|
+
---
|
|
36
|
+
|
|
37
|
+
`}),s.jsxs("div",{className:"flex items-center justify-between border-t border-(--color-border) px-4 py-1.5 text-[10px] text-(--color-text-subtle)",children:[s.jsxs("span",{children:[j," chars"]}),h?s.jsx("span",{className:"italic",children:"read-only"}):c?s.jsx("span",{className:"text-(--color-accent)",children:"unsaved"}):s.jsx("span",{children:"saved"})]})]})}function Ar(){return s.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-2 px-6 text-center",children:[s.jsx(Tt,{size:24,className:"text-(--color-text-subtle)"}),s.jsx("p",{className:"text-sm text-(--color-text-2)",children:"Select a file"}),s.jsxs("p",{className:"max-w-xs text-xs text-(--color-text-subtle)",children:[s.jsx("span",{className:"font-medium",children:"USER.md"})," is injected into every prompt."," ",s.jsx("span",{className:"font-medium",children:"INDEX.md"})," is the dream-maintained table of contents."," ",s.jsx("span",{className:"font-medium",children:"topics/"})," are searched by the agent on demand."," ",s.jsx("span",{className:"font-medium",children:"notes/"})," shows unprocessed notes — run ",s.jsx("code",{className:"font-mono",children:"Dream"})," to synthesise them."]})]})}const Us=vo("group/button inline-flex shrink-0 items-center justify-center rounded-lg border border-transparent bg-clip-padding text-sm font-medium whitespace-nowrap transition-all outline-none select-none focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 active:not-aria-[haspopup]:translate-y-px disabled:pointer-events-none disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",{variants:{variant:{default:"bg-primary text-primary-foreground [a]:hover:bg-primary/80",outline:"border-border bg-background hover:bg-muted hover:text-foreground aria-expanded:bg-muted aria-expanded:text-foreground dark:border-input dark:bg-input/30 dark:hover:bg-input/50",secondary:"bg-secondary text-secondary-foreground hover:bg-secondary/80 aria-expanded:bg-secondary aria-expanded:text-secondary-foreground",ghost:"hover:bg-muted hover:text-foreground aria-expanded:bg-muted aria-expanded:text-foreground dark:hover:bg-muted/50",destructive:"bg-destructive/10 text-destructive hover:bg-destructive/20 focus-visible:border-destructive/40 focus-visible:ring-destructive/20 dark:bg-destructive/20 dark:hover:bg-destructive/30 dark:focus-visible:ring-destructive/40",link:"text-primary underline-offset-4 hover:underline"},size:{default:"h-8 gap-1.5 px-2.5 has-data-[icon=inline-end]:pr-2 has-data-[icon=inline-start]:pl-2",xs:"h-6 gap-1 rounded-[min(var(--radius-md),10px)] px-2 text-xs in-data-[slot=button-group]:rounded-lg has-data-[icon=inline-end]:pr-1.5 has-data-[icon=inline-start]:pl-1.5 [&_svg:not([class*='size-'])]:size-3",sm:"h-7 gap-1 rounded-[min(var(--radius-md),12px)] px-2.5 text-[0.8rem] in-data-[slot=button-group]:rounded-lg has-data-[icon=inline-end]:pr-1.5 has-data-[icon=inline-start]:pl-1.5 [&_svg:not([class*='size-'])]:size-3.5",lg:"h-9 gap-1.5 px-2.5 has-data-[icon=inline-end]:pr-2 has-data-[icon=inline-start]:pl-2",icon:"size-8","icon-xs":"size-6 rounded-[min(var(--radius-md),10px)] in-data-[slot=button-group]:rounded-lg [&_svg:not([class*='size-'])]:size-3","icon-sm":"size-7 rounded-[min(var(--radius-md),12px)] in-data-[slot=button-group]:rounded-lg","icon-lg":"size-9"}},defaultVariants:{variant:"default",size:"default"}});function Y({className:e,variant:t="default",size:n="default",...r}){return s.jsx(yl,{"data-slot":"button",className:T(Us({variant:t,size:n,className:e})),...r})}function Jf(e,t,n="long"){return new Intl.DateTimeFormat("en-US",{hour:"numeric",timeZone:e,timeZoneName:n}).format(t).split(/\s/g).slice(2).join(" ")}const ex={},bs={};function At(e,t){try{const r=(ex[e]||=new Intl.DateTimeFormat("en-US",{timeZone:e,timeZoneName:"longOffset"}).format)(t).split("GMT")[1];return r in bs?bs[r]:Fr(r,r.split(":"))}catch{if(e in bs)return bs[e];const n=e?.match(tx);return n?Fr(e,n.slice(1)):NaN}}const tx=/([+-]\d\d):?(\d\d)?/;function Fr(e,t){const n=+(t[0]||0),r=+(t[1]||0),o=+(t[2]||0)/60;return bs[e]=n*60+r>0?n*60+r+o:n*60-r-o}class it extends Date{constructor(...t){super(),t.length>1&&typeof t[t.length-1]=="string"&&(this.timeZone=t.pop()),this.internal=new Date,isNaN(At(this.timeZone,this))?this.setTime(NaN):t.length?typeof t[0]=="number"&&(t.length===1||t.length===2&&typeof t[1]!="number")?this.setTime(t[0]):typeof t[0]=="string"?this.setTime(+new Date(t[0])):t[0]instanceof Date?this.setTime(+t[0]):(this.setTime(+new Date(...t)),Na(this),Pn(this)):this.setTime(Date.now())}static tz(t,...n){return n.length?new it(...n,t):new it(Date.now(),t)}withTimeZone(t){return new it(+this,t)}getTimezoneOffset(){const t=-At(this.timeZone,this);return t>0?Math.floor(t):Math.ceil(t)}setTime(t){return Date.prototype.setTime.apply(this,arguments),Pn(this),+this}[Symbol.for("constructDateFrom")](t){return new it(+new Date(t),this.timeZone)}}const Wr=/^(get|set)(?!UTC)/;Object.getOwnPropertyNames(Date.prototype).forEach(e=>{if(!Wr.test(e))return;const t=e.replace(Wr,"$1UTC");it.prototype[t]&&(e.startsWith("get")?it.prototype[e]=function(){return this.internal[t]()}:(it.prototype[e]=function(){return Date.prototype[t].apply(this.internal,arguments),sx(this),+this},it.prototype[t]=function(){return Date.prototype[t].apply(this,arguments),Pn(this),+this}))});function Pn(e){e.internal.setTime(+e),e.internal.setUTCSeconds(e.internal.getUTCSeconds()-Math.round(-At(e.timeZone,e)*60))}function sx(e){Date.prototype.setFullYear.call(e,e.internal.getUTCFullYear(),e.internal.getUTCMonth(),e.internal.getUTCDate()),Date.prototype.setHours.call(e,e.internal.getUTCHours(),e.internal.getUTCMinutes(),e.internal.getUTCSeconds(),e.internal.getUTCMilliseconds()),Na(e)}function Na(e){const t=At(e.timeZone,e),n=t>0?Math.floor(t):Math.ceil(t),r=new Date(+e);r.setUTCHours(r.getUTCHours()-1);const o=-new Date(+e).getTimezoneOffset(),a=-new Date(+r).getTimezoneOffset(),i=o-a,l=Date.prototype.getHours.apply(e)!==e.internal.getUTCHours();i&&l&&e.internal.setUTCMinutes(e.internal.getUTCMinutes()+i);const c=o-n;c&&Date.prototype.setUTCMinutes.call(e,Date.prototype.getUTCMinutes.call(e)+c);const d=new Date(+e);d.setUTCSeconds(0);const u=o>0?d.getSeconds():(d.getSeconds()-60)%60,m=Math.round(-(At(e.timeZone,e)*60))%60;(m||u)&&(e.internal.setUTCSeconds(e.internal.getUTCSeconds()+m),Date.prototype.setUTCSeconds.call(e,Date.prototype.getUTCSeconds.call(e)+m+u));const h=At(e.timeZone,e),g=h>0?Math.floor(h):Math.ceil(h),b=-new Date(+e).getTimezoneOffset()-g,x=g!==n,y=b-c;if(x&&y){Date.prototype.setUTCMinutes.call(e,Date.prototype.getUTCMinutes.call(e)+y);const j=At(e.timeZone,e),w=j>0?Math.floor(j):Math.ceil(j),N=g-w;N&&(e.internal.setUTCMinutes(e.internal.getUTCMinutes()+N),Date.prototype.setUTCMinutes.call(e,Date.prototype.getUTCMinutes.call(e)+N))}}class Ce extends it{static tz(t,...n){return n.length?new Ce(...n,t):new Ce(Date.now(),t)}toISOString(){const[t,n,r]=this.tzComponents(),o=`${t}${n}:${r}`;return this.internal.toISOString().slice(0,-1)+o}toString(){return`${this.toDateString()} ${this.toTimeString()}`}toDateString(){const[t,n,r,o]=this.internal.toUTCString().split(" ");return`${t?.slice(0,-1)} ${r} ${n} ${o}`}toTimeString(){const t=this.internal.toUTCString().split(" ")[4],[n,r,o]=this.tzComponents();return`${t} GMT${n}${r}${o} (${Jf(this.timeZone,this)})`}toLocaleString(t,n){return Date.prototype.toLocaleString.call(this,t,{...n,timeZone:n?.timeZone||this.timeZone})}toLocaleDateString(t,n){return Date.prototype.toLocaleDateString.call(this,t,{...n,timeZone:n?.timeZone||this.timeZone})}toLocaleTimeString(t,n){return Date.prototype.toLocaleTimeString.call(this,t,{...n,timeZone:n?.timeZone||this.timeZone})}tzComponents(){const t=this.getTimezoneOffset(),n=t>0?"-":"+",r=String(Math.floor(Math.abs(t)/60)).padStart(2,"0"),o=String(Math.abs(t)%60).padStart(2,"0");return[n,r,o]}withTimeZone(t){return new Ce(+this,t)}[Symbol.for("constructDateFrom")](t){return new Ce(+new Date(t),this.timeZone)}}const Lr=5,nx=4;function rx(e,t){const n=t.startOfMonth(e),r=n.getDay()>0?n.getDay():7,o=t.addDays(e,-r+1),a=t.addDays(o,Lr*7-1);return t.getMonth(e)===t.getMonth(a)?Lr:nx}function Sa(e,t){const n=t.startOfMonth(e),r=n.getDay();return r===1?n:r===0?t.addDays(n,-6):t.addDays(n,-1*(r-1))}function ox(e,t){const n=Sa(e,t),r=rx(e,t);return t.addDays(n,r*7-1)}const Ca={...Rt,labels:{labelDayButton:(e,t,n,r)=>{let o;r&&typeof r.format=="function"?o=r.format.bind(r):o=(i,l)=>Qe(i,l,{locale:Rt,...n});let a=o(e,"PPPP");return t.today&&(a=`Today, ${a}`),t.selected&&(a=`${a}, selected`),a},labelMonthDropdown:"Choose the Month",labelNext:"Go to the Next Month",labelPrevious:"Go to the Previous Month",labelWeekNumber:e=>`Week ${e}`,labelYearDropdown:"Choose the Year",labelGrid:(e,t,n)=>{let r;return n&&typeof n.format=="function"?r=n.format.bind(n):r=(o,a)=>Qe(o,a,{locale:Rt,...t}),r(e,"LLLL yyyy")},labelGridcell:(e,t,n,r)=>{let o;r&&typeof r.format=="function"?o=r.format.bind(r):o=(i,l)=>Qe(i,l,{locale:Rt,...n});let a=o(e,"PPPP");return t?.today&&(a=`Today, ${a}`),a},labelNav:"Navigation bar",labelWeekNumberHeader:"Week Number",labelWeekday:(e,t,n)=>{let r;return n&&typeof n.format=="function"?r=n.format.bind(n):r=(o,a)=>Qe(o,a,{locale:Rt,...t}),r(e,"cccc")}}};class Fe{constructor(t,n){this.Date=Date,this.today=()=>this.overrides?.today?this.overrides.today():this.options.timeZone?Ce.tz(this.options.timeZone):new this.Date,this.newDate=(r,o,a)=>this.overrides?.newDate?this.overrides.newDate(r,o,a):this.options.timeZone?new Ce(r,o,a,this.options.timeZone):new Date(r,o,a),this.addDays=(r,o)=>this.overrides?.addDays?this.overrides.addDays(r,o):zs(r,o),this.addMonths=(r,o)=>this.overrides?.addMonths?this.overrides.addMonths(r,o):Qo(r,o),this.addWeeks=(r,o)=>this.overrides?.addWeeks?this.overrides.addWeeks(r,o):Kd(r,o),this.addYears=(r,o)=>this.overrides?.addYears?this.overrides.addYears(r,o):Gd(r,o),this.differenceInCalendarDays=(r,o)=>this.overrides?.differenceInCalendarDays?this.overrides.differenceInCalendarDays(r,o):Qn(r,o),this.differenceInCalendarMonths=(r,o)=>this.overrides?.differenceInCalendarMonths?this.overrides.differenceInCalendarMonths(r,o):Zo(r,o),this.eachMonthOfInterval=r=>this.overrides?.eachMonthOfInterval?this.overrides.eachMonthOfInterval(r):Jd(r),this.eachYearOfInterval=r=>{const o=this.overrides?.eachYearOfInterval?this.overrides.eachYearOfInterval(r):su(r),a=new Set(o.map(l=>this.getYear(l)));if(a.size===o.length)return o;const i=[];return a.forEach(l=>{i.push(new Date(l,0,1))}),i},this.endOfBroadcastWeek=r=>this.overrides?.endOfBroadcastWeek?this.overrides.endOfBroadcastWeek(r):ox(r,this),this.endOfISOWeek=r=>this.overrides?.endOfISOWeek?this.overrides.endOfISOWeek(r):nu(r),this.endOfMonth=r=>this.overrides?.endOfMonth?this.overrides.endOfMonth(r):Zd(r),this.endOfWeek=(r,o)=>this.overrides?.endOfWeek?this.overrides.endOfWeek(r,o):ta(r,this.options),this.endOfYear=r=>this.overrides?.endOfYear?this.overrides.endOfYear(r):tu(r),this.format=(r,o,a)=>{const i=this.overrides?.format?this.overrides.format(r,o,this.options):Qe(r,o,this.options);return this.options.numerals&&this.options.numerals!=="latn"?this.replaceDigits(i):i},this.getISOWeek=r=>this.overrides?.getISOWeek?this.overrides.getISOWeek(r):Vs(r),this.getMonth=(r,o)=>this.overrides?.getMonth?this.overrides.getMonth(r,this.options):Zu(r,this.options),this.getYear=(r,o)=>this.overrides?.getYear?this.overrides.getYear(r,this.options):Ju(r,this.options),this.getWeek=(r,o)=>this.overrides?.getWeek?this.overrides.getWeek(r,this.options):Xs(r,this.options),this.isAfter=(r,o)=>this.overrides?.isAfter?this.overrides.isAfter(r,o):em(r,o),this.isBefore=(r,o)=>this.overrides?.isBefore?this.overrides.isBefore(r,o):tm(r,o),this.isDate=r=>this.overrides?.isDate?this.overrides.isDate(r):Vo(r),this.isSameDay=(r,o)=>this.overrides?.isSameDay?this.overrides.isSameDay(r,o):Kn(r,o),this.isSameMonth=(r,o)=>this.overrides?.isSameMonth?this.overrides.isSameMonth(r,o):Zm(r,o),this.isSameYear=(r,o)=>this.overrides?.isSameYear?this.overrides.isSameYear(r,o):Jm(r,o),this.max=r=>this.overrides?.max?this.overrides.max(r):Vd(r),this.min=r=>this.overrides?.min?this.overrides.min(r):Xd(r),this.setMonth=(r,o)=>this.overrides?.setMonth?this.overrides.setMonth(r,o):tf(r,o),this.setYear=(r,o)=>this.overrides?.setYear?this.overrides.setYear(r,o):sf(r,o),this.startOfBroadcastWeek=(r,o)=>this.overrides?.startOfBroadcastWeek?this.overrides.startOfBroadcastWeek(r,this):Sa(r,this),this.startOfDay=r=>this.overrides?.startOfDay?this.overrides.startOfDay(r):ks(r),this.startOfISOWeek=r=>this.overrides?.startOfISOWeek?this.overrides.startOfISOWeek(r):It(r),this.startOfMonth=r=>this.overrides?.startOfMonth?this.overrides.startOfMonth(r):eu(r),this.startOfWeek=(r,o)=>this.overrides?.startOfWeek?this.overrides.startOfWeek(r,this.options):jt(r,this.options),this.startOfYear=r=>this.overrides?.startOfYear?this.overrides.startOfYear(r):ea(r),this.options={locale:Ca,...t},this.overrides=n}getDigitMap(){const{numerals:t="latn"}=this.options,n=new Intl.NumberFormat("en-US",{numberingSystem:t}),r={};for(let o=0;o<10;o++)r[o.toString()]=n.format(o);return r}replaceDigits(t){const n=this.getDigitMap();return t.replace(/\d/g,r=>n[r]||r)}formatNumber(t){return this.replaceDigits(t.toString())}getMonthYearOrder(){const t=this.options.locale?.code;return t&&Fe.yearFirstLocales.has(t)?"year-first":"month-first"}formatMonthYear(t){const{locale:n,timeZone:r,numerals:o}=this.options,a=n?.code;if(a&&Fe.yearFirstLocales.has(a))try{return new Intl.DateTimeFormat(a,{month:"long",year:"numeric",timeZone:r,numberingSystem:o}).format(t)}catch{}const i=this.getMonthYearOrder()==="year-first"?"y LLLL":"LLLL y";return this.format(t,i)}}Fe.yearFirstLocales=new Set(["eu","hu","ja","ja-Hira","ja-JP","ko","ko-KR","lt","lt-LT","lv","lv-LV","mn","mn-MN","zh","zh-CN","zh-HK","zh-TW"]);const dt=new Fe;class Ta{constructor(t,n,r=dt){this.date=t,this.displayMonth=n,this.outside=!!(n&&!r.isSameMonth(t,n)),this.dateLib=r,this.isoDate=r.format(t,"yyyy-MM-dd"),this.displayMonthId=r.format(n,"yyyy-MM"),this.dateMonthId=r.format(t,"yyyy-MM")}isEqualTo(t){return this.dateLib.isSameDay(t.date,this.date)&&this.dateLib.isSameMonth(t.displayMonth,this.displayMonth)}}class ax{constructor(t,n){this.date=t,this.weeks=n}}class ix{constructor(t,n){this.days=n,this.weekNumber=t}}function lx(e){return D.createElement("button",{...e})}function cx(e){return D.createElement("span",{...e})}function dx(e){const{size:t=24,orientation:n="left",className:r}=e;return D.createElement("svg",{className:r,width:t,height:t,viewBox:"0 0 24 24"},n==="up"&&D.createElement("polygon",{points:"6.77 17 12.5 11.43 18.24 17 20 15.28 12.5 8 5 15.28"}),n==="down"&&D.createElement("polygon",{points:"6.77 8 12.5 13.57 18.24 8 20 9.72 12.5 17 5 9.72"}),n==="left"&&D.createElement("polygon",{points:"16 18.112 9.81111111 12 16 5.87733333 14.0888889 4 6 12 14.0888889 20"}),n==="right"&&D.createElement("polygon",{points:"8 18.112 14.18888889 12 8 5.87733333 9.91111111 4 18 12 9.91111111 20"}))}function ux(e){const{day:t,modifiers:n,...r}=e;return D.createElement("td",{...r})}function mx(e){const{day:t,modifiers:n,...r}=e,o=D.useRef(null);return D.useEffect(()=>{n.focused&&o.current?.focus()},[n.focused]),D.createElement("button",{ref:o,...r})}var O;(function(e){e.Root="root",e.Chevron="chevron",e.Day="day",e.DayButton="day_button",e.CaptionLabel="caption_label",e.Dropdowns="dropdowns",e.Dropdown="dropdown",e.DropdownRoot="dropdown_root",e.Footer="footer",e.MonthGrid="month_grid",e.MonthCaption="month_caption",e.MonthsDropdown="months_dropdown",e.Month="month",e.Months="months",e.Nav="nav",e.NextMonthButton="button_next",e.PreviousMonthButton="button_previous",e.Week="week",e.Weeks="weeks",e.Weekday="weekday",e.Weekdays="weekdays",e.WeekNumber="week_number",e.WeekNumberHeader="week_number_header",e.YearsDropdown="years_dropdown"})(O||(O={}));var ie;(function(e){e.disabled="disabled",e.hidden="hidden",e.outside="outside",e.focused="focused",e.today="today"})(ie||(ie={}));var Ke;(function(e){e.range_end="range_end",e.range_middle="range_middle",e.range_start="range_start",e.selected="selected"})(Ke||(Ke={}));var Re;(function(e){e.weeks_before_enter="weeks_before_enter",e.weeks_before_exit="weeks_before_exit",e.weeks_after_enter="weeks_after_enter",e.weeks_after_exit="weeks_after_exit",e.caption_after_enter="caption_after_enter",e.caption_after_exit="caption_after_exit",e.caption_before_enter="caption_before_enter",e.caption_before_exit="caption_before_exit"})(Re||(Re={}));function fx(e){const{options:t,className:n,components:r,classNames:o,...a}=e,i=[o[O.Dropdown],n].join(" "),l=t?.find(({value:c})=>c===a.value);return D.createElement("span",{"data-disabled":a.disabled,className:o[O.DropdownRoot]},D.createElement(r.Select,{className:i,...a},t?.map(({value:c,label:d,disabled:u})=>D.createElement(r.Option,{key:c,value:c,disabled:u},d))),D.createElement("span",{className:o[O.CaptionLabel],"aria-hidden":!0},l?.label,D.createElement(r.Chevron,{orientation:"down",size:18,className:o[O.Chevron]})))}function xx(e){return D.createElement("div",{...e})}function hx(e){return D.createElement("div",{...e})}function px(e){const{calendarMonth:t,displayIndex:n,...r}=e;return D.createElement("div",{...r},e.children)}function gx(e){const{calendarMonth:t,displayIndex:n,...r}=e;return D.createElement("div",{...r})}function bx(e){return D.createElement("table",{...e})}function yx(e){return D.createElement("div",{...e})}const Ma=f.createContext(void 0);function Rs(){const e=f.useContext(Ma);if(e===void 0)throw new Error("useDayPicker() must be used within a custom component.");return e}function vx(e){const{components:t}=Rs();return D.createElement(t.Dropdown,{...e})}function jx(e){const{onPreviousClick:t,onNextClick:n,previousMonth:r,nextMonth:o,...a}=e,{components:i,classNames:l,labels:{labelPrevious:c,labelNext:d}}=Rs(),u=f.useCallback(h=>{o&&n?.(h)},[o,n]),m=f.useCallback(h=>{r&&t?.(h)},[r,t]);return D.createElement("nav",{...a},D.createElement(i.PreviousMonthButton,{type:"button",className:l[O.PreviousMonthButton],tabIndex:r?void 0:-1,"aria-disabled":r?void 0:!0,"aria-label":c(r),onClick:m},D.createElement(i.Chevron,{disabled:r?void 0:!0,className:l[O.Chevron],orientation:"left"})),D.createElement(i.NextMonthButton,{type:"button",className:l[O.NextMonthButton],tabIndex:o?void 0:-1,"aria-disabled":o?void 0:!0,"aria-label":d(o),onClick:u},D.createElement(i.Chevron,{disabled:o?void 0:!0,orientation:"right",className:l[O.Chevron]})))}function wx(e){const{components:t}=Rs();return D.createElement(t.Button,{...e})}function kx(e){return D.createElement("option",{...e})}function Nx(e){const{components:t}=Rs();return D.createElement(t.Button,{...e})}function Sx(e){const{rootRef:t,...n}=e;return D.createElement("div",{...n,ref:t})}function Cx(e){return D.createElement("select",{...e})}function Tx(e){const{week:t,...n}=e;return D.createElement("tr",{...n})}function Mx(e){return D.createElement("th",{...e})}function Dx(e){return D.createElement("thead",{"aria-hidden":!0},D.createElement("tr",{...e}))}function _x(e){const{week:t,...n}=e;return D.createElement("th",{...n})}function Ex(e){return D.createElement("th",{...e})}function Ox(e){return D.createElement("tbody",{...e})}function Px(e){const{components:t}=Rs();return D.createElement(t.Dropdown,{...e})}const $x=Object.freeze(Object.defineProperty({__proto__:null,Button:lx,CaptionLabel:cx,Chevron:dx,Day:ux,DayButton:mx,Dropdown:fx,DropdownNav:xx,Footer:hx,Month:px,MonthCaption:gx,MonthGrid:bx,Months:yx,MonthsDropdown:vx,Nav:jx,NextMonthButton:wx,Option:kx,PreviousMonthButton:Nx,Root:Sx,Select:Cx,Week:Tx,WeekNumber:_x,WeekNumberHeader:Ex,Weekday:Mx,Weekdays:Dx,Weeks:Ox,YearsDropdown:Px},Symbol.toStringTag,{value:"Module"}));function ht(e,t,n=!1,r=dt){let{from:o,to:a}=e;const{differenceInCalendarDays:i,isSameDay:l}=r;return o&&a?(i(a,o)<0&&([o,a]=[a,o]),i(t,o)>=(n?1:0)&&i(a,t)>=(n?1:0)):!n&&a?l(a,t):!n&&o?l(o,t):!1}function er(e){return!!(e&&typeof e=="object"&&"before"in e&&"after"in e)}function Zs(e){return!!(e&&typeof e=="object"&&"from"in e)}function tr(e){return!!(e&&typeof e=="object"&&"after"in e)}function sr(e){return!!(e&&typeof e=="object"&&"before"in e)}function Da(e){return!!(e&&typeof e=="object"&&"dayOfWeek"in e)}function _a(e,t){return Array.isArray(e)&&e.every(t.isDate)}function pt(e,t,n=dt){const r=Array.isArray(t)?t:[t],{isSameDay:o,differenceInCalendarDays:a,isAfter:i}=n;return r.some(l=>{if(typeof l=="boolean")return l;if(n.isDate(l))return o(e,l);if(_a(l,n))return l.some(c=>o(e,c));if(Zs(l))return ht(l,e,!1,n);if(Da(l))return Array.isArray(l.dayOfWeek)?l.dayOfWeek.includes(e.getDay()):l.dayOfWeek===e.getDay();if(er(l)){const c=a(l.before,e),d=a(l.after,e),u=c>0,m=d<0;return i(l.before,l.after)?m&&u:u||m}return tr(l)?a(e,l.after)>0:sr(l)?a(l.before,e)>0:typeof l=="function"?l(e):!1})}function zx(e,t,n,r,o){const{disabled:a,hidden:i,modifiers:l,showOutsideDays:c,broadcastCalendar:d,today:u=o.today()}=t,{isSameDay:m,isSameMonth:h,startOfMonth:g,isBefore:p,endOfMonth:b,isAfter:x}=o,y=n&&g(n),j=r&&b(r),w={[ie.focused]:[],[ie.outside]:[],[ie.disabled]:[],[ie.hidden]:[],[ie.today]:[]},N={};for(const v of e){const{date:k,displayMonth:C}=v,z=!!(C&&!h(k,C)),q=!!(y&&p(k,y)),H=!!(j&&x(k,j)),E=!!(a&&pt(k,a,o)),L=!!(i&&pt(k,i,o))||q||H||!d&&!c&&z||d&&c===!1&&z,P=m(k,u);z&&w.outside.push(v),E&&w.disabled.push(v),L&&w.hidden.push(v),P&&w.today.push(v),l&&Object.keys(l).forEach(I=>{const _=l?.[I];_&&pt(k,_,o)&&(N[I]?N[I].push(v):N[I]=[v])})}return v=>{const k={[ie.focused]:!1,[ie.disabled]:!1,[ie.hidden]:!1,[ie.outside]:!1,[ie.today]:!1},C={};for(const z in w){const q=w[z];k[z]=q.some(H=>H===v)}for(const z in N)C[z]=N[z].some(q=>q===v);return{...k,...C}}}function Rx(e,t,n={}){return Object.entries(e).filter(([,o])=>o===!0).reduce((o,[a])=>(n[a]?o.push(n[a]):t[ie[a]]?o.push(t[ie[a]]):t[Ke[a]]&&o.push(t[Ke[a]]),o),[t[O.Day]])}function Ax(e){return{...$x,...e}}function Fx(e){const t={"data-mode":e.mode??void 0,"data-required":"required"in e?e.required:void 0,"data-multiple-months":e.numberOfMonths&&e.numberOfMonths>1||void 0,"data-week-numbers":e.showWeekNumber||void 0,"data-broadcast-calendar":e.broadcastCalendar||void 0,"data-nav-layout":e.navLayout||void 0};return Object.entries(e).forEach(([n,r])=>{n.startsWith("data-")&&(t[n]=r)}),t}function nr(){const e={};for(const t in O)e[O[t]]=`rdp-${O[t]}`;for(const t in ie)e[ie[t]]=`rdp-${ie[t]}`;for(const t in Ke)e[Ke[t]]=`rdp-${Ke[t]}`;for(const t in Re)e[Re[t]]=`rdp-${Re[t]}`;return e}function Ea(e,t,n){return(n??new Fe(t)).formatMonthYear(e)}const Wx=Ea;function Lx(e,t,n){return(n??new Fe(t)).format(e,"d")}function Ix(e,t=dt){return t.format(e,"LLLL")}function Bx(e,t,n){return(n??new Fe(t)).format(e,"cccccc")}function Yx(e,t=dt){return e<10?t.formatNumber(`0${e.toLocaleString()}`):t.formatNumber(`${e.toLocaleString()}`)}function qx(){return""}function Oa(e,t=dt){return t.format(e,"yyyy")}const Hx=Oa,Ux=Object.freeze(Object.defineProperty({__proto__:null,formatCaption:Ea,formatDay:Lx,formatMonthCaption:Wx,formatMonthDropdown:Ix,formatWeekNumber:Yx,formatWeekNumberHeader:qx,formatWeekdayName:Bx,formatYearCaption:Hx,formatYearDropdown:Oa},Symbol.toStringTag,{value:"Module"}));function Qx(e){return e?.formatMonthCaption&&!e.formatCaption&&(e.formatCaption=e.formatMonthCaption),e?.formatYearCaption&&!e.formatYearDropdown&&(e.formatYearDropdown=e.formatYearCaption),{...Ux,...e}}function rr(e,t,n,r){let o=(r??new Fe(n)).format(e,"PPPP");return t.today&&(o=`Today, ${o}`),t.selected&&(o=`${o}, selected`),o}const Kx=rr;function or(e,t,n){return(n??new Fe(t)).formatMonthYear(e)}const Gx=or;function Pa(e,t,n,r){let o=(r??new Fe(n)).format(e,"PPPP");return t?.today&&(o=`Today, ${o}`),o}function $a(e){return"Choose the Month"}function za(){return""}const Vx="Go to the Next Month";function Ra(e,t){return Vx}function Aa(e){return"Go to the Previous Month"}function Fa(e,t,n){return(n??new Fe(t)).format(e,"cccc")}function Wa(e,t){return`Week ${e}`}function La(e){return"Week Number"}function Ia(e){return"Choose the Year"}const Xx=Object.freeze(Object.defineProperty({__proto__:null,labelCaption:Gx,labelDay:Kx,labelDayButton:rr,labelGrid:or,labelGridcell:Pa,labelMonthDropdown:$a,labelNav:za,labelNext:Ra,labelPrevious:Aa,labelWeekNumber:Wa,labelWeekNumberHeader:La,labelWeekday:Fa,labelYearDropdown:Ia},Symbol.toStringTag,{value:"Module"})),qe=(e,t,n)=>t||(n?typeof n=="function"?n:(...r)=>n:e);function Zx(e,t){const n=t.locale?.labels??{};return{...Xx,...e??{},labelDayButton:qe(rr,e?.labelDayButton,n.labelDayButton),labelMonthDropdown:qe($a,e?.labelMonthDropdown,n.labelMonthDropdown),labelNext:qe(Ra,e?.labelNext,n.labelNext),labelPrevious:qe(Aa,e?.labelPrevious,n.labelPrevious),labelWeekNumber:qe(Wa,e?.labelWeekNumber,n.labelWeekNumber),labelYearDropdown:qe(Ia,e?.labelYearDropdown,n.labelYearDropdown),labelGrid:qe(or,e?.labelGrid,n.labelGrid),labelGridcell:qe(Pa,e?.labelGridcell,n.labelGridcell),labelNav:qe(za,e?.labelNav,n.labelNav),labelWeekNumberHeader:qe(La,e?.labelWeekNumberHeader,n.labelWeekNumberHeader),labelWeekday:qe(Fa,e?.labelWeekday,n.labelWeekday)}}function Jx(e,t,n,r,o){const{startOfMonth:a,startOfYear:i,endOfYear:l,eachMonthOfInterval:c,getMonth:d}=o;return c({start:i(e),end:l(e)}).map(h=>{const g=r.formatMonthDropdown(h,o),p=d(h),b=t&&h<a(t)||n&&h>a(n)||!1;return{value:p,label:g,disabled:b}})}function eh(e,t={},n={}){let r={...t?.[O.Day]};return Object.entries(e).filter(([,o])=>o===!0).forEach(([o])=>{r={...r,...n?.[o]}}),r}function th(e,t,n,r){const o=r??e.today(),a=n?e.startOfBroadcastWeek(o,e):t?e.startOfISOWeek(o):e.startOfWeek(o),i=[];for(let l=0;l<7;l++){const c=e.addDays(a,l);i.push(c)}return i}function sh(e,t,n,r,o=!1){if(!e||!t)return;const{startOfYear:a,endOfYear:i,eachYearOfInterval:l,getYear:c}=r,d=a(e),u=i(t),m=l({start:d,end:u});return o&&m.reverse(),m.map(h=>{const g=n.formatYearDropdown(h,r);return{value:c(h),label:g,disabled:!1}})}function nh(e,t={}){const{weekStartsOn:n,locale:r}=t,o=n??r?.options?.weekStartsOn??0,a=l=>{const c=typeof l=="number"||typeof l=="string"?new Date(l):l;return new Ce(c.getFullYear(),c.getMonth(),c.getDate(),12,0,0,e)},i=l=>{const c=a(l);return new Date(c.getFullYear(),c.getMonth(),c.getDate(),0,0,0,0)};return{today:()=>a(Ce.tz(e)),newDate:(l,c,d)=>new Ce(l,c,d,12,0,0,e),startOfDay:l=>a(l),startOfWeek:(l,c)=>{const d=a(l),u=c?.weekStartsOn??o,m=(d.getDay()-u+7)%7;return d.setDate(d.getDate()-m),d},startOfISOWeek:l=>{const c=a(l),d=(c.getDay()-1+7)%7;return c.setDate(c.getDate()-d),c},startOfMonth:l=>{const c=a(l);return c.setDate(1),c},startOfYear:l=>{const c=a(l);return c.setMonth(0,1),c},endOfWeek:(l,c)=>{const d=a(l),h=(((c?.weekStartsOn??o)+6)%7-d.getDay()+7)%7;return d.setDate(d.getDate()+h),d},endOfISOWeek:l=>{const c=a(l),d=(7-c.getDay())%7;return c.setDate(c.getDate()+d),c},endOfMonth:l=>{const c=a(l);return c.setMonth(c.getMonth()+1,0),c},endOfYear:l=>{const c=a(l);return c.setMonth(11,31),c},eachMonthOfInterval:l=>{const c=a(l.start),d=a(l.end),u=[],m=new Ce(c.getFullYear(),c.getMonth(),1,12,0,0,e),h=d.getFullYear()*12+d.getMonth();for(;m.getFullYear()*12+m.getMonth()<=h;)u.push(new Ce(m,e)),m.setMonth(m.getMonth()+1,1);return u},addDays:(l,c)=>{const d=a(l);return d.setDate(d.getDate()+c),d},addWeeks:(l,c)=>{const d=a(l);return d.setDate(d.getDate()+c*7),d},addMonths:(l,c)=>{const d=a(l);return d.setMonth(d.getMonth()+c),d},addYears:(l,c)=>{const d=a(l);return d.setFullYear(d.getFullYear()+c),d},eachYearOfInterval:l=>{const c=a(l.start),d=a(l.end),u=[],m=new Ce(c.getFullYear(),0,1,12,0,0,e);for(;m.getFullYear()<=d.getFullYear();)u.push(new Ce(m,e)),m.setFullYear(m.getFullYear()+1,0,1);return u},getWeek:(l,c)=>{const d=i(l);return Xs(d,{weekStartsOn:c?.weekStartsOn??o,firstWeekContainsDate:c?.firstWeekContainsDate??r?.options?.firstWeekContainsDate??1})},getISOWeek:l=>{const c=i(l);return Vs(c)},differenceInCalendarDays:(l,c)=>{const d=i(l),u=i(c);return Qn(d,u)},differenceInCalendarMonths:(l,c)=>{const d=i(l),u=i(c);return Zo(d,u)}}}const As=e=>e instanceof HTMLElement?e:null,gn=e=>[...e.querySelectorAll("[data-animated-month]")??[]],rh=e=>As(e.querySelector("[data-animated-month]")),bn=e=>As(e.querySelector("[data-animated-caption]")),yn=e=>As(e.querySelector("[data-animated-weeks]")),oh=e=>As(e.querySelector("[data-animated-nav]")),ah=e=>As(e.querySelector("[data-animated-weekdays]"));function ih(e,t,{classNames:n,months:r,focused:o,dateLib:a}){const i=f.useRef(null),l=f.useRef(r),c=f.useRef(!1);f.useLayoutEffect(()=>{const d=l.current;if(l.current=r,!t||!e.current||!(e.current instanceof HTMLElement)||r.length===0||d.length===0||r.length!==d.length)return;const u=a.isSameMonth(r[0].date,d[0].date),m=a.isAfter(r[0].date,d[0].date),h=m?n[Re.caption_after_enter]:n[Re.caption_before_enter],g=m?n[Re.weeks_after_enter]:n[Re.weeks_before_enter],p=i.current,b=e.current.cloneNode(!0);if(b instanceof HTMLElement?(gn(b).forEach(w=>{if(!(w instanceof HTMLElement))return;const N=rh(w);N&&w.contains(N)&&w.removeChild(N);const v=bn(w);v&&v.classList.remove(h);const k=yn(w);k&&k.classList.remove(g)}),i.current=b):i.current=null,c.current||u||o)return;const x=p instanceof HTMLElement?gn(p):[],y=gn(e.current);if(y?.every(j=>j instanceof HTMLElement)&&x&&x.every(j=>j instanceof HTMLElement)){c.current=!0,e.current.style.isolation="isolate";const j=oh(e.current);j&&(j.style.zIndex="1"),y.forEach((w,N)=>{const v=x[N];if(!v)return;w.style.position="relative",w.style.overflow="hidden";const k=bn(w);k&&k.classList.add(h);const C=yn(w);C&&C.classList.add(g);const z=()=>{c.current=!1,e.current&&(e.current.style.isolation=""),j&&(j.style.zIndex=""),k&&k.classList.remove(h),C&&C.classList.remove(g),w.style.position="",w.style.overflow="",w.contains(v)&&w.removeChild(v)};v.style.pointerEvents="none",v.style.position="absolute",v.style.overflow="hidden",v.setAttribute("aria-hidden","true");const q=ah(v);q&&(q.style.opacity="0");const H=bn(v);H&&(H.classList.add(m?n[Re.caption_before_exit]:n[Re.caption_after_exit]),H.addEventListener("animationend",z));const E=yn(v);E&&E.classList.add(m?n[Re.weeks_before_exit]:n[Re.weeks_after_exit]),w.insertBefore(v,w.firstChild)})}})}function lh(e,t,n,r){const o=e[0],a=e[e.length-1],{ISOWeek:i,fixedWeeks:l,broadcastCalendar:c}=n??{},{addDays:d,differenceInCalendarDays:u,differenceInCalendarMonths:m,endOfBroadcastWeek:h,endOfISOWeek:g,endOfMonth:p,endOfWeek:b,isAfter:x,startOfBroadcastWeek:y,startOfISOWeek:j,startOfWeek:w}=r,N=c?y(o,r):i?j(o):w(o),v=c?h(a):i?g(p(a)):b(p(a)),k=t&&(c?h(t):i?g(t):b(t)),C=k&&x(v,k)?k:v,z=u(C,N),q=m(a,o)+1,H=[];for(let P=0;P<=z;P++){const I=d(N,P);H.push(I)}const L=(c?35:42)*q;if(l&&H.length<L){const P=L-H.length;for(let I=0;I<P;I++){const _=d(H[H.length-1],1);H.push(_)}}return H}function ch(e){const t=[];return e.reduce((n,r)=>{const o=r.weeks.reduce((a,i)=>a.concat(i.days.slice()),t.slice());return n.concat(o.slice())},t.slice())}function dh(e,t,n,r){const{numberOfMonths:o=1}=n,a=[];for(let i=0;i<o;i++){const l=r.addMonths(e,i);if(t&&l>t)break;a.push(l)}return a}function Ir(e,t,n,r){const{month:o,defaultMonth:a,today:i=r.today(),numberOfMonths:l=1}=e;let c=o||a||i;const{differenceInCalendarMonths:d,addMonths:u,startOfMonth:m}=r;if(n&&d(n,c)<l-1){const h=-1*(l-1);c=u(n,h)}return t&&d(c,t)<0&&(c=t),m(c)}function uh(e,t,n,r){const{addDays:o,endOfBroadcastWeek:a,endOfISOWeek:i,endOfMonth:l,endOfWeek:c,getISOWeek:d,getWeek:u,startOfBroadcastWeek:m,startOfISOWeek:h,startOfWeek:g}=r,p=e.reduce((b,x)=>{const y=n.broadcastCalendar?m(x,r):n.ISOWeek?h(x):g(x),j=n.broadcastCalendar?a(x):n.ISOWeek?i(l(x)):c(l(x)),w=t.filter(C=>C>=y&&C<=j),N=n.broadcastCalendar?35:42;if(n.fixedWeeks&&w.length<N){const C=t.filter(z=>{const q=N-w.length;return z>j&&z<=o(j,q)});w.push(...C)}const v=w.reduce((C,z)=>{const q=n.ISOWeek?d(z):u(z),H=C.find(L=>L.weekNumber===q),E=new Ta(z,x,r);return H?H.days.push(E):C.push(new ix(q,[E])),C},[]),k=new ax(x,v);return b.push(k),b},[]);return n.reverseMonths?p.reverse():p}function mh(e,t){let{startMonth:n,endMonth:r}=e;const{startOfYear:o,startOfDay:a,startOfMonth:i,endOfMonth:l,addYears:c,endOfYear:d,newDate:u,today:m}=t,{fromYear:h,toYear:g,fromMonth:p,toMonth:b}=e;!n&&p&&(n=p),!n&&h&&(n=t.newDate(h,0,1)),!r&&b&&(r=b),!r&&g&&(r=u(g,11,31));const x=e.captionLayout==="dropdown"||e.captionLayout==="dropdown-years";return n?n=i(n):h?n=u(h,0,1):!n&&x&&(n=o(c(e.today??m(),-100))),r?r=l(r):g?r=u(g,11,31):!r&&x&&(r=d(e.today??m())),[n&&a(n),r&&a(r)]}function fh(e,t,n,r){if(n.disableNavigation)return;const{pagedNavigation:o,numberOfMonths:a=1}=n,{startOfMonth:i,addMonths:l,differenceInCalendarMonths:c}=r,d=o?a:1,u=i(e);if(!t)return l(u,d);if(!(c(t,e)<a))return l(u,d)}function xh(e,t,n,r){if(n.disableNavigation)return;const{pagedNavigation:o,numberOfMonths:a}=n,{startOfMonth:i,addMonths:l,differenceInCalendarMonths:c}=r,d=o?a??1:1,u=i(e);if(!t)return l(u,-d);if(!(c(u,t)<=0))return l(u,-d)}function hh(e){const t=[];return e.reduce((n,r)=>n.concat(r.weeks.slice()),t.slice())}function Js(e,t){const[n,r]=f.useState(e);return[t===void 0?n:t,r]}function ph(e,t){const[n,r]=mh(e,t),{startOfMonth:o,endOfMonth:a}=t,i=Ir(e,n,r,t),[l,c]=Js(i,e.month?i:void 0);f.useEffect(()=>{const N=Ir(e,n,r,t);c(N)},[e.timeZone]);const{months:d,weeks:u,days:m,previousMonth:h,nextMonth:g}=f.useMemo(()=>{const N=dh(l,r,{numberOfMonths:e.numberOfMonths},t),v=lh(N,e.endMonth?a(e.endMonth):void 0,{ISOWeek:e.ISOWeek,fixedWeeks:e.fixedWeeks,broadcastCalendar:e.broadcastCalendar},t),k=uh(N,v,{broadcastCalendar:e.broadcastCalendar,fixedWeeks:e.fixedWeeks,ISOWeek:e.ISOWeek,reverseMonths:e.reverseMonths},t),C=hh(k),z=ch(k),q=xh(l,n,e,t),H=fh(l,r,e,t);return{months:k,weeks:C,days:z,previousMonth:q,nextMonth:H}},[t,l.getTime(),r?.getTime(),n?.getTime(),e.disableNavigation,e.broadcastCalendar,e.endMonth?.getTime(),e.fixedWeeks,e.ISOWeek,e.numberOfMonths,e.pagedNavigation,e.reverseMonths]),{disableNavigation:p,onMonthChange:b}=e,x=N=>u.some(v=>v.days.some(k=>k.isEqualTo(N))),y=N=>{if(p)return;let v=o(N);n&&v<o(n)&&(v=o(n)),r&&v>o(r)&&(v=o(r)),c(v),b?.(v)};return{months:d,weeks:u,days:m,navStart:n,navEnd:r,previousMonth:h,nextMonth:g,goToMonth:y,goToDay:N=>{x(N)||y(N.date)}}}var st;(function(e){e[e.Today=0]="Today",e[e.Selected=1]="Selected",e[e.LastFocused=2]="LastFocused",e[e.FocusedModifier=3]="FocusedModifier"})(st||(st={}));function Br(e){return!e[ie.disabled]&&!e[ie.hidden]&&!e[ie.outside]}function gh(e,t,n,r){let o,a=-1;for(const i of e){const l=t(i);Br(l)&&(l[ie.focused]&&a<st.FocusedModifier?(o=i,a=st.FocusedModifier):r?.isEqualTo(i)&&a<st.LastFocused?(o=i,a=st.LastFocused):n(i.date)&&a<st.Selected?(o=i,a=st.Selected):l[ie.today]&&a<st.Today&&(o=i,a=st.Today))}return o||(o=e.find(i=>Br(t(i)))),o}function bh(e,t,n,r,o,a,i){const{ISOWeek:l,broadcastCalendar:c}=a,{addDays:d,addMonths:u,addWeeks:m,addYears:h,endOfBroadcastWeek:g,endOfISOWeek:p,endOfWeek:b,max:x,min:y,startOfBroadcastWeek:j,startOfISOWeek:w,startOfWeek:N}=i;let k={day:d,week:m,month:u,year:h,startOfWeek:C=>c?j(C,i):l?w(C):N(C),endOfWeek:C=>c?g(C):l?p(C):b(C)}[e](n,t==="after"?1:-1);return t==="before"&&r?k=x([r,k]):t==="after"&&o&&(k=y([o,k])),k}function Ba(e,t,n,r,o,a,i,l=0){if(l>365)return;const c=bh(e,t,n.date,r,o,a,i),d=!!(a.disabled&&pt(c,a.disabled,i)),u=!!(a.hidden&&pt(c,a.hidden,i)),m=c,h=new Ta(c,m,i);return!d&&!u?h:Ba(e,t,h,r,o,a,i,l+1)}function yh(e,t,n,r,o){const{autoFocus:a}=e,[i,l]=f.useState(),c=gh(t.days,n,r||(()=>!1),i),[d,u]=f.useState(a?c:void 0);return{isFocusTarget:b=>!!c?.isEqualTo(b),setFocused:u,focused:d,blur:()=>{l(d),u(void 0)},moveFocus:(b,x)=>{if(!d)return;const y=Ba(b,x,d,t.navStart,t.navEnd,e,o);y&&(e.disableNavigation&&!t.days.some(w=>w.isEqualTo(y))||(t.goToDay(y),u(y)))}}}function vh(e,t){const{selected:n,required:r,onSelect:o}=e,[a,i]=Js(n,o?n:void 0),l=o?n:a,{isSameDay:c}=t,d=g=>l?.some(p=>c(p,g))??!1,{min:u,max:m}=e;return{selected:l,select:(g,p,b)=>{let x=[...l??[]];if(d(g)){if(l?.length===u||r&&l?.length===1)return;x=l?.filter(y=>!c(y,g))}else l?.length===m?x=[g]:x=[...x,g];return o||i(x),o?.(x,g,p,b),x},isSelected:d}}function jh(e,t,n=0,r=0,o=!1,a=dt){const{from:i,to:l}=t||{},{isSameDay:c,isAfter:d,isBefore:u}=a;let m;if(!i&&!l)m={from:e,to:n>0?void 0:e};else if(i&&!l)c(i,e)?n===0?m={from:i,to:e}:o?m={from:i,to:void 0}:m=void 0:u(e,i)?m={from:e,to:i}:m={from:i,to:e};else if(i&&l)if(c(i,e)&&c(l,e))o?m={from:i,to:l}:m=void 0;else if(c(i,e))m={from:i,to:n>0?void 0:e};else if(c(l,e))m={from:e,to:n>0?void 0:e};else if(u(e,i))m={from:e,to:l};else if(d(e,i))m={from:i,to:e};else if(d(e,l))m={from:i,to:e};else throw new Error("Invalid range");if(m?.from&&m?.to){const h=a.differenceInCalendarDays(m.to,m.from);r>0&&h>r?m={from:e,to:void 0}:n>1&&h<n&&(m={from:e,to:void 0})}return m}function wh(e,t,n=dt){const r=Array.isArray(t)?t:[t];let o=e.from;const a=n.differenceInCalendarDays(e.to,e.from),i=Math.min(a,6);for(let l=0;l<=i;l++){if(r.includes(o.getDay()))return!0;o=n.addDays(o,1)}return!1}function Yr(e,t,n=dt){return ht(e,t.from,!1,n)||ht(e,t.to,!1,n)||ht(t,e.from,!1,n)||ht(t,e.to,!1,n)}function kh(e,t,n=dt){const r=Array.isArray(t)?t:[t];if(r.filter(l=>typeof l!="function").some(l=>typeof l=="boolean"?l:n.isDate(l)?ht(e,l,!1,n):_a(l,n)?l.some(c=>ht(e,c,!1,n)):Zs(l)?l.from&&l.to?Yr(e,{from:l.from,to:l.to},n):!1:Da(l)?wh(e,l.dayOfWeek,n):er(l)?n.isAfter(l.before,l.after)?Yr(e,{from:n.addDays(l.after,1),to:n.addDays(l.before,-1)},n):pt(e.from,l,n)||pt(e.to,l,n):tr(l)||sr(l)?pt(e.from,l,n)||pt(e.to,l,n):!1))return!0;const i=r.filter(l=>typeof l=="function");if(i.length){let l=e.from;const c=n.differenceInCalendarDays(e.to,e.from);for(let d=0;d<=c;d++){if(i.some(u=>u(l)))return!0;l=n.addDays(l,1)}}return!1}function Nh(e,t){const{disabled:n,excludeDisabled:r,resetOnSelect:o,selected:a,required:i,onSelect:l}=e,[c,d]=Js(a,l?a:void 0),u=l?a:c;return{selected:u,select:(g,p,b)=>{const{min:x,max:y}=e;let j;if(g){const w=u?.from,N=u?.to,v=!!w&&!!N,k=!!w&&!!N&&t.isSameDay(w,N)&&t.isSameDay(g,w);o&&(v||!u?.from)?!i&&k?j=void 0:j={from:g,to:void 0}:j=jh(g,u,x,y,i,t)}return r&&n&&j?.from&&j.to&&kh({from:j.from,to:j.to},n,t)&&(j.from=g,j.to=void 0),l||d(j),l?.(j,g,p,b),j},isSelected:g=>u&&ht(u,g,!1,t)}}function Sh(e,t){const{selected:n,required:r,onSelect:o}=e,[a,i]=Js(n,o?n:void 0),l=o?n:a,{isSameDay:c}=t;return{selected:l,select:(m,h,g)=>{let p=m;return!r&&l&&l&&c(m,l)&&(p=void 0),o||i(p),o?.(p,m,h,g),p},isSelected:m=>l?c(l,m):!1}}function Ch(e,t){const n=Sh(e,t),r=vh(e,t),o=Nh(e,t);switch(e.mode){case"single":return n;case"multiple":return r;case"range":return o;default:return}}function Le(e,t){return e instanceof Ce&&e.timeZone===t?e:new Ce(e,t)}function Kt(e,t,n){return Le(e,t)}function qr(e,t,n){return typeof e=="boolean"||typeof e=="function"?e:e instanceof Date?Kt(e,t):Array.isArray(e)?e.map(r=>r instanceof Date?Kt(r,t):r):Zs(e)?{...e,from:e.from?Le(e.from,t):e.from,to:e.to?Le(e.to,t):e.to}:er(e)?{before:Kt(e.before,t),after:Kt(e.after,t)}:tr(e)?{after:Kt(e.after,t)}:sr(e)?{before:Kt(e.before,t)}:e}function vn(e,t,n){return e&&(Array.isArray(e)?e.map(r=>qr(r,t)):qr(e,t))}function Th(e){let t=e;const n=t.timeZone;if(n&&(t={...e,timeZone:n},t.today&&(t.today=Le(t.today,n)),t.month&&(t.month=Le(t.month,n)),t.defaultMonth&&(t.defaultMonth=Le(t.defaultMonth,n)),t.startMonth&&(t.startMonth=Le(t.startMonth,n)),t.endMonth&&(t.endMonth=Le(t.endMonth,n)),t.mode==="single"&&t.selected?t.selected=Le(t.selected,n):t.mode==="multiple"&&t.selected?t.selected=t.selected?.map(B=>Le(B,n)):t.mode==="range"&&t.selected&&(t.selected={from:t.selected.from?Le(t.selected.from,n):t.selected.from,to:t.selected.to?Le(t.selected.to,n):t.selected.to}),t.disabled!==void 0&&(t.disabled=vn(t.disabled,n)),t.hidden!==void 0&&(t.hidden=vn(t.hidden,n)),t.modifiers)){const B={};Object.keys(t.modifiers).forEach(J=>{B[J]=vn(t.modifiers?.[J],n)}),t.modifiers=B}const{components:r,formatters:o,labels:a,dateLib:i,locale:l,classNames:c}=f.useMemo(()=>{const B={...Ca,...t.locale},J=t.broadcastCalendar?1:t.weekStartsOn,R=t.noonSafe&&t.timeZone?nh(t.timeZone,{weekStartsOn:J,locale:B}):void 0,V=t.dateLib&&R?{...R,...t.dateLib}:t.dateLib??R,ze=new Fe({locale:B,weekStartsOn:J,firstWeekContainsDate:t.firstWeekContainsDate,useAdditionalWeekYearTokens:t.useAdditionalWeekYearTokens,useAdditionalDayOfYearTokens:t.useAdditionalDayOfYearTokens,timeZone:t.timeZone,numerals:t.numerals},V);return{dateLib:ze,components:Ax(t.components),formatters:Qx(t.formatters),labels:Zx(t.labels,ze.options),locale:B,classNames:{...nr(),...t.classNames}}},[t.locale,t.broadcastCalendar,t.weekStartsOn,t.firstWeekContainsDate,t.useAdditionalWeekYearTokens,t.useAdditionalDayOfYearTokens,t.timeZone,t.numerals,t.dateLib,t.noonSafe,t.components,t.formatters,t.labels,t.classNames]);t.today||(t={...t,today:i.today()});const{captionLayout:d,mode:u,navLayout:m,numberOfMonths:h=1,onDayBlur:g,onDayClick:p,onDayFocus:b,onDayKeyDown:x,onDayMouseEnter:y,onDayMouseLeave:j,onNextClick:w,onPrevClick:N,showWeekNumber:v,styles:k}=t,{formatCaption:C,formatDay:z,formatMonthDropdown:q,formatWeekNumber:H,formatWeekNumberHeader:E,formatWeekdayName:L,formatYearDropdown:P}=o,I=ph(t,i),{days:_,months:A,navStart:ae,navEnd:$e,previousMonth:xe,nextMonth:ue,goToMonth:ne}=I,wt=zx(_,t,ae,$e,i),{isSelected:kt,select:ut,selected:mt}=Ch(t,i)??{},{blur:ft,focused:Dt,isFocusTarget:Nt,moveFocus:_t,setFocused:ge}=yh(t,I,wt,kt??(()=>!1),i),{labelDayButton:je,labelGridcell:Et,labelGrid:M,labelMonthDropdown:W,labelNav:Q,labelPrevious:we,labelNext:Se,labelWeekday:Ot,labelWeekNumber:on,labelWeekNumberHeader:Fs,labelYearDropdown:an}=a,ln=f.useMemo(()=>th(i,t.ISOWeek,t.broadcastCalendar,t.today),[i,t.ISOWeek,t.broadcastCalendar,t.today]),cs=u!==void 0||p!==void 0,xt=f.useCallback(()=>{xe&&(ne(xe),N?.(xe))},[xe,ne,N]),Pt=f.useCallback(()=>{ue&&(ne(ue),w?.(ue))},[ne,ue,w]),ds=f.useCallback((B,J)=>R=>{R.preventDefault(),R.stopPropagation(),ge(B),!J.disabled&&(ut?.(B.date,J,R),p?.(B.date,J,R))},[ut,p,ge]),Ws=f.useCallback((B,J)=>R=>{ge(B),b?.(B.date,J,R)},[b,ge]),cn=f.useCallback((B,J)=>R=>{ft(),g?.(B.date,J,R)},[ft,g]),us=f.useCallback((B,J)=>R=>{const V={ArrowLeft:[R.shiftKey?"month":"day",t.dir==="rtl"?"after":"before"],ArrowRight:[R.shiftKey?"month":"day",t.dir==="rtl"?"before":"after"],ArrowDown:[R.shiftKey?"year":"week","after"],ArrowUp:[R.shiftKey?"year":"week","before"],PageUp:[R.shiftKey?"year":"month","before"],PageDown:[R.shiftKey?"year":"month","after"],Home:["startOfWeek","before"],End:["endOfWeek","after"]};if(V[R.key]){R.preventDefault(),R.stopPropagation();const[ze,K]=V[R.key];_t(ze,K)}x?.(B.date,J,R)},[_t,x,t.dir]),S=f.useCallback((B,J)=>R=>{y?.(B.date,J,R)},[y]),Z=f.useCallback((B,J)=>R=>{j?.(B.date,J,R)},[j]),ce=f.useCallback(B=>J=>{const R=Number(J.target.value),V=i.setMonth(i.startOfMonth(B),R);ne(V)},[i,ne]),$t=f.useCallback(B=>J=>{const R=Number(J.target.value),V=i.setYear(i.startOfMonth(B),R);ne(V)},[i,ne]),{className:ms,style:mi}=f.useMemo(()=>({className:[c[O.Root],t.className].filter(Boolean).join(" "),style:{...k?.[O.Root],...t.style}}),[c,t.className,t.style,k]),fi=Fx(t),fr=f.useRef(null);ih(fr,!!t.animate,{classNames:c,months:A,focused:Dt,dateLib:i});const xi={dayPickerProps:t,selected:mt,select:ut,isSelected:kt,months:A,nextMonth:ue,previousMonth:xe,goToMonth:ne,getModifiers:wt,components:r,classNames:c,styles:k,labels:a,formatters:o};return D.createElement(Ma.Provider,{value:xi},D.createElement(r.Root,{rootRef:t.animate?fr:void 0,className:ms,style:mi,dir:t.dir,id:t.id,lang:t.lang??l.code,nonce:t.nonce,title:t.title,role:t.role,"aria-label":t["aria-label"],"aria-labelledby":t["aria-labelledby"],...fi},D.createElement(r.Months,{className:c[O.Months],style:k?.[O.Months]},!t.hideNavigation&&!m&&D.createElement(r.Nav,{"data-animated-nav":t.animate?"true":void 0,className:c[O.Nav],style:k?.[O.Nav],"aria-label":Q(),onPreviousClick:xt,onNextClick:Pt,previousMonth:xe,nextMonth:ue}),A.map((B,J)=>D.createElement(r.Month,{"data-animated-month":t.animate?"true":void 0,className:c[O.Month],style:k?.[O.Month],key:J,displayIndex:J,calendarMonth:B},m==="around"&&!t.hideNavigation&&J===0&&D.createElement(r.PreviousMonthButton,{type:"button",className:c[O.PreviousMonthButton],tabIndex:xe?void 0:-1,"aria-disabled":xe?void 0:!0,"aria-label":we(xe),onClick:xt,"data-animated-button":t.animate?"true":void 0},D.createElement(r.Chevron,{disabled:xe?void 0:!0,className:c[O.Chevron],orientation:t.dir==="rtl"?"right":"left"})),D.createElement(r.MonthCaption,{"data-animated-caption":t.animate?"true":void 0,className:c[O.MonthCaption],style:k?.[O.MonthCaption],calendarMonth:B,displayIndex:J},d?.startsWith("dropdown")?D.createElement(r.DropdownNav,{className:c[O.Dropdowns],style:k?.[O.Dropdowns]},(()=>{const R=d==="dropdown"||d==="dropdown-months"?D.createElement(r.MonthsDropdown,{key:"month",className:c[O.MonthsDropdown],"aria-label":W(),classNames:c,components:r,disabled:!!t.disableNavigation,onChange:ce(B.date),options:Jx(B.date,ae,$e,o,i),style:k?.[O.Dropdown],value:i.getMonth(B.date)}):D.createElement("span",{key:"month"},q(B.date,i)),V=d==="dropdown"||d==="dropdown-years"?D.createElement(r.YearsDropdown,{key:"year",className:c[O.YearsDropdown],"aria-label":an(i.options),classNames:c,components:r,disabled:!!t.disableNavigation,onChange:$t(B.date),options:sh(ae,$e,o,i,!!t.reverseYears),style:k?.[O.Dropdown],value:i.getYear(B.date)}):D.createElement("span",{key:"year"},P(B.date,i));return i.getMonthYearOrder()==="year-first"?[V,R]:[R,V]})(),D.createElement("span",{role:"status","aria-live":"polite",style:{border:0,clip:"rect(0 0 0 0)",height:"1px",margin:"-1px",overflow:"hidden",padding:0,position:"absolute",width:"1px",whiteSpace:"nowrap",wordWrap:"normal"}},C(B.date,i.options,i))):D.createElement(r.CaptionLabel,{className:c[O.CaptionLabel],role:"status","aria-live":"polite"},C(B.date,i.options,i))),m==="around"&&!t.hideNavigation&&J===h-1&&D.createElement(r.NextMonthButton,{type:"button",className:c[O.NextMonthButton],tabIndex:ue?void 0:-1,"aria-disabled":ue?void 0:!0,"aria-label":Se(ue),onClick:Pt,"data-animated-button":t.animate?"true":void 0},D.createElement(r.Chevron,{disabled:ue?void 0:!0,className:c[O.Chevron],orientation:t.dir==="rtl"?"left":"right"})),J===h-1&&m==="after"&&!t.hideNavigation&&D.createElement(r.Nav,{"data-animated-nav":t.animate?"true":void 0,className:c[O.Nav],style:k?.[O.Nav],"aria-label":Q(),onPreviousClick:xt,onNextClick:Pt,previousMonth:xe,nextMonth:ue}),D.createElement(r.MonthGrid,{role:"grid","aria-multiselectable":u==="multiple"||u==="range","aria-label":M(B.date,i.options,i)||void 0,className:c[O.MonthGrid],style:k?.[O.MonthGrid]},!t.hideWeekdays&&D.createElement(r.Weekdays,{"data-animated-weekdays":t.animate?"true":void 0,className:c[O.Weekdays],style:k?.[O.Weekdays]},v&&D.createElement(r.WeekNumberHeader,{"aria-label":Fs(i.options),className:c[O.WeekNumberHeader],style:k?.[O.WeekNumberHeader],scope:"col"},E()),ln.map(R=>D.createElement(r.Weekday,{"aria-label":Ot(R,i.options,i),className:c[O.Weekday],key:String(R),style:k?.[O.Weekday],scope:"col"},L(R,i.options,i)))),D.createElement(r.Weeks,{"data-animated-weeks":t.animate?"true":void 0,className:c[O.Weeks],style:k?.[O.Weeks]},B.weeks.map(R=>D.createElement(r.Week,{className:c[O.Week],key:R.weekNumber,style:k?.[O.Week],week:R},v&&D.createElement(r.WeekNumber,{week:R,style:k?.[O.WeekNumber],"aria-label":on(R.weekNumber,{locale:l}),className:c[O.WeekNumber],scope:"row",role:"rowheader"},H(R.weekNumber,i)),R.days.map(V=>{const{date:ze}=V,K=wt(V);if(K[ie.focused]=!K.hidden&&!!Dt?.isEqualTo(V),K[Ke.selected]=kt?.(ze)||K.selected,Zs(mt)){const{from:dn,to:un}=mt;K[Ke.range_start]=!!(dn&&un&&i.isSameDay(ze,dn)),K[Ke.range_end]=!!(dn&&un&&i.isSameDay(ze,un)),K[Ke.range_middle]=ht(mt,ze,!0,i)}const hi=eh(K,k,t.modifiersStyles),pi=Rx(K,c,t.modifiersClassNames),gi=!cs&&!K.hidden?Et(ze,K,i.options,i):void 0;return D.createElement(r.Day,{key:`${V.isoDate}_${V.displayMonthId}`,day:V,modifiers:K,className:pi.join(" "),style:hi,role:"gridcell","aria-selected":K.selected||void 0,"aria-label":gi,"data-day":V.isoDate,"data-month":V.outside?V.dateMonthId:void 0,"data-selected":K.selected||void 0,"data-disabled":K.disabled||void 0,"data-hidden":K.hidden||void 0,"data-outside":V.outside||void 0,"data-focused":K.focused||void 0,"data-today":K.today||void 0},!K.hidden&&cs?D.createElement(r.DayButton,{className:c[O.DayButton],style:k?.[O.DayButton],type:"button",day:V,modifiers:K,disabled:!K.focused&&K.disabled||void 0,"aria-disabled":K.focused&&K.disabled||void 0,tabIndex:Nt(V)?0:-1,"aria-label":je(ze,K,i.options,i),onClick:ds(V,K),onBlur:cn(V,K),onFocus:Ws(V,K),onKeyDown:us(V,K),onMouseEnter:S(V,K),onMouseLeave:Z(V,K)},z(ze,i.options,i)):!K.hidden&&z(V.date,i.options,i))})))))))),t.footer&&D.createElement(r.Footer,{className:c[O.Footer],style:k?.[O.Footer],role:"status","aria-live":"polite"},t.footer)))}function Mh({className:e,classNames:t,showOutsideDays:n=!0,captionLayout:r="label",buttonVariant:o="ghost",locale:a,formatters:i,components:l,...c}){const d=nr();return s.jsx(Th,{showOutsideDays:n,className:T("group/calendar bg-background p-2 [--cell-radius:var(--radius-md)] [--cell-size:--spacing(7)] in-data-[slot=card-content]:bg-transparent in-data-[slot=popover-content]:bg-transparent",String.raw`rtl:**:[.rdp-button\_next>svg]:rotate-180`,String.raw`rtl:**:[.rdp-button\_previous>svg]:rotate-180`,e),captionLayout:r,locale:a,formatters:{formatMonthDropdown:u=>u.toLocaleString(a?.code,{month:"short"}),...i},classNames:{root:T("w-fit",d.root),months:T("relative flex flex-col gap-4 md:flex-row",d.months),month:T("flex w-full flex-col gap-4",d.month),nav:T("absolute inset-x-0 top-0 flex w-full items-center justify-between gap-1",d.nav),button_previous:T(Us({variant:o}),"size-(--cell-size) p-0 select-none aria-disabled:opacity-50",d.button_previous),button_next:T(Us({variant:o}),"size-(--cell-size) p-0 select-none aria-disabled:opacity-50",d.button_next),month_caption:T("flex h-(--cell-size) w-full items-center justify-center px-(--cell-size)",d.month_caption),dropdowns:T("flex h-(--cell-size) w-full items-center justify-center gap-1.5 text-sm font-medium",d.dropdowns),dropdown_root:T("relative rounded-(--cell-radius)",d.dropdown_root),dropdown:T("absolute inset-0 bg-popover opacity-0",d.dropdown),caption_label:T("font-medium select-none",r==="label"?"text-sm":"flex items-center gap-1 rounded-(--cell-radius) text-sm [&>svg]:size-3.5 [&>svg]:text-muted-foreground",d.caption_label),table:"w-full border-collapse",weekdays:T("flex",d.weekdays),weekday:T("flex-1 rounded-(--cell-radius) text-[0.8rem] font-normal text-muted-foreground select-none",d.weekday),week:T("mt-2 flex w-full",d.week),week_number_header:T("w-(--cell-size) select-none",d.week_number_header),week_number:T("text-[0.8rem] text-muted-foreground select-none",d.week_number),day:T("group/day relative aspect-square h-full w-full rounded-(--cell-radius) p-0 text-center select-none [&:last-child[data-selected=true]_button]:rounded-r-(--cell-radius)",c.showWeekNumber?"[&:nth-child(2)[data-selected=true]_button]:rounded-l-(--cell-radius)":"[&:first-child[data-selected=true]_button]:rounded-l-(--cell-radius)",d.day),range_start:T("relative isolate z-0 rounded-l-(--cell-radius) bg-muted after:absolute after:inset-y-0 after:right-0 after:w-4 after:bg-muted",d.range_start),range_middle:T("rounded-none",d.range_middle),range_end:T("relative isolate z-0 rounded-r-(--cell-radius) bg-muted after:absolute after:inset-y-0 after:left-0 after:w-4 after:bg-muted",d.range_end),today:T("rounded-(--cell-radius) bg-muted text-foreground data-[selected=true]:rounded-none",d.today),outside:T("text-muted-foreground aria-selected:text-muted-foreground",d.outside),disabled:T("text-muted-foreground opacity-50",d.disabled),hidden:T("invisible",d.hidden),...t},components:{Root:({className:u,rootRef:m,...h})=>s.jsx("div",{"data-slot":"calendar",ref:m,className:T(u),...h}),Chevron:({className:u,orientation:m,...h})=>m==="left"?s.jsx(Li,{className:T("size-4",u),...h}):m==="right"?s.jsx(Es,{className:T("size-4",u),...h}):s.jsx(Xe,{className:T("size-4",u),...h}),DayButton:({...u})=>s.jsx(Dh,{locale:a,...u}),WeekNumber:({children:u,...m})=>s.jsx("td",{...m,children:s.jsx("div",{className:"flex size-(--cell-size) items-center justify-center text-center",children:u})}),...l},...c})}function Dh({className:e,day:t,modifiers:n,locale:r,...o}){const a=nr(),i=f.useRef(null);return f.useEffect(()=>{n.focused&&i.current?.focus()},[n.focused]),s.jsx(Y,{variant:"ghost",size:"icon","data-day":t.date.toLocaleDateString(r?.code),"data-selected-single":n.selected&&!n.range_start&&!n.range_end&&!n.range_middle,"data-range-start":n.range_start,"data-range-end":n.range_end,"data-range-middle":n.range_middle,className:T("relative isolate z-10 flex aspect-square size-auto w-full min-w-(--cell-size) flex-col gap-1 border-0 leading-none font-normal group-data-[focused=true]/day:relative group-data-[focused=true]/day:z-10 group-data-[focused=true]/day:border-ring group-data-[focused=true]/day:ring-[3px] group-data-[focused=true]/day:ring-ring/50 data-[range-end=true]:rounded-(--cell-radius) data-[range-end=true]:rounded-r-(--cell-radius) data-[range-end=true]:bg-primary data-[range-end=true]:text-primary-foreground data-[range-middle=true]:rounded-none data-[range-middle=true]:bg-muted data-[range-middle=true]:text-foreground data-[range-start=true]:rounded-(--cell-radius) data-[range-start=true]:rounded-l-(--cell-radius) data-[range-start=true]:bg-primary data-[range-start=true]:text-primary-foreground data-[selected-single=true]:bg-primary data-[selected-single=true]:text-primary-foreground dark:hover:text-foreground [&>span]:text-xs [&>span]:opacity-70",a.day,e),...o})}function en({...e}){return s.jsx(vl,{"data-slot":"popover",...e})}function tn({...e}){return s.jsx(jl,{"data-slot":"popover-trigger",...e})}function sn({className:e,align:t="center",alignOffset:n=0,side:r="bottom",sideOffset:o=4,...a}){return s.jsx(wl,{children:s.jsx(kl,{align:t,alignOffset:n,side:r,sideOffset:o,className:"isolate z-50",children:s.jsx(Nl,{"data-slot":"popover-content",className:T("z-50 flex w-72 origin-(--transform-origin) flex-col gap-2.5 rounded-lg bg-popover p-2.5 text-sm text-popover-foreground shadow-md ring-1 ring-foreground/10 outline-hidden duration-100 data-[side=bottom]:slide-in-from-top-2 data-[side=inline-end]:slide-in-from-left-2 data-[side=inline-start]:slide-in-from-right-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95",e),...a})})})}function Hr({value:e,min:t,max:n,label:r,onChange:o}){const a=c=>(c-t+(n-t+1))%(n-t+1)+t;function i(c){c.key==="ArrowUp"&&(c.preventDefault(),o(a(e+1))),c.key==="ArrowDown"&&(c.preventDefault(),o(a(e-1)))}function l(c){const d=c.target.value.replace(/\D/g,""),u=Math.min(n,Math.max(t,parseInt(d)||0));o(u)}return s.jsx("input",{type:"text",inputMode:"numeric",value:String(e).padStart(2,"0"),onChange:l,onKeyDown:i,"aria-label":r,className:"h-9 w-12 rounded-md border border-(--color-border) bg-(--color-surface-2) text-center text-sm tabular-nums text-(--color-text) focus:outline-none focus:ring-1 focus:ring-(--color-accent)"})}function Ya({value:e,onChange:t,placeholder:n="Pick date & time",className:r,disabled:o}){const[a,i]=f.useState(!1),l=x=>i(x),c=f.useMemo(()=>{if(!e)return;const x=Vm(e,"yyyy-MM-dd'T'HH:mm",new Date);return Xo(x)?x:void 0},[e]),d=c?.getHours()??0,u=c?.getMinutes()??0;function m(x,y,j){if(!x){t("");return}const w=new Date(x);w.setHours(y,j,0,0),t(Qe(w,"yyyy-MM-dd'T'HH:mm"))}function h(x){m(x,d,u)}function g(x){m(c,x,u)}function p(x){m(c,d,x)}const b=c?Qe(c,"dd/MM/yyyy HH:mm"):n;return s.jsx("div",{className:T("flex items-center",r),children:s.jsxs(en,{open:a,onOpenChange:l,children:[s.jsxs(tn,{disabled:o,className:T(Us({variant:"outline"}),"h-9 w-full justify-start gap-2 rounded-lg border border-(--color-border) bg-(--color-surface-2) px-3 text-sm font-normal text-(--color-text) hover:bg-(--color-surface-3)",!c&&"text-(--color-text-muted)"),children:[s.jsx(Ii,{className:"size-4 shrink-0 opacity-60"}),s.jsx("span",{children:b})]}),s.jsxs(sn,{className:"w-auto p-0",align:"start",children:[s.jsx(Mh,{mode:"single",selected:c,onSelect:h,disabled:x=>x<new Date(new Date().setHours(0,0,0,0)),initialFocus:!0}),s.jsxs("div",{className:"flex items-center justify-between gap-4 border-t border-(--color-border) px-4 py-3",children:[s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsx("span",{className:"mr-2 text-xs font-medium text-(--color-text-muted)",children:"Time"}),s.jsx(Hr,{value:d,min:0,max:23,label:"Hours",onChange:g}),s.jsx("span",{className:"mb-0.5 self-center px-0.5 text-base font-semibold text-(--color-text-muted)",children:":"}),s.jsx(Hr,{value:u,min:0,max:59,label:"Minutes",onChange:p})]}),s.jsx("button",{type:"button",onClick:()=>i(!1),className:"rounded-md bg-(--color-accent) px-3 py-1.5 text-xs font-medium text-white transition-opacity hover:opacity-90",children:"Done"})]})]})]})})}function oe({className:e,type:t,...n}){return s.jsx(Sl,{type:t,"data-slot":"input",className:T("h-8 w-full min-w-0 rounded-lg border border-input bg-transparent px-2.5 py-1 text-base transition-colors outline-none file:inline-flex file:h-6 file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 disabled:pointer-events-none disabled:cursor-not-allowed disabled:bg-input/50 disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 md:text-sm dark:bg-input/30 dark:disabled:bg-input/80 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40",e),...n})}function Ht({className:e,...t}){return s.jsx("textarea",{"data-slot":"textarea",className:T("flex field-sizing-content min-h-16 w-full rounded-lg border border-input bg-transparent px-2.5 py-2 text-base transition-colors outline-none placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 disabled:cursor-not-allowed disabled:bg-input/50 disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 md:text-sm dark:bg-input/30 dark:disabled:bg-input/80 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40",e),...t})}const Ss=Cl;function _h({className:e,...t}){return s.jsx(Wl,{"data-slot":"select-group",className:T("scroll-my-1 p-1",e),...t})}function Cs({className:e,...t}){return s.jsx(Dl,{"data-slot":"select-value",className:T("flex flex-1 text-left",e),...t})}function Ts({className:e,size:t="default",children:n,...r}){return s.jsxs(Tl,{"data-slot":"select-trigger","data-size":t,className:T("flex w-fit items-center justify-between gap-1.5 rounded-lg border border-input bg-transparent py-2 pr-2 pl-2.5 text-sm whitespace-nowrap transition-colors outline-none select-none focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 data-placeholder:text-muted-foreground data-[size=default]:h-8 data-[size=sm]:h-7 data-[size=sm]:rounded-[min(var(--radius-md),10px)] *:data-[slot=select-value]:line-clamp-1 *:data-[slot=select-value]:flex *:data-[slot=select-value]:items-center *:data-[slot=select-value]:gap-1.5 dark:bg-input/30 dark:hover:bg-input/50 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",e),...r,children:[n,s.jsx(Ml,{render:s.jsx(Xe,{className:"pointer-events-none size-4 text-muted-foreground"})})]})}function Ms({className:e,children:t,side:n="bottom",sideOffset:r=4,align:o="center",alignOffset:a=0,alignItemWithTrigger:i=!0,...l}){return s.jsx(_l,{children:s.jsx(El,{side:n,sideOffset:r,align:o,alignOffset:a,alignItemWithTrigger:i,className:"isolate z-50",children:s.jsxs(Ol,{"data-slot":"select-content","data-align-trigger":i,className:T("relative isolate z-50 max-h-(--available-height) w-(--anchor-width) min-w-36 origin-(--transform-origin) overflow-x-hidden overflow-y-auto rounded-lg bg-popover text-popover-foreground shadow-md ring-1 ring-foreground/10 duration-100 data-[align-trigger=true]:animate-none data-[side=bottom]:slide-in-from-top-2 data-[side=inline-end]:slide-in-from-left-2 data-[side=inline-start]:slide-in-from-right-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95",e),...l,children:[s.jsx(Oh,{}),s.jsx(Pl,{children:t}),s.jsx(Ph,{})]})})})}function Eh({className:e,...t}){return s.jsx(Ll,{"data-slot":"select-label",className:T("px-1.5 py-1 text-xs text-muted-foreground",e),...t})}function ts({className:e,children:t,...n}){return s.jsxs($l,{"data-slot":"select-item",className:T("relative flex w-full cursor-default items-center gap-1.5 rounded-md py-1 pr-8 pl-1.5 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground not-data-[variant=destructive]:focus:**:text-accent-foreground data-disabled:pointer-events-none data-disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 *:[span]:last:flex *:[span]:last:items-center *:[span]:last:gap-2",e),...n,children:[s.jsx(zl,{className:"flex flex-1 shrink-0 gap-2 whitespace-nowrap",children:t}),s.jsx(Rl,{render:s.jsx("span",{className:"pointer-events-none absolute right-2 flex size-4 items-center justify-center"}),children:s.jsx(vt,{className:"pointer-events-none"})})]})}function Oh({className:e,...t}){return s.jsx(Al,{"data-slot":"select-scroll-up-button",className:T("top-0 z-10 flex w-full cursor-default items-center justify-center bg-popover py-1 [&_svg:not([class*='size-'])]:size-4",e),...t,children:s.jsx(Gs,{})})}function Ph({className:e,...t}){return s.jsx(Fl,{"data-slot":"select-scroll-down-button",className:T("bottom-0 z-10 flex w-full cursor-default items-center justify-center bg-popover py-1 [&_svg:not([class*='size-'])]:size-4",e),...t,children:s.jsx(Xe,{})})}function nn({className:e,orientation:t="horizontal",...n}){return s.jsx(Il,{"data-slot":"tabs","data-orientation":t,className:T("group/tabs flex gap-2 data-horizontal:flex-col",e),...n})}const $h=vo("group/tabs-list inline-flex w-fit items-center justify-center rounded-lg p-[3px] text-muted-foreground group-data-horizontal/tabs:h-8 group-data-vertical/tabs:h-fit group-data-vertical/tabs:flex-col data-[variant=line]:rounded-none",{variants:{variant:{default:"bg-muted",line:"gap-1 bg-transparent"}},defaultVariants:{variant:"default"}});function rn({className:e,variant:t="default",...n}){return s.jsx(Bl,{"data-slot":"tabs-list","data-variant":t,className:T($h({variant:t}),e),...n})}function lt({className:e,...t}){return s.jsx(Yl,{"data-slot":"tabs-trigger",className:T("relative inline-flex h-[calc(100%-1px)] flex-1 items-center justify-center gap-1.5 rounded-md border border-transparent px-1.5 py-0.5 text-sm font-medium whitespace-nowrap text-foreground/60 transition-all group-data-vertical/tabs:w-full group-data-vertical/tabs:justify-start hover:text-foreground focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 focus-visible:outline-1 focus-visible:outline-ring disabled:pointer-events-none disabled:opacity-50 has-data-[icon=inline-end]:pr-1 has-data-[icon=inline-start]:pl-1 aria-disabled:pointer-events-none aria-disabled:opacity-50 dark:text-muted-foreground dark:hover:text-foreground group-data-[variant=default]/tabs-list:data-active:shadow-sm group-data-[variant=line]/tabs-list:data-active:shadow-none [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4","group-data-[variant=line]/tabs-list:bg-transparent group-data-[variant=line]/tabs-list:data-active:bg-transparent dark:group-data-[variant=line]/tabs-list:data-active:border-transparent dark:group-data-[variant=line]/tabs-list:data-active:bg-transparent","data-active:bg-background data-active:text-foreground dark:data-active:border-input dark:data-active:bg-input/30 dark:data-active:text-foreground","after:absolute after:bg-foreground after:opacity-0 after:transition-opacity group-data-horizontal/tabs:after:inset-x-0 group-data-horizontal/tabs:after:bottom-[-5px] group-data-horizontal/tabs:after:h-0.5 group-data-vertical/tabs:after:inset-y-0 group-data-vertical/tabs:after:-right-1 group-data-vertical/tabs:after:w-0.5 group-data-[variant=line]/tabs-list:data-active:after:opacity-100",e),...t})}function qa(e){if(e.schedule_type==="at"&&e.at_datetime)return`at ${Qe(new Date(e.at_datetime),"dd/MM/yyyy HH:mm")}`;if(e.schedule_type==="every"&&e.every_seconds){const t=Math.floor(e.every_seconds/60),n=e.every_seconds%60;return t>0&&n===0?`every ${t}m`:t===0?`every ${n}s`:`every ${t}m ${n}s`}return e.schedule_type==="cron"&&e.cron_expression?`cron: ${e.cron_expression}`:"unknown schedule"}function zh({open:e,onClose:t}){const n=Ye(),[r,o]=f.useState(null),[a,i]=f.useState(""),[l,c]=f.useState("list"),d=Wf(),u=Bn(),m=d.data?.tasks??[],h=u.data?.agents??[],g=m.filter(v=>v.name.toLowerCase().includes(a.toLowerCase())||v.agent.toLowerCase().includes(a.toLowerCase())),p=r?m.find(v=>v.id===r):null,b=v=>{o(v),n&&c("detail")},x=()=>{o(null),n&&c("list")},y=()=>{n&&c("create")},j=()=>{c("list")},w=!n||l==="list",N=!n||l==="detail"||l==="create";return s.jsx(be,{children:e&&s.jsxs(s.Fragment,{children:[s.jsx(se.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},transition:{duration:.15},onClick:t,className:"fixed inset-0 z-40 bg-black/40"}),s.jsxs(se.div,{initial:{x:"100%",opacity:0},animate:{x:0,opacity:1},exit:{x:"100%",opacity:0},transition:{duration:.22,ease:[.4,0,.2,1]},className:"fixed inset-y-0 right-0 z-50 flex w-[min(960px,90vw)] flex-col overflow-hidden bg-(--color-surface) shadow-2xl",children:[s.jsxs("header",{className:"flex items-center justify-between border-b border-(--color-border) px-4 py-3",children:[s.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-2",children:[n&&l!=="list"&&s.jsx("button",{onClick:j,className:"flex h-7 w-7 shrink-0 items-center justify-center rounded-md text-(--color-text-muted) transition-colors hover:bg-(--color-accent-subtle) hover:text-(--color-text)","aria-label":"Back to task list",children:s.jsx(Be,{size:14})}),s.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[s.jsx(To,{size:18,className:"shrink-0 text-(--color-accent)"}),s.jsxs("div",{className:"min-w-0",children:[s.jsx("h2",{className:"text-sm font-semibold text-(--color-text)",children:n&&l==="detail"&&p?p.name:n&&l==="create"?"Create Task":"Scheduled Tasks"}),(!n||l==="list")&&s.jsx("p",{className:"text-xs text-(--color-text-subtle)",children:"Manage cron and scheduled agent tasks"})]})]})]}),s.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[n&&l==="list"&&s.jsx(Y,{variant:"ghost",size:"icon-sm",onClick:y,"aria-label":"Create new task",title:"Create task",children:s.jsx(ct,{size:16})}),s.jsx(Y,{variant:"ghost",size:"icon-sm",onClick:t,"aria-label":"Close scheduler panel",children:s.jsx(Ee,{size:16})})]})]}),s.jsxs("div",{className:"flex flex-1 overflow-hidden",children:[w&&s.jsxs("div",{className:`flex flex-col border-r border-(--color-border) ${n?"w-full":"w-96 shrink-0"}`,children:[s.jsx("div",{className:"border-b border-(--color-border) p-3",children:s.jsx(oe,{placeholder:"Search tasks…",value:a,onChange:v=>i(v.target.value)})}),s.jsx("div",{className:"flex-1 overflow-y-auto",children:d.isLoading?s.jsx("div",{className:"flex items-center justify-center p-8",children:s.jsx(_e,{size:20,className:"animate-spin text-(--color-text-muted)"})}):d.isError?s.jsxs("div",{className:"flex flex-col items-center justify-center gap-2 p-8 text-center",children:[s.jsx(Ie,{size:20,className:"text-(--color-error)"}),s.jsx("p",{className:"text-sm text-(--color-text-muted)",children:"Failed to load tasks"})]}):g.length===0?s.jsxs("div",{className:"flex flex-col items-center justify-center gap-2 p-8 text-center",children:[s.jsx(Mo,{size:20,className:"text-(--color-text-muted)"}),s.jsx("p",{className:"text-sm text-(--color-text-muted)",children:a?"No tasks match your search":"No scheduled tasks yet"}),!a&&!n&&s.jsx("p",{className:"text-xs text-(--color-text-subtle)",children:"Use the form on the right to create one."})]}):s.jsx("div",{className:"space-y-1 p-2",children:g.map(v=>s.jsx(Rh,{task:v,isSelected:r===v.id,onSelect:()=>b(v.id)},v.id))})})]}),N&&s.jsx("div",{className:"flex flex-1 flex-col overflow-hidden",children:p&&(!n||l==="detail")?s.jsx(Fh,{task:p,agents:h,onClose:x}):s.jsx(Ah,{agents:h,onSuccess:x})})]})]})]})})}function Rh({task:e,isSelected:t,onSelect:n}){const r=Bf(),o=Yf(),a=qf(),i=Hf(),l={pending:"text-(--color-text-muted)",running:"text-(--color-accent)",paused:"text-(--color-warning)",completed:"text-(--color-success)",failed:"text-(--color-error)"}[e.status]??"text-(--color-text-muted)";return s.jsx("button",{onClick:n,className:`w-full rounded-lg border px-3 py-2 text-left transition-colors ${t?"border-(--color-accent) bg-(--color-accent-subtle)":"border-(--color-border) bg-(--color-surface-2) hover:border-(--color-border-strong)"}`,children:s.jsxs("div",{className:"flex items-start justify-between gap-2",children:[s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsx("p",{className:"truncate text-sm font-medium text-(--color-text)",children:e.name}),s.jsx("p",{className:"mt-0.5 truncate text-xs text-(--color-text-muted)",children:qa(e)}),s.jsxs("div",{className:"mt-1 flex items-center gap-2",children:[s.jsx("span",{className:"inline-block rounded-full bg-(--color-accent-subtle) px-2 py-0.5 text-xs text-(--color-accent)",children:e.agent}),s.jsx("span",{className:`text-xs font-medium ${l}`,children:e.status})]}),e.last_error&&s.jsx("p",{className:"mt-1 truncate text-xs text-(--color-error)",children:e.last_error}),e.next_fire_at&&s.jsxs("p",{className:"mt-1 text-xs text-(--color-text-muted)",children:["Next: ",Zt(e.next_fire_at)]})]}),s.jsxs("div",{className:"flex shrink-0 gap-1",children:[s.jsx(Y,{variant:"ghost",size:"icon-sm",onClick:c=>{c.stopPropagation(),i.mutate(e.id)},disabled:i.isPending,title:"Trigger now",children:i.isPending?s.jsx(_e,{size:14,className:"animate-spin"}):s.jsx(Bi,{size:14})}),s.jsx(Y,{variant:"ghost",size:"icon-sm",onClick:c=>{c.stopPropagation(),e.status==="paused"?a.mutate(e.id):o.mutate(e.id)},disabled:o.isPending||a.isPending,title:e.status==="paused"?"Resume":"Pause",children:o.isPending||a.isPending?s.jsx(_e,{size:14,className:"animate-spin"}):e.status==="paused"?s.jsx(Do,{size:14}):s.jsx(Yi,{size:14})}),s.jsx(Y,{variant:"ghost",size:"icon-sm",onClick:c=>{c.stopPropagation(),confirm(`Delete task "${e.name}"?`)&&r.mutate(e.id)},disabled:r.isPending,title:"Delete",className:"hover:bg-(--color-error-subtle) hover:text-(--color-error)",children:r.isPending?s.jsx(_e,{size:14,className:"animate-spin"}):s.jsx(Os,{size:14})})]})]})})}function Ah({agents:e,onSuccess:t}){const n=Intl.DateTimeFormat().resolvedOptions().timeZone,[r,o]=f.useState({name:"",agent:e[0]?.name??"",schedule_type:"every",every_seconds:3600,timezone:n,prompt:"",enabled:!0}),[a,i]=f.useState(null),l=Lf(),c=async d=>{if(d.preventDefault(),i(null),!r.name.trim()){i("Task name is required");return}if(!r.agent){i("Agent is required");return}if(!r.prompt.trim()){i("Prompt is required");return}if(r.schedule_type==="at"&&!r.at_datetime){i('Date/time is required for "at" schedule');return}if(r.schedule_type==="every"&&(!r.every_seconds||r.every_seconds<=0)){i("Interval must be greater than 0");return}if(r.schedule_type==="cron"&&!r.cron_expression?.trim()){i("Cron expression is required");return}const u={name:r.name.trim(),agent:r.agent,schedule_type:r.schedule_type,timezone:r.timezone,prompt:r.prompt.trim(),session_id:r.session_id,enabled:r.enabled,...r.schedule_type==="at"?{at_datetime:r.at_datetime}:{},...r.schedule_type==="every"?{every_seconds:r.every_seconds}:{},...r.schedule_type==="cron"?{cron_expression:r.cron_expression}:{}};l.mutate(u,{onSuccess:()=>{o({name:"",agent:e[0]?.name??"",schedule_type:"every",every_seconds:3600,timezone:n,prompt:"",enabled:!0}),t()},onError:m=>{i(m instanceof Error?m.message:"Failed to create task")}})};return s.jsxs("div",{className:"flex flex-col overflow-hidden",children:[s.jsx("div",{className:"border-b border-(--color-border) px-6 py-4",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(ct,{size:18,className:"text-(--color-accent)"}),s.jsx("h2",{className:"text-lg font-semibold text-(--color-text)",children:"Create Task"})]})}),s.jsxs("form",{onSubmit:c,className:"flex flex-1 flex-col overflow-y-auto p-6",children:[s.jsxs("div",{className:"space-y-4",children:[s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm font-medium text-(--color-text)",children:"Task Name"}),s.jsx(oe,{className:"mt-1",value:r.name,onChange:d=>o({...r,name:d.target.value}),placeholder:"e.g., Daily Report"})]}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm font-medium text-(--color-text)",children:"Agent"}),s.jsxs(Ss,{value:r.agent??"",onValueChange:d=>{d&&o({...r,agent:d})},children:[s.jsx(Ts,{className:"mt-1 w-full",children:s.jsx(Cs,{placeholder:"Select agent"})}),s.jsx(Ms,{children:e.map(d=>s.jsx(ts,{value:d.name,children:d.name},d.name))})]})]}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm font-medium text-(--color-text)",children:"Schedule Type"}),s.jsx(nn,{value:r.schedule_type,onValueChange:d=>o({...r,schedule_type:d}),className:"mt-2",children:s.jsxs(rn,{className:"w-full",children:[s.jsx(lt,{value:"every",className:"flex-1",children:"Every"}),s.jsx(lt,{value:"cron",className:"flex-1",children:"Cron"}),s.jsx(lt,{value:"at",className:"flex-1",children:"At"})]})})]}),r.schedule_type==="at"&&s.jsxs("div",{children:[s.jsxs("div",{className:"flex items-end gap-2",children:[s.jsxs("div",{className:"flex-1",children:[s.jsx("label",{className:"block text-sm font-medium text-(--color-text)",children:"Date & Time"}),s.jsx("div",{className:"mt-1",children:s.jsx(Ya,{value:r.at_datetime??"",onChange:d=>o({...r,at_datetime:d})})})]}),s.jsxs("div",{className:"w-44 shrink-0",children:[s.jsx("label",{className:"block text-sm font-medium text-(--color-text)",children:"Timezone"}),s.jsx(oe,{className:"mt-1",value:r.timezone,onChange:d=>o({...r,timezone:d.target.value}),placeholder:n})]})]}),s.jsx("p",{className:"mt-1 text-xs text-(--color-text-muted)",children:"IANA timezone (e.g., America/New_York)"})]}),r.schedule_type==="every"&&s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm font-medium text-(--color-text)",children:"Interval (seconds)"}),s.jsx(oe,{className:"mt-1",type:"number",min:"1",value:r.every_seconds??3600,onChange:d=>o({...r,every_seconds:parseInt(d.target.value)||0})}),s.jsx("p",{className:"mt-1 text-xs text-(--color-text-muted)",children:"e.g., 3600 = 1 hour, 86400 = 1 day"})]}),r.schedule_type==="cron"&&s.jsxs("div",{children:[s.jsxs("div",{className:"flex items-end gap-2",children:[s.jsxs("div",{className:"flex-1",children:[s.jsx("label",{className:"block text-sm font-medium text-(--color-text)",children:"Cron Expression"}),s.jsx(oe,{className:"mt-1",value:r.cron_expression??"",onChange:d=>o({...r,cron_expression:d.target.value}),placeholder:"e.g., 0 9 * * MON-FRI"})]}),s.jsxs("div",{className:"w-44 shrink-0",children:[s.jsx("label",{className:"block text-sm font-medium text-(--color-text)",children:"Timezone"}),s.jsx(oe,{className:"mt-1",value:r.timezone,onChange:d=>o({...r,timezone:d.target.value}),placeholder:n})]})]}),s.jsx("p",{className:"mt-1 text-xs text-(--color-text-muted)",children:"IANA timezone (e.g., America/New_York)"})]}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm font-medium text-(--color-text)",children:"Prompt"}),s.jsx(Ht,{className:"mt-1",value:r.prompt,onChange:d=>o({...r,prompt:d.target.value}),placeholder:"What should the agent do?",rows:4})]}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm font-medium text-(--color-text)",children:"Session ID (optional)"}),s.jsx(oe,{className:"mt-1",value:r.session_id??"",onChange:d=>o({...r,session_id:d.target.value||null}),placeholder:"Leave blank for new session, or enter 'auto'"}),s.jsx("p",{className:"mt-1 text-xs text-(--color-text-muted)",children:'null = new session each run, "auto" = persistent session, or UUID'})]}),a&&s.jsxs("div",{className:"flex gap-2 rounded-lg border border-(--color-error) bg-(--color-error-subtle) p-3",children:[s.jsx(Ie,{size:16,className:"shrink-0 text-(--color-error)"}),s.jsx("p",{className:"text-sm text-(--color-error)",children:a})]})]}),s.jsx(Y,{type:"submit",disabled:l.isPending,className:"mt-6 w-full",children:l.isPending?s.jsxs(s.Fragment,{children:[s.jsx(_e,{size:14,className:"animate-spin"}),"Creating…"]}):s.jsxs(s.Fragment,{children:[s.jsx(ct,{size:14}),"Create Task"]})})]})]})}function Fh({task:e,agents:t,onClose:n}){const[r,o]=f.useState(!1);if(r)return s.jsx(Wh,{task:e,agents:t,onSuccess:()=>o(!1),onCancel:()=>o(!1)});const a={pending:"text-(--color-text-muted)",running:"text-(--color-accent)",paused:"text-(--color-warning)",completed:"text-(--color-success)",failed:"text-(--color-error)"}[e.status]??"text-(--color-text-muted)";return s.jsxs("div",{className:"flex flex-col overflow-hidden",children:[s.jsx("div",{className:"border-b border-(--color-border) px-6 py-4",children:s.jsxs("div",{className:"flex items-start justify-between gap-4",children:[s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsx("h2",{className:"truncate text-lg font-semibold text-(--color-text)",children:e.name}),s.jsx("p",{className:"mt-1 text-sm text-(--color-text-muted)",children:qa(e)})]}),s.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[s.jsx(Y,{variant:"ghost",size:"icon-sm",onClick:()=>o(!0),title:"Edit task",children:s.jsx(_o,{size:16})}),s.jsx(Y,{variant:"ghost",size:"icon-sm",onClick:n,title:"Close",children:s.jsx(Ee,{size:16})})]})]})}),s.jsx("div",{className:"flex-1 overflow-y-auto p-6",children:s.jsxs("div",{className:"space-y-6",children:[s.jsxs("div",{children:[s.jsx("h3",{className:"text-sm font-semibold text-(--color-text)",children:"Status"}),s.jsxs("div",{className:"mt-2 space-y-2",children:[s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsx("span",{className:"text-sm text-(--color-text-muted)",children:"Current"}),s.jsx("span",{className:`text-sm font-medium ${a}`,children:e.status})]}),s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsx("span",{className:"text-sm text-(--color-text-muted)",children:"Enabled"}),s.jsx("span",{className:"text-sm text-(--color-text)",children:e.enabled?"Yes":"No"})]}),s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsx("span",{className:"text-sm text-(--color-text-muted)",children:"Run Count"}),s.jsx("span",{className:"text-sm text-(--color-text)",children:e.run_count})]})]})]}),s.jsxs("div",{children:[s.jsx("h3",{className:"text-sm font-semibold text-(--color-text)",children:"Schedule"}),s.jsxs("div",{className:"mt-2 space-y-2",children:[s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsx("span",{className:"text-sm text-(--color-text-muted)",children:"Type"}),s.jsx("span",{className:"text-sm text-(--color-text) capitalize",children:e.schedule_type})]}),e.schedule_type==="at"&&e.at_datetime&&s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsx("span",{className:"text-sm text-(--color-text-muted)",children:"Date/Time"}),s.jsx("span",{className:"text-sm text-(--color-text)",children:Qe(new Date(e.at_datetime),"dd/MM/yyyy HH:mm")})]}),e.schedule_type==="every"&&e.every_seconds&&s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsx("span",{className:"text-sm text-(--color-text-muted)",children:"Interval"}),s.jsxs("span",{className:"text-sm text-(--color-text)",children:[e.every_seconds,"s"]})]}),e.schedule_type==="cron"&&e.cron_expression&&s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsx("span",{className:"text-sm text-(--color-text-muted)",children:"Expression"}),s.jsx("span",{className:"text-sm text-(--color-text)",children:e.cron_expression})]}),s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsx("span",{className:"text-sm text-(--color-text-muted)",children:"Timezone"}),s.jsx("span",{className:"text-sm text-(--color-text)",children:e.timezone})]})]})]}),s.jsxs("div",{children:[s.jsx("h3",{className:"text-sm font-semibold text-(--color-text)",children:"Configuration"}),s.jsxs("div",{className:"mt-2 space-y-2",children:[s.jsxs("div",{children:[s.jsx("span",{className:"text-sm text-(--color-text-muted)",children:"Agent"}),s.jsx("p",{className:"mt-1 rounded-lg bg-(--color-surface-2) px-3 py-2 text-sm text-(--color-text)",children:e.agent})]}),s.jsxs("div",{children:[s.jsx("span",{className:"text-sm text-(--color-text-muted)",children:"Prompt"}),s.jsx("p",{className:"mt-1 rounded-lg bg-(--color-surface-2) px-3 py-2 text-sm text-(--color-text) whitespace-pre-wrap",children:e.prompt})]}),e.session_id&&s.jsxs("div",{children:[s.jsx("span",{className:"text-sm text-(--color-text-muted)",children:"Session ID"}),s.jsx("p",{className:"mt-1 rounded-lg bg-(--color-surface-2) px-3 py-2 text-sm text-(--color-text) break-all font-mono",children:e.session_id})]})]})]}),s.jsxs("div",{children:[s.jsx("h3",{className:"text-sm font-semibold text-(--color-text)",children:"Run History"}),s.jsxs("div",{className:"mt-2 space-y-2",children:[e.last_run_at&&s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsx("span",{className:"text-sm text-(--color-text-muted)",children:"Last Run"}),s.jsx("span",{className:"text-sm text-(--color-text)",children:Zt(e.last_run_at)})]}),e.next_fire_at&&s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsx("span",{className:"text-sm text-(--color-text-muted)",children:"Next Fire"}),s.jsx("span",{className:"text-sm text-(--color-text)",children:Zt(e.next_fire_at)})]}),e.last_error&&s.jsxs("div",{children:[s.jsx("span",{className:"text-sm text-(--color-text-muted)",children:"Last Error"}),s.jsx("p",{className:"mt-1 rounded-lg bg-(--color-error-subtle) px-3 py-2 text-sm text-(--color-error) whitespace-pre-wrap",children:e.last_error})]})]})]}),s.jsx("div",{className:"border-t border-(--color-border) pt-4",children:s.jsxs("div",{className:"space-y-2 text-xs text-(--color-text-muted)",children:[s.jsxs("div",{children:["Created: ",Zt(e.created_at)]}),s.jsxs("div",{children:["Updated: ",Zt(e.updated_at)]})]})})]})})]})}function Wh({task:e,agents:t,onSuccess:n,onCancel:r}){const o=Intl.DateTimeFormat().resolvedOptions().timeZone,[a,i]=f.useState({name:e.name,agent:e.agent,schedule_type:e.schedule_type,at_datetime:e.at_datetime??void 0,every_seconds:e.every_seconds??void 0,cron_expression:e.cron_expression??void 0,timezone:e.timezone,prompt:e.prompt,session_id:e.session_id??void 0,enabled:e.enabled}),[l,c]=f.useState(null),d=If(),u=async m=>{if(m.preventDefault(),c(null),!a.agent){c("Agent is required");return}if(!a.prompt.trim()){c("Prompt is required");return}if(a.schedule_type==="at"&&!a.at_datetime){c('Date/time is required for "at" schedule');return}if(a.schedule_type==="every"&&(!a.every_seconds||a.every_seconds<=0)){c("Interval must be greater than 0");return}if(a.schedule_type==="cron"&&!a.cron_expression?.trim()){c("Cron expression is required");return}const h={agent:a.agent,schedule_type:a.schedule_type,timezone:a.timezone,prompt:a.prompt.trim(),session_id:a.session_id,enabled:a.enabled,...a.schedule_type==="at"?{at_datetime:a.at_datetime}:{},...a.schedule_type==="every"?{every_seconds:a.every_seconds}:{},...a.schedule_type==="cron"?{cron_expression:a.cron_expression}:{}};d.mutate({id:e.id,body:h},{onSuccess:n,onError:g=>{c(g instanceof Error?g.message:"Failed to update task")}})};return s.jsxs("div",{className:"flex flex-col overflow-hidden",children:[s.jsxs("div",{className:"border-b border-(--color-border) px-6 py-4",children:[s.jsxs("div",{className:"flex items-center justify-between gap-4",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(_o,{size:18,className:"text-(--color-accent)"}),s.jsx("h2",{className:"text-lg font-semibold text-(--color-text)",children:"Edit Task"})]}),s.jsx(Y,{variant:"ghost",size:"icon-sm",onClick:r,title:"Cancel",children:s.jsx(Ee,{size:16})})]}),s.jsx("p",{className:"mt-1 text-sm text-(--color-text-muted)",children:e.name})]}),s.jsxs("form",{onSubmit:u,className:"flex flex-1 flex-col overflow-y-auto p-6",children:[s.jsxs("div",{className:"space-y-4",children:[s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm font-medium text-(--color-text)",children:"Agent"}),s.jsxs(Ss,{value:a.agent??"",onValueChange:m=>{m&&i({...a,agent:m})},children:[s.jsx(Ts,{className:"mt-1 w-full",children:s.jsx(Cs,{placeholder:"Select agent"})}),s.jsx(Ms,{children:t.map(m=>s.jsx(ts,{value:m.name,children:m.name},m.name))})]})]}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm font-medium text-(--color-text)",children:"Schedule Type"}),s.jsx(nn,{value:a.schedule_type,onValueChange:m=>i({...a,schedule_type:m}),className:"mt-2",children:s.jsxs(rn,{className:"w-full",children:[s.jsx(lt,{value:"every",className:"flex-1",children:"Every"}),s.jsx(lt,{value:"cron",className:"flex-1",children:"Cron"}),s.jsx(lt,{value:"at",className:"flex-1",children:"At"})]})})]}),a.schedule_type==="at"&&s.jsxs("div",{children:[s.jsxs("div",{className:"flex items-end gap-2",children:[s.jsxs("div",{className:"flex-1",children:[s.jsx("label",{className:"block text-sm font-medium text-(--color-text)",children:"Date & Time"}),s.jsx("div",{className:"mt-1",children:s.jsx(Ya,{value:a.at_datetime??"",onChange:m=>i({...a,at_datetime:m})})})]}),s.jsxs("div",{className:"w-44 shrink-0",children:[s.jsx("label",{className:"block text-sm font-medium text-(--color-text)",children:"Timezone"}),s.jsx(oe,{className:"mt-1",value:a.timezone,onChange:m=>i({...a,timezone:m.target.value}),placeholder:o})]})]}),s.jsx("p",{className:"mt-1 text-xs text-(--color-text-muted)",children:"IANA timezone (e.g., America/New_York)"})]}),a.schedule_type==="every"&&s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm font-medium text-(--color-text)",children:"Interval (seconds)"}),s.jsx(oe,{className:"mt-1",type:"number",min:"1",value:a.every_seconds??3600,onChange:m=>i({...a,every_seconds:parseInt(m.target.value)||0})}),s.jsx("p",{className:"mt-1 text-xs text-(--color-text-muted)",children:"e.g., 3600 = 1 hour, 86400 = 1 day"})]}),a.schedule_type==="cron"&&s.jsxs("div",{children:[s.jsxs("div",{className:"flex items-end gap-2",children:[s.jsxs("div",{className:"flex-1",children:[s.jsx("label",{className:"block text-sm font-medium text-(--color-text)",children:"Cron Expression"}),s.jsx(oe,{className:"mt-1",value:a.cron_expression??"",onChange:m=>i({...a,cron_expression:m.target.value}),placeholder:"e.g., 0 9 * * MON-FRI"})]}),s.jsxs("div",{className:"w-44 shrink-0",children:[s.jsx("label",{className:"block text-sm font-medium text-(--color-text)",children:"Timezone"}),s.jsx(oe,{className:"mt-1",value:a.timezone,onChange:m=>i({...a,timezone:m.target.value}),placeholder:o})]})]}),s.jsx("p",{className:"mt-1 text-xs text-(--color-text-muted)",children:"IANA timezone (e.g., America/New_York)"})]}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm font-medium text-(--color-text)",children:"Prompt"}),s.jsx(Ht,{className:"mt-1",value:a.prompt,onChange:m=>i({...a,prompt:m.target.value}),placeholder:"What should the agent do?",rows:4})]}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm font-medium text-(--color-text)",children:"Session ID (optional)"}),s.jsx(oe,{className:"mt-1",value:a.session_id??"",onChange:m=>i({...a,session_id:m.target.value||void 0}),placeholder:"Leave blank for new session, or enter 'auto'"}),s.jsx("p",{className:"mt-1 text-xs text-(--color-text-muted)",children:'null = new session each run, "auto" = persistent session, or UUID'})]}),l&&s.jsxs("div",{className:"flex gap-2 rounded-lg border border-(--color-error) bg-(--color-error-subtle) p-3",children:[s.jsx(Ie,{size:16,className:"shrink-0 text-(--color-error)"}),s.jsx("p",{className:"text-sm text-(--color-error)",children:l})]})]}),s.jsxs("div",{className:"mt-6 flex gap-2",children:[s.jsx(Y,{type:"button",variant:"outline",className:"flex-1",onClick:r,disabled:d.isPending,children:"Cancel"}),s.jsx(Y,{type:"submit",disabled:d.isPending,className:"flex-1",children:d.isPending?s.jsxs(s.Fragment,{children:[s.jsx(_e,{size:14,className:"animate-spin"}),"Saving…"]}):"Save Changes"})]})]})]})}const ar="oa-theme",Ha="(prefers-color-scheme: dark)";function Lh(e){return e==="light"||e==="dark"||e==="system"}function vs(){try{const e=localStorage.getItem(ar);if(Lh(e))return e}catch{}return"system"}function js(e){return e==="system"?typeof window<"u"&&window.matchMedia(Ha).matches?"dark":"light":e}function $n(e){const t=document.documentElement;t.classList.toggle("dark",e==="dark"),t.classList.toggle("light",e==="light")}function Ih(e){try{localStorage.setItem(ar,e)}catch{}$n(js(e))}function Bh(){const e=vs();if($n(js(e)),typeof window>"u"||!window.matchMedia)return()=>{};const t=window.matchMedia(Ha),n=()=>{vs()==="system"&&$n(t.matches?"dark":"light")};return t.addEventListener("change",n),()=>t.removeEventListener("change",n)}const jn="oa-theme-change",Yh="(prefers-color-scheme: dark)";function qh(){const[e,t]=f.useState(()=>vs()),[n,r]=f.useState(()=>js(vs()));f.useEffect(()=>{const a=()=>{const c=vs();t(c),r(js(c))},i=c=>{c.key===ar&&a()},l=()=>a();return window.addEventListener("storage",i),window.addEventListener(jn,l),()=>{window.removeEventListener("storage",i),window.removeEventListener(jn,l)}},[]),f.useEffect(()=>{if(e!=="system"||typeof window>"u"||!window.matchMedia)return;const a=window.matchMedia(Yh),i=()=>r(a.matches?"dark":"light");return a.addEventListener("change",i),()=>a.removeEventListener("change",i)},[e]);const o=f.useCallback(a=>{Ih(a),t(a),r(js(a)),window.dispatchEvent(new CustomEvent(jn))},[]);return{preference:e,resolved:n,setPreference:o}}const wn=[{value:"system",label:"System",Icon:qi},{value:"light",label:"Light",Icon:Hi},{value:"dark",label:"Dark",Icon:Ps}],Hh={system:"light",light:"dark",dark:"system"};function Uh({collapsed:e=!1}){const{preference:t,setPreference:n}=qh();if(e){const r=wn.find(a=>a.value===t)??wn[0],o=r.Icon;return s.jsx("button",{type:"button",onClick:()=>n(Hh[t]),title:`Theme: ${r.label} (click to cycle)`,"aria-label":`Theme: ${r.label}. Click to cycle.`,className:"interactive-weight flex h-8 w-8 items-center justify-center rounded-md text-(--color-text-muted) transition-colors hover:bg-(--color-accent-subtle) hover:text-(--color-text)",children:s.jsx(o,{size:14})})}return s.jsx("div",{role:"radiogroup","aria-label":"Theme preference",className:"flex items-center gap-0.5 rounded-lg border border-(--color-border) bg-(--color-bg) p-0.5",children:wn.map(({value:r,label:o,Icon:a})=>{const i=t===r;return s.jsxs("button",{type:"button",role:"radio","aria-checked":i,onClick:()=>n(r),title:o,className:`interactive-weight flex flex-1 items-center justify-center gap-1.5 rounded-md px-2 py-1 text-xs transition-colors ${i?"bg-(--color-accent-subtle) text-(--color-text)":"text-(--color-text-muted) hover:text-(--color-text)"}`,children:[s.jsx(a,{size:12}),s.jsx("span",{children:o})]},r)})})}function Qh(){const e=Fo();let t="bg-(--color-text-muted)",n="animate-pulse";return e.isSuccess?(t="bg-(--color-success)",n=""):e.isError&&(t="bg-(--color-error)",n=""),s.jsx("div",{className:`h-1.5 w-1.5 rounded-full ${t} ${n}`,title:e.isSuccess?"Connected":e.isError?"Backend error":"Connecting…","aria-label":e.isSuccess?"Connected":e.isError?"Backend error":"Connecting…"})}function Kh({...e}){return s.jsx(ql,{"data-slot":"dialog",...e})}function Gh({...e}){return s.jsx(Kl,{"data-slot":"dialog-portal",...e})}function Vh({className:e,...t}){return s.jsx(Gl,{"data-slot":"dialog-overlay",className:T("fixed inset-0 isolate z-50 bg-black/10 duration-100 supports-backdrop-filter:backdrop-blur-xs data-open:animate-in data-open:fade-in-0 data-closed:animate-out data-closed:fade-out-0",e),...t})}function Xh({className:e,children:t,showCloseButton:n=!0,...r}){return s.jsxs(Gh,{children:[s.jsx(Vh,{}),s.jsxs(Hl,{"data-slot":"dialog-content",className:T("fixed top-1/2 left-1/2 z-50 grid w-full max-w-[calc(100%-2rem)] -translate-x-1/2 -translate-y-1/2 gap-4 rounded-xl bg-popover p-4 text-sm text-popover-foreground ring-1 ring-foreground/10 duration-100 outline-none sm:max-w-sm data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95",e),...r,children:[t,n&&s.jsxs(zo,{"data-slot":"dialog-close",render:s.jsx(Y,{variant:"ghost",className:"absolute top-2 right-2",size:"icon-sm"}),children:[s.jsx(Ee,{}),s.jsx("span",{className:"sr-only",children:"Close"})]})]})]})}function Zh({className:e,...t}){return s.jsx("div",{"data-slot":"dialog-header",className:T("flex flex-col gap-2",e),...t})}function Jh({className:e,showCloseButton:t=!1,children:n,...r}){return s.jsxs("div",{"data-slot":"dialog-footer",className:T("-mx-4 -mb-4 flex flex-col-reverse gap-2 rounded-b-xl border-t bg-muted/50 p-4 sm:flex-row sm:justify-end",e),...r,children:[n,t&&s.jsx(zo,{render:s.jsx(Y,{variant:"outline"}),children:"Close"})]})}function ep({className:e,...t}){return s.jsx(Ul,{"data-slot":"dialog-title",className:T("font-heading text-base leading-none font-medium",e),...t})}function tp({className:e,...t}){return s.jsx(Ql,{"data-slot":"dialog-description",className:T("text-sm text-muted-foreground *:[a]:underline *:[a]:underline-offset-3 *:[a]:hover:text-foreground",e),...t})}function sp(e){const t=[],n=[],r=[];for(const a of e){const i=a.created_at?new Date(a.created_at):null;if(!i){r.push(a);continue}ca(i)?t.push(a):da(i)?n.push(a):r.push(a)}const o=[];return t.length&&o.push({label:"Today",sessions:t}),n.length&&o.push({label:"Yesterday",sessions:n}),r.length&&o.push({label:"Older",sessions:r}),o}const Ur="oa-sidebar-collapsed";function np({currentSessionId:e,onCommandPalette:t,onNewChat:n,mobileOpen:r=!1,onMobileClose:o}){const a=Ye(),i=Ve(),l=vf(),c=jf(),d=f.useRef(null),u=f.useRef(null),m=ha(d),h=l.data?.pages.flatMap(_=>_.data)??[],[g,p]=f.useState(()=>{try{return localStorage.getItem(Ur)==="true"}catch{return!1}}),[b,x]=f.useState(!1),[y,j]=f.useState(!1),[w,N]=f.useState(null),v=f.useCallback(()=>{p(_=>{const A=!_;try{localStorage.setItem(Ur,String(A))}catch{}return A})},[]),k=l.refetch;f.useEffect(()=>{const _=A=>{!A.ctrlKey||A.metaKey||(A.key==="b"&&(A.preventDefault(),v()),A.key==="r"&&(A.preventDefault(),k()),A.key==="m"&&(A.preventDefault(),x(ae=>!ae)),A.key==="s"&&(A.preventDefault(),j(ae=>!ae)))};return window.addEventListener("keydown",_),()=>window.removeEventListener("keydown",_)},[v,k]);const{hasNextPage:C,isFetchingNextPage:z,fetchNextPage:q}=l;f.useEffect(()=>{const _=u.current;if(!_)return;const A=new IntersectionObserver(ae=>{ae[0].isIntersecting&&C&&!z&&q()},{root:d.current,threshold:.1});return A.observe(_),()=>A.disconnect()},[C,z,q]);const H=(_,A)=>{_.stopPropagation(),N(A)},E=()=>{w&&(c.mutate(w.id),w.id===e&&i({to:"/cockpit"}),N(null))},L=_=>{i({to:"/cockpit/$sessionId",params:{sessionId:_}}),o?.()},P=()=>{n?n():i({to:"/cockpit"}),o?.()},I=g?56:256;return s.jsxs(s.Fragment,{children:[s.jsx(be,{children:a&&r&&s.jsx(se.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},transition:{duration:.2},className:"fixed inset-0 z-30 bg-black/60 md:hidden","aria-hidden":"true",onClick:o},"sidebar-backdrop")}),s.jsxs(se.aside,{animate:a?{x:r?0:-280}:{width:I},transition:{duration:.22,ease:[.4,0,.2,1]},className:a?"fixed inset-y-0 left-0 z-40 flex w-[272px] shrink-0 flex-col overflow-hidden bg-(--color-surface) shadow-xl":"relative flex shrink-0 flex-col overflow-hidden bg-(--color-surface)",style:a?void 0:{minWidth:I},children:[(()=>{const _=!a&&g;return s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"flex h-14 items-center justify-between px-3",children:[s.jsxs("button",{onClick:()=>i({to:"/"}),className:"flex items-center gap-2.5 overflow-hidden rounded-md p-1 -ml-1 transition-colors hover:bg-(--color-accent-subtle)",title:"Home",children:[s.jsx("div",{className:"flex h-8 w-8 shrink-0 items-center justify-center rounded-lg bg-(--color-accent-subtle) ring-1 ring-(--color-border-strong)",children:s.jsx(In,{width:18,height:18,className:"text-(--color-accent)"})}),s.jsx(be,{children:!_&&s.jsx(se.div,{initial:{opacity:0,x:-8},animate:{opacity:1,x:0},exit:{opacity:0,x:-8},transition:{duration:.15},className:"flex items-center gap-1.5 overflow-hidden",children:s.jsx("span",{className:"whitespace-nowrap text-sm font-semibold text-(--color-text)",children:"OpenAgentd"})})})]}),a?s.jsx("button",{onClick:o,className:"flex h-7 w-7 shrink-0 items-center justify-center rounded-md text-(--color-text-muted) transition-colors hover:bg-(--color-accent-subtle) hover:text-(--color-text-2)","aria-label":"Close sidebar",children:s.jsx(yr,{size:15})}):s.jsx("button",{onClick:v,className:"flex h-7 w-7 shrink-0 items-center justify-center rounded-md text-(--color-text-muted) transition-colors hover:bg-(--color-accent-subtle) hover:text-(--color-text-2)","aria-label":g?"Expand sidebar":"Collapse sidebar",title:g?"Expand sidebar (Ctrl+B)":"Collapse sidebar (Ctrl+B)",children:g?s.jsx(Ui,{size:15}):s.jsx(yr,{size:15})})]}),s.jsxs("div",{className:"px-2 pb-2 space-y-0.5",children:[s.jsxs("button",{onClick:P,title:"New Chat (Ctrl+N)",className:`interactive-weight flex w-full items-center gap-2 rounded-lg px-3 py-2 text-sm transition-all text-(--color-text-2) hover:bg-(--color-accent-subtle) hover:text-(--color-text) ${_?"justify-center":""}`,children:[s.jsx(ct,{size:16,className:"shrink-0"}),s.jsx(be,{children:!_&&s.jsx(se.span,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},transition:{duration:.12},className:"whitespace-nowrap flex-1 text-left",children:"New Chat"})}),!_&&s.jsx("kbd",{className:"shrink-0 rounded border border-(--color-border) bg-(--color-bg) px-1 py-0.5 font-mono text-xs text-(--color-text-subtle)",children:"^N"})]}),t&&s.jsxs("button",{onClick:t,title:"Commands (Ctrl+P)",className:`interactive-weight flex w-full items-center gap-2 rounded-lg px-3 py-2 text-sm transition-all text-(--color-text-subtle) hover:bg-(--color-accent-subtle) hover:text-(--color-text-muted) ${_?"justify-center":""}`,children:[s.jsx(_s,{size:15,className:"shrink-0"}),s.jsx(be,{children:!_&&s.jsx(se.span,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},transition:{duration:.12},className:"whitespace-nowrap flex-1 text-left",children:"Commands"})}),!_&&s.jsx("kbd",{className:"shrink-0 rounded border border-(--color-border) bg-(--color-bg) px-1 py-0.5 font-mono text-xs text-(--color-text-subtle)",children:"^P"})]}),s.jsxs("button",{onClick:()=>x(!0),title:"Wiki (Ctrl+M)",className:`interactive-weight flex w-full items-center gap-2 rounded-lg px-3 py-2 text-sm transition-all text-(--color-text-subtle) hover:bg-(--color-accent-subtle) hover:text-(--color-text-muted) ${_?"justify-center":""}`,children:[s.jsx(Qi,{size:15,className:"shrink-0"}),s.jsx(be,{children:!_&&s.jsx(se.span,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},transition:{duration:.12},className:"whitespace-nowrap flex-1 text-left",children:"Wiki"})}),!_&&s.jsx("kbd",{className:"shrink-0 rounded border border-(--color-border) bg-(--color-bg) px-1 py-0.5 font-mono text-xs text-(--color-text-subtle)",children:"^M"})]}),s.jsxs("button",{onClick:()=>j(!0),title:"Scheduled Tasks (Ctrl+S)",className:`interactive-weight flex w-full items-center gap-2 rounded-lg px-3 py-2 text-sm transition-all text-(--color-text-subtle) hover:bg-(--color-accent-subtle) hover:text-(--color-text-muted) ${_?"justify-center":""}`,children:[s.jsx(To,{size:15,className:"shrink-0"}),s.jsx(be,{children:!_&&s.jsx(se.span,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},transition:{duration:.12},className:"whitespace-nowrap flex-1 text-left",children:"Scheduled Tasks"})}),!_&&s.jsx("kbd",{className:"shrink-0 rounded border border-(--color-border) bg-(--color-bg) px-1 py-0.5 font-mono text-xs text-(--color-text-subtle)",children:"^S"})]}),s.jsxs("button",{onClick:()=>{i({to:"/settings"}),o?.()},title:"Settings",className:`interactive-weight flex w-full items-center gap-2 rounded-lg px-3 py-2 text-sm transition-all text-(--color-text-subtle) hover:bg-(--color-accent-subtle) hover:text-(--color-text-muted) ${_?"justify-center":""}`,children:[s.jsx(Wn,{size:15,className:"shrink-0"}),s.jsx(be,{children:!_&&s.jsx(se.span,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},transition:{duration:.12},className:"whitespace-nowrap flex-1 text-left",children:"Settings"})})]})]}),s.jsx(be,{children:!_&&s.jsxs(se.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},transition:{duration:.15},className:"flex min-h-0 flex-1 flex-col overflow-hidden",children:[s.jsxs("div",{className:"flex items-center justify-between px-3 pb-1 pt-1",children:[s.jsx("span",{className:"text-xs font-medium uppercase tracking-wider text-(--color-text-subtle)",children:"Recent"}),s.jsx("button",{onClick:()=>k(),className:"rounded p-1 text-(--color-text-subtle) transition-colors hover:bg-(--color-accent-subtle) hover:text-(--color-text-muted)","aria-label":"Refresh sessions",title:"Refresh sessions (Ctrl+R)",children:s.jsx(Eo,{size:12,className:l.isFetching?"animate-spin":""})})]}),s.jsxs("div",{ref:d,className:"flex-1 overflow-y-auto px-2 pb-2",children:[l.isLoading&&s.jsx("div",{className:"space-y-1 px-1 py-2",children:[...Array(6)].map((A,ae)=>s.jsx("div",{className:"h-8 animate-pulse rounded-md bg-(--color-accent-dim)"},ae))}),l.isError&&s.jsx("p",{className:"px-3 py-4 text-center text-xs text-(--color-error)",children:"Failed to load sessions"}),l.isSuccess&&h.length===0&&s.jsx("p",{className:"px-3 py-4 text-center text-xs text-(--color-text-subtle)",children:"No sessions yet"}),l.isSuccess&&h.length>0&&s.jsxs("div",{className:"space-y-0.5",children:[sp(h).map(({label:A,sessions:ae})=>s.jsxs("div",{children:[s.jsx("p",{className:"px-2 pb-0.5 pt-2 text-xs text-(--color-text-subtle) first:pt-1",children:A}),ae.map($e=>s.jsx(rp,{session:$e,isActive:$e.id===e,mouseY:m,onSelect:L,onDelete:(xe,ue)=>H(xe,ue)},$e.id))]},A)),s.jsx("div",{ref:u,className:"h-1","aria-hidden":!0}),z&&s.jsx("div",{className:"space-y-1 px-1 pt-1",children:[...Array(3)].map((A,ae)=>s.jsx("div",{className:"h-8 animate-pulse rounded-md bg-(--color-accent-dim)"},ae))})]})]})]})}),_&&s.jsx("div",{className:"flex flex-1 flex-col items-center gap-1 overflow-y-auto py-2",children:l.isSuccess&&h.slice(0,8).map(A=>{const ae=A.id===e;return s.jsx("button",{onClick:()=>L(A.id),title:A.title||"Untitled",className:`flex h-8 w-8 items-center justify-center rounded-md transition-colors ${ae?"bg-(--color-accent-dim) text-(--color-accent)":"text-(--color-text-subtle) hover:bg-(--color-accent-subtle) hover:text-(--color-text-2)"}`,children:s.jsx("div",{className:"h-1.5 w-1.5 rounded-full bg-current"})},A.id)})}),s.jsxs("div",{className:`flex items-center border-t border-(--color-border) px-3 py-2 pb-safe ${_?"justify-center":"justify-between"}`,children:[s.jsx(Uh,{collapsed:_}),!_&&s.jsx(Qh,{})]})]})})(),s.jsx(Xf,{open:b,onClose:()=>x(!1)}),s.jsx(zh,{open:y,onClose:()=>j(!1)}),s.jsx(Kh,{open:w!==null,onOpenChange:_=>{_||N(null)},children:s.jsxs(Xh,{showCloseButton:!1,children:[s.jsxs(Zh,{children:[s.jsx(ep,{children:"Delete session"}),s.jsxs(tp,{children:["“",w?.title||"Untitled","” will be permanently deleted. This cannot be undone."]})]}),s.jsxs(Jh,{children:[s.jsx(Y,{variant:"outline",onClick:()=>N(null),children:"Cancel"}),s.jsx(Y,{variant:"destructive",onClick:E,children:"Delete"})]})]})})]})]})}function rp({session:e,isActive:t,mouseY:n,onSelect:r,onDelete:o}){const{ref:a,intensity:i}=pa(n),l=!t&&i>0,c=!!e.scheduled_task_name;return s.jsxs("div",{ref:a,className:"group relative isolate",children:[l&&s.jsx("div",{"aria-hidden":!0,className:"pointer-events-none absolute inset-0 -z-10 rounded-md",style:{backgroundColor:`color-mix(in srgb, var(--color-accent-dim) ${i*100}%, transparent)`}}),s.jsx("button",{onClick:()=>r(e.id),className:`flex w-full items-start gap-2 rounded-md px-2.5 py-2 text-left transition-colors ${t?"bg-(--color-accent-dim) text-(--color-text)":"hover:bg-(--color-accent-dim) text-(--color-text-2)"}`,children:s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx(be,{mode:"wait",initial:!1,children:s.jsx(se.p,{initial:{opacity:0,y:-6},animate:{opacity:1,y:0},exit:{opacity:0,y:6},transition:{duration:.18,ease:"easeOut"},className:`min-w-0 truncate text-xs ${t?"font-medium text-(--color-text)":"text-(--color-text-2)"}`,children:e.title||"Untitled"},e.title??"untitled")}),c&&s.jsx("span",{className:"shrink-0 rounded px-1 py-px text-[10px] leading-tight bg-(--color-accent-subtle) text-(--color-text-subtle)",children:"sched"})]}),c&&s.jsx("p",{className:"mt-0.5 truncate text-xs text-(--color-text-subtle)",children:e.scheduled_task_name}),s.jsx("p",{className:"mt-0.5 truncate text-xs text-(--color-text-subtle)",children:Zt(e.created_at)})]})}),s.jsx("button",{onClick:d=>o(d,e),className:"absolute right-1.5 top-1/2 -translate-y-1/2 rounded p-1 text-(--color-text-subtle) transition-all hover:bg-(--color-error-subtle) hover:text-(--color-error) opacity-100 md:opacity-0 md:group-hover:opacity-100","aria-label":`Delete session ${e.title||"Untitled"}`,children:s.jsx(Os,{size:12})})]})}function op({commands:e,onClose:t}){const[n,r]=f.useState(""),[o,a]=f.useState(0),i=f.useRef(null),l=f.useRef(null),c=ha(l);f.useEffect(()=>{i.current?.focus()},[]);const d=f.useMemo(()=>n.trim()?e.filter(x=>{const y=n.toLowerCase();return x.label.toLowerCase().includes(y)||x.description?.toLowerCase().includes(y)||x.group?.toLowerCase().includes(y)}):e,[n]),u=f.useRef(n);u.current!==n&&(u.current=n,o!==0&&a(0)),f.useEffect(()=>{l.current?.querySelector(`[data-idx="${o}"]`)?.scrollIntoView({block:"nearest"})},[o]);const m=f.useCallback(x=>{t(),x.action()},[t]),h=x=>{if(x.key==="Escape"){t();return}if(x.key==="ArrowDown"){x.preventDefault(),a(y=>Math.min(y+1,d.length-1));return}if(x.key==="ArrowUp"){x.preventDefault(),a(y=>Math.max(y-1,0));return}if(x.key==="Enter"){x.preventDefault();const y=d[o];y&&m(y);return}},g=new Map;for(const x of d){const y=x.group??"";g.has(y)||g.set(y,[]),g.get(y).push(x)}const p=[];let b=0;for(const[x,y]of g.entries()){x&&p.push({type:"header",label:x});for(const j of y)p.push({type:"cmd",cmd:j,idx:b++})}return s.jsx(be,{children:s.jsx(se.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},transition:{duration:.15},className:"fixed inset-0 z-50 flex items-start justify-center bg-black/60 pt-[15vh] backdrop-blur-sm",onClick:t,children:s.jsxs(se.div,{initial:{opacity:0,scale:.97,y:-8},animate:{opacity:1,scale:1,y:0},exit:{opacity:0,scale:.97,y:-8},transition:{type:"spring",damping:30,stiffness:380},onClick:x=>x.stopPropagation(),className:"flex w-full max-w-md flex-col overflow-hidden rounded-2xl border border-(--color-border) bg-(--color-surface) shadow-2xl",role:"dialog","aria-modal":"true","aria-label":"Command palette",onKeyDown:h,children:[s.jsxs("div",{className:"flex items-center gap-3 border-b border-(--color-border) px-4 py-3",children:[s.jsx(_s,{size:15,className:"shrink-0 text-(--color-text-muted)"}),s.jsx("input",{ref:i,value:n,onChange:x=>r(x.target.value),placeholder:"Search commands…",className:"flex-1 bg-transparent text-sm text-(--color-text) placeholder-(--color-text-muted) outline-none","aria-label":"Search commands"}),n&&s.jsx("button",{onClick:()=>r(""),className:"text-xs text-(--color-text-muted) hover:text-(--color-text-2)",children:"Clear"})]}),s.jsx("div",{ref:l,className:"max-h-80 overflow-y-auto py-1.5",children:d.length===0?s.jsxs("p",{className:"px-4 py-6 text-center text-sm text-(--color-text-muted)",children:['No commands match "',n,'"']}):p.map((x,y)=>{if(x.type==="header")return s.jsx("p",{className:"px-4 pb-1 pt-3 text-xs font-semibold uppercase tracking-widest text-(--color-text-muted)",children:x.label},`h-${y}`);const j=x.idx===o;return s.jsx(ap,{cmd:x.cmd,idx:x.idx,isActive:j,mouseY:c,onRun:m,onActivate:a},x.cmd.id)})}),s.jsxs("div",{className:"flex items-center gap-2 border-t border-(--color-border) px-4 py-2",children:[s.jsx("kbd",{className:"rounded border border-(--color-border) bg-(--color-bg) px-1 py-0.5 font-mono text-[10px] text-(--color-text-muted)",children:"↑↓"}),s.jsx("span",{className:"text-xs text-(--color-text-muted)",children:"navigate"}),s.jsx("kbd",{className:"rounded border border-(--color-border) bg-(--color-bg) px-1 py-0.5 font-mono text-[10px] text-(--color-text-muted)",children:"↵"}),s.jsx("span",{className:"text-xs text-(--color-text-muted)",children:"run"}),s.jsx("kbd",{className:"rounded border border-(--color-border) bg-(--color-bg) px-1 py-0.5 font-mono text-[10px] text-(--color-text-muted)",children:"Esc"}),s.jsx("span",{className:"text-xs text-(--color-text-muted)",children:"close"})]})]},"panel")},"backdrop")})}function ap({cmd:e,idx:t,isActive:n,mouseY:r,onRun:o,onActivate:a}){const{ref:i,intensity:l}=pa(r),c=!n&&l>0;return s.jsxs("div",{ref:i,className:"relative isolate",children:[c&&s.jsx("div",{"aria-hidden":!0,className:"pointer-events-none absolute inset-0 -z-10",style:{backgroundColor:`color-mix(in srgb, var(--color-accent-dim) ${l*100}%, transparent)`}}),s.jsxs("button",{"data-idx":t,onClick:()=>o(e),onMouseEnter:()=>a(t),className:`flex w-full items-center gap-3 px-4 py-2.5 text-left transition-colors ${n?"bg-(--color-accent-subtle) text-(--color-text)":"text-(--color-text-2) hover:bg-(--color-accent-dim)"}`,children:[s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsx("span",{className:"block text-sm font-medium",children:e.label}),e.description&&s.jsx("span",{className:"block truncate text-xs text-(--color-text-muted)",children:e.description})]}),e.shortcut&&s.jsx("kbd",{className:"shrink-0 rounded border border-(--color-border) bg-(--color-bg) px-1.5 py-0.5 font-mono text-xs text-(--color-text-muted)",children:e.shortcut}),n&&s.jsx(Ki,{size:12,className:"shrink-0 text-(--color-text-muted)"})]})]})}const ip=new Set(["txt","md","markdown","rst","json","jsonl","ndjson","yaml","yml","toml","ini","env","csv","tsv","log","py","ts","tsx","js","jsx","mjs","cjs","html","css","scss","sass","sh","bash","zsh","fish","rs","go","java","kt","c","cpp","h","hpp","rb","php","swift","sql","xml","svg"]),lp=new Set(["png","jpg","jpeg","gif","webp","svg","bmp"]);function Ua(e){const t=e.lastIndexOf(".");return t>=0?e.slice(t+1).toLowerCase():""}function Qa(e){const t=Ua(e.name);return lp.has(t)||e.mime.startsWith("image/")?"image":ip.has(t)||e.mime.startsWith("text/")||e.mime==="application/json"?"text":"binary"}function Ka({file:e,size:t=12}){const n=Qa(e),r="shrink-0 text-(--color-text-muted)";if(n==="image")return s.jsx(Gi,{size:t,className:r});if(n==="text"){const o=Ua(e.name);return o&&!["txt","md","markdown","rst","log","csv","tsv"].includes(o)?s.jsx(Vi,{size:t,className:r}):s.jsx(Tt,{size:t,className:r})}return s.jsx(Bs,{size:t,className:r})}function cp(e){const t=new Map;for(const n of e){const r=n.path.lastIndexOf("/"),o=r<0?"":n.path.slice(0,r),a=t.get(o)??[];a.push(n),t.set(o,a)}return Array.from(t.entries()).sort(([n],[r])=>n===""?-1:r===""?1:n.localeCompare(r)).map(([n,r])=>({dir:n,files:r}))}function dp({file:e,selected:t,onSelect:n}){return s.jsxs("button",{onClick:()=>n(e),className:T("group flex w-full items-center gap-1.5 rounded px-2 py-1 text-left text-xs transition-colors",t?"bg-(--color-accent-subtle) text-(--color-accent)":"text-(--color-text-2) hover:bg-(--color-accent-subtle) hover:text-(--color-text)"),title:e.path,children:[s.jsx(Ka,{file:e}),s.jsx("span",{className:"min-w-0 flex-1 truncate font-mono",children:e.name}),s.jsx("span",{className:"shrink-0 text-[10px] text-(--color-text-subtle)",children:Bt(e.size)})]})}function up({group:e,selectedPath:t,onSelect:n}){return s.jsxs("div",{className:"mb-3",children:[s.jsxs("div",{className:"mb-1 flex items-center gap-1.5 px-2 py-0.5 text-[10px] font-semibold uppercase tracking-wider text-(--color-text-subtle)",children:[s.jsx(Co,{size:11}),s.jsx("span",{className:"truncate",children:e.dir||"/"})]}),s.jsx("ul",{className:"space-y-0.5",children:e.files.map(r=>s.jsx("li",{children:s.jsx(dp,{file:r,selected:r.path===t,onSelect:n})},r.path))})]})}function mp({sessionId:e,file:t}){const[n,r]=f.useState(!1),o=$s(e,t.path);return s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"flex h-full items-center justify-center bg-(--color-bg) p-4",children:s.jsx("img",{src:o,alt:t.name,onClick:()=>r(!0),className:"max-h-full max-w-full cursor-zoom-in rounded border border-(--color-border) object-contain"})}),s.jsx(Yn,{src:o,alt:t.name,isOpen:n,onClose:()=>r(!1)})]})}const Qs=512*1024;function fp({sessionId:e,file:t}){const n=t.size>Qs,[r,o]=f.useState(null),[a,i]=f.useState(null),[l,c]=f.useState(!n);return f.useEffect(()=>{if(n)return;let d=!1;return fetch($s(e,t.path)).then(async u=>{if(!u.ok)throw new Error(`HTTP ${u.status}`);return u.text()}).then(u=>{d||(o(u),c(!1))}).catch(u=>{d||(i(u instanceof Error?u.message:String(u)),c(!1))}),()=>{d=!0}},[e,t.path,n]),n?s.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-2 px-6 text-center",children:[s.jsx(Tt,{size:24,className:"text-(--color-text-subtle)"}),s.jsx("p",{className:"text-sm text-(--color-text-2)",children:"File too large to preview"}),s.jsxs("p",{className:"text-xs text-(--color-text-subtle)",children:[Bt(t.size)," — limit is ",Bt(Qs)]})]}):l?s.jsx("div",{className:"flex h-full items-center justify-center text-(--color-text-subtle)",children:s.jsx(_e,{size:16,className:"animate-spin"})}):a?s.jsxs("div",{className:"flex h-full items-center justify-center px-4 text-center text-xs text-(--color-error)",children:["Failed to load: ",a]}):r===null?null:s.jsx("pre",{className:"h-full overflow-auto p-4 font-mono text-xs leading-relaxed text-(--color-text) whitespace-pre",children:r})}function xp({sessionId:e,file:t}){const n=$s(e,t.path);return s.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-3 px-6 text-center",children:[s.jsx(Bs,{size:28,className:"text-(--color-text-subtle)"}),s.jsxs("div",{children:[s.jsx("p",{className:"text-sm text-(--color-text-2)",children:"No inline preview for this file type"}),s.jsxs("p",{className:"mt-0.5 text-xs text-(--color-text-subtle)",children:[t.mime," · ",Bt(t.size)]})]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsxs("a",{href:n,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 rounded-md bg-(--color-accent-subtle) px-3 py-1.5 text-xs text-(--color-accent) transition-colors hover:bg-(--color-accent-dim)",children:[s.jsx(So,{size:12})," Open in new tab"]}),s.jsxs("a",{href:n,download:t.name,className:"flex items-center gap-1.5 rounded-md border border-(--color-border) px-3 py-1.5 text-xs text-(--color-text-2) transition-colors hover:border-(--color-border-strong)",children:[s.jsx(Ln,{size:12})," Download"]})]})]})}function hp({sessionId:e,file:t}){const[n,r]=f.useState(!1),[o,a]=f.useState(!1),i=t.size>Qs,l=async()=>{if(!(o||i)){a(!0);try{const d=await fetch($s(e,t.path));if(!d.ok)throw new Error(`HTTP ${d.status}`);const u=await d.text();await navigator.clipboard.writeText(u),r(!0),window.setTimeout(()=>r(!1),1500)}catch{}finally{a(!1)}}},c=i?`File too large to copy (${Bt(t.size)} > ${Bt(Qs)})`:n?"Copied!":"Copy file contents";return s.jsx("button",{type:"button",onClick:l,disabled:o||i,title:c,"aria-label":c,className:"flex items-center gap-1 rounded px-2 py-1 text-xs text-(--color-text-muted) transition-colors hover:bg-(--color-accent-subtle) hover:text-(--color-text-2) disabled:cursor-not-allowed disabled:opacity-40 disabled:hover:bg-transparent disabled:hover:text-(--color-text-muted)",children:n?s.jsx(vt,{size:12,className:"text-(--color-success)"}):o?s.jsx(_e,{size:12,className:"animate-spin"}):s.jsx(Lt,{size:12})})}function pp({sessionId:e,file:t}){const n=Qa(t);return s.jsxs("div",{className:"flex h-full flex-col",children:[s.jsxs("div",{className:"flex shrink-0 items-center justify-between gap-3 border-b border-(--color-border) px-4 py-2",children:[s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx(Ka,{file:t,size:13}),s.jsx("div",{className:"truncate font-mono text-xs text-(--color-text)",children:t.path})]}),s.jsxs("div",{className:"mt-0.5 text-[10px] text-(--color-text-subtle)",children:[Bt(t.size)," · ",t.mime]})]}),s.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[s.jsx("a",{href:$s(e,t.path),download:t.name,className:"flex items-center gap-1 rounded px-2 py-1 text-xs text-(--color-text-muted) transition-colors hover:bg-(--color-accent-subtle) hover:text-(--color-text-2)",title:"Download",children:s.jsx(Ln,{size:12})}),n==="text"&&s.jsx(hp,{sessionId:e,file:t})]})]}),s.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:n==="image"?s.jsx(mp,{sessionId:e,file:t}):n==="text"?s.jsx(fp,{sessionId:e,file:t}):s.jsx(xp,{sessionId:e,file:t})})]})}function gp({message:e,hint:t}){return s.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-2 px-6 text-center",children:[s.jsx(Tt,{size:24,className:"text-(--color-text-subtle)"}),s.jsx("p",{className:"text-sm text-(--color-text-2)",children:e}),t&&s.jsx("p",{className:"max-w-xs text-xs text-(--color-text-subtle)",children:t})]})}function bp({open:e,sessionId:t,onClose:n}){const r=Ye(),{data:o,isLoading:a,isError:i,refetch:l,isFetching:c}=Mf(t),[d,u]=f.useState(null),[m,h]=f.useState("tree");f.useEffect(()=>{e&&t&&l()},[e,t]),f.useEffect(()=>{if(!e)return;const N=v=>{v.key==="Escape"&&(r&&m==="preview"?h("tree"):n())};return window.addEventListener("keydown",N),()=>window.removeEventListener("keydown",N)},[e,n,r,m]);const g=f.useMemo(()=>o?.files??[],[o]),p=f.useMemo(()=>cp(g),[g]);f.useEffect(()=>{d&&(g.some(N=>N.path===d)||(u(null),h("tree")))},[g,d]);const b=d?g.find(N=>N.path===d)??null:null,x=N=>{u(N.path),r&&h("preview")},y=()=>{h("tree")},j=!r||m==="tree",w=!r||m==="preview";return s.jsx(be,{children:e&&s.jsxs(s.Fragment,{children:[s.jsx(se.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},transition:{duration:.15},onClick:n,className:"fixed inset-0 z-40 bg-black/40"},"backdrop"),s.jsxs(se.aside,{initial:{x:"100%",opacity:0},animate:{x:0,opacity:1},exit:{x:"100%",opacity:0},transition:{duration:.22,ease:[.4,0,.2,1]},className:"fixed inset-y-0 right-0 z-50 flex w-[min(960px,95vw)] flex-col overflow-hidden border-l border-(--color-border) bg-(--color-surface) shadow-2xl",role:"dialog","aria-modal":"true","aria-label":"Workspace files",children:[s.jsxs("header",{className:"flex shrink-0 items-center justify-between gap-3 border-b border-(--color-border) px-4 py-3",children:[s.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-2",children:[r&&m==="preview"&&s.jsx("button",{onClick:y,className:"flex h-7 w-7 shrink-0 items-center justify-center rounded-md text-(--color-text-muted) transition-colors hover:bg-(--color-accent-subtle) hover:text-(--color-text)","aria-label":"Back to file list",children:s.jsx(Be,{size:14})}),s.jsxs("div",{className:"min-w-0",children:[s.jsx("h2",{className:"text-sm font-semibold text-(--color-text)",children:"Workspace"}),s.jsx("p",{className:"truncate text-[11px] text-(--color-text-subtle)",children:r&&m==="preview"&&b?b.name:s.jsxs(s.Fragment,{children:["Files the agent has written into this session",o?.truncated?" · list truncated":""]})})]})]}),s.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[s.jsx("button",{onClick:()=>l(),disabled:!t||c,className:"rounded p-1.5 text-(--color-text-muted) transition-colors hover:bg-(--color-accent-subtle) hover:text-(--color-text) disabled:opacity-50",title:"Refresh","aria-label":"Refresh",children:s.jsx(Eo,{size:14,className:c?"animate-spin":""})}),s.jsx("button",{onClick:n,className:"rounded p-1.5 text-(--color-text-muted) transition-colors hover:bg-(--color-accent-subtle) hover:text-(--color-text)",title:"Close (Esc)","aria-label":"Close",children:s.jsx(Ee,{size:16})})]})]}),s.jsxs("div",{className:"flex min-h-0 flex-1 overflow-hidden",children:[j&&s.jsx("nav",{className:T("overflow-y-auto border-r border-(--color-border) px-2 py-3",r?"w-full":"w-[260px] shrink-0"),children:t?a?s.jsx("div",{className:"px-2 py-6 text-center text-xs text-(--color-text-subtle)",children:s.jsx(_e,{size:14,className:"mx-auto animate-spin"})}):i?s.jsx("p",{className:"px-2 py-4 text-xs text-(--color-error)",children:"Failed to load workspace files"}):p.length===0?s.jsx("p",{className:"px-2 py-4 text-xs italic text-(--color-text-subtle)",children:"No files yet. Anything the agent writes will appear here."}):p.map(N=>s.jsx(up,{group:N,selectedPath:d,onSelect:x},N.dir)):s.jsx("p",{className:"px-2 py-4 text-xs italic text-(--color-text-subtle)",children:"No active session."})}),w&&s.jsx("div",{className:"min-w-0 flex-1",children:b&&t?s.jsx(pp,{sessionId:t,file:b},b.path):s.jsx(gp,{message:"Select a file",hint:"Images, markdown, and code files render inline. Other formats offer download."})})]}),s.jsxs("div",{className:"shrink-0 border-t border-(--color-border) px-4 py-2 text-[11px] text-(--color-text-muted) pb-safe",children:[g.length>0&&s.jsxs("span",{children:[g.length," file",g.length===1?"":"s"," · "]}),r?"Tap a file to preview":"Esc or click outside to close"]})]},"drawer")]})})}function yp(e){return he({queryKey:$.todos(e??""),queryFn:()=>gc(e),enabled:!!e,staleTime:5e3})}function vp(e){const t=f.useRef(e);f.useLayoutEffect(()=>{t.current=e}),f.useEffect(()=>{const n=r=>{if(!r.ctrlKey||r.metaKey)return;const o=t.current[r.key.toLowerCase()];o&&(r.preventDefault(),o())};return window.addEventListener("keydown",n),()=>window.removeEventListener("keydown",n)},[])}function Yt(e){return{type:"leaf",agentName:e}}function Ue(e){return e?e.type==="leaf"?[e.agentName]:[...Ue(e.a),...Ue(e.b)]:[]}function kn(e,t,n,r,o="after"){if(!e)return Yt(n);const a=Yt(n);function i(c){return c.type==="leaf"?c.agentName===t?{type:"split",dir:r,ratio:.5,a:o==="before"?a:c,b:o==="before"?c:a}:c:{...c,a:i(c.a),b:i(c.b)}}const l=i(e);return l===e?{type:"split",dir:r,ratio:.5,a:e,b:a}:l}function zn(e,t){if(!e)return null;if(e.type==="leaf")return e.agentName===t?null:e;const n=zn(e.a,t),r=zn(e.b,t);return n===null&&r===null?null:n===null?r:r===null?n:{...e,a:n,b:r}}function jp(e,t,n){if(!e)return null;const r=new Set(t);function o(a){if(a.type==="leaf")return r.has(a.agentName)?a:n&&r.has(n)?Yt(n):null;const i=o(a.a),l=o(a.b);return!i&&!l?null:i?l?{...a,a:i,b:l}:i:l}return o(e)}function wp(e,t,n){if(!e||t===n)return e;function r(o){return o.type==="leaf"?o.agentName===t?Yt(n):o.agentName===n?Yt(t):o:{...o,a:r(o.a),b:r(o.b)}}return r(e)}function kp(e,t){if(!e)return null;const n=Ue(e),r=n.indexOf(t);return r===-1?n[0]??null:r>0?n[r-1]:r<n.length-1?n[r+1]:null}function Ga(e){return`oa-tile-layout-${e}`}function Np(e,t){try{localStorage.setItem(Ga(e),JSON.stringify(t))}catch{}}function Sp(e){try{const t=localStorage.getItem(Ga(e));return t?JSON.parse(t):null}catch{return null}}function Cp({sessionId:e,leadName:t,agentNames:n}){const[r,o]=f.useState({root:null,focusedAgent:null}),a=f.useRef(null);f.useEffect(()=>{if(a.current===e)return;if(a.current=e,!e){o({root:null,focusedAgent:null});return}const p=Sp(e);o(p||(t?{root:Yt(t),focusedAgent:t}:{root:null,focusedAgent:null}))},[e,t]),f.useEffect(()=>{t&&o(p=>p.root!==null?p:{root:Yt(t),focusedAgent:t})},[t]),f.useEffect(()=>{n.length!==0&&o(p=>{const b=jp(p.root,n,t),x=new Set(Ue(b)),y=p.focusedAgent&&x.has(p.focusedAgent)?p.focusedAgent:Ue(b)[0]??null;return{root:b,focusedAgent:y}})},[n,t]),f.useEffect(()=>{e&&Np(e,r)},[e,r]);const i=f.useCallback((p,b="h")=>{o(x=>Ue(x.root).includes(p)?{...x,focusedAgent:p}:{root:kn(x.root,x.focusedAgent,p,b),focusedAgent:p})},[]),l=f.useCallback((p,b)=>{o(x=>Ue(x.root).includes(b)?{...x,focusedAgent:b}:{root:kn(x.root,p,b,"h","after"),focusedAgent:b})},[]),c=f.useCallback((p,b)=>{o(x=>Ue(x.root).includes(b)?{...x,focusedAgent:b}:{root:kn(x.root,p,b,"v","after"),focusedAgent:b})},[]),d=f.useCallback(p=>{o(b=>{const x=kp(b.root,p),y=zn(b.root,p),j=b.focusedAgent===p?x&&Ue(y).includes(x)?x:Ue(y)[0]??null:b.focusedAgent;return{root:y,focusedAgent:j}})},[]),u=f.useCallback(p=>{o(b=>({...b,focusedAgent:p}))},[]),m=f.useCallback((p,b)=>{o(x=>{const y=wp(x.root,p,b);return{...x,root:y}})},[]),h=f.useCallback((p,b)=>{},[]),g=Ue(r.root);return{root:r.root,focusedAgent:r.focusedAgent,openAgents:g,openAgent:i,splitRight:l,splitDown:c,closeAgent:d,focusAgent:u,swapAgents:m,setRatio:h}}const Tp=500,Qr=f.forwardRef(function({onSubmit:t,onStop:n,onSlashCommand:r,slashCommands:o=[],isStreaming:a=!1,disabled:i,placeholder:l="Message OpenAgentd…",autoFocus:c,capabilities:d,floating:u=!1,filesBelow:m=!1,renderDragHandle:h},g){const[p,b]=f.useState(""),[x,y]=f.useState([]),[j,w]=f.useState(0),N=f.useRef(null),v=f.useRef(null),k=f.useRef(0),C=f.useMemo(()=>{const M=new Map;return x.forEach((W,Q)=>{M.set(Q,URL.createObjectURL(W))}),M},[x]);f.useEffect(()=>()=>{C.forEach(M=>URL.revokeObjectURL(M))},[C]);const z=f.useCallback(()=>{const M=N.current;M&&(M.style.height="auto",M.style.height=`${Math.min(M.scrollHeight,144)}px`)},[]);f.useImperativeHandle(g,()=>({focus:()=>N.current?.focus(),setValue:M=>{b(M),requestAnimationFrame(z)}}));const q=f.useCallback(()=>{const M=p.trim();!M||i||(t(M,x.length>0?x:void 0),b(""),y([]),N.current&&(N.current.style.height="auto"))},[p,i,t,x]),H=f.useCallback(()=>{const M=["text/plain","text/csv","text/tab-separated-values","text/markdown","application/json",".txt",".csv",".tsv",".json",".md"];return d?.input.vision&&M.push("image/*"),d?.input.document_text&&M.push("application/pdf",".pdf","application/vnd.openxmlformats-officedocument.wordprocessingml.document",".docx"),d?.input.audio&&M.push("audio/*"),d?.input.video&&M.push("video/*"),M.join(",")},[d]),E=f.useCallback(M=>{const W=M.type,Q=M.name.toLowerCase();return!!(W.startsWith("text/")||W==="application/json"||Q.endsWith(".txt")||Q.endsWith(".csv")||Q.endsWith(".tsv")||Q.endsWith(".json")||Q.endsWith(".md")||d?.input.vision&&W.startsWith("image/")||d?.input.document_text&&(W==="application/pdf"||W==="application/vnd.openxmlformats-officedocument.wordprocessingml.document"||Q.endsWith(".pdf")||Q.endsWith(".docx"))||d?.input.audio&&W.startsWith("audio/")||d?.input.video&&W.startsWith("video/"))},[d]),L=f.useCallback(M=>{E(M)&&y(W=>[...W,M])},[E]),P=f.useCallback(M=>{const W=C.get(M);W&&URL.revokeObjectURL(W),y(Q=>Q.filter((we,Se)=>Se!==M))},[C]),I=f.useCallback(M=>{const W=M.clipboardData?.items;if(W)for(let Q=0;Q<W.length;Q++){const we=W[Q];if(we.kind==="file"){const Se=we.getAsFile();Se&&E(Se)&&(M.preventDefault(),L(Se))}}},[L,E]),_=f.useCallback(M=>{M.preventDefault(),k.current++},[]),A=f.useCallback(M=>{M.preventDefault(),k.current--},[]),ae=f.useCallback(M=>{M.preventDefault()},[]),$e=f.useCallback(M=>{M.preventDefault(),k.current=0;const W=M.dataTransfer?.files;if(W)for(let Q=0;Q<W.length;Q++){const we=W[Q];E(we)&&L(we)}},[L,E]),xe=f.useCallback(M=>{const W=M.currentTarget.files;if(W){for(let Q=0;Q<W.length;Q++){const we=W[Q];E(we)&&L(we)}M.currentTarget.value=""}},[L,E]),ue=p.startsWith("/")&&!p.includes(" ")?p.slice(1).toLowerCase():null,ne=f.useMemo(()=>ue===null||o.length===0?[]:o.filter(M=>M.id.toLowerCase().includes(ue)||M.label.toLowerCase().includes(ue)),[ue,o]),wt=ue!==null&&ne.length>0,kt=ne.length>0?j%ne.length:0,ut=f.useCallback(M=>{b(""),N.current&&(N.current.style.height="auto"),r?.(M.id)},[r]),mt=M=>{if(wt&&ne.length>0){if(M.key==="ArrowDown"){M.preventDefault(),w(W=>(W+1)%ne.length);return}if(M.key==="ArrowUp"){M.preventDefault(),w(W=>(W-1+ne.length)%ne.length);return}if(M.key==="Enter"||M.key==="Tab"){M.preventDefault(),ut(ne[kt]);return}if(M.key==="Escape"){M.preventDefault(),b("");return}}M.key==="Enter"&&!M.shiftKey&&(M.preventDefault(),q())},ft=M=>{b(M.target.value),w(0),z()},Dt=p.trim().length>0,Nt=Dt&&!i,_t=a&&!i&&n!=null,ge=p.length,je=ge>Tp,Et=x.length>0?s.jsx("div",{className:`${m?"mt-3":"mb-3"} -mx-2 -my-2`,children:s.jsx("div",{className:"overflow-x-auto px-2 py-2",children:s.jsx("div",{className:"flex w-max flex-nowrap items-center gap-2",children:x.map((M,W)=>{const Q=M.type.startsWith("image/"),we=C.get(W)||"";return Q?s.jsx("div",{className:"shrink-0",children:s.jsx(Hn,{src:we,alt:M.name,removable:!0,compact:!0,onRemove:()=>P(W)})},W):s.jsx("div",{className:"shrink-0",children:s.jsx(Un,{name:M.name,mediaType:M.type,removable:!0,onRemove:()=>P(W)})},W)})})})}):null;return s.jsx("div",{className:u?"":"border-t border-(--color-border) bg-(--color-bg) px-4 py-3",children:s.jsxs("div",{className:u?"relative":"relative mx-auto max-w-3xl",children:[!m&&Et,wt&&ne.length>0&&s.jsx("div",{className:"absolute bottom-full left-0 right-0 z-10 mb-1 overflow-hidden rounded-lg border border-(--color-border) bg-(--color-surface-2) shadow-lg",children:ne.map((M,W)=>s.jsxs("button",{onMouseDown:Q=>{Q.preventDefault(),ut(M)},className:`flex w-full items-center gap-3 px-3 py-2 text-left text-sm transition-colors ${W===kt?"bg-(--color-accent-subtle) text-(--color-text)":"text-(--color-text-muted) hover:bg-(--color-accent-dim)"}`,children:[s.jsxs("span",{className:"font-mono text-xs text-(--color-accent)",children:["/",M.id]}),s.jsx("span",{className:"text-(--color-text-2)",children:M.description})]},M.id))}),s.jsxs("div",{className:"relative",children:[h?.(),s.jsxs("div",{className:`relative flex items-center gap-2 rounded-2xl border border-(--color-border) px-4 py-2.5 transition-all focus-within:border-(--color-accent) focus-within:ring-1 focus-within:ring-(--color-accent-subtle) ${u?"bg-(--color-surface-2)/20 shadow-xl backdrop-blur-xl":"bg-(--color-surface-2)"}`,onDragEnter:_,onDragLeave:A,onDragOver:ae,onDrop:$e,children:[s.jsx("textarea",{ref:N,value:p,onChange:ft,onKeyDown:mt,onPaste:I,disabled:i,placeholder:i?"Waiting for response…":a?"Type /stop to interrupt, or click stop…":l,rows:1,autoFocus:c,className:"flex-1 resize-none bg-transparent py-1 text-sm leading-relaxed text-(--color-text) placeholder-(--color-text-muted) focus:outline-none disabled:opacity-50",style:{maxHeight:"144px"},"aria-label":"Message input"}),je&&s.jsx("span",{className:`shrink-0 self-end pb-1 text-xs ${ge>2e3?"text-(--color-error)":"text-(--color-text-muted)"}`,children:ge}),s.jsx("button",{onClick:()=>v.current?.click(),disabled:i,"aria-label":"Attach file",title:"Attach file (paste or drag)",className:"flex h-8 w-8 shrink-0 self-end items-center justify-center rounded-full text-(--color-text-muted) transition-colors hover:bg-(--color-accent-subtle) hover:text-(--color-text) disabled:opacity-25",children:s.jsx(Xi,{size:14})}),_t&&!Dt?s.jsx("button",{onClick:n,"aria-label":"Stop generation",className:"flex h-8 w-8 shrink-0 self-end items-center justify-center rounded-full bg-(--color-error) text-(--color-bg) shadow-sm transition-all hover:opacity-80 hover:shadow-md",children:s.jsx(Zi,{size:12,fill:"currentColor"})}):s.jsx("button",{onClick:q,disabled:!Nt,"aria-label":"Send message",title:"Send (Enter) · New line (Shift+Enter) · Commands (/)",className:"flex h-8 w-8 shrink-0 self-end items-center justify-center rounded-full bg-(--color-accent) text-(--color-bg) shadow-sm transition-all hover:bg-(--color-accent-hover) hover:shadow-md disabled:cursor-not-allowed disabled:opacity-25",children:i?s.jsx(_e,{size:14,className:"animate-spin"}):s.jsx(Ji,{size:14})})]})]}),m&&Et,s.jsx("input",{ref:v,type:"file",multiple:!0,accept:H(),onChange:xe,className:"hidden","aria-hidden":"true"})]})})});function Kr({inputRef:e}){const t=ee(o=>o._pendingMessages),n=ee(o=>o.removePendingMessage);if(t.length===0)return null;const r=(o,a)=>{n(o),e.current?.setValue(a),e.current?.focus()};return s.jsx("div",{className:"mb-2 flex flex-col gap-1 px-1",children:s.jsx(be,{initial:!1,children:t.map(o=>s.jsxs(se.div,{initial:{opacity:0,y:6,scale:.97},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,y:-4,scale:.97},transition:{duration:.15},className:"flex items-center gap-2 rounded-xl border border-(--color-border) bg-(--color-surface-2)/60 px-3 py-2 shadow-sm backdrop-blur-sm",children:[s.jsx(Mo,{size:12,className:"shrink-0 text-(--color-text-muted)","aria-hidden":"true"}),s.jsx("span",{className:"min-w-0 flex-1 truncate text-xs text-(--color-text-muted)",children:o.content}),o.files&&o.files.length>0&&s.jsxs("span",{className:"shrink-0 rounded-full bg-(--color-accent-subtle) px-1.5 py-0.5 text-[10px] text-(--color-accent)",children:["+",o.files.length]}),s.jsx("button",{onClick:()=>r(o.id,o.content),"aria-label":"Cancel queued message and restore to input",title:"Cancel — restore to input",className:"shrink-0 rounded-full p-0.5 text-(--color-text-muted) transition-colors hover:bg-(--color-accent-subtle) hover:text-(--color-text)",children:s.jsx(Ee,{size:12})})]},o.id))})})}const Va="oa-input-position";function Mp(){if(typeof window>"u")return{x:0,y:0};try{const e=window.localStorage.getItem(Va);if(!e)return{x:0,y:0};const t=JSON.parse(e);if(typeof t=="object"&&t!==null&&"x"in t&&"y"in t&&typeof t.x=="number"&&typeof t.y=="number")return{x:t.x,y:t.y}}catch{}return{x:0,y:0}}function Nn(e){if(!(typeof window>"u"))try{window.localStorage.setItem(Va,JSON.stringify(e))}catch{}}function Gr(e,t,n){const o=Math.max(0,(n.width-t.width)/2-16),a=-Math.max(0,n.height-t.height-16);return{x:Math.min(o,Math.max(-o,e.x)),y:Math.min(0,Math.max(a,e.y))}}const Dp=f.forwardRef(function({boundsRef:t,...n},r){const o=Ye(),a=Ei(),i=f.useRef(null),[l,c]=f.useState(()=>Mp()),[d,u]=f.useState(!0),m=140,h=f.useCallback(()=>{const b=t.current,x=i.current;if(!b||!x)return;const y=b.getBoundingClientRect(),j=x.getBoundingClientRect();u(y.bottom-j.bottom>=m)},[t]);f.useEffect(()=>{if(o)return;const b=()=>{const x=t.current,y=i.current;if(!x||!y)return;const j=x.getBoundingClientRect(),w=y.getBoundingClientRect();c(N=>{const v=Gr(N,{width:w.width,height:w.height},{width:j.width,height:j.height});return v.x===N.x&&v.y===N.y?N:(Nn(v),v)}),h()};return b(),window.addEventListener("resize",b),()=>window.removeEventListener("resize",b)},[o,t,h]);const g=f.useCallback((b,x)=>{const y=t.current,j=i.current;if(!y||!j)return;const w=y.getBoundingClientRect(),N=j.getBoundingClientRect(),v=Gr({x:l.x+x.offset.x,y:l.y+x.offset.y},{width:N.width,height:N.height},{width:w.width,height:w.height});c(v),Nn(v),requestAnimationFrame(h)},[t,l,h]),p=f.useCallback(()=>{const b={x:0,y:0};c(b),Nn(b),requestAnimationFrame(h)},[h]);return o?s.jsxs("div",{className:"pointer-events-auto border-t border-(--color-border) bg-(--color-surface-2)/20 px-3 pb-safe pt-2 backdrop-blur-xl",children:[s.jsx(Kr,{inputRef:r}),s.jsx(Qr,{ref:r,floating:!0,filesBelow:!1,...n})]}):s.jsxs(se.div,{ref:i,drag:!0,dragListener:!1,dragControls:a,dragMomentum:!1,dragElastic:0,onDragEnd:g,animate:{x:l.x,y:l.y},transition:{type:"spring",stiffness:380,damping:32},className:"pointer-events-auto absolute bottom-4 left-1/2 z-20 w-full max-w-xl -translate-x-1/2 px-4",style:{touchAction:"none"},children:[s.jsx(Kr,{inputRef:r}),s.jsx(Qr,{ref:r,floating:!0,filesBelow:d,renderDragHandle:()=>s.jsx("button",{type:"button","aria-label":"Drag input bar (double-click to reset position)",title:"Drag to move · Double-click to reset",onPointerDown:b=>a.start(b),onDoubleClick:p,className:"absolute left-1/2 top-0 z-10 flex h-4 w-10 -translate-x-1/2 -translate-y-1/2 cursor-grab items-center justify-center rounded-full border border-(--color-border) bg-(--color-surface-2) text-(--color-text-muted) shadow-sm transition-colors hover:text-(--color-text) active:cursor-grabbing",children:s.jsx(el,{size:12,"aria-hidden":"true"})}),...n})]})}),Vr=10;function _p({content:e,timestamp:t,attachments:n}){const[r,o]=f.useState(!1),[a,i]=f.useState(!1),[l,c]=f.useState(!1),d=async()=>{try{await navigator.clipboard.writeText(e),i(!0),setTimeout(()=>i(!1),1500)}catch{}},u=e.split(`
|
|
38
|
+
`),m=u.length>Vr,h=m&&!l?u.slice(0,Vr).join(`
|
|
39
|
+
`):e;return s.jsx("div",{className:"group mb-3 flex justify-end",onMouseEnter:()=>o(!0),onMouseLeave:()=>o(!1),children:s.jsxs("div",{className:"flex max-w-[85%] flex-col items-end gap-1.5",children:[n&&n.length>0&&s.jsx("div",{className:"flex flex-wrap justify-end gap-1.5",children:n.map((g,p)=>g.category==="image"?s.jsx(Hn,{src:g.url||"",alt:g.original_name||`Attachment ${p+1}`},p):s.jsx(Un,{name:g.original_name||g.filename||`File ${p+1}`,mediaType:g.media_type,url:g.url,clickable:!!g.url},p))}),s.jsxs("div",{className:"relative rounded-2xl rounded-br-sm bg-(--color-accent) px-3 py-2 text-xs leading-relaxed text-(--color-bg) overflow-hidden",children:[m&&s.jsx("button",{onClick:()=>c(g=>!g),"aria-expanded":l,title:l?"Collapse":"Expand",className:["absolute top-1 right-1","flex items-center justify-center shrink-0","rounded-md","h-4 w-4","transition-all duration-150","active:scale-90"].join(" "),style:{background:"rgba(0,0,0,0.15)",color:"var(--color-bg)"},children:l?s.jsx(Gs,{size:10}):s.jsx(Xe,{size:10})}),s.jsx("p",{className:"whitespace-pre-wrap",children:h}),m&&!l&&s.jsx("div",{className:"pointer-events-none absolute inset-x-0 bottom-0",style:{height:"1.9rem",background:"linear-gradient(to bottom, transparent 0%, var(--color-accent) 90%)"}})]}),t&&s.jsxs("div",{className:`flex items-center gap-1 transition-opacity duration-150 ${r?"opacity-100":"opacity-0"}`,children:[s.jsx("button",{onClick:d,className:"rounded p-0.5 text-(--color-text-muted) transition-colors hover:text-(--color-text-2)","aria-label":"Copy message",title:"Copy",children:a?s.jsx(vt,{size:10,className:"text-(--color-success)"}):s.jsx(Lt,{size:10})}),s.jsx("span",{className:"text-xs text-(--color-text-subtle)","aria-hidden":!r,title:Ns(t),children:Ns(t)})]})]})})}function Xr({block:e,isStreaming:t,isLast:n,sessionId:r}){switch(e.type){case"user":{const o=e.extra?.from_agent;return o&&o!=="user"?s.jsx(Ho,{content:e.content,fromAgent:o,compact:!0}):s.jsx(_p,{content:e.content,timestamp:e.timestamp,attachments:e.attachments})}case"thinking":return s.jsx(Yo,{content:e.content,isStreaming:t});case"tool":return s.jsx(qo,{name:e.toolName||"",args:e.toolArgs,done:e.toolDone,result:e.toolResult});case"text":{const o=Zn(e.content);return o!==null?s.jsxs("div",{children:[o&&s.jsx(Ys,{content:o,sessionId:r}),s.jsx("p",{className:"text-xs text-(--color-text-subtle) italic",children:"— idle —"})]}):s.jsxs("div",{children:[s.jsx(Ys,{content:e.content,sessionId:r}),t&&n&&s.jsx(Ro,{className:"ml-0.5 text-(--color-accent)"})]})}default:return null}}function Xa({name:e,stream:t,isLead:n,isFocused:r=!1,isDropTarget:o=!1,isDragging:a=!1,onClose:i,onFocus:l,onDragStart:c,onDragEnd:d,onDragOver:u,onDrop:m}){const h=f.useRef(null),g=ee(P=>P.sessionId)??void 0,p=t.status==="working",b=t.status==="error",x=!p&&!b&&t.currentBlocks.some(P=>P.type==="user"),y=f.useRef(!0),[j,w]=f.useState(!1),N=40,v=f.useCallback(()=>{const P=h.current;return P?P.scrollHeight-P.scrollTop-P.clientHeight<=N:!0},[]),k=f.useCallback((P=!1)=>{const I=h.current;I&&(y.current=!0,w(!1),P?I.scrollTo({top:I.scrollHeight,behavior:"smooth"}):I.scrollTop=I.scrollHeight)},[]);f.useEffect(()=>{const P=h.current;if(!P)return;const I=()=>{requestAnimationFrame(()=>{const _=v();y.current=_,w(!_)})};return P.addEventListener("wheel",I,{passive:!0}),P.addEventListener("touchmove",I,{passive:!0}),()=>{P.removeEventListener("wheel",I),P.removeEventListener("touchmove",I)}},[v]);const C=[...t.blocks,...t.currentBlocks],z=C[C.length-1]?.content??"";f.useEffect(()=>{y.current&&k()},[C.length,z]);const q=C.length===0,H=b?"border-(--color-error)":o?"border-(--color-info) bg-(--color-info-subtle)":r?"border-(--color-accent)":n?"border-(--color-border-strong)":"border-(--color-border)",E=b?"border-b-(--color-error)":p?"border-b-(--color-accent)":n?"border-b-(--color-border-strong)":"border-b-(--color-border)",L=!!c;return s.jsxs("div",{onDragOver:u,onDrop:m,onDragEnd:d,className:`flex h-full flex-col overflow-hidden rounded-xl border bg-(--color-bg) transition-all duration-150 ${H} ${a?"opacity-50":""}`,onClick:l,children:[s.jsxs("div",{className:`flex items-center gap-2 border-b px-3 py-2.5 ${E}`,children:[L&&s.jsx("div",{draggable:!0,onDragStart:c,onDragEnd:d,className:"cursor-grab text-(--color-text-subtle) hover:text-(--color-text-muted) active:cursor-grabbing",onClick:P=>P.stopPropagation(),title:"Drag to swap pane position","aria-label":`Drag ${e} pane`,children:s.jsx(tl,{size:14})}),s.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-1.5",children:[s.jsx("span",{className:`truncate text-xs font-semibold ${n?"text-(--color-text)":"text-(--color-text-2)"}`,children:e}),n&&s.jsx("span",{className:"shrink-0 rounded-sm bg-(--color-accent-subtle) px-1 py-0.5 text-xs text-(--color-accent)",children:"lead"})]}),s.jsxs("div",{className:"flex items-center gap-1 text-xs text-(--color-text-subtle)",children:[t.usage.totalTokens>0&&s.jsxs(s.Fragment,{children:[s.jsxs("span",{children:["in ",es(t.usage.promptTokens)]}),s.jsx("span",{className:"text-[#3c3836]",children:"·"}),s.jsxs("span",{children:["out ",es(t.usage.completionTokens)]}),t.usage.cachedTokens>0&&s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"text-[#3c3836]",children:"·"}),s.jsxs("span",{className:"text-[#458588]",children:["cached ",es(t.usage.cachedTokens)]})]}),t.model&&s.jsx("span",{className:"text-[#3c3836]",children:"·"})]}),t.model&&s.jsx("span",{className:"text-(--color-text-muted)",children:t.model}),s.jsx("span",{className:`h-1.5 w-1.5 rounded-full ${b?"bg-(--color-error)":p?"animate-pulse bg-(--color-accent)":"bg-(--color-success)"}`})]}),i&&s.jsx("button",{onClick:P=>{P.stopPropagation(),i()},className:"ml-1 rounded p-0.5 text-(--color-text-subtle) transition-colors hover:bg-(--color-accent-subtle) hover:text-(--color-text-2)",title:"Minimize pane","aria-label":`Minimize ${e} pane`,children:s.jsx(Ee,{size:12})})]}),s.jsxs("div",{className:"relative flex min-h-0 flex-1 flex-col",children:[s.jsxs("div",{ref:h,className:"flex-1 overflow-y-auto",style:{minHeight:0},children:[q&&!p&&s.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-3 py-8",children:[s.jsx(Lo,{className:"text-(--color-text-subtle) opacity-30",width:56,height:56}),s.jsx("p",{className:"text-xs text-(--color-text-subtle)",children:b?t.lastError||"Error":"Waiting…"})]}),C.length>0&&s.jsx("div",{className:"space-y-3 px-3 py-3",children:(()=>{const P=ma(C);return P.map((I,_)=>{if(I.kind==="user")return s.jsx(Xr,{block:I.block,isStreaming:!1,isLast:I.index===C.length-1,sessionId:g},I.block.id);const A=_===P.length-1;return s.jsx(ua,{blocks:I.blocks,startIndex:I.startIndex,finalizedCount:t.blocks.length,isWorking:p,isTrailingTurn:A,totalBlocks:C.length,renderBlock:({block:ae,isStreaming:$e,isLast:xe})=>s.jsx(Xr,{block:ae,isStreaming:$e,isLast:xe,sessionId:g})},`turn-${I.startIndex}-${I.blocks[0]?.id??_}`)})})()}),(x||p&&t.currentBlocks.length>0&&t.currentBlocks.every(P=>P.type==="user"))&&s.jsxs("div",{className:"flex items-center gap-1.5 px-3 pt-3",children:[s.jsx("span",{className:"h-1.5 w-1.5 animate-bounce rounded-full bg-(--color-accent)",style:{animationDelay:"0ms"}}),s.jsx("span",{className:"h-1.5 w-1.5 animate-bounce rounded-full bg-(--color-accent)",style:{animationDelay:"150ms"}}),s.jsx("span",{className:"h-1.5 w-1.5 animate-bounce rounded-full bg-(--color-accent)",style:{animationDelay:"300ms"}})]}),b&&t.lastError&&s.jsx("div",{className:"mx-3 mt-3 rounded-lg border border-(--color-error) bg-(--color-error-subtle) px-3 py-2",children:s.jsx("p",{className:"text-xs text-(--color-error)",children:t.lastError})})]}),j&&s.jsx("button",{onClick:()=>k(!0),className:"absolute bottom-2 left-1/2 z-10 -translate-x-1/2 rounded-full border border-(--color-border) bg-(--color-surface) p-1 text-(--color-text-muted) transition-colors hover:text-(--color-text-2)","aria-label":"Scroll to bottom",children:s.jsx(Xe,{size:12})})]})]})}function Ep({panelOrder:e,leadName:t,agentStreams:n,draggingIdx:r,dropTargetIdx:o,onDragStart:a,onDragOver:i,onDrop:l,onDragEnd:c}){const d=Math.min(e.length,6);if(d===0)return null;const u=(m,h)=>{const g=e[m];if(!g)return null;const p=n[g];return p?s.jsx("div",{style:h,className:"min-h-0",children:s.jsx(Xa,{name:g,stream:p,isLead:g===t,isDragging:r===m,isDropTarget:o===m&&r!==m,onDragStart:()=>a(m),onDragOver:b=>i(b,m),onDrop:()=>l(m),onDragEnd:c})},g):null};return d===1?s.jsx("div",{className:"h-full",children:u(0,{})}):d===2?s.jsxs("div",{className:"grid h-full gap-3",style:{gridTemplateColumns:"1fr 1fr"},children:[u(0,{gridColumn:1,gridRow:1}),u(1,{gridColumn:2,gridRow:1})]}):d===3?s.jsxs("div",{className:"grid h-full gap-3",style:{gridTemplateColumns:"1fr 1fr",gridTemplateRows:"1fr 1fr"},children:[u(0,{gridColumn:1,gridRow:"1 / 3"}),u(1,{gridColumn:2,gridRow:1}),u(2,{gridColumn:2,gridRow:2})]}):d===4?s.jsxs("div",{className:"grid h-full gap-3",style:{gridTemplateColumns:"1fr 1fr",gridTemplateRows:"1fr 1fr"},children:[u(0,{gridColumn:1,gridRow:1}),u(1,{gridColumn:2,gridRow:1}),u(2,{gridColumn:1,gridRow:2}),u(3,{gridColumn:2,gridRow:2})]}):d===5?s.jsxs("div",{className:"grid h-full gap-3",style:{gridTemplateColumns:"1fr 1fr 1fr",gridTemplateRows:"1fr 1fr"},children:[u(0,{gridColumn:1,gridRow:"1 / 3"}),u(1,{gridColumn:2,gridRow:1}),u(2,{gridColumn:2,gridRow:2}),u(3,{gridColumn:3,gridRow:1}),u(4,{gridColumn:3,gridRow:2})]}):s.jsxs("div",{className:"grid h-full gap-3",style:{gridTemplateColumns:"1fr 1fr 1fr",gridTemplateRows:"1fr 1fr"},children:[u(0,{gridColumn:1,gridRow:1}),u(1,{gridColumn:2,gridRow:1}),u(2,{gridColumn:3,gridRow:1}),u(3,{gridColumn:1,gridRow:2}),u(4,{gridColumn:2,gridRow:2}),u(5,{gridColumn:3,gridRow:2})]})}function Op({agentNames:e,agentStreams:t,leadName:n,openAgents:r,focusedAgent:o,onFocusOpen:a,onOpenMinimized:i,onClose:l}){const c=new Set(r);return s.jsx("div",{className:"flex items-center gap-0.5 overflow-x-auto",children:e.map(d=>{const u=t[d],m=c.has(d),h=o===d,g=u?.status==="working",p=u?.status==="error",b=d===n;return m?s.jsxs("button",{onClick:()=>a(d),className:`interactive-weight group flex shrink-0 items-center gap-1.5 rounded-t-lg border-b-2 px-2.5 py-1.5 text-xs transition-all ${h?"border-b-(--color-accent) bg-(--color-accent-subtle) text-(--color-accent)":"border-b-transparent text-(--color-text-2) hover:bg-(--color-accent-dim) hover:text-(--color-text)"}`,children:[s.jsx("span",{className:`h-1.5 w-1.5 shrink-0 rounded-full ${p?"bg-(--color-error)":g?"animate-pulse bg-(--color-accent)":"bg-(--color-success)"}`}),s.jsxs("span",{className:"max-w-30 truncate",children:[d,b&&s.jsx("span",{className:"ml-1 text-(--color-text-subtle)",children:"·"})]}),s.jsx("span",{onClick:x=>{x.stopPropagation(),l(d)},role:"button","aria-label":`Minimize ${d}`,title:"Minimize pane",className:`flex items-center rounded p-0.5 transition-colors ${h?"text-(--color-accent) hover:bg-(--color-accent-subtle)":"text-(--color-text-subtle) opacity-0 group-hover:opacity-100 hover:text-(--color-text-2)"}`,children:"×"})]},d):s.jsxs("button",{onClick:()=>i(d),title:`Open ${d} as new split pane`,className:"flex shrink-0 items-center gap-1 rounded-lg px-2 py-1.5 text-xs text-(--color-text-muted) transition-all hover:bg-(--color-accent-dim) hover:text-(--color-text-2)",children:[s.jsx("span",{className:`h-1.5 w-1.5 shrink-0 rounded-full ${p?"bg-(--color-error)":g?"animate-pulse bg-(--color-accent)":"bg-(--color-border-strong)"}`}),s.jsx("span",{className:"max-w-25 truncate opacity-60",children:d})]},d)})})}const Pp=e=>f.createElement("svg",{viewBox:"273 297 86 112",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",...e},f.createElement("path",{fill:"currentColor",d:"M303.12,346.849c0.022,0.373,0.132,0.762,0.36,1.063c0.311,0.411,0.864,0.646,1.374,0.525 c0.533-0.126,0.95-0.476,1.17-0.979c0.141-0.321,0.17-0.667,0.185-1.012c0.044-0.203,0.07-0.41,0.088-0.605 c0.065-0.723,0.033-1.602-0.299-2.265c-0.22-0.441-0.575-0.789-1.074-0.882c-0.491-0.091-0.983,0.152-1.272,0.543l-0.064,0.107 c-0.122,0.128-0.226,0.275-0.303,0.438c-0.177,0.378-0.239,0.844-0.253,1.259c-0.012,0.358,0.018,0.716,0.075,1.069 C303.104,346.358,303.106,346.605,303.12,346.849z"}),f.createElement("path",{fill:"currentColor",d:"M325.684,346.849c0.022,0.373,0.132,0.762,0.36,1.063c0.311,0.411,0.864,0.646,1.374,0.525 c0.533-0.126,0.95-0.476,1.17-0.979c0.141-0.321,0.17-0.667,0.186-1.012c0.044-0.203,0.07-0.41,0.087-0.605 c0.065-0.723,0.033-1.602-0.298-2.265c-0.22-0.441-0.576-0.789-1.074-0.882c-0.491-0.091-0.983,0.152-1.272,0.543l-0.064,0.107 c-0.122,0.128-0.226,0.275-0.303,0.438c-0.177,0.378-0.239,0.844-0.253,1.259c-0.012,0.358,0.018,0.716,0.075,1.069 C325.667,346.358,325.67,346.605,325.684,346.849z"}),f.createElement("path",{fill:"currentColor",d:"M310.249,352.225c1.353-0.136,2.707-0.264,4.058-0.425c0.675-0.08,1.349-0.166,2.025-0.241 c0.292-0.033,0.577-0.063,0.869-0.055c0.475,0.013,0.778-0.131,1.175-0.379c0.242-0.151,0.323-0.521,0.247-0.773 c-0.091-0.304-0.311-0.45-0.608-0.527c-0.42-0.108-0.71-0.084-1.121,0.056c-0.302,0.103-0.624,0.153-0.938,0.214 c-0.642,0.124-1.285,0.244-1.927,0.366c-1.311,0.249-2.616,0.531-3.923,0.803C309.496,351.39,309.622,352.289,310.249,352.225z"}),f.createElement("path",{fill:"currentColor",d:"M349.944,361.096c-0.768-3.263-1.551-6.522-2.342-9.78c-0.478-1.968-0.904-3.977-1.44-5.945 c1.334-2.937,2.07-6.117,2.07-9.439c0-14.73-14.356-26.714-32.002-26.714c-14.786,0-27.252,8.417-30.908,19.811 c-1.362,1.067-2.406,2.617-3.257,4.081c-0.861,1.481-1.599,3.095-1.794,4.816c-0.136,1.201-0.126,3.463,1.106,4.183 c-0.799,2.507-1.324,5.124-1.943,7.671c-0.795,3.27-1.58,6.542-2.351,9.817c-0.108,0.458,0.349,1.039,0.817,1.046 c2.948,0.043,5.891-0.15,8.797-0.655c1.409-0.245,2.805-0.556,4.185-0.929c0.535-0.144,1.132-0.276,1.726-0.434 c-0.363,0.405-0.715,0.82-1.037,1.257c-0.219,0.298-0.435,0.604-0.636,0.915c-0.059,0.091-0.105,0.194-0.143,0.301h-16.068v45.345 h3.651c0.002,0.223,0.013,0.447,0.022,0.67c0.02,0.491,0.033,0.983,0.063,1.473c0.029,0.49,0.063,0.979,0.094,1.469 c0.03,0.476,0.006,1.001,0.112,1.466c0.105,0.462,0.453,0.802,0.945,0.797c0.449-0.005,0.886-0.35,0.924-0.82 c0.043-0.527-0.051-1.082-0.093-1.608c-0.039-0.488-0.078-0.977-0.117-1.465c-0.039-0.488-0.096-0.974-0.146-1.461 c-0.017-0.168-0.033-0.344-0.052-0.52h71.65c-0.008,0.057-0.017,0.117-0.025,0.171c-0.074,0.492-0.122,0.985-0.17,1.48 c-0.047,0.477-0.094,0.955-0.14,1.432c-0.06,0.617-0.276,1.426,0.321,1.848c0.233,0.164,0.563,0.237,0.83,0.102 c0.421-0.213,0.595-0.549,0.619-1.007c0.013-0.257,0.026-0.515,0.039-0.772c0.024-0.48,0.049-0.961,0.073-1.441 c0.024-0.482,0.048-0.961,0.048-1.444c0-0.121,0.001-0.246,0.001-0.37h2.821v-1.153v-44.192H349.944z M330.03,360.031l0.405,0.695 c0.072,0.124,0.144,0.247,0.216,0.371h-3.692C328.008,360.784,329.034,360.43,330.03,360.031z M332.092,361.096 c0.001-0.047,0.005-0.095-0.001-0.139c-0.018-0.12-0.075-0.22-0.138-0.321l-0.121-0.188c-0.081-0.125-0.161-0.25-0.242-0.375 c-0.119-0.185-0.238-0.37-0.358-0.555c0.27-0.12,0.536-0.246,0.802-0.373c1.11,0.823,2.8,1.092,4.12,1.449 c0.676,0.182,1.355,0.349,2.038,0.501H332.092z M345.932,351.712c0.647,2.859,1.284,5.72,1.919,8.582 c-2.422-0.053-4.84-0.292-7.224-0.724c-1.364-0.247-2.72-0.552-4.055-0.927c-0.686-0.192-1.412-0.504-2.141-0.757 c4.475-2.593,8.124-6.112,10.542-10.224C345.289,349.016,345.628,350.366,345.932,351.712z M344.464,341.828 c-0.608,0.477-1.384,0.508-2.112,0.34c-1.448-0.334-2.888-1.22-4.035-2.141c-1.202-0.965-2.198-2.188-2.737-3.642 c-0.288-0.777-0.568-1.921-0.455-2.91c0.18-0.777,0.524-1.543,1.193-2.005c0.824-0.569,1.937-0.561,2.851-0.229 c2.041,0.74,3.387,2.904,4.368,4.724c0.527,0.978,0.999,2.025,1.213,3.121c0.081,0.413,0.133,0.831,0.139,1.251 c0.065,0.09,0.114,0.189,0.156,0.291C344.995,341.075,344.908,341.48,344.464,341.828z M316.23,311.524 c16.375,0,29.696,10.949,29.696,24.408c0,0.181-0.012,0.36-0.017,0.54c-0.276-0.628-0.597-1.237-0.938-1.825 c-1.384-2.381-3.278-4.995-6.221-5.378c-1.337-0.174-2.725,0.142-3.713,1.092c-0.915,0.879-1.356,2.114-1.415,3.365 c-0.135,2.85,0.826,5.57,3.152,7.307c2.037,1.521,4.784,3.279,7.428,2.802c0.01,0.066,0.026,0.132,0.037,0.199 c-4.075,9.487-15.088,16.306-28.008,16.306c-14.088,0-25.906-8.108-28.935-18.942c1.078-0.546,2.089-1.246,2.968-1.902 c2.326-1.737,3.287-4.457,3.152-7.307c-0.059-1.251-0.5-2.486-1.415-3.365c-0.989-0.95-2.377-1.266-3.713-1.092 c-0.003,0-0.006,0.001-0.009,0.001C292.385,318.298,303.355,311.524,316.23,311.524z M282.147,338.8 c0.005-0.42,0.058-0.838,0.139-1.251c0.214-1.096,0.686-2.142,1.213-3.121c0.981-1.821,2.327-3.984,4.368-4.724 c0.914-0.332,2.027-0.34,2.851,0.229c0.669,0.462,1.013,1.228,1.193,2.005c0.113,0.989-0.166,2.133-0.455,2.91 c-0.539,1.454-1.535,2.677-2.737,3.642c-1.148,0.921-2.587,1.807-4.035,2.141c-0.728,0.168-1.504,0.137-2.112-0.34 c-0.445-0.349-0.531-0.754-0.581-1.2C282.033,338.989,282.082,338.889,282.147,338.8z M290.462,357.106 c-1.335,0.374-2.691,0.679-4.055,0.926c-2.383,0.432-4.802,0.671-7.224,0.724c0.635-2.862,1.272-5.723,1.919-8.582 c0.59-2.608,1.313-5.228,1.732-7.877c0.761,0.137,1.531,0.085,2.289-0.089c1.587,5.48,5.204,10.303,10.146,13.887 c-0.062,0.047-0.123,0.093-0.182,0.141c-0.191-0.182-0.452-0.303-0.746-0.288C293.066,356.017,291.698,356.76,290.462,357.106z M293.431,360.344c0.382-0.504,0.787-0.989,1.215-1.454c0.406-0.441,0.77-0.797,1.237-1.214c0.237-0.212,0.492-0.427,0.727-0.659 c2.661,1.729,5.654,3.116,8.888,4.08h-12.613C293.065,360.844,293.244,360.591,293.431,360.344z M277.03,363.402h76.856l0,40.734 H277.03V363.402z"}));function Rn({node:e,agentStreams:t,leadName:n,focusedAgent:r,onFocus:o,onClose:a,onSwap:i}){if(e.type==="leaf")return s.jsx($p,{agentName:e.agentName,agentStreams:t,leadName:n,focusedAgent:r,onFocus:o,onClose:a,onSwap:i});const l=e.dir==="h",c=`${(e.ratio*100).toFixed(1)}%`,d=`${((1-e.ratio)*100).toFixed(1)}%`,u=l?{display:"flex",flexDirection:"row",width:"100%",height:"100%",gap:"6px"}:{display:"flex",flexDirection:"column",width:"100%",height:"100%",gap:"6px"},m=l?{width:c,height:"100%",minWidth:0}:{width:"100%",height:c,minHeight:0},h=l?{width:d,height:"100%",minWidth:0}:{width:"100%",height:d,minHeight:0};return s.jsxs("div",{style:u,children:[s.jsx("div",{style:m,children:s.jsx(Rn,{node:e.a,agentStreams:t,leadName:n,focusedAgent:r,onFocus:o,onClose:a,onSwap:i})}),s.jsx("div",{style:h,children:s.jsx(Rn,{node:e.b,agentStreams:t,leadName:n,focusedAgent:r,onFocus:o,onClose:a,onSwap:i})})]})}function $p({agentName:e,agentStreams:t,leadName:n,focusedAgent:r,onFocus:o,onClose:a,onSwap:i}){const l=t[e],c=r===e,d=e===n,[u,m]=f.useState(!1),h=f.useCallback(()=>o(e),[e,o]),g=f.useCallback(()=>a(e),[e,a]),p=f.useCallback(w=>{w.dataTransfer.setData("text/plain",e),w.dataTransfer.effectAllowed="move"},[e]),b=f.useCallback(w=>{w.preventDefault(),w.dataTransfer.dropEffect="move",m(!0)},[]),x=f.useCallback(()=>m(!1),[]),y=f.useCallback(w=>{w.preventDefault(),m(!1);const N=w.dataTransfer.getData("text/plain");N&&N!==e&&i(N,e)},[e,i]),j=f.useCallback(()=>m(!1),[]);return l?s.jsx("div",{className:"h-full",onDragOver:b,onDragLeave:x,onDrop:y,children:s.jsx(Xa,{name:e,stream:l,isLead:d,isFocused:c,isDropTarget:u,onClose:g,onFocus:h,onDragStart:p,onDragEnd:j})}):null}function zp({tileLayout:e,agentStreams:t,leadName:n}){const{root:r,focusedAgent:o,focusAgent:a,closeAgent:i,swapAgents:l}=e;return r?s.jsx("div",{className:"min-h-0 flex-1 p-3",children:s.jsx(Rn,{node:r,agentStreams:t,leadName:n,focusedAgent:o,onFocus:a,onClose:i,onSwap:l})}):s.jsxs("div",{className:"flex flex-1 flex-col items-center justify-center gap-3",children:[s.jsx(Pp,{className:"text-(--color-text-subtle) opacity-25",width:64,height:64}),s.jsx("p",{className:"text-sm text-(--color-text-muted)",children:"No agent panes open · click a tab above to open one"})]})}function Rp({agentNames:e,leadName:t}){const[n,r]=f.useState([]),[o,a]=f.useState(null),[i,l]=f.useState(null);f.useEffect(()=>{e.length>0&&n.length===0&&r(t?[t,...e.filter(h=>h!==t)]:[...e])},[e,t,n.length]);const c=f.useCallback(h=>a(h),[]),d=f.useCallback((h,g)=>{h.preventDefault(),l(g)},[]),u=f.useCallback(h=>{if(o===null||o===h){a(null),l(null);return}r(g=>{const p=[...g],[b]=p.splice(o,1);return p.splice(h,0,b),p}),a(null),l(null)},[o]),m=f.useCallback(()=>{a(null),l(null)},[]);return{panelOrder:n,draggingIdx:o,dropTargetIdx:i,onDragStart:c,onDragOver:d,onDrop:u,onDragEnd:m}}function Ap({viewMode:e,cycleViewMode:t,setViewMode:n,setShowAgentSidebar:r,setShowFilesPanel:o,setShowTodos:a,handleNewSession:i,handleDreamRun:l,agentNames:c,leadName:d,openAgents:u,focusedAgent:m,cycleActiveAgent:h,setActiveAgent:g,focusAgent:p,openAgent:b,handleSplitDown:x,handleSplitRight:y,handleClosePane:j,navigate:w}){return[{id:"new-chat",group:"Team",label:"New Team Chat",description:"Start a fresh team conversation",shortcut:"Ctrl+N",action:i},{id:"dream-run",group:"Team",label:"Run Dream",description:"Synthesise unprocessed sessions into wiki topics",action:l},{id:"toggle-view",group:"View",label:e==="agent"?"Switch to Split View":e==="split"?"Switch to Unified View":"Switch to Agent View",description:"Cycle: Agent → Split → Unified",shortcut:"Ctrl+V",action:t},...e==="unified"?[{id:"split-down",group:"View",label:"Split Pane Down",description:"Open next agent below focused pane",shortcut:"Ctrl+J",action:x},{id:"split-right",group:"View",label:"Split Pane Right",description:"Open next agent to the right of focused pane",shortcut:"Ctrl+K",action:y},{id:"close-pane",group:"View",label:"Close Focused Pane",description:"Minimize the focused agent pane",shortcut:"Ctrl+W",action:j}]:[],{id:"agent-info",group:"View",label:"Agent Capabilities",description:"Show agent tools, skills and config",shortcut:"Ctrl+A",action:()=>r(v=>!v)},{id:"todos",group:"View",label:"Task List",description:"View agent todos and progress",shortcut:"Ctrl+T",action:()=>a(v=>!v)},{id:"workspace-files",group:"View",label:"Toggle Workspace Files",description:"Browse files the agent has produced",shortcut:"Ctrl+F",action:()=>o(v=>!v)},{id:"collapse-sidebar",group:"View",label:"Toggle Sidebar",description:"",shortcut:"Ctrl+B",action:()=>window.dispatchEvent(new KeyboardEvent("keydown",{key:"b",ctrlKey:!0,bubbles:!0}))},{id:"wiki",group:"View",label:"Wiki",description:"Browse and edit the agent wiki",shortcut:"Ctrl+M",action:()=>window.dispatchEvent(new KeyboardEvent("keydown",{key:"m",ctrlKey:!0,bubbles:!0}))},{id:"scheduled-tasks",group:"View",label:"Scheduled Tasks",description:"Manage cron and scheduled agent tasks",shortcut:"Ctrl+S",action:()=>window.dispatchEvent(new KeyboardEvent("keydown",{key:"s",ctrlKey:!0,bubbles:!0}))},{id:"focus-input",group:"View",label:"Focus Chat Input",description:"Jump cursor to the message composer",shortcut:"Ctrl+I",action:()=>window.dispatchEvent(new CustomEvent("focus-chat-input"))},...c.map(v=>({id:`switch-${v}`,group:"Agents",label:e==="unified"?u.includes(v)?`Focus ${v}`:`Open ${v}`:`View ${v}`,description:v===d?"Lead agent":"Worker agent",action:()=>{e==="unified"?u.includes(v)?p(v):b(v):(n("agent"),g(v))}})),{id:"next-agent",group:"Agents",label:"Next Agent",description:"Tab",action:()=>e==="unified"?p(u[(u.indexOf(m??"")+1)%u.length]):h("next")},{id:"prev-agent",group:"Agents",label:"Previous Agent",description:"Shift+Tab",action:()=>e==="unified"?p(u[(u.indexOf(m??"")-1+u.length)%u.length]):h("prev")},{id:"go-home",group:"Navigation",label:"Go to Home",description:"",action:()=>w({to:"/"})},{id:"go-settings",group:"Navigation",label:"Open Settings",description:"Manage agents & skills",action:()=>w({to:"/settings/agents"})},{id:"settings-agents",group:"Settings",label:"Manage Agents",description:"Edit agent .md files",action:()=>w({to:"/settings/agents"})},{id:"settings-new-agent",group:"Settings",label:"New Agent",description:"Create a new agent",action:()=>w({to:"/settings/agents/new"})},{id:"settings-skills",group:"Settings",label:"Manage Skills",description:"Edit skill .md files",action:()=>w({to:"/settings/skills"})},{id:"settings-new-skill",group:"Settings",label:"New Skill",description:"Create a new skill",action:()=>w({to:"/settings/skills/new"})},{id:"settings-dream",group:"Settings",label:"Dream Config",description:"Edit the dream agent prompt and schedule",action:()=>w({to:"/settings/dream"})},...c.map(v=>({id:`edit-${v}`,group:"Settings",label:`Edit ${v}…`,description:"Jump to agent editor",action:()=>w({to:"/settings/agents/$name",params:{name:v}})}))]}const Sn=["agent","split","unified"];function Fp({sessionId:e}){const t=Ve(),n=Ye(),[r,o]=f.useState(!1),a=f.useRef(null),i=f.useRef(null),[l,c]=f.useState(!1),[d,u]=f.useState(!1),[m,h]=f.useState(!1),[g,p]=f.useState(!1),[b,x]=f.useState("agent"),y=n?"agent":b;f.useEffect(()=>{n&&(c(!1),u(!1))},[n]);const j=ee(S=>S.connectStream),w=ee(S=>S.loadTeamStatus),N=ee(S=>S.loadSession),v=ee(S=>S.sendMessage),k=ee(S=>S.newSession),C=ee(S=>S.cycleActiveAgent),z=ee(S=>S.setActiveAgent),q=ga(),H=Ge(S=>S.push),E=ee(S=>S.activeAgent),L=ee(S=>S.agentStreams),P=ee(S=>S.agentNames),I=ee(S=>S.isTeamWorking),_=ee(S=>S.sessionId),A=ee(S=>S.leadName),ae=ee(S=>S.activeAgent?S.agentStreams[S.activeAgent]?.blocks:void 0),$e=ee(S=>S.activeAgent?S.agentStreams[S.activeAgent]?.currentBlocks:void 0),xe=ee(S=>S.activeAgent?S.agentStreams[S.activeAgent]?.status:void 0),{data:ue}=yp(_),ne=ue?.todos??[],{data:wt}=Bn(),kt=wt?.agents?.find(S=>S.is_lead)?.capabilities,ut=ee(S=>Object.values(S.agentStreams).reduce((Z,ce)=>Z+ce.usage.promptTokens,0)),mt=ee(S=>Object.values(S.agentStreams).reduce((Z,ce)=>Z+ce.usage.completionTokens,0)),ft=ee(S=>Object.values(S.agentStreams).reduce((Z,ce)=>Z+ce.usage.cachedTokens,0)),Dt=ee(S=>Object.values(S.agentStreams).reduce((Z,ce)=>Z+ce.usage.totalTokens,0)),Nt=f.useRef(null),_t=Cp({sessionId:_,leadName:A,agentNames:P}),{openAgents:ge,focusedAgent:je,openAgent:Et,splitRight:M,splitDown:W,closeAgent:Q,focusAgent:we}=_t;f.useEffect(()=>{if(w(),!e)return;const S=ee.getState();if(S.sessionId===e&&S.isConnected)return;ee.setState({sessionId:e});let Z=!1;return(async()=>{if(await N(e),Z)return;const ce=j();ce&&(Nt.current=ce)})(),()=>{Z=!0,Nt.current?.abort()}},[e]);const Se=Rp({agentNames:P,leadName:A}),Ot=f.useCallback(()=>{Nt.current?.abort(),Nt.current=null,k(),t({to:"/cockpit"}),requestAnimationFrame(()=>a.current?.focus())},[k,t]),on=f.useCallback(()=>{q.mutate(void 0,{onSuccess:S=>{const{sessions_processed:Z,notes_processed:ce,remaining:$t}=S,ms=Z+ce;H({tone:"success",title:"Dream complete",description:ms>0?`${ms} item${ms!==1?"s":""} processed. ${$t} remaining.`:"Nothing to process."})},onError:S=>{H({tone:"error",title:"Dream failed",description:S instanceof Error?S.message:String(S)})}})},[q,H]),Fs=f.useCallback(()=>{a.current?.focus()},[]);f.useEffect(()=>{const S=()=>Fs();return window.addEventListener("focus-chat-input",S),()=>window.removeEventListener("focus-chat-input",S)},[Fs]);const an=[{id:"stop",label:"Stop",description:"Stop all working agents"},{id:"new",label:"New Chat",description:"Start a fresh team conversation"}],ln=f.useCallback(S=>{switch(S){case"stop":ee.getState().stopTeam();break;case"new":Ot();break}},[Ot]),cs=f.useCallback(()=>{x(S=>{const Z=Sn.indexOf(S);return Sn[(Z+1)%Sn.length]})},[]),xt=P.filter(S=>!ge.includes(S)),Pt=f.useCallback(()=>{if(!je)return;const S=xt[0];S&&W(je,S)},[je,xt,W]),ds=f.useCallback(()=>{if(!je)return;const S=xt[0];S&&M(je,S)},[je,xt,M]),Ws=f.useCallback(()=>{je&&Q(je)},[je,Q]),cn=Ap({viewMode:b,cycleViewMode:cs,setViewMode:x,setShowAgentSidebar:c,setShowFilesPanel:u,setShowTodos:h,handleNewSession:Ot,handleDreamRun:on,agentNames:P,leadName:A,openAgents:ge,focusedAgent:je,cycleActiveAgent:C,setActiveAgent:z,focusAgent:we,openAgent:Et,handleSplitDown:Pt,handleSplitRight:ds,handleClosePane:Ws,navigate:t});vp({n:Ot,v:n?void 0:cs,j:y==="unified"?Pt:void 0,k:y==="unified"?ds:void 0,w:y==="unified"?Ws:void 0,a:()=>c(S=>!S),f:()=>{_&&u(S=>!S)},t:()=>{_&&h(S=>!S)},p:n?void 0:()=>p(S=>!S),i:()=>window.dispatchEvent(new CustomEvent("focus-chat-input"))}),f.useEffect(()=>{const S=Z=>{if(!(Z.key!=="Tab"||Z.ctrlKey||Z.metaKey))if(Z.preventDefault(),y==="unified"){if(ge.length===0)return;const ce=je?ge.indexOf(je):-1,$t=Z.shiftKey?(ce-1+ge.length)%ge.length:(ce+1)%ge.length;we(ge[$t])}else C(Z.shiftKey?"prev":"next")};return window.addEventListener("keydown",S),()=>window.removeEventListener("keydown",S)},[y,ge,je,we,C]);const us=Se.panelOrder.length>0?Se.panelOrder:P;return s.jsxs("div",{className:"flex h-dvh bg-(--color-bg)",children:[s.jsx(np,{currentSessionId:_||void 0,onCommandPalette:n?void 0:()=>p(!0),onNewChat:Ot,mobileOpen:r,onMobileClose:()=>o(!1)}),s.jsxs("div",{ref:i,className:"relative flex min-w-0 flex-1 flex-col",children:[s.jsxs("header",{className:"flex items-center gap-1 border-b border-(--color-border) bg-(--color-bg) px-2 py-0 md:gap-0 md:px-4",children:[n&&s.jsx("button",{onClick:()=>o(!0),"aria-label":"Open navigation",className:"flex h-8 w-8 shrink-0 items-center justify-center rounded-md text-(--color-text-muted) transition-colors hover:bg-(--color-accent-subtle) hover:text-(--color-text)",children:s.jsx(sl,{size:16,"aria-hidden":"true"})}),s.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-0.5 overflow-x-auto",children:[y==="agent"&&P.map(S=>{const Z=L[S],ce=E===S,$t=Z?.status==="working";return s.jsxs("button",{onClick:()=>z(S),className:`flex shrink-0 items-center gap-1.5 rounded-lg px-2.5 py-1.5 text-xs font-medium transition-all ${ce?"bg-(--color-accent-subtle) text-(--color-accent)":"text-(--color-text-muted) hover:bg-(--color-accent-dim) hover:text-(--color-text-2)"}`,children:[s.jsx("span",{className:`h-1.5 w-1.5 rounded-full ${$t?"animate-pulse bg-(--color-accent)":Z?.status==="error"?"bg-(--color-error)":"bg-(--color-success)"}`}),S,S===A&&s.jsx("span",{className:"text-(--color-text-subtle)",children:"·"})]},S)}),y==="split"&&s.jsxs("span",{className:"text-xs text-(--color-text-muted)",children:["Split · ",us.length," agents · drag to reorder"]}),y==="unified"&&s.jsx(Op,{agentNames:P,agentStreams:L,leadName:A,openAgents:ge,focusedAgent:je,onFocusOpen:we,onOpenMinimized:Et,onClose:Q})]}),s.jsxs("div",{className:"flex shrink-0 items-center gap-1.5 py-2",children:[!n&&Dt>0&&s.jsxs("div",{className:"flex items-center gap-2 rounded-md px-2 py-1 text-xs text-(--color-text-muted)",title:`Prompt: ${ut.toLocaleString()} · Output: ${mt.toLocaleString()}${ft>0?` · Cached: ${ft.toLocaleString()}`:""}`,children:[s.jsx("span",{className:"text-(--color-text-muted)",children:"tokens"}),s.jsxs("span",{className:"font-mono text-(--color-text-2)",children:[es(ut),s.jsx("span",{className:"mx-0.5 text-(--color-text-subtle)",children:"/"}),es(mt),ft>0&&s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"mx-0.5 text-(--color-text-subtle)",children:"/"}),s.jsx("span",{className:"text-(--color-syn-operator)",children:es(ft)})]})]}),I&&s.jsx("span",{className:"inline-block h-1.5 w-1.5 animate-pulse rounded-full bg-(--color-accent)"})]}),q.isPending&&s.jsxs("div",{className:"flex items-center gap-1 rounded-md px-2 py-1 text-xs text-(--color-text-muted)",title:"Dream is running…",children:[s.jsx(Ps,{size:11,className:"animate-pulse","aria-hidden":"true"}),s.jsx("span",{className:"hidden sm:inline",children:"Dream…"})]}),!n&&y==="unified"&&xt.length>0&&s.jsxs("div",{className:"flex items-center gap-0.5",children:[s.jsx("button",{onClick:Pt,className:"flex items-center gap-1 rounded-lg px-2 py-1.5 text-xs text-(--color-text-muted) transition-colors hover:bg-(--color-accent-dim) hover:text-(--color-text-2)",title:"Split pane down (Ctrl+J)","aria-label":"Split pane down",children:s.jsx(nl,{size:12,"aria-hidden":"true"})}),s.jsx("button",{onClick:ds,className:"flex items-center gap-1 rounded-lg px-2 py-1.5 text-xs text-(--color-text-muted) transition-colors hover:bg-(--color-accent-dim) hover:text-(--color-text-2)",title:"Split pane right (Ctrl+K)","aria-label":"Split pane right",children:s.jsx(rl,{size:12,"aria-hidden":"true"})})]}),!n&&s.jsxs("div",{className:"flex items-center rounded-lg border border-(--color-border) bg-(--color-bg) p-0.5",children:[s.jsxs("button",{onClick:()=>x("agent"),className:`flex items-center gap-1.5 rounded-md px-2.5 py-1 text-xs transition-all ${b==="agent"?"bg-(--color-accent-subtle) text-(--color-accent)":"text-(--color-text-muted) hover:text-(--color-text-2)"}`,title:"Agent view (Ctrl+V)","aria-label":"Agent view","aria-pressed":b==="agent",children:[s.jsx(ol,{size:12,"aria-hidden":"true"}),"Agent"]}),s.jsxs("button",{onClick:()=>x("split"),className:`flex items-center gap-1.5 rounded-md px-2.5 py-1 text-xs transition-all ${b==="split"?"bg-(--color-accent-subtle) text-(--color-accent)":"text-(--color-text-muted) hover:text-(--color-text-2)"}`,title:"Split view (Ctrl+V)","aria-label":"Split view","aria-pressed":b==="split",children:[s.jsx(al,{size:12,"aria-hidden":"true"}),"Split"]}),s.jsxs("button",{onClick:()=>x("unified"),className:`flex items-center gap-1.5 rounded-md px-2.5 py-1 text-xs transition-all ${b==="unified"?"bg-(--color-accent-subtle) text-(--color-accent)":"text-(--color-text-muted) hover:text-(--color-text-2)"}`,title:"Unified view (Ctrl+V)","aria-label":"Unified view","aria-pressed":b==="unified",children:[s.jsx(il,{size:12,"aria-hidden":"true"}),"Unified"]})]}),s.jsxs(en,{open:m,onOpenChange:h,children:[s.jsxs(tn,{disabled:!_,className:"flex items-center gap-1.5 rounded-lg px-2.5 py-1.5 text-xs text-(--color-text-muted) transition-colors hover:bg-(--color-accent-dim) hover:text-(--color-text-2) disabled:cursor-not-allowed disabled:opacity-50",title:_?"Task list (Ctrl+T)":"No active session","aria-label":"Task list",children:[s.jsx(ll,{size:13,"aria-hidden":"true"}),s.jsx("span",{className:"hidden md:inline",children:"Todos"}),ne.some(S=>S.status==="in_progress")&&s.jsx("span",{className:"size-1.5 rounded-full bg-(--color-accent)"})]}),s.jsxs(sn,{side:"bottom",align:"end",className:"w-80 p-0",children:[s.jsxs("div",{className:"flex items-center justify-between border-b border-(--color-border) px-3 py-2",children:[s.jsx("span",{className:"text-xs font-semibold text-(--color-text)",children:"Tasks"}),ne.length>0&&s.jsxs("span",{className:"text-[10px] text-(--color-text-subtle)",children:[ne.filter(S=>S.status==="completed").length,"/",ne.length," done"]})]}),ne.length===0?s.jsx("p",{className:"px-3 py-4 text-center text-xs text-(--color-text-subtle)",children:"No tasks yet"}):s.jsx("ul",{className:"max-h-80 overflow-y-auto py-1",children:[...ne].sort((S,Z)=>{const ce={in_progress:0,pending:1,completed:2,cancelled:3};return ce[S.status]-ce[Z.status]}).map(S=>s.jsxs("li",{className:"flex items-start gap-2 px-3 py-1.5",children:[s.jsx("span",{className:"mt-0.5 shrink-0 text-[10px]",children:S.status==="completed"?"✓":S.status==="cancelled"?"✗":S.status==="in_progress"?"▶":"○"}),s.jsx("span",{className:`flex-1 text-xs leading-snug ${S.status==="completed"||S.status==="cancelled"?"text-(--color-text-subtle) line-through":"text-(--color-text)"}`,children:S.content}),s.jsx("span",{className:`shrink-0 self-start rounded px-1 py-0.5 text-[9px] font-medium uppercase ${S.priority==="high"?"bg-red-500/10 text-red-500":S.priority==="low"?"bg-(--color-accent-dim) text-(--color-text-subtle)":"bg-amber-500/10 text-amber-500"}`,children:S.priority})]},S.task_id))})]})]}),s.jsxs("button",{onClick:()=>u(S=>!S),disabled:!_,className:"flex items-center gap-1.5 rounded-lg px-2.5 py-1.5 text-xs text-(--color-text-muted) transition-colors hover:bg-(--color-accent-dim) hover:text-(--color-text-2) disabled:cursor-not-allowed disabled:opacity-50",title:_?"Workspace files (Ctrl+F)":"No active session","aria-label":"Workspace files",children:[s.jsx(cl,{size:13,"aria-hidden":"true"}),s.jsx("span",{className:"hidden md:inline",children:"Files"})]}),s.jsxs("button",{onClick:()=>c(S=>!S),className:"flex items-center gap-1.5 rounded-lg px-2.5 py-1.5 text-xs text-(--color-text-muted) transition-colors hover:bg-(--color-accent-dim) hover:text-(--color-text-2)",title:"Agent Capabilities (Ctrl+A)","aria-label":"Agent capabilities",children:[s.jsx(dl,{size:13,"aria-hidden":"true"}),s.jsx("span",{className:"hidden md:inline",children:"Agents"})]})]})]}),y==="split"&&us.length>0?s.jsx("div",{className:"min-h-0 flex-1 p-3",children:s.jsx(Ep,{panelOrder:us,leadName:A,agentStreams:L,draggingIdx:Se.draggingIdx,dropTargetIdx:Se.dropTargetIdx,onDragStart:Se.onDragStart,onDragOver:Se.onDragOver,onDrop:Se.onDrop,onDragEnd:Se.onDragEnd})}):y==="unified"?s.jsx(zp,{tileLayout:_t,agentStreams:L,leadName:A}):E&&L[E]?s.jsx(bf,{blocks:ae??L[E].blocks,currentBlocks:$e??L[E].currentBlocks,isWorking:(xe??L[E].status)==="working",isError:(xe??L[E].status)==="error",lastError:L[E].lastError}):s.jsxs("div",{className:"flex flex-1 flex-col items-center justify-center gap-3",children:[s.jsx(ed,{className:"text-(--color-text-subtle) opacity-25",width:64,height:64}),s.jsx("p",{className:"text-sm text-(--color-text-muted)",children:"Select an agent above"})]}),s.jsx(Dp,{ref:a,boundsRef:i,onSubmit:(S,Z)=>v(S,Z),onStop:()=>ee.getState().stopTeam(),onSlashCommand:ln,slashCommands:an,isStreaming:I,disabled:!1,autoFocus:!e,placeholder:q.isPending?"Dream is running…":I?"Team working… type to interrupt":"Message the team…",capabilities:kt})]}),s.jsx(dd,{open:l,agentNames:P,agentStreams:L,onClose:()=>c(!1)}),s.jsx(bp,{open:d,sessionId:_,onClose:()=>u(!1)}),!n&&g&&s.jsx(op,{commands:cn,onClose:()=>p(!1)})]})}function Wp(e,t){for(const n of t)switch(n.kind){case"wiki":e.invalidateQueries({queryKey:$.wiki.all()});break;case"workspace_files":e.invalidateQueries({queryKey:$.team.files(n.sessionId)});break;case"scheduler":e.invalidateQueries({queryKey:$.scheduler.list()});break;case"todos":e.invalidateQueries({queryKey:$.todos(n.sessionId)});break}}function Lp(){const t=Ds({strict:!1}).sessionId,n=Ve(),r=pe(),o=f.useRef(n),a=f.useRef(t);return f.useEffect(()=>{o.current=n,a.current=t}),f.useEffect(()=>ee.subscribe((i,l)=>{if(i.sessionId&&i.sessionId!==l.sessionId&&!a.current&&(r.invalidateQueries({queryKey:$.team.sessions.all()}),o.current({to:"/cockpit/$sessionId",params:{sessionId:i.sessionId},replace:!0})),i.sessionTitle&&i.sessionTitle!==l.sessionTitle&&i.sessionId){const c=i.sessionId,d=i.sessionTitle;r.setQueriesData({queryKey:$.team.sessions.all()},u=>u?.map(m=>m.id===c?{...m,title:d}:m))}i.cacheInvalidations!==l.cacheInvalidations&&i.cacheInvalidations.length>0&&Wp(r,ee.getState()._drainCacheInvalidations())}),[]),s.jsxs(s.Fragment,{children:[s.jsx(Fp,{sessionId:t}),s.jsx(ys,{})]})}function gt({...e}){return s.jsx(Vl,{"data-slot":"tooltip",...e})}function bt({...e}){return s.jsx(Xl,{"data-slot":"tooltip-trigger",...e})}function yt({className:e,side:t="top",sideOffset:n=4,align:r="center",alignOffset:o=0,children:a,...i}){return s.jsx(Zl,{children:s.jsx(Jl,{align:r,alignOffset:o,side:t,sideOffset:n,className:"isolate z-50",children:s.jsxs(ec,{"data-slot":"tooltip-content",className:T("z-50 inline-flex w-fit max-w-xs origin-(--transform-origin) items-center gap-1.5 rounded-md bg-foreground px-3 py-1.5 text-xs text-background has-data-[slot=kbd]:pr-1.5 data-[side=bottom]:slide-in-from-top-2 data-[side=inline-end]:slide-in-from-left-2 data-[side=inline-start]:slide-in-from-right-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 **:data-[slot=kbd]:relative **:data-[slot=kbd]:isolate **:data-[slot=kbd]:z-50 **:data-[slot=kbd]:rounded-sm data-[state=delayed-open]:animate-in data-[state=delayed-open]:fade-in-0 data-[state=delayed-open]:zoom-in-95 data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95",e),...i,children:[a,s.jsx(tc,{className:"z-50 size-2.5 translate-y-[calc(-50%-2px)] rotate-45 rounded-[2px] bg-foreground fill-foreground data-[side=bottom]:top-1 data-[side=inline-end]:top-1/2! data-[side=inline-end]:-left-1 data-[side=inline-end]:-translate-y-1/2 data-[side=inline-start]:top-1/2! data-[side=inline-start]:-right-1 data-[side=inline-start]:-translate-y-1/2 data-[side=left]:top-1/2! data-[side=left]:-right-1 data-[side=left]:-translate-y-1/2 data-[side=right]:top-1/2! data-[side=right]:-left-1 data-[side=right]:-translate-y-1/2 data-[side=top]:-bottom-2.5"})]})})})}const ir={agents:{title:"Agents",placeholder:"Search agents…",detailRoute:"/settings/agents/$name",newRoute:"/settings/agents/new",newLabel:"New agent",emptyTitle:"No agents yet",emptyBody:"Define a team member with a model, tools, and a system prompt."},skills:{title:"Skills",placeholder:"Search skills…",detailRoute:"/settings/skills/$name",newRoute:"/settings/skills/new",newLabel:"New skill",emptyTitle:"No skills yet",emptyBody:"Reusable instruction modules agents load on demand."},mcp:{title:"MCP servers",placeholder:"Search servers…",detailRoute:"/settings/mcp/$name",newRoute:"/settings/mcp/new",newLabel:"New server",emptyTitle:"No MCP servers yet",emptyBody:"External tool providers via Model Context Protocol."}},Ip={ready:"bg-green-500",starting:"bg-yellow-500",error:"bg-destructive",stopped:"bg-muted-foreground/40"};function Zr({kind:e}){switch(e){case"agents":return s.jsx(Bp,{});case"skills":return s.jsx(Yp,{});case"mcp":return s.jsx(qp,{})}}function Bp(){const{data:e,isLoading:t,isError:n}=ba(),r=f.useMemo(()=>e?.agents.map(o=>({name:o.name,subtitle:o.description||o.model||"No description",icon:o.role==="lead"?ul:os,iconTone:o.role==="lead"?"accent":"muted",invalid:!o.valid,invalidReason:o.error??void 0}))??[],[e?.agents]);return s.jsx(lr,{meta:ir.agents,rows:r,isLoading:t,isError:n})}function Yp(){const{data:e,isLoading:t,isError:n}=va(),r=f.useMemo(()=>e?.skills.map(o=>({name:o.name,subtitle:o.description||"No description",icon:ns,iconTone:"muted",invalid:!o.valid,invalidReason:o.error??void 0}))??[],[e?.skills]);return s.jsx(lr,{meta:ir.skills,rows:r,isLoading:t,isError:n})}function qp(){const{data:e,isLoading:t,isError:n}=Jn(),r=f.useMemo(()=>e?.servers.map(o=>({name:o.name,subtitle:`${o.transport}${o.enabled?"":" · disabled"}`,icon:rs,iconTone:"muted",mcpStatus:o}))??[],[e?.servers]);return s.jsx(lr,{meta:ir.mcp,rows:r,isLoading:t,isError:n})}function lr({meta:e,rows:t,isLoading:n,isError:r}){const o=Ye(),{name:a}=Ds({strict:!1}),[i,l]=f.useState(""),c=f.useMemo(()=>{const d=i.trim().toLowerCase();return d?t.filter(u=>u.name.toLowerCase().includes(d)||u.subtitle.toLowerCase().includes(d)):t},[t,i]);return s.jsxs("aside",{"aria-label":e.title,className:o?"flex h-full min-h-0 flex-1 flex-col border-r-0 bg-background":"flex h-full w-72 shrink-0 flex-col border-r border-border bg-background",children:[s.jsxs("header",{className:"flex h-14 shrink-0 items-center gap-2 border-b border-border px-3",children:[o&&s.jsx(Te,{to:"/settings","aria-label":"Back to settings",className:"flex h-8 w-8 shrink-0 items-center justify-center rounded-md text-muted-foreground transition-colors hover:bg-muted hover:text-foreground",children:s.jsx(Be,{size:16,"aria-hidden":"true"})}),s.jsx("h2",{className:"flex-1 truncate text-sm font-semibold",children:e.title}),s.jsxs(gt,{children:[s.jsx(bt,{render:s.jsx(Y,{size:"icon-sm",variant:"ghost","aria-label":e.newLabel,render:s.jsx(Te,{to:e.newRoute}),children:s.jsx(ct,{size:14})})}),s.jsx(yt,{children:e.newLabel})]})]}),t.length>0&&s.jsx("div",{className:"border-b border-border p-2",children:s.jsxs("div",{className:"relative",children:[s.jsx(_s,{size:12,className:"pointer-events-none absolute top-1/2 left-2.5 -translate-y-1/2 text-muted-foreground","aria-hidden":"true"}),s.jsx(oe,{value:i,onChange:d=>l(d.target.value),placeholder:e.placeholder,"aria-label":e.placeholder,className:"h-8 pl-7 text-sm"})]})}),s.jsxs("div",{className:"min-h-0 flex-1 overflow-y-auto",children:[n&&s.jsx("p",{className:"px-3 py-6 text-center text-xs text-muted-foreground",children:"Loading…"}),r&&s.jsx("p",{className:"px-3 py-6 text-center text-xs text-destructive",children:"Failed to load."}),!n&&!r&&t.length===0&&s.jsxs("div",{className:"flex flex-col items-center gap-3 px-4 py-10 text-center",children:[s.jsx("p",{className:"text-sm font-medium",children:e.emptyTitle}),s.jsx("p",{className:"text-xs leading-relaxed text-muted-foreground",children:e.emptyBody}),s.jsxs(Y,{size:"sm",render:s.jsx(Te,{to:e.newRoute}),children:[s.jsx(ct,{size:12,"aria-hidden":"true"}),e.newLabel]})]}),!n&&!r&&t.length>0&&c.length===0&&s.jsxs("p",{className:"px-3 py-6 text-center text-xs text-muted-foreground",children:["No matches for “",i,"”."]}),!n&&!r&&c.length>0&&s.jsx("ul",{className:"px-1 py-1.5",children:c.map(d=>s.jsx("li",{children:s.jsx(Hp,{row:d,detailRoute:e.detailRoute,active:a===d.name})},d.name))})]})]})}function Hp({row:e,detailRoute:t,active:n}){const r=e.icon;return s.jsxs(Te,{to:t,params:{name:e.name},"aria-current":n?"page":void 0,className:T("flex items-center gap-2.5 rounded-md px-2 py-1.5 transition-colors","hover:bg-muted","focus-visible:outline-none focus-visible:ring-3 focus-visible:ring-ring/40",n&&"bg-muted"),children:[s.jsx("span",{className:T("flex h-7 w-7 shrink-0 items-center justify-center rounded-md ring-1",e.iconTone==="accent"?"bg-foreground/5 text-foreground ring-border":"bg-muted text-muted-foreground ring-border"),"aria-hidden":"true",children:s.jsx(r,{size:13})}),s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx("span",{className:T("truncate text-sm",n?"font-semibold text-foreground":"font-medium"),children:e.name}),e.invalid&&s.jsxs(gt,{children:[s.jsx(bt,{render:s.jsx("span",{className:"text-destructive",children:s.jsx(Ie,{size:11,"aria-label":"Invalid configuration"})})}),s.jsx(yt,{children:e.invalidReason??"Invalid configuration"})]})]}),e.subtitle&&s.jsx("p",{className:"truncate text-[11px] text-muted-foreground",children:e.subtitle})]}),e.mcpStatus&&s.jsx(Up,{server:e.mcpStatus})]})}function Up({server:e}){return e.state==="error"?s.jsx("span",{className:"flex shrink-0 items-center text-destructive",title:e.error??"Server failed to start","aria-label":`Error: ${e.error??"unknown"}`,children:s.jsx(Ie,{size:12})}):s.jsx("span",{className:T("h-2 w-2 shrink-0 rounded-full",Ip[e.state]),title:e.state,"aria-label":`State: ${e.state}`})}const Jr=[{to:"/settings/agents",label:"Agents",icon:os,matchPrefix:"/settings/agents"},{to:"/settings/skills",label:"Skills",icon:ns,matchPrefix:"/settings/skills"},{to:"/settings/mcp",label:"MCP servers",icon:rs,matchPrefix:"/settings/mcp"},{to:"/settings/sandbox",label:"Sandbox",icon:Oo,matchPrefix:"/settings/sandbox"},{to:"/settings/dream",label:"Dream",icon:Ps,matchPrefix:"/settings/dream"}];function Qp(){const{pathname:e}=go(),t=f.useMemo(()=>Jr.find(r=>e===r.matchPrefix||e.startsWith(`${r.matchPrefix}/`))?.matchPrefix??null,[e]);return s.jsxs("nav",{"aria-label":"Settings categories",className:"flex h-full w-14 shrink-0 flex-col items-center gap-1 border-r border-border bg-muted/30 py-3",children:[s.jsxs(gt,{children:[s.jsx(bt,{render:s.jsx(Te,{to:"/","aria-label":"Exit settings",className:T("flex h-9 w-9 items-center justify-center rounded-lg transition-colors","text-muted-foreground hover:bg-muted hover:text-foreground","focus-visible:outline-none focus-visible:ring-3 focus-visible:ring-ring/40"),children:s.jsx(Be,{size:16,"aria-hidden":"true"})})}),s.jsx(yt,{side:"right",children:"Exit settings"})]}),s.jsx("div",{className:"my-1.5 h-px w-6 shrink-0 bg-border",role:"separator","aria-hidden":"true"}),Jr.map(n=>{const r=t===n.matchPrefix,o=n.icon;return s.jsxs(gt,{children:[s.jsx(bt,{render:s.jsx(Te,{to:n.to,"aria-label":n.label,"aria-current":r?"page":void 0,className:T("flex h-9 w-9 items-center justify-center rounded-lg transition-colors","text-muted-foreground hover:bg-muted hover:text-foreground","focus-visible:outline-none focus-visible:ring-3 focus-visible:ring-ring/40",r&&"bg-foreground/10 text-foreground ring-1 ring-border hover:bg-foreground/10"),children:s.jsx(o,{size:16,"aria-hidden":"true"})})}),s.jsx(yt,{side:"right",children:n.label})]},n.to)})]})}function Kp(e){return e.startsWith("/settings/agents")?"agents":e.startsWith("/settings/skills")?"skills":e.startsWith("/settings/mcp")?"mcp":null}function Gp(e){return e.startsWith("/settings/agents/")||e.startsWith("/settings/skills/")||e.startsWith("/settings/mcp/")||e==="/settings/sandbox"||e==="/settings/dream"||e==="/settings"}function Vp(){const{pathname:e}=go(),t=Ye(),n=Kp(e),r=Gp(e);return t?s.jsx("div",{className:"flex h-dvh flex-col overflow-hidden bg-background text-foreground",children:r?s.jsx("main",{className:"flex min-h-0 flex-1 flex-col overflow-y-auto",children:s.jsx(ys,{})}):n?s.jsx(Zr,{kind:n}):s.jsx("main",{className:"flex min-h-0 flex-1 flex-col overflow-y-auto",children:s.jsx(ys,{})})}):s.jsxs("div",{className:"flex h-dvh overflow-hidden bg-background text-foreground",children:[s.jsx(Qp,{}),n&&s.jsx(Zr,{kind:n}),s.jsx("main",{className:"flex min-w-0 flex-1 flex-col",children:s.jsx(ys,{})})]})}function ps({to:e,icon:t,title:n,description:r,count:o,countLabel:a}){return s.jsxs(Te,{to:e,className:T("group flex items-center gap-4 rounded-xl border border-border bg-card/40 p-4 transition-all","hover:border-border/80 hover:bg-card focus-visible:border-ring focus-visible:outline-none focus-visible:ring-3 focus-visible:ring-ring/40"),children:[s.jsx("span",{className:"flex h-10 w-10 shrink-0 items-center justify-center rounded-lg bg-muted text-muted-foreground ring-1 ring-border transition-colors group-hover:text-foreground","aria-hidden":"true",children:s.jsx(t,{size:18})}),s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"truncate text-sm font-semibold",children:n}),s.jsxs("span",{className:"rounded-full bg-muted px-2 py-0.5 font-mono text-[10px] tabular-nums text-muted-foreground",children:[o===null?"–":o," ",a]})]}),s.jsx("p",{className:"mt-0.5 truncate text-xs text-muted-foreground",children:r})]}),s.jsx(Es,{size:16,className:"shrink-0 text-muted-foreground transition-transform group-hover:translate-x-0.5 group-hover:text-foreground","aria-hidden":"true"})]})}function eo({children:e}){return s.jsx("h2",{className:"mb-2 px-1 text-[11px] font-medium tracking-wider text-muted-foreground uppercase",children:e})}function Xp(){const e=Ye(),t=ba(),n=va(),r=Jn(),o=ka(),a=t.data?.agents.length??null,i=n.data?.skills.length??null,l=r.data?.servers.length??null,c=o.data?.denied_patterns.length??null;return s.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto",children:s.jsxs("div",{className:"mx-auto max-w-3xl space-y-8 p-4 md:p-8",children:[s.jsxs("header",{className:"flex items-center gap-3",children:[e&&s.jsx(Te,{to:"/cockpit","aria-label":"Back to chat",className:"flex h-8 w-8 shrink-0 items-center justify-center rounded-md text-muted-foreground transition-colors hover:bg-muted hover:text-foreground",children:s.jsx(Be,{size:16,"aria-hidden":"true"})}),s.jsx("span",{className:"flex h-10 w-10 items-center justify-center rounded-xl bg-muted text-muted-foreground ring-1 ring-border","aria-hidden":"true",children:s.jsx(Wn,{size:18})}),s.jsxs("div",{children:[s.jsx("h1",{className:"text-lg font-semibold",children:"Settings"}),s.jsx("p",{className:"text-xs text-muted-foreground",children:"Configure your workspace and the agents that run in it."})]})]}),s.jsxs("section",{children:[s.jsx(eo,{children:"Workspace"}),s.jsxs("div",{className:"space-y-2",children:[s.jsx(ps,{to:"/settings/agents",icon:os,title:"Agents",description:"Define and edit your agent team — model, tools, system prompt",count:a,countLabel:a===1?"agent":"agents"}),s.jsx(ps,{to:"/settings/skills",icon:ns,title:"Skills",description:"Reusable instruction modules agents load on demand",count:i,countLabel:i===1?"skill":"skills"}),s.jsx(ps,{to:"/settings/mcp",icon:rs,title:"MCP servers",description:"External tool providers via Model Context Protocol",count:l,countLabel:l===1?"server":"servers"})]})]}),s.jsxs("section",{children:[s.jsx(eo,{children:"System"}),s.jsxs("div",{className:"space-y-2",children:[s.jsx(ps,{to:"/settings/sandbox",icon:Oo,title:"Sandbox",description:"Files and folders agents cannot access",count:c,countLabel:c===1?"pattern":"patterns"}),s.jsx(ps,{to:"/settings/dream",icon:Ps,title:"Dream",description:"Cron agent that synthesises sessions into wiki topics",count:null,countLabel:""})]})]})]})})}function cr({icon:e,title:t,body:n,ctaTo:r,ctaLabel:o,tips:a}){return s.jsx("div",{className:"flex h-full items-center justify-center p-10",children:s.jsxs("div",{className:"flex max-w-md flex-col items-center gap-4 text-center",children:[s.jsx("div",{className:"flex h-14 w-14 items-center justify-center rounded-2xl bg-muted ring-1 ring-border",children:s.jsx(e,{size:22,className:"text-muted-foreground","aria-hidden":"true"})}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("h2",{className:"text-base font-semibold",children:t}),s.jsx("p",{className:"text-sm leading-relaxed text-muted-foreground",children:n})]}),s.jsxs(Y,{size:"sm",render:s.jsx(Te,{to:r}),children:[s.jsx(ct,{size:12,"aria-hidden":"true"}),o]}),a&&a.length>0&&s.jsx("ul",{className:"mt-2 w-full space-y-1.5 rounded-lg border border-border bg-card/40 p-3 text-left text-xs text-muted-foreground",children:a.map((i,l)=>s.jsxs("li",{className:"flex gap-2",children:[s.jsx("span",{"aria-hidden":"true",children:"•"}),s.jsx("span",{children:i})]},l))})]})})}function Zp(){return s.jsx(cr,{icon:os,title:"Select an agent",body:"Pick an agent from the list, or create a new one to define a model, tools, skills, and a system prompt.",ctaTo:"/settings/agents/new",ctaLabel:"New agent",tips:["Lead agents coordinate the team; workers run focused tasks.","Tools and skills are referenced by name from the agent’s frontmatter."]})}function Me({className:e,size:t="default",...n}){return s.jsx("div",{"data-slot":"card","data-size":t,className:T("group/card flex flex-col gap-4 overflow-hidden rounded-xl bg-card py-4 text-sm text-card-foreground ring-1 ring-foreground/10 has-data-[slot=card-footer]:pb-0 has-[>img:first-child]:pt-0 data-[size=sm]:gap-3 data-[size=sm]:py-3 data-[size=sm]:has-data-[slot=card-footer]:pb-0 *:[img:first-child]:rounded-t-xl *:[img:last-child]:rounded-b-xl",e),...n})}function Oe({className:e,...t}){return s.jsx("div",{"data-slot":"card-header",className:T("group/card-header @container/card-header grid auto-rows-min items-start gap-1 rounded-t-xl px-4 group-data-[size=sm]/card:px-3 has-data-[slot=card-action]:grid-cols-[1fr_auto] has-data-[slot=card-description]:grid-rows-[auto_auto] [.border-b]:pb-4 group-data-[size=sm]/card:[.border-b]:pb-3",e),...t})}function Pe({className:e,...t}){return s.jsx("div",{"data-slot":"card-title",className:T("font-heading text-base leading-snug font-medium group-data-[size=sm]/card:text-sm",e),...t})}function Ae({className:e,...t}){return s.jsx("div",{"data-slot":"card-description",className:T("text-sm text-muted-foreground",e),...t})}function De({className:e,...t}){return s.jsx("div",{"data-slot":"card-content",className:T("px-4 group-data-[size=sm]/card:px-3",e),...t})}function Cn({options:e,value:t,onChange:n,placeholder:r="Select…",emptyLabel:o="No matches",searchId:a}){const[i,l]=f.useState(!1),[c,d]=f.useState(""),[u,m]=f.useState(0),h=f.useRef(null),g=f.useMemo(()=>new Set(t),[t]),p=f.useMemo(()=>{const k=c.trim().toLowerCase();return k?e.filter(C=>C.value.toLowerCase().includes(k)||C.label.toLowerCase().includes(k)||C.description?.toLowerCase().includes(k)):e},[e,c]),[b,x]=f.useState(p.length);b!==p.length&&(x(p.length),m(k=>Math.min(k,Math.max(p.length-1,0))));const[y,j]=f.useState(i);y!==i&&(j(i),i||(d(""),m(0)));const w=k=>{g.has(k)?n(t.filter(C=>C!==k)):n([...t,k])},N=k=>n(t.filter(C=>C!==k)),v=k=>{if(k.key==="ArrowDown")k.preventDefault(),m(C=>Math.min(C+1,p.length-1));else if(k.key==="ArrowUp")k.preventDefault(),m(C=>Math.max(C-1,0));else if(k.key==="Enter"){k.preventDefault();const C=p[u];C&&w(C.value)}else k.key==="Escape"?(k.preventDefault(),l(!1)):k.key==="Backspace"&&c===""&&t.length>0&&(k.preventDefault(),N(t[t.length-1]))};return s.jsxs(en,{open:i,onOpenChange:l,children:[s.jsx(tn,{render:s.jsxs("div",{role:"combobox","aria-expanded":i,"aria-haspopup":"listbox",tabIndex:0,className:T("flex min-h-8 w-full cursor-text flex-wrap items-center gap-1 rounded-lg border border-input bg-transparent px-1.5 py-1 text-sm transition-colors outline-none","focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50","aria-expanded:border-ring","dark:bg-input/30"),children:[t.length===0&&s.jsx("span",{className:"px-1.5 text-muted-foreground",children:r}),t.map(k=>s.jsxs("span",{className:"flex items-center gap-1 rounded-sm bg-muted px-1.5 py-0.5 font-mono text-xs text-foreground",children:[k,s.jsx("button",{type:"button",onMouseDown:C=>C.stopPropagation(),onClick:C=>{C.preventDefault(),C.stopPropagation(),N(k)},"aria-label":`Remove ${k}`,className:"text-muted-foreground transition-colors hover:text-foreground",children:s.jsx(Ee,{size:11})})]},k)),s.jsx(Xe,{size:14,className:"ml-auto shrink-0 self-center text-muted-foreground","aria-hidden":"true"})]})}),s.jsxs(sn,{align:"start",sideOffset:4,className:"w-[--anchor-width] min-w-72 max-w-[28rem] p-0",children:[s.jsxs("div",{className:"flex items-center gap-2 border-b border-border px-2.5 py-2",children:[s.jsx(_s,{size:13,className:"shrink-0 text-muted-foreground","aria-hidden":"true"}),s.jsx("input",{id:a,ref:h,autoFocus:!0,value:c,onChange:k=>d(k.target.value),onKeyDown:v,placeholder:"Search…",className:"flex-1 bg-transparent text-sm outline-none placeholder:text-muted-foreground","aria-label":"Search options"}),s.jsxs("span",{className:"shrink-0 text-[11px] text-muted-foreground",children:[p.length,"/",e.length]})]}),s.jsx("ul",{role:"listbox","aria-multiselectable":!0,className:"max-h-64 overflow-y-auto py-1",children:p.length===0?s.jsx("li",{className:"px-3 py-4 text-center text-sm text-muted-foreground",children:o}):p.map((k,C)=>{const z=g.has(k.value),q=C===u;return s.jsx("li",{children:s.jsxs("button",{type:"button",role:"option","aria-selected":z,onMouseDown:H=>H.preventDefault(),onClick:()=>{w(k.value),h.current?.focus()},onMouseEnter:()=>m(C),className:T("flex w-full items-start gap-2 px-2.5 py-1.5 text-left transition-colors",q&&"bg-muted"),children:[s.jsx("span",{className:T("mt-0.5 flex h-4 w-4 shrink-0 items-center justify-center rounded-sm border text-foreground transition-colors",z?"border-foreground bg-foreground text-background":"border-input"),"aria-hidden":"true",children:z&&s.jsx(vt,{size:10,strokeWidth:3})}),s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsx("p",{className:"truncate font-mono text-xs text-foreground",children:k.label}),k.description&&s.jsx("p",{className:"truncate text-[11px] text-muted-foreground",children:k.description})]})]})},k.value)})})]})]})}const Jp=/^\s*---\r?\n([\s\S]*?)\r?\n---\r?\n?([\s\S]*)$/;function ss(e){const t=Jp.exec(e);return t?{fm:t[1],body:t[2].replace(/^\r?\n/,"")}:{fm:"",body:e}}function e0(e){const t=[];if(t.push(`name: ${e.name}`),t.push(`role: ${e.role}`),e.description&&t.push(`description: ${r0(e.description)}`),e.model&&t.push(`model: ${e.model}`),e.fallback_model&&t.push(`fallback_model: ${e.fallback_model}`),e.temperature!=null&&!Number.isNaN(e.temperature)&&t.push(`temperature: ${e.temperature}`),e.thinking_level&&t.push(`thinking_level: ${e.thinking_level}`),e.tools&&e.tools.length>0){t.push("tools:");for(const n of[...e.tools].sort())t.push(` - ${n}`)}if(e.skills&&e.skills.length>0){t.push("skills:");for(const n of[...e.skills].sort())t.push(` - ${n}`)}if(e.mcp&&e.mcp.length>0){t.push("mcp:");for(const n of[...e.mcp].sort())t.push(` - ${n}`)}return t.join(`
|
|
40
|
+
`)}function t0(e,t){return`---
|
|
41
|
+
${e0(e)}
|
|
42
|
+
---
|
|
43
|
+
|
|
44
|
+
${t.trim()}
|
|
45
|
+
`}function Za(e,t){if(e===t)return!0;const n=ss(e),r=ss(t);if(n.body.replace(/\s+$/,"")!==r.body.replace(/\s+$/,""))return!1;const o=to(n.fm),a=to(r.fm);return o===null||a===null?n.fm.trim()===r.fm.trim():s0(o,a)}function s0(e,t){const n=new Set([...Object.keys(e),...Object.keys(t)]);for(const r of n){const o=e[r],a=t[r];if(Array.isArray(o)&&Array.isArray(a)){if(o.length!==a.length)return!1;const i=[...o].map(c=>String(c)).sort(),l=[...a].map(c=>String(c)).sort();for(let c=0;c<i.length;c++)if(i[c]!==l[c])return!1;continue}if(o!==a)return!1}return!0}function to(e){const t={},n=e.split(/\r?\n/);let r=null,o=null;for(const a of n){const i=a.replace(/\s+$/,"");if(!i.trim()||i.trim().startsWith("#"))continue;const l=/^\s+-\s+(.*)$/.exec(i);if(o&&l){o.push(so(l[1]));continue}const c=/^([A-Za-z_][\w-]*):\s*(.*)$/.exec(i);if(!c)return null;const[,d,u]=c;if(r=d,o=null,u===""){o=[],t[r]=o;continue}t[r]=n0(so(u))}return t}function so(e){const t=e.trim();return t.startsWith('"')&&t.endsWith('"')||t.startsWith("'")&&t.endsWith("'")?t.slice(1,-1).replace(/\\"/g,'"').replace(/\\\\/g,"\\"):t}function n0(e){if(e==="true")return!0;if(e==="false")return!1;if(e==="null"||e==="~"||e==="")return null;const t=Number(e);return!Number.isNaN(t)&&e.trim()!==""?t:e}function r0(e){return/[:#\n]/.test(e)||/^[\s-!&*?|<>=%@`]/.test(e)||/^\s|\s$/.test(e)||e===""||["true","false","null","yes","no","on","off"].includes(e.toLowerCase())?`"${e.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}"`:e}const dr=Ft().min(1,"Required").max(64,"Max 64 characters").regex(/^[a-zA-Z0-9][a-zA-Z0-9._-]*$/,"Use letters, digits, '.', '_', '-' only (must start with a letter or digit)"),An=Ft().regex(/^[a-zA-Z0-9_-]+:[^\s]+$/,"Expected 'provider:model' (e.g. 'openai:gpt-5.4')"),Ja=Mi().min(0,"Must be ≥ 0").max(2,"Must be ≤ 2"),o0=jo(["lead","member"]),a0=jo(["","none","low","medium","high"]),ei=Ft().max(500,"Max 500 characters"),i0=dr,l0=Ft().min(1,"Required — shown to agents when they browse skills").max(500,"Max 500 characters"),c0=wo({name:i0,description:l0});function d0(e){const t=c0.safeParse(e);if(t.success)return null;const n={};for(const r of t.error.issues){const o=r.path.join(".")||"_root";o in n||(n[o]=r.message)}return n}const u0=wo({name:dr,role:o0,description:ei.nullable().optional(),model:An,fallback_model:An.nullable().optional(),temperature:Ja.nullable().optional(),thinking_level:a0.nullable().optional(),tools:mn(Ft()).optional(),skills:mn(Ft()).optional(),mcp:mn(Ft()).optional()});function m0(e){const t=u0.safeParse(e);if(t.success)return null;const n={};for(const r of t.error.issues){const o=r.path.join(".")||"_root";o in n||(n[o]=r.message)}return n}function ur(e,t){const n=e.safeParse(t);return n.success?null:n.error.issues[0]?.message??"Invalid"}function f0(e){return ur(dr,e)}function no(e,t={}){return e?ur(An,e):t.required?"Required":null}function x0(e){return e?ur(ei,e):null}function ti(e){const{fm:t}=ss(e);if(!t.trim())return{_root:"Missing YAML frontmatter (needs --- … --- header)."};let n;try{n=ni(t)}catch(r){return{_root:r.message}}return m0(n)}function si(e){const{fm:t}=ss(e);if(!t.trim())return{_root:"Missing YAML frontmatter (needs --- … --- header)."};let n;try{n=ni(t)}catch(r){return{_root:r.message}}return d0(n)}function ni(e){const t={},n=e.split(/\r?\n/);let r=null;for(const o of n){const a=o.replace(/\s+$/,"");if(!a.trim()||a.trim().startsWith("#"))continue;const i=/^\s+-\s+(.*)$/.exec(a);if(r&&i){r.push(ro(i[1]));continue}const l=/^([A-Za-z_][\w-]*):\s*(.*)$/.exec(a);if(!l)continue;const[,c,d]=l;if(r=null,d===""){r=[],t[c]=r;continue}t[c]=h0(ro(d))}return t}function ro(e){const t=e.trim();return t.startsWith('"')&&t.endsWith('"')||t.startsWith("'")&&t.endsWith("'")?t.slice(1,-1).replace(/\\"/g,'"').replace(/\\\\/g,"\\"):t}function h0(e){if(e==="true")return!0;if(e==="false")return!1;if(e==="null"||e==="~"||e==="")return null;const t=Number(e);return!Number.isNaN(t)&&e.trim()!==""?t:e}function p0(e){const t=e.trim();if(t==="")return{ok:!0,value:null};if(t==="-"||t==="."||t==="-.")return{ok:"pending"};if(!/^-?\d*\.?\d*$/.test(t))return{ok:!1,error:"Not a number"};const n=Number(t);if(Number.isNaN(n))return{ok:!1,error:"Not a number"};const r=Ja.safeParse(n);return r.success?{ok:!0,value:r.data}:{ok:!1,error:r.error.issues[0]?.message??"Invalid"}}const g0=[{value:"__none__",label:"(default)"},{value:"none",label:"none"},{value:"low",label:"low"},{value:"medium",label:"medium"},{value:"high",label:"high"}];function ri({initial:e,onChange:t,disabled:n,isNew:r,mode:o,onModeChange:a}){const[i,l]=f.useState(e),c=f.useMemo(()=>Tn(e),[e]),[d,u]=f.useState(c.fm),[m,h]=f.useState(c.body),[g,p]=f.useState(c.error),[b,x]=f.useState(e);e!==b&&(x(e),l(e),u(c.fm),h(c.body),p(c.error));const[y,j]=f.useState(o);if(o!==y&&(j(o),o==="form")){const E=Tn(i);u(E.fm),h(E.body),p(E.error)}const w=_f(),N=Jn(),v=w.data?.tools.filter(E=>!E.name.startsWith("mcp_")).map(E=>({value:E.name,label:E.name,description:E.description}))??[],k=w.data?.skills.map(E=>({value:E.name,label:E.name,description:E.description}))??[],C=N.data?.servers.map(E=>{const L=E.tool_names.length,P=`${E.transport} · ${E.state} · ${L} tool${L===1?"":"s"}`;return{value:E.name,label:E.name,description:P}})??[],z=w.data?.models??[],q=(E,L)=>{u(E),h(L);const P=t0(E,L);l(P),t(P),p(null)},H=E=>{l(E),t(E);const L=Tn(E);u(L.fm),h(L.body),p(L.error)};return s.jsxs("div",{className:"flex flex-col gap-4",children:[g&&s.jsx(b0,{message:g,onSwitchToRaw:()=>a("raw")}),o==="form"?s.jsx(y0,{fm:d,body:m,disabled:n,isNew:r,toolOptions:v,skillOptions:k,mcpOptions:C,modelOptions:z,updateFromForm:q}):s.jsxs(Me,{size:"sm",children:[s.jsxs(Oe,{children:[s.jsx(Pe,{children:"Raw .md"}),s.jsx(Ae,{children:"Edit the raw frontmatter and body. Useful for fields the form doesn’t expose (e.g. nested summarization blocks)."})]}),s.jsx(De,{children:s.jsx(Ht,{value:i,onChange:E=>H(E.target.value),disabled:n,rows:28,spellCheck:!1,className:"font-mono text-[13px] leading-relaxed"})})]})]})}function b0({message:e,onSwitchToRaw:t}){return s.jsxs("div",{className:"flex items-start gap-2 rounded-lg border border-destructive/30 bg-destructive/10 px-3 py-2 text-xs text-destructive",children:[s.jsx(Ie,{size:14,className:"mt-0.5 shrink-0"}),s.jsxs("div",{className:"flex-1",children:[s.jsx("p",{className:"font-medium",children:"Parse error"}),s.jsx("p",{className:"mt-0.5 opacity-90",children:e})]}),s.jsx(Y,{size:"xs",variant:"outline",onClick:t,children:"Open raw"})]})}function y0({fm:e,body:t,disabled:n,isNew:r,toolOptions:o,skillOptions:a,mcpOptions:i,modelOptions:l,updateFromForm:c}){const[d,u]=f.useState(e.temperature==null?"":String(e.temperature)),[m,h]=f.useState(null),g=r?f0(e.name):null,p=x0(e.description??""),b=no(e.model??"",{required:!0}),x=no(e.fallback_model??""),y=j=>{u(j);const w=p0(j);w.ok===!0?(h(null),c({...e,temperature:w.value},t)):w.ok==="pending"?h(null):h(w.error)};return s.jsxs("div",{className:"flex flex-col gap-4",children:[s.jsxs(Me,{size:"sm",children:[s.jsxs(Oe,{children:[s.jsx(Pe,{children:"Identity"}),s.jsx(Ae,{children:"Who is this agent and what is its role?"})]}),s.jsxs(De,{className:"grid gap-4 md:grid-cols-2",children:[s.jsx(Ze,{label:"Name",required:!0,error:g,hint:r?"Letters, digits, ., _, - only.":"Filename stem; cannot be renamed after creation.",children:s.jsx(oe,{type:"text",value:e.name,onChange:j=>c({...e,name:j.target.value},t),disabled:n||!r,placeholder:"orchestrator","aria-invalid":!!g||void 0,className:"font-mono"})}),s.jsx(Ze,{label:"Role",required:!0,hint:"Exactly one agent in the team must be lead.",children:s.jsxs(Ss,{value:e.role,onValueChange:j=>j&&c({...e,role:j},t),disabled:n,children:[s.jsx(Ts,{className:"w-full",children:s.jsx(Cs,{})}),s.jsxs(Ms,{children:[s.jsx(ts,{value:"lead",children:"Lead"}),s.jsx(ts,{value:"member",children:"Member"})]})]})}),s.jsx(Ze,{label:"Description",error:p,className:"md:col-span-2",hint:"One-line summary shown when the lead browses the team.",children:s.jsx(oe,{type:"text",value:e.description??"",onChange:j=>c({...e,description:j.target.value||null},t),disabled:n,placeholder:"Coordinates the team. Breaks tasks, delegates to members.","aria-invalid":!!p||void 0})})]})]}),s.jsxs(Me,{size:"sm",children:[s.jsxs(Oe,{children:[s.jsx(Pe,{children:"Model & behaviour"}),s.jsx(Ae,{children:"Which provider, plus sampling temperature and reasoning depth."})]}),s.jsxs(De,{className:"grid gap-4 md:grid-cols-2",children:[s.jsx(Ze,{label:"Model",required:!0,error:b,className:"md:col-span-2",children:s.jsx(oo,{value:e.model??"",options:l,onChange:j=>c({...e,model:j},t),disabled:n,invalid:!!b})}),s.jsx(Ze,{label:"Fallback model",error:x,hint:"Used when the primary model errors out.",className:"md:col-span-2",children:s.jsx(oo,{value:e.fallback_model??"",options:l,allowEmpty:!0,onChange:j=>c({...e,fallback_model:j||null},t),disabled:n,invalid:!!x})}),s.jsx(Ze,{label:"Temperature",error:m,hint:"0 – 2; higher = more random.",children:s.jsx(oe,{type:"text",inputMode:"decimal",value:d,onChange:j=>y(j.target.value),disabled:n,placeholder:"0.2","aria-invalid":!!m||void 0,className:"font-mono"})}),s.jsx(Ze,{label:"Thinking level",hint:"How much hidden reasoning the model may use.",children:s.jsxs(Ss,{value:e.thinking_level?e.thinking_level:"__none__",onValueChange:j=>{j!=null&&c({...e,thinking_level:j==="__none__"?null:j},t)},disabled:n,children:[s.jsx(Ts,{className:"w-full",children:s.jsx(Cs,{})}),s.jsx(Ms,{children:g0.map(j=>s.jsx(ts,{value:j.value,children:j.label},j.value))})]})})]})]}),s.jsxs(Me,{size:"sm",children:[s.jsxs(Oe,{children:[s.jsx(Pe,{children:"Capabilities"}),s.jsx(Ae,{children:"Tools the agent may invoke, MCP servers it has access to, and skills it can load on demand."})]}),s.jsxs(De,{className:"flex flex-col gap-4",children:[s.jsx(Ze,{label:"Tools",hint:`${(e.tools??[]).length} selected of ${o.length} available.`,children:s.jsx(Cn,{options:o,value:e.tools??[],onChange:j=>c({...e,tools:j},t),placeholder:"Pick tools this agent may invoke…"})}),s.jsx(Ze,{label:"MCP servers",hint:i.length===0?"No MCP servers configured. Add one under Settings → MCP.":`${(e.mcp??[]).length} selected of ${i.length} available. Each grants every tool the server exposes.`,children:s.jsx(Cn,{options:i,value:e.mcp??[],onChange:j=>c({...e,mcp:j},t),placeholder:"Pick MCP servers this agent may use…",emptyLabel:"No matching servers"})}),s.jsx(Ze,{label:"Skills",hint:`${(e.skills??[]).length} selected of ${a.length} available.`,children:s.jsx(Cn,{options:a,value:e.skills??[],onChange:j=>c({...e,skills:j},t),placeholder:"Pick skills the agent can load on demand…"})})]})]}),s.jsxs(Me,{size:"sm",children:[s.jsxs(Oe,{children:[s.jsx(Pe,{children:"System prompt"}),s.jsx(Ae,{children:"The instructions placed at the top of every conversation with this agent."})]}),s.jsx(De,{children:s.jsx(Ht,{value:t,onChange:j=>c(e,j.target.value),disabled:n,rows:14,placeholder:"You are …",className:"font-mono text-[13px] leading-relaxed"})})]})]})}function oo({value:e,onChange:t,options:n,disabled:r,allowEmpty:o,invalid:a}){const i=!e||n.some(m=>m.id===e),[l,c]=f.useState(!i&&!!e),d=l||!i&&!!e,u=f.useMemo(()=>{const m=new Map;for(const h of n)m.has(h.provider)||m.set(h.provider,[]),m.get(h.provider).push(h);return m},[n]);return d?s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(oe,{type:"text",value:e,onChange:m=>t(m.target.value),disabled:r,placeholder:"provider:model","aria-invalid":a||void 0,className:"flex-1 font-mono"}),s.jsx(Y,{type:"button",size:"sm",variant:"ghost",onClick:()=>{c(!1),i||t("")},children:"Use list"})]}):s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsxs(Ss,{value:e||void 0,onValueChange:m=>t(m??""),disabled:r,children:[s.jsx(Ts,{className:T("flex-1",a&&"aria-invalid:border-destructive"),"aria-invalid":a||void 0,children:s.jsx(Cs,{placeholder:o?"(none)":"Select a model…"})}),s.jsx(Ms,{children:[...u.entries()].map(([m,h])=>s.jsxs(_h,{children:[s.jsx(Eh,{children:m}),h.map(g=>s.jsxs(ts,{value:g.id,className:"font-mono",children:[g.model,g.vision?" · vision":""]},g.id))]},m))})]}),s.jsx(Y,{type:"button",size:"sm",variant:"ghost",onClick:()=>c(!0),children:"Custom"})]})}function Ze({label:e,required:t,className:n,children:r,error:o,hint:a}){return s.jsxs("div",{className:T("flex flex-col gap-1.5",n),children:[s.jsxs("span",{className:"text-xs font-medium text-foreground",children:[e,t&&s.jsx("span",{className:"ml-0.5 text-destructive",children:"*"})]}),r,o?s.jsx("p",{className:"text-[11px] text-destructive",children:o}):a?s.jsx("p",{className:"text-[11px] text-muted-foreground",children:a}):null]})}function Tn(e){const{fm:t,body:n}=ss(e),r={name:"",role:"member"};if(!t.trim())return{fm:r,body:n,error:"Missing YAML frontmatter (needs --- … --- header)."};try{const o=v0(t);return typeof o.name=="string"&&(r.name=o.name),(o.role==="lead"||o.role==="member")&&(r.role=o.role),typeof o.description=="string"&&(r.description=o.description),typeof o.model=="string"&&(r.model=o.model),typeof o.fallback_model=="string"&&(r.fallback_model=o.fallback_model),typeof o.temperature=="number"&&(r.temperature=o.temperature),typeof o.thinking_level=="string"&&(r.thinking_level=o.thinking_level),Array.isArray(o.tools)&&(r.tools=o.tools.filter(a=>typeof a=="string")),Array.isArray(o.skills)&&(r.skills=o.skills.filter(a=>typeof a=="string")),Array.isArray(o.mcp)&&(r.mcp=o.mcp.filter(a=>typeof a=="string")),{fm:r,body:n,error:null}}catch(o){return{fm:r,body:n,error:String(o.message??o)}}}function v0(e){const t={},n=e.split(/\r?\n/);let r=null,o=null;for(const a of n){const i=a.replace(/\s+$/,"");if(!i.trim()||i.trim().startsWith("#"))continue;const l=/^\s+-\s+(.*)$/.exec(i);if(o&&l){o.push(ao(l[1]));continue}const c=/^([A-Za-z_][\w-]*):\s*(.*)$/.exec(i);if(!c)continue;const[,d,u]=c;if(r=d,o=null,u===""){o=[],t[r]=o;continue}t[r]=j0(ao(u))}return t}function ao(e){const t=e.trim();return t.startsWith('"')&&t.endsWith('"')||t.startsWith("'")&&t.endsWith("'")?t.slice(1,-1).replace(/\\"/g,'"').replace(/\\\\/g,"\\"):t}function j0(e){if(e==="true")return!0;if(e==="false")return!1;if(e==="null"||e==="~"||e==="")return null;const t=Number(e);return!Number.isNaN(t)&&e.trim()!==""?t:e}function is({name:e,path:t,kind:n,dirty:r,invalid:o,saving:a,error:i,validationHint:l,mode:c,onModeChange:d,onSave:u}){const m=n==="agent"?os:n==="skill"?ns:rs,h=n==="agent"?"/settings/agents":n==="skill"?"/settings/skills":"/settings/mcp",g=c!=null&&d!=null,p=!r||o||a,b=o?l??"Fix validation errors":r?null:"No unsaved changes";return s.jsxs("header",{className:"sticky top-0 z-10 flex h-14 items-center gap-3 border-b border-border bg-background px-4",children:[s.jsxs(gt,{children:[s.jsx(bt,{render:s.jsx(Y,{size:"icon-sm",variant:"ghost",render:s.jsx(Te,{to:h,"aria-label":"Back to list"}),children:s.jsx(Be,{size:14})})}),s.jsx(yt,{children:"Back"})]}),s.jsx("span",{className:"flex h-7 w-7 shrink-0 items-center justify-center rounded-md bg-muted text-muted-foreground ring-1 ring-border","aria-hidden":"true",children:s.jsx(m,{size:13})}),s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsx("p",{className:"truncate text-sm font-semibold leading-tight",children:e}),t&&s.jsx("p",{className:"truncate font-mono text-[10px] text-muted-foreground",children:t})]}),g&&s.jsx(nn,{value:c,onValueChange:x=>d(x),children:s.jsxs(rn,{className:"h-7",children:[s.jsxs(lt,{value:"form",className:"px-2 text-xs",children:[s.jsx(ml,{size:11,"aria-hidden":"true"}),"Form"]}),s.jsxs(lt,{value:"raw",className:"px-2 text-xs",children:[s.jsx(fl,{size:11,"aria-hidden":"true"}),"Raw"]})]})}),s.jsxs("div",{className:"flex items-center gap-2",children:[i&&s.jsxs(gt,{children:[s.jsx(bt,{render:s.jsxs("span",{className:"flex items-center gap-1 rounded-md bg-destructive/10 px-2 py-1 text-xs text-destructive",children:[s.jsx(Ie,{size:11}),"Error"]})}),s.jsx(yt,{children:i})]}),!i&&o&&l&&s.jsxs(gt,{children:[s.jsx(bt,{render:s.jsxs("span",{className:"flex items-center gap-1 rounded-md bg-destructive/10 px-2 py-1 text-xs text-destructive",children:[s.jsx(Ie,{size:11}),"Invalid"]})}),s.jsx(yt,{children:l})]}),!i&&!o&&r&&s.jsxs("span",{className:"flex items-center gap-1.5 text-xs text-muted-foreground",children:[s.jsx("span",{className:T("h-1.5 w-1.5 rounded-full bg-foreground",a?"animate-pulse":""),"aria-hidden":"true"}),"Unsaved"]}),b?s.jsxs(gt,{children:[s.jsx(bt,{render:s.jsxs(Y,{size:"sm",onClick:u,disabled:p,"aria-label":a?"Saving":"Save",children:[s.jsx(ws,{size:12,"aria-hidden":"true"}),a?"Saving…":"Save"]})}),s.jsx(yt,{children:b})]}):s.jsxs(Y,{size:"sm",onClick:u,disabled:p,children:[s.jsx(ws,{size:12,"aria-hidden":"true"}),a?"Saving…":"Save"]})]})]})}function w0(){const{name:e}=Ds({from:"/settings/agents/$name"}),t=Ve(),n=Ge(k=>k.push),{data:r,isLoading:o,isError:a,error:i,refetch:l}=Df(e),c=Of(),[d,u]=f.useState(()=>r?.content??""),[m,h]=f.useState(null),[g,p]=f.useState("form"),[b,x]=f.useState(!!r?.content);!b&&r?.content&&(x(!0),u(r.content));const y=!!r&&!Za(d,r.content),j=y?ti(d):null,w=j!==null,N=j?Object.values(j)[0]:null,v=async()=>{if(h(null),w){h(N??"Form has validation errors.");return}try{const k=await c.mutateAsync({name:e,content:d});n({tone:"success",title:`Saved "${e}"`,description:"Active on next turn."}),u(k.content),l()}catch(k){const C=k instanceof Mt?k.message:String(k);h(C),n({tone:"error",title:"Save failed",description:C})}};return s.jsxs("div",{className:"flex h-full flex-col",children:[s.jsx(is,{kind:"agent",name:e,path:r?.path,dirty:y,invalid:w,saving:c.isPending,error:m,validationHint:N,mode:g,onModeChange:p,onSave:v}),s.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto",children:s.jsxs("div",{className:"mx-auto max-w-3xl p-6",children:[o&&s.jsx("p",{className:"text-sm text-muted-foreground",children:"Loading…"}),a&&s.jsxs("p",{className:"text-sm text-destructive",children:["Failed to load: ",String(i)]}),r&&s.jsx(ri,{initial:r.content,onChange:u,disabled:c.isPending,isNew:!1,mode:g,onModeChange:p}),y&&s.jsxs("div",{className:"mt-4 flex items-center gap-2 text-xs text-muted-foreground",children:[s.jsx(Y,{variant:"ghost",size:"xs",onClick:()=>r&&u(r.content),children:"Discard changes"}),s.jsx(Y,{variant:"ghost",size:"xs",onClick:()=>t({to:"/settings/agents"}),children:"Leave without saving"})]})]})})]})}const Mn=`---
|
|
46
|
+
name: new_agent
|
|
47
|
+
role: member
|
|
48
|
+
description: A helpful team member.
|
|
49
|
+
model: googlegenai:gemini-3.1-flash-lite-preview
|
|
50
|
+
temperature: 0.2
|
|
51
|
+
tools:
|
|
52
|
+
- date
|
|
53
|
+
- read
|
|
54
|
+
- write
|
|
55
|
+
---
|
|
56
|
+
|
|
57
|
+
You are "new_agent" — a helpful team member.
|
|
58
|
+
|
|
59
|
+
## Style
|
|
60
|
+
- Be concise.
|
|
61
|
+
- Ask clarifying questions when requirements are ambiguous.
|
|
62
|
+
`;function k0(){const[e,t]=f.useState(Mn),[n,r]=f.useState("new_agent"),o=Ef(),a=Ge(x=>x.push),i=Ve(),[l,c]=f.useState(null),[d,u]=f.useState("form"),m=x=>{t(x);const y=/^\s*---[\s\S]*?name:\s*([A-Za-z0-9._-]+)/m.exec(x);y&&r(y[1])},h=ti(e),g=h!==null,p=h?Object.values(h)[0]:null,b=async()=>{if(c(null),g){c(p??"Form has validation errors.");return}try{await o.mutateAsync({name:n,content:e}),a({tone:"success",title:`Created "${n}"`,description:"Active on next turn."}),i({to:"/settings/agents/$name",params:{name:n}})}catch(x){const y=x instanceof Mt?x.message:String(x);c(y),a({tone:"error",title:"Create failed",description:y})}};return s.jsxs("div",{className:"flex h-full flex-col",children:[s.jsx(is,{kind:"agent",name:"New agent",dirty:e!==Mn,invalid:g,saving:o.isPending,error:l,validationHint:p,mode:d,onModeChange:u,onSave:b}),s.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto",children:s.jsx("div",{className:"mx-auto max-w-3xl p-6",children:s.jsx(ri,{initial:Mn,onChange:m,disabled:o.isPending,isNew:!0,mode:d,onModeChange:u})})})]})}function N0(){return s.jsx(cr,{icon:ns,title:"Select a skill",body:"Skills are reusable instruction modules agents load on demand via the skill tool.",ctaTo:"/settings/skills/new",ctaLabel:"New skill",tips:["Skills can include scripts, references, and templates.","Reference a skill from an agent’s frontmatter to make it available."]})}function S0(){const{name:e}=Ds({from:"/settings/skills/$name"}),t=Ve(),n=Ge(N=>N.push),{data:r,isLoading:o,isError:a,error:i,refetch:l}=Pf(e),c=zf(),[d,u]=f.useState(()=>r?.content??""),[m,h]=f.useState(null),[g,p]=f.useState(!!r?.content);!g&&r?.content&&(p(!0),u(r.content));const b=!!r&&!Za(d,r.content),x=b?si(d):null,y=x!==null,j=x?Object.values(x)[0]:null,w=async()=>{if(h(null),y){h(j??"Form has validation errors.");return}try{const N=await c.mutateAsync({name:e,content:d});n({tone:"success",title:`Saved "${e}"`,description:"Active on next turn."}),u(N.content),l()}catch(N){const v=N instanceof Mt?N.message:String(N);h(v),n({tone:"error",title:"Save failed",description:v})}};return s.jsxs("div",{className:"flex h-full flex-col",children:[s.jsx(is,{kind:"skill",name:e,path:r?.path,dirty:b,invalid:y,saving:c.isPending,error:m,validationHint:j,onSave:w}),s.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto",children:s.jsxs("div",{className:"mx-auto max-w-3xl p-6",children:[o&&s.jsx("p",{className:"text-sm text-muted-foreground",children:"Loading…"}),a&&s.jsxs("p",{className:"text-sm text-destructive",children:["Failed to load: ",String(i)]}),r&&s.jsxs(Me,{size:"sm",children:[s.jsxs(Oe,{children:[s.jsx(Pe,{children:"Skill source"}),s.jsxs(Ae,{children:["Frontmatter (",s.jsx("span",{className:"font-mono",children:"name"}),","," ",s.jsx("span",{className:"font-mono",children:"description"}),") is required; the body is the instruction the agent loads on demand."]})]}),s.jsx(De,{children:s.jsx(Ht,{value:d,onChange:N=>u(N.target.value),disabled:c.isPending,rows:28,spellCheck:!1,"aria-invalid":y||void 0,className:"font-mono text-[13px] leading-relaxed"})})]}),b&&s.jsxs("div",{className:"mt-4 flex items-center gap-2 text-xs text-muted-foreground",children:[s.jsx(Y,{variant:"ghost",size:"xs",onClick:()=>r&&u(r.content),children:"Discard changes"}),s.jsx(Y,{variant:"ghost",size:"xs",onClick:()=>t({to:"/settings/skills"}),children:"Leave without saving"})]})]})})]})}const io=`---
|
|
63
|
+
name: new-skill
|
|
64
|
+
description: One-line description shown to agents when they see the skill list.
|
|
65
|
+
---
|
|
66
|
+
|
|
67
|
+
# New skill
|
|
68
|
+
|
|
69
|
+
Replace this with the instructions an agent should follow when applying
|
|
70
|
+
this skill. Keep it focused on a single concern.
|
|
71
|
+
`;function C0(){const[e,t]=f.useState(io),[n,r]=f.useState("new-skill"),o=$f(),a=Ge(p=>p.push),i=Ve(),[l,c]=f.useState(null),d=p=>{t(p);const b=/^\s*---[\s\S]*?name:\s*([A-Za-z0-9._-]+)/m.exec(p);b&&r(b[1])},u=si(e),m=u!==null,h=u?Object.values(u)[0]:null,g=async()=>{if(c(null),m){c(h??"Form has validation errors.");return}try{await o.mutateAsync({name:n,content:e}),a({tone:"success",title:`Created skill "${n}"`,description:"Active on next turn."}),i({to:"/settings/skills/$name",params:{name:n}})}catch(p){const b=p instanceof Mt?p.message:String(p);c(b),a({tone:"error",title:"Create failed",description:b})}};return s.jsxs("div",{className:"flex h-full flex-col",children:[s.jsx(is,{kind:"skill",name:"New skill",dirty:e!==io,invalid:m,saving:o.isPending,error:l,validationHint:h,onSave:g}),s.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto",children:s.jsx("div",{className:"mx-auto max-w-3xl p-6",children:s.jsxs(Me,{size:"sm",children:[s.jsxs(Oe,{children:[s.jsx(Pe,{children:"Skill source"}),s.jsxs(Ae,{children:["Frontmatter (",s.jsx("span",{className:"font-mono",children:"name"}),","," ",s.jsx("span",{className:"font-mono",children:"description"}),") is required; the body is the instruction the agent loads on demand."]})]}),s.jsx(De,{children:s.jsx(Ht,{value:e,onChange:p=>d(p.target.value),disabled:o.isPending,rows:28,spellCheck:!1,"aria-invalid":m||void 0,className:"font-mono text-[13px] leading-relaxed"})})]})})})]})}function T0(){return s.jsx(cr,{icon:rs,title:"Select an MCP server",body:"MCP servers expose tools and resources to your agents over stdio or HTTP.",ctaTo:"/settings/mcp/new",ctaLabel:"New MCP server",tips:["Stdio servers run locally as a child process; HTTP servers are remote.","Use restart from the detail view if a server fails to start."]})}function oi({value:e,onChange:t,isNew:n,disabled:r,errors:o}){const a=i=>t({...e,...i});return s.jsxs("div",{className:"flex flex-col gap-4",children:[s.jsxs(Me,{size:"sm",children:[s.jsxs(Oe,{children:[s.jsx(Pe,{children:"Identity"}),s.jsx(Ae,{children:"How agents and the runtime address this server."})]}),s.jsxs(De,{className:"grid gap-4 md:grid-cols-2",children:[s.jsx(gs,{label:"Name",required:!0,error:o?.name,hint:n?"Letters, digits, _ or -; must start with a letter.":"Persisted key in mcp.json; cannot be renamed.",children:s.jsx(oe,{value:e.name,onChange:i=>a({name:i.target.value}),disabled:r||!n,placeholder:"filesystem","aria-invalid":!!o?.name||void 0,className:"font-mono"})}),s.jsx(gs,{label:"Status",hint:e.enabled?"Server is started at runtime.":"Server is left stopped.",children:s.jsx(M0,{value:e.enabled,onChange:i=>a({enabled:i}),disabled:r})})]})]}),s.jsxs(Me,{size:"sm",children:[s.jsxs(Oe,{children:[s.jsx(Pe,{children:"Transport"}),s.jsx(Ae,{children:"How the runtime talks to the server process."})]}),s.jsx(De,{children:s.jsx(nn,{value:e.transport,onValueChange:i=>a({transport:i}),children:s.jsxs(rn,{className:"grid w-full grid-cols-2",children:[s.jsx(lt,{value:"stdio",disabled:r,children:"Stdio"}),s.jsx(lt,{value:"http",disabled:r,children:"HTTP"})]})})})]}),e.transport==="stdio"&&s.jsxs(Me,{size:"sm",children:[s.jsxs(Oe,{children:[s.jsx(Pe,{children:"Stdio configuration"}),s.jsx(Ae,{children:"The runtime spawns a subprocess and speaks MCP over stdin/stdout."})]}),s.jsxs(De,{className:"flex flex-col gap-4",children:[s.jsx(gs,{label:"Command",required:!0,error:o?.command,hint:"Executable to launch (looked up on PATH).",children:s.jsx(oe,{value:e.command,onChange:i=>a({command:i.target.value}),disabled:r,placeholder:"npx","aria-invalid":!!o?.command||void 0,className:"font-mono"})}),s.jsx(gs,{label:"Arguments",hint:"One per line, in order.",children:s.jsx(Ht,{value:e.argsText,onChange:i=>a({argsText:i.target.value}),disabled:r,rows:4,spellCheck:!1,placeholder:`-y
|
|
72
|
+
@modelcontextprotocol/server-filesystem
|
|
73
|
+
/tmp`,className:"font-mono text-[13px] leading-relaxed"})}),s.jsx(co,{label:"Environment variables",keyPlaceholder:"KEY",valuePlaceholder:"value",error:o?.env,pairs:e.envPairs,onChange:i=>a({envPairs:i}),disabled:r})]})]}),e.transport==="http"&&s.jsxs(Me,{size:"sm",children:[s.jsxs(Oe,{children:[s.jsx(Pe,{children:"HTTP configuration"}),s.jsx(Ae,{children:"The runtime opens a Streamable HTTP session against the URL."})]}),s.jsxs(De,{className:"flex flex-col gap-4",children:[s.jsx(gs,{label:"URL",required:!0,error:o?.url,hint:"Streamable HTTP endpoint (full URL incl. scheme).",children:s.jsx(oe,{value:e.url,onChange:i=>a({url:i.target.value}),disabled:r,placeholder:"https://mcp.example.com/v1","aria-invalid":!!o?.url||void 0,className:"font-mono"})}),s.jsx(co,{label:"Headers",keyPlaceholder:"Header-Name",valuePlaceholder:"value",error:o?.headers,pairs:e.headerPairs,onChange:i=>a({headerPairs:i}),disabled:r})]})]})]})}function gs({label:e,required:t,className:n,children:r,error:o,hint:a}){return s.jsxs("div",{className:T("flex flex-col gap-1.5",n),children:[s.jsxs("span",{className:"text-xs font-medium text-foreground",children:[e,t&&s.jsx("span",{className:"ml-0.5 text-destructive",children:"*"})]}),r,o?s.jsx("p",{className:"text-[11px] text-destructive",children:o}):a?s.jsx("p",{className:"text-[11px] text-muted-foreground",children:a}):null]})}function M0({value:e,onChange:t,disabled:n}){return s.jsxs("div",{role:"radiogroup","aria-label":"Server enabled state",className:"inline-flex h-9 rounded-md bg-muted p-0.5 ring-1 ring-border",children:[s.jsx(lo,{active:e,onClick:()=>t(!0),disabled:n,label:"Enabled"}),s.jsx(lo,{active:!e,onClick:()=>t(!1),disabled:n,label:"Disabled"})]})}function lo({active:e,onClick:t,disabled:n,label:r}){return s.jsx("button",{type:"button",role:"radio","aria-checked":e,disabled:n,onClick:t,className:T("flex-1 rounded-sm px-3 text-xs font-medium transition-colors",e?"bg-background text-foreground shadow-sm":"text-muted-foreground hover:text-foreground",n&&"cursor-not-allowed opacity-50"),children:r})}function co({label:e,keyPlaceholder:t,valuePlaceholder:n,error:r,pairs:o,onChange:a,disabled:i}){const l=(u,m)=>a(o.map((h,g)=>g===u?{...h,...m}:h)),c=u=>a(o.filter((m,h)=>h!==u)),d=()=>a([...o,{key:"",value:""}]);return s.jsxs("div",{className:"flex flex-col gap-1.5",children:[s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsx("span",{className:"text-xs font-medium text-foreground",children:e}),s.jsxs(Y,{size:"xs",variant:"ghost",onClick:d,disabled:i,"aria-label":`Add ${e.toLowerCase()}`,children:[s.jsx(ct,{size:11,"aria-hidden":"true"}),"Add"]})]}),o.length===0?s.jsx("p",{className:"text-[11px] text-muted-foreground",children:"None."}):s.jsx("div",{className:"flex flex-col gap-1.5",children:o.map((u,m)=>s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx(oe,{value:u.key,onChange:h=>l(m,{key:h.target.value}),disabled:i,placeholder:t,className:"flex-1 font-mono text-xs"}),s.jsx(oe,{value:u.value,onChange:h=>l(m,{value:h.target.value}),disabled:i,placeholder:n,className:"flex-1 font-mono text-xs"}),s.jsx(Y,{size:"icon-xs",variant:"ghost",onClick:()=>c(m),disabled:i,"aria-label":`Remove ${u.key||"entry"}`,children:s.jsx(Os,{size:12})})]},m))}),r&&s.jsx("p",{className:"text-[11px] text-destructive",children:r})]})}const D0=/^[a-zA-Z][a-zA-Z0-9_-]*$/;function _0(){return{name:"",transport:"stdio",enabled:!0,command:"",argsText:"",envPairs:[],url:"",headerPairs:[]}}function E0(e,t){return t.transport==="stdio"?{name:e,transport:"stdio",enabled:t.enabled,command:t.command,argsText:t.args.join(`
|
|
74
|
+
`),envPairs:Object.entries(t.env).map(([n,r])=>({key:n,value:r})),url:"",headerPairs:[]}:{name:e,transport:"http",enabled:t.enabled,command:"",argsText:"",envPairs:[],url:t.url,headerPairs:Object.entries(t.headers).map(([n,r])=>({key:n,value:r}))}}function ai(e){return e.transport==="stdio"?e.command.trim()?{ok:!0,body:{transport:"stdio",command:e.command.trim(),args:e.argsText.split(`
|
|
75
|
+
`).map(t=>t.trim()).filter(Boolean),env:uo(e.envPairs),enabled:e.enabled}}:{ok:!1,error:"Command is required for stdio servers."}:e.url.trim()?{ok:!0,body:{transport:"http",url:e.url.trim(),headers:uo(e.headerPairs),enabled:e.enabled}}:{ok:!1,error:"URL is required for HTTP servers."}}function uo(e){return Object.fromEntries(e.filter(t=>t.key.trim()).map(t=>[t.key,t.value]))}function ii(e,t){const n={};t.isNew&&(e.name.trim()?D0.test(e.name)||(n.name="Name must start with a letter and contain only letters, digits, _ or -."):n.name="Name is required."),e.transport==="stdio"?e.command.trim()||(n.command="Command is required."):e.url.trim()||(n.url="URL is required.");const r=mo(e.envPairs);r&&(n.env=`Duplicate environment variable: ${r}`);const o=mo(e.headerPairs);return o&&(n.headers=`Duplicate header: ${o}`),Object.keys(n).length===0?null:n}function mo(e){const t=new Set;for(const n of e){const r=n.key.trim();if(r){if(t.has(r))return r;t.add(r)}}return null}function O0(e,t){return e.name!==t.name||e.transport!==t.transport||e.enabled!==t.enabled?!1:e.transport==="stdio"?e.command!==t.command||e.argsText!==t.argsText?!1:fo(e.envPairs,t.envPairs):e.url!==t.url?!1:fo(e.headerPairs,t.headerPairs)}function fo(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n].key!==t[n].key||e[n].value!==t[n].value)return!1;return!0}const Vt={..._0(),name:"new-server",command:"npx",argsText:`-y
|
|
76
|
+
@modelcontextprotocol/server-filesystem
|
|
77
|
+
/tmp`};function P0(e){return e.name===Vt.name&&e.transport===Vt.transport&&e.enabled===Vt.enabled&&e.command===Vt.command&&e.argsText===Vt.argsText&&e.envPairs.length===0&&e.url===""&&e.headerPairs.length===0}function $0(){const[e,t]=f.useState(Vt),[n,r]=f.useState(null),o=Qf(),a=Ge(h=>h.push),i=Ve(),l=ii(e,{isNew:!0}),c=l!==null,d=l?Object.values(l)[0]:null,u=!P0(e),m=async()=>{if(r(null),c){r(d??"Form has validation errors.");return}const h=ai(e);if(!h.ok){r(h.error);return}try{await o.mutateAsync({name:e.name,server:h.body}),a({tone:"success",title:`Created MCP server "${e.name}"`,description:"Available on next turn."}),i({to:"/settings/mcp/$name",params:{name:e.name}})}catch(g){const p=g instanceof Mt?g.message:String(g);r(p),a({tone:"error",title:"Create failed",description:p})}};return s.jsxs("div",{className:"flex h-full flex-col",children:[s.jsx(is,{kind:"mcp",name:"New MCP server",dirty:u,invalid:c,saving:o.isPending,error:n,validationHint:d,onSave:m}),s.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto",children:s.jsx("div",{className:"mx-auto max-w-3xl p-6",children:s.jsx(oi,{value:e,onChange:t,isNew:!0,disabled:o.isPending,errors:l})})})]})}function z0(){const{name:e}=Ds({from:"/settings/mcp/$name"}),t=Ve(),n=Ge(N=>N.push),r=Uf(e),o=Kf(),a=Gf(),i=f.useMemo(()=>{const N=r.data?.config;return N?E0(e,N):null},[e,r.data?.config]),[l,c]=f.useState(i),[d,u]=f.useState(null),[m,h]=f.useState(null);i&&m!==e&&(h(e),c(i),u(null));const g=!!i&&!!l&&!O0(l,i),p=l?ii(l,{isNew:!1}):null,b=p!==null,x=p?Object.values(p)[0]:null,y=async()=>{if(!l)return;if(u(null),b){u(x??"Form has validation errors.");return}const N=ai(l);if(!N.ok){u(N.error);return}try{await o.mutateAsync({name:e,server:N.body}),n({tone:"success",title:`Saved "${e}"`,description:"Available on next turn."})}catch(v){const k=v instanceof Mt?v.message:String(v);u(k),n({tone:"error",title:"Save failed",description:k})}},j=async()=>{try{await a.mutateAsync(e),n({tone:"success",title:`Restarted "${e}"`})}catch(N){const v=N instanceof Mt?N.message:String(N);n({tone:"error",title:`Failed to restart "${e}"`,description:v})}},w=r.data;return s.jsxs("div",{className:"flex h-full flex-col",children:[s.jsx(is,{kind:"mcp",name:e,path:".openagentd/config/mcp.json",dirty:g,invalid:b,saving:o.isPending,error:d,validationHint:x,onSave:y}),s.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto",children:s.jsxs("div",{className:"mx-auto flex max-w-3xl flex-col gap-4 p-6",children:[r.isLoading&&s.jsx("p",{className:"text-sm text-muted-foreground",children:"Loading server…"}),r.isError&&s.jsxs("p",{className:"text-sm text-destructive",children:["Failed to load: ",String(r.error)]}),w&&s.jsxs(s.Fragment,{children:[s.jsx(R0,{server:w}),w.state==="error"&&w.error&&s.jsxs(Me,{size:"sm",className:"border-destructive/40 bg-destructive/5",children:[s.jsx(Oe,{children:s.jsxs(Pe,{className:"flex items-center gap-2",children:[s.jsx(Ie,{size:14,className:"text-destructive"}),"Runtime error"]})}),s.jsx(De,{children:s.jsx("p",{className:"font-mono text-xs text-destructive",children:w.error})})]}),l?s.jsx(oi,{value:l,onChange:c,isNew:!1,disabled:o.isPending,errors:p}):s.jsx(Me,{size:"sm",children:s.jsx(De,{className:"pt-4",children:s.jsxs("p",{className:"text-xs text-muted-foreground",children:["No saved configuration found. The server may have been removed from ",s.jsx("span",{className:"font-mono",children:"mcp.json"}),"."]})})}),g&&s.jsxs("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[s.jsx(Y,{variant:"ghost",size:"xs",onClick:()=>i&&c(i),children:"Discard changes"}),s.jsx(Y,{variant:"ghost",size:"xs",onClick:()=>t({to:"/settings/mcp"}),children:"Leave without saving"})]}),s.jsx(A0,{onRestart:j,pending:a.isPending,enabled:w.enabled})]})]})})]})}function R0({server:e}){return s.jsxs(Me,{size:"sm",children:[s.jsxs(Oe,{children:[s.jsx(Pe,{children:"Runtime status"}),s.jsx(Ae,{children:"Live state of the running connection."})]}),s.jsxs(De,{className:"grid gap-3 text-xs sm:grid-cols-2",children:[s.jsx(Is,{label:"State",children:s.jsx("span",{className:e.state==="ready"?"text-green-600 dark:text-green-500":e.state==="starting"?"text-yellow-600 dark:text-yellow-500":e.state==="error"?"text-destructive":"text-muted-foreground",children:e.state})}),s.jsx(Is,{label:"Transport",children:s.jsx("span",{className:"font-mono",children:e.transport})}),s.jsx(Is,{label:"Enabled",children:e.enabled?"yes":"no"}),s.jsx(Is,{label:"Started",children:e.started_at?new Date(e.started_at).toLocaleString():"—"}),e.tool_names.length>0&&s.jsxs("div",{className:"sm:col-span-2",children:[s.jsxs("p",{className:"mb-1.5 text-xs font-medium text-foreground",children:["Tools (",e.tool_names.length,")"]}),s.jsx("div",{className:"flex flex-wrap gap-1",children:e.tool_names.map(t=>s.jsx("span",{className:"rounded-md bg-muted px-1.5 py-0.5 font-mono text-[11px] text-muted-foreground",children:t},t))})]})]})]})}function Is({label:e,children:t}){return s.jsxs("div",{className:"flex flex-col gap-0.5",children:[s.jsx("span",{className:"text-[11px] text-muted-foreground",children:e}),s.jsx("span",{className:"font-medium text-foreground",children:t})]})}function A0({onRestart:e,pending:t,enabled:n}){return s.jsxs(Me,{size:"sm",children:[s.jsxs(Oe,{children:[s.jsx(Pe,{children:"Connection"}),s.jsx(Ae,{children:"Restart the server process without changing its configuration."})]}),s.jsxs(De,{children:[s.jsxs(Y,{variant:"outline",size:"sm",onClick:e,disabled:t||!n,"aria-label":t?"Restarting":"Restart server",children:[s.jsx(xl,{size:12,"aria-hidden":"true"}),t?"Restarting…":"Restart"]}),!n&&s.jsx("p",{className:"mt-2 text-[11px] text-muted-foreground",children:"Server is disabled — enable and save first to restart."})]})]})}function F0(){const e=Ye(),{data:t,isLoading:n,error:r}=ka(),o=Vf(),a=Ge(x=>x.push),[i,l]=f.useState({source:[],patterns:[]}),c=t?.denied_patterns;c&&c!==i.source&&l({source:c,patterns:c});const d=i.patterns,u=x=>l(y=>({source:y.source,patterns:typeof x=="function"?x(y.patterns):x})),m=f.useMemo(()=>{const x=i.source;return x.length!==d.length?!0:x.some((y,j)=>y!==d[j])},[i.source,d]),h=(x,y)=>u(j=>j.map((w,N)=>N===x?y:w)),g=x=>u(y=>y.filter((j,w)=>w!==x)),p=()=>u(x=>[...x,""]),b=async()=>{const x=d.map(y=>y.trim()).filter(Boolean);try{await o.mutateAsync({denied_patterns:x}),u(x),a({tone:"success",title:"Sandbox saved",description:`${x.length} pattern${x.length===1?"":"s"} active.`})}catch(y){a({tone:"error",title:"Save failed",description:y instanceof Error?y.message:String(y)})}};return s.jsxs(s.Fragment,{children:[s.jsxs("header",{className:"sticky top-0 z-10 flex h-14 shrink-0 items-center gap-3 border-b border-border bg-background px-4",children:[e&&s.jsx(Te,{to:"/settings",className:"flex h-7 w-7 shrink-0 items-center justify-center rounded-md text-muted-foreground transition-colors hover:bg-accent hover:text-foreground","aria-label":"Back to settings",children:s.jsx(Be,{size:14})}),s.jsx("h1",{className:"flex-1 truncate text-sm font-semibold",children:"Sandbox"}),m&&s.jsx("span",{className:"text-xs text-muted-foreground","aria-live":"polite",children:"Unsaved"}),s.jsxs(Y,{size:"sm",onClick:b,disabled:!m||o.isPending,children:[s.jsx(ws,{size:12,"aria-hidden":"true"}),o.isPending?"Saving…":"Save"]})]}),s.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto",children:s.jsxs("div",{className:"mx-auto max-w-3xl space-y-5 p-6",children:[s.jsxs("p",{className:"text-sm leading-relaxed text-muted-foreground",children:["Glob patterns matched against the resolved absolute path. Use"," ",s.jsx("code",{className:"rounded bg-muted px-1 py-0.5 font-mono text-xs",children:"**"})," ","for any depth and"," ",s.jsx("code",{className:"rounded bg-muted px-1 py-0.5 font-mono text-xs",children:"*"})," ","for one path segment. The agent’s workspace and shared memory are always reachable, even when a pattern would otherwise match."," ",s.jsx(L0,{})]}),n&&s.jsx("p",{className:"text-sm text-muted-foreground",children:"Loading…"}),r&&s.jsxs("div",{className:"flex items-start gap-2 rounded-lg bg-destructive/10 p-3 text-xs text-destructive",role:"alert",children:[s.jsx(Ie,{size:13,"aria-hidden":"true",className:"mt-0.5"}),s.jsx("span",{children:r instanceof Error?r.message:String(r)})]}),!n&&!r&&s.jsx(s.Fragment,{children:d.length===0?s.jsxs("div",{className:"flex flex-col items-center gap-3 rounded-xl border border-dashed border-border p-10 text-center",children:[s.jsx("p",{className:"text-sm font-medium",children:"No patterns"}),s.jsxs("p",{className:"max-w-sm text-xs leading-relaxed text-muted-foreground",children:["Agents have unrestricted filesystem access (apart from the built-in DB / state / cache denial). Add a pattern below to block files like ",s.jsx("code",{className:"font-mono",children:".env"})," or folders like ",s.jsx("code",{className:"font-mono",children:"secrets/"}),"."]}),s.jsxs(Y,{size:"sm",onClick:p,children:[s.jsx(ct,{size:12,"aria-hidden":"true"}),"Add pattern"]})]}):s.jsxs(s.Fragment,{children:[s.jsx("ul",{className:"space-y-2",children:d.map((x,y)=>s.jsxs("li",{className:"flex items-center gap-2",children:[s.jsx(oe,{value:x,onChange:j=>h(y,j.target.value),placeholder:"**/.env","aria-label":`Pattern ${y+1}`,className:"h-9 font-mono text-sm"}),s.jsxs(gt,{children:[s.jsx(bt,{render:s.jsx(Y,{size:"icon-sm",variant:"ghost",onClick:()=>g(y),"aria-label":`Remove pattern ${y+1}`,children:s.jsx(Os,{size:13})})}),s.jsx(yt,{children:"Remove"})]})]},y))}),s.jsxs(Y,{size:"sm",variant:"outline",onClick:p,children:[s.jsx(ct,{size:12,"aria-hidden":"true"}),"Add pattern"]})]})})]})})]})}const W0=[{pattern:"**/.env",description:"Any file named .env, at any depth"},{pattern:"**/.env.*",description:"Variants like .env.local, .env.prod"},{pattern:"secrets/**",description:"Everything under a secrets/ folder"},{pattern:"**/*.pem",description:"PEM keys anywhere in the tree"},{pattern:"**/id_rsa*",description:"SSH private keys (and .pub if you wish)"},{pattern:"db/**",description:"Local database files in db/"}];function L0(){const[e,t]=f.useState(!1);return s.jsxs(en,{open:e,onOpenChange:t,children:[s.jsx(tn,{render:s.jsxs("button",{type:"button",className:"inline-flex items-center gap-0.5 rounded text-foreground underline-offset-2 hover:underline focus-visible:outline-none focus-visible:ring-3 focus-visible:ring-ring/40",children:["See examples",s.jsx(Xe,{size:12,"aria-hidden":"true",className:T("transition-transform duration-150",e&&"rotate-180")})]})}),s.jsxs(sn,{className:"w-80 gap-3 p-3",align:"start",children:[s.jsx("ul",{className:"flex flex-col gap-1.5",children:W0.map(n=>s.jsxs("li",{className:"flex flex-col gap-0.5",children:[s.jsx("code",{className:"self-start rounded bg-muted px-1.5 py-0.5 font-mono text-[11px]",children:n.pattern}),s.jsx("span",{className:"text-[11px] leading-snug text-muted-foreground",children:n.description})]},n.pattern))}),s.jsx("p",{className:"border-t border-border pt-2 text-[11px] leading-snug text-muted-foreground",children:"Built-in DB / state / cache paths are always denied; matching is logical-OR across patterns — one match blocks access."})]})]})}const Fn={name:"dream",model:"",tools:["ls","read","wiki_search","write"],enabled:!1,schedule:"0 2 * * *"},xo=`You are the dream agent. Your job is to consolidate the wiki from unprocessed conversation sessions and notes.
|
|
78
|
+
|
|
79
|
+
Your working directory is the wiki root. Use relative paths directly:
|
|
80
|
+
- \`USER.md\` (not wiki/USER.md)
|
|
81
|
+
- \`topics/{slug}.md\` (not wiki/topics/)
|
|
82
|
+
- \`INDEX.md\` (not wiki/INDEX.md)
|
|
83
|
+
|
|
84
|
+
For each session/note you process:
|
|
85
|
+
|
|
86
|
+
1. Read \`USER.md\` — update it if new stable facts about the user were learned (identity, preferences, working style). Rewrite in-place, do not append.
|
|
87
|
+
|
|
88
|
+
2. For each topic that emerged: create or update \`topics/{slug}.md\` with required frontmatter:
|
|
89
|
+
\`\`\`
|
|
90
|
+
---
|
|
91
|
+
description: One-sentence summary (drives search relevance).
|
|
92
|
+
tags: [tag1, tag2]
|
|
93
|
+
updated: YYYY-MM-DD
|
|
94
|
+
---
|
|
95
|
+
\`\`\`
|
|
96
|
+
|
|
97
|
+
3. Update \`INDEX.md\` — a table of contents listing all topic files with one-line descriptions.
|
|
98
|
+
|
|
99
|
+
Quality gate:
|
|
100
|
+
- Only promote durable facts worth remembering across sessions.
|
|
101
|
+
- Do not write noise, small talk, or one-off observations.
|
|
102
|
+
- If nothing worth promoting was found, do nothing.
|
|
103
|
+
|
|
104
|
+
Rules:
|
|
105
|
+
- Never delete existing topic files — only update them.
|
|
106
|
+
- Be surgical: only update sections that actually changed.
|
|
107
|
+
- Write precise, query-friendly descriptions for topics — they drive search relevance.`;function I0(e){const{fm:t,body:n}=ss(e);if(!t.trim())return{form:{...Fn},body:e.trim()};const r={...Fn},o=t.split(`
|
|
108
|
+
`);let a=!1;const i=[];for(const l of o){const c=l.replace(/\s+$/,"");if(!c.trim()||c.trim().startsWith("#"))continue;const d=/^\s+-\s+(.+)$/.exec(c);if(a&&d){i.push(d[1].trim());continue}a=!1;const u=/^([A-Za-z_][\w-]*):\s*(.*)$/.exec(c);if(!u)continue;const[,m,h]=u,g=h.trim().replace(/#.*$/,"").trim().replace(/^["']|["']$/g,"");switch(m){case"name":r.name=g;break;case"model":r.model=g;break;case"enabled":r.enabled=g==="true";break;case"schedule":r.schedule=g;break;case"tools":g||(a=!0);break}}return i.length>0&&(r.tools=i),{form:r,body:n.trim()}}function B0(e,t){const n=[];if(n.push(`name: ${e.name}`),n.push("role: member"),e.model&&n.push(`model: ${e.model}`),n.push(`enabled: ${e.enabled}`),n.push(`schedule: "${e.schedule}"`),e.tools.length>0){n.push("tools:");for(const r of[...e.tools].sort())n.push(` - ${r}`)}return`---
|
|
109
|
+
${n.join(`
|
|
110
|
+
`)}
|
|
111
|
+
---
|
|
112
|
+
|
|
113
|
+
${t.trim()}
|
|
114
|
+
`}function Y0(){const e=Ye(),{data:t,isLoading:n,error:r}=Cf(),o=Tf(),a=ga(),i=Ge(v=>v.push),[l,c]=f.useState(Fn),[d,u]=f.useState(xo),[m,h]=f.useState(""),g=t?.content??"";if(g!==m){const v=I0(g);c(v.form),u(v.body),h(g)}const p=f.useMemo(()=>B0(l,d),[l,d]),b=p!==m,x=async()=>{try{await o.mutateAsync(p),h(p),i({tone:"success",title:"Dream config saved"})}catch(v){i({tone:"error",title:"Save failed",description:v instanceof Error?v.message:String(v)})}},y=async()=>{try{const v=await a.mutateAsync();i({tone:"success",title:"Dream run complete",description:`${v.sessions_processed} sessions, ${v.notes_processed} notes processed.`})}catch(v){i({tone:"error",title:"Dream run failed",description:v instanceof Error?v.message:String(v)})}},j=(v,k)=>c(C=>({...C,[v]:k})),w=l.tools.join(", "),N=v=>j("tools",v.split(",").map(k=>k.trim()).filter(Boolean));return s.jsxs(s.Fragment,{children:[s.jsxs("header",{className:"sticky top-0 z-10 flex h-14 shrink-0 items-center gap-3 border-b border-border bg-background px-4",children:[e&&s.jsx(Te,{to:"/settings",className:"flex h-7 w-7 shrink-0 items-center justify-center rounded-md text-muted-foreground transition-colors hover:bg-accent hover:text-foreground","aria-label":"Back to settings",children:s.jsx(Be,{size:14})}),s.jsx(Ps,{size:15,className:"shrink-0 text-muted-foreground","aria-hidden":"true"}),s.jsx("h1",{className:"flex-1 truncate text-sm font-semibold",children:"Dream"}),b&&s.jsx("span",{className:"text-xs text-muted-foreground","aria-live":"polite",children:"Unsaved"}),s.jsxs(Y,{size:"sm",variant:"outline",onClick:y,disabled:a.isPending,children:[s.jsx(Do,{size:12,"aria-hidden":"true"}),a.isPending?"Running…":"Run now"]}),s.jsxs(Y,{size:"sm",onClick:x,disabled:!b||o.isPending,children:[s.jsx(ws,{size:12,"aria-hidden":"true"}),o.isPending?"Saving…":"Save"]})]}),s.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto",children:s.jsxs("div",{className:"mx-auto max-w-3xl space-y-6 p-6",children:[s.jsxs("p",{className:"text-sm leading-relaxed text-muted-foreground",children:["The dream agent runs on a cron schedule and synthesises unprocessed conversation sessions and notes into wiki topics. Configure its schedule, model, and system prompt below, or click ",s.jsx("strong",{children:"Run now"})," to trigger it immediately."]}),n&&s.jsx("p",{className:"text-sm text-muted-foreground",children:"Loading…"}),r&&s.jsx("p",{className:"text-sm text-destructive",children:r instanceof Error?r.message:String(r)}),!n&&!r&&s.jsxs("div",{className:"space-y-5",children:[s.jsxs("section",{className:"space-y-3 rounded-xl border border-border p-4",children:[s.jsx("h2",{className:"text-xs font-semibold uppercase tracking-wider text-muted-foreground",children:"Schedule"}),s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsxs("label",{className:"flex cursor-pointer items-center gap-2 text-sm",children:[s.jsx("input",{type:"checkbox",checked:l.enabled,onChange:v=>j("enabled",v.target.checked),className:"h-4 w-4 rounded border-border accent-foreground"}),"Enabled"]}),s.jsxs("span",{className:"text-xs text-muted-foreground",children:["When disabled, dream runs only via ",s.jsx("em",{children:"Run now"})," or ",s.jsx("code",{className:"font-mono",children:"/dream"}),"."]})]}),s.jsxs("div",{className:"grid gap-1.5",children:[s.jsx("label",{htmlFor:"dream-schedule",className:"text-xs font-medium text-muted-foreground",children:"Cron expression"}),s.jsx(oe,{id:"dream-schedule",value:l.schedule,onChange:v=>j("schedule",v.target.value),placeholder:"0 2 * * *",className:"h-9 font-mono text-sm"}),s.jsxs("p",{className:"text-[11px] text-muted-foreground",children:["Standard 5-field cron (UTC). Example: ",s.jsx("code",{className:"font-mono",children:"0 2 * * *"})," = daily at 2 AM."]})]})]}),s.jsxs("section",{className:"space-y-3 rounded-xl border border-border p-4",children:[s.jsx("h2",{className:"text-xs font-semibold uppercase tracking-wider text-muted-foreground",children:"Model"}),s.jsxs("div",{className:"grid gap-1.5",children:[s.jsx("label",{htmlFor:"dream-model",className:"text-xs font-medium text-muted-foreground",children:"Model ID"}),s.jsx(oe,{id:"dream-model",value:l.model,onChange:v=>j("model",v.target.value),placeholder:"googlegenai:gemini-2.0-flash",className:"h-9 font-mono text-sm"}),s.jsxs("p",{className:"text-[11px] text-muted-foreground",children:["Format: ",s.jsx("code",{className:"font-mono",children:"provider:model-name"}),". Leave empty to skip LLM synthesis (infrastructure-only mode)."]})]}),s.jsxs("div",{className:"grid gap-1.5",children:[s.jsx("label",{htmlFor:"dream-tools",className:"text-xs font-medium text-muted-foreground",children:"Extra tools (comma-separated)"}),s.jsx(oe,{id:"dream-tools",value:w,onChange:v=>N(v.target.value),placeholder:"ls, read, wiki_search, write",className:"h-9 font-mono text-sm"}),s.jsxs("p",{className:"text-[11px] text-muted-foreground",children:[s.jsx("code",{className:"font-mono",children:"read, write, ls, wiki_search"})," are always injected by the backend regardless of this list."]})]})]}),s.jsxs("section",{className:"space-y-3 rounded-xl border border-border p-4",children:[s.jsx("h2",{className:"text-xs font-semibold uppercase tracking-wider text-muted-foreground",children:"System prompt"}),s.jsx("textarea",{value:d,onChange:v=>u(v.target.value),rows:20,spellCheck:!1,className:"w-full resize-y rounded-lg border border-border bg-background px-3 py-2.5 font-mono text-sm text-foreground focus:outline-none focus:ring-2 focus:ring-ring/40",placeholder:xo}),s.jsx("p",{className:"text-[11px] text-muted-foreground",children:"The dream agent receives each unprocessed session transcript and note as user messages. This prompt sets its behaviour and quality gates."})]})]})]})})]})}const li=new Intl.NumberFormat("en-US"),q0=new Intl.NumberFormat("en-US",{notation:"compact",maximumFractionDigits:1});function nt(e){return li.format(e)}function Jt(e){return e<1e3?li.format(e):q0.format(e)}function rt(e){return e===0?"—":e<1e3?`${e.toFixed(0)} ms`:`${(e/1e3).toFixed(1)} s`}function H0(e,t){const n=Math.max(0,t-e),r=Math.floor(n/1e3);if(r<60)return`${r}s ago`;const o=Math.floor(r/60);if(o<60)return`${o}m ago`;const a=Math.floor(o/60);if(a<24)return`${a}h ago`;const i=Math.floor(a/24);return i<7?`${i}d ago`:new Date(e).toLocaleDateString()}function Ks(e){const t=e.startsWith("0x")?e.slice(2):e;return t.length<=12?t:`${t.slice(0,8)}…${t.slice(-4)}`}function ci({isFetching:e,left:t,subtitle:n,right:r}){return s.jsxs("header",{className:"flex h-14 shrink-0 items-center justify-between gap-3 border-b border-(--color-border) bg-(--color-surface-2) px-4",children:[s.jsxs("div",{className:"flex min-w-0 items-center gap-3",children:[s.jsxs(Te,{to:"/",className:"flex items-center gap-2.5 overflow-hidden rounded-md p-1 -ml-1 transition-colors hover:bg-(--color-accent-subtle)",title:"Home",children:[s.jsx("div",{className:"flex h-8 w-8 shrink-0 items-center justify-center rounded-lg bg-(--color-accent-subtle) ring-1 ring-(--color-border-strong)",children:s.jsx(In,{width:18,height:18,className:"text-(--color-accent)"})}),s.jsx("span",{className:"text-sm font-semibold text-(--color-text)",children:"Telemetry"})]}),t,s.jsxs("div",{className:"flex items-center gap-1.5 text-(--color-text-muted)",children:[s.jsx(No,{size:14,className:"text-(--color-accent)"}),s.jsx("span",{className:"text-xs",children:n??"Span aggregates & latency"}),e&&s.jsx(_e,{size:13,className:"ml-1 animate-spin","aria-label":"Refreshing"})]})]}),s.jsx("div",{className:"flex items-center gap-2",children:r})]})}function di({label:e}){return s.jsxs("div",{className:"flex h-64 items-center justify-center text-(--color-text-muted)",children:[s.jsx(_e,{size:18,className:"mr-2 animate-spin"}),s.jsx("span",{className:"text-sm",children:e})]})}function ui({message:e,onRetry:t}){return s.jsx("div",{className:"rounded-xl border border-(--color-danger-subtle) bg-(--color-danger-subtle)/30 p-5",children:s.jsxs("div",{className:"flex items-start gap-3",children:[s.jsx(hl,{size:18,className:"mt-0.5 shrink-0 text-(--color-danger)"}),s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsx("p",{className:"text-sm font-medium text-(--color-text)",children:"Could not load observability data"}),s.jsx("p",{className:"mt-1 text-xs text-(--color-text-muted)",children:e}),s.jsx("button",{onClick:t,className:"mt-3 rounded-md border border-(--color-border) bg-(--color-surface) px-3 py-1.5 text-xs font-medium text-(--color-text) transition-colors hover:bg-(--color-accent-subtle)",children:"Retry"})]})]})})}function Xt({children:e}){return s.jsx("h2",{className:"mb-2 text-xs font-semibold uppercase tracking-wide text-(--color-text-muted)",children:e})}function Je({label:e,value:t,tone:n}){return s.jsxs("div",{className:"rounded-lg border border-(--color-border) bg-(--color-surface) p-3",children:[s.jsx("p",{className:"text-[10px] uppercase tracking-wide text-(--color-text-muted)",children:e}),s.jsx("p",{className:`mt-1 text-lg font-semibold tabular-nums ${n==="danger"?"text-(--color-danger)":"text-(--color-text)"}`,children:t})]})}function ho({headers:e,rows:t,align:n}){return s.jsx("div",{className:"overflow-x-auto rounded-lg border border-(--color-border) bg-(--color-surface)",children:s.jsxs("table",{className:"min-w-[360px] w-full text-xs",children:[s.jsx("thead",{children:s.jsx("tr",{className:"border-b border-(--color-border) bg-(--color-surface-2)",children:e.map((r,o)=>s.jsx("th",{className:`px-3 py-2 font-medium text-(--color-text-muted) ${n[o]==="right"?"text-right":"text-left"}`,children:r},r))})}),s.jsx("tbody",{children:t.map((r,o)=>s.jsx("tr",{className:"border-b border-(--color-border) last:border-b-0",children:r.map((a,i)=>s.jsx("td",{className:`px-3 py-2 tabular-nums ${n[i]==="right"?"text-right":"text-left"} ${i===0?"font-medium text-(--color-text)":"text-(--color-text-2)"}`,children:a},i))},o))})]})})}function Wt({label:e}){return s.jsx("div",{className:"rounded-lg border border-dashed border-(--color-border) bg-(--color-surface-2) p-6 text-center",children:s.jsx("p",{className:"text-xs text-(--color-text-muted)",children:e})})}function et({children:e,align:t}){return s.jsx("th",{className:`px-3 py-2 font-medium text-(--color-text-muted) ${t==="right"?"text-right":"text-left"}`,children:e})}function tt({children:e,align:t,muted:n,mono:r}){return s.jsx("td",{className:`px-3 py-2 tabular-nums ${t==="right"?"text-right":"text-left"} ${n?"text-(--color-text-muted)":"text-(--color-text-2)"} ${r?"font-mono text-[10.5px]":""}`,children:e})}function Gt({label:e,value:t,mono:n}){return s.jsxs("div",{className:"flex items-baseline justify-between gap-3",children:[s.jsx("dt",{className:"shrink-0 text-(--color-text-muted)",children:e}),s.jsx("dd",{className:`min-w-0 truncate text-right text-(--color-text) ${n?"font-mono":""}`,children:t})]})}function U0({rows:e}){if(e.length===0)return s.jsx(Wt,{label:"No turns recorded in this window."});const t=Math.max(...e.map(n=>n.turns),1);return s.jsx("div",{className:"rounded-lg border border-(--color-border) bg-(--color-surface) p-4",children:s.jsx("div",{className:"flex h-28 items-end gap-2",children:e.map(n=>{const r=n.turns/t*100;return s.jsxs("div",{className:"flex min-w-0 flex-1 flex-col items-center gap-1",children:[s.jsx("div",{className:"flex w-full flex-col-reverse rounded-t-sm bg-(--color-accent) transition-all",style:{height:`${Math.max(r,2)}%`},title:`${n.day}: ${n.turns} turns${n.errors>0?`, ${n.errors} errors`:""}`,children:n.errors>0&&s.jsx("div",{className:"w-full rounded-t-sm bg-(--color-danger)",style:{height:`${n.errors/Math.max(n.turns,1)*100}%`}})}),s.jsx("span",{className:"w-full truncate text-[9px] text-(--color-text-muted)",children:n.day.slice(5)})]},n.day)})})})}function Q0({data:e}){const t=e.sample_ratio<1,{totals:n,latency_ms:r}=e;return s.jsxs("div",{className:"flex flex-col gap-5",children:[t&&s.jsxs("div",{className:"flex items-start gap-2 rounded-lg border border-(--color-border) bg-(--color-accent-subtle)/40 p-3",children:[s.jsx(ko,{size:14,className:"mt-0.5 shrink-0 text-(--color-accent)"}),s.jsxs("p",{className:"text-xs text-(--color-text-2)",children:["Spans are sampled at ",s.jsxs("strong",{children:[Math.round(e.sample_ratio*100),"%"]}),". Figures for non-error, non-slow spans are approximate. Set"," ",s.jsx("code",{className:"rounded bg-(--color-surface) px-1 py-0.5 text-[10px]",children:"OTEL_SPAN_SAMPLE_RATIO=1.0"})," ","to disable sampling."]})]}),s.jsxs("section",{children:[s.jsx(Xt,{children:"Totals"}),s.jsxs("div",{className:"grid grid-cols-2 gap-3 sm:grid-cols-3 lg:grid-cols-6",children:[s.jsx(Je,{label:"Turns",value:nt(n.turns)}),s.jsx(Je,{label:"LLM calls",value:nt(n.llm_calls)}),s.jsx(Je,{label:"Tool calls",value:nt(n.tool_calls)}),s.jsx(Je,{label:"Input tokens",value:Jt(n.input_tokens)}),s.jsx(Je,{label:"Output tokens",value:Jt(n.output_tokens)}),s.jsx(Je,{label:"Errors",value:nt(n.errors),tone:n.errors>0?"danger":void 0})]})]}),s.jsxs("section",{children:[s.jsx(Xt,{children:"Latency"}),s.jsxs("div",{className:"grid grid-cols-2 gap-3 sm:grid-cols-4",children:[s.jsx(Je,{label:"Turn p50",value:rt(r.turn_p50)}),s.jsx(Je,{label:"Turn p95",value:rt(r.turn_p95)}),s.jsx(Je,{label:"LLM p50",value:rt(r.llm_p50)}),s.jsx(Je,{label:"LLM p95",value:rt(r.llm_p95)})]})]}),s.jsxs("section",{children:[s.jsx(Xt,{children:"Turns per day"}),s.jsx(U0,{rows:e.daily_turns})]}),s.jsxs("section",{children:[s.jsx(Xt,{children:"By model"}),e.by_model.length===0?s.jsx(Wt,{label:"No LLM calls recorded in this window."}):s.jsx(ho,{headers:["Model","Calls","Input","Output","p95 ms"],rows:e.by_model.map(o=>[o.model,nt(o.calls),Jt(o.input_tokens),Jt(o.output_tokens),rt(o.p95_ms)]),align:["left","right","right","right","right"]})]}),s.jsxs("section",{children:[s.jsx(Xt,{children:"By tool"}),e.by_tool.length===0?s.jsx(Wt,{label:"No tool invocations recorded in this window."}):s.jsx(ho,{headers:["Tool","Calls","Errors","p95 ms"],rows:e.by_tool.map(o=>[o.tool,nt(o.calls),o.errors>0?s.jsx("span",{className:"text-(--color-danger)",children:nt(o.errors)}):"0",rt(o.p95_ms)]),align:["left","right","right","right"]})]})]})}function K0({traces:e,onSelect:t}){const[n]=f.useState(()=>Date.now());return s.jsx("div",{className:"overflow-x-auto rounded-lg border border-(--color-border) bg-(--color-surface)",children:s.jsxs("table",{className:"min-w-[640px] w-full text-xs",children:[s.jsx("thead",{children:s.jsxs("tr",{className:"border-b border-(--color-border) bg-(--color-surface-2)",children:[s.jsx(et,{children:"When"}),s.jsx(et,{children:"Session"}),s.jsx(et,{children:"Agent"}),s.jsx(et,{children:"Model"}),s.jsx(et,{align:"right",children:"Duration"}),s.jsx(et,{align:"right",children:"LLM"}),s.jsx(et,{align:"right",children:"Tools"}),s.jsx(et,{align:"right",children:"Tokens (in / out)"}),s.jsx(et,{align:"right",children:"Status"}),s.jsx(et,{})]})}),s.jsx("tbody",{children:e.map(r=>s.jsxs("tr",{onClick:()=>t(r.trace_id),className:"cursor-pointer border-b border-(--color-border) transition-colors last:border-b-0 hover:bg-(--color-accent-subtle)/40",children:[s.jsx(tt,{children:s.jsx("span",{title:new Date(r.start_ms).toLocaleString(),children:H0(r.start_ms,n)})}),s.jsx(tt,{muted:!0,mono:!0,children:r.session_id?Ks(r.session_id):"—"}),s.jsx(tt,{children:r.agent_name??"—"}),s.jsx(tt,{muted:!0,children:r.model??"—"}),s.jsx(tt,{align:"right",children:rt(r.duration_ms)}),s.jsx(tt,{align:"right",children:nt(r.llm_calls)}),s.jsx(tt,{align:"right",children:nt(r.tool_calls)}),s.jsxs(tt,{align:"right",muted:!0,children:[Jt(r.input_tokens)," / ",Jt(r.output_tokens)]}),s.jsx(tt,{align:"right",children:r.error?s.jsx("span",{className:"rounded bg-(--color-danger-subtle) px-1.5 py-0.5 text-[10px] font-medium text-(--color-danger)",children:"error"}):s.jsx("span",{className:"text-(--color-text-muted)",children:"ok"})}),s.jsx(tt,{align:"right",children:s.jsx(Es,{size:14,className:"text-(--color-text-muted)"})})]},r.trace_id))})]})})}function G0({query:e,onSelectTrace:t}){return s.jsxs("section",{children:[s.jsx(Xt,{children:"Recent traces"}),e.isLoading?s.jsx(Wt,{label:"Loading traces…"}):e.isError?s.jsx(Wt,{label:`Could not load traces: ${String(e.error)}`}):e.data&&e.data.traces.length===0?s.jsx(Wt,{label:"No traces in this window."}):e.data?s.jsx(K0,{traces:e.data.traces,onSelect:t}):null]})}function po({span:e,onClose:t,fullWidth:n=!1}){const r=f.useMemo(()=>X0(e.attributes).filter(([,a])=>a!=="—"),[e.attributes]),o=f.useMemo(()=>V0(e.attributes),[e.attributes]);return s.jsxs("aside",{className:`flex shrink-0 flex-col overflow-hidden border-l border-(--color-border) bg-(--color-surface-2) ${n?"w-full":"w-96"}`,children:[s.jsxs("div",{className:"flex h-12 shrink-0 items-center justify-between border-b border-(--color-border) px-4",children:[s.jsx("h3",{className:"truncate text-sm font-semibold text-(--color-text)",title:e.name,children:e.name}),s.jsx("button",{onClick:t,className:"flex h-6 w-6 items-center justify-center rounded text-(--color-text-muted) transition-colors hover:bg-(--color-accent-subtle) hover:text-(--color-text)","aria-label":"Close span detail",children:s.jsx(Ee,{size:14})})]}),s.jsxs("div",{className:"min-h-0 flex-1 overflow-y-auto p-4",children:[s.jsxs("dl",{className:"flex flex-col gap-3 text-xs",children:[s.jsx(Gt,{label:"Kind",value:e.kind||"—"}),s.jsx(Gt,{label:"Status",value:e.status==="ERROR"?s.jsx("span",{className:"text-(--color-danger)",children:e.status}):e.status||"OK"}),s.jsx(Gt,{label:"Duration",value:rt(e.duration_ms)}),s.jsx(Gt,{label:"Started",value:new Date(e.start_ms).toLocaleString()}),s.jsx(Gt,{label:"Span ID",value:Ks(e.span_id),mono:!0}),s.jsx(Gt,{label:"Parent",value:e.parent_span_id?Ks(e.parent_span_id):"root",mono:!0})]}),o.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("h4",{className:"mb-2 mt-5 text-[10px] font-semibold uppercase tracking-wide text-(--color-text-muted)",children:"Token usage"}),s.jsx("div",{className:"grid grid-cols-2 gap-2",children:o.map(a=>s.jsxs("div",{className:"rounded-md border border-(--color-border) bg-(--color-surface) p-2",children:[s.jsx("p",{className:"text-[9px] uppercase tracking-wide text-(--color-text-muted)",children:a.label}),s.jsx("p",{className:"mt-0.5 text-sm font-semibold tabular-nums text-(--color-text)",children:nt(a.value)})]},a.label))})]}),s.jsx("h4",{className:"mb-2 mt-5 text-[10px] font-semibold uppercase tracking-wide text-(--color-text-muted)",children:"Attributes"}),r.length===0?s.jsx("p",{className:"text-xs text-(--color-text-muted)",children:"No attributes."}):s.jsx("dl",{className:"flex flex-col divide-y divide-(--color-border) rounded-md border border-(--color-border) bg-(--color-surface) text-[11px]",children:r.map(([a,i])=>s.jsxs("div",{className:"flex flex-col gap-0.5 px-3 py-2",children:[s.jsx("dt",{className:"font-medium text-(--color-text-muted)",children:a}),s.jsx("dd",{className:"break-words font-mono text-(--color-text-2)",children:i})]},a))})]})]})}function V0(e){const t=[["gen_ai.usage.input_tokens","Input"],["gen_ai.usage.output_tokens","Output"],["gen_ai.usage.cache_read.input_tokens","Cached"],["gen_ai.usage.reasoning_tokens","Reasoning"],["gen_ai.usage.tool_use_tokens","Tool use"]],n=[];for(const[r,o]of t){const a=e[r],i=typeof a=="number"?a:Number(a);Number.isFinite(i)&&i>0&&n.push({label:o,value:i})}return n}function X0(e){const t=[];for(const[n,r]of Object.entries(e))t.push([n,Z0(r)]);return t.sort(([n],[r])=>n.localeCompare(r)),t}function Z0(e){if(e==null)return"—";if(typeof e=="string")return e;if(typeof e=="number"||typeof e=="boolean")return String(e);try{return JSON.stringify(e)}catch{return String(e)}}function J0(e){const t=new Map;for(const a of e)t.set(a.span_id,{span:a,depth:0,children:[]});const n=[];for(const a of t.values()){const i=a.span.parent_span_id,l=i?t.get(i):void 0;l?l.children.push(a):n.push(a)}const r=(a,i)=>a.span.start_ms-i.span.start_ms,o=(a,i)=>{a.depth=i,a.children.sort(r);for(const l of a.children)o(l,i+1)};n.sort(r);for(const a of n)o(a,0);return n}function eg(e){const t=[],n=r=>{t.push(r);for(const o of r.children)n(o)};for(const r of e)n(r);return t}function tg(e){if(e.length===0)return{start_ms:0,end_ms:0,duration_ms:0};let t=e[0].start_ms,n=e[0].end_ms;for(const r of e)r.start_ms<t&&(t=r.start_ms),r.end_ms>n&&(n=r.end_ms);return{start_ms:t,end_ms:n,duration_ms:n-t}}function sg(e,t){if(t.duration_ms<=0)return{leftPct:0,widthPct:100};const n=(e.start_ms-t.start_ms)/t.duration_ms*100,r=Math.max((e.end_ms-e.start_ms)/t.duration_ms*100,.5);return{leftPct:n,widthPct:r}}function ng(e){return e.startsWith("agent_run")?"agent_run":e.startsWith("chat")?"chat":e.startsWith("execute_tool")?"tool":e.startsWith("summarization")?"summarization":e.startsWith("title_generation")?"title":"other"}function rg(e){switch(e){case"agent_run":return"bg-(--color-accent)";case"chat":return"bg-sky-500";case"tool":return"bg-emerald-500";case"summarization":return"bg-purple-500";case"title":return"bg-amber-500";default:return"bg-slate-400"}}function og(e,t){if(t)return"bg-(--color-danger)";switch(e){case"agent_run":return"bg-(--color-accent)";case"chat":return"bg-sky-500";case"tool":return"bg-emerald-500";case"summarization":return"bg-purple-500";case"title":return"bg-amber-500";default:return"bg-slate-400"}}function ag({spans:e,selectedSpanId:t,onSelectSpan:n}){const{bounds:r,rows:o}=f.useMemo(()=>{const a=J0(e);return{bounds:tg(e),rows:eg(a)}},[e]);return o.length===0?s.jsx(Wt,{label:"This trace contains no spans."}):s.jsxs("div",{className:"flex flex-col gap-3",children:[s.jsxs("div",{className:"flex items-baseline justify-between text-xs text-(--color-text-muted)",children:[s.jsxs("span",{children:[o.length," span",o.length===1?"":"s"]}),s.jsxs("span",{children:["Total ",rt(r.duration_ms)]})]}),s.jsx("div",{className:"overflow-x-auto rounded-lg border border-(--color-border) bg-(--color-surface)",children:s.jsxs("div",{className:"min-w-[480px]",children:[s.jsxs("div",{className:"flex border-b border-(--color-border) bg-(--color-surface-2) px-3 py-2 text-[10px] font-medium uppercase tracking-wide text-(--color-text-muted)",children:[s.jsx("div",{className:"w-48 shrink-0 sm:w-64",children:"Span"}),s.jsx("div",{className:"flex-1",children:"Timeline"}),s.jsx("div",{className:"w-20 shrink-0 text-right",children:"Duration"})]}),s.jsx("div",{className:"divide-y divide-(--color-border)",children:o.map(a=>s.jsx(ig,{node:a,bounds:r,selected:t===a.span.span_id,onSelect:()=>n(a.span.span_id)},a.span.span_id))})]})})]})}function ig({node:e,bounds:t,selected:n,onSelect:r}){const{leftPct:o,widthPct:a}=sg(e.span,t),i=ng(e.span.name),l=e.span.status==="ERROR";return s.jsxs("button",{type:"button",onClick:r,className:`flex w-full items-center px-3 py-2 text-left text-xs transition-colors hover:bg-(--color-accent-subtle)/30 ${n?"bg-(--color-accent-subtle)/60":""}`,children:[s.jsxs("div",{className:"flex w-48 shrink-0 items-center gap-1.5 sm:w-64",style:{paddingLeft:`${e.depth*12}px`},children:[s.jsx("span",{className:`h-2 w-2 shrink-0 rounded-full ${rg(i)}`,"aria-hidden":!0}),s.jsx("span",{className:`truncate font-medium ${l?"text-(--color-danger)":"text-(--color-text)"}`,title:e.span.name,children:e.span.name})]}),s.jsx("div",{className:"relative h-5 flex-1",children:s.jsx("div",{className:`absolute top-1/2 h-2 -translate-y-1/2 rounded-sm ${og(i,l)}`,style:{left:`${o}%`,width:`${a}%`}})}),s.jsx("div",{className:"w-20 shrink-0 text-right tabular-nums text-(--color-text-2)",children:rt(e.span.duration_ms)})]})}const lg=[{value:1,label:"24 h"},{value:7,label:"7 d"},{value:30,label:"30 d"},{value:90,label:"90 d"}];function cg(){const[e,t]=f.useState(7),[n,r]=f.useState(null);return s.jsx("div",{className:"flex h-dvh flex-col overflow-hidden bg-(--color-bg) text-(--color-text)",children:n?s.jsx(ug,{traceId:n,onBack:()=>r(null)}):s.jsx(dg,{days:e,onChangeDays:t,onSelectTrace:r})})}function dg({days:e,onChangeDays:t,onSelectTrace:n}){const r=Rf(e),o=Af(e,50,0),a=r.isFetching||o.isFetching;return s.jsxs(s.Fragment,{children:[s.jsx(ci,{isFetching:a,right:s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"flex items-center gap-1 rounded-lg border border-(--color-border) bg-(--color-surface) p-0.5",children:lg.map(i=>s.jsx("button",{onClick:()=>t(i.value),className:`rounded-md px-2.5 py-1 text-xs font-medium transition-colors ${e===i.value?"bg-(--color-accent-subtle) text-(--color-accent)":"text-(--color-text-muted) hover:text-(--color-text)"}`,children:i.label},i.value))}),s.jsx(Te,{to:"/",className:"flex h-7 w-7 shrink-0 items-center justify-center rounded-md text-(--color-text-muted) transition-colors hover:bg-(--color-accent-subtle) hover:text-(--color-text-2)","aria-label":"Back to home",title:"Back to home",children:s.jsx(Be,{size:15})})]})}),s.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto p-5",children:r.isLoading?s.jsx(di,{label:"Loading span aggregates…"}):r.isError?s.jsx(ui,{message:String(r.error),onRetry:()=>r.refetch()}):r.data?s.jsxs("div",{className:"flex flex-col gap-6",children:[s.jsx(Q0,{data:r.data}),s.jsx(G0,{query:o,onSelectTrace:n})]}):null})]})}function ug({traceId:e,onBack:t}){const n=Ye(),{data:r,isLoading:o,isError:a,error:i,refetch:l,isFetching:c}=Ff(e),[d,u]=f.useState(null),m=r?.spans.find(h=>h.span_id===d)??null;return s.jsxs(s.Fragment,{children:[s.jsx(ci,{isFetching:c,left:s.jsx("button",{onClick:t,className:"flex h-7 w-7 items-center justify-center rounded-md text-(--color-text-muted) transition-colors hover:bg-(--color-accent-subtle) hover:text-(--color-text)","aria-label":"Back to list",children:s.jsx(Be,{size:14})}),subtitle:`Trace ${Ks(e)}`,right:s.jsx(Te,{to:"/",className:"flex h-7 w-7 shrink-0 items-center justify-center rounded-md text-(--color-text-muted) transition-colors hover:bg-(--color-accent-subtle) hover:text-(--color-text-2)","aria-label":"Back to home",title:"Back to home",children:s.jsx(Be,{size:15})})}),s.jsxs("div",{className:"relative flex min-h-0 flex-1 overflow-hidden",children:[s.jsx("div",{className:"min-w-0 flex-1 overflow-y-auto p-5",children:o?s.jsx(di,{label:"Loading trace…"}):a?s.jsx(ui,{message:String(i),onRetry:()=>l()}):r?s.jsx(ag,{spans:r.spans,selectedSpanId:d,onSelectSpan:u}):s.jsxs("div",{className:"rounded-xl border border-(--color-border) bg-(--color-surface-2) p-6 text-center",children:[s.jsx("p",{className:"text-sm font-medium text-(--color-text)",children:"Trace not found"}),s.jsx("p",{className:"mt-1 text-xs text-(--color-text-muted)",children:"This trace may have expired from the retention window."})]})}),m&&(n?s.jsx("div",{className:"absolute inset-0 z-10 overflow-y-auto bg-(--color-surface)",children:s.jsx(po,{span:m,onClose:()=>u(null),fullWidth:!0})}):s.jsx(po,{span:m,onClose:()=>u(null)}))]})]})}function mg(){const e=Ve();return f.useEffect(()=>{e({to:"/cockpit",replace:!0})},[e]),null}const ls=ki({component:lc,notFoundComponent:cc}),fg=ve({getParentRoute:()=>ls,path:"/",component:Jc}),mr=ve({getParentRoute:()=>ls,path:"/cockpit",component:Lp}),xg=ve({getParentRoute:()=>mr,path:"/",component:()=>null}),hg=ve({getParentRoute:()=>mr,path:"$sessionId",component:()=>null}),We=ve({getParentRoute:()=>ls,path:"/settings",component:Vp}),pg=ve({getParentRoute:()=>We,path:"/",component:Xp}),gg=ve({getParentRoute:()=>We,path:"agents",component:Zp}),bg=ve({getParentRoute:()=>We,path:"agents/new",component:k0}),yg=ve({getParentRoute:()=>We,path:"agents/$name",component:w0}),vg=ve({getParentRoute:()=>We,path:"skills",component:N0}),jg=ve({getParentRoute:()=>We,path:"skills/new",component:C0}),wg=ve({getParentRoute:()=>We,path:"skills/$name",component:S0}),kg=ve({getParentRoute:()=>We,path:"mcp",component:T0}),Ng=ve({getParentRoute:()=>We,path:"mcp/new",component:$0}),Sg=ve({getParentRoute:()=>We,path:"mcp/$name",component:z0}),Cg=ve({getParentRoute:()=>We,path:"sandbox",component:F0}),Tg=ve({getParentRoute:()=>We,path:"dream",component:Y0}),Mg=ve({getParentRoute:()=>ls,path:"/telemetry",component:cg}),Dg=ve({getParentRoute:()=>ls,path:"/scheduler",component:mg}),_g=ls.addChildren([fg,mr.addChildren([xg,hg]),We.addChildren([pg,gg,bg,yg,vg,jg,wg,kg,Ng,Sg,Cg,Tg]),Mg,Dg]),Eg=Ni({routeTree:_g});function Og(){return s.jsx(Si,{router:Eg})}Bh();yi.createRoot(document.getElementById("root")).render(s.jsx(f.StrictMode,{children:s.jsx(Og,{})}));
|